| [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 | 
 | 
|---|
| [ad011c] | 20 | #include "CodePatterns/MemDebug.hpp"
 | 
|---|
| [3a21a7] | 21 | 
 | 
|---|
| [d5240d] | 22 | #include <boost/version.hpp>
 | 
|---|
 | 23 | 
 | 
|---|
| [3a21a7] | 24 | #include <iostream>
 | 
|---|
 | 25 | #include <string>
 | 
|---|
 | 26 | 
 | 
|---|
 | 27 | #include "Actions/Values.hpp"
 | 
|---|
 | 28 | #include "CommandLineParser_validate.hpp"
 | 
|---|
 | 29 | 
 | 
|---|
 | 30 | /** boost::program_options validator specialization for VectorValue.
 | 
|---|
 | 31 |  * \param &v  reference for return value
 | 
|---|
 | 32 |  * \param &values string vector of scanned options
 | 
|---|
 | 33 |  * \param *
 | 
|---|
 | 34 |  * \param
 | 
|---|
 | 35 |  *
 | 
|---|
 | 36 |  */
 | 
|---|
 | 37 | void validate(boost::any& v, const std::vector<std::string>& values, VectorValue *, int)
 | 
|---|
 | 38 | {
 | 
|---|
 | 39 |   VectorValue VV;
 | 
|---|
 | 40 |   std::vector<std::string> components;
 | 
|---|
 | 41 | 
 | 
|---|
 | 42 |   // split comma-separated values
 | 
|---|
 | 43 |   if (values.size() != 1) {
 | 
|---|
 | 44 |     std::cerr <<  "Not one vector but " << values.size() << " given " << std::endl;
 | 
|---|
| [d5240d] | 45 | #if BOOST_VERSION < 104200
 | 
|---|
| [3a21a7] | 46 |     throw boost::program_options::validation_error("Unequal to one vector given");
 | 
|---|
| [d5240d] | 47 | #else
 | 
|---|
 | 48 |     throw boost::program_options::validation_error(
 | 
|---|
 | 49 |         boost::program_options::validation_error::invalid_option_value,
 | 
|---|
 | 50 |         std::string("value"),
 | 
|---|
 | 51 |         std::string("VectorValue")
 | 
|---|
 | 52 |     );
 | 
|---|
 | 53 | #endif
 | 
|---|
| [3a21a7] | 54 |   }
 | 
|---|
 | 55 |   std::string argument(values.at(0));
 | 
|---|
 | 56 |   std::string::iterator Aiter = argument.begin();
 | 
|---|
 | 57 |   std::string::iterator Biter = argument.begin();
 | 
|---|
 | 58 |   for (; Aiter != argument.end(); ++Aiter) {
 | 
|---|
 | 59 |     if (*Aiter == ',') {
 | 
|---|
 | 60 |       components.push_back(std::string(Biter,Aiter));
 | 
|---|
 | 61 |       do {
 | 
|---|
 | 62 |         Aiter++;
 | 
|---|
 | 63 |       } while (*Aiter == ' ' || *Aiter == '\t');
 | 
|---|
 | 64 |       Biter = Aiter;
 | 
|---|
 | 65 |     }
 | 
|---|
 | 66 |   }
 | 
|---|
 | 67 |   components.push_back(std::string(Biter,argument.end()));
 | 
|---|
 | 68 | 
 | 
|---|
 | 69 |   if (components.size() != 3) {
 | 
|---|
 | 70 |     std::cerr <<  "Specified vector does not have three components but " << components.size() << std::endl;
 | 
|---|
| [d5240d] | 71 | #if BOOST_VERSION < 104200
 | 
|---|
| [3a21a7] | 72 |     throw boost::program_options::validation_error("Specified vector does not have three components");
 | 
|---|
| [d5240d] | 73 | #else
 | 
|---|
 | 74 |     throw boost::program_options::validation_error(
 | 
|---|
 | 75 |         boost::program_options::validation_error::invalid_option_value,
 | 
|---|
 | 76 |         std::string("value"),
 | 
|---|
 | 77 |         std::string("VectorValue")
 | 
|---|
 | 78 |     );
 | 
|---|
 | 79 | #endif
 | 
|---|
| [3a21a7] | 80 |   }
 | 
|---|
| [528b3e] | 81 |   for (size_t i=0;i<NDIM;++i)
 | 
|---|
 | 82 |     VV.vector[i] = boost::lexical_cast<double>(components.at(i));
 | 
|---|
| [3a21a7] | 83 |   v = boost::any(VectorValue(VV));
 | 
|---|
 | 84 | }
 | 
|---|
 | 85 | 
 | 
|---|
 | 86 | void validate(boost::any& v, const std::vector<std::string>& values, BoxValue *, int)
 | 
|---|
 | 87 | {
 | 
|---|
 | 88 |   BoxValue BV;
 | 
|---|
 | 89 |   std::vector<std::string> components;
 | 
|---|
 | 90 | 
 | 
|---|
 | 91 |   // split comma-separated values
 | 
|---|
 | 92 |   if (values.size() != 1) {
 | 
|---|
 | 93 |     std::cerr <<  "Not one vector but " << values.size() << " given " << std::endl;
 | 
|---|
| [d5240d] | 94 | #if BOOST_VERSION < 104200
 | 
|---|
| [3a21a7] | 95 |     throw boost::program_options::validation_error("Unequal to one vector given");
 | 
|---|
| [d5240d] | 96 | #else
 | 
|---|
 | 97 |     throw boost::program_options::validation_error(
 | 
|---|
 | 98 |         boost::program_options::validation_error::invalid_option_value,
 | 
|---|
 | 99 |         std::string("value"),
 | 
|---|
 | 100 |         std::string("BoxValue")
 | 
|---|
 | 101 |     );
 | 
|---|
 | 102 | #endif
 | 
|---|
| [3a21a7] | 103 |   }
 | 
|---|
 | 104 |   std::string argument(values.at(0));
 | 
|---|
 | 105 |   std::string::iterator Aiter = argument.begin();
 | 
|---|
 | 106 |   std::string::iterator Biter = argument.begin();
 | 
|---|
 | 107 |   for (; Aiter != argument.end(); ++Aiter) {
 | 
|---|
 | 108 |     if (*Aiter == ',') {
 | 
|---|
 | 109 |       components.push_back(std::string(Biter,Aiter));
 | 
|---|
 | 110 |       do {
 | 
|---|
 | 111 |         Aiter++;
 | 
|---|
 | 112 |       } while (*Aiter == ' ' || *Aiter == '\t');
 | 
|---|
 | 113 |       Biter = Aiter;
 | 
|---|
 | 114 |     }
 | 
|---|
 | 115 |   }
 | 
|---|
 | 116 |   components.push_back(std::string(Biter,argument.end()));
 | 
|---|
 | 117 | 
 | 
|---|
 | 118 |   if (components.size() != 6) {
 | 
|---|
 | 119 |     std::cerr <<  "Specified vector does not have three components but " << components.size() << std::endl;
 | 
|---|
| [d5240d] | 120 | #if BOOST_VERSION < 104200
 | 
|---|
| [3a21a7] | 121 |     throw boost::program_options::validation_error("Specified symmetric box matrix does not have six components");
 | 
|---|
| [d5240d] | 122 | #else
 | 
|---|
 | 123 |     throw boost::program_options::validation_error(
 | 
|---|
 | 124 |         boost::program_options::validation_error::invalid_option_value,
 | 
|---|
 | 125 |         std::string("value"),
 | 
|---|
 | 126 |         std::string("BoxValue")
 | 
|---|
 | 127 |     );
 | 
|---|
 | 128 | #endif
 | 
|---|
| [3a21a7] | 129 |   }
 | 
|---|
| [528b3e] | 130 |   for (size_t i=0;i<(NDIM*(NDIM+1))/2; ++i)
 | 
|---|
 | 131 |     BV.matrix[i] = boost::lexical_cast<double>(components.at(i));
 | 
|---|
| [3a21a7] | 132 |   v = boost::any(BoxValue(BV));
 | 
|---|
 | 133 | }
 | 
|---|
 | 134 | 
 | 
|---|
 | 135 | /** boost::program_options validator specialization for boost::filesystem::path.
 | 
|---|
 | 136 |  * \param &v  reference for return value
 | 
|---|
 | 137 |  * \param &values string vector of scanned options
 | 
|---|
 | 138 |  * \param *
 | 
|---|
 | 139 |  * \param
 | 
|---|
 | 140 |  *
 | 
|---|
 | 141 |  */
 | 
|---|
 | 142 | void validate(boost::any& v, const std::vector<std::string>& values, boost::filesystem::path *, int)
 | 
|---|
 | 143 | {
 | 
|---|
 | 144 |   boost::filesystem::path filename;
 | 
|---|
 | 145 | 
 | 
|---|
 | 146 |   std::cerr << "boost::filesystem::path validator used." << std::endl;
 | 
|---|
 | 147 | 
 | 
|---|
 | 148 |   // split comma-separated values
 | 
|---|
 | 149 |   if (values.size() != 1) {
 | 
|---|
 | 150 |     std::cerr <<  "Not one file but " << values.size() << " given " << std::endl;
 | 
|---|
| [d5240d] | 151 | #if BOOST_VERSION < 104200
 | 
|---|
| [3a21a7] | 152 |     throw boost::program_options::validation_error("Unequal to one file given");
 | 
|---|
| [d5240d] | 153 | #else
 | 
|---|
 | 154 |     if (values.size() == 0) {
 | 
|---|
 | 155 |       throw boost::program_options::validation_error(
 | 
|---|
 | 156 |           boost::program_options::validation_error::at_least_one_value_required,
 | 
|---|
 | 157 |           std::string("value"),
 | 
|---|
 | 158 |           std::string("boost::filesystem::path")
 | 
|---|
 | 159 |       );
 | 
|---|
 | 160 |     } else {
 | 
|---|
 | 161 |       throw boost::program_options::validation_error(
 | 
|---|
 | 162 |           boost::program_options::validation_error::multiple_values_not_allowed,
 | 
|---|
 | 163 |           std::string("value"),
 | 
|---|
 | 164 |           std::string("boost::filesystem::path")
 | 
|---|
 | 165 |       );
 | 
|---|
 | 166 |     }
 | 
|---|
 | 167 | #endif
 | 
|---|
| [3a21a7] | 168 |   }
 | 
|---|
 | 169 |   filename = values.at(0);
 | 
|---|
 | 170 |   v = boost::any(boost::filesystem::path(filename));
 | 
|---|
 | 171 | }
 | 
|---|
 | 172 | 
 | 
|---|