Rumba C++ SDK
maquina::Node Class Reference

Base class of all Rumba nodes. More...

#include <Node.h>

Inheritance diagram for maquina::Node:
maquina::Workspace

Classes

class  Children
 A Node children accessor. More...
 
class  Plugs
 A Plug accessor. More...
 

Public Types

using Flags = Plug::Flags
 

Public Member Functions

 Node (const char *type, const char *name, Node *parent=nullptr, bool undo_stack=false)
 Create a node. More...
 
Node duplicate (Node *parent=nullptr, bool undo_stack=false) const
 Duplicate this node, plugs, dynamic plugs and children. More...
 
void delete_node (bool undo_stack=false)
 Delete this node from the document. More...
 
void rename (const char *new_name, bool undo_stack=false)
 
const char * name () const
 Return the node name. More...
 
std::string full_name () const
 Return the node full name starting at the workspace node. More...
 
std::string full_document_name () const
 Return the node full name starting at the document node. More...
 
const char * ui_descriptor () const
 Return the node ui json descriptor. More...
 
const char * type_name () const
 Return the node type name. More...
 
StringView ui_description () const
 Return the node ui json description. More...
 
bool is_instance (const char *node_type_name) const
 Check if this node derive from another node type. More...
 
bool is_referenced () const
 Check if this node is referenced. More...
 
bool is_mutable () const
 Check if this node can be modified. More...
 
bool is_reference_root () const
 Check if this node is the root node of a reference. More...
 
bool is_reference_loaded () const
 Returns true if this node is a root reference node and the reference is loaded. More...
 
bool is_serializable () const
 Returns true if this node and all its children will be serialised on save. More...
 
bool is_document_node () const
 Returns true if this node belong to a document. More...
 
void set_serializable (bool serialize)
 
std::wstring reference_filename () const
 Returns the reference file name for this node. More...
 
void unload_reference ()
 Unload this root reference node. More...
 
void load_reference ()
 Unload this root reference node. More...
 
void replace_reference (const std::wstring &new_reference)
 Replace this root reference node with another file. More...
 
void write (const std::wstring &filename) const
 Write the node into a file. More...
 
Children children () const
 Get the node children accessor. More...
 
bool has_parent () const
 Check if this node has a parent. More...
 
Node parent () const
 Get the node parent. More...
 
void set_parent (Node &parent, bool undo_stack)
 Set the node parent. More...
 
bool has_document () const
 Check if this node is child of a Document node. More...
 
Node document () const
 Get the Document parent node. More...
 
bool has_child (const char *child_name) const
 Check if a child node exists. More...
 
Node child (const char *name) const
 Get a child node by its name. More...
 
bool is_child_of (const Node &parent) const
 Return true if this node is child of parent or is parent. More...
 
Node find_first (const char *name) const
 Get the first node named name in the children hierarchy of this node. More...
 
Plugs plugs () const
 Return the node plugs iteration. More...
 
bool has_plug (const char *plug_name) const
 Check if a plug exists. More...
 
Plug add_plug (const char *name, const Value &default_value, int flags=Flags::serial, bool undo_stack=false, const std::string &description="")
 
void remove_plug (const char *name, bool undo_stack=false)
 
void remove_plug (const Plug &plug, bool undo_stack=false)
 
Plug plug (const char *plug_name) const
 Return a plug by its name. More...
 
std::vector< Plugchannels () const
 Returns the channels of this node. More...
 
std::vector< Noderelationship ()
 Returns the nodes in relationship with this node. More...
 
const std::vector< std::string > & bases () const
 Returns a list of all the types this class derives. More...
 
Node random_child ()
 Returns a Node with a random name as child of this node. More...
 
std::shared_ptr< NodePluginplugin () const
 Returns the node plug-in, if this node has been created by a plug-in, or nullptr. More...
 
std::vector< Nodesearch (const std::string &key) const
 Search in the node childrens all the name that satisfies the key. More...
 
std::shared_ptr< class NodeDelegatenode_delegate ()
 
void notify_first_init (bool undo_stack)
 Do the one shot initialization tasks for this node. More...
 
bool operator== (const Node &o) const
 
bool operator!= (const Node &o) const
 

Detailed Description

Base class of all Rumba nodes.

A Node has plugs and children nodes.

C++ example

using namespace maquina;
// Create a root node
Node node("Node", "node");
// Create two children nodes
Node child0("Node", "child", &node);
Node child1("Node", "child", &node);
UNIT_TEST_ASSERT(strcmp(child0.name(), "child") == 0);
UNIT_TEST_ASSERT(child0.full_name() == "/node/child");
UNIT_TEST_ASSERT(child1.full_name() == "/node/child1");
// Get the parent node
UNIT_TEST_ASSERT(child0.parent() == node);
// Test if a child exists
if(node.has_child("child"))
{
Node child = node.child("child");
}
// Iterate the children nodes
for(const Node& c : node.children())
{
std::string name = c.name();
}
// Iterate the children nodes using an iterator
auto ite = node.children().begin();
++ite;
std::string name = (*ite).name();
++ite;
UNIT_TEST_ASSERT(ite == node.children().end());
// Get a plug
Plug plug = node.plug("structure");
// Iterate the plugs
for(const Plug& p : node.plugs())
{
std::string plug_name = p.name();
}
// Iterate the node plugs using an iterator
auto ite2 = node.plugs().begin();
std::string child_name = (*ite2).name();
// Create a Lerp plug-in node
Node lerp("Lerp", "lerp");
// Get a plug
Plug weight = lerp.plug("weight");
// Set its value
weight.set_value(0.5f);

Member Typedef Documentation

◆ Flags

Constructor & Destructor Documentation

◆ Node()

maquina::Node::Node ( const char *  type,
const char *  name,
Node parent = nullptr,
bool  undo_stack = false 
)

Create a node.

Exceptions
std::runtime_errorif the type is unknown.
Parameters
typeThe node type to use
nameThe node name
parentThe optional parent node
undo_stacktrue if this node creation is undoable

Member Function Documentation

◆ add_plug()

Plug maquina::Node::add_plug ( const char *  name,
const Value default_value,
int  flags = Flags::serial,
bool  undo_stack = false,
const std::string &  description = "" 
)

Add a new plug to this node.

Parameters
nameInitial name of the plug, may be changed if a plug with this name already exists
default_valueDefault value held by this plug
flagsA combination of Flags
undo_stackThe modification is undoable if this parameter is true.

◆ bases()

const std::vector<std::string>& maquina::Node::bases ( ) const

Returns a list of all the types this class derives.

◆ channels()

std::vector<Plug> maquina::Node::channels ( ) const

Returns the channels of this node.

◆ child()

Node maquina::Node::child ( const char *  name) const

Get a child node by its name.

Exceptions
std::runtime_errorif the child doesn't exist.

◆ children()

Children maquina::Node::children ( ) const

Get the node children accessor.

◆ delete_node()

void maquina::Node::delete_node ( bool  undo_stack = false)

Delete this node from the document.

Parameters
undo_stackif true, this action is undoable

◆ document()

Node maquina::Node::document ( ) const

Get the Document parent node.

Exceptions
std::runtime_errorif the node is not a child of a Document node.

◆ duplicate()

Node maquina::Node::duplicate ( Node parent = nullptr,
bool  undo_stack = false 
) const

Duplicate this node, plugs, dynamic plugs and children.

Parameters
parentThe optional parent node
undo_stacktrue if this node creation is undoable

◆ find_first()

Node maquina::Node::find_first ( const char *  name) const

Get the first node named name in the children hierarchy of this node.

Exceptions
std::runtime_errorif the node doesn't exist.

◆ full_document_name()

std::string maquina::Node::full_document_name ( ) const

Return the node full name starting at the document node.

◆ full_name()

std::string maquina::Node::full_name ( ) const

Return the node full name starting at the workspace node.

◆ has_child()

bool maquina::Node::has_child ( const char *  child_name) const

Check if a child node exists.

◆ has_document()

bool maquina::Node::has_document ( ) const

Check if this node is child of a Document node.

◆ has_parent()

bool maquina::Node::has_parent ( ) const

Check if this node has a parent.

◆ has_plug()

bool maquina::Node::has_plug ( const char *  plug_name) const

Check if a plug exists.

◆ is_child_of()

bool maquina::Node::is_child_of ( const Node parent) const

Return true if this node is child of parent or is parent.

◆ is_document_node()

bool maquina::Node::is_document_node ( ) const

Returns true if this node belong to a document.

Returns true if the node is a document or is in a document, and is serializable.

◆ is_instance()

bool maquina::Node::is_instance ( const char *  node_type_name) const

Check if this node derive from another node type.

◆ is_mutable()

bool maquina::Node::is_mutable ( ) const

Check if this node can be modified.

The node is mutable if it is not inside a reference.

◆ is_reference_loaded()

bool maquina::Node::is_reference_loaded ( ) const

Returns true if this node is a root reference node and the reference is loaded.

◆ is_reference_root()

bool maquina::Node::is_reference_root ( ) const

Check if this node is the root node of a reference.

Returns true if the node is the root of a reference node, or an unloaded reference node. In case the node is unloaded, Node::is_referenced() returns false.

◆ is_referenced()

bool maquina::Node::is_referenced ( ) const

Check if this node is referenced.

Returns true if the node is inside a reference node (read only) or if the node is a loaded root reference node (mutable).

◆ is_serializable()

bool maquina::Node::is_serializable ( ) const

Returns true if this node and all its children will be serialised on save.

◆ load_reference()

void maquina::Node::load_reference ( )

Unload this root reference node.

Unload the reference starting at this node from memory, and keep all its values and connection. If Node::is_reference_root returns false or if Node::is_reference_loaded returns true, this method has no effect.

Exceptions
std::runtime_errorif the file is corrupted

◆ name()

const char* maquina::Node::name ( ) const

Return the node name.

◆ node_delegate()

std::shared_ptr<class NodeDelegate> maquina::Node::node_delegate ( )

◆ notify_first_init()

void maquina::Node::notify_first_init ( bool  undo_stack)

Do the one shot initialization tasks for this node.

This method must be called after the first time the node has been created and added to the workspace. This will call the NodePlugin::on_first_init callback to performe extra initialization tasks.

◆ operator!=()

bool maquina::Node::operator!= ( const Node o) const
inline

◆ operator==()

bool maquina::Node::operator== ( const Node o) const
inline

◆ parent()

Node maquina::Node::parent ( ) const

Get the node parent.

Exceptions
std::runtime_errorif the node has no parent.

◆ plug()

Plug maquina::Node::plug ( const char *  plug_name) const

Return a plug by its name.

Exceptions
std::runtime_errorif the plug does not exist.

◆ plugin()

std::shared_ptr<NodePlugin> maquina::Node::plugin ( ) const

Returns the node plug-in, if this node has been created by a plug-in, or nullptr.

◆ plugs()

Plugs maquina::Node::plugs ( ) const

Return the node plugs iteration.

◆ random_child()

Node maquina::Node::random_child ( )

Returns a Node with a random name as child of this node.

◆ reference_filename()

std::wstring maquina::Node::reference_filename ( ) const

Returns the reference file name for this node.

If the node is not a reference root node, return an empty string.

◆ relationship()

std::vector<Node> maquina::Node::relationship ( )

Returns the nodes in relationship with this node.

A relationship can have different meanings. For a layer for instance, the relationship are the controllers animated in this layer.

◆ remove_plug() [1/2]

void maquina::Node::remove_plug ( const char *  name,
bool  undo_stack = false 
)

Remove a plug from this node that was added by add_plug(). If no plug with such name exists or such a plug was not added by add_plug(), this method throws an exception. Otherwise the plug is detached from the evaluation graph (inputs, outputs, dependences and back dependences are removed) and it will be destroyed when the last reference to it disappear. *

Parameters
nameActual name of the plug, not necessarily the one given to add_plug().
undo_stackThe modification is undoable if this parameter is true.
Exceptions
std::runtime_errorWhen no plug with this name can be removed.

◆ remove_plug() [2/2]

void maquina::Node::remove_plug ( const Plug plug,
bool  undo_stack = false 
)

Remove a plug from this node that was added by add_plug(). If the given plug does not belong to this node or was not added by add_plug(), this method throws an exception. Otherwise the plug is detached from the evaluation graph (inputs, outputs, dependences and back dependences are removed) and it will be destroyed when the last reference to it disappear. *

Parameters
plugThe plug to remove.
undo_stackThe modification is undoable if this parameter is true.
Exceptions
std::runtime_errorWhen no plug with this name can be removed.

◆ rename()

void maquina::Node::rename ( const char *  new_name,
bool  undo_stack = false 
)

◆ replace_reference()

void maquina::Node::replace_reference ( const std::wstring &  new_reference)

Replace this root reference node with another file.

Replace the reference with another file. The reference stays loaded or unload.

Exceptions
std::runtime_errorif the file is corrupted

◆ search()

std::vector<Node> maquina::Node::search ( const std::string &  key) const

Search in the node childrens all the name that satisfies the key.

Returns a list of nodes that satisfies the search key.

Parameters
keyThe key use in the regex to search node by name, must follow regex standard

◆ set_parent()

void maquina::Node::set_parent ( Node parent,
bool  undo_stack 
)

Set the node parent.

Exceptions
std::runtime_errorif the node can't be re-parented.

◆ set_serializable()

void maquina::Node::set_serializable ( bool  serialize)

Set the serialization flag on this node.

Parameters
serializeif false, this node and all its children will not be serialized on save.

◆ type_name()

const char* maquina::Node::type_name ( ) const

Return the node type name.

◆ ui_description()

StringView maquina::Node::ui_description ( ) const

Return the node ui json description.

◆ ui_descriptor()

const char* maquina::Node::ui_descriptor ( ) const

Return the node ui json descriptor.

◆ unload_reference()

void maquina::Node::unload_reference ( )

Unload this root reference node.

Unload the reference starting at this node from memory, and keep all its values and connection. If Node::is_reference_loaded returns false, this method has no effect.

◆ write()

void maquina::Node::write ( const std::wstring &  filename) const

Write the node into a file.

Exceptions
std::runtime_errorif the writing fails.

The documentation for this class was generated from the following file: