00001 /*! \file 00002 \author victorien ferry & www.m4nkind.com 00003 \brief This file applies the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1 , read file COPYING. 00004 */ 00005 #ifndef COM_M4NKIND_PackString_H 00006 #define COM_M4NKIND_PackString_H 00007 00008 #include "BaseType.h" 00009 00010 /*! 00011 \class PackString 00012 \ingroup BaseSerializableClass 00013 \brief Base type managing a zero-ended ascii string. 00014 It is used for the automated serialization. 00015 00016 */ 00017 00018 class PackString : public BaseType 00019 { 00020 /*================================================================== 00021 PUBLIC 00022 ==================================================================*/ 00023 public: 00024 #ifdef _ENGINE_EDITABLE_ 00025 /*! 00026 \brief Constructor. 00027 */ 00028 PackString(void); 00029 #endif 00030 #ifdef _ENGINE_EDITABLE_ 00031 /*! 00032 \brief Destructor. 00033 */ 00034 virtual ~PackString(void); 00035 #endif 00036 /*! 00037 \brief Read the object description from a byte chunk. Could crash if chunk not valid. 00038 \param _pDescriptionChunk the objet description chunk. 00039 \return the end of the chunk written, possibly unlocated. Don't use this if you don't need it. 00040 */ 00041 virtual const unsigned char * Serialize_In( const unsigned char * _pDescriptionChunk); 00042 00043 #ifdef _ENGINE_EDITABLE_ 00044 /*! 00045 \brief get the size of the whole byte chunk that will be written by Serialize_Out(). 00046 \return byte size of the serialisation to do.(1,2,3, or4) 00047 */ 00048 virtual unsigned int GetSerializedDescriptionSize(void); 00049 #endif 00050 #ifdef _ENGINE_EDITABLE_ 00051 /*! 00052 \brief write the Current object definition to a Chunk using private packed types, recursively. 00053 \param _pDescriptionChunkToFill the chunk where to write the objet description chunk. 00054 \return the end of the chunk written, possibly unlocated. Don't use this if you don't need it. 00055 */ 00056 virtual unsigned char * Serialize_Out(unsigned char * _pDescriptionChunkToFill); 00057 #endif 00058 #ifdef _ENGINE_EDITABLE_ 00059 /*! 00060 \brief Each BaseType's inherited classes must explicit an ID for their 00061 class, or let use one of the super class at least through this virtual method. 00062 This is needed by GUIs to detect the types of each sub-members, and shape 00063 an interface for each Object according to their member list. 00064 \return a const character string, that must be unique and unchanged for all serializable base type. 00065 */ 00066 virtual const char *GetClassID() const { return "PackString"; }; 00067 #endif 00068 #ifdef _ENGINE_EDITABLE_ 00069 /*! 00070 \brief convert the value of this object to an explicit string. The object manages the string privately, 00071 so just read it or copy it. the string would be destroyed with the objects, and changed when using Set() methods. 00072 Note: this is not virtual, but each class can manage m_pValueString or not. 00073 \return the value as a const string. 00074 */ 00075 virtual const char *ValueToString(); 00076 #endif 00077 #ifdef _ENGINE_EDITABLE_ 00078 /*! 00079 \brief add a int value at the end of the current chain. 00080 \param _value the integer value. 00081 */ 00082 void AddInt( int _value); 00083 #endif 00084 #ifdef _ENGINE_EDITABLE_ 00085 /*! 00086 \brief apend a character string.. 00087 \param _pstr 00088 */ 00089 void AddString( const char * _pstr); 00090 #endif 00091 #ifdef _ENGINE_EDITABLE_ 00092 /*! 00093 \brief set the string value. It reallocates memory. 00094 as it is used by serialisation, it returns a pointer on the read memory AFTER the zero for convenience. 00095 This "set" is exceptionnaly compiled in non-editable mode, because 00096 it is used by serialization. 00097 \param _pCharacterString the string to copy. 00098 \return a pointer after read memory. 00099 */ 00100 virtual void Set( const char * _pCharacterString ); 00101 #endif 00102 /*! 00103 \brief set the string value. 00104 */ 00105 inline const char * Get() const {return( (char * ) m_StringBuffer );}; 00106 00107 /*! 00108 \brief compare a string. looks like strcmp(). 00109 \param _pStringToCompare the string to compare to the value 00110 \param _pOtherStringToCompare the other string 00111 \return 0 if the same. case sensitive test. 00112 */ 00113 static int Compare( const char * _pStringToCompare, const char * _pOtherStringToCompare ); 00114 /*! 00115 \brief like strlen() 00116 \return length, not including the last zero. 00117 */ 00118 inline unsigned int length(){ return length(Get())-1; }; 00119 00120 /*================================================================== 00121 PROTECTED 00122 ==================================================================*/ 00123 protected: 00124 //! the string buffer. 00125 char *m_StringBuffer; 00126 00127 #ifdef _ENGINE_EDITABLE_ 00128 //! the re-allocation constant. 00129 static const unsigned int m_GrowByteLength=64; 00130 //! the current m_StringBuffer used buffer. as it is zero ended, m_StringBuffer[m_UsedByteLength-1]==0 00131 unsigned int m_UsedByteLength; 00132 //! current m_StringBuffer total allocation. is multiple of m_GrowByteLength. 00133 unsigned int m_TotalByteLength; 00134 #endif 00135 00136 #ifdef _ENGINE_EDITABLE_ 00137 /*! 00138 \brief delete if was allocated. 00139 */ 00140 virtual void Free(); 00141 #endif 00142 00143 /*! 00144 \brief private tool. like strlen(), but with +1 for the zero end. 00145 \param _pString string. 00146 \return length+1 for the zero at the end. 00147 */ 00148 static unsigned int length( const char *_pString); 00149 /*! 00150 \brief private tool. like strcpy(), but with +1 for the zero end. 00151 as it is used by serialisation, it returns a pointer on the read memory AFTER the zero for convenience. 00152 \param _pStringToFill destination. 00153 \param _pSourceString source. 00154 \return a pointer after read memory 00155 */ 00156 static const char * strcopy( char *_pStringToFill, const char *_pSourceString); 00157 }; 00158 00159 /*! 00160 \def REGISTER_MEMBER_PACKSTRING 00161 00162 \brief This macro is used to register a serializable member in a class constructor. 00163 For editable mode, it uses _MemberName to explicit the use of the member, in order 00164 to display it in a GUI for example. 00165 00166 */ 00167 #ifdef _ENGINE_EDITABLE_ 00168 #define REGISTER_MEMBER_PACKSTRING(_object,_MemberName,_default) \ 00169 RegisterSerializableMember(_object);\ 00170 _object.SetMemberName( _MemberName );\ 00171 _object.Set( _default ); 00172 #else 00173 #define REGISTER_MEMBER_PACKSTRING(_object,_MemberName,_default) \ 00174 RegisterSerializableMember(_object); 00175 #endif 00176 00177 //end of file: 00178 #endif
/\/\ 4 N k ! N D _______ _ __ ___ _____ ___ _ _ ____ ___________ __//___ /________ |/ / ___________\_______/ \ / _ _ \/ _ / _ / _/_/____/ _ __ / / / / / / / \ \/ / / \ \ / \\___/___/___/ ¯ _____/_____/ ______\___/_____/\________\\ \________/_ ___ __ l____\ /elD! http://www.m4nkind.com \____/