configVariableString.I 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. // Filename: configVariableString.I
  2. // Created by: drose (20Oct04)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
  8. //
  9. // All use of this software is subject to the terms of the Panda 3d
  10. // Software license. You should have received a copy of this license
  11. // along with this source code; you will also find a current copy of
  12. // the license at http://etc.cmu.edu/panda3d/docs/license/ .
  13. //
  14. // To contact the maintainers of this program write to
  15. // [email protected] .
  16. //
  17. ////////////////////////////////////////////////////////////////////
  18. ////////////////////////////////////////////////////////////////////
  19. // Function: ConfigVariableString::Constructor
  20. // Access: Published
  21. // Description:
  22. ////////////////////////////////////////////////////////////////////
  23. INLINE ConfigVariableString::
  24. ConfigVariableString(const string &name) :
  25. ConfigVariable(name, VT_string)
  26. {
  27. _core->set_used();
  28. }
  29. ////////////////////////////////////////////////////////////////////
  30. // Function: ConfigVariableString::Constructor
  31. // Access: Published
  32. // Description:
  33. ////////////////////////////////////////////////////////////////////
  34. INLINE ConfigVariableString::
  35. ConfigVariableString(const string &name, const string &default_value,
  36. const string &description, int flags) :
  37. #ifdef PRC_SAVE_DESCRIPTIONS
  38. ConfigVariable(name, VT_string, description, flags)
  39. #else
  40. ConfigVariable(name, VT_string, string(), flags)
  41. #endif
  42. {
  43. _core->set_default_value(default_value);
  44. _core->set_used();
  45. }
  46. ////////////////////////////////////////////////////////////////////
  47. // Function: ConfigVariableString::operator =
  48. // Access: Published
  49. // Description: Reassigns the variable's local value.
  50. ////////////////////////////////////////////////////////////////////
  51. INLINE void ConfigVariableString::
  52. operator = (const string &value) {
  53. set_value(value);
  54. }
  55. ////////////////////////////////////////////////////////////////////
  56. // Function: ConfigVariableString::string typecast operator
  57. // Access: Published
  58. // Description: Returns the variable's value.
  59. ////////////////////////////////////////////////////////////////////
  60. INLINE ConfigVariableString::
  61. operator const string & () const {
  62. return get_value();
  63. }
  64. ////////////////////////////////////////////////////////////////////
  65. // Function: ConfigVariableString::c_str
  66. // Access: Public
  67. // Description:
  68. ////////////////////////////////////////////////////////////////////
  69. INLINE const char *ConfigVariableString::
  70. c_str() const {
  71. return get_value().c_str();
  72. }
  73. ////////////////////////////////////////////////////////////////////
  74. // Function: ConfigVariableString::empty
  75. // Access: Public
  76. // Description:
  77. ////////////////////////////////////////////////////////////////////
  78. INLINE bool ConfigVariableString::
  79. empty() const {
  80. return get_value().empty();
  81. }
  82. ////////////////////////////////////////////////////////////////////
  83. // Function: ConfigVariableString::length
  84. // Access: Public
  85. // Description:
  86. ////////////////////////////////////////////////////////////////////
  87. INLINE size_t ConfigVariableString::
  88. length() const {
  89. return get_value().length();
  90. }
  91. ////////////////////////////////////////////////////////////////////
  92. // Function: ConfigVariableString::Indexing operator
  93. // Access: Public
  94. // Description:
  95. ////////////////////////////////////////////////////////////////////
  96. INLINE char ConfigVariableString::
  97. operator [] (int n) const {
  98. assert(n >= 0 && n < (int)length());
  99. return get_value()[n];
  100. }
  101. ////////////////////////////////////////////////////////////////////
  102. // Function: ConfigVariableString::Equality operator
  103. // Access: Public
  104. // Description:
  105. ////////////////////////////////////////////////////////////////////
  106. INLINE bool ConfigVariableString::
  107. operator == (const string &other) const {
  108. return get_value() == other;
  109. }
  110. ////////////////////////////////////////////////////////////////////
  111. // Function: ConfigVariableString::Inequality operator
  112. // Access: Public
  113. // Description:
  114. ////////////////////////////////////////////////////////////////////
  115. INLINE bool ConfigVariableString::
  116. operator != (const string &other) const {
  117. return get_value() != other;
  118. }
  119. ////////////////////////////////////////////////////////////////////
  120. // Function: ConfigVariableString::Ordering operator
  121. // Access: Public
  122. // Description:
  123. ////////////////////////////////////////////////////////////////////
  124. INLINE bool ConfigVariableString::
  125. operator < (const string &other) const {
  126. return get_value() < other;
  127. }
  128. ////////////////////////////////////////////////////////////////////
  129. // Function: ConfigVariableString::set_value
  130. // Access: Published
  131. // Description: Reassigns the variable's local value.
  132. ////////////////////////////////////////////////////////////////////
  133. INLINE void ConfigVariableString::
  134. set_value(const string &value) {
  135. set_string_value(value);
  136. }
  137. ////////////////////////////////////////////////////////////////////
  138. // Function: ConfigVariableString::get_value
  139. // Access: Published
  140. // Description: Returns the variable's value.
  141. ////////////////////////////////////////////////////////////////////
  142. INLINE const string &ConfigVariableString::
  143. get_value() const {
  144. return get_string_value();
  145. }
  146. ////////////////////////////////////////////////////////////////////
  147. // Function: ConfigVariableString::get_default_value
  148. // Access: Published
  149. // Description: Returns the variable's default value.
  150. ////////////////////////////////////////////////////////////////////
  151. INLINE string ConfigVariableString::
  152. get_default_value() const {
  153. const ConfigDeclaration *decl = ConfigVariable::get_default_value();
  154. if (decl != (ConfigDeclaration *)NULL) {
  155. return decl->get_string_value();
  156. }
  157. return string();
  158. }
  159. ////////////////////////////////////////////////////////////////////
  160. // Function: ConfigVariableString::get_word
  161. // Access: Published
  162. // Description: Returns the variable's nth value.
  163. ////////////////////////////////////////////////////////////////////
  164. INLINE string ConfigVariableString::
  165. get_word(int n) const {
  166. return get_string_word(n);
  167. }
  168. ////////////////////////////////////////////////////////////////////
  169. // Function: ConfigVariableString::set_word
  170. // Access: Published
  171. // Description: Reassigns the variable's nth value. This makes a
  172. // local copy of the variable's overall value.
  173. ////////////////////////////////////////////////////////////////////
  174. INLINE void ConfigVariableString::
  175. set_word(int n, const string &value) {
  176. set_string_word(n, value);
  177. }