[97ebf8] | 1 | /*
|
---|
| 2 | * MapOfActions.cpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: 10.05.2010
|
---|
| 5 | * Author: heber
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | using namespace std;
|
---|
| 9 |
|
---|
| 10 | #include "Patterns/Singleton_impl.hpp"
|
---|
| 11 | #include "Actions/MapOfActions.hpp"
|
---|
| 12 | #include "Helpers/Assert.hpp"
|
---|
| 13 |
|
---|
[0286bc] | 14 | #include <boost/lexical_cast.hpp>
|
---|
| 15 | #include <boost/optional.hpp>
|
---|
| 16 | #include <boost/program_options.hpp>
|
---|
| 17 |
|
---|
[97ebf8] | 18 | #include "CommandLineParser.hpp"
|
---|
| 19 | #include "log.hpp"
|
---|
| 20 | #include "verbose.hpp"
|
---|
| 21 |
|
---|
[0286bc] | 22 | #include "Actions/Values.hpp"
|
---|
| 23 |
|
---|
| 24 | void validate(boost::any& v, const std::vector<std::string>& values, VectorValue *, int)
|
---|
| 25 | {
|
---|
| 26 | VectorValue VV;
|
---|
| 27 | if (values.size() != 3) {
|
---|
| 28 | cerr << "Specified vector does not have three components but " << values.size() << endl;
|
---|
| 29 | throw boost::program_options::validation_error("Specified vector does not have three components");
|
---|
| 30 | }
|
---|
| 31 | VV.x = boost::lexical_cast<double>(values.at(0));
|
---|
| 32 | VV.y = boost::lexical_cast<double>(values.at(1));
|
---|
| 33 | VV.z = boost::lexical_cast<double>(values.at(2));
|
---|
| 34 | v = boost::any(VectorValue(VV));
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | void validate(boost::any& v, const std::vector<std::string>& values, BoxValue *, int)
|
---|
| 38 | {
|
---|
| 39 | BoxValue BV;
|
---|
| 40 | if (values.size() != 6) {
|
---|
| 41 | cerr << "Specified vector does not have three components but " << values.size() << endl;
|
---|
| 42 | throw boost::program_options::validation_error("Specified symmetric box matrix does not have six components");
|
---|
| 43 | }
|
---|
| 44 | BV.xx = boost::lexical_cast<double>(values.at(0));
|
---|
| 45 | BV.xy = boost::lexical_cast<double>(values.at(1));
|
---|
| 46 | BV.xz = boost::lexical_cast<double>(values.at(2));
|
---|
| 47 | BV.yy = boost::lexical_cast<double>(values.at(3));
|
---|
| 48 | BV.yz = boost::lexical_cast<double>(values.at(4));
|
---|
| 49 | BV.zz = boost::lexical_cast<double>(values.at(5));
|
---|
| 50 | v = boost::any(BoxValue(BV));
|
---|
| 51 | }
|
---|
| 52 |
|
---|
[97ebf8] | 53 | /** Constructor of class MapOfActions.
|
---|
| 54 | *
|
---|
| 55 | */
|
---|
| 56 | MapOfActions::MapOfActions()
|
---|
| 57 | {
|
---|
| 58 | // initialise lookup map
|
---|
| 59 | CmdParserLookup[&generic] = &(CommandLineParser::getInstance().generic);
|
---|
| 60 | CmdParserLookup[&config] = &(CommandLineParser::getInstance().config);
|
---|
| 61 | CmdParserLookup[&hidden] = &(CommandLineParser::getInstance().hidden);
|
---|
| 62 | CmdParserLookup[&visible] = &(CommandLineParser::getInstance().visible);
|
---|
| 63 |
|
---|
| 64 | // keys for actions
|
---|
| 65 | DescriptionMap["add-atom"] = "add atom of specified element";
|
---|
| 66 | DescriptionMap["bond-table"] = "setting name of the bond length table file";
|
---|
| 67 | DescriptionMap["bond-file"] = "name of the bond file";
|
---|
| 68 | DescriptionMap["boundary"] = "change box to add an empty boundary around all atoms";
|
---|
| 69 | DescriptionMap["bound-in-box"] = "bound all atoms in the domain";
|
---|
| 70 | DescriptionMap["center-edge"] = "center edge of all atoms on (0,0,0)";
|
---|
| 71 | DescriptionMap["center-in-box"] = "center all atoms in the domain";
|
---|
| 72 | DescriptionMap["change-box"] = "change the symmetrc matrix of the simulation domain";
|
---|
| 73 | DescriptionMap["change-element"] = "change the element of an atom";
|
---|
| 74 | DescriptionMap["change-molname"] = "change the name of a molecule";
|
---|
| 75 | DescriptionMap["convex-envelope"] = "create the convex envelope for a molecule";
|
---|
| 76 | DescriptionMap["default-molname"] = "set the default name of new molecules";
|
---|
| 77 | DescriptionMap["depth-first-search"] = "Depth-First Search analysis of the molecular system";
|
---|
| 78 | DescriptionMap["element-db"] = "setting the path where the element databases can be found";
|
---|
| 79 | DescriptionMap["fastparsing"] = "setting whether trajectories shall be parsed completely (n) or just first step (y)";
|
---|
| 80 | DescriptionMap["fill-molecule"] = "fill empty space of box with a filler molecule";
|
---|
| 81 | DescriptionMap["fragment-mol"] = "create for a given molecule into fragments up to given order";
|
---|
[a77976] | 82 | DescriptionMap["help"] = "Give this help screen";
|
---|
[97ebf8] | 83 | DescriptionMap["linear-interpolate"] = "linear interpolation in discrete steps between start and end position of a molecule";
|
---|
| 84 | DescriptionMap["nonconvex-envelope"] = "create the non-convex envelope for a molecule";
|
---|
| 85 | DescriptionMap["molecular-volume"] = "calculate the volume of a given molecule";
|
---|
[58bbd3] | 86 | DescriptionMap["pair-correlation"] = "pair correlation analysis between two elements, element and point or element and surface";
|
---|
[97ebf8] | 87 | DescriptionMap["parse-xyz"] = "parse xyz file into World";
|
---|
| 88 | DescriptionMap["principal-axis-system"] = "calculate the principal axis system of the specified molecule";
|
---|
| 89 | DescriptionMap["remove-atom"] = "remove a specified atom";
|
---|
| 90 | DescriptionMap["remove-sphere"] = "remove sphere of atoms of around a specified atom";
|
---|
| 91 | DescriptionMap["repeat-box"] = "create periodic copies of the simulation box per axis";
|
---|
| 92 | DescriptionMap["rotate-to-pas"] = "calculate the principal axis system of the specified molecule and rotate specified axis to align with main axis";
|
---|
| 93 | DescriptionMap["set-basis"] = "set the name of the gaussian basis set for MPQC";
|
---|
| 94 | DescriptionMap["save-adjacency"] = "name of the adjacency file to write to";
|
---|
| 95 | DescriptionMap["save-bonds"] = "name of the bonds file to write to";
|
---|
| 96 | DescriptionMap["save-temperature"] = "name of the temperature file to write to";
|
---|
[2a92ff] | 97 | DescriptionMap["scale-box"] = "scale box and atomic positions inside";
|
---|
[6866aa] | 98 | DescriptionMap["subgraph-dissect"] = "dissect the molecular system into molecules representing disconnected subgraphs";
|
---|
[97ebf8] | 99 | DescriptionMap["suspend-in-water"] = "suspend the given molecule in water such that in the domain the mean density is as specified";
|
---|
| 100 | DescriptionMap["translate-mol"] = "translate molecule by given vector";
|
---|
| 101 | DescriptionMap["verbose"] = "set verbosity level";
|
---|
| 102 | DescriptionMap["verlet-integrate"] = "perform verlet integration of a given force file";
|
---|
| 103 | DescriptionMap["version"] = "show version";
|
---|
| 104 | // keys for values
|
---|
[54b953] | 105 | DescriptionMap["atom-by-id"] = "index of an atom";
|
---|
[97ebf8] | 106 | DescriptionMap["bin-output-file"] = "name of the bin output file";
|
---|
| 107 | DescriptionMap["bin-end"] = "start of the last bin";
|
---|
| 108 | DescriptionMap["bin-start"] = "start of the first bin";
|
---|
| 109 | DescriptionMap["bin-width"] = "width of the bins";
|
---|
[f6bd32] | 110 | DescriptionMap["convex-file"] = "filename of the non-convex envelope";
|
---|
[97ebf8] | 111 | DescriptionMap["distance"] = "distance in space";
|
---|
| 112 | DescriptionMap["distances"] = "list of three of distances in space, one for each axis direction";
|
---|
[0286bc] | 113 | DescriptionMap["DoRotate"] = "whether to rotate or just report angles";
|
---|
[58bbd3] | 114 | DescriptionMap["element"] = "single element";
|
---|
| 115 | DescriptionMap["elements"] = "set of elements";
|
---|
[a02462] | 116 | DescriptionMap["end-step"] = "last or end step";
|
---|
| 117 | DescriptionMap["id-mapping"] = "whether the identity shall be used in mapping atoms onto atoms or some closest distance measure shall be used";
|
---|
[97ebf8] | 118 | DescriptionMap["input"] = "name of input file";
|
---|
| 119 | DescriptionMap["length"] = "length in space";
|
---|
| 120 | DescriptionMap["lengths"] = "list of three of lengths in space, one for each axis direction";
|
---|
| 121 | DescriptionMap["MaxDistance"] = "maximum distance in space";
|
---|
| 122 | DescriptionMap["molecule-by-id"] = "index of a molecule";
|
---|
[58bbd3] | 123 | DescriptionMap["molecule-by-name"] = "name of a molecule";
|
---|
[f6bd32] | 124 | DescriptionMap["nonconvex-file"] = "filename of the non-convex envelope";
|
---|
[e4b5de] | 125 | DescriptionMap["order"] = "order of a discretization, dissection, ...";
|
---|
[97ebf8] | 126 | DescriptionMap["output-file"] = "name of the output file";
|
---|
| 127 | DescriptionMap["periodic"] = "system is constraint to periodic boundary conditions (y/n)";
|
---|
| 128 | DescriptionMap["position"] = "position in R^3 space";
|
---|
[980dd6] | 129 | DescriptionMap["sphere-radius"] = "radius of tesselation sphere";
|
---|
[a02462] | 130 | DescriptionMap["start-step"] = "first or start step";
|
---|
[97ebf8] | 131 |
|
---|
| 132 | // short forms for the actions
|
---|
| 133 | ShortFormMap["add-atom"] = "a";
|
---|
| 134 | ShortFormMap["bond-table"] = "g";
|
---|
| 135 | ShortFormMap["bond-file"] = "A";
|
---|
| 136 | ShortFormMap["boundary"] = "c";
|
---|
[6ca1f7] | 137 | ShortFormMap["change-box"] = "B";
|
---|
[97ebf8] | 138 | ShortFormMap["center-edge"] = "O";
|
---|
| 139 | ShortFormMap["center-in-box"] = "b";
|
---|
| 140 | ShortFormMap["change-element"] = "E";
|
---|
| 141 | ShortFormMap["convex-envelope"] = "o";
|
---|
| 142 | ShortFormMap["default-molname"] = "X";
|
---|
| 143 | ShortFormMap["depth-first-search"] = "D";
|
---|
| 144 | ShortFormMap["element-db"] = "e";
|
---|
| 145 | ShortFormMap["fastparsing"] = "n";
|
---|
| 146 | ShortFormMap["fill-molecule"] = "F";
|
---|
| 147 | ShortFormMap["fragment-mol"] = "f";
|
---|
| 148 | ShortFormMap["help"] = "h";
|
---|
| 149 | ShortFormMap["input"] = "i";
|
---|
| 150 | ShortFormMap["linear-interpolate"] = "L";
|
---|
| 151 | ShortFormMap["nonconvex-envelope"] = "N";
|
---|
[58bbd3] | 152 | ShortFormMap["pair-correlation"] = "C";
|
---|
[97ebf8] | 153 | ShortFormMap["parse-xyz"] = "p";
|
---|
| 154 | ShortFormMap["remove-atom"] = "r";
|
---|
| 155 | ShortFormMap["remove-sphere"] = "R";
|
---|
| 156 | ShortFormMap["repeat-box"] = "d";
|
---|
| 157 | ShortFormMap["rotate-to-pas"] = "m";
|
---|
| 158 | ShortFormMap["save-adjacency"] = "J";
|
---|
| 159 | ShortFormMap["save-bonds"] = "j";
|
---|
| 160 | ShortFormMap["save-temperature"] = "S";
|
---|
| 161 | ShortFormMap["scale-box"] = "s";
|
---|
| 162 | ShortFormMap["set-basis"] = "M";
|
---|
[6866aa] | 163 | ShortFormMap["subgraph-dissect"] = "I";
|
---|
[48ab70a] | 164 | ShortFormMap["suspend-in-water"] = "u";
|
---|
[97ebf8] | 165 | ShortFormMap["translate-mol"] = "t";
|
---|
[6670a97] | 166 | ShortFormMap["verbose"] = "v";
|
---|
[97ebf8] | 167 | ShortFormMap["verlet-integrate"] = "P";
|
---|
[6670a97] | 168 | ShortFormMap["version"] = "V";
|
---|
[97ebf8] | 169 |
|
---|
| 170 | // value types for the actions
|
---|
[f0a3ec] | 171 | TypeMap["add-atom"] = Element;
|
---|
[97ebf8] | 172 | TypeMap["bond-file"] = String;
|
---|
| 173 | TypeMap["bond-table"] = String;
|
---|
| 174 | TypeMap["boundary"] = Vector;
|
---|
[0286bc] | 175 | TypeMap["center-in-box"] = Box;
|
---|
| 176 | TypeMap["change-box"] = Box;
|
---|
[54b953] | 177 | TypeMap["change-element"] = Atom;
|
---|
[97ebf8] | 178 | TypeMap["change-molname"] = String;
|
---|
| 179 | TypeMap["convex-envelope"] = Molecule;
|
---|
| 180 | TypeMap["default-molname"] = String;
|
---|
| 181 | TypeMap["depth-first-search"] = Double;
|
---|
| 182 | TypeMap["element-db"] = String;
|
---|
| 183 | TypeMap["fastparsing"] = Boolean;
|
---|
| 184 | TypeMap["fill-molecule"] = String;
|
---|
| 185 | TypeMap["fragment-mol"] = Molecule;
|
---|
| 186 | TypeMap["input"] = String;
|
---|
| 187 | TypeMap["linear-interpolate"] = String;
|
---|
| 188 | TypeMap["molecular-volume"] = Molecule;
|
---|
| 189 | TypeMap["nonconvex-envelope"] = Molecule;
|
---|
| 190 | TypeMap["parse-xyz"] = String;
|
---|
[58bbd3] | 191 | TypeMap["pair-correlation"] = String;
|
---|
[2b5574] | 192 | TypeMap["principal-axis-system"] = Molecule;
|
---|
[97ebf8] | 193 | TypeMap["remove-atom"] = Atom;
|
---|
[e2b47c] | 194 | TypeMap["remove-sphere"] = Double;
|
---|
[e30ce8] | 195 | TypeMap["repeat-box"] = Vector;
|
---|
[97ebf8] | 196 | TypeMap["rotate-to-pas"] = Molecule;
|
---|
| 197 | TypeMap["save-adjacency"] = String;
|
---|
| 198 | TypeMap["save-bonds"] = String;
|
---|
| 199 | TypeMap["save-temperature"] = String;
|
---|
| 200 | TypeMap["scale-box"] = Vector;
|
---|
| 201 | TypeMap["set-basis"] = String;
|
---|
[6866aa] | 202 | TypeMap["subgraph-dissect"] = None;
|
---|
[48ab70a] | 203 | TypeMap["suspend-in-water"] = Double;
|
---|
[97ebf8] | 204 | TypeMap["translate-mol"] = Vector;
|
---|
| 205 | TypeMap["verlet-integrate"] = String;
|
---|
| 206 | TypeMap["verbose"] = Integer;
|
---|
[e30ce8] | 207 |
|
---|
[97ebf8] | 208 | // value types for the values
|
---|
[54b953] | 209 | TypeMap["atom-by-id"] = Atom;
|
---|
[97ebf8] | 210 | TypeMap["bin-output-file"] = String;
|
---|
| 211 | TypeMap["bin-end"] = Double;
|
---|
| 212 | TypeMap["bin-start"] = Double;
|
---|
[58bbd3] | 213 | TypeMap["bin-width"] = Double;
|
---|
[f6bd32] | 214 | TypeMap["convex-file"] = String;
|
---|
[97ebf8] | 215 | TypeMap["distance"] = Double;
|
---|
[0286bc] | 216 | TypeMap["distances"] = Vector;
|
---|
| 217 | TypeMap["DoRotate"] = Boolean;
|
---|
[f0a3ec] | 218 | TypeMap["element"] = Element;
|
---|
[97ebf8] | 219 | TypeMap["elements"] = ListOfElements;
|
---|
[a02462] | 220 | TypeMap["end-step"] = Integer;
|
---|
| 221 | TypeMap["id-mapping"] = Boolean;
|
---|
[97ebf8] | 222 | TypeMap["length"] = Double;
|
---|
[0286bc] | 223 | TypeMap["lengths"] = Vector;
|
---|
[97ebf8] | 224 | TypeMap["MaxDistance"] = Double;
|
---|
| 225 | TypeMap["molecule-by-id"] = Molecule;
|
---|
[58bbd3] | 226 | TypeMap["molecule-by-name"] = Molecule;
|
---|
[f6bd32] | 227 | TypeMap["nonconvex-file"] = String;
|
---|
[e4b5de] | 228 | TypeMap["order"] = Integer;
|
---|
[97ebf8] | 229 | TypeMap["output-file"] = String;
|
---|
| 230 | TypeMap["periodic"] = Boolean;
|
---|
| 231 | TypeMap["position"] = Vector;
|
---|
[980dd6] | 232 | TypeMap["sphere-radius"] = Double;
|
---|
[a02462] | 233 | TypeMap["start-step"] = Integer;
|
---|
[97ebf8] | 234 |
|
---|
[e30ce8] | 235 | // default values for any action that needs one (always string!)
|
---|
[58bbd3] | 236 | DefaultValue["bin-width"] = "0.5";
|
---|
[f821d6] | 237 | DefaultValue["fastparsing"] = "0";
|
---|
[54b953] | 238 | DefaultValue["atom-by-id"] = "-1";
|
---|
[f821d6] | 239 | DefaultValue["molecule-by-id"] = "-1";
|
---|
[58bbd3] | 240 | DefaultValue["periodic"] = "0";
|
---|
[e30ce8] | 241 |
|
---|
| 242 |
|
---|
[97ebf8] | 243 | // list of generic actions
|
---|
[f0a3ec] | 244 | generic.insert("add-atom");
|
---|
[f4bd01] | 245 | generic.insert("bond-file");
|
---|
[39af9f] | 246 | generic.insert("bond-table");
|
---|
[116f37] | 247 | generic.insert("boundary");
|
---|
[97ebf8] | 248 | // generic.insert("bound-in-box");
|
---|
[584a2a] | 249 | generic.insert("center-edge");
|
---|
[158c594] | 250 | generic.insert("center-in-box");
|
---|
[6ca1f7] | 251 | generic.insert("change-box");
|
---|
[97ebf8] | 252 | // generic.insert("change-molname");
|
---|
[54b953] | 253 | generic.insert("change-element");
|
---|
[f6bd32] | 254 | generic.insert("convex-envelope");
|
---|
[387b36] | 255 | generic.insert("default-molname");
|
---|
[8540f0] | 256 | generic.insert("depth-first-search");
|
---|
[198494] | 257 | generic.insert("element-db");
|
---|
[f821d6] | 258 | generic.insert("fastparsing");
|
---|
[0286bc] | 259 | generic.insert("fill-molecule");
|
---|
[e4b5de] | 260 | generic.insert("fragment-mol");
|
---|
[97ebf8] | 261 | generic.insert("help");
|
---|
[a02462] | 262 | generic.insert("linear-interpolate");
|
---|
[97ebf8] | 263 | // generic.insert("molecular-volume");
|
---|
[980dd6] | 264 | generic.insert("nonconvex-envelope");
|
---|
[58bbd3] | 265 | generic.insert("pair-correlation");
|
---|
[97ebf8] | 266 | // generic.insert("parse-xyz");
|
---|
| 267 | // generic.insert("principal-axis-system");
|
---|
[d55743e] | 268 | generic.insert("remove-atom");
|
---|
[e2b47c] | 269 | generic.insert("remove-sphere");
|
---|
[0286bc] | 270 | generic.insert("repeat-box");
|
---|
[2b5574] | 271 | generic.insert("rotate-to-pas");
|
---|
[77de81] | 272 | generic.insert("save-adjacency");
|
---|
| 273 | generic.insert("save-bonds");
|
---|
[a307af] | 274 | generic.insert("save-temperature");
|
---|
[2a92ff] | 275 | generic.insert("scale-box");
|
---|
[bdaacd] | 276 | generic.insert("set-basis");
|
---|
[6866aa] | 277 | generic.insert("subgraph-dissect");
|
---|
[48ab70a] | 278 | generic.insert("suspend-in-water");
|
---|
[77b2d7] | 279 | generic.insert("translate-mol");
|
---|
[97ebf8] | 280 | generic.insert("verbose");
|
---|
[aacce8] | 281 | generic.insert("verlet-integrate");
|
---|
[97ebf8] | 282 | generic.insert("version");
|
---|
| 283 |
|
---|
| 284 | // positional arguments
|
---|
[f6bd32] | 285 | generic.insert("input");
|
---|
| 286 | inputfile.insert("input");
|
---|
[0286bc] | 287 |
|
---|
| 288 | // hidden arguments
|
---|
[54b953] | 289 | generic.insert("atom-by-id");
|
---|
[58bbd3] | 290 | generic.insert("bin-end");
|
---|
| 291 | generic.insert("bin-output-file");
|
---|
| 292 | generic.insert("bin-start");
|
---|
| 293 | generic.insert("bin-width");
|
---|
[f6bd32] | 294 | generic.insert("convex-file");
|
---|
[e4b5de] | 295 | generic.insert("distance");
|
---|
| 296 | generic.insert("DoRotate");
|
---|
| 297 | generic.insert("distances");
|
---|
[58bbd3] | 298 | generic.insert("element");
|
---|
| 299 | generic.insert("elements");
|
---|
[a02462] | 300 | generic.insert("end-step");
|
---|
| 301 | generic.insert("id-mapping");
|
---|
[e4b5de] | 302 | generic.insert("lengths");
|
---|
| 303 | generic.insert("MaxDistance");
|
---|
| 304 | generic.insert("molecule-by-id");
|
---|
[58bbd3] | 305 | generic.insert("molecule-by-name");
|
---|
[f6bd32] | 306 | generic.insert("nonconvex-file");
|
---|
[e4b5de] | 307 | generic.insert("order");
|
---|
[58bbd3] | 308 | generic.insert("output-file");
|
---|
| 309 | generic.insert("periodic");
|
---|
| 310 | generic.insert("position");
|
---|
[980dd6] | 311 | generic.insert("sphere-radius");
|
---|
[a02462] | 312 | generic.insert("start-step");
|
---|
[97ebf8] | 313 | }
|
---|
| 314 |
|
---|
| 315 | /** Destructor of class MapOfActions.
|
---|
| 316 | *
|
---|
| 317 | */
|
---|
| 318 | MapOfActions::~MapOfActions()
|
---|
| 319 | {
|
---|
| 320 | DescriptionMap.clear();
|
---|
| 321 | }
|
---|
| 322 |
|
---|
| 323 | /** Adds all options to the CommandLineParser.
|
---|
| 324 | *
|
---|
| 325 | */
|
---|
| 326 | void MapOfActions::AddOptionsToParser()
|
---|
| 327 | {
|
---|
| 328 | // add other options
|
---|
| 329 | for (map< set<string>*, po::options_description* >::iterator ListRunner = CmdParserLookup.begin(); ListRunner != CmdParserLookup.end(); ++ListRunner) {
|
---|
| 330 | for (set<string>::iterator OptionRunner = ListRunner->first->begin(); OptionRunner != ListRunner->first->end(); ++OptionRunner) {
|
---|
| 331 | if (hasValue(*OptionRunner)) {
|
---|
| 332 | DoLog(0) && (Log() << Verbose(0) << "Adding option " << *OptionRunner << " with type " << TypeMap[*OptionRunner] << " to CommandLineParser." << endl);
|
---|
| 333 | switch((enum OptionTypes) TypeMap[*OptionRunner]) {
|
---|
| 334 | default:
|
---|
| 335 | case None:
|
---|
| 336 | ListRunner->second->add_options()
|
---|
| 337 | (getKeyAndShortForm(*OptionRunner).c_str(), getDescription(*OptionRunner).c_str())
|
---|
| 338 | ;
|
---|
| 339 | break;
|
---|
| 340 | case Boolean:
|
---|
| 341 | ListRunner->second->add_options()
|
---|
[e30ce8] | 342 | (getKeyAndShortForm(*OptionRunner).c_str(),
|
---|
| 343 | DefaultValue.find(*OptionRunner) != DefaultValue.end() ?
|
---|
| 344 | po::value< bool >()->default_value(atoi(DefaultValue[*OptionRunner].c_str())) :
|
---|
| 345 | po::value< bool >(),
|
---|
| 346 | getDescription(*OptionRunner).c_str())
|
---|
[97ebf8] | 347 | ;
|
---|
| 348 | break;
|
---|
[0286bc] | 349 | case Box:
|
---|
| 350 | ListRunner->second->add_options()
|
---|
| 351 | (getKeyAndShortForm(*OptionRunner).c_str(),
|
---|
| 352 | po::value<BoxValue>()->multitoken(),
|
---|
| 353 | getDescription(*OptionRunner).c_str())
|
---|
| 354 | ;
|
---|
| 355 | break;
|
---|
[97ebf8] | 356 | case Integer:
|
---|
| 357 | ListRunner->second->add_options()
|
---|
[e30ce8] | 358 | (getKeyAndShortForm(*OptionRunner).c_str(),
|
---|
| 359 | DefaultValue.find(*OptionRunner) != DefaultValue.end() ?
|
---|
| 360 | po::value< int >()->default_value(atoi(DefaultValue[*OptionRunner].c_str())) :
|
---|
| 361 | po::value< int >(),
|
---|
| 362 | getDescription(*OptionRunner).c_str())
|
---|
[97ebf8] | 363 | ;
|
---|
| 364 | break;
|
---|
| 365 | case ListOfInts:
|
---|
| 366 | ListRunner->second->add_options()
|
---|
[e30ce8] | 367 | (getKeyAndShortForm(*OptionRunner).c_str(),
|
---|
| 368 | po::value< vector<int> >()->multitoken(),
|
---|
| 369 | getDescription(*OptionRunner).c_str())
|
---|
[97ebf8] | 370 | ;
|
---|
| 371 | break;
|
---|
| 372 | case Double:
|
---|
| 373 | ListRunner->second->add_options()
|
---|
[e30ce8] | 374 | (getKeyAndShortForm(*OptionRunner).c_str(),
|
---|
| 375 | DefaultValue.find(*OptionRunner) != DefaultValue.end() ?
|
---|
| 376 | po::value< double >()->default_value(atof(DefaultValue[*OptionRunner].c_str())) :
|
---|
| 377 | po::value< double >(),
|
---|
| 378 | getDescription(*OptionRunner).c_str())
|
---|
[97ebf8] | 379 | ;
|
---|
| 380 | break;
|
---|
| 381 | case ListOfDoubles:
|
---|
| 382 | ListRunner->second->add_options()
|
---|
[e30ce8] | 383 | (getKeyAndShortForm(*OptionRunner).c_str(),
|
---|
| 384 | po::value< vector<double> >()->multitoken(),
|
---|
| 385 | getDescription(*OptionRunner).c_str())
|
---|
[97ebf8] | 386 | ;
|
---|
| 387 | break;
|
---|
| 388 | case String:
|
---|
| 389 | ListRunner->second->add_options()
|
---|
[e30ce8] | 390 | (getKeyAndShortForm(*OptionRunner).c_str(),
|
---|
| 391 | DefaultValue.find(*OptionRunner) != DefaultValue.end() ?
|
---|
| 392 | po::value< std::string >()->default_value(DefaultValue[*OptionRunner]) :
|
---|
| 393 | po::value< std::string >(),
|
---|
| 394 | getDescription(*OptionRunner).c_str())
|
---|
[97ebf8] | 395 | ;
|
---|
| 396 | break;
|
---|
| 397 | case Axis:
|
---|
| 398 | ListRunner->second->add_options()
|
---|
[e30ce8] | 399 | (getKeyAndShortForm(*OptionRunner).c_str(),
|
---|
| 400 | DefaultValue.find(*OptionRunner) != DefaultValue.end() ?
|
---|
| 401 | po::value< int >()->default_value(atoi(DefaultValue[*OptionRunner].c_str())) :
|
---|
| 402 | po::value< int >(),
|
---|
| 403 | getDescription(*OptionRunner).c_str())
|
---|
[97ebf8] | 404 | ;
|
---|
| 405 | break;
|
---|
| 406 | case Vector:
|
---|
| 407 | ListRunner->second->add_options()
|
---|
[e30ce8] | 408 | (getKeyAndShortForm(*OptionRunner).c_str(),
|
---|
[0286bc] | 409 | po::value<VectorValue>()->multitoken(),
|
---|
[e30ce8] | 410 | getDescription(*OptionRunner).c_str())
|
---|
[97ebf8] | 411 | ;
|
---|
| 412 | break;
|
---|
| 413 | case Molecule:
|
---|
| 414 | ListRunner->second->add_options()
|
---|
[e30ce8] | 415 | (getKeyAndShortForm(*OptionRunner).c_str(),
|
---|
| 416 | DefaultValue.find(*OptionRunner) != DefaultValue.end() ?
|
---|
| 417 | po::value< int >()->default_value(atoi(DefaultValue[*OptionRunner].c_str())) :
|
---|
| 418 | po::value< int >(),
|
---|
| 419 | getDescription(*OptionRunner).c_str())
|
---|
[97ebf8] | 420 | ;
|
---|
| 421 | break;
|
---|
| 422 | case ListOfMolecules:
|
---|
| 423 | ListRunner->second->add_options()
|
---|
[e30ce8] | 424 | (getKeyAndShortForm(*OptionRunner).c_str(),
|
---|
| 425 | po::value< vector<int> >()->multitoken(),
|
---|
| 426 | getDescription(*OptionRunner).c_str())
|
---|
[97ebf8] | 427 | ;
|
---|
| 428 | break;
|
---|
| 429 | case Atom:
|
---|
| 430 | ListRunner->second->add_options()
|
---|
[e30ce8] | 431 | (getKeyAndShortForm(*OptionRunner).c_str(),
|
---|
| 432 | DefaultValue.find(*OptionRunner) != DefaultValue.end() ?
|
---|
| 433 | po::value< int >()->default_value(atoi(DefaultValue[*OptionRunner].c_str())) :
|
---|
| 434 | po::value< int >(),
|
---|
| 435 | getDescription(*OptionRunner).c_str())
|
---|
[97ebf8] | 436 | ;
|
---|
| 437 | break;
|
---|
| 438 | case ListOfAtoms:
|
---|
| 439 | ListRunner->second->add_options()
|
---|
[e30ce8] | 440 | (getKeyAndShortForm(*OptionRunner).c_str(),
|
---|
| 441 | po::value< vector<int> >()->multitoken(),
|
---|
| 442 | getDescription(*OptionRunner).c_str())
|
---|
[97ebf8] | 443 | ;
|
---|
| 444 | break;
|
---|
| 445 | case Element:
|
---|
| 446 | ListRunner->second->add_options()
|
---|
[e30ce8] | 447 | (getKeyAndShortForm(*OptionRunner).c_str(),
|
---|
[f0a3ec] | 448 | po::value< vector<int> >(),
|
---|
[e30ce8] | 449 | getDescription(*OptionRunner).c_str())
|
---|
[97ebf8] | 450 | ;
|
---|
| 451 | break;
|
---|
| 452 | case ListOfElements:
|
---|
| 453 | ListRunner->second->add_options()
|
---|
[e30ce8] | 454 | (getKeyAndShortForm(*OptionRunner).c_str(),
|
---|
| 455 | po::value< vector<int> >()->multitoken(),
|
---|
| 456 | getDescription(*OptionRunner).c_str())
|
---|
[97ebf8] | 457 | ;
|
---|
| 458 | break;
|
---|
| 459 | }
|
---|
| 460 | } else {
|
---|
| 461 | DoLog(0) && (Log() << Verbose(0) << "Adding option " << *OptionRunner << " to CommandLineParser." << endl);
|
---|
| 462 | ListRunner->second->add_options()
|
---|
| 463 | (getKeyAndShortForm(*OptionRunner).c_str(), getDescription(*OptionRunner).c_str())
|
---|
| 464 | ;
|
---|
| 465 | }
|
---|
| 466 | }
|
---|
| 467 | }
|
---|
| 468 | // add positional arguments
|
---|
| 469 | for (set<string>::iterator OptionRunner = inputfile.begin(); OptionRunner != inputfile.end(); ++OptionRunner) {
|
---|
| 470 | DoLog(0) && (Log() << Verbose(0) << "Adding option " << *OptionRunner << " to positional CommandLineParser." << endl);
|
---|
| 471 | CommandLineParser::getInstance().inputfile.add((*OptionRunner).c_str(), -1);
|
---|
| 472 | }
|
---|
| 473 | cout << "Name for position 1: " << CommandLineParser::getInstance().inputfile.name_for_position(1) << endl;
|
---|
| 474 | }
|
---|
| 475 |
|
---|
| 476 | /** Getter for MapOfActions:DescriptionMap.
|
---|
| 477 | * Note that we assert when action does not exist in CommandLineParser::DescriptionMap.
|
---|
| 478 | * \param actionname name of the action to lookup
|
---|
| 479 | * \return Description of the action
|
---|
| 480 | */
|
---|
| 481 | std::string MapOfActions::getDescription(string actionname)
|
---|
| 482 | {
|
---|
| 483 | ASSERT(DescriptionMap.find(actionname) != DescriptionMap.end(), "Unknown action name passed to MapOfActions::getDescription");
|
---|
| 484 | return DescriptionMap[actionname];
|
---|
| 485 | }
|
---|
| 486 |
|
---|
| 487 | /** Specific Getter for a MapOfActions:ShortFormMap.
|
---|
| 488 | * If action has a short for, then combination is as "actionname,ShortForm" (this is
|
---|
| 489 | * the desired format for boost::program_options). If no short form exists in the map,
|
---|
| 490 | * just actionname will be returned
|
---|
| 491 | * Note that we assert when action does not exist in CommandLineParser::DescriptionMap.
|
---|
| 492 | * \param actionname name of the action to lookup
|
---|
| 493 | * \return actionname,ShortForm or Description of the action
|
---|
| 494 | */
|
---|
| 495 | std::string MapOfActions::getKeyAndShortForm(string actionname)
|
---|
| 496 | {
|
---|
| 497 | stringstream output;
|
---|
| 498 | ASSERT(DescriptionMap.find(actionname) != DescriptionMap.end(), "Unknown action name passed to MapOfActions::getDescriptionAndShortForm");
|
---|
| 499 | output << actionname;
|
---|
| 500 | if (ShortFormMap.find(actionname) != DescriptionMap.end())
|
---|
| 501 | output << "," << ShortFormMap[actionname];
|
---|
| 502 | return output.str();
|
---|
| 503 | }
|
---|
| 504 |
|
---|
| 505 | /** Getter for MapOfActions:ShortFormMap.
|
---|
| 506 | * Note that we assert when action does not exist CommandLineParser::ShortFormMap.
|
---|
| 507 | * \param actionname name of the action to lookup
|
---|
| 508 | * \return ShortForm of the action
|
---|
| 509 | */
|
---|
| 510 | std::string MapOfActions::getShortForm(string actionname)
|
---|
| 511 | {
|
---|
| 512 | ASSERT(ShortFormMap.find(actionname) != ShortFormMap.end(), "Unknown action name passed to MapOfActions::getShortForm");
|
---|
| 513 | return ShortFormMap[actionname];
|
---|
| 514 | }
|
---|
| 515 |
|
---|
| 516 | /** Returns whether the given action needs a value or not.
|
---|
| 517 | * \param actionname name of the action to look up
|
---|
| 518 | * \return true - value is needed, false - no value is stored in MapOfActions::TypeMap
|
---|
| 519 | */
|
---|
| 520 | bool MapOfActions::hasValue(string actionname)
|
---|
| 521 | {
|
---|
| 522 | return (TypeMap.find(actionname) != TypeMap.end());
|
---|
| 523 | }
|
---|
| 524 |
|
---|
| 525 | /** Getter for MapOfActions::TypeMap.
|
---|
| 526 | * \param actionname name of the action to look up
|
---|
| 527 | * \return type of the action
|
---|
| 528 | */
|
---|
| 529 | enum MapOfActions::OptionTypes MapOfActions::getValueType(string actionname)
|
---|
| 530 | {
|
---|
| 531 | return TypeMap[actionname];
|
---|
| 532 | }
|
---|
| 533 |
|
---|
| 534 | /** Searches whether action is registered with CommandLineParser.
|
---|
| 535 | * Note that this method is only meant transitionally for ParseCommandLineOptions' removal.
|
---|
| 536 | * I.e. All actions that are already handled by the new CommandLineUIFactory can be checked
|
---|
| 537 | * by this function.
|
---|
| 538 | * \param shortform command short form to look for
|
---|
| 539 | * \return true - action has been registered, false - action has not been registered.
|
---|
| 540 | */
|
---|
| 541 | bool MapOfActions::isShortFormPresent(string shortform)
|
---|
| 542 | {
|
---|
| 543 | bool result = false;
|
---|
| 544 | string actionname;
|
---|
| 545 | for (map<std::string, std::string>::iterator ShortFormRunner = ShortFormMap.begin(); ShortFormRunner != ShortFormMap.end(); ++ShortFormRunner)
|
---|
| 546 | if (ShortFormRunner->second == shortform) {
|
---|
| 547 | actionname = ShortFormRunner->first;
|
---|
| 548 | break;
|
---|
| 549 | }
|
---|
| 550 | result = result || (generic.find(actionname) != generic.end());
|
---|
| 551 | result = result || (config.find(actionname) != config.end());
|
---|
| 552 | result = result || (hidden.find(actionname) != hidden.end());
|
---|
| 553 | result = result || (visible.find(actionname) != visible.end());
|
---|
| 554 | result = result || (inputfile.find(actionname) != inputfile.end());
|
---|
| 555 | return result;
|
---|
| 556 | }
|
---|
| 557 |
|
---|
[7e6b00] | 558 | /** Returns the inverse to MapOfActions::ShortFormMap, i.e. lookup actionname for its short form.
|
---|
| 559 | * \return map from short form of action to name of action
|
---|
| 560 | */
|
---|
| 561 | map <std::string, std::string> MapOfActions::getShortFormToActionMap()
|
---|
| 562 | {
|
---|
| 563 | map <std::string, std::string> result;
|
---|
| 564 |
|
---|
| 565 | for (map<std::string, std::string>::iterator iter = ShortFormMap.begin(); iter != ShortFormMap.end(); ++iter)
|
---|
| 566 | result[iter->second] = iter->first;
|
---|
| 567 |
|
---|
| 568 | return result;
|
---|
| 569 | }
|
---|
[97ebf8] | 570 |
|
---|
| 571 |
|
---|
| 572 | CONSTRUCT_SINGLETON(MapOfActions)
|
---|