ALib C++ Library
Library Version: 2402 R1
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 * \emoji :copyright: 2013-2024 A-Worx GmbH, Germany.
6 * Published under \ref mainpage_license "Boost Software License".
7 **************************************************************************************************/
8#ifndef HPP_ALIB_EXPRESSIONS_STANDARD_REPOSITORY
9#define HPP_ALIB_EXPRESSIONS_STANDARD_REPOSITORY
10
11#ifndef HPP_ALIB_EXPRESSIONS_COMPILER
13#endif
14
15ALIB_ASSERT_MODULE(CONFIGURATION)
16
17#ifndef HPP_ALIB_LANG_RESOURCES_RESOURCES
19#endif
20
21#ifndef HPP_ALIB_CONFIG_CONFIGURATION
23#endif
24
25
26namespace alib { namespace expressions {
27
28/** ************************************************************************************************
29 * This is a default implementation of abstract interface \alib{expressions;ExpressionRepository}
30 * which retrieves definitions of named expressions using core mechanics of \alib, namely:
31 * 1. \ref alib_basecamp_resources "Static resource data", and
32 * 2. \ref alib_mod_config "Configuration data".
33 **************************************************************************************************/
35{
36 protected:
37 /** A variable object, reused (performance vs memory) */
39
40 /**
41 * The configuration object used to retrieve definitions of nested expressions.
42 */
44
45 /**
46 * The resource pool used to retrieve definitions of nested expressions, if not found
47 * with configuration data of field #config.
48 */
50
51 /**
52 * The category within #resources to use for searching expression strings.
53 */
55
56 public:
57 /**
58 * May be filled with category names of field #config. A named expression's identifier will
59 * be first tried to be loaded using each category name added here. If this fails,
60 * it is checked if an underscore <c>'_'</c>character is found in the name, if yes,
61 * it is then tried to extract the category from the variable name.
62 *
63 * \note To allow to search in the unnamed-category as well, an empty string may be added.
64 */
65 std::vector<AString> DefaultCategories;
66
67 /**
68 * Within this vector, all variables that have been loaded from #config are stored.
69 *
70 * The tuple elements provide:
71 * - the priority (configuration slot),
72 * - the category name,
73 * - the variable name and
74 * - the name of the nested expression.
75 *
76 * The latter is needed, as it might differ from the combination of the category and
77 * variable name due to definitions in #DefaultCategories.
78 *
79 * This vector might be used for various things, e.g. logging out status information.
80 * It is also used by method #StoreLoadedExpressions.
81 *
82 * \note
83 * This list is never cleared by this class. It might be cleared from outside
84 * (e.g. to release memory) without causing any side effects, other than those occurring
85 * to mechanics an application itself volunteers to implement using this information.
86 */
87 std::vector<std::tuple<Priorities,AString,AString,String>> VariablesLoaded;
88
89 public:
90 /** ****************************************************************************************
91 * Constructor.
92 *
93 * @param pConfig The configuration data to use.
94 * May be set to \c nullptr to omit the use of configuration data.
95 * @param pResources The resources to use.
96 * May be set to \c nullptr to omit the use of resource data.
97 * @param pResCategory The category within #resources to use for searching expression
98 * strings.
99 ******************************************************************************************/
100 inline
101 StandardRepository( Configuration* pConfig, ResourcePool* pResources, NString pResCategory )
102 : config (pConfig)
103 , resources (pResources)
104 , resourceCategory(pResCategory)
105 {}
106
107 /** ****************************************************************************************
108 * Implementation of the central interface method. If invoked, the definition string is
109 * first searched in #config and if not found, secondly searched in field #resources.
110 *
111 * @param identifier The name of the required expression.
112 * @param[out] target The target to write the requested expression string to.
113 * @return This \c true, if the expression string could be retrieved, \c false otherwise.
114 * If \c true is returned and \p{target} is still empty, then the string is defined
115 * to be empty, which throws an exception on compilation.
116 ******************************************************************************************/
117 virtual ALIB_API
118 bool Get( const String& identifier, AString& target ) override;
119
120 /** ****************************************************************************************
121 * Stores back all expression strings which had been automatically loaded from
122 * the plug-in of field #config, specified by parameter \p{slot}.
123 * For storing, the normalized expression string is used. Thus, this method may be used to
124 * write a "clean" expression string, that does not use abbreviations for identifiers, has
125 * no unnecessary whitespaces, etc.
126 *
127 * Note the importance of parameter \p{slot}: Usually, only such expression variables
128 * should be stored that had been loaded from a configuration source that is manually edited
129 * by end-users, like INI-files.
130 *
131 * @param compiler The compiler that this interface is attached to.
132 * @param slot The slot of the configuration plug-in of which loaded variables are to
133 * be written back.
134 * @return The number of variables written.
135 ******************************************************************************************/
137 int StoreLoadedExpressions( Compiler* compiler,
138 Priorities slot = Priorities::Standard );
139};
140
141}} // namespace [alib::expressions]
142
143#endif // HPP_ALIB_EXPRESSIONS_STANDARD_REPOSITORY
virtual ALIB_API bool Get(const String &identifier, AString &target) override
std::vector< std::tuple< Priorities, AString, AString, String > > VariablesLoaded
StandardRepository(Configuration *pConfig, ResourcePool *pResources, NString pResCategory)
ALIB_API int StoreLoadedExpressions(Compiler *compiler, Priorities slot=Priorities::Standard)
#define ALIB_ASSERT_MODULE(modulename)
Definition alib.hpp:190
#define ALIB_API
Definition alib.hpp:538
Definition alib.cpp:57