Pteros  2.0
Molecular modeling library for human beings!
options.h
1 /*
2  * This file is a part of
3  *
4  * ============================================
5  * ### Pteros molecular modeling library ###
6  * ============================================
7  *
8  * https://github.com/yesint/pteros
9  *
10  * (C) 2009-2021, Semen Yesylevskyy
11  *
12  * All works, which use Pteros, should cite the following papers:
13  *
14  * 1. Semen O. Yesylevskyy, "Pteros 2.0: Evolution of the fast parallel
15  * molecular analysis library for C++ and python",
16  * Journal of Computational Chemistry, 2015, 36(19), 1480–1488.
17  * doi: 10.1002/jcc.23943.
18  *
19  * 2. Semen O. Yesylevskyy, "Pteros: Fast and easy to use open-source C++
20  * library for molecular analysis",
21  * Journal of Computational Chemistry, 2012, 33(19), 1632–1636.
22  * doi: 10.1002/jcc.22989.
23  *
24  * This is free software distributed under Artistic License:
25  * http://www.opensource.org/licenses/artistic-license-2.0.php
26  *
27 */
28 
29 #pragma once
30 
31 #include <string>
32 #include <vector>
33 #include <Eigen/Core>
34 
35 namespace pteros {
36 
37 class Options;
38 
39 // Single option such as -t sss fff ggg
40 class Option {
41  friend class Options;
44  friend void parse_command_line(int argc, char** argv,
45  Options& toplevel,
46  std::string task_tag,
47  std::vector<Options>& tasks);
49  friend void parse_command_line(int argc, char** argv, Options& toplevel);
50 
51 public:
54  std::string as_string() const;
56  int as_int() const;
58  float as_float() const;
60  bool as_bool() const;
61 
64  std::vector<std::string> as_strings() const;
65  std::vector<int> as_ints() const;
66  std::vector<float> as_floats() const;
67  std::vector<bool> as_bools() const;
68  Eigen::VectorXf as_VectorXf() const;
69 private:
70  // Internal storage is just a vector of strings representing values
71  std::vector<std::string> data;
72  // name of this option
73  std::string name;
74 #ifdef DEBUG
75  void debug();
76 #endif
77 };
78 
79 //---------------------------------------------------------------------------
80 
82 class Options {
85  friend void parse_command_line(int argc, char** argv,
86  Options& toplevel,
87  std::string task_tag,
88  std::vector<Options>& tasks);
90  friend void parse_command_line(int argc, char** argv, Options& toplevel);
91 
92 public:
94  const Option& operator()(std::string key) const;
95  const Option& operator()(std::string key, std::string default_val);
96  bool has(std::string key);
97  std::string get_name(){ return task_name; }
98 #ifdef DEBUG
99  void debug();
100 #endif
101 private:
102  std::vector<Option> data;
103  std::string task_name;
104 };
105 
106 
107 } // namespace
108 
109 
110 
111 
pteros::Options
All options obtained from command line including nested options for tasks.
Definition: options.h:82
pteros::Options::operator()
const Option & operator()(std::string key) const
Return single option with given name.
Definition: options.cpp:166
pteros::Options::parse_command_line
friend void parse_command_line(int argc, char **argv, Options &toplevel, std::string task_tag, std::vector< Options > &tasks)
Create options from command line with nested tasks.
Definition: options.cpp:53