Panda3D
configVariableList.I
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 configVariableList.I
10  * @author drose
11  * @date 2004-10-20
12  */
13 
14 /**
15  *
16  */
17 INLINE ConfigVariableList::
18 ~ConfigVariableList() {
19 }
20 
21 /**
22  *
23  */
24 INLINE ConfigVariableList::
25 ConfigVariableList(const std::string &name,
26  const std::string &description, int flags) :
27 #ifdef PRC_SAVE_DESCRIPTIONS
28  ConfigVariableBase(name, VT_list, description, flags)
29 #else
30  ConfigVariableBase(name, VT_list, std::string(), flags)
31 #endif
32 {
33  // A list variable implicitly defines a default value of the empty string.
34  // This is just to prevent the core variable from complaining should anyone
35  // ask for its solitary value.
36  if (_core->get_default_value() == nullptr) {
37  _core->set_default_value("");
38  }
39  _core->set_used();
40 }
41 
42 /**
43  * Returns the number of values in the variable.
44  */
45 INLINE size_t ConfigVariableList::
46 get_num_values() const {
47  nassertr(_core != nullptr, 0);
48  return _core->get_num_trusted_references();
49 }
50 
51 /**
52  * Returns the nth value of the variable.
53  */
54 INLINE std::string ConfigVariableList::
55 get_string_value(size_t n) const {
56  nassertr(_core != nullptr, std::string());
57  const ConfigDeclaration *decl = _core->get_trusted_reference(n);
58  if (decl != nullptr) {
59  return decl->get_string_value();
60  }
61  return std::string();
62 }
63 
64 /**
65  * Returns the number of unique values in the variable.
66  */
67 INLINE size_t ConfigVariableList::
69  nassertr(_core != nullptr, 0);
70  return _core->get_num_unique_references();
71 }
72 
73 /**
74  * Returns the nth unique value of the variable.
75  */
76 INLINE std::string ConfigVariableList::
77 get_unique_value(size_t n) const {
78  nassertr(_core != nullptr, std::string());
79  const ConfigDeclaration *decl = _core->get_unique_reference(n);
80  if (decl != nullptr) {
81  return decl->get_string_value();
82  }
83  return std::string();
84 }
85 
86 /**
87  * Returns the number of unique values of the variable.
88  */
89 INLINE size_t ConfigVariableList::
90 size() const {
91  return get_num_unique_values();
92 }
93 
94 /**
95  * Returns the nth unique value of the variable. Note that the indexing
96  * operator returns the list of unique values, and so the maximum range is
97  * get_num_unique_values().
98  */
99 INLINE std::string ConfigVariableList::
100 operator [] (size_t n) const {
101  return get_unique_value(n);
102 }
103 
104 INLINE std::ostream &
105 operator << (std::ostream &out, const ConfigVariableList &variable) {
106  variable.output(out);
107  return out;
108 }
const std::string & get_string_value() const
Returns the value assigned to this variable.
size_t get_num_unique_values() const
Returns the number of unique values in the variable.
size_t get_num_values() const
Returns the number of values in the variable.
This class is similar to ConfigVariable, but it reports its value as a list of strings.
std::string operator [](size_t n) const
Returns the nth unique value of the variable.
size_t size() const
Returns the number of unique values of the variable.
std::string get_string_value(size_t n) const
Returns the nth value of the variable.
std::string get_unique_value(size_t n) const
Returns the nth unique value of the variable.
This class is the base class for both ConfigVariableList and ConfigVariable (and hence for all of the...
A single declaration of a config variable, typically defined as one line in a .prc file,...