/Rainman2/attributes.h

http://modstudio2.googlecode.com/ · C Header · 123 lines · 58 code · 18 blank · 47 comment · 5 complexity · ee8950f07c6376b1f3d75bba6efe9fe1 MD5 · raw file

  1. /*
  2. Copyright (c) 2008 Peter "Corsix" Cawley
  3. Permission is hereby granted, free of charge, to any person
  4. obtaining a copy of this software and associated documentation
  5. files (the "Software"), to deal in the Software without
  6. restriction, including without limitation the rights to use,
  7. copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the
  9. Software is furnished to do so, subject to the following
  10. conditions:
  11. The above copyright notice and this permission notice shall be
  12. included in all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  14. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  15. OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  16. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  17. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  18. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. OTHER DEALINGS IN THE SOFTWARE.
  21. */
  22. #pragma once
  23. #include "string.h"
  24. #include <limits.h>
  25. class IAttributeTable;
  26. //! All the possible types of values found in attribute files
  27. enum eAttributeValueTypes
  28. {
  29. VT_String, //!< String data (represented with a RainString, but may be stored as ASCII)
  30. VT_Boolean, //!< Boolean data (true/false)
  31. VT_Table, //!< A table containing further values
  32. VT_Float, //!< Single-precision floating point data
  33. VT_Integer, //!< 32-bit signed integer
  34. //! Should never be found in attribute files, but provided as a convenience
  35. VT_Unknown,
  36. };
  37. //! All the possible icons which represent inheritance in an attribute file
  38. /*!
  39. Only some types of attribute files support inheritance. These icons are designed
  40. to make editing those easier by making it clear what values are inherited and
  41. which aren't.
  42. */
  43. enum eAttributeValueIcons
  44. {
  45. //! The value/table is *exactly* the same as in the parent file
  46. VI_SameAsParent,
  47. //! The value is different to the parent file (not applicable to tables)
  48. VI_DifferentToParent,
  49. //! The table inherits from a parent, but has some values which are not the same as parent
  50. /*!
  51. If *all* the values within a table are the same as the parent, then the table itself is
  52. the same as parent. Otherwise, this icon is used if there is a parent, and VI_NewSinceParent
  53. is used if not.
  54. */
  55. VI_Table,
  56. //! The value/table is not in the parent file
  57. VI_NewSinceParent,
  58. };
  59. //! Interface for a key/value pair from an attribute file
  60. class RAINMAN2_API IAttributeValue
  61. {
  62. public:
  63. virtual ~IAttributeValue(); //!< Virtual destructor
  64. //! Get the name (key) of the value
  65. /*!
  66. The returned value is a hash. Use one of the RgdDictionary::hashTo methods
  67. to convert it to text.
  68. */
  69. virtual unsigned long getName() const throw() = 0;
  70. virtual eAttributeValueTypes getType() const throw() = 0;
  71. virtual eAttributeValueIcons getIcon() const throw() = 0;
  72. virtual RainString getFileSetIn() const throw() = 0;
  73. virtual const IAttributeValue* getParent() const throw(...) = 0;
  74. virtual const IAttributeValue* getParentNoThrow() const throw() = 0;
  75. inline bool isString () const throw() {return getType() == VT_String ;}
  76. inline bool isBoolean() const throw() {return getType() == VT_Boolean;}
  77. inline bool isTable () const throw() {return getType() == VT_Table ;}
  78. inline bool isFloat () const throw() {return getType() == VT_Float ;}
  79. inline bool isInteger() const throw() {return getType() == VT_Integer;}
  80. virtual RainString getValueString () const throw(...) = 0;
  81. virtual bool getValueBoolean() const throw(...) = 0;
  82. virtual IAttributeTable* getValueTable () const throw(...) = 0;
  83. virtual float getValueFloat () const throw(...) = 0;
  84. virtual long getValueInteger() const throw(...) = 0;
  85. virtual const char* getValueStringRaw(size_t* iLength) const throw();
  86. virtual void setName(unsigned long iName ) throw(...) = 0;
  87. virtual void setType(eAttributeValueTypes eNewType) throw(...) = 0;
  88. virtual void setValueString (const RainString& sValue) throw(...) = 0;
  89. virtual void setValueBoolean(bool bValue ) throw(...) = 0;
  90. virtual void setValueFloat (float fValue ) throw(...) = 0;
  91. };
  92. class RAINMAN2_API IAttributeTable
  93. {
  94. public:
  95. virtual ~IAttributeTable();
  96. static const unsigned long NO_INDEX = static_cast<unsigned long>(-1);
  97. virtual unsigned long getChildCount() throw() = 0;
  98. virtual IAttributeValue* getChild(unsigned long iIndex) throw(...) = 0;
  99. virtual void addChild(unsigned long iName) throw(...) = 0;
  100. virtual unsigned long findChildIndex(unsigned long iName) throw() = 0;
  101. virtual void deleteChild(unsigned long iIndex, bool bRevertIsSufficient) throw(...) = 0;
  102. };