Torque3D Documentation / _generateds / tamlWriteNode.h

tamlWriteNode.h

Engine/source/persistence/taml/tamlWriteNode.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_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            dsize_t valueLen = dStrlen(pValue) + 1;
 58            mpValue = new char[ valueLen ];
 59            dStrcpy( (char *)mpValue, pValue, valueLen );
 60        }
 61        
 62
 63        StringTableEntry    mName;
 64        const char*         mpValue;
 65    };
 66
 67public:
 68    TamlWriteNode()
 69    {
 70        // NOTE: This MUST be done before the state is reset otherwise we'll be touching uninitialized stuff.
 71        mRefToNode = NULL;
 72        mpSimObject = NULL;
 73        mpTamlCallbacks = NULL;
 74        mpObjectName = NULL;
 75        mChildren = NULL;
 76
 77        resetNode();
 78    }
 79
 80    void set( SimObject* pSimObject )
 81    {
 82        // Sanity!
 83        AssertFatal( pSimObject != NULL, "Cannot set a write node with a NULL sim object." );
 84
 85        // Reset the node.
 86        resetNode();
 87
 88        // Set sim object.
 89        mpSimObject = pSimObject;
 90
 91        // Fetch name.
 92        const char* pObjectName = pSimObject->getName();
 93
 94        // Assign name usage.
 95        if ( pObjectName != NULL &&
 96            pObjectName != StringTable->EmptyString() &&
 97            dStrlen( pObjectName ) > 0 )
 98        {
 99            mpObjectName = pObjectName;
100        }
101
102        // Find Taml callbacks.
103        mpTamlCallbacks = dynamic_cast<TamlCallbacks*>( mpSimObject );
104    }
105
106    void resetNode( void );
107
108    U32                         mRefId;
109    TamlWriteNode*              mRefToNode;
110    SimObject*                  mpSimObject;
111    TamlCallbacks*              mpTamlCallbacks;
112    const char*                 mpObjectName;
113    Vector<TamlWriteNode::FieldValuePair*> mFields;
114    Vector<TamlWriteNode*>*     mChildren;
115    TamlCustomNodes             mCustomNodes;
116};
117
118#endif // _TAML_WRITE_NODE_H_
119