Torque3D Documentation / _generateds / tamlAssetReferencedUpdateVisitor.h

tamlAssetReferencedUpdateVisitor.h

Engine/source/assets/tamlAssetReferencedUpdateVisitor.h

More...

Classes:

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_ASSET_REFERENCED_UPDATE_VISITOR_H_
 25#define _TAML_ASSET_REFERENCED_UPDATE_VISITOR_H_
 26
 27#ifndef _TAML_VISITOR_H_
 28#include "persistence/taml/tamlVisitor.h"
 29#endif
 30
 31#ifndef _TAML_PARSER_H_
 32#include "persistence\/taml/tamlParser.h"
 33#endif
 34
 35#ifndef _STRINGUNIT_H_
 36#include "string/stringUnit.h"
 37#endif
 38
 39#ifndef _STRINGTABLE_H_
 40#include "string/stringTable.h"
 41#endif
 42
 43#ifndef _ASSET_FIELD_TYPES_H_
 44#include "assets/assetFieldTypes.h"
 45#endif
 46
 47// Debug Profiling.
 48#include "platform/profiler.h"
 49
 50//-----------------------------------------------------------------------------
 51
 52class TamlAssetReferencedUpdateVisitor : public TamlVisitor
 53{
 54private:    
 55    StringTableEntry mAssetIdFrom;
 56    StringTableEntry mAssetIdTo;
 57
 58public:
 59    TamlAssetReferencedUpdateVisitor() : mAssetIdFrom(StringTable->EmptyString()), mAssetIdTo(StringTable->EmptyString()) {}
 60    virtual ~TamlAssetReferencedUpdateVisitor() {}
 61
 62    void setAssetIdFrom( const char* pAssetIdFrom )
 63    {
 64        // Sanity!
 65        AssertFatal( pAssetIdFrom != NULL, "Asset Id from cannot be NULL." );
 66
 67        mAssetIdFrom = StringTable->insert( pAssetIdFrom );
 68    }
 69    StringTableEntry getAssetIdFrom( void ) const { return mAssetIdFrom; }
 70
 71    void setAssetIdTo( const char* pAssetIdTo )
 72    {
 73        // Sanity!
 74        AssertFatal( pAssetIdTo != NULL, "Asset Id to cannot be NULL." );
 75
 76        mAssetIdTo = StringTable->insert( pAssetIdTo );
 77    }
 78    const char* getAssetIdTo( void ) const { return mAssetIdTo; }
 79
 80    virtual bool wantsPropertyChanges( void ) { return true; }
 81    virtual bool wantsRootOnly( void ) { return false; }
 82
 83    virtual bool visit( const TamlParser& parser, TamlVisitor::PropertyState& propertyState )
 84    {
 85        // Debug Profiling.
 86        PROFILE_SCOPE(TamlAssetReferencedUpdateVisitor_Visit);
 87
 88        // Fetch the property value.
 89        const char* pPropertyValue = propertyState.getPropertyValue();
 90
 91        // Fetch property value word count.
 92        const U32 valueWordCount = StringUnit::getUnitCount( pPropertyValue, ASSET_ASSIGNMENT_TOKEN );
 93
 94        // Finish if not two words.
 95        if ( valueWordCount != 2 )
 96            return true;
 97
 98        // Finish if this is not an asset signature.
 99        if ( dStricmp( StringUnit::getUnit( pPropertyValue, 0, ASSET_ASSIGNMENT_TOKEN), assetLooseIdSignature ) != 0 )
100            return true;
101
102        // Get the asset value.
103        const char* pAssetValue = StringUnit::getUnit( pPropertyValue, 1, ASSET_ASSIGNMENT_TOKEN );
104
105        // Finish if not the asset Id we're looking for.
106        if ( dStricmp( pAssetValue, mAssetIdFrom ) != 0 )
107            return true;
108
109        // Is the target asset empty?
110        if ( mAssetIdTo == StringTable->EmptyString() )
111        {
112            // Yes, so update the property as empty.
113           propertyState.updatePropertyValue(StringTable->EmptyString());
114            return true;
115        }
116
117        // Format asset.
118        char assetBuffer[1024];
119        dSprintf( assetBuffer, sizeof(assetBuffer), "%s%s%s", assetLooseIdSignature, ASSET_ASSIGNMENT_TOKEN, mAssetIdTo );
120
121        // Assign new value.
122        propertyState.updatePropertyValue( assetBuffer );
123
124        return true;
125    }
126};
127
128#endif // _TAML_ASSET_REFERENCED_UPDATE_VISITOR_H_
129