TemplateArguments Class Reference

#include <nodetemplate.h>

Detailed Description

The TemplateArguments class implements a dictionary which stores template arguments for instantiations of NodeTemplates. It implements a two-level dictionary:

  • The first level stores /default arguments/. This level is set by user code when a node template instantiation is initially added to a node system. The default arguments are never changed implicitly.
  • The second level stores /deduced/ or /explicit/ values, these have higher priority than default arguments. Deduced values get implicitly set during node system validation: Whenever a template parameter is available as a port and a EffectivePortValue can be deduced for that port, that value is used as argument for the template parameter by making a corresponding override in the TemplateArguments.

Template arguments are usually identified by their relative port path within the node template and the kind of template argument. For a given port there may be several arguments if the port represents several template parameters (for example a TypeTemplateParameter as well as a TemplateParameter).

Public Types

enum class  KIND : UChar {
  NONE ,
  DEDUCED ,
  EXPLICIT ,
  VALUE ,
  TYPE ,
  BUNDLE ,
  VALUEMODE ,
  MASK
}
 
using KeyType = Tuple< NodePath, KIND >
 

Public Member Functions

enum maxon::nodes::TemplateArguments::KIND UChar MAXON_ENUM_FLAGS_CLASS (KIND)
 
 TemplateArguments ()=default
 
 TemplateArguments (const DataDictionary &defaultArgs)
 
void Reset ()
 
template<typename T >
Result< void > SetDefault (const NodePath &path, KIND kind, T &&value)
 
template<typename T >
Result< void > SetExplicit (const NodePath &path, KIND kind, T &&value)
 
template<typename T >
Result< void > SetDefaultRemoveDeduced (const NodePath &path, KIND kind, T &&value)
 
template<typename T >
Result< void > SetNoKindArgument (const InternedId &id, T &&value)
 
Result< void > Remove (const NodePath &path, KIND kind)
 
Result< void > Add (const TemplateArguments &args)
 
Opt< const Data & > Get (const NodePath &path, KIND kind) const
 
template<typename T >
Opt< const T & > Get (const NodePath &path, KIND kind) const
 
template<typename T >
Opt< const T & > GetValueArgument (const NodePath &path) const
 
Opt< const Array< InternedId > & > GetBundleArgument (const NodePath &path) const
 
Opt< const DataType & > GetTypeArgument (const NodePath &path) const
 
Opt< const VALUEMODE & > GetValueModeArgument (const NodePath &path) const
 
Bool HasDefault (const NodePath &path, KIND kind) const
 
Bool HasDeduced (const NodePath &path, KIND kind) const
 
Bool HasExplicit (const NodePath &path, KIND kind) const
 
Bool Contains (const NodePath &path, KIND kind) const
 
template<typename OP >
Result< BoolGetPathArguments (OP &&receiver) const
 
const DataDictionary & GetArgs () const
 
DataDictionary & GetArgs ()
 
Bool IsEmpty () const
 
Bool IsPopulated () const
 
 MAXON_OPERATOR_STRUCT (TemplateArguments, _args)
 

Static Public Member Functions

template<typename... ARGS>
static Result< TemplateArgumentsCreate (ARGS &&... args)
 

Private Member Functions

const DataGetImpl (const NodePath &path, KIND kind) const
 
template<typename PATH , typename T , typename... REST>
Result< void > CreateImpl (const PATH &path, T &&value, REST &&... rest)
 
template<typename T >
Result< void > SetImpl (const NodePath &path, T &&value)
 
template<typename T >
Result< void > SetImpl (const Char *path, T &&value)
 

Static Private Member Functions

static Result< void > CreateImpl ()
 
static KIND GetKindFor (const void *, OverloadRank0)
 
static KIND GetKindFor (const DataType *, OverloadRank1)
 
static KIND GetKindFor (const Array< InternedId > *, OverloadRank1)
 

Private Attributes

DataDictionary _args
 

Member Typedef Documentation

◆ KeyType

using KeyType = Tuple<NodePath, KIND>

Member Enumeration Documentation

◆ KIND

enum KIND : UChar
strong

This enum lists the different kinds of template arguments. Exactly one of VALUE, TYPE, BUNDLE has to be set.

Enumerator
NONE 

No flag set.

DEDUCED 

This flag is set internally (in combination with the other flags) if the value has been deduced from the node graph.

EXPLICIT 

This flag is used in combination with the other flags if the value has been explicitly set by code and shall not be deduced or modified by the user.

VALUE 

The template argument is for a port which is marked as TemplateParameter.

TYPE 

The template argument is for a port which is marked as TypeTemplateParameter.

BUNDLE 

The template argument is for a port which is marked as BundleTemplateParameter.

VALUEMODE 

The template argument is for a port which is marked as ValueModeTemplateParameter.

MASK 

Anything but DEDUCED or EXPLICIT.

Constructor & Destructor Documentation

◆ TemplateArguments() [1/2]

TemplateArguments ( )
default

{NodePath to port with template argument, argument kind}.

Constructs a @CLASS object with default values.

◆ TemplateArguments() [2/2]

TemplateArguments ( const DataDictionary &  defaultArgs)
explicit

Constructs a TemplateArguments object with the given default arguments.

Parameters
[in]defaultArgsThe default arguments.

Member Function Documentation

◆ MAXON_ENUM_FLAGS_CLASS()

enum maxon::nodes::TemplateArguments::KIND UChar MAXON_ENUM_FLAGS_CLASS ( KIND  )

◆ Reset()

void Reset ( )

Resets this @CLASS to the state it has right after default construction. This includes freeing all resources held by this @CLASS.

◆ SetDefault()

Result<void> SetDefault ( const NodePath &  path,
KIND  kind,
T &&  value 
)

Sets the default value for the template parameter path to value. Deduced or explicit values aren't removed.

Parameters
[in]pathThe path of the template parameter.
[in]kindThe kind of the template parameter.
[in]valueThe default value for the template parameter.
Returns
OK on success.

◆ SetExplicit()

Result<void> SetExplicit ( const NodePath &  path,
KIND  kind,
T &&  value 
)

Sets the explicit value for the template parameter path to value.

Parameters
[in]pathThe path of the template parameter.
[in]kindThe kind of the template parameter.
[in]valueThe explicit value for the template parameter.
Returns
OK on success.

◆ SetDefaultRemoveDeduced()

Result<void> SetDefaultRemoveDeduced ( const NodePath &  path,
KIND  kind,
T &&  value 
)

Sets the default value for the template parameter path to value, and removes a deduced value if there is one.

Parameters
[in]pathThe path of the template parameter.
[in]kindThe kind of the template parameter.
[in]valueThe default value for the template parameter.
Returns
OK on success.

◆ SetNoKindArgument()

Result<void> SetNoKindArgument ( const InternedId id,
T &&  value 
)

Sets a template parameter with no KIND value. This can be useful when passing TemplateArguments to lower level node implementation.

Parameters
[in]idThe identifier of the template parameter (use as key to read this parameter).
[in]valueThe value for the template parameter.
Returns
OK on success.

◆ Remove()

Result<void> Remove ( const NodePath &  path,
KIND  kind 
)

Removes any value (default or overridden) for the template parameter path. If there is no such value, nothing happens. kind should not contain any of KIND::MASK or it will not be able to remove all arguments of the given kind (KIND::VALUE, KIND::TYPE or KIND::BUNDLE).

Parameters
[in]pathThe path of the template parameter.
[in]kindThe kind of the template parameter.

◆ Add()

Result<void> Add ( const TemplateArguments args)

Adds all entries of args on top of this object. So if both TemplateArguments have entries for the same template parameter, the value stored in this object will be overwritten with that of args.

Parameters
[in]argsAnother TemplateArguments object to add to this object.

◆ Get() [1/2]

Opt<const Data&> Get ( const NodePath &  path,
KIND  kind 
) const

Returns the value for the template parameter identified by the given path.

Parameters
[in]pathThe path of the template parameter.
[in]kindThe kind of the template parameter.
Returns
The argument for the parameter.

◆ Get() [2/2]

Opt<const T&> Get ( const NodePath &  path,
KIND  kind 
) const

Returns the value for the template parameter identified by the given path.

Parameters
[in]pathThe path of the template parameter.
[in]kindThe kind of the template parameter.
Returns
The argument for the parameter.

◆ GetValueArgument()

Opt<const T&> GetValueArgument ( const NodePath &  path) const

Returns the value for the value template parameter identified by the given path.

Parameters
[in]pathThe path of the template parameter.
Returns
The argument for the parameter.

◆ GetBundleArgument()

Opt<const Array<InternedId>&> GetBundleArgument ( const NodePath &  path) const

Returns the value for the bundle template parameter identified by the given path.

Parameters
[in]pathThe path of the template parameter.
Returns
The argument for the parameter.

◆ GetTypeArgument()

Opt<const DataType&> GetTypeArgument ( const NodePath &  path) const

Returns the value for the type template parameter identified by the given path.

Parameters
[in]pathThe path of the template parameter.
Returns
The argument for the parameter.

◆ GetValueModeArgument()

Opt<const VALUEMODE&> GetValueModeArgument ( const NodePath &  path) const

Returns the value for the value mode template parameter identified by the given path.

Parameters
[in]pathThe path of the template parameter.
Returns
The argument for the parameter.

◆ HasDefault()

Bool HasDefault ( const NodePath &  path,
KIND  kind 
) const

Checks if the template parameter identified by path has a default value.

Parameters
[in]pathThe path of the template parameter.
[in]kindThe kind of the template parameter.
Returns
True if template parameter path has a default value, false otherwise.

◆ HasDeduced()

Bool HasDeduced ( const NodePath &  path,
KIND  kind 
) const

Checks if the template parameter identified by path has a deduced value.

Parameters
[in]pathThe path of the template parameter.
[in]kindThe kind of the template parameter.
Returns
True if template parameter path has a deduced value, false otherwise.

◆ HasExplicit()

Bool HasExplicit ( const NodePath &  path,
KIND  kind 
) const

Checks if the template parameter identified by path has an explicit value.

Parameters
[in]pathThe path of the template parameter.
[in]kindThe kind of the template parameter.
Returns
True if template parameter path has an explicit value, false otherwise.

◆ Contains()

Bool Contains ( const NodePath &  path,
KIND  kind 
) const

Checks if there is a value for the template parameter identified by path.

Parameters
[in]pathThe path of the template parameter.
[in]kindThe kind of the template parameter.
Returns
True if there is a value for template parameter path, false otherwise.

◆ GetPathArguments()

Result<Bool> GetPathArguments ( OP &&  receiver) const

Yields all arguments for NodePath-identified parameters to receiver. receiver has to accept (const NodePath&, TemplateArguments::KIND, const Data&) as arguments and return a Result<Bool>, where false as result value stops yielding of further arguments. For parameters which have both a default and a deduced/explicit value only the deduced/explicit value is reported.

Parameters
[in]receiverA callback which receives the arguments.
Returns
false if the receiver cancelled further evaluation, true otherwise.

◆ GetArgs() [1/2]

const DataDictionary& GetArgs ( ) const

Returns the underlying DataDictionary used by this TemplateArguments object. The dictionary stores default values as well as overridden values. The keys are usually of type Tuple<NodePath, KIND>, but there may be additional arguments which aren't related to node ports.

Returns
The underlying DataDictionary containing the arguments.

◆ GetArgs() [2/2]

DataDictionary& GetArgs ( )

Returns the underlying DataDictionary used by this TemplateArguments object. The dictionary stores default values as well as overridden values. The keys are usually of type Tuple<NodePath, KIND>, but there may be additional arguments which aren't related to node ports.

Returns
The underlying DataDictionary containing the arguments.

◆ Create()

static Result<TemplateArguments> Create ( ARGS &&...  args)
static

◆ IsEmpty()

Bool IsEmpty ( ) const

◆ IsPopulated()

Bool IsPopulated ( ) const

◆ GetImpl()

const Data* GetImpl ( const NodePath &  path,
KIND  kind 
) const
private

◆ CreateImpl() [1/2]

static Result<void> CreateImpl ( )
staticprivate

◆ CreateImpl() [2/2]

Result<void> CreateImpl ( const PATH &  path,
T &&  value,
REST &&...  rest 
)
private

◆ GetKindFor() [1/3]

static KIND GetKindFor ( const void *  ,
OverloadRank0   
)
staticprivate

◆ GetKindFor() [2/3]

static KIND GetKindFor ( const DataType ,
OverloadRank1   
)
staticprivate

◆ GetKindFor() [3/3]

static KIND GetKindFor ( const Array< InternedId > *  ,
OverloadRank1   
)
staticprivate

◆ SetImpl() [1/2]

Result<void> SetImpl ( const NodePath &  path,
T &&  value 
)
private

◆ SetImpl() [2/2]

Result<void> SetImpl ( const Char path,
T &&  value 
)
private

◆ MAXON_OPERATOR_STRUCT()

MAXON_OPERATOR_STRUCT ( TemplateArguments  ,
_args   
)

Member Data Documentation

◆ _args

DataDictionary _args
private