configVariableString.I 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /**
  2. * PANDA 3D SOFTWARE
  3. * Copyright (c) Carnegie Mellon University. All rights reserved.
  4. *
  5. * All use of this software is subject to the terms of the revised BSD
  6. * license. You should have received a copy of this license along
  7. * with this source code in a file named "LICENSE."
  8. *
  9. * @file configVariableString.I
  10. * @author drose
  11. * @date 2004-10-20
  12. */
  13. /**
  14. *
  15. */
  16. INLINE ConfigVariableString::
  17. ConfigVariableString(const string &name) :
  18. ConfigVariable(name, VT_string),
  19. _local_modified(initial_invalid_cache())
  20. {
  21. _core->set_used();
  22. }
  23. /**
  24. *
  25. */
  26. INLINE ConfigVariableString::
  27. ConfigVariableString(const string &name, const string &default_value,
  28. const string &description, int flags) :
  29. #ifdef PRC_SAVE_DESCRIPTIONS
  30. ConfigVariable(name, VT_string, description, flags),
  31. #else
  32. ConfigVariable(name, VT_string, string(), flags),
  33. #endif
  34. _local_modified(initial_invalid_cache())
  35. {
  36. _core->set_default_value(default_value);
  37. _core->set_used();
  38. }
  39. /**
  40. * Reassigns the variable's local value.
  41. */
  42. INLINE void ConfigVariableString::
  43. operator = (const string &value) {
  44. set_value(value);
  45. }
  46. /**
  47. * Returns the variable's value.
  48. */
  49. INLINE ConfigVariableString::
  50. operator const string & () const {
  51. return get_value();
  52. }
  53. /**
  54. *
  55. */
  56. INLINE const char *ConfigVariableString::
  57. c_str() const {
  58. return get_value().c_str();
  59. }
  60. /**
  61. *
  62. */
  63. INLINE bool ConfigVariableString::
  64. empty() const {
  65. return get_value().empty();
  66. }
  67. /**
  68. *
  69. */
  70. INLINE size_t ConfigVariableString::
  71. length() const {
  72. return get_value().length();
  73. }
  74. /**
  75. *
  76. */
  77. INLINE char ConfigVariableString::
  78. operator [] (size_t n) const {
  79. assert(n < length());
  80. return get_value()[n];
  81. }
  82. /**
  83. *
  84. */
  85. INLINE bool ConfigVariableString::
  86. operator == (const string &other) const {
  87. return get_value() == other;
  88. }
  89. /**
  90. *
  91. */
  92. INLINE bool ConfigVariableString::
  93. operator != (const string &other) const {
  94. return get_value() != other;
  95. }
  96. /**
  97. *
  98. */
  99. INLINE bool ConfigVariableString::
  100. operator < (const string &other) const {
  101. return get_value() < other;
  102. }
  103. /**
  104. * Reassigns the variable's local value.
  105. */
  106. INLINE void ConfigVariableString::
  107. set_value(const string &value) {
  108. set_string_value(value);
  109. }
  110. /**
  111. * Returns the variable's value.
  112. */
  113. INLINE const string &ConfigVariableString::
  114. get_value() const {
  115. TAU_PROFILE("const string &ConfigVariableString::get_value() const", " ", TAU_USER);
  116. if (!is_cache_valid(_local_modified)) {
  117. ((ConfigVariableString *)this)->reload_cache();
  118. }
  119. return _cache;
  120. }
  121. /**
  122. * Returns the variable's default value.
  123. */
  124. INLINE string ConfigVariableString::
  125. get_default_value() const {
  126. const ConfigDeclaration *decl = ConfigVariable::get_default_value();
  127. if (decl != (ConfigDeclaration *)NULL) {
  128. return decl->get_string_value();
  129. }
  130. return string();
  131. }
  132. /**
  133. * Returns the variable's nth value.
  134. */
  135. INLINE string ConfigVariableString::
  136. get_word(size_t n) const {
  137. return get_string_word(n);
  138. }
  139. /**
  140. * Reassigns the variable's nth value. This makes a local copy of the
  141. * variable's overall value.
  142. */
  143. INLINE void ConfigVariableString::
  144. set_word(size_t n, const string &value) {
  145. set_string_word(n, value);
  146. }