ct_common
1.0.1
Common library for combinatorial testing
|
00001 //===----- ct_common/common/paramspec.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 ParamSpec 00010 // 00011 //===----------------------------------------------------------------------===// 00012 00013 #include <ct_common/common/paramspec.h> 00014 #include <ct_common/common/pvpair.h> 00015 00016 using namespace ct::common; 00017 00018 ParamSpec::ParamSpec(void) 00019 : is_aux_(false), is_auto_(false) { 00020 } 00021 00022 ParamSpec::ParamSpec(const ParamSpec &from) { 00023 this->init(from); 00024 } 00025 00026 ParamSpec &ParamSpec::operator = (const ParamSpec &right) { 00027 this->init(right); 00028 return *this; 00029 } 00030 00031 void ParamSpec::init(const ParamSpec &from) { 00032 this->param_name_ = from.param_name_; 00033 this->string_values_ = from.string_values_; 00034 this->map_string_values_2_vid_ = from.map_string_values_2_vid_; 00035 this->is_aux_ = from.is_aux_; 00036 this->is_auto_ = from.is_auto_; 00037 } 00038 00039 ParamSpec::~ParamSpec(void) { 00040 } 00041 00042 void ParamSpec::set_values(const std::vector<std::string> &values) { 00043 if (values.size() == 0) { 00044 CT_EXCEPTION(std::string("no values for ") + this->get_param_name()); 00045 } 00046 this->map_string_values_2_vid_.clear(); 00047 this->string_values_ = values; 00048 this->string_values_.push_back("#"); 00049 for (std::size_t i = 0; i < values.size(); i++) { 00050 if (values[i].size() <= 0) { 00051 CT_EXCEPTION("empty value found"); 00052 } 00053 if (this->map_string_values_2_vid_.find(values[i]) != 00054 this->map_string_values_2_vid_.end()) { 00055 CT_EXCEPTION(std::string("value ") + values[i] + " is already registered for " + this->get_param_name()); 00056 } 00057 map_string_values_2_vid_.insert(std::pair<std::string, std::size_t>(values[i], i)); 00058 } 00059 } 00060 00061 std::string ParamSpec::get_class_name(void) const { 00062 return ParamSpec::class_name(); 00063 } 00064 00065 std::string ParamSpec::class_name(void) { 00066 return "ParamSpec"; 00067 } 00068 00069 std::size_t ParamSpec::query_value_id(const std::string &str) const { 00070 std::map<std::string, std::size_t>::const_iterator iter = 00071 this->map_string_values_2_vid_.find(str); 00072 if (iter != this->map_string_values_2_vid_.end()) { 00073 return iter->second; 00074 } 00075 return VID_BOUND; 00076 } 00077 00078 std::size_t ParamSpec::get_width(void) const { 00079 std::size_t width = this->param_name_.size(); 00080 for (std::size_t i = 0; i < this->string_values_.size(); ++i) { 00081 if (width < this->string_values_[i].size()) { 00082 width = this->string_values_[i].size(); 00083 } 00084 } 00085 return std::max(width + 2, std::size_t(5)); 00086 } 00087 00088 std::size_t ct::common::find_param_id(const std::vector<boost::shared_ptr<ParamSpec> > ¶m_specs, 00089 const std::string ¶m_name) { 00090 for (std::size_t i = 0; i < param_specs.size(); ++i) { 00091 if (param_specs[i]->get_param_name() == param_name) { 00092 return i; 00093 } 00094 } 00095 return PID_BOUND; 00096 } 00097 00098 void ParamSpec::touch_pids( const std::vector<boost::shared_ptr<ParamSpec> > ¶m_specs, 00099 std::set<std::size_t> &pids_to_touch) const { 00100 for (std::size_t i = 0; i < this->auto_value_specs_.size(); ++i) { 00101 if (!this->auto_value_specs_[i].first) { 00102 CT_EXCEPTION("encountered invalid auto value condition"); 00103 return; 00104 } 00105 if (!this->auto_value_specs_[i].second) { 00106 CT_EXCEPTION("encountered invalid auto value expression"); 00107 return; 00108 } 00109 this->auto_value_specs_[i].first->touch_pids(param_specs, pids_to_touch); 00110 this->auto_value_specs_[i].second->touch_pids(param_specs, pids_to_touch); 00111 } 00112 }