mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
configTarget.hpp
Go to the documentation of this file.
1 /** \file configTarget.hpp
2  * \author Jared R. Males
3  * \brief Targets for the configuration manager, and utiltities.
4  *
5  * \ingroup mxApp_files
6  *
7  */
8 
9 //***********************************************************************//
10 // Copyright 2015, 2016, 2017, 2018 Jared R. Males (jaredmales@gmail.com)
11 //
12 // This file is part of mxlib.
13 //
14 // mxlib is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 // mxlib is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 // GNU General Public License for more details.
23 //
24 // You should have received a copy of the GNU General Public License
25 // along with mxlib. If not, see <http://www.gnu.org/licenses/>.
26 //***********************************************************************//
27 
28 #ifndef configTarget_hpp
29 #define configTarget_hpp
30 
31 #include <unordered_map>
32 
33 
34 #include "../ioutils/stringUtils.hpp"
35 #include "../meta/trueFalseT.hpp"
36 #include "../meta/typeTraits.hpp"
37 #include "../meta/typeDescription.hpp"
38 
39 #include "../mxError.hpp"
40 
41 namespace mx
42 {
43 namespace app
44 {
45 
46 /// A configuration target
47 /** Specifies the details of a configuration target, which is a value that can be set from the command line and/or a config file.
48  * A target has a name used as a key for accessing it, and defines how it is set with short and long command line options and the section and
49  * key for the config file. Can also include help message details.
50  *
51  * \ingroup mxApp
52  */
54 {
55  std::string name; ///<The name of the target
56  std::string shortOpt; ///< The command-line short option (e.g. "f" for -f)
57  std::string longOpt; ///< The command-line long option (e.g. "file" for --file)
58  int clType {0}; ///< The command-line option type, argType::false, argType::true, argType::optional, argType::required
59  std::string section; ///< The config file section name, can be empty ""
60  std::string keyword; ///< The config file keyword, read in a "keyword=value" pair
61  bool set {false}; ///< true if the value has been set by the configuration, use to distinguish empty strings
62 
63 
64  bool isRequired {false}; ///< Whether or not this is option is required to be set.
65  std::string helpType; ///< The type to display in the help message.
66  std::string helpExplanation; ///< The explanation to display in the help message.
67 
68 
69  std::vector<std::string> values; ///< holds the values in the order they are set by the configuration
70  std::vector<std::string> sources; ///< holds the sources of the values (command line or config file path)
71 
72  int verbosity {0}; ///< Records the verbosity of command line options. E.g. for -v:1, -vv:2, -vvv:3 etc.
73  int orderAdded {0}; ///< The order in which this was added. Useful for displaying help messages.
74 
75  bool used {false};
76 
77  /// Default c'tor
79  {
80  }
81 
82  /// Construct and set values
83  configTarget( const std::string &n, ///< [in] The name of the target
84  const std::string &so, ///< [in] The command-line short option (e.g. "f" for -f)
85  const std::string &lo, ///< [in] The command-line long option (e.g. "file" for --file)
86  int clt, ///< [in] The command-line option type, argType::false, argType::true, argType::optional, argType::required
87  const std::string & s, ///< [in] The config file section name, can be empty ""
88  const std::string & kw, ///< [in] The config file keyword, read in a "keyword=value" pair
89  bool isReq = false, ///< [in] Whether or not this is option is required to be set
90  const std::string & ht = "", ///< [in] The type to display in the help message
91  const std::string & he = "", ///< [in] The explanation to display in the help message
92  int oa = 0 ///< [in] [optional] ///< the order in which this was added.
93  ) : name(n), shortOpt(so), longOpt(lo), clType (clt), section(s), keyword(kw), isRequired(isReq), helpType(ht), helpExplanation(he), orderAdded(oa)
94  {
95  }
96 };
97 
98 
99 
100 
101 } //namespace app
102 } //namespace mx
103 
104 #endif // appConfigurator_hpp
The mxlib c++ namespace.
Definition: mxError.hpp:107
A configuration target.
std::vector< std::string > values
holds the values in the order they are set by the configuration
bool set
true if the value has been set by the configuration, use to distinguish empty strings
std::string helpExplanation
The explanation to display in the help message.
int clType
The command-line option type, argType::false, argType::true, argType::optional, argType::required.
std::string keyword
The config file keyword, read in a "keyword=value" pair.
int orderAdded
The order in which this was added. Useful for displaying help messages.
int verbosity
Records the verbosity of command line options. E.g. for -v:1, -vv:2, -vvv:3 etc.
configTarget(const std::string &n, const std::string &so, const std::string &lo, int clt, const std::string &s, const std::string &kw, bool isReq=false, const std::string &ht="", const std::string &he="", int oa=0)
Construct and set values.
configTarget()
Default c'tor.
std::string section
The config file section name, can be empty "".
std::string helpType
The type to display in the help message.
std::vector< std::string > sources
holds the sources of the values (command line or config file path)
std::string name
The name of the target.
std::string shortOpt
The command-line short option (e.g. "f" for -f)
std::string longOpt
The command-line long option (e.g. "file" for –file)
bool isRequired
Whether or not this is option is required to be set.