tamlAssetDeclaredUpdateVisitor.h
Engine/source/assets/tamlAssetDeclaredUpdateVisitor.h
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_DECLARED_UPDATE_VISITOR_H_ 25#define _TAML_ASSET_DECLARED_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 _ASSET_FIELD_TYPES_H_ 36#include "assets/assetFieldTypes.h" 37#endif 38 39// Debug Profiling. 40#include "platform/profiler.h" 41 42//----------------------------------------------------------------------------- 43 44class TamlAssetDeclaredUpdateVisitor : public TamlVisitor 45{ 46private: 47 StringTableEntry mAssetIdFrom; 48 StringTableEntry mAssetIdTo; 49 StringTableEntry mAssetNameFrom; 50 StringTableEntry mAssetNameTo; 51 52public: 53 TamlAssetDeclaredUpdateVisitor(): 54 mAssetIdFrom(StringTable->EmptyString()), mAssetIdTo(StringTable->EmptyString()), 55 mAssetNameFrom(StringTable->EmptyString()), mAssetNameTo(StringTable->EmptyString()) {} 56 57 virtual ~TamlAssetDeclaredUpdateVisitor() {} 58 59 void setAssetIdFrom( const char* pAssetIdFrom ) 60 { 61 // Sanity! 62 AssertFatal( pAssetIdFrom != NULL, "Asset Id from cannot be NULL." ); 63 64 // Reset asset Id. 65 mAssetIdFrom = StringTable->EmptyString(); 66 mAssetNameFrom = StringTable->EmptyString(); 67 68 // Is asset Id the correct format? 69 if ( StringUnit::getUnitCount( pAssetIdFrom, ASSET_SCOPE_TOKEN ) != 2 ) 70 { 71 // No, so warn. 72 Con::warnf( "TamlAssetDeclaredUpdateVisitor::setAssetIdFrom() - Cannot use asset Id '%s' as it is not the correct format.", pAssetIdFrom ); 73 return; 74 } 75 76 // Set asset Id. 77 mAssetIdFrom = StringTable->insert( pAssetIdFrom ); 78 mAssetNameFrom = StringTable->insert( StringUnit::getUnit( pAssetIdFrom, 1, ASSET_SCOPE_TOKEN ) ); 79 } 80 StringTableEntry getAssetIdFrom( void ) const { return mAssetIdFrom; } 81 82 void setAssetIdTo( const char* pAssetIdTo ) 83 { 84 // Sanity! 85 AssertFatal( pAssetIdTo != NULL, "Asset Id to cannot be NULL." ); 86 87 // Reset asset Id. 88 mAssetIdTo = StringTable->EmptyString(); 89 mAssetNameTo = StringTable->EmptyString(); 90 91 // Is asset Id the correct format? 92 if ( StringUnit::getUnitCount( pAssetIdTo, ASSET_SCOPE_TOKEN ) != 2 ) 93 { 94 // No, so warn. 95 Con::warnf( "TamlAssetDeclaredUpdateVisitor::setAssetIdTo() - Cannot use asset Id '%s' as it is not the correct format.", pAssetIdTo ); 96 return; 97 } 98 99 // Set asset Id. 100 mAssetIdTo = StringTable->insert( pAssetIdTo ); 101 mAssetNameTo = StringTable->insert( StringUnit::getUnit( pAssetIdTo, 1, ASSET_SCOPE_TOKEN ) ); 102 } 103 const char* getAssetIdTo( void ) const { return mAssetIdTo; } 104 105 virtual bool wantsPropertyChanges( void ) { return true; } 106 virtual bool wantsRootOnly( void ) { return true; } 107 108 virtual bool visit( const TamlParser& parser, TamlVisitor::PropertyState& propertyState ) 109 { 110 // Debug Profiling. 111 PROFILE_SCOPE(TamlAssetDeclaredUpdateVisitor_Visit); 112 113 // Finish if not the asset name field. 114 if ( propertyState.getPropertyName() != assetNameField ) 115 return true; 116 117 // Is this the asset Id we're looking for? 118 if ( dStricmp( propertyState.getPropertyValue(), mAssetNameFrom ) != 0 ) 119 { 120 // No, so warn. 121 Con::warnf("Cannot rename asset Name '%s' to asset Name '%s' as the declared asset Name was %s", 122 mAssetNameFrom, mAssetNameTo, propertyState.getPropertyValue() ); 123 124 // Stop processing! 125 return false; 126 } 127 128 // Assign new value. 129 propertyState.updatePropertyValue( mAssetNameTo ); 130 131 // Stop processing! 132 return false; 133 } 134}; 135 136#endif // _TAML_ASSET_DECLARED_UPDATE_VISITOR_H_ 137