Panda3D

configDeclaration.I

00001 // Filename: configDeclaration.I
00002 // Created by:  drose (15Oct04)
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: ConfigDeclaration::operator <
00018 //       Access: Public
00019 //  Description: Sorts two declarations in order based on the order in
00020 //               which their respective pages were loaded, and the
00021 //               order in which they appear within the same page.
00022 ////////////////////////////////////////////////////////////////////
00023 INLINE bool ConfigDeclaration::
00024 operator < (const ConfigDeclaration &other) const {
00025   if (get_page() == other.get_page()) {
00026     // On the same page, we compare based on the decl_seq.
00027     return get_decl_seq() < other.get_decl_seq();
00028   }
00029 
00030   // On different pages, we compare based on the page importance.
00031   return *get_page() < *other.get_page();
00032 }
00033 
00034 ////////////////////////////////////////////////////////////////////
00035 //     Function: ConfigDeclaration::get_page
00036 //       Access: Public
00037 //  Description: Returns the page on which this declaration can be
00038 //               found.
00039 ////////////////////////////////////////////////////////////////////
00040 INLINE ConfigPage *ConfigDeclaration::
00041 get_page() const {
00042   return _page;
00043 }
00044 
00045 ////////////////////////////////////////////////////////////////////
00046 //     Function: ConfigDeclaration::get_variable
00047 //       Access: Public
00048 //  Description: Returns the variable that this declaration names.
00049 //               This variable may or may not have been defined by the
00050 //               time the declaration is read.
00051 ////////////////////////////////////////////////////////////////////
00052 INLINE ConfigVariableCore *ConfigDeclaration::
00053 get_variable() const {
00054   return _variable;
00055 }
00056 
00057 ////////////////////////////////////////////////////////////////////
00058 //     Function: ConfigDeclaration::get_string_value
00059 //       Access: Public
00060 //  Description: Returns the value assigned to this variable.  This is
00061 //               the original one-line text defined for the variable
00062 //               in the .prc file (or passed to
00063 //               ConfigPage::make_declaration()).
00064 ////////////////////////////////////////////////////////////////////
00065 INLINE const string &ConfigDeclaration::
00066 get_string_value() const {
00067   return _string_value;
00068 }
00069 
00070 ////////////////////////////////////////////////////////////////////
00071 //     Function: ConfigDeclaration::set_string_value
00072 //       Access: Public
00073 //  Description: Changes the value assigned to this variable.
00074 ////////////////////////////////////////////////////////////////////
00075 INLINE void ConfigDeclaration::
00076 set_string_value(const string &string_value) {
00077   _string_value = string_value;
00078   _got_words = false;
00079   invalidate_cache();
00080 }
00081 
00082 ////////////////////////////////////////////////////////////////////
00083 //     Function: ConfigDeclaration::get_num_words
00084 //       Access: Public
00085 //  Description: Returns the number of words in the declaration's
00086 //               value.  A word is defined as a sequence of
00087 //               non-whitespace characters delimited by whitespace.
00088 ////////////////////////////////////////////////////////////////////
00089 INLINE int ConfigDeclaration::
00090 get_num_words() const {
00091   if (!_got_words) {
00092     ((ConfigDeclaration *)this)->get_words();
00093   }
00094   return _words.size();
00095 }
00096 
00097 ////////////////////////////////////////////////////////////////////
00098 //     Function: ConfigDeclaration::has_string_word
00099 //       Access: Public
00100 //  Description: Returns true if the declaration's value has a valid
00101 //               string value for the nth word.  This is really the
00102 //               same thing as asking if there are at least n words in
00103 //               the value.
00104 ////////////////////////////////////////////////////////////////////
00105 INLINE bool ConfigDeclaration::
00106 has_string_word(int n) const {
00107   if (!_got_words) {
00108     ((ConfigDeclaration *)this)->get_words();
00109   }
00110   return (n >= 0 && n < (int)_words.size());
00111 }
00112 
00113 ////////////////////////////////////////////////////////////////////
00114 //     Function: ConfigDeclaration::has_bool_word
00115 //       Access: Public
00116 //  Description: Returns true if the declaration's value has a valid
00117 //               boolean value for the nth word.
00118 ////////////////////////////////////////////////////////////////////
00119 INLINE bool ConfigDeclaration::
00120 has_bool_word(int n) const {
00121   if (has_string_word(n)) {
00122     ((ConfigDeclaration *)this)->check_bool_word(n);
00123     return (_words[n]._flags & F_valid_bool) != 0;
00124   }
00125   return false;
00126 }
00127 
00128 ////////////////////////////////////////////////////////////////////
00129 //     Function: ConfigDeclaration::has_int_word
00130 //       Access: Public
00131 //  Description: Returns true if the declaration's value has a valid
00132 //               integer value for the nth word.
00133 ////////////////////////////////////////////////////////////////////
00134 INLINE bool ConfigDeclaration::
00135 has_int_word(int n) const {
00136   if (has_string_word(n)) {
00137     ((ConfigDeclaration *)this)->check_int_word(n);
00138     return (_words[n]._flags & F_valid_int) != 0;
00139   }
00140   return false;
00141 }
00142 
00143 ////////////////////////////////////////////////////////////////////
00144 //     Function: ConfigDeclaration::has_int64_word
00145 //       Access: Public
00146 //  Description: Returns true if the declaration's value has a valid
00147 //               int64 value for the nth word.
00148 ////////////////////////////////////////////////////////////////////
00149 INLINE bool ConfigDeclaration::
00150 has_int64_word(int n) const {
00151   if (has_string_word(n)) {
00152     ((ConfigDeclaration *)this)->check_int64_word(n);
00153     return (_words[n]._flags & F_valid_int64) != 0;
00154   }
00155   return false;
00156 }
00157 
00158 ////////////////////////////////////////////////////////////////////
00159 //     Function: ConfigDeclaration::has_double_word
00160 //       Access: Public
00161 //  Description: Returns true if the declaration's value has a valid
00162 //               integer value for the nth word.
00163 ////////////////////////////////////////////////////////////////////
00164 INLINE bool ConfigDeclaration::
00165 has_double_word(int n) const {
00166   if (has_string_word(n)) {
00167     ((ConfigDeclaration *)this)->check_double_word(n);
00168     return (_words[n]._flags & F_valid_double) != 0;
00169   }
00170   return false;
00171 }
00172 
00173 ////////////////////////////////////////////////////////////////////
00174 //     Function: ConfigDeclaration::get_string_word
00175 //       Access: Public
00176 //  Description: Returns the string value of the nth word of the
00177 //               declaration's value, or empty string if there is no
00178 //               nth value.  See also has_string_word().
00179 ////////////////////////////////////////////////////////////////////
00180 INLINE string ConfigDeclaration::
00181 get_string_word(int n) const {
00182   if (has_string_word(n)) {
00183     return _words[n]._str;
00184   }
00185   return string();
00186 }
00187 
00188 ////////////////////////////////////////////////////////////////////
00189 //     Function: ConfigDeclaration::get_bool_word
00190 //       Access: Public
00191 //  Description: Returns the boolean value of the nth word of the
00192 //               declaration's value, or false if there is no nth
00193 //               value.  See also has_bool_word().
00194 ////////////////////////////////////////////////////////////////////
00195 INLINE bool ConfigDeclaration::
00196 get_bool_word(int n) const {
00197   // We use has_string_word() instead of has_bool_word(), so we can
00198   // return a partial answer if there was one.
00199   if (has_string_word(n)) {
00200     ((ConfigDeclaration *)this)->check_bool_word(n);
00201     return _words[n]._bool;
00202   }
00203   return false;
00204 }
00205 
00206 ////////////////////////////////////////////////////////////////////
00207 //     Function: ConfigDeclaration::get_int_word
00208 //       Access: Public
00209 //  Description: Returns the integer value of the nth word of the
00210 //               declaration's value, or 0 if there is no nth value.
00211 //               See also has_int_word().
00212 ////////////////////////////////////////////////////////////////////
00213 INLINE int ConfigDeclaration::
00214 get_int_word(int n) const {
00215   // We use has_string_word() instead of has_int_word(), so we can
00216   // return a partial answer if there was one.
00217   if (has_string_word(n)) {
00218     ((ConfigDeclaration *)this)->check_int_word(n);
00219     return _words[n]._int;
00220   }
00221   return 0;
00222 }
00223 
00224 ////////////////////////////////////////////////////////////////////
00225 //     Function: ConfigDeclaration::get_int64_word
00226 //       Access: Public
00227 //  Description: Returns the int64 value of the nth word of the
00228 //               declaration's value, or 0 if there is no nth value.
00229 //               See also has_int64_word().
00230 ////////////////////////////////////////////////////////////////////
00231 INLINE PN_int64 ConfigDeclaration::
00232 get_int64_word(int n) const {
00233   // We use has_string_word() instead of has_int64_word(), so we can
00234   // return a partial answer if there was one.
00235   if (has_string_word(n)) {
00236     ((ConfigDeclaration *)this)->check_int64_word(n);
00237     return _words[n]._int_64;
00238   }
00239   return 0;
00240 }
00241 
00242 ////////////////////////////////////////////////////////////////////
00243 //     Function: ConfigDeclaration::get_double_word
00244 //       Access: Public
00245 //  Description: Returns the integer value of the nth word of the
00246 //               declaration's value, or 0 if there is no nth value.
00247 //               See also has_double_word().
00248 ////////////////////////////////////////////////////////////////////
00249 INLINE double ConfigDeclaration::
00250 get_double_word(int n) const {
00251   // We use has_string_word() instead of has_double_word(), so we can
00252   // return a partial answer if there was one.
00253   if (has_string_word(n)) {
00254     ((ConfigDeclaration *)this)->check_double_word(n);
00255     return _words[n]._double;
00256   }
00257   return 0.0;
00258 }
00259 
00260 
00261 ////////////////////////////////////////////////////////////////////
00262 //     Function: ConfigDeclaration::get_decl_seq
00263 //       Access: Public
00264 //  Description: Returns the sequence number of the declaration within
00265 //               the page.  Sequence numbers are assigned as each
00266 //               declaration is created; each declaration is given a
00267 //               higher sequence number than all the declarations
00268 //               created in the page before it.
00269 ////////////////////////////////////////////////////////////////////
00270 INLINE int ConfigDeclaration::
00271 get_decl_seq() const {
00272   return _decl_seq;
00273 }
00274 
00275 INLINE ostream &
00276 operator << (ostream &out, const ConfigDeclaration &decl) {
00277   decl.output(out);
00278   return out;
00279 }
 All Classes Functions Variables Enumerations