tamlVisitor.h

Engine/source/persistence/taml/tamlVisitor.h

More...

Classes:

class

Visitor property state.

Detailed Description

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