Skip to content

Commit bdcdf21

Browse files
committed
default constructor for scheduler
added version.hpp cmake project version is now pulled from version.hpp
1 parent b6d7b19 commit bdcdf21

6 files changed

Lines changed: 64 additions & 7 deletions

File tree

CMakeLists.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
cmake_minimum_required(VERSION 3.24)
22

3-
project(chron-cpp VERSION 0.1.0 LANGUAGES CXX)
3+
include(cmake/utils.cmake)
44

5-
message(STATUS "Build ${PROJECT_NAME}: ${PROJECT_VERSION}")
5+
oryx_extract_version()
66

7-
include(cmake/utils.cmake)
7+
project(chron-cpp VERSION ${ORYX_CHRON_VERSION} LANGUAGES CXX)
8+
9+
message(STATUS "Build ${PROJECT_NAME}: ${PROJECT_VERSION}")
810

911
option(ORYX_CHRON_BUILD_SHARED_LIBS "Build shared library" ${BUILD_SHARED_LIBS})
1012
option(ORYX_CHRON_BUILD_TESTS "Build tests" OFF)

cmake/utils.cmake

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,35 @@
1+
2+
function(_internal_extract_version_fail_message tag)
3+
message(FATAL_ERROR "Could not extract ${tag} version number from chron/version.hpp")
4+
endfunction()
5+
6+
function(oryx_extract_version)
7+
file(READ "${CMAKE_CURRENT_LIST_DIR}/include/oryx/chron/version.hpp" file_contents)
8+
9+
string(REGEX MATCH "kVersionMajor[ \t]*=[ \t]*([0-9]+)" _ "${file_contents}")
10+
if(NOT CMAKE_MATCH_COUNT EQUAL 1)
11+
_internal_extract_version_fail_message(major)
12+
endif()
13+
set(ver_major ${CMAKE_MATCH_1})
14+
15+
string(REGEX MATCH "KVersionMinor[ \t]*=[ \t]*([0-9]+)" _ "${file_contents}")
16+
if(NOT CMAKE_MATCH_COUNT EQUAL 1)
17+
_internal_extract_version_fail_message(minor)
18+
endif()
19+
20+
set(ver_minor ${CMAKE_MATCH_1})
21+
string(REGEX MATCH "kVersionPatch[ \t]*=[ \t]*([0-9]+)" _ "${file_contents}")
22+
if(NOT CMAKE_MATCH_COUNT EQUAL 1)
23+
_internal_extract_version_fail_message(patch)
24+
endif()
25+
set(ver_patch ${CMAKE_MATCH_1})
26+
27+
set(ORYX_CHRON_VERSION_MAJOR ${ver_major} PARENT_SCOPE)
28+
set(ORYX_CHRON_VERSION_MINOR ${ver_minor} PARENT_SCOPE)
29+
set(ORYX_CHRON_VERSION_PATCH ${ver_patch} PARENT_SCOPE)
30+
set(ORYX_CHRON_VERSION "${ver_major}.${ver_minor}.${ver_patch}" PARENT_SCOPE)
31+
endfunction()
32+
133
function(oryx_enable_addr_sanitizer target_name)
234
if(NOT CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
335
message(FATAL_ERROR "Sanitizer supported only for gcc/clang!")

include/oryx/chron.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include <oryx/chron/version.hpp>
34
#include <oryx/chron/clock.hpp>
45
#include <oryx/chron/task.hpp>
56
#include <oryx/chron/scheduler.hpp>

include/oryx/chron/scheduler.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ template <traits::Clock ClockType = LocalClock,
3030
DataCachePolicy CachePolicy = DataCachePolicy::kUseCache>
3131
class Scheduler {
3232
public:
33+
Scheduler() = default;
34+
3335
// Schedule management
3436
auto AddSchedule(std::string name, const std::string& schedule, Task::TaskFn work) -> bool {
3537
auto data = Data::Create<CachePolicy>(schedule);
@@ -170,10 +172,10 @@ class Scheduler {
170172
private:
171173
void UnsafeSortTasks() { std::ranges::sort(tasks_, std::less<>{}); }
172174

173-
std::vector<Task> tasks_;
174-
mutable MutexType tasks_mtx_;
175-
ClockType clock_;
176-
TimePoint last_tick_;
175+
std::vector<Task> tasks_{};
176+
mutable MutexType tasks_mtx_{};
177+
ClockType clock_{};
178+
TimePoint last_tick_{};
177179
bool first_tick_{true};
178180
};
179181

include/oryx/chron/version.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#pragma once
2+
3+
namespace oryx::chron {
4+
5+
inline constexpr int kVersionMajor = 0;
6+
inline constexpr int KVersionMinor = 2;
7+
inline constexpr int kVersionPatch = 0;
8+
9+
auto MakeStringVersion() -> std::string;
10+
11+
} // namespace oryx::chron

src/version.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <oryx/chron/version.hpp>
2+
3+
#include <format>
4+
5+
namespace oryx::chron {
6+
7+
auto MakeStringVersion() -> std::string { return std::format("{}.{}.{}", kVersionMajor, KVersionMinor, kVersionPatch); }
8+
9+
} // namespace oryx::chron

0 commit comments

Comments
 (0)