Panda3D
 All Classes Functions Variables Enumerations
factoryParams.cxx
1 // Filename: factoryParams.cxx
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 #include "factoryParams.h"
16 
17 ////////////////////////////////////////////////////////////////////
18 // Function: FactoryParams::Constructor
19 // Access: Public
20 // Description:
21 ////////////////////////////////////////////////////////////////////
22 FactoryParams::
23 FactoryParams() {
24 }
25 
26 ////////////////////////////////////////////////////////////////////
27 // Function: FactoryParams::Destructor
28 // Access: Public
29 // Description:
30 ////////////////////////////////////////////////////////////////////
31 FactoryParams::
32 ~FactoryParams() {
33 }
34 
35 ////////////////////////////////////////////////////////////////////
36 // Function: FactoryParams::add_param
37 // Access: Public
38 // Description:
39 ////////////////////////////////////////////////////////////////////
40 void FactoryParams::
41 add_param(FactoryParam *param) {
42  nassertv(param != (FactoryParam *)NULL);
43  _params.push_back(param);
44 }
45 
46 ////////////////////////////////////////////////////////////////////
47 // Function: FactoryParams::clear
48 // Access: Public
49 // Description: Removes all parameters from the set.
50 ////////////////////////////////////////////////////////////////////
51 void FactoryParams::
52 clear() {
53  _params.clear();
54 }
55 
56 ////////////////////////////////////////////////////////////////////
57 // Function: FactoryParams::get_num_params
58 // Access: Public
59 // Description: Returns the number of parameters that have been added
60 // to the set.
61 ////////////////////////////////////////////////////////////////////
63 get_num_params() const {
64  return _params.size();
65 }
66 
67 ////////////////////////////////////////////////////////////////////
68 // Function: FactoryParams::get_param
69 // Access: Public
70 // Description: Returns the nth parameter that has been added to the
71 // set.
72 ////////////////////////////////////////////////////////////////////
74 get_param(int n) const {
75  nassertr(n >= 0 && n < (int)_params.size(), NULL);
76  return DCAST(FactoryParam, _params[n]);
77 }
78 
79 ////////////////////////////////////////////////////////////////////
80 // Function: FactoryParams::get_param_of_type
81 // Access: Public
82 // Description: Returns the first parameter that matches exactly the
83 // indicated type, or if there are no exact matches,
84 // returns the first one that derives from the indicated
85 // type. If no parameters match at all, returns NULL.
86 ////////////////////////////////////////////////////////////////////
89  Params::const_iterator pi;
90 
91  // First, search for the exact match.
92  for (pi = _params.begin(); pi != _params.end(); ++pi) {
93  FactoryParam *param;
94  DCAST_INTO_R(param, *pi, NULL);
95  nassertr(param != (FactoryParam *)NULL, NULL);
96 
97  if (param->is_exact_type(type)) {
98  return param;
99  }
100  }
101 
102  // Now, search for a derived match.
103  for (pi = _params.begin(); pi != _params.end(); ++pi) {
104  FactoryParam *param;
105  DCAST_INTO_R(param, *pi, NULL);
106  nassertr(param != (FactoryParam *)NULL, NULL);
107 
108  if (param->is_of_type(type)) {
109  return param;
110  }
111  }
112 
113  return NULL;
114 }
FactoryParam * get_param(int n) const
Returns the nth parameter that has been added to the set.
bool is_of_type(TypeHandle handle) const
Returns true if the current object is or derives from the indicated type.
Definition: typedObject.I:63
The base class of any number of specific pieces of parameter information that might be passed to a Fa...
Definition: factoryParam.h:34
bool is_exact_type(TypeHandle handle) const
Returns true if the current object is the indicated type exactly.
Definition: typedObject.I:74
void clear()
Removes all parameters from the set.
FactoryParam * get_param_of_type(TypeHandle type) const
Returns the first parameter that matches exactly the indicated type, or if there are no exact matches...
int get_num_params() const
Returns the number of parameters that have been added to the set.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85