ALib C++ Library
Library Version: 2511 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
plugins.mpp
Go to the documentation of this file.
1//==================================================================================================
2/// \file
3/// This header-file is part of the \aliblong.
4/// With supporting legacy or module builds, .mpp-files are either recognized by the build-system
5/// as C++20 Module interface files, or are included by the
6/// \ref alib_manual_modules_impludes "import/include headers".
7///
8/// \emoji :copyright: 2013-2025 A-Worx GmbH, Germany.
9/// Published under \ref mainpage_license "Boost Software License".
10//==================================================================================================
11#if !defined(ALIB_C20_MODULES) || ((ALIB_C20_MODULES != 0) && (ALIB_C20_MODULES != 1))
12# error "Symbol ALIB_C20_MODULES has to be given to the compiler as either 0 or 1"
13#endif
14#if ALIB_C20_MODULES
15 module;
16#endif
17//========================================= Global Fragment ========================================
20
21#include "ALib.Strings.Vector.H"
22#if ALIB_DEBUG_BOXING
23# include <vector>
24#endif
25//============================================== Module ============================================
26#if ALIB_C20_MODULES
27 /// This is a <em><b>C++ Module</b></em> of the \aliblong.
28 /// Due to the dual-compile option (either as C++20 Modules or using legacy C++ inclusion),
29 /// the C++20 Module names are not of further interest or use.<br>
30 /// In general, the names equal the names of the header files listed in the chapter
31 /// \ref alib_manual_modules_impludes of the \alib User Manual.
32 ///
33 /// @see The documentation of the <em><b>"ALib Module"</b></em> given with the corresponding
34 /// Programmer's Manual \alib_variables.
35 export module ALib.Variables.Plugins;
36 import ALib.Variables;
37 import ALib.Monomem;
38 import ALib.Strings;
39#else
40#include "ALib.Variables.H"
41#include "ALib.Monomem.H"
42#include "ALib.Strings.H"
43#endif
44
45//============================================= Exports ============================================
47
48//==================================================================================================
49/// Specialization of abstract interface class #ConfigurationPlugin, which reads command line
50/// parameters from namespace globals #alib::ARG_C and #alib::ARG_VN / \alib{ARG_VW} on request.
51/// Its priority value usually is \alib{variables;Priority;Priority::CLI}, which is higher
52/// than all other default plug-ins provided.
53///
54/// To recognize variables, the separation character <c>'/'</c> of the configuration tree is
55/// converted to underscore character <c>'_'</c>. For example, the \alib locale variable with path
56/// ALIB/LOCALE
57/// is recognized as
58/// ALIB_LOCALE
59///
60/// Variable names are insensitive in respect to character case.
61///
62/// Command line variables may be passed with either one hyphen ('-') or two ('--').
63/// Both are accepted.
64///
65/// An application can specify one or more "default categories" by adding their string names to
66/// public field #DefaultCategories. Variables of these categories are recognized by the plug-in
67/// also when given without the name prefix of category name and underscore \c '_'.
68//==================================================================================================
70{
71 public:
72 /// If any value is added to this vector, its values are used as the source of command line
73 /// arguments instead of using \alib namespace variables \alib{ARG_C} and
74 /// \alib{ARG_VN}/\alib{ARG_VW}.<br>
75 /// This mechanic provides an alternative method to set the command line argument list.
76 ///
77 /// Applications that have a dedicated (more sophisticated) CLI interface which performs
78 /// more complex processing of CLI arguments, may collect any unrecognized
79 /// CLI argument here to be duly recognized as a configuration variable instead
81
82 /// An application can specify one or more "default categories" by adding a prefix of the
83 /// variable path here. Variables of these "categories" are recognized by the plug-in also
84 /// when given without this prefix.<br>
85 /// Please note, that if \alib and \alox variables should be abbreviatable, for example, that
86 /// the locale can be given with
87 /// --locale=de_DE.UTF-8
88 /// instead of
89 /// --alib_locale=de_DE.UTF-8
90 /// this vector has to be populated during bootstrap phase \alib{BootstrapPhases;PrepareConfig}.
91 /// See chapter \ref alib_mod_bs_customize for more information on how to
92 /// customize \alib bootstrapping.
94
95 /// Determines whether zero, one or two introducing hyphen characters <c>'-'</c> are mandatory.
96 /// An command line argument is ignored if the number of leading hyphens is smaller than
97 /// the value set here.<br>
98 /// Defaults to \c 0.
99 /// @see Sibling option #QtyOptionalHyphens.
101
102 /// Determines whether zero, one or two optional hyphen characters <c>'-'</c> might be given.
103 /// An command line argument is ignored if the number of leading hyphens is greater than
104 /// the value set here.<br>
105 /// Defaults to \c 2.
106 /// @see Sibling option #QtyMandatoryHyphens.
108
109 /// Constructor.
110 /// @param ma The monotonic allocator to use. This usually is the one of the
111 /// configuration instance.
112 /// @param pPriority The priority that this plug-in uses. Defaults to
113 /// \alib{variables;Priority;CLI}.
115 CLIVariablesPlugin( MonoAllocator& ma, Priority pPriority= Priority::CLI );
116
117 /// Virtual Destructor.
118 virtual ~CLIVariablesPlugin() override {}
119
120 /// @return The plug-in name, in this case, we read resource variable "CFGPlgCLI".
121 ALIB_DLL virtual String Name() const override;
122
123 /// Searches the variable in the command line parameters.
124 /// @param name The name of the variable to retrieve.
125 /// @param[out] target A reference to the buffer to write the variable's exported value to.
126 /// @return \c true if variable was found, \c false if not.
127 ALIB_DLL virtual bool Get( const String& name, AString& target ) override;
128};
129
130//==================================================================================================
131/// Specialization of abstract interface class #ConfigurationPlugin, retrieves configuration
132/// data from the system environment.
133///
134/// The priority value of this plug-in usually is \alib{variables;Priority;Priority::Environment},
135/// which is higher than \alib{variables;Priority;Standard} but lower than \alib{variables;Priority;CLI}.
136///
137/// To recognize variables, the separation character <c>'/'</c> of the configuration tree is
138/// converted to underscore character <c>'_'</c>. For example, the \alib locale variable with path
139/// ALIB/LOCALE
140/// is recognized as
141/// ALIB_LOCALE
142///
143/// Category and Variable names are insensitive in respect to character case.
144//==================================================================================================
146{
147 public:
148 /// An application can specify one or more "default categories" by adding a prefix of the
149 /// variable path here. Variables of these "categories" are recognized by the plug-in also
150 /// when given without this prefix.<br>
151 /// Please note, that if \alib and \alox variables should be abbreviatable, for example, that
152 /// the locale can be given with
153 /// --locale=de_DE.UTF-8
154 /// instead of
155 /// --alib_locale=de_DE.UTF-8
156 /// this vector has to be populated during bootstrap phase \alib{BootstrapPhases;PrepareConfig}.
157 /// See chapter \ref alib_mod_bs_customize for more information on how to
158 /// customize \alib bootstrapping.
160
161 /// Constructor.
162 /// @param ma The monotonic allocator to use. This usually is the one of the
163 /// configuration instance.
164 /// @param pPriority The priority that this plug-in uses. Defaults to
165 /// \alib{variables;Priority;Environment}.
167 Priority pPriority = Priority::Environment );
168
169 /// Virtual Destructor.
170 virtual ~EnvironmentVariablesPlugin() override {}
171
172 /// @return The name of the plug-in, in this case, the value of resource variable "CFGPlgEnv".
173 ALIB_DLL virtual String Name() const override;
174
175 /// Searches the variable in the environment.
176 /// @param name The name of the variable to retrieve.
177 /// @param[out] target A reference to the buffer to write the variable's exported value to.
178 /// @return \c true if variable was found, \c false if not.
179 ALIB_DLL virtual bool Get( const String& name, AString& target ) override;
180};
181
182} // namespace [alib::variables]
ALIB_DLL CLIVariablesPlugin(MonoAllocator &ma, Priority pPriority=Priority::CLI)
Definition plugins.cpp:41
virtual ~CLIVariablesPlugin() override
Virtual Destructor.
Definition plugins.mpp:118
virtual ALIB_DLL String Name() const override
Definition plugins.cpp:46
virtual ALIB_DLL bool Get(const String &name, AString &target) override
Definition plugins.cpp:54
ALIB_DLL EnvironmentVariablesPlugin(MonoAllocator &ma, Priority pPriority=Priority::Environment)
Definition plugins.cpp:137
virtual ALIB_DLL bool Get(const String &name, AString &target) override
Definition plugins.cpp:150
virtual ~EnvironmentVariablesPlugin() override
Virtual Destructor.
Definition plugins.mpp:170
virtual ALIB_DLL String Name() const override
Definition plugins.cpp:142
#define ALIB_DLL
Definition alib.inl:503
#define ALIB_EXPORT
Definition alib.inl:497
strings::TAString< character, lang::HeapAllocator > AString
Type alias in namespace alib.
strings::util::TStringVector< character, MonoAllocator > StringVectorMA
Type alias in namespace alib.
monomem::TMonoAllocator< lang::HeapAllocator > MonoAllocator
strings::TString< character > String
Type alias in namespace alib.
Definition string.inl:2189