source: src/UIElements/CommandLineUI/CommandLineParser_validate.cpp@ 7d9416

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 7d9416 was 7d9416, checked in by Frederik Heber <heber@…>, 13 years ago

Turned query<Box> into query<RealSpaceMatrix>

  • Property mode set to 100644
File size: 5.3 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010-2012 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 "CodePatterns/MemDebug.hpp"
21
22#include <boost/version.hpp>
23
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 */
37void 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;
45#if BOOST_VERSION < 104200
46 throw boost::program_options::validation_error("Unequal to one vector given");
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
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;
71#if BOOST_VERSION < 104200
72 throw boost::program_options::validation_error("Specified vector does not have three components");
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
80 }
81 for (size_t i=0;i<NDIM;++i)
82 VV.vector[i] = boost::lexical_cast<double>(components.at(i));
83 v = boost::any(VectorValue(VV));
84}
85
86void validate(boost::any& v, const std::vector<std::string>& values, RealSpaceMatrixValue *, int)
87{
88 RealSpaceMatrixValue RSMV;
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;
94#if BOOST_VERSION < 104200
95 throw boost::program_options::validation_error("Unequal to one vector given");
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
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;
120#if BOOST_VERSION < 104200
121 throw boost::program_options::validation_error("Specified symmetric box matrix does not have six components");
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
129 }
130 for (size_t i=0;i<(NDIM*(NDIM+1))/2; ++i)
131 RSMV.matrix[i] = boost::lexical_cast<double>(components.at(i));
132 v = boost::any(RealSpaceMatrixValue(RSMV));
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 */
142void 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;
151#if BOOST_VERSION < 104200
152 throw boost::program_options::validation_error("Unequal to one file given");
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
168 }
169 filename = values.at(0);
170 v = boost::any(boost::filesystem::path(filename));
171}
172
Note: See TracBrowser for help on using the repository browser.