Gizmo3D

gzObject.h

Go to the documentation of this file.
00001 //*****************************************************************************
00002 // File         : gzObject.h
00003 // Module       : gzBase
00004 // Description  : Class definition of object management
00005 // Author       : Anders Modén      
00006 // Product      : GizmoBase 2.1.1
00007 //      
00008 // Copyright © 2003- Saab Training Systems AB, Sweden   
00009 //          
00010 // NOTE:    GizmoBase is a platform abstraction utility layer for C++. It contains 
00011 //          design patterns and C++ solutions for the advanced programmer.
00012 //
00013 //
00014 // Revision History...                          
00015 //                                  
00016 // Who  Date    Description                     
00017 //                                  
00018 // AMO  980915  Created file    
00019 //
00020 //******************************************************************************
00021 #ifndef __GZ_OBJECT_H__
00022 #define __GZ_OBJECT_H__
00023 
00031 #include "gzMemory.h"
00032 #include "gzTemplates.h"
00033 #include "gzBase.h"
00034 #include "gzSerialize.h"
00035 #include "gzNotify.h"
00036 #include "gzDynamic.h"
00037 #include "gzHashUtils.h"
00038 
00039 class gzObject; // Forward decl of attached data to an object
00040 
00041 //******************************************************************************
00042 // Class    : gzUserData
00043 //                                  
00044 // Purpose  : Basic holder of all user defined data. All objects inherits from
00045 //            the gzObject class that has a set of UserData
00046 //                                  
00047 // Notes    : Default behaviour is to ref()/unref() on two virtual functions    
00048 //                                  
00049 // Revision History...                          
00050 //                                  
00051 // Who  Date    Description                     
00052 //                                  
00053 // AMO  980912  Created 
00054 //                                  
00055 //******************************************************************************
00057 class  gzUserData : public gzReference , public gzSerializeData
00058 {
00059 public:
00060 
00061     GZ_DECLARE_TYPE_INTERFACE_EXPORT(GZ_BASE_EXPORT);   // RTTI
00062 
00063     GZ_BASE_EXPORT virtual ~gzUserData(){};
00064 
00065     GZ_BASE_EXPORT virtual gzVoid onAttach( gzObject *object , const gzString &attribute ) { ref(); }
00066 
00067     GZ_BASE_EXPORT virtual gzVoid onDetach( gzObject *object , const gzString &attribute) { unref(); }
00068 
00070     GZ_BASE_EXPORT virtual gzReference* clone() const=0;
00071 
00073     GZ_BASE_EXPORT virtual gzBool isEqualTo(const gzUserData *data) const { return data==this; }
00074 
00075 };
00076 
00077 //******************************************************************************
00078 // Class    : gzUserDataAttributeContainer
00079 //                                  
00080 // Purpose  : Basic holder of all user defined data. All objects inherits from
00081 //            the gzObject class that has a set of UserData
00082 //                                  
00083 // Notes    : Default behaviour is to ref()/unref() on two virtual functions    
00084 //                                  
00085 // Revision History...                          
00086 //                                  
00087 // Who  Date    Description                     
00088 //                                  
00089 // AMO  980912  Created 
00090 //                                  
00091 //******************************************************************************
00093 class  gzUserDataAttributeContainer : public gzUserData , public gzDynamicTypeContainer
00094 {
00095 public:
00096 
00097     GZ_DECLARE_TYPE_INTERFACE_EXPORT(GZ_BASE_EXPORT);   // RTTI
00098 
00099     GZ_BASE_EXPORT virtual ~gzUserDataAttributeContainer();
00100 
00101     GZ_BASE_EXPORT virtual gzVoid onAttributeEvent( gzDynamicTypeEvent reason , const gzString &name);
00102 
00103     GZ_BASE_EXPORT virtual gzVoid onAttach( gzObject *object , const gzString &attribute); 
00104 
00105     GZ_BASE_EXPORT virtual gzVoid onDetach( gzObject *object , const gzString &attribute);
00106 
00107     GZ_BASE_EXPORT virtual gzReference* clone() const;
00108 
00109     GZ_BASE_EXPORT virtual gzBool isEqualTo(const gzUserData *data) const;
00110 
00111     GZ_BASE_EXPORT virtual gzVoid write(gzSerializeAdapter *adapter);
00112 
00113     GZ_BASE_EXPORT virtual gzVoid read(gzSerializeAdapter *adapter);
00114 
00115     GZ_BASE_EXPORT virtual gzVoid pushBack(gzSerializeAdapter *adapter);
00116 
00117     GZ_BASE_EXPORT virtual gzULong  getDataSize(gzSerializeAdapter *adapter=NULL) const;
00118 
00119 
00120 private:
00121 
00122     gzList<gzObject>            m_attachements;
00123 };
00124 
00125 //******************************************************************************
00126 // Class    : gzObjectDictionary
00127 //                                  
00128 // Purpose  : Private class that hold data for gzObject
00129 //                                  
00130 // Notes    : - 
00131 //                                  
00132 // Revision History...                          
00133 //                                  
00134 // Who  Date    Description                     
00135 //                                  
00136 // AMO  980912  Created 
00137 //                                  
00138 //******************************************************************************
00140 class  gzUserDataDictionary : public gzDict<gzString,gzUserData>
00141 {
00142     virtual ~gzUserDataDictionary(){};
00143 
00144 private:
00145     friend class gzObject;
00146 
00147     gzUserDataDictionary();
00148     
00149     gzObject *m_owner;
00150 
00151     virtual gzVoid onInsert(const gzString &key, gzUserData * value ) const { value->onAttach(m_owner,key);}
00152 
00153     virtual gzVoid onRemove(const gzString &key, gzUserData * value ) const { value->onDetach(m_owner,key);}
00154 };
00155 
00156 
00157 class gzObjectInvokeInterface : public gzReference , public gzDynamicInvokeInterface
00158 {
00159 public:
00160     GZ_DECLARE_TYPE_INTERFACE_EXPORT(GZ_BASE_EXPORT);   // typed interface
00161 
00162     GZ_BASE_EXPORT gzObjectInvokeInterface();
00163     GZ_BASE_EXPORT virtual ~gzObjectInvokeInterface();
00164 
00165     // ---------- Interface registration -------------------------------
00166     GZ_BASE_EXPORT static gzVoid registerInterface(gzType *type,gzObjectInvokeInterface *iface);
00167     GZ_BASE_EXPORT static gzVoid unRegisterInterface(gzType *ifacetype);
00168 
00169     // ---------- Dynamic method invokation ----------------------------
00170 
00171     GZ_BASE_EXPORT static gzDynamicType                 instanceInvokeMethod(gzReference *instance,const gzString &IIDS_method,GZ_DYNAMIC_ATTRIBUTE_LIST);
00172     GZ_BASE_EXPORT static gzDynamicType                 instanceInvokeMethod(gzReference *instance,gzULongLong IID_method,GZ_DYNAMIC_ATTRIBUTE_LIST);
00173     GZ_BASE_EXPORT static gzBool                        instanceSupportMethod(gzReference *instance,gzULongLong IID_method);
00174     GZ_BASE_EXPORT static gzULongLong                   instanceGetMethodIID(gzReference *instance,const gzString &IIDS_method);
00175     GZ_BASE_EXPORT static gzDynamicMethod               instanceGetDirectMethod(gzReference *instance,gzULongLong IID_method);
00176     GZ_BASE_EXPORT static gzString                      instanceGetDescription(gzReference *instance,gzULongLong IID_method);
00177     GZ_BASE_EXPORT static gzArray<gzDynamicMethodID>    instanceQueryAllMethodIID(gzReference *instance);
00178 
00179 private:
00180 
00181     static gzRefDict<gzType,gzObjectInvokeInterface>        s_interfaces;
00182 };
00183 
00184 //******************************************************************************
00185 // Class    : gzObject
00186 //                                  
00187 // Purpose  : Base class for all Gizmo objects. 
00188 //                                  
00189 // Notes    : - 
00190 //                                  
00191 // Revision History...                          
00192 //                                  
00193 // Who  Date    Description                     
00194 //                                  
00195 // AMO  980912  Created 
00196 //                                  
00197 //******************************************************************************
00210 class  gzObject : public gzUserData 
00211 {
00212 public:
00213     GZ_DECLARE_TYPE_INTERFACE_EXPORT(GZ_BASE_EXPORT);   // typed interface
00214     
00215     GZ_BASE_EXPORT gzObject();
00216     GZ_BASE_EXPORT gzObject( const gzObject &copy);
00217     GZ_BASE_EXPORT gzObject &operator=(const gzObject &copy);
00218 
00219     GZ_BASE_EXPORT virtual ~gzObject();
00220 
00221     //---------------------- custom user data ----------------------------------
00222     GZ_BASE_EXPORT gzVoid       addUserData(    const gzString &name , gzUserData *data);
00223     GZ_BASE_EXPORT gzUserData * getUserData(    const gzString &name , gzUserData *parent=NULL);
00224     GZ_BASE_EXPORT gzBool       existUserData(  const gzString &name , gzUserData *data = NULL);
00225     GZ_BASE_EXPORT gzBool       removeUserData( const gzString &name , gzUserData *data = NULL);
00226     GZ_BASE_EXPORT gzVoid       removeAllUserData();
00227     GZ_BASE_EXPORT gzBool       hasUserData();
00228     GZ_BASE_EXPORT gzBool       hasSameUserData(const gzObject *object);
00229 
00230     GZ_BASE_EXPORT gzUserDataDictionary *   getUserDataDictionary();
00231 
00232 
00233     //---------------------- Attribute data ------------------------------------
00234 
00235     GZ_BASE_EXPORT gzVoid           setAttribute(const gzString &userdata , const gzString &name , const gzDynamicType &attribute);
00236     GZ_BASE_EXPORT gzDynamicType    getAttribute(const gzString &userdata ,const gzString &name) const;
00237     GZ_BASE_EXPORT gzBool           hasAttribute(const gzString &userdata ,const gzString &name);
00238     GZ_BASE_EXPORT gzBool           removeAttribute(const gzString &userdata ,const gzString &name);
00239     GZ_BASE_EXPORT gzVoid           removeAllAttributes(const gzString &userdata );
00240     GZ_BASE_EXPORT gzULong          getNumberOfAttributes(const gzString &userdata) const;
00241 
00242     GZ_BASE_EXPORT virtual gzVoid onUserDataAttributeEvent( gzUserData *data , gzDynamicTypeEvent reason , const gzString &name) {};
00243 
00244     // ---------- Clone interface ---------------------------------------
00245     GZ_BASE_EXPORT virtual gzReference* clone() const;
00246 
00247     // ---------- Factory management ------------------------------------
00248 
00249     GZ_BASE_EXPORT static gzULong registerFactoryObject(gzObject *object);
00250     GZ_BASE_EXPORT static gzVoid unregisterFactory(gzULong id);
00251     GZ_BASE_EXPORT static gzVoid unregisterAllFactories();
00252     GZ_BASE_EXPORT static gzObject *createFactoryObject(gzULong id);
00253 
00254     // ---------- Serializing -------------------------------------------
00255 
00256     GZ_BASE_EXPORT virtual gzVoid   write(gzSerializeAdapter *adapter);
00257     GZ_BASE_EXPORT virtual gzVoid   read(gzSerializeAdapter *adapter);
00258     GZ_BASE_EXPORT virtual gzULong  getDataSize(gzSerializeAdapter *adapter=NULL) const;
00259     
00260     // ---------- Serialize Utils ---------------------------------------
00261 
00262     GZ_BASE_EXPORT static   gzVoid      writeObject(gzObject *object, gzSerializeAdapter *adapter, gzULong totlen=0,const gzString &banner=GZ_EMPTY_STRING);
00263     GZ_BASE_EXPORT static   gzObject *  readObject(gzSerializeAdapter *adapter, gzULong totlen=0,const gzString &banner=GZ_EMPTY_STRING);
00264     GZ_BASE_EXPORT static   gzULong     getChunkSize(gzObject *object,gzSerializeAdapter *adapter);
00265 
00266 
00267     // ---------- Dynamic method invokation ----------------------------
00268 
00269     GZ_BASE_EXPORT gzDynamicType                invokeMethod(const gzString &IIDS_method,GZ_DYNAMIC_ATTRIBUTE_LIST);
00270     GZ_BASE_EXPORT gzDynamicType                invokeMethod(gzULongLong IID_method,GZ_DYNAMIC_ATTRIBUTE_LIST);
00271     GZ_BASE_EXPORT gzBool                       supportMethod(gzULongLong IID_method);
00272     GZ_BASE_EXPORT gzULongLong                  getMethodIID(const gzString &IIDS_method);
00273     GZ_BASE_EXPORT gzDynamicMethod              getDirectMethod(gzULongLong IID_method);
00274     GZ_BASE_EXPORT gzString                     getDescription(gzULongLong IID_method); 
00275     GZ_BASE_EXPORT gzArray<gzDynamicMethodID>   queryAllMethodIID();
00276 
00277 
00278 private:
00279 
00280     GZ_BASE_EXPORT virtual gzVoid   pushBack(gzSerializeAdapter *adapter);  
00281 
00282     gzUserDataDictionary    *m_userData;
00283 
00284     static gzRefDict< gzValueCompareInterface ,gzObject>    s_objectFactory;
00285 
00286     static gzMemCheck<gzMutex>                              s_factoryLocker;
00287 };
00288 
00289 
00290 #endif

Documentation for Gizmo3D generated at Wed Feb 20 11:54:07 2008 by   Saab Training Systems AB, ¸ (c) 2003-and beyond