source: src/UIElements/CommandLineUI/CommandLineParser_validate.cpp@ ae21cbd

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 ae21cbd was 3a21a7, checked in by Frederik Heber <heber@…>, 14 years ago

Moved validate() functions for boost::program_options into own module.

  • Property mode set to 100644
File size: 4.1 KB
RevLine 
[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 */
35void 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
69void 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 */
113void 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
Note: See TracBrowser for help on using the repository browser.