ct_common  1.0.1
Common library for combinatorial testing
src/ct_common/common/exp_s_param.cpp
Go to the documentation of this file.
00001 //===----- ct_common/common/exp_s_param.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_S_Param
00010 //
00011 //===----------------------------------------------------------------------===//
00012 
00013 #include <ct_common/common/utils.h>
00014 #include <ct_common/common/exp_s_param.h>
00015 #include <ct_common/common/paramspec_string.h>
00016 #include <ct_common/common/constraint.h>
00017 
00018 using namespace ct::common;
00019 
00020 Exp_S_Param::Exp_S_Param(void)
00021     : Exp_S_Atom(), pid_(PID_BOUND) {
00022 }
00023 
00024 Exp_S_Param::Exp_S_Param(const Exp_S_Param &from)
00025     : Exp_S_Atom(from), pid_(from.pid_) {
00026 }
00027 
00028 Exp_S_Param &Exp_S_Param::operator = (const Exp_S_Param &right) {
00029   Exp_S_Atom::operator=(right);
00030   this->pid_ = right.pid_;
00031   return *this;
00032 }
00033 
00034 Exp_S_Param::~Exp_S_Param(void) {
00035 }
00036 
00037 EvalType_String Exp_S_Param::Evaluate(const std::vector<boost::shared_ptr<ParamSpec> > &param_specs,
00038                                   const Assignment &assignment) const {
00039   EvalType_String tmp_return;
00040   if (!TYPE_CHECK(param_specs[this->pid_].get(), ParamSpec_String*)) {
00041     CT_EXCEPTION("cannot evaluate string value of a non-string parameter");
00042     return tmp_return;
00043   }
00044   // FIXME: need to reconsider the logic
00045   if (param_specs[this->pid_]->is_auto()) {
00046     for (std::size_t i = 0; i < param_specs[this->pid_]->get_auto_value_specs().size(); ++i) {
00047       boost::shared_ptr<Constraint> cond = boost::dynamic_pointer_cast<Constraint>(param_specs[this->pid_]->auto_value_specs()[i].first);
00048       if (cond) {
00049         EvalType_Bool cond_value = cond->Evaluate(param_specs, assignment);
00050         if (cond_value.is_valid_ && cond_value.value_) {
00051           // condition met, taking the value
00052           boost::shared_ptr<Exp_S> val_exp = boost::dynamic_pointer_cast<Exp_S>(param_specs[this->pid_]->auto_value_specs()[i].second);
00053           if (val_exp) {
00054             return val_exp->Evaluate(param_specs, assignment);
00055           } else {
00056             CT_EXCEPTION("Error: encountering invalid auto value expression");
00057             return tmp_return;
00058           }
00059         }
00060       } else {
00061         CT_EXCEPTION("Error: encountering invalid auto value condition");
00062         return tmp_return;
00063       }
00064     }
00065     // FIXME: suppressing error
00066     //CT_EXCEPTION(std::string("Error: encountering unhandled auto value condition for parameter ")+param_specs[this->pid_]->get_param_name());
00067     return tmp_return;
00068   }
00069   std::size_t vid = assignment.GetValue(this->pid_);
00070   tmp_return.is_valid_ = !param_specs[this->pid_]->is_vid_invalid(vid);
00071   if (tmp_return.is_valid_) {
00072     tmp_return.value_ = dynamic_cast<ParamSpec_String *>(param_specs[this->pid_].get())
00073               ->get_string_values()[vid];
00074   }
00075   return tmp_return;
00076 }
00077 
00078 std::string Exp_S_Param::get_class_name(void) const {
00079   return Exp_S_Param::class_name();
00080 }
00081 
00082 std::string Exp_S_Param::class_name(void) {
00083   return "Exp_S_Param";
00084 }
00085 
00086 void Exp_S_Param::inner_touch_leaf_pids(const std::vector<boost::shared_ptr<ParamSpec> > &param_specs,
00087                                   std::set<std::size_t> &pids_to_touch) const {
00088   if (!param_specs[this->pid_]) {
00089     CT_EXCEPTION("encountered invalid parameter spec");
00090     return;
00091   }
00092   if (param_specs[this->pid_]->is_auto()) {
00093     param_specs[this->pid_]->touch_pids(param_specs, pids_to_touch);
00094   } else {
00095     pids_to_touch.insert(this->pid_);
00096   }
00097 }
00098 
00099 void Exp_S_Param::dump(std::ostream &os, const std::vector<boost::shared_ptr<ParamSpec> > &param_specs) const {
00100   os << param_specs[this->pid_]->get_param_name();
00101 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines