ALib C++ Library
Library Version: 2402 R1
Documentation generated by doxygen
Loading...
Searching...
No Matches
standardrepository.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 !defined(ALIB_DOX)
10# if !defined (HPP_ALIB_EXPRESSIONS_STANDARD_REPOSITORY)
12# endif
13# if !defined (HPP_ALIB_CONFIG_CONFIGURATION)
15# endif
16# if !defined (HPP_ALIB_CONFIG_VARIABLE)
18# endif
19#endif // !defined(ALIB_DOX)
20
21namespace alib { namespace expressions {
22
24{
25 int count= 0;
26 for( auto& entry : VariablesLoaded )
27 if( std::get<0>( entry ) == slot )
28 {
29 ++count;
30 var.Declare( std::get<1>( entry ), std::get<2>( entry ) );
31 var.SetPriority( slot );
32 var.Add( compiler->GetNamed( std::get<3>( entry ))->GetNormalizedString() );
33 config->Store( var );
34 }
35
36 return count;
37}
38
39bool StandardRepository::Get( const String& identifier, AString& target )
40{
41 if( config != nullptr )
42 {
43 // search in given default categories first.
44 for( auto& category : DefaultCategories )
45 {
46 if( config->Load( var.Declare( category, identifier ) ) != Priorities::NONE )
47 {
48 target << var.GetString();
49 VariablesLoaded.emplace_back( var.Priority(), category, identifier, identifier );
50 return true;
51 }
52 }
53
54 // try to split identifier in "category_name"
55 integer underscorePos= identifier.IndexOf( '_', 1 );
56 while( underscorePos > 0 )
57 {
58 Substring name;
59 Substring category(identifier);
60 category.Split( underscorePos, name, 1 );
61 if( config->Load( var.Declare( category, name ) ) != Priorities::NONE )
62 {
63 target << var.GetString();
64 VariablesLoaded.emplace_back( var.Priority(), category, name, identifier );
65 return true;
66 }
67 underscorePos= identifier.IndexOf( '_', underscorePos + 1 );
68 }
69 }
70
71 if( resources != nullptr )
72 {
73 auto& result= resources->Get( resourceCategory, identifier ALIB_DBG(, false) );
74 if( result.IsNotNull() )
75 {
76 target << result;
77 return true;
78 }
79 }
80
81
82 // failed
83 return false;
84}
85
86}} // namespace [alib::expressions]
ALIB_API Priorities Load(Variable &variable)
ALIB_API Priorities Store(Variable &variable, const String &externalizedValue=nullptr)
void SetPriority(Priorities priority)
Definition variable.hpp:628
ALIB_API void Add(const String &value)
Definition variable.cpp:223
ALIB_API Variable & Declare(const VariableDecl &declaration, const Box &replacements)
Definition variable.cpp:77
const String & GetString(int idx=0)
Definition variable.hpp:780
Priorities Priority() const
Definition variable.hpp:617
virtual ALIB_API SPExpression GetNamed(const String &name)
Definition compiler.cpp:389
virtual ALIB_API bool Get(const String &identifier, AString &target) override
std::vector< std::tuple< Priorities, AString, AString, String > > VariablesLoaded
ALIB_API int StoreLoadedExpressions(Compiler *compiler, Priorities slot=Priorities::Standard)
virtual const String & Get(const NString &category, const NString &name, bool dbgAssert)=0
integer IndexOf(TChar needle, integer startIdx=0) const
Definition string.hpp:889
TSubstring & Split(integer position, TSubstring &target, integer separatorWidth=0, bool trim=false)
#define ALIB_DBG(...)
Definition alib.hpp:457
Definition alib.cpp:57
lang::integer integer
Type alias in namespace alib.
Definition integers.hpp:286