ALib C++ Library
Library Version: 2510 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
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{
46 Variable var( Self(), String(String256(category) << '/' << name), A_CHAR("S") );
47 bool existed= var.IsDefined();
48 if(var.Define())
49 var.GetString().Reset(resource);
50 return existed;
51}
52
53
54void ConfigResourcePool::BootstrapBulk( const nchar* category, ... )
55{
56 va_list args;
57 va_start(args, category);
58 auto cursor= Self().Root();
59#if ALIB_CHARACTERS_WIDE
60 String256 wCategory(category);
61 ALIB_ASSERT_RESULT_EQUALS(cursor.GoToCreateChildIfNotExistent( wCategory ), true)
62#else
63 ALIB_ASSERT_RESULT_EQUALS(cursor.GoToCreateChildIfNotExistent( category ), true)
64#endif
65 for(;;)
66 {
67 NString name= va_arg( args, const nchar* );
68
69 if( name.IsNull() )
70 break;
71
72 #if ALIB_CHARACTERS_WIDE
73 String256 wName(name);
74 auto child= cursor.CreatePathIfNotExistent(wName).first;
75 #else
76 auto child= cursor.CreatePathIfNotExistent(name).first;
77 #endif
78 if( !child.IsValid() )
79 {
80 ALIB_WARNING("RESOURCES", "ConfigResourcePool: Resource value existed already. Name=",
81 name)
82 continue;
83 }
84
85 Variable var(child, A_CHAR("S") );
86 (void) var.Define(Priority::DefaultValues);
87 var.GetString().Reset( String(va_arg( args, const character* )) );
88
89 // \checkpromise: when typed ALib assertions and warnings are available, then
90 // raise a warning if the result of above EmplaceOrAssign is an assign, aka the
91 // bulk data existed already.
92 }
93 va_end(args);
94}
95
96
97const String& ConfigResourcePool::Get( const NString& category, const NString& name ALIB_DBG(, bool dbgAssert ) )
98{
99
100 String256 path(category); path << '/' << name;
101 Variable var(Self());
102 if( var.Try(path) )
103 return var.GetString();
104
105 ALIB_ASSERT_ERROR( !dbgAssert, "RESOURCES",
106 "Unknown resource! Category: {}, Name: ", category, name )
107 return NULL_STRING;
108}
109
110} // namespace [alib::variables]
111#endif // ALIB_RESOURCES
constexpr bool IsNull() const
Definition string.inl:352
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:280
bool Try(const String &name)
#define ALIB_ASSERT_RESULT_EQUALS( func, value)
Definition alib.inl:1066
#define A_CHAR(STR)
#define ALIB_WARNING(domain,...)
Definition alib.inl:1046
#define ALIB_DBG(...)
Definition alib.inl:836
#define ALIB_ASSERT_ERROR(cond, domain,...)
Definition alib.inl:1049
constexpr String NULL_STRING
A nulled string of the default character type.
Definition string.inl:2463
LocalString< 256 > String256
Type alias name for TLocalString<character,256>.
strings::TString< nchar > NString
Type alias in namespace alib.
Definition string.inl:2390
characters::nchar nchar
Type alias in namespace alib.
strings::TString< character > String
Type alias in namespace alib.
Definition string.inl:2381
characters::character character
Type alias in namespace alib.