tamlVisitor.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _TAML_VISITOR_H_
  23. #define _TAML_VISITOR_H_
  24. #include "string/stringTable.h"
  25. //-----------------------------------------------------------------------------
  26. class TamlParser;
  27. //-----------------------------------------------------------------------------
  28. /// @ingroup tamlGroup
  29. /// @see tamlGroup
  30. class TamlVisitor
  31. {
  32. public:
  33. /// Visitor property state.
  34. struct PropertyState
  35. {
  36. private:
  37. StringTableEntry mObjectName;
  38. StringTableEntry mPropertyName;
  39. char mPropertyValue[4096];
  40. bool mPropertyValueDirty;
  41. bool mIsRootObject;
  42. public:
  43. PropertyState()
  44. {
  45. mObjectName = StringTable->EmptyString;
  46. mPropertyName = StringTable->EmptyString;
  47. *mPropertyValue = 0;
  48. mPropertyValueDirty = false;
  49. mIsRootObject = false;
  50. }
  51. inline void setObjectName( const char* pObjectName, const bool rootObject )
  52. {
  53. mObjectName = StringTable->insert( pObjectName );
  54. mIsRootObject = rootObject;
  55. }
  56. inline StringTableEntry getObjectName( void ) const { return mObjectName; }
  57. inline bool isRootObject( void ) const { return mIsRootObject; }
  58. inline void setProperty( const char* pPropertyName, const char* pPropertyValue )
  59. {
  60. // Set property name.
  61. mPropertyName = StringTable->insert( pPropertyName );
  62. // Format property value.
  63. dSprintf( mPropertyValue, sizeof(mPropertyValue), "%s", pPropertyValue );
  64. // Flag as not dirty.
  65. mPropertyValueDirty = false;
  66. }
  67. inline void updatePropertyValue( const char* pPropertyValue )
  68. {
  69. // Update property value.
  70. dSprintf( mPropertyValue, sizeof(mPropertyValue), "%s", pPropertyValue );
  71. // Flag as dirty.
  72. mPropertyValueDirty = true;
  73. }
  74. inline StringTableEntry getPropertyName( void ) const { return mPropertyName; }
  75. inline const char* getPropertyValue( void ) const { return mPropertyValue; }
  76. inline void resetPropertyValueDirty( void ) { mPropertyValueDirty = false; }
  77. inline bool getPropertyValueDirty( void ) const { return mPropertyValueDirty; }
  78. };
  79. public:
  80. TamlVisitor() {}
  81. virtual ~TamlVisitor() {}
  82. /// Whether the visitor wants to perform property changes.
  83. /// This allows a check against the parser which may not allow changes.
  84. virtual bool wantsPropertyChanges( void ) = 0;
  85. /// Whether the visitor wants to visit the root node only.
  86. virtual bool wantsRootOnly( void ) = 0;
  87. /// The state of the visited property.
  88. virtual bool visit( const TamlParser& parser, PropertyState& propertyState ) = 0;
  89. };
  90. #endif // _TAML_VISITOR_H_