Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
c7b3f24
Init adding spdlog to dsm project
Grufoony Nov 20, 2024
6f09527
Working logger
Grufoony Nov 20, 2024
1518ac6
Fix some messages
Grufoony Nov 20, 2024
765328f
Enhance logging
Grufoony Nov 21, 2024
e004129
Change default generator
Grufoony Nov 21, 2024
66640d2
Fix env variable
Grufoony Nov 21, 2024
29c330b
Update installation guidelines
Grufoony Nov 21, 2024
ad4917a
Add multiplication factor to Graph class
Grufoony Nov 25, 2024
f7287df
Small bugfix
Grufoony Nov 25, 2024
33e3efa
Merge branch 'main' into feature_addLogger
Grufoony Nov 25, 2024
857cc9a
Revert Graph changes
Grufoony Nov 25, 2024
c81977e
Removed test
Grufoony Nov 25, 2024
410bbe1
Update version
Grufoony Nov 25, 2024
afeaea8
Replace vcpkg with FetchContent
Grufoony Nov 25, 2024
a2c0095
Update Readme.md
Grufoony Nov 25, 2024
34087d7
Merge branch 'main' into feature_addLogger
Grufoony Nov 25, 2024
55e49f0
Formatting
Grufoony Nov 25, 2024
983efca
Zio bricco pylint
Grufoony Nov 25, 2024
240150e
Update cmakelists
Grufoony Nov 25, 2024
933f338
Fix pylint
Grufoony Nov 25, 2024
a73b473
Working benchmarks
Grufoony Nov 26, 2024
9334858
Add logger to Street class
Grufoony Nov 26, 2024
f3d81aa
Enhance console logger in street
Grufoony Nov 26, 2024
52adbc5
Slightly rework of addAgentsRandomly
Grufoony Nov 26, 2024
a475187
Bugfix and console logging agent class
Grufoony Nov 26, 2024
6d65371
Adding console loggers...
Grufoony Nov 26, 2024
2d3cc48
Adding console logger to Itinerary
Grufoony Nov 26, 2024
9fe83e8
Ops
Grufoony Nov 26, 2024
026f5dd
Addd console logger to node class
Grufoony Nov 26, 2024
6ac3c78
Bugfixing
Grufoony Nov 26, 2024
cf5d3c7
Try to fix workflow
Grufoony Nov 26, 2024
a48aed8
Merge branch 'main' into feature_addLogger
Grufoony Nov 26, 2024
b32fc38
Update checkout action
Grufoony Nov 26, 2024
9d59f40
Add wf for tests on macos
Grufoony Nov 26, 2024
4aaf9d9
Fix some clang warnings
Grufoony Nov 26, 2024
0ade4b0
Try -pthreads flag
Grufoony Nov 26, 2024
69de6a1
Nope
Grufoony Nov 26, 2024
a9a0a1e
Merge branch 'main' into feature_addLogger
Grufoony Nov 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/cmake_install_macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ jobs:
touch test.cpp
echo "#include <dsm/dsm.hpp>" >> test.cpp
echo "int main() {}" >> test.cpp
g++ test.cpp -std=c++20 && echo "Compiled successfully" \
g++ test.cpp -std=c++20 -lspdlog && echo "Compiled successfully" \
|| (echo "Cannot include dsm" ; exit 1)
1 change: 0 additions & 1 deletion .github/workflows/cmake_test_macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ env:
jobs:
build:
runs-on: macos-latest

steps:
- uses: actions/checkout@v4

Expand Down
29 changes: 18 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,35 @@ cmake_minimum_required(VERSION 3.16.0)

project(dms VERSION 2.0.0 LANGUAGES CXX)

# set the C++ standard
# Set the C++ standard
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

include(FetchContent)
# Get spdlog
FetchContent_Declare(
spdlog
GIT_REPOSITORY https://github.com/gabime/spdlog.git
GIT_TAG v1.15.0
)
FetchContent_MakeAvailable(spdlog)

file(GLOB SOURCES "src/dsm/headers/*.cpp")

add_library(dsm STATIC ${SOURCES})

target_link_libraries(dsm PUBLIC spdlog::spdlog)

target_include_directories(dsm PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/headers>
$<INSTALL_INTERFACE:include>
)

install(TARGETS dsm
EXPORT dsmConfig
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)

install(DIRECTORY ${PROJECT_SOURCE_DIR}/src/ DESTINATION ${CMAKE_INSTALL_PREFIX}/include)
EXPORT dsmConfig
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)

install(EXPORT dsmConfig
FILE dsmConfig.cmake
NAMESPACE dsm::
DESTINATION lib/cmake/dsm)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/src/ DESTINATION ${CMAKE_INSTALL_PREFIX}/include)
17 changes: 5 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,21 @@ This rework consists of a full code rewriting, in order to implement more featur

## Requirements

The project only requires `C++20` or greater and `cmake`.
This project requieres a compiler whith full support for `C++20` or greater and `cmake`.
It also depends on [spdlog](https://github.com/gabime/spdlog).

Utilities are written in python. To install their dependencies:
```shell
pip install -r ./requirements.txt
```

## Installation
The library can be installed using CMake. To build and install the project in the default folder run:
The library can be installed using CMake.
To build and install the project in the default folder run:
```shell
cmake -B build && cmake --build build
cmake -B build && make -C build
sudo cmake --install build
```
Otherwise, it is possible to customize the installation path:
```shell
cmake -B build -DCMAKE_INSTALL_PREFIX=/path/to/install
```
then building and installing it (eventually in sudo mode) with:
```shell
cmake --build build
cmake --install build
```

## Testing
This project uses [Doctest](https://github.com/doctest/doctest) for testing.
Expand Down
9 changes: 9 additions & 0 deletions benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ set(CMAKE_CXX_EXTENSIONS OFF)

include_directories(../extern/benchmark/)

include(FetchContent)
# Get spdlog
FetchContent_Declare(
spdlog
GIT_REPOSITORY https://github.com/gabime/spdlog.git
GIT_TAG v1.15.0
)
FetchContent_MakeAvailable(spdlog)

# add subdirectories
add_subdirectory(Graph)
add_subdirectory(Street)
Expand Down
1 change: 1 addition & 0 deletions benchmark/Dynamics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ set(EXECUTABLE_OUTPUT_PATH ../../)

include_directories(../../src/dsm/headers)
include_directories(../../src/dsm/utility/)
include_directories(${spdlog_SOURCE_DIR}/include)

file(GLOB SOURCES "../../src/dsm/headers/*.cpp")

Expand Down
1 change: 1 addition & 0 deletions benchmark/Graph/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ set(EXECUTABLE_OUTPUT_PATH ../../)

include_directories(../../src/dsm/headers/)
include_directories(../../src/dsm/utility/)
include_directories(${spdlog_SOURCE_DIR}/include)

file(GLOB SOURCES "../../src/dsm/headers/*.cpp")

Expand Down
1 change: 1 addition & 0 deletions benchmark/Street/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ set(EXECUTABLE_OUTPUT_PATH ../../)

include_directories(../../src/dsm/headers)
include_directories(../../src/dsm/utility/)
include_directories(${spdlog_SOURCE_DIR}/include)

file(GLOB SOURCES "../../src/dsm/headers/*.cpp")

Expand Down
11 changes: 10 additions & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ endif()
# Set the folder for the executable
set(EXECUTABLE_OUTPUT_PATH ../)

include(FetchContent)
# Get spdlog
FetchContent_Declare(
spdlog
GIT_REPOSITORY https://github.com/gabime/spdlog.git
GIT_TAG v1.15.0
)
FetchContent_MakeAvailable(spdlog)

# add as executable all cpp files into '.' folder
file(GLOB SOURCES "*.cpp")
file(GLOB SRC_SOURCES "../src/dsm/headers/*.cpp")
Expand All @@ -25,5 +34,5 @@ file(GLOB SRC_SOURCES "../src/dsm/headers/*.cpp")
foreach(SOURCE ${SOURCES})
get_filename_component(EXE_NAME ${SOURCE} NAME_WE)
add_executable(${EXE_NAME}.out ${SOURCE} ${SRC_SOURCES})
target_include_directories(${EXE_NAME}.out PRIVATE ../src/dsm/headers/ ../src/dsm/utility/TypeTraits/)
target_include_directories(${EXE_NAME}.out PRIVATE ../src/dsm/headers/ ../src/dsm/utility/TypeTraits/ ${spdlog_SOURCE_DIR}/include)
endforeach()
13 changes: 11 additions & 2 deletions profiling/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,22 @@ string(APPEND CMAKE_CXX_FLAGS "-Wall -Wextra -Os")
# Set the folder for the executable
set(EXECUTABLE_OUTPUT_PATH ../)

include(FetchContent)
# Get spdlog
FetchContent_Declare(
spdlog
GIT_REPOSITORY https://github.com/gabime/spdlog.git
GIT_TAG v1.15.0
)
FetchContent_MakeAvailable(spdlog)

file(GLOB SOURCES "../src/dsm/headers/*.cpp")

# Define the executable
add_executable(prof.out main.cpp ${SOURCES})
target_include_directories(prof.out PRIVATE ../src/)
target_include_directories(prof.out PRIVATE ../src/ ${spdlog_SOURCE_DIR}/include)
target_compile_options(prof.out PRIVATE -pg)
target_link_options(prof.out PRIVATE -pg)
add_executable(mem.out main.cpp ${SOURCES})
target_include_directories(mem.out PRIVATE ../src/)
target_include_directories(mem.out PRIVATE ../src/ ${spdlog_SOURCE_DIR}/include)
add_executable(parse_massif.out parse_massif.cpp)
5 changes: 1 addition & 4 deletions src/dsm/dsm.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef dsm_hpp
#define dsm_hpp
#pragma once

#include <cstdint>
#include <format>
Expand Down Expand Up @@ -27,5 +26,3 @@ namespace dsm {
#include "utility/TypeTraits/is_node.hpp"
#include "utility/TypeTraits/is_street.hpp"
#include "utility/TypeTraits/is_numeric.hpp"

#endif
31 changes: 19 additions & 12 deletions src/dsm/headers/Agent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@
#include <limits>
#include <optional>

#include <spdlog/spdlog.h>
#include <spdlog/sinks/stdout_color_sinks.h>
#include <spdlog/sinks/basic_file_sink.h>

namespace dsm {
/// @brief The Agent class represents an agent in the network.
/// @tparam Id, The type of the agent's id. It must be an unsigned integral type.
/// @tparam Size, The type of the size of a street. It must be an unsigned integral type.
/// @tparam Delay, The type of the agent's delay. It must be a numeric type (see utility/TypeTraits/is_numeric.hpp).
template <typename Delay>
requires(is_numeric_v<Delay>)
class Agent {
private:
inline static auto const pConsoleLogger{spdlog::stdout_color_mt("DSM_AGENT_CONSOLE")};
Id m_id;
Id m_itineraryId;
std::optional<Id> m_streetId;
Expand Down Expand Up @@ -63,11 +66,9 @@ namespace dsm {
/// @throw std::invalid_argument, if speed is negative
void setSpeed(double speed);
/// @brief Increment the agent's delay by 1
/// @throw std::overflow_error, if delay has reached its maximum value
void incrementDelay();
/// @brief Increment the agent's delay by a given value
/// @param delay The agent's delay
/// @throw std::overflow_error, if delay has reached its maximum value
void incrementDelay(Delay const delay);
/// @brief Decrement the agent's delay by 1
/// @throw std::underflow_error, if delay has reached its minimum value
Expand All @@ -78,12 +79,10 @@ namespace dsm {
/// @param distance The value to increment the agent's distance byù
/// @throw std::invalid_argument, if distance is negative
void incrementDistance(double distance);
/// @brief Increment the agent's time by 1
/// @throw std::overflow_error, if time has reached its maximum value
/// @brief Increment the agent's time by 1.
void incrementTime();
/// @brief Increment the agent's time by a given value
/// @brief Increment the agent's time by a given value.
/// @param time The value to increment the agent's time by
/// @throw std::overflow_error, if time has reached its maximum value
void incrementTime(unsigned int const time);

Check notice

Code scanning / Cppcheck (reported by Codacy)

time is Y2038-unsafe Note

time is Y2038-unsafe
/// @brief Reset the agent's time to 0
void resetTime() { m_time = 0; }
Expand Down Expand Up @@ -147,15 +146,19 @@ namespace dsm {
requires(is_numeric_v<Delay>)
void Agent<Delay>::incrementDelay() {
if (m_delay == std::numeric_limits<Delay>::max()) {
throw std::overflow_error(buildLog("Delay has reached its maximum value"));
pConsoleLogger->critical(
"Agent {} delay has reached its maximum value ({}).", m_id, m_delay);
std::abort();
}
++m_delay;
}
template <typename Delay>
requires(is_numeric_v<Delay>)
void Agent<Delay>::incrementDelay(Delay const delay) {
if (m_delay + delay < m_delay) {
throw std::overflow_error(buildLog("Delay has reached its maximum value"));
pConsoleLogger->critical(
"Agent {} delay has reached its maximum value ({}).", m_id, m_delay);
std::abort();
}
m_delay += delay;
}
Expand All @@ -181,15 +184,19 @@ namespace dsm {
requires(is_numeric_v<Delay>)
void Agent<Delay>::incrementTime() {
if (m_time == std::numeric_limits<unsigned int>::max()) {
throw std::overflow_error(buildLog("Time has reached its maximum value"));
pConsoleLogger->critical(
"Agent {} time has reached its maximum value ({}).", m_id, m_time);
std::abort();
}
++m_time;
}
template <typename Delay>
requires(is_numeric_v<Delay>)
void Agent<Delay>::incrementTime(unsigned int const time) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

time is Y2038-unsafe Note

time is Y2038-unsafe
if (m_time + time < m_time) {
throw std::overflow_error(buildLog("Time has reached its maximum value"));
pConsoleLogger->critical(
"Agent {} time has reached its maximum value ({}).", m_id, m_time);
std::abort();
}
m_time += time;
}
Expand Down
Loading
Loading