Panda3D
Loading...
Searching...
No Matches
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 */
17INLINE ConfigVariableList::
18~ConfigVariableList() {
19}
20
21/**
22 *
23 */
24INLINE ConfigVariableList::
25ConfigVariableList(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 */
46get_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 */
54INLINE std::string ConfigVariableList::
55get_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 */
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 */
76INLINE std::string ConfigVariableList::
77get_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 */
90size() 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 */
99INLINE std::string ConfigVariableList::
100operator [] (size_t n) const {
101 return get_unique_value(n);
102}
103
104INLINE std::ostream &
105operator << (std::ostream &out, const ConfigVariableList &variable) {
106 variable.output(out);
107 return out;
108}
A single declaration of a config variable, typically defined as one line in a .prc file,...
const std::string & get_string_value() const
Returns the value assigned to this variable.
This class is the base class for both ConfigVariableList and ConfigVariable (and hence for all of the...
This class is similar to ConfigVariable, but it reports its value as a list of strings.
std::string get_unique_value(size_t n) const
Returns the nth unique value of the variable.
size_t get_num_unique_values() const
Returns the number of unique values in the variable.
size_t size() const
Returns the number of unique values of the variable.
std::string operator[](size_t n) const
Returns the nth unique value of the variable.
size_t get_num_values() const
Returns the number of values in the variable.
std::string get_string_value(size_t n) const
Returns the nth value of the variable.
STL namespace.