99
1010#pragma once
1111
12- #include < cassert>
1312#include < functional>
1413#include < map>
1514#include < memory>
@@ -84,7 +83,8 @@ inline constexpr EStateFlags& operator&=(EStateFlags& lhs, EStateFlags rhs)
8483 * @tparam EventType Event type
8584 * @tparam HistoryMapAllocator Allocator for history map (only when history states are used)
8685 */
87- template <typename ImplType, typename EventType, PolymorphicAllocatorProvider HistoryMapAllocator = HeapAllocator>
86+ template <typename ImplType, typename EventType, PolymorphicAllocatorProvider HistoryMapAllocator = HeapAllocator,
87+ AssertionProvider AssertionProviderType = DefaultAssertionProvider>
8888class Statemachine
8989{
9090public:
@@ -435,7 +435,7 @@ public:
435435 */
436436 void Init (ImplPtr impl, const char * name)
437437 {
438- assert (impl != nullptr );
438+ AssertionProviderType::Assert (impl != nullptr );
439439 name_ = name;
440440 impl_ = impl;
441441 }
@@ -446,7 +446,7 @@ public:
446446 */
447447 void Start (const State* initial)
448448 {
449- assert (impl_ != nullptr ); // Most probably you forgot to call Init()
449+ AssertionProviderType::Assert (impl_ != nullptr ); // Most probably you forgot to call Init()
450450 current_state_ = &kInTransition ;
451451 initial_.clear ();
452452 EnterStatesFromDownTo (nullptr , initial);
@@ -459,8 +459,8 @@ public:
459459 */
460460 void React (Event event)
461461 {
462- assert (current_state_ != nullptr ); // Most probably you forgot to call Start()
463- assert (!working_); // Most probably you are recursively calling React()
462+ AssertionProviderType::Assert (current_state_ != nullptr ); // Most probably you forgot to call Start()
463+ AssertionProviderType::Assert (!working_); // Most probably you are recursively calling React()
464464 working_ = true ;
465465
466466 Transition transition (kInTransition );
@@ -477,7 +477,7 @@ public:
477477
478478 if (transition.target_ == &kDeferEvent )
479479 {
480- assert (on_defer_event_ != nullptr );
480+ AssertionProviderType::Assert (on_defer_event_ != nullptr );
481481 on_defer_event_ (*s, event);
482482 working_ = false ;
483483 return ;
@@ -527,7 +527,7 @@ public:
527527 */
528528 void RecallEvents ()
529529 {
530- assert (on_recall_deferred_events_ != nullptr );
530+ AssertionProviderType::Assert (on_recall_deferred_events_ != nullptr );
531531 on_recall_deferred_events_ (*current_state_);
532532 }
533533
@@ -809,13 +809,19 @@ private:
809809 }
810810};
811811
812- template <typename Impl, typename Event, PolymorphicAllocatorProvider Allocator>
813- const typename Statemachine<Impl, Event, Allocator>::State Statemachine<Impl, Event, Allocator>::kNone =
814- typename Statemachine<Impl, Event, Allocator>::State(" None" , nullptr );
815- template <typename Impl, typename Event, PolymorphicAllocatorProvider Allocator>
816- const typename Statemachine<Impl, Event, Allocator>::State Statemachine<Impl, Event, Allocator>::kInTransition =
817- typename Statemachine<Impl, Event, Allocator>::State(" InTransition" , nullptr );
818- template <typename Impl, typename Event, PolymorphicAllocatorProvider Allocator>
819- const typename Statemachine<Impl, Event, Allocator>::State Statemachine<Impl, Event, Allocator>::kDeferEvent =
820- typename Statemachine<Impl, Event, Allocator>::State(" Defer" , nullptr );
812+ template <typename Impl, typename Event, PolymorphicAllocatorProvider Allocator,
813+ AssertionProvider AssertionProviderType>
814+ const typename Statemachine<Impl, Event, Allocator, AssertionProviderType>::State
815+ Statemachine<Impl, Event, Allocator, AssertionProviderType>::kNone =
816+ typename Statemachine<Impl, Event, Allocator, AssertionProviderType>::State(" None" , nullptr );
817+ template <typename Impl, typename Event, PolymorphicAllocatorProvider Allocator,
818+ AssertionProvider AssertionProviderType>
819+ const typename Statemachine<Impl, Event, Allocator, AssertionProviderType>::State
820+ Statemachine<Impl, Event, Allocator, AssertionProviderType>::kInTransition =
821+ typename Statemachine<Impl, Event, Allocator, AssertionProviderType>::State(" InTransition" , nullptr );
822+ template <typename Impl, typename Event, PolymorphicAllocatorProvider Allocator,
823+ AssertionProvider AssertionProviderType>
824+ const typename Statemachine<Impl, Event, Allocator, AssertionProviderType>::State
825+ Statemachine<Impl, Event, Allocator, AssertionProviderType>::kDeferEvent =
826+ typename Statemachine<Impl, Event, Allocator, AssertionProviderType>::State(" Defer" , nullptr );
821827} // namespace cpp_event_framework
0 commit comments