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_PackStruct_H 00006 #define COM_M4NKIND_PackStruct_H 00007 00008 #include "BaseType.h" 00009 #include "PackULong.h" 00010 /*! 00011 \class PackStruct 00012 \ingroup BaseSerializableClass 00013 \brief Base type managing a suit of any PackSerializable (or inherited) Objects, 00014 which types are differents but can't be changed. 00015 To use a PackStruct, register a list of PackSerializable objects in construction. 00016 This objects must be already allocated. PackStruct doesn't manage the existance 00017 of the listed objects. It just allows to re-serialize their values. 00018 This list must not vary in the life of the object, so that it can be 00019 serialized in and out again and again. 00020 For a dynamic List handling objects from the same class, look: PackList 00021 */ 00022 00023 class PackStruct : public BaseType 00024 { 00025 /*================================================================== 00026 PUBLIC 00027 ==================================================================*/ 00028 public: 00029 /*! 00030 \brief Constructor. 00031 */ 00032 PackStruct(); 00033 #ifdef _ENGINE_EDITABLE_ 00034 /*! 00035 \brief Destructor. 00036 */ 00037 virtual ~PackStruct(void); 00038 #endif 00039 /*! 00040 \class Cell 00041 \brief nested class to PackStruct , stands for an element cell in the list. 00042 */ 00043 class Cell 00044 { 00045 public: 00046 /*! 00047 \brief Constructor. 00048 */ 00049 Cell(): m_pNextCell(0L) 00050 ,m_pPreviousCell(0L) 00051 ,m_pObjectManaged(0L) {}; 00052 00053 /*! 00054 \brief get next cell in the list, NULL if last. 00055 \return the cell element or 0L. 00056 */ 00057 inline Cell * GetPreviousBrotherCell(){ return m_pPreviousCell; }; 00058 00059 /*! 00060 \brief get next cell in the list, NULL if last. 00061 \return the cell element or 0L. 00062 */ 00063 inline Cell * GetNextBrotherCell(){ return m_pNextCell; }; 00064 /*! 00065 \brief set object that this cell manage 00066 \param _ob the serializable object 00067 */ 00068 inline void SetManagedObject(BaseType *_ob){ m_pObjectManaged = _ob ; }; 00069 /*! 00070 \brief set object that this cell manage 00071 \return the object or NULL if none. 00072 */ 00073 inline BaseType *GetManagedObject(){ return m_pObjectManaged; }; 00074 #ifdef _ENGINE_EDITABLE_ 00075 /*! 00076 \brief Set Previous cell in the list. 00077 \param _pPrevCell the new cell element. 00078 */ 00079 inline void SetPreviousBrotherCell(Cell *_pPrevCell){ m_pPreviousCell = _pPrevCell; }; 00080 #endif 00081 /*! 00082 \brief Set next cell in the list. 00083 \param _pNewCell the new cell element. 00084 */ 00085 inline void SetNextBrotherCell(Cell *_pNewCell){ m_pNextCell = _pNewCell; }; 00086 00087 protected: 00088 //! previous cell 00089 Cell *m_pPreviousCell; 00090 //! next cell 00091 Cell *m_pNextCell; 00092 //! the object serialized by this cell: 00093 BaseType *m_pObjectManaged; 00094 }; 00095 /*! 00096 \brief Read the object description from a byte chunk. Could crash if chunk not valid. 00097 \param _pDescriptionChunk the objet description chunk. 00098 \return the end of the chunk written, possibly unlocated. Don't use this if you don't need it. 00099 */ 00100 virtual const unsigned char * Serialize_In( const unsigned char * _pDescriptionChunk); 00101 00102 #ifdef _ENGINE_EDITABLE_ 00103 /*! 00104 \brief get the size of the whole byte chunk that will be written by Serialize_Out(). 00105 \return byte size of the serialisation to do. 00106 */ 00107 virtual unsigned int GetSerializedDescriptionSize(void); 00108 #endif 00109 #ifdef _ENGINE_EDITABLE_ 00110 /*! 00111 \brief write the Current object definition to a Chunk using private packed types, recursively. 00112 \param _pDescriptionChunkToFill the chunk where to write the objet description chunk. 00113 \return the end of the chunk written, possibly unlocated. Don't use this if you don't need it. 00114 */ 00115 virtual unsigned char * Serialize_Out(unsigned char * _pDescriptionChunkToFill); 00116 #endif 00117 00118 /*! 00119 \brief The Object this one belong to as a member. Should only be used at init. 00120 \param _pManager BaseObject 00121 */ 00122 virtual void SetObjectThatManagesThis(BaseObject *_pManager); 00123 00124 #ifdef _ENGINE_EDITABLE_ 00125 /*! 00126 \brief Each BaseType's inherited classes must explicit an ID for their 00127 class, or let use one of the super class at least through this virtual method. 00128 This is needed by GUIs to detect the types of each sub-members, and shape 00129 an interface for each Object according to their member list. 00130 \return a const character string, that must be unique and unchanged for all serializable base type. 00131 */ 00132 virtual const char *GetClassID() const { return "PackStruct"; }; 00133 #endif 00134 #ifdef _ENGINE_EDITABLE_ 00135 /*! 00136 \brief convert the value of this object to an explicit string. The object manages the string privately, 00137 so just read it or copy it. the string would be destroyed with the objects, and changed when using Set() methods. 00138 Note: this is not virtual, but each class can manage m_pValueString or not. 00139 \return the value as a const string. 00140 */ 00141 virtual const char *ValueToString(); 00142 #endif 00143 /*! 00144 \brief Add a new element, at the given index. 00145 \param _indexWhereToInsert the index where to insert. if -1, at the end. 00146 \param _pObjectToAdd object to manage, or NULL to set it after on the returned cell. 00147 \return the element created. 00148 */ 00149 virtual Cell * AddElement( int _indexWhereToInsert=-1,BaseType *_pObjectToAdd=0L); 00150 00151 /*! 00152 \brief get an element at a given index. 00153 \param _index the index of the element 00154 \return the element at the index or NULL if failed. 00155 */ 00156 BaseType * Get( unsigned int _index); 00157 00158 #ifdef _ENGINE_EDITABLE_ 00159 /*! 00160 \brief delete an element at a given object of the cell to destroy. 00161 does not destroy the object. 00162 \param _index index of the object to destroy. 00163 */ 00164 virtual void DeleteElement( unsigned int _index); 00165 00166 #endif 00167 /*! 00168 \brief FirstCell or null if empty 00169 \return the cell 00170 */ 00171 inline Cell *GetFirstCell() const{ return(m_pFirstCell ); }; 00172 /*! 00173 \brief the Last Cell or null if empty 00174 \return the cell 00175 */ 00176 inline Cell *GetLastCell() const{ return(m_pLastCell ); }; 00177 /*! 00178 \brief return the number of cell. 00179 \return the number of cell. 00180 */ 00181 inline unsigned int GetNumberOfCell() const{ return(m_NumberOfCell ); }; 00182 #ifdef _ENGINE_EDITABLE_ 00183 /*! 00184 \brief close and destroy the whole list. 00185 */ 00186 void DeleteAllElements( void ); 00187 #endif 00188 /*================================================================== 00189 PROTECTED 00190 ==================================================================*/ 00191 protected: 00192 //! member that manages the list of members to serialize automatically. 00193 Cell *m_pFirstCell; 00194 //! another member that manages the list of members to serialize automatically, and allow to grow the list by the end. 00195 Cell *m_pLastCell; 00196 //! the number of cell. 00197 unsigned int m_NumberOfCell; 00198 /*! 00199 \brief Register any serializable object to serialize for read or write operation, 00200 Use it in objects constructors. 00201 The object are serialized in the file in the same order as they are given by this method. 00202 \param _object reference to the member, which must inherit from BaseType. 00203 */ 00204 void RegisterSerializableMember( BaseType &_object ); 00205 00206 00207 }; 00208 00209 #endif
/\/\ 4 N k ! N D _______ _ __ ___ _____ ___ _ _ ____ ___________ __//___ /________ |/ / ___________\_______/ \ / _ _ \/ _ / _ / _/_/____/ _ __ / / / / / / / \ \/ / / \ \ / \\___/___/___/ ¯ _____/_____/ ______\___/_____/\________\\ \________/_ ___ __ l____\ /elD! http://www.m4nkind.com \____/