ALib C++ Library
Library Version: 2412 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
aloxcamp.hpp
Go to the documentation of this file.
1//==================================================================================================
2/// \file
3/// This header file is part of module \alib_alox of the \aliblong.
4///
5/// \emoji :copyright: 2013-2024 A-Worx GmbH, Germany.
6/// Published under \ref mainpage_license "Boost Software License".
7//==================================================================================================
8#ifndef HPP_ALIB_ALOX_CAMP
9#define HPP_ALIB_ALOX_CAMP 1
10#pragma once
11#if !defined(DOXYGEN)
12# include "alib/alib.hpp"
13#endif
15
16#include "alib/alox/alox.hpp"
20
21namespace alib { namespace lox {
22
23//==================================================================================================
24/// Configuration variables uses by ALox.
25/// \note
26/// As required by module \alib_config, this enumerations is equipped with
27/// \ref alib_enums_records "ALib Enum Records" of type \alib{config;Declaration} and resourced
28/// with this module \alib_alox_nl.<br>
29/// Hence, all variable categories, names, default values and such can be modified
30/// by modifying the resource data of the singleton of class \alib{lang::basecamp;BaseCamp}.
31//==================================================================================================
32enum class Variables
33{
34 /// Denotes configuration variable \ref alxcvALOX_NO_IDE_LOGGER used by \alox{Log::AddDebugLogger}.
35 NO_IDE_LOGGER = 1,
36
37 /// Denotes configuration variable \ref alxcvALOX_CONSOLE_TYPE used by \alox{Lox::CreateConsoleLogger}.
38 CONSOLE_TYPE = 2,
39
40 /// Denotes configuration variable \ref alxcvALOX_LOGGERNAME_VERBOSITY_WITH_LOXNAME.
41 VERBOSITY = 3,
42
43 /// Denotes configuration variable \ref alxcvALOX_GLOBAL_SOURCE_PATH_TRIM_RULES.
44 SPTR_GLOBAL = 4,
45
46 /// Denotes configuration variable \ref alxcvALOX_LOXNAME_SOURCE_PATH_TRIM_RULES used by class \alox{Lox}.
47 SPTR_LOX = 5,
48
49 /// Denotes configuration variable \ref alxcvALOX_LOXNAME_DOMAIN_SUBSTITUTION used by class \alox{Lox}.
51
52 /// Denotes configuration variable \ref alxcvALOX_LOXNAME_PREFIXES used by class \alox{Lox}.
53 PREFIXES = 7,
54
55 /// Denotes configuration variable \ref alxcvALOX_LOXNAME_DUMP_STATE_ON_EXIT used by class \alox{Lox}.
57
58 /// Denotes configuration variable \ref alxcvALOX_LOGGERNAME_AUTO_SIZES used by class \alox{textlogger,TextLogger}.
59 AUTO_SIZES = 20,
60
61 /// Denotes configuration variable \ref alxcvALOX_LOGGERNAME_FORMAT used by class \alox{textlogger,TextLogger}.
62 FORMAT = 21,
63
64 /// Denotes configuration variable \ref alxcvALOX_LOGGERNAME_FORMAT_DATE_TIME used by class \alox{textlogger,TextLogger}.
66
67 /// Denotes configuration variable \ref alxcvALOX_LOGGERNAME_FORMAT_MULTILINE used by class \alox{textlogger,TextLogger}.
69
70 /// Denotes configuration variable \ref alxcvALOX_LOGGERNAME_FORMAT_TIME_DIFF used by class \alox{textlogger,TextLogger}.
72
73 /// Denotes configuration variable \ref alxcvALOX_LOGGERNAME_FORMAT_OTHER used by class \alox{textlogger,TextLogger}.
74 FORMAT_OTHER = 25,
75
76 /// Denotes configuration variable \ref alxcvALOX_LOGGERNAME_REPLACEMENTS used by class \alox{textlogger,TextLogger}.
77 REPLACEMENTS = 26,
78
79 /// Denotes configuration variable \ref alxcvALOX_CONSOLE_LIGHT_COLORS used by colorful specializations of class \alox{textlogger,TextLogger}.
81
82 #if defined(_WIN32)
83 /// Denotes configuration variable \ref alxcvALOX_CODEPAGE used by class \alox{loggers,WindowsConsoleLogger}.
84 CODEPAGE = 28,
85 #endif
86};
87
88//==================================================================================================
89/// Variable data struct, defining the verbosities of the domains of a \e Logger in a \e Lox.
90/// This struct is used with the \ref alib_mod_config "configuration variable" named
91/// \ref alxcvALOX_LOGGERNAME_VERBOSITY_WITH_LOXNAME.
92///
93/// Note that during the run of a software, the verbosity values are stored differently and this
94/// variable type is only for importing and exporting such values to external systems.
95//==================================================================================================
96struct CVVerbosities : protected StringVectorPA
97{
98 bool ExportAll= false; ///< Determines whether only the minimum necessary domain tree
99 ///< is written when verbosities are exported.
100 ///< If \c true, redundant verbosity information is given,
101 ///< even if Subdomains have the same value.
102 /// Constructor.
103 /// @param pAllocator The allocator to use.
105 : StringVectorPA(pAllocator) {}
106
107 /// Destructor. Frees all allocated strings.
109
111 using StringVectorPA::begin;
112 using StringVectorPA::end;
114
115 /// @return \c true if this vector is empty, \c false otherwise.
116 bool IsEmpty() { return empty(); }
117
118 /// Frees all allocated strings and clears vector.
119 void Clear()
120 {
121 for ( auto it = begin() ; it != end() ; ++it )
122 it->Free( GetAllocator() );
123 clear();
124 }
125};
126
127//==================================================================================================
128/// This is the module class for \alox logging library residing in namespace \ref alib::lox.
129///
130/// This is a strict singleton class. The only instance is found with namespace variable
131/// \ref alib::ALOX.
132//==================================================================================================
133class ALoxCamp : public lang::Camp
134{
135 public:
136 //==========================================================================================
137 /// Constructor.<br>
138 /// While this is public, it must not be invoked as this is a strict singleton type.
139 /// (See notes in \ref alib_manual_camp_modules_campmodule).
140 //==========================================================================================
141 ALoxCamp();
142
143 // #############################################################################################
144 // Public fields
145 // #############################################################################################
146 public:
147
148 #if defined(_WIN32)
149 /// Attributes of corresponding configuration variable \ref alxcvALOX_CODEPAGE
150 /// used by class \alox{loggers,WindowsConsoleLogger}.
152 #endif
153
154 // #############################################################################################
155 // Protected fields
156 // #############################################################################################
157 protected:
158
159 // #############################################################################################
160 // Lox management
161 // #############################################################################################
162 public:
163 //==========================================================================================
164 /// Returns a \b %Lox with the given name.
165 /// A \b %Lox is only found if it was created and registered with \alox using #Register.
166 /// If not found, and parameter \p{create} is \c true (the default), a new \b Lox is created,
167 /// registered and returned.
168 ///
169 /// @param name The name of the \b %Lox to search and optionally to create.
170 /// Comparison is case insensitive.
171 /// @param create Denotes whether a \b %Lox that was not found is created.
172 /// Optional and defaults to \b %CreateIfNotExists::No.
173 /// @return The \b Lox found, \c nullptr in case of failure.
174 //==========================================================================================
175 ALIB_API Lox* Get( const NString& name,
177
178 //==========================================================================================
179 /// Registers or un-registers a \b %Lox object statically with \alox.
180 /// Once registered, any code entity of the same process is enabled to retrieve
181 /// the \b %Lox using #Get.<br>
182 /// No two objects with the same name must be registered. If this is done, the latter
183 /// will not be registered and not be found by #Get. In debug-compilations, an \alib
184 /// error report is written (by default raises 'assert') if a name is registered twice.<br>
185 /// Note that name comparison is performed case <b>in</b>-sensitive.
186 ///
187 /// If debug-logging is enabled (depends on optional compiler symbols) and used, the
188 /// singleton of type \c %Lox provided for debug-logging is registered. This uses the name
189 /// \c "Log".
190 ///
191 /// Registration is \e not mandatory but done by default by the constructor of class \b %Lox.
192 /// Therefore, to keep a \b Lox private, an optional parameter is available.
193 ///
194 /// @param lox The \b %Lox to register.
195 /// @param operation If \b %ContainerOp::Remove, the given \p{Lox} is deregistered.
196 /// Defaults to \b %ContainerOp::Insert.
197 //==========================================================================================
198 ALIB_API void Register( Lox* lox, lang::ContainerOp operation );
199
200 //==========================================================================================
201 /// Resets this object. Concretely, the following steps are performed:
202 /// - If the debug lox singleton exists, it is deleted.
203 /// - It is asserted that no other lox object is registered.
204 /// - The \alox path of the configuration is deleted.
205 ///
206 /// \attention
207 /// This method was introduced to support resetting \alox in the unit tests.
208 /// In real applications, this method should NOT be used.
209 /// Side effects might appear using this method and it is not tested otherwise than
210 /// used in tests!
211 //==========================================================================================
212 ALIB_API void Reset();
213
214 // #############################################################################################
215 // Internals
216 // #############################################################################################
217 protected:
218 //==========================================================================================
219 /// Implementation of \alib{lang;Camp::bootstrap}.
220 /// @param phase The initialization phase to perform.
221 //==========================================================================================
222 virtual void bootstrap( BootstrapPhases phase ) override;
223
224 //==========================================================================================
225 /// Implementation of \alib{lang;Camp::shutdown}.
226 /// @param phase The shutdown phase to perform.
227 //==========================================================================================
228 virtual void shutdown( ShutdownPhases phase ) override;
229
230};// class ALoxCamp
231
232} // namespace alib[::lox]
233
234/// The singleton instance of \alibcamp class \alib{lox;ALoxCamp}.
236
237} // namespace [alib]
238
241
242// #################################################################################################
243// T_Append<Scope> / T_Append<Verbosity>
244// #################################################################################################
245#if !DOXYGEN
246namespace alib::strings {
247
248template<> struct T_Append<Scope,nchar, lang::HeapAllocator>
249{
251 void operator()( TAString<nchar, lang::HeapAllocator>& target, const Scope src );
252};
253
254template<> struct T_Append<std::pair<Verbosity, Priority>,nchar, lang::HeapAllocator>
255{
257 void operator()( TAString<nchar, lang::HeapAllocator>& target, const std::pair<Verbosity, Priority>& src );
258};
259
260} // namespace [alib::strings]
261#endif // !DOXYGEN
262
264
265#endif // HPP_ALIB_ALOX_CAMP
266
ALIB_API void Reset()
Definition aloxcamp.cpp:397
virtual void bootstrap(BootstrapPhases phase) override
Definition aloxcamp.cpp:147
virtual void shutdown(ShutdownPhases phase) override
Definition aloxcamp.cpp:377
ALIB_API void Register(Lox *lox, lang::ContainerOp operation)
Definition aloxcamp.cpp:104
ALIB_API Lox * Get(const NString &name, lang::CreateIfNotExists create=lang::CreateIfNotExists::No)
Definition aloxcamp.cpp:82
static ALIB_API config::Declaration CODEPAGE
Definition aloxcamp.hpp:151
This class acts as a container for Loggers and provides a convenient interface to logging.
Definition lox.inl:58
TAllocator AllocatorType
The allocator type that TAllocator specifies.
integer Add(const strings::TString< TChar > &src)
#define ALIB_CONFIG_VARIABLE_DEFINE_TYPE_WITH_POOL_CONSTRUCTOR(Namespace, CPPName, CfgTypeString)
Definition vmeta.hpp:186
#define ALIB_ASSERT_MODULE(modulename)
Definition alib.hpp:223
#define A_CHAR(STR)
#define ALIB_ENUMS_ASSIGN_RECORD(TEnum, TRecord)
Definition records.hpp:712
#define ALIB_API
Definition alib.hpp:639
#define ALIB_RESOURCED_IN_MODULE(T, Camp, ResName)
CreateIfNotExists
Denotes whether something should be created if it does not exist.
ContainerOp
Denotes standard container operations.
@ FORMAT_TIME_DIFF
Denotes configuration variable ALOX/LOGGERNAME/FORMAT_TIME_DIFF used by class TextLogger.
@ CONSOLE_LIGHT_COLORS
Denotes configuration variable ALOX/CONSOLE_LIGHT_COLORS used by colorful specializations of class Te...
@ CONSOLE_TYPE
Denotes configuration variable ALOX/CONSOLE_TYPE used by Lox::CreateConsoleLogger.
@ VERBOSITY
Denotes configuration variable ALOX/LOGGERNAME/VERBOSITY_WITH_LOXNAME.
@ FORMAT
Denotes configuration variable ALOX/LOGGERNAME/FORMAT used by class TextLogger.
@ DOMAIN_SUBSTITUTION
Denotes configuration variable ALOX/LOXNAME/DOMAIN_SUBSTITUTION used by class Lox.
@ CODEPAGE
Denotes configuration variable ALOX/CODEPAGE used by class WindowsConsoleLogger.
@ REPLACEMENTS
Denotes configuration variable ALOX/LOGGERNAME/REPLACEMENTS used by class TextLogger.
@ DUMP_STATE_ON_EXIT
Denotes configuration variable ALOX/LOXNAME/DUMP_STATE_ON_EXIT used by class Lox.
@ FORMAT_DATE_TIME
Denotes configuration variable ALOX/LOGGERNAME/FORMAT_DATE_TIME used by class TextLogger.
@ FORMAT_MULTILINE
Denotes configuration variable ALOX/LOGGERNAME/FORMAT_MULTILINE used by class TextLogger.
@ SPTR_GLOBAL
Denotes configuration variable ALOX/GLOBAL_SOURCE_PATH_TRIM_RULES.
@ FORMAT_OTHER
Denotes configuration variable ALOX/LOGGERNAME/FORMAT_OTHER used by class TextLogger.
@ SPTR_LOX
Denotes configuration variable ALOX/LOXNAME/SOURCE_PATH_TRIM_RULES used by class Lox.
@ PREFIXES
Denotes configuration variable ALOX/LOXNAME/PREFIXES used by class Lox.
@ NO_IDE_LOGGER
Denotes configuration variable ALOX/NO_IDE_LOGGER used by Log::AddDebugLogger.
@ AUTO_SIZES
Denotes configuration variable ALOX/LOGGERNAME/AUTO_SIZES used by class TextLogger.
Definition alib.cpp:69
ShutdownPhases
Termination levels usable with Bootstrapping ALib Camps.
Definition alib.hpp:1418
lox::ALoxCamp ALOX
The singleton instance of ALib Camp class ALoxCamp.
Definition aloxcamp.cpp:33
BootstrapPhases
Initialization levels usable with Bootstrapping ALib Camps.
Definition alib.hpp:1393
lox::Scope Scope
Type alias in namespace alib.
lang::HeapAllocator HeapAllocator
Type alias in namespace alib.
characters::nchar nchar
Type alias in namespace alib.
~CVVerbosities()
Destructor. Frees all allocated strings.
Definition aloxcamp.hpp:108
void Clear()
Frees all allocated strings and clears vector.
Definition aloxcamp.hpp:119
CVVerbosities(AllocatorType &pAllocator)
Definition aloxcamp.hpp:104
void operator()(TAString< TChar > &target, const TAppendable &src)