32#ifndef _util_class_class_h
33#define _util_class_class_h
45#include <util/ref/ref.h>
46#include <util/misc/exenv.h>
50template <
class T,
class C>
51class DescribedMemberDatum {
55 DescribedMemberDatum(T C::*member): member_(member) {}
70 enum Access { Private, Protected, Public };
76 ParentClass(
ClassDesc*,Access access = Private,
int is_virtual = 0);
77 ParentClass(
const ParentClass&);
79 int is_virtual()
const;
80 Access access()
const {
return _access; }
93 ParentClasses(
const ParentClasses&);
94 void operator=(
const ParentClasses&);
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; }
122DescribedClass* create(
const Ref<KeyVal>& keyval)
124 return new T(keyval);
132 return new T(statein);
137 const std::type_info *ti_;
139 type_info_key(): ti_(0) {}
140 type_info_key(
const std::type_info *ti): ti_(ti) {}
141 type_info_key& operator=(
const type_info_key&);
142 int operator==(
const type_info_key&)
const;
143 int operator<(
const type_info_key&)
const;
144 int cmp(
const type_info_key&)
const;
159 friend class ParentClasses;
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_;
168 ParentClasses parents_;
169 std::set<std::string> *children_;
173 const std::type_info *ti_;
175 void change_parent(ClassDesc*oldcd,ClassDesc*newcd);
178 ClassDesc(
const ClassDesc&);
179 void operator=(
const ClassDesc&);
182 ClassDesc(
const char*);
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();
196 const ParentClasses& parents()
const {
return parents_; }
206 const char*
name()
const {
return classname_; }
244class DescribedClass :
public RefCount {
247 DescribedClass(
const DescribedClass&);
248 DescribedClass& operator=(
const DescribedClass&);
249 virtual ~DescribedClass();
281require_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());
302require_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());
325 virtual ~ForceLinkBase() {};
338template <
class T,
class A = const Ref<KeyVal> &>
339class ForceLink:
public ForceLinkBase<A> {
342 virtual ~ForceLink() {};
This class is used to contain information about classes.
Definition class.h:158
int version() const
Returns the version number of the class.
Definition class.h:208
static int load_class(const char *classname)
Attempt to dynamically load the shared object file for classname.
static ClassDesc * name_to_class_desc(const char *)
Given the name of the class, return a pointer to the class descriptor.
virtual DescribedClass * create() const
Create an instance of DescribedClass with exact type equal to the class to which this class descripto...
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(StateIn &) const
Create an instance of DescribedClass with exact type equal to the class to which this class descripto...
static ClassDesc * class_desc(const std::type_info &)
Given a type_info object return a pointer to the ClassDesc.
DescribedClass * create_described_class() const
This member has been replaced by create().
virtual DescribedClass * create(const Ref< KeyVal > &) const
Create an instance of DescribedClass with exact type equal to the class to which this class descripto...
Classes which need runtime information about themselves and their relationship to other classes can v...
Definition class.h:244
const char * class_name() const
Return the name of the object's exact type.
int class_version() const
Return the version of the class.
ClassDesc * class_desc() const
This returns the unique pointer to the ClassDesc corresponding to the given type_info object.
virtual void print(std::ostream &=ExEnv::out0()) const
Print the object.
The ExEnv class is used to find out about how the program is being run.
Definition exenv.h:47
Identity gives objects a unique identity and ordering relationship relative to all other objects.
Definition identity.h:89
The KeyVal class is designed to simplify the process of allowing a user to specify keyword/value asso...
Definition keyval.h:69
Gives one parent class of a class.
Definition class.h:68
A template class that maintains references counts.
Definition ref.h:332
Restores objects that derive from SavableState.
Definition statein.h:70