00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef _SUPPORT_STATIC_VALUE_H_
00014 #define _SUPPORT_STATIC_VALUE_H_
00015
00021 #include <support/Debug.h>
00022 #include <support/SupportDefs.h>
00023 #include <support/SharedBuffer.h>
00024 #include <support/TypeConstants.h>
00025
00026 #if _SUPPORTS_NAMESPACE
00027 namespace palmos {
00028 namespace support {
00029 #endif
00030
00035 class SString;
00036 class SValue;
00037
00038
00039
00040
00041
00042
00043 extern "C" void palmsource_inc_package_ref();
00044 extern "C" void palmsource_dec_package_ref();
00045
00046
00047
00051 struct static_small_value
00052 {
00053 uint32_t type;
00054 char data[4];
00055
00056 inline operator const SValue&() const { return *(const SValue*)(void*)this; }
00057 };
00058
00062 struct static_large_value
00063 {
00064 uint32_t type;
00065 const void* data;
00066
00067 inline operator const SValue&() const { return *(const SValue*)(void*)this; }
00068 };
00069
00071 struct static_small_string_value
00072 {
00073 uint32_t type;
00074 char data[4];
00075 const void* data_str;
00076
00077 inline operator const SString&() const { return *(const SString*)(void*)&data_str; }
00078 inline operator const SValue&() const { return *(const SValue*)(void*)this; }
00079 };
00080
00082 struct static_large_string_value
00083 {
00084 uint32_t type;
00085 const void* data;
00086 const void* data_str;
00087
00088 inline operator const SString&() const { return *(const SString*)(void*)&data_str; }
00089 inline operator const SValue&() const { return *(const SValue*)(void*)this; }
00090 };
00091
00095 struct static_int32_value
00096 {
00097 uint32_t type;
00098 int32_t value;
00099
00100 inline operator const SValue&() const { return *(const SValue*)(void*)this; }
00101 };
00102
00106 struct static_float_value
00107 {
00108 uint32_t type;
00109 float value;
00110
00111 inline operator const SValue&() const { return *(const SValue*)(void*)this; }
00112 };
00113
00117 struct static_bool_value
00118 {
00119 uint32_t type;
00120
00121
00122
00123 int8_t value;
00124
00125 inline operator const SValue&() const { return *(const SValue*)(void*)this; }
00126 };
00127
00128
00129
00130
00131 typedef const static_small_string_value value_csml;
00132 typedef const static_large_string_value value_clrg;
00133 typedef const static_int32_value value_cint32;
00134 typedef const static_float_value value_cfloat;
00135 typedef const static_bool_value value_cbool;
00136
00137
00138
00139 #define STRING_ASSERT(x) inline void string_assert() { STATIC_ASSERT(x); }
00140 #define PADDED_STRING_LENGTH(string) sizeof(string)+((4-(sizeof(string)%4)) & 0x3)
00141
00143 #define B_CONST_STRING_VALUE_SMALL(ident, string, prefix) \
00144 const struct { \
00145 STRING_ASSERT(sizeof(string)<=4); \
00146 SSharedBuffer::inc_ref_func incFunc; \
00147 SSharedBuffer::dec_ref_func decFunc; \
00148 int32_t users; \
00149 size_t length; \
00150 char data[PADDED_STRING_LENGTH(string)]; \
00151 } ident##str = { \
00152 &palmsource_inc_package_ref, \
00153 &palmsource_dec_package_ref, \
00154 B_STATIC_USERS, \
00155 sizeof(string)<<B_BUFFER_LENGTH_SHIFT, string \
00156 }; \
00157 const static_small_string_value prefix##ident = { \
00158 B_PACK_SMALL_TYPE(B_STRING_TYPE, sizeof(string)), string, \
00159 &ident##str.data \
00160 }; \
00161
00162
00163 #define B_STATIC_STRING_VALUE_SMALL(ident, string, prefix) \
00164 static const struct { \
00165 STRING_ASSERT(sizeof(string)<=4); \
00166 SSharedBuffer::inc_ref_func incFunc; \
00167 SSharedBuffer::dec_ref_func decFunc; \
00168 int32_t users; \
00169 size_t length; \
00170 char data[PADDED_STRING_LENGTH(string)]; \
00171 } ident##str = { \
00172 &palmsource_inc_package_ref, \
00173 &palmsource_dec_package_ref, \
00174 B_STATIC_USERS, \
00175 sizeof(string)<<B_BUFFER_LENGTH_SHIFT, string \
00176 }; \
00177 static const static_small_string_value prefix##ident = { \
00178 B_PACK_SMALL_TYPE(B_STRING_TYPE, sizeof(string)), string, \
00179 &ident##str.data \
00180 }; \
00181
00182
00183 #define B_CONST_STRING_VALUE_LARGE(ident, string, prefix) \
00184 const struct { \
00185 STRING_ASSERT(sizeof(string)>4); \
00186 SSharedBuffer::inc_ref_func incFunc; \
00187 SSharedBuffer::dec_ref_func decFunc; \
00188 int32_t users; \
00189 size_t length; \
00190 char data[PADDED_STRING_LENGTH(string)]; \
00191 } ident##str = { \
00192 &palmsource_inc_package_ref, \
00193 &palmsource_dec_package_ref, \
00194 B_STATIC_USERS, \
00195 sizeof(string)<<B_BUFFER_LENGTH_SHIFT, string \
00196 }; \
00197 const static_large_string_value prefix##ident = { \
00198 B_PACK_LARGE_TYPE(B_STRING_TYPE), &ident##str.users, \
00199 &ident##str.data \
00200 }; \
00201
00202
00203 #define B_STATIC_STRING_VALUE_LARGE(ident, string, prefix) \
00204 static const struct { \
00205 STRING_ASSERT(sizeof(string)>4); \
00206 SSharedBuffer::inc_ref_func incFunc; \
00207 SSharedBuffer::dec_ref_func decFunc; \
00208 int32_t users; \
00209 size_t length; \
00210 char data[PADDED_STRING_LENGTH(string)]; \
00211 } ident##str = { \
00212 &palmsource_inc_package_ref, \
00213 &palmsource_dec_package_ref, \
00214 B_STATIC_USERS, \
00215 sizeof(string)<<B_BUFFER_LENGTH_SHIFT, string \
00216 }; \
00217 static const static_large_string_value prefix##ident = { \
00218 B_PACK_LARGE_TYPE(B_STRING_TYPE), &ident##str.users, \
00219 &ident##str.data \
00220 }; \
00221
00222
00223 #define B_CONST_INT32_VALUE(ident, val, prefix) \
00224 const static_int32_value prefix##ident = { \
00225 B_PACK_SMALL_TYPE(B_INT32_TYPE, sizeof(int32_t)), val \
00226 }; \
00227
00228
00229 #define B_STATIC_INT32_VALUE(ident, val, prefix) \
00230 static const static_int32_value prefix##ident = { \
00231 B_PACK_SMALL_TYPE(B_INT32_TYPE, sizeof(int32_t)), val \
00232 }; \
00233
00234
00235 #define B_CONST_FLOAT_VALUE(ident, val, prefix) \
00236 const static_float_value prefix##ident = { \
00237 B_PACK_SMALL_TYPE(B_FLOAT_TYPE, sizeof(float)), val \
00238 }; \
00239
00240
00241 #define B_STATIC_FLOAT_VALUE(ident, val, prefix) \
00242 static const static_float_value prefix##ident = { \
00243 B_PACK_SMALL_TYPE(B_FLOAT_TYPE, sizeof(float)), val \
00244 }; \
00245
00246
00248
00249 #define B_CONST_STRING_VALUE_4 B_CONST_STRING_VALUE_SMALL
00250 #define B_STATIC_STRING_VALUE_4 B_STATIC_STRING_VALUE_SMALL
00251 #define B_CONST_STRING_VALUE_8 B_CONST_STRING_VALUE_LARGE
00252 #define B_STATIC_STRING_VALUE_8 B_STATIC_STRING_VALUE_LARGE
00253 #define B_CONST_STRING_VALUE_12 B_CONST_STRING_VALUE_LARGE
00254 #define B_STATIC_STRING_VALUE_12 B_STATIC_STRING_VALUE_LARGE
00255 #define B_CONST_STRING_VALUE_16 B_CONST_STRING_VALUE_LARGE
00256 #define B_STATIC_STRING_VALUE_16 B_STATIC_STRING_VALUE_LARGE
00257 #define B_CONST_STRING_VALUE_20 B_CONST_STRING_VALUE_LARGE
00258 #define B_STATIC_STRING_VALUE_20 B_STATIC_STRING_VALUE_LARGE
00259 #define B_CONST_STRING_VALUE_24 B_CONST_STRING_VALUE_LARGE
00260 #define B_STATIC_STRING_VALUE_24 B_STATIC_STRING_VALUE_LARGE
00261 #define B_CONST_STRING_VALUE_28 B_CONST_STRING_VALUE_LARGE
00262 #define B_STATIC_STRING_VALUE_28 B_STATIC_STRING_VALUE_LARGE
00263 #define B_CONST_STRING_VALUE_32 B_CONST_STRING_VALUE_LARGE
00264 #define B_STATIC_STRING_VALUE_32 B_STATIC_STRING_VALUE_LARGE
00265 #define B_CONST_STRING_VALUE_36 B_CONST_STRING_VALUE_LARGE
00266 #define B_STATIC_STRING_VALUE_36 B_STATIC_STRING_VALUE_LARGE
00267 #define B_CONST_STRING_VALUE_40 B_CONST_STRING_VALUE_LARGE
00268 #define B_STATIC_STRING_VALUE_40 B_STATIC_STRING_VALUE_LARGE
00269 #define B_CONST_STRING_VALUE_44 B_CONST_STRING_VALUE_LARGE
00270 #define B_STATIC_STRING_VALUE_44 B_STATIC_STRING_VALUE_LARGE
00271 #define B_STATIC_STRING B_STATIC_STRING_VALUE_LARGE
00272 #define B_CONST_STRING B_CONST_STRING_VALUE_LARGE
00273
00274
00275
00276 #if _SUPPORTS_NAMESPACE
00277 } }
00278 #endif
00279
00280 #endif