d
This commit is contained in:
27
v4/ctx.h
27
v4/ctx.h
@@ -18,13 +18,15 @@ template <class T> class ctx_Controller {
|
|||||||
void executeFunctions() {
|
void executeFunctions() {
|
||||||
T c = queue.front();
|
T c = queue.front();
|
||||||
queue.pop_front();
|
queue.pop_front();
|
||||||
for (int i = 0; i < functions.size(); ++i) {
|
for (const auto &f : functions) {
|
||||||
T ctx = functions[i](c);
|
T ctx = f(c);
|
||||||
if (ctx.recentField != "none") {
|
if (ctx.recentField != "none") {
|
||||||
queue.push_back(ctx);
|
queue.push_back(ctx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
context = c;
|
|
||||||
|
context.recentField = c.recentField;
|
||||||
|
context.setField(c.recentField, c.field(c.recentField));
|
||||||
reportContext();
|
reportContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,13 +46,28 @@ template <class T> class ctx_Controller {
|
|||||||
callbacks.push_back(cb);
|
callbacks.push_back(cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void registerFieldCallback(const std::string &fieldName, void (*cb)(T)) {
|
||||||
|
auto execCB = [fieldName, cb](T c) {
|
||||||
|
if (c.recentField == fieldName) {
|
||||||
|
cb(c);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
callbacks.push_back(execCB);
|
||||||
|
}
|
||||||
|
|
||||||
void registerFunction(T (*f)(T)) {
|
void registerFunction(T (*f)(T)) {
|
||||||
functions.push_back(f);
|
functions.push_back(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void registerFunctions(const std::list<T *(T)> funcs) {
|
||||||
|
for (const auto &f : funcs) {
|
||||||
|
functions.push_back(f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void reportContext() {
|
void reportContext() {
|
||||||
for (int i = 0; i < callbacks.size(); ++i) {
|
for (const auto &cb : callbacks) {
|
||||||
callbacks[i](context);
|
cb(context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user