Panda3D
factory.h
1 // Filename: factory.h
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 #ifndef FACTORY_H
16 #define FACTORY_H
17 
18 #include "pandabase.h"
19 
20 #include "factoryBase.h"
21 
22 ////////////////////////////////////////////////////////////////////
23 // Class : Factory
24 // Description : A Factory can be used to create an instance of a
25 // particular subclass of some general base class. Each
26 // subclass registers itself with the Factory, supplying
27 // a function that will construct an instance of that
28 // subclass; the Factory can later choose a suitable
29 // subclass and return a newly-constructed pointer to an
30 // object of that type on the user's demand. This is
31 // used, for instance, to manage the set of
32 // GraphicsPipes available to the user.
33 //
34 // This is a thin template wrapper around FactoryBase.
35 // All it does is ensure the types are correctly cast.
36 // All of its methods are inline, and it has no data
37 // members, so it is not necessary to export the class
38 // from the DLL.
39 ////////////////////////////////////////////////////////////////////
40 template<class Type>
41 class Factory : public FactoryBase {
42 public:
43  typedef Type *CreateFunc(const FactoryParams &params);
44 
45  INLINE Type *make_instance(TypeHandle handle,
46  const FactoryParams &params = FactoryParams());
47 
48  INLINE Type *make_instance(const string &type_name,
49  const FactoryParams &params = FactoryParams());
50 
51  INLINE Type *
53  const FactoryParams &params = FactoryParams());
54 
55  INLINE Type *
56  make_instance_more_general(const string &type_name,
57  const FactoryParams &params = FactoryParams());
58 
59  INLINE void register_factory(TypeHandle handle, CreateFunc *func);
60 };
61 
62 #include "factory.I"
63 
64 #endif
65 
A Factory can be used to create an instance of a particular subclass of some general base class...
Definition: factory.h:41
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
A Factory can be used to create an instance of a particular subclass of some general base class...
Definition: factoryBase.h:42
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