ALib C++ Library
by
Library Version:
2510 R0
Documentation generated by
Loading...
Searching...
No Matches
home
dev
A-Worx
ALib
src
alib
variables
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 \ref mainpage_license "Boost Software 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
// #################################################################################################
21
namespace
alib
{
namespace
variables
{
22
23
24
//==================================================================================================
25
/// \alib{enumops;ArithmeticalTraits;Arithmetical enumeration} used to control write access to
26
/// configuration variables, depending on the source of assignable values.
27
/// @see Chapter \ref alib_variables_definition_prios of the Programmer's Manual of camp
28
/// \alib_variables_nl.
29
//==================================================================================================
30
enum 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.
43
AutoDetected
= 1000,
44
45
/// Used to store default values, either from (resourced) declarations, hard-coded values,
46
/// or values provided with method \alib{variables;Configuration::PresetImportString}.
47
/// The underlying integral value is \c 2,000.
48
DefaultValues
= 2000,
49
50
/// This is the default priority when a variable is defined for setting a 'hard-coded' value.
51
/// The underlying integral value is \c 4,000. Hard-coded values have a higher priority
52
/// than default values, but are deemed to get overwritten by any other configuration source.
53
Standard
= 4000,
54
55
/// External application configuration sources use this element to define variables
56
/// found. This element is also used with built-in class \alib{variables;IniFileFeeder}.
57
/// The underlying integral value is \c 6,000.
58
ConfigFile
= 6000,
59
60
/// Used with plug-in \alib{variables;EnvironmentVariablesPlugin}.
61
/// The underlying integral value is \c 8,000.
62
Environment
= 8000,
63
64
/// Used to store temporary session information. Those are higher than \b Environment but lower
65
/// than \b CLI. This session priority is only a proposal. Implementations might use a
66
/// different value, even for different variables, for example <b>Environment - 1 </b> or
67
/// <b>CLI + 1 </b>. It depends on the use case.<br>
68
/// The underlying integral value is \c 10,000.
69
SessionFile
= 10000,
70
71
/// Used with plug-in \alib{variables;CLIVariablesPlugin}.
72
/// The underlying integral value is \c 12,000.
73
CLI
= 12000,
74
75
/// Used to store generate temporary session information. While usually changes made in
76
/// source code has a low priority, session information is overwritten by running software, no
77
/// matter from which external source an existing values came.
78
/// If software wants to disallow the change of session information imposed by a library
79
/// or a different software part, still a value can be set to protected.
80
/// The underlying integral value is \c 14,000.
81
Session
= 14000,
82
83
/// Used to define variables with protected values. If all code entities apply to the
84
/// \ref alib_variables_definition "contract that this camp imposes" in respect to variable
85
/// definitions and priorities, a value set with this priority cannot be manipulated from
86
/// "outside", hence by config files, command line arguments or any custom configuration source
87
/// or plug-in.
88
///
89
/// The underlying integral value is <c>std::numeric_limits<int>::max()</c>.
90
Protected
= (std::numeric_limits<uint16_t>::max)(),
91
92
};
93
94
}
// namespace alib::[config]
95
96
/// Type alias in namespace \b alib.
97
using
Priority
=
alib::variables::Priority
;
98
99
}
// namespace [alib]
100
101
// #################################################################################################
102
// Symbols introduced by module ALib.Variables
103
// #################################################################################################
104
#define ALIB_VARIABLES_DEFINE_TYPE( Namespace, CPPName,CfgTypeString) \
105
ALIB_EXPORT namespace alib::variables::detail { \
106
struct VMeta_ ## CPPName : public VMeta \
107
{ \
108
ALIB_DLL String typeName () const override { return CfgTypeString; } \
109
ALIB_DBG(ALIB_DLL const std::type_info& dbgTypeID() override { return typeid(Namespace CPPName); } ) \
110
ALIB_DLL void construct(void* obj, PoolAllocator&) override { new (obj) Namespace CPPName(); } \
111
ALIB_DLL void destruct (void* obj, PoolAllocator&) override { reinterpret_cast<Namespace CPPName*>(obj)->~CPPName(); } \
112
ALIB_DLL size_t size () override { static_assert(alignof(Namespace CPPName) <= alib::PoolAllocator::MAX_ALIGNMENT); return (std::max)( sizeof(Namespace CPPName), sizeof(void*) ); } \
113
ALIB_DLL void imPort (VDATA*, Configuration&, const StringEscaper&, const String&) override;\
114
ALIB_DLL void exPort (VDATA*, Configuration&, const StringEscaper&, AString&) override;\
115
};}
116
117
#define ALIB_VARIABLES_DEFINE_TYPE_WITH_POOL_CONSTRUCTOR( Namespace, CPPName,CfgTypeString) \
118
ALIB_EXPORT namespace alib::variables::detail { \
119
struct VMeta_ ## CPPName : public VMeta \
120
{ \
121
ALIB_DLL String typeName () const override { return CfgTypeString; } \
122
ALIB_DBG(ALIB_DLL const std::type_info& dbgTypeID() override { return typeid(Namespace CPPName); } ) \
123
ALIB_DLL void construct(void* obj, PoolAllocator& pool) override { new (obj) Namespace CPPName(pool); } \
124
ALIB_DLL void destruct (void* obj, PoolAllocator&) override { reinterpret_cast<Namespace CPPName*>(obj)->~CPPName(); } \
125
ALIB_DLL size_t size () override { static_assert(alignof(Namespace CPPName) <= alib::PoolAllocator::MAX_ALIGNMENT); return (std::max)( sizeof(Namespace CPPName), sizeof(void*) ); } \
126
ALIB_DLL void imPort (VDATA*, Configuration&, const StringEscaper&, const String&) override;\
127
ALIB_DLL void exPort (VDATA*, Configuration&, const StringEscaper&, AString&) override;\
128
};}
129
130
131
#define ALIB_VARIABLES_REGISTER_TYPE(CPPName) \
132
GetConfig()->RegisterType<alib::variables::detail::VMeta_ ## CPPName>();
133
134
135
136
#endif
137
#endif
// HPP_ALIB_VARIABLES_PP
138
alib.inl
alib::variables
Definition
camp.inl:341
alib::variables::Priority
Priority
Definition
variables.prepro.hpp:31
alib::variables::Priority::Environment
@ Environment
Definition
variables.prepro.hpp:62
alib::variables::Priority::ConfigFile
@ ConfigFile
Definition
variables.prepro.hpp:58
alib::variables::Priority::Protected
@ Protected
Definition
variables.prepro.hpp:90
alib::variables::Priority::SessionFile
@ SessionFile
Definition
variables.prepro.hpp:69
alib::variables::Priority::Session
@ Session
Definition
variables.prepro.hpp:81
alib::variables::Priority::CLI
@ CLI
Definition
variables.prepro.hpp:73
alib::variables::Priority::AutoDetected
@ AutoDetected
Definition
variables.prepro.hpp:43
alib::variables::Priority::NONE
@ NONE
Definition
variables.prepro.hpp:34
alib::variables::Priority::Standard
@ Standard
Definition
variables.prepro.hpp:53
alib::variables::Priority::DefaultValues
@ DefaultValues
Definition
variables.prepro.hpp:48
alib
Definition
ALib.Boxing.StdFunctors.H:18
alib::Priority
alib::variables::Priority Priority
Type alias in namespace alib.
Definition
erpriority.inl:32