Browse Source

- Taml serialization WIP.

MelvMay-GG 12 years ago
parent
commit
72ec97d

+ 21 - 18
engine/source/assets/assetQuery.cc

@@ -57,7 +57,7 @@ void AssetQuery::onTamlCustomWrite( TamlCustomNodes& customNodes )
     Parent::onTamlCustomWrite( customNodes );
 
     // Add node.
-    TamlCustomNode* pCustomNode = customNodes..addProperty( ASSETQUERY_CUSTO_PROPERTY_NAME );
+    TamlCustomNode* pCustomNode = customNodes.addNode( ASSETQUERY_RESULTS_NODE_NAME );
 
     // Finish if no assets.
     if ( size() == 0 )
@@ -66,11 +66,11 @@ void AssetQuery::onTamlCustomWrite( TamlCustomNodes& customNodes )
     // Iterate asset.
     for( Vector<StringTableEntry>::iterator assetItr = begin(); assetItr != end(); ++assetItr )
     {
-        // Add alias.
-        TamlPropertyAlias* pAlias = pProperty->addAlias( ASSETQUERY_TYPE_NAME );
+        // Add custom node.
+        TamlCustomNode* pAssetNode = pCustomNode->addNode( ASSETQUERY_ASSETNODE_NAME );
 
         // Add fields.
-        pAlias->addField( ASSETQUERY_ASSETID_FIELD_NAME, *assetItr );
+        pAssetNode->addField( ASSETQUERY_ASSETID_FIELD_NAME, *assetItr );
     }
 }
 
@@ -79,30 +79,33 @@ void AssetQuery::onTamlCustomWrite( TamlCustomNodes& customNodes )
 void AssetQuery::onTamlCustomRead( const TamlCustomNodes& customNodes )
 {
     // Call parent.
-    Parent::onTamlCustomRead( customProperties );
+    Parent::onTamlCustomRead( customNodes );
 
-    // Find custom property name.
-    const TamlCustomProperty* pProperty = customProperties.findProperty( ASSETQUERY_CUSTO_PROPERTY_NAME );
+    // Find custom node name.
+    const TamlCustomNode* pResultsNode = customNodes.findNode( ASSETQUERY_RESULTS_NODE_NAME );
 
-    // Finish if we don't have a property name.
-    if ( pProperty == NULL )
+    // Finish if we don't have a results name.
+    if ( pResultsNode == NULL )
         return;
 
-    // Fetch alias name.
-    StringTableEntry typeAliasName = StringTable->insert( ASSETQUERY_TYPE_NAME );
+    // Fetch node name.
+    StringTableEntry assetNodeName = StringTable->insert( ASSETQUERY_ASSETNODE_NAME );
 
-    // Iterate property alias.
-    for( TamlCustomProperty::const_iterator propertyAliasItr = pProperty->begin(); propertyAliasItr != pProperty->end(); ++propertyAliasItr )
+    // Fetch children asset nodes.
+    const TamlCustomNodeVector& assetNodes = pResultsNode->getChildren();
+
+    // Iterate asset nodes.
+    for( TamlCustomNodeVector::const_iterator assetNodeItr = assetNodes.begin(); assetNodeItr != assetNodes.end(); ++assetNodeItr )
     {
-        // Fetch property alias.
-        const TamlPropertyAlias* pAlias = *propertyAliasItr;
+        // Fetch asset node.
+        const TamlCustomNode* pAssetNode = *assetNodeItr;
 
-        // Skip if an unknown alias name.
-        if ( pAlias->mAliasName != typeAliasName )
+        // Skip if an unknown node name.
+        if ( pAssetNode->mNodeName != assetNodeName )
             continue;
 
         // Fetch field.
-        const TamlCustomNodeField* pField = pAlias->findField( ASSETQUERY_ASSETID_FIELD_NAME );
+        const TamlCustomNodeField* pField = pAssetNode->findField( ASSETQUERY_ASSETID_FIELD_NAME );
 
         // Do we find the field?
         if ( pField == NULL )

+ 2 - 2
engine/source/assets/assetQuery.h

@@ -37,8 +37,8 @@
 
 //-----------------------------------------------------------------------------
 
-#define ASSETQUERY_CUSTO_PROPERTY_NAME      "Results"
-#define ASSETQUERY_TYPE_NAME            "Asset"
+#define ASSETQUERY_RESULTS_NODE_NAME     "Results"
+#define ASSETQUERY_ASSETNODE_NAME        "Asset"
 #define ASSETQUERY_ASSETID_FIELD_NAME   "AssetId"
 
 //-----------------------------------------------------------------------------

+ 56 - 4
engine/source/persistence/taml/tamlCustom.h

@@ -247,6 +247,53 @@ public:
         mNodeName = StringTable->insert( pNodeName );
     }
 
+    TamlCustomNode* addNode( const char* pNodeName, const bool ignoreEmpty = true )
+    {
+        // Create a custom node.
+        TamlCustomNode* pCustomNode = TamlCustomNodeFactory.createObject();
+
+        // Set node name.
+        pCustomNode->set( pNodeName );
+
+        // Set ignore-empty flag.
+        pCustomNode->mIgnoreEmpty = ignoreEmpty;
+
+        // Store node.
+        mChildren.push_back( pCustomNode );
+
+        return pCustomNode;
+    }
+
+    void removeNode( const U32 index )
+    {
+        // Sanity!
+        AssertFatal( index < (U32)mChildren.size(), "tamlCustomNode::removeNode() - Index is out of bounds." );
+
+        // Cache the custom node.
+        TamlCustomNodeFactory.cacheObject( mChildren[index] );
+
+        // Remove it.
+        mChildren.erase( index );
+    }
+
+    const TamlCustomNode* findNode( const char* pNodeName ) const
+    {
+        // Sanity!
+        AssertFatal( pNodeName != NULL, "Cannot find Taml node name that is NULL." );
+
+        // Fetch node name.
+        StringTableEntry nodeName = StringTable->insert( pNodeName );
+
+        // Find node.
+        for( Vector<TamlCustomNode*>::const_iterator nodeItr = mChildren.begin(); nodeItr != mChildren.end(); ++nodeItr )
+        {
+            if ( (*nodeItr)->mNodeName == nodeName )
+                return (*nodeItr);
+        }
+
+        return NULL;
+    }
+
     TamlCustomNodeField* addField( const char* pFieldName, const ColorI& fieldValue )
     {
         // Fetch the field value.
@@ -345,7 +392,7 @@ public:
                 continue;
 
             // Warn!
-            Con::warnf("Conflicting Taml node field name of '%s' in property alias of '%s'.", pFieldName, mNodeName );
+            Con::warnf("Conflicting Taml node field name of '%s' in node '%s'.", pFieldName, mNodeName );
 
             // Cache node field.
             TamlCustomNodeFieldFactory.cacheObject( pNodeField );
@@ -420,6 +467,9 @@ public:
         return NULL;
     }
 
+    const TamlCustomNodeVector& getChildren( void ) const { return mChildren; }
+    const TamlCustomNodeFieldVector& getFields( void ) const { return mFields; }
+
     StringTableEntry            mNodeName;
     Vector<TamlCustomNode*>     mChildren;
     TamlCustomNodeFieldVector   mFields;
@@ -475,12 +525,12 @@ public:
             // Warn!
             Con::warnf("Conflicting Taml custom node name of '%s'.", pNodeName );
 
-            // Cache property.
+            // Cache node.
             TamlCustomNodeFactory.cacheObject( pCustomNode );
             return NULL;
         }
 #endif
-        // Store property.
+        // Store node.
         mNodes.push_back( pCustomNode );
 
         return pCustomNode;
@@ -498,7 +548,7 @@ public:
         mNodes.erase( index );
     }
 
-    const TamlCustomNode* findProperty( const char* pNodeName ) const
+    const TamlCustomNode* findNode( const char* pNodeName ) const
     {
         // Sanity!
         AssertFatal( pNodeName != NULL, "Cannot find Taml node name that is NULL." );
@@ -516,6 +566,8 @@ public:
         return NULL;
     }
 
+    const TamlCustomNodeVector& getNodes( void ) const { return mNodes; }
+
 private:
     TamlCustomNodeVector mNodes;
 };