Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions .github/workflows/linux.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,12 @@ jobs:
include:
- name: "ASan"
extra-flags: "-DORYX_CHRON_SANITIZE_ADDRESS=ON"
- name: "TSan"
extra-flags: "-DORYX_CHRON_SANITIZE_THREAD=ON" # Not doing much right now
- name: "Optimized Build"
extra-flags: "-DCMAKE_CXX_FLAGS=-O3"
- name: "Shared Build"
extra-flags: "-DORYX_CHRON_BUILD_SHARED_LIBS=ON"

name: "${{ github.job }} ${{ matrix.name }}"
runs-on: ubuntu-latest
Expand Down
16 changes: 10 additions & 6 deletions .github/workflows/windows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,33 @@ name: windows

on: [push, pull_request]

env:
VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite"

jobs:
windows-msvc:
runs-on: windows-latest
strategy:
matrix:
shared: [OFF, ON]
name: "Windows MSVC ${{ matrix.shared == 'ON' && 'shared' || 'static' }}"
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0

- name: Export GitHub Actions cache environment variables
uses: actions/github-script@v7
with:
script: |
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');

- uses: ilammy/msvc-dev-cmd@v1

- name: Compile
run: |
cmake -B build -DORYX_CHRON_BUILD_TESTS=ON -DCMAKE_CXX_STANDARD=20 -DCMAKE_BUILD_TYPE=Release
cmake -B build -DORYX_CHRON_BUILD_TESTS=ON -DORYX_CHRON_BUILD_SHARED_LIBS=${{ matrix.shared }} -DCMAKE_CXX_STANDARD=20 -DCMAKE_BUILD_TYPE=Release
cmake --build build

- name: Run tests
run: |
.\build\Debug\chron-cpp_tests --success
run: .\build\Debug\chron-cpp_tests
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ endif()

if (ORYX_CHRON_BUILD_SHARED_LIBS)
add_library(${PROJECT_NAME} SHARED)
target_compile_definitions(${PROJECT_NAME} PUBLIC ORYX_CHRON_BUILD_SHARED_LIBS)
set_target_properties(${PROJECT_NAME} PROPERTIES SOVERSION ${PROJECT_VERSION})
else()
add_library(${PROJECT_NAME} STATIC)
Expand All @@ -40,6 +41,8 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
target_compile_options(${PROJECT_NAME}
PRIVATE
/W4
PUBLIC
$<$<BOOL:${ORYX_CHRON_BUILD_SHARED_LIBS}>:/wd4251>
)
else()
target_compile_options(${PROJECT_NAME}
Expand Down
11 changes: 0 additions & 11 deletions include/oryx/chron/chrono_types.hpp

This file was deleted.

10 changes: 5 additions & 5 deletions include/oryx/chron/clock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
#include <mutex>
#include <chrono>

#include <oryx/chron/traits.hpp>
#include <oryx/chron/chrono_types.hpp>
#include "common.hpp"
#include "traits.hpp"

namespace oryx::chron {

class UTCClock {
class ORYX_CHRON_API UTCClock {
public:
auto Now() const -> TimePoint { return Clock::now(); }
auto UtcOffset(TimePoint) const -> std::chrono::seconds { return std::chrono::seconds(0); }
};

class LocalClock {
class ORYX_CHRON_API LocalClock {
public:
auto Now() const -> TimePoint {
auto now = Clock::now();
Expand All @@ -25,7 +25,7 @@ class LocalClock {
auto UtcOffset(TimePoint now) const -> std::chrono::seconds;
};

class TzClock {
class ORYX_CHRON_API TzClock {
public:
auto Now() const -> TimePoint {
auto now = Clock::now();
Expand Down
25 changes: 25 additions & 0 deletions include/oryx/chron/common.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once

#include <chrono>

#ifdef ORYX_CHRON_BUILD_SHARED_LIBS
#ifdef _WIN32
#ifdef chron_cpp_EXPORTS
#define ORYX_CHRON_API __declspec(dllexport)
#else
#define ORYX_CHRON_API __declspec(dllimport)
#endif
#else
#define ORYX_CHRON_API __attribute__((visibility("default")))
#endif
#else
#define ORYX_CHRON_API
#endif

namespace oryx::chron {

using Clock = std::chrono::system_clock;
using TimePoint = std::chrono::time_point<Clock>;
using Duration = Clock::duration;

} // namespace oryx::chron
2 changes: 0 additions & 2 deletions include/oryx/chron/details/any_of.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
#include <cstdint>
#include <set>

#include <oryx/chron/details/to_underlying.hpp>

namespace oryx::chron::details {

namespace traits {
Expand Down
15 changes: 0 additions & 15 deletions include/oryx/chron/details/null_mutex.hpp

This file was deleted.

15 changes: 15 additions & 0 deletions include/oryx/chron/null_mutex.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#include "traits.hpp"

namespace oryx::chron {

class NullMutex {
public:
void lock() noexcept {}
void unlock() noexcept {}
};

static_assert(traits::BasicLockable<NullMutex>);

} // namespace oryx::chron
12 changes: 7 additions & 5 deletions include/oryx/chron/parser.hpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
#pragma once

#include <optional>
#include <mutex>
#include <string_view>
#include <optional>
#include <functional>
#include <algorithm>

#include <oryx/chron/details/null_mutex.hpp>

#include "common.hpp"
#include "chron_data.hpp"
#include "traits.hpp"
#include "null_mutex.hpp"

namespace oryx::chron {

struct ExpressionParser {
struct ORYX_CHRON_API ExpressionParser {
auto operator()(std::string_view cron_expression) const -> std::optional<ChronData>;
};

template <traits::BasicLockable MutexType = details::NullMutex>
template <traits::BasicLockable MutexType = NullMutex>
class CachedExpressionParser : ExpressionParser {
public:
using Pair = std::pair<std::size_t, ChronData>;
Expand Down
6 changes: 3 additions & 3 deletions include/oryx/chron/preprocessor.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <oryx/chron/traits.hpp>
#include "traits.hpp"

namespace oryx::chron {

Expand All @@ -22,11 +22,11 @@ struct Processors<Curr, Rest...> {
}
};

struct DollarExpressionProcessor {
struct ORYX_CHRON_API DollarExpressionProcessor {
static auto Process(std::string data) noexcept -> std::string;
};

struct WeekMonthDayLiteralProcessor {
struct ORYX_CHRON_API WeekMonthDayLiteralProcessor {
static auto Process(std::string data) noexcept -> std::string;
};

Expand Down
5 changes: 4 additions & 1 deletion include/oryx/chron/randomization.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
#include <optional>
#include <random>

#include "common.hpp"

namespace oryx::chron {
class Randomization {

class ORYX_CHRON_API Randomization {
public:
Randomization();

Expand Down
9 changes: 5 additions & 4 deletions include/oryx/chron/schedule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

#include <optional>

#include <oryx/chron/chron_data.hpp>
#include <oryx/chron/date_time.hpp>
#include <oryx/chron/chrono_types.hpp>
#include "common.hpp"
#include "chron_data.hpp"
#include "date_time.hpp"

namespace oryx::chron {
class Schedule {

class ORYX_CHRON_API Schedule {
public:
explicit Schedule(ChronData data)
: data_(std::move(data)) {}
Expand Down
16 changes: 8 additions & 8 deletions include/oryx/chron/scheduler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
#include <chrono>
#include <vector>

#include <oryx/chron/traits.hpp>
#include <oryx/chron/task.hpp>
#include <oryx/chron/clock.hpp>
#include <oryx/chron/chrono_types.hpp>
#include <oryx/chron/parser.hpp>
#include "common.hpp"
#include "traits.hpp"
#include "clock.hpp"
#include "parser.hpp"
#include "task.hpp"

namespace oryx::chron {

template <traits::Clock ClockType = LocalClock,
traits::BasicLockable MutexType = details::NullMutex,
traits::BasicLockable MutexType = NullMutex,
traits::Parser ParserType = ExpressionParser>
class Scheduler {
public:
Expand Down Expand Up @@ -67,7 +67,7 @@ class Scheduler {

void RemoveSchedule(std::string_view name) {
std::lock_guard lock{tasks_mtx_};
std::erase_if(tasks_, [name](const Task& t) { return t == name; });
std::erase_if(tasks_, [name](const Task& t) { return t.GetName() == name; });
}

void RecalculateSchedules() {
Expand Down Expand Up @@ -170,7 +170,7 @@ class Scheduler {
};

template <traits::Clock ClockType = LocalClock>
using CScheduler = Scheduler<ClockType, details::NullMutex, CachedExpressionParser<details::NullMutex>>;
using CScheduler = Scheduler<ClockType, NullMutex, CachedExpressionParser<NullMutex>>;

template <traits::Clock ClockType = LocalClock>
using MTScheduler = Scheduler<ClockType, std::mutex>;
Expand Down
14 changes: 3 additions & 11 deletions include/oryx/chron/task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#include <functional>
#include <string>

#include <oryx/chron/schedule.hpp>
#include <oryx/chron/chrono_types.hpp>
#include "common.hpp"
#include "schedule.hpp"

namespace oryx::chron {

Expand All @@ -15,7 +15,7 @@ struct TaskInfo {

using TaskFn = std::function<void(TaskInfo)>;

class Task {
class ORYX_CHRON_API Task {
public:
Task(std::string name, Schedule schedule, TaskFn task);

Expand All @@ -41,12 +41,4 @@ class Task {
bool valid_;
};

inline auto operator==(std::string_view lhs, const Task &rhs) -> bool { return lhs == rhs.GetName(); }

inline auto operator==(const Task &lhs, std::string_view rhs) -> bool { return lhs.GetName() == rhs; }

inline auto operator!=(std::string_view lhs, const Task &rhs) -> bool { return !(lhs == rhs); }

inline auto operator!=(const Task &lhs, std::string_view rhs) -> bool { return !(lhs == rhs); }

} // namespace oryx::chron
2 changes: 1 addition & 1 deletion include/oryx/chron/traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <string_view>
#include <type_traits>

#include "chrono_types.hpp"
#include "common.hpp"
#include "chron_data.hpp"

namespace oryx::chron::traits {
Expand Down
4 changes: 3 additions & 1 deletion include/oryx/chron/version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

#include <string>

#include "common.hpp"

namespace oryx::chron {

inline constexpr int kVersionMajor = 0;
inline constexpr int KVersionMinor = 3;
inline constexpr int kVersionPatch = 0;

auto MakeStringVersion() -> std::string;
ORYX_CHRON_API auto MakeStringVersion() -> std::string;

} // namespace oryx::chron
3 changes: 1 addition & 2 deletions src/clock.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#include <oryx/chron/clock.hpp>

#ifdef WIN32
Expand Down Expand Up @@ -40,7 +39,7 @@ auto TzClock::TrySetTimezone(std::string_view name) -> bool {

try {
new_zone = locate_zone(name);
} catch (std::runtime_error &err) {
} catch (std::runtime_error &) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/schedule.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include <optional>

#include <oryx/chron/schedule.hpp>
#include <oryx/chron/common.hpp>
#include <oryx/chron/details/to_underlying.hpp>
#include <oryx/chron/chrono_types.hpp>

using namespace std::chrono;

Expand Down
Loading