|
|
@@ -7,77 +7,82 @@ |
|
|
|
template <class T> class ctx_Controller { |
|
|
|
T context; |
|
|
|
std::list<void *(T)> callbacks; |
|
|
|
/* |
|
|
|
std::list<T *(T)> functions; |
|
|
|
bool isProcessingQueue = false; |
|
|
|
std::list<T> queue; |
|
|
|
*/ |
|
|
|
|
|
|
|
ctx_Controller(const T &c) { |
|
|
|
context = c; |
|
|
|
} |
|
|
|
public: |
|
|
|
ctx_Controller(const T &c) { |
|
|
|
context = c; |
|
|
|
} |
|
|
|
|
|
|
|
void executeFunctions() { |
|
|
|
T c = queue.front(); |
|
|
|
queue.pop_front(); |
|
|
|
for (const auto &f : functions) { |
|
|
|
T ctx = f(c); |
|
|
|
if (ctx.recentField != "none") { |
|
|
|
queue.push_back(ctx); |
|
|
|
/* |
|
|
|
void executeFunctions() { |
|
|
|
T c = queue.front(); |
|
|
|
queue.pop_front(); |
|
|
|
for (const auto &f : functions) { |
|
|
|
T ctx = f(c); |
|
|
|
if (ctx.recentField != "none") { |
|
|
|
queue.push_back(ctx); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
context.recentField = c.recentField; |
|
|
|
context.setField(c.recentField, c.field(c.recentField)); |
|
|
|
reportContext(); |
|
|
|
} |
|
|
|
|
|
|
|
context.recentField = c.recentField; |
|
|
|
context.setField(c.recentField, c.field(c.recentField)); |
|
|
|
reportContext(); |
|
|
|
} |
|
|
|
void processQueue() { |
|
|
|
// Decline recursion. |
|
|
|
if (isProcessingQueue) { |
|
|
|
return; |
|
|
|
} |
|
|
|
isProcessingQueue = true; |
|
|
|
while (!queue.empty()) { |
|
|
|
executeFunctions(); |
|
|
|
} |
|
|
|
isProcessingQueue = false; |
|
|
|
} |
|
|
|
|
|
|
|
void processQueue() { |
|
|
|
// Decline recursion. |
|
|
|
if (isProcessingQueue) { |
|
|
|
return; |
|
|
|
void registerCallback(void (*cb)(T)) { |
|
|
|
callbacks.push_back(cb); |
|
|
|
} |
|
|
|
isProcessingQueue = true; |
|
|
|
while (!queue.empty()) { |
|
|
|
executeFunctions(); |
|
|
|
|
|
|
|
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); |
|
|
|
} |
|
|
|
isProcessingQueue = false; |
|
|
|
} |
|
|
|
|
|
|
|
void registerCallback(void (*cb)(T)) { |
|
|
|
callbacks.push_back(cb); |
|
|
|
} |
|
|
|
void registerFunction(T (*f)(T)) { |
|
|
|
functions.push_back(f); |
|
|
|
} |
|
|
|
|
|
|
|
void registerFieldCallback(const std::string &fieldName, void (*cb)(T)) { |
|
|
|
auto execCB = [fieldName, cb](T c) { |
|
|
|
if (c.recentField == fieldName) { |
|
|
|
cb(c); |
|
|
|
void registerFunctions(const std::list<T *(T)> funcs) { |
|
|
|
for (const auto &f : funcs) { |
|
|
|
functions.push_back(f); |
|
|
|
} |
|
|
|
}; |
|
|
|
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 (const auto &cb : callbacks) { |
|
|
|
cb(context); |
|
|
|
void reportContext() { |
|
|
|
for (const auto &cb : callbacks) { |
|
|
|
cb(context); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
template <typename U> void set(const std::string &fieldName, const U &value) { |
|
|
|
T c = context; |
|
|
|
c.setField(fieldName, value); |
|
|
|
c.recentField = fieldName; |
|
|
|
queue.push_back(c); |
|
|
|
processQueue(); |
|
|
|
} |
|
|
|
template <typename U> void set(const std::string &fieldName, const U &value) { |
|
|
|
T c = context; |
|
|
|
c.setField(fieldName, value); |
|
|
|
c.recentField = fieldName; |
|
|
|
queue.push_back(c); |
|
|
|
processQueue(); |
|
|
|
} |
|
|
|
*/ |
|
|
|
}; |
|
|
|
|
|
|
|
#endif // ctx_HEADER |