diff --git a/CppTick/Inc/cpptick/argstore.hpp b/CppTick/Inc/cpptick/argstore.hpp index 2f5e3e1..d1cad11 100644 --- a/CppTick/Inc/cpptick/argstore.hpp +++ b/CppTick/Inc/cpptick/argstore.hpp @@ -4,10 +4,10 @@ #pragma once -#include #include #include #include +#include namespace cpptick { @@ -54,7 +54,7 @@ struct ArgStorage pointer_buffer_head++; if (pointer_buffer_head != pointer_buffer.end()) { - *pointer_buffer_head = (char*)memory_location + sizeof(T); + *pointer_buffer_head = (char*) memory_location + sizeof(T); space_remaining -= sizeof(T); } } @@ -74,14 +74,14 @@ struct ArgStorage pointer_buffer_head++; if (pointer_buffer_head != pointer_buffer.end()) { - *pointer_buffer_head = (char*)memory_location + sizeof(T); + *pointer_buffer_head = (char*) memory_location + sizeof(T); space_remaining -= sizeof(T); } } template void cleanUp(const std::size_t) - { } + {} template void cleanUp(const std::size_t index) @@ -105,14 +105,14 @@ struct ArgStorage template T& at(const std::size_t idx) { - return *((T*)pointer_buffer[idx]); + return *((T*) pointer_buffer[idx]); } template const T& at(const std::size_t idx) const { - return *((T*)pointer_buffer[idx]); + return *((T*) pointer_buffer[idx]); } }; -} +}// namespace cpptick diff --git a/CppTick/Inc/cpptick/cpptick.hpp b/CppTick/Inc/cpptick/cpptick.hpp index a980398..86d50b8 100644 --- a/CppTick/Inc/cpptick/cpptick.hpp +++ b/CppTick/Inc/cpptick/cpptick.hpp @@ -5,6 +5,6 @@ #pragma once #include "cpptick/argstore.hpp" -#include "cpptick/timer.hpp" #include "cpptick/scheduler.hpp" #include "cpptick/slot.hpp" +#include "cpptick/timer.hpp" diff --git a/CppTick/Inc/cpptick/scheduler.hpp b/CppTick/Inc/cpptick/scheduler.hpp index ed3ae19..b256b7a 100644 --- a/CppTick/Inc/cpptick/scheduler.hpp +++ b/CppTick/Inc/cpptick/scheduler.hpp @@ -4,9 +4,9 @@ #pragma once -#include -#include #include +#include +#include #include #include @@ -18,7 +18,7 @@ namespace cpptick struct BaseScheduler { - using StoredCall = std::pair*, ArgStorage>; + using StoredCall = std::pair*, ArgStorage>; Utility::Ringbuffer stored_calls; using StoredTimer = std::pair; @@ -48,7 +48,7 @@ struct BaseScheduler } } - ArgStorage& storeCall(Utility::IFunction* call) + ArgStorage& storeCall(Utility::IFunction* call) { // @todo: handle overflow... @@ -81,7 +81,7 @@ struct Scheduler : BaseScheduler if (empty_slot == stored_timers.end()) return; - *empty_slot = { time_to_run, timer }; + *empty_slot = {time_to_run, timer}; std::sort(stored_timers.begin(), stored_timers.end()); } @@ -120,5 +120,4 @@ struct Scheduler : BaseScheduler } }; -} - +}// namespace cpptick diff --git a/CppTick/Inc/cpptick/slot.hpp b/CppTick/Inc/cpptick/slot.hpp index c954f77..8c5ca88 100644 --- a/CppTick/Inc/cpptick/slot.hpp +++ b/CppTick/Inc/cpptick/slot.hpp @@ -4,9 +4,9 @@ #pragma once -#include #include #include +#include #include #include @@ -23,15 +23,14 @@ struct Slot; template struct Slot { - std::array*, 12> signals; + std::array*, 12> signals; BaseScheduler* scheduler; - Utility::FunctionOwned, void (ArgStorage&)> invoke_ptr; + Utility::FunctionOwned, void(ArgStorage&)> invoke_ptr; Slot() = delete; explicit Slot(BaseScheduler* sched) - : scheduler(sched) - , invoke_ptr(*this, &Slot::callUp) + : scheduler(sched), invoke_ptr(*this, &Slot::callUp) { signals.fill(nullptr); } @@ -41,7 +40,7 @@ struct Slot Slot& operator=(const Slot&) = delete; Slot& operator=(Slot&&) = delete; - void connect(Utility::IFunction* signal) + void connect(Utility::IFunction* signal) { for (auto*& callable : signals) { @@ -53,9 +52,9 @@ struct Slot } } - Utility::IFunction* connect(R (*func)(Args...)) + Utility::IFunction* connect(R (*func)(Args...)) { - auto* f = new Utility::Function(func); + auto* f = new Utility::Function(func); connect(f); @@ -63,9 +62,9 @@ struct Slot } template - Utility::IFunction* connect(Source& src, R (Source::* func)(Args...)) + Utility::IFunction* connect(Source& src, R (Source::*func)(Args...)) { - auto* f = new Utility::FunctionOwned(src, func); + auto* f = new Utility::FunctionOwned(src, func); connect(f); @@ -73,12 +72,12 @@ struct Slot } template - void callUpFunction(Utility::IFunction* func, ArgStorage& args, std::index_sequence) + void callUpFunction(Utility::IFunction* func, ArgStorage& args, std::index_sequence) { (*func)(std::forward(args.at(Is))...); } - void callUpFunction(Utility::IFunction* func, ArgStorage& args) + void callUpFunction(Utility::IFunction* func, ArgStorage& args) { callUpFunction(func, args, std::make_index_sequence{}); } @@ -103,4 +102,4 @@ struct Slot } }; -} +}// namespace cpptick diff --git a/CppTick/Inc/cpptick/timer.hpp b/CppTick/Inc/cpptick/timer.hpp index 6e362ff..d795a25 100644 --- a/CppTick/Inc/cpptick/timer.hpp +++ b/CppTick/Inc/cpptick/timer.hpp @@ -25,10 +25,8 @@ struct Timer }; Timer(BaseScheduler* scheduler, const std::uint32_t timeout_ms, const Type type) - : scheduler_(scheduler) - , period_ms(timeout_ms) - , type(type) - { } + : scheduler_(scheduler), period_ms(timeout_ms), type(type) + {} Timer() = delete; Timer(const Timer&) = delete; @@ -44,12 +42,12 @@ struct Timer setSlot(&slot.invoke_ptr); } - void setSlot(Utility::IFunction* slot) + void setSlot(Utility::IFunction* slot) { slot_ = slot; } - Utility::IFunction* getSlot() + Utility::IFunction* getSlot() { return slot_; } @@ -61,9 +59,10 @@ struct Timer std::uint32_t period_ms; Type type; + private: BaseScheduler* scheduler_; - Utility::IFunction* slot_ = nullptr; + Utility::IFunction* slot_ = nullptr; }; -} +}// namespace cpptick diff --git a/CppTick/Src/timer.cpp b/CppTick/Src/timer.cpp index 860cba0..8eef880 100644 --- a/CppTick/Src/timer.cpp +++ b/CppTick/Src/timer.cpp @@ -14,4 +14,4 @@ void Timer::start() scheduler_->storeTimer(this); } -} +}// namespace cpptick diff --git a/Tests/cpptick.cpp b/Tests/cpptick.cpp index c2f9ce9..89fa2ef 100644 --- a/Tests/cpptick.cpp +++ b/Tests/cpptick.cpp @@ -36,19 +36,18 @@ struct TestHal return std::uint32_t( duration_cast(system_clock::now().time_since_epoch()) - .count() - ); + .count()); } }; -} +}// namespace TEST_CASE("Slot calls function properly with void args.", "[cpptick]") { cpptick::Scheduler scheduler; - cpptick::Slot slot(&scheduler); + cpptick::Slot slot(&scheduler); auto* f = slot.connect(callbackByOne); callback_count = 0; @@ -99,7 +98,7 @@ TEST_CASE("Slot calls function properly with args.", "[cpptick]") { cpptick::Scheduler scheduler; - cpptick::Slot slot(&scheduler); + cpptick::Slot slot(&scheduler); auto* f = slot.connect(callbackByN); callback_count = 0; @@ -122,7 +121,7 @@ TEST_CASE("Timer will be invoked.", "[cpptick]") { cpptick::Scheduler scheduler; - cpptick::Slot slot(&scheduler); + cpptick::Slot slot(&scheduler); auto* f = slot.connect(callbackByOne); callback_count = 0; @@ -179,7 +178,7 @@ TEST_CASE("Periodic timers will be invoked repeatedly.", "[cpptick]") { cpptick::Scheduler scheduler; - cpptick::Slot slot(&scheduler); + cpptick::Slot slot(&scheduler); auto* f = slot.connect(callbackByOne); callback_count = 0; @@ -226,17 +225,16 @@ TEST_CASE("Sequential timers operate appropriately.", "[cpptick]") { cpptick::Scheduler scheduler; - cpptick::Slot slot_a(&scheduler); + cpptick::Slot slot_a(&scheduler); auto* f = slot_a.connect(callbackByOne); cpptick::Timer timer_a(&scheduler, 100, cpptick::Timer::PERIODIC); timer_a.setSlot(slot_a); - auto callback_by_two = []() -> void - { + auto callback_by_two = []() -> void { callback_count += 2; }; - cpptick::Slot slot_b(&scheduler); + cpptick::Slot slot_b(&scheduler); auto* ff = slot_b.connect(callback_by_two); cpptick::Timer timer_b(&scheduler, 50, cpptick::Timer::ONE_SHOT);