ALib C++ Framework
by
Library Version: 2511 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
variables.prepro.hpp
Go to the documentation of this file.
1//==================================================================================================
2/// \file
3/// This header-file is part of the \aliblong.
4///
5/// \emoji :copyright: 2013-2025 A-Worx GmbH, Germany.
6/// Published under #"mainpage_license".
7//==================================================================================================
8#ifndef HPP_ALIB_VARIABLES_PP
9#define HPP_ALIB_VARIABLES_PP
10#pragma once
11#ifndef INL_ALIB
12# include "alib/alib.inl"
13#endif
14#if ALIB_VARIABLES
15
16//##################################################################################################
17// Enum Priority.
18// Note: This is excluded from the module because it is used by ALox and if it was included, ALox
19// needed to include Configuration in is base module already.
20//##################################################################################################
21namespace alib { namespace variables {
22
23
24//==================================================================================================
25/// #"ArithmeticalTraits;Arithmetical enumeration" used to control write access to
26/// configuration variables, depending on the source of assignable values.
27/// @see Chapter #"alib_variables_definition_prios" of the Programmer's Manual of camp
28/// \alib_variables_nl.
29//==================================================================================================
30enum class Priority : uint16_t
31{
32 /// This priority value denotes that a variable is undefined and has no value set.
33 /// The underlying integral value is \c 0.
34 NONE = 0,
35
36 /// Constant providing a priority which is even lower than default. A use-case for this
37 /// priority are for third party libraries that may preset variables in cases where values are
38 /// estimated or detected instead of defaulted.<br>
39 /// A using code of such library may then overwrite the auto-detection estimates, by setting a
40 /// default value in the configuration.<br>
41 /// This priority is not used internally (by any \alib camp) today.<br>
42 /// The underlying integral value is \c 1,000.
44
45 /// Used to store default values, either from (resourced) declarations, hard-coded values,
46 /// or values provided with the method
47 /// #"Configuration::PresetImportString(StringEscaper*);Configuration::PresetImportString".
48 /// The underlying integral value is \c 2,000.
50
51 /// This is the default priority when a variable is defined for setting a 'hard-coded' value.
52 /// The underlying integral value is \c 4,000. Hard-coded values have a higher priority
53 /// than default values, but are deemed to get overwritten by any other configuration source.
54 Standard = 4000,
55
56 /// External application configuration sources use this element to define variables
57 /// found. This element is also used with built-in class #"IniFileFeeder".
58 /// The underlying integral value is \c 6,000.
59 ConfigFile = 6000,
60
61 /// Used with plug-in #"EnvironmentVariablesPlugin".
62 /// The underlying integral value is \c 8,000.
64
65 /// Used to store temporary session information. Those are higher than \b Environment but lower
66 /// than \b CLI. This session priority is only a proposal. Implementations might use a
67 /// different value, even for different variables, for example, <b>Environment - 1 </b> or
68 /// <b>CLI + 1 </b>. It depends on the use case.<br>
69 /// The underlying integral value is \c 10,000.
70 SessionFile = 10000,
71
72 /// Used with plug-in #"CLIVariablesPlugin".
73 /// The underlying integral value is \c 12,000.
74 CLI = 12000,
75
76 /// Used to store generate temporary session information. While usually changes made in
77 /// source code has a low priority, session information is overwritten by running software, no
78 /// matter from which external source an existing values came.
79 /// If software wants to disallow the change of session information imposed by a library
80 /// or a different software part, still a value can be set to protected.
81 /// The underlying integral value is \c 14,000.
82 Session = 14000,
83
84 /// Used to define variables with protected values. If all code entities apply to the
85 /// #"alib_variables_definition;contract that this camp imposes" in respect to variable
86 /// definitions and priorities, a value set with this priority cannot be manipulated from
87 /// "outside", hence by config files, command-line arguments or any custom configuration source
88 /// or plug-in.
89 ///
90 /// The underlying integral value is <c>std::numeric_limits<int>::max()</c>.
91 Protected = (std::numeric_limits<uint16_t>::max)(),
92
93};
94
95} // namespace alib::[config]
96
97/// Type alias in namespace \b alib.
99
100} // namespace [alib]
101
102//##################################################################################################
103// Macro introduced by module ALib.Variables
104//##################################################################################################
105#define ALIB_VARIABLES_DEFINE_TYPE( Namespace, CPPName,CfgTypeString) \
106ALIB_EXPORT namespace alib::variables::detail { \
107struct VMeta_ ## CPPName : public VMeta \
108{ \
109 ALIB_DLL String typeName () const override { return CfgTypeString; } \
110ALIB_DBG(ALIB_DLL const std::type_info& dbgTypeID() override { return typeid(Namespace CPPName); } ) \
111 ALIB_DLL void construct(VDATA* obj, PoolAllocator&) override { new (obj) Namespace CPPName(); } \
112 ALIB_DLL void destruct (VDATA* obj, PoolAllocator&) override { reinterpret_cast<Namespace CPPName*>(obj)->~CPPName(); } \
113 ALIB_DLL size_t size () override { static_assert(alignof(Namespace CPPName) <= alib::PoolAllocator::MAX_ALIGNMENT); return (std::max)( sizeof(Namespace CPPName), sizeof(void*) ); } \
114 ALIB_DLL void imPort (VDATA*, Configuration&, const StringEscaper&, const String&) override;\
115 ALIB_DLL void exPort (VDATA*, Configuration&, const StringEscaper&, AString&) override;\
116};}
117
118#define ALIB_VARIABLES_DEFINE_TYPE_WITH_POOL_CONSTRUCTOR( Namespace, CPPName,CfgTypeString) \
119ALIB_EXPORT namespace alib::variables::detail { \
120struct VMeta_ ## CPPName : public VMeta \
121{ \
122 ALIB_DLL String typeName () const override { return CfgTypeString; } \
123ALIB_DBG(ALIB_DLL const std::type_info& dbgTypeID() override { return typeid(Namespace CPPName); } ) \
124 ALIB_DLL void construct(VDATA* obj, PoolAllocator& pool) override { new (obj) Namespace CPPName(pool); } \
125 ALIB_DLL void destruct (VDATA* obj, PoolAllocator&) override { reinterpret_cast<Namespace CPPName*>(obj)->~CPPName(); } \
126 ALIB_DLL size_t size () override { static_assert(alignof(Namespace CPPName) <= alib::PoolAllocator::MAX_ALIGNMENT); return (std::max)( sizeof(Namespace CPPName), sizeof(void*) ); } \
127 ALIB_DLL void imPort (VDATA*, Configuration&, const StringEscaper&, const String&) override;\
128 ALIB_DLL void exPort (VDATA*, Configuration&, const StringEscaper&, AString&) override;\
129};}
130
131
132#define ALIB_VARIABLES_REGISTER_TYPE(CPPName) \
133 GetConfig()->RegisterType<alib::variables::detail::VMeta_ ## CPPName>();
134
135
136
137#endif
138#endif // HPP_ALIB_VARIABLES_PP
alib::variables::Priority Priority
Type alias in namespace alib.
cli::CliCamp CLI
The singleton instance of ALib Camp class #"CliCamp".
Definition clicamp.cpp:42