Alexandria 2.31.0
SDC-CH common library for the Euclid project
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Attributes | List of all members
Pyston::Function< R, Args > Class Template Reference

#include <Function.h>

Inheritance diagram for Pyston::Function< R, Args >:
Inheritance graph
[legend]
Collaboration diagram for Pyston::Function< R, Args >:
Collaboration graph
[legend]

Public Types

using functor_t = std::function< R(const Context &, Args...)>
 
using children_t = std::tuple< std::shared_ptr< Node< Args > >... >
 

Public Member Functions

 Function (const std::string &repr_, std::function< R(const Context &, Args...)> functor, const std::shared_ptr< Node< Args > >... args)
 
std::string repr () const final
 
eval (const Context &context, const Arguments &args) const final
 
void visit (Visitor &visitor) const final
 
- Public Member Functions inherited from Pyston::Node< R >
 Node ()
 
virtual ~Node ()=default
 
eval (const Context &context, Args... args) const
 
eval (Args... args) const
 
- Public Member Functions inherited from Pyston::NodeBase
 NodeBase (const std::type_index &type_index)
 
virtual ~NodeBase ()=default
 
const std::type_indextype () const
 

Private Attributes

std::string m_repr
 
functor_t m_functor
 
children_t m_children
 

Additional Inherited Members

- Protected Member Functions inherited from Pyston::Node< R >
eval_helper (const Context &context, Arguments &arguments) const
 
eval_helper (const Context &context, Arguments &arguments, A0 v0, AN... an) const
 

Detailed Description

template<typename R, typename... Args>
class Pyston::Function< R, Args >

Template class for unary operators

Template Parameters
ROperator return type
TOperator parameter type

Definition at line 38 of file Function.h.

Member Typedef Documentation

◆ children_t

template<typename R , typename... Args>
using Pyston::Function< R, Args >::children_t = std::tuple<std::shared_ptr<Node<Args> >...>

Definition at line 41 of file Function.h.

◆ functor_t

template<typename R , typename... Args>
using Pyston::Function< R, Args >::functor_t = std::function<R(const Context&, Args...)>

Definition at line 40 of file Function.h.

Constructor & Destructor Documentation

◆ Function()

template<typename R , typename... Args>
Pyston::Function< R, Args >::Function ( const std::string repr_,
std::function< R(const Context &, Args...)>  functor,
const std::shared_ptr< Node< Args > >...  args 
)
inline

Constructor

Parameters
nodeValue to which the operator will be applied
functorImplements the operator
reprHuman readable representation of the functor (i.e. +, -, abs, exp, ...)

Definition at line 52 of file Function.h.

Member Function Documentation

◆ eval()

template<typename R , typename... Args>
R Pyston::Function< R, Args >::eval ( const Context context,
const Arguments args 
) const
finalvirtual

Evaluate the computing tree

In principle one could avoid to pass any values here, and assign directly the final value to the placeholders that were used to create this tree. However, this would cause the placeholders not to be thread-safe, and a tree would have to be either cloned, either protected by a mutex. Passing the values as an argument allows making the full tree immutable once built, and fully thread safe.

Returns
Result of the evaluation

Implements Pyston::Node< R >.

◆ repr()

template<typename R , typename... Args>
std::string Pyston::Function< R, Args >::repr ( ) const
inlinefinalvirtual

Returns
A human readable representation of the node
Note
It should not include the representation of the children, if any. That's what visitors are for.

Implements Pyston::NodeBase.

Definition at line 59 of file Function.h.

References Pyston::Function< R, Args >::m_repr.

◆ visit()

template<typename R , typename... Args>
void Pyston::Function< R, Args >::visit ( Visitor visitor) const
finalvirtual

Entry point for the visitor

Implements Pyston::NodeBase.

Member Data Documentation

◆ m_children

template<typename R , typename... Args>
children_t Pyston::Function< R, Args >::m_children
private

Definition at line 76 of file Function.h.

◆ m_functor

template<typename R , typename... Args>
functor_t Pyston::Function< R, Args >::m_functor
private

Definition at line 75 of file Function.h.

◆ m_repr

template<typename R , typename... Args>
std::string Pyston::Function< R, Args >::m_repr
private

Definition at line 74 of file Function.h.

Referenced by Pyston::Function< R, Args >::repr().


The documentation for this class was generated from the following file: