From e373b52c92b773576a1cd0cf76a203d8b58f981f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B8=D0=BD=D0=B8=D1=8F=D1=82=D1=83=D0=BB=D0=BB?= =?UTF-8?q?=D0=B8=D0=BD=D0=B0=20=D0=90=D0=B8=D0=B4=D0=B0?= Date: Mon, 22 Dec 2025 03:16:27 +0300 Subject: [PATCH 01/10] =?UTF-8?q?feat:=20=D1=81=D0=BA=D0=B5=D0=BB=D0=B5?= =?UTF-8?q?=D1=82=20=D0=BF=D1=80=D0=BE=D0=B5=D0=BA=D1=82=D0=B0=20=D1=81?= =?UTF-8?q?=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/.gitignore | 8 + .idea/editor.xml | 344 +++++++++++++++++++++++++++ .idea/incapsulation.iml | 2 + .idea/material_theme_project_new.xml | 10 + .idea/misc.xml | 12 + .idea/modules.xml | 8 + .idea/vcs.xml | 6 + CMakeLists.txt | 11 + engine.cpp | 7 + engine.h | 16 ++ main.cpp | 8 + subject.cpp | 9 + subject.h | 13 + 13 files changed, 454 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/editor.xml create mode 100644 .idea/incapsulation.iml create mode 100644 .idea/material_theme_project_new.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 CMakeLists.txt create mode 100644 engine.cpp create mode 100644 engine.h create mode 100644 main.cpp create mode 100644 subject.cpp create mode 100644 subject.h diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/editor.xml b/.idea/editor.xml new file mode 100644 index 0000000..25c6c37 --- /dev/null +++ b/.idea/editor.xml @@ -0,0 +1,344 @@ + + + + + \ No newline at end of file diff --git a/.idea/incapsulation.iml b/.idea/incapsulation.iml new file mode 100644 index 0000000..f08604b --- /dev/null +++ b/.idea/incapsulation.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/.idea/material_theme_project_new.xml b/.idea/material_theme_project_new.xml new file mode 100644 index 0000000..2f07d81 --- /dev/null +++ b/.idea/material_theme_project_new.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..37d66a9 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..b474a82 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..80f0d48 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.31) +project(incapsulation) + +set(CMAKE_CXX_STANDARD 20) + +add_executable( + incapsulation_lab + + main.cpp + subject.cpp + engine.cpp) diff --git a/engine.cpp b/engine.cpp new file mode 100644 index 0000000..3c511b4 --- /dev/null +++ b/engine.cpp @@ -0,0 +1,7 @@ +// +// Created by User on 12/18/2025. +// +#include "engine.h" + +void Engine::register_command(void* cmd, const std::string& name) {} +int Engine::execute(const std::string& name) { return 0; } \ No newline at end of file diff --git a/engine.h b/engine.h new file mode 100644 index 0000000..33382cb --- /dev/null +++ b/engine.h @@ -0,0 +1,16 @@ +// +// Created by User on 12/18/2025. +// + +#ifndef ENGINE_H +#define ENGINE_H + +#include + +class Engine { +public: + void register_command(void* cmd, const std::string& name); + int execute(const std::string& name); +}; + +#endif \ No newline at end of file diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..bf39327 --- /dev/null +++ b/main.cpp @@ -0,0 +1,8 @@ +#include +#include "subject.h" +#include "engine.h" + +int main() { + std::cout << "Project started" << std::endl; + return 0; +} \ No newline at end of file diff --git a/subject.cpp b/subject.cpp new file mode 100644 index 0000000..1c105ee --- /dev/null +++ b/subject.cpp @@ -0,0 +1,9 @@ +// +// Created by User on 12/18/2025. +// + +#include "subject.h" + +int Subject::f3(int arg1, int arg2) { + return 0; +} \ No newline at end of file diff --git a/subject.h b/subject.h new file mode 100644 index 0000000..3f6e25b --- /dev/null +++ b/subject.h @@ -0,0 +1,13 @@ +// +// Created by User on 12/18/2025. +// + +#ifndef SUBJECT_H +#define SUBJECT_H + +class Subject { +public: + int f3(int arg1, int arg2); +}; + +#endif \ No newline at end of file From 321cf847e5be4a1d7b6c0496b5a9f32687177ed3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B8=D0=BD=D0=B8=D1=8F=D1=82=D1=83=D0=BB=D0=BB?= =?UTF-8?q?=D0=B8=D0=BD=D0=B0=20=D0=90=D0=B8=D0=B4=D0=B0?= Date: Mon, 22 Dec 2025 03:23:31 +0300 Subject: [PATCH 02/10] =?UTF-8?q?feat:=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BD=D0=B0=D1=87=D0=B0=D0=BB=D1=8C=D0=BD?= =?UTF-8?q?=D1=8B=D1=85=20=D1=84=D0=B0=D0=B9=D0=BB=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 80f0d48..f2c3a29 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ project(incapsulation) set(CMAKE_CXX_STANDARD 20) add_executable( - incapsulation_lab + incapsulation main.cpp subject.cpp From 4d0e8c8a9ae36825f5efee94514fffdf802e85c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B8=D0=BD=D0=B8=D1=8F=D1=82=D1=83=D0=BB=D0=BB?= =?UTF-8?q?=D0=B8=D0=BD=D0=B0=20=D0=90=D0=B8=D0=B4=D0=B0?= Date: Mon, 22 Dec 2025 03:27:30 +0300 Subject: [PATCH 03/10] feat: implement Wrapper class for method encapsulation --- wrapper.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 wrapper.h diff --git a/wrapper.h b/wrapper.h new file mode 100644 index 0000000..6fc79c4 --- /dev/null +++ b/wrapper.h @@ -0,0 +1,46 @@ +// +// Created by User on 12/18/2025. +// +#ifndef WRAPPER_H +#define WRAPPER_H + +#include +#include +#include + +class WrapperBase { +public: + virtual ~WrapperBase() {} + virtual int call(const std::map& args) = 0; +}; + +template +class Wrapper : public WrapperBase { + T* obj; + std::function)> func; + std::map defaults; + +public: + Wrapper(T* object, int(T::*method)(int, int), std::map defs = {}) + : obj(object), defaults(defs) { + func = [method](T* o, std::map args) { + auto it = args.begin(); + int a = it->second; + ++it; + int b = it->second; + return (o->*method)(a, b); + }; + } + + int call(const std::map& args) override { + std::map all = defaults; + + for (const auto& pair : args) { + all[pair.first] = pair.second; + } + + return func(obj, all); + } +}; + +#endif \ No newline at end of file From 2ae7dbf1289b3f09615dbe8c0fb0b62b999a3970 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B8=D0=BD=D0=B8=D1=8F=D1=82=D1=83=D0=BB=D0=BB?= =?UTF-8?q?=D0=B8=D0=BD=D0=B0=20=D0=90=D0=B8=D0=B4=D0=B0?= Date: Mon, 22 Dec 2025 04:19:02 +0300 Subject: [PATCH 04/10] feat: implement Engine for command registration and execution --- engine.cpp | 19 +++++++++++++++++-- engine.h | 10 +++++++--- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/engine.cpp b/engine.cpp index 3c511b4..94e3b0a 100644 --- a/engine.cpp +++ b/engine.cpp @@ -2,6 +2,21 @@ // Created by User on 12/18/2025. // #include "engine.h" +#include -void Engine::register_command(void* cmd, const std::string& name) {} -int Engine::execute(const std::string& name) { return 0; } \ No newline at end of file +Engine::~Engine() { + // не удаляем - объекты на стеке + commands.clear(); +} + +void Engine::register_command(WrapperBase* cmd, const std::string& name) { + commands[name] = cmd; +} + +int Engine::execute(const std::string& name, const std::map& args) { + auto it = commands.find(name); + if (it == commands.end()) { + throw std::runtime_error("Command not found"); + } + return it->second->call(args); +}::execute(const std::string& name) { return 0; } \ No newline at end of file diff --git a/engine.h b/engine.h index 33382cb..304eb56 100644 --- a/engine.h +++ b/engine.h @@ -1,16 +1,20 @@ // // Created by User on 12/18/2025. // - #ifndef ENGINE_H #define ENGINE_H +#include #include +#include "wrapper.h" class Engine { + std::map commands; + public: - void register_command(void* cmd, const std::string& name); - int execute(const std::string& name); + ~Engine(); + void register_command(WrapperBase* cmd, const std::string& name); + int execute(const std::string& name, const std::map& args = {}); }; #endif \ No newline at end of file From 507edcbf48b9c6007252b727e37555ffa1eba67c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B8=D0=BD=D0=B8=D1=8F=D1=82=D1=83=D0=BB=D0=BB?= =?UTF-8?q?=D0=B8=D0=BD=D0=B0=20=D0=90=D0=B8=D0=B4=D0=B0?= Date: Mon, 22 Dec 2025 04:20:36 +0300 Subject: [PATCH 05/10] feat: implement Subject class with method f3 --- subject.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/subject.cpp b/subject.cpp index 1c105ee..282f716 100644 --- a/subject.cpp +++ b/subject.cpp @@ -1,9 +1,8 @@ // // Created by User on 12/18/2025. // - #include "subject.h" int Subject::f3(int arg1, int arg2) { - return 0; + return arg1 + arg2; } \ No newline at end of file From a35d52451c8ed3295ee89edc053d93de060eaaa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B8=D0=BD=D0=B8=D1=8F=D1=82=D1=83=D0=BB=D0=BB?= =?UTF-8?q?=D0=B8=D0=BD=D0=B0=20=D0=90=D0=B8=D0=B4=D0=B0?= Date: Mon, 22 Dec 2025 04:21:43 +0300 Subject: [PATCH 06/10] feat: integrate all components with example from assignment --- main.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index bf39327..5e250c4 100644 --- a/main.cpp +++ b/main.cpp @@ -1,8 +1,19 @@ #include +#include +#include #include "subject.h" +#include "wrapper.h" #include "engine.h" int main() { - std::cout << "Project started" << std::endl; + Subject subj; + + Wrapper wrapper(&subj, &Subject::f3, {{"arg1", 0}, {"arg2", 0}}); + + Engine engine; + engine.register_command(&wrapper, "command1"); + + std::cout << engine.execute("command1", {{"arg1", 4}, {"arg2", 5}}) << std::endl; + return 0; } \ No newline at end of file From e7e978b1540ecfc7211f017fe28378e9f2ec808e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B8=D0=BD=D0=B8=D1=8F=D1=82=D1=83=D0=BB=D0=BB?= =?UTF-8?q?=D0=B8=D0=BD=D0=B0=20=D0=90=D0=B8=D0=B4=D0=B0?= Date: Mon, 22 Dec 2025 04:23:15 +0300 Subject: [PATCH 07/10] test: add unit tests for different scenarios --- test.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 test.cpp diff --git a/test.cpp b/test.cpp new file mode 100644 index 0000000..ee30dc9 --- /dev/null +++ b/test.cpp @@ -0,0 +1,54 @@ +// +// Created by User on 12/18/2025. +// +#include +#include +#include +#include +#include "subject.h" +#include "wrapper.h" +#include "engine.h" + +void test_basic() { + // тест по тз + Subject subj; + Wrapper w(&subj, &Subject::f3, {{"arg1", 0}, {"arg2", 0}}); + Engine e; + e.register_command(&w, "command1"); + assert(e.execute("command1", {{"arg1", 4}, {"arg2", 5}}) == 9); + std::cout << "Basic test OK" << std::endl; +} + +void test_defaults() { + // тест с другими значениями по умолчанию + Subject subj; + Wrapper w(&subj, &Subject::f3, {{"x", 10}, {"y", 20}}); + Engine e; + e.register_command(&w, "add"); + assert(e.execute("add") == 30); + assert(e.execute("add", {{"x", 100}}) == 120); + std::cout << "Defaults test OK" << std::endl; +} + +void test_error() { + // тест на ошибку + Subject subj; + Wrapper w(&subj, &Subject::f3, {{"a", 0}, {"b", 0}}); + Engine e; + e.register_command(&w, "test"); + + try { + e.execute("unknown"); + assert(false); // не должны сюда попасть + } catch (const std::runtime_error&) { + std::cout << "Error test OK" << std::endl; + } +} + +int main() { + test_basic(); + test_defaults(); + test_error(); + std::cout << "All tests passed!" << std::endl; + return 0; +} \ No newline at end of file From 66f59bcbce34bb5a42941860021bc8642c446c60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B8=D0=BD=D0=B8=D1=8F=D1=82=D1=83=D0=BB=D0=BB?= =?UTF-8?q?=D0=B8=D0=BD=D0=B0=20=D0=90=D0=B8=D0=B4=D0=B0?= Date: Mon, 22 Dec 2025 04:32:22 +0300 Subject: [PATCH 08/10] feat: changed CMakeLists.txt do that it works on tests as well and points correctly to configurations --- CMakeLists.txt | 15 ++++++++++++--- engine.cpp | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f2c3a29..ae84608 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,20 @@ cmake_minimum_required(VERSION 3.31) -project(incapsulation) +project(incapsulation_lab) set(CMAKE_CXX_STANDARD 20) add_executable( - incapsulation + incapsulation_lab main.cpp subject.cpp - engine.cpp) + engine.cpp +) + +add_executable( + tests + + test.cpp + subject.cpp + engine.cpp +) \ No newline at end of file diff --git a/engine.cpp b/engine.cpp index 94e3b0a..759ffbb 100644 --- a/engine.cpp +++ b/engine.cpp @@ -19,4 +19,4 @@ int Engine::execute(const std::string& name, const std::map& a throw std::runtime_error("Command not found"); } return it->second->call(args); -}::execute(const std::string& name) { return 0; } \ No newline at end of file +} \ No newline at end of file From 74353157426488a56e89be8a22cef95655050f4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B8=D0=BD=D0=B8=D1=8F=D1=82=D1=83=D0=BB=D0=BB?= =?UTF-8?q?=D0=B8=D0=BD=D0=B0=20=D0=90=D0=B8=D0=B4=D0=B0?= Date: Mon, 22 Dec 2025 04:37:04 +0300 Subject: [PATCH 09/10] deleted idea and other trash --- .gitignore | Bin 0 -> 90 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..20ffd9f268ed16e3177f4156404c2daaafde7a50 GIT binary patch literal 90 zcmezWPmdv!A%!88A(26!ftP`cA(&H2LK_54?zF` literal 0 HcmV?d00001 From 7681a3118e51171eed08eb652a785cd15894657c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B8=D0=BD=D0=B8=D1=8F=D1=82=D1=83=D0=BB=D0=BB?= =?UTF-8?q?=D0=B8=D0=BD=D0=B0=20=D0=90=D0=B8=D0=B4=D0=B0?= Date: Mon, 22 Dec 2025 04:38:07 +0300 Subject: [PATCH 10/10] chore: add gitignore and remove IDE files --- .idea/.gitignore | 8 - .idea/editor.xml | 344 --------------------------- .idea/incapsulation.iml | 2 - .idea/material_theme_project_new.xml | 10 - .idea/misc.xml | 12 - .idea/modules.xml | 8 - .idea/vcs.xml | 6 - 7 files changed, 390 deletions(-) delete mode 100644 .idea/.gitignore delete mode 100644 .idea/editor.xml delete mode 100644 .idea/incapsulation.iml delete mode 100644 .idea/material_theme_project_new.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 13566b8..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Editor-based HTTP Client requests -/httpRequests/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml diff --git a/.idea/editor.xml b/.idea/editor.xml deleted file mode 100644 index 25c6c37..0000000 --- a/.idea/editor.xml +++ /dev/null @@ -1,344 +0,0 @@ - - - - - \ No newline at end of file diff --git a/.idea/incapsulation.iml b/.idea/incapsulation.iml deleted file mode 100644 index f08604b..0000000 --- a/.idea/incapsulation.iml +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/.idea/material_theme_project_new.xml b/.idea/material_theme_project_new.xml deleted file mode 100644 index 2f07d81..0000000 --- a/.idea/material_theme_project_new.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 37d66a9..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index b474a82..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file