Browse Source

- TAML schema WIP.

MelvMay-GG 12 years ago
parent
commit
af7925c

+ 22 - 0
engine/source/console/consoleObject.cc

@@ -73,6 +73,28 @@ AbstractClassRep* AbstractClassRep::findFieldRoot( StringTableEntry fieldName )
 
 //-----------------------------------------------------------------------------
 
+AbstractClassRep* AbstractClassRep::findContainerChildRoot( AbstractClassRep* pChild )
+{
+    // Fetch container child.
+    AbstractClassRep* pContainerChildClass = getContainerChildClass( true );
+
+    // Finish if not found.
+    if ( pContainerChildClass == NULL )
+        return NULL;
+
+    // We're the root for the child if we have no parent.
+    if ( getParentClass() == NULL )
+        return this;
+
+    // Find child in parent.
+    AbstractClassRep* pParentContainerChildClass = getParentClass()->findContainerChildRoot( pChild );
+
+    // We;re the root if the parent does not contain the child else return the container root.
+    return pParentContainerChildClass == NULL ? this : pParentContainerChildClass;
+}
+
+//-----------------------------------------------------------------------------
+
 AbstractClassRep* AbstractClassRep::findClassRep(const char* in_pClassName)
 {
    AssertFatal(initialized,

+ 6 - 4
engine/source/console/consoleObject.h

@@ -197,7 +197,7 @@ public:
    Namespace*                 getNameSpace();
    AbstractClassRep*          getNextClass();
    AbstractClassRep*          getParentClass();
-   virtual AbstractClassRep*  getContainerChildClass() = 0;
+   virtual AbstractClassRep*  getContainerChildClass( const bool recurse ) = 0;
 
    /// Helper class to see if we are a given class, or a subclass thereof.
    bool                       isClass(AbstractClassRep  *acr)
@@ -274,6 +274,8 @@ public:
    const Field *findField(StringTableEntry fieldName) const;
 
    AbstractClassRep* findFieldRoot( StringTableEntry fieldName );
+
+   AbstractClassRep* findContainerChildRoot( AbstractClassRep* pChild );
    
    /// @}
 
@@ -369,11 +371,11 @@ public:
       registerClassRep(this);
    };
 
-    virtual AbstractClassRep* getContainerChildClass()
+    virtual AbstractClassRep* getContainerChildClass( const bool recurse )
     {
         // Fetch container children type.
         AbstractClassRep* pChildren = T::getContainerChildStaticClassRep();
-        if ( pChildren != NULL )
+        if ( !recurse || pChildren != NULL )
             return pChildren;
 
         // Fetch parent type.
@@ -382,7 +384,7 @@ public:
             return NULL;
 
         // Get parent container children.
-        return pParent->getContainerChildClass();
+        return pParent->getContainerChildClass( recurse );
     }
 
    /// Perform class specific initialization tasks.

+ 1 - 1
engine/source/gui/guiControl.cc

@@ -41,7 +41,7 @@
 
 //------------------------------------------------------------------------------
 
-IMPLEMENT_CONOBJECT(GuiControl);
+IMPLEMENT_CONOBJECT_CHILDREN(GuiControl);
 
 //used to locate the next/prev responder when tab is pressed
 S32 GuiControl::smCursorChanged           = -1;

+ 1 - 0
engine/source/gui/guiControl.h

@@ -94,6 +94,7 @@ class GuiControl : public SimGroup
 {
 private:
    typedef SimGroup Parent;
+   typedef GuiControl Children;
 
 public:
 

+ 37 - 42
engine/source/persistence/taml/taml.cc

@@ -858,7 +858,6 @@ bool Taml::generateTamlSchema( const char* pFilename )
 
     // Reset scratch state.
     char buffer[1024];
-    HashMap<AbstractClassRep*, StringTableEntry> containerGroups;
 
     // Generate the type elements.
     TiXmlComment* pComment = new TiXmlComment( "Type Elements" );
@@ -909,55 +908,51 @@ bool Taml::generateTamlSchema( const char* pFilename )
         }
 
         // Fetch container child class.
-        AbstractClassRep* pContainerChildClass = pType->getContainerChildClass();
+        AbstractClassRep* pContainerChildClass = pType->getContainerChildClass( false );
 
         // Is the type allowed children?
         if ( pContainerChildClass != NULL )
         {
-            //  Yes, so do we already have a group for this?
-            HashMap<AbstractClassRep*, StringTableEntry>::iterator groupItr = containerGroups.find( pContainerChildClass );
-            if ( groupItr == containerGroups.end() )
-            {
-                // No, so add group comment.
-                dSprintf( buffer, sizeof(buffer), " %s Child Group ", pContainerChildClass->getClassName() );
-                TiXmlComment* pComment = new TiXmlComment( buffer );
-                pSchemaElement->LinkEndChild( pComment );
+            // Yes, so add group comment.
+            dSprintf( buffer, sizeof(buffer), " %s Children Group ", pType->getClassName() );
+            TiXmlComment* pComment = new TiXmlComment( buffer );
+            pSchemaElement->LinkEndChild( pComment );
 
-                // Format the group name.
-                dSprintf( buffer, sizeof(buffer), "%s_ChildGroup", pContainerChildClass->getClassName() );
+            // Format the group name.
+            dSprintf( buffer, sizeof(buffer), "%s_ChildGroup", pType->getClassName() );
                 
-                // Insert into groups.
-                groupItr = containerGroups.insert( pContainerChildClass, StringTable->insert( buffer ) );
-
-                // Add group.
-                TiXmlElement* pGroupElement = new TiXmlElement( "xs:group" );
-                pGroupElement->SetAttribute( "name", buffer );
-                pSchemaElement->LinkEndChild( pGroupElement );
-                TiXmlElement* pGroupChoiceElement = new TiXmlElement( "xs:choice" );
-                pGroupElement->LinkEndChild( pGroupChoiceElement );
-
-                // Add group members.
-                for ( AbstractClassRep* pGroupType = pRootType; pGroupType != NULL; pGroupType = pGroupType->getNextClass() )
-                {
-                    // Skip if not derived from the container child class.
-                    if ( !pGroupType->isClass( pContainerChildClass ) )
-                        continue;
-
-                    // Add group member.
-                    TiXmlElement* pGroupMemberElement = new TiXmlElement( "xs:element" );
-                    pGroupMemberElement->SetAttribute( "name", pGroupType->getClassName() );
-                    dSprintf( buffer, sizeof(buffer), "%s_Type", pGroupType->getClassName() );
-                    pGroupMemberElement->SetAttribute( "type", buffer );
-                    pGroupChoiceElement->LinkEndChild( pGroupMemberElement );
-                }
-            }
+            // Add group.
+            TiXmlElement* pGroupElement = new TiXmlElement( "xs:group" );
+            pGroupElement->SetAttribute( "name", buffer );
+            pSchemaElement->LinkEndChild( pGroupElement );
+            TiXmlElement* pGroupChoiceElement = new TiXmlElement( "xs:choice" );
+            pGroupElement->LinkEndChild( pGroupChoiceElement );
 
             // Add group reference.
-            TiXmlElement* pGroupElement = new TiXmlElement( "xs:group" );
-            pGroupElement->SetAttribute( "ref", groupItr->value );
-            pGroupElement->SetAttribute( "minOccurs", "0" );
-            pGroupElement->SetAttribute( "maxOccurs", "unbounded" );
-            pContentParentElement->LinkEndChild( pGroupElement );
+            TiXmlElement* pGroupReferenceElement = new TiXmlElement( "xs:group" );
+            pGroupReferenceElement->SetAttribute( "ref", buffer );
+            pGroupReferenceElement->SetAttribute( "minOccurs", "0" );
+            pGroupReferenceElement->SetAttribute( "maxOccurs", "unbounded" );
+            pContentParentElement->LinkEndChild( pGroupReferenceElement );
+
+            // Add group members.
+            for ( AbstractClassRep* pGroupType = pRootType; pGroupType != NULL; pGroupType = pGroupType->getNextClass() )
+            {
+                // Skip if not derived from the container child class.
+                if ( !pGroupType->isClass( pContainerChildClass ) )
+                    continue;
+
+                // Skip if a parent contains the child class already.
+                if ( pType->findContainerChildRoot( pGroupType ) != pType )
+                    continue;
+
+                // Add group member.
+                TiXmlElement* pGroupMemberElement = new TiXmlElement( "xs:element" );
+                pGroupMemberElement->SetAttribute( "name", pGroupType->getClassName() );
+                dSprintf( buffer, sizeof(buffer), "%s_Type", pGroupType->getClassName() );
+                pGroupMemberElement->SetAttribute( "type", buffer );
+                pGroupChoiceElement->LinkEndChild( pGroupMemberElement );
+            }
         }
 
         // Iterate static fields.

+ 1 - 1
engine/source/persistence/taml/tamlBinaryReader.cc

@@ -272,7 +272,7 @@ void TamlBinaryReader::parseChildren( Stream& stream, TamlCallbacks* pCallbacks,
     }
 
     // Fetch any container child class specifier.
-    AbstractClassRep* pContainerChildClass = pSimObject->getClassRep()->getContainerChildClass();
+    AbstractClassRep* pContainerChildClass = pSimObject->getClassRep()->getContainerChildClass( true );
 
     // Iterate children.
     for ( U32 index = 0; index < childrenCount; ++ index )

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

@@ -175,7 +175,7 @@ SimObject* TamlXmlReader::parseElement( TiXmlElement* pXmlElement )
         TamlChildren* pChildren = dynamic_cast<TamlChildren*>( pSimObject );
 
         // Fetch any container child class specifier.
-        AbstractClassRep* pContainerChildClass = pSimObject->getClassRep()->getContainerChildClass();
+        AbstractClassRep* pContainerChildClass = pSimObject->getClassRep()->getContainerChildClass( true );
 
         // Iterate siblings.
         do

+ 1 - 2
engine/source/sim/simSet.cc

@@ -246,8 +246,7 @@ SimObject* SimSet::findObjectByInternalName(const char* internalName, bool searc
 
 //////////////////////////////////////////////////////////////////////////
 
-IMPLEMENT_CONOBJECT(SimSet);
-
+IMPLEMENT_CONOBJECT_CHILDREN(SimSet);
 
 
 inline void SimSetIterator::Stack::push_back(SimSet* set)

+ 2 - 0
engine/source/sim/simSet.h

@@ -101,6 +101,8 @@
 class SimSet: public SimObject, public TamlChildren
 {
    typedef SimObject Parent;
+   typedef SimObject Children;
+
 protected:
    SimObjectList objectList;
    void *mMutex;