Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

general/STypeInfo.h

Go to the documentation of this file.
00001 /* #start# ***********************************************************
00002 
00003            Scheduling Simulator
00004         Lehrstuhl f"ur Effiziente Algorithmen
00005            Technische Universit"at M"unchen
00006 
00007  File    : $Id: STypeInfo.h,v 1.4 2003/01/08 18:57:12 meierb Exp $
00008 
00009  Purpose : A small typechecking-system for the classes which are part of the
00010            general classification scheme.
00011      To use it inherit from STypeInfo and include one of the macros
00012      TYPEINFO0,1,2 or 3 -- depending on the number of classes from which
00013      you are subclassing -- as the first statement in the class 
00014      declaration.
00015      Include TYPEINFOVAR in the corresponding .cpp file.
00016 
00017  RCS-Log:
00018  $Log: STypeInfo.h,v $
00019  Revision 1.4  2003/01/08 18:57:12  meierb
00020  added randomized release times
00021 
00022  Revision 1.1.1.1  2002/12/02 22:26:19  meierb
00023  my_schedule
00024 
00025  Revision 1.2  2002/11/09 02:51:03  taeubig
00026  Replaced <iostream.h> header inclusion by <iostream>, cerr by std::cerr...
00027 
00028  Revision 1.1  2002/08/29 12:59:58  taeubig
00029  Added the sources
00030 
00031  Revision 1.8  2000/05/24 12:28:51  taeubig
00032  New compiler (gcc-2.95) and new Qt (2.1)
00033  Replaced "list" by "leda_list" etc.
00034 
00035  Revision 1.7  2000/01/11 17:26:15  zoidl
00036  added javadoc comments
00037 
00038  Revision 1.6  1999/03/30 12:13:39  schickin
00039  dynamic_cast added, constructors for task system classes added
00040 
00041  Revision 1.5  1999/03/19 16:45:09  hall
00042  nc
00043 
00044  Revision 1.4  1999/02/10 15:53:31  hall
00045  TypeInfo, Observer works
00046 
00047 
00048  * #end# ************************************************************* */
00049 
00050 #ifndef STYPEINFO_H
00051 #define STYPEINFO_H
00052 
00053 // system header files
00054 #include <iostream>
00055 #include <cmath>
00056 
00057 #include <LEDA/list.h>
00058 #include <LEDA/string.h>
00059 
00060 // project header files
00061 #include "SUtil.h"
00062 
00076 // -----------------------------------------------------------------------
00077 class STypeInfo {
00078 public:
00079   
00085   virtual leda_string getClassifier() const =0;
00086   
00093   virtual bool isInstanceOf(const leda_string &classifier) const =0;
00094   
00099   virtual void assureInstanceOf(const leda_string &classifier) const =0;
00100 };
00101 // -----------------------------------------------------------------------
00102 
00103 // -----------------------------------------------------------------------
00104 #define TYPEINFOSTART       \
00105 private:          \
00106   static bool _validAncesAndSelf;   \
00107   static leda_list<leda_string> _ancesAndSelf;  \
00108 public:           \
00109   static const leda_list<leda_string> &getTypeInfo() {  \
00110     if( _validAncesAndSelf )      \
00111       return _ancesAndSelf;     \
00112                 \
00113     leda_list<leda_string> l;
00114 
00115 // -----------------------------------------------------------------------
00116 #undef dbgOn
00117 #define dbgOn false
00118 #define TYPEINFOEND(theName, theClassifier)           \
00119     _ancesAndSelf.sort();             \
00120     _ancesAndSelf.unique();             \
00121     _ancesAndSelf.append(theClassifier);          \
00122     dbgVar("ancesAndSelf", _ancesAndSelf);                                      \
00123     _validAncesAndSelf = true;                                                  \
00124     return _ancesAndSelf;             \
00125   };                    \
00126   virtual leda_string getClassifier() const { return theClassifier; };          \
00127   virtual bool isInstanceOf(const leda_string &classifier) const {              \
00128     return ( NULL != theName::getTypeInfo().search(classifier) );   \
00129   };                    \
00130   virtual void assureInstanceOf(const leda_string &classifier) const {    \
00131     if( !isInstanceOf(classifier) ) {                                           \
00132       std::cerr << "You tried to use an object of the class \""           \
00133            << theClassifier << "\" as an instance of the \"" << classifier  \
00134      << "\" class" << std::endl;                                          \
00135       std::cerr << "A cast isn't possible here!" << std::endl                   \
00136      << "This object is an instance of:" << std::endl                     \
00137      << theName::getTypeInfo() << std::endl;              \
00138       exit(1);                  \
00139     }                   \
00140   }
00141 // -----------------------------------------------------------------------
00149 #define TYPEINFO0(theName, theClassifier) \
00150   TYPEINFOSTART         \
00151   TYPEINFOEND(theName, theClassifier)
00152 
00162 #define TYPEINFO1(theName, theClassifier, theSuper1)  \
00163   TYPEINFOSTART           \
00164     l = theSuper1::getTypeInfo();     \
00165     _ancesAndSelf.conc(l);        \
00166   TYPEINFOEND(theName, theClassifier)
00167 
00178 #define TYPEINFO2(theName, theClassifier, theSuper1, theSuper2) \
00179   TYPEINFOSTART             \
00180     l = theSuper1::getTypeInfo();       \
00181     _ancesAndSelf.conc(l);          \
00182     l = theSuper2::getTypeInfo();       \
00183     _ancesAndSelf.conc(l);          \
00184   TYPEINFOEND(theName, theClassifier)
00185 
00197 #define TYPEINFO3(theName, theClassifier, theSuper1, theSuper2, theSuper3)  \
00198   TYPEINFOSTART                 \
00199     l = theSuper1::getTypeInfo();           \
00200     _ancesAndSelf.conc(l);              \
00201     l = theSuper2::getTypeInfo();           \
00202     _ancesAndSelf.conc(l);              \
00203     l = theSuper3::getTypeInfo();           \
00204     _ancesAndSelf.conc(l);              \
00205   TYPEINFOEND(theName, theClassifier)
00206   
00207 // -----------------------------------------------------------------------
00214 #define TYPEINFOVAR(theName)      \
00215   bool theName::_validAncesAndSelf = false; \
00216   leda_list<leda_string> theName::_ancesAndSelf;
00217   
00218 // -----------------------------------------------------------------------
00219 
00220 #endif //STYPEINFO_H
00221 
00222 
00223 
00224 
00225 
00226 

Generated on Thu May 22 16:48:08 2003 for Sketch-it! by doxygen1.2.18