Browse Source

- Taml serialization WIP.

MelvMay-GG 12 years ago
parent
commit
8ef8090

+ 5 - 0
engine/source/persistence/taml/tamlBinaryReader.cc

@@ -362,6 +362,11 @@ void TamlBinaryReader::parseCustomNode( Stream& stream, TamlCustomNode* pCustomN
     // Add child node.
     // Add child node.
     TamlCustomNode* pChildNode = pCustomNode->addNode( nodeName );
     TamlCustomNode* pChildNode = pCustomNode->addNode( nodeName );
 
 
+    // Read child node text.
+    char childNodeTextBuffer[MAX_TAML_NODE_FIELDVALUE_LENGTH];
+    stream.readLongString( MAX_TAML_NODE_FIELDVALUE_LENGTH, childNodeTextBuffer );
+    pChildNode->setNodeText( childNodeTextBuffer );
+
     // Read child node count.
     // Read child node count.
     U32 childNodeCount;
     U32 childNodeCount;
     stream.read( &childNodeCount );
     stream.read( &childNodeCount );

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

@@ -245,6 +245,9 @@ void TamlBinaryWriter::writeCustomNode( Stream& stream, const TamlCustomNode* pC
     // Write custom node name.
     // Write custom node name.
     stream.writeString( pCustomNode->getNodeName() );
     stream.writeString( pCustomNode->getNodeName() );
 
 
+    // Write custom node text.
+    stream.writeString( pCustomNode->getNodeText().getFieldValue(), MAX_TAML_NODE_FIELDVALUE_LENGTH );
+
     // Fetch node children.
     // Fetch node children.
     const TamlCustomNodeVector& nodeChildren = pCustomNode->getChildren();
     const TamlCustomNodeVector& nodeChildren = pCustomNode->getChildren();
 
 

+ 15 - 6
engine/source/persistence/taml/tamlCustom.h

@@ -183,6 +183,8 @@ public:
         return ( fieldName == comparison );
         return ( fieldName == comparison );
     }
     }
 
 
+    inline bool isValueEmpty( void ) const { return *mFieldValue == 0; }
+
 private:
 private:
     StringTableEntry    mFieldName;
     StringTableEntry    mFieldName;
     char                mFieldValue[MAX_TAML_NODE_FIELDVALUE_LENGTH];
     char                mFieldValue[MAX_TAML_NODE_FIELDVALUE_LENGTH];
@@ -234,6 +236,9 @@ public:
         // Reset the node name.
         // Reset the node name.
         mNodeName = StringTable->EmptyString;
         mNodeName = StringTable->EmptyString;
 
 
+        // Reset node text.
+        mNodeText.resetState();
+
         // Reset the ignore empty flag.
         // Reset the ignore empty flag.
         mIgnoreEmpty = false;
         mIgnoreEmpty = false;
     }
     }
@@ -258,17 +263,14 @@ public:
 
 
     inline TamlCustomNode* addNode( const char* pNodeName, const bool ignoreEmpty = true )
     inline TamlCustomNode* addNode( const char* pNodeName, const bool ignoreEmpty = true )
     {
     {
-        // Sanity!
-        AssertFatal( pNodeName != NULL, "Cannot add a NULL node name." );
-
         // Create a custom node.
         // Create a custom node.
         TamlCustomNode* pCustomNode = TamlCustomNodeFactory.createObject();
         TamlCustomNode* pCustomNode = TamlCustomNodeFactory.createObject();
 
 
         // Fetch node name.
         // Fetch node name.
-        StringTableEntry nodeName = StringTable->insert( pNodeName );
+        pCustomNode->setNodeName( pNodeName );
 
 
         // Set ignore-empty flag.
         // Set ignore-empty flag.
-        pCustomNode->mIgnoreEmpty = ignoreEmpty;
+        pCustomNode->setIgnoreEmpty( ignoreEmpty );
 
 
         // Store node.
         // Store node.
         mChildren.push_back( pCustomNode );
         mChildren.push_back( pCustomNode );
@@ -459,9 +461,15 @@ public:
 
 
     inline StringTableEntry getNodeName( void ) const { return mNodeName; }
     inline StringTableEntry getNodeName( void ) const { return mNodeName; }
 
 
+    void setWriteNode( TamlWriteNode* pWriteNode );
 
 
+    inline void setNodeText( const char* pNodeText )
+    {
+        AssertFatal( dStrlen( pNodeText ) >= MAX_TAML_NODE_FIELDVALUE_LENGTH, "Custom node text is too long." );
 
 
-    void setWriteNode( TamlWriteNode* pWriteNode );
+        mNodeText.set( StringTable->EmptyString, pNodeText );
+    }
+    inline const TamlCustomField& getNodeText( void ) const { return mNodeText; }
 
 
     inline const Vector<TamlCustomNode*>& getChildren( void ) const { return mChildren; }
     inline const Vector<TamlCustomNode*>& getChildren( void ) const { return mChildren; }
     inline const TamlCustomFieldVector& getFields( void ) const { return mFields; }
     inline const TamlCustomFieldVector& getFields( void ) const { return mFields; }
@@ -478,6 +486,7 @@ public:
 
 
 private:
 private:
     StringTableEntry        mNodeName;
     StringTableEntry        mNodeName;
+    TamlCustomField         mNodeText;
     Vector<TamlCustomNode*> mChildren;
     Vector<TamlCustomNode*> mChildren;
     TamlCustomFieldVector   mFields;
     TamlCustomFieldVector   mFields;
     bool                    mIgnoreEmpty;
     bool                    mIgnoreEmpty;

+ 25 - 15
engine/source/persistence/taml/tamlXmlReader.cc

@@ -330,9 +330,33 @@ void TamlXmlReader::parseCustomNode( TiXmlElement* pXmlElement, TamlCustomNode*
         return;
         return;
     }
     }
 
 
-    // Add child node.
+    // Yes, so add child node.
     TamlCustomNode* pChildNode = pCustomNode->addNode( pXmlElement->Value() );
     TamlCustomNode* pChildNode = pCustomNode->addNode( pXmlElement->Value() );
 
 
+    // Iterate attributes.
+    for ( TiXmlAttribute* pAttribute = pXmlElement->FirstAttribute(); pAttribute; pAttribute = pAttribute->Next() )
+    {
+        // Insert attribute name.
+        StringTableEntry attributeName = StringTable->insert( pAttribute->Name() );
+
+        // Skip if a Taml reference attribute.
+        if ( attributeName == mTamlRefId || attributeName == mTamlRefToId )
+            continue;
+
+        // Add node field.
+        pChildNode->addField( attributeName, pAttribute->Value() );
+    }
+
+    // Fetch any element text.
+    const char* pElementText = pXmlElement->GetText();
+
+    // Do we have any element text?
+    if ( pElementText != NULL )
+    {
+        // Yes, so store it.
+        pChildNode->setNodeText( pElementText );
+    }
+
     // Fetch any children.
     // Fetch any children.
     TiXmlNode* pChildXmlNode = pXmlElement->FirstChild();
     TiXmlNode* pChildXmlNode = pXmlElement->FirstChild();
 
 
@@ -356,20 +380,6 @@ void TamlXmlReader::parseCustomNode( TiXmlElement* pXmlElement, TamlCustomNode*
         }
         }
         while( pChildXmlNode != NULL );
         while( pChildXmlNode != NULL );
     }
     }
-
-    // Iterate attributes.
-    for ( TiXmlAttribute* pAttribute = pXmlElement->FirstAttribute(); pAttribute; pAttribute = pAttribute->Next() )
-    {
-        // Insert attribute name.
-        StringTableEntry attributeName = StringTable->insert( pAttribute->Name() );
-
-        // Skip if a Taml reference attribute.
-        if ( attributeName == mTamlRefId || attributeName == mTamlRefToId )
-            continue;
-
-        // Add node field.
-        pChildNode->addField( attributeName, pAttribute->Value() );
-    }
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------

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

@@ -70,7 +70,7 @@ private:
 
 
     SimObject* parseElement( TiXmlElement* pXmlElement );
     SimObject* parseElement( TiXmlElement* pXmlElement );
     void parseAttributes( TiXmlElement* pXmlElement, SimObject* pSimObject );
     void parseAttributes( TiXmlElement* pXmlElement, SimObject* pSimObject );
-    void parseCustomElement( TiXmlElement* pXmlElement, TamlCustomNodes& customNodes );
+    void parseCustomElement( TiXmlElement* pXmlElement, TamlCustomNodes& pCustomNode );
     void parseCustomNode( TiXmlElement* pXmlElement, TamlCustomNode* pCustomNode );
     void parseCustomNode( TiXmlElement* pXmlElement, TamlCustomNode* pCustomNode );
 
 
     U32 getTamlRefId( TiXmlElement* pXmlElement );
     U32 getTamlRefId( TiXmlElement* pXmlElement );

+ 20 - 13
engine/source/persistence/taml/tamlXmlWriter.cc

@@ -212,6 +212,26 @@ void TamlXmlWriter::compileCustomNode( TiXmlElement* pXmlElement, const TamlCust
     // Create element.
     // Create element.
     TiXmlElement* pNodeElement = new TiXmlElement( pCustomNode->getNodeName() );
     TiXmlElement* pNodeElement = new TiXmlElement( pCustomNode->getNodeName() );
 
 
+    // Is there any node text?
+    if ( !pCustomNode->getNodeText().isValueEmpty() )
+    {
+        // Yes, so add a text node.
+        pNodeElement->LinkEndChild( new TiXmlText( pCustomNode->getNodeText().getFieldValue() ) );
+    }
+
+    // Fetch fields.
+    const TamlCustomFieldVector& fields = pCustomNode->getFields();
+
+    // Iterate fields.
+    for ( TamlCustomFieldVector::const_iterator fieldItr = fields.begin(); fieldItr != fields.end(); ++fieldItr )
+    {
+        // Fetch field.
+        const TamlCustomField* pField = *fieldItr;
+
+        // Set field.
+        pNodeElement->SetAttribute( pField->getFieldName(), pField->getFieldValue() );
+    }
+
     // Fetch node children.
     // Fetch node children.
     const TamlCustomNodeVector& nodeChildren = pCustomNode->getChildren();
     const TamlCustomNodeVector& nodeChildren = pCustomNode->getChildren();
 
 
@@ -235,19 +255,6 @@ void TamlXmlWriter::compileCustomNode( TiXmlElement* pXmlElement, const TamlCust
         }
         }
     }
     }
 
 
-    // Fetch fields.
-    const TamlCustomFieldVector& fields = pCustomNode->getFields();
-
-    // Iterate fields.
-    for ( TamlCustomFieldVector::const_iterator fieldItr = fields.begin(); fieldItr != fields.end(); ++fieldItr )
-    {
-        // Fetch field.
-        const TamlCustomField* pField = *fieldItr;
-
-        // Set field.
-        pNodeElement->SetAttribute( pField->getFieldName(), pField->getFieldValue() );
-    }
-
     // Finish if the node is set to ignore if empty and it is empty (including fields).
     // Finish if the node is set to ignore if empty and it is empty (including fields).
     if ( pCustomNode->getIgnoreEmpty() && fields.size() == 0 && pNodeElement->NoChildren() )
     if ( pCustomNode->getIgnoreEmpty() && fields.size() == 0 && pNodeElement->NoChildren() )
     {
     {