Михаил Капелько 2 weeks ago
parent
commit
37f6f30680
5 changed files with 36 additions and 5 deletions
  1. +7
    -4
      v4/ctx.h
  2. +25
    -0
      v4/ctx_test2.cpp
  3. +1
    -0
      v4/ctx_test2.h
  4. +1
    -1
      v4/ctx_test2.py
  5. +2
    -0
      v4/main.cpp

+ 7
- 4
v4/ctx.h View File

@@ -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);


+ 25
- 0
v4/ctx_test2.cpp View File

@@ -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";
}

+ 1
- 0
v4/ctx_test2.h View File

@@ -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

+ 1
- 1
v4/ctx_test2.py View File

@@ -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(


+ 2
- 0
v4/main.cpp View File

@@ -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()


Loading…
Cancel
Save