Generics Reference Manual |
---|
class CObjectListener : public CMetaModule { // instanciation section public : CObjectListener (); virtual ~CObjectListener () =0; // listener section public : // called when CObject constructor is executed on inSender (except when CObject is instanciated from serialization process // because in such cases the cobject would already be allocated when the listener would be attached) virtual void OnConstruct (CObject *inSender) { } // called when CObject destructor is executed on inSender, don't forget that only CObject's memory stack is available at //this point ! virtual void OnDestruct (CObject *inSender) { } // private section private : // listener callers CObjects m_Owners; // friend object class friend class CObject; // generic metaclass association SECTION_GENERIC_METACLASS; }; // metaclass and class tag declarations DECLARE_GENERIC_METACLASS ('_obj', CObjectListener, CMetaModule); class CObject : public CMetaModule { // instanciation section public : CObject (const CObjectListener *inListener =NULL); virtual ~CObject () =0; // protected definition protected : // object expected listener type virtual CMetaClass * ListenerMustBe () const; // specific functions public : // listener affectation, reader and removal (do not force class type caller on AssignListener : to increase performance, // types may be checked only while assignation in overwritten functions, not before calling specific listener functions; // if you force, you could generate segmentation faults not on this call but later on the listener exploitation) Bool AssignListener (const CObjectListener *inListener); CObjectListener * RemoveListener (); CObjectListener * GetListener () const; // serialization redefinition public : // object serialization, stores or instanciates associated listener if any virtual void Serialize (CXMLElementNode *&ioXMLElementNode, const int inMode); // protected attributes protected : // the object listener CObjectListener * m_Listener; // friend object listener class friend class CObjectListener; // generic metaclass specifications SECTION_GENERIC_METACLASS; }; // generic metaclass and class tag declarations DECLARE_GENERIC_METACLASS ('objt', CObject, CMetaModule); |