Panda3D
|
00001 // Filename: configVariableInt.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: ConfigVariableInt::Constructor 00018 // Access: Published 00019 // Description: 00020 //////////////////////////////////////////////////////////////////// 00021 INLINE ConfigVariableInt:: 00022 ConfigVariableInt(const string &name) : 00023 ConfigVariable(name, VT_int), 00024 _local_modified(initial_invalid_cache()) 00025 { 00026 _core->set_used(); 00027 } 00028 00029 //////////////////////////////////////////////////////////////////// 00030 // Function: ConfigVariableInt::Constructor 00031 // Access: Published 00032 // Description: 00033 //////////////////////////////////////////////////////////////////// 00034 INLINE ConfigVariableInt:: 00035 ConfigVariableInt(const string &name, int default_value, 00036 const string &description, int flags) : 00037 #ifdef PRC_SAVE_DESCRIPTIONS 00038 ConfigVariable(name, ConfigVariableCore::VT_int, description, flags), 00039 #else 00040 ConfigVariable(name, ConfigVariableCore::VT_int, string(), flags), 00041 #endif 00042 _local_modified(initial_invalid_cache()) 00043 { 00044 set_default_value(default_value); 00045 _core->set_used(); 00046 } 00047 00048 //////////////////////////////////////////////////////////////////// 00049 // Function: ConfigVariableInt::Constructor 00050 // Access: Published 00051 // Description: 00052 //////////////////////////////////////////////////////////////////// 00053 INLINE ConfigVariableInt:: 00054 ConfigVariableInt(const string &name, const string &default_value, 00055 const string &description, int flags) : 00056 #ifdef PRC_SAVE_DESCRIPTIONS 00057 ConfigVariable(name, ConfigVariableCore::VT_int, description, flags), 00058 #else 00059 ConfigVariable(name, ConfigVariableCore::VT_int, string(), flags), 00060 #endif 00061 _local_modified(initial_invalid_cache()) 00062 { 00063 _core->set_default_value(default_value); 00064 _core->set_used(); 00065 } 00066 00067 //////////////////////////////////////////////////////////////////// 00068 // Function: ConfigVariableInt::operator = 00069 // Access: Published 00070 // Description: Reassigns the variable's local value. 00071 //////////////////////////////////////////////////////////////////// 00072 INLINE void ConfigVariableInt:: 00073 operator = (int value) { 00074 set_value(value); 00075 } 00076 00077 //////////////////////////////////////////////////////////////////// 00078 // Function: ConfigVariableInt::typecast operator 00079 // Access: Published 00080 // Description: Returns the variable's value. 00081 //////////////////////////////////////////////////////////////////// 00082 INLINE ConfigVariableInt:: 00083 operator int () const { 00084 return get_value(); 00085 } 00086 00087 //////////////////////////////////////////////////////////////////// 00088 // Function: ConfigVariableInt::size() 00089 // Access: Published 00090 // Description: Returns the number of unique words in the variable. 00091 //////////////////////////////////////////////////////////////////// 00092 INLINE int ConfigVariableInt:: 00093 size() const { 00094 return get_num_words(); 00095 } 00096 00097 //////////////////////////////////////////////////////////////////// 00098 // Function: ConfigVariableInt::operator [] 00099 // Access: Published 00100 // Description: Returns the value of the variable's nth word. 00101 //////////////////////////////////////////////////////////////////// 00102 INLINE int ConfigVariableInt:: 00103 operator [] (int n) const { 00104 return get_word(n); 00105 } 00106 00107 //////////////////////////////////////////////////////////////////// 00108 // Function: ConfigVariableInt::set_value 00109 // Access: Published 00110 // Description: Reassigns the variable's local value. 00111 //////////////////////////////////////////////////////////////////// 00112 INLINE void ConfigVariableInt:: 00113 set_value(int value) { 00114 set_string_value(""); 00115 set_int_word(0, value); 00116 } 00117 00118 //////////////////////////////////////////////////////////////////// 00119 // Function: ConfigVariableInt::get_value 00120 // Access: Published 00121 // Description: Returns the variable's value. 00122 //////////////////////////////////////////////////////////////////// 00123 INLINE int ConfigVariableInt:: 00124 get_value() const { 00125 TAU_PROFILE("int ConfigVariableInt::get_value() const", " ", TAU_USER); 00126 if (!is_cache_valid(_local_modified)) { 00127 mark_cache_valid(((ConfigVariableInt *)this)->_local_modified); 00128 ((ConfigVariableInt *)this)->_cache = get_int_word(0); 00129 } 00130 return _cache; 00131 } 00132 00133 //////////////////////////////////////////////////////////////////// 00134 // Function: ConfigVariableInt::get_default_value 00135 // Access: Published 00136 // Description: Returns the variable's default value. 00137 //////////////////////////////////////////////////////////////////// 00138 INLINE int ConfigVariableInt:: 00139 get_default_value() const { 00140 const ConfigDeclaration *decl = ConfigVariable::get_default_value(); 00141 if (decl != (ConfigDeclaration *)NULL) { 00142 return decl->get_int_word(0); 00143 } 00144 return 0; 00145 } 00146 00147 //////////////////////////////////////////////////////////////////// 00148 // Function: ConfigVariableInt::get_word 00149 // Access: Published 00150 // Description: Returns the variable's nth value. 00151 //////////////////////////////////////////////////////////////////// 00152 INLINE int ConfigVariableInt:: 00153 get_word(int n) const { 00154 return get_int_word(n); 00155 } 00156 00157 //////////////////////////////////////////////////////////////////// 00158 // Function: ConfigVariableInt::set_word 00159 // Access: Published 00160 // Description: Reassigns the variable's nth value. This makes a 00161 // local copy of the variable's overall value. 00162 //////////////////////////////////////////////////////////////////// 00163 INLINE void ConfigVariableInt:: 00164 set_word(int n, int value) { 00165 set_int_word(n, value); 00166 } 00167