Panda3D

configVariableList.I

00001 // Filename: configVariableList.I
00002 // Created by:  drose (20Oct04)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 
00016 ////////////////////////////////////////////////////////////////////
00017 //     Function: ConfigVariableList::Destructor
00018 //       Access: Published
00019 //  Description: 
00020 ////////////////////////////////////////////////////////////////////
00021 INLINE ConfigVariableList::
00022 ~ConfigVariableList() {
00023 }
00024 
00025 ////////////////////////////////////////////////////////////////////
00026 //     Function: ConfigVariableList::Constructor
00027 //       Access: Published
00028 //  Description: 
00029 ////////////////////////////////////////////////////////////////////
00030 INLINE ConfigVariableList::
00031 ConfigVariableList(const string &name, 
00032                    const string &description, int flags) :
00033 #ifdef PRC_SAVE_DESCRIPTIONS
00034   ConfigVariableBase(name, VT_list, description, flags)
00035 #else
00036   ConfigVariableBase(name, VT_list, string(), flags)
00037 #endif
00038 {
00039   // A list variable implicitly defines a default value of the empty
00040   // string.  This is just to prevent the core variable from
00041   // complaining should anyone ask for its solitary value.
00042   if (_core->get_default_value() == (ConfigDeclaration *)NULL) {
00043     _core->set_default_value("");
00044   }
00045   _core->set_used();
00046 }
00047 
00048 ////////////////////////////////////////////////////////////////////
00049 //     Function: ConfigVariableList::get_num_values
00050 //       Access: Published
00051 //  Description: Returns the number of values in the variable.
00052 ////////////////////////////////////////////////////////////////////
00053 INLINE int ConfigVariableList::
00054 get_num_values() const {
00055   nassertr(_core != (ConfigVariableCore *)NULL, 0);
00056   return _core->get_num_trusted_references();
00057 }
00058 
00059 ////////////////////////////////////////////////////////////////////
00060 //     Function: ConfigVariableList::get_string_value
00061 //       Access: Published
00062 //  Description: Returns the nth value of the variable.
00063 ////////////////////////////////////////////////////////////////////
00064 INLINE string ConfigVariableList::
00065 get_string_value(int n) const {
00066   nassertr(_core != (ConfigVariableCore *)NULL, string());
00067   const ConfigDeclaration *decl = _core->get_trusted_reference(n);
00068   if (decl != (ConfigDeclaration *)NULL) {
00069     return decl->get_string_value();
00070   }
00071   return string();
00072 }
00073 
00074 ////////////////////////////////////////////////////////////////////
00075 //     Function: ConfigVariableList::get_num_unique_values
00076 //       Access: Published
00077 //  Description: Returns the number of unique values in the variable.
00078 ////////////////////////////////////////////////////////////////////
00079 INLINE int ConfigVariableList::
00080 get_num_unique_values() const {
00081   nassertr(_core != (ConfigVariableCore *)NULL, 0);
00082   return _core->get_num_unique_references();
00083 }
00084 
00085 ////////////////////////////////////////////////////////////////////
00086 //     Function: ConfigVariableList::get_unique_value
00087 //       Access: Published
00088 //  Description: Returns the nth unique value of the variable.
00089 ////////////////////////////////////////////////////////////////////
00090 INLINE string ConfigVariableList::
00091 get_unique_value(int n) const {
00092   nassertr(_core != (ConfigVariableCore *)NULL, string());
00093   const ConfigDeclaration *decl = _core->get_unique_reference(n);
00094   if (decl != (ConfigDeclaration *)NULL) {
00095     return decl->get_string_value();
00096   }
00097   return string();
00098 }
00099 
00100 ////////////////////////////////////////////////////////////////////
00101 //     Function: ConfigVariableList::size()
00102 //       Access: Published
00103 //  Description: Returns the number of unique values of the variable.
00104 ////////////////////////////////////////////////////////////////////
00105 INLINE int ConfigVariableList::
00106 size() const {
00107   return get_num_unique_values();
00108 }
00109 
00110 ////////////////////////////////////////////////////////////////////
00111 //     Function: ConfigVariableList::operator []
00112 //       Access: Published
00113 //  Description: Returns the nth unique value of the variable.  Note
00114 //               that the indexing operator returns the list of unique
00115 //               values, and so the maximum range is
00116 //               get_num_unique_values().
00117 ////////////////////////////////////////////////////////////////////
00118 INLINE string ConfigVariableList::
00119 operator [] (int n) const {
00120   return get_unique_value(n);
00121 }
00122 
00123 INLINE ostream &
00124 operator << (ostream &out, const ConfigVariableList &variable) {
00125   variable.output(out);
00126   return out;
00127 }
 All Classes Functions Variables Enumerations