ALib C++ Library
Library Version: 2510 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
standardrepository.inl
Go to the documentation of this file.
1//==================================================================================================
2/// \file
3/// This header-file is part of module \alib_expressions of the \aliblong.
4///
5/// \emoji :copyright: 2013-2025 A-Worx GmbH, Germany.
6/// Published under \ref mainpage_license "Boost Software License".
7//==================================================================================================
8ALIB_EXPORT namespace alib { namespace expressions {
9
10//==================================================================================================
11/// This is a default implementation of abstract interface \alib{expressions;ExpressionRepository}
12/// which retrieves definitions of named expressions using core mechanics of \alib, namely:
13/// 1. \ref alib_mod_resources "Static resource data", and
14/// 2. \ref alib_mod_variables "Configuration data".
15//==================================================================================================
17{
18 protected:
19 /// The configuration object used to retrieve definitions of nested expressions.
21
22 /// The resource pool used to retrieve definitions of nested expressions, if not found
23 /// with configuration data of field #config.
25
26 /// The category within #resources to use for searching expression strings.
28
29 public:
30 /// May be filled with paths in field #config. A named expression's identifier will
31 /// be first tried to be loaded using each path name added here.
32 ///
33 /// If this is left empty, with the first invocation of method #Get, an empty string is
34 /// added to enable to search an expression in the root of the \b StringTree of #config.
35 std::vector<AString> ConfigPaths;
36
37 /// Within this vector, all variables that have been loaded from #config are stored.
38 ///
39 /// The tuple elements provide:
40 /// - the priority (configuration slot),
41 /// - the variable name and
42 /// - the name of the nested expression.
43 ///
44 /// The latter is needed, as it might differ from the combination of the "category" and
45 /// variable name due to definitions in #ConfigPaths.
46 ///
47 /// This vector might be used for various things, e.g., logging out status information.
48 /// It is also used by method #StoreLoadedExpressions.
49 ///
50 /// \note
51 /// This list is never cleared by this class. It might be cleared from outside
52 /// (e.g., to release memory) without causing any side effects, other than those occurring
53 /// to mechanics an application itself volunteers to implement using this information.
54 std::vector<std::tuple<Priority,AString,String>> VariablesLoaded;
55
56 //==========================================================================================
57 /// Constructor.
58 ///
59 /// @param pConfig The configuration data to use.
60 /// May be set to \c nullptr to omit the use of configuration data.
61 /// @param pResources The resources to use.
62 /// May be set to \c nullptr to omit the use of resource data.
63 /// @param pResCategory The category within #resources to use for searching expression
64 /// strings.
65 //==========================================================================================
66 inline
68 ResourcePool* pResources,
69 NString pResCategory )
70 : config (pConfig)
71 , resources (pResources)
72 , resourceCategory(pResCategory)
73 {}
74
75 //==========================================================================================
76 /// Implementation of the central interface method. If invoked, the definition string is
77 /// first searched in #config and if not found, secondly searched in field #resources.
78 ///
79 /// @param identifier The name of the required expression.
80 /// @param[out] target The target to write the requested expression string to.
81 /// @return This \c true, if the expression string could be retrieved, \c false otherwise.
82 /// If \c true is returned and \p{target} is still empty, then the string is defined
83 /// to be empty, which throws an exception on compilation.
84 //==========================================================================================
85 virtual ALIB_DLL
86 bool Get( const String& identifier, AString& target ) override;
87
88 //==========================================================================================
89 /// Stores back all expression strings which had been automatically loaded from
90 /// the plug-in of field #config, specified by parameter \p{slot}.
91 /// For storing, the normalized expression string is used. Thus, this method may be used to
92 /// write a "clean" expression string, that does not use abbreviations for identifiers, has
93 /// no unnecessary whitespaces, etc.
94 ///
95 /// Note the importance of parameter \p{slot}: Usually, only such expression variables
96 /// should be stored that had been loaded from a configuration source that is manually edited
97 /// by end-users, like INI-files.
98 ///
99 /// @param compiler The compiler that this interface is attached to.
100 /// @param slot The slot of the configuration plug-in of which loaded variables are to
101 /// be written back.
102 /// @return The number of variables written.
103 //==========================================================================================
105 int StoreLoadedExpressions( Compiler* compiler,
106 Priority slot = Priority::Standard );
107};
108
109}} // namespace [alib::expressions]
110
ALIB_DLL int StoreLoadedExpressions(Compiler *compiler, Priority slot=Priority::Standard)
StandardRepository(const SharedConfiguration &pConfig, ResourcePool *pResources, NString pResCategory)
std::vector< std::tuple< Priority, AString, String > > VariablesLoaded
SharedConfiguration config
The configuration object used to retrieve definitions of nested expressions.
NString resourceCategory
The category within resources to use for searching expression strings.
virtual ALIB_DLL bool Get(const String &identifier, AString &target) override
#define ALIB_DLL
Definition alib.inl:496
#define ALIB_EXPORT
Definition alib.inl:488
strings::TAString< character, lang::HeapAllocator > AString
Type alias in namespace alib.
strings::TString< nchar > NString
Type alias in namespace alib.
Definition string.inl:2390
variables::TSharedConfiguration< SharedLock > SharedConfiguration
Type alias in namespace alib.
resources::ResourcePool ResourcePool
Type alias in namespace alib.
alib::variables::Priority Priority
Type alias in namespace alib.
strings::TString< character > String
Type alias in namespace alib.
Definition string.inl:2381