From 5038b21d4d353f85426427042a39ea9f0b77f93a Mon Sep 17 00:00:00 2001 From: Phong Nguyen Date: Tue, 3 Mar 2026 13:03:16 +0700 Subject: [PATCH 1/5] Update README for mem check --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 9571397..2ee8a41 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,11 @@ Get-ChildItem -Recurse -Include *.cpp, *.h, *.hpp | ForEach-Object { clang-forma $ ./cpp_lab_project $ ./cpp_lab_project_test ``` + * Detect Memory Leak Using [valgrind](https://valgrind.org/) + ``` + $ sudo apt install valgrind + $ valgrind --leak-check=full -v ./cpp-lab + ``` * (Optional) Run static analysis - cppcheck ``` $ sudo apt-get install cppcheck From b99373c2816b0f99be0b9b8fab1ec5e4a0f966e2 Mon Sep 17 00:00:00 2001 From: Phong Nguyen Date: Tue, 3 Mar 2026 14:19:56 +0700 Subject: [PATCH 2/5] Update README --- README.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2ee8a41..597b2a5 100644 --- a/README.md +++ b/README.md @@ -105,6 +105,21 @@ docker image ls docker push DOCKER_USERNAME/cpp-lab ``` -## 6. TROUBLESHOOTING +## 6. TroubleShooting 1. `push access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed` => docker login / Docker Desktop login + +## 7. Evaluate Executable +- List all sections: +```bash +$ size ./build/cpp-lab +``` +- The expected output should be the following: +```bash + text data bss dec hex filename + 14791 792 280 15863 ./build/cpp-lab +``` + +- `.text`: Text Segment - the executable code size, including: complied function, inline, template, constants, string literals +- `.data`: Initialized Data Segment - the memory for the global, static variables, has init value. +- `.bss`: Uninitialized Data Segment - global and static variables that are not initialized \ No newline at end of file From b5fc2b496e11f6ea9dc9569d9a22dc788255e132 Mon Sep 17 00:00:00 2001 From: Phong Nguyen Date: Thu, 5 Mar 2026 10:27:22 +0700 Subject: [PATCH 3/5] Update comment --- src/core/exception/BasicHandle.cpp | 2 +- src/core/filehandle/StringStream.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/exception/BasicHandle.cpp b/src/core/exception/BasicHandle.cpp index af5f026..77410e7 100644 --- a/src/core/exception/BasicHandle.cpp +++ b/src/core/exception/BasicHandle.cpp @@ -12,7 +12,7 @@ void run() { errorFnc(); } catch (std::exception& e) { std::cout << e.what(); - throw std::runtime_error("[M] Middle error \n"); + throw std::runtime_error("[M] Middle error \n"); // use as custom exception // throw; // rethrow } } catch (std::exception& e) { diff --git a/src/core/filehandle/StringStream.cpp b/src/core/filehandle/StringStream.cpp index 9185084..8eb3a12 100644 --- a/src/core/filehandle/StringStream.cpp +++ b/src/core/filehandle/StringStream.cpp @@ -10,7 +10,7 @@ void runStringStreamExample() { std::stringstream os{}; - // input + // input: std::istringstream iss; os << "0xF"; std::cout << os.str(); @@ -19,7 +19,7 @@ void runStringStreamExample() { os.clear(); std::cout << os.str(); - // output + // output: std::ostringstream oss; std::string bytesStr = os.str(); std::cout << bytesStr; From ccab5b158d6c899fbbfb1627ff286471251c1bd7 Mon Sep 17 00:00:00 2001 From: Phong Nguyen Date: Thu, 5 Mar 2026 11:06:32 +0700 Subject: [PATCH 4/5] Add auto run script (AI gen) --- README.md | 5 +++++ run.sh | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100755 run.sh diff --git a/README.md b/README.md index 597b2a5..82db833 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,9 @@ ## 1. Overview +**TL;DR** +```bash +./r +``` + **Project Structure** ``` includes/ → Header files (.h, .hpp) diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..3e2906e --- /dev/null +++ b/run.sh @@ -0,0 +1,57 @@ +## NOTE: +## This file was initially generated with the assistance of AI. +## The code has been reviewed and may have been modified by the developer +## to ensure correctness, readability, and compliance with project requirements. +#!/usr/bin/env bash + +set -e # Exit immediately if a command fails + +PROJECT_EXEC="./build/cpp_lab_project" +BUILD_DIR="./build" + +clear +echo "==============================" +echo " Starting build pipeline... " +echo "==============================" + +# Check required tools +for tool in cmake cppcheck python3; do + if ! command -v $tool &> /dev/null; then + echo "[ERR]: $tool is not installed." + exit 1 + fi +done + +echo "" +echo "===========>> Building project..." +cmake --build "$BUILD_DIR" + +echo "" +echo "===========>> Running cppcheck..." +cppcheck \ + --enable=warning,style,performance,portability \ + --inconclusive \ + --inline-suppr \ + --quiet \ + --error-exitcode=1 \ + ./src ./include + +echo "[OK] Static analysis passed" + +echo "" +echo "===========>> Generating commit id..." +python3 ./private/genid.py + +echo "" +echo "===========>> Running program..." +if [ -f "$PROJECT_EXEC" ]; then + "$PROJECT_EXEC" +else + echo "[ERR] Executable not found: $PROJECT_EXEC" + exit 1 +fi + +echo "" +echo "==============================" +echo "Pipeline finished successfully!" +echo "==============================" \ No newline at end of file From 39d03902acceb813d018c4fbb9d497205a588fea Mon Sep 17 00:00:00 2001 From: Phong Nguyen Date: Thu, 5 Mar 2026 11:06:49 +0700 Subject: [PATCH 5/5] Add an example for DateTime --- CMakeLists.txt | 2 ++ src/core/datetime/CTime.cpp | 39 +++++++++++++++++++++++++++++++++++++ src/core/datetime/REAME.md | 23 ++++++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 src/core/datetime/CTime.cpp create mode 100644 src/core/datetime/REAME.md diff --git a/CMakeLists.txt b/CMakeLists.txt index 1456339..96b3d94 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -172,6 +172,8 @@ set(APP_SOURCES "src/core/overloading/AssignmentOperator.cpp" "src/core/overloading/ClassMemberAccessOperator.cpp" "src/core/overloading/AllocationOperator.cpp" + ## Date and Time + "src/core/datetime/CTime.cpp" ) # Test files diff --git a/src/core/datetime/CTime.cpp b/src/core/datetime/CTime.cpp new file mode 100644 index 0000000..8969c29 --- /dev/null +++ b/src/core/datetime/CTime.cpp @@ -0,0 +1,39 @@ +#include +#include "ExampleRegistry.h" + +#include + +namespace { +void run() { + // **1. Get the current timestamp** + std::time_t now = time(NULL); + const auto* ts = ctime(&now); + std::cout << "Current time: " << ts << '\n'; + + // **2. Create the dt structure** + struct tm datetime = *localtime(&now); + std::cout << "Year: " << datetime.tm_year + 1900 << '\n'; + std::cout << "Current time stamp: " << mktime(&datetime) << '\n'; + + // **3. Formatting** + char output[50]; + strftime(output, 50, "%B %e, %Y", &datetime); + std::cout << output << "\n"; + strftime(output, 50, "%I:%M:%S %p", &datetime); + std::cout << output << "\n"; + strftime(output, 50, "%m/%d/%y", &datetime); + std::cout << output << "\n"; + strftime(output, 50, "%a %b %e %H:%M:%S %Y", &datetime); + std::cout << output << "\n"; +} +} // namespace + +class CTime : public IExample { + public: + std::string group() const override { return "core/datetime"; } + std::string name() const override { return "CTime"; } + std::string description() const override { return ""; } + void execute() override { run(); } +}; + +REGISTER_EXAMPLE(CTime, "core/datetime", "CTime"); \ No newline at end of file diff --git a/src/core/datetime/REAME.md b/src/core/datetime/REAME.md new file mode 100644 index 0000000..7fec4c5 --- /dev/null +++ b/src/core/datetime/REAME.md @@ -0,0 +1,23 @@ +# Date and Time +- : provides functions and types to work with date and time values including parsing and formatting (inherited from C) + +- : provides facilities to deal with the duration time points and clocks (std11), it is more modern and type-safe approach + +## ctime +- Data Types: + - `time_t`: for timestamps + - `struct tm`: for datetime structes + - Use `mktime()` to convert struct tm to time_t, and `localtime()` and `gmtime()` for vice versa +- `strftime()` format: +>%a Short representation of the weekday Fri +%b Short representation of the month name Dec +%B Full representation of the month name December +%d Day of the month with leading zero 09 +%e Day of the month with leading spaces 9 +%H 24-hour format of an hour 14 +%I 12-hour format of an hour 02 +%M Minutes within an hour 30 +%p AM or PM PM +%S Seconds within a minute 01 +%y 2-digit year representation 23 +%Y 4-digit year representation 2023 \ No newline at end of file