Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/MapOfActions.cpp

    r7230be rbd2390  
    3131#include <boost/optional.hpp>
    3232#include <boost/program_options.hpp>
     33#include <boost/filesystem.hpp>
    3334
    3435#include <iostream>
     
    190191  BV.zz = boost::lexical_cast<double>(components.at(5));
    191192  v = boost::any(BoxValue(BV));
     193}
     194
     195void validate(boost::any& v, const std::vector<std::string>& values, boost::filesystem::path *, int)
     196{
     197  boost::filesystem::path filename;
     198  std::vector<std::string> components;
     199
     200  std::cout << "boost::filesystem::path validator used." << std::endl;
     201
     202  // split comma-separated values
     203  if (values.size() != 1) {
     204    cerr <<  "Not one file but " << components.size() << " given " << endl;
     205    throw boost::program_options::validation_error("Unequal to one file given");
     206  }
     207  filename = values.at(0);
     208  v = boost::any(boost::filesystem::path(filename));
    192209}
    193210
     
    367384  TypeMap["fill-void"] = &typeid(std::string);
    368385  TypeMap["fragment-mol"] = &typeid(std::string);
    369   TypeMap["input"] = &typeid(std::string);
     386  TypeMap["input"] = &typeid(boost::filesystem::path);
    370387  TypeMap["linear-interpolate"] = &typeid(std::string);
    371388  TypeMap["molecular-volume"] = &typeid(molecule);
     
    446463  TypeEnumMap[&typeid(bool)] = Boolean;
    447464  TypeEnumMap[&typeid(int)] = Integer;
     465  TypeEnumMap[&typeid(boost::filesystem::path)] = File;
    448466  TypeEnumMap[&typeid(std::vector<int>)] = ListOfIntegers;
    449467  TypeEnumMap[&typeid(double)] = Double;
     
    825843}
    826844
     845void MapOfActions::queryCurrentValue(const char * name, boost::filesystem::path&_T)
     846{
     847  std::string tmp;
     848  if (typeid( boost::filesystem::path ) == *TypeMap[name]) {
     849    if (CurrentValue.find(name) == CurrentValue.end())
     850      throw MissingValueException(__FILE__, __LINE__);
     851    std::istringstream stream(CurrentValue[name]);
     852    CurrentValue.erase(name);
     853    if (!stream.fail()) {
     854      stream >> tmp >> ws;
     855      _T = tmp;
     856    }
     857  } else
     858    throw IllegalTypeException(__FILE__,__LINE__);
     859}
     860
    827861
    828862void MapOfActions::setCurrentValue(const char * name, class atom * &_T)
     
    927961      stream << (*iter)->getId() << " ";
    928962    }
     963    CurrentValue[name] = stream.str();
     964  } else
     965    throw IllegalTypeException(__FILE__,__LINE__);
     966}
     967
     968void MapOfActions::setCurrentValue(const char * name, boost::filesystem::path &_T)
     969{
     970  if (typeid( boost::filesystem::path ) == *TypeMap[name]) {
     971    std::ostringstream stream;
     972    stream << _T.string();
    929973    CurrentValue[name] = stream.str();
    930974  } else
     
    10511095              ;
    10521096            break;
     1097          case File:
     1098            ListRunner->second->add_options()
     1099              (getKeyAndShortForm(*OptionRunner).c_str(),
     1100                  po::value< boost::filesystem::path >(),
     1101                  getDescription(*OptionRunner).c_str())
     1102              ;
     1103            break;
    10531104          case Integer:
    10541105            ListRunner->second->add_options()
Note: See TracChangeset for help on using the changeset viewer.