Browse Source

- Some minor consistency changes to Taml.

MelvMay-GG 12 years ago
parent
commit
498a84a

+ 3 - 3
engine/source/persistence/taml/taml.cc

@@ -1306,19 +1306,19 @@ bool Taml::generateTamlSchema()
 
             // Add Taml "Name" attribute element.
             TiXmlElement* pNameAttributeElement = new TiXmlElement( "xs:attribute" );
-            pNameAttributeElement->SetAttribute( "name", TAML_OBJECTNAME_ATTRIBUTE_NAME );
+            pNameAttributeElement->SetAttribute( "name", tamlNamedObjectName );
             pNameAttributeElement->SetAttribute( "type", "xs:normalizedString" );
             pFieldAttributeGroupElement->LinkEndChild( pNameAttributeElement );
 
             // Add Taml "TamlId" attribute element.
             TiXmlElement* pTamlIdAttributeElement = new TiXmlElement( "xs:attribute" );
-            pTamlIdAttributeElement->SetAttribute( "name", TAML_ID_ATTRIBUTE_NAME );
+            pTamlIdAttributeElement->SetAttribute( "name", tamlRefIdName );
             pTamlIdAttributeElement->SetAttribute( "type", "xs:nonNegativeInteger" );
             pFieldAttributeGroupElement->LinkEndChild( pTamlIdAttributeElement );
 
             // Add Taml "TamlRefId" attribute element.
             TiXmlElement* pTamlRefIdAttributeElement = new TiXmlElement( "xs:attribute" );
-            pTamlRefIdAttributeElement->SetAttribute( "name", TAML_REFID_ATTRIBUTE_NAME );
+            pTamlRefIdAttributeElement->SetAttribute( "name", tamlRefToIdName );
             pTamlRefIdAttributeElement->SetAttribute( "type", "xs:nonNegativeInteger" );
             pFieldAttributeGroupElement->LinkEndChild( pTamlRefIdAttributeElement );
         }

+ 0 - 6
engine/source/persistence/taml/taml.h

@@ -54,12 +54,6 @@
 //-----------------------------------------------------------------------------
 
 #define TAML_SIGNATURE                  "Taml"
-#define TAML_ID_ATTRIBUTE_NAME          "TamlId"
-#define TAML_REFID_ATTRIBUTE_NAME       "TamlRefId"
-#define TAML_OBJECTNAME_ATTRIBUTE_NAME  "Name"
-
-//-----------------------------------------------------------------------------
-
 #define TAML_SCHEMA_VARIABLE            "$pref::T2D::TAMLSchema"
 
 //-----------------------------------------------------------------------------

+ 0 - 1
engine/source/persistence/taml/tamlBinaryReader.h

@@ -48,7 +48,6 @@ public:
 
 private:
     Taml*               mpTaml;
-    StringTableEntry    mTamlObjectName;
 
     typedef HashMap<SimObjectId, SimObject*> typeObjectReferenceHash;
 

+ 13 - 29
engine/source/persistence/taml/tamlXmlReader.cc

@@ -27,6 +27,12 @@
 
 //-----------------------------------------------------------------------------
 
+StringTableEntry tamlRefIdName          = StringTable->insert( "TamlId" );
+StringTableEntry tamlRefToIdName        = StringTable->insert( "TamlRefId" );
+StringTableEntry tamlNamedObjectName    = StringTable->insert( "Name" );
+
+//-----------------------------------------------------------------------------
+
 SimObject* TamlXmlReader::read( FileStream& stream )
 {
     // Debug Profiling.
@@ -285,10 +291,9 @@ void TamlXmlReader::parseAttributes( TiXmlElement* pXmlElement, SimObject* pSimO
         StringTableEntry attributeName = StringTable->insert( pAttribute->Name() );
 
         // Ignore if this is a Taml attribute.
-        if (    attributeName == mTamlRefId ||
-            attributeName == mTamlRefToId ||
-            attributeName == mTamlObjectName ||
-            attributeName == mTamlRefField )
+        if (    attributeName == tamlRefIdName ||
+                attributeName == tamlRefToIdName ||
+                attributeName == tamlNamedObjectName )
             continue;
 
         // We can assume this is a field for now.
@@ -363,7 +368,7 @@ void TamlXmlReader::parseCustomNode( TiXmlElement* pXmlElement, TamlCustomNode*
         StringTableEntry attributeName = StringTable->insert( pAttribute->Name() );
 
         // Skip if a Taml reference attribute.
-        if ( attributeName == mTamlRefId || attributeName == mTamlRefToId )
+        if ( attributeName == tamlRefIdName || attributeName == tamlRefToIdName )
             continue;
 
         // Add node field.
@@ -419,7 +424,7 @@ U32 TamlXmlReader::getTamlRefId( TiXmlElement* pXmlElement )
         StringTableEntry attributeName = StringTable->insert( pAttribute->Name() );
 
         // Skip if not the correct attribute.
-        if ( attributeName != mTamlRefId )
+        if ( attributeName != tamlRefIdName )
             continue;
 
         // Return it.
@@ -444,7 +449,7 @@ U32 TamlXmlReader::getTamlRefToId( TiXmlElement* pXmlElement )
         StringTableEntry attributeName = StringTable->insert( pAttribute->Name() );
 
         // Skip if not the correct attribute.
-        if ( attributeName != mTamlRefToId )
+        if ( attributeName != tamlRefToIdName )
             continue;
 
         // Return it.
@@ -469,7 +474,7 @@ const char* TamlXmlReader::getTamlObjectName( TiXmlElement* pXmlElement )
         StringTableEntry attributeName = StringTable->insert( pAttribute->Name() );
 
         // Skip if not the correct attribute.
-        if ( attributeName != mTamlObjectName )
+        if ( attributeName != tamlNamedObjectName )
             continue;
 
         // Return it.
@@ -480,26 +485,5 @@ const char* TamlXmlReader::getTamlObjectName( TiXmlElement* pXmlElement )
     return NULL;
 }
 
-//-----------------------------------------------------------------------------
-
-const char* TamlXmlReader::getTamlRefField( TiXmlElement* pXmlElement )
-{
-    // Iterate attributes.
-    for ( TiXmlAttribute* pAttribute = pXmlElement->FirstAttribute(); pAttribute; pAttribute = pAttribute->Next() )
-    {
-        // Insert attribute name.
-        StringTableEntry attributeName = StringTable->insert( pAttribute->Name() );
-
-        // Skip if not the correct attribute.
-        if ( attributeName != mTamlRefField )
-            continue;
-
-        // Return it.
-        return pAttribute->Value();
-    }
-
-    // Not found.
-    return NULL;
-}
 
 

+ 1 - 10
engine/source/persistence/taml/tamlXmlReader.h

@@ -42,11 +42,7 @@ class TamlXmlReader
 public:
     TamlXmlReader( Taml* pTaml ) :
         mpTaml( pTaml )
-    {
-        mTamlRefId      = StringTable->insert( TAML_ID_ATTRIBUTE_NAME );
-        mTamlRefToId    = StringTable->insert( TAML_REFID_ATTRIBUTE_NAME );
-        mTamlObjectName = StringTable->insert( TAML_OBJECTNAME_ATTRIBUTE_NAME );
-    }
+    {}
 
     virtual ~TamlXmlReader() {}
 
@@ -55,10 +51,6 @@ public:
 
 private:
     Taml*               mpTaml;
-    StringTableEntry    mTamlRefId;
-    StringTableEntry    mTamlRefToId;
-    StringTableEntry    mTamlObjectName;
-    StringTableEntry    mTamlRefField;
 
     typedef HashMap<SimObjectId, SimObject*> typeObjectReferenceHash;
 
@@ -75,7 +67,6 @@ private:
     U32 getTamlRefId( TiXmlElement* pXmlElement );
     U32 getTamlRefToId( TiXmlElement* pXmlElement );
     const char* getTamlObjectName( TiXmlElement* pXmlElement );   
-    const char* getTamlRefField( TiXmlElement* pXmlElement );
 };
 
 #endif // _TAML_XMLREADER_H_

+ 3 - 3
engine/source/persistence/taml/tamlXmlWriter.cc

@@ -97,7 +97,7 @@ TiXmlElement* TamlXmlWriter::compileElement( const TamlWriteNode* pTamlWriteNode
     if ( referenceId != 0 )
     {
         // Yes, so set reference Id attribute.
-        pElement->SetAttribute( TAML_ID_ATTRIBUTE_NAME, referenceId );
+        pElement->SetAttribute( tamlRefIdName, referenceId );
     }
 
     // Do we have a reference to node?
@@ -110,7 +110,7 @@ TiXmlElement* TamlXmlWriter::compileElement( const TamlWriteNode* pTamlWriteNode
         AssertFatal( referenceToId != 0, "Taml: Invalid reference to Id." );
 
         // Set reference to Id attribute.
-        pElement->SetAttribute( TAML_REFID_ATTRIBUTE_NAME, referenceToId );
+        pElement->SetAttribute( tamlRefToIdName, referenceToId );
 
         // Finish because we're a reference to another object.
         return pElement;
@@ -123,7 +123,7 @@ TiXmlElement* TamlXmlWriter::compileElement( const TamlWriteNode* pTamlWriteNode
     if ( pObjectName != NULL )
     {
         // Yes, so set name attribute.
-        pElement->SetAttribute( TAML_OBJECTNAME_ATTRIBUTE_NAME, pObjectName );
+        pElement->SetAttribute( tamlNamedObjectName, pObjectName );
     }
 
     // Compile attributes.

+ 6 - 2
engine/source/persistence/taml/tamlXmlWriter.h

@@ -31,6 +31,11 @@
 #include "persistence/tinyXML/tinyxml.h"
 #endif
 
+//-----------------------------------------------------------------------------
+
+extern StringTableEntry tamlRefIdName;
+static StringTableEntry tamlRefToIdName;
+static StringTableEntry tamlNamedObjectName;
 
 //-----------------------------------------------------------------------------
 
@@ -39,8 +44,7 @@ class TamlXmlWriter
 public:
     TamlXmlWriter( Taml* pTaml ) :
         mpTaml( pTaml )
-    {
-    }
+    {}
     virtual ~TamlXmlWriter() {}
 
     /// Write.