Belle II Software light-2406-ragdoll
BinaryExpressionNode< AVariableManager > Class Template Reference

BinaryExpressionNode Node which connects two expression nodes with an arithemtic operation. More...

#include <CutNodes.h>

Inheritance diagram for BinaryExpressionNode< AVariableManager >:
Collaboration diagram for BinaryExpressionNode< 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> apply arithmetic operation to the evaluations.
 
void print () const override
 Print node.
 
std::string decompile () const override
 Decompile Node back to a string.
 
 ~BinaryExpressionNode ()
 Destructor.
 

Private Types

typedef AVariableManager::Object Object
 Template argument dependent Particle type definition.
 

Private Member Functions

 BinaryExpressionNode (Nodetuple left_node, Nodetuple right_node, ArithmeticOperation aoperation)
 Constructor.
 

Private Attributes

std::unique_ptr< const AbstractExpressionNode< AVariableManager > > m_left_enode
 left expression node
 
std::unique_ptr< const AbstractExpressionNode< AVariableManager > > m_right_enode
 right expression node
 
ArithmeticOperation m_aoperation
 arithmetic operation to be applied to the evaluations of left and right expressions
 

Friends

class NodeFactory
 

Detailed Description

template<class AVariableManager>
class Belle2::BinaryExpressionNode< AVariableManager >

BinaryExpressionNode Node which connects two expression nodes with an arithemtic operation.

Definition at line 726 of file CutNodes.h.

Member Typedef Documentation

◆ Object

typedef AVariableManager::Object Object
private

Template argument dependent Particle type definition.

Definition at line 730 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

◆ ~BinaryExpressionNode()

~BinaryExpressionNode ( )
inline

Destructor.

Definition at line 862 of file CutNodes.h.

862{}

◆ BinaryExpressionNode()

BinaryExpressionNode ( Nodetuple  left_node,
Nodetuple  right_node,
ArithmeticOperation  aoperation 
)
inlineexplicitprivate

Constructor.

Parameters
left_node(const boost::python::tuple&): tuple containing an expression node
right_node(const boost::python::tuple&): tuple containing an expression node
aoperation(ArithmeticOperator): arithmetic operator enum value

Definition at line 872 of file CutNodes.h.

872 : m_left_enode{NodeFactory::compile_expression_node<AVariableManager>(left_node)},
873 m_right_enode{NodeFactory::compile_expression_node<AVariableManager>(right_node)}, m_aoperation{aoperation}
874 {
875 }
std::unique_ptr< const AbstractExpressionNode< AVariableManager > > m_left_enode
left expression node
Definition: CutNodes.h:876
std::unique_ptr< const AbstractExpressionNode< AVariableManager > > m_right_enode
right expression node
Definition: CutNodes.h:877
ArithmeticOperation m_aoperation
arithmetic operation to be applied to the evaluations of left and right expressions
Definition: CutNodes.h:878

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 850 of file CutNodes.h.

851 {
852 std::stringstream stringstream;
853 stringstream << m_left_enode->decompile();
855 stringstream << m_right_enode->decompile();
856
857 return stringstream.str();
858 }
void injectArithmeticOperatorToStream(std::ostream &stream, const ArithmeticOperation &aoperation)
Helper functions for AbstractBooleanNode and AbstractExpressionNode print() and decompile() members S...

◆ evaluate()

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

Evaluation of the child nodes and return result as a variant<double, int, bool> apply arithmetic operation to the evaluations.

Parameters
ppointer to the object, that should be checked.

Implements AbstractExpressionNode< AVariableManager >.

Definition at line 737 of file CutNodes.h.

738 {
739 typename AVariableManager::VarVariant l_val, r_val, ret;
740 l_val = m_left_enode->evaluate(p);
741 r_val = m_right_enode->evaluate(p);
742 switch (m_aoperation) {
743 case ArithmeticOperation::PLUS:
744 if (std::holds_alternative<int>(l_val) && std::holds_alternative<int>(r_val)) {
745 ret = std::get<int>(l_val) + std::get<int>(r_val);
746 return ret;
747 } else if (std::holds_alternative<double>(l_val) && std::holds_alternative<double>(r_val)) {
748 ret = std::get<double>(l_val) + std::get<double>(r_val);
749 return ret;
750 } else if (std::holds_alternative<double>(l_val) && std::holds_alternative<int>(r_val)) {
751 ret = std::get<double>(l_val) + std::get<int>(r_val);
752 return ret;
753 } else if (std::holds_alternative<int>(l_val) && std::holds_alternative<double>(r_val)) {
754 ret = std::get<int>(l_val) + std::get<double>(r_val);
755 return ret;
756 } else {
757 throw std::runtime_error("Invalid datatypes in plus operation.");
758 }
759 break;
760 case ArithmeticOperation::MINUS:
761 if (std::holds_alternative<int>(l_val) && std::holds_alternative<int>(r_val)) {
762 ret = std::get<int>(l_val) - std::get<int>(r_val);
763 return ret;
764 } else if (std::holds_alternative<double>(l_val) && std::holds_alternative<double>(r_val)) {
765 ret = std::get<double>(l_val) - std::get<double>(r_val);
766 return ret;
767 } else if (std::holds_alternative<double>(l_val) && std::holds_alternative<int>(r_val)) {
768 ret = std::get<double>(l_val) - std::get<int>(r_val);
769 return ret;
770 } else if (std::holds_alternative<int>(l_val) && std::holds_alternative<double>(r_val)) {
771 ret = std::get<int>(l_val) - std::get<double>(r_val);
772 return ret;
773 } else {
774 throw std::runtime_error("Invalid datatypes in minus operation.");
775 }
776 break;
777 case ArithmeticOperation::PRODUCT:
778 if (std::holds_alternative<int>(l_val) && std::holds_alternative<int>(r_val)) {
779 ret = std::get<int>(l_val) * std::get<int>(r_val);
780 return ret;
781 } else if (std::holds_alternative<double>(l_val) && std::holds_alternative<double>(r_val)) {
782 ret = std::get<double>(l_val) * std::get<double>(r_val);
783 return ret;
784 } else if (std::holds_alternative<double>(l_val) && std::holds_alternative<int>(r_val)) {
785 ret = std::get<double>(l_val) * std::get<int>(r_val);
786 return ret;
787 } else if (std::holds_alternative<int>(l_val) && std::holds_alternative<double>(r_val)) {
788 ret = std::get<int>(l_val) * std::get<double>(r_val);
789 return ret;
790 } else {
791 throw std::runtime_error("Invalid datatypes in product operation.");
792 }
793 break;
794 case ArithmeticOperation::DIVISION:
795 if (std::holds_alternative<int>(l_val) && std::holds_alternative<int>(r_val)) {
796 // Always do double division
797 double d = std::get<int>(r_val);
798 ret = std::get<int>(l_val) / d;
799 return ret;
800 } else if (std::holds_alternative<double>(l_val) && std::holds_alternative<double>(r_val)) {
801 ret = std::get<double>(l_val) / std::get<double>(r_val);
802 return ret;
803 } else if (std::holds_alternative<double>(l_val) && std::holds_alternative<int>(r_val)) {
804 ret = std::get<double>(l_val) / std::get<int>(r_val);
805 return ret;
806 } else if (std::holds_alternative<int>(l_val) && std::holds_alternative<double>(r_val)) {
807 ret = std::get<int>(l_val) / std::get<double>(r_val);
808 return ret;
809 } else {
810 throw std::runtime_error("Invalid datatypes in division operation.");
811 }
812 break;
813 case ArithmeticOperation::POWER:
814 if (std::holds_alternative<int>(l_val) && std::holds_alternative<int>(r_val)) {
815 ret = std::pow(std::get<int>(l_val), std::get<int>(r_val));
816 return ret;
817 } else if (std::holds_alternative<double>(l_val) && std::holds_alternative<double>(r_val)) {
818 ret = std::pow(std::get<double>(l_val), std::get<double>(r_val));
819 return ret;
820 } else if (std::holds_alternative<double>(l_val) && std::holds_alternative<int>(r_val)) {
821 ret = std::pow(std::get<double>(l_val), std::get<int>(r_val));
822 return ret;
823 } else if (std::holds_alternative<int>(l_val) && std::holds_alternative<double>(r_val)) {
824 ret = std::pow(std::get<int>(l_val), std::get<double>(r_val));
825 return ret;
826 } else {
827 throw std::runtime_error("Invalid datatypes in power operation.");
828 }
829 break;
830 default:
831 throw std::runtime_error("Operation not valid");
832 }
833 ret = false;
834 return ret;
835 }

◆ print()

void print ( ) const
inlineoverridevirtual

Print node.

Implements AbstractExpressionNode< AVariableManager >.

Definition at line 839 of file CutNodes.h.

840 {
841 m_left_enode->print();
843 m_right_enode->print();
844 }

Friends And Related Function Documentation

◆ NodeFactory

friend class NodeFactory
friend

Definition at line 865 of file CutNodes.h.

Member Data Documentation

◆ m_aoperation

ArithmeticOperation m_aoperation
private

arithmetic operation to be applied to the evaluations of left and right expressions

Definition at line 878 of file CutNodes.h.

◆ m_left_enode

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

left expression node

Definition at line 876 of file CutNodes.h.

◆ m_right_enode

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

right expression node

Definition at line 877 of file CutNodes.h.


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