Main Page   Packages   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

C:/temp/src/j2k/Fred/Serialize.hpp

Go to the documentation of this file.
00001 #ifndef __J2K__Serialize_HPP__
00002 #define __J2K__Serialize_HPP__
00003 
00004 ////////////////////////////////////////////////////////////////////////////
00005 /// Serialize Macro Part Version 2.0  ( Contain Class Info )             ///
00006 ////////////////////////////////////////////////////////////////////////////
00007 // ULONG is used to have a large possibility range
00008 // You could add more if you wish and get the proper OFFSET for them.
00009 // They must be PUBLIC members and with the Offset technique
00010 // it works fine with virtual functions and single/multi/diamond inheritance
00011 // Just make sure that you don't get out of User Memory space by reading
00012 // TOO FAR in memory, that's why the offset is set close to 0.
00013 // It's normally equal to 4 bytes.
00014 
00015     typedef  unsigned long   serial_t;
00016     typedef  unsigned long   hashCode_t;
00017 
00018     class JObject;
00019     class JString;
00020 
00021 ////////////////////////////////////////////////////////////////////////////
00022 // Make sure this is the first thing in your class.
00023 // The last line must be private,
00024 // since normally a class default is private,
00025 // if not mentionned.
00026 
00027 #define MC_SerializeHeader()                          \
00028     public:                                           \
00029       serial_t  SerializationID;                      \
00030       char*     ClassName;                            \
00031       char*     ClassAuthor;                          \
00032       char*     ClassVersion;                         \
00033       char*     ClassInherited;                       \
00034     private:                                          
00035 
00036 
00037 #define MC_printSerialInfo( CLASS )                   \
00038    if ( CLASS ## ClassName       != NULL )            \
00039      printf("The class %s",   CLASS ## ClassName   ); \
00040    if ( CLASS ## ClassAuthor     != NULL )            \
00041      printf("Build by %s.\n", CLASS ## ClassAuthor ); \
00042    if ( CLASS ## ClassVersion    != NULL )            \
00043     printf("The current version is %s.\n",  CLASS ## ClassVersion ); \
00044    if ( CLASS ## ClassInherited  != NULL )            \
00045     printf("List of Inherited components [%s].\n", CLASS ## ClassInherited );
00046 
00047 
00048 ////////////////////////////////////////////////////////////////////////////
00049 // Destroy char*, if you don't use strdup( ) don't use destructor !
00050 
00051 #define MC_SerializeDestructor()                                \
00052   if ( ClassName      != NULL ) {  delete [] ClassName;      }  \
00053   if ( ClassAuthor    != NULL ) {  delete [] ClassAuthor;    }  \
00054   if ( ClassVersion   != NULL ) {  delete [] ClassVersion;   }  \
00055   if ( ClassInherited != NULL ) {  delete [] ClassInherited; }  \
00056 
00057 
00058 ////////////////////////////////////////////////////////////////////////////
00059 // Serial: The Serial Number optimize macro for Constructor
00060 
00061 #define MC_SerializeConstructor( Serial, Name, Author, Version, Inherited ) \
00062     SerializationID( Serial ),     ClassName(    strdup( Name )    ),       \
00063     ClassAuthor( strdup(Author) ), ClassVersion( strdup( Version ) ),       \
00064     ClassInherited( strdup(Inherited) )                                     
00065 
00066 
00067 #define MC_SerializeInit( Name, Author, Version, Inherited ) \
00068     ClassName      = Name;      \
00069     ClassAuthor    = Author;    \
00070     ClassVersion   = Version;   \
00071     ClassInherited = Inherited; 
00072 
00073 
00074 // Get the offset for that Class
00075 #define MC_getSerialOffset( CLASS )  (size_t)&( ((CLASS *)0)->SerializationID )
00076 
00077 
00078 ////////////////////////////////////////////////////////////////////////////
00079 //  ptr:    The void* pointer
00080 //  OFFSET: The offset for the Serialization ID
00081 
00082 #define MC_getSerial( ptr, OFFSET )   (  *(serial_t*)((char*)ptr + OFFSET)  )
00083 
00084 #define MC_testSerial( ptr, OFFSET, Arg )  (  (MC_getSerial(ptr, OFFSET) & Arg) == Arg  )
00085 
00086 #define MC_SerializeTools( HASHCODE )                          \
00087     JString  getClass() const {                                \
00088        return JString( ClassName );                            \
00089     }                                                          \
00090                                                                \
00091     JString  toString() {                                      \
00092        char* buf = new char[128];                              \
00093        sprintf( buf, "%s@%.8x", ClassName, hashCode() );       \
00094        return JString( buf );                                  \
00095     }                                                          \
00096                                                                \
00097     hashCode_t hashCode() const {                              \
00098       return HASHCODE;                                         \
00099     }                                                          \
00100                                                                \
00101     void  notify() {                                           \
00102     }                                                          \
00103                                                                \
00104     void  notifyAll() {                                        \
00105     }                                                          \
00106                                                                \
00107     BOOL equals( const JObject& obj ) {                        \
00108       if ( isKindOf( obj ) == FALSE ) {                        \
00109         return FALSE;                                          \
00110       }                                                        \
00111       return ( hashCode() == obj.hashCode() );                 \
00112     }                                                          \
00113                                                                \
00114     BOOL isKindOf( const JObject& obj ) const {                \
00115        return ( !strcmp( ClassName, obj.ClassName ) );         \
00116     }                                                          \
00117                                                                \
00118     BOOL isDerivedFrom( const JObject& obj ) const {           \
00119        char* pDest = strstr( obj.ClassName, ClassInherited );  \
00120                                                                \
00121        long result = pDest - obj.ClassInherited + 1;           \
00122                                                                \
00123        return (result > 0);                                    \
00124     }                                                          \
00125                                                                \
00126     BOOL isRelatedTo( JObject& obj ) const {                   \
00127        return ( isKindOf( obj ) || isDerivedFrom( obj ) );     \
00128     }                                                          
00129 
00130 ////////////////////////////////////////////////////////////////////////////
00131 
00132 
00133 
00134 #endif

Generated on Sun Oct 14 18:46:32 2001 for Standard J2K Library by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001