Panda3D
factoryParams.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 factoryParams.h
10  * @author drose
11  * @date 2000-05-08
12  */
13 
14 #ifndef FACTORYPARAMS_H
15 #define FACTORYPARAMS_H
16 
17 #include "pandabase.h"
18 
19 #include "typedObject.h"
20 #include "typedReferenceCount.h"
21 #include "pointerTo.h"
22 #include "factoryParam.h"
23 #include "dcast.h"
24 
25 #include "pvector.h"
26 
27 /**
28  * An instance of this class is passed to the Factory when requesting it to do
29  * its business and construct a new something. It can be filled with optional
30  * parameters to the CreateFunc for the particular subclass the Factory will
31  * be creating.
32  *
33  * This is just a vector of pointers to *something*; it will be up to the
34  * individual CreateFuncs to interpret this meaningfully.
35  */
36 class EXPCL_PANDA_PUTIL FactoryParams {
37 public:
38  FactoryParams() = default;
39  FactoryParams(const FactoryParams &copy) = default;
40  FactoryParams(FactoryParams &&from) noexcept = default;
41  ~FactoryParams() = default;
42 
43  FactoryParams &operator = (FactoryParams &&from) noexcept = default;
44 
45  void add_param(FactoryParam *param);
46  void clear();
47 
48  int get_num_params() const;
49  FactoryParam *get_param(int n) const;
50 
51  FactoryParam *get_param_of_type(TypeHandle type) const;
52 
53  INLINE void *get_user_data() const;
54 
55 private:
56  typedef pvector< PT(TypedReferenceCount) > Params;
57 
58  Params _params;
59  void *_user_data = nullptr;
60 
61  friend class FactoryBase;
62 };
63 
64 template<class ParamType>
65 INLINE bool get_param_into(ParamType *&pointer, const FactoryParams &params);
66 
67 #include "factoryParams.I"
68 
69 #endif
pvector
This is our own Panda specialization on the default STL vector.
Definition: pvector.h:42
FactoryParam
The base class of any number of specific pieces of parameter information that might be passed to a Fa...
Definition: factoryParam.h:30
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pvector.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
dcast.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
FactoryBase
A Factory can be used to create an instance of a particular subclass of some general base class.
Definition: factoryBase.h:36
TypedReferenceCount
A base class for things which need to inherit from both TypedObject and from ReferenceCount.
Definition: typedReferenceCount.h:31
factoryParam.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
FactoryParams
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:36
typedObject.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
typedReferenceCount.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
factoryParams.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_param_into
bool get_param_into(ParamType *&pointer, const FactoryParams &params)
A handy convenience template function that extracts a parameter of the indicated type from the Factor...
Definition: factoryParams.I:31
pointerTo.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.