tamlWriteNode.h
Engine/source/persistence/taml/tamlWriteNode.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_WRITE_NODE_H_ 25#define _TAML_WRITE_NODE_H_ 26 27#ifndef _TAML_CUSTOM_H_ 28#include "persistence/taml/tamlCustom.h" 29#endif 30 31#ifndef _SIMBASE_H_ 32#include "console/simBase.h" 33#endif 34 35#ifndef _VECTOR_H_ 36#include "core/util/tVector.h" 37#endif 38 39//----------------------------------------------------------------------------- 40 41class TamlCallbacks; 42 43//----------------------------------------------------------------------------- 44 45class TamlWriteNode 46{ 47public: 48 class FieldValuePair 49 { 50 public: 51 FieldValuePair( StringTableEntry name, const char* pValue ) 52 { 53 // Set the field name. 54 mName = name; 55 56 // Allocate and copy the value. 57 mpValue = new char[ dStrlen(pValue)+1 ]; 58 dStrcpy( (char *)mpValue, pValue ); 59 } 60 61 62 StringTableEntry mName; 63 const char* mpValue; 64 }; 65 66public: 67 TamlWriteNode() 68 { 69 // NOTE: This MUST be done before the state is reset otherwise we'll be touching uninitialized stuff. 70 mRefToNode = NULL; 71 mpSimObject = NULL; 72 mpTamlCallbacks = NULL; 73 mpObjectName = NULL; 74 mChildren = NULL; 75 76 resetNode(); 77 } 78 79 void set( SimObject* pSimObject ) 80 { 81 // Sanity! 82 AssertFatal( pSimObject != NULL, "Cannot set a write node with a NULL sim object." ); 83 84 // Reset the node. 85 resetNode(); 86 87 // Set sim object. 88 mpSimObject = pSimObject; 89 90 // Fetch name. 91 const char* pObjectName = pSimObject->getName(); 92 93 // Assign name usage. 94 if ( pObjectName != NULL && 95 pObjectName != StringTable->EmptyString() && 96 dStrlen( pObjectName ) > 0 ) 97 { 98 mpObjectName = pObjectName; 99 } 100 101 // Find Taml callbacks. 102 mpTamlCallbacks = dynamic_cast<TamlCallbacks*>( mpSimObject ); 103 } 104 105 void resetNode( void ); 106 107 U32 mRefId; 108 TamlWriteNode* mRefToNode; 109 SimObject* mpSimObject; 110 TamlCallbacks* mpTamlCallbacks; 111 const char* mpObjectName; 112 Vector<TamlWriteNode::FieldValuePair*> mFields; 113 Vector<TamlWriteNode*>* mChildren; 114 TamlCustomNodes mCustomNodes; 115}; 116 117#endif // _TAML_WRITE_NODE_H_ 118
