SNode.C
Loading...
Searching...
No Matches
ConfigApp.h
Go to the documentation of this file.
1/*
2 * SNode.C - A Slim Toolkit for Network Communication
3 * Copyright (C) Volker Christian <me@vchrist.at>
4 * 2020, 2021, 2022, 2023, 2024, 2025, 2026
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published
8 * by the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20/*
21 * MIT License
22 *
23 * Permission is hereby granted, free of charge, to any person obtaining a copy
24 * of this software and associated documentation files (the "Software"), to deal
25 * in the Software without restriction, including without limitation the rights
26 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
27 * copies of the Software, and to permit persons to whom the Software is
28 * furnished to do so, subject to the following conditions:
29 *
30 * The above copyright notice and this permission notice shall be included in
31 * all copies or substantial portions of the Software.
32 *
33 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
39 * THE SOFTWARE.
40 */
41
42#ifndef UTILS_CONFIGAPP_H
43#define UTILS_CONFIGAPP_H
44
45#ifndef DOXYGEN_SHOULD_SKIP_THIS
46
47namespace CLI {
48 class App;
49 class Option;
50 class Formatter;
51} // namespace CLI
52
53#include <map>
54#include <memory>
55#include <string>
56
57#ifdef __GNUC__
58#pragma GCC diagnostic push
59#pragma GCC diagnostic ignored "-Wfloat-equal"
60#ifdef __has_warning
61#if __has_warning("-Wweak-vtables")
62#pragma GCC diagnostic ignored "-Wweak-vtables"
63#endif
64#if __has_warning("-Wcovered-switch-default")
65#pragma GCC diagnostic ignored "-Wcovered-switch-default"
66#endif
67#if __has_warning("-Wmissing-noreturn")
68#pragma GCC diagnostic ignored "-Wmissing-noreturn"
69#endif
70#if __has_warning("-Wnrvo")
71#pragma GCC diagnostic ignored "-Wnrvo"
72#endif
73#endif
74#endif
75#include "utils/CLI11.hpp" // IWYU pragma: export
76#ifdef __GNUC__
77#pragma GCC diagnostic pop
78#endif
79
80#endif /* DOXYGEN_SHOULD_SKIP_THIS */
81
82namespace utils {
83
84 template <class T>
85 struct AppWithPtr : CLI::App {
86 AppWithPtr(const std::string& description, const std::string& name, T* t);
87
88 const T* getPtr() const;
89
90 T* getPtr();
91
92 private:
93 T* ptr = nullptr;
94 };
95
96 template <class T>
97 AppWithPtr<T>::AppWithPtr(const std::string& description, const std::string& name, T* t)
98 : CLI::App(description, name)
99 , ptr(t) {
100 }
101
102 template <class T>
103 const T* AppWithPtr<T>::getPtr() const {
104 return ptr;
105 }
106
107 template <class T>
109 return ptr;
110 }
111
112} // namespace utils
113
114#endif // UTILS_CONFIGAPP_H
CLI::Option * htmlRootOpt
Definition ConfigWWW.h:89
ConfigWWW & setHtmlRoot(const std::string &htmlRoot)
Definition ConfigWWW.cpp:86
std::string getHtmlRoot()
Definition ConfigWWW.cpp:96
static constexpr std::string_view name
Definition ConfigWWW.h:79
static constexpr std::string_view description
Definition ConfigWWW.h:80
CLI::App * configWWWSc
Definition ConfigWWW.h:88
CLI::App * newSection(std::shared_ptr< CLI::App > appWithPtr, const std::string &group)
const std::string & getInstanceName() const
CLI::Option * addOption(const std::string &name, const std::string &description, const std::string &typeName)
CLI::Option * addOption(const std::string &name, const std::string &description, const std::string &typeName, ValueTypeT defaultValue)
CLI::Option * addOption(const std::string &name, const std::string &description, const std::string &typeName, ValueTypeT defaultValue, const CLI::Validator &additionalValidator)
CLI::Option * addOptionFunction(const std::string &name, const std::function< void(const std::string &)> &optionFunction, const std::string &description)
ConfigSection(ConfigInstance *instance, T *sectionPtr, const std::string &group="Sections")
CLI::Option * addFlag(const std::string &name, const std::string &description, const std::string &typeName, ValueTypeT defaultValue)
CLI::Option * addFlag(const std::string &name, const std::string &description, const std::string &typeName, ValueTypeT defaultValue, const CLI::Validator &additionalValidator)
CLI::Option * addFlag(const std::string &name, const std::string &description, const std::string &typeName)
void required(CLI::Option *opt, bool req=true)
ConfigWWW(net::config::ConfigInstance *instance)
Definition ConfigWWW.cpp:52
static constexpr std::string_view description
Definition ConfigWWW.h:62
ConfigWWW & setHtmlRoot(const std::string &htmlRoot)
Definition ConfigWWW.cpp:58
std::string getHtmlRoot()
Definition ConfigWWW.cpp:65
static constexpr std::string_view name
Definition ConfigWWW.h:61
CLI::Option * htmlRootOpt
Definition ConfigWWW.h:70
static CLI::Option * enforceLogFileOpt
Definition Config.h:120
static CLI::Option * verboseLevelOpt
Definition Config.h:122
static bool parse1()
Definition Config.cpp:400
static CLI::Option * groupNameOpt
Definition Config.h:119
static bool removeInstance(CLI::App *instance)
Definition Config.cpp:916
static std::string applicationName
Definition Config.h:110
Config(const Config &)=delete
static bool subParse
Definition Config.h:109
static std::map< std::string, std::string > aliases
Definition Config.h:132
static CLI::App * addHelp(CLI::App *app)
Definition Config.cpp:834
static CLI::App * helpTriggerApp
Definition Config.h:126
static std::shared_ptr< CLI::Formatter > sectionFormatter
Definition Config.h:129
static CLI::Option * logFileOpt
Definition Config.h:117
static std::string configDirectory
Definition Config.h:112
static std::shared_ptr< CLI::App > app
Definition Config.h:107
static T * addInstance()
static std::string pidDirectory
Definition Config.h:114
static CLI::App * addSimpleHelp(CLI::App *app)
Definition Config.cpp:850
static T * getInstance()
~Config()=delete
static void terminate()
Definition Config.cpp:698
static std::string getApplicationName()
Definition Config.cpp:922
static CLI::App * showConfigTriggerApp
Definition Config.h:127
static void disabled(CLI::App *instance, bool disabled=true)
Definition Config.cpp:888
static std::vector< std::shared_ptr< void > > configSections
Definition Config.h:135
static int argc
Definition Config.h:104
static CLI::App * addStandardFlags(CLI::App *app)
Definition Config.cpp:770
static CLI::Option * userNameOpt
Definition Config.h:118
static std::map< std::string, CLI::Option * > applicationOptions
Definition Config.h:133
static std::string logDirectory
Definition Config.h:113
static bool init(int argc, char *argv[])
Definition Config.cpp:138
static void required(CLI::App *instance, bool required=true)
Definition Config.cpp:865
Config & operator=(const Config &)=delete
static CLI::Option * quietOpt
Definition Config.h:123
Config()=delete
static CLI::Option * daemonizeOpt
Definition Config.h:116
static bool parse2()
Definition Config.cpp:583
static char ** argv
Definition Config.h:105
static bool bootstrap()
Definition Config.cpp:370
static int getLogLevel()
Definition Config.cpp:926
static CLI::Option * logLevelOpt
Definition Config.h:121
static CLI::App * newInstance(std::shared_ptr< CLI::App > appWithPtr, const std::string &group, bool final=false)
Definition Config.cpp:736
static int getVerboseLevel()
Definition Config.cpp:930
std::shared_ptr< CLI::App > Section(const std::string &name, const std::string &description, T *section)
std::shared_ptr< CLI::App > Section(T *section)
std::shared_ptr< utils::AppWithPtr< T > > Instance(const std::string &name, const std::string &description, T *section)
const T * getPtr() const
Definition ConfigApp.h:103
AppWithPtr(const std::string &description, const std::string &name, T *t)
Definition ConfigApp.h:97