00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef ISerializableImplHelperHPP
00033 #define ISerializableImplHelperHPP
00034
00036 #define SERIALOBJECT_HEADER 0xF5E4D3C2
00037
00038 #define SERIAL_INT32_ID 0x10
00039 #define SERIAL_FLOAT64_ID 0x11
00040 #define SERIAL_BOOL_ID 0x12
00041 #define SERIAL_INT8_ID 0x14
00042 #define SERIAL_INT16_ID 0x15
00043 #define SERIAL_INT64_ID 0x16
00044 #define SERIAL_FLOAT32_ID 0x17
00045 #define SERIAL_UINT8_ID 0x18
00046 #define SERIAL_UINT16_ID 0x19
00047 #define SERIAL_UINT32_ID 0x1A
00048 #define SERIAL_UINT64_ID 0x1B
00049 #define SERIAL_STRING_ID 0x20
00050 #define SERIAL_BYTEARRAY_ID 0x21
00051 #define SERIAL_OBJECT_ID 0x22
00052 #define SERIAL_XMLDOCUMENT_ID 0x23
00053 #define SERIAL_GUID_ID 0x24
00054
00055
00056 #define SERIAL_OBJECTLIST_ID 0x24
00057 #define SERIAL_FLOAT64LIST_ID 0x30
00058 #define SERIAL_STRINGLIST_ID 0x31
00059 #define SERIAL_GUIDLIST_ID 0x32
00060 #define SERIAL_UINT32LIST_ID 0x33
00061
00062
00063 #define SERIAL_STRING_STRINGMAP_ID 0x50
00064 #define SERIAL_OBJECT_GUIDMAP_ID 0x51
00065
00066
00067
00071
00072 #define OBJECTFACTORY_REGISTER_CLASS(classid) \
00073 classid::autoreg(true);
00074
00075
00078
00079 #define SERIAL_CREATE_OBJECT_INTERNAL(classid) \
00080 Retval MQUALIFIER classid::createObject(Uint uiObjectID, IInputStream* pStream, IZUnknown*& rpObj) \
00081 { \
00082 Retval retValue = RET_REQUEST_FAILED;\
00083 TAutoPtr<classid> ptrNewObject; \
00084 bool bError = false; \
00085 if (pStream != NULL)\
00086 { \
00087 try \
00088 { \
00089 ptrNewObject = new classid(uiObjectID, *pStream, bError);\
00090 } \
00091 catch(...) \
00092 { \
00093 bError = true;\
00094 } \
00095 } \
00096 else \
00097 { \
00098 ptrNewObject = new classid(); \
00099 } \
00100 \
00101 if (!bError && ptrNewObject != NULL && ptrNewObject->askForInterface(INTERFACE_ISerializable, rpObj) == RET_NOERROR) \
00102 { \
00103 retValue = RET_NOERROR;\
00104 } \
00105 else \
00106 { \
00107 retValue = RET_REQUEST_FAILED; \
00108 } \
00109 return retValue;\
00110 } \
00111
00112
00116
00117 #define SERIAL_CONSTRUCTOR_START(classid) \
00118 SERIAL_CREATE_OBJECT_INTERNAL(classid)\
00119 classid::classid(Uint uiObjectID, IInputStream& rStream, bool& rError)
00120
00121
00125
00126 #define INLINE_SERIAL_CONSTRUCTOR_START(classid) \
00127 inline SERIAL_CREATE_OBJECT_INTERNAL(classid)\
00128 inline classid::classid(Uint uiObjectID, IInputStream& rStream, bool& rError)
00129
00130
00131
00135
00136 #define SERIAL_CONSTRUCTOR_INIT rError = (doSerialize(uiObjectID, &rStream, this, NULL, NULL) != RET_NOERROR);
00137
00138
00142
00143 #define SERIAL_CONSTRUCTOR(classid) \
00144 SERIAL_CONSTRUCTOR_START(classid) \
00145 { \
00146 SERIAL_CONSTRUCTOR_INIT; \
00147 }
00148
00149
00153
00154 #define INLINE_SERIAL_CONSTRUCTOR(classid) \
00155 INLINE_SERIAL_CONSTRUCTOR_START(classid) \
00156 { \
00157 SERIAL_CONSTRUCTOR_INIT; \
00158 }
00159
00160
00167
00168 #define SERIAL_START_ABSTRACTCLASS(classid, classname) \
00169 public : \
00170 inline virtual Retval MQUALIFIER serialize(IByteArray& rStream) const \
00171 { \
00172 TByteArrayOutputStream* pStream = new TByteArrayOutputStream();\
00173 Retval retValue = doSerialize(0, NULL, NULL, pStream, this); \
00174 pStream->popData(rStream);\
00175 pStream->release();\
00176 return retValue; \
00177 } \
00178 \
00179 inline virtual Uint MQUALIFIER getObjectID() const \
00180 { return m_uiID; } \
00181 \
00182 \
00183 inline static Retval doSerialize(Uint obj_id_in, \
00184 IInputStream* stream_in, \
00185 classid* obj_new, \
00186 IOutputStream* stream_out, \
00187 const classid* obj_old, \
00188 bool bWriteHeaderInfo = true) \
00189 { \
00190 Retval retValue = RET_REQUEST_FAILED; \
00191 Int32 lMode = 0; \
00192 if (stream_in != NULL && obj_new != NULL) \
00193 { \
00194 lMode = 1; \
00195 obj_new->m_uiID = obj_id_in; \
00196 } \
00197 else if (stream_out != NULL && obj_old != NULL) \
00198 { \
00199 lMode = 2; \
00200 if (bWriteHeaderInfo) \
00201 { \
00202 stream_out->writeInt32(SERIALOBJECT_HEADER);\
00203 stream_out->writeInt32(obj_old->m_uiID);\
00204 TString strClassName(classname);\
00205 stream_out->writeString(strClassName);\
00206 } \
00207 } \
00208 \
00209 if (lMode > 0) \
00210 { \
00211 retValue = RET_NOERROR;
00212
00213
00218
00219 #define SERIAL_START(classid, classname) \
00220 public : \
00221 classid(Uint uiObjectID, IInputStream& rStream, bool& rError);\
00222 static Retval MQUALIFIER createObject(Uint uiObjectID, IInputStream* pStream, IZUnknown*& rpObj); \
00223 \
00224 inline static void autoreg(bool bReg)\
00225 { \
00226 static Uint classid##Handle = 0;\
00227 TString strClassName(classname); \
00228 if (bReg) \
00229 { \
00230 classid##Handle = ZObjectFactory.registerClass(strClassName, createObject); \
00231 } \
00232 else \
00233 { \
00234 ZObjectFactory.unregisterClass(strClassName, classid##Handle); \
00235 } \
00236 } \
00237 SERIAL_START_ABSTRACTCLASS(classid, classname)
00238
00239
00243
00244 #define SERIAL_PARENTCLASS(classid) \
00245 if (retValue == RET_NOERROR) \
00246 { \
00247 retValue = classid::doSerialize(obj_id_in, stream_in, obj_new, stream_out, obj_old, false); \
00248 }
00249
00250
00258
00259 #define SERIAL_NUMERIC_CONV(attrib, att_type, conv_type, serialmethod, default_val) \
00260 if (retValue == RET_NOERROR) \
00261 { \
00262 if (lMode == 2) \
00263 { \
00264 TSerializer::serialmethod(*stream_out, static_cast<conv_type>(obj_old->attrib)); \
00265 } \
00266 else \
00267 { \
00268 conv_type vValue = default_val;\
00269 retValue = TSerializer::de ## serialmethod(*stream_in, vValue); \
00270 obj_new->attrib = static_cast<att_type>(vValue);\
00271 } \
00272 }
00273
00274
00281
00282 #define SERIAL_NUMERIC(attrib, att_type, serialmethod, default_val) SERIAL_NUMERIC_CONV(attrib, att_type, att_type, serialmethod, default_val)
00283
00284
00292
00293 #define SERIAL_NUMERIC_GET_SET(getmethod, setmethod, att_type, serialmethod, default_val) \
00294 if (retValue == RET_NOERROR) \
00295 { \
00296 if (lMode == 2) \
00297 { \
00298 att_type vValue = static_cast<att_type>(obj_old->getmethod()); \
00299 TSerializer::serialmethod(*stream_out, vValue); \
00300 } \
00301 else \
00302 { \
00303 att_type vValue = default_val;\
00304 retValue = TSerializer::de ## serialmethod(*stream_in, vValue); \
00305 obj_new->setmethod(vValue);\
00306 } \
00307 }
00308
00309
00314
00315 #define SERIAL_OBJECTREF(attrib, serialmethod) \
00316 if (retValue == RET_NOERROR) \
00317 { \
00318 if (lMode == 2) \
00319 { \
00320 TSerializer::serialmethod(*stream_out, obj_old->attrib); \
00321 } \
00322 else \
00323 { \
00324 retValue = TSerializer::de ## serialmethod(*stream_in, obj_new->attrib); \
00325 } \
00326 }
00327
00328
00335
00336 #define SERIAL_OBJECTREF_GET_SET(getmethod, setmethod, att_type, serialmethod) \
00337 if (retValue == RET_NOERROR) \
00338 { \
00339 if (lMode == 2) \
00340 { \
00341 att_type vValue = obj_old->getmethod(); \
00342 TSerializer::serialmethod(*stream_out, vValue); \
00343 } \
00344 else \
00345 { \
00346 att_type vValue; \
00347 retValue = TSerializer::de ## serialmethod(*stream_in, vValue); \
00348 obj_new->setmethod(vValue); \
00349 } \
00350 }
00351
00352
00358
00359 #define SERIAL_OBJECTPTR(attrib, serialmethod) \
00360 if (retValue == RET_NOERROR) \
00361 { \
00362 if (lMode == 2) \
00363 { \
00364 TSerializer::serialmethod(*stream_out, obj_old->attrib); \
00365 } \
00366 else \
00367 { \
00368 retValue = TSerializer::de ## serialmethod(*stream_in, obj_new->attrib); \
00369 if (retValue == RET_REQUEST_FAILED) \
00370 { \
00371 obj_new->attrib = NULL; \
00372 retValue = RET_NOERROR; \
00373 } \
00374 } \
00375 }
00376
00377
00378 #define SERIAL_BOOL(attrib) SERIAL_NUMERIC(attrib, bool, serializeBool, false)
00379 #define SERIAL_INT8(attrib) SERIAL_NUMERIC(attrib, Int8, serializeInt8, 0)
00380 #define SERIAL_INT16(attrib) SERIAL_NUMERIC(attrib, Int16, serializeInt16, 0)
00381 #define SERIAL_INT32(attrib) SERIAL_NUMERIC(attrib, Int32, serializeInt32, 0)
00382 #define SERIAL_INT64(attrib) SERIAL_NUMERIC(attrib, Int64, serializeInt64, 0)
00383 #define SERIAL_UINT8(attrib) SERIAL_NUMERIC(attrib, Uint8, serializeUint8, 0)
00384 #define SERIAL_UINT16(attrib) SERIAL_NUMERIC(attrib, Uint16, serializeUint16, 0)
00385 #define SERIAL_UINT32(attrib) SERIAL_NUMERIC(attrib, Uint32, serializeUint32, 0)
00386 #define SERIAL_UINT64(attrib) SERIAL_NUMERIC(attrib, Uint64, serializeUint64, 0)
00387 #define SERIAL_FLOAT32(attrib) SERIAL_NUMERIC(attrib, Float32, serializeFloat32, 0.0f)
00388 #define SERIAL_FLOAT64(attrib) SERIAL_NUMERIC(attrib, Float64, serializeFloat64, 0.0)
00389 #define SERIAL_ENUM(attrib, att_type) SERIAL_NUMERIC_CONV(attrib, att_type, Int32, serializeInt32, 0)
00390 #define SERIAL_STRING(attrib) SERIAL_OBJECTREF(attrib, serializeString)
00391 #define SERIAL_BYTEARRAY(attrib) SERIAL_OBJECTREF(attrib, serializeByteArray)
00392 #define SERIAL_XMLDOCUMENT(attrib) SERIAL_OBJECTPTR(attrib, serializeXMLDocument)
00393 #define SERIAL_GUID(attrib) SERIAL_OBJECTREF(attrib, serializeGUID)
00394
00395 #define SERIAL_BOOLLIST(attrib) SERIAL_OBJECTREF(attrib, serializeBoolList)
00396 #define SERIAL_INT8LIST(attrib) SERIAL_OBJECTREF(attrib, serializeInt8List)
00397 #define SERIAL_INT16LIST(attrib) SERIAL_OBJECTREF(attrib, serializeInt16List)
00398 #define SERIAL_INT32LIST(attrib) SERIAL_OBJECTREF(attrib, serializeInt32List)
00399 #define SERIAL_INT64LIST(attrib) SERIAL_OBJECTREF(attrib, serializeInt64List)
00400 #define SERIAL_UINT8LIST(attrib) SERIAL_OBJECTREF(attrib, serializeUint8List)
00401 #define SERIAL_UINT16LIST(attrib) SERIAL_OBJECTREF(attrib, serializeUint16List)
00402 #define SERIAL_UINT32LIST(attrib) SERIAL_OBJECTREF(attrib, serializeUint32List)
00403 #define SERIAL_UINT64LIST(attrib) SERIAL_OBJECTREF(attrib, serializeUint64List)
00404 #define SERIAL_FLOAT32LIST(attrib) SERIAL_OBJECTREF(attrib, serializeFloat32List)
00405 #define SERIAL_FLOAT64LIST(attrib) SERIAL_OBJECTREF(attrib, serializeFloat64List)
00406 #define SERIAL_STRINGLIST(attrib) SERIAL_OBJECTREF(attrib, serializeStringList)
00407 #define SERIAL_GUIDLIST(attrib) SERIAL_OBJECTREF(attrib, serializeGUIDList)
00408
00409 #define SERIAL_BOOL_STRINGMAP(attrib) SERIAL_OBJECTREF(attrib, serializeBoolStringMap)
00410 #define SERIAL_INT8_STRINGMAP(attrib) SERIAL_OBJECTREF(attrib, serializeInt8StringMap)
00411 #define SERIAL_INT16_STRINGMAP(attrib) SERIAL_OBJECTREF(attrib, serializeInt16StringMap)
00412 #define SERIAL_INT32_STRINGMAP(attrib) SERIAL_OBJECTREF(attrib, serializeInt32StringMap)
00413 #define SERIAL_INT64_STRINGMAP(attrib) SERIAL_OBJECTREF(attrib, serializeInt64StringMap)
00414 #define SERIAL_UINT8_STRINGMAP(attrib) SERIAL_OBJECTREF(attrib, serializeUint8StringMap)
00415 #define SERIAL_UINT16_STRINGMAP(attrib) SERIAL_OBJECTREF(attrib, serializeUint16StringMap)
00416 #define SERIAL_UINT32_STRINGMAP(attrib) SERIAL_OBJECTREF(attrib, serializeUint32StringMap)
00417 #define SERIAL_UINT64_STRINGMAP(attrib) SERIAL_OBJECTREF(attrib, serializeUint64StringMap)
00418 #define SERIAL_FLOAT32_STRINGMAP(attrib) SERIAL_OBJECTREF(attrib, serializeFloat32StringMap)
00419 #define SERIAL_FLOAT64_STRINGMAP(attrib) SERIAL_OBJECTREF(attrib, serializeFloat64StringMap)
00420 #define SERIAL_STRING_STRINGMAP(attrib) SERIAL_OBJECTREF(attrib, serializeStringStringMap)
00421
00422
00423 #define SERIAL_BOOL_GET_SET(getmethod, setmethod) SERIAL_NUMERIC_GET_SET(getmethod, setmethod, bool, serializeBool, false)
00424 #define SERIAL_INT8_GET_SET(getmethod, setmethod) SERIAL_NUMERIC_GET_SET(getmethod, setmethod, Int8, serializeInt8, 0)
00425 #define SERIAL_INT16_GET_SET(getmethod, setmethod) SERIAL_NUMERIC_GET_SET(getmethod, setmethod, Int16, serializeInt16, 0)
00426 #define SERIAL_INT32_GET_SET(getmethod, setmethod) SERIAL_NUMERIC_GET_SET(getmethod, setmethod, Int32, serializeInt32, 0)
00427 #define SERIAL_INT64_GET_SET(getmethod, setmethod) SERIAL_NUMERIC_GET_SET(getmethod, setmethod, Int64, serializeInt64, 0)
00428 #define SERIAL_UINT8_GET_SET(getmethod, setmethod) SERIAL_NUMERIC_GET_SET(getmethod, setmethod, Uint8, serializeUint8, 0)
00429 #define SERIAL_UINT16_GET_SET(getmethod, setmethod) SERIAL_NUMERIC_GET_SET(getmethod, setmethod, Uint16, serializeUint16, 0)
00430 #define SERIAL_UINT32_GET_SET(getmethod, setmethod) SERIAL_NUMERIC_GET_SET(getmethod, setmethod, Uint32, serializeUint32, 0)
00431 #define SERIAL_UINT64_GET_SET(getmethod, setmethod) SERIAL_NUMERIC_GET_SET(getmethod, setmethod, Uint64, serializeUint64, 0)
00432 #define SERIAL_FLOAT32_GET_SET(getmethod, setmethod) SERIAL_NUMERIC_GET_SET(getmethod, setmethod, Float32, serializeFloat32, 0.0f)
00433 #define SERIAL_FLOAT64_GET_SET(getmethod, setmethod) SERIAL_NUMERIC_GET_SET(getmethod, setmethod, Float64, serializeFloat64, 0.0)
00434 #define SERIAL_STRING_GET_SET(getmethod, setmethod) SERIAL_OBJECTREF_GET_SET(getmethod, setmethod, TString, serializeString)
00435 #define SERIAL_BYTEARRAY_GET_SET(getmethod, setmethod) SERIAL_OBJECTREF_GET_SET(getmethod, setmethod, TByteArray, serializeByteArray)
00436
00437
00438
00442
00443 #define SERIAL_BYTEARRAY_PTR(attrib) \
00444 if (retValue == RET_NOERROR) \
00445 { \
00446 if (obj_old->attrib != NULL)\
00447 { \
00448 if (lMode == 2) \
00449 { \
00450 TSerializer::serializeByteArray(*stream_out, *obj_old->attrib); \
00451 } \
00452 else \
00453 { \
00454 retValue = TSerializer::deserializeByteArray(*stream_in, *obj_new->attrib); \
00455 } \
00456 } \
00457 else \
00458 { \
00459 retValue = RET_REQUEST_FAILED; \
00460 } \
00461 }
00462
00463
00464
00470
00471 #define SERIAL_OBJECT(interface_id, attrib) \
00472 if (retValue == RET_NOERROR) \
00473 { \
00474 if (lMode == 2) \
00475 { \
00476 TSerializer::serializeObject(*stream_out, obj_old->attrib); \
00477 } \
00478 else \
00479 { \
00480 retValue = TSerializer::deserializeObject(*stream_in, interface_id, ICAST(obj_new->attrib)); \
00481 if (retValue != RET_NOERROR) \
00482 { \
00483 obj_new->attrib = NULL; \
00484 retValue = RET_NOERROR;\
00485 } \
00486 } \
00487 } \
00488 else \
00489 { \
00490 if (lMode == 1)\
00491 { \
00492 obj_new->attrib = NULL; \
00493 } \
00494 } \
00495
00496
00502
00503 #define SERIAL_OBJECTLIST(interface_id, subclass, attrib) \
00504 if (retValue == RET_NOERROR) \
00505 { \
00506 if (lMode == 2) \
00507 { \
00508 TSerializer::serializeCollectionCount(*stream_out, SERIAL_OBJECTLIST_ID, (obj_old->attrib).getCount()); \
00509 const IListIterator<subclass*>* pIt = (obj_old->attrib).getConstIterator(); \
00510 while(pIt->hasNextItem()) \
00511 { \
00512 TSerializer::serializeObjectFromCollection(*stream_out, pIt->getNextItemConst()); \
00513 } \
00514 (obj_old->attrib).releaseIterator(pIt); \
00515 } \
00516 else \
00517 { \
00518 Int iCount = 0; \
00519 retValue = TSerializer::deserializeCollectionCount(*stream_in, SERIAL_OBJECTLIST_ID, iCount); \
00520 if (retValue == RET_NOERROR) \
00521 { \
00522 for(Int i = 0; i < iCount; i++) \
00523 { \
00524 subclass* pObject = NULL;\
00525 if (TSerializer::deserializeObjectFromCollection(*stream_in, interface_id, ICAST(pObject)) == RET_NOERROR)\
00526 { \
00527 obj_new->attrib.add((subclass*)pObject);\
00528 } \
00529 else \
00530 { \
00531 obj_new->attrib.add(NULL); \
00532 } \
00533 } \
00534 } \
00535 } \
00536 }
00537
00538
00544
00545 #define SERIAL_OBJECT_GUIDMAP(interface_id, subclass, attrib) \
00546 if (retValue == RET_NOERROR) \
00547 { \
00548 if (lMode == 2) \
00549 { \
00550 TSerializer::serializeCollectionCount(*stream_out, SERIAL_OBJECT_GUIDMAP_ID, (obj_old->attrib).getCount()); \
00551 const IMapIterator<TypGUID, subclass*>* pIt = (obj_old->attrib).getConstIterator(); \
00552 while(pIt->hasNextItem()) \
00553 { \
00554 TypGUID Key;\
00555 subclass* pItem = pIt->getNextItemWithKeyConst(Key); \
00556 TSerializer::serializeGUIDFromCollection(*stream_out, Key); \
00557 TSerializer::serializeObjectFromCollection(*stream_out, pItem); \
00558 } \
00559 (obj_old->attrib).releaseIterator(pIt); \
00560 } \
00561 else \
00562 { \
00563 Int iCount = 0; \
00564 retValue = TSerializer::deserializeCollectionCount(*stream_in, SERIAL_OBJECT_GUIDMAP_ID, iCount); \
00565 if (retValue == RET_NOERROR) \
00566 { \
00567 for(Int i = 0; i < iCount; i++) \
00568 { \
00569 TypGUID Key;\
00570 subclass* pObject = NULL;\
00571 Retval retKey = TSerializer::deserializeGUIDFromCollection(*stream_in, Key); \
00572 Retval retObj = TSerializer::deserializeObjectFromCollection(*stream_in, interface_id, ICAST(pObject));\
00573 if (retKey == RET_NOERROR && retObj == RET_NOERROR && !obj_new->attrib.hasItem(Key))\
00574 { \
00575 obj_new->attrib.setItem(Key, (subclass*)pObject);\
00576 } \
00577 } \
00578 } \
00579 } \
00580 }
00581
00582
00583
00584
00587
00588 #define SERIAL_CUSTOM_START \
00589 if (retValue == RET_NOERROR) \
00590 { \
00591
00592
00595
00596 #define SERIAL_CUSTOM_END \
00597 }
00598
00599
00602
00603 #define SERIAL_END \
00604 } \
00605 return retValue; \
00606 }
00607
00608 #endif