28 instance = make_instance_exact(handle, params);
29 if (instance ==
nullptr) {
31 instance = make_instance_more_specific(handle, params);
34 if (util_cat.is_debug()) {
36 <<
"make_instance(" << handle <<
", params) returns " 38 if (instance !=
nullptr) {
40 <<
", of type " << instance->get_type();
42 util_cat.debug(
false) <<
"\n";
54 TypedObject *
object = make_instance_exact(handle, params);
56 if (
object ==
nullptr) {
64 for (
int i = 0; i < num_parents &&
object ==
nullptr; i++) {
69 if (util_cat.is_debug()) {
71 <<
"make_instance(" << handle <<
", params) returns " 73 if (
object !=
nullptr) {
75 <<
", of type " <<
object->get_type();
77 util_cat.debug(
false) <<
"\n";
91 Creators::const_iterator ci = _creators.find(handle);
92 if (ci != _creators.end()) {
100 return TypeHandle::none();
104 for (
int i = 0; i < num_parents; i++) {
106 if (result != TypeHandle::none()) {
112 return TypeHandle::none();
122 nassertv(handle != TypeHandle::none());
123 nassertv(func !=
nullptr);
126 creator._func = func;
127 creator._user_data = user_data;
128 _creators[handle] = creator;
136 return _creators.size();
147 Creators::const_iterator ci;
148 for (ci = _creators.begin(); ci != _creators.end(); ++ci) {
156 nassertr(
false, TypeHandle::none());
157 return TypeHandle::none();
175 nassertv(handle != TypeHandle::none());
176 _preferred.push_back(handle);
184 return _preferred.size();
193 return _preferred[n];
202 Creators::const_iterator ci;
203 for (ci = _creators.begin(); ci != _creators.end(); ++ci) {
204 indent(out, indent_level) << (*ci).first <<
"\n";
215 Creators::const_iterator ci = _creators.find(handle);
216 if (ci == _creators.end()) {
220 Creator creator = (*ci).second;
221 nassertr(creator._func !=
nullptr,
nullptr);
222 params._user_data = creator._user_data;
223 return (*creator._func)(params);
237 if (ptype.is_derived_from(handle)) {
238 TypedObject *
object = make_instance_exact(ptype, params);
239 if (
object !=
nullptr) {
247 Creators::const_iterator ci;
248 for (ci = _creators.begin(); ci != _creators.end(); ++ci) {
251 Creator creator = (*ci).second;
252 nassertr(creator._func !=
nullptr,
nullptr);
253 params._user_data = creator._user_data;
255 if (
object !=
nullptr) {
size_t get_num_types() const
Returns the number of different types the Factory knows how to create.
TypeHandle get_type(size_t n) const
Returns the nth type the Factory knows how to create.
TypedObject * make_instance(TypeHandle handle, const FactoryParams ¶ms)
Attempts to create a new instance of some class of the indicated type, or some derivative if necessar...
size_t get_num_preferred() const
Returns the number of types added to the preferred-type list.
void register_factory(TypeHandle handle, BaseCreateFunc *func, void *user_data=nullptr)
Registers a new kind of thing the Factory will be able to create.
This is an abstract class that all classes which use TypeHandle, and also provide virtual functions t...
bool is_derived_from(TypeHandle parent, TypedObject *object=nullptr) const
Returns true if this type is derived from the indicated type, false otherwise.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void clear_preferred()
Empties the list of preferred types.
void write_types(std::ostream &out, int indent_level=0) const
Writes a list of all known types the Factory can create to the indicated output stream,...
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
get_parent_class
Returns the nth parent class of this type.
TypeHandle get_preferred(size_t n) const
Returns the nth type added to the preferred-type list.
get_num_parent_classes
Returns the number of parent classes that this type is known to have.
TypeHandle is the identifier used to differentiate C++ class types.
void add_preferred(TypeHandle handle)
Adds the indicated type to the end of the list of preferred types.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypeHandle find_registered_type(TypeHandle handle)
Returns the TypeHandle given, if it is a registered type, or if it is not registered,...
TypedObject * make_instance_more_general(TypeHandle handle, const FactoryParams ¶ms)
Attempts to create an instance of the type requested, or some base type of the type requested.