Browse Source

WIP: cpp17

cpp17-init-dingo-fail
chodak166 5 months ago
parent
commit
a7c13a1cca
  1. 2
      .gitignore
  2. 3
      cpp17/.devcontainer/devcontainer.json
  3. 2
      cpp17/.devcontainer/docker-compose.yml
  4. 10
      cpp17/CMakeLists.txt
  5. 12
      cpp17/CMakePresets.json
  6. 54
      cpp17/TODO.md
  7. 8
      cpp17/app/CMakeLists.txt
  8. 25
      cpp17/app/src/App.cpp
  9. 16
      cpp17/app/src/App.h
  10. 6
      cpp17/app/src/Main.cpp
  11. 2
      cpp17/docker/Dockerfile
  12. 26
      cpp17/lib/CMakeLists.txt
  13. 11
      cpp17/lib/include/autostore/AutoStore.h
  14. 15
      cpp17/lib/src/AutoStore.cpp
  15. 8
      cpp17/vcpkg.json

2
.gitignore vendored

@ -3,6 +3,8 @@
*.d
build
build-*
volumes
tmp
# Compiled Object files
*.slo

3
cpp17/.devcontainer/devcontainer.json

@ -6,7 +6,8 @@
"customizations": {
"vscode": {
"settings": {
"terminal.integrated.defaultProfile.linux": "bash"
"terminal.integrated.defaultProfile.linux": "bash",
"cmake.useCMakePresets": "always"
},
"extensions": [
"ms-vscode.cmake-tools",

2
cpp17/.devcontainer/docker-compose.yml

@ -7,6 +7,6 @@ services:
dockerfile: .devcontainer/Dockerfile
volumes:
- ../:/workspace:cached
- ./volumes/vscode-server:/home/ubuntu/.vscode-server
command: ["sleep", "infinity"]
user: "1000:1000"
network_mode: host

10
cpp17/CMakeLists.txt

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.10)
cmake_minimum_required(VERSION 3.20)
project(AutoStore VERSION 1.0.0 LANGUAGES CXX)
set(PROJECT_ROOT ${PROJECT_SOURCE_DIR})
@ -6,8 +6,8 @@ set(PROJECT_ROOT ${PROJECT_SOURCE_DIR})
set(CTEST_OUTPUT_ON_FAILURE ON)
enable_testing(true)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
# add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/Lib")
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/app")
add_subdirectory(lib)
add_subdirectory(app)

12
cpp17/CMakePresets.json

@ -0,0 +1,12 @@
{
"version": 3,
"configurePresets": [
{
"name": "default",
"toolchainFile": "${env:VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"cacheVariables": {
"CMAKE_EXPORT_COMPILE_COMMANDS": "TRUE"
}
}
]
}

54
cpp17/TODO.md

@ -0,0 +1,54 @@
# C++17 AutoStore Implementation Plan
This document outlines the steps to implement the C++17 version of the AutoStore application. Implemented classes should use `nxl::` namespace prefix.
## Phase 1: Project Scaffolding & Build System
- [x] Initialize a CMake project structure.
- [x] Set up the root `CMakeLists.txt` to manage the `app` and `lib` subdirectories.
- [x] Create the `lib` directory for the static library.
- [x] Create the `app` directory for the executable.
- [x] Configure `vcpkg` for dependency management and integrate it with CMake.
- [x] Add a dependency for an HTTP library (e.g., `cpp-httplib`) via `vcpkg`.
- [x] Add a dependency for a testing framework (e.g., `catch2`) via `vcpkg`.
## Phase 2: Library (`lib`) - Dummy Implementation
- [x] Create the directory structure for the library: `lib/src`, `lib/include`.
- [x] Create `lib/CMakeLists.txt` to build a static library.
- [x] In `lib/include/autostore`, define the public interface for the `App` to use.
- [x] Create a dummy `AutoStore` class in `lib/include/autostore/AutoStore.h` and a source file in `lib/src/AutoStore.cpp`.
- [ ] Define dummy classes for core domain and application logic inside the library (e.g., `ItemRepository`, `UserService`, etc.) to establish the architecture. These will be private to the library initially.
## Phase 3: Application (`app`) - Dummy Implementation
- [ ] Create the directory structure for the application: `app/src`.
- [x] Create `app/CMakeLists.txt` to build the executable.
- [ ] Link the `app` against the `lib` static library.
- [ ] Implement the main `App` class in `app/src/App.h` and `app/src/App.cpp`.
- [ ] The `App` class will have a constructor `App(int argc, char** argv)` and an `exec()` method.
- [ ] Implement signal handling (for `SIGINT`, `SIGTERM`) in the `App` class for graceful shutdown.
- [x] In `app/src/Main.cpp`, instantiate and run the `App` class.
- [ ] Ensure the project compiles and links successfully with the dummy implementations.
## Phase 4: Core Logic Implementation
- [ ] Implement the Domain layer in `lib/src/domain`.
- [ ] Implement the Application layer in `lib/src/application`.
- [ ] Implement the Infrastructure layer in `lib/src/infrastructure` (e.g., file-based persistence, HTTP client for ordering).
- [ ] Implement the Presentation layer (HTTP API) using the chosen HTTP library.
- [ ] Implement the startup logic to check for expired items.
- [ ] Implement a background mechanism (e.g., a thread) to periodically check for expired items.
## Phase 5: Testing
- [ ] Set up a `tests` directory.
- [ ] Create `tests/CMakeLists.txt` to build the test runner.
- [ ] Write unit tests for the Domain layer.
- [ ] Write unit tests for the Application layer, using mocks for infrastructure interfaces.
- [ ] Write integration tests for the Infrastructure layer.
## Phase 6: Containerization
- [x] Create a `Dockerfile` to build the C++ application in a container.
- [x] Create a `docker-compose.yml` file to easily build and run the application.

8
cpp17/app/CMakeLists.txt

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.10)
cmake_minimum_required(VERSION 3.20)
project(AutoStoreApp LANGUAGES CXX VERSION 0.1.0)
set(TARGET_NAME AutoStore)
@ -6,14 +6,16 @@ set(TARGET_NAME AutoStore)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
configure_file(src/Version.h.in ${CMAKE_BINARY_DIR}/Version.h)
set(SOURCES
src/Main.cpp
src/App.cpp
src/App.h
)
set (LIBRARIES
AutoStoreLib
)
add_executable(${TARGET_NAME} ${SOURCES})
@ -26,6 +28,6 @@ target_include_directories(${TARGET_NAME}
# target_compile_options(${TARGET_NAME} PRIVATE -static-libgcc -static-libstdc++)
# target_link_options(${TARGET_NAME} PRIVATE -static-libgcc -static-libstdc++)
target_link_libraries(${TARGET_NAME} ${LIBRARIES})
target_link_libraries(${TARGET_NAME} PRIVATE ${LIBRARIES})
# add_subdirectory(tests/unit)

25
cpp17/app/src/App.cpp

@ -0,0 +1,25 @@
#include "App.h"
#include "autostore/AutoStore.h"
#include <iostream>
namespace nxl
{
App::App(int argc, char **argv)
{
signal(SIGINT, App::handle_signal);
signal(SIGTERM, App::handle_signal);
}
int App::exec()
{
nxl::AutoStore autostore;
autostore.run();
return 0;
}
void App::handle_signal(int signum)
{
std::cout << "\nCaught signal " << signum << ". Graceful shutdown." << std::endl;
exit(signum);
}
}

16
cpp17/app/src/App.h

@ -0,0 +1,16 @@
#pragma once
#include <csignal>
namespace nxl
{
class App
{
public:
App(int argc, char **argv);
int exec();
private:
static void handle_signal(int signum);
};
}

6
cpp17/app/src/Main.cpp

@ -1,8 +1,10 @@
#include "App.h"
#include "Version.h"
#include <iostream>
int main()
int main(int argc, char **argv)
{
std::cout << "AutoStore v" << nxl::getVersionString() << std::endl;
return 0;
nxl::App app(argc, argv);
return app.exec();
}

2
cpp17/docker/Dockerfile

@ -10,4 +10,4 @@ RUN cmake -DCMAKE_TOOLCHAIN_FILE:STRING=${VCPKG_ROOT}/scripts/buildsystems/vcpkg
-H/workspace -B/workspace/build -G Ninja
RUN cmake --build /workspace/build --config Release --target all -j 6 --
CMD ["/workspace/build/autostore"]
CMD ["/workspace/build/bin/AutoStore"]

26
cpp17/lib/CMakeLists.txt

@ -0,0 +1,26 @@
cmake_minimum_required(VERSION 3.20)
project(AutoStoreLib)
set(TARGET_NAME AutoStoreLib)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_library(${TARGET_NAME} STATIC
src/AutoStore.cpp
)
target_include_directories(${TARGET_NAME}
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
)
# Find dependencies
find_package(httplib CONFIG REQUIRED)
find_package(Catch2 CONFIG REQUIRED)
target_link_libraries(${TARGET_NAME}
PUBLIC
httplib::httplib
Catch2::Catch2WithMain
)

11
cpp17/lib/include/autostore/AutoStore.h

@ -0,0 +1,11 @@
#pragma once
namespace nxl
{
class AutoStore
{
public:
AutoStore();
void run();
};
} // namespace nxl

15
cpp17/lib/src/AutoStore.cpp

@ -0,0 +1,15 @@
#include "autostore/AutoStore.h"
#include <iostream>
namespace nxl
{
AutoStore::AutoStore()
{
std::cout << "AutoStore library initialized." << std::endl;
}
void AutoStore::run()
{
std::cout << "AutoStore library is running." << std::endl;
}
} // namespace nxl

8
cpp17/vcpkg.json

@ -0,0 +1,8 @@
{
"name": "autostore",
"version-string": "1.0.0",
"dependencies": [
"cpp-httplib",
"catch2"
]
}
Loading…
Cancel
Save