ECF 1.5
Public Member Functions | Protected Attributes | List of all members
cartesian::Function< Container, Result > Class Template Referenceabstract
Inheritance diagram for cartesian::Function< Container, Result >:
cartesian::Add< Container, Result > cartesian::Cos< Container, Result > cartesian::Div< Container, Result > cartesian::Max< Container, Result > cartesian::Min< Container, Result > cartesian::Mul< Container, Result > cartesian::Neg< Container, Result > cartesian::Nlog< Container, Result > cartesian::Sin< Container, Result > cartesian::Sq_exp< Container, Result > cartesian::Sqrt< Container, Result > cartesian::Step< Container, Result > cartesian::Sub< Container, Result >

Public Member Functions

 Function (uint numArgs)
 
virtual void evaluate (Container &container, Result &result)=0
 
std::string getName ()
 
uint getNumOfArgs ()
 

Protected Attributes

std::string name_
 
uint numOfArgs_
 

Detailed Description

template<typename Container, typename Result>
class cartesian::Function< Container, Result >

Definition at line 7 of file Function.h.

Constructor & Destructor Documentation

◆ Function() [1/2]

template<typename Container , typename Result >
cartesian::Function< Container, Result >::Function ( )
inline

Definition at line 10 of file Function.h.

◆ Function() [2/2]

template<typename Container , typename Result >
cartesian::Function< Container, Result >::Function ( uint  numArgs)
inline

Definition at line 11 of file Function.h.

◆ ~Function()

template<typename Container , typename Result >
virtual cartesian::Function< Container, Result >::~Function ( )
inlinevirtual

Definition at line 12 of file Function.h.

Member Function Documentation

◆ evaluate()

template<typename Container , typename Result >
virtual void cartesian::Function< Container, Result >::evaluate ( Container &  container,
Result &  result 
)
pure virtual

Evaluate function could be done in a better way. What it does is it takes inputs to a function node as first argument and result as a second argument.

Problem arises because of the following: 1.) Passed input should support an operation which is performed(+, -, *, /, sqrt, max, min). This is not a problem for built-in types, but does create a problem for user-defined types or aggregate-types.

2.) Assuming that input is given as a collection or any stl container, strictly speaking all support needed for first argument is to be able to iterate over it.

For general usage, abstract function evaluate could be defined as: virtual void evaluate(voidP inputs, void* result) = 0;

However this would require that concrete functions (derived classes of Function) know in what to cast voidP and void*. This could be achieved using class templates. Still, user would have to know in what to cast inputs.

I opted for a solution of making base-class a template class, and arguments of evaluate function container and a result.

Solution I like the most (once C++ 2020 is supported by compilers) is to use concepts, and scrape inheritance completely.

Implemented in cartesian::Add< Container, Result >, cartesian::Cos< Container, Result >, cartesian::Div< Container, Result >, cartesian::Nlog< Container, Result >, cartesian::Max< Container, Result >, cartesian::Min< Container, Result >, cartesian::Mul< Container, Result >, cartesian::Neg< Container, Result >, cartesian::Sin< Container, Result >, cartesian::Sq_exp< Container, Result >, cartesian::Sqrt< Container, Result >, cartesian::Step< Container, Result >, and cartesian::Sub< Container, Result >.

◆ getName()

template<typename Container , typename Result >
std::string cartesian::Function< Container, Result >::getName ( )
inline

Definition at line 41 of file Function.h.

◆ getNumOfArgs()

template<typename Container , typename Result >
uint cartesian::Function< Container, Result >::getNumOfArgs ( )
inline

Definition at line 46 of file Function.h.

Member Data Documentation

◆ name_

template<typename Container , typename Result >
std::string cartesian::Function< Container, Result >::name_
protected

Definition at line 52 of file Function.h.

◆ numOfArgs_

template<typename Container , typename Result >
uint cartesian::Function< Container, Result >::numOfArgs_
protected

Definition at line 53 of file Function.h.


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