5 // Compilation C++ recquise
\r
7 #error Object.hpp requires C++ compilation (use a .cxx suffix)
\r
12 #include <ClassNotFoundException.hpp>
\r
18 //////////////////////////////////////////////////////////////////////////////
\r
21 // Returns the runtime class of the class_name object.
\r
22 #define MSG_GET_CLASS(class_name) \
\r
23 ((Class*)(&class_name::class##class_name))
\r
25 // Declare the class class_name as dynamic
\r
26 #define MSG_DECLARE_DYNAMIC(class_name) \
\r
28 static Class class##class_name; \
\r
29 virtual Class* getClass() const; \
\r
30 static Object* createObject(); \
\r
32 // The runtime class implementation.
\r
33 #define MSG_IMPLEMENT_CLASS(class_name, base_class_name, pfn,class_init) \
\r
34 Class class_name::class##class_name = { \
\r
35 #class_name, sizeof(class class_name),pfn, \
\r
36 MSG_GET_CLASS(base_class_name), NULL,class_init}; \
\r
37 Class* class_name::getClass() const \
\r
38 { return MSG_GET_CLASS(class_name); } \
\r
40 // CreateObject implementation.
\r
41 #define MSG_IMPLEMENT_DYNAMIC(class_name, base_class_name) \
\r
42 Object* class_name::createObject() \
\r
43 { return (Object*)(new class_name); } \
\r
44 DeclaringClass _declaringClass_##class_name(MSG_GET_CLASS(class_name)); \
\r
45 MSG_IMPLEMENT_CLASS(class_name, base_class_name, \
\r
46 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 SIMGRIDX_EXPORT 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
87 struct SIMGRIDX_EXPORT Class
\r
92 const char* name; // class name.
\r
93 size_t 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
123 class SIMGRIDX_EXPORT Object
\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
145 // Returns true is the object is an instance of the class specified as parameter.
\r
146 bool isInstanceOf(const char* className);
\r
152 // The runtime class.
\r
153 static const Class classObject;
\r
156 // inline member functions of the class Object.
\r
158 // Returns the runtime class of the object.
\r
159 inline Class* Object::getClass(void) const
\r
161 return MSG_GET_CLASS(Object);
\r
164 // Returns true if the class is derived from the class pBaseClass. Otherwise
\r
165 // the method returns false.
\r
166 inline bool Object::isDerivedFrom(const Class* baseClass) const
\r
168 return (getClass()->isDerivedFrom(baseClass));
\r
171 // Returns true if the object is valid. Otherwise the method returns false.
\r
172 inline bool Object::isValid(void) const
\r
174 // returns always true.
\r
179 class DeclaringClasses
\r
184 DeclaringClasses();
\r
187 virtual ~DeclaringClasses(){}
\r
191 // Add the class at the head of the list.
\r
192 void addHead(Class* c);
\r
194 // Get the runtime class of the head of the list.
\r
195 Class* getHead(void) const ;
\r
197 // Remove the class from the list (don't destroy it).
\r
198 bool remove(Class* c);
\r
200 // Remove the head of the list.
\r
201 Class* removeHead(void);
\r
203 // Return true if the list is empty.
\r
205 bool isEmpty(void) const;
\r
207 // Remove of the elements of the list.
\r
208 void removeAll(void);
\r
210 // Get the number of classes in the list.
\r
211 unsigned int getCount(void);
\r
215 void unlock(void){}
\r
219 // The head of the list.
\r
226 // The number of elements of the list.
\r
227 unsigned int count;
\r
231 // Constructor (Add the class in the list).
\r
232 inline DeclaringClass::DeclaringClass(Class* c)
\r
234 if(!declaringClasses)
\r
235 declaringClasses = new DeclaringClasses();
\r
241 inline DeclaringClass::~DeclaringClass()
\r
243 /*if(NULL != declaringClasses)
\r
244 delete declaringClasses;
\r
246 declaringClasses=NULL;*/
\r
250 // Returns the number of elements of the list.
\r
251 inline unsigned int DeclaringClasses::getCount()
\r
256 // Returns the head of the list.
\r
257 inline Class* DeclaringClasses::getHead() const
\r
262 // Returns true if the list is empty. Otherwise this function
\r
264 inline bool DeclaringClasses::isEmpty() const
\r
269 // Removes all the elements of the list.
\r
270 inline void DeclaringClasses::removeAll()
\r
276 } // namespace Msg
\r
277 } // namespace SimGrid
\r
280 using namespace SimGrid::Msg;
\r
282 #define instanceOf(class_name) reinterpret_cast<class_name*>(Class::createObject(#class_name))
\r
284 #endif // !MSG_OBJECT_H
\r