Add shared tasks to Target.hpp

This commit is contained in:
Username404 2021-12-21 17:06:29 +01:00
parent a0e185adb5
commit ab01c1bcb2
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
1 changed files with 9 additions and 2 deletions

View File

@ -66,12 +66,19 @@ protected:
} else output << openCharacters << view << closeCharacters << '\n';
}
typedef function<void (const ParseTree& parsedTree, unsigned int& index)> task;
#define make_task(X, L) make_pair(type_index(typeid(X)), [this](const ParseTree& parsedTree, unsigned int& index) { const X& parseComponent = pointerAs<X>(parsedTree[index]); L })
#define make_task_base(type, captures, function_body) make_pair(type_index(typeid(type)), [captures](const ParseTree& parsedTree, unsigned int& index) { const type& parseComponent = pointerAs<type>(parsedTree[index]); function_body })
#define make_task(T, F) make_task_base(T, this, F)
typedef unordered_map<type_index, optional<task>> unordered_task_map;
virtual unordered_task_map getTaskMap() = 0;
public:
unordered_task_map& getTaskMapInstance() {
const unordered_task_map& getTaskMapInstance() {
static unordered_task_map staticMap = getTaskMap();
// Default / Shared tasks:
staticMap.merge(unordered_task_map({
make_task(StandardComponents::Reference,
output << parseComponent.name;
)
}));
return staticMap;
};
static shared_ptr<Target> forName(string_view name, bool newLines);