ALib C++ Framework
by
Library Version: 2605 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
variables/plugins.hpp
Go to the documentation of this file.
1//==================================================================================================
2/// \file
3/// This header-file is part of module \alib_variables of the \aliblong.
4///
5/// Copyright 2013-2026 A-Worx GmbH, Germany.
6/// Published under #"mainpage_license".
7//==================================================================================================
9
10//==================================================================================================
11/// Specialization of abstract interface class #"ConfigurationPlugin", which reads command-line
12/// parameters from namespace globals #"alib::ARG_C;2" and #"alib::ARG_VN;2" / #"ARG_VW;2" on
13/// request.
14/// Its priority value usually is #"Priority::CLI", which is higher
15/// than all other default plug-ins provided.
16///
17/// To recognize variables, the separation character <c>'/'</c> of the configuration tree is
18/// converted to underscore character <c>'_'</c>. For example, the \alib locale variable with path
19/// ALIB/LOCALE
20/// is recognized as
21/// ALIB_LOCALE
22///
23/// Variable names are insensitive in respect to character case.
24///
25/// Command line variables may be passed with either one hyphen ('-') or two ('--').
26/// Both are accepted.
27///
28/// An application can specify one or more "default categories" by adding their string names to
29/// public field #".DefaultCategories". Variables of these categories are recognized by the plug-in
30/// also when given without the name prefix of category name and underscore \c '_'.
31//==================================================================================================
33 public:
34 /// If any value is added to this vector, its values are used as the source of command-line
35 /// arguments instead of using \alib namespace variables #"ARG_C;2" and
36 /// #"ARG_VN;2" / #"ARG_VW;2".<br>
37 /// This mechanic provides an alternative method to set the command-line argument list.
38 ///
39 /// Applications that have a dedicated (more sophisticated) CLI interface which performs
40 /// more complex processing of CLI arguments, may collect any unrecognized
41 /// CLI argument here to be duly recognized as a configuration variable instead
43
44 /// An application can specify one or more "default categories" by adding a prefix of the
45 /// variable path here. Variables of these "categories" are recognized by the plug-in also
46 /// when given without this prefix.<br>
47 /// Please note, that if \alib and \alox variables should be abbreviatable, for example, that
48 /// the locale can be given with
49 /// --locale=de_DE.UTF-8
50 /// instead of
51 /// --alib_locale=de_DE.UTF-8
52 /// this vector has to be populated during bootstrap phase #"BootstrapPhases::PrepareConfig".
53 /// See chapter #"alib_mod_bs_customize" for more information on how to
54 /// customize \alib bootstrapping.
56
57 /// Determines whether zero, one or two introducing hyphen characters <c>'-'</c> are mandatory.
58 /// An command-line argument is ignored if the number of leading hyphens is smaller than
59 /// the value set here.<br>
60 /// Defaults to \c 0.
61 /// @see Sibling option #"QtyOptionalHyphens".
63
64 /// Determines whether zero, one or two optional hyphen characters <c>'-'</c> might be given.
65 /// An command-line argument is ignored if the number of leading hyphens is greater than
66 /// the value set here.<br>
67 /// Defaults to \c 2.
68 /// @see Sibling option #"QtyMandatoryHyphens".
69 uint8_t QtyOptionalHyphens = 2;
70
71 /// Constructor.
72 /// @param ma The monotonic allocator to use. This usually is the one of the
73 /// configuration instance.
74 /// @param pPriority The priority that this plug-in uses. Defaults to #"Priority::CLI".
76 CLIVariablesPlugin( MonoAllocator& ma, Priority pPriority= Priority::CLI );
77
78 /// Virtual Destructor.
79 virtual ~CLIVariablesPlugin() override {}
80
81 /// @return The plug-in name, in this case, we read resource variable "CFGPlgCLI".
82 ALIB_DLL virtual String Name() const override;
83
84 /// Searches the variable in the command-line parameters.
85 /// @param name The name of the variable to retrieve.
86 /// @param[out] target A reference to the buffer to write the variable's exported value to.
87 /// @return \c true if variable was found, \c false if not.
88 ALIB_DLL virtual bool Get( const String& name, AString& target ) override;
89};
90
91//==================================================================================================
92/// Specialization of abstract interface class #"ConfigurationPlugin", retrieves configuration
93/// data from the system environment.
94///
95/// The priority value of this plug-in usually is #"Priority::Environment",
96/// which is higher than #"var Priority::Standard" but lower than #"Priority::CLI".
97///
98/// To recognize variables, the separation character <c>'/'</c> of the configuration tree is
99/// converted to underscore character <c>'_'</c>. For example, the \alib locale variable with path
100/// ALIB/LOCALE
101/// is recognized as
102/// ALIB_LOCALE
103///
104/// Category and Variable names are insensitive in respect to character case.
105//==================================================================================================
107 public:
108 /// An application can specify one or more "default categories" by adding a prefix of the
109 /// variable path here. Variables of these "categories" are recognized by the plug-in also
110 /// when given without this prefix.<br>
111 /// Please note, that if \alib and \alox variables should be abbreviatable, for example, that
112 /// the locale can be given with
113 /// --locale=de_DE.UTF-8
114 /// instead of
115 /// --alib_locale=de_DE.UTF-8
116 /// this vector has to be populated during bootstrap phase #"BootstrapPhases::PrepareConfig".
117 /// See chapter #"alib_mod_bs_customize" for more information on how to
118 /// customize \alib bootstrapping.
120
121 /// Constructor.
122 /// @param ma The monotonic allocator to use. This usually is the one of the
123 /// configuration instance.
124 /// @param pPriority The priority that this plug-in uses. Defaults to #"Priority::Environment".
126 Priority pPriority = Priority::Environment );
127
128 /// Virtual Destructor.
129 virtual ~EnvironmentVariablesPlugin() override {}
130
131 /// @return The name of the plug-in, in this case, the value of the resource variable
132 /// \b "CFGPlgEnv".
133 ALIB_DLL virtual String Name() const override;
134
135 /// Searches the variable in the environment.
136 /// @param name The name of the variable to retrieve.
137 /// @param[out] target A reference to the buffer to write the variable's exported value to.
138 /// @return \c true if variable was found, \c false if not.
139 ALIB_DLL virtual bool Get( const String& name, AString& target ) override;
140};
141
142} // namespace [alib::variables]
#define ALIB_DLL
#define ALIB_EXPORT
CLIVariablesPlugin(MonoAllocator &ma, Priority pPriority=Priority::CLI)
Definition plugins.cpp:7
virtual ~CLIVariablesPlugin() override
Virtual Destructor.
virtual String Name() const override
Definition plugins.cpp:12
virtual bool Get(const String &name, AString &target) override
Definition plugins.cpp:20
EnvironmentVariablesPlugin(MonoAllocator &ma, Priority pPriority=Priority::Environment)
Definition plugins.cpp:103
virtual bool Get(const String &name, AString &target) override
Definition plugins.cpp:116
virtual ~EnvironmentVariablesPlugin() override
Virtual Destructor.
virtual String Name() const override
Definition plugins.cpp:108
monomem::TMonoAllocator< lang::HeapAllocator > MonoAllocator
strings::util::TStringVector< character, MonoAllocator > StringVectorMA
Type alias in namespace #"%alib".
Definition vector.hpp:107
strings::TString< character > String
Type alias in namespace #"%alib".
Definition string.hpp:2165
strings::TAString< character, lang::HeapAllocator > AString
Type alias in namespace #"%alib".