ALib C++ Library
Library Version: 2412 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
configresourcepool.cpp
1// #################################################################################################
2// ALib C++ Library
3//
4// Copyright 2013-2024 A-Worx GmbH, Germany
5// Published under 'Boost Software License' (a free software license, see LICENSE.txt)
6// #################################################################################################
8
9#if !DOXYGEN
12#endif // !DOXYGEN
13
14#include <cstdarg>
15
16namespace alib::config {
17
18
20 const NString& name,
21 const String& resource )
22{
23 Variable var( Self(), String(String256(category) << '/' << name), A_CHAR("S") );
24 bool existed= var.IsDefined();
25 if(var.Define())
26 var.GetString().Reset(resource);
27 return existed;
28}
29
30
31void ConfigResourcePool::BootstrapBulk( const nchar* category, ... )
32{
33 va_list args;
34 va_start(args, category);
35 auto cursor= Self().Root();
36#if ALIB_CHARACTERS_WIDE
37 String256 wCategory(category);
38 ALIB_ASSERT_RESULT_EQUALS(cursor.GoToCreateChildIfNotExistent( wCategory ), true)
39#else
40 ALIB_ASSERT_RESULT_EQUALS(cursor.GoToCreateChildIfNotExistent( category ), true)
41#endif
42 for(;;)
43 {
44 NString name= va_arg( args, const nchar* );
45
46 if( name.IsNull() )
47 break;
48
49#if ALIB_CHARACTERS_WIDE
50 String256 wName(name);
51 auto child= cursor.CreatePathIfNotExistent(wName).first;
52#else
53 auto child= cursor.CreatePathIfNotExistent(name).first;
54#endif
55 if( !child.IsValid() )
56 {
57 ALIB_WARNING("RESOURCES", "ConfigResourcePool: Resource value existed already. Name=", name)
58 continue;
59 }
60
61 Variable var(child, A_CHAR("S") );
62 (void) var.Define(Priority::DefaultValues);
63 var.GetString().Reset( String(va_arg( args, const character* )) );
64
65 // \checkpromise: when typed ALib assertions and warnings are available, then
66 // raise a warning if the result of above EmplaceOrAssign is an assign, aka the
67 // bulk data existed already.
68 }
69 va_end(args);
70}
71
72
73const String& ConfigResourcePool::Get( const NString& category, const NString& name ALIB_DBG(, bool dbgAssert ) )
74{
75
76 String256 path(category); path << '/' << name;
77 Variable var(Self());
78 if( var.Try(path) )
79 return var.GetString();
80
81 ALIB_ASSERT_ERROR( !dbgAssert, "RESOURCES", "Unknown resource! Category: ", NString64(category),
82 ", Name: ", NString64(name) )
83 return NULL_STRING;
84}
85
86} // namespace [alib::config]
87
virtual ALIB_API void BootstrapBulk(const nchar *category,...) override
bool BootstrapAddOrReplace(const NString &category, const NString &name, const String &data) override
bool Try(const String &name)
ALIB_API bool Define(Priority requestedPriority=Priority::Standard)
Definition variable.cpp:272
constexpr bool IsNull() const
Definition string.hpp:364
#define ALIB_WARNING(...)
Definition alib.hpp:1268
#define ALIB_ASSERT_RESULT_EQUALS( func, value)
Definition alib.hpp:1286
#define A_CHAR(STR)
#define ALIB_ASSERT_ERROR(cond,...)
Definition alib.hpp:1271
#define ALIB_DBG(...)
Definition alib.hpp:390
NLocalString< 64 > NString64
Type alias name for TLocalString<nchar,64>.
LocalString< 256 > String256
Type alias name for TLocalString<character,256>.
characters::character character
Type alias in namespace alib.
strings::TString< character > String
Type alias in namespace alib.
characters::nchar nchar
Type alias in namespace alib.
constexpr String NULL_STRING
A nulled string of the default character type.
Definition string.hpp:2549