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