Pteros  2.0
Molecular modeling library for human beings!
options.h
1 /*
2  *
3  * This source code is part of
4  * ******************
5  * *** Pteros ***
6  * ******************
7  * molecular modeling library
8  *
9  * Copyright (c) 2009-2013, Semen Yesylevskyy
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of Artistic License:
13  *
14  * Please note, that Artistic License is slightly more restrictive
15  * then GPL license in terms of distributing the modified versions
16  * of this software (they should be approved first).
17  * Read http://www.opensource.org/licenses/artistic-license-2.0.php
18  * for details. Such license fits scientific software better then
19  * GPL because it prevents the distribution of bugged derivatives.
20  *
21 */
22 
23 #ifndef OPTIONS_H
24 #define OPTIONS_H
25 
26 #include <string>
27 #include <vector>
28 
29 namespace pteros {
30 
31 class Options;
32 
33 // Single option such as -t sss fff ggg
34 class Option {
35  friend class Options;
38  friend void parse_command_line(int argc, char** argv,
39  Options& toplevel,
40  std::string task_tag,
41  std::vector<Options>& tasks);
43  friend void parse_command_line(int argc, char** argv, Options& toplevel);
44 
45 public:
48  std::string as_string() const;
50  int as_int() const;
52  float as_float() const;
54  bool as_bool() const;
55 
58  std::vector<std::string> as_strings() const;
59  std::vector<int> as_ints() const;
60  std::vector<float> as_floats() const;
61  std::vector<bool> as_bools() const;
62 private:
63  // Internal storage is just a vector of strings representing values
64  std::vector<std::string> data;
65  // names of this option
66  std::string name;
67 #ifdef DEBUG
68  void debug();
69 #endif
70 };
71 
72 //---------------------------------------------------------------------------
73 
75 class Options {
78  friend void parse_command_line(int argc, char** argv,
79  Options& toplevel,
80  std::string task_tag,
81  std::vector<Options>& tasks);
83  friend void parse_command_line(int argc, char** argv, Options& toplevel);
84 
85 public:
87  const Option& operator()(std::string key) const;
88  const Option& operator()(std::string key, std::string default_val);
89  bool has(std::string key);
90  std::string get_name(){ return task_name; }
91 #ifdef DEBUG
92  void debug();
93 #endif
94 private:
95  std::vector<Option> data;
96  std::string task_name;
97 };
98 
99 
100 } // namespace
101 
102 #endif
Pteros namespace.
Definition: options.cpp:32
All options obtained from command line including nested options for tasks.
Definition: options.h:75