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_BaseType_H 00006 #define COM_M4NKIND_BaseType_H 00007 /*! 00008 \addtogroup BaseSerializableClass Base Type Serializable Classes 00009 \brief Here are links to the low level types Classes provided by the base library. 00010 They each manage accessors, serialization, and events. 00011 They can be used alone, or as members of a BaseObject class. 00012 They all inherit from class BaseType. 00013 */ 00014 class BaseObject; 00015 class BaseContext; 00016 class PackString; 00017 /*! 00018 \class BaseType 00019 00020 \brief Virtual class for all \mainprojectname serializable types. 00021 It is the root of all serializable classes, and actually all classes in \mainprojectname Inherit from it. 00022 00023 All inherited objects will be able to read their values with Serialize_In(), and write 00024 it to a first call to GetSerializedDescriptionSize(), which return the size of the data to write, 00025 and then Serialize_Out() that writes it. 00026 In editable mode, each objects has direct access to ReadFile() and WriteFile() which uses the serialization. 00027 00028 \mainprojectname Also provide a more complex Context management, through classes BaseContext and BaseObject : 00029 a BaseContext object manages a set of BaseObject. Simple BaseType are then used 00030 as class members of BaseObjects. That's why this class is also able to tell if it is a baseObject member 00031 with GetObjectThatManagesThis() , and implements methods for BaseContext edition notification. 00032 00033 */ 00034 class BaseType; 00035 //! BaseTypeCreatorCallBackFunction stands for a pointer to a static method that make a new BaseType. It is used by PackStruct 00036 typedef BaseType *(*BaseTypeCreatorCallBackFunction)(void); 00037 00038 class BaseType 00039 { 00040 /*================================================================== 00041 PUBLIC 00042 ==================================================================*/ 00043 public: 00044 /*! 00045 \brief Constructor. 00046 */ 00047 BaseType(void); 00048 00049 #ifdef _ENGINE_EDITABLE_ 00050 /*! 00051 \brief Destructor. 00052 */ 00053 virtual ~BaseType(void); 00054 #endif 00055 /*! 00056 \brief Read the object description from a byte chunk. Could crash if chunk not valid. 00057 \param _pDescriptionChunk the objet description chunk. 00058 \return the end of the chunk written, possibly unlocated. Don't use this if you don't need it. 00059 */ 00060 virtual const unsigned char * Serialize_In( const unsigned char * _pDescriptionChunk)=0; 00061 00062 #ifdef _ENGINE_EDITABLE_ 00063 /*! 00064 \brief get the size of the whole byte chunk that will be written by Serialize_Out(). 00065 \return byte size of the serialisation to do. 00066 */ 00067 virtual unsigned int GetSerializedDescriptionSize(void)=0; 00068 #endif 00069 #ifdef _ENGINE_EDITABLE_ 00070 /*! 00071 \brief write the Current object definition to a Chunk using private packed types, recursively. 00072 \param _pDescriptionChunkToFill the chunk where to write the objet description chunk. 00073 \return the end of the chunk written, possibly unlocated. Don't use this if you don't need it. 00074 */ 00075 virtual unsigned char * Serialize_Out(unsigned char * _pDescriptionChunkToFill)=0; 00076 #endif 00077 #ifdef _ENGINE_EDITABLE_ 00078 /*! 00079 \brief write a serialized form, using GetSerializedDescriptionSize() and Serialize_Out(). 00080 \param _pFileName the file path. 00081 \return 0 if OK. 00082 */ 00083 virtual unsigned int WriteFile(const char * _pFileName); 00084 #endif 00085 #ifdef _ENGINE_EDITABLE_ 00086 /*! 00087 \brief Try to read a serialized form, using Serialize_In(). 00088 \param _pFileName the file path. 00089 \return 0 if OK. 00090 */ 00091 virtual unsigned int ReadFile(const char * _pFileName); 00092 #endif 00093 00094 /*! 00095 \brief The Object this one belong to as a member. Should only be used at init. 00096 \param _pManager BaseObject 00097 */ 00098 virtual void SetObjectThatManagesThis(BaseObject *_pManager); 00099 00100 #ifdef _ENGINE_EDITABLE_ 00101 /*! 00102 \brief Explicits the name of an object when used as a class member. It exists only in editable mode, 00103 and then can be used by any GUI. A member with an 00104 infoString not NULL, should be drawn in a GUI and receive updates. 00105 an object member with GetMemberName() returning NULL should not be edited by an interface 00106 or undo-managed. 00107 Use REGISTER_MEMBER macros family: it registers the members and 00108 use SetMemberName() automatically (or not, according to the compilation mode). 00109 \param _MemberName the member name 00110 */ 00111 void SetMemberName(const char * _MemberName); 00112 #endif 00113 #ifdef _ENGINE_EDITABLE_ 00114 /*! 00115 \brief Explicits the name of an object when used as a class member. 00116 It exists only in editable mode, 00117 and then can be used by any GUI. A member with an 00118 infoString not NULL, should be drawn in a GUI and receive updates. 00119 an object member with GetMemberName() to NULL should not be edited by an interface 00120 or undo-managed. set with SetMemberName(). 00121 \return the member name or NULL 00122 */ 00123 inline const char * GetMemberName() const{ return m_pMemberName; }; 00124 #endif 00125 #ifdef _ENGINE_EDITABLE_ 00126 /*! 00127 \brief Explicits the use of an object when used as a class member. 00128 It should explain what the member does for the object. 00129 It exists only in editable mode,and can be used by any GUI. 00130 Don't use html tags , only \\n are allowed. 00131 Use REGISTER_MEMBER_INFO macro after the REGISTER_MEMBER macro 00132 in the constructors. It can be left NULL. 00133 \param _MemberName a short string explaining what's the object for. 00134 */ 00135 void SetMemberInfo(const char * _MemberInfo); 00136 #endif 00137 #ifdef _ENGINE_EDITABLE_ 00138 /*! 00139 \brief Explicits the use of an object when used as a class member. 00140 It exists only in editable mode and can be used by any GUI. 00141 It should explain what the member does for the object. 00142 \return a short string explaining what's the object for, or NULL if not set. 00143 */ 00144 inline const char * GetMemberInfo() const{ return m_pMemberInfo; }; 00145 #endif 00146 00147 #ifdef _ENGINE_EDITABLE_ 00148 /*! 00149 \brief Each BaseType's inherited classes must explicit an ID for their 00150 class, or let use one of the super class at least through this virtual method. 00151 This is needed by GUIs to detect the types of each sub-members, and shape 00152 an interface for each Object according to their member list. 00153 \return a const character string, that must be unique and unchanged for all serializable base type. 00154 */ 00155 virtual const char *GetClassID() const =0; 00156 #endif 00157 #ifdef _ENGINE_EDITABLE_ 00158 /*! 00159 \brief convert the value of this object to an explicit string. The object manages the string privately, 00160 so just read it or copy it. the string would be destroyed with the objects, and changed when using Set() methods. 00161 \return the value as a const string. 00162 */ 00163 virtual const char *ValueToString(); 00164 #endif 00165 00166 /*! 00167 \brief If there is any, get the object that manages this one as a member. 00168 \return the object that manages this one as a member, or NULL 00169 */ 00170 inline BaseObject *GetObjectThatManagesThis(){ return m_pObjectThatManagesThis; }; 00171 00172 #ifdef _ENGINE_EDITABLE_ 00173 /*! 00174 \brief Tool that makes an object take the values of another using serialization. 00175 <b>Use with care:</b> 00176 You got to clone a PackUlong with a PackULong, a PackString with a PackString: 00177 Clone Object of the same type or it will crash . 00178 A test is done at the beginning to check that for both types are the sames, 00179 if not it does nothing. however it may still crash with 2 objects from unherited 00180 classes. 00181 Also, some type like PackObjectReference, will not clone its value 00182 by copying a pointer.Reference member clonage is done with BaseObject::Clone() 00183 \param _ModelObject the object took as a model. 00184 */ 00185 void MakeCloneOf( BaseType &_ModelObject ); 00186 #endif 00187 #ifdef _ENGINE_EDITABLE_ 00188 /*! 00189 \typedef eVedaUpdate 00190 \brief enum used by BaseContext::NotifyObjectChange() to 00191 describe the notification meaning. Used by interfaces 00192 to monitor a context. 00193 */ 00194 typedef enum{ 00195 //! 0 means No Update. 00196 eVedaUpdate_NoUpdate=0, 00197 //! Sent before a BaseObject member value change.( in order to lock the context to prevent object use from other thread.) 00198 eVedaUpdate_MemberIsGoingToChange, 00199 //! a member of a BaseObject just changed. 00200 eVedaUpdate_MemberChanged, // sent after the member value change, and is used by the context to manage undo stack and other things... 00201 //! a member of a BaseObject just changed, but because of an undo. 00202 //! you may treat it the same as eVedaUpdate_MemberChanged. 00203 eVedaUpdate_MemberChangedBecauseOfUndo, // so that the change does not re-affect the undo stack !! 00204 //! Member of object Destroyed ! Watch out, the ID of the member is a dead pointer. 00205 eVedaUpdate_MemberDestroyed, // when there is a list/tree member and one cell is destroyed. 00206 //! new BaseObject created. 00207 eVedaUpdate_ObjectNew, 00208 //! BaseObject just destroyed.Watch out, the ID of the object is a dead pointer. 00209 eVedaUpdate_ObjectDestroyed, 00210 //! an object has just been Created; It's state has changed! 00211 eVedaUpdate_ObjectReCreated, 00212 //! an object has just been closed; It's state has changed! 00213 eVedaUpdate_ObjectClosed, 00214 //! TODO: a new class has been registered to the context. 00215 eVedaUpdate_NewRegisteredClass 00216 } eVedaUpdate; 00217 /*! 00218 \class ObjectManager 00219 \brief Nested Class that manages events 00220 (TODO,When final, this will give more independances between Base types 00221 and Context class) 00222 */ 00223 class ObjectManager 00224 { public: 00225 /*! 00226 \brief Used by BaseObjects "Set()" member methods to notify what happened when one of 00227 the member was edited, to change its value. It is used to manage the Undo/Redo capability. 00228 You should not use this method unless you create a PackSerializable base type and code it's Set(). 00229 TODO: not final. 00230 \param _UpDateType eVedaUpdate enum that identify the update info type. 00231 \param _ObjectMember BaseType if _UpDateType is about a member. 00232 \param _PreviousShapeChunk optionnal serialization of the previous state or 0L. 00233 \param _PreviousShapeChunkLength optionnal serialization of the previous state or 0L. 00234 \param _NewShapeChunk optionnal serialization of the new state or 0L. 00235 \param _NewShapeChunkLength optionnal serialization of the new state or 0L. 00236 */ 00237 virtual void NotifyObjectChange( eVedaUpdate _UpDateType,BaseType *_ObjectMember, 00238 const unsigned char *_PreviousShapeChunk=0L, 00239 unsigned int _PreviousShapeChunkLength=0L, 00240 const unsigned char *_NewShapeChunk=0L, 00241 unsigned int _NewShapeChunkLength=0L 00242 )=0; 00243 }; 00244 #endif 00245 /*================================================================== 00246 PROTECTED 00247 ==================================================================*/ 00248 protected: 00249 00250 //! an object can belong (or not) to a BaseObject,( and to a BaseContext through it). 00251 BaseObject *m_pObjectThatManagesThis; 00252 00253 #ifdef _ENGINE_EDITABLE_ 00254 //! If used as a member in an object, the member name, or NULL (not editable member). 00255 const char *m_pMemberName; 00256 #endif 00257 #ifdef _ENGINE_EDITABLE_ 00258 //! a short string explaining what's the object for in editable mode. OK if NULL (no info). 00259 const char *m_pMemberInfo; 00260 #endif 00261 00262 #ifdef _ENGINE_EDITABLE_ 00263 //! a string standing for an expression of the value of the object: 00264 PackString *m_pValueString; 00265 #endif 00266 00267 #ifdef _ENGINE_EDITABLE_ 00268 //! used as a temp for object change notification in Begin/EndChangeNotification(): 00269 unsigned char *m_pPreviousValueShape; 00270 unsigned int m_PreviousValueShapeLength; 00271 #endif 00272 00273 #ifdef _ENGINE_EDITABLE_ 00274 /*! 00275 \brief In edition mode, when a member of an object is changed (like in a Set()), 00276 you got to use BeginChangeNotification(), make your changes, and then 00277 EndChangeNotification(), so that the edition of this object and member 00278 is known by the context, and allows it to manage a GUI update and the undo stack. 00279 */ 00280 void BeginChangeNotification(); 00281 #endif 00282 #ifdef _ENGINE_EDITABLE_ 00283 /*! 00284 \brief In edition mode, when a member of an object is changed (like in a Set()), 00285 you got to use BeginChangeNotification(), make your changes, and then 00286 EndChangeNotification(), so that the edition of this object and member 00287 is known by the context, and allows it to manage a GUI update and the undo stack. 00288 */ 00289 void EndChangeNotification(); 00290 #endif 00291 00292 }; 00293 00294 /*! 00295 \def REGISTER_MEMBER 00296 00297 \brief This macro is used to register a serializable member in a class constructor. 00298 For editable mode, it uses _MemberName to explicit the use of the member, in order 00299 to display it in a GUI for example. 00300 00301 */ 00302 #ifdef _ENGINE_EDITABLE_ 00303 #define REGISTER_MEMBER(_object,_MemberName) \ 00304 RegisterSerializableMember(_object);\ 00305 _object.SetMemberName( _MemberName ); 00306 #define REGISTER_MEMBER_INFO(_object,_MemberInfo) _object.SetMemberInfo( _MemberInfo ); 00307 #else 00308 #define REGISTER_MEMBER(_object,_MemberName) \ 00309 RegisterSerializableMember(_object); 00310 #define REGISTER_MEMBER_INFO(_object,_MemberInfo) 00311 #endif 00312 00313 // end of file 00314 #endif
/\/\ 4 N k ! N D _______ _ __ ___ _____ ___ _ _ ____ ___________ __//___ /________ |/ / ___________\_______/ \ / _ _ \/ _ / _ / _/_/____/ _ __ / / / / / / / \ \/ / / \ \ / \\___/___/___/ ¯ _____/_____/ ______\___/_____/\________\\ \________/_ ___ __ l____\ /elD! http://www.m4nkind.com \____/