47 #ifndef _MIRA_XML_MACROS_SCOPE_H_ 48 #define _MIRA_XML_MACROS_SCOPE_H_ 51 #include <unordered_map> 68 using Definitions = std::unordered_map<std::string, xmlmacros::MacroPtr>;
78 using Ptr = std::shared_ptr<Scope>;
90 auto it = ns->second.find(
id.name);
92 if (it != ns->second.end()) {
98 return parent->findOptional(
id);
108 if (ptr ==
nullptr) {
110 "No definition for macro \"" + name.
xmlns +
":" + name.
name +
"\" found.");
125 if (ns->second.find(
id.name) != ns->second.end()) {
126 MIRA_THROW(XInvalidConfig,
"Macro \"" +
id.
toString() +
"\" already defined in this scope.");
129 ns->second.insert(std::make_pair(std::move(
id.name), std::move(macro)));
140 std::vector<std::remove_reference_t<decltype(ns)>::iterator> toErase;
142 for (
auto it = ns.begin(); it != ns.end(); ++it) {
143 if (it->second.use_count() == 1) {
144 toErase.emplace_back(it);
148 for (
auto it : toErase) {
159 #endif // _MIRA_XML_MACROS_SCOPE_H_ MacroPtr findOptional(const Identifier &id) const
Definition: Scope.h:85
std::shared_ptr< Scope > Ptr
Definition: Scope.h:78
std::unordered_map< std::string, Definitions > namespaces
Definition: Scope.h:83
#define MIRA_THROW(ex, msg)
Macro for throwing an exception.
Definition: Exception.h:78
std::string name
Definition: Scope.h:60
std::string toString(const T &value, int precision=-1)
Converts any data type to string (the data type must support the stream << operator).
Definition: ToString.h:252
Variable scope of the macro processor.
Definition: Scope.h:76
MacroPtr find(const Identifier &name) const
Definition: Scope.h:104
std::string toString() const
Definition: Scope.h:62
std::unordered_map< std::string, xmlmacros::MacroPtr > Definitions
Definition: Scope.h:68
Scope::Ptr parent
Definition: Scope.h:80
void collectGarbage()
Remove any definitions that no one else depends on.
Definition: Scope.h:137
Scope::Ptr ScopePtr
Definition: Scope.h:155
Interface for implementing XML macros.
std::shared_ptr< IMacro > MacroPtr
Definition: IMacro.h:99
std::string xmlns
Definition: Scope.h:59
Definition: Builtins.h:56
void define(Identifier id, MacroPtr macro)
Definition: Scope.h:116