[3a21a7] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
| 4 | * Copyright (C) 2010 University of Bonn. All rights reserved.
|
---|
| 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | /*
|
---|
| 9 | * CommandLineParser_validate.cpp
|
---|
| 10 | *
|
---|
| 11 | * Created on: Nov 8, 2010
|
---|
| 12 | * Author: heber
|
---|
| 13 | */
|
---|
| 14 |
|
---|
| 15 | // include config.h
|
---|
| 16 | #ifdef HAVE_CONFIG_H
|
---|
| 17 | #include <config.h>
|
---|
| 18 | #endif
|
---|
| 19 |
|
---|
| 20 | #include "Helpers/MemDebug.hpp"
|
---|
| 21 |
|
---|
| 22 | #include <iostream>
|
---|
| 23 | #include <string>
|
---|
| 24 |
|
---|
| 25 | #include "Actions/Values.hpp"
|
---|
| 26 | #include "CommandLineParser_validate.hpp"
|
---|
| 27 |
|
---|
| 28 | /** boost::program_options validator specialization for VectorValue.
|
---|
| 29 | * \param &v reference for return value
|
---|
| 30 | * \param &values string vector of scanned options
|
---|
| 31 | * \param *
|
---|
| 32 | * \param
|
---|
| 33 | *
|
---|
| 34 | */
|
---|
| 35 | void validate(boost::any& v, const std::vector<std::string>& values, VectorValue *, int)
|
---|
| 36 | {
|
---|
| 37 | VectorValue VV;
|
---|
| 38 | std::vector<std::string> components;
|
---|
| 39 |
|
---|
| 40 | // split comma-separated values
|
---|
| 41 | if (values.size() != 1) {
|
---|
| 42 | std::cerr << "Not one vector but " << values.size() << " given " << std::endl;
|
---|
| 43 | throw boost::program_options::validation_error("Unequal to one vector given");
|
---|
| 44 | }
|
---|
| 45 | std::string argument(values.at(0));
|
---|
| 46 | std::string::iterator Aiter = argument.begin();
|
---|
| 47 | std::string::iterator Biter = argument.begin();
|
---|
| 48 | for (; Aiter != argument.end(); ++Aiter) {
|
---|
| 49 | if (*Aiter == ',') {
|
---|
| 50 | components.push_back(std::string(Biter,Aiter));
|
---|
| 51 | do {
|
---|
| 52 | Aiter++;
|
---|
| 53 | } while (*Aiter == ' ' || *Aiter == '\t');
|
---|
| 54 | Biter = Aiter;
|
---|
| 55 | }
|
---|
| 56 | }
|
---|
| 57 | components.push_back(std::string(Biter,argument.end()));
|
---|
| 58 |
|
---|
| 59 | if (components.size() != 3) {
|
---|
| 60 | std::cerr << "Specified vector does not have three components but " << components.size() << std::endl;
|
---|
| 61 | throw boost::program_options::validation_error("Specified vector does not have three components");
|
---|
| 62 | }
|
---|
| 63 | VV.x = boost::lexical_cast<double>(components.at(0));
|
---|
| 64 | VV.y = boost::lexical_cast<double>(components.at(1));
|
---|
| 65 | VV.z = boost::lexical_cast<double>(components.at(2));
|
---|
| 66 | v = boost::any(VectorValue(VV));
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | void validate(boost::any& v, const std::vector<std::string>& values, BoxValue *, int)
|
---|
| 70 | {
|
---|
| 71 | BoxValue BV;
|
---|
| 72 | std::vector<std::string> components;
|
---|
| 73 |
|
---|
| 74 | // split comma-separated values
|
---|
| 75 | if (values.size() != 1) {
|
---|
| 76 | std::cerr << "Not one vector but " << values.size() << " given " << std::endl;
|
---|
| 77 | throw boost::program_options::validation_error("Unequal to one vector given");
|
---|
| 78 | }
|
---|
| 79 | std::string argument(values.at(0));
|
---|
| 80 | std::string::iterator Aiter = argument.begin();
|
---|
| 81 | std::string::iterator Biter = argument.begin();
|
---|
| 82 | for (; Aiter != argument.end(); ++Aiter) {
|
---|
| 83 | if (*Aiter == ',') {
|
---|
| 84 | components.push_back(std::string(Biter,Aiter));
|
---|
| 85 | do {
|
---|
| 86 | Aiter++;
|
---|
| 87 | } while (*Aiter == ' ' || *Aiter == '\t');
|
---|
| 88 | Biter = Aiter;
|
---|
| 89 | }
|
---|
| 90 | }
|
---|
| 91 | components.push_back(std::string(Biter,argument.end()));
|
---|
| 92 |
|
---|
| 93 | if (components.size() != 6) {
|
---|
| 94 | std::cerr << "Specified vector does not have three components but " << components.size() << std::endl;
|
---|
| 95 | throw boost::program_options::validation_error("Specified symmetric box matrix does not have six components");
|
---|
| 96 | }
|
---|
| 97 | BV.xx = boost::lexical_cast<double>(components.at(0));
|
---|
| 98 | BV.yx = boost::lexical_cast<double>(components.at(1));
|
---|
| 99 | BV.yy = boost::lexical_cast<double>(components.at(2));
|
---|
| 100 | BV.zx = boost::lexical_cast<double>(components.at(3));
|
---|
| 101 | BV.zy = boost::lexical_cast<double>(components.at(4));
|
---|
| 102 | BV.zz = boost::lexical_cast<double>(components.at(5));
|
---|
| 103 | v = boost::any(BoxValue(BV));
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | /** boost::program_options validator specialization for boost::filesystem::path.
|
---|
| 107 | * \param &v reference for return value
|
---|
| 108 | * \param &values string vector of scanned options
|
---|
| 109 | * \param *
|
---|
| 110 | * \param
|
---|
| 111 | *
|
---|
| 112 | */
|
---|
| 113 | void validate(boost::any& v, const std::vector<std::string>& values, boost::filesystem::path *, int)
|
---|
| 114 | {
|
---|
| 115 | boost::filesystem::path filename;
|
---|
| 116 |
|
---|
| 117 | std::cerr << "boost::filesystem::path validator used." << std::endl;
|
---|
| 118 |
|
---|
| 119 | // split comma-separated values
|
---|
| 120 | if (values.size() != 1) {
|
---|
| 121 | std::cerr << "Not one file but " << values.size() << " given " << std::endl;
|
---|
| 122 | throw boost::program_options::validation_error("Unequal to one file given");
|
---|
| 123 | }
|
---|
| 124 | filename = values.at(0);
|
---|
| 125 | v = boost::any(boost::filesystem::path(filename));
|
---|
| 126 | }
|
---|
| 127 |
|
---|