Panda3D
Loading...
Searching...
No Matches
typeRegistry.h
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file typeRegistry.h
10 * @author drose
11 * @date 2001-08-06
12 */
13
14#ifndef TYPEREGISTRY_H
15#define TYPEREGISTRY_H
16
17#include "dtoolbase.h"
18#include "mutexImpl.h"
19#include "memoryBase.h"
20
21#include <set>
22#include <map>
23#include <vector>
24
25class TypeHandle;
27class TypedObject;
28
29/**
30 * The TypeRegistry class maintains all the assigned TypeHandles in a given
31 * system. There should be only one TypeRegistry class during the lifetime of
32 * the application. It will be created on the local heap initially, and it
33 * should be migrated to shared memory as soon as shared memory becomes
34 * available.
35 */
36class EXPCL_DTOOL_DTOOLBASE TypeRegistry : public MemoryBase {
37public:
38 // User code shouldn't generally need to call TypeRegistry::register_type()
39 // or record_derivation() directly; instead, use the register_type
40 // convenience function, defined in register_type.h.
41 bool register_type(TypeHandle &type_handle, const std::string &name);
42
43PUBLISHED:
44 TypeHandle register_dynamic_type(const std::string &name);
45
46 void record_derivation(TypeHandle child, TypeHandle parent);
47 void record_alternate_name(TypeHandle type, const std::string &name);
48#ifdef HAVE_PYTHON
49 void record_python_type(TypeHandle type, PyObject *python_type);
50#endif
51
52 TypeHandle find_type(const std::string &name) const;
53 TypeHandle find_type_by_id(int id) const;
54
55 std::string get_name(TypeHandle type, TypedObject *object) const;
56 bool is_derived_from(TypeHandle child, TypeHandle base,
57 TypedObject *child_object);
58
59 int get_num_typehandles();
60 TypeHandle get_typehandle(int n);
61 MAKE_SEQ(get_typehandles, get_num_typehandles, get_typehandle);
62
63 int get_num_root_classes();
64 TypeHandle get_root_class(int n);
65 MAKE_SEQ(get_root_classes, get_num_root_classes, get_root_class);
66
67 int get_num_parent_classes(TypeHandle child,
68 TypedObject *child_object) const;
69 TypeHandle get_parent_class(TypeHandle child, int index) const;
70
71 int get_num_child_classes(TypeHandle child,
72 TypedObject *child_object) const;
73 TypeHandle get_child_class(TypeHandle child, int index) const;
74
75 TypeHandle get_parent_towards(TypeHandle child, TypeHandle base,
76 TypedObject *child_object);
77
78 static void reregister_types();
79
80 void write(std::ostream &out) const;
81
82 // ptr() returns the pointer to the global TypeRegistry object.
83 static INLINE TypeRegistry *ptr();
84
85 MAKE_SEQ_PROPERTY(typehandles, get_num_typehandles, get_typehandle);
86 MAKE_SEQ_PROPERTY(root_classes, get_num_root_classes, get_root_class);
87
88private:
89 // The TypeRegistry class should never be constructed by user code. There
90 // is only one in the universe, and it constructs itself!
92
93 static void init_global_pointer();
94 INLINE TypeRegistryNode *look_up(TypeHandle type, TypedObject *object) const;
95 TypeRegistryNode *look_up_invalid(TypeHandle type, TypedObject *object) const;
96
97 INLINE void freshen_derivations();
98 void rebuild_derivations();
99
100 void do_write(std::ostream &out) const;
101 void write_node(std::ostream &out, int indent_level,
102 const TypeRegistryNode *node) const;
103
104 static INLINE void init_lock();
105
106 typedef std::vector<TypeRegistryNode *> HandleRegistry;
107 HandleRegistry _handle_registry;
108
109 typedef std::map<std::string, TypeRegistryNode *> NameRegistry;
110 NameRegistry _name_registry;
111
112 typedef std::vector<TypeRegistryNode *> RootClasses;
113 RootClasses _root_classes;
114
115 bool _derivations_fresh;
116
117 static MutexImpl *_lock;
118 static TypeRegistry *_global_pointer;
119
120 friend class TypeHandle;
121};
122
123// Helper function to allow for "C" interaction into the type system
124extern "C" EXPCL_DTOOL_DTOOLBASE int get_best_parent_from_Set(int id, const std::set<int> &this_set);
125
126#include "typeHandle.h"
127
128#include "typeRegistry.I"
129
130#endif
This class is intended to be the base class of all objects in Panda that might be allocated and delet...
Definition memoryBase.h:65
A fake mutex implementation for single-threaded applications that don't need any synchronization cont...
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
int get_best_parent_from_Set(const std::set< int > &legal_vals) const
Return the Index of the BEst fit Classs from a set.
This is a single entry in the TypeRegistry.
The TypeRegistry class maintains all the assigned TypeHandles in a given system.
This is an abstract class that all classes which use TypeHandle, and also provide virtual functions t...
Definition typedObject.h:88
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
TypeHandle register_dynamic_type(const std::string &name)
This is essentially similar to register_type(), except that it doesn't store a reference to any TypeH...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.