Михаил Капелько 3 weeks ago
parent
commit
e9e0073061
1 changed files with 22 additions and 5 deletions
  1. +22
    -5
      v4/ctx.h

+ 22
- 5
v4/ctx.h View File

@@ -18,13 +18,15 @@ template <class T> class ctx_Controller {
void executeFunctions() {
T c = queue.front();
queue.pop_front();
for (int i = 0; i < functions.size(); ++i) {
T ctx = functions[i](c);
for (const auto &f : functions) {
T ctx = f(c);
if (ctx.recentField != "none") {
queue.push_back(ctx);
}
}
context = c;

context.recentField = c.recentField;
context.setField(c.recentField, c.field(c.recentField));
reportContext();
}

@@ -44,13 +46,28 @@ template <class T> class ctx_Controller {
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)) {
functions.push_back(f);
}

void registerFunctions(const std::list<T *(T)> funcs) {
for (const auto &f : funcs) {
functions.push_back(f);
}
}

void reportContext() {
for (int i = 0; i < callbacks.size(); ++i) {
callbacks[i](context);
for (const auto &cb : callbacks) {
cb(context);
}
}



Loading…
Cancel
Save