xref: /aoo42x/main/registry/source/reflcnst.hxx (revision 5a5f4a75)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _REFLCNST_HXX_
25 #define _REFLCNST_HXX_
26 
27 #include <registry/refltype.hxx>
28 #include <sal/macros.h>
29 
30 #include <string.h>
31 
32 #define REGTYPE_IEEE_NATIVE 1
33 
34 extern const sal_uInt32	magic;
35 extern const sal_uInt16 minorVersion;
36 extern const sal_uInt16 majorVersion;
37 
38 #define OFFSET_MAGIC 				0
39 #define OFFSET_SIZE 				(OFFSET_MAGIC + sizeof(magic))
40 #define OFFSET_MINOR_VERSION 		(OFFSET_SIZE + sizeof(sal_uInt32))
41 #define OFFSET_MAJOR_VERSION 		(OFFSET_MINOR_VERSION + sizeof(minorVersion))
42 #define OFFSET_N_ENTRIES   	 		(OFFSET_MAJOR_VERSION + sizeof(sal_uInt16))
43 #define OFFSET_TYPE_SOURCE    		(OFFSET_N_ENTRIES + sizeof(sal_uInt16))
44 #define OFFSET_TYPE_CLASS 			(OFFSET_TYPE_SOURCE + sizeof(sal_uInt16))
45 #define OFFSET_THIS_TYPE 			(OFFSET_TYPE_CLASS + sizeof(sal_uInt16))
46 #define OFFSET_UIK 					(OFFSET_THIS_TYPE + sizeof(sal_uInt16))
47 #define OFFSET_DOKU 	   			(OFFSET_UIK + sizeof(sal_uInt16))
48 #define OFFSET_FILENAME				(OFFSET_DOKU + sizeof(sal_uInt16))
49 
50 #define OFFSET_N_SUPERTYPES			(OFFSET_FILENAME + sizeof(sal_uInt16))
51 #define OFFSET_SUPERTYPES			(OFFSET_N_SUPERTYPES + sizeof(sal_uInt16))
52 
53 #define OFFSET_CP_SIZE				(OFFSET_SUPERTYPES + sizeof(sal_uInt16))
54 #define OFFSET_CP 					(OFFSET_CP_SIZE + sizeof(sal_uInt16))
55 
56 #define CP_OFFSET_ENTRY_SIZE		0
57 #define CP_OFFSET_ENTRY_TAG			(CP_OFFSET_ENTRY_SIZE + sizeof(sal_uInt32))
58 #define CP_OFFSET_ENTRY_DATA		(CP_OFFSET_ENTRY_TAG + sizeof(sal_uInt16))
59 #define CP_OFFSET_ENTRY_UIK1		CP_OFFSET_ENTRY_DATA
60 #define CP_OFFSET_ENTRY_UIK2		(CP_OFFSET_ENTRY_UIK1 + sizeof(sal_uInt32))
61 #define CP_OFFSET_ENTRY_UIK3		(CP_OFFSET_ENTRY_UIK2 + sizeof(sal_uInt16))
62 #define CP_OFFSET_ENTRY_UIK4		(CP_OFFSET_ENTRY_UIK3 + sizeof(sal_uInt16))
63 #define CP_OFFSET_ENTRY_UIK5		(CP_OFFSET_ENTRY_UIK4 + sizeof(sal_uInt32))
64 
65 #define FIELD_OFFSET_ACCESS			0
66 #define FIELD_OFFSET_NAME			(FIELD_OFFSET_ACCESS + sizeof(sal_uInt16))
67 #define FIELD_OFFSET_TYPE			(FIELD_OFFSET_NAME + sizeof(sal_uInt16))
68 #define FIELD_OFFSET_VALUE			(FIELD_OFFSET_TYPE + sizeof(sal_uInt16))
69 #define FIELD_OFFSET_DOKU			(FIELD_OFFSET_VALUE + sizeof(sal_uInt16))
70 #define FIELD_OFFSET_FILENAME		(FIELD_OFFSET_DOKU + sizeof(sal_uInt16))
71 //#define FIELD_ENTRY_SIZE			(FIELD_OFFSET_FILENAME + sizeof(sal_uInt16))
72 
73 #define PARAM_OFFSET_TYPE			0
74 #define PARAM_OFFSET_MODE			(PARAM_OFFSET_TYPE + sizeof(sal_uInt16))
75 #define PARAM_OFFSET_NAME			(PARAM_OFFSET_MODE + sizeof(sal_uInt16))
76 //#define PARAM_ENTRY_SIZE			(PARAM_OFFSET_NAME + sizeof(sal_uInt16))
77 
78 #define METHOD_OFFSET_SIZE			0
79 #define METHOD_OFFSET_MODE			(METHOD_OFFSET_SIZE + sizeof(sal_uInt16))
80 #define METHOD_OFFSET_NAME			(METHOD_OFFSET_MODE + sizeof(sal_uInt16))
81 #define METHOD_OFFSET_RETURN		(METHOD_OFFSET_NAME + sizeof(sal_uInt16))
82 #define METHOD_OFFSET_DOKU			(METHOD_OFFSET_RETURN + sizeof(sal_uInt16))
83 #define METHOD_OFFSET_PARAM_COUNT	(METHOD_OFFSET_DOKU + sizeof(sal_uInt16))
84 //#define METHOD_OFFSET_PARAM(i)		(METHOD_OFFSET_PARAM_COUNT + sizeof(sal_uInt16) + (i * PARAM_ENTRY_SIZE))
85 
86 #define REFERENCE_OFFSET_TYPE	   	0
87 #define REFERENCE_OFFSET_NAME	   	(REFERENCE_OFFSET_TYPE + sizeof(sal_uInt16))
88 #define REFERENCE_OFFSET_DOKU	   	(REFERENCE_OFFSET_NAME + sizeof(sal_uInt16))
89 #define REFERENCE_OFFSET_ACCESS	   	(REFERENCE_OFFSET_DOKU + sizeof(sal_uInt16))
90 //#define REFERENCE_ENTRY_SIZE	   	(REFERENCE_OFFSET_ACCESS + sizeof(sal_uInt16))
91 
92 enum CPInfoTag
93 {
94 	CP_TAG_INVALID = RT_TYPE_NONE,
95 	CP_TAG_CONST_BOOL = RT_TYPE_BOOL,
96 	CP_TAG_CONST_BYTE  = RT_TYPE_BYTE,
97 	CP_TAG_CONST_INT16 = RT_TYPE_INT16,
98 	CP_TAG_CONST_UINT16 = RT_TYPE_UINT16,
99 	CP_TAG_CONST_INT32 = RT_TYPE_INT32,
100 	CP_TAG_CONST_UINT32 = RT_TYPE_UINT32,
101 	CP_TAG_CONST_INT64 = RT_TYPE_INT64,
102 	CP_TAG_CONST_UINT64 = RT_TYPE_UINT64,
103 	CP_TAG_CONST_FLOAT = RT_TYPE_FLOAT,
104 	CP_TAG_CONST_DOUBLE = RT_TYPE_DOUBLE,
105 	CP_TAG_CONST_STRING = RT_TYPE_STRING,
106 	CP_TAG_UTF8_NAME,
107 	CP_TAG_UIK
108 };
109 
writeBYTE(sal_uInt8 * buffer,sal_uInt8 v)110 inline sal_uInt32 writeBYTE(sal_uInt8* buffer, sal_uInt8 v)
111 {
112 	buffer[0] = v;
113 
114 	return sizeof(sal_uInt8);
115 }
116 
readBYTE(const sal_uInt8 * buffer,sal_uInt8 & v)117 inline sal_uInt16 readBYTE(const sal_uInt8* buffer, sal_uInt8& v)
118 {
119 	v = buffer[0];
120 
121 	return sizeof(sal_uInt8);
122 }
123 
writeINT16(sal_uInt8 * buffer,sal_Int16 v)124 inline sal_uInt32 writeINT16(sal_uInt8* buffer, sal_Int16 v)
125 {
126 	buffer[0] = (sal_uInt8)((v >> 8) & 0xFF);
127 	buffer[1] = (sal_uInt8)((v >> 0) & 0xFF);
128 
129 	return sizeof(sal_Int16);
130 }
131 
readINT16(const sal_uInt8 * buffer,sal_Int16 & v)132 inline sal_uInt32 readINT16(const sal_uInt8* buffer, sal_Int16& v)
133 {
134 	v = ((buffer[0] << 8) | (buffer[1] << 0));
135 
136 	return sizeof(sal_Int16);
137 }
138 
writeUINT16(sal_uInt8 * buffer,sal_uInt16 v)139 inline sal_uInt32 writeUINT16(sal_uInt8* buffer, sal_uInt16 v)
140 {
141 	buffer[0] = (sal_uInt8)((v >> 8) & 0xFF);
142 	buffer[1] = (sal_uInt8)((v >> 0) & 0xFF);
143 
144 	return sizeof(sal_uInt16);
145 }
146 
readUINT16(const sal_uInt8 * buffer,sal_uInt16 & v)147 inline sal_uInt32 readUINT16(const sal_uInt8* buffer, sal_uInt16& v)
148 {
149 	v = ((buffer[0] << 8) | (buffer[1] << 0));
150 
151 	return sizeof(sal_uInt16);
152 }
153 
writeINT32(sal_uInt8 * buffer,sal_Int32 v)154 inline sal_uInt32 writeINT32(sal_uInt8* buffer, sal_Int32 v)
155 {
156 	buffer[0] = (sal_uInt8)((v >> 24) & 0xFF);
157 	buffer[1] = (sal_uInt8)((v >> 16) & 0xFF);
158 	buffer[2] = (sal_uInt8)((v >> 8) & 0xFF);
159 	buffer[3] = (sal_uInt8)((v >> 0) & 0xFF);
160 
161 	return sizeof(sal_Int32);
162 }
163 
readINT32(const sal_uInt8 * buffer,sal_Int32 & v)164 inline sal_uInt32 readINT32(const sal_uInt8* buffer, sal_Int32& v)
165 {
166 	v = (
167 			(buffer[0] << 24) |
168 			(buffer[1] << 16) |
169 			(buffer[2] << 8)  |
170 			(buffer[3] << 0)
171 		);
172 
173 	return sizeof(sal_Int32);
174 }
175 
writeUINT32(sal_uInt8 * buffer,sal_uInt32 v)176 inline sal_uInt32 writeUINT32(sal_uInt8* buffer, sal_uInt32 v)
177 {
178 	buffer[0] = (sal_uInt8)((v >> 24) & 0xFF);
179 	buffer[1] = (sal_uInt8)((v >> 16) & 0xFF);
180 	buffer[2] = (sal_uInt8)((v >> 8) & 0xFF);
181 	buffer[3] = (sal_uInt8)((v >> 0) & 0xFF);
182 
183 	return sizeof(sal_uInt32);
184 }
185 
readUINT32(const sal_uInt8 * buffer,sal_uInt32 & v)186 inline sal_uInt32 readUINT32(const sal_uInt8* buffer, sal_uInt32& v)
187 {
188 	v = (
189 			(buffer[0] << 24) |
190 			(buffer[1] << 16) |
191 			(buffer[2] << 8)  |
192 			(buffer[3] << 0)
193 		);
194 
195 	return sizeof(sal_uInt32);
196 }
197 
writeINT64(sal_uInt8 * buffer,sal_Int64 v)198 inline sal_uInt32 writeINT64(sal_uInt8* buffer, sal_Int64 v)
199 {
200 	buffer[0] = (sal_uInt8)((v >> 56) & 0xFF);
201 	buffer[1] = (sal_uInt8)((v >> 48) & 0xFF);
202 	buffer[2] = (sal_uInt8)((v >> 40) & 0xFF);
203 	buffer[3] = (sal_uInt8)((v >> 32) & 0xFF);
204 	buffer[4] = (sal_uInt8)((v >> 24) & 0xFF);
205 	buffer[5] = (sal_uInt8)((v >> 16) & 0xFF);
206 	buffer[6] = (sal_uInt8)((v >> 8) & 0xFF);
207 	buffer[7] = (sal_uInt8)((v >> 0) & 0xFF);
208 
209 	return sizeof(sal_Int64);
210 }
211 
readINT64(const sal_uInt8 * buffer,sal_Int64 & v)212 inline sal_uInt32 readINT64(const sal_uInt8* buffer, sal_Int64& v)
213 {
214 	v = (
215 			((sal_Int64)buffer[0] << 56) |
216 			((sal_Int64)buffer[1] << 48) |
217 			((sal_Int64)buffer[2] << 40) |
218 			((sal_Int64)buffer[3] << 32) |
219 			((sal_Int64)buffer[4] << 24) |
220 			((sal_Int64)buffer[5] << 16) |
221 			((sal_Int64)buffer[6] << 8)  |
222 			((sal_Int64)buffer[7] << 0)
223 		);
224 
225 	return sizeof(sal_Int64);
226 }
227 
writeUINT64(sal_uInt8 * buffer,sal_uInt64 v)228 inline sal_uInt32 writeUINT64(sal_uInt8* buffer, sal_uInt64 v)
229 {
230 	buffer[0] = (sal_uInt8)((v >> 56) & 0xFF);
231 	buffer[1] = (sal_uInt8)((v >> 48) & 0xFF);
232 	buffer[2] = (sal_uInt8)((v >> 40) & 0xFF);
233 	buffer[3] = (sal_uInt8)((v >> 32) & 0xFF);
234 	buffer[4] = (sal_uInt8)((v >> 24) & 0xFF);
235 	buffer[5] = (sal_uInt8)((v >> 16) & 0xFF);
236 	buffer[6] = (sal_uInt8)((v >> 8) & 0xFF);
237 	buffer[7] = (sal_uInt8)((v >> 0) & 0xFF);
238 
239 	return sizeof(sal_uInt64);
240 }
241 
readUINT64(const sal_uInt8 * buffer,sal_uInt64 & v)242 inline sal_uInt32 readUINT64(const sal_uInt8* buffer, sal_uInt64& v)
243 {
244 	v = (
245 			((sal_uInt64)buffer[0] << 56) |
246 			((sal_uInt64)buffer[1] << 48) |
247 			((sal_uInt64)buffer[2] << 40) |
248 			((sal_uInt64)buffer[3] << 32) |
249 			((sal_uInt64)buffer[4] << 24) |
250 			((sal_uInt64)buffer[5] << 16) |
251 			((sal_uInt64)buffer[6] << 8)  |
252 			((sal_uInt64)buffer[7] << 0)
253 		);
254 
255 	return sizeof(sal_uInt64);
256 }
257 
writeUtf8(sal_uInt8 * buffer,const sal_Char * v)258 inline sal_uInt32 writeUtf8(sal_uInt8* buffer, const sal_Char* v)
259 {
260 	sal_uInt32 size = strlen(v) + 1;
261 
262 	memcpy(buffer, v, size);
263 
264 	return (size);
265 }
266 
readUtf8(const sal_uInt8 * buffer,sal_Char * v,sal_uInt32 maxSize)267 inline sal_uInt32 readUtf8(const sal_uInt8* buffer, sal_Char* v, sal_uInt32 maxSize)
268 {
269 	sal_uInt32 size = SAL_MIN(strlen((const sal_Char*) buffer) + 1, maxSize);
270 
271 	memcpy(v, buffer, size);
272 
273 	if (size == maxSize) v[size - 1] = '\0';
274 
275 	return (size);
276 }
277 
278 
279 sal_uInt32 writeFloat(sal_uInt8* buffer, float v);
280 sal_uInt32 writeDouble(sal_uInt8* buffer, double v);
281 sal_uInt32 writeString(sal_uInt8* buffer, const sal_Unicode* v);
282 sal_uInt32 readString(const sal_uInt8* buffer, sal_Unicode* v, sal_uInt32 maxSize);
283 
284 sal_uInt32 UINT16StringLen(const sal_uInt8* wstring);
285 
286 #endif
287 
288 
289 
290 
291 
292