Line data Source code
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 : #include "../mxlib.hpp"
34 : #include "../ioutils/stringUtils.hpp"
35 : #include "../meta/trueFalseT.hpp"
36 : #include "../meta/typeTraits.hpp"
37 : #include "../meta/typeDescription.hpp"
38 :
39 :
40 : namespace mx
41 : {
42 : namespace app
43 : {
44 :
45 : /// A configuration target
46 : /** Specifies the details of a configuration target, which is a value that can be set from the command line and/or a
47 : * config file. A target has a name used as a key for accessing it, and defines how it is set with short and long
48 : * command line options and the section and key for the config file. Can also include help message details.
49 : *
50 : * \ingroup mxApp
51 : */
52 : struct configTarget
53 : {
54 : std::string name; ///< The name of the target
55 : std::string shortOpt; ///< The command-line short option (e.g. "f" for -f)
56 : std::string longOpt; ///< The command-line long option (e.g. "file" for --file)
57 : int clType{ 0 }; /**< The command-line option type, argType::false, argType::true, argType::optional,
58 : 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 : bool isRequired{ false }; ///< Whether or not this is option is required to be set.
64 : std::string helpType; ///< The type to display in the help message.
65 : std::string helpExplanation; ///< The explanation to display in the help message.
66 :
67 : std::vector<std::string> values; ///< holds the values in the order they are set by the configuration
68 : std::vector<std::string> sources; ///< holds the sources of the values (command line or config file path)
69 :
70 : int verbosity{ 0 }; ///< Records the verbosity of command line options. E.g. for -v:1, -vv:2, -vvv:3 etc.
71 : int orderAdded{ 0 }; ///< The order in which this was added. Useful for displaying help messages.
72 :
73 : bool used{ false };
74 :
75 : /// Default c'tor
76 11 : configTarget()
77 11 : {
78 11 : }
79 :
80 : /// Construct and set values
81 774 : configTarget( const std::string &n, ///< [in] The name of the target
82 : const std::string &so, ///< [in] The command-line short option (e.g. "f" for -f)
83 : const std::string &lo, ///< [in] The command-line long option (e.g. "file" for --file)
84 : int clt, ///< [in] The command-line option type, argType::false, argType::true, argType::optional,
85 : ///< argType::required
86 : const std::string &s, ///< [in] The config file section name, can be empty ""
87 : const std::string &kw, ///< [in] The config file keyword, read in a "keyword=value" pair
88 : bool isReq = false, ///< [in] Whether or not this is option is required to be set
89 : const std::string &ht = "", ///< [in] The type to display in the help message
90 : const std::string &he = "", ///< [in] The explanation to display in the help message
91 : int oa = 0 ///< [in] [optional] ///< the order in which this was added.
92 : )
93 774 : : name( n ), shortOpt( so ), longOpt( lo ), clType( clt ), section( s ), keyword( kw ), isRequired( isReq ),
94 774 : helpType( ht ), helpExplanation( he ), orderAdded( oa )
95 : {
96 774 : }
97 : };
98 :
99 : } // namespace app
100 : } // namespace mx
101 :
102 : #endif // appConfigurator_hpp
|