NodesLib Class Reference

#include <nodeslib.h>

Detailed Description

NodesLib provides a set of static methods for the creation and management of node systems.

Classes

struct  Variant
 

Public Types

using InstantiateDelegate = Delegate< Result< MutableRoot >(const InstantiationTrace &parent, const TemplateArguments &args, const NodeTemplate &self)>
 
using VariantTreeMap = TreeMap< Id, Variant, ArrayMapSelector< false > >
 

Static Public Member Functions

static MAXON_METHOD Result< NodeSystemBasedNodeTemplate > CreateTemplateFromNodeSystem (const NodeSystem &templ, const AssetRepositoryRef &lookup)
 
static MAXON_METHOD Result< NodeTemplate > LoadTemplate (const AssetRepositoryRef &repo, const Id &assetId)
 
static MAXON_METHOD Result< NodeTemplate > LoadBuiltinTemplate (const Id &assetId)
 
static MAXON_METHOD Result< NodeTemplate > CreateTemplateWithInstantiationCache (const NodeTemplate &templ)
 
static MAXON_METHOD Result< NodeTemplate > CreateLazyTemplate (const Id &nodeId, Delegate< Result< NodeTemplate >()> &&creator, Delegate< Result< Bool >(const NodeSystemClass &cls)> &&support={})
 
static MAXON_FUNCTION Result< NodeTemplate > CreateLazyTemplate (const Id &nodeId, Delegate< Result< NodeTemplate >()> &&creator, const ComponentDescriptor &support)
 
static MAXON_FUNCTION Result< NodeTemplate > CreateLazyTemplate (const Id &nodeId, Delegate< Result< NodeTemplate >()> &&creator, const NodeSystemClass &support)
 
static MAXON_METHOD Result< NodeTemplate > CreateTemplateFromDelegate (const Id &nodeId, Bool cache, InstantiateDelegate &&instantiate, Delegate< Result< Bool >(const NodeSystemClass &cls)> &&support={})
 
static MAXON_FUNCTION Result< NodeTemplate > CreateTemplateFromDelegate (const Id &nodeId, Bool cache, InstantiateDelegate &&instantiate, const ComponentDescriptor &support)
 
static MAXON_FUNCTION Result< NodeTemplate > CreateTemplateFromDelegate (const Id &nodeId, Bool cache, InstantiateDelegate &&instantiate, const NodeSystemClass &support)
 
static MAXON_METHOD Result< NodeTemplate > CreateVariantTemplate (VariantTreeMap &&variants)
 
static MAXON_METHOD Result< NodeSystemBasedNodeTemplate > BuildNodeFromDescription (const Id &id, const NodeSystemClass &nodeClass, Bool addDependencies=true, const Delegate< Result< void >(const MutableRoot &root, const TemplateArguments &args)> &finalizer={})
 
static MAXON_METHOD Result< DescriptionProcessor > CreateNodeDescriptionProcessor (Delegate< Result< NodeTemplate >(const Id &descriptionId, const DataDescription &dataDescription)> &&delegate)
 
static MAXON_METHOD Result< DescriptionProcessor > CreateNodeDescriptionProcessorEx (Delegate< Result< NodeTemplate >(const Id &descriptionId, const DataDescriptionDefinition &dataDef, const DataDescription &dataDescription)> &&delegate)
 
static MAXON_METHOD Result< BoolAssetSupports (const AssetDescription &nodeAsset, const NodeSystemClass &cls)
 
static MAXON_METHOD Result< ChangeList > CreateChangeList ()
 
static MAXON_METHOD Result< AssetDescription > StoreAsset (const AssetRepositoryRef &repository, const Id &assetId, const NodeSystemData &data)
 
static MAXON_METHOD String PrivateGNodeToString (const GNodeBase &node, const FormatStatement *fs)
 
static MAXON_METHOD Result< IdMakePortUuid (const Char *prefix)
 
static MAXON_METHOD Result< IdMakePortUuid (PORT_DIR dir)
 

Private Member Functions

 MAXON_INTERFACE_NONVIRTUAL (NodesLib, MAXON_REFERENCE_NONE, "net.maxon.node.interface.nodeslib")
 

Member Typedef Documentation

◆ InstantiateDelegate

using InstantiateDelegate = Delegate<Result<MutableRoot>(const InstantiationTrace& parent, const TemplateArguments& args, const NodeTemplate& self)>

The Delegate type to use for CreateTemplateFromDelegate. This is used to implement NodeTemplateInterface::InstantiateImpl.

Parameters
[in]parentThe parent instantiation context, this defines the node system class to use as well as the asset repository for asset resolution.
[in]argsArguments to parametrize the instantiation.
[in]selfThe NodeTemplate created by CreateTemplateFromDelegate is passed here.
Returns
The MutableRoot of the node system to use for the instantiation.

◆ VariantTreeMap

A VariantTreeMap is used as argument for CreateVariantTemplate to define the variants of the variant template.

Member Function Documentation

◆ MAXON_INTERFACE_NONVIRTUAL()

MAXON_INTERFACE_NONVIRTUAL ( NodesLib  ,
MAXON_REFERENCE_NONE  ,
"net.maxon.node.interface.nodeslib"   
)
private

◆ CreateTemplateFromNodeSystem()

static MAXON_METHOD Result<NodeSystemBasedNodeTemplate> CreateTemplateFromNodeSystem ( const NodeSystem templ,
const AssetRepositoryRef &  lookup 
)
static

Creates a NodeSystemBasedNodeTemplate from a template node system.

Parameters
[in]templA node system to be used as template.
[in]lookupThe asset repository to use for lookup of assets within #templ.
Returns
A NodeSystemBasedNodeTemplate based on #templ.

◆ LoadTemplate()

static MAXON_METHOD Result<NodeTemplate> LoadTemplate ( const AssetRepositoryRef &  repo,
const Id assetId 
)
static

Loads a NodeTemplate asset from a repository. This is a convenience method around AssetRepositoryRef::FindAssets, it returns the latest version for assetId after a check that the asset is really a NodeTemplate.

Parameters
[in]repoA repository.
[in]assetIdThe id of the asset to load.
Returns
The loaded NodeTemplate asset, or an IllegalArgumentError if no such asset exists.

◆ LoadBuiltinTemplate()

static MAXON_METHOD Result<NodeTemplate> LoadBuiltinTemplate ( const Id assetId)
static

Loads a NodeTemplate asset from the builtin asset repository. This is the same as LoadTemplate, but restricted to the builtin asset repository. The returned asset is a decorated version of the corresponding NodeTemplate in the BuiltinNodes registry, adding support for meta data, resource descriptions and instantiation cache.

Parameters
[in]assetIdThe id of the asset to load.
Returns
The loaded NodeTemplate asset, or an IllegalArgumentError if no such asset exists.

◆ CreateTemplateWithInstantiationCache()

static MAXON_METHOD Result<NodeTemplate> CreateTemplateWithInstantiationCache ( const NodeTemplate &  templ)
static

Creates a NodeTemplate which wraps the given template and caches instantiations. I.e., whenever the template is instantiated with equal arguments, the returned instantiation will be the same NodeSystem.

Parameters
[in]templThe node template to wrap.
Returns
A wrapper template around templ which caches instantiations.

◆ CreateLazyTemplate() [1/3]

static MAXON_METHOD Result<NodeTemplate> CreateLazyTemplate ( const Id nodeId,
Delegate< Result< NodeTemplate >()> &&  creator,
Delegate< Result< Bool >(const NodeSystemClass &cls)> &&  support = {} 
)
static

Creates a NodeTemplate which wraps a lazily created NodeTemplate. Only when needed the creator is called once to obtain the NodeTemplate to be wrapped, this is then cached.

Parameters
[in]nodeIdThe asset id to use for the NodeTemplate. The asset repository will be set to the built-in repository.
[in]creatorThe callback for lazy creation of the wrapped NodeTemplate.
[in]supportThe callback to implement NodeTemplateInterface::SupportsImpl. Pass a null value (the default) to use the wrapped implementation.
Returns
The lazy NodeTemplate wrapper for #creator.

◆ CreateLazyTemplate() [2/3]

static MAXON_FUNCTION Result<NodeTemplate> CreateLazyTemplate ( const Id nodeId,
Delegate< Result< NodeTemplate >()> &&  creator,
const ComponentDescriptor support 
)
static

Creates a NodeTemplate which wraps a lazily created NodeTemplate. Only when needed the creator is called once to obtain the NodeTemplate to be wrapped, this is then cached.

Parameters
[in]nodeIdThe asset id to use for the NodeTemplate. The asset repository will be set to the built-in repository.
[in]creatorThe callback for lazy creation of the wrapped NodeTemplate.
[in]supportThe returned NodeTemplate implements the SupportsImpl method such that it returns true if and only if the NodeSystemClass argument has the component given by #support.
Returns
The lazy NodeTemplate wrapper for creator.

◆ CreateLazyTemplate() [3/3]

static MAXON_FUNCTION Result<NodeTemplate> CreateLazyTemplate ( const Id nodeId,
Delegate< Result< NodeTemplate >()> &&  creator,
const NodeSystemClass &  support 
)
static

Creates a NodeTemplate which wraps a lazily created NodeTemplate. Only when needed the creator is called once to obtain the NodeTemplate to be wrapped, this is then cached.

Parameters
[in]nodeIdThe asset id to use for the NodeTemplate. The asset repository will be set to the built-in repository.
[in]creatorThe callback for lazy creation of the wrapped NodeTemplate.
[in]supportThe returned NodeTemplate implements the SupportsImpl method such that it returns true if and only if the NodeSystemClass argument is the same as the class given by #support or a subclass thereof.
Returns
The lazy NodeTemplate wrapper for creator.

◆ CreateTemplateFromDelegate() [1/3]

static MAXON_METHOD Result<NodeTemplate> CreateTemplateFromDelegate ( const Id nodeId,
Bool  cache,
InstantiateDelegate &&  instantiate,
Delegate< Result< Bool >(const NodeSystemClass &cls)> &&  support = {} 
)
static

Creates a NodeTemplate where the Instantiate method is implemented by the given delegate.

Parameters
[in]nodeIdThe asset id to use for the NodeTemplate. The asset repository will be set to the built-in repository.
[in]cacheIf true, instantiations will be cached. I.e., for a given set of template arguments, the delegate will be called only once and the result will be cached.
[in]instantiateThe delegate to implement NodeTemplateInterface::InstantiateImpl.
[in]supportThe callback to implement NodeTemplateInterface::SupportsImpl. Pass a null value (the default) to use the wrapped implementation.
Returns
The NodeTemplate wrapper for #instantiate.

◆ CreateTemplateFromDelegate() [2/3]

static MAXON_FUNCTION Result<NodeTemplate> CreateTemplateFromDelegate ( const Id nodeId,
Bool  cache,
InstantiateDelegate &&  instantiate,
const ComponentDescriptor support 
)
static

Creates a NodeTemplate where the Instantiate method is implemented by the given delegate.

Parameters
[in]nodeIdThe asset id to use for the NodeTemplate. The asset repository will be set to the built-in repository.
[in]cacheIf true, instantiations will be cached. I.e., for a given set of template arguments, the delegate will be called only once and the result will be cached.
[in]instantiateThe delegate to implement NodeTemplateInterface::InstantiateImpl.
[in]supportThe returned NodeTemplate implements the SupportsImpl method such that it returns true if and only if the NodeSystemClass argument has the component given by #support.
Returns
The NodeTemplate wrapper for #instantiate.

◆ CreateTemplateFromDelegate() [3/3]

static MAXON_FUNCTION Result<NodeTemplate> CreateTemplateFromDelegate ( const Id nodeId,
Bool  cache,
InstantiateDelegate &&  instantiate,
const NodeSystemClass &  support 
)
static

Creates a NodeTemplate where the Instantiate method is implemented by the given delegate.

Parameters
[in]nodeIdThe asset id to use for the NodeTemplate. The asset repository will be set to the built-in repository.
[in]cacheIf true, instantiations will be cached. I.e., for a given set of template arguments, the delegate will be called only once and the result will be cached.
[in]instantiateThe delegate to implement NodeTemplateInterface::InstantiateImpl.
[in]supportThe returned NodeTemplate implements the SupportsImpl method such that it returns true if and only if the NodeSystemClass argument is the same as the class given by #support or a subclass thereof.
Returns
The NodeTemplate wrapper for #instantiate.

◆ CreateVariantTemplate()

static MAXON_METHOD Result<NodeTemplate> CreateVariantTemplate ( VariantTreeMap &&  variants)
static

Creates a variant template for the VariantTreeMap #variants. A variant template allows the user to choose between different other templates, for example the arithmetic node allows to select the operation (add, subtract, multiply, divide) at first level and the datatype at second level. The selection of the variant is controlled by template parameter ports (see Variant::childSelector) of the returned node template.

Parameters
[in]variantsThe variants as a tree of alternatives.
Returns
A node template which allows to choose among the #variants using template parameter ports.

◆ BuildNodeFromDescription()

static MAXON_METHOD Result<NodeSystemBasedNodeTemplate> BuildNodeFromDescription ( const Id id,
const NodeSystemClass &  nodeClass,
Bool  addDependencies = true,
const Delegate< Result< void >(const MutableRoot &root, const TemplateArguments &args)> &  finalizer = {} 
)
static

Builds a node template from a resource description.

Parameters
[in]idThe identifier of the description.
[in]nodeClassThe node system class to use for the construction.
[in]addDependenciesIf true (the default) dependency wires are added crosswise between input and output ports.
[in]finalizerAn optional finalizer which will be called at the end to allow for customization.
Returns
A node template built from the information in a resource description.

◆ CreateNodeDescriptionProcessor()

static MAXON_METHOD Result<DescriptionProcessor> CreateNodeDescriptionProcessor ( Delegate< Result< NodeTemplate >(const Id &descriptionId, const DataDescription &dataDescription)> &&  delegate)
static

Creates a DescriptionProcessor which processes a resource description to build a node template. The actual processing is done by #delegate, the returned DescriptionProcessor just adds the automatic insertion of the node template into the BuiltinNodes registry.

Parameters
[in]delegateA delegate to process the dataDescription for descriptionId into a NodeTemplate.
Returns
A DescriptionProcessor which wraps #delegate.

◆ CreateNodeDescriptionProcessorEx()

static MAXON_METHOD Result<DescriptionProcessor> CreateNodeDescriptionProcessorEx ( Delegate< Result< NodeTemplate >(const Id &descriptionId, const DataDescriptionDefinition &dataDef, const DataDescription &dataDescription)> &&  delegate)
static

Creates a DescriptionProcessor which processes a resource description to build a node template. The actual processing is done by #delegate, the returned DescriptionProcessor just adds the automatic insertion of the node template into the BuiltinNodes registry.

Parameters
[in]delegateA delegate to process the dataDescription for descriptionId into a NodeTemplate.
Returns
A DescriptionProcessor which wraps #delegate.

◆ AssetSupports()

static MAXON_METHOD Result<Bool> AssetSupports ( const AssetDescription &  nodeAsset,
const NodeSystemClass &  cls 
)
static

Checks if a node template asset is supported by a node system class using a cache. The method caches this information in the asset meta data, so that the asset only needs to be loaded and the NodeTemplate::Supports only needs to be called once.

Parameters
[in]nodeAssetThe node asset to check.
[in]clsThe node system class to check.
Returns
True if #nodeAsset can be instantiated for cls, false otherwise.

◆ CreateChangeList()

static MAXON_METHOD Result<ChangeList> CreateChangeList ( )
static

Creates a ChangeList which can be used to track NodeSystem changes. Most of the methods which modify a NodeSystem have an optional ChangeList parameter, when a ChangeList is passed there the changes will be tracked.

Returns
A new ChangeList which is compatible with NodeSystem.

◆ StoreAsset()

static MAXON_METHOD Result<AssetDescription> StoreAsset ( const AssetRepositoryRef &  repository,
const Id assetId,
const NodeSystemData &  data 
)
static

◆ PrivateGNodeToString()

static MAXON_METHOD String PrivateGNodeToString ( const GNodeBase node,
const FormatStatement fs 
)
static

◆ MakePortUuid() [1/2]

static MAXON_METHOD Result<Id> MakePortUuid ( const Char prefix)
static

Creates a UUID (universally unique identifier) for a port. If prefix is given, the returned identifier starts with prefix, otherwise it is a UUID only.

The implementation is based on AssetInterface::MakeUuid. In addition to that method it makes sure that special port ids such as those with component access tags are handled correctly.

Parameters
[in]prefixThe prefix for the identifier, may be nullptr. Only the characters up to the first @ sign are used.
Returns
A new UUID. It is safe to assume that this UUID differs from any other UUID returned by this method.

◆ MakePortUuid() [2/2]

static MAXON_METHOD Result<Id> MakePortUuid ( PORT_DIR  dir)
static

Creates a UUID (universally unique identifier) for a port. The UUID will have a direction-dependent prefix.

Parameters
[in]dirThe port direction.
Returns
A new UUID. It is safe to assume that this UUID differs from any other UUID returned by this method.