| 1 | /* | 
|---|
| 2 | * MapOfActions.cpp | 
|---|
| 3 | * | 
|---|
| 4 | *  Created on: 10.05.2010 | 
|---|
| 5 | *      Author: heber | 
|---|
| 6 | */ | 
|---|
| 7 |  | 
|---|
| 8 | #include "Helpers/MemDebug.hpp" | 
|---|
| 9 |  | 
|---|
| 10 | using namespace std; | 
|---|
| 11 |  | 
|---|
| 12 | #include "Patterns/Singleton_impl.hpp" | 
|---|
| 13 | #include "Actions/MapOfActions.hpp" | 
|---|
| 14 | #include "Helpers/Assert.hpp" | 
|---|
| 15 |  | 
|---|
| 16 | #include <boost/lexical_cast.hpp> | 
|---|
| 17 | #include <boost/optional.hpp> | 
|---|
| 18 | #include <boost/program_options.hpp> | 
|---|
| 19 |  | 
|---|
| 20 | #include <iostream> | 
|---|
| 21 |  | 
|---|
| 22 | #include "CommandLineParser.hpp" | 
|---|
| 23 | #include "log.hpp" | 
|---|
| 24 | #include "verbose.hpp" | 
|---|
| 25 |  | 
|---|
| 26 | #include "Actions/ActionRegistry.hpp" | 
|---|
| 27 | #include "Actions/AnalysisAction/MolecularVolumeAction.hpp" | 
|---|
| 28 | #include "Actions/AnalysisAction/PairCorrelationAction.hpp" | 
|---|
| 29 | #include "Actions/AnalysisAction/PrincipalAxisSystemAction.hpp" | 
|---|
| 30 | #include "Actions/AtomAction/AddAction.hpp" | 
|---|
| 31 | #include "Actions/AtomAction/ChangeElementAction.hpp" | 
|---|
| 32 | #include "Actions/AtomAction/RemoveAction.hpp" | 
|---|
| 33 | #include "Actions/CmdAction/BondLengthTableAction.hpp" | 
|---|
| 34 | #include "Actions/CmdAction/ElementDbAction.hpp" | 
|---|
| 35 | #include "Actions/CmdAction/FastParsingAction.hpp" | 
|---|
| 36 | #include "Actions/CmdAction/HelpAction.hpp" | 
|---|
| 37 | #include "Actions/CmdAction/VerboseAction.hpp" | 
|---|
| 38 | #include "Actions/CmdAction/VersionAction.hpp" | 
|---|
| 39 | #include "Actions/FragmentationAction/DepthFirstSearchAction.hpp" | 
|---|
| 40 | #include "Actions/FragmentationAction/SubgraphDissectionAction.hpp" | 
|---|
| 41 | #include "Actions/FragmentationAction/FragmentationAction.hpp" | 
|---|
| 42 | #include "Actions/MoleculeAction/BondFileAction.hpp" | 
|---|
| 43 | #include "Actions/MoleculeAction/ChangeNameAction.hpp" | 
|---|
| 44 | #include "Actions/MoleculeAction/FillWithMoleculeAction.hpp" | 
|---|
| 45 | #include "Actions/MoleculeAction/LinearInterpolationofTrajectoriesAction.hpp" | 
|---|
| 46 | #include "Actions/MoleculeAction/RotateToPrincipalAxisSystemAction.hpp" | 
|---|
| 47 | #include "Actions/MoleculeAction/SaveAdjacencyAction.hpp" | 
|---|
| 48 | #include "Actions/MoleculeAction/SaveBondsAction.hpp" | 
|---|
| 49 | #include "Actions/MoleculeAction/SaveTemperatureAction.hpp" | 
|---|
| 50 | #include "Actions/MoleculeAction/SuspendInWaterAction.hpp" | 
|---|
| 51 | #include "Actions/MoleculeAction/TranslateAction.hpp" | 
|---|
| 52 | #include "Actions/MoleculeAction/VerletIntegrationAction.hpp" | 
|---|
| 53 | #include "Actions/ParserAction/LoadXyzAction.hpp" | 
|---|
| 54 | #include "Actions/ParserAction/SaveXyzAction.hpp" | 
|---|
| 55 | #include "Actions/TesselationAction/ConvexEnvelopeAction.hpp" | 
|---|
| 56 | #include "Actions/TesselationAction/NonConvexEnvelopeAction.hpp" | 
|---|
| 57 | #include "Actions/WorldAction/AddEmptyBoundaryAction.hpp" | 
|---|
| 58 | #include "Actions/WorldAction/BoundInBoxAction.hpp" | 
|---|
| 59 | #include "Actions/WorldAction/CenterInBoxAction.hpp" | 
|---|
| 60 | #include "Actions/WorldAction/CenterOnEdgeAction.hpp" | 
|---|
| 61 | #include "Actions/WorldAction/ChangeBoxAction.hpp" | 
|---|
| 62 | #include "Actions/WorldAction/InputAction.hpp" | 
|---|
| 63 | #include "Actions/WorldAction/OutputAction.hpp" | 
|---|
| 64 | #include "Actions/WorldAction/RemoveSphereOfAtomsAction.hpp" | 
|---|
| 65 | #include "Actions/WorldAction/RepeatBoxAction.hpp" | 
|---|
| 66 | #include "Actions/WorldAction/ScaleBoxAction.hpp" | 
|---|
| 67 | #include "Actions/WorldAction/SetDefaultNameAction.hpp" | 
|---|
| 68 | #include "Actions/WorldAction/SetGaussianBasisAction.hpp" | 
|---|
| 69 | #include "Actions/WorldAction/SetOutputFormatsAction.hpp" | 
|---|
| 70 | #include "Actions/Values.hpp" | 
|---|
| 71 |  | 
|---|
| 72 | void validate(boost::any& v, const std::vector<std::string>& values, VectorValue *, int) | 
|---|
| 73 | { | 
|---|
| 74 | VectorValue VV; | 
|---|
| 75 | std::vector<std::string> components; | 
|---|
| 76 |  | 
|---|
| 77 | // split comma-separated values | 
|---|
| 78 | if (values.size() != 1) { | 
|---|
| 79 | cerr <<  "Not one vector but " << components.size() << " given " << endl; | 
|---|
| 80 | throw boost::program_options::validation_error("Unequal to one vector given"); | 
|---|
| 81 | } | 
|---|
| 82 | std::string argument(values.at(0)); | 
|---|
| 83 | std::string::iterator Aiter = argument.begin(); | 
|---|
| 84 | std::string::iterator Biter = argument.begin(); | 
|---|
| 85 | for (; Aiter != argument.end(); ++Aiter) { | 
|---|
| 86 | if (*Aiter == ',') { | 
|---|
| 87 | components.push_back(string(Biter,Aiter)); | 
|---|
| 88 | do { | 
|---|
| 89 | Aiter++; | 
|---|
| 90 | } while (*Aiter == ' ' || *Aiter == '\t'); | 
|---|
| 91 | Biter = Aiter; | 
|---|
| 92 | } | 
|---|
| 93 | } | 
|---|
| 94 | components.push_back(string(Biter,argument.end())); | 
|---|
| 95 |  | 
|---|
| 96 | if (components.size() != 3) { | 
|---|
| 97 | cerr <<  "Specified vector does not have three components but " << components.size() << endl; | 
|---|
| 98 | throw boost::program_options::validation_error("Specified vector does not have three components"); | 
|---|
| 99 | } | 
|---|
| 100 | VV.x = boost::lexical_cast<double>(components.at(0)); | 
|---|
| 101 | VV.y = boost::lexical_cast<double>(components.at(1)); | 
|---|
| 102 | VV.z = boost::lexical_cast<double>(components.at(2)); | 
|---|
| 103 | v = boost::any(VectorValue(VV)); | 
|---|
| 104 | } | 
|---|
| 105 |  | 
|---|
| 106 | void validate(boost::any& v, const std::vector<std::string>& values, BoxValue *, int) | 
|---|
| 107 | { | 
|---|
| 108 | BoxValue BV; | 
|---|
| 109 | std::vector<std::string> components; | 
|---|
| 110 |  | 
|---|
| 111 | // split comma-separated values | 
|---|
| 112 | if (values.size() != 1) { | 
|---|
| 113 | cerr <<  "Not one vector but " << components.size() << " given " << endl; | 
|---|
| 114 | throw boost::program_options::validation_error("Unequal to one vector given"); | 
|---|
| 115 | } | 
|---|
| 116 | std::string argument(values.at(0)); | 
|---|
| 117 | std::string::iterator Aiter = argument.begin(); | 
|---|
| 118 | std::string::iterator Biter = argument.begin(); | 
|---|
| 119 | for (; Aiter != argument.end(); ++Aiter) { | 
|---|
| 120 | if (*Aiter == ',') { | 
|---|
| 121 | components.push_back(string(Biter,Aiter)); | 
|---|
| 122 | do { | 
|---|
| 123 | Aiter++; | 
|---|
| 124 | } while (*Aiter == ' ' || *Aiter == '\t'); | 
|---|
| 125 | Biter = Aiter; | 
|---|
| 126 | } | 
|---|
| 127 | } | 
|---|
| 128 | components.push_back(string(Biter,argument.end())); | 
|---|
| 129 |  | 
|---|
| 130 | if (components.size() != 6) { | 
|---|
| 131 | cerr <<  "Specified vector does not have three components but " << components.size() << endl; | 
|---|
| 132 | throw boost::program_options::validation_error("Specified symmetric box matrix does not have six components"); | 
|---|
| 133 | } | 
|---|
| 134 | BV.xx = boost::lexical_cast<double>(components.at(0)); | 
|---|
| 135 | BV.xy = boost::lexical_cast<double>(components.at(1)); | 
|---|
| 136 | BV.xz = boost::lexical_cast<double>(components.at(2)); | 
|---|
| 137 | BV.yy = boost::lexical_cast<double>(components.at(3)); | 
|---|
| 138 | BV.yz = boost::lexical_cast<double>(components.at(4)); | 
|---|
| 139 | BV.zz = boost::lexical_cast<double>(components.at(5)); | 
|---|
| 140 | v = boost::any(BoxValue(BV)); | 
|---|
| 141 | } | 
|---|
| 142 |  | 
|---|
| 143 | /** Constructor of class MapOfActions. | 
|---|
| 144 | * | 
|---|
| 145 | */ | 
|---|
| 146 | MapOfActions::MapOfActions() | 
|---|
| 147 | { | 
|---|
| 148 | // initialise lookup map | 
|---|
| 149 | CmdParserLookup[&generic] = &(CommandLineParser::getInstance().generic); | 
|---|
| 150 | CmdParserLookup[&config] = &(CommandLineParser::getInstance().config); | 
|---|
| 151 | CmdParserLookup[&hidden] = &(CommandLineParser::getInstance().hidden); | 
|---|
| 152 | CmdParserLookup[&visible] = &(CommandLineParser::getInstance().visible); | 
|---|
| 153 |  | 
|---|
| 154 | // keys for actions | 
|---|
| 155 | DescriptionMap["add-atom"] = "add atom of specified element"; | 
|---|
| 156 | DescriptionMap["bond-table"] = "setting name of the bond length table file"; | 
|---|
| 157 | DescriptionMap["bond-file"] = "name of the bond file"; | 
|---|
| 158 | DescriptionMap["boundary"] = "change box to add an empty boundary around all atoms"; | 
|---|
| 159 | DescriptionMap["bound-in-box"] = "bound all atoms in the domain"; | 
|---|
| 160 | DescriptionMap["center-edge"] = "center edge of all atoms on (0,0,0)"; | 
|---|
| 161 | DescriptionMap["center-in-box"] = "center all atoms in the domain"; | 
|---|
| 162 | DescriptionMap["change-box"] = "change the symmetrc matrix of the simulation domain"; | 
|---|
| 163 | DescriptionMap["change-element"] = "change the element of an atom"; | 
|---|
| 164 | DescriptionMap["change-molname"] = "change the name of a molecule"; | 
|---|
| 165 | DescriptionMap["convex-envelope"] = "create the convex envelope for a molecule"; | 
|---|
| 166 | DescriptionMap["default-molname"] = "set the default name of new molecules"; | 
|---|
| 167 | DescriptionMap["depth-first-search"] = "Depth-First Search analysis of the molecular system"; | 
|---|
| 168 | DescriptionMap["element-db"] = "setting the path where the element databases can be found"; | 
|---|
| 169 | DescriptionMap["fastparsing"] = "setting whether trajectories shall be parsed completely (n) or just first step (y)"; | 
|---|
| 170 | DescriptionMap["fill-molecule"] = "fill empty space of box with a filler molecule"; | 
|---|
| 171 | DescriptionMap["fragment-mol"] = "create for a given molecule into fragments up to given order"; | 
|---|
| 172 | DescriptionMap["help"] = "Give this help screen"; | 
|---|
| 173 | DescriptionMap["input"] = "specify input files"; | 
|---|
| 174 | DescriptionMap["linear-interpolate"] = "linear interpolation in discrete steps between start and end position of a molecule"; | 
|---|
| 175 | DescriptionMap["molecular-volume"] = "calculate the volume of a given molecule"; | 
|---|
| 176 | DescriptionMap["nonconvex-envelope"] = "create the non-convex envelope for a molecule"; | 
|---|
| 177 | DescriptionMap["output"] = "write output files"; | 
|---|
| 178 | DescriptionMap["set-output"] = "specify output formats"; | 
|---|
| 179 | DescriptionMap["pair-correlation"] = "pair correlation analysis between two elements, element and point or element and surface"; | 
|---|
| 180 | DescriptionMap["parse-xyz"] = "parse xyz file into World"; | 
|---|
| 181 | DescriptionMap["principal-axis-system"] = "calculate the principal axis system of the specified molecule"; | 
|---|
| 182 | DescriptionMap["remove-atom"] = "remove a specified atom"; | 
|---|
| 183 | DescriptionMap["remove-sphere"] = "remove sphere of atoms of around a specified atom"; | 
|---|
| 184 | DescriptionMap["repeat-box"] = "create periodic copies of the simulation box per axis"; | 
|---|
| 185 | DescriptionMap["rotate-to-pas"] = "calculate the principal axis system of the specified molecule and rotate specified axis to align with main axis"; | 
|---|
| 186 | DescriptionMap["save-adjacency"] = "name of the adjacency file to write to"; | 
|---|
| 187 | DescriptionMap["save-bonds"] = "name of the bonds file to write to"; | 
|---|
| 188 | DescriptionMap["save-temperature"] = "name of the temperature file to write to"; | 
|---|
| 189 | DescriptionMap["SaveXyz"] = "save world as xyz file"; | 
|---|
| 190 | DescriptionMap["scale-box"] = "scale box and atomic positions inside"; | 
|---|
| 191 | DescriptionMap["set-basis"] = "set the name of the gaussian basis set for MPQC"; | 
|---|
| 192 | DescriptionMap["set-output"] = "specify output formats"; | 
|---|
| 193 | DescriptionMap["subgraph-dissect"] = "dissect the molecular system into molecules representing disconnected subgraphs"; | 
|---|
| 194 | DescriptionMap["suspend-in-water"] = "suspend the given molecule in water such that in the domain the mean density is as specified"; | 
|---|
| 195 | DescriptionMap["translate-mol"] = "translate molecule by given vector"; | 
|---|
| 196 | DescriptionMap["verbose"] = "set verbosity level"; | 
|---|
| 197 | DescriptionMap["verlet-integrate"] = "perform verlet integration of a given force file"; | 
|---|
| 198 | DescriptionMap["version"] = "show version"; | 
|---|
| 199 | // keys for values | 
|---|
| 200 | DescriptionMap["atom-by-id"] = "index of an atom"; | 
|---|
| 201 | DescriptionMap["bin-output-file"] = "name of the bin output file"; | 
|---|
| 202 | DescriptionMap["bin-end"] = "start of the last bin"; | 
|---|
| 203 | DescriptionMap["bin-start"] = "start of the first bin"; | 
|---|
| 204 | DescriptionMap["bin-width"] = "width of the bins"; | 
|---|
| 205 | DescriptionMap["convex-file"] = "filename of the non-convex envelope"; | 
|---|
| 206 | DescriptionMap["distance"] = "distance in space"; | 
|---|
| 207 | DescriptionMap["distances"] = "list of three of distances in space, one for each axis direction"; | 
|---|
| 208 | DescriptionMap["DoRotate"] = "whether to rotate or just report angles"; | 
|---|
| 209 | DescriptionMap["element"] = "single element"; | 
|---|
| 210 | DescriptionMap["elements"] = "set of elements"; | 
|---|
| 211 | DescriptionMap["end-step"] = "last or end step"; | 
|---|
| 212 | DescriptionMap["id-mapping"] = "whether the identity shall be used in mapping atoms onto atoms or some closest distance measure shall be used"; | 
|---|
| 213 | DescriptionMap["input"] = "name of input file"; | 
|---|
| 214 | DescriptionMap["length"] = "length in space"; | 
|---|
| 215 | DescriptionMap["lengths"] = "list of three of lengths in space, one for each axis direction"; | 
|---|
| 216 | DescriptionMap["MaxDistance"] = "maximum distance in space"; | 
|---|
| 217 | DescriptionMap["molecule-by-id"] = "index of a molecule"; | 
|---|
| 218 | DescriptionMap["molecule-by-name"] = "name of a molecule"; | 
|---|
| 219 | DescriptionMap["nonconvex-file"] = "filename of the non-convex envelope"; | 
|---|
| 220 | DescriptionMap["order"] = "order of a discretization, dissection, ..."; | 
|---|
| 221 | DescriptionMap["output-file"] = "name of the output file"; | 
|---|
| 222 | DescriptionMap["periodic"] = "system is constraint to periodic boundary conditions (y/n)"; | 
|---|
| 223 | DescriptionMap["position"] = "position in R^3 space"; | 
|---|
| 224 | DescriptionMap["sphere-radius"] = "radius of tesselation sphere"; | 
|---|
| 225 | DescriptionMap["start-step"] = "first or start step"; | 
|---|
| 226 |  | 
|---|
| 227 | // short forms for the actions | 
|---|
| 228 | ShortFormMap["add-atom"] = "a"; | 
|---|
| 229 | ShortFormMap["bond-table"] = "g"; | 
|---|
| 230 | ShortFormMap["bond-file"] = "A"; | 
|---|
| 231 | ShortFormMap["boundary"] = "c"; | 
|---|
| 232 | ShortFormMap["change-box"] = "B"; | 
|---|
| 233 | ShortFormMap["center-edge"] = "O"; | 
|---|
| 234 | ShortFormMap["center-in-box"] = "b"; | 
|---|
| 235 | ShortFormMap["change-element"] = "E"; | 
|---|
| 236 | //  ShortFormMap["convex-envelope"] = "x"; | 
|---|
| 237 | ShortFormMap["default-molname"] = "X"; | 
|---|
| 238 | ShortFormMap["depth-first-search"] = "D"; | 
|---|
| 239 | ShortFormMap["element-db"] = "e"; | 
|---|
| 240 | ShortFormMap["fastparsing"] = "n"; | 
|---|
| 241 | ShortFormMap["fill-molecule"] = "F"; | 
|---|
| 242 | ShortFormMap["fragment-mol"] = "f"; | 
|---|
| 243 | ShortFormMap["help"] = "h"; | 
|---|
| 244 | ShortFormMap["input"] = "i"; | 
|---|
| 245 | ShortFormMap["linear-interpolate"] = "L"; | 
|---|
| 246 | ShortFormMap["nonconvex-envelope"] = "N"; | 
|---|
| 247 | //  ShortFormMap["output"] = "o"; | 
|---|
| 248 | ShortFormMap["pair-correlation"] = "C"; | 
|---|
| 249 | ShortFormMap["parse-xyz"] = "p"; | 
|---|
| 250 | ShortFormMap["remove-atom"] = "r"; | 
|---|
| 251 | ShortFormMap["remove-sphere"] = "R"; | 
|---|
| 252 | ShortFormMap["repeat-box"] = "d"; | 
|---|
| 253 | ShortFormMap["rotate-to-pas"] = "m"; | 
|---|
| 254 | ShortFormMap["save-adjacency"] = "J"; | 
|---|
| 255 | ShortFormMap["save-bonds"] = "j"; | 
|---|
| 256 | ShortFormMap["save-temperature"] = "S"; | 
|---|
| 257 | ShortFormMap["scale-box"] = "s"; | 
|---|
| 258 | ShortFormMap["set-basis"] = "M"; | 
|---|
| 259 | ShortFormMap["set-output"] = "o"; | 
|---|
| 260 | ShortFormMap["subgraph-dissect"] = "I"; | 
|---|
| 261 | ShortFormMap["suspend-in-water"] = "u"; | 
|---|
| 262 | ShortFormMap["translate-mol"] = "t"; | 
|---|
| 263 | ShortFormMap["verbose"] = "v"; | 
|---|
| 264 | ShortFormMap["verlet-integrate"] = "P"; | 
|---|
| 265 | ShortFormMap["version"] = "V"; | 
|---|
| 266 |  | 
|---|
| 267 | // value types for the actions | 
|---|
| 268 | TypeMap["add-atom"] = Element; | 
|---|
| 269 | TypeMap["bond-file"] = String; | 
|---|
| 270 | TypeMap["bond-table"] = String; | 
|---|
| 271 | TypeMap["boundary"] = Vector; | 
|---|
| 272 | TypeMap["center-in-box"] = Box; | 
|---|
| 273 | TypeMap["change-box"] = Box; | 
|---|
| 274 | TypeMap["change-element"] = Element; | 
|---|
| 275 | TypeMap["change-molname"] = String; | 
|---|
| 276 | TypeMap["convex-envelope"] = Molecule; | 
|---|
| 277 | TypeMap["default-molname"] = String; | 
|---|
| 278 | TypeMap["depth-first-search"] = Double; | 
|---|
| 279 | TypeMap["element-db"] = String; | 
|---|
| 280 | TypeMap["fastparsing"] = Boolean; | 
|---|
| 281 | TypeMap["fill-molecule"] = String; | 
|---|
| 282 | TypeMap["fragment-mol"] = String; | 
|---|
| 283 | TypeMap["input"] = String; | 
|---|
| 284 | TypeMap["linear-interpolate"] = String; | 
|---|
| 285 | TypeMap["molecular-volume"] = Molecule; | 
|---|
| 286 | TypeMap["nonconvex-envelope"] = Molecule; | 
|---|
| 287 | TypeMap["output"] = None; | 
|---|
| 288 | TypeMap["parse-xyz"] = String; | 
|---|
| 289 | TypeMap["pair-correlation"] = String; | 
|---|
| 290 | TypeMap["principal-axis-system"] = Molecule; | 
|---|
| 291 | TypeMap["remove-atom"] = Atom; | 
|---|
| 292 | TypeMap["remove-sphere"] = Double; | 
|---|
| 293 | TypeMap["repeat-box"] = Vector; | 
|---|
| 294 | TypeMap["rotate-to-pas"] = Molecule; | 
|---|
| 295 | TypeMap["save-adjacency"] = String; | 
|---|
| 296 | TypeMap["save-bonds"] = String; | 
|---|
| 297 | TypeMap["save-temperature"] = String; | 
|---|
| 298 | TypeMap["scale-box"] = Vector; | 
|---|
| 299 | TypeMap["set-basis"] = String; | 
|---|
| 300 | TypeMap["set-output"] = ListOfString; | 
|---|
| 301 | TypeMap["subgraph-dissect"] = None; | 
|---|
| 302 | TypeMap["suspend-in-water"] = Double; | 
|---|
| 303 | TypeMap["translate-mol"] = Vector; | 
|---|
| 304 | TypeMap["verlet-integrate"] = String; | 
|---|
| 305 | TypeMap["verbose"] = Integer; | 
|---|
| 306 |  | 
|---|
| 307 | // value types for the values | 
|---|
| 308 | TypeMap["atom-by-id"] = Atom; | 
|---|
| 309 | TypeMap["bin-output-file"] = String; | 
|---|
| 310 | TypeMap["bin-end"] = Double; | 
|---|
| 311 | TypeMap["bin-start"] = Double; | 
|---|
| 312 | TypeMap["bin-width"] = Double; | 
|---|
| 313 | TypeMap["convex-file"] = String; | 
|---|
| 314 | TypeMap["distance"] = Double; | 
|---|
| 315 | TypeMap["distances"] = Vector; | 
|---|
| 316 | TypeMap["DoRotate"] = Boolean; | 
|---|
| 317 | TypeMap["element"] = Element; | 
|---|
| 318 | TypeMap["elements"] = ListOfElements; | 
|---|
| 319 | TypeMap["end-step"] = Integer; | 
|---|
| 320 | TypeMap["id-mapping"] = Boolean; | 
|---|
| 321 | TypeMap["length"] = Double; | 
|---|
| 322 | TypeMap["lengths"] = Vector; | 
|---|
| 323 | TypeMap["MaxDistance"] = Double; | 
|---|
| 324 | TypeMap["molecule-by-id"] = Molecule; | 
|---|
| 325 | TypeMap["molecule-by-name"] = String; | 
|---|
| 326 | TypeMap["nonconvex-file"] = String; | 
|---|
| 327 | TypeMap["order"] = Integer; | 
|---|
| 328 | TypeMap["output-file"] = String; | 
|---|
| 329 | TypeMap["periodic"] = Boolean; | 
|---|
| 330 | TypeMap["position"] = Vector; | 
|---|
| 331 | TypeMap["sphere-radius"] = Double; | 
|---|
| 332 | TypeMap["start-step"] = Integer; | 
|---|
| 333 |  | 
|---|
| 334 | // default values for any action that needs one (always string!) | 
|---|
| 335 | DefaultValue["bin-width"] = "0.5"; | 
|---|
| 336 | DefaultValue["fastparsing"] = "0"; | 
|---|
| 337 | DefaultValue["atom-by-id"] = "-1"; | 
|---|
| 338 | DefaultValue["molecule-by-id"] = "-1"; | 
|---|
| 339 | DefaultValue["periodic"] = "0"; | 
|---|
| 340 |  | 
|---|
| 341 | // put action into each menu category | 
|---|
| 342 | MenuDescription["analysis"] = pair<std::string,std::string>("Analysis (pair correlation, volume)", "Analysis"); | 
|---|
| 343 | MenuDescription["atom"] = pair<std::string,std::string>("Edit atoms", "Edit atoms"); | 
|---|
| 344 | MenuDescription["command"] = pair<std::string,std::string>("Configuration", "Configuration"); | 
|---|
| 345 | MenuDescription["fragmentation"] = pair<std::string,std::string>("Fragmentation", "Fragmentation"); | 
|---|
| 346 | MenuDescription["molecule"] = pair<std::string,std::string>("Parse files into system", "Parse files"); | 
|---|
| 347 | MenuDescription["parser"] = pair<std::string,std::string>("Edit molecules (load, parse, save)", "Edit molecules"); | 
|---|
| 348 | MenuDescription["tesselation"] = pair<std::string,std::string>("Tesselate molecules", "Tesselate molecules"); | 
|---|
| 349 | MenuDescription["world"] = pair<std::string,std::string>("Edit world", "Edit world"); | 
|---|
| 350 |  | 
|---|
| 351 | MenuContainsActionMap.insert( pair<std::string, std::string> ("analysis", "molecular-volume") ); | 
|---|
| 352 | MenuContainsActionMap.insert( pair<std::string, std::string> ("analysis", "pair-correlation") ); | 
|---|
| 353 | MenuContainsActionMap.insert( pair<std::string, std::string> ("analysis", "principal-axis-system") ); | 
|---|
| 354 |  | 
|---|
| 355 | MenuContainsActionMap.insert( pair<std::string, std::string> ("atom", "add-atom") ); | 
|---|
| 356 | MenuContainsActionMap.insert( pair<std::string, std::string> ("atom", "change-element") ); | 
|---|
| 357 | MenuContainsActionMap.insert( pair<std::string, std::string> ("atom", "remove-atom") ); | 
|---|
| 358 |  | 
|---|
| 359 | MenuContainsActionMap.insert( pair<std::string, std::string> ("command", "bond-table") ); | 
|---|
| 360 | MenuContainsActionMap.insert( pair<std::string, std::string> ("command", "element-db") ); | 
|---|
| 361 | MenuContainsActionMap.insert( pair<std::string, std::string> ("command", "fastparsing") ); | 
|---|
| 362 | MenuContainsActionMap.insert( pair<std::string, std::string> ("command", "verbose") ); | 
|---|
| 363 | MenuContainsActionMap.insert( pair<std::string, std::string> ("command", "version") ); | 
|---|
| 364 |  | 
|---|
| 365 | MenuContainsActionMap.insert( pair<std::string, std::string> ("fragmentation", "depth-first-search") ); | 
|---|
| 366 | MenuContainsActionMap.insert( pair<std::string, std::string> ("fragmentation", "fragment-mol") ); | 
|---|
| 367 | MenuContainsActionMap.insert( pair<std::string, std::string> ("fragmentation", "subgraph-dissect") ); | 
|---|
| 368 |  | 
|---|
| 369 | MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "bond-file") ); | 
|---|
| 370 | MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "change-molname") ); | 
|---|
| 371 | MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "fill-molecule") ); | 
|---|
| 372 | MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "linear-interpolate") ); | 
|---|
| 373 | MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "rotate-to-pas") ); | 
|---|
| 374 | MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "save-adjacency") ); | 
|---|
| 375 | MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "save-bonds") ); | 
|---|
| 376 | MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "save-temperature") ); | 
|---|
| 377 | MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "suspend-in-water") ); | 
|---|
| 378 | MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "translate-mol") ); | 
|---|
| 379 | MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "verlet-integrate") ); | 
|---|
| 380 |  | 
|---|
| 381 | MenuContainsActionMap.insert( pair<std::string, std::string> ("parser", "parse-xyz") ); | 
|---|
| 382 | MenuContainsActionMap.insert( pair<std::string, std::string> ("parser", "SaveXyz") ); | 
|---|
| 383 |  | 
|---|
| 384 | MenuContainsActionMap.insert( pair<std::string, std::string> ("tesselation", "convex-envelope") ); | 
|---|
| 385 | MenuContainsActionMap.insert( pair<std::string, std::string> ("tesselation", "nonconvex-envelope") ); | 
|---|
| 386 |  | 
|---|
| 387 | MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "boundary") ); | 
|---|
| 388 | MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "bound-in-box") ); | 
|---|
| 389 | MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "center-in-box") ); | 
|---|
| 390 | MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "center-edge") ); | 
|---|
| 391 | MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "change-box") ); | 
|---|
| 392 | MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "input") ); | 
|---|
| 393 | MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "output") ); | 
|---|
| 394 | MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "remove-sphere") ); | 
|---|
| 395 | MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "repeat-box") ); | 
|---|
| 396 | MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "scale-box") ); | 
|---|
| 397 | MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "default-molname") ); | 
|---|
| 398 | MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "set-basis") ); | 
|---|
| 399 | MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "set-output") ); | 
|---|
| 400 |  | 
|---|
| 401 | // put actions into command line category | 
|---|
| 402 | generic.insert("add-atom"); | 
|---|
| 403 | generic.insert("bond-file"); | 
|---|
| 404 | generic.insert("bond-table"); | 
|---|
| 405 | generic.insert("boundary"); | 
|---|
| 406 | //  generic.insert("bound-in-box"); | 
|---|
| 407 | generic.insert("center-edge"); | 
|---|
| 408 | generic.insert("center-in-box"); | 
|---|
| 409 | generic.insert("change-box"); | 
|---|
| 410 | //  generic.insert("change-molname"); | 
|---|
| 411 | generic.insert("change-element"); | 
|---|
| 412 | generic.insert("convex-envelope"); | 
|---|
| 413 | generic.insert("default-molname"); | 
|---|
| 414 | generic.insert("depth-first-search"); | 
|---|
| 415 | generic.insert("element-db"); | 
|---|
| 416 | generic.insert("fastparsing"); | 
|---|
| 417 | generic.insert("fill-molecule"); | 
|---|
| 418 | generic.insert("fragment-mol"); | 
|---|
| 419 | generic.insert("help"); | 
|---|
| 420 | generic.insert("input"); | 
|---|
| 421 | generic.insert("linear-interpolate"); | 
|---|
| 422 | //  generic.insert("molecular-volume"); | 
|---|
| 423 | generic.insert("nonconvex-envelope"); | 
|---|
| 424 | generic.insert("output"); | 
|---|
| 425 | generic.insert("pair-correlation"); | 
|---|
| 426 | generic.insert("parse-xyz"); | 
|---|
| 427 | //  generic.insert("principal-axis-system"); | 
|---|
| 428 | generic.insert("remove-atom"); | 
|---|
| 429 | generic.insert("remove-sphere"); | 
|---|
| 430 | generic.insert("repeat-box"); | 
|---|
| 431 | generic.insert("rotate-to-pas"); | 
|---|
| 432 | generic.insert("save-adjacency"); | 
|---|
| 433 | generic.insert("save-bonds"); | 
|---|
| 434 | generic.insert("save-temperature"); | 
|---|
| 435 | generic.insert("scale-box"); | 
|---|
| 436 | generic.insert("set-basis"); | 
|---|
| 437 | generic.insert("set-output"); | 
|---|
| 438 | generic.insert("subgraph-dissect"); | 
|---|
| 439 | generic.insert("suspend-in-water"); | 
|---|
| 440 | generic.insert("translate-mol"); | 
|---|
| 441 | generic.insert("verbose"); | 
|---|
| 442 | generic.insert("verlet-integrate"); | 
|---|
| 443 | generic.insert("version"); | 
|---|
| 444 |  | 
|---|
| 445 | // positional arguments | 
|---|
| 446 | generic.insert("input"); | 
|---|
| 447 | inputfile.insert("input"); | 
|---|
| 448 |  | 
|---|
| 449 | // hidden arguments | 
|---|
| 450 | generic.insert("atom-by-id"); | 
|---|
| 451 | generic.insert("bin-end"); | 
|---|
| 452 | generic.insert("bin-output-file"); | 
|---|
| 453 | generic.insert("bin-start"); | 
|---|
| 454 | generic.insert("bin-width"); | 
|---|
| 455 | generic.insert("convex-file"); | 
|---|
| 456 | generic.insert("distance"); | 
|---|
| 457 | generic.insert("DoRotate"); | 
|---|
| 458 | generic.insert("distances"); | 
|---|
| 459 | generic.insert("element"); | 
|---|
| 460 | generic.insert("elements"); | 
|---|
| 461 | generic.insert("end-step"); | 
|---|
| 462 | generic.insert("id-mapping"); | 
|---|
| 463 | generic.insert("lengths"); | 
|---|
| 464 | generic.insert("MaxDistance"); | 
|---|
| 465 | generic.insert("molecule-by-id"); | 
|---|
| 466 | generic.insert("molecule-by-name"); | 
|---|
| 467 | generic.insert("nonconvex-file"); | 
|---|
| 468 | generic.insert("order"); | 
|---|
| 469 | generic.insert("output-file"); | 
|---|
| 470 | generic.insert("periodic"); | 
|---|
| 471 | generic.insert("position"); | 
|---|
| 472 | generic.insert("sphere-radius"); | 
|---|
| 473 | generic.insert("start-step"); | 
|---|
| 474 | } | 
|---|
| 475 |  | 
|---|
| 476 | /** Destructor of class MapOfActions. | 
|---|
| 477 | * | 
|---|
| 478 | */ | 
|---|
| 479 | MapOfActions::~MapOfActions() | 
|---|
| 480 | { | 
|---|
| 481 | DescriptionMap.clear(); | 
|---|
| 482 | } | 
|---|
| 483 |  | 
|---|
| 484 |  | 
|---|
| 485 | void MapOfActions::populateActions() | 
|---|
| 486 | { | 
|---|
| 487 | new AnalysisMolecularVolumeAction(); | 
|---|
| 488 | new AnalysisPairCorrelationAction(); | 
|---|
| 489 | new AnalysisPrincipalAxisSystemAction(); | 
|---|
| 490 |  | 
|---|
| 491 | new AtomAddAction(); | 
|---|
| 492 | new AtomChangeElementAction(); | 
|---|
| 493 | new AtomRemoveAction(); | 
|---|
| 494 |  | 
|---|
| 495 | new CommandLineBondLengthTableAction(); | 
|---|
| 496 | new CommandLineElementDbAction(); | 
|---|
| 497 | new CommandLineFastParsingAction(); | 
|---|
| 498 | new CommandLineHelpAction(); | 
|---|
| 499 | new CommandLineVerboseAction(); | 
|---|
| 500 | new CommandLineVersionAction(); | 
|---|
| 501 |  | 
|---|
| 502 | new FragmentationDepthFirstSearchAction(); | 
|---|
| 503 | new FragmentationFragmentationAction(); | 
|---|
| 504 | new FragmentationSubgraphDissectionAction(); | 
|---|
| 505 |  | 
|---|
| 506 | new MoleculeBondFileAction(); | 
|---|
| 507 | new MoleculeChangeNameAction(); | 
|---|
| 508 | new MoleculeFillWithMoleculeAction(); | 
|---|
| 509 | new MoleculeLinearInterpolationofTrajectoriesAction(); | 
|---|
| 510 | new MoleculeRotateToPrincipalAxisSystemAction(); | 
|---|
| 511 | new MoleculeSaveAdjacencyAction(); | 
|---|
| 512 | new MoleculeSaveBondsAction(); | 
|---|
| 513 | new MoleculeSaveTemperatureAction(); | 
|---|
| 514 | new MoleculeSuspendInWaterAction(); | 
|---|
| 515 | new MoleculeTranslateAction(); | 
|---|
| 516 | new MoleculeVerletIntegrationAction(); | 
|---|
| 517 |  | 
|---|
| 518 | new ParserLoadXyzAction(); | 
|---|
| 519 | new ParserSaveXyzAction(); | 
|---|
| 520 |  | 
|---|
| 521 | new TesselationConvexEnvelopeAction(); | 
|---|
| 522 | new TesselationNonConvexEnvelopeAction(); | 
|---|
| 523 |  | 
|---|
| 524 | new WorldAddEmptyBoundaryAction(); | 
|---|
| 525 | new WorldBoundInBoxAction(); | 
|---|
| 526 | new WorldCenterInBoxAction(); | 
|---|
| 527 | new WorldCenterOnEdgeAction(); | 
|---|
| 528 | new WorldChangeBoxAction(); | 
|---|
| 529 | new WorldInputAction(); | 
|---|
| 530 | new WorldOutputAction(); | 
|---|
| 531 | new WorldRemoveSphereOfAtomsAction(); | 
|---|
| 532 | new WorldRepeatBoxAction(); | 
|---|
| 533 | new WorldScaleBoxAction(); | 
|---|
| 534 | new WorldSetDefaultNameAction(); | 
|---|
| 535 | new WorldSetGaussianBasisAction(); | 
|---|
| 536 | new WorldSetOutputFormatsAction(); | 
|---|
| 537 | } | 
|---|
| 538 |  | 
|---|
| 539 |  | 
|---|
| 540 | /** Adds all options to the CommandLineParser. | 
|---|
| 541 | * | 
|---|
| 542 | */ | 
|---|
| 543 | void MapOfActions::AddOptionsToParser() | 
|---|
| 544 | { | 
|---|
| 545 | // add other options | 
|---|
| 546 | for (map< set<string>*, po::options_description* >::iterator ListRunner = CmdParserLookup.begin(); ListRunner != CmdParserLookup.end(); ++ListRunner) { | 
|---|
| 547 | for (set<string>::iterator OptionRunner = ListRunner->first->begin(); OptionRunner != ListRunner->first->end(); ++OptionRunner) { | 
|---|
| 548 | if (hasValue(*OptionRunner)) { | 
|---|
| 549 | DoLog(0) && (Log() << Verbose(0) << "Adding option " << *OptionRunner << " with type " << TypeMap[*OptionRunner] << " to CommandLineParser." << endl); | 
|---|
| 550 | switch((enum OptionTypes) TypeMap[*OptionRunner]) { | 
|---|
| 551 | default: | 
|---|
| 552 | case None: | 
|---|
| 553 | ListRunner->second->add_options() | 
|---|
| 554 | (getKeyAndShortForm(*OptionRunner).c_str(), getDescription(*OptionRunner).c_str()) | 
|---|
| 555 | ; | 
|---|
| 556 | break; | 
|---|
| 557 | case Boolean: | 
|---|
| 558 | ListRunner->second->add_options() | 
|---|
| 559 | (getKeyAndShortForm(*OptionRunner).c_str(), | 
|---|
| 560 | DefaultValue.find(*OptionRunner) != DefaultValue.end() ? | 
|---|
| 561 | po::value< bool >()->default_value(atoi(DefaultValue[*OptionRunner].c_str())) : | 
|---|
| 562 | po::value< bool >(), | 
|---|
| 563 | getDescription(*OptionRunner).c_str()) | 
|---|
| 564 | ; | 
|---|
| 565 | break; | 
|---|
| 566 | case Box: | 
|---|
| 567 | ListRunner->second->add_options() | 
|---|
| 568 | (getKeyAndShortForm(*OptionRunner).c_str(), | 
|---|
| 569 | po::value<BoxValue>()->multitoken(), | 
|---|
| 570 | getDescription(*OptionRunner).c_str()) | 
|---|
| 571 | ; | 
|---|
| 572 | break; | 
|---|
| 573 | case Integer: | 
|---|
| 574 | ListRunner->second->add_options() | 
|---|
| 575 | (getKeyAndShortForm(*OptionRunner).c_str(), | 
|---|
| 576 | DefaultValue.find(*OptionRunner) != DefaultValue.end() ? | 
|---|
| 577 | po::value< int >()->default_value(atoi(DefaultValue[*OptionRunner].c_str())) : | 
|---|
| 578 | po::value< int >(), | 
|---|
| 579 | getDescription(*OptionRunner).c_str()) | 
|---|
| 580 | ; | 
|---|
| 581 | break; | 
|---|
| 582 | case ListOfInts: | 
|---|
| 583 | ListRunner->second->add_options() | 
|---|
| 584 | (getKeyAndShortForm(*OptionRunner).c_str(), | 
|---|
| 585 | po::value< vector<int> >()->multitoken(), | 
|---|
| 586 | getDescription(*OptionRunner).c_str()) | 
|---|
| 587 | ; | 
|---|
| 588 | break; | 
|---|
| 589 | case Double: | 
|---|
| 590 | ListRunner->second->add_options() | 
|---|
| 591 | (getKeyAndShortForm(*OptionRunner).c_str(), | 
|---|
| 592 | DefaultValue.find(*OptionRunner) != DefaultValue.end() ? | 
|---|
| 593 | po::value< double >()->default_value(atof(DefaultValue[*OptionRunner].c_str())) : | 
|---|
| 594 | po::value< double >(), | 
|---|
| 595 | getDescription(*OptionRunner).c_str()) | 
|---|
| 596 | ; | 
|---|
| 597 | break; | 
|---|
| 598 | case ListOfDoubles: | 
|---|
| 599 | ListRunner->second->add_options() | 
|---|
| 600 | (getKeyAndShortForm(*OptionRunner).c_str(), | 
|---|
| 601 | po::value< vector<double> >()->multitoken(), | 
|---|
| 602 | getDescription(*OptionRunner).c_str()) | 
|---|
| 603 | ; | 
|---|
| 604 | break; | 
|---|
| 605 | case String: | 
|---|
| 606 | ListRunner->second->add_options() | 
|---|
| 607 | (getKeyAndShortForm(*OptionRunner).c_str(), | 
|---|
| 608 | DefaultValue.find(*OptionRunner) != DefaultValue.end() ? | 
|---|
| 609 | po::value< std::string >()->default_value(DefaultValue[*OptionRunner]) : | 
|---|
| 610 | po::value< std::string >(), | 
|---|
| 611 | getDescription(*OptionRunner).c_str()) | 
|---|
| 612 | ; | 
|---|
| 613 | break; | 
|---|
| 614 | case ListOfString: | 
|---|
| 615 | ListRunner->second->add_options() | 
|---|
| 616 | (getKeyAndShortForm(*OptionRunner).c_str(), | 
|---|
| 617 | po::value< vector<std::string> >()->multitoken(), | 
|---|
| 618 | getDescription(*OptionRunner).c_str()) | 
|---|
| 619 | ; | 
|---|
| 620 | break; | 
|---|
| 621 | case Axis: | 
|---|
| 622 | ListRunner->second->add_options() | 
|---|
| 623 | (getKeyAndShortForm(*OptionRunner).c_str(), | 
|---|
| 624 | DefaultValue.find(*OptionRunner) != DefaultValue.end() ? | 
|---|
| 625 | po::value< int >()->default_value(atoi(DefaultValue[*OptionRunner].c_str())) : | 
|---|
| 626 | po::value< int >(), | 
|---|
| 627 | getDescription(*OptionRunner).c_str()) | 
|---|
| 628 | ; | 
|---|
| 629 | break; | 
|---|
| 630 | case Vector: | 
|---|
| 631 | ListRunner->second->add_options() | 
|---|
| 632 | (getKeyAndShortForm(*OptionRunner).c_str(), | 
|---|
| 633 | po::value<VectorValue>(), | 
|---|
| 634 | getDescription(*OptionRunner).c_str()) | 
|---|
| 635 | ; | 
|---|
| 636 | break; | 
|---|
| 637 | case Molecule: | 
|---|
| 638 | ListRunner->second->add_options() | 
|---|
| 639 | (getKeyAndShortForm(*OptionRunner).c_str(), | 
|---|
| 640 | DefaultValue.find(*OptionRunner) != DefaultValue.end() ? | 
|---|
| 641 | po::value< int >()->default_value(atoi(DefaultValue[*OptionRunner].c_str())) : | 
|---|
| 642 | po::value< int >(), | 
|---|
| 643 | getDescription(*OptionRunner).c_str()) | 
|---|
| 644 | ; | 
|---|
| 645 | break; | 
|---|
| 646 | case ListOfMolecules: | 
|---|
| 647 | ListRunner->second->add_options() | 
|---|
| 648 | (getKeyAndShortForm(*OptionRunner).c_str(), | 
|---|
| 649 | po::value< vector<int> >()->multitoken(), | 
|---|
| 650 | getDescription(*OptionRunner).c_str()) | 
|---|
| 651 | ; | 
|---|
| 652 | break; | 
|---|
| 653 | case Atom: | 
|---|
| 654 | ListRunner->second->add_options() | 
|---|
| 655 | (getKeyAndShortForm(*OptionRunner).c_str(), | 
|---|
| 656 | DefaultValue.find(*OptionRunner) != DefaultValue.end() ? | 
|---|
| 657 | po::value< int >()->default_value(atoi(DefaultValue[*OptionRunner].c_str())) : | 
|---|
| 658 | po::value< int >(), | 
|---|
| 659 | getDescription(*OptionRunner).c_str()) | 
|---|
| 660 | ; | 
|---|
| 661 | break; | 
|---|
| 662 | case ListOfAtoms: | 
|---|
| 663 | ListRunner->second->add_options() | 
|---|
| 664 | (getKeyAndShortForm(*OptionRunner).c_str(), | 
|---|
| 665 | po::value< vector<int> >()->multitoken(), | 
|---|
| 666 | getDescription(*OptionRunner).c_str()) | 
|---|
| 667 | ; | 
|---|
| 668 | break; | 
|---|
| 669 | case Element: | 
|---|
| 670 | ListRunner->second->add_options() | 
|---|
| 671 | (getKeyAndShortForm(*OptionRunner).c_str(), | 
|---|
| 672 | po::value< vector<int> >(), | 
|---|
| 673 | getDescription(*OptionRunner).c_str()) | 
|---|
| 674 | ; | 
|---|
| 675 | break; | 
|---|
| 676 | case ListOfElements: | 
|---|
| 677 | ListRunner->second->add_options() | 
|---|
| 678 | (getKeyAndShortForm(*OptionRunner).c_str(), | 
|---|
| 679 | po::value< vector<int> >()->multitoken(), | 
|---|
| 680 | getDescription(*OptionRunner).c_str()) | 
|---|
| 681 | ; | 
|---|
| 682 | break; | 
|---|
| 683 | } | 
|---|
| 684 | } else { | 
|---|
| 685 | DoLog(0) && (Log() << Verbose(0) << "Adding option " << *OptionRunner << " to CommandLineParser." << endl); | 
|---|
| 686 | ListRunner->second->add_options() | 
|---|
| 687 | (getKeyAndShortForm(*OptionRunner).c_str(), getDescription(*OptionRunner).c_str()) | 
|---|
| 688 | ; | 
|---|
| 689 | } | 
|---|
| 690 | } | 
|---|
| 691 | } | 
|---|
| 692 | // add positional arguments | 
|---|
| 693 | for (set<string>::iterator OptionRunner = inputfile.begin(); OptionRunner != inputfile.end(); ++OptionRunner) { | 
|---|
| 694 | DoLog(0) && (Log() << Verbose(0) << "Adding option " << *OptionRunner << " to positional CommandLineParser." << endl); | 
|---|
| 695 | CommandLineParser::getInstance().inputfile.add((*OptionRunner).c_str(), -1); | 
|---|
| 696 | } | 
|---|
| 697 | cout << "Name for position 1: " << CommandLineParser::getInstance().inputfile.name_for_position(1) << endl; | 
|---|
| 698 | } | 
|---|
| 699 |  | 
|---|
| 700 | /** Getter for MapOfActions:DescriptionMap. | 
|---|
| 701 | * Note that we assert when action does not exist in CommandLineParser::DescriptionMap. | 
|---|
| 702 | * \param actionname name of the action to lookup | 
|---|
| 703 | * \return Description of the action | 
|---|
| 704 | */ | 
|---|
| 705 | std::string MapOfActions::getDescription(string actionname) | 
|---|
| 706 | { | 
|---|
| 707 | ASSERT(DescriptionMap.find(actionname) != DescriptionMap.end(), "Unknown action name passed to MapOfActions::getDescription"); | 
|---|
| 708 | return DescriptionMap[actionname]; | 
|---|
| 709 | } | 
|---|
| 710 |  | 
|---|
| 711 | /** Specific Getter for a MapOfActions:ShortFormMap. | 
|---|
| 712 | * If action has a short for, then combination is as "actionname,ShortForm" (this is | 
|---|
| 713 | * the desired format for boost::program_options). If no short form exists in the map, | 
|---|
| 714 | * just actionname will be returned | 
|---|
| 715 | * Note that we assert when action does not exist in CommandLineParser::DescriptionMap. | 
|---|
| 716 | * \param actionname name of the action to lookup | 
|---|
| 717 | * \return actionname,ShortForm or Description of the action | 
|---|
| 718 | */ | 
|---|
| 719 | std::string MapOfActions::getKeyAndShortForm(string actionname) | 
|---|
| 720 | { | 
|---|
| 721 | stringstream output; | 
|---|
| 722 | ASSERT(DescriptionMap.find(actionname) != DescriptionMap.end(), "Unknown action name passed to MapOfActions::getDescriptionAndShortForm"); | 
|---|
| 723 | output << actionname; | 
|---|
| 724 | if (ShortFormMap.find(actionname) != DescriptionMap.end()) | 
|---|
| 725 | output << "," << ShortFormMap[actionname]; | 
|---|
| 726 | return output.str(); | 
|---|
| 727 | } | 
|---|
| 728 |  | 
|---|
| 729 | /** Getter for MapOfActions:ShortFormMap. | 
|---|
| 730 | * Note that we assert when action does not exist CommandLineParser::ShortFormMap. | 
|---|
| 731 | * \param actionname name of the action to lookup | 
|---|
| 732 | * \return ShortForm of the action | 
|---|
| 733 | */ | 
|---|
| 734 | std::string MapOfActions::getShortForm(string actionname) | 
|---|
| 735 | { | 
|---|
| 736 | ASSERT(ShortFormMap.find(actionname) != ShortFormMap.end(), "Unknown action name passed to MapOfActions::getShortForm"); | 
|---|
| 737 | return ShortFormMap[actionname]; | 
|---|
| 738 | } | 
|---|
| 739 |  | 
|---|
| 740 | /** Returns whether the given action needs a value or not. | 
|---|
| 741 | * \param actionname name of the action to look up | 
|---|
| 742 | * \return true - value is needed, false - no value is stored in MapOfActions::TypeMap | 
|---|
| 743 | */ | 
|---|
| 744 | bool MapOfActions::hasValue(string actionname) | 
|---|
| 745 | { | 
|---|
| 746 | return (TypeMap.find(actionname) != TypeMap.end()); | 
|---|
| 747 | } | 
|---|
| 748 |  | 
|---|
| 749 | /** Getter for MapOfActions::TypeMap. | 
|---|
| 750 | * \param actionname name of the action to look up | 
|---|
| 751 | * \return type of the action | 
|---|
| 752 | */ | 
|---|
| 753 | enum MapOfActions::OptionTypes MapOfActions::getValueType(string actionname) | 
|---|
| 754 | { | 
|---|
| 755 | return TypeMap[actionname]; | 
|---|
| 756 | } | 
|---|
| 757 |  | 
|---|
| 758 | /** Searches whether action is registered with CommandLineParser. | 
|---|
| 759 | * Note that this method is only meant transitionally for ParseCommandLineOptions' removal. | 
|---|
| 760 | * I.e. All actions that are already handled by the new CommandLineUIFactory can be checked | 
|---|
| 761 | * by this function. | 
|---|
| 762 | * \param shortform command short form to look for | 
|---|
| 763 | * \return true - action has been registered, false - action has not been registered. | 
|---|
| 764 | */ | 
|---|
| 765 | bool MapOfActions::isShortFormPresent(string shortform) | 
|---|
| 766 | { | 
|---|
| 767 | bool result = false; | 
|---|
| 768 | string actionname; | 
|---|
| 769 | for (map<std::string, std::string>::iterator ShortFormRunner = ShortFormMap.begin(); ShortFormRunner != ShortFormMap.end(); ++ShortFormRunner) | 
|---|
| 770 | if (ShortFormRunner->second == shortform) { | 
|---|
| 771 | actionname = ShortFormRunner->first; | 
|---|
| 772 | break; | 
|---|
| 773 | } | 
|---|
| 774 | result = result || (generic.find(actionname) != generic.end()); | 
|---|
| 775 | result = result || (config.find(actionname) != config.end()); | 
|---|
| 776 | result = result || (hidden.find(actionname) != hidden.end()); | 
|---|
| 777 | result = result || (visible.find(actionname) != visible.end()); | 
|---|
| 778 | result = result || (inputfile.find(actionname) != inputfile.end()); | 
|---|
| 779 | return result; | 
|---|
| 780 | } | 
|---|
| 781 |  | 
|---|
| 782 | /** Returns the inverse to MapOfActions::ShortFormMap, i.e. lookup actionname for its short form. | 
|---|
| 783 | * \return map from short form of action to name of action | 
|---|
| 784 | */ | 
|---|
| 785 | map <std::string, std::string> MapOfActions::getShortFormToActionMap() | 
|---|
| 786 | { | 
|---|
| 787 | map <std::string, std::string> result; | 
|---|
| 788 |  | 
|---|
| 789 | for (map<std::string, std::string>::iterator iter = ShortFormMap.begin(); iter != ShortFormMap.end();  ++iter) | 
|---|
| 790 | result[iter->second] = iter->first; | 
|---|
| 791 |  | 
|---|
| 792 | return result; | 
|---|
| 793 | } | 
|---|
| 794 |  | 
|---|
| 795 |  | 
|---|
| 796 | CONSTRUCT_SINGLETON(MapOfActions) | 
|---|