Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified src/UIElements/CommandLineUI/CommandLineParser.cpp

    r3a21a7 re4afb4  
    2121
    2222#include <boost/filesystem.hpp>
     23#include <boost/lexical_cast.hpp>
    2324#include <boost/program_options.hpp>
    2425#include <fstream>
    2526#include <iostream>
    2627#include <map>
     28#include <vector>
    2729
    2830#include "Actions/Action.hpp"
     
    3234#include "Actions/OptionTrait.hpp"
    3335#include "Actions/Values.hpp"
     36#include "Helpers/Assert.hpp"
    3437#include "Helpers/Log.hpp"
    3538#include "Helpers/Verbose.hpp"
    3639#include "CommandLineParser.hpp"
    37 #include "CommandLineParser_validate.hpp"
    3840
    3941#include "Patterns/Singleton_impl.hpp"
    4042
    4143class element;
     44
     45using namespace std;
     46
     47/** boost::program_options validator specialization for VectorValue.
     48 * \param &v  reference for return value
     49 * \param &values string vector of scanned options
     50 * \param *
     51 * \param
     52 *
     53 */
     54void validate(boost::any& v, const std::vector<std::string>& values, VectorValue *, int)
     55{
     56  VectorValue VV;
     57  std::vector<std::string> components;
     58
     59  // split comma-separated values
     60  if (values.size() != 1) {
     61    cerr <<  "Not one vector but " << values.size() << " given " << endl;
     62    throw boost::program_options::validation_error("Unequal to one vector given");
     63  }
     64  std::string argument(values.at(0));
     65  std::string::iterator Aiter = argument.begin();
     66  std::string::iterator Biter = argument.begin();
     67  for (; Aiter != argument.end(); ++Aiter) {
     68    if (*Aiter == ',') {
     69      components.push_back(string(Biter,Aiter));
     70      do {
     71        Aiter++;
     72      } while (*Aiter == ' ' || *Aiter == '\t');
     73      Biter = Aiter;
     74    }
     75  }
     76  components.push_back(string(Biter,argument.end()));
     77
     78  if (components.size() != 3) {
     79    cerr <<  "Specified vector does not have three components but " << components.size() << endl;
     80    throw boost::program_options::validation_error("Specified vector does not have three components");
     81  }
     82  VV.x = boost::lexical_cast<double>(components.at(0));
     83  VV.y = boost::lexical_cast<double>(components.at(1));
     84  VV.z = boost::lexical_cast<double>(components.at(2));
     85  v = boost::any(VectorValue(VV));
     86}
     87
     88void validate(boost::any& v, const std::vector<std::string>& values, BoxValue *, int)
     89{
     90  BoxValue BV;
     91  std::vector<std::string> components;
     92
     93  // split comma-separated values
     94  if (values.size() != 1) {
     95    cerr <<  "Not one vector but " << values.size() << " given " << endl;
     96    throw boost::program_options::validation_error("Unequal to one vector given");
     97  }
     98  std::string argument(values.at(0));
     99  std::string::iterator Aiter = argument.begin();
     100  std::string::iterator Biter = argument.begin();
     101  for (; Aiter != argument.end(); ++Aiter) {
     102    if (*Aiter == ',') {
     103      components.push_back(string(Biter,Aiter));
     104      do {
     105        Aiter++;
     106      } while (*Aiter == ' ' || *Aiter == '\t');
     107      Biter = Aiter;
     108    }
     109  }
     110  components.push_back(string(Biter,argument.end()));
     111
     112  if (components.size() != 6) {
     113    cerr <<  "Specified vector does not have three components but " << components.size() << endl;
     114    throw boost::program_options::validation_error("Specified symmetric box matrix does not have six components");
     115  }
     116  BV.xx = boost::lexical_cast<double>(components.at(0));
     117  BV.yx = boost::lexical_cast<double>(components.at(1));
     118  BV.yy = boost::lexical_cast<double>(components.at(2));
     119  BV.zx = boost::lexical_cast<double>(components.at(3));
     120  BV.zy = boost::lexical_cast<double>(components.at(4));
     121  BV.zz = boost::lexical_cast<double>(components.at(5));
     122  v = boost::any(BoxValue(BV));
     123}
     124
     125/** boost::program_options validator specialization for boost::filesystem::path.
     126 * \param &v  reference for return value
     127 * \param &values string vector of scanned options
     128 * \param *
     129 * \param
     130 *
     131 */
     132void validate(boost::any& v, const std::vector<std::string>& values, boost::filesystem::path *, int)
     133{
     134  boost::filesystem::path filename;
     135
     136  std::cout << "boost::filesystem::path validator used." << std::endl;
     137
     138  // split comma-separated values
     139  if (values.size() != 1) {
     140    cerr <<  "Not one file but " << values.size() << " given " << endl;
     141    throw boost::program_options::validation_error("Unequal to one file given");
     142  }
     143  filename = values.at(0);
     144  v = boost::any(boost::filesystem::path(filename));
     145}
     146
    42147
    43148/** Constructor of class CommandLineParser.
     
    356461{
    357462  po::store(po::command_line_parser(argc,argv).options(cmdline_options).run(), vm);
    358   std::ifstream input;
     463  ifstream input;
    359464  input.open("example.cfg");
    360465  if (!input.fail())
     
    368473void CommandLineParser::scanforSequenceOfArguments()
    369474{
    370   std::map <std::string, std::string> ShortFormToActionMap = getShortFormToActionMap();
     475  map <std::string, std::string> ShortFormToActionMap = getShortFormToActionMap();
    371476  // go through all arguments
    372477  for (int i=1;i<argc;i++) {
    373     (std::cout << Verbose(1) << "Checking on " << argv[i] << std::endl);
     478    (cout << Verbose(1) << "Checking on " << argv[i] << endl);
    374479    // check whether they
    375480    if (argv[i][0] == '-') { // .. begin with -
     
    380485        //  .. and check that next letter is not numeric, if so insert
    381486      } else if (((argv[i][1] < '0') || (argv[i][1] > '9')) && ((argv[i][1] != '.'))) {
    382         std::map <std::string, std::string>::iterator iter = ShortFormToActionMap.find(&(argv[i][1]));
     487        map <std::string, std::string>::iterator iter = ShortFormToActionMap.find(&(argv[i][1]));
    383488        if (iter != ShortFormToActionMap.end()) {
    384489          (cout << Verbose(1) << "Putting " << iter->second << " for " << iter->first << " into the sequence." << endl);
     
    406511std::map <std::string, std::string> CommandLineParser::getShortFormToActionMap()
    407512{
    408   std::map <std::string, std::string> result;
     513  map <std::string, std::string> result;
    409514
    410515  ActionRegistry &AR = ActionRegistry::getInstance();
Note: See TracChangeset for help on using the changeset viewer.