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