Skip to content

Commit bcb3095

Browse files
authored
Merge pull request #43 from urbytes21/dev_branch_1
id 1772703616
2 parents a6a460b + 39d0390 commit bcb3095

7 files changed

Lines changed: 150 additions & 4 deletions

File tree

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ set(APP_SOURCES
172172
"src/core/overloading/AssignmentOperator.cpp"
173173
"src/core/overloading/ClassMemberAccessOperator.cpp"
174174
"src/core/overloading/AllocationOperator.cpp"
175+
## Date and Time
176+
"src/core/datetime/CTime.cpp"
175177
)
176178

177179
# Test files

README.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
## 1. Overview
2+
**TL;DR**
3+
```bash
4+
./r
5+
```
6+
27
**Project Structure**
38
```
49
includes/ → Header files (.h, .hpp)
@@ -50,6 +55,11 @@ Get-ChildItem -Recurse -Include *.cpp, *.h, *.hpp | ForEach-Object { clang-forma
5055
$ ./cpp_lab_project
5156
$ ./cpp_lab_project_test
5257
```
58+
* Detect Memory Leak Using [valgrind](https://valgrind.org/)
59+
```
60+
$ sudo apt install valgrind
61+
$ valgrind --leak-check=full -v ./cpp-lab
62+
```
5363
* (Optional) Run static analysis - cppcheck
5464
```
5565
$ sudo apt-get install cppcheck
@@ -100,6 +110,21 @@ docker image ls
100110
docker push DOCKER_USERNAME/cpp-lab
101111
```
102112
103-
## 6. TROUBLESHOOTING
113+
## 6. TroubleShooting
104114
1. `push access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed`
105115
=> docker login / Docker Desktop login
116+
117+
## 7. Evaluate Executable
118+
- List all sections:
119+
```bash
120+
$ size ./build/cpp-lab
121+
```
122+
- The expected output should be the following:
123+
```bash
124+
text data bss dec hex filename
125+
14791 792 280 15863 ./build/cpp-lab
126+
```
127+
128+
- `.text`: Text Segment - the executable code size, including: complied function, inline, template, constants, string literals
129+
- `.data`: Initialized Data Segment - the memory for the global, static variables, has init value.
130+
- `.bss`: Uninitialized Data Segment - global and static variables that are not initialized

run.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
## NOTE:
2+
## This file was initially generated with the assistance of AI.
3+
## The code has been reviewed and may have been modified by the developer
4+
## to ensure correctness, readability, and compliance with project requirements.
5+
#!/usr/bin/env bash
6+
7+
set -e # Exit immediately if a command fails
8+
9+
PROJECT_EXEC="./build/cpp_lab_project"
10+
BUILD_DIR="./build"
11+
12+
clear
13+
echo "=============================="
14+
echo " Starting build pipeline... "
15+
echo "=============================="
16+
17+
# Check required tools
18+
for tool in cmake cppcheck python3; do
19+
if ! command -v $tool &> /dev/null; then
20+
echo "[ERR]: $tool is not installed."
21+
exit 1
22+
fi
23+
done
24+
25+
echo ""
26+
echo "===========>> Building project..."
27+
cmake --build "$BUILD_DIR"
28+
29+
echo ""
30+
echo "===========>> Running cppcheck..."
31+
cppcheck \
32+
--enable=warning,style,performance,portability \
33+
--inconclusive \
34+
--inline-suppr \
35+
--quiet \
36+
--error-exitcode=1 \
37+
./src ./include
38+
39+
echo "[OK] Static analysis passed"
40+
41+
echo ""
42+
echo "===========>> Generating commit id..."
43+
python3 ./private/genid.py
44+
45+
echo ""
46+
echo "===========>> Running program..."
47+
if [ -f "$PROJECT_EXEC" ]; then
48+
"$PROJECT_EXEC"
49+
else
50+
echo "[ERR] Executable not found: $PROJECT_EXEC"
51+
exit 1
52+
fi
53+
54+
echo ""
55+
echo "=============================="
56+
echo "Pipeline finished successfully!"
57+
echo "=============================="

src/core/datetime/CTime.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include <iostream>
2+
#include "ExampleRegistry.h"
3+
4+
#include <ctime>
5+
6+
namespace {
7+
void run() {
8+
// **1. Get the current timestamp**
9+
std::time_t now = time(NULL);
10+
const auto* ts = ctime(&now);
11+
std::cout << "Current time: " << ts << '\n';
12+
13+
// **2. Create the dt structure**
14+
struct tm datetime = *localtime(&now);
15+
std::cout << "Year: " << datetime.tm_year + 1900 << '\n';
16+
std::cout << "Current time stamp: " << mktime(&datetime) << '\n';
17+
18+
// **3. Formatting**
19+
char output[50];
20+
strftime(output, 50, "%B %e, %Y", &datetime);
21+
std::cout << output << "\n";
22+
strftime(output, 50, "%I:%M:%S %p", &datetime);
23+
std::cout << output << "\n";
24+
strftime(output, 50, "%m/%d/%y", &datetime);
25+
std::cout << output << "\n";
26+
strftime(output, 50, "%a %b %e %H:%M:%S %Y", &datetime);
27+
std::cout << output << "\n";
28+
}
29+
} // namespace
30+
31+
class CTime : public IExample {
32+
public:
33+
std::string group() const override { return "core/datetime"; }
34+
std::string name() const override { return "CTime"; }
35+
std::string description() const override { return ""; }
36+
void execute() override { run(); }
37+
};
38+
39+
REGISTER_EXAMPLE(CTime, "core/datetime", "CTime");

src/core/datetime/REAME.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Date and Time
2+
- <ctime> : provides functions and types to work with date and time values including parsing and formatting (inherited from C)
3+
4+
- <chrono>: provides facilities to deal with the duration time points and clocks (std11), it is more modern and type-safe approach
5+
6+
## ctime
7+
- Data Types:
8+
- `time_t`: for timestamps
9+
- `struct tm`: for datetime structes
10+
- Use `mktime()` to convert struct tm to time_t, and `localtime()` and `gmtime()` for vice versa
11+
- `strftime()` format:
12+
>%a Short representation of the weekday Fri
13+
%b Short representation of the month name Dec
14+
%B Full representation of the month name December
15+
%d Day of the month with leading zero 09
16+
%e Day of the month with leading spaces 9
17+
%H 24-hour format of an hour 14
18+
%I 12-hour format of an hour 02
19+
%M Minutes within an hour 30
20+
%p AM or PM PM
21+
%S Seconds within a minute 01
22+
%y 2-digit year representation 23
23+
%Y 4-digit year representation 2023

src/core/exception/BasicHandle.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ void run() {
1212
errorFnc();
1313
} catch (std::exception& e) {
1414
std::cout << e.what();
15-
throw std::runtime_error("[M] Middle error \n");
15+
throw std::runtime_error("[M] Middle error \n"); // use as custom exception
1616
// throw; // rethrow
1717
}
1818
} catch (std::exception& e) {

src/core/filehandle/StringStream.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ void runStringStreamExample() {
1010

1111
std::stringstream os{};
1212

13-
// input
13+
// input: std::istringstream iss;
1414
os << "0xF";
1515
std::cout << os.str();
1616

@@ -19,7 +19,7 @@ void runStringStreamExample() {
1919
os.clear();
2020
std::cout << os.str();
2121

22-
// output
22+
// output: std::ostringstream oss;
2323
std::string bytesStr = os.str();
2424
std::cout << bytesStr;
2525

0 commit comments

Comments
 (0)