Skip to content

Commit 5a6bc9e

Browse files
authored
Merge pull request #62 from urbytes21/dev_branch_3
id 1778259501
2 parents e9135cb + 3b8d7c3 commit 5a6bc9e

109 files changed

Lines changed: 1222 additions & 646 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/README.md

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# CPP Lab Docs
22

3-
## Core
3+
---
4+
## 1. Core
45

56
1. [Basic](../src/core/basics/README.md)
67
2. [Class](../src/core/class/README.md)
@@ -12,18 +13,22 @@
1213
8. [File handle](../src/core/filehandle/README.md)
1314
9. [Smart pointer](../src/core/smart_pointer/README.md)
1415
10. [String](../src/core/string/README.md)
16+
11. [Utilities library](../src/core/utils/README.md)
1517

16-
## Design Patterns
18+
---
19+
## 2. Design Patterns
1720

18-
11. [Behavioral](../src/dp/behavioral/README.md)
19-
12. [Structural](../src/dp/structural/README.md)
20-
13. [Creational](../src/dp/creational/README.md)
21+
1. [Behavioral](../src/dp/behavioral/README.md)
22+
2. [Structural](../src/dp/structural/README.md)
23+
3. [Creational](../src/dp/creational/README.md)
2124

22-
## Architecture Patterns
25+
---
26+
## 3. Architecture Patterns
2327

24-
14. [MVC/MVVM](../src/ap/README.md)
28+
1. [MVC/MVVM](../src/ap/README.md)
2529

26-
## Other
30+
---
31+
## 4. Other
2732

28-
15. [Socket](../src/socket/README.md)
29-
16. [Google Test](../tests/README.md)
33+
1. [Socket](../src/socket/README.md)
34+
2. [Google Test](../tests/README.md)

include/ExampleRegistry.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@
44
#include <unordered_map>
55
#include "IExample.h"
66

7-
#define REGISTER_EXAMPLE(CLASS, GROUP, NAME) \
8-
namespace { \
9-
struct CLASS##Registrar { \
10-
CLASS##Registrar() { \
11-
ExampleRegistry::instance().registerExample( \
12-
GROUP, NAME, []() { return std::make_unique<CLASS>(); }); \
13-
} \
14-
}; \
15-
static CLASS##Registrar global_##CLASS##Registrar; \
7+
#define REGISTER_EXAMPLE(CLASS) \
8+
namespace { \
9+
struct CLASS##Registrar { \
10+
CLASS##Registrar() { \
11+
auto obj = std::make_unique<CLASS>(); \
12+
ExampleRegistry::instance().registerExample( \
13+
obj->group(), obj->name(), \
14+
[]() { return std::make_unique<CLASS>(); }); \
15+
} \
16+
}; \
17+
static CLASS##Registrar global_##CLASS##Registrar; \
1618
}
1719

1820
class ExampleRegistry {

include/Logger.h

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define LOGGER_H_
33

44
#include <iostream>
5+
#include <sstream>
56

67
#ifndef NDEBUG
78
#include <mutex>
@@ -35,9 +36,12 @@ class Logger {
3536
char time_buf[9];
3637
std::strftime(time_buf, sizeof(time_buf), "%H:%M:%S", &tm);
3738

39+
constexpr const char* kGreen = "\033[32m";
40+
constexpr const char* kReset = "\033[0m";
41+
3842
std::cout << "[" << time_buf << "]" << "[" << level << "]" << "[" << file
3943
<< ":" << loc.line() << "]" << "[" << loc.function_name() << "] "
40-
<< msg << '\n';
44+
<< kGreen << msg << kReset << '\n';
4145
}
4246

4347
// Prevent copies
@@ -51,11 +55,35 @@ class Logger {
5155

5256
#define LOG(msg) Logger::instance().log(msg)
5357

58+
#define LOG_S(expr) \
59+
do { \
60+
std::ostringstream oss_; \
61+
oss_ << expr; \
62+
std::string s_ = oss_.str(); \
63+
if (!s_.empty() && s_.back() == '\n') \
64+
s_.pop_back(); \
65+
Logger::instance().log(s_); \
66+
} while (0)
67+
5468
#else
5569

5670
inline void LOG(const std::string& msg) {
5771
std::cout << msg << '\n';
5872
}
5973

74+
inline void LOG_S_IMPL(std::ostringstream& oss) {
75+
std::string s = oss.str();
76+
if (!s.empty() && s.back() == '\n')
77+
s.pop_back();
78+
std::cout << s << '\n';
79+
}
80+
81+
#define LOG_S(expr) \
82+
do { \
83+
std::ostringstream oss_; \
84+
oss_ << expr; \
85+
LOG_S_IMPL(oss_); \
86+
} while (0)
87+
6088
#endif
6189
#endif

src/controller/pid/PIDSim.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ class PIDSim : public IExample {
2525
void execute() override { run(); }
2626
};
2727

28-
REGISTER_EXAMPLE(PIDSim, "controller", "PIDSim");
28+
REGISTER_EXAMPLE(PIDSim);

src/core/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ set(CORE_SOURCES
5656
${CMAKE_CURRENT_SOURCE_DIR}/filehandle/Directory.cpp
5757
${CMAKE_CURRENT_SOURCE_DIR}/filehandle/OutputFormatting.cpp
5858
${CMAKE_CURRENT_SOURCE_DIR}/filehandle/BinaryFileHandling.cpp
59+
${CMAKE_CURRENT_SOURCE_DIR}/filehandle/TerminalColor.cpp
5960

6061
# STL containers and expressions
6162
${CMAKE_CURRENT_SOURCE_DIR}/container/sequence/Array.cpp
@@ -98,8 +99,11 @@ set(CORE_SOURCES
9899
${CMAKE_CURRENT_SOURCE_DIR}/concurrency/FuturePromise.cpp
99100

100101
# Utils
101-
${CMAKE_CURRENT_SOURCE_DIR}/utils/StdAlgorithm.cpp
102+
${CMAKE_CURRENT_SOURCE_DIR}/utils/Algorithm.cpp
102103
${CMAKE_CURRENT_SOURCE_DIR}/utils/TypeTrait.cpp
104+
${CMAKE_CURRENT_SOURCE_DIR}/utils/Optional.cpp
105+
${CMAKE_CURRENT_SOURCE_DIR}/utils/Variadic.cpp
106+
${CMAKE_CURRENT_SOURCE_DIR}/utils/Regex.cpp
103107
)
104108

105109
# Export CORE_SOURCES to the parent CMakeLists.txt

src/core/basics/ControlFlow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,4 @@ class ControlFlow : public IExample {
132132
}
133133
};
134134

135-
REGISTER_EXAMPLE(ControlFlow, "core", "ControlFlow");
135+
REGISTER_EXAMPLE(ControlFlow);

src/core/basics/InitializeVariable.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class InitializeVariable : public IExample {
1313
void execute() override { initialize_variable(); }
1414
};
1515

16-
REGISTER_EXAMPLE(InitializeVariable, "core", "InitializeVariable");
16+
REGISTER_EXAMPLE(InitializeVariable);
1717

1818
struct Foo {
1919
Foo() { std::cout << "Default constructor/ default init\n"; }

src/core/basics/Operations.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Operations : public IExample {
1919
}
2020
};
2121

22-
REGISTER_EXAMPLE(Operations, "core", "Operations");
22+
REGISTER_EXAMPLE(Operations);
2323

2424
void arithmeticOperator() {
2525
std::cout << "\n--- ArithmeticOperator Examples ---\n";

src/core/basics/TypeQualifier.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ class TypeQualifier : public IExample {
4040
void execute() override { Constant::run(); }
4141
};
4242

43-
REGISTER_EXAMPLE(TypeQualifier, "core", "TypeQualifier");
43+
REGISTER_EXAMPLE(TypeQualifier);

src/core/class/Binding.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ void run() {
6969
} // namespace
7070

7171
class Binding : public IExample {
72+
public:
7273
std::string group() const override { return "core/class"; };
7374

7475
std::string name() const override { return "Binding"; };
@@ -80,4 +81,4 @@ class Binding : public IExample {
8081
};
8182
};
8283

83-
REGISTER_EXAMPLE(Binding, "core/class", "Binding");
84+
REGISTER_EXAMPLE(Binding);

0 commit comments

Comments
 (0)