6 // Compilation C++ recquise
\r
8 #error Object.hpp requires C++ compilation (use a .cxx suffix)
\r
13 #include <ClassNotFoundException.hpp>
\r
17 //////////////////////////////////////////////////////////////////////////////
\r
20 // Returns the runtime class of the class_name object.
\r
21 #define MSG_GET_CLASS(class_name) \
\r
22 ((Class*)(&class_name::class##class_name))
\r
24 // Declare the class class_name as dynamic
\r
25 #define MSG_DECLARE_DYNAMIC(class_name) \
\r
27 static const Class class##class_name; \
\r
28 virtual Class* getClass() const; \
\r
29 static Object* createObject(); \
\r
31 // The runtime class implementation.
\r
32 #define MSG_IMPLEMENT_CLASS(class_name, base_class_name, pfn,class_init) \
\r
33 const Class class_name::class##class_name = { \
\r
34 #class_name, sizeof(class class_name),pfn, \
\r
35 MSG_GET_CLASS(base_class_name), NULL,class_init}; \
\r
36 Class* class_name::getClass() const \
\r
37 { return MSG_GET_CLASS(class_name); } \
\r
39 // CreateObject implementation.
\r
40 #define MSG_IMPLEMENT_DYNAMIC(class_name, base_class_name) \
\r
41 Object* class_name::createObject() \
\r
42 { return (Object*)(new class_name); } \
\r
43 DeclaringClass _declaringClass_##class_name(MSG_GET_CLASS(class_name)); \
\r
44 MSG_IMPLEMENT_CLASS(class_name, base_class_name, \
\r
45 class_name::createObject, &_declaringClass_##class_name) \
\r
48 //////////////////////////////////////////////////////////////////////////////
\r
49 // Classes declared in this file.
\r
51 class Object; // The msg object.
\r
53 //////////////////////////////////////////////////////////////////////////////
\r
54 // Structures declared in this files.
\r
56 struct Class; // used during the rtti operations
\r
57 struct DeclaringClass; // used during the instances registration.
\r
60 class DeclaringClasses;
\r
62 //////////////////////////////////////////////////////////////////////////////
\r
65 // Used during the registration.
\r
66 void DeclareClass(Class* c);
\r
68 //////////////////////////////////////////////////////////////////////////////
\r
71 struct DeclaringClass
\r
73 // Constructor : add the runtime classe in the list.
\r
74 DeclaringClass(Class* c);
\r
77 virtual ~DeclaringClass(void);
\r
80 // the list of runtime classes.
\r
81 static DeclaringClasses* declaringClasses;
\r
84 #define MSG_DELCARING_CLASSES (*(DeclaringClass::declaringClasses))
\r
92 const char* name; // class name.
\r
93 int typeSize; // type size.
\r
94 Object* (*createObjectFn)(void); // pointer to the create object function.
\r
95 Class* baseClass; // the runtime class of the runtime class.
\r
96 Class* next; // the next runtime class in the list.
\r
97 const DeclaringClass* declaringClass; // used during the registration of the class.
\r
101 // Create the runtime class from its name.
\r
102 static Class* fromName(const char* name)
\r
103 throw (ClassNotFoundException);
\r
105 // Create an object from the name of the its class.
\r
106 static Object* createObject(const char* name);
\r
108 // Create an instance of the class.
\r
109 Object* createObject(void);
\r
111 // Return true is the class is dervived from the base class baseClass.
\r
112 bool isDerivedFrom(const Class* baseClass) const;
\r
116 // Create an instance of the class.
\r
117 inline Object* Class::createObject(void)
\r
119 return (*createObjectFn)();
\r
127 // Default constructor.
\r
131 virtual ~Object(){}
\r
135 // Get the runtime class.
\r
136 virtual Class* getClass(void) const;
\r
138 // Returns true if the class is derived from the class baseClass. Otherwise
\r
139 // the method returns false.
\r
140 bool isDerivedFrom(const Class* baseClass) const;
\r
142 // Returns true if the object is valid. Otherwise the method returns false.
\r
143 virtual bool isValid(void) const;
\r
149 // The runtime class.
\r
150 static const Class classObject;
\r
153 // inline member functions of the class Object.
\r
155 // Returns the runtime class of the object.
\r
156 inline Class* Object::getClass(void) const
\r
158 return MSG_GET_CLASS(Object);
\r
161 // Returns true if the class is derived from the class pBaseClass. Otherwise
\r
162 // the method returns false.
\r
163 inline bool Object::isDerivedFrom(const Class* baseClass) const
\r
165 return (getClass()->isDerivedFrom(baseClass));
\r
168 // Returns true if the object is valid. Otherwise the method returns false.
\r
169 inline bool Object::isValid(void) const
\r
171 // returns always true.
\r
175 class DeclaringClasses
\r
180 DeclaringClasses();
\r
183 virtual ~DeclaringClasses(){}
\r
187 // Add the class at the head of the list.
\r
188 void addHead(Class* c);
\r
190 // Get the runtime class of the head of the list.
\r
191 Class* getHead(void) const ;
\r
193 // Remove the class from the list (don't destroy it).
\r
194 bool remove(Class* c);
\r
196 // Remove the head of the list.
\r
197 Class* removeHead(void);
\r
199 // Return true if the list is empty.
\r
201 bool isEmpty(void) const;
\r
203 // Remove of the elements of the list.
\r
204 void removeAll(void);
\r
206 // Get the number of classes in the list.
\r
207 unsigned int getCount(void);
\r
211 void unlock(void){}
\r
215 // The head of the list.
\r
222 // The number of elements of the list.
\r
223 unsigned int count;
\r
227 // Constructor (Add the class in the list).
\r
228 inline DeclaringClass::DeclaringClass(Class* c)
\r
230 if(!declaringClasses)
\r
231 declaringClasses = new DeclaringClasses();
\r
237 inline DeclaringClass::~DeclaringClass()
\r
239 /*if(NULL != declaringClasses)
\r
240 delete declaringClasses;
\r
242 declaringClasses=NULL;*/
\r
246 // Returns the number of elements of the list.
\r
247 inline unsigned int DeclaringClasses::getCount()
\r
252 // Returns the head of the list.
\r
253 inline Class* DeclaringClasses::getHead() const
\r
258 // Returns true if the list is empty. Otherwise this function
\r
260 inline bool DeclaringClasses::isEmpty() const
\r
265 // Removes all the elements of the list.
\r
266 inline void DeclaringClasses::removeAll()
\r
275 using namespace msg;
\r
277 #endif // !MSG_OBJECT_H
\r