Panda3D
factory.I
1 // Filename: factory.I
2 // Created by: drose (08May00)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 ////////////////////////////////////////////////////////////////////
16 // Function: Factory::make_instance
17 // Access: Public
18 // Description: Attempts to create a new instance of some class of
19 // the indicated type, or some derivative if necessary.
20 // If an instance of the exact type cannot be created,
21 // the specified preferred will specify which derived
22 // class will be preferred.
23 ////////////////////////////////////////////////////////////////////
24 template<class Type>
25 INLINE Type *Factory<Type>::
26 make_instance(TypeHandle handle, const FactoryParams &params) {
27  return (Type *)FactoryBase::make_instance(handle, params);
28 }
29 
30 ////////////////////////////////////////////////////////////////////
31 // Function: Factory::make_instance
32 // Access: Public
33 // Description: Attempts to create a new instance of some class of
34 // the indicated type, or some derivative if necessary.
35 // If an instance of the exact type cannot be created,
36 // the specified preferred will specify which derived
37 // class will be preferred.
38 //
39 // This flavor of make_instance() accepts a string name
40 // that indicates the desired type. It must be the name
41 // of some already-registered type.
42 ////////////////////////////////////////////////////////////////////
43 template<class Type>
44 INLINE Type *Factory<Type>::
45 make_instance(const string &type_name, const FactoryParams &params) {
46  return (Type *)FactoryBase::make_instance(type_name, params);
47 }
48 
49 ////////////////////////////////////////////////////////////////////
50 // Function: Factory::make_instance_more_general
51 // Access: Public
52 // Description: Attempts to create an instance of the type requested,
53 // or some base type of the type requested. Returns the
54 // new instance created, or NULL if the instance could
55 // not be created.
56 ////////////////////////////////////////////////////////////////////
57 template<class Type>
58 INLINE Type *Factory<Type>::
60  return (Type *)FactoryBase::make_instance_more_general(handle, params);
61 }
62 
63 ////////////////////////////////////////////////////////////////////
64 // Function: Factory::make_instance_more_general
65 // Access: Public
66 // Description: Attempts to create an instance of the type requested,
67 // or some base type of the type requested. Returns the
68 // new instance created, or NULL if the instance could
69 // not be created.
70 //
71 // This flavor of make_instance_more_general() accepts a
72 // string name that indicates the desired type. It must
73 // be the name of some already-registered type.
74 ////////////////////////////////////////////////////////////////////
75 template<class Type>
76 INLINE Type *Factory<Type>::
77 make_instance_more_general(const string &type_name,
78  const FactoryParams &params) {
79  return (Type *)FactoryBase::make_instance_more_general(type_name, params);
80 }
81 
82 ////////////////////////////////////////////////////////////////////
83 // Function: Factory::register_factory
84 // Access: Public
85 // Description: Registers a new kind of thing the Factory will be
86 // able to create.
87 ////////////////////////////////////////////////////////////////////
88 template<class Type>
89 INLINE void Factory<Type>::
90 register_factory(TypeHandle handle, CreateFunc *func) {
91  FactoryBase::register_factory(handle, (BaseCreateFunc *)func);
92 }
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:47
void register_factory(TypeHandle handle, BaseCreateFunc *func)
Registers a new kind of thing the Factory will be able to create.
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:59
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:40
void register_factory(TypeHandle handle, CreateFunc *func)
Registers a new kind of thing the Factory will be able to create.
Definition: factory.I:90
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:26
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
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:78