Ignore:
File:
1 edited

Legend:

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

    re4afb4 r3a21a7  
    2121
    2222#include <boost/filesystem.hpp>
    23 #include <boost/lexical_cast.hpp>
    2423#include <boost/program_options.hpp>
    2524#include <fstream>
    2625#include <iostream>
    2726#include <map>
    28 #include <vector>
    2927
    3028#include "Actions/Action.hpp"
     
    3432#include "Actions/OptionTrait.hpp"
    3533#include "Actions/Values.hpp"
    36 #include "Helpers/Assert.hpp"
    3734#include "Helpers/Log.hpp"
    3835#include "Helpers/Verbose.hpp"
    3936#include "CommandLineParser.hpp"
     37#include "CommandLineParser_validate.hpp"
    4038
    4139#include "Patterns/Singleton_impl.hpp"
    4240
    4341class element;
    44 
    45 using 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  */
    54 void 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 
    88 void 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  */
    132 void 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 
    14742
    14843/** Constructor of class CommandLineParser.
     
    461356{
    462357  po::store(po::command_line_parser(argc,argv).options(cmdline_options).run(), vm);
    463   ifstream input;
     358  std::ifstream input;
    464359  input.open("example.cfg");
    465360  if (!input.fail())
     
    473368void CommandLineParser::scanforSequenceOfArguments()
    474369{
    475   map <std::string, std::string> ShortFormToActionMap = getShortFormToActionMap();
     370  std::map <std::string, std::string> ShortFormToActionMap = getShortFormToActionMap();
    476371  // go through all arguments
    477372  for (int i=1;i<argc;i++) {
    478     (cout << Verbose(1) << "Checking on " << argv[i] << endl);
     373    (std::cout << Verbose(1) << "Checking on " << argv[i] << std::endl);
    479374    // check whether they
    480375    if (argv[i][0] == '-') { // .. begin with -
     
    485380        //  .. and check that next letter is not numeric, if so insert
    486381      } else if (((argv[i][1] < '0') || (argv[i][1] > '9')) && ((argv[i][1] != '.'))) {
    487         map <std::string, std::string>::iterator iter = ShortFormToActionMap.find(&(argv[i][1]));
     382        std::map <std::string, std::string>::iterator iter = ShortFormToActionMap.find(&(argv[i][1]));
    488383        if (iter != ShortFormToActionMap.end()) {
    489384          (cout << Verbose(1) << "Putting " << iter->second << " for " << iter->first << " into the sequence." << endl);
     
    511406std::map <std::string, std::string> CommandLineParser::getShortFormToActionMap()
    512407{
    513   map <std::string, std::string> result;
     408  std::map <std::string, std::string> result;
    514409
    515410  ActionRegistry &AR = ActionRegistry::getInstance();
Note: See TracChangeset for help on using the changeset viewer.