Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/UIElements/CommandLineUI/CommandLineParser_validate.cpp

    r33e801 r94d5ac6  
    4242#include "Actions/Values.hpp"
    4343#include "CommandLineParser_validate.hpp"
    44 #include "Parameters/Specifics/KeyValuePair.hpp"
    4544
    4645/** boost::program_options validator specialization for VectorValue.
     
    158157void validate(boost::any& v, const std::vector<std::string>& values, boost::filesystem::path *, int)
    159158{
    160 //  std::cerr << "boost::filesystem::path validator used." << std::endl;
     159  boost::filesystem::path filename;
    161160
    162   // Make sure no previous assignment to 'a' was made.
    163   boost::program_options::validators::check_first_occurrence(v);
    164   // Extract the first string from 'values'. If there is more than
    165   // one string, it's an error, and exception will be thrown.
    166   const std::string& s = boost::program_options::validators::get_single_string(values);
    167 
    168   v = boost::any(boost::filesystem::path(s));
    169 }
    170 
    171 /** boost::program_options validator specialization for boost::filesystem::path.
    172  * \param &v  reference for return value
    173  * \param &values string vector of scanned options
    174  * \param *
    175  * \param
    176  *
    177  */
    178 void validate(boost::any& v, const std::vector<std::string>& values, KeyValuePair *, int)
    179 {
    180 //  std::cerr << "KeyValuePair validator used." << std::endl;
    181 
    182   // Make sure no previous assignment to 'a' was made.
    183   boost::program_options::validators::check_first_occurrence(v);
    184   // Extract the first string from 'values'. If there is more than
    185   // one string, it's an error, and exception will be thrown.
    186   const std::string& s = boost::program_options::validators::get_single_string(values);
    187 
    188   if (s.find("=") == std::string::npos) {
    189 #if BOOST_VERSION < 104200
    190     throw boost::program_options::validation_error("Invalid KeyValue given");
    191 #else
    192 throw boost::program_options::validation_error(
    193     boost::program_options::validation_error::invalid_option_value,
    194     std::string("value"),
    195     std::string("vector<KeyValuePair>")
    196     );
    197 #endif
    198   }
    199   v = boost::any(KeyValuePair(s));
    200 }
    201 
    202 /** boost::program_options validator specialization for boost::filesystem::path.
    203  * \param &v  reference for return value
    204  * \param &values string vector of scanned options
    205  * \param *
    206  * \param
    207  *
    208  */
    209 void validate(boost::any& v, const std::vector<std::string>& values, std::vector<KeyValuePair> *, int)
    210 {
    211 //  std::cerr << "vector<KeyValuePair> validator used." << std::endl;
     161  std::cerr << "boost::filesystem::path validator used." << std::endl;
    212162
    213163  // split comma-separated values
    214   if (values.size() > 1) {
     164  if (values.size() != 1) {
     165    std::cerr <<  "Not one file but " << values.size() << " given " << std::endl;
    215166#if BOOST_VERSION < 104200
    216167    throw boost::program_options::validation_error("Unequal to one file given");
     
    220171          boost::program_options::validation_error::at_least_one_value_required,
    221172          std::string("value"),
    222           std::string("vector<KeyValuePair>")
     173          std::string("boost::filesystem::path")
     174      );
     175    } else {
     176      throw boost::program_options::validation_error(
     177          boost::program_options::validation_error::multiple_values_not_allowed,
     178          std::string("value"),
     179          std::string("boost::filesystem::path")
    223180      );
    224181    }
    225182#endif
    226     for (std::vector<std::string>::const_iterator iter = values.begin();
    227         iter != values.end();++iter)
    228       if ((*iter).find("=") == std::string::npos) {
    229 #if BOOST_VERSION < 104200
    230     throw boost::program_options::validation_error("Invalid KeyValue given");
    231 #else
    232     throw boost::program_options::validation_error(
    233         boost::program_options::validation_error::invalid_option_value,
    234         std::string("value"),
    235         std::string("vector<KeyValuePair>")
    236     );
    237 #endif
    238       }
    239183  }
    240   std::vector<KeyValuePair> temp;
    241   for (std::vector<std::string>::const_iterator iter = values.begin();
    242       iter != values.end();++iter)
    243     temp.push_back(KeyValuePair(*iter));
    244   v = boost::any(temp);
     184  filename = values.at(0);
     185  v = boost::any(boost::filesystem::path(filename));
    245186}
     187
Note: See TracChangeset for help on using the changeset viewer.