CoreNodesLib Class Reference

#include <corenodes_lib.h>

Detailed Description

CoreNodesLib provides a set of static methods around core nodes.

Static Public Member Functions

static MAXON_METHOD Result< const ConversionSequence * > GetConversion (const DataType &to, const DataType &from)
 
static MAXON_METHOD Bool IsEqualConversionSequence (const ConversionSequence &a, const ConversionSequence &b)
 
static MAXON_METHOD Bool IsBetterConversionSequence (const ConversionSequence &a, const ConversionSequence &b)
 
static MAXON_METHOD Result< DataConvert (const ConversionSequence &cs, const ConstDataPtr &value)
 
static MAXON_METHOD Result< DataConvert (const DataType &to, const ConstDataPtr &value)
 
static MAXON_METHOD Result< CoreNode > GetPassThroughNode (const DataType &type)
 
static MAXON_METHOD Result< CoreNode > WrapFunction (const reflection::Function &function)
 
static MAXON_METHOD Optimizer CreateOptimizer (const Block< const ShortCircuitRule > &rules)
 
static MAXON_METHOD ConstDataPtr GetConstant (const DataType &type, Int value)
 

Private Member Functions

 MAXON_INTERFACE_NONVIRTUAL (CoreNodesLib, MAXON_REFERENCE_NONE, "net.maxon.corenode.interface.corenodeslib")
 

Static Private Member Functions

static MAXON_METHOD Result< BoolPrivateConvertArgument (TrivialDataPtr &arg, const DataType &expectedType, PointerArray< Data > &resultReferences)
 

Member Function Documentation

◆ MAXON_INTERFACE_NONVIRTUAL()

MAXON_INTERFACE_NONVIRTUAL ( CoreNodesLib  ,
MAXON_REFERENCE_NONE  ,
"net.maxon.corenode.interface.corenodeslib"   
)
private

◆ GetConversion()

static MAXON_METHOD Result<const ConversionSequence*> GetConversion ( const DataType to,
const DataType from 
)
static

Constructs a ConversionSequence from type from to type #to. The sequence consists of zero to two ConversionNodes. If no suitable sequence can be found, nullptr is returned.

Parameters
[in]toThe destination type.
[in]fromThe source type.
Returns
A ConversionSequence from → #to, or nullptr if no such sequence exists.

◆ IsEqualConversionSequence()

static MAXON_METHOD Bool IsEqualConversionSequence ( const ConversionSequence a,
const ConversionSequence b 
)
static

Checks if two conversion sequences are equal (consist of equal conversion nodes). You don't have to call this method explicitly, just use ConversionSequence::operator==.

Parameters
[in]aA conversion sequence.
[in]bAnother conversion sequence.
Returns
True if both conversion sequences are equal, false otherwise.

◆ IsBetterConversionSequence()

static MAXON_METHOD Bool IsBetterConversionSequence ( const ConversionSequence a,
const ConversionSequence b 
)
static

Checks if a conversion sequence is better than another one. You don't have to call this method explicitly, just use ConversionSequence::operator>.

Parameters
[in]aA conversion sequence.
[in]bAnother conversion sequence.
Returns
True if #a is better then #b, false otherwise.

◆ Convert() [1/2]

static MAXON_METHOD Result<Data> Convert ( const ConversionSequence cs,
const ConstDataPtr value 
)
static

Converts a given value using conversion sequence #cs to the destination type of the conversion sequence.

Parameters
[in]csA conversion sequence.
[in]valueA value to convert. This has to match the source type of #cs, otherwise an error is returned.
Returns
The converted value, or an error if value can't be converted by #cs.

◆ Convert() [2/2]

static MAXON_METHOD Result<Data> Convert ( const DataType to,
const ConstDataPtr value 
)
static

Converts a given value to a destination type #to using registered ConversionNodes. This method obtains a ConversionSequence using Convert() and then calls that sequence to convert the value. If no ConversionSequence can be found a conversion with DataType::Convert() is tried.

Parameters
[in]toThe destination type.
[in]valueA value to convert.
Returns
The converted value, or an error the conversion isn't possible.

◆ GetPassThroughNode()

static MAXON_METHOD Result<CoreNode> GetPassThroughNode ( const DataType type)
static

Constructs a CoreNode which implements a direct pass-through of its single input port to its single output port. Such nodes can be used by Optimizers to set up special cases, for example a multiplication by one can be optimized to a pass-through.

Parameters
[in]typeThe type of the values for the pass-through.
Returns
A CoreNode implementing a pass-through of values of the given type.

◆ WrapFunction()

static MAXON_METHOD Result<CoreNode> WrapFunction ( const reflection::Function function)
static

Constructs a CoreNode which calls the given function on execution. The returned CoreNode has input ports for function parameters and a single output port for the function result.

Parameters
[in]functionThe function to be wrapped by a CoreNode.
Returns
A CoreNode which calls function on execution.

◆ CreateOptimizer()

static MAXON_METHOD Optimizer CreateOptimizer ( const Block< const ShortCircuitRule > &  rules)
static

Creates an Optimizer for a set of ShortCircuitRules, see there for the meaning of the rules. The returned Optimizer will test the rules in the given order and apply the first matching one.

Parameters
[in]rulesA set of rules. The Optimizer doesn't make a copy, to you have to ensure that the rules remain valid during the lifetime of the Optimizer. For example just put the rules in a global static variable as in the example given at ShortCircuitRule.
Returns
An Optimizer using the given #rules.

◆ GetConstant()

static MAXON_METHOD ConstDataPtr GetConstant ( const DataType type,
Int  value 
)
static

Allows to fetch a zero or non zero constant value for a specific DataType. For instance "GetConstant(GetDataType<Matrix>(), 0)" will return a Matrix with a null translation, rotation and scale. "GetConstant(GetDataType<Matrix>(), 1)" would return an identity matrix. "GetConstant(GetDataType<ColorA>(), 1)" will return a ColorA's default value, hence ColorA{0.0_f, 0.0_f, 0.0_f, 1.0_f}. Mostly used to node optimizers.

Parameters
[in]typeThe requested DataType.
[in]value0 to get a zero initialized version of the data, 1 to get non-zero (default value) for type.
Returns
The zero or non zero default value for this DataType.

◆ PrivateConvertArgument()

static MAXON_METHOD Result<Bool> PrivateConvertArgument ( TrivialDataPtr arg,
const DataType expectedType,
PointerArray< Data > &  resultReferences 
)
staticprivate

Applies the required conversion sequence on the TrivialDataPtr's content to transform it into the desired DataType. This supports VALUEKIND::FUNCTION value types. The owner of the resulting TrivialDataPtr is in #resultReferences, i.e. keep it valid as long as arg can be used.

Parameters
[in,out]argA value to be converted using CoreNodesLib::GetConversion (and more for VALUEKIND::FUNCTION).
[in]expectedTypeThe desired type for arg.
[out]resultReferencesA Data array to maintain until the content of arg is not needed anymore. arg becomes invalid when resultReferences is out of scope or reset.
Returns
True if the conversion succeeded, then arg will be updated to the new value.