MicroNodeInterface Class Reference

#include <corenodes_instances.h>

Inheritance diagram for MicroNodeInterface:

Detailed Description

A MicroNodeInterface instance wraps a MicroNode so that it can be part of a micro node group.

MicroNodeInterface instances aren't created directly, instead you create them by one of the MicroNodeGroupRef::Add functions which get a MicroNode as parameter and impliclity create the required MicroNodeInterface wrapper. For example in the following code

class MyNode
{
public:
... port declarations ...
class Impl : public BasicMicroNode
{
public:
Result<void> Process(const Ports<...>& ports) const;
};
static Result<void> Init(const MicroNodeGroupRef& group)
{
iferr_scope;
MicroNodePtr<Impl> n = group.AddChild<Impl>() iferr_return;
... optionally do something with n, usually not needed ...
return OK;
}
};

the call to Add adds an instance of the BasicMicroNode implementation class Impl to #group and returns a pointer to the MicroNodeInterface instance which wraps the Impl object.

MicroNodeInterface instances are always owned by the enclosing micro node group, therefore there is no reference class.

Public Member Functions

MAXON_FUNCTION const MicroNodeGroupInterfaceGetParentGroup () const
 
MAXON_FUNCTION MicroNodeGroupInterfaceGetParentGroup ()
 
MAXON_METHOD MicroNode::TYPE GetType () const
 
MAXON_METHOD const MN & GetImplementation () const
 
MicroNodeGetImplementation ()
 
MAXON_METHOD void AddFlags (MicroNode::FLAGS flags)
 
MAXON_METHOD Result< void > SetDataType (const DataType &type)
 
template<typename VARIADIC_ACCESS , typename MN >
MAXON_FUNCTION Result< BaseArray< typename VARIADIC_ACCESS::VPort::PortId > > AddVariadicPort (VARIADIC_ACCESS MN::*acc, const CString &prefix, const Data &arg, WIRETYPE wires=VARIADIC_ACCESS::VPort::DEFAULT_WIRE, const DataType &type=GetZeroRef< DataType >(), MicroNode::FLAGS flags=MicroNode::FLAGS::NONE)
 
template<typename VARIADIC_ACCESS , typename MN >
MAXON_FUNCTION Result< BaseArray< typename VARIADIC_ACCESS::VPort::PortId > > AddVariadicPort (VARIADIC_ACCESS MN::*acc, const CString &prefix, Int count, Int base=0, WIRETYPE wires=VARIADIC_ACCESS::VPort::DEFAULT_WIRE, MicroNode::FLAGS flags=MicroNode::FLAGS::NONE)
 
template<typename VARIADIC_ACCESS , typename MN >
MAXON_FUNCTION Result< BaseArray< typename VARIADIC_ACCESS::VPort::PortId > > AddVariadicPort (VARIADIC_ACCESS MN::*acc, const Block< const Member > &members, WIRETYPE wires=VARIADIC_ACCESS::VPort::DEFAULT_WIRE, MicroNode::FLAGS flags=MicroNode::FLAGS::NONE)
 
MAXON_METHOD Result< void > Connect (ACCESS_INDEX thisIndex, MicroNodeInterface *target, ACCESS_INDEX targetIndex, WIRETYPE wires)
 
MAXON_FUNCTION Result< void > Connect (MicroNodeInterface *target, WIRETYPE wires)
 
MAXON_FUNCTION Result< InPortIdExport (const InPortId &parentPort, WIRETYPE wires, ACCESS_INDEX index, const DataType &type=DataType::NullValue(), MicroNode::FLAGS flags=MicroNode::FLAGS::NONE)
 
MAXON_FUNCTION Result< InPortIdExport (const InPortId &parentPort, WIRETYPE wires=WIRETYPE::DEFAULT_INPUT, MicroNode::FLAGS flags=MicroNode::FLAGS::NONE)
 
MAXON_FUNCTION Result< OutPortIdExport (const OutPortId &parentPort, WIRETYPE wires, ACCESS_INDEX index, const DataType &type=DataType::NullValue(), MicroNode::FLAGS flags=MicroNode::FLAGS::NONE)
 
MAXON_FUNCTION Result< OutPortIdExport (const OutPortId &parentPort, WIRETYPE wires=WIRETYPE::DEFAULT_OUTPUT, MicroNode::FLAGS flags=MicroNode::FLAGS::NONE)
 
template<typename PORT >
MAXON_FUNCTION Result< typename PORT::PortIdType > Export (const PORT &parentPort, WIRETYPE wires=PORT::PortIdType::DEFAULT_WIRE, ACCESS_INDEX index=ACCESS_INDEX::UNUSED, MicroNode::FLAGS flags=MicroNode::FLAGS::NONE)
 
template<typename MN , typename A , typename... ARGS>
MAXON_FUNCTION Result< void > operator() (Result< A > &&arg, ARGS &&... args)
 
template<typename MN , typename A , typename... ARGS>
MAXON_FUNCTION Result< void > operator() (A &&arg, ARGS &&... args)
 
- Public Member Functions inherited from CoreNodeInstanceBaseInterface
MAXON_METHOD const IdGetName () const
 
MAXON_METHOD void SetName (const Id &name)
 
MAXON_METHOD const CoreNodeBaseInterfaceGetParentGroup () const
 
MAXON_FUNCTION CoreNodeBaseInterfaceGetParentGroup ()
 
MAXON_METHOD const NodeHandle * GetHandle () const
 
template<typename... INSTANCEPATH>
MAXON_FUNCTION Result< const NodeHandle * > GetHandle (const INSTANCEPATH &... path) const
 
MAXON_FUNCTION String ToString (const FormatStatement *fmt=nullptr) const
 
MAXON_METHOD const DataGetUserData () const
 
MAXON_METHOD void SetUserData (Data &&value)
 
MAXON_METHOD const DataDictionary & GetCompilationData () const
 
MAXON_METHOD void SetCompilationData (DataDictionary &&data)
 

Private Member Functions

 MAXON_INTERFACE_NONVIRTUAL_DERIVED (MicroNodeInterface, MAXON_REFERENCE_POINTER, "net.maxon.corenode.interface.micronode")
 
 MAXON_GENERIC ((std::is_base_of) typename MN=MicroNode)
 
MAXON_METHOD Result< IntExportImpl (const PortId &parentPort, WIRETYPE wires, ACCESS_INDEX index, const DataType &type, MicroNode::FLAGS flags)
 
template<typename MN >
ResultOk< void > operator() ()
 
template<typename MN , typename T , typename = typename std::enable_if<MN::template AllowsChild<T>::value && T::template AllowsParent<MN>::value>::type>
Result< void > AddChild (MicroNodePtr< T > mn, WIRETYPE wt=WIRETYPE::DOMAIN_FLOW|WIRETYPE::HIERARCHY)
 

Additional Inherited Members

- Static Public Member Functions inherited from CoreNodeInstanceBaseInterface
static MAXON_METHOD Result< BaseArray< const CoreNodeInstanceBaseInterface * > > GetInstancePath (const NodeHandle *handle)
 
static MAXON_METHOD String PrivateNodeHandleToString (const NodeHandle *handle, const FormatStatement *fs)
 

Member Function Documentation

◆ MAXON_INTERFACE_NONVIRTUAL_DERIVED()

MAXON_INTERFACE_NONVIRTUAL_DERIVED ( MicroNodeInterface  ,
MAXON_REFERENCE_POINTER  ,
"net.maxon.corenode.interface.micronode"   
)
private

◆ MAXON_GENERIC()

MAXON_GENERIC ( (std::is_base_of) typename  MN = MicroNode)
private

The type of the micro node implementation class of this micro node.

◆ GetParentGroup() [1/2]

MAXON_FUNCTION const MicroNodeGroupInterface* GetParentGroup ( ) const

Returns the micro node group to which this micro node belongs.

Returns
The parent group of this micro node.

◆ GetParentGroup() [2/2]

Returns the micro node group to which this micro node belongs.

Returns
The parent group of this micro node.

◆ GetType()

MAXON_METHOD MicroNode::TYPE GetType ( ) const

Returns the type of this micro node. This is the type of the MicroNode implementation wrapped by this node.

Returns
The type of this node.

◆ GetImplementation() [1/2]

MAXON_METHOD const MN& GetImplementation ( ) const

Returns the MicroNode implementation which is wrapped by this MicroNodeInterface instance.

Returns
The implementation type of this node.

◆ GetImplementation() [2/2]

MicroNode& GetImplementation ( )

Returns the MicroNode implementation which is wrapped by this MicroNodeInterface instance.

Returns
The implementation type of this node.

◆ AddFlags()

MAXON_METHOD void AddFlags ( MicroNode::FLAGS  flags)

Adds additional flags to the micro node.

Parameters
[in]flagsThe flags to add. Only modifier flags (MicroNode::FLAGS::MODIFIERS) can be added.

◆ SetDataType()

MAXON_METHOD Result<void> SetDataType ( const DataType type)

Sets the data type of this micro node. This is only supported for a subset of micro nodes.

Parameters
[in]typeThe data type of this micro node.

◆ AddVariadicPort() [1/3]

MAXON_FUNCTION Result<BaseArray<typename VARIADIC_ACCESS::VPort::PortId> > AddVariadicPort ( VARIADIC_ACCESS MN::*  acc,
const CString prefix,
const Data arg,
WIRETYPE  wires = VARIADIC_ACCESS::VPort::DEFAULT_WIRE,
const DataType type = GetZeroRef<DataType>(),
MicroNode::FLAGS  flags = MicroNode::FLAGS::NONE 
)

Adds a variadic port to this micro node. The number and names of the variadic port instances are determined from arg:

  • If arg wraps an Array<VariadicInstance>, then it defines number and names. If prefix is given, it is used as a prefix with a # as an additional separation character.
  • If arg wraps a non-negative Int, then it defines the number of port instances. The names are given by the prefix, followed by a # and a 0-based index.
  • Otherwise a single instance is added whose name is just the prefix followed by a #. This special case is only needed for CoreNodeWrapper: It has to create node templates for core nodes, and this special case allows to instantiate a core node with a placeholder port which stands for an arbitrary number of port instances.

The typical use looks as follows:

template <typename T> class SumNode
{
public:
MAXON_PORT_OUTPUT(T, out);
class Impl : public BasicMicroNode
{
public:
Result<void> Process(const Ports<out>& ports) const
{
T sum = T();
for (auto input : _inputs(ports))
sum += input();
ports.out.Update(sum);
return OK;
}
typename VariadicPort<const T>::Access _inputs;
};
static Result<void> Init(const MicroNodeGroupRef& group, const DataDictionary& args)
{
iferr_scope;
MicroNodePtr<Impl> base = group.AddChild<Impl>() iferr_return;
base.AddVariadicPort(&Impl::_inputs, "in"_cs, args.Get(Id("in"), Data())) iferr_return;
return OK;
}
};
Parameters
[in]accPointer-to-member for a member of the micro node implementation MN of type VariadicPort<const T>::Access. This member can be used in the micro node implementation to loop over the port instances.
[in]prefixA name prefix.
[in]argThis controls the number and names of the port instances, see above.
[in]wiresThe wires to use for the connection to the port instances.
[in]typeThe type to use for the variadic ports. By default this is the type of #acc.
[in]flagsAdditional flags for the created ports.
Returns
Array of identifiers for the variadic port instances.

◆ AddVariadicPort() [2/3]

MAXON_FUNCTION Result<BaseArray<typename VARIADIC_ACCESS::VPort::PortId> > AddVariadicPort ( VARIADIC_ACCESS MN::*  acc,
const CString prefix,
Int  count,
Int  base = 0,
WIRETYPE  wires = VARIADIC_ACCESS::VPort::DEFAULT_WIRE,
MicroNode::FLAGS  flags = MicroNode::FLAGS::NONE 
)

Adds a variadic port to this micro node. See the other AddVariadicPort function for a description. This functions differs from the other one in how the variadic ports are given: count is the number of variadic ports, and the names are given by the prefix, then a # and finally an index which starts with base. If base is negative, count has to be 1, then the name of the single port is just the prefix plus #.

Parameters
[in]accPointer-to-member for a member of the micro node implementation MN of type VariadicPort<const T>::Access. This member can be used in the micro node implementation to loop over the port instances.
[in]prefixA name prefix.
[in]countThe number of port instances to create.
[in]baseThe base to use for name counting.
[in]wiresThe wire types to use for the connection to the port instances.
[in]flagsAdditional flags for the created ports.
Returns
Array of identifiers for the variadic port instances.

◆ AddVariadicPort() [3/3]

MAXON_FUNCTION Result<BaseArray<typename VARIADIC_ACCESS::VPort::PortId> > AddVariadicPort ( VARIADIC_ACCESS MN::*  acc,
const Block< const Member > &  members,
WIRETYPE  wires = VARIADIC_ACCESS::VPort::DEFAULT_WIRE,
MicroNode::FLAGS  flags = MicroNode::FLAGS::NONE 
)

◆ Connect() [1/2]

MAXON_METHOD Result<void> Connect ( ACCESS_INDEX  thisIndex,
MicroNodeInterface target,
ACCESS_INDEX  targetIndex,
WIRETYPE  wires 
)

Adds a connection from this micro node to the target micro node. thisIndex and targetIndex control at which index the Process methods of #this and target produce/receive the value transported by the connection.

To connect a micro node with a port of its enclosing group, use Export().

Parameters
[in]thisIndexThe index of the parameter of this micro node which shall be transported along the connection. Use ACCESS_INDEX::UNUSED when this is not needed.
[in]targetAnother micro node.
[in]targetIndexThe index of the parameter of the target micro node which shall receive the transported value of the connection. Use ACCESS_INDEX::UNUSED when this is not needed.
[in]wiresThe wires to use for the connection. Already existing wires aren't changed. Wires which aren't supported by both ends are ignored.

◆ Connect() [2/2]

MAXON_FUNCTION Result<void> Connect ( MicroNodeInterface target,
WIRETYPE  wires 
)

Adds a connection from this micro node to the target micro node. If it is necessary to specify at least one ACCESS_INDEX for the connection, use the other Connect() method.

To connect a micro node with a port of its enclosing group, use Export().

Parameters
[in]targetAnother micro node.
[in]wiresThe wires to use for the connection. Already existing wires aren't changed. Wires which aren't supported by both ends are ignored.

◆ Export() [1/5]

MAXON_FUNCTION Result<InPortId> Export ( const InPortId parentPort,
WIRETYPE  wires,
ACCESS_INDEX  index,
const DataType type = DataType::NullValue(),
MicroNode::FLAGS  flags = MicroNode::FLAGS::NONE 
)

Exports an input parameter of this micro node to a port of the enclosing group. This is only needed for built-in micro nodes, custom micro nodes automatically export their ports according to the parameters of the Process method.

If parentPort is given by a name for which there is no port yet, a corresponding port is created at the enclosing group. If parentPort is empty or has an empty name, the name of this micro node is used instead of parentPort.

Parameters
[in]parentPortA port of the enclosing group.
[in]wiresThe wires to use for the export connection. Already existing wires aren't changed. Wires which aren't supported by this micro node are ignored.
[in]indexThe index of the input parameter of this micro node which shall be exported. Use ACCESS_INDEX::UNUSED (the default) when this is not needed.
[in]typeAn optional type for the exported port. This is combined with the current type of the exported port, which may result in an error if the types can't be combined.
[in]flagsOptional flags for the input port.

◆ Export() [2/5]

Exports an input parameter of this micro node to a port of the enclosing group. This is only needed for built-in micro nodes, custom micro nodes automatically export their ports according to the parameters of the Process method.

If parentPort is given by a name for which there is no port yet, a corresponding port is created at the enclosing group. If parentPort is empty or has an empty name, the name of this micro node is used instead of parentPort.

Parameters
[in]parentPortA port of the enclosing group.
[in]wiresThe wires to use for the export connection. Already existing wires aren't changed. Wires which aren't supported by this micro node are ignored.
[in]flagsOptional flags for the input port.

◆ Export() [3/5]

MAXON_FUNCTION Result<OutPortId> Export ( const OutPortId parentPort,
WIRETYPE  wires,
ACCESS_INDEX  index,
const DataType type = DataType::NullValue(),
MicroNode::FLAGS  flags = MicroNode::FLAGS::NONE 
)

Exports an output parameter of this micro node to a port of the enclosing group. This is only needed for built-in micro nodes, custom micro nodes automatically export their ports according to the parameters of the Process method.

If parentPort is given by a name for which there is no port yet, a corresponding port is created at the enclosing group. If parentPort is empty or has an empty name, the name of this micro node is used instead of parentPort.

Parameters
[in]parentPortA port of the enclosing group.
[in]wiresThe wires to use for the export connection. Already existing wires aren't changed. Wires which aren't supported by this micro node are ignored.
[in]indexThe index of the output parameter of this micro node which shall be exported. Use ACCESS_INDEX::UNUSED (the default) when this is not needed.
[in]typeAn optional type for the exported port. This is combined with the current type of the exported port, which may result in an error if the types can't be combined.
[in]flagsOptional flags for the input port.

◆ Export() [4/5]

Exports an output parameter of this micro node to a port of the enclosing group. This is only needed for built-in micro nodes, custom micro nodes automatically export their ports according to the parameters of the Process method.

If parentPort is given by a name for which there is no port yet, a corresponding port is created at the enclosing group. If parentPort is empty or has an empty name, the name of this micro node is used instead of parentPort.

Parameters
[in]parentPortA port of the enclosing group.
[in]wiresThe wires to use for the export connection. Already existing wires aren't changed. Wires which aren't supported by this micro node are ignored.
[in]flagsOptional flags for the input port.

◆ Export() [5/5]

MAXON_FUNCTION Result<typename PORT::PortIdType> Export ( const PORT &  parentPort,
WIRETYPE  wires = PORT::PortIdType::DEFAULT_WIRE,
ACCESS_INDEX  index = ACCESS_INDEX::UNUSED,
MicroNode::FLAGS  flags = MicroNode::FLAGS::NONE 
)

Exports a parameter of this micro node to a port of the enclosing group. This is only needed for built-in micro nodes, custom micro nodes automatically export their ports according to the parameters of the Process method.

This function can be used instead of the other Export functions when a port from a MAXON_PORT macro shall be used as argument instead of an index or name. The name of the port, followed by a pair of parentheses, has to be used as argument for parentPort:

class WhileNode
{
public:
MAXON_PORT_INPUT(Bool, condition);
static Result<void> Init(const MicroNodeGroupRef& group, const DataDictionary&)
{
...
MicroNodePtr<WhileConditionMicroNode> it = group.AddChild<WhileConditionMicroNode>() iferr_return;
it.Export(condition(), WIRETYPE::DEFAULT, ACCESS_INDEX::INDEX_0) iferr_return;
...
}
};

For indexed ports you have to specify the indices within the parentheses, MicroNodeGroupInterface::GetPort.

Parameters
[in]parentPortOne of the ports declared by a MAXON_PORT macro within the enclosing group. A parentheses pair, possibly including indices, is needed after the name, see example.
[in]wiresThe wires to use for the export connection. Already existing wires aren't changed. Wires which aren't supported by this micro node are ignored.
[in]indexThe index of the parameter of this micro node which shall be exported. Use ACCESS_INDEX::UNUSED (the default) when this is not needed.
[in]flagsOptional flags for the input port.

◆ operator()() [1/3]

MAXON_FUNCTION Result<void> operator() ( Result< A > &&  arg,
ARGS &&...  args 
)

@MAXON_ANNOTATION{returnsThis}

◆ operator()() [2/3]

MAXON_FUNCTION Result<void> operator() ( A &&  arg,
ARGS &&...  args 
)

@MAXON_ANNOTATION{returnsThis}

◆ ExportImpl()

MAXON_METHOD Result<Int> ExportImpl ( const PortId parentPort,
WIRETYPE  wires,
ACCESS_INDEX  index,
const DataType type,
MicroNode::FLAGS  flags 
)
private

◆ operator()() [3/3]

ResultOk<void> operator() ( )
private

◆ AddChild()

Result<void> AddChild ( MicroNodePtr< T >  mn,
WIRETYPE  wt = WIRETYPE::DOMAIN_FLOW | WIRETYPE::HIERARCHY 
)
private