From 37f6f30680f2a74750c60a61a1ae4deec75f7a28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Fri, 7 Jun 2024 22:04:18 +0300 Subject: [PATCH] d --- v4/ctx.h | 11 +++++++---- v4/ctx_test2.cpp | 25 +++++++++++++++++++++++++ v4/ctx_test2.h | 1 + v4/ctx_test2.py | 2 +- v4/main.cpp | 2 ++ 5 files changed, 36 insertions(+), 5 deletions(-) diff --git a/v4/ctx.h b/v4/ctx.h index a6f27cd..c0df3fc 100644 --- a/v4/ctx.h +++ b/v4/ctx.h @@ -6,7 +6,7 @@ #define ctx_HEADER template class ctx_Controller { - std::list > callbacks; + std::list > callbacks; std::list > functions; std::queue queue; @@ -49,12 +49,14 @@ template class ctx_Controller { functions.push_back(f); } - /* - void registerCallback(void (*cb)(T)) { + void registerCallback(std::function cb) { callbacks.push_back(cb); } - void registerFieldCallback(const std::string &fieldName, void (*cb)(T)) { + void registerFieldCallback( + const std::string &fieldName, + std::function cb + ) { auto execCB = [fieldName, cb](T c) { if (c.recentField == fieldName) { cb(c); @@ -63,6 +65,7 @@ template class ctx_Controller { callbacks.push_back(execCB); } + /* void registerFunctions(const std::list funcs) { for (const auto &f : funcs) { functions.push_back(f); diff --git a/v4/ctx_test2.cpp b/v4/ctx_test2.cpp index d9b4d63..5ddfbdf 100644 --- a/v4/ctx_test2.cpp +++ b/v4/ctx_test2.cpp @@ -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 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"; +} diff --git a/v4/ctx_test2.h b/v4/ctx_test2.h index 2f8a794..b01d057 100644 --- a/v4/ctx_test2.h +++ b/v4/ctx_test2.h @@ -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 diff --git a/v4/ctx_test2.py b/v4/ctx_test2.py index 1a2bc83..3d1fd58 100644 --- a/v4/ctx_test2.py +++ b/v4/ctx_test2.py @@ -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( diff --git a/v4/main.cpp b/v4/main.cpp index e2e5d00..84cb9c0 100644 --- a/v4/main.cpp +++ b/v4/main.cpp @@ -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()