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