/* * CENA C++ Utilities * * by Stephane Chatty * * Copyright 1991, 1992 * Laboratoire de Recherche en Informatique (LRI) * Centre d'Etudes de la Navigation Aerienne (CENA) * * metaclasses, originally by Michel Beaudouin-Lafon * * $Id$ * $CurLog$ */ #include "MetaClass.h" #include /*?class MetaClass This class provides minimal support for metaclasses in C++. A \typ{MetaClass} object represents a C++ class. It contains a name (a string holding the name of the C++ class), and the inheritance information. Multiple inheritance is not supported in this version. ?*/ /* a discuter : autres fonctions dans MetaClass, notamment pour le transport d'objet stocker dans l'objet MetaClass la fonction de chargement/ecriture mettre les MetaClass dans une h-table indexee par le nom persistance: la description des classes pour la sauvegarde/chargement pourrait etre non pas dans le code, mais dans un fichier (par exemple le .h !!!) faut-il conserver la liste des classes filles ? */ /*? Create a metaclass for the base class named \var{n}. ?*/ MetaClass :: MetaClass (const char* n) : Name (n), BaseClasses () { } /*? Create a metaclass for the derived class named \var{n}. \var{s} is the metaclass of the base class of the class named \var{n}. ?*/ MetaClass :: MetaClass (const char* n, MetaClass& s) : Name (n), BaseClasses () { BaseClasses->Append (s); } /*? Return true if this metaclass is a derived class of the metaclass s. ?*/ int MetaClass :: IsDerivedClass (const MetaClass& s) const { register const MetaClass* m = this; do { if (m == &s) return 1; } while (m = m->BaseClass); return 0; } /*? Return 1 if this metaclass is a derived class of the metaclass named \var{n}. This form is less efficient than the previous one. It may be useful to avoid including the definition of the class named \var{n}. ?*/ int MetaClass :: IsSubClass (const char* n) const { register const MetaClass* m = this; do { if (strcmp (m->name, n) == 0) return 1; } while (m = m->BaseClass); return 0; } #ifdef DOC // fake entries for documentation /*? Return the superClass of this metaclass. Note that base classe have MetaClass::ROOT as superClass. MetaClass::ROOT is its own metaclass (there is a loop at the root of the inheritance tree). ?*/ MetaClass& MetaClass :: SuperClass () const { } /*? Return the name of this metaclass. By convention, it is identical to the identifier for the class represented by this metaclass. ?*/ const char* MetaClass :: Name () const { } /*? This conversion operator returns the name of this metaclass. See the member function Name. ?*/ MetaClass :: operator const char* () const { } /*?nextdoc?*/ int MetaClass :: Base () const { } /*? Return true if the class represented by this metaclass is a base class (resp. a derived class). ?*/ int MetaClass :: Derived () const { } /*? Return 0 if this metaclass is MetaClass::ROOT, else return 1. This makes it easy to walk up the hierarchy of metaclasses:\\ \hspace*{1cm}\com{while (mc = mc.SuperClass ()) ...}. ?*/ MetaClass :: operator int () const { } /*?nextdoc?*/ int MetaClass :: operator <= (const MetaClass& c) const { } /*?nextdoc?*/ int MetaClass :: operator >= (const MetaClass& c) const { } /*?nextdoc?*/ int MetaClass :: operator < (const MetaClass& c) const { } /*?nextdoc?*/ int MetaClass :: operator > (const MetaClass& c) const { } /*?nextdoc?*/ int MetaClass :: operator == (const MetaClass& c) const { } /*? Relational operations between metaclasses. The metaclass of class A is $<$ to the metaclass of class B if A is a derived class of B. The definitions of the other operators derive from this one. Note however that the order between metaclasses is not total : two metaclasses A and B can be uncomparable, that is neither A $<$ B or B $<$ A is true. This is the case when A does not derive from B and B does not derive from A. ?*/ int MetaClass :: operator != (const MetaClass& c) const { } /*?nodoc?*/ const MetaClass& MetaClass :: operator = (const MetaClass&) { } #endif