1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef _REFLCNST_HXX_ 29 #define _REFLCNST_HXX_ 30 31 #include <registry/refltype.hxx> 32 #include <sal/macros.h> 33 34 #include <string.h> 35 36 #define REGTYPE_IEEE_NATIVE 1 37 38 extern const sal_uInt32 magic; 39 extern const sal_uInt16 minorVersion; 40 extern const sal_uInt16 majorVersion; 41 42 #define OFFSET_MAGIC 0 43 #define OFFSET_SIZE (OFFSET_MAGIC + sizeof(magic)) 44 #define OFFSET_MINOR_VERSION (OFFSET_SIZE + sizeof(sal_uInt32)) 45 #define OFFSET_MAJOR_VERSION (OFFSET_MINOR_VERSION + sizeof(minorVersion)) 46 #define OFFSET_N_ENTRIES (OFFSET_MAJOR_VERSION + sizeof(sal_uInt16)) 47 #define OFFSET_TYPE_SOURCE (OFFSET_N_ENTRIES + sizeof(sal_uInt16)) 48 #define OFFSET_TYPE_CLASS (OFFSET_TYPE_SOURCE + sizeof(sal_uInt16)) 49 #define OFFSET_THIS_TYPE (OFFSET_TYPE_CLASS + sizeof(sal_uInt16)) 50 #define OFFSET_UIK (OFFSET_THIS_TYPE + sizeof(sal_uInt16)) 51 #define OFFSET_DOKU (OFFSET_UIK + sizeof(sal_uInt16)) 52 #define OFFSET_FILENAME (OFFSET_DOKU + sizeof(sal_uInt16)) 53 54 #define OFFSET_N_SUPERTYPES (OFFSET_FILENAME + sizeof(sal_uInt16)) 55 #define OFFSET_SUPERTYPES (OFFSET_N_SUPERTYPES + sizeof(sal_uInt16)) 56 57 #define OFFSET_CP_SIZE (OFFSET_SUPERTYPES + sizeof(sal_uInt16)) 58 #define OFFSET_CP (OFFSET_CP_SIZE + sizeof(sal_uInt16)) 59 60 #define CP_OFFSET_ENTRY_SIZE 0 61 #define CP_OFFSET_ENTRY_TAG (CP_OFFSET_ENTRY_SIZE + sizeof(sal_uInt32)) 62 #define CP_OFFSET_ENTRY_DATA (CP_OFFSET_ENTRY_TAG + sizeof(sal_uInt16)) 63 #define CP_OFFSET_ENTRY_UIK1 CP_OFFSET_ENTRY_DATA 64 #define CP_OFFSET_ENTRY_UIK2 (CP_OFFSET_ENTRY_UIK1 + sizeof(sal_uInt32)) 65 #define CP_OFFSET_ENTRY_UIK3 (CP_OFFSET_ENTRY_UIK2 + sizeof(sal_uInt16)) 66 #define CP_OFFSET_ENTRY_UIK4 (CP_OFFSET_ENTRY_UIK3 + sizeof(sal_uInt16)) 67 #define CP_OFFSET_ENTRY_UIK5 (CP_OFFSET_ENTRY_UIK4 + sizeof(sal_uInt32)) 68 69 #define FIELD_OFFSET_ACCESS 0 70 #define FIELD_OFFSET_NAME (FIELD_OFFSET_ACCESS + sizeof(sal_uInt16)) 71 #define FIELD_OFFSET_TYPE (FIELD_OFFSET_NAME + sizeof(sal_uInt16)) 72 #define FIELD_OFFSET_VALUE (FIELD_OFFSET_TYPE + sizeof(sal_uInt16)) 73 #define FIELD_OFFSET_DOKU (FIELD_OFFSET_VALUE + sizeof(sal_uInt16)) 74 #define FIELD_OFFSET_FILENAME (FIELD_OFFSET_DOKU + sizeof(sal_uInt16)) 75 //#define FIELD_ENTRY_SIZE (FIELD_OFFSET_FILENAME + sizeof(sal_uInt16)) 76 77 #define PARAM_OFFSET_TYPE 0 78 #define PARAM_OFFSET_MODE (PARAM_OFFSET_TYPE + sizeof(sal_uInt16)) 79 #define PARAM_OFFSET_NAME (PARAM_OFFSET_MODE + sizeof(sal_uInt16)) 80 //#define PARAM_ENTRY_SIZE (PARAM_OFFSET_NAME + sizeof(sal_uInt16)) 81 82 #define METHOD_OFFSET_SIZE 0 83 #define METHOD_OFFSET_MODE (METHOD_OFFSET_SIZE + sizeof(sal_uInt16)) 84 #define METHOD_OFFSET_NAME (METHOD_OFFSET_MODE + sizeof(sal_uInt16)) 85 #define METHOD_OFFSET_RETURN (METHOD_OFFSET_NAME + sizeof(sal_uInt16)) 86 #define METHOD_OFFSET_DOKU (METHOD_OFFSET_RETURN + sizeof(sal_uInt16)) 87 #define METHOD_OFFSET_PARAM_COUNT (METHOD_OFFSET_DOKU + sizeof(sal_uInt16)) 88 //#define METHOD_OFFSET_PARAM(i) (METHOD_OFFSET_PARAM_COUNT + sizeof(sal_uInt16) + (i * PARAM_ENTRY_SIZE)) 89 90 #define REFERENCE_OFFSET_TYPE 0 91 #define REFERENCE_OFFSET_NAME (REFERENCE_OFFSET_TYPE + sizeof(sal_uInt16)) 92 #define REFERENCE_OFFSET_DOKU (REFERENCE_OFFSET_NAME + sizeof(sal_uInt16)) 93 #define REFERENCE_OFFSET_ACCESS (REFERENCE_OFFSET_DOKU + sizeof(sal_uInt16)) 94 //#define REFERENCE_ENTRY_SIZE (REFERENCE_OFFSET_ACCESS + sizeof(sal_uInt16)) 95 96 enum CPInfoTag 97 { 98 CP_TAG_INVALID = RT_TYPE_NONE, 99 CP_TAG_CONST_BOOL = RT_TYPE_BOOL, 100 CP_TAG_CONST_BYTE = RT_TYPE_BYTE, 101 CP_TAG_CONST_INT16 = RT_TYPE_INT16, 102 CP_TAG_CONST_UINT16 = RT_TYPE_UINT16, 103 CP_TAG_CONST_INT32 = RT_TYPE_INT32, 104 CP_TAG_CONST_UINT32 = RT_TYPE_UINT32, 105 CP_TAG_CONST_INT64 = RT_TYPE_INT64, 106 CP_TAG_CONST_UINT64 = RT_TYPE_UINT64, 107 CP_TAG_CONST_FLOAT = RT_TYPE_FLOAT, 108 CP_TAG_CONST_DOUBLE = RT_TYPE_DOUBLE, 109 CP_TAG_CONST_STRING = RT_TYPE_STRING, 110 CP_TAG_UTF8_NAME, 111 CP_TAG_UIK 112 }; 113 114 inline sal_uInt32 writeBYTE(sal_uInt8* buffer, sal_uInt8 v) 115 { 116 buffer[0] = v; 117 118 return sizeof(sal_uInt8); 119 } 120 121 inline sal_uInt16 readBYTE(const sal_uInt8* buffer, sal_uInt8& v) 122 { 123 v = buffer[0]; 124 125 return sizeof(sal_uInt8); 126 } 127 128 inline sal_uInt32 writeINT16(sal_uInt8* buffer, sal_Int16 v) 129 { 130 buffer[0] = (sal_uInt8)((v >> 8) & 0xFF); 131 buffer[1] = (sal_uInt8)((v >> 0) & 0xFF); 132 133 return sizeof(sal_Int16); 134 } 135 136 inline sal_uInt32 readINT16(const sal_uInt8* buffer, sal_Int16& v) 137 { 138 v = ((buffer[0] << 8) | (buffer[1] << 0)); 139 140 return sizeof(sal_Int16); 141 } 142 143 inline sal_uInt32 writeUINT16(sal_uInt8* buffer, sal_uInt16 v) 144 { 145 buffer[0] = (sal_uInt8)((v >> 8) & 0xFF); 146 buffer[1] = (sal_uInt8)((v >> 0) & 0xFF); 147 148 return sizeof(sal_uInt16); 149 } 150 151 inline sal_uInt32 readUINT16(const sal_uInt8* buffer, sal_uInt16& v) 152 { 153 v = ((buffer[0] << 8) | (buffer[1] << 0)); 154 155 return sizeof(sal_uInt16); 156 } 157 158 inline sal_uInt32 writeINT32(sal_uInt8* buffer, sal_Int32 v) 159 { 160 buffer[0] = (sal_uInt8)((v >> 24) & 0xFF); 161 buffer[1] = (sal_uInt8)((v >> 16) & 0xFF); 162 buffer[2] = (sal_uInt8)((v >> 8) & 0xFF); 163 buffer[3] = (sal_uInt8)((v >> 0) & 0xFF); 164 165 return sizeof(sal_Int32); 166 } 167 168 inline sal_uInt32 readINT32(const sal_uInt8* buffer, sal_Int32& v) 169 { 170 v = ( 171 (buffer[0] << 24) | 172 (buffer[1] << 16) | 173 (buffer[2] << 8) | 174 (buffer[3] << 0) 175 ); 176 177 return sizeof(sal_Int32); 178 } 179 180 inline sal_uInt32 writeUINT32(sal_uInt8* buffer, sal_uInt32 v) 181 { 182 buffer[0] = (sal_uInt8)((v >> 24) & 0xFF); 183 buffer[1] = (sal_uInt8)((v >> 16) & 0xFF); 184 buffer[2] = (sal_uInt8)((v >> 8) & 0xFF); 185 buffer[3] = (sal_uInt8)((v >> 0) & 0xFF); 186 187 return sizeof(sal_uInt32); 188 } 189 190 inline sal_uInt32 readUINT32(const sal_uInt8* buffer, sal_uInt32& v) 191 { 192 v = ( 193 (buffer[0] << 24) | 194 (buffer[1] << 16) | 195 (buffer[2] << 8) | 196 (buffer[3] << 0) 197 ); 198 199 return sizeof(sal_uInt32); 200 } 201 202 inline sal_uInt32 writeINT64(sal_uInt8* buffer, sal_Int64 v) 203 { 204 buffer[0] = (sal_uInt8)((v >> 56) & 0xFF); 205 buffer[1] = (sal_uInt8)((v >> 48) & 0xFF); 206 buffer[2] = (sal_uInt8)((v >> 40) & 0xFF); 207 buffer[3] = (sal_uInt8)((v >> 32) & 0xFF); 208 buffer[4] = (sal_uInt8)((v >> 24) & 0xFF); 209 buffer[5] = (sal_uInt8)((v >> 16) & 0xFF); 210 buffer[6] = (sal_uInt8)((v >> 8) & 0xFF); 211 buffer[7] = (sal_uInt8)((v >> 0) & 0xFF); 212 213 return sizeof(sal_Int64); 214 } 215 216 inline sal_uInt32 readINT64(const sal_uInt8* buffer, sal_Int64& v) 217 { 218 v = ( 219 ((sal_Int64)buffer[0] << 56) | 220 ((sal_Int64)buffer[1] << 48) | 221 ((sal_Int64)buffer[2] << 40) | 222 ((sal_Int64)buffer[3] << 32) | 223 ((sal_Int64)buffer[4] << 24) | 224 ((sal_Int64)buffer[5] << 16) | 225 ((sal_Int64)buffer[6] << 8) | 226 ((sal_Int64)buffer[7] << 0) 227 ); 228 229 return sizeof(sal_Int64); 230 } 231 232 inline sal_uInt32 writeUINT64(sal_uInt8* buffer, sal_uInt64 v) 233 { 234 buffer[0] = (sal_uInt8)((v >> 56) & 0xFF); 235 buffer[1] = (sal_uInt8)((v >> 48) & 0xFF); 236 buffer[2] = (sal_uInt8)((v >> 40) & 0xFF); 237 buffer[3] = (sal_uInt8)((v >> 32) & 0xFF); 238 buffer[4] = (sal_uInt8)((v >> 24) & 0xFF); 239 buffer[5] = (sal_uInt8)((v >> 16) & 0xFF); 240 buffer[6] = (sal_uInt8)((v >> 8) & 0xFF); 241 buffer[7] = (sal_uInt8)((v >> 0) & 0xFF); 242 243 return sizeof(sal_uInt64); 244 } 245 246 inline sal_uInt32 readUINT64(const sal_uInt8* buffer, sal_uInt64& v) 247 { 248 v = ( 249 ((sal_uInt64)buffer[0] << 56) | 250 ((sal_uInt64)buffer[1] << 48) | 251 ((sal_uInt64)buffer[2] << 40) | 252 ((sal_uInt64)buffer[3] << 32) | 253 ((sal_uInt64)buffer[4] << 24) | 254 ((sal_uInt64)buffer[5] << 16) | 255 ((sal_uInt64)buffer[6] << 8) | 256 ((sal_uInt64)buffer[7] << 0) 257 ); 258 259 return sizeof(sal_uInt64); 260 } 261 262 inline sal_uInt32 writeUtf8(sal_uInt8* buffer, const sal_Char* v) 263 { 264 sal_uInt32 size = strlen(v) + 1; 265 266 memcpy(buffer, v, size); 267 268 return (size); 269 } 270 271 inline sal_uInt32 readUtf8(const sal_uInt8* buffer, sal_Char* v, sal_uInt32 maxSize) 272 { 273 sal_uInt32 size = SAL_MIN(strlen((const sal_Char*) buffer) + 1, maxSize); 274 275 memcpy(v, buffer, size); 276 277 if (size == maxSize) v[size - 1] = '\0'; 278 279 return (size); 280 } 281 282 283 sal_uInt32 writeFloat(sal_uInt8* buffer, float v); 284 sal_uInt32 writeDouble(sal_uInt8* buffer, double v); 285 sal_uInt32 writeString(sal_uInt8* buffer, const sal_Unicode* v); 286 sal_uInt32 readString(const sal_uInt8* buffer, sal_Unicode* v, sal_uInt32 maxSize); 287 288 sal_uInt32 UINT16StringLen(const sal_uInt8* wstring); 289 290 #endif 291 292 293 294 295 296