Panda3D
configVariableList.I
1 // Filename: configVariableList.I
2 // Created by: drose (20Oct04)
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 
16 ////////////////////////////////////////////////////////////////////
17 // Function: ConfigVariableList::Destructor
18 // Access: Published
19 // Description:
20 ////////////////////////////////////////////////////////////////////
21 INLINE ConfigVariableList::
22 ~ConfigVariableList() {
23 }
24 
25 ////////////////////////////////////////////////////////////////////
26 // Function: ConfigVariableList::Constructor
27 // Access: Published
28 // Description:
29 ////////////////////////////////////////////////////////////////////
30 INLINE ConfigVariableList::
31 ConfigVariableList(const string &name,
32  const string &description, int flags) :
33 #ifdef PRC_SAVE_DESCRIPTIONS
34  ConfigVariableBase(name, VT_list, description, flags)
35 #else
36  ConfigVariableBase(name, VT_list, string(), flags)
37 #endif
38 {
39  // A list variable implicitly defines a default value of the empty
40  // string. This is just to prevent the core variable from
41  // complaining should anyone ask for its solitary value.
42  if (_core->get_default_value() == (ConfigDeclaration *)NULL) {
43  _core->set_default_value("");
44  }
45  _core->set_used();
46 }
47 
48 ////////////////////////////////////////////////////////////////////
49 // Function: ConfigVariableList::get_num_values
50 // Access: Published
51 // Description: Returns the number of values in the variable.
52 ////////////////////////////////////////////////////////////////////
53 INLINE int ConfigVariableList::
54 get_num_values() const {
55  nassertr(_core != (ConfigVariableCore *)NULL, 0);
56  return _core->get_num_trusted_references();
57 }
58 
59 ////////////////////////////////////////////////////////////////////
60 // Function: ConfigVariableList::get_string_value
61 // Access: Published
62 // Description: Returns the nth value of the variable.
63 ////////////////////////////////////////////////////////////////////
64 INLINE string ConfigVariableList::
65 get_string_value(int n) const {
66  nassertr(_core != (ConfigVariableCore *)NULL, string());
67  const ConfigDeclaration *decl = _core->get_trusted_reference(n);
68  if (decl != (ConfigDeclaration *)NULL) {
69  return decl->get_string_value();
70  }
71  return string();
72 }
73 
74 ////////////////////////////////////////////////////////////////////
75 // Function: ConfigVariableList::get_num_unique_values
76 // Access: Published
77 // Description: Returns the number of unique values in the variable.
78 ////////////////////////////////////////////////////////////////////
79 INLINE int ConfigVariableList::
81  nassertr(_core != (ConfigVariableCore *)NULL, 0);
82  return _core->get_num_unique_references();
83 }
84 
85 ////////////////////////////////////////////////////////////////////
86 // Function: ConfigVariableList::get_unique_value
87 // Access: Published
88 // Description: Returns the nth unique value of the variable.
89 ////////////////////////////////////////////////////////////////////
90 INLINE string ConfigVariableList::
91 get_unique_value(int n) const {
92  nassertr(_core != (ConfigVariableCore *)NULL, string());
93  const ConfigDeclaration *decl = _core->get_unique_reference(n);
94  if (decl != (ConfigDeclaration *)NULL) {
95  return decl->get_string_value();
96  }
97  return string();
98 }
99 
100 ////////////////////////////////////////////////////////////////////
101 // Function: ConfigVariableList::size()
102 // Access: Published
103 // Description: Returns the number of unique values of the variable.
104 ////////////////////////////////////////////////////////////////////
105 INLINE int ConfigVariableList::
106 size() const {
107  return get_num_unique_values();
108 }
109 
110 ////////////////////////////////////////////////////////////////////
111 // Function: ConfigVariableList::operator []
112 // Access: Published
113 // Description: Returns the nth unique value of the variable. Note
114 // that the indexing operator returns the list of unique
115 // values, and so the maximum range is
116 // get_num_unique_values().
117 ////////////////////////////////////////////////////////////////////
118 INLINE string ConfigVariableList::
119 operator [] (int n) const {
120  return get_unique_value(n);
121 }
122 
123 INLINE ostream &
124 operator << (ostream &out, const ConfigVariableList &variable) {
125  variable.output(out);
126  return out;
127 }
int size() const
Returns the number of unique values of the variable.
The internal definition of a ConfigVariable.
int 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.
string get_string_value(int n) const
Returns the nth value of the variable.
string get_unique_value(int n) const
Returns the nth unique value of the variable.
int get_num_unique_values() const
Returns the number of unique values in the variable.
This class is the base class for both ConfigVariableList and ConfigVariable (and hence for all of the...
string operator[](int n) const
Returns the nth unique value of the variable.
A single declaration of a config variable, typically defined as one line in a .prc file...
const string & get_string_value() const
Returns the value assigned to this variable.