d
This commit is contained in:
11
v4/ctx.h
11
v4/ctx.h
@@ -6,7 +6,7 @@
|
||||
#define ctx_HEADER
|
||||
|
||||
template <class T> class ctx_Controller {
|
||||
std::list<std::function<T(T)> > callbacks;
|
||||
std::list<std::function<void(T)> > callbacks;
|
||||
std::list<std::function<T(T)> > functions;
|
||||
std::queue<T> queue;
|
||||
|
||||
@@ -49,12 +49,14 @@ template <class T> class ctx_Controller {
|
||||
functions.push_back(f);
|
||||
}
|
||||
|
||||
/*
|
||||
void registerCallback(void (*cb)(T)) {
|
||||
void registerCallback(std::function<void(T)> cb) {
|
||||
callbacks.push_back(cb);
|
||||
}
|
||||
|
||||
void registerFieldCallback(const std::string &fieldName, void (*cb)(T)) {
|
||||
void registerFieldCallback(
|
||||
const std::string &fieldName,
|
||||
std::function<void(T)> cb
|
||||
) {
|
||||
auto execCB = [fieldName, cb](T c) {
|
||||
if (c.recentField == fieldName) {
|
||||
cb(c);
|
||||
@@ -63,6 +65,7 @@ template <class T> class ctx_Controller {
|
||||
callbacks.push_back(execCB);
|
||||
}
|
||||
|
||||
/*
|
||||
void registerFunctions(const std::list<T *(T)> funcs) {
|
||||
for (const auto &f : funcs) {
|
||||
functions.push_back(f);
|
||||
|
||||
@@ -63,3 +63,28 @@ std::string test_ctx_Controller_processQueue() {
|
||||
return "ERR: ctx_Controller_processQueue";
|
||||
}
|
||||
|
||||
std::string test_ctx_Controller_registerFieldCallback_match() {
|
||||
auto c = memory_createContext();
|
||||
ctx_Controller<memory_Context> ctrl(c);
|
||||
|
||||
c.input = "123";
|
||||
c.recentField = "input";
|
||||
std::string callbackInput = "";
|
||||
|
||||
auto setCallbackInput = [&callbackInput](memory_Context c) {
|
||||
if (
|
||||
c.recentField == "input"
|
||||
) {
|
||||
callbackInput = c.input;
|
||||
}
|
||||
};
|
||||
|
||||
ctrl.registerFieldCallback("input", setCallbackInput);
|
||||
ctrl.reportContext();
|
||||
if (
|
||||
ctrl.context.input == callbackInput
|
||||
) {
|
||||
return "OK: ctx_Controller_registerFieldCallback_match";
|
||||
}
|
||||
return "ERR: ctx_Controller_registerFieldCallback_match";
|
||||
}
|
||||
|
||||
@@ -5,5 +5,6 @@
|
||||
|
||||
std::string test_ctx_Controller_executeFunctions_set();
|
||||
std::string test_ctx_Controller_processQueue();
|
||||
std::string test_ctx_Controller_registerFieldCallback_match();
|
||||
|
||||
#endif // ctx_test_HEADER
|
||||
|
||||
@@ -87,7 +87,7 @@ def ctx_test_Controller_registerFieldCallback_match(
|
||||
):
|
||||
return "OK: ctx_Controller_registerFieldCallback_match"
|
||||
#}
|
||||
return f"ERR: ctx_Controller_registerFieldCallback_match"
|
||||
return "ERR: ctx_Controller_registerFieldCallback_match"
|
||||
#}
|
||||
|
||||
def ctx_test_Controller_registerFieldCallback_mismatch(
|
||||
|
||||
@@ -11,6 +11,8 @@ int main() {
|
||||
<< std::endl
|
||||
<< test_ctx_Controller_processQueue()
|
||||
<< std::endl
|
||||
<< test_ctx_Controller_registerFieldCallback_match()
|
||||
<< std::endl
|
||||
<< llm_test_isDigit_digit()
|
||||
<< std::endl
|
||||
<< llm_test_isDigit_notDigit()
|
||||
|
||||
Reference in New Issue
Block a user