The TypeRegistry class maintains all the assigned TypeHandles in a given system. More...
#include "typeRegistry.h"
Public Member Functions | |
TypeHandle | find_type (const std::string &name) const |
Looks for a previously-registered type of the given name. More... | |
TypeHandle | find_type_by_id (int id) const |
Looks for a previously-registered type with the given id number (as returned by TypeHandle::get_index()). More... | |
TypeHandle | get_child_class (TypeHandle child, int index) const |
Returns the nth child class of this type. More... | |
std::string | get_name (TypeHandle type, TypedObject *object) const |
Returns the name of the indicated type. More... | |
int | get_num_child_classes (TypeHandle child, TypedObject *child_object) const |
Returns the number of child classes that the indicated type is known to have. More... | |
int | get_num_parent_classes (TypeHandle child, TypedObject *child_object) const |
Returns the number of parent classes that the indicated type is known to have. More... | |
int | get_num_root_classes () |
int | get_num_typehandles () |
TypeHandle | get_parent_class (TypeHandle child, int index) const |
Returns the nth parent class of this type. More... | |
TypeHandle | get_parent_towards (TypeHandle child, TypeHandle base, TypedObject *child_object) |
Returns the parent of the indicated child class that is in a direct line of inheritance to the indicated ancestor class. More... | |
TypeHandle | get_root_class (int n) |
TypeHandle | get_typehandle (int n) |
bool | is_derived_from (TypeHandle child, TypeHandle base, TypedObject *child_object) |
Returns true if the first type is derived from the second type, false otherwise. More... | |
void | record_alternate_name (TypeHandle type, const std::string &name) |
Indicates an alternate name for the same type. More... | |
void | record_derivation (TypeHandle child, TypeHandle parent) |
Records that the type referenced by child inherits directly from the type referenced by parent. More... | |
TypeHandle | register_dynamic_type (const std::string &name) |
Registers a new type on-the-fly, presumably at runtime. More... | |
bool | register_type (TypeHandle &type_handle, const std::string &name) |
Creates a new Type of the given name and assigns a unique value to the type_handle. More... | |
void | write (std::ostream &out) const |
Makes an attempt to format the entire TypeRegistry in a nice way that shows the derivation tree as intelligently as possible. More... | |
Static Public Member Functions | |
static TypeRegistry * | ptr () |
Returns the pointer to the global TypeRegistry object. More... | |
static void | reregister_types () |
Walks through the TypeRegistry tree and makes sure that each type that was previously registered is *still* registered. More... | |
Public Attributes | |
get_num_root_classes | |
Returns the number of root classes–that is, classes that do not inherit from any other classes–known in the system. More... | |
get_num_typehandles | |
Returns the total number of unique TypeHandles in the system. More... | |
get_root_class | |
Returns the nth root class in the system. More... | |
get_typehandle | |
Returns the nth TypeHandle in the system. More... | |
Friends | |
class | TypeHandle |
The TypeRegistry class maintains all the assigned TypeHandles in a given system.
There should be only one TypeRegistry class during the lifetime of the application. It will be created on the local heap initially, and it should be migrated to shared memory as soon as shared memory becomes available.
Definition at line 36 of file typeRegistry.h.
TypeHandle TypeRegistry::find_type | ( | const std::string & | name | ) | const |
Looks for a previously-registered type of the given name.
Returns its TypeHandle if it exists, or TypeHandle::none() if there is no such type.
Definition at line 233 of file typeRegistry.cxx.
Referenced by FindApproxPath::add_component(), FactoryBase::make_instance(), FactoryBase::make_instance_more_general(), PT(), and BamReader::read_handle().
TypeHandle TypeRegistry::find_type_by_id | ( | int | id | ) | const |
Looks for a previously-registered type with the given id number (as returned by TypeHandle::get_index()).
Returns its TypeHandle if it exists, or TypeHandle::none() if there is no such type.
Definition at line 253 of file typeRegistry.cxx.
TypeHandle TypeRegistry::get_child_class | ( | TypeHandle | child, |
int | index | ||
) | const |
Returns the nth child class of this type.
The index should be in the range 0 <= index < get_num_child_classes().
Definition at line 438 of file typeRegistry.cxx.
string TypeRegistry::get_name | ( | TypeHandle | type, |
TypedObject * | object | ||
) | const |
Returns the name of the indicated type.
The "object" pointer is an optional pointer to the TypedObject class that owns this TypeHandle. It is only used in case the TypeHandle is inadvertantly undefined.
Definition at line 273 of file typeRegistry.cxx.
int TypeRegistry::get_num_child_classes | ( | TypeHandle | child, |
TypedObject * | child_object | ||
) | const |
Returns the number of child classes that the indicated type is known to have.
This may then be used to index into get_child_class().
The "object" pointer is an optional pointer to the TypedObject class that owns this TypeHandle. It is only used in case the TypeHandle is inadvertantly undefined.
Definition at line 424 of file typeRegistry.cxx.
int TypeRegistry::get_num_parent_classes | ( | TypeHandle | child, |
TypedObject * | child_object | ||
) | const |
Returns the number of parent classes that the indicated type is known to have.
This may then be used to index into get_parent_class(). The result will be 0 if this class does not inherit from any other classes, 1 if normal, single inheritance is in effect, or greater than one if multiple inheritance is in effect.
The "object" pointer is an optional pointer to the TypedObject class that owns this TypeHandle. It is only used in case the TypeHandle is inadvertantly undefined.
Definition at line 387 of file typeRegistry.cxx.
TypeHandle TypeRegistry::get_parent_class | ( | TypeHandle | child, |
int | index | ||
) | const |
Returns the nth parent class of this type.
The index should be in the range 0 <= index < get_num_parent_classes().
Definition at line 401 of file typeRegistry.cxx.
TypeHandle TypeRegistry::get_parent_towards | ( | TypeHandle | child, |
TypeHandle | base, | ||
TypedObject * | child_object | ||
) |
Returns the parent of the indicated child class that is in a direct line of inheritance to the indicated ancestor class.
This is useful in the presence of multiple inheritance to try to determine what properties an unknown type may have.
The "object" pointer is an optional pointer to the TypedObject class that owns this TypeHandle. It is only used in case the TypeHandle is inadvertantly undefined.
Definition at line 463 of file typeRegistry.cxx.
References TypeRegistryNode::get_parent_towards().
Referenced by TypeHandle::get_parent_towards().
bool TypeRegistry::is_derived_from | ( | TypeHandle | child, |
TypeHandle | base, | ||
TypedObject * | child_object | ||
) |
Returns true if the first type is derived from the second type, false otherwise.
The "child_object" pointer is an optional pointer to the TypedObject class that owns the child TypeHandle. It is only used in case the TypeHandle is inadvertently undefined.
This function definition follows the definitions for look_up() and freshen_derivations() just to maximize the chance the the compiler will be able to inline the above functions. Yeah, a compiler shouldn't care, but there's a big different between "shouldn't" and "doesn't".
Definition at line 297 of file typeRegistry.cxx.
References TypeRegistryNode::is_derived_from().
Referenced by TypeHandle::is_derived_from().
|
inlinestatic |
Returns the pointer to the global TypeRegistry object.
Definition at line 30 of file typeRegistry.I.
Referenced by FindApproxPath::add_component(), TypeHandle::dec_memory_usage(), TypeHandle::get_memory_usage(), TypeHandle::get_parent_towards(), TypeHandle::inc_memory_usage(), TypeHandle::is_derived_from(), FactoryBase::make_instance(), FactoryBase::make_instance_more_general(), PT(), BamReader::read_handle(), BamWriter::record_obsolete_type_name(), register_dynamic_type(), register_type(), and reregister_types().
void TypeRegistry::record_alternate_name | ( | TypeHandle | type, |
const std::string & | name | ||
) |
Indicates an alternate name for the same type.
This is particularly useful when a type has changed names, since the type is stored in a Bam file by name; setting the original name as the alternate will allow the type to be correctly read from old Bam files.
Definition at line 189 of file typeRegistry.cxx.
Referenced by BamWriter::record_obsolete_type_name().
void TypeRegistry::record_derivation | ( | TypeHandle | child, |
TypeHandle | parent | ||
) |
Records that the type referenced by child inherits directly from the type referenced by parent.
In the event of multiple inheritance, this should be called once for each parent class.
Definition at line 159 of file typeRegistry.cxx.
TypeHandle TypeRegistry::register_dynamic_type | ( | const std::string & | name | ) |
Registers a new type on-the-fly, presumably at runtime.
A new TypeHandle is returned if the typename was not seen before; otherwise the same TypeHandle that was last used for this typename is returned.
Definition at line 121 of file typeRegistry.cxx.
Referenced by BamReader::read_handle(), and register_dynamic_type().
bool TypeRegistry::register_type | ( | TypeHandle & | type_handle, |
const std::string & | name | ||
) |
Creates a new Type of the given name and assigns a unique value to the type_handle.
All type names must be unique. If the type name has already been used, the supplied type_handle value must match the name's assigned type_handle or an error is triggered. Returns true if the name wasn't defined before, false if it was.
Definition at line 39 of file typeRegistry.cxx.
Referenced by register_type().
|
static |
Walks through the TypeRegistry tree and makes sure that each type that was previously registered is *still* registered.
This seems to get broken in certain circumstances when compiled against libc5–it is as if the static initializer stomps on the _type_handle values of each class after they've been registered.
Definition at line 486 of file typeRegistry.cxx.
References ptr().
void TypeRegistry::write | ( | std::ostream & | out | ) | const |
Makes an attempt to format the entire TypeRegistry in a nice way that shows the derivation tree as intelligently as possible.
Definition at line 508 of file typeRegistry.cxx.
int TypeRegistry::get_num_root_classes |
Returns the number of root classes–that is, classes that do not inherit from any other classes–known in the system.
Definition at line 65 of file typeRegistry.h.
int TypeRegistry::get_num_typehandles |
Returns the total number of unique TypeHandles in the system.
Definition at line 61 of file typeRegistry.h.
TypeHandle TypeRegistry::get_root_class |
Returns the nth root class in the system.
See get_num_root_classes().
Definition at line 65 of file typeRegistry.h.
TypeHandle TypeRegistry::get_typehandle |
Returns the nth TypeHandle in the system.
See get_num_typehandles().
Definition at line 61 of file typeRegistry.h.