My own xml nodes
#2
Apost 
Hi!

You can do so by deriving from Graph::Node.

In the header file, write:
#include "murl_graph_node.h"
#include "app_i_my_node.h"

namespace Murl
{
    namespace App
    {
        class MyNode : public IMyNode, public Graph::Node
        {
            // Declare the attributes here:

            MURL_DECLARE_FACTORY_OBJECT_BEGIN(App::MyNode)
                MURL_DECLARE_FACTORY_OBJECT_PROPERTY(PROPERTY_MY_ATTR)
            MURL_DECLARE_FACTORY_OBJECT_END(App::MyNode)
            
            static INode* Create(const Graph::IFactory* factory);

        public:
            virtual Graph::INode* GetNodeInterface();
            virtual const Graph::INode* GetNodeInterface() const;

        protected:
            MyNode(const Graph::IFactory* factory);
            virtual ~MyNode();
            virtual Bool DeserializeBaseAttribute(Graph::IDeserializeAttributeTracker* tracker);

            // Use member variables to store attribute values.

            SInt32 mMyAttr;
        };
    }
}


Then implement in the CPP file:
using namespace Murl;

// Define the attributes here:

MURL_DEFINE_FACTORY_OBJECT_BEGIN(App::MyNode)
    MURL_DEFINE_FACTORY_OBJECT_PROPERTY(PROPERTY_MY_ATTR, "myAttr")
MURL_DEFINE_FACTORY_OBJECT_END(App::MyNode)

Graph::INode* App::MyNode::Create(const Graph::IFactory* factory)
{
    return new MyNode(factory);
}

App::MyNode::MyNode(const Graph::IFactory* factory)
: Graph::Node(factory)
, mMyAttr(0)
{
}

App::MyNode::~MyNode()
{
}

Graph::INode* App::MyNode::GetNodeInterface()
{
    return this;
}

const Graph::INode* App::MyNode::GetNodeInterface() const
{
    return this;
}

Bool App::MyNode::DeserializeBaseAttribute(Graph::IDeserializeAttributeTracker* tracker)
{
    switch(tracker->GetBaseAttributeProperty(GetProperties()))
    {
        case PROPERTY_MY_ATTR:
            tracker->GetAttributeValue(mMyAttr);
            return true;

        // handle other attributes here

        default:
            return Graph::Node::DeserializeBaseAttribute(tracker);
    }
}


You may want to override the InitSelf, ProcessLogicSelf, etc. methods from Graph::Node to add custom behavior.

Finally, you need to register/unregister the node in your App class by overriding these methods from AppBase:
Bool App::MyApp::RegisterCustomFactoryClasses(IAppFactoryRegistry* factoryRegistry)
{
    factoryRegistry->GetGraphFactoryRegistry()->RegisterNodeClass(App::MyNode::GetClassInfo());
    return true;
}

Bool App::MyApp::UnregisterCustomFactoryClasses(IAppFactoryRegistry* factoryRegistry)
{
    factoryRegistry->GetGraphFactoryRegistry()->UnregisterNodeClass(App::MyNode::GetClassInfo());
    return true;
}


Now you can use:

<App::MyNode myAttr="42"/>


Or:

<MyNode myAttr="42"/>


Wink
Reply


Messages In This Thread
My own xml nodes - by CodingMarmot - 17 Jul 2013, 12:51
RE: My own xml nodes - by Stefan - 18 Jul 2013, 15:54
RE: My own xml nodes - by CodingMarmot - 19 Jul 2013, 8:39
RE: My own xml nodes - by yothsoggoth - 16 Dec 2014, 23:51
RE: My own xml nodes - by dizzy - 18 Dec 2014, 7:53

Forum Jump:


Copyright © 2011-2021 Spraylight GmbH.