Panda3D
Loading...
Searching...
No Matches
factoryParams.cxx
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.cxx
10 * @author drose
11 * @date 2000-05-08
12 */
13
14#include "factoryParams.h"
15
16/**
17 *
18 */
19void FactoryParams::
20add_param(FactoryParam *param) {
21 nassertv(param != nullptr);
22 _params.push_back(param);
23}
24
25/**
26 * Removes all parameters from the set.
27 */
29clear() {
30 _params.clear();
31}
32
33/**
34 * Returns the number of parameters that have been added to the set.
35 */
37get_num_params() const {
38 return _params.size();
39}
40
41/**
42 * Returns the nth parameter that has been added to the set.
43 */
45get_param(int n) const {
46 nassertr(n >= 0 && n < (int)_params.size(), nullptr);
47 return DCAST(FactoryParam, _params[n]);
48}
49
50/**
51 * Returns the first parameter that matches exactly the indicated type, or if
52 * there are no exact matches, returns the first one that derives from the
53 * indicated type. If no parameters match at all, returns NULL.
54 */
56get_param_of_type(TypeHandle type) const {
57 Params::const_iterator pi;
58
59 // First, search for the exact match.
60 for (pi = _params.begin(); pi != _params.end(); ++pi) {
61 FactoryParam *param;
62 DCAST_INTO_R(param, *pi, nullptr);
63 nassertr(param != nullptr, nullptr);
64
65 if (param->is_exact_type(type)) {
66 return param;
67 }
68 }
69
70 // Now, search for a derived match.
71 for (pi = _params.begin(); pi != _params.end(); ++pi) {
72 FactoryParam *param;
73 DCAST_INTO_R(param, *pi, nullptr);
74 nassertr(param != nullptr, nullptr);
75
76 if (param->is_of_type(type)) {
77 return param;
78 }
79 }
80
81 return nullptr;
82}
The base class of any number of specific pieces of parameter information that might be passed to a Fa...
int get_num_params() const
Returns the number of parameters that have been added to the set.
FactoryParam * get_param(int n) const
Returns the nth parameter that has been added to the set.
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...
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
bool is_exact_type(TypeHandle handle) const
Returns true if the current object is the indicated type exactly.
Definition typedObject.I:38
bool is_of_type(TypeHandle handle) const
Returns true if the current object is or derives from the indicated type.
Definition typedObject.I:28
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.