4 * Copyright 2006,2007 Martin Quinson, Malek Cherier
7 * This program is free software; you can redistribute
8 * it and/or modify it under the terms of the license
9 *(GNU LGPL) which comes with this package.
13 /* SimGrid::Msg RTTI implementation.
19 #include <xbt/dynar.h>
24 DeclaringClasses* DeclaringClass::declaringClasses = NULL;
31 // Generate static object constructor for class registration
32 void DeclareClass(Class* c)
34 MSG_DELCARING_CLASSES.lock();
35 MSG_DELCARING_CLASSES.addHead(c);
36 MSG_DELCARING_CLASSES.unlock();
39 } // namespace SimGrid
41 //////////////////////////////////////////////////////////////////////////////
42 // Implémentation des fonctions membre de la classe Class
44 // true if the class is derived from base classe referenced
46 bool Class::isDerivedFrom(const Class* baseClass) const
48 const Class* cur = this;
61 // Dynamic name lookup and creation
62 Class* Class::fromName(const char* name)
63 throw (ClassNotFoundException)
67 MSG_DELCARING_CLASSES.lock();
69 for(cur = MSG_DELCARING_CLASSES.getHead(); cur; cur = cur->next)
71 if(!strcmp(name,cur->name))
73 MSG_DELCARING_CLASSES.unlock();
78 MSG_DELCARING_CLASSES.unlock();
79 throw ClassNotFoundException(name);
83 Object* Class::createObject(const char* name)
85 Class* c = fromName(name);
86 return c->createObject();
90 //////////////////////////////////////////////////////////////////////////////
91 // Object members implementation
93 // Special runtime-class structure for Object (no base class)
94 const struct Class Object::classObject =
97 sizeof(Object), // typeSize
100 NULL // declaringClass
104 //////////////////////////////////////////////////////////////////////////////
105 // DeclaringClasses members implementation
108 DeclaringClasses::DeclaringClasses()
115 // Ajoute une nouvelle classe en tête de liste
116 void DeclaringClasses::addHead(Class* c)
125 // Retourne la tête de liste et la retire de la liste
126 Class* DeclaringClasses::removeHead(void)
140 // Retire la classe pClasse de la liste, mais ne la détruit pas
141 bool DeclaringClasses::remove(Class* c)
146 bool success = false;
158 while((NULL != cur) && (cur->next!= c))
172 bool Object::isInstanceOf(const char* className)
174 Class* c = Class::fromName(className);
176 return this->getClass()->isDerivedFrom(c);