32 #ifndef _util_class_class_h 33 #define _util_class_class_h 45 #include <util/ref/ref.h> 46 #include <util/misc/exenv.h> 50 template <
class T,
class C>
70 enum Access { Private, Protected, Public };
79 int is_virtual()
const;
80 Access access()
const {
return _access; }
97 void init(
const char*);
100 const ParentClass& parent(
int i)
const {
return *_classes[i]; }
101 ParentClass& operator[](
int i) {
return *_classes[i]; }
102 const ParentClass& operator[](
int i)
const {
return *_classes[i]; }
103 int n()
const {
return _n; }
122 DescribedClass* create(
const Ref<KeyVal>& keyval)
124 return new T(keyval);
130 DescribedClass* create(StateIn& statein)
132 return new T(statein);
137 const std::type_info *ti_;
161 static std::map<std::string,ClassDescP> *all_;
162 static std::map<type_info_key,ClassDescP> *type_info_all_;
163 static char * classlib_search_path_;
164 static std::set<std::string> *unresolved_parents_;
169 std::set<std::string> *children_;
173 const std::type_info *ti_;
183 void init(
const char*,
int=1,
const char* p=0,
184 const std::type_info *ti=0,
189 ClassDesc(
const std::type_info&,
const char*,
int=1,
const char* p=0,
195 static std::map<std::string,ClassDescP>& all();
206 const char*
name()
const {
return classname_; }
272 class_desc(DescribedClass *d)
281 require_dynamic_cast(DescribedClass*p,
const char * errmsg,...)
283 T t =
dynamic_cast<T
>(p);
286 va_start(args,errmsg);
287 fprintf(stderr,
"A required dynamic_cast failed in: ");
288 vfprintf(stderr,errmsg,args);
289 fprintf(stderr,
"\nwanted type \"%s\" but got \"%s\"\n",
290 typeid(T).name(),p->class_desc()->name());
302 require_dynamic_cast(
const DescribedClass*p,
const char * errmsg,...)
304 T t =
dynamic_cast<T
>(p);
307 va_start(args,errmsg);
308 fprintf(stderr,
"A required dynamic_cast failed in: ");
309 vfprintf(stderr,errmsg,args);
310 fprintf(stderr,
"\nwanted type \"%s\" but got \"%s\"\n",
311 typeid(T).name(),p->class_desc()->name());
338 template <
class T,
class A = const Ref<KeyVal> &>
virtual void print(std::ostream &=ExEnv::out0()) const
Print the object.
int class_version() const
Return the version of the class.
Gives a list of parent classes of a class.
Definition: class.h:86
DescribedClass * create_described_class() const
This member has been replaced by create().
static ClassDesc * class_desc(const std::type_info &)
Given a type_info object return a pointer to the ClassDesc.
const char * class_name() const
Return the name of the object's exact type.
Classes which need runtime information about themselves and their relationship to other classes can v...
Definition: class.h:244
This, together with ForceLink, is used to force code for particular classes to be linked into executa...
Definition: class.h:322
Gives one parent class of a class.
Definition: class.h:67
The base class for all reference counted objects.
Definition: ref.h:194
A template class that maintains references counts.
Definition: ref.h:332
This, together with ForceLinkBase, is used to force code for particular classes to be linked into exe...
Definition: class.h:339
Restores objects that derive from SavableState.
Definition: statein.h:70
static int load_class(const char *classname)
Attempt to dynamically load the shared object file for classname.
Identity gives objects a unique identity and ordering relationship relative to all other objects...
Definition: identity.h:89
This class is used to contain information about classes.
Definition: class.h:158
static std::ostream & out0()
Return an ostream that writes from node 0.
ClassDesc * class_desc() const
This returns the unique pointer to the ClassDesc corresponding to the given type_info object...
static ClassDesc * name_to_class_desc(const char *)
Given the name of the class, return a pointer to the class descriptor.
const char * name() const
Returns the name of the class.
Definition: class.h:206
static void list_all_classes()
Writes a list of all of the classes to ExEnv::out0().
virtual DescribedClass * create() const
Create an instance of DescribedClass with exact type equal to the class to which this class descripto...
int version() const
Returns the version number of the class.
Definition: class.h:208
The KeyVal class is designed to simplify the process of allowing a user to specify keyword/value ass...
Definition: keyval.h:69