diff --git a/CMakeLists.txt b/CMakeLists.txt index c86a8b1..3d4692d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -137,6 +137,7 @@ set(APP_SOURCES "src/core/datatypes/container/adapter/Queue.cpp" "src/core/datatypes/container/adapter/Stack.cpp" "src/core/datatypes/container/sequence/Deque.cpp" + "src/core/datatypes/container/associative/Set.cpp" ## LC "src/leetcode/arrays/two_sum/TwoSum.cpp" "src/leetcode/arrays/median_two_arrays/MedianTwoSortedArrays.cpp" diff --git a/src/controller/pid/PIDSim.cpp b/src/controller/pid/PIDSim.cpp index c54f970..a03f1d8 100644 --- a/src/controller/pid/PIDSim.cpp +++ b/src/controller/pid/PIDSim.cpp @@ -2,7 +2,6 @@ #include "pid.h" #include "ExampleRegistry.h" -#include "IExample.h" namespace { void run() { diff --git a/src/core/basics/ControlFlow.cpp b/src/core/basics/ControlFlow.cpp index 8a57328..25c2b05 100644 --- a/src/core/basics/ControlFlow.cpp +++ b/src/core/basics/ControlFlow.cpp @@ -117,7 +117,6 @@ void exceptions() { } #include "ExampleRegistry.h" -#include "IExample.h" class ControlFlow : public IExample { public: diff --git a/src/core/basics/InitializeVariable.cpp b/src/core/basics/InitializeVariable.cpp index 4410afd..c10602d 100644 --- a/src/core/basics/InitializeVariable.cpp +++ b/src/core/basics/InitializeVariable.cpp @@ -2,7 +2,6 @@ using namespace std; #include "ExampleRegistry.h" -#include "IExample.h" void initialize_variable(); diff --git a/src/core/basics/Operations.cpp b/src/core/basics/Operations.cpp index d123057..e5f4575 100644 --- a/src/core/basics/Operations.cpp +++ b/src/core/basics/Operations.cpp @@ -2,7 +2,6 @@ using namespace std; #include "ExampleRegistry.h" -#include "IExample.h" void arithmeticOperator(); void logicalOperator(); diff --git a/src/core/basics/TypeQualifier.cpp b/src/core/basics/TypeQualifier.cpp index 95507d8..1b81de9 100644 --- a/src/core/basics/TypeQualifier.cpp +++ b/src/core/basics/TypeQualifier.cpp @@ -31,7 +31,6 @@ void run() { } // namespace #include "ExampleRegistry.h" -#include "IExample.h" class TypeQualifier : public IExample { public: diff --git a/src/core/datatypes/CArray.cpp b/src/core/datatypes/CArray.cpp index 3af858c..cafe1dc 100644 --- a/src/core/datatypes/CArray.cpp +++ b/src/core/datatypes/CArray.cpp @@ -1,7 +1,6 @@ #include #include "ExampleRegistry.h" -#include "IExample.h" void arrayExamples() { std::cout << "\n--- Array Examples ---\n"; diff --git a/src/core/datatypes/CEnum.cpp b/src/core/datatypes/CEnum.cpp index 13aca53..c705104 100644 --- a/src/core/datatypes/CEnum.cpp +++ b/src/core/datatypes/CEnum.cpp @@ -40,7 +40,6 @@ void enums() { } #include "ExampleRegistry.h" -#include "IExample.h" class CEnum : public IExample { public: diff --git a/src/core/datatypes/CPointers.cpp b/src/core/datatypes/CPointers.cpp index 1890898..2bbef1f 100644 --- a/src/core/datatypes/CPointers.cpp +++ b/src/core/datatypes/CPointers.cpp @@ -104,7 +104,6 @@ void pointers() { } #include "ExampleRegistry.h" -#include "IExample.h" class CPointers : public IExample { public: diff --git a/src/core/datatypes/CReferences.cpp b/src/core/datatypes/CReferences.cpp index f8e044d..20a6583 100644 --- a/src/core/datatypes/CReferences.cpp +++ b/src/core/datatypes/CReferences.cpp @@ -83,7 +83,6 @@ void run() { } // namespace RvalueReference #include "ExampleRegistry.h" -#include "IExample.h" class CReferences : public IExample { public: diff --git a/src/core/datatypes/CStruct.cpp b/src/core/datatypes/CStruct.cpp index b181fb7..a7f311b 100644 --- a/src/core/datatypes/CStruct.cpp +++ b/src/core/datatypes/CStruct.cpp @@ -62,7 +62,6 @@ void structs() { } #include "ExampleRegistry.h" -#include "IExample.h" class CStruct : public IExample { public: diff --git a/src/core/datatypes/CUnion.cpp b/src/core/datatypes/CUnion.cpp index 7874094..3b48c44 100644 --- a/src/core/datatypes/CUnion.cpp +++ b/src/core/datatypes/CUnion.cpp @@ -38,7 +38,6 @@ void unionDemo() { // --- Auto-run struct --- #include "ExampleRegistry.h" -#include "IExample.h" class CUnion : public IExample { public: diff --git a/src/core/datatypes/Fundamental.cpp b/src/core/datatypes/Fundamental.cpp index 919cdf5..a72c9ab 100644 --- a/src/core/datatypes/Fundamental.cpp +++ b/src/core/datatypes/Fundamental.cpp @@ -51,7 +51,6 @@ void primative() { } #include "ExampleRegistry.h" -#include "IExample.h" class Fundamental : public IExample { public: diff --git a/src/core/datatypes/TypeConVersions.cpp b/src/core/datatypes/TypeConVersions.cpp index 1d2a6d2..9c5ae3e 100644 --- a/src/core/datatypes/TypeConVersions.cpp +++ b/src/core/datatypes/TypeConVersions.cpp @@ -145,7 +145,6 @@ void typeDeduction() { } #include "ExampleRegistry.h" -#include "IExample.h" class CTypeConversion : public IExample { public: diff --git a/src/core/datatypes/class/CConstructors.cpp b/src/core/datatypes/class/CConstructors.cpp index ce0841d..579f018 100644 --- a/src/core/datatypes/class/CConstructors.cpp +++ b/src/core/datatypes/class/CConstructors.cpp @@ -303,7 +303,6 @@ void constructers() { } // namespace Move #include "ExampleRegistry.h" -#include "IExample.h" class CConstructors : public IExample { public: diff --git a/src/core/datatypes/class/CDestructors.cpp b/src/core/datatypes/class/CDestructors.cpp index 15ce8b9..64bc62b 100644 --- a/src/core/datatypes/class/CDestructors.cpp +++ b/src/core/datatypes/class/CDestructors.cpp @@ -58,7 +58,6 @@ void destructers() { } // namespace Virtual #include "ExampleRegistry.h" -#include "IExample.h" class CDestructors : public IExample { public: diff --git a/src/core/datatypes/class/RoleOfThreeFiveZero.cpp b/src/core/datatypes/class/RoleOfThreeFiveZero.cpp index 9e4e96d..0f42b94 100644 --- a/src/core/datatypes/class/RoleOfThreeFiveZero.cpp +++ b/src/core/datatypes/class/RoleOfThreeFiveZero.cpp @@ -273,7 +273,6 @@ void run() { } // namespace #include "ExampleRegistry.h" -#include "IExample.h" class RoleOfThreeFiveZero : public IExample { public: diff --git a/src/core/datatypes/class/SallowDeepCopying.cpp b/src/core/datatypes/class/SallowDeepCopying.cpp index 845d05b..2577d19 100644 --- a/src/core/datatypes/class/SallowDeepCopying.cpp +++ b/src/core/datatypes/class/SallowDeepCopying.cpp @@ -152,7 +152,6 @@ void run() { } // namespace #include "ExampleRegistry.h" -#include "IExample.h" class ShallowDeepCopying : public IExample { public: diff --git a/src/core/datatypes/container/README.md b/src/core/datatypes/container/README.md index 644c4e7..ad52251 100644 --- a/src/core/datatypes/container/README.md +++ b/src/core/datatypes/container/README.md @@ -2,7 +2,7 @@ - The Containers library is a generic collection of class templates and algorithms that allow programmers to easilly implement common data structures. - All container functions can be called concurrently by different threads on different containers ## 1. Sequence Containers -Sequence containers implement data structures which can be accessed sequentially. +*Sequence containers* implement data structures which can be accessed sequentially. |name|description| |---|---| @@ -12,18 +12,34 @@ Sequence containers implement data structures which can be accessed sequentially |forward_list|singly-linked list| |list|doubly-linked list| +
+ ## 2. Unordered Containers -Unordered associative containers implement unsorted (hashed) data structures that can be quickly searched (O(1) average, O(n) worst-case complexity). +*Unordered associative containers* implement unsorted (hashed) data structures that can be quickly searched (**O(1) average, O(n) worst-case complexity**). + |name|description| |---|---| |unordered_map|collection of key-value pairs, hashed by keys, keys are unique| |unordered_set|collection of unique keys, hashed by keys| -## 3. Adapter Container -**Container adaptors** provide a different interface for **sequential containers**. +
+ +## 3. Adapter Containers +*Container adaptors* provide a different interface for **sequential containers**. + |name|description| |---|---| |queue|apdapts a container to provide queue (**FIFO** data structure)| |stack|adapts a container to provide stack (**LIFO** data structure)| -TBD \ No newline at end of file +
+ +## 4. Associative Containers +- *Associative containers* implement sorted data structures that can be quickly searched (**O(logn)**) + +|name|description| +|---|---| +|set|collection of unique keys, sorted by keys| +|map|collection of key-value pairs, sorted by keys| + +
diff --git a/src/core/datatypes/container/adapter/Queue.cpp b/src/core/datatypes/container/adapter/Queue.cpp index da6fcbb..2cd91df 100644 --- a/src/core/datatypes/container/adapter/Queue.cpp +++ b/src/core/datatypes/container/adapter/Queue.cpp @@ -43,14 +43,13 @@ void run() { } // namespace #include "ExampleRegistry.h" -#include "IExample.h" class Queue : public IExample { public: - std::string group() const override { return "core"; } + std::string group() const override { return "core/container"; } std::string name() const override { return "Queue"; } std::string description() const override { return "std::queue Example"; } void execute() override { run(); } }; -REGISTER_EXAMPLE(Queue, "core", "Queue"); \ No newline at end of file +REGISTER_EXAMPLE(Queue, "core/container", "Queue"); \ No newline at end of file diff --git a/src/core/datatypes/container/adapter/Stack.cpp b/src/core/datatypes/container/adapter/Stack.cpp index f40be12..3bc4c03 100644 --- a/src/core/datatypes/container/adapter/Stack.cpp +++ b/src/core/datatypes/container/adapter/Stack.cpp @@ -46,10 +46,10 @@ void run() { class Stack : public IExample { public: - std::string group() const override { return "core"; } + std::string group() const override { return "core/container"; } std::string name() const override { return "Stack"; } std::string description() const override { return "std::stack Example"; } void execute() override { run(); } }; -REGISTER_EXAMPLE(Stack, "core", "Stack"); \ No newline at end of file +REGISTER_EXAMPLE(Stack, "core/container", "Stack"); \ No newline at end of file diff --git a/src/core/datatypes/container/associative/Set.cpp b/src/core/datatypes/container/associative/Set.cpp new file mode 100644 index 0000000..9cf3248 --- /dev/null +++ b/src/core/datatypes/container/associative/Set.cpp @@ -0,0 +1,33 @@ + +// cppcheck-suppress-file [] +#include +#include +#include "ExampleRegistry.h" + +namespace { +void run() { + // 1. Init + std::set m_set{3, 4, 5, 1, 2}; + + // 2. Modifiers + m_set.insert(-1); + + m_set.insert(99); + m_set.erase(99); + + for (const auto k : m_set) { + std::cout << k << " "; + } + std::cout << std::endl; +} +} // namespace + +class Set : public IExample { + public: + std::string group() const override { return "core/container"; } + std::string name() const override { return "Set"; } + std::string description() const override { return "std::set Example"; } + void execute() override { run(); } +}; + +REGISTER_EXAMPLE(Set, "core/container", "Set"); \ No newline at end of file diff --git a/src/core/datatypes/container/sequence/Array.cpp b/src/core/datatypes/container/sequence/Array.cpp index dd93c7e..64560ce 100644 --- a/src/core/datatypes/container/sequence/Array.cpp +++ b/src/core/datatypes/container/sequence/Array.cpp @@ -75,14 +75,13 @@ void run() { } // namespace #include "ExampleRegistry.h" -#include "IExample.h" class Array : public IExample { public: - std::string group() const override { return "core"; } + std::string group() const override { return "core/container"; } std::string name() const override { return "Array"; } std::string description() const override { return ""; } void execute() override { run(); } }; -REGISTER_EXAMPLE(Array, "core", "Array"); \ No newline at end of file +REGISTER_EXAMPLE(Array, "core/container", "Array"); \ No newline at end of file diff --git a/src/core/datatypes/container/sequence/Deque.cpp b/src/core/datatypes/container/sequence/Deque.cpp index e9dc4cf..e161ea1 100644 --- a/src/core/datatypes/container/sequence/Deque.cpp +++ b/src/core/datatypes/container/sequence/Deque.cpp @@ -36,14 +36,13 @@ void run() { } // namespace #include "ExampleRegistry.h" -#include "IExample.h" class Deque : public IExample { public: - std::string group() const override { return "core"; } + std::string group() const override { return "core/container"; } std::string name() const override { return "Deque"; } std::string description() const override { return "std::deque Example"; } void execute() override { run(); } }; -REGISTER_EXAMPLE(Deque, "core", "Deque"); \ No newline at end of file +REGISTER_EXAMPLE(Deque, "core/container", "Deque"); \ No newline at end of file diff --git a/src/core/datatypes/container/sequence/Vector.cpp b/src/core/datatypes/container/sequence/Vector.cpp index fc8c2b3..2286e8d 100644 --- a/src/core/datatypes/container/sequence/Vector.cpp +++ b/src/core/datatypes/container/sequence/Vector.cpp @@ -48,14 +48,13 @@ void run() { } // namespace #include "ExampleRegistry.h" -#include "IExample.h" class Vector : public IExample { public: - std::string group() const override { return "core"; } + std::string group() const override { return "core/container"; } std::string name() const override { return "Vector"; } std::string description() const override { return ""; } void execute() override { run(); } }; -REGISTER_EXAMPLE(Vector, "core", "Vector"); \ No newline at end of file +REGISTER_EXAMPLE(Vector, "core/container", "Vector"); \ No newline at end of file diff --git a/src/core/datatypes/container/unordered/UnorderedMap.cpp b/src/core/datatypes/container/unordered/UnorderedMap.cpp index 855403a..fae0b00 100644 --- a/src/core/datatypes/container/unordered/UnorderedMap.cpp +++ b/src/core/datatypes/container/unordered/UnorderedMap.cpp @@ -70,14 +70,13 @@ void run() { } // namespace #include "ExampleRegistry.h" -#include "IExample.h" class UnorderedMap : public IExample { public: - std::string group() const override { return "core"; } + std::string group() const override { return "core/container"; } std::string name() const override { return "UnorderedMap"; } std::string description() const override { return ""; } void execute() override { run(); } }; -REGISTER_EXAMPLE(UnorderedMap, "core", "UnorderedMap"); \ No newline at end of file +REGISTER_EXAMPLE(UnorderedMap, "core/container", "UnorderedMap"); \ No newline at end of file diff --git a/src/core/datatypes/smart_pointer/Shared.cpp b/src/core/datatypes/smart_pointer/Shared.cpp index 6af1d4a..48dc723 100644 --- a/src/core/datatypes/smart_pointer/Shared.cpp +++ b/src/core/datatypes/smart_pointer/Shared.cpp @@ -66,7 +66,6 @@ void run() { } // namespace #include "ExampleRegistry.h" -#include "IExample.h" class Shared : public IExample { public: diff --git a/src/core/datatypes/smart_pointer/Unique.cpp b/src/core/datatypes/smart_pointer/Unique.cpp index 6ec9179..514b6b6 100644 --- a/src/core/datatypes/smart_pointer/Unique.cpp +++ b/src/core/datatypes/smart_pointer/Unique.cpp @@ -54,7 +54,6 @@ void run() { } // namespace #include "ExampleRegistry.h" -#include "IExample.h" class Unique : public IExample { public: diff --git a/src/core/datatypes/smart_pointer/Weak.cpp b/src/core/datatypes/smart_pointer/Weak.cpp index 6980aec..3204bed 100644 --- a/src/core/datatypes/smart_pointer/Weak.cpp +++ b/src/core/datatypes/smart_pointer/Weak.cpp @@ -47,7 +47,6 @@ void run() { * wp.lock() != nullptr // same condition */ #include "ExampleRegistry.h" -#include "IExample.h" class Weak : public IExample { public: diff --git a/src/core/exception/BasicHandle.cpp b/src/core/exception/BasicHandle.cpp index ee6746a..af5f026 100644 --- a/src/core/exception/BasicHandle.cpp +++ b/src/core/exception/BasicHandle.cpp @@ -24,11 +24,10 @@ void run() { } // namespace #include "ExampleRegistry.h" -#include "IExample.h" class BasicHandle : public IExample { public: - std::string group() const override { return "core"; } + std::string group() const override { return "core/exception"; } std::string name() const override { return "BasicHandle"; } std::string description() const override { return "Basic Expception Handle Example"; @@ -36,4 +35,4 @@ class BasicHandle : public IExample { void execute() override { run(); } }; -REGISTER_EXAMPLE(BasicHandle, "core", "BasicHandle"); \ No newline at end of file +REGISTER_EXAMPLE(BasicHandle, "core/exception", "BasicHandle"); \ No newline at end of file diff --git a/src/core/exception/ThrowNoexcept.cpp b/src/core/exception/ThrowNoexcept.cpp index ee3315e..9be8f45 100644 --- a/src/core/exception/ThrowNoexcept.cpp +++ b/src/core/exception/ThrowNoexcept.cpp @@ -35,11 +35,10 @@ void run() { } // namespace #include "ExampleRegistry.h" -#include "IExample.h" class ThrowNoexcept : public IExample { public: - std::string group() const override { return "core"; } + std::string group() const override { return "core/exception"; } std::string name() const override { return "ThrowNoexcept"; } std::string description() const override { return "Exception throw/noexcept Example"; @@ -47,4 +46,4 @@ class ThrowNoexcept : public IExample { void execute() override { run(); } }; -REGISTER_EXAMPLE(ThrowNoexcept, "core", "ThrowNoexcept"); \ No newline at end of file +REGISTER_EXAMPLE(ThrowNoexcept, "core/exception", "ThrowNoexcept"); \ No newline at end of file diff --git a/src/core/expression/FunctionPointer.cpp b/src/core/expression/FunctionPointer.cpp index 388b05f..04cdfb2 100644 --- a/src/core/expression/FunctionPointer.cpp +++ b/src/core/expression/FunctionPointer.cpp @@ -50,11 +50,10 @@ void run() { } // namespace #include "ExampleRegistry.h" -#include "IExample.h" class FunctionPointer : public IExample { public: - std::string group() const override { return "core"; } + std::string group() const override { return "core/expression"; } std::string name() const override { return "FunctionPointer"; } std::string description() const override { return "Function Pointer Example"; @@ -62,4 +61,4 @@ class FunctionPointer : public IExample { void execute() override { run(); } }; -REGISTER_EXAMPLE(FunctionPointer, "core", "FunctionPointer"); +REGISTER_EXAMPLE(FunctionPointer, "core/expression", "FunctionPointer"); diff --git a/src/core/expression/Lambda.cpp b/src/core/expression/Lambda.cpp index 58bdb56..b93a7f1 100644 --- a/src/core/expression/Lambda.cpp +++ b/src/core/expression/Lambda.cpp @@ -37,11 +37,10 @@ void run() { } // namespace #include "ExampleRegistry.h" -#include "IExample.h" class Lambda : public IExample { public: - std::string group() const override { return "core"; } + std::string group() const override { return "core/expression"; } std::string name() const override { return "Lambda"; } std::string description() const override { return "Lambda Expression Example"; @@ -49,4 +48,4 @@ class Lambda : public IExample { void execute() override { run(); } }; -REGISTER_EXAMPLE(Lambda, "core", "Lambda"); +REGISTER_EXAMPLE(Lambda, "core/expression", "Lambda"); diff --git a/src/core/filehandle/Directory.cpp b/src/core/filehandle/Directory.cpp index 08365f7..bb62f77 100644 --- a/src/core/filehandle/Directory.cpp +++ b/src/core/filehandle/Directory.cpp @@ -3,7 +3,6 @@ #include #include "ExampleRegistry.h" -#include "IExample.h" namespace { void run() { @@ -44,10 +43,10 @@ void run() { class Directory : public IExample { public: - std::string group() const override { return "core"; } + std::string group() const override { return "core/filehandle"; } std::string name() const override { return "Directory"; } std::string description() const override { return ""; } void execute() override { run(); } }; -REGISTER_EXAMPLE(Directory, "core", "Directory"); \ No newline at end of file +REGISTER_EXAMPLE(Directory, "core/filehandle", "Directory"); \ No newline at end of file diff --git a/src/core/filehandle/FileIO.cpp b/src/core/filehandle/FileIO.cpp index 8de57dd..bfd505f 100644 --- a/src/core/filehandle/FileIO.cpp +++ b/src/core/filehandle/FileIO.cpp @@ -107,14 +107,13 @@ void run() { } // namespace #include "ExampleRegistry.h" -#include "IExample.h" class FileIO : public IExample { public: - std::string group() const override { return "core"; } + std::string group() const override { return "core/filehandle"; } std::string name() const override { return "FileIO"; } std::string description() const override { return ""; } void execute() override { run(); } }; -REGISTER_EXAMPLE(FileIO, "core", "FileIO"); \ No newline at end of file +REGISTER_EXAMPLE(FileIO, "core/filehandle", "FileIO"); \ No newline at end of file diff --git a/src/core/filehandle/IOStream.cpp b/src/core/filehandle/IOStream.cpp index 0a93afe..a8e78c8 100644 --- a/src/core/filehandle/IOStream.cpp +++ b/src/core/filehandle/IOStream.cpp @@ -3,7 +3,6 @@ #include #include "ExampleRegistry.h" -#include "IExample.h" namespace { void run() { @@ -33,10 +32,10 @@ void run() { class IOStream : public IExample { public: - std::string group() const override { return "core"; } + std::string group() const override { return "core/filehandle"; } std::string name() const override { return "IOStream"; } std::string description() const override { return ""; } void execute() override { run(); } }; -REGISTER_EXAMPLE(IOStream, "core", "IOStream"); \ No newline at end of file +REGISTER_EXAMPLE(IOStream, "core/filehandle", "IOStream"); \ No newline at end of file diff --git a/src/core/filehandle/StringStream.cpp b/src/core/filehandle/StringStream.cpp index e77b261..9185084 100644 --- a/src/core/filehandle/StringStream.cpp +++ b/src/core/filehandle/StringStream.cpp @@ -3,7 +3,6 @@ #include #include "ExampleRegistry.h" -#include "IExample.h" namespace { void runStringStreamExample() { @@ -40,10 +39,10 @@ void runStringStreamExample() { class StringStream : public IExample { public: - std::string group() const override { return "core"; } + std::string group() const override { return "core/filehandle"; } std::string name() const override { return "StringStream"; } std::string description() const override { return ""; } void execute() override { runStringStreamExample(); } }; -REGISTER_EXAMPLE(StringStream, "core", "StringStream"); \ No newline at end of file +REGISTER_EXAMPLE(StringStream, "core/filehandle", "StringStream"); \ No newline at end of file diff --git a/src/core/linkage/Linkage.cpp b/src/core/linkage/Linkage.cpp index 59ea4f4..2223ed4 100644 --- a/src/core/linkage/Linkage.cpp +++ b/src/core/linkage/Linkage.cpp @@ -39,7 +39,6 @@ void run() { } // namespace External #include "ExampleRegistry.h" -#include "IExample.h" class Linkage : public IExample { public: diff --git a/src/core/linkage/sharing/Sharing.cpp b/src/core/linkage/sharing/Sharing.cpp index 0e3d4e7..629232f 100644 --- a/src/core/linkage/sharing/Sharing.cpp +++ b/src/core/linkage/sharing/Sharing.cpp @@ -25,7 +25,6 @@ void run() { } // namespace InlineWay #include "ExampleRegistry.h" -#include "IExample.h" class Sharing : public IExample { public: diff --git a/src/core/string/CString.cpp b/src/core/string/CString.cpp index 56d7029..d5e83b0 100644 --- a/src/core/string/CString.cpp +++ b/src/core/string/CString.cpp @@ -192,7 +192,6 @@ void run() { } // namespace #include "ExampleRegistry.h" -#include "IExample.h" class CString : public IExample { public: diff --git a/src/main.cpp b/src/main.cpp index 199bc1d..ad8b908 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -37,16 +37,21 @@ void runMenu() { std::vector groups; for (const auto& [group, _] : data) { - std::cout << gIndex++ << ". " << group << "\n"; groups.push_back(group); } - std::cout << "0. quit\n"; + + // sort + std::sort(groups.begin(), groups.end()); + for (const auto& group : groups) { + std::cout << gIndex++ << ". " << group << "\n"; + } + std::cout << "0. Exit\n"; std::cout << "----------------------------------------\n"; std::cout << "Enter choice: "; int gChoice = readChoice(); if (gChoice == 0) { - std::cout << "End\n"; + std::cout << "\n--- Exit ---\n"; break; } @@ -67,7 +72,7 @@ void runMenu() { std::cout << eIndex++ << ". " << name << "\n"; names.push_back(name); } - std::cout << "0. back\n"; + std::cout << "0. Back\n"; std::cout << "----------------------------------------\n"; std::cout << "Enter choice: "; diff --git a/src/patterns/behavioral/ChainOfCommand.cpp b/src/patterns/behavioral/ChainOfCommand.cpp index a359d61..fca6de1 100644 --- a/src/patterns/behavioral/ChainOfCommand.cpp +++ b/src/patterns/behavioral/ChainOfCommand.cpp @@ -135,15 +135,14 @@ void run() { } // namespace #include "ExampleRegistry.h" -#include "IExample.h" class ChainOfResponsibilityExample : public IExample { public: - std::string group() const override { return "patterns"; } + std::string group() const override { return "patterns/behavioral"; } std::string name() const override { return "ChainOfResponsibility"; } std::string description() const override { return "CoR Pattern Example"; } void execute() override { CoR::run(); } }; -REGISTER_EXAMPLE(ChainOfResponsibilityExample, "patterns", +REGISTER_EXAMPLE(ChainOfResponsibilityExample, "patterns/behavioral", "ChainOfResponsibility"); \ No newline at end of file diff --git a/src/patterns/behavioral/Command.cpp b/src/patterns/behavioral/Command.cpp index dc73396..240c4b7 100644 --- a/src/patterns/behavioral/Command.cpp +++ b/src/patterns/behavioral/Command.cpp @@ -126,14 +126,13 @@ void run() { } // namespace #include "ExampleRegistry.h" -#include "IExample.h" class CommandExample : public IExample { public: - std::string group() const override { return "patterns"; } + std::string group() const override { return "patterns/behavioral"; } std::string name() const override { return "Command"; } std::string description() const override { return "Command Pattern Example"; } void execute() override { Command::run(); } }; -REGISTER_EXAMPLE(CommandExample, "patterns", "Command"); \ No newline at end of file +REGISTER_EXAMPLE(CommandExample, "patterns/behavioral", "Command"); \ No newline at end of file diff --git a/src/patterns/behavioral/Iterator.cpp b/src/patterns/behavioral/Iterator.cpp index 0222e69..cd085f7 100644 --- a/src/patterns/behavioral/Iterator.cpp +++ b/src/patterns/behavioral/Iterator.cpp @@ -197,11 +197,10 @@ void run() { } // namespace #include "ExampleRegistry.h" -#include "IExample.h" class IteratorExample : public IExample { public: - std::string group() const override { return "patterns"; } + std::string group() const override { return "patterns/behavioral"; } std::string name() const override { return "Iterator"; } std::string description() const override { return "Iterator Pattern Example"; @@ -209,4 +208,4 @@ class IteratorExample : public IExample { void execute() override { Iterator::run(); } }; -REGISTER_EXAMPLE(IteratorExample, "patterns", "Iterator"); \ No newline at end of file +REGISTER_EXAMPLE(IteratorExample, "patterns/behavioral", "Iterator"); \ No newline at end of file diff --git a/src/patterns/behavioral/Mediator.cpp b/src/patterns/behavioral/Mediator.cpp index ec28195..1bb8e96 100644 --- a/src/patterns/behavioral/Mediator.cpp +++ b/src/patterns/behavioral/Mediator.cpp @@ -163,11 +163,10 @@ void run() { } // namespace #include "ExampleRegistry.h" -#include "IExample.h" class MediatorExample : public IExample { public: - std::string group() const override { return "patterns"; } + std::string group() const override { return "patterns/behavioral"; } std::string name() const override { return "Mediator"; } std::string description() const override { return "Mediator Pattern Example"; @@ -175,4 +174,4 @@ class MediatorExample : public IExample { void execute() override { Mediator::run(); } }; -REGISTER_EXAMPLE(MediatorExample, "patterns", "Mediator"); \ No newline at end of file +REGISTER_EXAMPLE(MediatorExample, "patterns/behavioral", "Mediator"); \ No newline at end of file diff --git a/src/patterns/behavioral/Memento.cpp b/src/patterns/behavioral/Memento.cpp index 6f378c2..0eedf6e 100644 --- a/src/patterns/behavioral/Memento.cpp +++ b/src/patterns/behavioral/Memento.cpp @@ -192,11 +192,10 @@ void run() { } // namespace #include "ExampleRegistry.h" -#include "IExample.h" class MementoExample : public IExample { public: - std::string group() const override { return "patterns"; } + std::string group() const override { return "patterns/behavioral"; } std::string name() const override { return "Memento"; } std::string description() const override { return "Memento Pattern Example "; @@ -204,4 +203,4 @@ class MementoExample : public IExample { void execute() override { Memento::run(); } }; -REGISTER_EXAMPLE(MementoExample, "patterns", "Memento"); \ No newline at end of file +REGISTER_EXAMPLE(MementoExample, "patterns/behavioral", "Memento"); \ No newline at end of file diff --git a/src/patterns/behavioral/Observer.cpp b/src/patterns/behavioral/Observer.cpp index cf8a62f..decb5e5 100644 --- a/src/patterns/behavioral/Observer.cpp +++ b/src/patterns/behavioral/Observer.cpp @@ -176,11 +176,10 @@ void run() { } // namespace #include "ExampleRegistry.h" -#include "IExample.h" class ObserverExample : public IExample { public: - std::string group() const override { return "patterns"; } + std::string group() const override { return "patterns/behavioral"; } std::string name() const override { return "Observer"; } std::string description() const override { return "Observer Pattern Example"; @@ -188,4 +187,4 @@ class ObserverExample : public IExample { void execute() override { Observer::run(); } }; -REGISTER_EXAMPLE(ObserverExample, "patterns", "Observer"); \ No newline at end of file +REGISTER_EXAMPLE(ObserverExample, "patterns/behavioral", "Observer"); \ No newline at end of file diff --git a/src/patterns/behavioral/State.cpp b/src/patterns/behavioral/State.cpp index a507cd5..05fb9a5 100644 --- a/src/patterns/behavioral/State.cpp +++ b/src/patterns/behavioral/State.cpp @@ -133,14 +133,13 @@ void run() { } // namespace #include "ExampleRegistry.h" -#include "IExample.h" class StateExample : public IExample { public: - std::string group() const override { return "patterns"; } + std::string group() const override { return "patterns/behavioral"; } std::string name() const override { return "State"; } std::string description() const override { return "State Pattern Example"; } void execute() override { State::run(); } }; -REGISTER_EXAMPLE(StateExample, "patterns", "State"); \ No newline at end of file +REGISTER_EXAMPLE(StateExample, "patterns/behavioral", "State"); \ No newline at end of file diff --git a/src/patterns/behavioral/Strategy.cpp b/src/patterns/behavioral/Strategy.cpp index e9b7084..a929389 100644 --- a/src/patterns/behavioral/Strategy.cpp +++ b/src/patterns/behavioral/Strategy.cpp @@ -102,11 +102,10 @@ void run() { } // namespace #include "ExampleRegistry.h" -#include "IExample.h" class StrategyExample : public IExample { public: - std::string group() const override { return "patterns"; } + std::string group() const override { return "patterns/behavioral"; } std::string name() const override { return "Strategy"; } std::string description() const override { return "Strategy Pattern Example"; @@ -114,4 +113,4 @@ class StrategyExample : public IExample { void execute() override { Strategy::run(); } }; -REGISTER_EXAMPLE(StrategyExample, "patterns", "Strategy"); \ No newline at end of file +REGISTER_EXAMPLE(StrategyExample, "patterns/behavioral", "Strategy"); \ No newline at end of file diff --git a/src/patterns/behavioral/TemplateMethod.cpp b/src/patterns/behavioral/TemplateMethod.cpp index 5ce9852..0cdcdf6 100644 --- a/src/patterns/behavioral/TemplateMethod.cpp +++ b/src/patterns/behavioral/TemplateMethod.cpp @@ -104,11 +104,10 @@ void run() { } // namespace #include "ExampleRegistry.h" -#include "IExample.h" class TemplateMethodExample : public IExample { public: - std::string group() const override { return "patterns"; } + std::string group() const override { return "patterns/behavioral"; } std::string name() const override { return "TemplateMethod"; } std::string description() const override { return "TemplateMethod Pattern Example"; @@ -116,4 +115,4 @@ class TemplateMethodExample : public IExample { void execute() override { TemplateMethod::run(); } }; -REGISTER_EXAMPLE(TemplateMethodExample, "patterns", "TemplateMethod"); \ No newline at end of file +REGISTER_EXAMPLE(TemplateMethodExample, "patterns/behavioral", "TemplateMethod"); \ No newline at end of file diff --git a/src/patterns/behavioral/Visitor.cpp b/src/patterns/behavioral/Visitor.cpp index 54aff44..ea11a59 100644 --- a/src/patterns/behavioral/Visitor.cpp +++ b/src/patterns/behavioral/Visitor.cpp @@ -237,14 +237,13 @@ void run() { } // namespace #include "ExampleRegistry.h" -#include "IExample.h" class VisitorExample : public IExample { public: - std::string group() const override { return "patterns"; } + std::string group() const override { return "patterns/behavioral"; } std::string name() const override { return "Visitor"; } std::string description() const override { return "Visitor Pattern Example"; } void execute() override { Visitor::run(); } }; -REGISTER_EXAMPLE(VisitorExample, "patterns", "Visitor"); \ No newline at end of file +REGISTER_EXAMPLE(VisitorExample, "patterns/behavioral", "Visitor"); \ No newline at end of file diff --git a/src/patterns/creational/AbstractFactory.cpp b/src/patterns/creational/AbstractFactory.cpp index 8b3b10e..b78653a 100644 --- a/src/patterns/creational/AbstractFactory.cpp +++ b/src/patterns/creational/AbstractFactory.cpp @@ -164,11 +164,10 @@ void run() { } // namespace #include "ExampleRegistry.h" -#include "IExample.h" class AbstractFactoryExample : public IExample { public: - std::string group() const override { return "patterns"; } + std::string group() const override { return "patterns/creational"; } std::string name() const override { return "AbstractFactory"; } std::string description() const override { return "AbstractFactory Pattern Example"; @@ -176,4 +175,4 @@ class AbstractFactoryExample : public IExample { void execute() override { AbstractFactory::run(); } }; -REGISTER_EXAMPLE(AbstractFactoryExample, "patterns", "AbstractFactory"); \ No newline at end of file +REGISTER_EXAMPLE(AbstractFactoryExample, "patterns/creational", "AbstractFactory"); \ No newline at end of file diff --git a/src/patterns/creational/Builder.cpp b/src/patterns/creational/Builder.cpp index 5c32374..46ed44f 100644 --- a/src/patterns/creational/Builder.cpp +++ b/src/patterns/creational/Builder.cpp @@ -162,14 +162,13 @@ void run() { } // namespace #include "ExampleRegistry.h" -#include "IExample.h" class BuilderExample : public IExample { public: - std::string group() const override { return "patterns"; } + std::string group() const override { return "patterns/creational"; } std::string name() const override { return "Builder"; } std::string description() const override { return "Builder Pattern Example"; } void execute() override { BuilderPattern::run(); } }; -REGISTER_EXAMPLE(BuilderExample, "patterns", "Builder"); \ No newline at end of file +REGISTER_EXAMPLE(BuilderExample, "patterns/creational", "Builder"); \ No newline at end of file diff --git a/src/patterns/creational/FactoryMethod.cpp b/src/patterns/creational/FactoryMethod.cpp index 78962b4..80dc69f 100644 --- a/src/patterns/creational/FactoryMethod.cpp +++ b/src/patterns/creational/FactoryMethod.cpp @@ -131,11 +131,10 @@ void run() { } // namespace #include "ExampleRegistry.h" -#include "IExample.h" class FactoryMethodExample : public IExample { public: - std::string group() const override { return "patterns"; } + std::string group() const override { return "patterns/creational"; } std::string name() const override { return "FactoryMethod"; } std::string description() const override { return "FactoryMethod Pattern Example"; @@ -143,4 +142,4 @@ class FactoryMethodExample : public IExample { void execute() override { FactoryMethod::run(); } }; -REGISTER_EXAMPLE(FactoryMethodExample, "patterns", "FactoryMethod"); \ No newline at end of file +REGISTER_EXAMPLE(FactoryMethodExample, "patterns/creational", "FactoryMethod"); \ No newline at end of file diff --git a/src/patterns/creational/Prototype.cpp b/src/patterns/creational/Prototype.cpp index 1ec8a0a..8fd289c 100644 --- a/src/patterns/creational/Prototype.cpp +++ b/src/patterns/creational/Prototype.cpp @@ -118,11 +118,10 @@ void run() { } // namespace #include "ExampleRegistry.h" -#include "IExample.h" class PrototypeExample : public IExample { public: - std::string group() const override { return "patterns"; } + std::string group() const override { return "patterns/creational"; } std::string name() const override { return "Prototype"; } std::string description() const override { return "Prototype Pattern Example"; @@ -130,4 +129,4 @@ class PrototypeExample : public IExample { void execute() override { Prototy::run(); } }; -REGISTER_EXAMPLE(PrototypeExample, "patterns", "Prototype"); \ No newline at end of file +REGISTER_EXAMPLE(PrototypeExample, "patterns/creational", "Prototype"); \ No newline at end of file diff --git a/src/patterns/creational/Singleton.cpp b/src/patterns/creational/Singleton.cpp index 953e629..65e845e 100644 --- a/src/patterns/creational/Singleton.cpp +++ b/src/patterns/creational/Singleton.cpp @@ -71,11 +71,10 @@ void run() { } // namespace #include "ExampleRegistry.h" -#include "IExample.h" class SingletonExample : public IExample { public: - std::string group() const override { return "patterns"; } + std::string group() const override { return "patterns/creational"; } std::string name() const override { return "Singleton"; } std::string description() const override { return "Singleton Pattern Example"; @@ -83,4 +82,4 @@ class SingletonExample : public IExample { void execute() override { SingletonPattern::run(); } }; -REGISTER_EXAMPLE(SingletonExample, "patterns", "Singleton"); \ No newline at end of file +REGISTER_EXAMPLE(SingletonExample, "patterns/creational", "Singleton"); \ No newline at end of file diff --git a/src/patterns/structural/Adapter.cpp b/src/patterns/structural/Adapter.cpp index 98e35ee..90fcead 100644 --- a/src/patterns/structural/Adapter.cpp +++ b/src/patterns/structural/Adapter.cpp @@ -142,11 +142,10 @@ void run() { } // namespace CaseStudy #include "ExampleRegistry.h" -#include "IExample.h" class AdapterExample : public IExample { public: - std::string group() const override { return "patterns"; } + std::string group() const override { return "patterns/structural"; } std::string name() const override { return "Adapter"; } std::string description() const override { return "Factory Pattern Example"; } void execute() override { @@ -155,4 +154,4 @@ class AdapterExample : public IExample { } }; -REGISTER_EXAMPLE(AdapterExample, "patterns", "Adapter"); \ No newline at end of file +REGISTER_EXAMPLE(AdapterExample, "patterns/structural", "Adapter"); \ No newline at end of file diff --git a/src/patterns/structural/Bridge.cpp b/src/patterns/structural/Bridge.cpp index 234bfb0..f6a19a9 100644 --- a/src/patterns/structural/Bridge.cpp +++ b/src/patterns/structural/Bridge.cpp @@ -14,7 +14,6 @@ #include #include "ExampleRegistry.h" -#include "IExample.h" namespace { namespace Problem { @@ -172,7 +171,7 @@ void run() { class BridgeExample : public IExample { public: - std::string group() const override { return "patterns"; } + std::string group() const override { return "patterns/structural"; } std::string name() const override { return "Bridge"; } std::string description() const override { return "Bridge Pattern Example"; } void execute() override { @@ -181,5 +180,5 @@ class BridgeExample : public IExample { } }; -REGISTER_EXAMPLE(BridgeExample, "patterns", "Bridge"); +REGISTER_EXAMPLE(BridgeExample, "patterns/structural", "Bridge"); } // namespace \ No newline at end of file diff --git a/src/patterns/structural/Composite.cpp b/src/patterns/structural/Composite.cpp index 968bbc2..7a40213 100644 --- a/src/patterns/structural/Composite.cpp +++ b/src/patterns/structural/Composite.cpp @@ -426,11 +426,10 @@ void run() { } // namespace #include "ExampleRegistry.h" -#include "IExample.h" class CompositeExample : public IExample { public: - std::string group() const override { return "patterns"; } + std::string group() const override { return "patterns/structural"; } std::string name() const override { return "Composite"; } std::string description() const override { return "Composite Pattern Example"; @@ -441,4 +440,4 @@ class CompositeExample : public IExample { } }; -REGISTER_EXAMPLE(CompositeExample, "patterns", "Composite"); \ No newline at end of file +REGISTER_EXAMPLE(CompositeExample, "patterns/structural", "Composite"); \ No newline at end of file diff --git a/src/patterns/structural/Decorator.cpp b/src/patterns/structural/Decorator.cpp index 20e8b61..5e66230 100644 --- a/src/patterns/structural/Decorator.cpp +++ b/src/patterns/structural/Decorator.cpp @@ -186,11 +186,10 @@ void run() { } // namespace #include "ExampleRegistry.h" -#include "IExample.h" class DecoratorExample : public IExample { public: - std::string group() const override { return "patterns"; } + std::string group() const override { return "patterns/structural"; } std::string name() const override { return "Decorator"; } std::string description() const override { return "Decorator Pattern Example"; @@ -201,4 +200,4 @@ class DecoratorExample : public IExample { } }; -REGISTER_EXAMPLE(DecoratorExample, "patterns", "Decorator"); \ No newline at end of file +REGISTER_EXAMPLE(DecoratorExample, "patterns/structural", "Decorator"); \ No newline at end of file diff --git a/src/patterns/structural/Facade.cpp b/src/patterns/structural/Facade.cpp index 4fc7f54..04f8940 100644 --- a/src/patterns/structural/Facade.cpp +++ b/src/patterns/structural/Facade.cpp @@ -210,11 +210,10 @@ void run() { } // namespace #include "ExampleRegistry.h" -#include "IExample.h" class FacadeExample : public IExample { public: - std::string group() const override { return "patterns"; } + std::string group() const override { return "patterns/structural"; } std::string name() const override { return "Facade"; } std::string description() const override { return "Facade Pattern Example"; } void execute() override { @@ -223,4 +222,4 @@ class FacadeExample : public IExample { } }; -REGISTER_EXAMPLE(FacadeExample, "patterns", "Facade"); \ No newline at end of file +REGISTER_EXAMPLE(FacadeExample, "patterns/structural", "Facade"); \ No newline at end of file diff --git a/src/patterns/structural/Flyweight.cpp b/src/patterns/structural/Flyweight.cpp index 61aa2ad..ed9436d 100644 --- a/src/patterns/structural/Flyweight.cpp +++ b/src/patterns/structural/Flyweight.cpp @@ -328,11 +328,10 @@ void run() { } // namespace #include "ExampleRegistry.h" -#include "IExample.h" class FlyweightExample : public IExample { public: - std::string group() const override { return "patterns"; } + std::string group() const override { return "patterns/structural"; } std::string name() const override { return "Flyweight"; } std::string description() const override { return "Flyweight Pattern Example"; @@ -343,4 +342,4 @@ class FlyweightExample : public IExample { } }; -REGISTER_EXAMPLE(FlyweightExample, "patterns", "Flyweight"); \ No newline at end of file +REGISTER_EXAMPLE(FlyweightExample, "patterns/structural", "Flyweight"); \ No newline at end of file diff --git a/src/patterns/structural/Proxy.cpp b/src/patterns/structural/Proxy.cpp index 0589aff..a5d79f8 100644 --- a/src/patterns/structural/Proxy.cpp +++ b/src/patterns/structural/Proxy.cpp @@ -17,7 +17,6 @@ #include #include "ExampleRegistry.h" -#include "IExample.h" namespace { namespace Problem { @@ -222,7 +221,7 @@ void run() { class ProxyExample : public IExample { public: - std::string group() const override { return "patterns"; } + std::string group() const override { return "patterns/structural"; } std::string name() const override { return "Proxy"; } std::string description() const override { return "Proxy Pattern Example"; } void execute() override { @@ -231,5 +230,5 @@ class ProxyExample : public IExample { } }; -REGISTER_EXAMPLE(ProxyExample, "patterns", "Proxy"); +REGISTER_EXAMPLE(ProxyExample, "patterns/structural", "Proxy"); } // namespace