@smellymumbler Hey, for sure. In fact, I can refer you directly to the source!
In our approach, we have three main classes for the Node Graph:
- IoGraph - handles node add/delete, link add/delete, and solving the graph.
- IoComponentBase - the base class for inheriting nodes that do particular things. There are a bunch of important functions in this class, but by far the most important is the SolveInstance. This handles what exactly the node does.
- IoInputSlot and IoOutputSlot - these classes handle what kind of data is passed to SolveInstance, and the level of DataAccess (i.e. Item, List, Tree).
So, to interact with the NodeGraph, you would create some custom nodes from IoComponentBase and then add them to the graph, along with some connections, and add some data at the exposed input slots. Here is an example from one of the tests:
Context* myContext = new Context();
//the data
Vector<Variant> someFloats;
someFloats.Push(7.0f);
someFloats.Push(9.0f);
someFloats.Push(11.0f);
someFloats.Push(13.0f);
someFloats.Push(15.0f);
someFloats.Push(17.0f);
//push data to data tree
IoDataTree tree0(myContext, someFloats);
//create graph object
IoGraph g(myContext);
//create the Mass Average component
SharedPtr<IoComponentBase> averager(new Maths_MassAverage(myContext));
g.AddNewComponent(averager);
//add the data tree input at component index 0, input slot index 0
g.SetInputIoDataTree(0, 0, tree0);
//solve using topological sorting
g.TopoSolveGraph();
//collect data
IoDataTree outTree(myContext);
g.GetOutputIoDataTree(0, 0, outTree);
We use a topological sorting algorithm that orders that orders the nodes by their rank (i.e. how many edges away from being a root node). Then, you can loop through the nodes and call the Solve methods.