ALib C++ Library
Library Version: 2511 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 /// Constructor.
57 ///
58 /// @param pConfig The configuration data to use.
59 /// May be set to \c nullptr to omit the use of configuration data.
60 /// @param pResources The resources to use.
61 /// May be set to \c nullptr to omit the use of resource data.
62 /// @param pResCategory The category within #resources to use for searching expression
63 /// strings.
64 inline
66 ResourcePool* pResources,
67 NString pResCategory )
68 : config (pConfig)
69 , resources (pResources)
70 , resourceCategory(pResCategory) {}
71
72 /// Implementation of the central interface method. If invoked, the definition string is
73 /// first searched in #config and if not found, secondly searched in field #resources.
74 ///
75 /// @param identifier The name of the required expression.
76 /// @param[out] target The target to write the requested expression string to.
77 /// @return This \c true, if the expression string could be retrieved, \c false otherwise.
78 /// If \c true is returned and \p{target} is still empty, then the string is defined
79 /// to be empty, which throws an exception on compilation.
80 virtual ALIB_DLL
81 bool Get( const String& identifier, AString& target ) override;
82
83 /// Stores back all expression strings which had been automatically loaded from
84 /// the plug-in of field #config, specified by parameter \p{slot}.
85 /// For storing, the normalized expression string is used. Thus, this method may be used to
86 /// write a "clean" expression string, that does not use abbreviations for identifiers, has
87 /// no unnecessary whitespaces, etc.
88 ///
89 /// Note the importance of parameter \p{slot}: Usually, only such expression variables
90 /// should be stored that had been loaded from a configuration source that is manually edited
91 /// by end-users, like INI-files.
92 ///
93 /// @param compiler The compiler that this interface is attached to.
94 /// @param slot The slot of the configuration plug-in of which loaded variables are to
95 /// be written back.
96 /// @return The number of variables written.
98 int StoreLoadedExpressions( Compiler* compiler,
99 Priority slot = Priority::Standard );
100};
101
102}} // namespace [alib::expressions]
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:503
#define ALIB_EXPORT
Definition alib.inl:497
strings::TAString< character, lang::HeapAllocator > AString
Type alias in namespace alib.
strings::TString< nchar > NString
Type alias in namespace alib.
Definition string.inl:2198
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:2189