6 // Compilation C++ recquise
\r
8 #error Object.hpp requires C++ compilation (use a .cxx suffix)
\r
15 //////////////////////////////////////////////////////////////////////////////
\r
18 // Returns the runtime class of the class_name object.
\r
19 #define MSG_GET_CLASS(class_name) \
\r
20 ((Class*)(&class_name::class##class_name))
\r
22 // Declare the class class_name as dynamic
\r
23 #define MSG_DECLARE_DYNAMIC(class_name) \
\r
25 static const Class class##class_name; \
\r
26 virtual Class* getClass() const; \
\r
27 static Object* createObject(); \
\r
29 // The runtime class implementation.
\r
30 #define MSG_IMPLEMENT_CLASS(class_name, base_class_name, pfn,class_init) \
\r
31 const Class class_name::class##class_name = { \
\r
32 #class_name, sizeof(class class_name),pfn, \
\r
33 MSG_GET_CLASS(base_class_name), NULL,class_init}; \
\r
34 Class* class_name::getClass() const \
\r
35 { return MSG_GET_CLASS(class_name); } \
\r
37 // CreateObject implementation.
\r
38 #define MSG_IMPLEMENT_DYNAMIC(class_name, base_class_name) \
\r
39 Object* class_name::createObject() \
\r
40 { return (Object*)(new class_name); } \
\r
41 DeclaringClass _declaringClass_##class_name(MSG_GET_CLASS(class_name)); \
\r
42 MSG_IMPLEMENT_CLASS(class_name, base_class_name, \
\r
43 class_name::createObject, &_declaringClass_##class_name) \
\r
46 //////////////////////////////////////////////////////////////////////////////
\r
47 // Classes declared in this file.
\r
49 class Object; // The msg object.
\r
51 //////////////////////////////////////////////////////////////////////////////
\r
52 // Structures declared in this files.
\r
54 struct Class; // used during the rtti operations
\r
55 struct DeclaringClass; // used during the instances registration.
\r
58 class DeclaringClasses;
\r
60 //////////////////////////////////////////////////////////////////////////////
\r
63 // Used during the registration.
\r
64 void DeclareClass(Class* c);
\r
66 //////////////////////////////////////////////////////////////////////////////
\r
69 struct DeclaringClass
\r
71 // Constructor : add the runtime classe in the list.
\r
72 DeclaringClass(Class* c);
\r
75 virtual ~DeclaringClass(void);
\r
78 // the list of runtime classes.
\r
79 static DeclaringClasses* declaringClasses;
\r
82 #define MSG_DELCARING_CLASSES (*(DeclaringClass::declaringClasses))
\r
90 const char* name; // class name.
\r
91 int typeSize; // type size.
\r
92 Object* (*createObjectFn)(void); // pointer to the create object function.
\r
93 Class* baseClass; // the runtime class of the runtime class.
\r
94 Class* next; // the next runtime class in the list.
\r
95 const DeclaringClass* declaringClass; // used during the registration of the class.
\r
99 // Create the runtime class from its name.
\r
100 static Class* fromName(const char* name);
\r
102 // Create an object from the name of the its class.
\r
103 static Object* createObject(const char* name);
\r
105 // Create an instance of the class.
\r
106 Object* createObject(void);
\r
108 // Return true is the class is dervived from the base class baseClass.
\r
109 bool isDerivedFrom(const Class* baseClass) const;
\r
113 // Create an instance of the class.
\r
114 inline Object* Class::createObject(void)
\r
116 return (*createObjectFn)();
\r
124 // Default constructor.
\r
128 virtual ~Object(){}
\r
132 // Get the runtime class.
\r
133 virtual Class* getClass(void) const;
\r
135 // Returns true if the class is derived from the class baseClass. Otherwise
\r
136 // the method returns false.
\r
137 bool isDerivedFrom(const Class* baseClass) const;
\r
139 // Returns true if the object is valid. Otherwise the method returns false.
\r
140 virtual bool isValid(void) const;
\r
146 // The runtime class.
\r
147 static const Class classObject;
\r
150 // inline member functions of the class Object.
\r
152 // Returns the runtime class of the object.
\r
153 inline Class* Object::getClass(void) const
\r
155 return MSG_GET_CLASS(Object);
\r
158 // Returns true if the class is derived from the class pBaseClass. Otherwise
\r
159 // the method returns false.
\r
160 inline bool Object::isDerivedFrom(const Class* baseClass) const
\r
162 return (getClass()->isDerivedFrom(baseClass));
\r
165 // Returns true if the object is valid. Otherwise the method returns false.
\r
166 inline bool Object::isValid(void) const
\r
168 // returns always true.
\r
172 class DeclaringClasses
\r
177 DeclaringClasses();
\r
180 virtual ~DeclaringClasses(){}
\r
184 // Add the class at the head of the list.
\r
185 void addHead(Class* c);
\r
187 // Get the runtime class of the head of the list.
\r
188 Class* getHead(void) const ;
\r
190 // Remove the class from the list (don't destroy it).
\r
191 bool remove(Class* c);
\r
193 // Remove the head of the list.
\r
194 Class* removeHead(void);
\r
196 // Return true if the list is empty.
\r
198 bool isEmpty(void) const;
\r
200 // Remove of the elements of the list.
\r
201 void removeAll(void);
\r
203 // Get the number of classes in the list.
\r
204 unsigned int getCount(void);
\r
208 void unlock(void){}
\r
212 // The head of the list.
\r
219 // The number of elements of the list.
\r
220 unsigned int count;
\r
224 // Constructor (Add the class in the list).
\r
225 inline DeclaringClass::DeclaringClass(Class* c)
\r
227 if(!declaringClasses)
\r
228 declaringClasses = new DeclaringClasses();
\r
234 inline DeclaringClass::~DeclaringClass()
\r
236 /*if(NULL != declaringClasses)
\r
237 delete declaringClasses;
\r
239 declaringClasses=NULL;*/
\r
243 // Returns the number of elements of the list.
\r
244 inline unsigned int DeclaringClasses::getCount()
\r
249 // Returns the head of the list.
\r
250 inline Class* DeclaringClasses::getHead() const
\r
255 // Returns true if the list is empty. Otherwise this function
\r
257 inline bool DeclaringClasses::isEmpty() const
\r
262 // Removes all the elements of the list.
\r
263 inline void DeclaringClasses::removeAll()
\r
272 using namespace msg;
\r
274 #endif // !MSG_OBJECT_H
\r