ALib C++ Library
Library Version: 2511 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
configresourcepool.cpp
1//##################################################################################################
2// ALib C++ Library
3//
4// Copyright 2013-2025 A-Worx GmbH, Germany
5// Published under 'Boost Software License' (a free software license, see LICENSE.txt)
6//##################################################################################################
7#include "alib_precompile.hpp"
8#if !defined(ALIB_C20_MODULES) || ((ALIB_C20_MODULES != 0) && (ALIB_C20_MODULES != 1))
9# error "Symbol ALIB_C20_MODULES has to be given to the compiler as either 0 or 1"
10#endif
11#if ALIB_C20_MODULES
12 module;
13#endif
14//========================================= Global Fragment ========================================
16#include <cstdarg>
17
18//============================================== Module ============================================
19#if ALIB_C20_MODULES
20 module ALib.Variables.ResourcePool;
21 import ALib.Strings.StdIOStream;
22 import ALib.EnumRecords;
23# if ALIB_EXCEPTIONS
24 import ALib.Exceptions;
25# endif
26 import ALib.System;
27# if ALIB_VARIABLES
28 import ALib.Variables;
29# endif
30#else
32# include "ALib.Exceptions.H"
33# include "ALib.System.H"
34# include "ALib.Variables.H"
36#endif
37//========================================== Implementation ========================================
38#if ALIB_RESOURCES
39
40namespace alib::variables {
41
43 const NString& name,
44 const String& resource ) {
45 Variable var( Self(), String(String256(category) << '/' << name), A_CHAR("S") );
46 bool existed= var.IsDefined();
47 if(var.Define())
48 var.GetString().Reset(resource);
49 return existed;
50}
51
52
53void ConfigResourcePool::BootstrapBulk( const nchar* category, ... ) {
54 va_list args;
55 va_start(args, category);
56 auto cursor= Self().Root();
57#if ALIB_CHARACTERS_WIDE
58 String256 wCategory(category);
59 ALIB_ASSERT_RESULT_EQUALS(cursor.GoToCreateChildIfNotExistent( wCategory ), true)
60#else
61 ALIB_ASSERT_RESULT_EQUALS(cursor.GoToCreateChildIfNotExistent( category ), true)
62#endif
63 for(;;) {
64 NString name= va_arg( args, const nchar* );
65
66 if( name.IsNull() )
67 break;
68
69 #if ALIB_CHARACTERS_WIDE
70 String256 wName(name);
71 auto child= cursor.CreatePathIfNotExistent(wName).first;
72 #else
73 auto child= cursor.CreatePathIfNotExistent(name).first;
74 #endif
75 if( !child.IsValid() ) {
76 ALIB_WARNING("RESOURCES", "ConfigResourcePool: Resource value existed already. Name=",
77 name)
78 continue;
79 }
80
81 Variable var(child, A_CHAR("S") );
82 (void) var.Define(Priority::DefaultValues);
83 var.GetString().Reset( String(va_arg( args, const character* )) );
84
85 // \checkpromise: when typed ALib assertions and warnings are available, then
86 // raise a warning if the result of above EmplaceOrAssign is an assign, aka the
87 // bulk data existed already.
88 }
89 va_end(args);
90}
91
92
93const String& ConfigResourcePool::Get( const NString& category,
94 const NString& name ALIB_DBG(, bool dbgAssert ) ) {
95
96 String256 path(category); path << '/' << name;
97 Variable var(Self());
98 if( var.Try(path) )
99 return var.GetString();
100
101 ALIB_ASSERT_ERROR( !dbgAssert, "RESOURCES",
102 "Unknown resource! Category: {}, Name: ", category, name )
103 return NULL_STRING;
104}
105
106} // namespace [alib::variables]
107#endif // ALIB_RESOURCES
constexpr bool IsNull() const
Definition string.inl:350
virtual ALIB_DLL void BootstrapBulk(const nchar *category,...) override
bool BootstrapAddOrReplace(const NString &category, const NString &name, const String &data) override
ALIB_DLL bool Define(Priority requestedPriority=Priority::Standard)
Definition variable.cpp:261
bool Try(const String &name)
#define ALIB_ASSERT_RESULT_EQUALS( func, value)
Definition alib.inl:1083
#define A_CHAR(STR)
#define ALIB_WARNING(domain,...)
Definition alib.inl:1063
#define ALIB_DBG(...)
Definition alib.inl:853
#define ALIB_ASSERT_ERROR(cond, domain,...)
Definition alib.inl:1066
constexpr String NULL_STRING
A nulled string of the default character type.
Definition string.inl:2271
LocalString< 256 > String256
Type alias name for TLocalString<character,256>.
strings::TString< nchar > NString
Type alias in namespace alib.
Definition string.inl:2198
characters::nchar nchar
Type alias in namespace alib.
strings::TString< character > String
Type alias in namespace alib.
Definition string.inl:2189
characters::character character
Type alias in namespace alib.