ct_common  1.0.1
Common library for combinatorial testing
src/ct_common/common/exp_a_binary.cpp
Go to the documentation of this file.
00001 //===----- ct_common/common/exp_a_binary.cpp --------------------*- C++ -*-===//
00002 //
00003 //                      The ct_common Library
00004 //
00005 // This file is distributed under the MIT license. See LICENSE for details.
00006 //
00007 //===----------------------------------------------------------------------===//
00008 //
00009 // This file contains the function definitions of class Exp_A_Binary
00010 //
00011 //===----------------------------------------------------------------------===//
00012 
00013 #include <ct_common/common/exp_a_binary.h>
00014 #include <ct_common/common/arithmetic_utils.h>
00015 
00016 using namespace ct::common;
00017 
00018 Exp_A_Binary::Exp_A_Binary(void)
00019     : Exp_A() {
00020   this->oprds_.resize(2);
00021 }
00022 
00023 Exp_A_Binary::Exp_A_Binary(const Exp_A_Binary &from)
00024   : Exp_A(from) {
00025 }
00026 
00027 Exp_A_Binary &Exp_A_Binary::operator = (const Exp_A_Binary &right) {
00028   Exp_A::operator=(right);
00029   return *this;
00030 }
00031 
00032 Exp_A_Binary::~Exp_A_Binary(void) {
00033 }
00034 
00035 std::string Exp_A_Binary::get_class_name(void) const {
00036   return Exp_A_Binary::class_name();
00037 }
00038 
00039 std::string Exp_A_Binary::class_name(void) {
00040   return "Exp_A_Binary";
00041 }
00042 
00043 EvalType_Double Exp_A_Binary::EvaluateDouble_Impl(const std::vector<boost::shared_ptr<ParamSpec> > &param_specs,
00044                                       const Assignment &assignment) const {
00045   EvalType_Double tmp_return;
00046   if (this->get_loprd()->get_type() == EAT_INT &&
00047       this->get_roprd()->get_type() == EAT_INT) {
00048     GET_EXP_VAL(EvalType_Int, val_l, this->get_loprd(), param_specs, assignment);
00049     GET_EXP_VAL(EvalType_Int, val_r, this->get_roprd(), param_specs, assignment);
00050     tmp_return.is_valid_ = val_l.is_valid_ && val_r.is_valid_;
00051     if (tmp_return.is_valid_) {
00052       tmp_return.value_ = this->evaluate_int(val_l.value_, val_r.value_);
00053     }
00054   } else if (this->get_loprd()->get_type() == EAT_DOUBLE ||
00055       this->get_roprd()->get_type() == EAT_DOUBLE) {
00056     GET_EXP_VAL(EvalType_Double, val_l, this->get_loprd(), param_specs, assignment);
00057     GET_EXP_VAL(EvalType_Double, val_r, this->get_roprd(), param_specs, assignment);
00058     tmp_return.is_valid_ = val_l.is_valid_ && val_r.is_valid_;
00059     if (tmp_return.is_valid_) {
00060       tmp_return.value_ = this->evaluate_double(val_l.value_, val_r.value_);
00061     }
00062   } else {
00063     CT_EXCEPTION("cannot evaluate this expression");
00064   }
00065   return tmp_return;
00066 }
00067 
00068 EvalType_Int Exp_A_Binary::EvaluateInt_Impl(const std::vector<boost::shared_ptr<ParamSpec> > &param_specs,
00069                                 const Assignment &assignment) const {
00070   EvalType_Int tmp_return;
00071   if (this->get_loprd()->get_type() == EAT_INT &&
00072       this->get_roprd()->get_type() == EAT_INT) {
00073     GET_EXP_VAL(EvalType_Int, val_l, this->get_loprd(), param_specs, assignment);
00074     GET_EXP_VAL(EvalType_Int, val_r, this->get_roprd(), param_specs, assignment);
00075     tmp_return.is_valid_ = val_l.is_valid_ && val_r.is_valid_;
00076     if (tmp_return.is_valid_) {
00077       tmp_return.value_ = this->evaluate_int(val_l.value_, val_r.value_);
00078     }
00079   } else if (this->get_loprd()->get_type() == EAT_DOUBLE ||
00080       this->get_roprd()->get_type() == EAT_DOUBLE) {
00081     GET_EXP_VAL(EvalType_Double, val_l, this->get_loprd(), param_specs, assignment);
00082     GET_EXP_VAL(EvalType_Double, val_r, this->get_roprd(), param_specs, assignment);
00083     tmp_return.is_valid_ = val_l.is_valid_ && val_r.is_valid_;
00084     if (tmp_return.is_valid_) {
00085       tmp_return.value_ = (int)this->evaluate_double(val_l.value_, val_r.value_);
00086     }
00087   } else {
00088     CT_EXCEPTION("cannot evaluate this expression");
00089   }
00090   return tmp_return;
00091 }
00092 
00093 void Exp_A_Binary::dump(std::ostream &os, const std::vector<boost::shared_ptr<ParamSpec> > &param_specs) const {
00094   os << "(";
00095   this->get_loprd()->dump(os, param_specs);
00096   os << this->get_op_token();
00097   this->get_roprd()->dump(os, param_specs);
00098   os << ")";
00099 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines