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