configVariableCore.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 configVariableCore.h
  10. * @author drose
  11. * @date 2004-10-15
  12. */
  13. #ifndef CONFIGVARIABLECORE_H
  14. #define CONFIGVARIABLECORE_H
  15. #include "dtoolbase.h"
  16. #include "configFlags.h"
  17. #include "configPageManager.h"
  18. #include "pnotify.h"
  19. #include <vector>
  20. class ConfigDeclaration;
  21. /**
  22. * The internal definition of a ConfigVariable. This object is shared between
  23. * all instances of a ConfigVariable that use the same variable name.
  24. *
  25. * You cannot create a ConfigVariableCore instance directly; instead, use the
  26. * make() method, which may return a shared instance. Once created, these
  27. * objects are never destructed.
  28. */
  29. class EXPCL_DTOOL_PRC ConfigVariableCore : public ConfigFlags {
  30. private:
  31. ConfigVariableCore(const std::string &name);
  32. ConfigVariableCore(const ConfigVariableCore &templ, const std::string &name);
  33. ~ConfigVariableCore();
  34. PUBLISHED:
  35. INLINE const std::string &get_name() const;
  36. INLINE bool is_used() const;
  37. INLINE ValueType get_value_type() const;
  38. INLINE const std::string &get_description() const;
  39. INLINE int get_flags() const;
  40. INLINE bool is_closed() const;
  41. INLINE int get_trust_level() const;
  42. INLINE bool is_dynamic() const;
  43. INLINE const ConfigDeclaration *get_default_value() const;
  44. void set_value_type(ValueType value_type);
  45. void set_flags(int flags);
  46. void set_description(const std::string &description);
  47. void set_default_value(const std::string &default_value);
  48. INLINE void set_used();
  49. ConfigDeclaration *make_local_value();
  50. bool clear_local_value();
  51. INLINE bool has_local_value() const;
  52. bool has_value() const;
  53. size_t get_num_declarations() const;
  54. const ConfigDeclaration *get_declaration(size_t n) const;
  55. MAKE_SEQ(get_declarations, get_num_declarations, get_declaration);
  56. INLINE size_t get_num_references() const;
  57. INLINE const ConfigDeclaration *get_reference(size_t n) const;
  58. MAKE_SEQ(get_references, get_num_references, get_reference);
  59. INLINE size_t get_num_trusted_references() const;
  60. INLINE const ConfigDeclaration *get_trusted_reference(size_t n) const;
  61. MAKE_SEQ(get_trusted_references, get_num_trusted_references, get_trusted_reference);
  62. INLINE size_t get_num_unique_references() const;
  63. INLINE const ConfigDeclaration *get_unique_reference(size_t n) const;
  64. MAKE_SEQ(get_unique_references, get_num_unique_references, get_unique_reference);
  65. MAKE_SEQ_PROPERTY(declarations, get_num_declarations, get_declaration);
  66. void output(std::ostream &out) const;
  67. void write(std::ostream &out) const;
  68. MAKE_PROPERTY(name, get_name);
  69. MAKE_PROPERTY(used, is_used);
  70. MAKE_PROPERTY(closed, is_closed);
  71. MAKE_PROPERTY(trust_level, get_trust_level);
  72. MAKE_PROPERTY(dynamic, is_dynamic);
  73. MAKE_PROPERTY(value_type, get_value_type, set_value_type);
  74. MAKE_PROPERTY(description, get_description, set_description);
  75. MAKE_PROPERTY(default_value, get_default_value, set_default_value);
  76. MAKE_SEQ_PROPERTY(references, get_num_references, get_reference);
  77. MAKE_SEQ_PROPERTY(trusted_references, get_num_trusted_references, get_trusted_reference);
  78. MAKE_SEQ_PROPERTY(unique_references, get_num_unique_references, get_unique_reference);
  79. private:
  80. void add_declaration(ConfigDeclaration *decl);
  81. void remove_declaration(ConfigDeclaration *decl);
  82. INLINE void check_sort_declarations() const;
  83. void sort_declarations();
  84. private:
  85. std::string _name;
  86. bool _is_used;
  87. ValueType _value_type;
  88. std::string _description;
  89. int _flags;
  90. ConfigDeclaration *_default_value;
  91. ConfigDeclaration *_local_value;
  92. typedef std::vector<const ConfigDeclaration *> Declarations;
  93. Declarations _declarations;
  94. Declarations _trusted_declarations;
  95. Declarations _untrusted_declarations;
  96. Declarations _unique_declarations;
  97. bool _declarations_sorted;
  98. bool _value_queried;
  99. friend class ConfigDeclaration;
  100. friend class ConfigVariableManager;
  101. };
  102. INLINE std::ostream &operator << (std::ostream &out, const ConfigVariableCore &variable);
  103. #include "configVariableCore.I"
  104. #endif