tamlModuleIdUpdateVisitor.h
Engine/source/module/tamlModuleIdUpdateVisitor.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_MODULE_ID_UPDATE_VISITOR_H_ 25#define _TAML_MODULE_ID_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#include "platform/profiler.h" 40 41//----------------------------------------------------------------------------- 42 43class TamlModuleIdUpdateVisitor : public TamlVisitor 44{ 45private: 46 StringTableEntry mModuleIdFrom; 47 StringTableEntry mModuleIdTo; 48 U32 mModuleIdFromLength; 49 U32 mModuleIdToLength; 50 51public: 52 TamlModuleIdUpdateVisitor() : 53 mModuleIdFrom( StringTable->EmptyString() ), 54 mModuleIdTo(StringTable->EmptyString()), 55 mModuleIdFromLength( 0 ), 56 mModuleIdToLength( 0 ) 57 {} 58 virtual ~TamlModuleIdUpdateVisitor() {} 59 60 virtual bool wantsPropertyChanges( void ) { return true; } 61 virtual bool wantsRootOnly( void ) { return true; } 62 63 virtual bool visit( const TamlParser& parser, TamlVisitor::PropertyState& propertyState ) 64 { 65 // Debug Profiling. 66 PROFILE_SCOPE(TamlModuleIdUpdateVisitor_Visit); 67 68 // Fetch property value. 69 const char* pPropertyValue = propertyState.getPropertyValue(); 70 71 // Fetch value length. 72 const U32 valueLenth = dStrlen(pPropertyValue); 73 74 char newAttributeValueBuffer[1024]; 75 76 // Is this an expando? 77 if ( *pPropertyValue == '^' ) 78 { 79 // Yes, so finish if it's not the correct length. 80 if ( valueLenth < mModuleIdFromLength+1 ) 81 return true; 82 83 // Is this the module Id? 84 if ( dStrnicmp( pPropertyValue+1, mModuleIdFrom, mModuleIdFromLength ) == 0 ) 85 { 86 // Yes, so format a new value. 87 dSprintf( newAttributeValueBuffer, sizeof(newAttributeValueBuffer), "^%s%s", 88 mModuleIdTo, pPropertyValue+1+mModuleIdFromLength ); 89 90 // Assign new value. 91 propertyState.updatePropertyValue( newAttributeValueBuffer ); 92 } 93 94 return true; 95 } 96 97 // Does the field start with the module Id? 98 if ( dStrnicmp( pPropertyValue, mModuleIdFrom, mModuleIdFromLength ) == 0 ) 99 { 100 // Yes, so format a new value. 101 dSprintf( newAttributeValueBuffer, sizeof(newAttributeValueBuffer), "%s%s", 102 mModuleIdTo, pPropertyValue+mModuleIdFromLength ); 103 104 // Assign new value. 105 propertyState.updatePropertyValue( newAttributeValueBuffer ); 106 } 107 108 return true; 109 } 110 111 void setModuleIdFrom( const char* pModuleIdFrom ) 112 { 113 // Sanity! 114 AssertFatal( pModuleIdFrom != NULL, "Module Id from cannot be NULL." ); 115 116 // Set module Id. 117 mModuleIdFrom = StringTable->insert( pModuleIdFrom ); 118 mModuleIdFromLength = dStrlen(mModuleIdFrom); 119 } 120 StringTableEntry getModuleIdFrom( void ) const { return mModuleIdFrom; } 121 122 void setModuleIdTo( const char* pModuleIdTo ) 123 { 124 // Sanity! 125 AssertFatal( pModuleIdTo != NULL, "Module Id to cannot be NULL." ); 126 127 // Set module Id. 128 mModuleIdTo = StringTable->insert( pModuleIdTo ); 129 mModuleIdToLength = dStrlen(mModuleIdTo); 130 } 131 const char* getModuleIdTo( void ) const { return mModuleIdTo; } 132}; 133 134#endif // _TAML_MODULE_ID_UPDATE_VISITOR_H_ 135