Belle II Software development
UnaryExpressionNode< AVariableManager > Class Template Reference

UnaryExpressionNode Node class with a single expression node as child. More...

#include <CutNodes.h>

Inheritance diagram for UnaryExpressionNode< AVariableManager >:
AbstractExpressionNode< AVariableManager >

Public Types

typedef AVariableManager::Var Var
 Template argument dependent Variable type definition.
 

Public Member Functions

AVariableManager::VarVariant evaluate (const Object *p) const override
 Evaluation of the child nodes and return result as a variant<double, int, bool> return negative result if m_unary_minus true.
 
void print () const override
 Print node.
 
std::string decompile () const override
 Decompile Node back to a string.
 
 ~UnaryExpressionNode ()
 Destructor.
 

Private Types

typedef AbstractExpressionNode< AVariableManager >::Object Object
 Template argument dependent Particle type definition.
 

Private Member Functions

 UnaryExpressionNode (Nodetuple node, bool unary_minus, bool parenthesized)
 Constructor.
 

Private Attributes

std::unique_ptr< const AbstractExpressionNode< AVariableManager > > m_enode
 pointer to single expression node
 
const bool m_unary_minus
 flag if expression evaluation should be returned times -1
 
const bool m_parenthesized
 flag if expression in cut was in parenthesis
 

Friends

class NodeFactory
 

Detailed Description

template<class AVariableManager>
class Belle2::UnaryExpressionNode< AVariableManager >

UnaryExpressionNode Node class with a single expression node as child.

Used for unary minus signs and parenthesis conservation on decompiling cuts.

Definition at line 653 of file CutNodes.h.

Member Typedef Documentation

◆ Object

typedef AbstractExpressionNode<AVariableManager>::Object Object
private

Template argument dependent Particle type definition.

Definition at line 657 of file CutNodes.h.

◆ Var

typedef AVariableManager::Var Var
inherited

Template argument dependent Variable type definition.

Definition at line 75 of file AbstractNodes.h.

Constructor & Destructor Documentation

◆ ~UnaryExpressionNode()

~UnaryExpressionNode ( )
inline

Destructor.

Definition at line 701 of file CutNodes.h.

701{}

◆ UnaryExpressionNode()

UnaryExpressionNode ( Nodetuple  node,
bool  unary_minus,
bool  parenthesized 
)
inlineexplicitprivate

Constructor.

Parameters
node(const boost::python::tuple&): tuple containing an expression node
unary_minus(bool): flag indicating if evaluate result should be multiplied by -1
parenthesized(bool): flag indicating if expression in cut was in parenthesis

Definition at line 711 of file CutNodes.h.

711 : m_enode{NodeFactory::compile_expression_node<AVariableManager>(node)},
712 m_unary_minus{unary_minus}, m_parenthesized{parenthesized}
713 {
714 }
const bool m_parenthesized
flag if expression in cut was in parenthesis
Definition: CutNodes.h:717
std::unique_ptr< const AbstractExpressionNode< AVariableManager > > m_enode
pointer to single expression node
Definition: CutNodes.h:715
const bool m_unary_minus
flag if expression evaluation should be returned times -1
Definition: CutNodes.h:716

Member Function Documentation

◆ decompile()

std::string decompile ( ) const
inlineoverridevirtual

Decompile Node back to a string.

decompile(compile) should give the same result.

Implements AbstractExpressionNode< AVariableManager >.

Definition at line 689 of file CutNodes.h.

690 {
691 std::stringstream stringstream;
692 if (m_unary_minus) stringstream << "-";
693 if (m_parenthesized) stringstream << "( ";
694 stringstream << m_enode->decompile();
695 if (m_parenthesized) stringstream << " )";
696 return stringstream.str();
697 }

◆ evaluate()

AVariableManager::VarVariant evaluate ( const Object p) const
inlineoverridevirtual

Evaluation of the child nodes and return result as a variant<double, int, bool> return negative result if m_unary_minus true.

Parameters
ppointer to the object, that should be checked.

Implements AbstractExpressionNode< AVariableManager >.

Definition at line 664 of file CutNodes.h.

665 {
666 typename AVariableManager::VarVariant ret = m_enode->evaluate(p);
667 if (m_unary_minus) {
668 if (std::holds_alternative<int>(ret)) return -1 * std::get<int>(ret);
669 if (std::holds_alternative<double>(ret)) return -1.0 * std::get<double>(ret);
670 throw std::runtime_error("Attempted unary sign with boolean type value.");
671 }
672 return ret;
673 }

◆ print()

void print ( ) const
inlineoverridevirtual

Print node.

Implements AbstractExpressionNode< AVariableManager >.

Definition at line 677 of file CutNodes.h.

678 {
679 if (m_unary_minus) std::cout << "-";
680 if (m_parenthesized) std::cout << "( ";
681 m_enode->print();
682 if (m_parenthesized) std::cout << " )";
683 }

Friends And Related Function Documentation

◆ NodeFactory

friend class NodeFactory
friend

Definition at line 704 of file CutNodes.h.

Member Data Documentation

◆ m_enode

std::unique_ptr<const AbstractExpressionNode<AVariableManager> > m_enode
private

pointer to single expression node

Definition at line 715 of file CutNodes.h.

◆ m_parenthesized

const bool m_parenthesized
private

flag if expression in cut was in parenthesis

Definition at line 717 of file CutNodes.h.

◆ m_unary_minus

const bool m_unary_minus
private

flag if expression evaluation should be returned times -1

Definition at line 716 of file CutNodes.h.


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