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_PackTreeCell_H 00006 #define COM_M4NKIND_PackTreeCell_H 00007 00008 #include "BaseType.h" 00009 #include "PackULong.h" 00010 /*! 00011 \class PackTreeCell 00012 \ingroup BaseSerializableClass 00013 \brief base type managing a Tree database of any PackSerializable (or inherited) Objects. 00014 the object type managed is unique and defined at construction, by passing 00015 a function that do return a new object. 00016 00017 */ 00018 00019 class PackTreeCell : public BaseType 00020 { 00021 /*================================================================== 00022 PUBLIC 00023 ==================================================================*/ 00024 public: 00025 /*! 00026 \brief Constructor. 00027 \param _func a function that return a new object to manage as an element of the list. 00028 */ 00029 PackTreeCell( BaseTypeCreatorCallBackFunction _func); 00030 #ifdef _ENGINE_EDITABLE_ 00031 /*! 00032 \brief Destructor. 00033 */ 00034 virtual ~PackTreeCell(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. 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 "PackTreeCell"; }; 00067 #endif 00068 /*! 00069 \brief The Object this one belong to as a member. Should only be used at init. 00070 \param _pManager BaseObject 00071 */ 00072 virtual void SetObjectThatManagesThis(BaseObject *_pManager); 00073 00074 /*! 00075 \brief Add a new sub cell element, at the given index, to this Cell. 00076 \param _indexWhereToInsert the index where to insert. if -1, at the end. 00077 \return the element created. 00078 */ 00079 PackTreeCell * AddSubCellToThisCell( int _indexWhereToInsert=-1 ); 00080 /*! 00081 \brief Return a pointer on the BaseType managed by this cell: 00082 \return the object. should never be zero. 00083 */ 00084 inline BaseType * GetObject(){ return m_pObjectManaged; }; 00085 00086 /*! 00087 \brief get next brother cell in the hierarchy, or null if last of the brotherhood. 00088 It used to scan the tree. 00089 \return the cell element or 0L. 00090 */ 00091 inline PackTreeCell * GetNextBrotherCell(){ return m_pNextSerializedBrotherCell; }; 00092 /*! 00093 \brief get first subCell if there is any, or null if no subcell at all. 00094 It used to scan the tree. 00095 \return the cell element or 0L. 00096 */ 00097 inline PackTreeCell * GetFirstSubCell(){ return m_pFirstSerializedSubCell; }; 00098 00099 #ifdef _ENGINE_EDITABLE_ 00100 /*! 00101 \brief delete an element and its whole sub elements. the first to delete can be at any level. 00102 \param _pSubCellToDelete pointer to subcell. 00103 */ 00104 void DeleteSubCells( PackTreeCell *_pSubCellToDelete); 00105 #endif 00106 #ifdef _ENGINE_EDITABLE_ 00107 /*! 00108 \brief delete an element at a given index. It closes and destroys the object. 00109 \param _index index of the object to destroy. 00110 */ 00111 //old not validated void DeleteSubCell( unsigned int _index); 00112 #endif 00113 #ifdef _ENGINE_EDITABLE_ 00114 /*! 00115 \brief Edition tool: Exchange 2 cells in the tree. 00116 You can't exchange the root cell. if one of the 2 cells 00117 is the root, nothing happens. If method is thrown 00118 \param_pFirstSubCell 00119 \param _pSecondSubCell 00120 */ 00121 //TODO virtual void SwapElements( PackTreeCell *_pFirstSubCell,PackTreeCell *_pSecondSubCell ); 00122 #endif 00123 #ifdef _ENGINE_EDITABLE_ 00124 /*! 00125 \brief Edition tool: Insert a new element after _indexOfElementToClone, 00126 and clone it with the previous element shape. Note this 00127 can exclude some data members, like Object reference. 00128 \param _pSubCellToClone the cell element to clone. 00129 */ 00130 //TODO virtual void CloneElementAsBrother( PackTreeCell *_pSubCellToClone); 00131 #endif 00132 /*================================================================== 00133 PROTECTED 00134 ==================================================================*/ 00135 protected: 00136 //! a function pointer that return a new object of the type managed by the Tree. 00137 BaseTypeCreatorCallBackFunction m_CreatorFunction; 00138 00139 //! the object serialized by this cell: 00140 BaseType *m_pObjectManaged; 00141 00142 //! chunk length: 00143 PackULong mSerUlong_JumpToNextChunk; 00144 00145 //! member that manages the list of sub cell to serialize automatically. NULL if no subcellss. 00146 PackTreeCell *m_pFirstSerializedSubCell; 00147 00148 //! member that manages the list of cell to serialize automatically. NULL if no subcells. 00149 PackTreeCell *m_pNextSerializedBrotherCell; 00150 00151 //! another member that manages the list of members to serialize automatically, and allow to grow the list by the end. 00152 PackTreeCell **m_ppPointerToAttachNextSerializedSubCellAtEnd; 00153 00154 #ifdef _ENGINE_EDITABLE_ 00155 /*! 00156 \brief close and destroy the whole list. 00157 */ 00158 void DeleteAllSubCells( void ); 00159 #endif 00160 #ifdef _ENGINE_EDITABLE_ 00161 /*! 00162 \brief delete an element and its whole sub elements. the first to delete can be at any level. 00163 \param _pSubCellToDelete pointer to subcell. 00164 */ 00165 void DeleteSubCellsProtectedRecursive( PackTreeCell *_pSubCellToDelete); 00166 #endif 00167 }; 00168 00169 #endif
/\/\ 4 N k ! N D _______ _ __ ___ _____ ___ _ _ ____ ___________ __//___ /________ |/ / ___________\_______/ \ / _ _ \/ _ / _ / _/_/____/ _ __ / / / / / / / \ \/ / / \ \ / \\___/___/___/ ¯ _____/_____/ ______\___/_____/\________\\ \________/_ ___ __ l____\ /elD! http://www.m4nkind.com \____/