micronodes_ports.h File Reference

Classes

class  DirectPortAccess< PORT, OWNER >
 
class  MappedPortAccess< PORT, OWNER >
 
class  PortOpsBase< T, ACCESS >
 
class  PortOpsBase< T &, ACCESS >
 
class  PortOps< T, ACCESS, CHECK >
 
class  IndexedPortAccess< ACCESS >
 
class  IndexedPort< OP, N >
 
struct  SourceCodePortId
 
class  PortDefBase< C, MICRO, HASH, FLAGS, INDEXCOUNT >
 
class  PortDefBaseCtor< C, MICRO, HASH, FLAGS, MEMBERS, DIMENSION, INDEXCOUNT >
 
class  PortDefBaseCtor< C, MICRO, HASH, FLAGS, MEMBERS, void, -1 >
 
struct  AddDimension< T, N >
 
struct  AddDimension< void, N >
 
class  PortArrayAccess< ACCESS >
 
struct  Select< PORT, MASK, OWNER >
 
class  PortMembers< PORTS >
 
struct  UnannotatedType< T >
 
class  MicroNode::Lazy< PORT >
 
class  MicroNode::Lazy< PORT >::Port< OWNER >
 
class  MicroNode::PortsAccess< ACCESS_FLAGS, PORTS >
 
class  MicroNode::PortsAccess< ACCESS_FLAGS, PORTS >::InputMembers
 
class  MicroNode::PortsAccess< ACCESS_FLAGS, PORTS >::NonEmptyInputMembersIteration
 
class  MicroNode::PortsAccess< ACCESS_FLAGS, PORTS >::OutputMembers
 
class  MicroNode::PortsAccess< ACCESS_FLAGS, PORTS >::Members
 
class  MicroNode::PortsAccess< ACCESS_FLAGS, PORTS >::EmptyInputMembersIteration
 
class  MicroNode::PortsAccess< ACCESS_FLAGS, PORTS >::Iterator
 
class  MicroNode::PortsAccess< ACCESS_FLAGS, PORTS >::BatchIterator
 

Namespaces

 maxon
 
 maxon::corenodes
 
 maxon::corenodes::details
 

Macros

#define MAXON_PORT_INPUT(T, name, ...)
 
#define MAXON_PORT_INPUT_LAMBDA(T, name)
 
#define MAXON_PORT_INPUT_INDEXED(T, name, N)
 
#define MAXON_PORT_INPUT_NAMED(T, name, portId)
 
#define MAXON_PORT_OUTPUT(T, name, ...)
 
#define MAXON_PORT_OUTPUT_INDEXED(T, name, N)
 
#define MAXON_PORT_OUTPUT_NAMED(T, name, portId)
 
#define PRIVATE_MAXON_PORT_WRAP_false(CNT, ...)
 
#define PRIVATE_MAXON_PORT_WRAP_true(CNT, ...)
 
#define PRIVATE_MAXON_PORT_DIMENSION_false(CNT)
 
#define PRIVATE_MAXON_PORT_DIMENSION_true(CNT)
 
#define PRIVATE_MAXON_PORT_MEMBER(name, ARRAY, CNT)
 
#define PRIVATE_MAXON_PORT(name, portId, ARRAY, CNT, ...)
 
#define PRIVATE_MAXON_PORT_GET_NAME_HASHCODE(name)
 
#define PRIVATE_MAXON_INPUT_PORT_NAMED(T, name, portId, MICROFLAGS, ARRAY, CNT, ...)
 
#define PRIVATE_MAXON_INPUT_PORT(T, name, MICROFLAGS, ARRAY, CNT, ...)
 
#define PRIVATE_MAXON_STATE_PORT(T, name, MICROFLAGS, ARRAY, CNT, ...)
 
#define PRIVATE_MAXON_OUTPUT_PORT_NAMED(T, name, portId, mtype, MICROFLAGS, ARRAY, CNT, ...)
 
#define PRIVATE_MAXON_OUTPUT_PORT(T, name, mtype, MICROFLAGS, ARRAY, CNT, ...)
 

Typedefs

template<typename T >
using MyBegin = typename T::Begin
 
template<typename T >
using PortValueTypeHelper = typename std::conditional< STD_IS_REPLACEMENT(reference, T), typename std::decay< T >::type, typename std::add_const< T >::type >::type
 
template<typename T >
using UnannotatedTypeHelper = typename SubstituteType< T, UnannotatedType >::type
 
using PrivateMaxonCorenodesParentDimension = void
 

Functions

template<typename DIMENSION >
Int ComputeLinearIndex (const Int *index)
 
template<>
Int ComputeLinearIndex< Char > (const Int *index)
 
template<typename DIMENSION >
Int ComputeLinearIndex (Int index)
 
template<typename PORTIDTYPE >
constexpr UInt GetPortHashCodeHelper (PORTIDTYPE const &inId)
 
constexpr UInt GetPortHashCodeHelper (LiteralId const &inId)
 
template<Int LENGTH>
constexpr UInt GetPortHashCodeHelper (const char(&inId)[LENGTH])
 

Macro Definition Documentation

◆ MAXON_PORT_INPUT

#define MAXON_PORT_INPUT (   T,
  name,
  ... 
)

Defines an input port of a micro node group with the given type and name. The macro has to be used within a micro node group implementation class, see MicroNodeGroupInterface for a complete example.

To be accessible within the Process method of a micro node, you have to add the port to the port list of the MicroNode::Ports or BatchMicroNode::Batch template for the Process methods's parameter. Within the method you can use two operations on the port:

  • {ports.name()} returns the value of the input port.
  • {ports.name.HasValue()} returns true if the port has some explicitly given value (such as a default value or a value coming from a connected upstream port), false otherwise.

The following code shows the usage of MAXON_INPUT_PORT:

class MySquareRoot
{
public:
// Declaration of the input and output ports of the micro node group.
MAXON_PORT_INPUT(Float, input);
MAXON_PORT_OUTPUT(Float, result);
class Impl : public BasicMicroNode
{
public:
// The Process method needs to specify which ports of the group the micro node accesses, in this case all ports.
// If the group contains more than one micro node, each micro node usually needs only a subset of the ports.
Result<void> Process(const Ports<input, result>& ports) const
{
// Read value from input port.
Float x = ports.input();
// Check if the input port has a user-defined value.
Bool hasValue = ports.input.HasValue();
...
return OK;
}
};
...
};
Parameters
[in]TThe type of the port.
[in]nameThe name of the port.
[in]...Optional MicroNode::FLAGS for the port.

◆ MAXON_PORT_INPUT_LAMBDA

#define MAXON_PORT_INPUT_LAMBDA (   T,
  name 
)

◆ MAXON_PORT_INPUT_INDEXED

#define MAXON_PORT_INPUT_INDEXED (   T,
  name,
 
)

Defines an indexed input port of a micro node group with the given type and name. An indexed port is an indexable collection of N ports with same name and type. The number N has to be a compile-time constant, for a dynamic number of ports see VariadicPort.

The macro has to be used within a micro node group implementation class, afterwards you can use the indexed port for micro nodes as in this example:

// This class template defines a micro node group which adds N values.
template <Int N> class MyIndexedAddNode
{
public:
// Declaration of the input and output ports of the micro node group.
MAXON_PORT_INPUT_INDEXED(Int, in, N);
MAXON_PORT_OUTPUT(Int, out);
// Implementation of the single custom micro node.
class Impl : public BasicMicroNode
{
public:
// The Process method needs to specify which ports of the group the micro node accesses, in this case all ports.
// If the group contains more than one micro node, each micro node usually needs only a subset of the ports.
Result<void> Process(const Ports<in, out>& ports) const
{
Int sum = 0;
for (Int i = 0; i < N; ++i)
{
sum += ports.in[i]();
}
ports.out.Update(sum);
return OK;
}
};
// The Init function will be called to set up the micro node group
// when you call CreateNode<MyIndexedAddNode<N>>() or as part of the MAXON_CORENODE_REGISTER macro.
static Result<void> Init(const MicroNodeGroupRef& group)
{
iferr_scope;
group.AddChild<Impl>() iferr_return;
for (Int i = 0; i < N; ++i)
{
// GetPort() needs the index of the port for which you want to get the PortId,
// you have to specify the index within the parentheses.
InPortId p = group.GetPort(in(i)) iferr_return;
DiagnosticOutput("Name of port @ is @.", i, group.GetPortInfo(p).name);
}
return OK;
}
};
Note
name is the name by which the port is accessed in source code. The name which is used by the API (such as in PortInfo::name) is name followed by a dot and the index plus one (so the names are 1-based).
Parameters
[in]TThe type of the indexed port.
[in]nameThe name of the indexed port.
[in]NThe number of ports.

◆ MAXON_PORT_INPUT_NAMED

#define MAXON_PORT_INPUT_NAMED (   T,
  name,
  portId 
)

Defines a named input port with an id that can differ from the name.

See also
MAXON_INPUT_PORT, split name parameter into name + portId. portId supports any constexpr type, hardcoded strings, attribute, LiteralId.

◆ MAXON_PORT_OUTPUT

#define MAXON_PORT_OUTPUT (   T,
  name,
  ... 
)

Defines an output port of a micro node group with the given type and name. The macro has to be used within a micro node group implementation class, see MicroNodeGroupInterface for a complete example.

To be accessible within the Process method of a micro node, you have to add the port to the port list of the MicroNode::Ports or BatchMicroNode::Batch template for the Process methods's parameter. Within the method you can use several operations on the port:

  • {ports.name.Update(v)} updates the output value with v. Update checks if the value differs from the previous value, and also updates the modification stamp in that case.
  • {ports.name.GetWritable()} returns an l-value-reference to the value of the output port. You can modify the value through that reference. The modification stamp of the port's value is automatically updated by the call to GetWritable(), whether there will be a subsequent modification of the value or not.
  • {ports.name.GetWritableTouchLater()} returns an l-value-reference to the value of the output port. You can modify the value through that reference. If you have made some modification, you have to make sure to update the modification stamp of the port's value by a call to Touch(), otherwise downstream parts of the core node graph might not get re-evaluated.
  • {ports.name.Touch()} updates the modification stamp of the port value. You have to call this after GetWritableTouchLater() if you've made an actual modification.
  • {ports.name.IsNeeded()} returns true if the port's value is needed at all, false otherwise. This is useful for micro nodes with multiple output ports where only some of them are needed by downstream parts of the core node graph to avoid unnecessary, time-consuming computations. If the micro node has just a single output port this isn't needed because the micro node won't be evaluated if the output port's value isn't used.
  • {ports.name.IsTimeStamped()} returns true if the port's value is time-stamped, false otherwise.

The following code shows the usage of MAXON_OUTPUT_PORT:

class MySquareRoot
{
public:
// Declaration of the input and output ports of the micro node group.
MAXON_PORT_INPUT(Float, input);
MAXON_PORT_OUTPUT(Float, result);
class Impl : public BasicMicroNode
{
public:
// The Process method needs to specify which ports of the group the micro node accesses, in this case all ports.
// If the group contains more than one micro node, each micro node usually needs only a subset of the ports.
Result<void> Process(const Ports<input, result>& ports) const
{
Float x = ports.input();
// Update the port's value, this will only update the time stamp if the new value differs from the previous one.
ports.result.Update(Sqrt(x));
// Directly set the port's value, this will always update the time stamp.
ports.result.GetWritable() = Sqrt(x);
// Same as above.
Float& r = ports.result.GetWritable();
r = Sqrt(x);
// GetWritableTouchLater() returns a writable reference for the port value. When you modify the referenced value
// you have to make sure to call Touch() on the port to update the time stamp.
Float& s = ports.result.GetWritableTouchLater();
if (s * s != x)
{
// Current value of output port isn't the square root of x, recompute and update time stamp.
// (In practice one wouldn't use this optimization for something as simple as Sqrt.)
s = Sqrt(x);
ports.result.Touch();
}
// Check if the value of the output port is actually needed.
Bool needed = ports.result.IsNeeded();
// Check if the output port is time-stamped.
Bool timeStamped = ports.result.IsTimeStamped();
return OK;
}
};
...
};
Parameters
[in]TThe type of the port.
[in]nameThe name of the port.
[in]...Optional MicroNode::FLAGS for the port.

◆ MAXON_PORT_OUTPUT_INDEXED

#define MAXON_PORT_OUTPUT_INDEXED (   T,
  name,
 
)

Defines an indexed output port of a micro node group with the given type and name, see MAXON_PORT_INPUT_INDEXED for more details.

Parameters
[in]TThe type of the indexed port.
[in]nameThe name of the indexed port.
[in]NThe number of ports.

◆ MAXON_PORT_OUTPUT_NAMED

#define MAXON_PORT_OUTPUT_NAMED (   T,
  name,
  portId 
)

Defines a named output port with an id that can differ from the name.

See also
MAXON_INPUT_PORT, split name parameter into name + portId. portId supports any constexpr type, hardcoded strings, attribute, LiteralId.

◆ PRIVATE_MAXON_PORT_WRAP_false

#define PRIVATE_MAXON_PORT_WRAP_false (   CNT,
  ... 
)

◆ PRIVATE_MAXON_PORT_WRAP_true

#define PRIVATE_MAXON_PORT_WRAP_true (   CNT,
  ... 
)

◆ PRIVATE_MAXON_PORT_DIMENSION_false

#define PRIVATE_MAXON_PORT_DIMENSION_false (   CNT)

◆ PRIVATE_MAXON_PORT_DIMENSION_true

#define PRIVATE_MAXON_PORT_DIMENSION_true (   CNT)

◆ PRIVATE_MAXON_PORT_MEMBER

#define PRIVATE_MAXON_PORT_MEMBER (   name,
  ARRAY,
  CNT 
)

◆ PRIVATE_MAXON_PORT

#define PRIVATE_MAXON_PORT (   name,
  portId,
  ARRAY,
  CNT,
  ... 
)

◆ PRIVATE_MAXON_PORT_GET_NAME_HASHCODE

#define PRIVATE_MAXON_PORT_GET_NAME_HASHCODE (   name)

◆ PRIVATE_MAXON_INPUT_PORT_NAMED

#define PRIVATE_MAXON_INPUT_PORT_NAMED (   T,
  name,
  portId,
  MICROFLAGS,
  ARRAY,
  CNT,
  ... 
)

◆ PRIVATE_MAXON_INPUT_PORT

#define PRIVATE_MAXON_INPUT_PORT (   T,
  name,
  MICROFLAGS,
  ARRAY,
  CNT,
  ... 
)

◆ PRIVATE_MAXON_STATE_PORT

#define PRIVATE_MAXON_STATE_PORT (   T,
  name,
  MICROFLAGS,
  ARRAY,
  CNT,
  ... 
)

◆ PRIVATE_MAXON_OUTPUT_PORT_NAMED

#define PRIVATE_MAXON_OUTPUT_PORT_NAMED (   T,
  name,
  portId,
  mtype,
  MICROFLAGS,
  ARRAY,
  CNT,
  ... 
)

◆ PRIVATE_MAXON_OUTPUT_PORT

#define PRIVATE_MAXON_OUTPUT_PORT (   T,
  name,
  mtype,
  MICROFLAGS,
  ARRAY,
  CNT,
  ... 
)

Typedef Documentation

◆ PrivateMaxonCorenodesParentDimension