PageRenderTime 38ms CodeModel.GetById 18ms app.highlight 15ms RepoModel.GetById 2ms app.codeStats 0ms

/Rainman2/attributes.h

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