Panda3D
factory.I
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 factory.I
10  * @author drose
11  * @date 2000-05-08
12  */
13 
14 /**
15  * Attempts to create a new instance of some class of the indicated type, or
16  * some derivative if necessary. If an instance of the exact type cannot be
17  * created, the specified preferred will specify which derived class will be
18  * preferred.
19  */
20 template<class Type>
21 INLINE Type *Factory<Type>::
22 make_instance(TypeHandle handle, const FactoryParams &params) {
23  return (Type *)FactoryBase::make_instance(handle, params);
24 }
25 
26 /**
27  * Attempts to create a new instance of some class of the indicated type, or
28  * some derivative if necessary. If an instance of the exact type cannot be
29  * created, the specified preferred will specify which derived class will be
30  * preferred.
31  *
32  * This flavor of make_instance() accepts a string name that indicates the
33  * desired type. It must be the name of some already-registered type.
34  */
35 template<class Type>
36 INLINE Type *Factory<Type>::
37 make_instance(const std::string &type_name, const FactoryParams &params) {
38  return (Type *)FactoryBase::make_instance(type_name, params);
39 }
40 
41 /**
42  * Attempts to create an instance of the type requested, or some base type of
43  * the type requested. Returns the new instance created, or NULL if the
44  * instance could not be created.
45  */
46 template<class Type>
47 INLINE Type *Factory<Type>::
49  return (Type *)FactoryBase::make_instance_more_general(handle, params);
50 }
51 
52 /**
53  * Attempts to create an instance of the type requested, or some base type of
54  * the type requested. Returns the new instance created, or NULL if the
55  * instance could not be created.
56  *
57  * This flavor of make_instance_more_general() accepts a string name that
58  * indicates the desired type. It must be the name of some already-registered
59  * type.
60  */
61 template<class Type>
62 INLINE Type *Factory<Type>::
63 make_instance_more_general(const std::string &type_name,
64  const FactoryParams &params) {
65  return (Type *)FactoryBase::make_instance_more_general(type_name, params);
66 }
67 
68 /**
69  * Registers a new kind of thing the Factory will be able to create.
70  */
71 template<class Type>
72 INLINE void Factory<Type>::
73 register_factory(TypeHandle handle, CreateFunc *func, void *user_data) {
74  FactoryBase::register_factory(handle, (BaseCreateFunc *)func, user_data);
75 }
TypedObject * make_instance(TypeHandle handle, const FactoryParams &params)
Attempts to create a new instance of some class of the indicated type, or some derivative if necessar...
Definition: factoryBase.cxx:25
Type * make_instance_more_general(TypeHandle handle, const FactoryParams &params=FactoryParams())
Attempts to create an instance of the type requested, or some base type of the type requested.
Definition: factory.I:48
void register_factory(TypeHandle handle, BaseCreateFunc *func, void *user_data=nullptr)
Registers a new kind of thing the Factory will be able to create.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:36
void register_factory(TypeHandle handle, CreateFunc *func, void *user_data=nullptr)
Registers a new kind of thing the Factory will be able to create.
Definition: factory.I:73
Type * make_instance(TypeHandle handle, const FactoryParams &params=FactoryParams())
Attempts to create a new instance of some class of the indicated type, or some derivative if necessar...
Definition: factory.I:22
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
TypedObject * make_instance_more_general(TypeHandle handle, const FactoryParams &params)
Attempts to create an instance of the type requested, or some base type of the type requested.
Definition: factoryBase.cxx:53