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