diff --git a/README.md b/README.md index 616c08c..986b524 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ Header-only heriarchical FSM framework in C++11, with fully statically-defined s ## Feature Highlights -- Permissive **[MIT License](https://github.com/andrew-gresyk/FFSM2/blob/master/LICENSE)** +- Permissive **[MIT License](https://github.com/andrew-gresyk/HFSM2/blob/master/LICENSE)** - Written in widely-supported modern(ish) C++11 - Header-only - Convenient, minimal boilerplate diff --git a/examples/advanced_event_handling/main.cpp b/examples/advanced_event_handling/main.cpp index e740304..5fc3b7a 100644 --- a/examples/advanced_event_handling/main.cpp +++ b/examples/advanced_event_handling/main.cpp @@ -1,4 +1,4 @@ -// HFSM (hierarchical state machine for games and interactive applications) +// HFSM2 (hierarchical state machine for games and interactive applications) // Created by Andrew Gresyk // // Event handling example @@ -94,7 +94,7 @@ struct Reactive : FSM::State { // handle a single event type - TransitionEvent - void react(const TransitionEvent&, FullControl& control) { + void react(const TransitionEvent&, FullControl& control) noexcept { std::cout << " Reactive: reacting to TransitionEvent\n"; control.changeTo(); @@ -118,12 +118,12 @@ struct ConcreteHandler : FSM::State { // handle two event types - PrimaryEvent - void react(const PrimaryEvent&, FullControl&) { + void react(const PrimaryEvent&, FullControl&) noexcept { std::cout << " ConcreteHandler: reacting to PrimaryEvent\n"; } // and SecondaryEvent - void react(const SecondaryEvent&, FullControl&) { + void react(const SecondaryEvent&, FullControl&) noexcept { std::cout << " ConcreteHandler: reacting to SecondaryEvent\n"; } @@ -138,7 +138,7 @@ struct TemplateHandler { // handle all possible event types template - void react(const TEvent&, FullControl&) { + void react(const TEvent&, FullControl&) noexcept { std::cout << " TemplateHandler: reacting to TEvent\n"; } }; @@ -151,14 +151,14 @@ struct EnableIfHandler // use std::enable_if to build more complex conditional event handling template typename std::enable_if::value>::type - react(const TEvent&, FullControl&) { + react(const TEvent&, FullControl&) noexcept { std::cout << " EnableIfHandler: reacting to a \n"; } // but remember to cover all the remaining cases template typename std::enable_if::value>::type - react(const TEvent&, FullControl&) { + react(const TEvent&, FullControl&) noexcept { std::cout << " EnableIfHandler: reacting to a \n"; } }; @@ -168,7 +168,7 @@ struct EnableIfHandler struct Target : FSM::State { - void enter(Control&) { + void enter(Control&) noexcept { std::cout << " changed to Target\n"; } }; @@ -176,7 +176,7 @@ struct Target //////////////////////////////////////////////////////////////////////////////// int -main() { +main() noexcept { FSM::Instance machine; std::cout << "sending PrimaryEvent:\n"; diff --git a/examples/basic_audio_player/main.cpp b/examples/basic_audio_player/main.cpp index 4ff18de..8918a87 100644 --- a/examples/basic_audio_player/main.cpp +++ b/examples/basic_audio_player/main.cpp @@ -1,4 +1,4 @@ -// HFSM (hierarchical state machine for games and interactive applications) +// HFSM2 (hierarchical state machine for games and interactive applications) // Created by Andrew Gresyk // // An HFSM2 port of https://gist.github.com/martinmoene/797b1923f9c6c1ae355bb2d6870be25e @@ -64,7 +64,7 @@ static_assert(FSM::stateId() == 3, ""); struct Logger : M::LoggerInterface { - static const char* stateName(const StateID stateId) { + static const char* stateName(const StateID stateId) noexcept { switch (stateId) { case 1: return "Idle"; @@ -81,7 +81,7 @@ struct Logger void recordTransition(Context& /*context*/, const StateID origin, const TransitionType /*transition*/, - const StateID target) override + const StateID target) noexcept override { std::cout << stateName(origin) << " -> " << stateName(target) << "\n"; } @@ -94,7 +94,7 @@ struct Base : FSM::State { template - void react(const Event&, FullControl&) { + void react(const Event&, FullControl&) noexcept { std::cout << "[unsupported transition]\n"; } }; @@ -105,7 +105,7 @@ struct Idle { using Base::react; - void react(const Play& event, FullControl& control) { + void react(const Play& event, FullControl& control) noexcept { control.context() = event.title; control.changeTo(); } @@ -116,11 +116,11 @@ struct Playing { using Base::react; - void react(const Pause&, FullControl& control) { + void react(const Pause&, FullControl& control) noexcept { control.changeTo(); } - void react(const Stop&, FullControl& control) { + void react(const Stop&, FullControl& control) noexcept { control.changeTo(); } }; @@ -130,39 +130,40 @@ struct Paused { using Base::react; - void react(const Resume&, FullControl& control) { + void react(const Resume&, FullControl& control) noexcept { control.changeTo(); } - void react(const Stop&, FullControl& control) { + void react(const Stop&, FullControl& control) noexcept { control.changeTo(); } }; //------------------------------------------------------------------------------ -int main() { +int +main() noexcept { // construct everything Context title; Logger logger; FSM::Instance machine(title, &logger); // do the work :) - machine.react(Play{"any"}); - machine.react(Stop{}); + machine.react(Play{"any"}); // Idle -> Playing + machine.react(Stop{}); // Playing -> Idle - machine.react(Play{"optional"}); - machine.react(Pause{}); - machine.react(Stop{}); + machine.react(Play{"optional"}); // Idle -> Playing + machine.react(Pause{}); // Playing -> Paused + machine.react(Stop{}); // Paused -> Idle - machine.react(Play{"variant"}); - machine.react(Pause{}); //-V760 - machine.react(Resume{}); - machine.react(Stop{}); + machine.react(Play{"variant"}); // Idle -> Playing + machine.react(Pause{}); //-V760 // Playing -> Paused + machine.react(Resume{}); // Paused -> Playing + machine.react(Stop{}); // Playing -> Idle - machine.react(Pause{}); - machine.react(Resume{}); - machine.react(Stop{}); + machine.react(Pause{}); // [unsupported transition] + machine.react(Resume{}); // [unsupported transition] + machine.react(Stop{}); // [unsupported transition] return 0; } diff --git a/examples/basic_traffic_light/main.cpp b/examples/basic_traffic_light/main.cpp index 1167e8b..478061b 100644 --- a/examples/basic_traffic_light/main.cpp +++ b/examples/basic_traffic_light/main.cpp @@ -1,4 +1,4 @@ -// HFSM (hierarchical state machine for games and interactive applications) +// HFSM2 (hierarchical state machine for games and interactive applications) // Created by Andrew Gresyk // // Traffic light example: @@ -42,7 +42,7 @@ // data shared between FSM states and outside code struct Context { - unsigned cycleCount; + unsigned cycleCount = 0; }; // convenience typedef @@ -110,7 +110,7 @@ struct On : FSM::State // necessary boilerplate! { // called on state entry - void enter(Control& control) { + void enter(Control& control) noexcept { control.context().cycleCount = 0; std::cout << "On" << std::endl; } @@ -122,13 +122,13 @@ struct On struct Red : FSM::State { - void enter(Control& control) { + void enter(Control& control) noexcept { ++control.context().cycleCount; std::cout << " Red" << std::endl; } // state can initiate transitions to _any_ other state - void update(FullControl& control) { + void update(FullControl& control) noexcept { // multiple transitions can be initiated, can be useful in a hierarchy if (control.context().cycleCount > 3) control.changeTo(); @@ -142,11 +142,11 @@ struct Red struct YellowDownwards : FSM::State { - void enter(Control&) { + void enter(Control&) noexcept { std::cout << " Yellow v" << std::endl; } - void update(FullControl& control) { + void update(FullControl& control) noexcept { control.changeTo(); } }; @@ -156,11 +156,11 @@ struct YellowDownwards struct YellowUpwards : FSM::State { - void enter(Control&) { + void enter(Control&) noexcept { std::cout << " Yellow ^" << std::endl; } - void update(FullControl& control) { + void update(FullControl& control) noexcept { control.changeTo(); } }; @@ -170,11 +170,11 @@ struct YellowUpwards struct Green : FSM::State { - void enter(Control&) { + void enter(Control&) noexcept { std::cout << " Green" << std::endl; } - void update(FullControl& control) { + void update(FullControl& control) noexcept { control.changeTo(); } }; @@ -185,7 +185,7 @@ struct Green struct Off : FSM::State { - void enter(Control&) { + void enter(Control&) noexcept { std::cout << "Off" << std::endl; } }; @@ -193,7 +193,7 @@ struct Off //////////////////////////////////////////////////////////////////////////////// int -main() { +main() noexcept { // shared data storage instance Context context; diff --git a/examples/debug_logger_interface/main.cpp b/examples/debug_logger_interface/main.cpp index 93b2cbb..04a46a7 100644 --- a/examples/debug_logger_interface/main.cpp +++ b/examples/debug_logger_interface/main.cpp @@ -1,4 +1,4 @@ -// HFSM (hierarchical state machine for games and interactive applications) +// HFSM2 (hierarchical state machine for games and interactive applications) // Created by Andrew Gresyk // // Attachable logger example: @@ -90,7 +90,7 @@ struct Logger { void recordMethod(Context& /*context*/, const hfsm2::StateID /*origin*/, - const Method method) override + const Method method) noexcept override { std::cout //<< hfsm2::stateName(origin) << "::" << hfsm2::methodName(method) << "()\n"; @@ -99,7 +99,7 @@ struct Logger void recordTransition(Context& /*context*/, const hfsm2::StateID /*origin*/, const TransitionType transitionType, - const hfsm2::StateID /*target*/) override + const hfsm2::StateID /*target*/) noexcept override { std::cout //<< hfsm2::stateName(origin) << ": " << hfsm2::transitionName(transitionType) << "<" @@ -115,12 +115,12 @@ struct Top : FSM::State // necessary boilerplate! { // all state methods: - void entryGuard(GuardControl&) {} // not going to be called in this example - void enter(Control&) {} - void update(FullControl&) {} + void entryGuard(GuardControl&) noexcept {} // not going to be called in this example + void enter(Control&) noexcept {} + void update(FullControl&) noexcept {} template - void react(const TEvent&, FullControl&) {} - void exit(Control&) {} + void react(const TEvent&, FullControl&) noexcept {} + void exit(Control&) noexcept {} }; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -130,12 +130,12 @@ struct From : FSM::State { // all state methods: - void entryGuard(GuardControl&) {} // not going to be called in this example - void enter(Control&) {} - void update(FullControl&) {} + void entryGuard(GuardControl&) noexcept {} // not going to be called in this example + void enter(Control&) noexcept {} + void update(FullControl&) noexcept {} template - void react(const TEvent&, FullControl& control) { control.changeTo(); } - void exit(Control&) {} + void react(const TEvent&, FullControl& control) noexcept { control.changeTo(); } + void exit(Control&) noexcept {} }; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -145,17 +145,18 @@ struct To : FSM::State { // all state methods: - void entryGuard(GuardControl&) {} - void enter(Control&) {} - void update(FullControl&) {} + void entryGuard(GuardControl&) noexcept {} + void enter(Control&) noexcept {} + void update(FullControl&) noexcept {} template - void react(const TEvent&, FullControl&) {} // not going to be called in this example - void exit(Control&) {} + void react(const TEvent&, FullControl&) noexcept {} // not going to be called in this example + void exit(Control&) noexcept {} }; //////////////////////////////////////////////////////////////////////////////// -int main() { +int +main() noexcept { { // logger Logger logger; diff --git a/examples/snippets/wiki_plans.cpp b/examples/snippets/wiki_plans.cpp index 4e8f2b6..9c4fdb0 100644 --- a/examples/snippets/wiki_plans.cpp +++ b/examples/snippets/wiki_plans.cpp @@ -24,7 +24,7 @@ TEST_CASE("Wiki.Plans.Traffic Light", "[Wiki]") { struct Apex : FSM::State { - void enter(PlanControl& control) { + void enter(PlanControl& control) noexcept { // create an empty plan auto plan = control.plan(); @@ -42,15 +42,15 @@ TEST_CASE("Wiki.Plans.Traffic Light", "[Wiki]") { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - struct Red : FSM::State { - void update(FullControl& control) { control.succeed(); } + void update(FullControl& control) noexcept { control.succeed(); } }; struct Yellow : FSM::State { - void update(FullControl& control) { control.succeed(); } + void update(FullControl& control) noexcept { control.succeed(); } }; struct Green : FSM::State { - void update(FullControl& control) { control.succeed(); } + void update(FullControl& control) noexcept { control.succeed(); } }; //---------------------------------------------------------------------- @@ -104,7 +104,7 @@ TEST_CASE("Wiki.Plans.Detailed Demo", "[Wiki]") { struct PlanOwner : FSM::State { - void enter(PlanControl& control) { + void enter(PlanControl& control) noexcept { auto plan = control.plan(); // build the plan by sequencing transitions @@ -124,7 +124,7 @@ TEST_CASE("Wiki.Plans.Detailed Demo", "[Wiki]") { //void planSucceeded(FullControl& control) {} // respond to plan failure below - void planFailed(FullControl& control) { + void planFailed(FullControl& control) noexcept { control.changeTo(); } }; @@ -132,7 +132,7 @@ TEST_CASE("Wiki.Plans.Detailed Demo", "[Wiki]") { struct StateTask : FSM::State { - void update(FullControl& control) { + void update(FullControl& control) noexcept { control.succeed(); } }; @@ -144,7 +144,7 @@ TEST_CASE("Wiki.Plans.Detailed Demo", "[Wiki]") { struct CT_Initial : FSM::State { - void update(FullControl& control) { + void update(FullControl& control) noexcept { // mark the task as successful control.changeTo(); } @@ -153,7 +153,7 @@ TEST_CASE("Wiki.Plans.Detailed Demo", "[Wiki]") { struct CT_Following : FSM::State { - void update(FullControl& control) { + void update(FullControl& control) noexcept { // even though CompositeTask has no plan attached to it, // the sub-state can 'succeed' the entire region control.succeed(); @@ -169,7 +169,7 @@ TEST_CASE("Wiki.Plans.Detailed Demo", "[Wiki]") { struct OT_2 : FSM::State { - void update(FullControl& control) { + void update(FullControl& control) noexcept { // the task can also be marked successful // from its sub-state one level down control.succeed(); @@ -181,7 +181,7 @@ TEST_CASE("Wiki.Plans.Detailed Demo", "[Wiki]") { struct ReplanTask : FSM::State { - void update(FullControl& control) { + void update(FullControl& control) noexcept { // parametrized version of PlanControl::plan() allows access to plans // hosted by any region auto plan = control.plan(); @@ -219,7 +219,7 @@ TEST_CASE("Wiki.Plans.Detailed Demo", "[Wiki]") { : FSM::State { // guard gets executed before the first sub-state activates implicitly .. - void entryGuard(GuardControl& control) { + void entryGuard(GuardControl& control) noexcept { // .. so the plan can start from the second sub-state control.changeTo(); @@ -230,15 +230,15 @@ TEST_CASE("Wiki.Plans.Detailed Demo", "[Wiki]") { // without plan execution reactions, plan results // are propagated to the outer plan // - //void planSucceeded(FullControl& control) {} - //void planFailed(FullControl& control) {} + //void planSucceeded(FullControl& control) noexcept {} + //void planFailed(FullControl& control) noexcept {} }; // these appear in the plan in reverse order struct SubTask_1 : FSM::State { - void update(FullControl& control) { + void update(FullControl& control) noexcept { // owner region's planFailed() gets called in response to plan failure control.fail(); } @@ -247,7 +247,7 @@ TEST_CASE("Wiki.Plans.Detailed Demo", "[Wiki]") { struct SubTask_2 : FSM::State { - void update(FullControl& control) { + void update(FullControl& control) noexcept { // continue in reverse order, as defined by the plan in SubPlanOwner control.succeed(); } diff --git a/examples/snippets/wiki_transitions-within-hierarchy.cpp b/examples/snippets/wiki_transitions-within-hierarchy.cpp index e70939a..c846ec1 100644 --- a/examples/snippets/wiki_transitions-within-hierarchy.cpp +++ b/examples/snippets/wiki_transitions-within-hierarchy.cpp @@ -90,7 +90,7 @@ TEST_CASE("Wiki.Transitions within Hierarchy.Internal Transition Interface", "[W struct Origin : FSM::State { - void update(FullControl& control) { + void update(FullControl& control) noexcept { control.changeTo(); // internal transition } }; @@ -187,13 +187,13 @@ TEST_CASE("Wiki.Transitions within Hierarchy.'Utilize' Transition", "[Wiki]") { struct LowRated : FSM::State { - float utility(const Control&) { return 0.5f; } + float utility(const Control&) noexcept { return 0.5f; } }; struct HighRated : FSM::State { - float utility(const Control&) { return 2.0f; } + float utility(const Control&) noexcept { return 2.0f; } }; FSM::Instance fsm; @@ -224,25 +224,25 @@ TEST_CASE("Wiki.Transitions within Hierarchy.'Randomize' Transition", "[Wiki]") struct FilteredOut : FSM::State { - int8_t rank(const Control&) { return 0; } // filter out using low rank + int8_t rank(const Control&) noexcept { return 0; } // filter out using low rank - float utility(const Control&) { return 0.5f; } + float utility(const Control&) noexcept { return 0.5f; } }; struct LowRated : FSM::State { - int8_t rank(const Control&) { return 1; } + int8_t rank(const Control&) noexcept { return 1; } - float utility(const Control&) { return 0.5f; } + float utility(const Control&) noexcept { return 0.5f; } }; struct HighRated : FSM::State { - int8_t rank(const Control&) { return 1; } + int8_t rank(const Control&) noexcept { return 1; } - float utility(const Control&) { return 2.0f; } + float utility(const Control&) noexcept { return 2.0f; } }; FSM::Instance fsm; diff --git a/examples/snippets/wiki_tutorial.cpp b/examples/snippets/wiki_tutorial.cpp index 9cf6fcf..355650a 100644 --- a/examples/snippets/wiki_tutorial.cpp +++ b/examples/snippets/wiki_tutorial.cpp @@ -33,9 +33,9 @@ using M = hfsm2::MachineT; #define S(s) struct s using FSM = M::PeerRoot< - S(Off), // initial top-level state - M::Composite, @@ -56,55 +56,55 @@ struct Event {}; struct Off : FSM::State { - void entryGuard(FullControl& control) { // called before state activation, use to re-route transitions - if (control.context().powerOn) // access shared data - control.changeTo(); // initiate a transition into 'On' region + void entryGuard(FullControl& control) noexcept { // called before state activation, use to re-route transitions + if (control.context().powerOn) // access shared data + control.changeTo(); // initiate a transition into 'On' region } }; struct On : FSM::State { - void enter(PlanControl& control) { // called on state activation - auto plan = control.plan(); // access the plan for the region + void enter(PlanControl& control) noexcept { // called on state activation + auto plan = control.plan(); // access the plan for the region - plan.change(); // sequence plan steps, executed when the previous state succeeds + plan.change(); // sequence plan steps, executed when the previous state succeeds plan.change(); plan.change(); plan.change(); } - void exit(PlanControl& /*control*/) {} // called on state deactivation + void exit(PlanControl& /*control*/) noexcept {} // called on state deactivation - void planSucceeded(FullControl& control) { // called on the successful completion of all plan steps + void planSucceeded(FullControl& control) noexcept { // called on the successful completion of all plan steps control.changeTo(); } - void planFailed(FullControl& /*control*/) {} // called if any of the plan steps fails + void planFailed(FullControl& /*control*/) noexcept {} // called if any of the plan steps fails }; struct Red : FSM::State { - void update(FullControl& control) { // called on periodic state machine updates - control.succeed(); // notify successful completion of the plan step - } // plan will advance to the 'Yellow' state + void update(FullControl& control) noexcept { // called on periodic state machine updates + control.succeed(); // notify successful completion of the plan step + } // plan will advance to the 'Yellow' state }; struct Yellow : FSM::State { - void update(FullControl& control) { - control.succeed(); // plan will advance to the 'Green' state on the first entry - // and 'Red' state on the second one + void update(FullControl& control) noexcept { + control.succeed(); // plan will advance to the 'Green' state on the first entry + // and 'Red' state on the second one } }; struct Green : FSM::State { - void react(const Event&, FullControl& control) { // called on external events - control.succeed(); // advance to the next plan step + void react(const Event&, FullControl& control) noexcept { // called on external events + control.succeed(); // advance to the next plan step } }; @@ -121,23 +121,23 @@ TEST_CASE("Wiki.Tutorial", "[Wiki]") { context.powerOn = true; FSM::Instance fsm{context}; - assert(fsm.isActive()); // activated by Off::entryGuard() - assert(fsm.isActive()); // On's initial sub-state + assert(fsm.isActive()); // activated by Off::entryGuard() + assert(fsm.isActive()); // On's initial sub-state fsm.update(); - assert(fsm.isActive()); // 1st setp of On's plan + assert(fsm.isActive()); // 1st setp of On's plan fsm.update(); - assert(fsm.isActive()); // 2nd setp of On's plan + assert(fsm.isActive()); // 2nd setp of On's plan fsm.react(Event{}); - assert(fsm.isActive()); // 3rd setp of On's plan + assert(fsm.isActive()); // 3rd setp of On's plan fsm.update(); - assert(fsm.isActive()); // 4th setp of On's plan + assert(fsm.isActive()); // 4th setp of On's plan fsm.update(); - assert(fsm.isActive()); // activated by On::planSucceeded() + assert(fsm.isActive()); // activated by On::planSucceeded() } //////////////////////////////////////////////////////////////////////////////// diff --git a/examples/snippets/wiki_utility-theory.cpp b/examples/snippets/wiki_utility-theory.cpp index 8b5bca2..ea82da4 100644 --- a/examples/snippets/wiki_utility-theory.cpp +++ b/examples/snippets/wiki_utility-theory.cpp @@ -26,7 +26,7 @@ struct Event { Event(const hfsm2::StateID state_, const Enum type_, - const hfsm2::StateID prong_ = hfsm2::INVALID_STATE_ID) + const hfsm2::StateID prong_ = hfsm2::INVALID_STATE_ID) noexcept : state{state_} , type{type_} , prong{prong_} @@ -45,7 +45,7 @@ struct Logger { void recordMethod(Context& /*context*/, const StateID state, - const Method method) override + const Method method) noexcept override { if (method == Method::RANK) history.emplace_back(state, Event::RANK); @@ -56,7 +56,7 @@ struct Logger void recordUtilityResolution(Context& /*context*/, const StateID head, const StateID prong, - const Utilty /*utilty*/) override + const Utilty /*utilty*/) noexcept override { history.emplace_back(head, Event::UTILITY_RESOLUTION, prong); } @@ -64,13 +64,12 @@ struct Logger void recordRandomResolution(Context& /*context*/, const StateID head, const StateID prong, - const Utilty /*utilty*/) override + const Utilty /*utilty*/) noexcept override { history.emplace_back(head, Event::RANDOM_RESOLUTION, prong); } - void assertSequence(const Events& reference) - { + void assertSequence(const Events& reference) noexcept { const auto count = std::max(history.size(), reference.size()); for (unsigned i = 0; i < count; ++i) { @@ -143,11 +142,11 @@ struct R_Activated : FSM::State {}; // only consider previously activated sub- struct U : FSM::State {}; // for 'Utilitarian' region, // find the highest-scoring sub-state struct U_033 : FSM::State { - Utility utility(const Control&) { return 0.33f; } + Utility utility(const Control&) noexcept { return 0.33f; } }; struct U_067 : FSM::State { - Utility utility(const Control&) { return 0.67f; } + Utility utility(const Control&) noexcept { return 0.67f; } }; struct D : FSM::State {}; // for 'Random' region, @@ -155,17 +154,17 @@ struct D : FSM::State {}; // for 'Random' region, // 2. from the remaining sub-states, // randomly select one based on their score struct D_Filtered : FSM::State { - Rank rank(const Control&) {return -1; } + Rank rank(const Control&) noexcept {return -1; } }; struct D_010 : FSM::State { - Rank rank(const Control&) {return 0; } - Utility utility(const Control&) { return 0.10f; } + Rank rank(const Control&) noexcept {return 0; } + Utility utility(const Control&) noexcept { return 0.10f; } }; struct D_090 : FSM::State { // inherit FSM::State::rank(), which returns '0' - Utility utility(const Control&) { return 0.90f; } + Utility utility(const Control&) noexcept { return 0.90f; } }; struct O : FSM::State {}; diff --git a/examples/temp/main.cpp b/examples/temp/main.cpp index c257b6f..f994581 100644 --- a/examples/temp/main.cpp +++ b/examples/temp/main.cpp @@ -66,7 +66,8 @@ struct Off void enter(Control&) { std::cout << "Off" << std::endl; } }; -int main() { +int +main() { Context context; FSM::Instance machine{ context }; diff --git a/hfsm2.natvis b/hfsm2.natvis index 9beffff..9f0bcf8 100644 --- a/hfsm2.natvis +++ b/hfsm2.natvis @@ -57,14 +57,20 @@ <{CAPACITY & 0x1}> - _storage + + (CAPACITY + 7 / 8) + (_storage[$i / (sizeof(Unit) * 8)] >> ($i % (sizeof(Unit) * 8))) & 0x1 + - + <{CAPACITY & 0x1}> - _storage + + (CAPACITY + 7 / 8) + (_storage[$i / (sizeof(Unit) * 8)] >> ($i % (sizeof(Unit) * 8))) & 0x1 + diff --git a/include/hfsm2/detail/features/common.hpp b/include/hfsm2/detail/features/common.hpp index 80c57ef..e4c8794 100644 --- a/include/hfsm2/detail/features/common.hpp +++ b/include/hfsm2/detail/features/common.hpp @@ -58,7 +58,7 @@ enum class StatusEvent : uint8_t { static inline const char* -stateName(const std::type_index stateType) { +stateName(const std::type_index stateType) noexcept { const char* const raw = stateType.name(); #if defined(_MSC_VER) @@ -84,7 +84,7 @@ stateName(const std::type_index stateType) { static inline const char* -methodName(const Method method) { +methodName(const Method method) noexcept { switch (method) { #ifdef HFSM2_ENABLE_UTILITY_THEORY @@ -117,7 +117,7 @@ methodName(const Method method) { static inline const char* -transitionName(const TransitionType type) { +transitionName(const TransitionType type) noexcept { switch (type) { case TransitionType::CHANGE: return "changeTo"; case TransitionType::RESTART: return "restart"; @@ -148,12 +148,12 @@ namespace detail { #endif struct alignas(4) TransitionBase { - HFSM2_INLINE TransitionBase() = default; + constexpr TransitionBase() noexcept = default; //---------------------------------------------------------------------- HFSM2_INLINE TransitionBase(const StateID destination_, - const TransitionType type_) + const TransitionType type_) noexcept : destination{destination_} , type{type_} {} @@ -162,15 +162,15 @@ struct alignas(4) TransitionBase { HFSM2_INLINE TransitionBase(const StateID origin_, const StateID destination_, - const TransitionType type_) - : origin{origin_} + const TransitionType type_) noexcept + : origin {origin_} , destination{destination_} - , type{type_} + , type {type_} {} //---------------------------------------------------------------------- - HFSM2_INLINE bool operator == (const TransitionBase& other) const { + HFSM2_INLINE bool operator == (const TransitionBase& other) const noexcept { return origin == other.origin && destination == other.destination && method == other.method && @@ -198,15 +198,19 @@ struct alignas(4) TransitionT using Payload = TPayload; using Storage = typename std::aligned_storage::type; - HFSM2_INLINE TransitionT() = default; - using TransitionBase::TransitionBase; //---------------------------------------------------------------------- + HFSM2_INLINE TransitionT() noexcept { + new (&storage) Payload{}; + } + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + HFSM2_INLINE TransitionT(const StateID destination, const TransitionType type, - const Payload& payload) + const Payload& payload) noexcept : TransitionBase{destination, type} , payloadSet{true} { @@ -217,7 +221,7 @@ struct alignas(4) TransitionT HFSM2_INLINE TransitionT(const StateID destination, const TransitionType type, - Payload&& payload) + Payload&& payload) noexcept : TransitionBase{destination, type} , payloadSet{true} { @@ -229,7 +233,7 @@ struct alignas(4) TransitionT HFSM2_INLINE TransitionT(const StateID origin, const StateID destination, const TransitionType type, - const Payload& payload) + const Payload& payload) noexcept : TransitionBase{origin, destination, type} , payloadSet{true} { @@ -241,7 +245,7 @@ struct alignas(4) TransitionT HFSM2_INLINE TransitionT(const StateID origin, const StateID destination, const TransitionType type, - Payload&& payload) + Payload&& payload) noexcept : TransitionBase{origin, destination, type} , payloadSet{true} { @@ -250,7 +254,7 @@ struct alignas(4) TransitionT //---------------------------------------------------------------------- - HFSM2_INLINE bool operator == (const TransitionT& other) const { + HFSM2_INLINE bool operator == (const TransitionT& other) const noexcept { return TransitionBase::operator == (other) && (payloadSet == other.payloadSet); // (!payloadSet && !other.payloadSet || payload == other.payload); diff --git a/include/hfsm2/detail/features/logger_interface.hpp b/include/hfsm2/detail/features/logger_interface.hpp index db67aed..7353bc0 100644 --- a/include/hfsm2/detail/features/logger_interface.hpp +++ b/include/hfsm2/detail/features/logger_interface.hpp @@ -25,13 +25,13 @@ struct LoggerInterfaceT { virtual void recordMethod(Context& /*context*/, const StateID /*origin*/, - const Method /*method*/) + const Method /*method*/) noexcept {} virtual void recordTransition(Context& /*context*/, const StateID /*origin*/, const TransitionType /*transitionType*/, - const StateID /*target*/) + const StateID /*target*/) noexcept {} #ifdef HFSM2_ENABLE_PLANS @@ -39,18 +39,18 @@ struct LoggerInterfaceT { virtual void recordTaskStatus(Context& /*context*/, const RegionID /*region*/, const StateID /*origin*/, - const StatusEvent /*event*/) + const StatusEvent /*event*/) noexcept {} virtual void recordPlanStatus(Context& /*context*/, const RegionID /*region*/, - const StatusEvent /*event*/) + const StatusEvent /*event*/) noexcept {} #endif virtual void recordCancelledPending(Context& /*context*/, - const StateID /*origin*/) + const StateID /*origin*/) noexcept {} #ifdef HFSM2_ENABLE_UTILITY_THEORY @@ -58,13 +58,13 @@ struct LoggerInterfaceT { virtual void recordUtilityResolution(Context& /*context*/, const StateID /*head*/, const StateID /*prong*/, - const Utilty /*utilty*/) + const Utilty /*utilty*/) noexcept {} virtual void recordRandomResolution(Context& /*context*/, const StateID /*head*/, const StateID /*prong*/, - const Utilty /*utilty*/) + const Utilty /*utilty*/) noexcept {} #endif diff --git a/include/hfsm2/detail/features/structure_report.hpp b/include/hfsm2/detail/features/structure_report.hpp index 98fd997..d0487af 100644 --- a/include/hfsm2/detail/features/structure_report.hpp +++ b/include/hfsm2/detail/features/structure_report.hpp @@ -29,14 +29,14 @@ struct alignas(alignof(void*)) StructureStateInfo { COUNT }; - StructureStateInfo() = default; + StructureStateInfo() noexcept = default; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE StructureStateInfo(const Long parent_, const RegionType regionType_, const Short depth_, - const char* const name_) + const char* const name_) noexcept : name{name_} , parent{parent_} , regionType{regionType_ } diff --git a/include/hfsm2/detail/root.hpp b/include/hfsm2/detail/root.hpp index 6b0d5c6..fba9b20 100644 --- a/include/hfsm2/detail/root.hpp +++ b/include/hfsm2/detail/root.hpp @@ -9,6 +9,7 @@ namespace detail { template class R_ { +public: static constexpr FeatureTag FEATURE_TAG = TConfig::FEATURE_TAG; using Context = typename TConfig::Context; @@ -21,6 +22,7 @@ class R_ { using Payload = typename TConfig::Payload; +private: using Apex = TApex; using Forward = RF_; @@ -76,8 +78,8 @@ class R_ { #endif #ifdef HFSM2_ENABLE_STRUCTURE_REPORT - using Prefix = StaticArray; - using Prefixes = StaticArray; + using Prefix = StaticArrayT; + using Prefixes = StaticArrayT; using StructureStateInfos = typename Args::StructureStateInfos; #endif @@ -90,11 +92,21 @@ class R_ { //---------------------------------------------------------------------- - explicit R_(Context& context - HFSM2_IF_UTILITY_THEORY(, RNG& rng) - HFSM2_IF_LOG_INTERFACE(, Logger* const logger = nullptr)); + HFSM2_INLINE explicit R_(Context& context + HFSM2_IF_UTILITY_THEORY(, RNG& rng) + HFSM2_IF_LOG_INTERFACE(, Logger* const logger = nullptr)) noexcept; - ~R_(); + HFSM2_INLINE ~R_() noexcept; + + //---------------------------------------------------------------------- + + /// @brief Access context + /// @return context + HFSM2_INLINE Context& context() noexcept { return _context; } + + /// @brief Access context + /// @return context + HFSM2_INLINE const Context& context() const noexcept { return _context; } //---------------------------------------------------------------------- @@ -102,13 +114,13 @@ class R_ { /// @tparam TState State type /// @return Numeric state identifier template - static constexpr StateID stateId() { return index(); } + static constexpr StateID stateId() noexcept { return index(); } /// @brief Get region identifier for a region type /// @tparam TState Region head state type /// @return Numeric region identifier template - static constexpr RegionID regionId() { return (RegionID) index(); } + static constexpr RegionID regionId() noexcept { return (RegionID) index(); } //---------------------------------------------------------------------- #ifdef HFSM2_EXPLICIT_MEMBER_SPECIALIZATION @@ -129,8 +141,8 @@ class R_ { template struct Accessor { - HFSM2_INLINE static TState& get( MaterialApex& apex) { return apex.template access(); } - HFSM2_INLINE static const TState& get(const MaterialApex& apex) { return apex.template access(); } + HFSM2_INLINE static TState& get( MaterialApex& apex) noexcept { return apex.template access(); } + HFSM2_INLINE static const TState& get(const MaterialApex& apex) noexcept { return apex.template access(); } }; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -146,13 +158,13 @@ class R_ { /// @tparam TState State type /// @return State instance template - HFSM2_INLINE TState& access() { return Accessor::get(_apex); } + HFSM2_INLINE TState& access() noexcept { return Accessor::get(_apex); } /// @brief Access state instance /// @tparam TState State type /// @return State instance template - HFSM2_INLINE const TState& access() const { return Accessor::get(_apex); } + HFSM2_INLINE const TState& access() const noexcept { return Accessor::get(_apex); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -164,98 +176,100 @@ class R_ { /// @tparam TState State type /// @return State instance template - HFSM2_INLINE TState& access() { return Accessor{_apex}.get(); } + HFSM2_INLINE TState& access() noexcept { return Accessor{_apex}.get(); } /// @brief Access state instance /// @tparam TState State type /// @return State instance template - HFSM2_INLINE const TState& access() const { return Accessor{_apex}.get(); } + HFSM2_INLINE const TState& access() const noexcept { return Accessor{_apex}.get(); } #endif //---------------------------------------------------------------------- /// @brief Trigger FSM update cycle (recursively call 'update()' on all active states, then process requested transitions) - void update(); + void update() noexcept; /// @brief Have FSM react to an event (recursively call matching 'react<>()' on all active states, then process requested transitions) /// @tparam TEvent Event type /// @param event Event to react to template - HFSM2_INLINE void react (const TEvent& event); + HFSM2_INLINE void react(const TEvent& event) noexcept; //---------------------------------------------------------------------- /// @brief Check if a state is active /// @param stateId Destination state identifier /// @return State active status - HFSM2_INLINE bool isActive (const StateID stateId) const { return _registry.isActive (stateId); } + HFSM2_INLINE bool isActive (const StateID stateId) const noexcept { return _registry.isActive (stateId); } /// @brief Check if a state is active /// @tparam TState Destination state type /// @return State active status template - HFSM2_INLINE bool isActive () const { return isActive (stateId()); } + HFSM2_INLINE bool isActive () const noexcept { return isActive (stateId()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /// @brief Check if a state is resumable (activated then deactivated previously) /// @param stateId Destination state identifier /// @return State resumable status - HFSM2_INLINE bool isResumable(const StateID stateId) const { return _registry.isResumable(stateId); } + HFSM2_INLINE bool isResumable (const StateID stateId) const noexcept { return _registry.isResumable(stateId); } /// @brief Check if a state is resumable (activated then deactivated previously) /// @tparam TState Destination state type /// @return State resumable status template - HFSM2_INLINE bool isResumable() const { return isResumable(stateId()); } + HFSM2_INLINE bool isResumable () const noexcept { return isResumable(stateId()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /// @brief Check if a state is scheduled to activate on the next transition to parent region /// @param stateId Destination state identifier /// @return State scheduled status - HFSM2_INLINE bool isScheduled(const StateID stateId) const { return isResumable(stateId); } + HFSM2_INLINE bool isScheduled (const StateID stateId) const noexcept { return isResumable(stateId); } /// @brief Check if a state is scheduled to activate on the next transition to parent region /// @tparam TState Destination state type /// @return State scheduled status template - HFSM2_INLINE bool isScheduled() const { return isResumable(); } + HFSM2_INLINE bool isScheduled () const noexcept { return isResumable(); } //------------------------------------------------------------------------------ + // COMMON /// @brief Transition into a state (if transitioning into a region, acts depending on the region type) /// @param stateId Destination state identifier - HFSM2_INLINE void changeTo (const StateID stateId); + HFSM2_INLINE void changeTo (const StateID stateId) noexcept; /// @brief Transition into a state (if transitioning into a region, acts depending on the region type) /// @tparam TState Destination state type template - HFSM2_INLINE void changeTo () { changeTo (stateId()); } + HFSM2_INLINE void changeTo () noexcept { changeTo (stateId()); } + // COMMON // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /// @brief Transition into a state (if transitioning into a region, activates the initial state) /// @param stateId Destination state identifier - HFSM2_INLINE void restart (const StateID stateId); + HFSM2_INLINE void restart (const StateID stateId) noexcept; /// @brief Transition into a state (if transitioning into a region, activates the initial state) /// @tparam TState Destination state type template - HFSM2_INLINE void restart () { restart (stateId()); } + HFSM2_INLINE void restart () noexcept { restart (stateId()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /// @brief Transition into a state (if transitioning into a region, activates the state that was active previously) /// @param stateId Destination state identifier - HFSM2_INLINE void resume (const StateID stateId); + HFSM2_INLINE void resume (const StateID stateId) noexcept; /// @brief Transition into a state (if transitioning into a region, activates the state that was active previously) /// @tparam TState Destination state type template - HFSM2_INLINE void resume () { resume (stateId()); } + HFSM2_INLINE void resume () noexcept { resume (stateId()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -265,14 +279,14 @@ class R_ { /// with the highest 'utility()' among those with the highest 'rank()') /// @param stateId Destination state identifier /// @see HFSM2_ENABLE_UTILITY_THEORY - HFSM2_INLINE void utilize (const StateID stateId); + HFSM2_INLINE void utilize (const StateID stateId) noexcept; /// @brief Transition into a state (if transitioning into a region, activates the state /// with the highest 'utility()' among those with the highest 'rank()') /// @tparam TState Destination state type /// @see HFSM2_ENABLE_UTILITY_THEORY template - HFSM2_INLINE void utilize () { utilize (stateId()); } + HFSM2_INLINE void utilize () noexcept { utilize (stateId()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -280,14 +294,14 @@ class R_ { /// proportional to 'utility()' among those with the highest 'rank()') /// @param stateId Destination state identifier /// @see HFSM2_ENABLE_UTILITY_THEORY - HFSM2_INLINE void randomize (const StateID stateId); + HFSM2_INLINE void randomize (const StateID stateId) noexcept; /// @brief Transition into a state (if transitioning into a region, uses weighted random to activate the state /// proportional to 'utility()' among those with the highest 'rank()') /// @tparam TState Destination state type /// @see HFSM2_ENABLE_UTILITY_THEORY template - HFSM2_INLINE void randomize () { randomize(stateId()); } + HFSM2_INLINE void randomize () noexcept { randomize(stateId()); } #endif @@ -295,56 +309,56 @@ class R_ { /// @brief Schedule a state to be activated when its parent region is activated /// @param stateId Destination state identifier - HFSM2_INLINE void schedule (const StateID stateId); + HFSM2_INLINE void schedule (const StateID stateId) noexcept; /// @brief Schedule a state to be activated when its parent region is activated /// @tparam TState Destination state type template - HFSM2_INLINE void schedule () { schedule (stateId()); } + HFSM2_INLINE void schedule () noexcept { schedule (stateId()); } //------------------------------------------------------------------------------ /// @brief Check if a state is going to be activated or deactivated /// @param stateId Destination state identifier /// @return State pending activation/deactivation status - HFSM2_INLINE bool isPendingChange(const StateID stateId) const { return _registry.isPendingChange(stateId); } + HFSM2_INLINE bool isPendingChange(const StateID stateId) const noexcept { return _registry.isPendingChange(stateId); } /// @brief Check if a state is going to be activated or deactivated /// @tparam TState Destination state type /// @return State pending activation/deactivation status template - HFSM2_INLINE bool isPendingChange() { return isPendingChange(stateId()); } + HFSM2_INLINE bool isPendingChange() noexcept { return isPendingChange(stateId()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /// @brief Check if a state is going to be activated /// @param stateId Destination state identifier /// @return State pending activation status - HFSM2_INLINE bool isPendingEnter (const StateID stateId) const { return _registry.isPendingEnter (stateId); } + HFSM2_INLINE bool isPendingEnter (const StateID stateId) const noexcept { return _registry.isPendingEnter (stateId); } /// @brief Check if a state is going to be activated /// @tparam TState Destination state type /// @return State pending activation status template - HFSM2_INLINE bool isPendingEnter () { return isPendingEnter (stateId()); } + HFSM2_INLINE bool isPendingEnter () noexcept { return isPendingEnter (stateId()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /// @brief Check if a state is going to be deactivated /// @param stateId Destination state identifier /// @return State pending deactivation status - HFSM2_INLINE bool isPendingExit (const StateID stateId) const { return _registry.isPendingExit (stateId); } + HFSM2_INLINE bool isPendingExit (const StateID stateId) const noexcept { return _registry.isPendingExit (stateId); } /// @brief Check if a state is going to be deactivated /// @tparam TState Destination state type /// @return State pending deactivation status template - HFSM2_INLINE bool isPendingExit () { return isPendingExit (stateId()); } + HFSM2_INLINE bool isPendingExit () noexcept { return isPendingExit (stateId()); } //------------------------------------------------------------------------------ /// @brief Reset FSM to initial state (recursively 'exit()' currently active states, 'enter()' initial states) - void reset(); + void reset() noexcept; //------------------------------------------------------------------------------ @@ -358,12 +372,12 @@ class R_ { /// @brief Serialize FSM into 'buffer' /// @param buffer 'SerialBuffer' to serialize to /// @see HFSM2_ENABLE_SERIALIZATION - void save( SerialBuffer& buffer) const; + void save( SerialBuffer& buffer) const noexcept; /// @brief De-serialize FSM from 'buffer' /// @param buffer 'SerialBuffer' to de-serialize from /// @see HFSM2_ENABLE_SERIALIZATION - void load(const SerialBuffer& buffer); + void load(const SerialBuffer& buffer) noexcept; #endif @@ -374,7 +388,7 @@ class R_ { /// @brief Get the list of transitions recorded during last 'update()' /// @return Array of last recorded transitions /// @see HFSM2_ENABLE_TRANSITION_HISTORY - const TransitionSets& previousTransitions() const { return _previousTransitions; } + const TransitionSets& previousTransitions() const noexcept { return _previousTransitions; } /// @brief Force process transitions (skips 'guard()' calls) /// Can be used to synchronize multiple FSMs @@ -382,7 +396,8 @@ class R_ { /// @param count Number of transitions /// @return Success status /// @see HFSM2_ENABLE_TRANSITION_HISTORY - bool replayTransitions(const Transition* const transitions, const uint64_t count); + bool replayTransitions(const Transition* const transitions, + const uint64_t count) noexcept; /// @brief Force process transitions (skips 'guard()' calls) /// Can be used to synchronize multiple FSMs @@ -390,27 +405,28 @@ class R_ { /// @return Success status /// @see HFSM2_ENABLE_TRANSITION_HISTORY template - bool replayTransitions(const Array& transitions); + bool replayTransitions(const ArrayT& transitions) noexcept; /// @brief Force process a transition (skips 'guard()' calls) /// Can be used to synchronize multiple FSMs /// @param transition 'Transition' to replay /// @return Success status /// @see HFSM2_ENABLE_TRANSITION_HISTORY - bool replayTransition (const Transition& transition) { return replayTransitions(&transition, 1); } + bool replayTransition (const Transition& transition) noexcept { return replayTransitions(&transition, 1); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /// @brief Get the last transition that caused the state to be activated /// @param stateId State identifier /// @return Pointer to the last transition that activated the state - const Transition* lastTransition(const StateID stateId) const; + const Transition* lastTransition(const StateID stateId) const noexcept; /// @brief Get the last transition that caused the state to be activated /// @tparam TState State type /// @return Pointer to the last transition that activated the state template - const Transition* lastTransition() const { return lastTransition(stateId()); } + const Transition* lastTransition() const noexcept { return lastTransition(stateId()); } #endif @@ -420,21 +436,21 @@ class R_ { /// @brief Array of 'StructureEntry' representing FSM structure /// @see HFSM2_ENABLE_STRUCTURE_REPORT - using Structure = Array; + using Structure = ArrayT; /// @brief Array of 'char' representing FSM activation history (negative - 'update()' cycles since deactivated, positive - 'update()' cycles since activated) /// @see HFSM2_ENABLE_STRUCTURE_REPORT - using ActivityHistory = Array; + using ActivityHistory = ArrayT; /// @brief Get the array of 'StructureEntry' representing FSM structure /// @return FSM structure /// @see HFSM2_ENABLE_STRUCTURE_REPORT - const Structure& structure() const { return _structure; } + const Structure& structure() const noexcept { return _structure; } /// @brief Get the array of 'char' representing FSM activation history (negative - 'update()' cycles since deactivated, positive - 'update()' cycles since activated) /// @return FSM activation history /// @see HFSM2_ENABLE_STRUCTURE_REPORT - const ActivityHistory& activityHistory() const { return _activityHistory; } + const ActivityHistory& activityHistory() const noexcept { return _activityHistory; } #endif @@ -445,37 +461,37 @@ class R_ { /// @brief Attach logger /// @param logger A logger implementing 'hfsm2::LoggerInterfaceT<>' interface /// @see HFSM2_ENABLE_LOG_INTERFACE - void attachLogger(Logger* const logger) { _logger = logger; } + HFSM2_INLINE void attachLogger(Logger* const logger) noexcept { _logger = logger; } #endif //---------------------------------------------------------------------- private: - void initialEnter(); - void processTransitions(TransitionSets& currentTransitions); + void initialEnter() noexcept; + void processTransitions(TransitionSets& currentTransitions) noexcept; - bool applyRequest (Control& control, const Transition& request, const Short index); - bool applyRequests(Control& control); + bool applyRequest (Control& control, const Transition& request, const Short index) noexcept; + bool applyRequests(Control& control) noexcept; bool cancelledByEntryGuards(const TransitionSets& currentTransitions, - const TransitionSet& pendingTransitions); + const TransitionSet& pendingTransitions) noexcept; bool cancelledByGuards(const TransitionSets& currentTransitions, - const TransitionSet& pendingTransitions); + const TransitionSet& pendingTransitions) noexcept; #ifdef HFSM2_ENABLE_TRANSITION_HISTORY bool applyRequests(Control& control, const Transition* const transitions, - const uint64_t count); + const uint64_t count) noexcept; TransitionTargets _transitionTargets; TransitionSets _previousTransitions; #endif #ifdef HFSM2_ENABLE_STRUCTURE_REPORT - void getStateNames(); - void udpateActivity(); + void getStateNames() noexcept; + void udpateActivity() noexcept; Prefixes _prefixes; StructureStateInfos _stateInfos; @@ -485,7 +501,7 @@ class R_ { #endif protected: - Context& _context; + Context _context; HFSM2_IF_UTILITY_THEORY(RNG& _rng); Registry _registry; @@ -524,78 +540,83 @@ class RP_ , TApex>; - using Payload = TPayload; - using Transition = TransitionT; + using Transition = TransitionT; public: - using Base::Base; + using Payload = typename Base::Payload; - using Base::stateId; - using Base::regionId; +#ifdef HFSM2_ENABLE_UTILITY_THEORY + using RNG = typename Base::RNG; +#endif + +public: + using Base::Base; /// @brief Get state identifier for a state type /// @tparam TState State type /// @return Numeric state identifier template - static constexpr StateID stateId() { return Base::template stateId(); } + static constexpr StateID stateId() noexcept { return Base::template stateId(); } /// @brief Get region identifier for a region type /// @tparam TState Region head state type /// @return Numeric region identifier template - static constexpr RegionID regionId() { return Base::template regionId(); } + static constexpr RegionID regionId() noexcept { return Base::template regionId(); } //------------------------------------------------------------------------------ + // COMMON /// @brief Transition into a state (if transitioning into a region, acts depending on the region type) /// @param stateId Destination state identifier /// @param payload Payload HFSM2_INLINE void changeWith (const StateID stateId, - const Payload& payload); + const Payload& payload) noexcept; /// @brief Transition into a state (if transitioning into a region, acts depending on the region type) /// @param stateId Destination state identifier /// @param payload Payload HFSM2_INLINE void changeWith (const StateID stateId, - Payload&& payload); + Payload&& payload) noexcept; /// @brief Transition into a state (if transitioning into a region, acts depending on the region type) /// @tparam TState Destination state type /// @param payload Payload template - HFSM2_INLINE void changeWith (const Payload& payload) { changeWith (stateId(), payload ); } + HFSM2_INLINE void changeWith (const Payload& payload) noexcept { changeWith (stateId(), payload ); } /// @brief Transition into a state (if transitioning into a region, acts depending on the region type) /// @tparam TState Destination state type /// @param payload Payload template - HFSM2_INLINE void changeWith ( Payload&& payload) { changeWith (stateId(), std::move(payload)); } + HFSM2_INLINE void changeWith ( Payload&& payload) noexcept { changeWith (stateId(), std::move(payload)); } + // COMMON // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /// @brief Transition into a state (if transitioning into a region, activates the initial state) /// @param stateId Destination state identifier /// @param payload Payload HFSM2_INLINE void restartWith (const StateID stateId, - const Payload& payload); + const Payload& payload) noexcept; /// @brief Transition into a state (if transitioning into a region, activates the initial state) /// @param stateId Destination state identifier /// @param payload Payload HFSM2_INLINE void restartWith (const StateID stateId, - Payload&& payload); + Payload&& payload) noexcept; /// @brief Transition into a state (if transitioning into a region, activates the initial state) /// @tparam TState Destination state type /// @param payload Payload template - HFSM2_INLINE void restartWith (const Payload& payload) { restartWith (stateId(), payload ); } + HFSM2_INLINE void restartWith (const Payload& payload) noexcept { restartWith (stateId(), payload ); } /// @brief Transition into a state (if transitioning into a region, activates the initial state) /// @tparam TState Destination state type /// @param payload Payload template - HFSM2_INLINE void restartWith ( Payload&& payload) { restartWith (stateId(), std::move(payload)); } + HFSM2_INLINE void restartWith ( Payload&& payload) noexcept { restartWith (stateId(), std::move(payload)); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -603,25 +624,25 @@ class RP_ - HFSM2_INLINE void resumeWith (const Payload& payload) { resumeWith (stateId(), payload ); } + HFSM2_INLINE void resumeWith (const Payload& payload) noexcept { resumeWith (stateId(), payload ); } /// @brief Transition into a state (if transitioning into a region, activates the state that was active previously) /// @tparam TState Destination state type /// @param payload Payload template - HFSM2_INLINE void resumeWith ( Payload&& payload) { resumeWith (stateId(), std::move(payload)); } + HFSM2_INLINE void resumeWith ( Payload&& payload) noexcept { resumeWith (stateId(), std::move(payload)); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -633,7 +654,7 @@ class RP_ - HFSM2_INLINE void utilizeWith (const Payload& payload) { utilizeWith (stateId(), payload ); } + HFSM2_INLINE void utilizeWith (const Payload& payload) noexcept { utilizeWith (stateId(), payload ); } /// @brief Transition into a state (if transitioning into a region, activates the state /// with the highest 'utility()' among those with the highest 'rank()') @@ -657,7 +678,7 @@ class RP_ - HFSM2_INLINE void utilizeWith ( Payload&& payload) { utilizeWith (stateId(), std::move(payload)); } + HFSM2_INLINE void utilizeWith ( Payload&& payload) noexcept { utilizeWith (stateId(), std::move(payload)); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -667,7 +688,7 @@ class RP_ - HFSM2_INLINE void randomizeWith(const Payload& payload) { randomizeWith(stateId(), payload ); } + HFSM2_INLINE void randomizeWith(const Payload& payload) noexcept { randomizeWith(stateId(), payload ); } /// @brief Transition into a state (if transitioning into a region, uses weighted random to activate the state /// proportional to 'utility()' among those with the highest 'rank()') @@ -691,7 +712,7 @@ class RP_ - HFSM2_INLINE void randomizeWith( Payload&& payload) { randomizeWith(stateId(), std::move(payload)); } + HFSM2_INLINE void randomizeWith( Payload&& payload) noexcept { randomizeWith(stateId(), std::move(payload)); } #endif @@ -701,36 +722,38 @@ class RP_ - HFSM2_INLINE void scheduleWith (const Payload& payload) { scheduleWith (stateId(), payload ); } + HFSM2_INLINE void scheduleWith (const Payload& payload) noexcept { scheduleWith (stateId(), payload ); } /// @brief Schedule a state to be activated when its parent region is activated /// @tparam TState Destination state type /// @param payload Payload template - HFSM2_INLINE void scheduleWith ( Payload&& payload) { scheduleWith (stateId(), std::move(payload)); } + HFSM2_INLINE void scheduleWith ( Payload&& payload) noexcept { scheduleWith (stateId(), std::move(payload)); } //------------------------------------------------------------------------------ -private: +protected: using Base::_context; + +private: using Base::_requests; HFSM2_IF_LOG_INTERFACE(using Base::_logger); }; -//------------------------------------------------------------------------------ +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - template , TApex>; +public: +#ifdef HFSM2_ENABLE_UTILITY_THEORY + using RNG = typename Base::RNG; +#endif + public: using Base::Base; }; //////////////////////////////////////////////////////////////////////////////// -/// @brief FSM Root -/// @tparam Cfg Type configuration -/// @tparam TApex Root region type -template -class RW_ final - : public RP_ +template +class RC_; + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +// TContext + +template +class RC_ , TApex> + : public RP_, TApex> { - using Base = RP_; + using Base = RP_, TApex>; public: - using Base::Base; + static constexpr FeatureTag FEATURE_TAG = Base::FEATURE_TAG; + + using Context = TContext; + using Payload = typename Base::Payload; + +#ifdef HFSM2_ENABLE_UTILITY_THEORY + using RNG = typename Base::RNG; +#endif + +#ifdef HFSM2_ENABLE_LOG_INTERFACE + using Logger = typename Base::Logger; +#endif + +public: + HFSM2_INLINE explicit RC_(Context& context + HFSM2_IF_UTILITY_THEORY(, RNG& rng) + HFSM2_IF_LOG_INTERFACE(, Logger* const logger = nullptr)) noexcept + : Base{context + HFSM2_IF_UTILITY_THEORY(, rng) + HFSM2_IF_LOG_INTERFACE(, logger)} + {} + + HFSM2_INLINE void setContext(const Context& context) noexcept { _context = context ; } + HFSM2_INLINE void setContext( Context&& context) noexcept { _context = std::move(context); } + +private: + using Base::_context; }; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// TContext == ::hfsm2::EmptyContext +// TContext& + +template +class RC_ , TApex> + : public RP_, TApex> +{ + using Base = RP_, TApex>; + +public: + static constexpr FeatureTag FEATURE_TAG = Base::FEATURE_TAG; + + using Context = typename Base::Context; + using Payload = typename Base::Payload; #ifdef HFSM2_ENABLE_UTILITY_THEORY - typename TRank, - typename TUtility, - typename TRNG, + using RNG = typename Base::RNG; #endif - Long NSubstitutionLimit, - HFSM2_IF_PLANS(Long NTaskCapacity,) - typename TPayload, - typename TApex> -class RW_ <::hfsm2::ConfigT<::hfsm2::EmptyContext HFSM2_IF_UTILITY_THEORY(, TRank, TUtility, TRNG), NSubstitutionLimit HFSM2_IF_PLANS(, NTaskCapacity), TPayload>, TApex> final - : public RP_<::hfsm2::ConfigT<::hfsm2::EmptyContext HFSM2_IF_UTILITY_THEORY(, TRank, TUtility, TRNG), NSubstitutionLimit HFSM2_IF_PLANS(, NTaskCapacity), TPayload>, TApex> - , ::hfsm2::EmptyContext + +#ifdef HFSM2_ENABLE_LOG_INTERFACE + using Logger = typename Base::Logger; +#endif + +public: + HFSM2_INLINE explicit RC_(Context context + HFSM2_IF_UTILITY_THEORY(, RNG& rng) + HFSM2_IF_LOG_INTERFACE(, Logger* const logger = nullptr)) noexcept + : Base{context + HFSM2_IF_UTILITY_THEORY(, rng) + HFSM2_IF_LOG_INTERFACE(, logger)} + {} + + HFSM2_INLINE void setContext(Context context) noexcept { _context = context; } + +private: + using Base::_context; +}; + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +// TContext* + +template +class RC_ , TApex> + : public RP_, TApex> { - using Cfg = ::hfsm2::ConfigT<::hfsm2::EmptyContext HFSM2_IF_UTILITY_THEORY(, TRank, TUtility, TRNG), NSubstitutionLimit HFSM2_IF_PLANS(, NTaskCapacity), TPayload>; + using Base = RP_, TApex>; +public: + static constexpr FeatureTag FEATURE_TAG = Base::FEATURE_TAG; + + using Context = typename Base::Context; + using Payload = typename Base::Payload; + +#ifdef HFSM2_ENABLE_UTILITY_THEORY + using RNG = typename Base::RNG; +#endif + +#ifdef HFSM2_ENABLE_LOG_INTERFACE + using Logger = typename Base::Logger; +#endif + +public: #ifdef HFSM2_ENABLE_UTILITY_THEORY - using RNG = TRNG; + + HFSM2_INLINE explicit RC_(Context context + , RNG& rng + HFSM2_IF_LOG_INTERFACE(, Logger* const logger = nullptr)) noexcept + : Base{context + , rng + HFSM2_IF_LOG_INTERFACE(, logger)} + {} + +#else + + HFSM2_INLINE explicit RC_(Context context = nullptr + HFSM2_IF_LOG_INTERFACE(, Logger* const logger = nullptr)) noexcept + : Base{context + HFSM2_IF_LOG_INTERFACE(, logger)} + {} + #endif - using Context = typename Cfg::Context; - using Base = RP_; + HFSM2_INLINE void setContext(Context context) noexcept { _context = context; } + +private: + using Base::_context; +}; + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +// TContext == EmptyContext + +template +class RC_ , TApex> + : public RP_, TApex> + , public EmptyContext +{ + using Base = RP_, TApex>; + +public: + static constexpr FeatureTag FEATURE_TAG = Base::FEATURE_TAG; + + using Context = typename Base::Context; + using Payload = typename Base::Payload; + +#ifdef HFSM2_ENABLE_UTILITY_THEORY + using RNG = typename Base::RNG; +#endif #ifdef HFSM2_ENABLE_LOG_INTERFACE - using Logger = typename Cfg::LoggerInterface; + using Logger = typename Base::Logger; #endif public: + #ifdef HFSM2_ENABLE_UTILITY_THEORY - explicit HFSM2_INLINE RW_(RNG& rng - HFSM2_IF_LOG_INTERFACE(, Logger* const logger = nullptr)) + HFSM2_INLINE explicit RC_(RNG& rng + HFSM2_IF_LOG_INTERFACE(, Logger* const logger = nullptr)) noexcept : Base{static_cast(*this) , rng HFSM2_IF_LOG_INTERFACE(, logger)} @@ -812,7 +997,7 @@ class RW_ <::hfsm2::ConfigT<::hfsm2::EmptyContext HFSM2_IF_UTILITY_THEORY(, TRa #else - explicit HFSM2_INLINE RW_(HFSM2_IF_LOG_INTERFACE( Logger* const logger = nullptr)) + HFSM2_INLINE explicit RC_(HFSM2_IF_LOG_INTERFACE(Logger* const logger = nullptr)) noexcept : Base{static_cast(*this) HFSM2_IF_LOG_INTERFACE(, logger)} {} @@ -820,43 +1005,67 @@ class RW_ <::hfsm2::ConfigT<::hfsm2::EmptyContext HFSM2_IF_UTILITY_THEORY(, TRa #endif }; +//////////////////////////////////////////////////////////////////////////////// + +/// @brief FSM Root +/// @tparam Cfg Type configuration +/// @tparam TApex Root region type +template +class RR_ final + : public RC_ +{ + using Base = RC_; + +public: + using Base::Base; +}; + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// TRNG == ::hfsm2::RandomT +// TRNG == RNGT -template -class RW_ <::hfsm2::ConfigT), NSubstitutionLimit HFSM2_IF_PLANS(, NTaskCapacity), TPayload>, TApex> final - : public RP_<::hfsm2::ConfigT), NSubstitutionLimit HFSM2_IF_PLANS(, NTaskCapacity), TPayload>, TApex> - HFSM2_IF_UTILITY_THEORY(, ::hfsm2::RandomT) + , Long NSubstitutionLimit + HFSM2_IF_PLANS(, Long NTaskCapacity) + , typename TPayload + , typename TApex> +class RR_ ), NSubstitutionLimit HFSM2_IF_PLANS(, NTaskCapacity), TPayload>, TApex> final + : public RC_), NSubstitutionLimit HFSM2_IF_PLANS(, NTaskCapacity), TPayload>, TApex> + HFSM2_IF_UTILITY_THEORY(, public RNGT) { - using Cfg = ::hfsm2::ConfigT), NSubstitutionLimit HFSM2_IF_PLANS(, NTaskCapacity), TPayload>; + using Base = RC_), NSubstitutionLimit HFSM2_IF_PLANS(, NTaskCapacity), TPayload>, TApex>; + +public: + static constexpr FeatureTag FEATURE_TAG = Base::FEATURE_TAG; + + using Context = typename Base::Context; + using Payload = typename Base::Payload; #ifdef HFSM2_ENABLE_UTILITY_THEORY - using RNG = ::hfsm2::RandomT; + using RNG = typename Base::RNG; #endif - using Context = typename Cfg::Context; - using Base = RP_; - #ifdef HFSM2_ENABLE_LOG_INTERFACE - using Logger = typename Cfg::LoggerInterface; + using Logger = typename Base::Logger; #endif - public: #ifdef HFSM2_ENABLE_UTILITY_THEORY - explicit HFSM2_INLINE RW_(Context& context - HFSM2_IF_LOG_INTERFACE(, Logger* const logger = nullptr)) + HFSM2_INLINE explicit RR_(Context& context + HFSM2_IF_LOG_INTERFACE(, Logger* const logger = nullptr)) noexcept : Base{context , static_cast(*this) HFSM2_IF_LOG_INTERFACE(, logger)} @@ -865,8 +1074,8 @@ class RW_ <::hfsm2::ConfigT +// TContext == EmptyContext +// TRNG == RNGT -#ifdef HFSM2_ENABLE_UTILITY_THEORY - -template -class RW_ <::hfsm2::ConfigT<::hfsm2::EmptyContext, TRank, TUtility, ::hfsm2::RandomT, NSubstitutionLimit HFSM2_IF_PLANS(, NTaskCapacity), TPayload>, TApex> final - : public RP_<::hfsm2::ConfigT<::hfsm2::EmptyContext, TRank, TUtility, ::hfsm2::RandomT, NSubstitutionLimit HFSM2_IF_PLANS(, NTaskCapacity), TPayload>, TApex> - , ::hfsm2::EmptyContext - , ::hfsm2::RandomT +/// @brief FSM Root +/// @tparam Cfg Type configuration +/// @tparam TApex Root region type +template +class RR_ , NSubstitutionLimit HFSM2_IF_PLANS(, NTaskCapacity), TPayload>, TApex> final + : public RC_, NSubstitutionLimit HFSM2_IF_PLANS(, NTaskCapacity), TPayload>, TApex> + , public RNGT { - using Cfg = ::hfsm2::ConfigT<::hfsm2::EmptyContext, TRank, TUtility, ::hfsm2::RandomT, NSubstitutionLimit HFSM2_IF_PLANS(, NTaskCapacity), TPayload>; + using Base = RC_, NSubstitutionLimit HFSM2_IF_PLANS(, NTaskCapacity), TPayload>, TApex>; + +public: + static constexpr FeatureTag FEATURE_TAG = Base::FEATURE_TAG; - using Context = typename Cfg::Context; - using RNG = typename Cfg::RNG; - using Base = RP_; + using Context = typename Base::Context; + using Payload = typename Base::Payload; + using RNG = typename Base::RNG; #ifdef HFSM2_ENABLE_LOG_INTERFACE - using Logger = typename Cfg::LoggerInterface; + using Logger = typename Base::Logger; #endif public: - explicit HFSM2_INLINE RW_(HFSM2_IF_LOG_INTERFACE(Logger* const logger = nullptr)) - : Base{static_cast(*this) - , static_cast(*this) + HFSM2_INLINE explicit RR_(HFSM2_IF_LOG_INTERFACE(Logger* const logger = nullptr)) noexcept + : Base{static_cast(*this) HFSM2_IF_LOG_INTERFACE(, logger)} , RNG{0} {} diff --git a/include/hfsm2/detail/root.inl b/include/hfsm2/detail/root.inl index 1c0b48b..afe4bad 100644 --- a/include/hfsm2/detail/root.inl +++ b/include/hfsm2/detail/root.inl @@ -6,7 +6,7 @@ namespace detail { template R_::R_(Context& context HFSM2_IF_UTILITY_THEORY(, RNG& rng) - HFSM2_IF_LOG_INTERFACE(, Logger* const logger)) + HFSM2_IF_LOG_INTERFACE(, Logger* const logger)) noexcept : _context{context} HFSM2_IF_UTILITY_THEORY(, _rng{rng}) HFSM2_IF_LOG_INTERFACE(, _logger{logger}) @@ -21,7 +21,7 @@ R_::R_(Context& context // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - template -R_::~R_() { +R_::~R_() noexcept { PlanControl control{_context , _registry , _requests @@ -41,7 +41,7 @@ R_::~R_() { template void -R_::update() { +R_::update() noexcept { FullControl control{_context , _registry , _requests @@ -69,7 +69,7 @@ R_::update() { template template void -R_::react(const TEvent& event) { +R_::react(const TEvent& event) noexcept { FullControl control{_context , _registry , _requests @@ -96,7 +96,7 @@ R_::react(const TEvent& event) { template void -R_::changeTo(const StateID stateId) { +R_::changeTo(const StateID stateId) noexcept { _requests.append(Transition{stateId, TransitionType::CHANGE}); HFSM2_LOG_TRANSITION(_context, INVALID_STATE_ID, TransitionType::CHANGE, stateId); @@ -106,7 +106,7 @@ R_::changeTo(const StateID stateId) { template void -R_::restart(const StateID stateId) { +R_::restart(const StateID stateId) noexcept { _requests.append(Transition{stateId, TransitionType::RESTART}); HFSM2_LOG_TRANSITION(_context, INVALID_STATE_ID, TransitionType::RESTART, stateId); @@ -116,7 +116,7 @@ R_::restart(const StateID stateId) { template void -R_::resume(const StateID stateId) { +R_::resume(const StateID stateId) noexcept { _requests.append(Transition{stateId, TransitionType::RESUME}); HFSM2_LOG_TRANSITION(_context, INVALID_STATE_ID, TransitionType::RESUME, stateId); @@ -128,7 +128,7 @@ R_::resume(const StateID stateId) { template void -R_::utilize(const StateID stateId) { +R_::utilize(const StateID stateId) noexcept { _requests.append(Transition{stateId, TransitionType::UTILIZE}); HFSM2_LOG_TRANSITION(_context, INVALID_STATE_ID, TransitionType::UTILIZE, stateId); @@ -138,7 +138,7 @@ R_::utilize(const StateID stateId) { template void -R_::randomize(const StateID stateId) { +R_::randomize(const StateID stateId) noexcept { _requests.append(Transition{stateId, TransitionType::RANDOMIZE}); HFSM2_LOG_TRANSITION(_context, INVALID_STATE_ID, TransitionType::RANDOMIZE, stateId); @@ -150,7 +150,7 @@ R_::randomize(const StateID stateId) { template void -R_::schedule(const StateID stateId) { +R_::schedule(const StateID stateId) noexcept { _requests.append(Transition{stateId, TransitionType::SCHEDULE}); HFSM2_LOG_TRANSITION(_context, INVALID_STATE_ID, TransitionType::SCHEDULE, stateId); @@ -160,7 +160,7 @@ R_::schedule(const StateID stateId) { template void -R_::reset() { +R_::reset() noexcept { PlanControl control{_context , _registry , _requests @@ -193,7 +193,7 @@ R_::reset() { template void -R_::save(SerialBuffer& _buffer) const { +R_::save(SerialBuffer& _buffer) const noexcept { WriteStream stream{_buffer}; // TODO: save _registry @@ -210,7 +210,7 @@ R_::save(SerialBuffer& _buffer) const { template void -R_::load(const SerialBuffer& buffer) { +R_::load(const SerialBuffer& buffer) noexcept { _requests.clear(); PlanControl control{_context @@ -255,7 +255,7 @@ R_::load(const SerialBuffer& buffer) { template bool R_::replayTransitions(const Transition* const transitions, - const uint64_t count) + const uint64_t count) noexcept { HFSM2_IF_TRANSITION_HISTORY(_transitionTargets.clear()); HFSM2_IF_TRANSITION_HISTORY(_previousTransitions.clear()); @@ -295,7 +295,7 @@ R_::replayTransitions(const Transition* const transitions, template template bool -R_::replayTransitions(const Array& transitions) { +R_::replayTransitions(const ArrayT& transitions) noexcept { if (transitions.count()) return replayTransitions(&transitions[0], transitions.count()); @@ -307,7 +307,7 @@ R_::replayTransitions(const Array& transitions) { template const typename R_::Transition* -R_::lastTransition(const StateID stateId) const { +R_::lastTransition(const StateID stateId) const noexcept { if (HFSM2_CHECKED(stateId < StateList::SIZE)) { const Short index = _transitionTargets[stateId]; @@ -324,7 +324,7 @@ R_::lastTransition(const StateID stateId) const { template void -R_::initialEnter() { +R_::initialEnter() noexcept { // TODO: //HFSM2_ASSERT(_registry.empty() == 0); HFSM2_ASSERT(_requests.count() == 0); @@ -389,7 +389,7 @@ R_::initialEnter() { template void -R_::processTransitions(TransitionSets& currentTransitions) { +R_::processTransitions(TransitionSets& currentTransitions) noexcept { HFSM2_ASSERT(_requests.count()); RegistryBackUp registryUndo; @@ -442,7 +442,7 @@ template bool R_::applyRequest(Control& control, const Transition& request, - const Short index) + const Short index) noexcept { switch (request.type) { case TransitionType::CHANGE: @@ -477,7 +477,7 @@ R_::applyRequest(Control& control, template bool -R_::applyRequests(Control& control) { +R_::applyRequests(Control& control) noexcept { bool changesMade = false; for (Short i = 0; i < _requests.count(); ++i) @@ -491,7 +491,7 @@ R_::applyRequests(Control& control) { template bool R_::cancelledByEntryGuards(const TransitionSets& currentTransitions, - const TransitionSet& pendingTransitions) + const TransitionSet& pendingTransitions) noexcept { GuardControl guardControl{_context , _registry @@ -512,7 +512,7 @@ R_::cancelledByEntryGuards(const TransitionSets& currentTransitions, template bool R_::cancelledByGuards(const TransitionSets& currentTransitions, - const TransitionSet& pendingTransitions) + const TransitionSet& pendingTransitions) noexcept { GuardControl guardControl{_context , _registry @@ -537,7 +537,7 @@ template bool R_::applyRequests(Control& control, const Transition* const transitions, - const uint64_t count) + const uint64_t count) noexcept { if (HFSM2_CHECKED(transitions && count)) { bool changesMade = false; @@ -558,7 +558,7 @@ R_::applyRequests(Control& control, template void -R_::getStateNames() { +R_::getStateNames() noexcept { _stateInfos.clear(); _apex.deepGetNames((Long) -1, StructureStateInfo::RegionType::COMPOSITE, 0, _stateInfos); @@ -636,7 +636,7 @@ R_::getStateNames() { template void -R_::udpateActivity() { +R_::udpateActivity() noexcept { for (Long s = 0, i = 0; s < _stateInfos.count(); ++s) if (_stateInfos[s].name[0] != L'\0') { _structure[i].isActive = isActive(s); @@ -666,7 +666,7 @@ R_::udpateActivity() { template void RP_, TA>::changeWith(const StateID stateId, - const Payload& payload) + const Payload& payload) noexcept { _requests.append(Transition{stateId, TransitionType::CHANGE, payload}); @@ -676,7 +676,7 @@ RP_ void RP_, TA>::changeWith(const StateID stateId, - Payload&& payload) + Payload&& payload) noexcept { _requests.append(Transition{stateId, TransitionType::CHANGE, std::move(payload)}); @@ -688,7 +688,7 @@ RP_ void RP_, TA>::restartWith(const StateID stateId, - const Payload& payload) + const Payload& payload) noexcept { _requests.append(Transition{stateId, TransitionType::RESTART, payload}); @@ -698,7 +698,7 @@ RP_ void RP_, TA>::restartWith(const StateID stateId, - Payload&& payload) + Payload&& payload) noexcept { _requests.append(Transition{stateId, TransitionType::RESTART, std::move(payload)}); @@ -710,7 +710,7 @@ RP_ void RP_, TA>::resumeWith(const StateID stateId, - const Payload& payload) + const Payload& payload) noexcept { _requests.append(Transition{stateId, TransitionType::RESUME, payload}); @@ -720,7 +720,7 @@ RP_ void RP_, TA>::resumeWith(const StateID stateId, - Payload&& payload) + Payload&& payload) noexcept { _requests.append(Transition{stateId, TransitionType::RESUME, std::move(payload)}); @@ -734,7 +734,7 @@ RP_ void RP_, TA>::utilizeWith(const StateID stateId, - const Payload& payload) + const Payload& payload) noexcept { _requests.append(Transition{stateId, TransitionType::UTILIZE, payload}); @@ -744,7 +744,7 @@ RP_ void RP_, TA>::utilizeWith(const StateID stateId, - Payload&& payload) + Payload&& payload) noexcept { _requests.append(Transition{stateId, TransitionType::UTILIZE, std::move(payload)}); @@ -756,7 +756,7 @@ RP_ void RP_, TA>::randomizeWith(const StateID stateId, - const Payload& payload) + const Payload& payload) noexcept { _requests.append(Transition{stateId, TransitionType::RANDOMIZE, payload}); @@ -766,7 +766,7 @@ RP_ void RP_, TA>::randomizeWith(const StateID stateId, - Payload&& payload) + Payload&& payload) noexcept { _requests.append(Transition{stateId, TransitionType::RANDOMIZE, std::move(payload)}); @@ -780,7 +780,7 @@ RP_ void RP_, TA>::scheduleWith(const StateID stateId, - const Payload& payload) + const Payload& payload) noexcept { _requests.append(Transition{stateId, TransitionType::SCHEDULE, payload}); @@ -790,7 +790,7 @@ RP_ void RP_, TA>::scheduleWith(const StateID stateId, - Payload&& payload) + Payload&& payload) noexcept { _requests.append(Transition{stateId, TransitionType::SCHEDULE, std::move(payload)}); diff --git a/include/hfsm2/detail/root/control.hpp b/include/hfsm2/detail/root/control.hpp index 9724f86..963f46b 100644 --- a/include/hfsm2/detail/root/control.hpp +++ b/include/hfsm2/detail/root/control.hpp @@ -27,11 +27,11 @@ class ControlT { using Payload = typename TArgs::Payload; using Transition = TransitionT; - using TransitionSet = Array; - using TransitionSets = Array; + using TransitionSet = ArrayT; + using TransitionSets = ArrayT; #ifdef HFSM2_ENABLE_TRANSITION_HISTORY - using TransitionTargets = StaticArray; + using TransitionTargets = StaticArrayT; #endif #ifdef HFSM2_ENABLE_UTILITY_THEORY @@ -40,7 +40,7 @@ class ControlT { #ifdef HFSM2_ENABLE_PLANS using PlanData = PlanDataT; - using ConstPlan = ConstPlanT; + using CPlan = CPlanT; #endif #ifdef HFSM2_ENABLE_LOG_INTERFACE @@ -51,9 +51,9 @@ class ControlT { struct Origin { HFSM2_INLINE Origin(ControlT& control_, - const StateID stateId); + const StateID stateId) noexcept; - HFSM2_INLINE ~Origin(); + HFSM2_INLINE ~Origin() noexcept; ControlT& control; const StateID prevId; @@ -63,9 +63,9 @@ class ControlT { struct Region { HFSM2_INLINE Region(ControlT& control, - const RegionID regionId); + const RegionID regionId) noexcept; - HFSM2_INLINE ~Region(); + HFSM2_INLINE ~Region() noexcept; ControlT& control; const RegionID prevId; @@ -80,7 +80,7 @@ class ControlT { HFSM2_IF_PLANS(, PlanData& planData) HFSM2_IF_TRANSITION_HISTORY(, TransitionTargets& transitionTargets) HFSM2_IF_TRANSITION_HISTORY(, const TransitionSets& previousTransitions) - HFSM2_IF_LOG_INTERFACE(, Logger* const logger)) + HFSM2_IF_LOG_INTERFACE(, Logger* const logger)) noexcept : _context{context} , _registry{registry} , _requests{requests} @@ -91,14 +91,14 @@ class ControlT { HFSM2_IF_LOG_INTERFACE(, _logger{logger}) {} - HFSM2_INLINE void setOrigin (const StateID stateId); - HFSM2_INLINE void resetOrigin(const StateID stateId); + HFSM2_INLINE void setOrigin (const StateID stateId) noexcept; + HFSM2_INLINE void resetOrigin(const StateID stateId) noexcept; - HFSM2_INLINE void setRegion (const RegionID regionId); - HFSM2_INLINE void resetRegion(const RegionID regionId); + HFSM2_INLINE void setRegion (const RegionID regionId) noexcept; + HFSM2_INLINE void resetRegion(const RegionID regionId) noexcept; #ifdef HFSM2_ENABLE_TRANSITION_HISTORY - HFSM2_INLINE void pinLastTransition(const StateID stateId, const Short index); + HFSM2_INLINE void pinLastTransition(const StateID stateId, const Short index) noexcept; #endif public: @@ -107,78 +107,78 @@ class ControlT { /// @tparam TState State type /// @return Numeric state identifier template - static constexpr StateID stateId() { return index(); } + static constexpr StateID stateId() noexcept { return index(); } /// @brief Get region identifier for a region type /// @tparam TState Region head state type /// @return Numeric region identifier template - static constexpr RegionID regionId() { return (RegionID) index(); } + static constexpr RegionID regionId() noexcept { return (RegionID) index(); } /// @brief Access FSM context (data shared between states and/or data interface between FSM and external code) /// @return context /// @see Control::context() - HFSM2_INLINE Context& _() { return _context; } + HFSM2_INLINE Context& _() noexcept { return _context; } /// @brief Access FSM context (data shared between states and/or data interface between FSM and external code) /// @return context /// @see Control::context() - HFSM2_INLINE const Context& _() const { return _context; } + HFSM2_INLINE const Context& _() const noexcept { return _context; } /// @brief Access FSM context (data shared between states and/or data interface between FSM and external code) /// @return context /// @see Control::_() - HFSM2_INLINE Context& context() { return _context; } + HFSM2_INLINE Context& context() noexcept { return _context; } /// @brief Access FSM context (data shared between states and/or data interface between FSM and external code) /// @return context /// @see Control::_() - HFSM2_INLINE const Context& context() const { return _context; } + HFSM2_INLINE const Context& context() const noexcept { return _context; } //---------------------------------------------------------------------- /// @brief Inspect current transition requests /// @return Array of transition requests - HFSM2_INLINE const TransitionSet& requests() const { return _requests; } + HFSM2_INLINE const TransitionSet& requests() const noexcept { return _requests; } //---------------------------------------------------------------------- /// @brief Check if a state is active /// @param stateId State identifier /// @return State active status - HFSM2_INLINE bool isActive (const StateID stateId) const { return _registry.isActive (stateId); } + HFSM2_INLINE bool isActive (const StateID stateId) const noexcept { return _registry.isActive (stateId); } /// @brief Check if a state is active /// @tparam TState State type /// @return State active status template - HFSM2_INLINE bool isActive () const { return isActive (stateId()); } + HFSM2_INLINE bool isActive () const noexcept { return isActive (stateId()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /// @brief Check if a state is resumable (activated then deactivated previously) /// @param stateId State identifier /// @return State resumable status - HFSM2_INLINE bool isResumable(const StateID stateId) const { return _registry.isResumable(stateId); } + HFSM2_INLINE bool isResumable(const StateID stateId) const noexcept { return _registry.isResumable(stateId); } /// @brief Check if a state is resumable (activated then deactivated previously) /// @tparam TState State type /// @return State resumable status template - HFSM2_INLINE bool isResumable() const { return isResumable(stateId()); } + HFSM2_INLINE bool isResumable() const noexcept { return isResumable(stateId()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /// @brief Check if a state is scheduled to activate on the next transition to parent region /// @param stateId State identifier /// @return State scheduled status - HFSM2_INLINE bool isScheduled(const StateID stateId) const { return isResumable(stateId); } + HFSM2_INLINE bool isScheduled(const StateID stateId) const noexcept { return isResumable(stateId); } /// @brief Check if a state is scheduled to activate on the next transition to parent region /// @tparam TState State type /// @return State scheduled status template - HFSM2_INLINE bool isScheduled() const { return isResumable(stateId()); } + HFSM2_INLINE bool isScheduled() const noexcept { return isResumable(stateId()); } //---------------------------------------------------------------------- @@ -186,24 +186,24 @@ class ControlT { /// @brief Access read-only plan for the current region /// @return Plan for the current region - HFSM2_INLINE ConstPlan plan() const { return ConstPlan{_planData, _regionId}; } + HFSM2_INLINE CPlan plan() const noexcept { return CPlan{_planData, _regionId}; } /// @brief Access read-only plan for a region /// @param regionId Region identifier /// @return Read-only plan for the region - HFSM2_INLINE ConstPlan plan(const RegionID regionId) const { return ConstPlan{_planData, regionId}; } + HFSM2_INLINE CPlan plan(const RegionID regionId) const noexcept { return CPlan{_planData, regionId}; } /// @brief Access read-only plan for a region /// @tparam TRegion Region head state type /// @return Read-only plan for the region template - HFSM2_INLINE ConstPlan plan() { return ConstPlan{_planData, regionId()}; } + HFSM2_INLINE CPlan plan() noexcept { return CPlan{_planData, regionId()}; } /// @brief Access read-only plan for a region /// @tparam TRegion Region head state type /// @return Read-only Plan for the region template - HFSM2_INLINE ConstPlan plan() const { return ConstPlan{_planData, regionId()}; } + HFSM2_INLINE CPlan plan() const noexcept { return CPlan{_planData, regionId()}; } #endif @@ -213,24 +213,24 @@ class ControlT { /// @brief Get transitions processed during last 'update()', 'react()' or 'replayTransitions()' /// @return Array of last transition requests - HFSM2_INLINE const TransitionSets& previousTransitions() const { return _previousTransitions; } + HFSM2_INLINE const TransitionSets& previousTransitions() const noexcept { return _previousTransitions; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /// @brief Get the last transition that caused the state to be activated /// @param stateId State identifier /// @return Pointer to the last transition that activated the state - const Transition* lastTransition(const StateID stateId) const; + const Transition* lastTransition(const StateID stateId) const noexcept; /// @brief Get the last transition that caused the state to be activated /// @tparam TState State type /// @return Pointer to the last transition that activated the state template - const Transition* lastTransition() const { return lastTransition(stateId()); } + const Transition* lastTransition() const noexcept { return lastTransition(stateId()); } /// @brief Get the last transition that caused the current state to be activated /// @return Pointer to the last transition that activated the current state - const Transition* lastTransition() const; + const Transition* lastTransition() const noexcept; #endif @@ -238,7 +238,7 @@ class ControlT { protected: #ifdef HFSM2_ENABLE_LOG_INTERFACE - HFSM2_INLINE Logger* logger() { return _logger; } + HFSM2_INLINE Logger* logger() noexcept { return _logger; } #endif protected: @@ -280,7 +280,7 @@ class PlanControlT #ifdef HFSM2_ENABLE_PLANS using typename Control::PlanData; - using typename Control::ConstPlan; + using typename Control::CPlan; using Plan = PlanT; #endif @@ -291,9 +291,9 @@ class PlanControlT HFSM2_INLINE Region(PlanControlT& control, const RegionID regionId, const StateID index, - const Long size); + const Long size) noexcept; - HFSM2_INLINE ~Region(); + HFSM2_INLINE ~Region() noexcept; PlanControlT& control; const RegionID prevId; @@ -305,43 +305,50 @@ class PlanControlT using Control::Control; - HFSM2_INLINE void setRegion (const RegionID regionId, const StateID index, const Long size); - HFSM2_INLINE void resetRegion(const RegionID regionId, const StateID index, const Long size); + HFSM2_INLINE void setRegion(const RegionID regionId, const StateID index, const Long size) noexcept; + HFSM2_INLINE void resetRegion(const RegionID regionId, const StateID index, const Long size) noexcept; public: // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #ifdef HFSM2_ENABLE_PLANS +// COMMON /// @brief Access plan for the current region /// @return Plan for the current region - HFSM2_INLINE Plan plan() { return Plan{_planData, _regionId}; } + HFSM2_INLINE Plan plan() noexcept { return Plan{_planData, _regionId}; } + +// COMMON /// @brief Access plan for a region /// @param regionId /// @return Plan for the region - HFSM2_INLINE Plan plan(const RegionID regionId) { return Plan{_planData, regionId}; } + HFSM2_INLINE Plan plan(const RegionID regionId) noexcept { return Plan{_planData, regionId}; } /// @brief Access plan for a region /// @tparam TRegion Region head state type /// @return Plan for the region template - HFSM2_INLINE Plan plan() { return Plan{_planData, Control::template regionId()}; } + HFSM2_INLINE Plan plan() noexcept { return Plan{_planData, Control::template regionId()}; } + +// COMMON /// @brief Access plan for the current region /// @return Plan for the current region - HFSM2_INLINE ConstPlan plan() const { return ConstPlan{_planData, _regionId}; } + HFSM2_INLINE CPlan plan() const noexcept { return CPlan{_planData, _regionId}; } + +// COMMON /// @brief Access plan for a region /// @param regionId /// @return Plan for the region - HFSM2_INLINE ConstPlan plan(const RegionID regionId) const { return ConstPlan{_planData, regionId}; } + HFSM2_INLINE CPlan plan(const RegionID regionId) const noexcept { return CPlan{_planData, regionId}; } /// @brief Access plan for a region /// @tparam TRegion Region head state type /// @return Plan for the region template - HFSM2_INLINE ConstPlan plan() const { return ConstPlan{_planData, Control::template regionId()}; } + HFSM2_INLINE CPlan plan() const noexcept { return CPlan{_planData, Control::template regionId()}; } #endif @@ -384,14 +391,14 @@ class FullControlBaseT using typename PlanControl::Transition; #ifdef HFSM2_ENABLE_PLANS - using TasksBits = BitArray; + using TasksBits = BitArrayT; #endif // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - struct Lock { - HFSM2_INLINE Lock(FullControlBaseT& control_); - HFSM2_INLINE ~Lock(); + HFSM2_INLINE Lock(FullControlBaseT& control_) noexcept; + HFSM2_INLINE ~Lock() noexcept; FullControlBaseT* const control; }; @@ -403,7 +410,7 @@ class FullControlBaseT #ifdef HFSM2_ENABLE_PLANS template - Status buildPlanStatus(); + Status buildPlanStatus() noexcept; #endif @@ -411,38 +418,39 @@ class FullControlBaseT using PlanControl::context; //---------------------------------------------------------------------- - // Clang trips over 'stateId<>()', so give it a hint it comes from PlanControl + // COMMON /// @brief Transition into a state (if transitioning into a region, acts depending on the region type) /// @param stateId State identifier - HFSM2_INLINE void changeTo (const StateID stateId); + HFSM2_INLINE void changeTo (const StateID stateId) noexcept; /// @brief Transition into a state (if transitioning into a region, acts depending on the region type) /// @tparam TState State type template - HFSM2_INLINE void changeTo () { changeTo (PlanControl::template stateId()); } + HFSM2_INLINE void changeTo () noexcept { changeTo (PlanControl::template stateId()); } + // COMMON // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /// @brief Transition into a state (if transitioning into a region, activates the initial state) /// @param stateId State identifier - HFSM2_INLINE void restart (const StateID stateId); + HFSM2_INLINE void restart (const StateID stateId) noexcept; /// @brief Transition into a state (if transitioning into a region, activates the initial state) /// @tparam TState State type template - HFSM2_INLINE void restart () { restart (PlanControl::template stateId()); } + HFSM2_INLINE void restart () noexcept { restart (PlanControl::template stateId()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /// @brief Transition into a state (if transitioning into a region, activates the state that was active previously) /// @param stateId State identifier - HFSM2_INLINE void resume (const StateID stateId); + HFSM2_INLINE void resume (const StateID stateId) noexcept; /// @brief Transition into a state (if transitioning into a region, activates the state that was active previously) /// @tparam TState State type template - HFSM2_INLINE void resume () { resume (PlanControl::template stateId()); } + HFSM2_INLINE void resume () noexcept { resume (PlanControl::template stateId()); } //---------------------------------------------------------------------- @@ -452,14 +460,14 @@ class FullControlBaseT /// with the highest 'utility()' among those with the highest 'rank()') /// @param stateId State identifier /// @see HFSM2_ENABLE_UTILITY_THEORY - HFSM2_INLINE void utilize (const StateID stateId); + HFSM2_INLINE void utilize (const StateID stateId) noexcept; /// @brief Transition into a state (if transitioning into a region, activates the state /// with the highest 'utility()' among those with the highest 'rank()') /// @tparam TState State type /// @see HFSM2_ENABLE_UTILITY_THEORY template - HFSM2_INLINE void utilize () { utilize (PlanControl::template stateId()); } + HFSM2_INLINE void utilize () noexcept { utilize (PlanControl::template stateId()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -467,14 +475,14 @@ class FullControlBaseT /// proportional to 'utility()' among those with the highest 'rank()') /// @param stateId State identifier /// @see HFSM2_ENABLE_UTILITY_THEORY - HFSM2_INLINE void randomize(const StateID stateId); + HFSM2_INLINE void randomize(const StateID stateId) noexcept; /// @brief Transition into a state (if transitioning into a region, uses weighted random to activate the state /// proportional to 'utility()' among those with the highest 'rank()') /// @tparam TState State type /// @see HFSM2_ENABLE_UTILITY_THEORY template - HFSM2_INLINE void randomize() { randomize(PlanControl::template stateId()); } + HFSM2_INLINE void randomize() noexcept { randomize(PlanControl::template stateId()); } #endif @@ -482,22 +490,22 @@ class FullControlBaseT /// @brief Schedule a state to be activated when its parent region is activated /// @param stateId State identifier - HFSM2_INLINE void schedule (const StateID stateId); + HFSM2_INLINE void schedule (const StateID stateId) noexcept; /// @brief Schedule a state to be activated when its parent region is activated /// @tparam TState State type template - HFSM2_INLINE void schedule () { schedule (PlanControl::template stateId()); } + HFSM2_INLINE void schedule () noexcept { schedule (PlanControl::template stateId()); } //---------------------------------------------------------------------- #ifdef HFSM2_ENABLE_PLANS /// @brief Succeed a plan task for the current state - HFSM2_INLINE void succeed(); + HFSM2_INLINE void succeed() noexcept; /// @brief Fail a plan task for the current state - HFSM2_INLINE void fail(); + HFSM2_INLINE void fail() noexcept; #endif @@ -602,7 +610,7 @@ class FullControlT - Status updatePlan(TState& headState, const Status subStatus); + Status updatePlan(TState& headState, const Status subStatus) noexcept; #endif @@ -615,56 +623,58 @@ class FullControlT - HFSM2_INLINE void changeWith (const Payload& payload) { changeWith (FullControlBase::template stateId(), payload ); } + HFSM2_INLINE void changeWith (const Payload& payload) noexcept { changeWith (FullControlBase::template stateId(), payload ); } /// @brief Transition into a state (if transitioning into a region, acts depending on the region type) /// @tparam TState Destination state type /// @param payload Payload template - HFSM2_INLINE void changeWith ( Payload&& payload) { changeWith (FullControlBase::template stateId(), std::move(payload)); } + HFSM2_INLINE void changeWith ( Payload&& payload) noexcept { changeWith (FullControlBase::template stateId(), std::move(payload)); } + // COMMON // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /// @brief Transition into a state (if transitioning into a region, activates the initial state) /// @param stateId Destination state identifier /// @param payload Payload HFSM2_INLINE void restartWith (const StateID stateId, - const Payload& payload); + const Payload& payload) noexcept; /// @brief Transition into a state (if transitioning into a region, activates the initial state) /// @param stateId Destination state identifier /// @param payload Payload HFSM2_INLINE void restartWith (const StateID stateId, - Payload&& payload); + Payload&& payload) noexcept; /// @brief Transition into a state (if transitioning into a region, activates the initial state) /// @tparam TState Destination state type /// @param payload Payload template - HFSM2_INLINE void restartWith (const Payload& payload) { restartWith (FullControlBase::template stateId(), payload ); } + HFSM2_INLINE void restartWith (const Payload& payload) noexcept { restartWith (FullControlBase::template stateId(), payload ); } /// @brief Transition into a state (if transitioning into a region, activates the initial state) /// @tparam TState Destination state type /// @param payload Payload template - HFSM2_INLINE void restartWith ( Payload&& payload) { restartWith (FullControlBase::template stateId(), std::move(payload)); } + HFSM2_INLINE void restartWith ( Payload&& payload) noexcept { restartWith (FullControlBase::template stateId(), std::move(payload)); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -672,25 +682,25 @@ class FullControlT - HFSM2_INLINE void resumeWith (const Payload& payload) { resumeWith (FullControlBase::template stateId(), payload ); } + HFSM2_INLINE void resumeWith (const Payload& payload) noexcept { resumeWith (FullControlBase::template stateId(), payload ); } /// @brief Transition into a state (if transitioning into a region, activates the state that was active previously) /// @tparam TState Destination state type /// @param payload Payload template - HFSM2_INLINE void resumeWith ( Payload&& payload) { resumeWith (FullControlBase::template stateId(), std::move(payload)); } + HFSM2_INLINE void resumeWith ( Payload&& payload) noexcept { resumeWith (FullControlBase::template stateId(), std::move(payload)); } //------------------------------------------------------------------------------ @@ -702,7 +712,7 @@ class FullControlT - HFSM2_INLINE void utilizeWith (const Payload& payload) { utilizeWith (FullControlBase::template stateId(), payload ); } + HFSM2_INLINE void utilizeWith (const Payload& payload) noexcept { utilizeWith (FullControlBase::template stateId(), payload ); } /// @brief Transition into a state (if transitioning into a region, activates the state /// with the highest 'utility()' among those with the highest 'rank()') @@ -726,7 +736,7 @@ class FullControlT - HFSM2_INLINE void utilizeWith ( Payload&& payload) { utilizeWith (FullControlBase::template stateId(), std::move(payload)); } + HFSM2_INLINE void utilizeWith ( Payload&& payload) noexcept { utilizeWith (FullControlBase::template stateId(), std::move(payload)); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -736,7 +746,7 @@ class FullControlT - HFSM2_INLINE void randomizeWith(const Payload& payload) { randomizeWith(FullControlBase::template stateId(), payload ); } + HFSM2_INLINE void randomizeWith(const Payload& payload) noexcept { randomizeWith(FullControlBase::template stateId(), payload ); } /// @brief Transition into a state (if transitioning into a region, uses weighted random to activate the state /// proportional to 'utility()' among those with the highest 'rank()') @@ -760,7 +770,7 @@ class FullControlT - HFSM2_INLINE void randomizeWith( Payload&& payload) { randomizeWith(FullControlBase::template stateId(), std::move(payload)); } + HFSM2_INLINE void randomizeWith( Payload&& payload) noexcept { randomizeWith(FullControlBase::template stateId(), std::move(payload)); } #endif @@ -770,25 +780,25 @@ class FullControlT - HFSM2_INLINE void scheduleWith (const Payload& payload) { scheduleWith (FullControlBase::template stateId(), payload ); } + HFSM2_INLINE void scheduleWith (const Payload& payload) noexcept { scheduleWith (FullControlBase::template stateId(), payload ); } /// @brief Schedule a state to be activated when its parent region is activated /// @tparam TState Destination state type /// @param payload Payload template - HFSM2_INLINE void scheduleWith ( Payload&& payload) { scheduleWith (FullControlBase::template stateId(), std::move(payload)); } + HFSM2_INLINE void scheduleWith ( Payload&& payload) noexcept { scheduleWith (FullControlBase::template stateId(), std::move(payload)); } //------------------------------------------------------------------------------ @@ -882,7 +892,7 @@ class FullControlT - Status updatePlan(TState& headState, const Status subStatus); + Status updatePlan(TState& headState, const Status subStatus) noexcept; #endif @@ -946,7 +956,7 @@ class GuardControlT final HFSM2_IF_PLANS(, PlanData& planData) HFSM2_IF_TRANSITION_HISTORY(, TransitionTargets& transitionTargets) HFSM2_IF_TRANSITION_HISTORY(, const TransitionSets& previousTransitions) - HFSM2_IF_LOG_INTERFACE(, Logger* const logger)) + HFSM2_IF_LOG_INTERFACE(, Logger* const logger)) noexcept : FullControl{context , registry , requests @@ -969,51 +979,51 @@ class GuardControlT final /// @brief Check if a state is going to be activated or deactivated /// @param stateId State identifier /// @return State pending activation/deactivation status - HFSM2_INLINE bool isPendingChange(const StateID stateId) const { return _registry.isPendingChange(stateId); } + HFSM2_INLINE bool isPendingChange(const StateID stateId) const noexcept { return _registry.isPendingChange(stateId); } /// @brief Check if a state is going to be activated or deactivated /// @tparam TState State type /// @return State pending activation/deactivation status template - HFSM2_INLINE bool isPendingChange() { return isPendingChange(FullControl::template stateId()); } + HFSM2_INLINE bool isPendingChange() const noexcept { return isPendingChange(FullControl::template stateId()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /// @brief Check if a state is going to be activated /// @param stateId State identifier /// @return State pending activation status - HFSM2_INLINE bool isPendingEnter (const StateID stateId) const { return _registry.isPendingEnter (stateId); } + HFSM2_INLINE bool isPendingEnter (const StateID stateId) const noexcept { return _registry.isPendingEnter (stateId); } /// @brief Check if a state is going to be activated /// @tparam TState State type /// @return State pending activation status template - HFSM2_INLINE bool isPendingEnter () { return isPendingEnter (FullControl::template stateId()); } + HFSM2_INLINE bool isPendingEnter () const noexcept { return isPendingEnter (FullControl::template stateId()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /// @brief Check if a state is going to be deactivated /// @param stateId State identifier /// @return State pending deactivation status - HFSM2_INLINE bool isPendingExit (const StateID stateId) const { return _registry.isPendingExit (stateId); } + HFSM2_INLINE bool isPendingExit (const StateID stateId) const noexcept { return _registry.isPendingExit (stateId); } /// @brief Check if a state is going to be deactivated /// @tparam TState State type /// @return State pending deactivation status template - HFSM2_INLINE bool isPendingExit () { return isPendingExit (FullControl::template stateId()); } + HFSM2_INLINE bool isPendingExit () const noexcept { return isPendingExit (FullControl::template stateId()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE const TransitionSets& currentTransitions() const { return _currentTransitions; } + HFSM2_INLINE const TransitionSets& currentTransitions() const noexcept { return _currentTransitions; } /// @brief Get pending transition requests /// @return Array of pending transition requests - HFSM2_INLINE const TransitionSet& pendingTransitions() const { return _pendingTransitions; } + HFSM2_INLINE const TransitionSet& pendingTransitions() const noexcept { return _pendingTransitions; } /// @brief Cancel pending transition requests /// (can be used to substitute a transition into the current state with a different one) - HFSM2_INLINE void cancelPendingTransitions(); + HFSM2_INLINE void cancelPendingTransitions() noexcept; private: using FullControl::_registry; diff --git a/include/hfsm2/detail/root/control.inl b/include/hfsm2/detail/root/control.inl index 1af8486..9b819a5 100644 --- a/include/hfsm2/detail/root/control.inl +++ b/include/hfsm2/detail/root/control.inl @@ -2,10 +2,11 @@ namespace hfsm2 { namespace detail { //////////////////////////////////////////////////////////////////////////////// +// COMMON template ControlT::Origin::Origin(ControlT& control_, - const StateID stateId) + const StateID stateId) noexcept : control{control_} , prevId{control._originId} { @@ -15,15 +16,16 @@ ControlT::Origin::Origin(ControlT& control_, //------------------------------------------------------------------------------ template -ControlT::Origin::~Origin() { +ControlT::Origin::~Origin() noexcept { control.resetOrigin(prevId); } +// COMMON //////////////////////////////////////////////////////////////////////////////// template ControlT::Region::Region(ControlT& control_, - const RegionID regionId) + const RegionID regionId) noexcept : control{control_} , prevId{control._regionId} { @@ -33,7 +35,7 @@ ControlT::Region::Region(ControlT& control_, //------------------------------------------------------------------------------ template -ControlT::Region::~Region() { +ControlT::Region::~Region() noexcept { control.resetRegion(prevId); } @@ -41,7 +43,7 @@ ControlT::Region::~Region() { template void -ControlT::setOrigin(const StateID stateId) { +ControlT::setOrigin(const StateID stateId) noexcept { HFSM2_ASSERT(stateId < StateList::SIZE); _originId = stateId; @@ -51,7 +53,7 @@ ControlT::setOrigin(const StateID stateId) { template void -ControlT::resetOrigin(const StateID stateId) { //-V524 +ControlT::resetOrigin(const StateID stateId) noexcept { //-V524 _originId = stateId; } @@ -59,7 +61,7 @@ ControlT::resetOrigin(const StateID stateId) { //-V524 template void -ControlT::setRegion(const RegionID regionId) { +ControlT::setRegion(const RegionID regionId) noexcept { HFSM2_ASSERT(_regionId <= regionId && regionId < RegionList::SIZE); _regionId = regionId; @@ -69,7 +71,7 @@ ControlT::setRegion(const RegionID regionId) { template void -ControlT::resetRegion(const RegionID regionId) { //-V524 +ControlT::resetRegion(const RegionID regionId) noexcept { //-V524 HFSM2_ASSERT(regionId <= _regionId && _regionId < RegionList::SIZE); _regionId = regionId; @@ -82,7 +84,7 @@ ControlT::resetRegion(const RegionID regionId) { //-V524 template void ControlT::pinLastTransition(const StateID stateId, - const Short index) + const Short index) noexcept { if (index != INVALID_SHORT) { HFSM2_ASSERT(index < TransitionSets::CAPACITY); @@ -96,7 +98,7 @@ ControlT::pinLastTransition(const StateID stateId, template const typename ControlT::Transition* -ControlT::lastTransition(const StateID stateId) const { +ControlT::lastTransition(const StateID stateId) const noexcept { if (HFSM2_CHECKED(stateId < StateList::SIZE)) { const Short index = _transitionTargets[stateId]; @@ -111,7 +113,7 @@ ControlT::lastTransition(const StateID stateId) const { template const typename ControlT::Transition* -ControlT::lastTransition() const { +ControlT::lastTransition() const noexcept { HFSM2_ASSERT(_originId < _transitionTargets.CAPACITY); return lastTransition(_originId); @@ -125,7 +127,7 @@ template PlanControlT::Region::Region(PlanControlT& control_, const RegionID regionId, const StateID index, - const Long size) + const Long size) noexcept : control {control_} , prevId {control._regionId} , prevIndex{control._regionStateId} @@ -137,7 +139,7 @@ PlanControlT::Region::Region(PlanControlT& control_, //------------------------------------------------------------------------------ template -PlanControlT::Region::~Region() { +PlanControlT::Region::~Region() noexcept { control.resetRegion(prevId, prevIndex, prevSize); control._status.clear(); @@ -149,7 +151,7 @@ template void PlanControlT::setRegion(const RegionID regionId, const StateID index, - const Long size) + const Long size) noexcept { HFSM2_ASSERT(_regionId <= regionId && regionId < RegionList::SIZE); HFSM2_ASSERT(_regionStateId <= index && index + size <= _regionStateId + _regionSize); @@ -165,7 +167,7 @@ template void PlanControlT::resetRegion(const RegionID regionId, //-V524 const StateID index, - const Long size) + const Long size) noexcept { HFSM2_ASSERT(regionId <= _regionId && _regionId < RegionList::SIZE); HFSM2_ASSERT(index <= _regionStateId && _regionStateId + _regionSize <= index + size); @@ -178,7 +180,7 @@ PlanControlT::resetRegion(const RegionID regionId, //-V524 //////////////////////////////////////////////////////////////////////////////// template -FullControlBaseT::Lock::Lock(FullControlBaseT& control_) +FullControlBaseT::Lock::Lock(FullControlBaseT& control_) noexcept : control{!control_._locked ? &control_ : nullptr} { if (control) @@ -188,7 +190,7 @@ FullControlBaseT::Lock::Lock(FullControlBaseT& control_) //------------------------------------------------------------------------------ template -FullControlBaseT::Lock::~Lock() { +FullControlBaseT::Lock::~Lock() noexcept { if (control) control->_locked = false; } @@ -200,7 +202,7 @@ FullControlBaseT::Lock::~Lock() { template template Status -FullControlBaseT::buildPlanStatus() { +FullControlBaseT::buildPlanStatus() noexcept { using State = TState; static constexpr StateID STATE_ID = State::STATE_ID; @@ -231,10 +233,11 @@ FullControlBaseT::buildPlanStatus() { #endif //------------------------------------------------------------------------------ +// COMMON template void -FullControlBaseT::changeTo(const StateID stateId) { +FullControlBaseT::changeTo(const StateID stateId) noexcept { if (!_locked) { _requests.append(Transition{_originId, stateId, TransitionType::CHANGE}); @@ -245,11 +248,12 @@ FullControlBaseT::changeTo(const StateID stateId) { } } +// COMMON //------------------------------------------------------------------------------ template void -FullControlBaseT::restart(const StateID stateId) { +FullControlBaseT::restart(const StateID stateId) noexcept { if (!_locked) { _requests.append(Transition{_originId, stateId, TransitionType::RESTART}); @@ -264,7 +268,7 @@ FullControlBaseT::restart(const StateID stateId) { template void -FullControlBaseT::resume(const StateID stateId) { +FullControlBaseT::resume(const StateID stateId) noexcept { if (!_locked) { _requests.append(Transition{_originId, stateId, TransitionType::RESUME}); @@ -281,7 +285,7 @@ FullControlBaseT::resume(const StateID stateId) { template void -FullControlBaseT::utilize(const StateID stateId) { +FullControlBaseT::utilize(const StateID stateId) noexcept { if (!_locked) { _requests.append(Transition{_originId, stateId, TransitionType::UTILIZE}); @@ -296,7 +300,7 @@ FullControlBaseT::utilize(const StateID stateId) { template void -FullControlBaseT::randomize(const StateID stateId) { +FullControlBaseT::randomize(const StateID stateId) noexcept { if (!_locked) { _requests.append(Transition{_originId, stateId, TransitionType::RANDOMIZE}); @@ -313,7 +317,7 @@ FullControlBaseT::randomize(const StateID stateId) { template void -FullControlBaseT::schedule(const StateID stateId) { +FullControlBaseT::schedule(const StateID stateId) noexcept { _requests.append(Transition{_originId, stateId, TransitionType::SCHEDULE}); HFSM2_LOG_TRANSITION(context(), _originId, TransitionType::SCHEDULE, stateId); @@ -325,7 +329,7 @@ FullControlBaseT::schedule(const StateID stateId) { template void -FullControlBaseT::succeed() { +FullControlBaseT::succeed() noexcept { _status.result = Status::Result::SUCCESS; _planData.tasksSuccesses.set(_originId); @@ -344,7 +348,7 @@ FullControlBaseT::succeed() { template void -FullControlBaseT::fail() { +FullControlBaseT::fail() noexcept { _status.result = Status::Result::FAILURE; _planData.tasksFailures.set(_originId); @@ -369,7 +373,7 @@ template Status FullControlT>::updatePlan(TState& headState, - const Status subStatus) + const Status subStatus) noexcept { using State = TState; static constexpr StateID STATE_ID = State::STATE_ID; @@ -416,11 +420,12 @@ FullControlT>::update #endif //------------------------------------------------------------------------------ +// COMMON template void FullControlT>::changeWith(const StateID stateId, - const Payload& payload) + const Payload& payload) noexcept { if (!_locked) { _requests.append(Transition{_originId, stateId, TransitionType::CHANGE, payload}); @@ -435,7 +440,7 @@ FullControlT void FullControlT>::changeWith(const StateID stateId, - Payload&& payload) + Payload&& payload) noexcept { if (!_locked) { _requests.append(Transition{_originId, stateId, TransitionType::CHANGE, std::move(payload)}); @@ -447,12 +452,13 @@ FullControlT void FullControlT>::restartWith(const StateID stateId, - const Payload& payload) + const Payload& payload) noexcept { if (!_locked) { _requests.append(Transition{_originId, stateId, TransitionType::RESTART, payload}); @@ -467,7 +473,7 @@ FullControlT void FullControlT>::restartWith(const StateID stateId, - Payload&& payload) + Payload&& payload) noexcept { if (!_locked) { _requests.append(Transition{_originId, stateId, TransitionType::RESTART, std::move(payload)}); @@ -484,7 +490,7 @@ FullControlT void FullControlT>::resumeWith(const StateID stateId, - const Payload& payload) + const Payload& payload) noexcept { if (!_locked) { _requests.append(Transition{_originId, stateId, TransitionType::RESUME, payload}); @@ -499,7 +505,7 @@ FullControlT void FullControlT>::resumeWith(const StateID stateId, - Payload&& payload) + Payload&& payload) noexcept { if (!_locked) { _requests.append(Transition{_originId, stateId, TransitionType::RESUME, std::move(payload)}); @@ -518,7 +524,7 @@ FullControlT void FullControlT>::utilizeWith(const StateID stateId, - const Payload& payload) + const Payload& payload) noexcept { if (!_locked) { _requests.append(Transition{_originId, stateId, TransitionType::UTILIZE, payload}); @@ -533,7 +539,7 @@ FullControlT void FullControlT>::utilizeWith(const StateID stateId, - Payload&& payload) + Payload&& payload) noexcept { if (!_locked) { _requests.append(Transition{_originId, stateId, TransitionType::UTILIZE, std::move(payload)}); @@ -550,7 +556,7 @@ FullControlT void FullControlT>::randomizeWith(const StateID stateId, - const Payload& payload) + const Payload& payload) noexcept { if (!_locked) { _requests.append(Transition{_originId, stateId, TransitionType::RANDOMIZE, payload}); @@ -565,7 +571,7 @@ FullControlT void FullControlT>::randomizeWith(const StateID stateId, - Payload&& payload) + Payload&& payload) noexcept { if (!_locked) { _requests.append(Transition{_originId, stateId, TransitionType::RANDOMIZE, std::move(payload)}); @@ -584,7 +590,7 @@ FullControlT void FullControlT>::scheduleWith(const StateID stateId, - const Payload& payload) + const Payload& payload) noexcept { _requests.append(Transition{_originId, stateId, TransitionType::SCHEDULE, payload}); @@ -594,7 +600,7 @@ FullControlT void FullControlT>::scheduleWith(const StateID stateId, - Payload&& payload) + Payload&& payload) noexcept { _requests.append(Transition{_originId, stateId, TransitionType::SCHEDULE, std::move(payload)}); @@ -609,7 +615,7 @@ template Status FullControlT>::updatePlan(TState& headState, - const Status subStatus) + const Status subStatus) noexcept { using State = TState; static constexpr StateID STATE_ID = State::STATE_ID; @@ -659,7 +665,7 @@ FullControlT>::updat template void -GuardControlT::cancelPendingTransitions() { +GuardControlT::cancelPendingTransitions() noexcept { _cancelled = true; HFSM2_LOG_CANCELLED_PENDING(context(), _originId); diff --git a/include/hfsm2/detail/root/plan.hpp b/include/hfsm2/detail/root/plan.hpp index d705fdd..460283c 100644 --- a/include/hfsm2/detail/root/plan.hpp +++ b/include/hfsm2/detail/root/plan.hpp @@ -16,11 +16,11 @@ struct Status { bool outerTransition = false; inline Status(const Result result_ = Result::NONE, - const bool outerTransition_ = false); + const bool outerTransition_ = false) noexcept; - inline explicit operator bool() const { return result != Result::NONE || outerTransition; } + inline explicit operator bool() const noexcept { return result != Result::NONE || outerTransition; } - inline void clear(); + inline void clear() noexcept; }; #pragma pack(pop) @@ -28,7 +28,7 @@ struct Status { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - inline Status -combine(const Status lhs, const Status rhs) { +combine(const Status lhs, const Status rhs) noexcept { const Status::Result result = lhs.result > rhs.result ? lhs.result : rhs.result; @@ -40,7 +40,7 @@ combine(const Status lhs, const Status rhs) { #ifdef HFSM2_ENABLE_PLANS template -class ConstPlanT { +class CPlanT { template friend class ControlT; @@ -67,19 +67,19 @@ class ConstPlanT { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - struct Iterator { - HFSM2_INLINE Iterator(const ConstPlanT& plan); + struct IteratorT { + HFSM2_INLINE IteratorT(const CPlanT& plan) noexcept; - HFSM2_INLINE explicit operator bool() const; + HFSM2_INLINE explicit operator bool() const noexcept; - HFSM2_INLINE void operator ++(); + HFSM2_INLINE void operator ++() noexcept; - HFSM2_INLINE const Task& operator *() const { return _plan._planData.tasks[_curr]; } - HFSM2_INLINE const Task* operator ->() const { return &_plan._planData.tasks[_curr]; } + HFSM2_INLINE const Task& operator *() const noexcept { return _plan._planData.tasks[_curr]; } + HFSM2_INLINE const Task* operator ->() const noexcept { return &_plan._planData.tasks[_curr]; } - HFSM2_INLINE Long next() const; + HFSM2_INLINE Long next() const noexcept; - const ConstPlanT& _plan; + const CPlanT& _plan; Long _curr; Long _next; }; @@ -87,19 +87,19 @@ class ConstPlanT { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - private: - HFSM2_INLINE ConstPlanT(const PlanData& planData, - const RegionID regionId); + HFSM2_INLINE CPlanT(const PlanData& planData, + const RegionID regionId) noexcept; template - static constexpr StateID stateId() { return index(); } + static constexpr StateID stateId() noexcept { return index(); } template - static constexpr RegionID regionId() { return (RegionID) index(); } + static constexpr RegionID regionId() noexcept { return (RegionID) index(); } public: - HFSM2_INLINE explicit operator bool() const; + HFSM2_INLINE explicit operator bool() const noexcept; - HFSM2_INLINE Iterator first() { return Iterator{*this}; } + HFSM2_INLINE IteratorT first() noexcept { return IteratorT{*this}; } private: const PlanData& _planData; @@ -126,22 +126,22 @@ class PlanBaseT { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - struct Iterator { - HFSM2_INLINE Iterator(PlanBaseT& plan); + struct IteratorT { + HFSM2_INLINE IteratorT(PlanBaseT& plan) noexcept; - HFSM2_INLINE explicit operator bool() const; + HFSM2_INLINE explicit operator bool() const noexcept; - HFSM2_INLINE void operator ++(); + HFSM2_INLINE void operator ++() noexcept; - HFSM2_INLINE Task& operator *() { return _plan._planData.tasks[_curr]; } - HFSM2_INLINE const Task& operator *() const { return _plan._planData.tasks[_curr]; } + HFSM2_INLINE Task& operator *() noexcept { return _plan._planData.tasks[_curr]; } + HFSM2_INLINE const Task& operator *() const noexcept { return _plan._planData.tasks[_curr]; } - HFSM2_INLINE Task* operator ->() { return &_plan._planData.tasks[_curr]; } - HFSM2_INLINE const Task* operator ->() const { return &_plan._planData.tasks[_curr]; } + HFSM2_INLINE Task* operator ->() noexcept { return &_plan._planData.tasks[_curr]; } + HFSM2_INLINE const Task* operator ->() const noexcept { return &_plan._planData.tasks[_curr]; } - HFSM2_INLINE void remove(); + HFSM2_INLINE void remove() noexcept; - HFSM2_INLINE Long next() const; + HFSM2_INLINE Long next() const noexcept; PlanBaseT& _plan; Long _curr; @@ -150,20 +150,20 @@ class PlanBaseT { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - struct ConstIterator { - HFSM2_INLINE ConstIterator(const PlanBaseT& plan); + struct CIterator { + HFSM2_INLINE CIterator(const PlanBaseT& plan) noexcept; - HFSM2_INLINE explicit operator bool() const; + HFSM2_INLINE explicit operator bool() const noexcept; - HFSM2_INLINE void operator ++(); + HFSM2_INLINE void operator ++() noexcept; - HFSM2_INLINE Task& operator *() { return _plan._planData.tasks[_curr]; } - HFSM2_INLINE const Task& operator *() const { return _plan._planData.tasks[_curr]; } + HFSM2_INLINE Task& operator *() noexcept { return _plan._planData.tasks[_curr]; } + HFSM2_INLINE const Task& operator *() const noexcept { return _plan._planData.tasks[_curr]; } - HFSM2_INLINE Task* operator ->() { return &_plan._planData.tasks[_curr]; } - HFSM2_INLINE const Task* operator ->() const { return &_plan._planData.tasks[_curr]; } + HFSM2_INLINE Task* operator ->() noexcept { return &_plan._planData.tasks[_curr]; } + HFSM2_INLINE const Task* operator ->() const noexcept { return &_plan._planData.tasks[_curr]; } - HFSM2_INLINE Long next() const; + HFSM2_INLINE Long next() const noexcept; const PlanBaseT& _plan; Long _curr; @@ -174,25 +174,25 @@ class PlanBaseT { protected: HFSM2_INLINE PlanBaseT(PlanData& planData, - const RegionID regionId); + const RegionID regionId) noexcept; template - static constexpr StateID stateId() { return index(); } + static constexpr StateID stateId() noexcept { return index(); } template - static constexpr RegionID regionId() { return (RegionID) index(); } + static constexpr RegionID regionId() noexcept { return (RegionID) index(); } bool append(const StateID origin, const StateID destination, - const TransitionType transitionType); + const TransitionType transitionType) noexcept; - bool linkTask(const Long index); + bool linkTask(const Long index) noexcept; public: - HFSM2_INLINE explicit operator bool() const; + HFSM2_INLINE explicit operator bool() const noexcept; /// @brief Clear all tasks from the plan - HFSM2_INLINE void clear(); + HFSM2_INLINE void clear() noexcept; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -202,7 +202,7 @@ class PlanBaseT { /// @param destination Destination state identifier /// @return Seccess if FSM total number of tasks is below task capacity /// @note use 'Config::TaskCapacityN<>' to increase task capacity if necessary - HFSM2_INLINE bool change (const StateID origin, const StateID destination) { return append(origin, destination, TransitionType::CHANGE); } + HFSM2_INLINE bool change (const StateID origin, const StateID destination) noexcept { return append(origin, destination, TransitionType::CHANGE); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, acts depending on the region type) @@ -211,7 +211,7 @@ class PlanBaseT { /// @return Seccess if FSM total number of tasks is below task capacity /// @note use 'Config::TaskCapacityN<>' to increase task capacity if necessary template - HFSM2_INLINE bool change (const StateID destination) { return change (stateId(), destination); } + HFSM2_INLINE bool change (const StateID destination) noexcept { return change (stateId(), destination); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, acts depending on the region type) @@ -220,7 +220,7 @@ class PlanBaseT { /// @return Seccess if FSM total number of tasks is below task capacity /// @note use 'Config::TaskCapacityN<>' to increase task capacity if necessary template - HFSM2_INLINE bool change () { return change (stateId(), stateId()); } + HFSM2_INLINE bool change () noexcept { return change (stateId(), stateId()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -230,7 +230,7 @@ class PlanBaseT { /// @param destination Destination state identifier /// @return Seccess if FSM total number of tasks is below task capacity /// @note use 'Config::TaskCapacityN<>' to increase task capacity if necessary - HFSM2_INLINE bool restart (const StateID origin, const StateID destination) { return append(origin, destination, TransitionType::RESTART); } + HFSM2_INLINE bool restart (const StateID origin, const StateID destination) noexcept { return append(origin, destination, TransitionType::RESTART); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, activates the initial state) @@ -239,7 +239,7 @@ class PlanBaseT { /// @return Seccess if FSM total number of tasks is below task capacity /// @note use 'Config::TaskCapacityN<>' to increase task capacity if necessary template - HFSM2_INLINE bool restart (const StateID destination) { return restart (stateId(), destination); } + HFSM2_INLINE bool restart (const StateID destination) noexcept { return restart (stateId(), destination); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, activates the initial state) @@ -248,7 +248,7 @@ class PlanBaseT { /// @return Seccess if FSM total number of tasks is below task capacity /// @note use 'Config::TaskCapacityN<>' to increase task capacity if necessary template - HFSM2_INLINE bool restart () { return restart (stateId(), stateId()); } + HFSM2_INLINE bool restart () noexcept { return restart (stateId(), stateId()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -258,7 +258,7 @@ class PlanBaseT { /// @param destination Destination state identifier /// @return Seccess if FSM total number of tasks is below task capacity /// @note use 'Config::TaskCapacityN<>' to increase task capacity if necessary - HFSM2_INLINE bool resume (const StateID origin, const StateID destination) { return append(origin, destination, TransitionType::RESUME); } + HFSM2_INLINE bool resume (const StateID origin, const StateID destination) noexcept { return append(origin, destination, TransitionType::RESUME); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, activates the state that was active previously) @@ -267,7 +267,7 @@ class PlanBaseT { /// @return Seccess if FSM total number of tasks is below task capacity /// @note use 'Config::TaskCapacityN<>' to increase task capacity if necessary template - HFSM2_INLINE bool resume (const StateID destination) { return resume (stateId(), destination); } + HFSM2_INLINE bool resume (const StateID destination) noexcept { return resume (stateId(), destination); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, activates the state that was active previously) @@ -276,7 +276,7 @@ class PlanBaseT { /// @return Seccess if FSM total number of tasks is below task capacity /// @note use 'Config::TaskCapacityN<>' to increase task capacity if necessary template - HFSM2_INLINE bool resume () { return resume (stateId(), stateId()); } + HFSM2_INLINE bool resume () noexcept { return resume (stateId(), stateId()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -289,7 +289,7 @@ class PlanBaseT { /// @return Seccess if FSM total number of tasks is below task capacity /// @note use 'Config::TaskCapacityN<>' to increase task capacity if necessary /// @see HFSM2_ENABLE_UTILITY_THEORY - HFSM2_INLINE bool utilize (const StateID origin, const StateID destination) { return append(origin, destination, TransitionType::UTILIZE); } + HFSM2_INLINE bool utilize (const StateID origin, const StateID destination) noexcept { return append(origin, destination, TransitionType::UTILIZE); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, activates the state with the highest 'utility()' among those with the highest 'rank()') @@ -299,7 +299,7 @@ class PlanBaseT { /// @note use 'Config::TaskCapacityN<>' to increase task capacity if necessary /// @see HFSM2_ENABLE_UTILITY_THEORY template - HFSM2_INLINE bool utilize (const StateID destination) { return utilize (stateId(), destination); } + HFSM2_INLINE bool utilize (const StateID destination) noexcept { return utilize (stateId(), destination); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, activates the state with the highest 'utility()' among those with the highest 'rank()') @@ -309,7 +309,7 @@ class PlanBaseT { /// @note use 'Config::TaskCapacityN<>' to increase task capacity if necessary /// @see HFSM2_ENABLE_UTILITY_THEORY template - HFSM2_INLINE bool utilize () { return utilize (stateId(), stateId()); } + HFSM2_INLINE bool utilize () noexcept { return utilize (stateId(), stateId()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -320,7 +320,7 @@ class PlanBaseT { /// @return Seccess if FSM total number of tasks is below task capacity /// @note use 'Config::TaskCapacityN<>' to increase task capacity if necessary /// @see HFSM2_ENABLE_UTILITY_THEORY - HFSM2_INLINE bool randomize(const StateID origin, const StateID destination) { return append(origin, destination, TransitionType::RANDOMIZE); } + HFSM2_INLINE bool randomize(const StateID origin, const StateID destination) noexcept { return append(origin, destination, TransitionType::RANDOMIZE); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, uses weighted random to activate the state proportional to 'utility()' among those with the highest 'rank()') @@ -330,7 +330,7 @@ class PlanBaseT { /// @note use 'Config::TaskCapacityN<>' to increase task capacity if necessary /// @see HFSM2_ENABLE_UTILITY_THEORY template - HFSM2_INLINE bool randomize(const StateID destination) { return randomize(stateId(), destination); } + HFSM2_INLINE bool randomize(const StateID destination) noexcept { return randomize(stateId(), destination); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, uses weighted random to activate the state proportional to 'utility()' among those with the highest 'rank()') @@ -340,7 +340,7 @@ class PlanBaseT { /// @note use 'Config::TaskCapacityN<>' to increase task capacity if necessary /// @see HFSM2_ENABLE_UTILITY_THEORY template - HFSM2_INLINE bool randomize() { return randomize(stateId(), stateId()); } + HFSM2_INLINE bool randomize() noexcept { return randomize(stateId(), stateId()); } #endif @@ -351,7 +351,7 @@ class PlanBaseT { /// @param destination Destination state identifier /// @return Seccess if FSM total number of tasks is below task capacity /// @note use 'Config::TaskCapacityN<>' to increase task capacity if necessary - HFSM2_INLINE bool schedule (const StateID origin, const StateID destination) { return append(origin, destination, TransitionType::SCHEDULE); } + HFSM2_INLINE bool schedule (const StateID origin, const StateID destination) noexcept { return append(origin, destination, TransitionType::SCHEDULE); } /// @brief Add a task to schedule a transition to 'destination' if 'origin' completes with 'success()' /// @tparam TOrigin Origin state type @@ -359,7 +359,7 @@ class PlanBaseT { /// @return Seccess if FSM total number of tasks is below task capacity /// @note use 'Config::TaskCapacityN<>' to increase task capacity if necessary template - HFSM2_INLINE bool schedule (const StateID destination) { return schedule (stateId(), destination); } + HFSM2_INLINE bool schedule (const StateID destination) noexcept { return schedule (stateId(), destination); } /// @brief Add a task to schedule a transition to 'destination' if 'origin' completes with 'success()' /// @tparam TOrigin Origin state type @@ -367,20 +367,20 @@ class PlanBaseT { /// @return Seccess if FSM total number of tasks is below task capacity /// @note use 'Config::TaskCapacityN<>' to increase task capacity if necessary template - HFSM2_INLINE bool schedule () { return schedule (stateId(), stateId()); } + HFSM2_INLINE bool schedule () noexcept { return schedule (stateId(), stateId()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /// @brief Begin iteration over plan tasks for the current region - /// @return Iterator to the first task - HFSM2_INLINE Iterator first() { return Iterator{*this}; } + /// @return IteratorT to the first task + HFSM2_INLINE IteratorT first() noexcept { return IteratorT{*this}; } /// @brief Begin iteration over plan tasks - /// @return ConstIterator to the first task - HFSM2_INLINE ConstIterator first() const { return ConstIterator{*this}; } + /// @return CIterator to the first task + HFSM2_INLINE CIterator first() const noexcept { return CIterator{*this}; } private: - void remove(const Long task); + void remove(const Long task) noexcept; protected: PlanData& _planData; @@ -463,12 +463,12 @@ class PlanT' to increase task capacity if necessary - HFSM2_INLINE bool changeWith (const StateID origin, const StateID destination, const Payload& payload) { return append (origin , destination , TransitionType::CHANGE , payload ); } + HFSM2_INLINE bool changeWith (const StateID origin, const StateID destination, const Payload& payload) noexcept { return append(origin , destination , TransitionType::CHANGE , payload ); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, acts depending on the region type) @@ -489,7 +489,7 @@ class PlanT' to increase task capacity if necessary - HFSM2_INLINE bool changeWith (const StateID origin, const StateID destination, Payload&& payload) { return append (origin , destination , TransitionType::CHANGE , std::move(payload)); } + HFSM2_INLINE bool changeWith (const StateID origin, const StateID destination, Payload&& payload) noexcept { return append(origin , destination , TransitionType::CHANGE , std::move(payload)); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, acts depending on the region type) @@ -499,7 +499,7 @@ class PlanT' to increase task capacity if necessary template - HFSM2_INLINE bool changeWith ( const StateID destination, const Payload& payload) { return changeWith (PlanBase::template stateId(), destination , payload ); } + HFSM2_INLINE bool changeWith ( const StateID destination, const Payload& payload) noexcept { return append(PlanBase::template stateId(), destination , TransitionType::CHANGE , payload ); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, acts depending on the region type) @@ -509,7 +509,7 @@ class PlanT' to increase task capacity if necessary template - HFSM2_INLINE bool changeWith ( const StateID destination, Payload&& payload) { return changeWith (PlanBase::template stateId(), destination , std::move(payload)); } + HFSM2_INLINE bool changeWith ( const StateID destination, Payload&& payload) noexcept { return append(PlanBase::template stateId(), destination , TransitionType::CHANGE , std::move(payload)); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, acts depending on the region type) @@ -519,7 +519,7 @@ class PlanT' to increase task capacity if necessary template - HFSM2_INLINE bool changeWith ( const Payload& payload) { return changeWith (PlanBase::template stateId(), PlanBase::template stateId(), payload ); } + HFSM2_INLINE bool changeWith ( const Payload& payload) noexcept { return append(PlanBase::template stateId(), PlanBase::template stateId(), TransitionType::CHANGE , payload ); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, acts depending on the region type) @@ -529,7 +529,7 @@ class PlanT' to increase task capacity if necessary template - HFSM2_INLINE bool changeWith ( Payload&& payload) { return changeWith (PlanBase::template stateId(), PlanBase::template stateId(), std::move(payload)); } + HFSM2_INLINE bool changeWith ( Payload&& payload) noexcept { return append(PlanBase::template stateId(), PlanBase::template stateId(), TransitionType::CHANGE , std::move(payload)); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -540,7 +540,7 @@ class PlanT' to increase task capacity if necessary - HFSM2_INLINE bool restartWith (const StateID origin, const StateID destination, const Payload& payload) { return append (origin , destination , TransitionType::RESTART , payload ); } + HFSM2_INLINE bool restartWith (const StateID origin, const StateID destination, const Payload& payload) noexcept { return append(origin , destination , TransitionType::RESTART , payload ); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, activates the initial state) @@ -549,7 +549,7 @@ class PlanT' to increase task capacity if necessary - HFSM2_INLINE bool restartWith (const StateID origin, const StateID destination, Payload&& payload) { return append (origin , destination , TransitionType::RESTART , std::move(payload)); } + HFSM2_INLINE bool restartWith (const StateID origin, const StateID destination, Payload&& payload) noexcept { return append(origin , destination , TransitionType::RESTART , std::move(payload)); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, activates the initial state) @@ -559,7 +559,7 @@ class PlanT' to increase task capacity if necessary template - HFSM2_INLINE bool restartWith ( const StateID destination, const Payload& payload) { return restartWith (PlanBase::template stateId(), destination , payload ); } + HFSM2_INLINE bool restartWith ( const StateID destination, const Payload& payload) noexcept { return append(PlanBase::template stateId(), destination , TransitionType::RESTART , payload ); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, activates the initial state) @@ -569,7 +569,7 @@ class PlanT' to increase task capacity if necessary template - HFSM2_INLINE bool restartWith ( const StateID destination, Payload&& payload) { return restartWith (PlanBase::template stateId(), destination , std::move(payload)); } + HFSM2_INLINE bool restartWith ( const StateID destination, Payload&& payload) noexcept { return append(PlanBase::template stateId(), destination , TransitionType::RESTART , std::move(payload)); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, activates the initial state) @@ -579,7 +579,7 @@ class PlanT' to increase task capacity if necessary template - HFSM2_INLINE bool restartWith ( const Payload& payload) { return restartWith (PlanBase::template stateId(), PlanBase::template stateId(), payload ); } + HFSM2_INLINE bool restartWith ( const Payload& payload) noexcept { return append(PlanBase::template stateId(), PlanBase::template stateId(), TransitionType::RESTART , payload ); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, activates the initial state) @@ -589,7 +589,7 @@ class PlanT' to increase task capacity if necessary template - HFSM2_INLINE bool restartWith ( Payload&& payload) { return restartWith (PlanBase::template stateId(), PlanBase::template stateId(), std::move(payload)); } + HFSM2_INLINE bool restartWith ( Payload&& payload) noexcept { return append(PlanBase::template stateId(), PlanBase::template stateId(), TransitionType::RESTART , std::move(payload)); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -600,7 +600,7 @@ class PlanT' to increase task capacity if necessary - HFSM2_INLINE bool resumeWith (const StateID origin, const StateID destination, const Payload& payload) { return append (origin , destination , TransitionType::RESUME , payload ); } + HFSM2_INLINE bool resumeWith (const StateID origin, const StateID destination, const Payload& payload) noexcept { return append(origin , destination , TransitionType::RESUME , payload ); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, activates the state that was active previously) @@ -609,7 +609,7 @@ class PlanT' to increase task capacity if necessary - HFSM2_INLINE bool resumeWith (const StateID origin, const StateID destination, Payload&& payload) { return append (origin , destination , TransitionType::RESUME , std::move(payload)); } + HFSM2_INLINE bool resumeWith (const StateID origin, const StateID destination, Payload&& payload) noexcept { return append(origin , destination , TransitionType::RESUME , std::move(payload)); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, activates the state that was active previously) @@ -619,7 +619,7 @@ class PlanT' to increase task capacity if necessary template - HFSM2_INLINE bool resumeWith ( const StateID destination, const Payload& payload) { return resumeWith (PlanBase::template stateId(), destination , payload ); } + HFSM2_INLINE bool resumeWith ( const StateID destination, const Payload& payload) noexcept { return append(PlanBase::template stateId(), destination , TransitionType::RESUME , payload ); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, activates the state that was active previously) @@ -629,7 +629,7 @@ class PlanT' to increase task capacity if necessary template - HFSM2_INLINE bool resumeWith ( const StateID destination, Payload&& payload) { return resumeWith (PlanBase::template stateId(), destination , std::move(payload)); } + HFSM2_INLINE bool resumeWith ( const StateID destination, Payload&& payload) noexcept { return append(PlanBase::template stateId(), destination , TransitionType::RESUME , std::move(payload)); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, activates the state that was active previously) @@ -639,7 +639,7 @@ class PlanT' to increase task capacity if necessary template - HFSM2_INLINE bool resumeWith ( const Payload& payload) { return resumeWith (PlanBase::template stateId(), PlanBase::template stateId(), payload ); } + HFSM2_INLINE bool resumeWith ( const Payload& payload) noexcept { return append(PlanBase::template stateId(), PlanBase::template stateId(), TransitionType::RESUME , payload ); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, activates the state that was active previously) @@ -649,7 +649,7 @@ class PlanT' to increase task capacity if necessary template - HFSM2_INLINE bool resumeWith ( Payload&& payload) { return resumeWith (PlanBase::template stateId(), PlanBase::template stateId(), std::move(payload)); } + HFSM2_INLINE bool resumeWith ( Payload&& payload) noexcept { return append(PlanBase::template stateId(), PlanBase::template stateId(), TransitionType::RESUME , std::move(payload)); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -663,7 +663,7 @@ class PlanT' to increase task capacity if necessary /// @see HFSM2_ENABLE_UTILITY_THEORY - HFSM2_INLINE bool utilizeWith (const StateID origin, const StateID destination, const Payload& payload) { return append (origin , destination , TransitionType::UTILIZE , payload ); } + HFSM2_INLINE bool utilizeWith (const StateID origin, const StateID destination, const Payload& payload) noexcept { return append(origin , destination , TransitionType::UTILIZE , payload ); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, activates the state with the highest 'utility()' among those with the highest 'rank()') @@ -673,7 +673,7 @@ class PlanT' to increase task capacity if necessary /// @see HFSM2_ENABLE_UTILITY_THEORY - HFSM2_INLINE bool utilizeWith (const StateID origin, const StateID destination, Payload&& payload) { return append (origin , destination , TransitionType::UTILIZE , std::move(payload)); } + HFSM2_INLINE bool utilizeWith (const StateID origin, const StateID destination, Payload&& payload) noexcept { return append(origin , destination , TransitionType::UTILIZE , std::move(payload)); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, activates the state with the highest 'utility()' among those with the highest 'rank()') @@ -684,7 +684,7 @@ class PlanT' to increase task capacity if necessary /// @see HFSM2_ENABLE_UTILITY_THEORY template - HFSM2_INLINE bool utilizeWith ( const StateID destination, const Payload& payload) { return utilizeWith (PlanBase::template stateId(), destination , payload ); } + HFSM2_INLINE bool utilizeWith ( const StateID destination, const Payload& payload) noexcept { return append(PlanBase::template stateId(), destination , TransitionType::UTILIZE , payload ); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, activates the state with the highest 'utility()' among those with the highest 'rank()') @@ -695,7 +695,7 @@ class PlanT' to increase task capacity if necessary /// @see HFSM2_ENABLE_UTILITY_THEORY template - HFSM2_INLINE bool utilizeWith ( const StateID destination, Payload&& payload) { return utilizeWith (PlanBase::template stateId(), destination , std::move(payload)); } + HFSM2_INLINE bool utilizeWith ( const StateID destination, Payload&& payload) noexcept { return append(PlanBase::template stateId(), destination , TransitionType::UTILIZE , std::move(payload)); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, activates the state with the highest 'utility()' among those with the highest 'rank()') @@ -706,7 +706,7 @@ class PlanT' to increase task capacity if necessary /// @see HFSM2_ENABLE_UTILITY_THEORY template - HFSM2_INLINE bool utilizeWith ( const Payload& payload) { return utilizeWith (PlanBase::template stateId(), PlanBase::template stateId(), payload ); } + HFSM2_INLINE bool utilizeWith ( const Payload& payload) noexcept { return append(PlanBase::template stateId(), PlanBase::template stateId(), TransitionType::UTILIZE , payload ); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, activates the state with the highest 'utility()' among those with the highest 'rank()') @@ -717,7 +717,7 @@ class PlanT' to increase task capacity if necessary /// @see HFSM2_ENABLE_UTILITY_THEORY template - HFSM2_INLINE bool utilizeWith ( Payload&& payload) { return utilizeWith (PlanBase::template stateId(), PlanBase::template stateId(), std::move(payload)); } + HFSM2_INLINE bool utilizeWith ( Payload&& payload) noexcept { return append(PlanBase::template stateId(), PlanBase::template stateId(), TransitionType::UTILIZE , std::move(payload)); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -729,7 +729,7 @@ class PlanT' to increase task capacity if necessary /// @see HFSM2_ENABLE_UTILITY_THEORY - HFSM2_INLINE bool randomizeWith(const StateID origin, const StateID destination, const Payload& payload) { return append (origin , destination , TransitionType::RANDOMIZE, payload ); } + HFSM2_INLINE bool randomizeWith(const StateID origin, const StateID destination, const Payload& payload) noexcept { return append(origin , destination , TransitionType::RANDOMIZE, payload ); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, uses weighted random to activate the state proportional to 'utility()' among those with the highest 'rank()') @@ -739,7 +739,7 @@ class PlanT' to increase task capacity if necessary /// @see HFSM2_ENABLE_UTILITY_THEORY - HFSM2_INLINE bool randomizeWith(const StateID origin, const StateID destination, Payload&& payload) { return append (origin , destination , TransitionType::RANDOMIZE, std::move(payload)); } + HFSM2_INLINE bool randomizeWith(const StateID origin, const StateID destination, Payload&& payload) noexcept { return append(origin , destination , TransitionType::RANDOMIZE, std::move(payload)); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, uses weighted random to activate the state proportional to 'utility()' among those with the highest 'rank()') @@ -750,7 +750,7 @@ class PlanT' to increase task capacity if necessary /// @see HFSM2_ENABLE_UTILITY_THEORY template - HFSM2_INLINE bool randomizeWith( const StateID destination, const Payload& payload) { return randomizeWith(PlanBase::template stateId(), destination , payload ); } + HFSM2_INLINE bool randomizeWith( const StateID destination, const Payload& payload) noexcept { return append(PlanBase::template stateId(), destination , TransitionType::RANDOMIZE, payload ); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, uses weighted random to activate the state proportional to 'utility()' among those with the highest 'rank()') @@ -761,7 +761,7 @@ class PlanT' to increase task capacity if necessary /// @see HFSM2_ENABLE_UTILITY_THEORY template - HFSM2_INLINE bool randomizeWith( const StateID destination, Payload&& payload) { return randomizeWith(PlanBase::template stateId(), destination , std::move(payload)); } + HFSM2_INLINE bool randomizeWith( const StateID destination, Payload&& payload) noexcept { return append(PlanBase::template stateId(), destination , TransitionType::RANDOMIZE, std::move(payload)); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, uses weighted random to activate the state proportional to 'utility()' among those with the highest 'rank()') @@ -772,7 +772,7 @@ class PlanT' to increase task capacity if necessary /// @see HFSM2_ENABLE_UTILITY_THEORY template - HFSM2_INLINE bool randomizeWith( const Payload& payload) { return randomizeWith(PlanBase::template stateId(), PlanBase::template stateId(), payload ); } + HFSM2_INLINE bool randomizeWith( const Payload& payload) noexcept { return append(PlanBase::template stateId(), PlanBase::template stateId(), TransitionType::RANDOMIZE, payload ); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, uses weighted random to activate the state proportional to 'utility()' among those with the highest 'rank()') @@ -783,7 +783,7 @@ class PlanT' to increase task capacity if necessary /// @see HFSM2_ENABLE_UTILITY_THEORY template - HFSM2_INLINE bool randomizeWith( Payload&& payload) { return randomizeWith(PlanBase::template stateId(), PlanBase::template stateId(), std::move(payload)); } + HFSM2_INLINE bool randomizeWith( Payload&& payload) noexcept { return append(PlanBase::template stateId(), PlanBase::template stateId(), TransitionType::RANDOMIZE, std::move(payload)); } #endif @@ -795,7 +795,7 @@ class PlanT' to increase task capacity if necessary - HFSM2_INLINE bool scheduleWith (const StateID origin, const StateID destination, const Payload& payload) { return append (origin , destination , TransitionType::SCHEDULE , payload ); } + HFSM2_INLINE bool scheduleWith (const StateID origin, const StateID destination, const Payload& payload) noexcept { return append(origin , destination , TransitionType::SCHEDULE , payload ); } /// @brief Add a task to schedule a transition to 'destination' if 'origin' completes with 'success()' /// @param origin Origin state identifier @@ -803,7 +803,7 @@ class PlanT' to increase task capacity if necessary - HFSM2_INLINE bool scheduleWith (const StateID origin, const StateID destination, Payload&& payload) { return append (origin , destination , TransitionType::SCHEDULE , std::move(payload)); } + HFSM2_INLINE bool scheduleWith (const StateID origin, const StateID destination, Payload&& payload) noexcept { return append(origin , destination , TransitionType::SCHEDULE , std::move(payload)); } /// @brief Add a task to schedule a transition to 'destination' if 'origin' completes with 'success()' /// @tparam TOrigin Origin state type @@ -812,7 +812,7 @@ class PlanT' to increase task capacity if necessary template - HFSM2_INLINE bool scheduleWith ( const StateID destination, const Payload& payload) { return scheduleWith (PlanBase::template stateId(), destination , payload ); } + HFSM2_INLINE bool scheduleWith ( const StateID destination, const Payload& payload) noexcept { return append(PlanBase::template stateId(), destination , TransitionType::SCHEDULE , payload ); } /// @brief Add a task to schedule a transition to 'destination' if 'origin' completes with 'success()' /// @tparam TOrigin Origin state type @@ -821,7 +821,7 @@ class PlanT' to increase task capacity if necessary template - HFSM2_INLINE bool scheduleWith ( const StateID destination, Payload&& payload) { return scheduleWith (PlanBase::template stateId(), destination , std::move(payload)); } + HFSM2_INLINE bool scheduleWith ( const StateID destination, Payload&& payload) noexcept { return append(PlanBase::template stateId(), destination , TransitionType::SCHEDULE , std::move(payload)); } /// @brief Add a task to schedule a transition to 'destination' if 'origin' completes with 'success()' /// @tparam TOrigin Origin state type @@ -830,7 +830,7 @@ class PlanT' to increase task capacity if necessary template - HFSM2_INLINE bool scheduleWith ( const Payload& payload) { return scheduleWith (PlanBase::template stateId(), PlanBase::template stateId(), payload ); } + HFSM2_INLINE bool scheduleWith ( const Payload& payload) noexcept { return append(PlanBase::template stateId(), PlanBase::template stateId(), TransitionType::SCHEDULE , payload ); } /// @brief Add a task to schedule a transition to 'destination' if 'origin' completes with 'success()' /// @tparam TOrigin Origin state type @@ -839,7 +839,7 @@ class PlanT' to increase task capacity if necessary template - HFSM2_INLINE bool scheduleWith ( Payload&& payload) { return scheduleWith (PlanBase::template stateId(), PlanBase::template stateId(), std::move(payload)); } + HFSM2_INLINE bool scheduleWith ( Payload&& payload) noexcept { return append(PlanBase::template stateId(), PlanBase::template stateId(), TransitionType::SCHEDULE , std::move(payload)); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/include/hfsm2/detail/root/plan.inl b/include/hfsm2/detail/root/plan.inl index ab2b19f..1bd929c 100644 --- a/include/hfsm2/detail/root/plan.inl +++ b/include/hfsm2/detail/root/plan.inl @@ -4,7 +4,7 @@ namespace detail { //////////////////////////////////////////////////////////////////////////////// Status::Status(const Result result_, - const bool outerTransition_) + const bool outerTransition_) noexcept : result{result_} , outerTransition{outerTransition_} {} @@ -12,7 +12,7 @@ Status::Status(const Result result_, //------------------------------------------------------------------------------ void -Status::clear() { +Status::clear() noexcept { result = Result::NONE; outerTransition = false; } @@ -22,7 +22,7 @@ Status::clear() { #ifdef HFSM2_ENABLE_PLANS template -ConstPlanT::Iterator::Iterator(const ConstPlanT& plan) +CPlanT::IteratorT::IteratorT(const CPlanT& plan) noexcept : _plan{plan} , _curr{plan._bounds.first} { @@ -32,17 +32,17 @@ ConstPlanT::Iterator::Iterator(const ConstPlanT& plan) //------------------------------------------------------------------------------ template -ConstPlanT::Iterator::operator bool() const { - HFSM2_ASSERT(_curr < ConstPlanT::TASK_CAPACITY || _curr == INVALID_LONG); +CPlanT::IteratorT::operator bool() const noexcept { + HFSM2_ASSERT(_curr < CPlanT::TASK_CAPACITY || _curr == INVALID_LONG); - return _curr < ConstPlanT::TASK_CAPACITY; + return _curr < CPlanT::TASK_CAPACITY; } //------------------------------------------------------------------------------ template void -ConstPlanT::Iterator::operator ++() { +CPlanT::IteratorT::operator ++() noexcept { _curr = _next; _next = next(); } @@ -51,8 +51,8 @@ ConstPlanT::Iterator::operator ++() { template Long -ConstPlanT::Iterator::next() const { - if (_curr < ConstPlanT::TASK_CAPACITY) { +CPlanT::IteratorT::next() const noexcept { + if (_curr < CPlanT::TASK_CAPACITY) { const TaskLink& link = _plan._planData.taskLinks[_curr]; return link.next; @@ -66,8 +66,8 @@ ConstPlanT::Iterator::next() const { //////////////////////////////////////////////////////////////////////////////// template -ConstPlanT::ConstPlanT(const PlanData& planData, - const RegionID regionId) +CPlanT::CPlanT(const PlanData& planData, + const RegionID regionId) noexcept : _planData{planData} , _bounds{planData.tasksBounds[regionId]} {} @@ -75,7 +75,7 @@ ConstPlanT::ConstPlanT(const PlanData& planData, //------------------------------------------------------------------------------ template -ConstPlanT::operator bool() const { +CPlanT::operator bool() const noexcept { if (_bounds.first < TASK_CAPACITY) { HFSM2_ASSERT(_bounds.last < TASK_CAPACITY); return true; @@ -88,7 +88,7 @@ ConstPlanT::operator bool() const { //////////////////////////////////////////////////////////////////////////////// template -PlanBaseT::Iterator::Iterator(PlanBaseT& plan) +PlanBaseT::IteratorT::IteratorT(PlanBaseT& plan) noexcept : _plan{plan} , _curr{plan._bounds.first} { @@ -98,7 +98,7 @@ PlanBaseT::Iterator::Iterator(PlanBaseT& plan) //------------------------------------------------------------------------------ template -PlanBaseT::Iterator::operator bool() const { +PlanBaseT::IteratorT::operator bool() const noexcept { HFSM2_ASSERT(_curr < PlanBaseT::TASK_CAPACITY || _curr == INVALID_LONG); return _curr < PlanBaseT::TASK_CAPACITY; @@ -108,7 +108,7 @@ PlanBaseT::Iterator::operator bool() const { template void -PlanBaseT::Iterator::operator ++() { +PlanBaseT::IteratorT::operator ++() noexcept { _curr = _next; _next = next(); } @@ -117,7 +117,7 @@ PlanBaseT::Iterator::operator ++() { template void -PlanBaseT::Iterator::remove() { +PlanBaseT::IteratorT::remove() noexcept { _plan.remove(_curr); } @@ -125,7 +125,7 @@ PlanBaseT::Iterator::remove() { template Long -PlanBaseT::Iterator::next() const { +PlanBaseT::IteratorT::next() const noexcept { if (_curr < PlanBaseT::TASK_CAPACITY) { const TaskLink& link = _plan._planData.taskLinks[_curr]; @@ -140,7 +140,7 @@ PlanBaseT::Iterator::next() const { //////////////////////////////////////////////////////////////////////////////// template -PlanBaseT::ConstIterator::ConstIterator(const PlanBaseT& plan) +PlanBaseT::CIterator::CIterator(const PlanBaseT& plan) noexcept : _plan{plan} , _curr{plan._bounds.first} { @@ -150,7 +150,7 @@ PlanBaseT::ConstIterator::ConstIterator(const PlanBaseT& plan) //------------------------------------------------------------------------------ template -PlanBaseT::ConstIterator::operator bool() const { +PlanBaseT::CIterator::operator bool() const noexcept { HFSM2_ASSERT(_curr < PlanBaseT::TASK_CAPACITY || _curr == INVALID_LONG); return _curr < PlanBaseT::TASK_CAPACITY; @@ -160,7 +160,7 @@ PlanBaseT::ConstIterator::operator bool() const { template void -PlanBaseT::ConstIterator::operator ++() { +PlanBaseT::CIterator::operator ++() noexcept { _curr = _next; _next = next(); } @@ -169,7 +169,7 @@ PlanBaseT::ConstIterator::operator ++() { template Long -PlanBaseT::ConstIterator::next() const { +PlanBaseT::CIterator::next() const noexcept { if (_curr < PlanBaseT::TASK_CAPACITY) { const TaskLink& link = _plan._planData.taskLinks[_curr]; @@ -185,7 +185,7 @@ PlanBaseT::ConstIterator::next() const { template PlanBaseT::PlanBaseT(PlanData& planData, - const RegionID regionId) + const RegionID regionId) noexcept : _planData{planData} , _regionId{regionId} , _bounds{planData.tasksBounds[regionId]} @@ -194,7 +194,7 @@ PlanBaseT::PlanBaseT(PlanData& planData, // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - template -PlanBaseT::operator bool() const { +PlanBaseT::operator bool() const noexcept { if (_bounds.first < TASK_CAPACITY) { HFSM2_ASSERT(_bounds.last < TASK_CAPACITY); return true; @@ -210,7 +210,7 @@ template bool PlanBaseT::append(const StateID origin, const StateID destination, - const TransitionType transitionType) + const TransitionType transitionType) noexcept { _planData.planExists.set(_regionId); @@ -221,7 +221,7 @@ PlanBaseT::append(const StateID origin, template bool -PlanBaseT::linkTask(const Long index) { +PlanBaseT::linkTask(const Long index) noexcept { if (index != Tasks::INVALID) { if (_bounds.first == INVALID_LONG) { HFSM2_ASSERT(_bounds.last == INVALID_LONG); @@ -256,7 +256,7 @@ PlanBaseT::linkTask(const Long index) { template void -PlanBaseT::clear() { +PlanBaseT::clear() noexcept { if (_bounds.first < TaskLinks::CAPACITY) { HFSM2_ASSERT(_bounds.last < TaskLinks::CAPACITY); @@ -290,7 +290,7 @@ PlanBaseT::clear() { template void -PlanBaseT::remove(const Long task) { +PlanBaseT::remove(const Long task) noexcept { HFSM2_ASSERT(_planData.planExists.get(_regionId)); HFSM2_ASSERT(_bounds.first < TaskLinks::CAPACITY); HFSM2_ASSERT(_bounds.last < TaskLinks::CAPACITY); @@ -328,7 +328,7 @@ bool PlanT>::append(const StateID origin, const StateID destination, const TransitionType transitionType, - const Payload& payload) + const Payload& payload) noexcept { _planData.planExists.set(_regionId); @@ -342,7 +342,7 @@ bool PlanT>::append(const StateID origin, const StateID destination, const TransitionType transitionType, - Payload&& payload) + Payload&& payload) noexcept { _planData.planExists.set(_regionId); diff --git a/include/hfsm2/detail/root/plan_data.hpp b/include/hfsm2/detail/root/plan_data.hpp index 8238f99..3ea50e3 100644 --- a/include/hfsm2/detail/root/plan_data.hpp +++ b/include/hfsm2/detail/root/plan_data.hpp @@ -7,80 +7,6 @@ namespace detail { #pragma pack(push, 2) -struct TaskBase { - HFSM2_INLINE TaskBase() {} - - HFSM2_INLINE TaskBase(const StateID origin_, - const StateID destination_, - const TransitionType type_) - : origin{origin_} - , destination{destination_} - , type{type_} - {} - - StateID origin = INVALID_STATE_ID; - StateID destination = INVALID_STATE_ID; - TransitionType type = TransitionType::COUNT; -}; - -//------------------------------------------------------------------------------ - -template -struct TaskT - : TaskBase -{ - using Payload = TPayload; - using Storage = typename std::aligned_storage::type; - - using TaskBase::TaskBase; - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE TaskT() { - new (&storage) Payload{}; - } - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE TaskT(const StateID origin, - const StateID destination, - const TransitionType type, - const Payload& payload) - : TaskBase{origin, destination, type} - , payloadSet{true} - { - new (&storage) Payload{payload}; - } - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE TaskT(const StateID origin, - const StateID destination, - const TransitionType type, - Payload&& payload) - : TaskBase{origin, destination, type} - , payloadSet{true} - { - new (&storage) Payload{std::move(payload)}; - } - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool payloadSet = false; - Storage storage; -}; - -//------------------------------------------------------------------------------ - -template <> -struct TaskT - : TaskBase -{ - using TaskBase::TaskBase; -}; - -//------------------------------------------------------------------------------ - struct TaskLink { Long prev = INVALID_LONG; Long next = INVALID_LONG; @@ -145,14 +71,14 @@ struct PlanDataT; - using Tasks = List; - using TaskLinks = StaticArray; - using Payloads = StaticArray; + using Task = TaskT; + using Tasks = TaskListT ; + using TaskLinks = StaticArrayT; + using Payloads = StaticArrayT; - using TasksBounds = Array; - using TasksBits = BitArray; - using RegionBits = BitArray; + using TasksBounds = ArrayT ; + using TasksBits = BitArrayT; + using RegionBits = BitArrayT; Tasks tasks; TaskLinks taskLinks; @@ -164,9 +90,12 @@ struct PlanDataT; - using Tasks = List; - using TaskLinks = StaticArray; + using Tasks = TaskListT; + using TaskLinks = StaticArrayT; - using TasksBounds = Array; - using TasksBits = BitArray; - using RegionBits = BitArray; + using TasksBounds = ArrayT ; + using TasksBits = BitArrayT; + using RegionBits = BitArrayT; Tasks tasks; TaskLinks taskLinks; @@ -216,9 +145,12 @@ struct PlanDataT> { + void clearTaskStatus (const StateID) noexcept {} + void verifyEmptyStatus(const StateID) const noexcept {} + #ifdef HFSM2_ENABLE_ASSERT - void verifyPlans() const {} + void verifyPlans() const noexcept {} #endif }; diff --git a/include/hfsm2/detail/root/plan_data.inl b/include/hfsm2/detail/root/plan_data.inl index 4f5eebb..bb9ff4b 100644 --- a/include/hfsm2/detail/root/plan_data.inl +++ b/include/hfsm2/detail/root/plan_data.inl @@ -5,12 +5,39 @@ namespace detail { //////////////////////////////////////////////////////////////////////////////// +template +void +PlanDataT>::clearTaskStatus(const StateID stateId) noexcept { + if (stateId != INVALID_STATE_ID) { + tasksSuccesses.clear(stateId); + tasksFailures .clear(stateId); + } +} + +//------------------------------------------------------------------------------ + +template +void +PlanDataT>::verifyEmptyStatus(const StateID HFSM2_IF_ASSERT(stateId)) const noexcept { +#ifdef HFSM2_ENABLE_ASSERT + + if (stateId != INVALID_STATE_ID) { + HFSM2_ASSERT(!tasksSuccesses.get(stateId)); + HFSM2_ASSERT(!tasksFailures .get(stateId)); + } + +#endif +} + +//------------------------------------------------------------------------------ + #ifdef HFSM2_ENABLE_ASSERT template void -PlanDataT>::verifyPlans() const { +PlanDataT>::verifyPlans() const noexcept { Long planCount = 0; + for (RegionID regionId = 0; regionId < REGION_COUNT; ++regionId) planCount += verifyPlan(regionId); @@ -21,7 +48,7 @@ PlanDataT>::verifyPla template Long -PlanDataT>::verifyPlan(const RegionID regionId) const { +PlanDataT>::verifyPlan(const RegionID regionId) const noexcept { Long length = 0; const Bounds& bounds = tasksBounds[regionId]; @@ -40,9 +67,8 @@ PlanDataT>::verifyPla if (fast != INVALID_LONG) { fast = taskLinks[fast].next; - if (fast != INVALID_LONG) { + if (fast != INVALID_LONG) fast = taskLinks[fast].next; - } HFSM2_ASSERT(fast == INVALID_LONG || slow != fast); } @@ -58,12 +84,43 @@ PlanDataT>::verifyPla return length; } +#endif + //////////////////////////////////////////////////////////////////////////////// template void -PlanDataT>::verifyPlans() const { +PlanDataT>::clearTaskStatus(const StateID stateId) noexcept { + if (stateId != INVALID_STATE_ID) { + tasksSuccesses.clear(stateId); + tasksFailures .clear(stateId); + } +} + +//------------------------------------------------------------------------------ + +template +void +PlanDataT>::verifyEmptyStatus(const StateID HFSM2_IF_ASSERT(stateId)) const noexcept { +#ifdef HFSM2_ENABLE_ASSERT + + if (stateId != INVALID_STATE_ID) { + HFSM2_ASSERT(!tasksSuccesses.get(stateId)); + HFSM2_ASSERT(!tasksFailures .get(stateId)); + } + +#endif +} + +//------------------------------------------------------------------------------ + +#ifdef HFSM2_ENABLE_ASSERT + +template +void +PlanDataT>::verifyPlans() const noexcept { Long planCount = 0; + for (RegionID regionId = 0; regionId < REGION_COUNT; ++regionId) planCount += verifyPlan(regionId); @@ -74,7 +131,7 @@ PlanDataT>::verifyPl template Long -PlanDataT>::verifyPlan(const RegionID regionId) const { +PlanDataT>::verifyPlan(const RegionID regionId) const noexcept { Long length = 0; const Bounds& bounds = tasksBounds[regionId]; @@ -93,9 +150,8 @@ PlanDataT>::verifyPl if (fast != INVALID_LONG) { fast = taskLinks[fast].next; - if (fast != INVALID_LONG) { + if (fast != INVALID_LONG) fast = taskLinks[fast].next; - } HFSM2_ASSERT(fast == INVALID_LONG || slow != fast); } diff --git a/include/hfsm2/detail/root/registry.hpp b/include/hfsm2/detail/root/registry.hpp index c4a7507..d2f06cc 100644 --- a/include/hfsm2/detail/root/registry.hpp +++ b/include/hfsm2/detail/root/registry.hpp @@ -20,17 +20,17 @@ enum Strategy { struct alignas(2 * sizeof(Short)) Parent { HFSM2_INLINE Parent() = default; - HFSM2_INLINE Parent(const ForkID forkId_) + HFSM2_INLINE Parent(const ForkID forkId_) noexcept : forkId{forkId_} {} HFSM2_INLINE Parent(const ForkID forkId_, - const Short prong_) + const Short prong_) noexcept : forkId{forkId_} , prong{prong_} {} - HFSM2_INLINE explicit operator bool() const { + HFSM2_INLINE explicit operator bool() const noexcept { return forkId != INVALID_FORK_ID && prong != INVALID_SHORT; } @@ -107,35 +107,35 @@ struct RegistryT; - using StateParents = StaticArray; + using StateParents = StaticArrayT; - using CompoParents = StaticArray; - using OrthoParents = StaticArray; - using OrthoUnits = StaticArray; + using CompoParents = StaticArrayT; + using OrthoParents = StaticArrayT; + using OrthoUnits = StaticArrayT; - using CompoForks = StaticArray; - using OrthoForks = BitArray ; + using CompoForks = StaticArrayT; + using OrthoForks = BitArrayT ; using OrthoBits = typename OrthoForks::Bits; - using CompoRemains = BitArray ; + using CompoRemains = BitArrayT ; using BackUp = BackUpT; - bool isActive (const StateID stateId) const; - bool isResumable (const StateID stateId) const; + bool isActive (const StateID stateId) const noexcept; + bool isResumable (const StateID stateId) const noexcept; - bool isPendingChange (const StateID stateId) const; - bool isPendingEnter (const StateID stateId) const; - bool isPendingExit (const StateID stateId) const; + bool isPendingChange (const StateID stateId) const noexcept; + bool isPendingEnter (const StateID stateId) const noexcept; + bool isPendingExit (const StateID stateId) const noexcept; - HFSM2_INLINE const Parent& forkParent(const ForkID forkId) const; + HFSM2_INLINE const Parent& forkParent(const ForkID forkId) const noexcept; - HFSM2_INLINE OrthoBits requestedOrthoFork(const ForkID forkId); + HFSM2_INLINE OrthoBits requestedOrthoFork(const ForkID forkId) noexcept; - bool requestImmediate(const Transition& request); - void requestScheduled(const StateID stateId); + bool requestImmediate(const Transition& request) noexcept; + void requestScheduled(const StateID stateId) noexcept; - void clearRequests(); - void clear(); + void clearRequests() noexcept; + void clear() noexcept; StateParents stateParents; CompoParents compoParents; @@ -182,29 +182,29 @@ struct RegistryT; - using StateParents = StaticArray; - using CompoParents = StaticArray; + using StateParents = StaticArrayT; + using CompoParents = StaticArrayT; - using CompoForks = StaticArray; - using OrthoForks = BitArray ; - using CompoRemains = BitArray ; + using CompoForks = StaticArrayT; + using OrthoForks = BitArrayT ; + using CompoRemains = BitArrayT ; using BackUp = BackUpT; - bool isActive (const StateID stateId) const; - bool isResumable (const StateID stateId) const; + bool isActive (const StateID stateId) const noexcept; + bool isResumable (const StateID stateId) const noexcept; - bool isPendingChange (const StateID stateId) const; - bool isPendingEnter (const StateID stateId) const; - bool isPendingExit (const StateID stateId) const; + bool isPendingChange (const StateID stateId) const noexcept; + bool isPendingEnter (const StateID stateId) const noexcept; + bool isPendingExit (const StateID stateId) const noexcept; - HFSM2_INLINE const Parent& forkParent(const ForkID forkId) const; + HFSM2_INLINE const Parent& forkParent(const ForkID forkId) const noexcept; - bool requestImmediate(const Transition& request); - void requestScheduled(const StateID stateId); + bool requestImmediate(const Transition& request) noexcept; + void requestScheduled(const StateID stateId) noexcept; - void clearRequests(); - void clear(); + void clearRequests() noexcept; + void clear() noexcept; StateParents stateParents; CompoParents compoParents; @@ -222,7 +222,7 @@ struct RegistryT void backup(const TRegistry& registry, - BackUpT& copy) + BackUpT& copy) noexcept { overwrite(copy.compoRequested, registry.compoRequested); overwrite(copy.orthoRequested, registry.orthoRequested); @@ -234,7 +234,7 @@ backup(const TRegistry& registry, template void restore(TRegistry& registry, - const BackUpT& copy) + const BackUpT& copy) noexcept { overwrite(registry.compoRequested, copy.compoRequested); overwrite(registry.orthoRequested, copy.orthoRequested); diff --git a/include/hfsm2/detail/root/registry_1.inl b/include/hfsm2/detail/root/registry_1.inl index 93a6f9a..12ec93c 100644 --- a/include/hfsm2/detail/root/registry_1.inl +++ b/include/hfsm2/detail/root/registry_1.inl @@ -5,7 +5,7 @@ namespace detail { template bool -RegistryT>::isActive(const StateID stateId) const { +RegistryT>::isActive(const StateID stateId) const noexcept { if (HFSM2_CHECKED(stateId < STATE_COUNT)) for (Parent parent = stateParents[stateId]; parent; @@ -24,7 +24,7 @@ RegistryT bool -RegistryT>::isResumable(const StateID stateId) const { +RegistryT>::isResumable(const StateID stateId) const noexcept { if (HFSM2_CHECKED(stateId < STATE_COUNT)) for (Parent parent = stateParents[stateId]; parent; @@ -43,7 +43,7 @@ RegistryT bool -RegistryT>::isPendingChange(const StateID stateId) const { +RegistryT>::isPendingChange(const StateID stateId) const noexcept { if (HFSM2_CHECKED(stateId < STATE_COUNT)) for (Parent parent = stateParents[stateId]; parent; @@ -63,7 +63,7 @@ RegistryT bool -RegistryT>::isPendingEnter(const StateID stateId) const { +RegistryT>::isPendingEnter(const StateID stateId) const noexcept { if (HFSM2_CHECKED(stateId < STATE_COUNT)) for (Parent parent = stateParents[stateId]; parent; @@ -83,7 +83,7 @@ RegistryT bool -RegistryT>::isPendingExit(const StateID stateId) const { +RegistryT>::isPendingExit(const StateID stateId) const noexcept { if (HFSM2_CHECKED(stateId < STATE_COUNT)) for (Parent parent = stateParents[stateId]; parent; @@ -103,7 +103,7 @@ RegistryT const Parent& -RegistryT>::forkParent(const ForkID forkId) const { +RegistryT>::forkParent(const ForkID forkId) const noexcept { HFSM2_ASSERT(forkId != 0); return forkId > 0 ? @@ -115,7 +115,7 @@ RegistryT typename RegistryT>::OrthoBits -RegistryT>::requestedOrthoFork(const ForkID forkId) { +RegistryT>::requestedOrthoFork(const ForkID forkId) noexcept { HFSM2_ASSERT(forkId < 0); const Units& units = orthoUnits[-forkId - 1]; @@ -126,7 +126,7 @@ RegistryT bool -RegistryT>::requestImmediate(const Transition& request) { +RegistryT>::requestImmediate(const Transition& request) noexcept { if (request.destination == 0) return false; else if (HFSM2_CHECKED(request.destination < STATE_COUNT)) { @@ -180,7 +180,7 @@ RegistryT void -RegistryT>::requestScheduled(const StateID stateId) { +RegistryT>::requestScheduled(const StateID stateId) noexcept { if (HFSM2_CHECKED(stateId < STATE_COUNT)) { const Parent parent = stateParents[stateId]; @@ -194,7 +194,7 @@ RegistryT void -RegistryT>::clearRequests() { +RegistryT>::clearRequests() noexcept { compoRequested.clear(); orthoRequested.clear(); compoRemains .clear(); @@ -204,7 +204,7 @@ RegistryT void -RegistryT>::clear() { +RegistryT>::clear() noexcept { clearRequests(); compoActive .clear(); diff --git a/include/hfsm2/detail/root/registry_2.inl b/include/hfsm2/detail/root/registry_2.inl index 8276265..69f15ef 100644 --- a/include/hfsm2/detail/root/registry_2.inl +++ b/include/hfsm2/detail/root/registry_2.inl @@ -5,7 +5,7 @@ namespace detail { template bool -RegistryT>::isActive(const StateID stateId) const { +RegistryT>::isActive(const StateID stateId) const noexcept { if (HFSM2_CHECKED(stateId < STATE_COUNT)) { if (Parent parent = stateParents[stateId]) { HFSM2_ASSERT(parent.forkId > 0); @@ -22,7 +22,7 @@ RegistryT bool -RegistryT>::isResumable(const StateID stateId) const { +RegistryT>::isResumable(const StateID stateId) const noexcept { if (HFSM2_CHECKED(stateId < STATE_COUNT)) if (Parent parent = stateParents[stateId]) { HFSM2_ASSERT(parent.forkId > 0); @@ -37,7 +37,7 @@ RegistryT bool -RegistryT>::isPendingChange(const StateID stateId) const { +RegistryT>::isPendingChange(const StateID stateId) const noexcept { if (HFSM2_CHECKED(stateId < STATE_COUNT)) if (Parent parent = stateParents[stateId]) { HFSM2_ASSERT(parent.forkId > 0); @@ -53,7 +53,7 @@ RegistryT bool -RegistryT>::isPendingEnter(const StateID stateId) const { +RegistryT>::isPendingEnter(const StateID stateId) const noexcept { if (HFSM2_CHECKED(stateId < STATE_COUNT)) if (Parent parent = stateParents[stateId]) { HFSM2_ASSERT(parent.forkId > 0); @@ -69,7 +69,7 @@ RegistryT bool -RegistryT>::isPendingExit(const StateID stateId) const { +RegistryT>::isPendingExit(const StateID stateId) const noexcept { if (HFSM2_CHECKED(stateId < STATE_COUNT)) if (Parent parent = stateParents[stateId]) { HFSM2_ASSERT(parent.forkId > 0); @@ -85,7 +85,7 @@ RegistryT const Parent& -RegistryT>::forkParent(const ForkID forkId) const { +RegistryT>::forkParent(const ForkID forkId) const noexcept { HFSM2_ASSERT(forkId > 0); return compoParents[forkId - 1]; @@ -95,7 +95,7 @@ RegistryT bool -RegistryT>::requestImmediate(const Transition& request) { +RegistryT>::requestImmediate(const Transition& request) noexcept { // record request // promote it to all children @@ -138,7 +138,7 @@ RegistryT void -RegistryT>::requestScheduled(const StateID stateId) { +RegistryT>::requestScheduled(const StateID stateId) noexcept { if (HFSM2_CHECKED(stateId < STATE_COUNT)) { const Parent parent = stateParents[stateId]; @@ -151,7 +151,7 @@ RegistryT void -RegistryT>::clearRequests() { +RegistryT>::clearRequests() noexcept { compoRequested.clear(); orthoRequested.clear(); compoRemains .clear(); @@ -161,7 +161,7 @@ RegistryT void -RegistryT>::clear() { +RegistryT>::clear() noexcept { clearRequests(); compoActive .clear(); diff --git a/include/hfsm2/detail/root/state_access.hpp b/include/hfsm2/detail/root/state_access.hpp index d68a527..8030915 100644 --- a/include/hfsm2/detail/root/state_access.hpp +++ b/include/hfsm2/detail/root/state_access.hpp @@ -19,7 +19,7 @@ template > { using Host = C_; - HFSM2_INLINE T& get() { return Accessor{host._subStates}.get(); } + HFSM2_INLINE T& get() noexcept { return Accessor{host._subStates}.get(); } Host& host; }; @@ -35,7 +35,7 @@ template > { using Host = const C_; - HFSM2_INLINE const T& get() const { return Accessor{host._subStates}.get(); } + HFSM2_INLINE const T& get() const noexcept { return Accessor{host._subStates}.get(); } Host& host; }; @@ -50,7 +50,7 @@ template > { using Host = C_; - HFSM2_INLINE T& get() { return host._headState._headBox.get(); } + HFSM2_INLINE T& get() noexcept { return host._headState._headBox.get(); } Host& host; }; @@ -65,7 +65,7 @@ template > { using Host = const C_; - HFSM2_INLINE const T& get() const { return host._headState._headBox.get(); } + HFSM2_INLINE const T& get() const noexcept { return host._headState._headBox.get(); } Host& host; }; @@ -81,7 +81,7 @@ template > { using Host = CS_; - HFSM2_INLINE T& get() { + HFSM2_INLINE T& get() noexcept { return contains() ? Accessor{host.lHalf}.get() : Accessor{host.rHalf}.get(); @@ -101,7 +101,7 @@ template > { using Host = const CS_; - HFSM2_INLINE const T& get() const { + HFSM2_INLINE const T& get() const noexcept { return contains() ? Accessor{host.lHalf}.get() : Accessor{host.rHalf}.get(); @@ -121,7 +121,7 @@ template > { using Host = CS_; - HFSM2_INLINE T& get() { return Accessor{host.state}.get(); } + HFSM2_INLINE T& get() noexcept { return Accessor{host.state}.get(); } Host& host; }; @@ -137,7 +137,7 @@ template > { using Host = const CS_; - HFSM2_INLINE const T& get() const { return Accessor{host.state}.get(); } + HFSM2_INLINE const T& get() const noexcept { return Accessor{host.state}.get(); } Host& host; }; @@ -152,7 +152,7 @@ template > { using Host = O_; - HFSM2_INLINE T& get() { return Accessor{host._subStates}.get(); } + HFSM2_INLINE T& get() noexcept { return Accessor{host._subStates}.get(); } Host& host; }; @@ -167,7 +167,7 @@ template > { using Host = const O_; - HFSM2_INLINE const T& get() const { return Accessor{host._subStates}.get(); } + HFSM2_INLINE const T& get() const noexcept { return Accessor{host._subStates}.get(); } Host& host; }; @@ -181,7 +181,7 @@ template > { using Host = O_; - HFSM2_INLINE T& get() { return host._headState._headBox.get(); } + HFSM2_INLINE T& get() noexcept { return host._headState._headBox.get(); } Host& host; }; @@ -195,7 +195,7 @@ template > { using Host = const O_; - HFSM2_INLINE const T& get() const { return host._headState._headBox.get(); } + HFSM2_INLINE const T& get() const noexcept { return host._headState._headBox.get(); } Host& host; }; @@ -210,7 +210,7 @@ template > { using Host = OS_; - HFSM2_INLINE T& get() { + HFSM2_INLINE T& get() noexcept { return contains() ? Accessor{host.initial }.get() : Accessor{host.remaining}.get(); @@ -229,7 +229,7 @@ template > { using Host = const OS_; - HFSM2_INLINE const T& get() const { + HFSM2_INLINE const T& get() const noexcept { return contains() ? Accessor{host.initial }.get() : Accessor{host.remaining}.get(); @@ -248,7 +248,7 @@ template > { using Host = OS_; - HFSM2_INLINE T& get() { return Accessor{host.initial }.get(); } + HFSM2_INLINE T& get() noexcept { return Accessor{host.initial }.get(); } Host& host; }; @@ -263,7 +263,7 @@ template > { using Host = const OS_; - HFSM2_INLINE const T& get() const { return Accessor{host.initial }.get(); } + HFSM2_INLINE const T& get() const noexcept { return Accessor{host.initial }.get(); } Host& host; }; @@ -283,7 +283,7 @@ template > { using Host = S_; - HFSM2_INLINE T& get() { HFSM2_BREAK(); return *reinterpret_cast(0); } + HFSM2_INLINE T& get() noexcept { HFSM2_BREAK(); return *reinterpret_cast(0); } Host& host; }; @@ -297,7 +297,7 @@ template > { using Host = const S_; - HFSM2_INLINE const T& get() const { HFSM2_BREAK(); return *reinterpret_cast(0); } + HFSM2_INLINE const T& get() const noexcept { HFSM2_BREAK(); return *reinterpret_cast(0); } Host& host; }; @@ -314,7 +314,7 @@ template > { using Host = S_; - HFSM2_INLINE T& get() { return host._headBox.get(); } + HFSM2_INLINE T& get() noexcept { return host._headBox.get(); } Host& host; }; @@ -327,7 +327,7 @@ template > { using Host = const S_; - HFSM2_INLINE const T& get() const { return host._headBox.get(); } + HFSM2_INLINE const T& get() const noexcept { return host._headBox.get(); } Host& host; }; diff --git a/include/hfsm2/detail/root/task_list.hpp b/include/hfsm2/detail/root/task_list.hpp new file mode 100644 index 0000000..ab7a8f5 --- /dev/null +++ b/include/hfsm2/detail/root/task_list.hpp @@ -0,0 +1,149 @@ +#ifdef HFSM2_ENABLE_PLANS + +namespace hfsm2 { +namespace detail { + +//////////////////////////////////////////////////////////////////////////////// + +#pragma pack(push, 1) + +struct TaskBase { + HFSM2_INLINE TaskBase() noexcept {} + + HFSM2_INLINE TaskBase(const StateID origin_, + const StateID destination_, + const TransitionType type_) noexcept + : origin{origin_} + , destination{destination_} + , type{type_} + {} + + static_assert(sizeof(Long) == sizeof(StateID), ""); + + union { + StateID origin = INVALID_STATE_ID; + Long prev; + }; + + union { + StateID destination = INVALID_STATE_ID; + Long next; + }; + + TransitionType type = TransitionType::COUNT; +}; + +inline bool operator == (const TaskBase& lhs, const TaskBase& rhs) noexcept { + return lhs.origin == rhs.origin && + lhs.destination == rhs.destination && + lhs.type == rhs.type; +} + +//------------------------------------------------------------------------------ + +template +struct TaskT + : TaskBase +{ + using Payload = TPayload; + using Storage = typename std::aligned_storage::type; + + using TaskBase::TaskBase; + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + HFSM2_INLINE TaskT() noexcept { + new (&storage) Payload{}; + } + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + HFSM2_INLINE TaskT(const StateID origin, + const StateID destination, + const TransitionType type, + const Payload& payload) noexcept + : TaskBase{origin, destination, type} + , payloadSet{true} + { + new (&storage) Payload{payload}; + } + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + HFSM2_INLINE TaskT(const StateID origin, + const StateID destination, + const TransitionType type, + Payload&& payload) noexcept + : TaskBase{origin, destination, type} + , payloadSet{true} + { + new (&storage) Payload{std::move(payload)}; + } + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + Storage storage; + bool payloadSet = false; +}; + +//------------------------------------------------------------------------------ + +template <> +struct TaskT + : TaskBase +{ + using TaskBase::TaskBase; +}; + +#pragma pack(pop) + +//////////////////////////////////////////////////////////////////////////////// + +template +class TaskListT { +public: + using Index = Long; + + static constexpr Index CAPACITY = NCapacity; + + static constexpr Index INVALID = Index (-1); + +private: + using Payload = TPayload; + using Item = TaskT; + +public: + template + Index emplace(TArgs&&... args) noexcept; + + void remove(const Index i) noexcept; + + HFSM2_INLINE Item& operator[] (const Index i) noexcept; + HFSM2_INLINE const Item& operator[] (const Index i) const noexcept; + + HFSM2_INLINE Index count() const noexcept { return _count; } + +private: + HFSM2_IF_ASSERT(void verifyStructure(const Index occupied = INVALID) const noexcept); + +private: + Item _items[CAPACITY]; + Index _vacantHead = 0; + Index _vacantTail = 0; + Index _last = 0; + Index _count = 0; +}; + +//------------------------------------------------------------------------------ + +template +class TaskListT {}; + +//////////////////////////////////////////////////////////////////////////////// + +} +} + +#include "task_list.inl" + +#endif diff --git a/include/hfsm2/detail/shared/list.inl b/include/hfsm2/detail/root/task_list.inl similarity index 72% rename from include/hfsm2/detail/shared/list.inl rename to include/hfsm2/detail/root/task_list.inl index 25c7084..0de5617 100644 --- a/include/hfsm2/detail/shared/list.inl +++ b/include/hfsm2/detail/root/task_list.inl @@ -1,18 +1,20 @@ +#ifdef HFSM2_ENABLE_PLANS + namespace hfsm2 { namespace detail { //////////////////////////////////////////////////////////////////////////////// -template +template template Long -List::emplace(TA... args) { +TaskListT::emplace(TA&&... args) noexcept { if (_count < CAPACITY) { HFSM2_ASSERT(_vacantHead < CAPACITY); HFSM2_ASSERT(_vacantTail < CAPACITY); const Index index = _vacantHead; - auto& cell = _cells[index]; + auto& cell = _items[index]; ++_count; if (_vacantHead != _vacantTail) { @@ -22,7 +24,7 @@ List::emplace(TA... args) { _vacantHead = cell.next; - auto& head = _cells[_vacantHead]; + auto& head = _items[_vacantHead]; HFSM2_ASSERT(head.prev == index); head.prev = INVALID; } else if (_last < CAPACITY - 1) { @@ -31,7 +33,7 @@ List::emplace(TA... args) { _vacantHead = _last; _vacantTail = _last; - auto& vacant = _cells[_vacantHead]; + auto& vacant = _items[_vacantHead]; vacant.prev = INVALID; vacant.next = INVALID; } else { @@ -43,7 +45,7 @@ List::emplace(TA... args) { HFSM2_IF_ASSERT(verifyStructure()); - new (&cell.item) Item{std::forward(args)...}; + new (&cell) Item{std::forward(args)...}; return index; } else { @@ -59,12 +61,12 @@ List::emplace(TA... args) { //------------------------------------------------------------------------------ -template +template void -List::remove(const Index i) { +TaskListT::remove(const Index i) noexcept { HFSM2_ASSERT(i < CAPACITY && _count); - auto& fresh = _cells[i]; + auto& fresh = _items[i]; if (_count < CAPACITY) { HFSM2_ASSERT(_vacantHead < CAPACITY); @@ -73,7 +75,7 @@ List::remove(const Index i) { fresh.prev = INVALID; fresh.next = _vacantHead; - auto& head = _cells[_vacantHead]; + auto& head = _items[_vacantHead]; head.prev = i; _vacantHead = i; @@ -97,49 +99,49 @@ List::remove(const Index i) { //------------------------------------------------------------------------------ -template -T& -List::operator[] (const Index i) { +template +typename TaskListT::Item& +TaskListT::operator[] (const Index i) noexcept { HFSM2_IF_ASSERT(verifyStructure()); - return _cells[i].item; + return _items[i]; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -template -const T& -List::operator[] (const Index i) const { +template +const typename TaskListT::Item& +TaskListT::operator[] (const Index i) const noexcept { HFSM2_IF_ASSERT(verifyStructure()); - return _cells[i].item; + return _items[i]; } //------------------------------------------------------------------------------ #ifdef HFSM2_ENABLE_ASSERT -template +template void -List::verifyStructure(const Index occupied) const { +TaskListT::verifyStructure(const Index occupied) const noexcept { if (_count < CAPACITY) { HFSM2_ASSERT(_vacantHead < CAPACITY); HFSM2_ASSERT(_vacantTail < CAPACITY); - HFSM2_ASSERT(_cells[_vacantHead].prev == INVALID); - HFSM2_ASSERT(_cells[_vacantTail].next == INVALID); + HFSM2_ASSERT(_items[_vacantHead].prev == INVALID); + HFSM2_ASSERT(_items[_vacantTail].next == INVALID); auto emptyCount = 1; for (auto c = _vacantHead; c != _vacantTail; ) { HFSM2_ASSERT(occupied != c); - const auto& current = _cells[c]; + const auto& current = _items[c]; const auto f = current.next; if (f != INVALID) { // next - const auto& following = _cells[f]; + const auto& following = _items[f]; HFSM2_ASSERT(following.prev == c); @@ -165,3 +167,5 @@ List::verifyStructure(const Index occupied) const { } } + +#endif diff --git a/include/hfsm2/detail/shared/array.hpp b/include/hfsm2/detail/shared/array.hpp index 9683d3f..8fbd3a7 100644 --- a/include/hfsm2/detail/shared/array.hpp +++ b/include/hfsm2/detail/shared/array.hpp @@ -4,7 +4,7 @@ namespace detail { //////////////////////////////////////////////////////////////////////////////// template -class StaticArray { +class StaticArrayT { public: static constexpr Long CAPACITY = NCapacity; static constexpr Long DUMMY = INVALID_LONG; @@ -13,27 +13,27 @@ class StaticArray { using Index = UnsignedCapacity; public: - HFSM2_INLINE StaticArray() = default; - HFSM2_INLINE StaticArray(const Item filler); + HFSM2_INLINE StaticArrayT() = default; + HFSM2_INLINE StaticArrayT(const Item filler) noexcept; template - HFSM2_INLINE Item& operator[] (const N i); + HFSM2_INLINE Item& operator[] (const N i) noexcept; template - HFSM2_INLINE const Item& operator[] (const N i) const; + HFSM2_INLINE const Item& operator[] (const N i) const noexcept; - HFSM2_INLINE Long count() const { return CAPACITY; } + HFSM2_INLINE Long count() const noexcept { return CAPACITY; } - HFSM2_INLINE void fill(const Item filler); - HFSM2_INLINE void clear() { fill(INVALID_SHORT); } + HFSM2_INLINE void fill(const Item filler) noexcept; + HFSM2_INLINE void clear() noexcept { fill(INVALID_SHORT); } - HFSM2_INLINE Iterator< StaticArray> begin() { return Iterator< StaticArray>(*this, 0); } - HFSM2_INLINE Iterator begin() const { return Iterator(*this, 0); } - HFSM2_INLINE Iterator cbegin() const { return Iterator(*this, 0); } + HFSM2_INLINE IteratorT< StaticArrayT> begin() noexcept { return IteratorT< StaticArrayT>(*this, 0); } + HFSM2_INLINE IteratorT begin() const noexcept { return IteratorT(*this, 0); } + HFSM2_INLINE IteratorT cbegin() const noexcept { return IteratorT(*this, 0); } - HFSM2_INLINE Iterator< StaticArray> end() { return Iterator< StaticArray>(*this, DUMMY); } - HFSM2_INLINE Iterator end() const { return Iterator(*this, DUMMY); } - HFSM2_INLINE Iterator cend() const { return Iterator(*this, DUMMY); } + HFSM2_INLINE IteratorT< StaticArrayT> end() noexcept { return IteratorT< StaticArrayT>(*this, DUMMY); } + HFSM2_INLINE IteratorT end() const noexcept { return IteratorT(*this, DUMMY); } + HFSM2_INLINE IteratorT cend() const noexcept { return IteratorT(*this, DUMMY); } private: Item _items[CAPACITY]; @@ -42,19 +42,19 @@ class StaticArray { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - template -struct StaticArray { +struct StaticArrayT { using Item = T; - HFSM2_INLINE StaticArray() = default; - HFSM2_INLINE StaticArray(const Item) {} + HFSM2_INLINE StaticArrayT() = default; + HFSM2_INLINE StaticArrayT(const Item) noexcept {} }; //------------------------------------------------------------------------------ template -class Array { +class ArrayT { template - friend class Iterator; + friend class IteratorT; public: static constexpr Long CAPACITY = NCapacity; @@ -64,37 +64,37 @@ class Array { using Index = UnsignedCapacity; public: - HFSM2_INLINE void clear() { _count = 0; } + HFSM2_INLINE void clear() noexcept { _count = 0; } // TODO: replace with 'emplace<>()'? template - HFSM2_INLINE Long append(const TValue& value); + HFSM2_INLINE Long append(const TValue& value) noexcept; template - HFSM2_INLINE Long append(TValue&& value); + HFSM2_INLINE Long append( TValue&& value) noexcept; template - HFSM2_INLINE Item& operator[] (const N i); + HFSM2_INLINE Item& operator[] (const N i) noexcept; template - HFSM2_INLINE const Item& operator[] (const N i) const; + HFSM2_INLINE const Item& operator[] (const N i) const noexcept; - HFSM2_INLINE Long count() const { return _count; } + HFSM2_INLINE Long count() const noexcept { return _count; } template - Array& operator += (const Array& other); + HFSM2_INLINE ArrayT& operator += (const ArrayT& other) noexcept; - HFSM2_INLINE Iterator< Array> begin() { return Iterator< Array>(*this, 0); } - HFSM2_INLINE Iterator begin() const { return Iterator(*this, 0); } - HFSM2_INLINE Iterator cbegin() const { return Iterator(*this, 0); } + HFSM2_INLINE IteratorT< ArrayT> begin() noexcept { return IteratorT< ArrayT>(*this, 0); } + HFSM2_INLINE IteratorT begin() const noexcept { return IteratorT(*this, 0); } + HFSM2_INLINE IteratorT cbegin() const noexcept { return IteratorT(*this, 0); } - HFSM2_INLINE Iterator< Array> end() { return Iterator< Array>(*this, DUMMY); } - HFSM2_INLINE Iterator end() const { return Iterator(*this, DUMMY); } - HFSM2_INLINE Iterator cend() const { return Iterator(*this, DUMMY); } + HFSM2_INLINE IteratorT< ArrayT> end() noexcept { return IteratorT< ArrayT>(*this, DUMMY); } + HFSM2_INLINE IteratorT end() const noexcept { return IteratorT(*this, DUMMY); } + HFSM2_INLINE IteratorT cend() const noexcept { return IteratorT(*this, DUMMY); } private: - HFSM2_INLINE Long next(const Long i) const { return i + 1; } - HFSM2_INLINE Long limit() const { return _count; } + HFSM2_INLINE Long next(const Long i) const noexcept { return i + 1; } + HFSM2_INLINE Long limit() const noexcept { return _count; } private: Long _count = 0; @@ -114,7 +114,7 @@ class Array { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - template -class Array { +class ArrayT { public: static constexpr Long CAPACITY = 0; static constexpr Long DUMMY = INVALID_LONG; diff --git a/include/hfsm2/detail/shared/array.inl b/include/hfsm2/detail/shared/array.inl index fa58692..45e57c9 100644 --- a/include/hfsm2/detail/shared/array.inl +++ b/include/hfsm2/detail/shared/array.inl @@ -4,7 +4,7 @@ namespace detail { //////////////////////////////////////////////////////////////////////////////// template -StaticArray::StaticArray(const Item filler) { +StaticArrayT::StaticArrayT(const Item filler) noexcept { fill(filler); } @@ -13,7 +13,7 @@ StaticArray::StaticArray(const Item filler) { template template T& -StaticArray::operator[] (const N i) { +StaticArrayT::operator[] (const N i) noexcept { HFSM2_ASSERT(0 <= i && i < CAPACITY); return _items[(Index) i]; @@ -24,7 +24,7 @@ StaticArray::operator[] (const N i) { template template const T& -StaticArray::operator[] (const N i) const { +StaticArrayT::operator[] (const N i) const noexcept { HFSM2_ASSERT(0 <= i && i < CAPACITY); return _items[(Index) i]; @@ -34,7 +34,7 @@ StaticArray::operator[] (const N i) const { template void -StaticArray::fill(const Item filler) { +StaticArrayT::fill(const Item filler) noexcept { for (Long i = 0; i < CAPACITY; ++i) _items[i] = filler; } @@ -44,7 +44,7 @@ StaticArray::fill(const Item filler) { template template Long -Array::append(const TValue& value) { +ArrayT::append(const TValue& value) noexcept { HFSM2_ASSERT(_count < CAPACITY); new (&_items[_count]) Item{value}; @@ -57,7 +57,7 @@ Array::append(const TValue& value) { template template Long -Array::append(TValue&& value) { +ArrayT::append(TValue&& value) noexcept { HFSM2_ASSERT(_count < CAPACITY); new (&_items[_count]) Item{std::move(value)}; @@ -70,7 +70,7 @@ Array::append(TValue&& value) { template template T& -Array::operator[] (const N i) { +ArrayT::operator[] (const N i) noexcept { HFSM2_ASSERT(0 <= i && i < CAPACITY); return _items[(Index) i]; @@ -81,7 +81,7 @@ Array::operator[] (const N i) { template template const T& -Array::operator[] (const N i) const { +ArrayT::operator[] (const N i) const noexcept { HFSM2_ASSERT(0 <= i && i < CAPACITY); return _items[(Index) i]; @@ -91,8 +91,8 @@ Array::operator[] (const N i) const { template template -Array& -Array::operator += (const Array& other) { +ArrayT& +ArrayT::operator += (const ArrayT& other) noexcept { for (const auto& item : other) append(item); diff --git a/include/hfsm2/detail/shared/bit_array.hpp b/include/hfsm2/detail/shared/bit_array.hpp index 2c076b5..ac3f772 100644 --- a/include/hfsm2/detail/shared/bit_array.hpp +++ b/include/hfsm2/detail/shared/bit_array.hpp @@ -5,7 +5,7 @@ namespace detail { struct Units { inline Units(Short unit_ = INVALID_SHORT, - Short width_ = INVALID_SHORT) + Short width_ = INVALID_SHORT) noexcept : unit {unit_ } , width{width_} {} @@ -16,44 +16,46 @@ struct Units { //------------------------------------------------------------------------------ -template -class BitArray final { +template +class BitArrayT final { public: using Index = TIndex; using Unit = unsigned char; - static constexpr Index CAPACITY = NCapacity; + static constexpr Index UNIT_COUNT = NUnitCount; + static constexpr Index UNIT_WIDTH = sizeof(Unit) * 8; + static constexpr Index BIT_COUNT = UNIT_COUNT * UNIT_WIDTH; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - class Bits { template - friend class BitArray; + friend class BitArrayT; private: HFSM2_INLINE explicit Bits(Unit* const storage, - const Index width) + const Index width) noexcept : _storage{storage} , _width{width} {} public: - HFSM2_INLINE explicit operator bool() const; + HFSM2_INLINE explicit operator bool() const noexcept; - HFSM2_INLINE void clear(); + HFSM2_INLINE void clear() noexcept; template - HFSM2_INLINE bool get() const; + HFSM2_INLINE bool get() const noexcept; template - HFSM2_INLINE void set(); + HFSM2_INLINE void set() noexcept; template - HFSM2_INLINE void clear(); + HFSM2_INLINE void clear() noexcept; - HFSM2_INLINE bool get (const Index index) const; - HFSM2_INLINE void set (const Index index); - HFSM2_INLINE void clear(const Index index); + HFSM2_INLINE bool get (const Index index) const noexcept; + HFSM2_INLINE void set (const Index index) noexcept; + HFSM2_INLINE void clear(const Index index) noexcept; private: Unit* const _storage; @@ -62,24 +64,24 @@ class BitArray final { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - class ConstBits { + class CBits { template - friend class BitArray; + friend class BitArrayT; private: - HFSM2_INLINE explicit ConstBits(const Unit* const storage, - const Index width) + HFSM2_INLINE explicit CBits(const Unit* const storage, + const Index width) noexcept : _storage{storage} , _width{width} {} public: - HFSM2_INLINE explicit operator bool() const; + HFSM2_INLINE explicit operator bool() const noexcept; template - HFSM2_INLINE bool get() const; + HFSM2_INLINE bool get() const noexcept; - HFSM2_INLINE bool get(const Index index) const; + HFSM2_INLINE bool get(const Index index) const noexcept; private: const Unit* const _storage; @@ -89,45 +91,44 @@ class BitArray final { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - public: - BitArray() { + BitArrayT() noexcept { clear(); } - HFSM2_INLINE void clear(); + HFSM2_INLINE void clear() noexcept; template - HFSM2_INLINE bool get() const; + HFSM2_INLINE bool get() const noexcept; template - HFSM2_INLINE void set(); + HFSM2_INLINE void set() noexcept; template - HFSM2_INLINE void clear(); + HFSM2_INLINE void clear() noexcept; - HFSM2_INLINE bool get (const Index index) const; - HFSM2_INLINE void set (const Index index); - HFSM2_INLINE void clear(const Index index); + HFSM2_INLINE bool get (const Index index) const noexcept; + HFSM2_INLINE void set (const Index index) noexcept; + HFSM2_INLINE void clear(const Index index) noexcept; template - HFSM2_INLINE Bits bits(); + HFSM2_INLINE Bits bits() noexcept; template - HFSM2_INLINE ConstBits bits() const; + HFSM2_INLINE CBits bits() const noexcept; - - HFSM2_INLINE Bits bits(const Units& units); - HFSM2_INLINE ConstBits bits(const Units& units) const; + HFSM2_INLINE Bits bits(const Units& units) noexcept; + HFSM2_INLINE CBits bits(const Units& units) const noexcept; private: - Unit _storage[CAPACITY]; + Unit _storage[UNIT_COUNT]; }; //------------------------------------------------------------------------------ template -class BitArray final { +class BitArrayT final { public: - HFSM2_INLINE void clear() {} + HFSM2_INLINE void clear() noexcept {} }; //////////////////////////////////////////////////////////////////////////////// diff --git a/include/hfsm2/detail/shared/bit_array.inl b/include/hfsm2/detail/shared/bit_array.inl index 7ccc8d2..e8fa96c 100644 --- a/include/hfsm2/detail/shared/bit_array.inl +++ b/include/hfsm2/detail/shared/bit_array.inl @@ -4,15 +4,15 @@ namespace detail { //////////////////////////////////////////////////////////////////////////////// template -BitArray::Bits::operator bool() const { - const Short fullUnits = _width / (sizeof(Unit) * 8); +BitArrayT::Bits::operator bool() const noexcept { + const Short fullUnits = _width / UNIT_WIDTH; // TODO: cover this case for (Index i = 0; i < fullUnits; ++i) if (_storage[i]) return true; - const Short bit = _width % (sizeof(Unit) * 8); + const Short bit = _width % UNIT_WIDTH; const Unit mask = (1 << bit) - 1; const Unit& u = _storage[fullUnits]; @@ -23,10 +23,10 @@ BitArray::Bits::operator bool() const { template void -BitArray::Bits::clear() { - const Index count = (_width + 7) / (sizeof(Unit) * 8); +BitArrayT::Bits::clear() noexcept { + const Index unitCount = contain(_width, UNIT_WIDTH); - for (Index i = 0; i < count; ++i) + for (Index i = 0; i < unitCount; ++i) _storage[i] = Unit{0}; } @@ -35,12 +35,12 @@ BitArray::Bits::clear() { template template bool -BitArray::Bits::get() const { +BitArrayT::Bits::get() const noexcept { constexpr Index INDEX = NIndex; HFSM2_ASSERT(INDEX < _width); - constexpr Index BIT_UNIT = INDEX / (sizeof(Unit) * 8); - constexpr Index BIT_INDEX = INDEX % (sizeof(Unit) * 8); + constexpr Index BIT_UNIT = INDEX / UNIT_WIDTH; + constexpr Index BIT_INDEX = INDEX % UNIT_WIDTH; constexpr Unit MASK = 1 << BIT_INDEX; return (_storage[BIT_UNIT] & MASK) != 0; @@ -51,12 +51,12 @@ BitArray::Bits::get() const { template template void -BitArray::Bits::set() { +BitArrayT::Bits::set() noexcept { constexpr Index INDEX = NIndex; HFSM2_ASSERT(INDEX < _width); - constexpr Index BIT_UNIT = INDEX / (sizeof(Unit) * 8); - constexpr Index BIT_INDEX = INDEX % (sizeof(Unit) * 8); + constexpr Index BIT_UNIT = INDEX / UNIT_WIDTH; + constexpr Index BIT_INDEX = INDEX % UNIT_WIDTH; constexpr Unit MASK = 1 << BIT_INDEX; _storage[BIT_UNIT] |= MASK; @@ -67,12 +67,12 @@ BitArray::Bits::set() { template template void -BitArray::Bits::clear() { +BitArrayT::Bits::clear() noexcept { constexpr Index INDEX = NIndex; HFSM2_ASSERT(INDEX < _width); - constexpr Index BIT_UNIT = INDEX / (sizeof(Unit) * 8); - constexpr Index BIT_INDEX = INDEX % (sizeof(Unit) * 8); + constexpr Index BIT_UNIT = INDEX / UNIT_WIDTH; + constexpr Index BIT_INDEX = INDEX % UNIT_WIDTH; constexpr Unit MASK = 1 << BIT_INDEX; _storage[BIT_UNIT] &= ~MASK; @@ -82,11 +82,11 @@ BitArray::Bits::clear() { template bool -BitArray::Bits::get(const Index index) const { +BitArrayT::Bits::get(const Index index) const noexcept { HFSM2_ASSERT(index < _width); - const Index unit = index / (sizeof(Unit) * 8); - const Index bit = index % (sizeof(Unit) * 8); + const Index unit = index / UNIT_WIDTH; + const Index bit = index % UNIT_WIDTH; const Unit mask = 1 << bit; return (_storage[unit] & mask) != 0; @@ -96,11 +96,11 @@ BitArray::Bits::get(const Index index) const { template void -BitArray::Bits::set(const Index index) { +BitArrayT::Bits::set(const Index index) noexcept { HFSM2_ASSERT(index < _width); - const Index unit = index / (sizeof(Unit) * 8); - const Index bit = index % (sizeof(Unit) * 8); + const Index unit = index / UNIT_WIDTH; + const Index bit = index % UNIT_WIDTH; const Unit mask = 1 << bit; _storage[unit] |= mask; @@ -110,11 +110,11 @@ BitArray::Bits::set(const Index index) { template void -BitArray::Bits::clear(const Index index) { +BitArrayT::Bits::clear(const Index index) noexcept { HFSM2_ASSERT(index < _width); - const Index unit = index / (sizeof(Unit) * 8); - const Index bit = index % (sizeof(Unit) * 8); + const Index unit = index / UNIT_WIDTH; + const Index bit = index % UNIT_WIDTH; const Unit mask = 1 << bit; _storage[unit] &= ~mask; @@ -123,14 +123,14 @@ BitArray::Bits::clear(const Index index) { //////////////////////////////////////////////////////////////////////////////// template -BitArray::ConstBits::operator bool() const { - const Short fullUnits = _width / (sizeof(Unit) * 8); +BitArrayT::CBits::operator bool() const noexcept { + const Short fullUnits = _width / UNIT_WIDTH; for (Index i = 0; i < fullUnits; ++i) if (_storage[i]) return true; - const Short bit = _width % (sizeof(Unit) * 8); + const Short bit = _width % UNIT_WIDTH; const Unit mask = (1 << bit) - 1; const Unit& u = _storage[fullUnits]; @@ -142,12 +142,12 @@ BitArray::ConstBits::operator bool() const { template template bool -BitArray::ConstBits::get() const { +BitArrayT::CBits::get() const noexcept { constexpr Index INDEX = NIndex; static_assert(INDEX < _width, ""); - constexpr Index BIT_UNIT = INDEX / (sizeof(Unit) * 8); - constexpr Index BIT_INDEX = INDEX % (sizeof(Unit) * 8); + constexpr Index BIT_UNIT = INDEX / UNIT_WIDTH; + constexpr Index BIT_INDEX = INDEX % UNIT_WIDTH; constexpr Unit MASK = 1 << BIT_INDEX; return (_storage[BIT_UNIT] & MASK) != 0; @@ -157,11 +157,11 @@ BitArray::ConstBits::get() const { template bool -BitArray::ConstBits::get(const Index index) const { +BitArrayT::CBits::get(const Index index) const noexcept { HFSM2_ASSERT(index < _width); - const Index unit = index / (sizeof(Unit) * 8); - const Index bit = index % (sizeof(Unit) * 8); + const Index unit = index / UNIT_WIDTH; + const Index bit = index % UNIT_WIDTH; const Unit mask = 1 << bit; return (_storage[unit] & mask) != 0; @@ -171,7 +171,7 @@ BitArray::ConstBits::get(const Index index) const { template void -BitArray::clear() { +BitArrayT::clear() noexcept { for (Unit& unit: _storage) unit = Unit{0}; } @@ -181,12 +181,12 @@ BitArray::clear() { template template bool -BitArray::get() const { +BitArrayT::get() const noexcept { constexpr Index INDEX = NIndex; - static_assert(INDEX < CAPACITY, ""); + static_assert(INDEX < BIT_COUNT, ""); - constexpr Index BIT_UNIT = INDEX / (sizeof(Unit) * 8); - constexpr Index BIT_INDEX = INDEX % (sizeof(Unit) * 8); + constexpr Index BIT_UNIT = INDEX / UNIT_WIDTH; + constexpr Index BIT_INDEX = INDEX % UNIT_WIDTH; constexpr Unit MASK = 1 << BIT_INDEX; return (_storage[BIT_UNIT] & MASK) != 0; @@ -197,12 +197,12 @@ BitArray::get() const { template template void -BitArray::set() { +BitArrayT::set() noexcept { constexpr Index INDEX = NIndex; - static_assert(INDEX < CAPACITY, ""); + static_assert(INDEX < BIT_COUNT, ""); - constexpr Index BIT_UNIT = INDEX / (sizeof(Unit) * 8); - constexpr Index BIT_INDEX = INDEX % (sizeof(Unit) * 8); + constexpr Index BIT_UNIT = INDEX / UNIT_WIDTH; + constexpr Index BIT_INDEX = INDEX % UNIT_WIDTH; constexpr Unit MASK = 1 << BIT_INDEX; _storage[BIT_UNIT] |= MASK; @@ -213,12 +213,12 @@ BitArray::set() { template template void -BitArray::clear() { +BitArrayT::clear() noexcept { constexpr Index INDEX = NIndex; - static_assert(INDEX < CAPACITY, ""); + static_assert(INDEX < BIT_COUNT, ""); - constexpr Index BIT_UNIT = INDEX / (sizeof(Unit) * 8); - constexpr Index BIT_INDEX = INDEX % (sizeof(Unit) * 8); + constexpr Index BIT_UNIT = INDEX / UNIT_WIDTH; + constexpr Index BIT_INDEX = INDEX % UNIT_WIDTH; constexpr Unit MASK = 1 << BIT_INDEX; _storage[BIT_UNIT] &= ~MASK; @@ -228,11 +228,11 @@ BitArray::clear() { template bool -BitArray::get(const Index index) const { - HFSM2_ASSERT(index < CAPACITY); +BitArrayT::get(const Index index) const noexcept { + HFSM2_ASSERT(index < BIT_COUNT); - const Index unit = index / (sizeof(Unit) * 8); - const Index bit = index % (sizeof(Unit) * 8); + const Index unit = index / UNIT_WIDTH; + const Index bit = index % UNIT_WIDTH; const Unit mask = 1 << bit; return (_storage[unit] & mask) != 0; @@ -242,11 +242,11 @@ BitArray::get(const Index index) const { template void -BitArray::set(const Index index) { - HFSM2_ASSERT(index < CAPACITY); +BitArrayT::set(const Index index) noexcept { + HFSM2_ASSERT(index < BIT_COUNT); - const Index unit = index / (sizeof(Unit) * 8); - const Index bit = index % (sizeof(Unit) * 8); + const Index unit = index / UNIT_WIDTH; + const Index bit = index % UNIT_WIDTH; const Unit mask = 1 << bit; _storage[unit] |= mask; @@ -256,11 +256,11 @@ BitArray::set(const Index index) { template void -BitArray::clear(const Index index) { - HFSM2_ASSERT(index < CAPACITY); +BitArrayT::clear(const Index index) noexcept { + HFSM2_ASSERT(index < BIT_COUNT); - const Index unit = index / (sizeof(Unit) * 8); - const Index bit = index % (sizeof(Unit) * 8); + const Index unit = index / UNIT_WIDTH; + const Index bit = index % UNIT_WIDTH; const Unit mask = 1 << bit; _storage[unit] &= ~mask; @@ -270,11 +270,11 @@ BitArray::clear(const Index index) { template template -typename BitArray::Bits -BitArray::bits() { +typename BitArrayT::Bits +BitArrayT::bits() noexcept { constexpr Short UNIT = NUnit; constexpr Short WIDTH = NWidth; - static_assert(UNIT + (WIDTH + 7) / (sizeof(Unit) * 8) <= CAPACITY, ""); + static_assert(UNIT + contain(WIDTH, UNIT_WIDTH) <= UNIT_COUNT, ""); return Bits{_storage + UNIT, WIDTH}; } @@ -283,21 +283,21 @@ BitArray::bits() { template template -typename BitArray::ConstBits -BitArray::bits() const { +typename BitArrayT::CBits +BitArrayT::bits() const noexcept { constexpr Short UNIT = NUnit; constexpr Short WIDTH = NWidth; - static_assert(UNIT + (WIDTH + 7) / (sizeof(Unit) * 8) <= CAPACITY, ""); + static_assert(UNIT + contain(WIDTH, UNIT_WIDTH) <= UNIT_COUNT, ""); - return ConstBits{_storage + UNIT, WIDTH}; + return CBits{_storage + UNIT, WIDTH}; } //------------------------------------------------------------------------------ template -typename BitArray::Bits -BitArray::bits(const Units& units) { - HFSM2_ASSERT(units.unit + (units.width + 7) / (sizeof(Unit) * 8) <= CAPACITY); +typename BitArrayT::Bits +BitArrayT::bits(const Units& units) noexcept { + HFSM2_ASSERT(units.unit + contain(units.width, UNIT_WIDTH) <= UNIT_COUNT); return Bits{_storage + units.unit, units.width}; } @@ -305,11 +305,11 @@ BitArray::bits(const Units& units) { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - template -typename BitArray::ConstBits -BitArray::bits(const Units& units) const { - HFSM2_ASSERT(units.unit + (units.width + 7) / (sizeof(Unit) * 8) <= CAPACITY); +typename BitArrayT::CBits +BitArrayT::bits(const Units& units) const noexcept { + HFSM2_ASSERT(units.unit + contain(units.width, UNIT_WIDTH) <= UNIT_COUNT); - return ConstBits{_storage + units.unit, units.width}; + return CBits{_storage + units.unit, units.width}; } //////////////////////////////////////////////////////////////////////////////// diff --git a/include/hfsm2/detail/shared/bit_stream.hpp b/include/hfsm2/detail/shared/bit_stream.hpp index 7773812..188898e 100644 --- a/include/hfsm2/detail/shared/bit_stream.hpp +++ b/include/hfsm2/detail/shared/bit_stream.hpp @@ -1,19 +1,21 @@ +#ifdef HFSM2_ENABLE_SERIALIZATION + namespace hfsm2 { namespace detail { //------------------------------------------------------------------------------ template -struct StreamBuffer { +struct StreamBufferT { static constexpr Long BIT_CAPACITY = NBitCapacity; - static constexpr Long BYTE_COUNT = roundUp(BIT_CAPACITY, 8); + static constexpr Long BYTE_COUNT = contain(BIT_CAPACITY, 8u); using Size = UnsignedCapacity; using Data = uint8_t[BYTE_COUNT]; - void clear(); + void clear() noexcept; - //Size write(const uint8_t byte); + //Size write(const uint8_t byte) noexcept; Size bitSize; Data payload; @@ -22,17 +24,17 @@ struct StreamBuffer { //////////////////////////////////////////////////////////////////////////////// template -class BitWriteStream final { +class BitWriteStreamT final { public: static constexpr Long BIT_CAPACITY = NBitCapacity; - using Buffer = StreamBuffer; + using Buffer = StreamBufferT; public: - BitWriteStream(Buffer& _buffer); + BitWriteStreamT(Buffer& _buffer) noexcept; template - void write(const UnsignedBitWidth item); + void write(const UnsignedBitWidth item) noexcept; private: Buffer& _buffer; @@ -41,21 +43,21 @@ class BitWriteStream final { //------------------------------------------------------------------------------ template -class BitReadStream final { +class BitReadStreamT final { public: static constexpr Long BIT_CAPACITY = NBitCapacity; - using Buffer = StreamBuffer; + using Buffer = StreamBufferT; public: - BitReadStream(const Buffer& buffer) + BitReadStreamT(const Buffer& buffer) noexcept : _buffer{buffer} {} template - UnsignedBitWidth read(); + UnsignedBitWidth read() noexcept; - Long cursor() const { return _cursor; } + Long cursor() const noexcept { return _cursor; } private: const Buffer& _buffer; @@ -69,3 +71,5 @@ class BitReadStream final { } #include "bit_stream.inl" + +#endif diff --git a/include/hfsm2/detail/shared/bit_stream.inl b/include/hfsm2/detail/shared/bit_stream.inl index a20cc11..26b3fcb 100644 --- a/include/hfsm2/detail/shared/bit_stream.inl +++ b/include/hfsm2/detail/shared/bit_stream.inl @@ -1,3 +1,5 @@ +#ifdef HFSM2_ENABLE_SERIALIZATION + namespace hfsm2 { namespace detail { @@ -5,7 +7,7 @@ namespace detail { template void -StreamBuffer::clear() { +StreamBufferT::clear() noexcept { bitSize = 0; fill(payload, 0); } @@ -13,7 +15,7 @@ StreamBuffer::clear() { //////////////////////////////////////////////////////////////////////////////// template -BitWriteStream::BitWriteStream(Buffer& buffer) +BitWriteStreamT::BitWriteStreamT(Buffer& buffer) noexcept : _buffer{buffer} { _buffer.clear(); @@ -24,7 +26,7 @@ BitWriteStream::BitWriteStream(Buffer& buffer) template template void -BitWriteStream::write(const UnsignedBitWidth item) { +BitWriteStreamT::write(const UnsignedBitWidth item) noexcept { constexpr Short BIT_WIDTH = NBitWidth; static_assert(BIT_WIDTH > 0, "STATIC ASSERT"); @@ -55,7 +57,7 @@ BitWriteStream::write(const UnsignedBitWidth item) { template template UnsignedBitWidth -BitReadStream::read() { +BitReadStreamT::read() noexcept { constexpr Short BIT_WIDTH = NBitWidth; static_assert(BIT_WIDTH > 0, "STATIC ASSERT"); @@ -90,3 +92,5 @@ BitReadStream::read() { } } + +#endif diff --git a/include/hfsm2/detail/shared/iterator.hpp b/include/hfsm2/detail/shared/iterator.hpp index eba27a1..f68bdc1 100644 --- a/include/hfsm2/detail/shared/iterator.hpp +++ b/include/hfsm2/detail/shared/iterator.hpp @@ -4,31 +4,31 @@ namespace detail { //////////////////////////////////////////////////////////////////////////////// template -class Iterator { +class IteratorT { public: using Container = TContainer; using Item = typename Container::Item; template - friend class Array; + friend class ArrayT; private: - HFSM2_INLINE Iterator(Container& container, - const Long cursor) + HFSM2_INLINE IteratorT(Container& container, + const Long cursor) noexcept : _container{container} , _cursor{cursor} {} public: - HFSM2_INLINE bool operator != (const Iterator& dummy) const; + HFSM2_INLINE bool operator != (const IteratorT& other) const noexcept; - HFSM2_INLINE Iterator& operator ++(); + HFSM2_INLINE IteratorT& operator ++() noexcept; - HFSM2_INLINE Item& operator *() { return _container[_cursor]; } - HFSM2_INLINE const Item& operator *() const { return _container[_cursor]; } + HFSM2_INLINE Item& operator *() noexcept { return _container[_cursor]; } + HFSM2_INLINE const Item& operator *() const noexcept { return _container[_cursor]; } - HFSM2_INLINE Item* operator->() { return &_container[_cursor]; } - HFSM2_INLINE const Item* operator->() const { return &_container[_cursor]; } + HFSM2_INLINE Item* operator->() noexcept { return &_container[_cursor]; } + HFSM2_INLINE const Item* operator->() const noexcept { return &_container[_cursor]; } private: Container& _container; @@ -39,29 +39,29 @@ class Iterator { //------------------------------------------------------------------------------ template -class Iterator { +class IteratorT { public: using Container = TContainer; using Item = typename Container::Item; template - friend class Array; + friend class ArrayT; private: - HFSM2_INLINE Iterator(const Container& container, - const Long cursor) + HFSM2_INLINE IteratorT(const Container& container, + const Long cursor) noexcept : _container{container} , _cursor{cursor} {} public: - HFSM2_INLINE bool operator != (const Iterator& dummy) const; + HFSM2_INLINE bool operator != (const IteratorT& other) const noexcept; - HFSM2_INLINE Iterator& operator ++(); + HFSM2_INLINE IteratorT& operator ++() noexcept; - HFSM2_INLINE const Item& operator *() const { return _container[_cursor]; } + HFSM2_INLINE const Item& operator *() const noexcept { return _container[_cursor]; } - HFSM2_INLINE const Item* operator->() const { return &operator *(); } + HFSM2_INLINE const Item* operator->() const noexcept { return &operator *(); } private: const Container& _container; diff --git a/include/hfsm2/detail/shared/iterator.inl b/include/hfsm2/detail/shared/iterator.inl index 9b9ba4b..3cfb59a 100644 --- a/include/hfsm2/detail/shared/iterator.inl +++ b/include/hfsm2/detail/shared/iterator.inl @@ -5,8 +5,8 @@ namespace detail { template bool -Iterator::operator != (const Iterator& HFSM2_IF_ASSERT(dummy)) const { - HFSM2_ASSERT(&_container == &dummy._container); +IteratorT::operator != (const IteratorT& HFSM2_IF_ASSERT(other)) const noexcept { + HFSM2_ASSERT(&_container == &other._container); return _cursor != _container.limit(); } @@ -14,8 +14,8 @@ Iterator::operator != (const Iterator& HFSM2_IF_ASSERT(dummy)) const { //------------------------------------------------------------------------------ template -Iterator& -Iterator::operator ++() { +IteratorT& +IteratorT::operator ++() noexcept { _cursor = _container.next(_cursor); return *this; @@ -25,8 +25,8 @@ Iterator::operator ++() { template bool -Iterator::operator != (const Iterator& HFSM2_IF_ASSERT(dummy)) const { - HFSM2_ASSERT(&_container == &dummy._container); +IteratorT::operator != (const IteratorT& HFSM2_IF_ASSERT(other)) const noexcept { + HFSM2_ASSERT(&_container == &other._container); return _cursor != _container.limit(); } @@ -34,8 +34,8 @@ Iterator::operator != (const Iterator& HFSM2_IF_ASSERT(dummy)) //------------------------------------------------------------------------------ template -Iterator& -Iterator::operator ++() { +IteratorT& +IteratorT::operator ++() noexcept { _cursor = _container.next(_cursor); return *this; diff --git a/include/hfsm2/detail/shared/list.hpp b/include/hfsm2/detail/shared/list.hpp deleted file mode 100644 index 66bac44..0000000 --- a/include/hfsm2/detail/shared/list.hpp +++ /dev/null @@ -1,60 +0,0 @@ -namespace hfsm2 { -namespace detail { - -//////////////////////////////////////////////////////////////////////////////// - -template -class List { -public: - using Index = Long; - - static constexpr Index CAPACITY = NCapacity; - - static constexpr Index INVALID = Index (-1); - -private: - using Item = TItem; - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - struct Cell { - Item item; - Index prev; - Index next; - }; - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -public: - template - Index emplace(TArgs... args); - - void remove(const Index i); - - HFSM2_INLINE Item& operator[] (const Index i); - HFSM2_INLINE const Item& operator[] (const Index i) const; - - HFSM2_INLINE Index count() const { return _count; } - -private: - HFSM2_IF_ASSERT(void verifyStructure(const Index occupied = INVALID) const); - -private: - Cell _cells[CAPACITY]; - Index _vacantHead = 0; - Index _vacantTail = 0; - Index _last = 0; - Index _count = 0; -}; - -//------------------------------------------------------------------------------ - -template -class List {}; - -//////////////////////////////////////////////////////////////////////////////// - -} -} - -#include "list.inl" diff --git a/include/hfsm2/detail/shared/macros_off.hpp b/include/hfsm2/detail/shared/macros_off.hpp index 43a81d6..d104e80 100644 --- a/include/hfsm2/detail/shared/macros_off.hpp +++ b/include/hfsm2/detail/shared/macros_off.hpp @@ -27,6 +27,7 @@ #undef HFSM2_EXPLICIT_MEMBER_SPECIALIZATION +#undef HFSM2_IF_TYPEINDEX #undef HFSM2_IF_UTILITY_THEORY #undef HFSM2_IF_PLANS #undef HFSM2_IF_SERIALIZATION diff --git a/include/hfsm2/detail/shared/macros_on.hpp b/include/hfsm2/detail/shared/macros_on.hpp index 6ab3d5b..7596fb8 100644 --- a/include/hfsm2/detail/shared/macros_on.hpp +++ b/include/hfsm2/detail/shared/macros_on.hpp @@ -62,61 +62,71 @@ //------------------------------------------------------------------------------ +#ifndef HFSM2_DISABLE_TYPEINDEX + #define HFSM2_IF_TYPEINDEX(...) __VA_ARGS__ + #define HFSM2_TYPEINDEX_MASK (1 << 0) +#else + #define HFSM2_IF_TYPEINDEX(...) + #define HFSM2_TYPEINDEX_MASK (0 << 0) +#endif + +//------------------------------------------------------------------------------ + #ifdef HFSM2_ENABLE_UTILITY_THEORY #define HFSM2_IF_UTILITY_THEORY(...) __VA_ARGS__ - #define HFSM2_UTILITY_THEORY_MASK (1 << 0) + #define HFSM2_UTILITY_THEORY_MASK (1 << 1) #else #define HFSM2_IF_UTILITY_THEORY(...) - #define HFSM2_UTILITY_THEORY_MASK (0 << 0) + #define HFSM2_UTILITY_THEORY_MASK (0 << 1) #endif //------------------------------------------------------------------------------ #ifdef HFSM2_ENABLE_PLANS #define HFSM2_IF_PLANS(...) __VA_ARGS__ - #define HFSM2_PLANS_MASK (1 << 1) + #define HFSM2_PLANS_MASK (1 << 2) #else #define HFSM2_IF_PLANS(...) - #define HFSM2_PLANS_MASK (0 << 1) + #define HFSM2_PLANS_MASK (0 << 2) #endif //------------------------------------------------------------------------------ #ifdef HFSM2_ENABLE_SERIALIZATION #define HFSM2_IF_SERIALIZATION(...) __VA_ARGS__ - #define HFSM2_SERIALIZATION_MASK (1 << 2) + #define HFSM2_SERIALIZATION_MASK (1 << 3) #else #define HFSM2_IF_SERIALIZATION(...) - #define HFSM2_SERIALIZATION_MASK (0 << 2) + #define HFSM2_SERIALIZATION_MASK (0 << 3) #endif //------------------------------------------------------------------------------ #ifdef HFSM2_ENABLE_TRANSITION_HISTORY #define HFSM2_IF_TRANSITION_HISTORY(...) __VA_ARGS__ - #define HFSM2_TRANSITION_HISTORY_MASK (1 << 3) + #define HFSM2_TRANSITION_HISTORY_MASK (1 << 4) #else #define HFSM2_IF_TRANSITION_HISTORY(...) - #define HFSM2_TRANSITION_HISTORY_MASK (0 << 3) + #define HFSM2_TRANSITION_HISTORY_MASK (0 << 4) #endif //------------------------------------------------------------------------------ #ifdef HFSM2_ENABLE_STRUCTURE_REPORT #define HFSM2_IF_STRUCTURE_REPORT(...) __VA_ARGS__ - #define HFSM2_STRUCTURE_REPORT_MASK (1 << 4) + #define HFSM2_STRUCTURE_REPORT_MASK (1 << 5) #else #define HFSM2_IF_STRUCTURE_REPORT(...) - #define HFSM2_STRUCTURE_REPORT_MASK (0 << 4) + #define HFSM2_STRUCTURE_REPORT_MASK (0 << 5) #endif //////////////////////////////////////////////////////////////////////////////// #ifdef HFSM2_ENABLE_VERBOSE_DEBUG_LOG #define HFSM2_ENABLE_LOG_INTERFACE - #define HFSM2_VERBOSE_DEBUG_LOG_MASK (1 << 5) + #define HFSM2_VERBOSE_DEBUG_LOG_MASK (1 << 6) #else - #define HFSM2_VERBOSE_DEBUG_LOG_MASK (0 << 5) + #define HFSM2_VERBOSE_DEBUG_LOG_MASK (0 << 6) #endif // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -124,7 +134,7 @@ #ifdef HFSM2_ENABLE_LOG_INTERFACE #define HFSM2_IF_LOG_INTERFACE(...) __VA_ARGS__ - #define HFSM2_LOG_INTERFACE_MASK (1 << 6) + #define HFSM2_LOG_INTERFACE_MASK (1 << 7) #define HFSM2_LOG_TRANSITION(CONTEXT, ORIGIN, TYPE, DESTINATION) \ if (_logger) \ @@ -161,7 +171,7 @@ #else #define HFSM2_IF_LOG_INTERFACE(...) - #define HFSM2_LOG_INTERFACE_MASK (0 << 6) + #define HFSM2_LOG_INTERFACE_MASK (0 << 7) #define HFSM2_LOG_TRANSITION(CONTEXT, ORIGIN, TYPE, DESTINATION) @@ -205,18 +215,20 @@ namespace hfsm2 { using FeatureTag = uint8_t; -constexpr FeatureTag HFSM2_FEATURE_TAG = HFSM2_UTILITY_THEORY_MASK | - HFSM2_PLANS_MASK | - HFSM2_SERIALIZATION_MASK | - HFSM2_TRANSITION_HISTORY_MASK | - HFSM2_STRUCTURE_REPORT_MASK | - HFSM2_VERBOSE_DEBUG_LOG_MASK | - HFSM2_LOG_INTERFACE_MASK; +constexpr FeatureTag HFSM2_FEATURE_TAG = HFSM2_TYPEINDEX_MASK + | HFSM2_PLANS_MASK + | HFSM2_UTILITY_THEORY_MASK + | HFSM2_SERIALIZATION_MASK + | HFSM2_TRANSITION_HISTORY_MASK + | HFSM2_STRUCTURE_REPORT_MASK + | HFSM2_VERBOSE_DEBUG_LOG_MASK + | HFSM2_LOG_INTERFACE_MASK; } //------------------------------------------------------------------------------ +#undef HFSM2_TYPEINDEX_MASK #undef HFSM2_UTILITY_THEORY_MASK #undef HFSM2_PLANS_MASK #undef HFSM2_SERIALIZATION_MASK diff --git a/include/hfsm2/detail/shared/random.hpp b/include/hfsm2/detail/shared/random.hpp index 3283093..a51f7fd 100644 --- a/include/hfsm2/detail/shared/random.hpp +++ b/include/hfsm2/detail/shared/random.hpp @@ -12,13 +12,13 @@ namespace hfsm2 { class SplitMix64 { public: - inline SplitMix64() {} - inline SplitMix64(const uint64_t seed); + inline SplitMix64() noexcept {} + inline SplitMix64(const uint64_t seed) noexcept; - inline uint64_t next(); + inline uint64_t next() noexcept; private: - inline uint64_t raw(); + inline uint64_t raw() noexcept; private: @@ -34,18 +34,18 @@ class SplitMix64 { class XoShiRo256Plus { public: - inline XoShiRo256Plus(); - inline XoShiRo256Plus(const uint64_t s); - inline XoShiRo256Plus(const uint64_t(& s)[4]); + inline XoShiRo256Plus() noexcept; + inline XoShiRo256Plus(const uint64_t s) noexcept; + inline XoShiRo256Plus(const uint64_t(& s)[4]) noexcept; - inline void seed(const uint64_t s); - inline void seed(const uint64_t(& s)[4]); + inline void seed(const uint64_t s) noexcept; + inline void seed(const uint64_t(& s)[4]) noexcept; - inline float next(); - inline void jump(); + inline float next() noexcept; + inline void jump() noexcept; private: - inline uint64_t raw(); + inline uint64_t raw() noexcept; private: uint64_t _state[4]; @@ -61,13 +61,13 @@ class XoShiRo256Plus { class SplitMix32 { public: - inline SplitMix32() {} - inline SplitMix32(const uint32_t seed); + inline SplitMix32() noexcept {} + inline SplitMix32(const uint32_t seed) noexcept; - inline uint32_t next(); + inline uint32_t next() noexcept; private: - inline uint32_t raw(); + inline uint32_t raw() noexcept; private: uint32_t _state; @@ -82,18 +82,18 @@ class SplitMix32 { class XoShiRo128Plus { public: - inline XoShiRo128Plus(); - inline XoShiRo128Plus(const uint32_t s); - inline XoShiRo128Plus(const uint32_t(& s)[4]); + inline XoShiRo128Plus() noexcept; + inline XoShiRo128Plus(const uint32_t s) noexcept; + inline XoShiRo128Plus(const uint32_t(& s)[4]) noexcept; - inline void seed(const uint32_t s); - inline void seed(const uint32_t(& s)[4]); + inline void seed(const uint32_t s) noexcept; + inline void seed(const uint32_t(& s)[4]) noexcept; - inline float next(); - inline void jump(); + inline float next() noexcept; + inline void jump() noexcept; private: - inline uint32_t raw(); + inline uint32_t raw() noexcept; private: uint32_t _state[4]; @@ -102,12 +102,12 @@ class XoShiRo128Plus { //------------------------------------------------------------------------------ template -class RandomT; +class RNGT; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - template <> -class RandomT +class RNGT : public HFSM2_64BIT_OR_32BIT(XoShiRo256Plus, XoShiRo128Plus) { public: diff --git a/include/hfsm2/detail/shared/random.inl b/include/hfsm2/detail/shared/random.inl index f8af808..a33eeaa 100644 --- a/include/hfsm2/detail/shared/random.inl +++ b/include/hfsm2/detail/shared/random.inl @@ -8,7 +8,7 @@ namespace detail { inline float -uniformReal(const uint32_t uint) { +uniformReal(const uint32_t uint) noexcept { const auto real = convert(UINT32_C(0x7F) << 23 | uint >> 9); return real - 1.0f; @@ -18,7 +18,7 @@ uniformReal(const uint32_t uint) { inline double -uniformReal(const uint64_t uint) { +uniformReal(const uint64_t uint) noexcept { const auto real = convert(UINT64_C(0x3FF) << 52 | uint >> 12); return real - 1.0; @@ -28,7 +28,7 @@ uniformReal(const uint64_t uint) { inline uint32_t -rotl(const uint32_t x, const uint32_t k) { +rotl(const uint32_t x, const uint32_t k) noexcept { return (x << k) | (x >> (32 - k)); } @@ -36,7 +36,7 @@ rotl(const uint32_t x, const uint32_t k) { inline uint64_t -rotl(const uint64_t x, const uint64_t k) { +rotl(const uint64_t x, const uint64_t k) noexcept { return (x << k) | (x >> (64 - k)); } @@ -44,14 +44,14 @@ rotl(const uint64_t x, const uint64_t k) { //////////////////////////////////////////////////////////////////////////////// -SplitMix64::SplitMix64(const uint64_t seed) +SplitMix64::SplitMix64(const uint64_t seed) noexcept : _state{seed} {} //------------------------------------------------------------------------------ uint64_t -SplitMix64::next() { +SplitMix64::next() noexcept { for (;;) if (const uint64_t number = raw()) return number; @@ -60,7 +60,7 @@ SplitMix64::next() { //------------------------------------------------------------------------------ uint64_t -SplitMix64::raw() { +SplitMix64::raw() noexcept { uint64_t z = (_state += 0x9e3779b97f4a7c15); z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9; z = (z ^ (z >> 27)) * 0x94d049bb133111eb; @@ -70,7 +70,7 @@ SplitMix64::raw() { //////////////////////////////////////////////////////////////////////////////// -XoShiRo256Plus::XoShiRo256Plus() { +XoShiRo256Plus::XoShiRo256Plus() noexcept { SplitMix64 generator; _state[0] = generator.next(); @@ -81,20 +81,20 @@ XoShiRo256Plus::XoShiRo256Plus() { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -XoShiRo256Plus::XoShiRo256Plus(const uint64_t s) { +XoShiRo256Plus::XoShiRo256Plus(const uint64_t s) noexcept { seed(s); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -XoShiRo256Plus::XoShiRo256Plus(const uint64_t(& s)[4]) { +XoShiRo256Plus::XoShiRo256Plus(const uint64_t(& s)[4]) noexcept { seed(s); } //------------------------------------------------------------------------------ void -XoShiRo256Plus::seed(const uint64_t s) { +XoShiRo256Plus::seed(const uint64_t s) noexcept { SplitMix64 generator{s}; _state[0] = generator.next(); @@ -106,7 +106,7 @@ XoShiRo256Plus::seed(const uint64_t s) { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void -XoShiRo256Plus::seed(const uint64_t(& s)[4]) { +XoShiRo256Plus::seed(const uint64_t(& s)[4]) noexcept { _state[0] = s[0]; _state[1] = s[1]; _state[2] = s[2]; @@ -116,14 +116,14 @@ XoShiRo256Plus::seed(const uint64_t(& s)[4]) { //------------------------------------------------------------------------------ float -XoShiRo256Plus::next() { +XoShiRo256Plus::next() noexcept { return detail::uniformReal((uint32_t) raw()); } //------------------------------------------------------------------------------ void -XoShiRo256Plus::jump() { +XoShiRo256Plus::jump() noexcept { static const uint64_t JUMP[] = { 0x180ec6d33cfd0aba, 0xd5a61266f0c9392c, 0xa9582618e03fc9aa, 0x39abdc4529b1661c }; uint64_t s0 = 0; @@ -151,7 +151,7 @@ XoShiRo256Plus::jump() { //------------------------------------------------------------------------------ uint64_t -XoShiRo256Plus::raw() { +XoShiRo256Plus::raw() noexcept { const uint64_t result_plus = _state[0] + _state[3]; const uint64_t t = _state[1] << 17; @@ -170,14 +170,14 @@ XoShiRo256Plus::raw() { //////////////////////////////////////////////////////////////////////////////// -SplitMix32::SplitMix32(const uint32_t seed) +SplitMix32::SplitMix32(const uint32_t seed) noexcept : _state{seed} {} //------------------------------------------------------------------------------ uint32_t -SplitMix32::next() { +SplitMix32::next() noexcept { for (;;) if (const uint32_t number = raw()) return number; @@ -186,7 +186,7 @@ SplitMix32::next() { //------------------------------------------------------------------------------ uint32_t -SplitMix32::raw() { +SplitMix32::raw() noexcept { uint32_t z = (_state += 0x9E3779B9); z = (z ^ (z >> 16)) * 0x85ebca6b; z = (z ^ (z >> 13)) * 0xc2b2ae35; @@ -196,7 +196,7 @@ SplitMix32::raw() { //////////////////////////////////////////////////////////////////////////////// -XoShiRo128Plus::XoShiRo128Plus() { +XoShiRo128Plus::XoShiRo128Plus() noexcept { SplitMix32 generator; _state[0] = generator.next(); @@ -207,20 +207,20 @@ XoShiRo128Plus::XoShiRo128Plus() { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -XoShiRo128Plus::XoShiRo128Plus(const uint32_t s) { +XoShiRo128Plus::XoShiRo128Plus(const uint32_t s) noexcept { seed(s); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -XoShiRo128Plus::XoShiRo128Plus(const uint32_t(& s)[4]) { +XoShiRo128Plus::XoShiRo128Plus(const uint32_t(& s)[4]) noexcept { seed(s); } //------------------------------------------------------------------------------ void -XoShiRo128Plus::seed(const uint32_t s) { +XoShiRo128Plus::seed(const uint32_t s) noexcept { SplitMix32 generator{s}; _state[0] = generator.next(); @@ -232,7 +232,7 @@ XoShiRo128Plus::seed(const uint32_t s) { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void -XoShiRo128Plus::seed(const uint32_t(& s)[4]) { +XoShiRo128Plus::seed(const uint32_t(& s)[4]) noexcept { _state[0] = s[0]; _state[1] = s[1]; _state[2] = s[2]; @@ -242,14 +242,14 @@ XoShiRo128Plus::seed(const uint32_t(& s)[4]) { //------------------------------------------------------------------------------ float -XoShiRo128Plus::next() { +XoShiRo128Plus::next() noexcept { return detail::uniformReal(raw()); } //------------------------------------------------------------------------------ void -XoShiRo128Plus::jump() { +XoShiRo128Plus::jump() noexcept { static const uint32_t JUMP[] = { 0x8764000b, 0xf542d2d3, 0x6fa035c3, 0x77f2db5b }; uint32_t s0 = 0; @@ -277,7 +277,7 @@ XoShiRo128Plus::jump() { //------------------------------------------------------------------------------ uint32_t -XoShiRo128Plus::raw() { +XoShiRo128Plus::raw() noexcept { const uint32_t result_plus = _state[0] + _state[3]; const uint32_t t = _state[1] << 9; diff --git a/include/hfsm2/detail/shared/type_list.hpp b/include/hfsm2/detail/shared/type_list.hpp index 091f805..ef4a217 100644 --- a/include/hfsm2/detail/shared/type_list.hpp +++ b/include/hfsm2/detail/shared/type_list.hpp @@ -1,301 +1,100 @@ namespace hfsm2 { - -//////////////////////////////////////////////////////////////////////////////// - -#if 0 - namespace detail { -template -struct IndexConstant {}; - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -template -struct IndexSequence { - using Type = IndexSequence; -}; - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -template -struct MakeIndexSequenceT {}; - -template -struct MakeIndexSequenceT, - IndexSequence> - : MakeIndexSequenceT, - IndexSequence> -{}; - -template -struct MakeIndexSequenceT, - IndexSequence> - : IndexSequence -{}; - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -template -using MakeIndexSequence = typename MakeIndexSequenceT, - IndexSequence<>>::Type; - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -template -using IndexSequenceFor = MakeIndexSequence; - //////////////////////////////////////////////////////////////////////////////// -template -struct ITL_EntryT {}; - -template -struct ITL_EntryN - : ITL_EntryT -{}; - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -template -struct ITL_Impl; - -template -struct ITL_Impl, Ts...> - : ITL_EntryN... -{ - template - static constexpr Long select(ITL_EntryN) { return (Long) N; } -}; - -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - template -struct TypeList - : private detail::ITL_Impl, Ts...> -{ - using Base = detail::ITL_Impl, Ts...>; - +struct TL_ { static constexpr Long SIZE = sizeof...(Ts); - - template - static constexpr Long index() { - return Base::template select(TypeList{}); - } }; -template -constexpr Long index () { return TList::template index (); } - -template -constexpr bool contains() { return std::is_base_of, TList>::value; } - -//////////////////////////////////////////////////////////////////////////////// - -namespace detail { - -template -struct PrependT; - -template -struct PrependT> { - using Type = TypeList; -}; - -} - -template -using Prepend = typename detail::PrependT::Type; - -//------------------------------------------------------------------------------ - -namespace detail { - -template -struct MergeT; - -template -struct MergeT, TypeList> { - using Type = TypeList; -}; - -} - -template -using Merge = typename detail::MergeT::Type; - //------------------------------------------------------------------------------ -namespace detail { - -template -struct LowerT; - -template -using Lower = typename LowerT::Type; - -template -struct LowerT { - using Type = typename std::conditional< - (I < H), - Prepend>, - Lower - >::type; -}; - -template -struct LowerT { - using Type = TypeList<>; -}; - -} - -template -using LHalf = detail::Lower; - -//------------------------------------------------------------------------------ - -namespace detail { - -template -struct UpperT; - -template -using Upper = typename UpperT::Type; - -template -struct UpperT { - using Type = typename std::conditional< - (I < H), - UpperT, - TypeList - >::type; -}; - -template -struct UpperT { - using Type = TypeList<>; -}; - -} - -template -using RHalf = detail::Upper; - -//////////////////////////////////////////////////////////////////////////////// - -#else - -template -struct TypeList { - static constexpr Long SIZE = sizeof...(Ts); -}; - -//------------------------------------------------------------------------------ - -namespace detail { - template struct Const { - static constexpr Long Value = N; + static constexpr Long VALUE = N; }; //------------------------------------------------------------------------------ -template +template struct PrependT; template -struct PrependT> { - using Type = TypeList; +struct PrependT> { + using Type = TL_; }; -} - template -using Prepend = typename detail::PrependT::Type; +using PrependTypes = typename PrependT::Type; //------------------------------------------------------------------------------ -namespace detail { - -template +template struct MergeT; template -struct MergeT, TypeList> { - using Type = TypeList; +struct MergeT, TL_> { + using Type = TL_; }; -} - template -using Merge = typename detail::MergeT::Type; +using Merge = typename MergeT::Type; //------------------------------------------------------------------------------ -namespace detail { - template struct LowerT; -template -using Lower = typename LowerT::Type; +template +using LowerTypes = typename LowerT::Type; -template -struct LowerT { - using Type = typename std::conditional< - (I < H), - Prepend>, - Lower - >::type; -}; +template +struct LowerT { + using LTypeList = typename LowerT::Type; -template -struct LowerT { - using Type = TypeList<>; + using Type = Conditional< + (NIndex < NHalf), + PrependTypes, + LTypeList + >; }; -} +template +struct LowerT { + using Type = TL_<>; +}; template -using LHalf = detail::Lower; +using LHalfTypes = LowerTypes; //------------------------------------------------------------------------------ -namespace detail { - template struct UpperT; -template -using Upper = typename UpperT::Type; +template +using UpperTypes = typename UpperT::Type; -template -struct UpperT { - using Type = typename std::conditional< - (I < H), - Upper, - TypeList - >::type; +template +struct UpperT { + using Type = Conditional< + (NIndex < NHalf), + UpperTypes, + TL_ + >; }; -template -struct UpperT { - using Type = TypeList<>; +template +struct UpperT { + using Type = TL_<>; }; -} - template -using RHalf = detail::Upper; +using RHalfTypes = UpperTypes; //------------------------------------------------------------------------------ -namespace detail { - template struct FindImpl : Const @@ -317,22 +116,20 @@ template struct Find; template -struct Find> +struct Find, T> : FindImpl<0, T, Ts...> {}; -} +//////////////////////////////////////////////////////////////////////////////// -//------------------------------------------------------------------------------ +} template -constexpr Long index () { return detail::Find::Value; } +constexpr Long index () noexcept { return detail::Find::VALUE; } template -constexpr bool contains() { return index() != INVALID_LONG; } - -#endif +constexpr bool contains() noexcept { return index() != INVALID_LONG; } -//////////////////////////////////////////////////////////////////////////////// +//------------------------------------------------------------------------------ } diff --git a/include/hfsm2/detail/shared/utility.hpp b/include/hfsm2/detail/shared/utility.hpp index 8543035..e002288 100644 --- a/include/hfsm2/detail/shared/utility.hpp +++ b/include/hfsm2/detail/shared/utility.hpp @@ -30,19 +30,34 @@ namespace detail { //////////////////////////////////////////////////////////////////////////////// +template +struct ConditionalT { + using Type = TT; +}; + +template +struct ConditionalT { + using Type = TF; +}; + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +template +using Conditional = typename ConditionalT::Type; + +//////////////////////////////////////////////////////////////////////////////// + template -HFSM2_INLINE -void -fill(T& a, const char value) { +HFSM2_INLINE void +fill(T& a, const char value) noexcept { memset(&a, (int) value, sizeof(a)); } //------------------------------------------------------------------------------ template -constexpr -unsigned -count(const T(&)[NCount]) { +constexpr unsigned +count(const T(&)[NCount]) noexcept { return NCount; } @@ -63,9 +78,11 @@ struct Max { //------------------------------------------------------------------------------ template -constexpr -T -min(const T t1, const T t2) { return t1 < t2 ? t1 : t2; } +constexpr T +min(const T t1, const T t2) noexcept { + return t1 < t2 ? + t1 : t2; +} //------------------------------------------------------------------------------ @@ -74,10 +91,10 @@ template struct UnsignedCapacityT { static constexpr Long CAPACITY = NCapacity; - using Type = typename std::conditional::type>::type>::type; + using Type = Conditional>>; static_assert(CAPACITY <= UINT64_MAX, "STATIC ASSERT"); }; @@ -91,32 +108,31 @@ template struct UnsignedBitWidthT { static constexpr Short BIT_WIDTH = NBitWidth; - using Type = typename std::conditional::type>::type>::type; + using Type = Conditional>>; static_assert(BIT_WIDTH <= 64, "STATIC ASSERT"); }; +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + template using UnsignedBitWidth = typename UnsignedBitWidthT::Type; //------------------------------------------------------------------------------ -constexpr -Long -roundUp(const Long x, - const Long to) -{ - return (x + (to - 1)) / to; +template +constexpr T1 +contain(const T1 x, const T2 to) noexcept { + return (x + (T1) to - 1) / ((T1) to); } //------------------------------------------------------------------------------ -constexpr -Short -bitWidth(const Short x) { +constexpr Short +bitWidth(const Short x) noexcept { return x <= 2 ? 1 : x <= 4 ? 2 : x <= 8 ? 3 : @@ -130,8 +146,8 @@ bitWidth(const Short x) { //------------------------------------------------------------------------------ template -void -overwrite(TTo& to, const TFrom& from) { +HFSM2_INLINE void +overwrite(TTo& to, const TFrom& from) noexcept { static_assert(sizeof(TTo) == sizeof(TFrom), "STATIC ASSERT"); #if defined(__GNUC__) || defined(__GNUG__) @@ -144,7 +160,8 @@ overwrite(TTo& to, const TFrom& from) { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - template -TO convert(const TI& in) { +HFSM2_INLINE TO +convert(const TI& in) noexcept { TO out; overwrite(out, in); diff --git a/include/hfsm2/detail/structure/composite.hpp b/include/hfsm2/detail/structure/composite.hpp index 3035c8e..bb1680b 100644 --- a/include/hfsm2/detail/structure/composite.hpp +++ b/include/hfsm2/detail/structure/composite.hpp @@ -68,124 +68,125 @@ struct C_ final { #ifdef HFSM2_EXPLICIT_MEMBER_SPECIALIZATION template struct Accessor { - HFSM2_INLINE static T& get( C_& c) { return c._subStates.template access(); } - HFSM2_INLINE static const T& get(const C_& c) { return c._subStates.template access(); } + HFSM2_INLINE static T& get( C_& c) noexcept { return c._subStates.template access(); } + HFSM2_INLINE static const T& get(const C_& c) noexcept { return c._subStates.template access(); } }; template <> struct Accessor { - HFSM2_INLINE static Head& get( C_& c) { return c._headState._headBox.get(); } - HFSM2_INLINE static const Head& get(const C_& c) { return c._headState._headBox.get(); } + HFSM2_INLINE static Head& get( C_& c) noexcept { return c._headState._headBox.get(); } + HFSM2_INLINE static const Head& get(const C_& c) noexcept { return c._headState._headBox.get(); } }; template - HFSM2_INLINE T& access() { return Accessor::get(*this); } + HFSM2_INLINE T& access() noexcept { return Accessor::get(*this); } template - HFSM2_INLINE const T& access() const { return Accessor::get(*this); } + HFSM2_INLINE const T& access() const noexcept { return Accessor::get(*this); } #endif //---------------------------------------------------------------------- #ifdef HFSM2_ENABLE_SERIALIZATION - HFSM2_INLINE Short compoRequested (const Registry& registry) const { return registry.compoRequested[COMPO_INDEX]; } - HFSM2_INLINE Short& compoRequested ( Registry& registry) const { return registry.compoRequested[COMPO_INDEX]; } + HFSM2_INLINE Short compoRequested (const Registry& registry) const noexcept { return registry.compoRequested[COMPO_INDEX]; } + HFSM2_INLINE Short& compoRequested ( Registry& registry) const noexcept { return registry.compoRequested[COMPO_INDEX]; } - HFSM2_INLINE Short compoActive (const Registry& registry) const { return registry.compoActive [COMPO_INDEX]; } - HFSM2_INLINE Short& compoActive ( Registry& registry) const { return registry.compoActive [COMPO_INDEX]; } + HFSM2_INLINE Short compoActive (const Registry& registry) const noexcept { return registry.compoActive [COMPO_INDEX]; } + HFSM2_INLINE Short& compoActive ( Registry& registry) const noexcept { return registry.compoActive [COMPO_INDEX]; } - HFSM2_INLINE Short compoResumable (const Registry& registry) const { return registry.compoResumable[COMPO_INDEX]; } - HFSM2_INLINE Short& compoResumable ( Registry& registry) const { return registry.compoResumable[COMPO_INDEX]; } + HFSM2_INLINE Short compoResumable (const Registry& registry) const noexcept { return registry.compoResumable[COMPO_INDEX]; } + HFSM2_INLINE Short& compoResumable ( Registry& registry) const noexcept { return registry.compoResumable[COMPO_INDEX]; } #endif - HFSM2_INLINE Short& compoRequested (Control& control) const { return control._registry.compoRequested[COMPO_INDEX]; } - HFSM2_INLINE Short& compoActive (Control& control) const { return control._registry.compoActive [COMPO_INDEX]; } - HFSM2_INLINE Short& compoResumable (Control& control) const { return control._registry.compoResumable[COMPO_INDEX]; } + HFSM2_INLINE Short& compoRequested (Control& control) const noexcept { return control._registry.compoRequested[COMPO_INDEX]; } + HFSM2_INLINE Short& compoActive (Control& control) const noexcept { return control._registry.compoActive [COMPO_INDEX]; } + HFSM2_INLINE Short& compoResumable (Control& control) const noexcept { return control._registry.compoResumable[COMPO_INDEX]; } - HFSM2_INLINE bool compoRemain (Control& control) const { return control._registry.compoRemains.template get(); } + HFSM2_INLINE bool compoRemain (Control& control) const noexcept { return control._registry.compoRemains.template get(); } #ifdef HFSM2_ENABLE_UTILITY_THEORY HFSM2_INLINE Short resolveRandom (Control& control, const Utility(& options)[Info::WIDTH], const Utility sum, - const Rank (& ranks) [Info::WIDTH], const Rank top) const; + const Rank (& ranks) [Info::WIDTH], const Rank top) const noexcept; #endif - HFSM2_INLINE void deepRegister (Registry& registry, const Parent parent); + HFSM2_INLINE void deepRegister (Registry& registry, const Parent parent) noexcept; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE bool deepForwardEntryGuard (GuardControl& control); - HFSM2_INLINE bool deepEntryGuard (GuardControl& control); + HFSM2_INLINE bool deepForwardEntryGuard (GuardControl& control) noexcept; + HFSM2_INLINE bool deepEntryGuard (GuardControl& control) noexcept; - HFSM2_INLINE void deepConstruct (PlanControl& control); + HFSM2_INLINE void deepConstruct (PlanControl& control) noexcept; - HFSM2_INLINE void deepEnter (PlanControl& control); - HFSM2_INLINE void deepReenter (PlanControl& control); + HFSM2_INLINE void deepEnter (PlanControl& control) noexcept; + HFSM2_INLINE void deepReenter (PlanControl& control) noexcept; - HFSM2_INLINE Status deepUpdate (FullControl& control); + HFSM2_INLINE Status deepUpdate (FullControl& control) noexcept; template - HFSM2_INLINE Status deepReact (FullControl& control, const TEvent& event); + HFSM2_INLINE Status deepReact (FullControl& control, + const TEvent& event) noexcept; - HFSM2_INLINE bool deepForwardExitGuard (GuardControl& control); - HFSM2_INLINE bool deepExitGuard (GuardControl& control); + HFSM2_INLINE bool deepForwardExitGuard (GuardControl& control) noexcept; + HFSM2_INLINE bool deepExitGuard (GuardControl& control) noexcept; - HFSM2_INLINE void deepExit (PlanControl& control); + HFSM2_INLINE void deepExit (PlanControl& control) noexcept; - HFSM2_INLINE void deepDestruct (PlanControl& control); + HFSM2_INLINE void deepDestruct (PlanControl& control) noexcept; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE void deepForwardActive (Control& control, const Request request); - HFSM2_INLINE void deepForwardRequest (Control& control, const Request request); + HFSM2_INLINE void deepForwardActive (Control& control, const Request request) noexcept; + HFSM2_INLINE void deepForwardRequest (Control& control, const Request request) noexcept; - HFSM2_INLINE void deepRequest (Control& control, const Request request); + HFSM2_INLINE void deepRequest (Control& control, const Request request) noexcept; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #ifdef HFSM2_EXPLICIT_MEMBER_SPECIALIZATION template - HFSM2_INLINE void deepRequestChange (Control& control, const Request request, const Short = INVALID_SHORT); + HFSM2_INLINE void deepRequestChange (Control& control, const Request request, const Short = INVALID_SHORT) noexcept; template <> - HFSM2_INLINE void deepRequestChange (Control& control, const Request request, const Short) { deepRequestChangeComposite (control, request); } + HFSM2_INLINE void deepRequestChange (Control& control, const Request request, const Short) noexcept { deepRequestChangeComposite (control, request); } template <> - HFSM2_INLINE void deepRequestChange (Control& control, const Request request, const Short) { deepRequestChangeResumable (control, request); } + HFSM2_INLINE void deepRequestChange (Control& control, const Request request, const Short) noexcept { deepRequestChangeResumable (control, request); } #ifdef HFSM2_ENABLE_UTILITY_THEORY template <> - HFSM2_INLINE void deepRequestChange(Control& control, const Request request, const Short) { deepRequestChangeUtilitarian(control, request); } + HFSM2_INLINE void deepRequestChange(Control& control, const Request request, const Short) noexcept { deepRequestChangeUtilitarian(control, request); } template <> - HFSM2_INLINE void deepRequestChange (Control& control, const Request request, const Short) { deepRequestChangeRandom (control, request); } + HFSM2_INLINE void deepRequestChange (Control& control, const Request request, const Short) noexcept { deepRequestChangeRandom (control, request); } #endif #else - HFSM2_INLINE void deepRequestChange (Control& control, const Request request); + HFSM2_INLINE void deepRequestChange (Control& control, const Request request) noexcept; #endif - HFSM2_INLINE void deepRequestChangeComposite (Control& control, const Request request); - HFSM2_INLINE void deepRequestChangeResumable (Control& control, const Request request); + HFSM2_INLINE void deepRequestChangeComposite (Control& control, const Request request) noexcept; + HFSM2_INLINE void deepRequestChangeResumable (Control& control, const Request request) noexcept; #ifdef HFSM2_ENABLE_UTILITY_THEORY - HFSM2_INLINE void deepRequestChangeUtilitarian (Control& control, const Request request); - HFSM2_INLINE void deepRequestChangeRandom (Control& control, const Request request); + HFSM2_INLINE void deepRequestChangeUtilitarian (Control& control, const Request request) noexcept; + HFSM2_INLINE void deepRequestChangeRandom (Control& control, const Request request) noexcept; #endif // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE void deepRequestRestart (Control& control, const Request request); - HFSM2_INLINE void deepRequestResume (Control& control, const Request request); + HFSM2_INLINE void deepRequestRestart (Control& control, const Request request) noexcept; + HFSM2_INLINE void deepRequestResume (Control& control, const Request request) noexcept; #ifdef HFSM2_ENABLE_UTILITY_THEORY - HFSM2_INLINE void deepRequestUtilize (Control& control, const Request request); - HFSM2_INLINE void deepRequestRandomize (Control& control, const Request request); + HFSM2_INLINE void deepRequestUtilize (Control& control, const Request request) noexcept; + HFSM2_INLINE void deepRequestRandomize (Control& control, const Request request) noexcept; #endif // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -194,42 +195,42 @@ struct C_ final { #ifdef HFSM2_EXPLICIT_MEMBER_SPECIALIZATION template - HFSM2_INLINE UP deepReportChange (Control& control); + HFSM2_INLINE UP deepReportChange (Control& control) noexcept; template <> - HFSM2_INLINE UP deepReportChange (Control& control) { return deepReportChangeComposite (control); } + HFSM2_INLINE UP deepReportChange (Control& control) noexcept { return deepReportChangeComposite (control); } template <> - HFSM2_INLINE UP deepReportChange (Control& control) { return deepReportChangeResumable (control); } + HFSM2_INLINE UP deepReportChange (Control& control) noexcept { return deepReportChangeResumable (control); } template <> - HFSM2_INLINE UP deepReportChange (Control& control) { return deepReportChangeUtilitarian(control); } + HFSM2_INLINE UP deepReportChange (Control& control) noexcept { return deepReportChangeUtilitarian(control); } template <> - HFSM2_INLINE UP deepReportChange (Control& control) { return deepReportChangeRandom (control); } + HFSM2_INLINE UP deepReportChange (Control& control) noexcept { return deepReportChangeRandom (control); } #else - HFSM2_INLINE UP deepReportChange (Control& control); + HFSM2_INLINE UP deepReportChange (Control& control) noexcept; #endif - HFSM2_INLINE UP deepReportChangeComposite (Control& control); - HFSM2_INLINE UP deepReportChangeResumable (Control& control); - HFSM2_INLINE UP deepReportChangeUtilitarian (Control& control); - HFSM2_INLINE UP deepReportChangeRandom (Control& control); + HFSM2_INLINE UP deepReportChangeComposite (Control& control) noexcept; + HFSM2_INLINE UP deepReportChangeResumable (Control& control) noexcept; + HFSM2_INLINE UP deepReportChangeUtilitarian (Control& control) noexcept; + HFSM2_INLINE UP deepReportChangeRandom (Control& control) noexcept; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE UP deepReportUtilize (Control& control); - HFSM2_INLINE Rank deepReportRank (Control& control); - HFSM2_INLINE Utility deepReportRandomize (Control& control); + HFSM2_INLINE UP deepReportUtilize (Control& control) noexcept; + HFSM2_INLINE Rank deepReportRank (Control& control) noexcept; + HFSM2_INLINE Utility deepReportRandomize (Control& control) noexcept; #endif // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE void deepChangeToRequested (PlanControl& control); + HFSM2_INLINE void deepChangeToRequested (PlanControl& control) noexcept; //---------------------------------------------------------------------- @@ -237,11 +238,11 @@ struct C_ final { using WriteStream = typename Args::WriteStream; using ReadStream = typename Args::ReadStream; - HFSM2_INLINE void deepSaveActive (const Registry& registry, WriteStream& stream) const; - HFSM2_INLINE void deepSaveResumable (const Registry& registry, WriteStream& stream) const; + HFSM2_INLINE void deepSaveActive (const Registry& registry, WriteStream& stream) const noexcept; + HFSM2_INLINE void deepSaveResumable (const Registry& registry, WriteStream& stream) const noexcept; - HFSM2_INLINE void deepLoadRequested ( Registry& registry, ReadStream& stream) const; - HFSM2_INLINE void deepLoadResumable ( Registry& registry, ReadStream& stream) const; + HFSM2_INLINE void deepLoadRequested ( Registry& registry, ReadStream& stream) const noexcept; + HFSM2_INLINE void deepLoadResumable ( Registry& registry, ReadStream& stream) const noexcept; #endif // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -255,7 +256,7 @@ struct C_ final { void deepGetNames(const Long parent, const RegionType region, const Short depth, - StructureStateInfos& stateInfos) const; + StructureStateInfos& stateInfos) const noexcept; #endif //---------------------------------------------------------------------- diff --git a/include/hfsm2/detail/structure/composite.inl b/include/hfsm2/detail/structure/composite.inl index 282418b..d8c1b47 100644 --- a/include/hfsm2/detail/structure/composite.inl +++ b/include/hfsm2/detail/structure/composite.inl @@ -11,7 +11,7 @@ C_::resolveRandom(Control& control, const Utility(& options)[Info::WIDTH], const Utility sum, const Rank(& ranks)[Info::WIDTH], - const Rank top) const + const Rank top) const noexcept { const Utility random = control._rng.next(); HFSM2_ASSERT(0.0f <= random && random < 1.0f); @@ -42,7 +42,7 @@ C_::resolveRandom(Control& control, template void C_::deepRegister(Registry& registry, - const Parent parent) + const Parent parent) noexcept { registry.compoParents[COMPO_INDEX] = parent; @@ -54,7 +54,7 @@ C_::deepRegister(Registry& registry, template bool -C_::deepForwardEntryGuard(GuardControl& control) { +C_::deepForwardEntryGuard(GuardControl& control) noexcept { const Short active = compoActive (control); const Short requested = compoRequested(control); @@ -72,7 +72,7 @@ C_::deepForwardEntryGuard(GuardControl& control) { template bool -C_::deepEntryGuard(GuardControl& control) { +C_::deepEntryGuard(GuardControl& control) noexcept { const Short requested = compoRequested(control); HFSM2_ASSERT(requested != INVALID_SHORT); @@ -86,7 +86,7 @@ C_::deepEntryGuard(GuardControl& control) { template void -C_::deepConstruct(PlanControl& control) { +C_::deepConstruct(PlanControl& control) noexcept { Short& active = compoActive (control); Short& resumable = compoResumable(control); Short& requested = compoRequested(control); @@ -109,7 +109,7 @@ C_::deepConstruct(PlanControl& control) { template void -C_::deepEnter(PlanControl& control) { +C_::deepEnter(PlanControl& control) noexcept { const Short& active = compoActive(control); HFSM2_ASSERT(active != INVALID_SHORT); @@ -123,7 +123,7 @@ C_::deepEnter(PlanControl& control) { template void -C_::deepReenter(PlanControl& control) { +C_::deepReenter(PlanControl& control) noexcept { Short& active = compoActive (control); Short& resumable = compoResumable(control); Short& requested = compoRequested(control); @@ -155,7 +155,7 @@ C_::deepReenter(PlanControl& control) { template Status -C_::deepUpdate(FullControl& control) { +C_::deepUpdate(FullControl& control) noexcept { const Short active = compoActive(control); HFSM2_ASSERT(active != INVALID_SHORT); @@ -189,7 +189,7 @@ template template Status C_::deepReact(FullControl& control, - const TEvent& event) + const TEvent& event) noexcept { const Short active = compoActive(control); HFSM2_ASSERT(active != INVALID_SHORT); @@ -223,7 +223,7 @@ C_::deepReact(FullControl& control, template bool -C_::deepForwardExitGuard(GuardControl& control) { +C_::deepForwardExitGuard(GuardControl& control) noexcept { const Short active = compoActive(control); HFSM2_ASSERT(active != INVALID_SHORT); @@ -239,7 +239,7 @@ C_::deepForwardExitGuard(GuardControl& control) { template bool -C_::deepExitGuard(GuardControl& control) { +C_::deepExitGuard(GuardControl& control) noexcept { const Short active = compoActive(control); HFSM2_ASSERT(active != INVALID_SHORT); @@ -253,7 +253,7 @@ C_::deepExitGuard(GuardControl& control) { template void -C_::deepExit(PlanControl& control) { +C_::deepExit(PlanControl& control) noexcept { Short& active = compoActive(control); HFSM2_ASSERT(active != INVALID_SHORT); @@ -265,7 +265,7 @@ C_::deepExit(PlanControl& control) { template void -C_::deepDestruct(PlanControl& control) { +C_::deepDestruct(PlanControl& control) noexcept { Short& active = compoActive (control); Short& resumable = compoResumable(control); @@ -288,7 +288,7 @@ C_::deepDestruct(PlanControl& control) { template void C_::deepForwardActive(Control& control, - const Request request) + const Request request) noexcept { HFSM2_ASSERT(control._registry.isActive(HEAD_ID)); @@ -307,7 +307,7 @@ C_::deepForwardActive(Control& control, template void C_::deepForwardRequest(Control& control, - const Request request) + const Request request) noexcept { HFSM2_IF_TRANSITION_HISTORY(control.pinLastTransition(HEAD_ID, request.index)); @@ -324,7 +324,7 @@ C_::deepForwardRequest(Control& control, template void C_::deepRequest(Control& control, - const Request request) + const Request request) noexcept { switch (request.type) { case TransitionType::CHANGE: @@ -363,7 +363,7 @@ C_::deepRequest(Control& control, template void C_::deepRequestChange(Control& control, - const Request request) + const Request request) noexcept { switch (STRATEGY) { case Strategy::Composite: @@ -398,7 +398,7 @@ C_::deepRequestChange(Control& control, template void C_::deepRequestChangeComposite(Control& control, - const Request request) + const Request request) noexcept { HFSM2_IF_TRANSITION_HISTORY(control.pinLastTransition(HEAD_ID, request.index)); @@ -414,7 +414,7 @@ C_::deepRequestChangeComposite(Control& control, template void C_::deepRequestChangeResumable(Control& control, - const Request request) + const Request request) noexcept { HFSM2_IF_TRANSITION_HISTORY(control.pinLastTransition(HEAD_ID, request.index)); @@ -434,7 +434,7 @@ C_::deepRequestChangeResumable(Control& control, template void C_::deepRequestChangeUtilitarian(Control& control, - const Request HFSM2_IF_TRANSITION_HISTORY(request)) + const Request HFSM2_IF_TRANSITION_HISTORY(request)) noexcept { HFSM2_IF_TRANSITION_HISTORY(control.pinLastTransition(HEAD_ID, request.index)); @@ -452,7 +452,7 @@ C_::deepRequestChangeUtilitarian(Control& control, template void C_::deepRequestChangeRandom(Control& control, - const Request HFSM2_IF_TRANSITION_HISTORY(request)) + const Request HFSM2_IF_TRANSITION_HISTORY(request)) noexcept { HFSM2_IF_TRANSITION_HISTORY(control.pinLastTransition(HEAD_ID, request.index)); @@ -474,7 +474,7 @@ C_::deepRequestChangeRandom(Control& control, template void C_::deepRequestRestart(Control& control, - const Request request) + const Request request) noexcept { HFSM2_IF_TRANSITION_HISTORY(control.pinLastTransition(HEAD_ID, request.index)); @@ -490,7 +490,7 @@ C_::deepRequestRestart(Control& control, template void C_::deepRequestResume(Control& control, - const Request request) + const Request request) noexcept { HFSM2_IF_TRANSITION_HISTORY(control.pinLastTransition(HEAD_ID, request.index)); @@ -510,7 +510,7 @@ C_::deepRequestResume(Control& control, template void C_::deepRequestUtilize(Control& control, - const Request HFSM2_IF_TRANSITION_HISTORY(request)) + const Request HFSM2_IF_TRANSITION_HISTORY(request)) noexcept { HFSM2_IF_TRANSITION_HISTORY(control.pinLastTransition(HEAD_ID, request.index)); @@ -527,7 +527,7 @@ C_::deepRequestUtilize(Control& control, template void C_::deepRequestRandomize(Control& control, - const Request HFSM2_IF_TRANSITION_HISTORY(request)) + const Request HFSM2_IF_TRANSITION_HISTORY(request)) noexcept { HFSM2_IF_TRANSITION_HISTORY(control.pinLastTransition(HEAD_ID, request.index)); @@ -551,7 +551,7 @@ C_::deepRequestRandomize(Control& control, template typename TA::UP -C_::deepReportChange(Control& control) { +C_::deepReportChange(Control& control) noexcept { switch (STRATEGY) { case Strategy::Composite: return deepReportChangeComposite (control); @@ -577,7 +577,7 @@ C_::deepReportChange(Control& control) { template typename TA::UP -C_::deepReportChangeComposite(Control& control) { +C_::deepReportChangeComposite(Control& control) noexcept { Short& requested = compoRequested(control); requested = 0; @@ -594,7 +594,7 @@ C_::deepReportChangeComposite(Control& control) { template typename TA::UP -C_::deepReportChangeResumable(Control& control) { +C_::deepReportChangeResumable(Control& control) noexcept { const Short resumable = compoResumable(control); Short& requested = compoRequested(control); @@ -614,7 +614,7 @@ C_::deepReportChangeResumable(Control& control) { template typename TA::UP -C_::deepReportChangeUtilitarian(Control& control) { +C_::deepReportChangeUtilitarian(Control& control) noexcept { const UP h = _headState.deepReportChange(control); const UP s = _subStates.wideReportChangeUtilitarian(control); @@ -633,7 +633,7 @@ C_::deepReportChangeUtilitarian(Control& control) { template typename TA::UP -C_::deepReportChangeRandom(Control& control) { +C_::deepReportChangeRandom(Control& control) noexcept { const UP h = _headState.deepReportChange(control); Rank ranks[Info::WIDTH]; @@ -656,7 +656,7 @@ C_::deepReportChangeRandom(Control& control) { template typename TA::UP -C_::deepReportUtilize(Control& control) { +C_::deepReportUtilize(Control& control) noexcept { const UP h = _headState.deepReportUtilize(control); const UP s = _subStates.wideReportUtilize(control); @@ -675,7 +675,7 @@ C_::deepReportUtilize(Control& control) { template typename TA::Rank -C_::deepReportRank(Control& control) { +C_::deepReportRank(Control& control) noexcept { return _headState.wrapRank(control); } @@ -683,7 +683,7 @@ C_::deepReportRank(Control& control) { template typename TA::Utility -C_::deepReportRandomize(Control& control) { +C_::deepReportRandomize(Control& control) noexcept { const Utility h = _headState.wrapUtility(control); Rank ranks[Info::WIDTH]; @@ -702,10 +702,11 @@ C_::deepReportRandomize(Control& control) { #endif //------------------------------------------------------------------------------ +// COMMON template void -C_::deepChangeToRequested(PlanControl& control) { +C_::deepChangeToRequested(PlanControl& control) noexcept { Short& active = compoActive (control); Short& resumable = compoResumable(control); Short& requested = compoRequested(control); @@ -740,6 +741,7 @@ C_::deepChangeToRequested(PlanControl& control) { } } +// COMMON //------------------------------------------------------------------------------ #ifdef HFSM2_ENABLE_SERIALIZATION @@ -747,7 +749,7 @@ C_::deepChangeToRequested(PlanControl& control) { template void C_::deepSaveActive(const Registry& registry, - WriteStream& stream) const + WriteStream& stream) const noexcept { const Short active = compoActive (registry); const Short resumable = compoResumable(registry); @@ -768,7 +770,7 @@ C_::deepSaveActive(const Registry& registry, template void C_::deepSaveResumable(const Registry& registry, - WriteStream& stream) const + WriteStream& stream) const noexcept { const Short resumable = compoResumable(registry); @@ -786,7 +788,7 @@ C_::deepSaveResumable(const Registry& registry, template void C_::deepLoadRequested(Registry& registry, - ReadStream& stream) const + ReadStream& stream) const noexcept { Short& resumable = compoResumable(registry); Short& requested = compoRequested(registry); @@ -808,7 +810,7 @@ C_::deepLoadRequested(Registry& registry, template void C_::deepLoadResumable(Registry& registry, - ReadStream& stream) const + ReadStream& stream) const noexcept { Short& resumable = compoResumable(registry); @@ -832,7 +834,7 @@ void C_::deepGetNames(const Long parent, const RegionType regionType, const Short depth, - StructureStateInfos& _stateInfos) const + StructureStateInfos& _stateInfos) const noexcept { _headState.deepGetNames(parent, regionType, depth, _stateInfos); _subStates.wideGetNames(_stateInfos.count() - 1, StructureStateInfo::RegionType::COMPOSITE, depth + 1, _stateInfos); diff --git a/include/hfsm2/detail/structure/composite_sub.hpp b/include/hfsm2/detail/structure/composite_sub.hpp index 19fe8e7..c4d066d 100644 --- a/include/hfsm2/detail/structure/composite_sub.hpp +++ b/include/hfsm2/detail/structure/composite_sub.hpp @@ -43,7 +43,7 @@ struct CS_ final { static constexpr Short L_PRONG = PRONG_INDEX; - using LStateList = LHalf; + using LStateList = LHalfTypes; using LMaterial = CSubMaterial; + using RStateList = RHalfTypes; using RMaterial = CSubMaterial - HFSM2_INLINE T& access(); + HFSM2_INLINE T& access() noexcept; template - HFSM2_INLINE const T& access() const; + HFSM2_INLINE const T& access() const noexcept; #endif // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE void wideRegister (Registry& registry, const Parent parent); + HFSM2_INLINE void wideRegister (Registry& registry, const Parent parent) noexcept; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE bool wideForwardEntryGuard (GuardControl& control, const Short prong); - HFSM2_INLINE bool wideEntryGuard (GuardControl& control, const Short prong); + HFSM2_INLINE bool wideForwardEntryGuard (GuardControl& control, const Short prong) noexcept; + HFSM2_INLINE bool wideEntryGuard (GuardControl& control, const Short prong) noexcept; - HFSM2_INLINE void wideConstruct (PlanControl& control, const Short prong); + HFSM2_INLINE void wideConstruct (PlanControl& control, const Short prong) noexcept; - HFSM2_INLINE void wideEnter (PlanControl& control, const Short prong); - HFSM2_INLINE void wideReenter (PlanControl& control, const Short prong); + HFSM2_INLINE void wideEnter (PlanControl& control, const Short prong) noexcept; + HFSM2_INLINE void wideReenter (PlanControl& control, const Short prong) noexcept; - HFSM2_INLINE Status wideUpdate (FullControl& control, const Short prong); + HFSM2_INLINE Status wideUpdate (FullControl& control, const Short prong) noexcept; template - HFSM2_INLINE Status wideReact (FullControl& control, const TEvent& event, const Short prong); + HFSM2_INLINE Status wideReact (FullControl& control, + const TEvent& event, const Short prong) noexcept; - HFSM2_INLINE bool wideForwardExitGuard (GuardControl& control, const Short prong); - HFSM2_INLINE bool wideExitGuard (GuardControl& control, const Short prong); + HFSM2_INLINE bool wideForwardExitGuard (GuardControl& control, const Short prong) noexcept; + HFSM2_INLINE bool wideExitGuard (GuardControl& control, const Short prong) noexcept; - HFSM2_INLINE void wideExit (PlanControl& control, const Short prong); + HFSM2_INLINE void wideExit (PlanControl& control, const Short prong) noexcept; - HFSM2_INLINE void wideDestruct (PlanControl& control, const Short prong); + HFSM2_INLINE void wideDestruct (PlanControl& control, const Short prong) noexcept; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE void wideForwardActive (Control& control, const Request request, const Short prong); - HFSM2_INLINE void wideForwardRequest (Control& control, const Request request, const Short prong); + HFSM2_INLINE void wideForwardActive (Control& control, const Request request, const Short prong) noexcept; + HFSM2_INLINE void wideForwardRequest (Control& control, const Request request, const Short prong) noexcept; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE void wideRequestChangeComposite (Control& control, const Request request); - HFSM2_INLINE void wideRequestChangeResumable (Control& control, const Request request, const Short prong); + HFSM2_INLINE void wideRequestChangeComposite (Control& control, const Request request ) noexcept; + HFSM2_INLINE void wideRequestChangeResumable (Control& control, const Request request, const Short prong) noexcept; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE void wideRequestRestart (Control& control, const Request request); - HFSM2_INLINE void wideRequestResume (Control& control, const Request request, const Short prong); + HFSM2_INLINE void wideRequestRestart (Control& control, const Request request ) noexcept; + HFSM2_INLINE void wideRequestResume (Control& control, const Request request, const Short prong) noexcept; #ifdef HFSM2_ENABLE_UTILITY_THEORY /* - HFSM2_INLINE void wideRequestUtilize (Control& control, const Request request); - HFSM2_INLINE void wideRequestRandomize (Control& control, const Request request); + HFSM2_INLINE void wideRequestUtilize (Control& control, const Request request) noexcept; + HFSM2_INLINE void wideRequestRandomize (Control& control, const Request request) noexcept; */ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE UP wideReportChangeComposite (Control& control); - HFSM2_INLINE UP wideReportChangeResumable (Control& control, const Short prong); - HFSM2_INLINE UP wideReportChangeUtilitarian (Control& control); - HFSM2_INLINE Utility wideReportChangeRandom (Control& control, Utility* const options, const Rank* const ranks, const Rank top); + HFSM2_INLINE UP wideReportChangeComposite (Control& control ) noexcept; + HFSM2_INLINE UP wideReportChangeResumable (Control& control, const Short prong ) noexcept; + HFSM2_INLINE UP wideReportChangeUtilitarian (Control& control ) noexcept; + HFSM2_INLINE Utility wideReportChangeRandom (Control& control, Utility* const options, const Rank* const ranks, const Rank top) noexcept; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE UP wideReportUtilize (Control& control); - HFSM2_INLINE Rank wideReportRank (Control& control, Rank* const ranks); - HFSM2_INLINE Utility wideReportRandomize (Control& control, Utility* const options, const Rank* const ranks, const Rank top); + HFSM2_INLINE UP wideReportUtilize (Control& control ) noexcept; + HFSM2_INLINE Rank wideReportRank (Control& control, Rank* const ranks ) noexcept; + HFSM2_INLINE Utility wideReportRandomize (Control& control, Utility* const options, const Rank* const ranks, const Rank top) noexcept; #endif // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE void wideChangeToRequested (PlanControl& control, const Short prong); + HFSM2_INLINE void wideChangeToRequested (PlanControl& control, const Short prong) noexcept; //---------------------------------------------------------------------- @@ -148,11 +149,11 @@ struct CS_ final { using WriteStream = typename Args::WriteStream; using ReadStream = typename Args::ReadStream; - HFSM2_INLINE void wideSaveActive (const Registry& registry, WriteStream& stream, const Short prong) const; - HFSM2_INLINE void wideSaveResumable (const Registry& registry, WriteStream& stream ) const; + HFSM2_INLINE void wideSaveActive (const Registry& registry, WriteStream& stream, const Short prong) const noexcept; + HFSM2_INLINE void wideSaveResumable (const Registry& registry, WriteStream& stream ) const noexcept; - HFSM2_INLINE void wideLoadRequested ( Registry& registry, ReadStream& stream, const Short prong) const; - HFSM2_INLINE void wideLoadResumable ( Registry& registry, ReadStream& stream ) const; + HFSM2_INLINE void wideLoadRequested ( Registry& registry, ReadStream& stream, const Short prong) const noexcept; + HFSM2_INLINE void wideLoadResumable ( Registry& registry, ReadStream& stream ) const noexcept; #endif // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -166,7 +167,7 @@ struct CS_ final { void wideGetNames(const Long parent, const RegionType region, const Short depth, - StructureStateInfos& stateInfos) const; + StructureStateInfos& stateInfos) const noexcept; #endif //---------------------------------------------------------------------- @@ -224,76 +225,77 @@ struct CS_ final { #ifdef HFSM2_EXPLICIT_MEMBER_SPECIALIZATION template - HFSM2_INLINE T& access() { return state.template access(); } + HFSM2_INLINE T& access() noexcept { return state.template access(); } template - HFSM2_INLINE const T& access() const { return state.template access(); } + HFSM2_INLINE const T& access() const noexcept { return state.template access(); } #endif // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE void wideRegister (Registry& registry, const Parent parent); + HFSM2_INLINE void wideRegister (Registry& registry, const Parent parent) noexcept; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE bool wideForwardEntryGuard (GuardControl& control, const Short prong); - HFSM2_INLINE bool wideEntryGuard (GuardControl& control, const Short prong); + HFSM2_INLINE bool wideForwardEntryGuard (GuardControl& control, const Short prong) noexcept; + HFSM2_INLINE bool wideEntryGuard (GuardControl& control, const Short prong) noexcept; - HFSM2_INLINE void wideConstruct (PlanControl& control, const Short prong); + HFSM2_INLINE void wideConstruct (PlanControl& control, const Short prong) noexcept; - HFSM2_INLINE void wideEnter (PlanControl& control, const Short prong); - HFSM2_INLINE void wideReenter (PlanControl& control, const Short prong); + HFSM2_INLINE void wideEnter (PlanControl& control, const Short prong) noexcept; + HFSM2_INLINE void wideReenter (PlanControl& control, const Short prong) noexcept; - HFSM2_INLINE Status wideUpdate (FullControl& control, const Short prong); + HFSM2_INLINE Status wideUpdate (FullControl& control, const Short prong) noexcept; template - HFSM2_INLINE Status wideReact (FullControl& control, const TEvent& event, const Short prong); + HFSM2_INLINE Status wideReact (FullControl& control, + const TEvent& event, const Short prong) noexcept; - HFSM2_INLINE bool wideForwardExitGuard (GuardControl& control, const Short prong); - HFSM2_INLINE bool wideExitGuard (GuardControl& control, const Short prong); + HFSM2_INLINE bool wideForwardExitGuard (GuardControl& control, const Short prong) noexcept; + HFSM2_INLINE bool wideExitGuard (GuardControl& control, const Short prong) noexcept; - HFSM2_INLINE void wideExit (PlanControl& control, const Short prong); + HFSM2_INLINE void wideExit (PlanControl& control, const Short prong) noexcept; - HFSM2_INLINE void wideDestruct (PlanControl& control, const Short prong); + HFSM2_INLINE void wideDestruct (PlanControl& control, const Short prong) noexcept; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE void wideForwardActive (Control& control, const Request request, const Short prong); - HFSM2_INLINE void wideForwardRequest (Control& control, const Request request, const Short prong); + HFSM2_INLINE void wideForwardActive (Control& control, const Request request, const Short prong) noexcept; + HFSM2_INLINE void wideForwardRequest (Control& control, const Request request, const Short prong) noexcept; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE void wideRequestChangeComposite (Control& control, const Request request); - HFSM2_INLINE void wideRequestChangeResumable (Control& control, const Request request, const Short prong); + HFSM2_INLINE void wideRequestChangeComposite (Control& control, const Request request ) noexcept; + HFSM2_INLINE void wideRequestChangeResumable (Control& control, const Request request, const Short prong) noexcept; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE void wideRequestRestart (Control& control, const Request request); - HFSM2_INLINE void wideRequestResume (Control& control, const Request request, const Short prong); + HFSM2_INLINE void wideRequestRestart (Control& control, const Request request ) noexcept; + HFSM2_INLINE void wideRequestResume (Control& control, const Request request, const Short prong) noexcept; #ifdef HFSM2_ENABLE_UTILITY_THEORY /* - HFSM2_INLINE void wideRequestUtilize (Control& control, const Request request); - HFSM2_INLINE void wideRequestRandomize (Control& control, const Request request); + HFSM2_INLINE void wideRequestUtilize (Control& control, const Request request) noexcept; + HFSM2_INLINE void wideRequestRandomize (Control& control, const Request request) noexcept; */ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE UP wideReportChangeComposite (Control& control); - HFSM2_INLINE UP wideReportChangeResumable (Control& control, const Short prong); - HFSM2_INLINE UP wideReportChangeUtilitarian (Control& control); - HFSM2_INLINE Utility wideReportChangeRandom (Control& control, Utility* const options, const Rank* const ranks, const Rank top); + HFSM2_INLINE UP wideReportChangeComposite (Control& control ) noexcept; + HFSM2_INLINE UP wideReportChangeResumable (Control& control, const Short prong ) noexcept; + HFSM2_INLINE UP wideReportChangeUtilitarian (Control& control ) noexcept; + HFSM2_INLINE Utility wideReportChangeRandom (Control& control, Utility* const options, const Rank* const ranks, const Rank top) noexcept; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE UP wideReportUtilize (Control& control); - HFSM2_INLINE Rank wideReportRank (Control& control, Rank* const ranks); - HFSM2_INLINE Utility wideReportRandomize (Control& control, Utility* const options, const Rank* const ranks, const Rank top); + HFSM2_INLINE UP wideReportUtilize (Control& control ) noexcept; + HFSM2_INLINE Rank wideReportRank (Control& control, Rank* const ranks ) noexcept; + HFSM2_INLINE Utility wideReportRandomize (Control& control, Utility* const options, const Rank* const ranks, const Rank top) noexcept; #endif // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE void wideChangeToRequested (PlanControl& control, const Short prong); + HFSM2_INLINE void wideChangeToRequested (PlanControl& control, const Short prong) noexcept; //---------------------------------------------------------------------- @@ -301,11 +303,11 @@ struct CS_ final { using WriteStream = typename Args::WriteStream; using ReadStream = typename Args::ReadStream; - HFSM2_INLINE void wideSaveActive (const Registry& registry, WriteStream& stream, const Short prong) const; - HFSM2_INLINE void wideSaveResumable (const Registry& registry, WriteStream& stream ) const; + HFSM2_INLINE void wideSaveActive (const Registry& registry, WriteStream& stream, const Short prong) const noexcept; + HFSM2_INLINE void wideSaveResumable (const Registry& registry, WriteStream& stream ) const noexcept; - HFSM2_INLINE void wideLoadRequested ( Registry& registry, ReadStream& stream, const Short prong) const; - HFSM2_INLINE void wideLoadResumable ( Registry& registry, ReadStream& stream ) const; + HFSM2_INLINE void wideLoadRequested ( Registry& registry, ReadStream& stream, const Short prong) const noexcept; + HFSM2_INLINE void wideLoadResumable ( Registry& registry, ReadStream& stream ) const noexcept; #endif // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -319,7 +321,7 @@ struct CS_ final { void wideGetNames(const Long parent, const RegionType region, const Short depth, - StructureStateInfos& stateInfos) const; + StructureStateInfos& stateInfos) const noexcept; #endif //---------------------------------------------------------------------- diff --git a/include/hfsm2/detail/structure/composite_sub_1.inl b/include/hfsm2/detail/structure/composite_sub_1.inl index 6a33503..bb315f0 100644 --- a/include/hfsm2/detail/structure/composite_sub_1.inl +++ b/include/hfsm2/detail/structure/composite_sub_1.inl @@ -8,7 +8,7 @@ namespace detail { template template T& -CS_::access() { +CS_::access() noexcept { return contains() ? lHalf.template access() : rHalf.template access(); @@ -19,7 +19,7 @@ CS_::access() { template template const T& -CS_::access() const { +CS_::access() const noexcept { return contains() ? lHalf.template access() : rHalf.template access(); @@ -32,7 +32,7 @@ CS_::access() const { template void CS_::wideRegister(Registry& registry, - const Parent parent) + const Parent parent) noexcept { lHalf.wideRegister(registry, Parent{parent.forkId, L_PRONG}); rHalf.wideRegister(registry, Parent{parent.forkId, R_PRONG}); @@ -43,7 +43,7 @@ CS_::wideRegister(Registry& registry, template bool CS_::wideForwardEntryGuard(GuardControl& control, - const Short prong) + const Short prong) noexcept { HFSM2_ASSERT(prong != INVALID_SHORT); @@ -54,11 +54,12 @@ CS_::wideForwardEntryGuard(GuardControl& control, } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +// COMMON template bool CS_::wideEntryGuard(GuardControl& control, - const Short prong) + const Short prong) noexcept { HFSM2_ASSERT(prong != INVALID_SHORT); @@ -73,7 +74,7 @@ CS_::wideEntryGuard(GuardControl& control, template void CS_::wideConstruct(PlanControl& control, - const Short prong) + const Short prong) noexcept { HFSM2_ASSERT(prong != INVALID_SHORT); @@ -88,7 +89,7 @@ CS_::wideConstruct(PlanControl& control, template void CS_::wideEnter(PlanControl& control, - const Short prong) + const Short prong) noexcept { HFSM2_ASSERT(prong != INVALID_SHORT); @@ -103,7 +104,7 @@ CS_::wideEnter(PlanControl& control, template void CS_::wideReenter(PlanControl& control, - const Short prong) + const Short prong) noexcept { HFSM2_ASSERT(prong != INVALID_SHORT); @@ -118,7 +119,7 @@ CS_::wideReenter(PlanControl& control, template Status CS_::wideUpdate(FullControl& control, - const Short prong) + const Short prong) noexcept { HFSM2_ASSERT(prong != INVALID_SHORT); @@ -134,7 +135,7 @@ template Status CS_::wideReact(FullControl& control, const TEvent& event, - const Short prong) + const Short prong) noexcept { HFSM2_ASSERT(prong != INVALID_SHORT); @@ -148,7 +149,7 @@ CS_::wideReact(FullControl& control, template bool CS_::wideForwardExitGuard(GuardControl& control, - const Short prong) + const Short prong) noexcept { HFSM2_ASSERT(prong != INVALID_SHORT); @@ -159,11 +160,12 @@ CS_::wideForwardExitGuard(GuardControl& control, } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +// COMMON template bool CS_::wideExitGuard(GuardControl& control, - const Short prong) + const Short prong) noexcept { HFSM2_ASSERT(prong != INVALID_SHORT); @@ -178,7 +180,7 @@ CS_::wideExitGuard(GuardControl& control, template void CS_::wideExit(PlanControl& control, - const Short prong) + const Short prong) noexcept { HFSM2_ASSERT(prong != INVALID_SHORT); @@ -193,7 +195,7 @@ CS_::wideExit(PlanControl& control, template void CS_::wideDestruct(PlanControl& control, - const Short prong) + const Short prong) noexcept { HFSM2_ASSERT(prong != INVALID_SHORT); @@ -209,7 +211,7 @@ template void CS_::wideForwardActive(Control& control, const Request request, - const Short prong) + const Short prong) noexcept { HFSM2_ASSERT(prong != INVALID_SHORT); @@ -225,7 +227,7 @@ template void CS_::wideForwardRequest(Control& control, const Request request, - const Short prong) + const Short prong) noexcept { HFSM2_ASSERT(prong != INVALID_SHORT); @@ -240,7 +242,7 @@ CS_::wideForwardRequest(Control& control, template void CS_::wideRequestChangeComposite(Control& control, - const Request request) + const Request request) noexcept { lHalf.wideRequestChangeComposite(control, request); } @@ -251,7 +253,7 @@ template void CS_::wideRequestChangeResumable(Control& control, const Request request, - const Short prong) + const Short prong) noexcept { HFSM2_ASSERT(prong != INVALID_SHORT); @@ -266,7 +268,7 @@ CS_::wideRequestChangeResumable(Control& control, template void CS_::wideRequestRestart(Control& control, - const Request request) + const Request request) noexcept { lHalf.wideRequestRestart(control, request); } @@ -277,7 +279,7 @@ template void CS_::wideRequestResume(Control& control, const Request request, - const Short prong) + const Short prong) noexcept { HFSM2_ASSERT(prong != INVALID_SHORT); @@ -293,7 +295,7 @@ CS_::wideRequestResume(Control& control, template typename TA::UP -CS_::wideReportUtilize(Control& control) { +CS_::wideReportUtilize(Control& control) noexcept { const UP l = lHalf.wideReportUtilize(control); const UP r = rHalf.wideReportUtilize(control); @@ -306,7 +308,7 @@ CS_::wideReportUtilize(Control& control) { template typename TA::Rank CS_::wideReportRank(Control& control, - Rank* const ranks) + Rank* const ranks) noexcept { HFSM2_ASSERT(ranks); @@ -324,7 +326,7 @@ typename TA::Utility CS_::wideReportRandomize(Control& control, Utility* const options, const Rank* const ranks, - const Rank top) + const Rank top) noexcept { HFSM2_ASSERT(options && ranks); @@ -338,7 +340,7 @@ CS_::wideReportRandomize(Control& control, template typename TA::UP -CS_::wideReportChangeComposite(Control& control) { +CS_::wideReportChangeComposite(Control& control) noexcept { return lHalf.wideReportChangeComposite(control); } @@ -347,7 +349,7 @@ CS_::wideReportChangeComposite(Control& control) { template typename TA::UP CS_::wideReportChangeResumable(Control& control, - const Short prong) + const Short prong) noexcept { HFSM2_ASSERT(prong != INVALID_SHORT); @@ -361,7 +363,7 @@ CS_::wideReportChangeResumable(Control& control, template typename TA::UP -CS_::wideReportChangeUtilitarian(Control& control) { +CS_::wideReportChangeUtilitarian(Control& control) noexcept { const UP l = lHalf.wideReportChangeUtilitarian(control); const UP r = rHalf.wideReportChangeUtilitarian(control); @@ -376,7 +378,7 @@ typename TA::Utility CS_::wideReportChangeRandom(Control& control, Utility* const options, const Rank* const ranks, - const Rank top) + const Rank top) noexcept { HFSM2_ASSERT(options && ranks); @@ -389,11 +391,12 @@ CS_::wideReportChangeRandom(Control& control, #endif //------------------------------------------------------------------------------ +// COMMON template void CS_::wideChangeToRequested(PlanControl& control, - const Short prong) + const Short prong) noexcept { HFSM2_ASSERT(prong != INVALID_SHORT); @@ -411,7 +414,7 @@ template void CS_::wideSaveActive(const Registry& registry, WriteStream& stream, - const Short prong) const + const Short prong) const noexcept { HFSM2_ASSERT(prong != INVALID_SHORT); @@ -429,7 +432,7 @@ CS_::wideSaveActive(const Registry& registry, template void CS_::wideSaveResumable(const Registry& registry, - WriteStream& stream) const + WriteStream& stream) const noexcept { lHalf.wideSaveResumable(registry, stream); rHalf.wideSaveResumable(registry, stream); @@ -441,7 +444,7 @@ template void CS_::wideLoadRequested(Registry& registry, ReadStream& stream, - const Short prong) const + const Short prong) const noexcept { HFSM2_ASSERT(prong != INVALID_SHORT); @@ -459,7 +462,7 @@ CS_::wideLoadRequested(Registry& registry, template void CS_::wideLoadResumable(Registry& registry, - ReadStream& stream) const + ReadStream& stream) const noexcept { lHalf.wideLoadResumable(registry, stream); rHalf.wideLoadResumable(registry, stream); @@ -476,7 +479,7 @@ void CS_::wideGetNames(const Long parent, const RegionType /*region*/, const Short depth, - StructureStateInfos& _stateInfos) const + StructureStateInfos& _stateInfos) const noexcept { lHalf.wideGetNames(parent, StructureStateInfo::RegionType::COMPOSITE, depth, _stateInfos); rHalf.wideGetNames(parent, StructureStateInfo::RegionType::COMPOSITE, depth, _stateInfos); diff --git a/include/hfsm2/detail/structure/composite_sub_2.inl b/include/hfsm2/detail/structure/composite_sub_2.inl index 2d840da..6c65279 100644 --- a/include/hfsm2/detail/structure/composite_sub_2.inl +++ b/include/hfsm2/detail/structure/composite_sub_2.inl @@ -6,7 +6,7 @@ namespace detail { template void CS_::wideRegister(Registry& registry, - const Parent parent) + const Parent parent) noexcept { state.deepRegister(registry, Parent{parent.forkId, PRONG_INDEX}); } @@ -16,7 +16,7 @@ CS_::wideRegister(Registry& registry, template bool CS_::wideForwardEntryGuard(GuardControl& control, - const Short HFSM2_IF_ASSERT(prong)) + const Short HFSM2_IF_ASSERT(prong)) noexcept { HFSM2_ASSERT(prong == PRONG_INDEX); @@ -24,11 +24,12 @@ CS_::wideForwardEntryGuard(GuardControl& control, } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +// COMMON template bool CS_::wideEntryGuard(GuardControl& control, - const Short HFSM2_IF_ASSERT(prong)) + const Short HFSM2_IF_ASSERT(prong)) noexcept { HFSM2_ASSERT(prong == PRONG_INDEX); @@ -40,7 +41,7 @@ CS_::wideEntryGuard(GuardControl& control, template void CS_::wideConstruct(PlanControl& control, - const Short HFSM2_IF_ASSERT(prong)) + const Short HFSM2_IF_ASSERT(prong)) noexcept { HFSM2_ASSERT(prong == PRONG_INDEX); @@ -52,7 +53,7 @@ CS_::wideConstruct(PlanControl& control, template void CS_::wideEnter(PlanControl& control, - const Short HFSM2_IF_ASSERT(prong)) + const Short HFSM2_IF_ASSERT(prong)) noexcept { HFSM2_ASSERT(prong == PRONG_INDEX); @@ -64,7 +65,7 @@ CS_::wideEnter(PlanControl& control, template void CS_::wideReenter(PlanControl& control, - const Short HFSM2_IF_ASSERT(prong)) + const Short HFSM2_IF_ASSERT(prong)) noexcept { HFSM2_ASSERT(prong == PRONG_INDEX); @@ -76,7 +77,7 @@ CS_::wideReenter(PlanControl& control, template Status CS_::wideUpdate(FullControl& control, - const Short HFSM2_IF_ASSERT(prong)) + const Short HFSM2_IF_ASSERT(prong)) noexcept { HFSM2_ASSERT(prong == PRONG_INDEX); @@ -90,7 +91,7 @@ template Status CS_::wideReact(FullControl& control, const TEvent& event, - const Short HFSM2_IF_ASSERT(prong)) + const Short HFSM2_IF_ASSERT(prong)) noexcept { HFSM2_ASSERT(prong == PRONG_INDEX); @@ -102,7 +103,7 @@ CS_::wideReact(FullControl& control, template bool CS_::wideForwardExitGuard(GuardControl& control, - const Short HFSM2_IF_ASSERT(prong)) + const Short HFSM2_IF_ASSERT(prong)) noexcept { HFSM2_ASSERT(prong == PRONG_INDEX); @@ -110,11 +111,12 @@ CS_::wideForwardExitGuard(GuardControl& control, } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +// COMMON template bool CS_::wideExitGuard(GuardControl& control, - const Short HFSM2_IF_ASSERT(prong)) + const Short HFSM2_IF_ASSERT(prong)) noexcept { HFSM2_ASSERT(prong == PRONG_INDEX); @@ -126,7 +128,7 @@ CS_::wideExitGuard(GuardControl& control, template void CS_::wideExit(PlanControl& control, - const Short HFSM2_IF_ASSERT(prong)) + const Short HFSM2_IF_ASSERT(prong)) noexcept { HFSM2_ASSERT(prong == PRONG_INDEX); @@ -138,7 +140,7 @@ CS_::wideExit(PlanControl& control, template void CS_::wideDestruct(PlanControl& control, - const Short HFSM2_IF_ASSERT(prong)) + const Short HFSM2_IF_ASSERT(prong)) noexcept { HFSM2_ASSERT(prong == PRONG_INDEX); @@ -151,7 +153,7 @@ template void CS_::wideForwardActive(Control& control, const Request request, - const Short HFSM2_IF_ASSERT(prong)) + const Short HFSM2_IF_ASSERT(prong)) noexcept { HFSM2_ASSERT(prong == PRONG_INDEX); @@ -164,7 +166,7 @@ template void CS_::wideForwardRequest(Control& control, const Request request, - const Short HFSM2_IF_ASSERT(prong)) + const Short HFSM2_IF_ASSERT(prong)) noexcept { HFSM2_ASSERT(prong == PRONG_INDEX); @@ -176,7 +178,7 @@ CS_::wideForwardRequest(Control& control, template void CS_::wideRequestChangeComposite(Control& control, - const Request request) + const Request request) noexcept { state.deepRequestChange(control, request); } @@ -187,7 +189,7 @@ template void CS_::wideRequestChangeResumable(Control& control, const Request request, - const Short HFSM2_IF_ASSERT(prong)) + const Short HFSM2_IF_ASSERT(prong)) noexcept { HFSM2_ASSERT(prong == PRONG_INDEX); @@ -199,7 +201,7 @@ CS_::wideRequestChangeResumable(Control& control, template void CS_::wideRequestRestart(Control& control, - const Request request) + const Request request) noexcept { state.deepRequestRestart(control, request); } @@ -210,7 +212,7 @@ template void CS_::wideRequestResume(Control& control, const Request request, - const Short HFSM2_IF_ASSERT(prong)) + const Short HFSM2_IF_ASSERT(prong)) noexcept { HFSM2_ASSERT(prong == PRONG_INDEX); @@ -223,7 +225,7 @@ CS_::wideRequestResume(Control& control, template typename TA::UP -CS_::wideReportUtilize(Control& control) { +CS_::wideReportUtilize(Control& control) noexcept { return state.deepReportUtilize(control); } @@ -232,7 +234,7 @@ CS_::wideReportUtilize(Control& control) { template typename TA::Rank CS_::wideReportRank(Control& control, - Rank* const ranks) + Rank* const ranks) noexcept { HFSM2_ASSERT(ranks); @@ -248,7 +250,7 @@ typename TA::Utility CS_::wideReportRandomize(Control& control, Utility* const options, const Rank* const ranks, - const Rank top) + const Rank top) noexcept { HFSM2_ASSERT(options && ranks); @@ -262,7 +264,7 @@ CS_::wideReportRandomize(Control& control, template typename TA::UP -CS_::wideReportChangeComposite(Control& control) { +CS_::wideReportChangeComposite(Control& control) noexcept { return state.deepReportChange(control); } @@ -271,7 +273,7 @@ CS_::wideReportChangeComposite(Control& control) { template typename TA::UP CS_::wideReportChangeResumable(Control& control, - const Short HFSM2_IF_ASSERT(prong)) + const Short HFSM2_IF_ASSERT(prong)) noexcept { HFSM2_ASSERT(prong == PRONG_INDEX); @@ -282,7 +284,7 @@ CS_::wideReportChangeResumable(Control& control, template typename TA::UP -CS_::wideReportChangeUtilitarian(Control& control) { +CS_::wideReportChangeUtilitarian(Control& control) noexcept { return state.deepReportChange(control); } @@ -293,7 +295,7 @@ typename TA::Utility CS_::wideReportChangeRandom(Control& control, Utility* const options, const Rank* const ranks, - const Rank top) + const Rank top) noexcept { HFSM2_ASSERT(options && ranks); @@ -310,7 +312,7 @@ CS_::wideReportChangeRandom(Control& control, template void CS_::wideChangeToRequested(PlanControl& control, - const Short HFSM2_IF_ASSERT(prong)) + const Short HFSM2_IF_ASSERT(prong)) noexcept { HFSM2_ASSERT(prong == PRONG_INDEX); @@ -325,7 +327,7 @@ template void CS_::wideSaveActive(const Registry& registry, WriteStream& stream, - const Short HFSM2_IF_ASSERT(prong)) const + const Short HFSM2_IF_ASSERT(prong)) const noexcept { HFSM2_ASSERT(prong == PRONG_INDEX); @@ -337,7 +339,7 @@ CS_::wideSaveActive(const Registry& registry, template void CS_::wideSaveResumable(const Registry& registry, - WriteStream& stream) const + WriteStream& stream) const noexcept { state.deepSaveResumable(registry, stream); } @@ -348,7 +350,7 @@ template void CS_::wideLoadRequested(Registry& registry, ReadStream& stream, - const Short HFSM2_IF_ASSERT(prong)) const + const Short HFSM2_IF_ASSERT(prong)) const noexcept { HFSM2_ASSERT(prong == PRONG_INDEX); @@ -360,7 +362,7 @@ CS_::wideLoadRequested(Registry& registry, template void CS_::wideLoadResumable(Registry& registry, - ReadStream& stream) const + ReadStream& stream) const noexcept { state.deepLoadResumable(registry, stream); } @@ -376,7 +378,7 @@ void CS_::wideGetNames(const Long parent, const RegionType /*region*/, const Short depth, - StructureStateInfos& _stateInfos) const + StructureStateInfos& _stateInfos) const noexcept { state.deepGetNames(parent, StructureStateInfo::RegionType::COMPOSITE, depth, _stateInfos); } diff --git a/include/hfsm2/detail/structure/forward.hpp b/include/hfsm2/detail/structure/forward.hpp index 8f096b9..5b51d2c 100644 --- a/include/hfsm2/detail/structure/forward.hpp +++ b/include/hfsm2/detail/structure/forward.hpp @@ -62,8 +62,8 @@ using WrapInfo = typename WrapInfoT::Type; template struct SI_ final { using Head = THead; - using StateList = TypeList; - using RegionList = TypeList<>; + using StateList = TL_; + using RegionList = TL_<>; static constexpr Short WIDTH = 1; static constexpr Long REVERSE_DEPTH = 1; @@ -243,15 +243,15 @@ struct ArgsT final { static constexpr Long TASK_CAPACITY = NTaskCapacity; #endif - using Payload = TPayload; + using Payload = TPayload; #ifdef HFSM2_ENABLE_SERIALIZATION - using SerialBuffer = StreamBuffer ; - using WriteStream = BitWriteStream; - using ReadStream = BitReadStream ; + using SerialBuffer = StreamBufferT ; + using WriteStream = BitWriteStreamT; + using ReadStream = BitReadStreamT ; #endif - HFSM2_IF_STRUCTURE_REPORT(using StructureStateInfos = Array); + HFSM2_IF_STRUCTURE_REPORT(using StructureStateInfos = ArrayT); }; //------------------------------------------------------------------------------ @@ -285,7 +285,7 @@ template struct OS_; template -class RW_; +class RR_; //------------------------------------------------------------------------------ @@ -363,7 +363,7 @@ struct RF_ final { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - using Instance = RW_; + using Instance = RR_; using Control = ControlT ; using FullControl = FullControlT ; @@ -401,13 +401,13 @@ struct RF_ final { //---------------------------------------------------------------------- template - static constexpr bool contains() { return contains(); } + static constexpr bool contains() noexcept { return contains(); } template - static constexpr StateID stateId() { return index(); } + static constexpr StateID stateId() noexcept { return index (); } template - static constexpr RegionID regionId() { return (RegionID) index(); } + static constexpr RegionID regionId() noexcept { return (RegionID) index(); } }; //////////////////////////////////////////////////////////////////////////////// @@ -416,7 +416,7 @@ template struct CSubMaterialT; template -struct CSubMaterialT> { +struct CSubMaterialT> { using Type = CS_; }; diff --git a/include/hfsm2/detail/structure/injections.hpp b/include/hfsm2/detail/structure/injections.hpp index 487cff9..23c6ee2 100644 --- a/include/hfsm2/detail/structure/injections.hpp +++ b/include/hfsm2/detail/structure/injections.hpp @@ -30,26 +30,26 @@ class InjectionT { using GuardControl = GuardControlT; public: - HFSM2_INLINE void preEntryGuard(Context&) {} + HFSM2_INLINE void preEntryGuard(Context&) noexcept {} - HFSM2_INLINE void preEnter (Context&) {} - HFSM2_INLINE void preReenter (Context&) {} + HFSM2_INLINE void preEnter (Context&) noexcept {} + HFSM2_INLINE void preReenter (Context&) noexcept {} - HFSM2_INLINE void preUpdate (Context&) {} + HFSM2_INLINE void preUpdate (Context&) noexcept {} template HFSM2_INLINE void preReact (const TEvent&, - Context&) {} + Context&) noexcept {} - HFSM2_INLINE void preExitGuard (Context&) {} + HFSM2_INLINE void preExitGuard (Context&) noexcept {} - HFSM2_INLINE void postExit (Context&) {} + HFSM2_INLINE void postExit (Context&) noexcept {} template - static constexpr StateID stateId() { return index(); } - - template - static constexpr RegionID regionId() { return (RegionID) index(); } + static constexpr StateID stateId() noexcept { return index(); } + + template + static constexpr RegionID regionId() noexcept { return (RegionID) index(); } }; //------------------------------------------------------------------------------ @@ -87,20 +87,20 @@ struct B_ using TFirst::stateId; using TFirst::regionId; - HFSM2_INLINE void widePreEntryGuard(Context& context); + HFSM2_INLINE void widePreEntryGuard(Context& context) noexcept; - HFSM2_INLINE void widePreEnter (Context& context); - HFSM2_INLINE void widePreReenter (Context& context); + HFSM2_INLINE void widePreEnter (Context& context) noexcept; + HFSM2_INLINE void widePreReenter (Context& context) noexcept; - HFSM2_INLINE void widePreUpdate (Context& context); + HFSM2_INLINE void widePreUpdate (Context& context) noexcept; template HFSM2_INLINE void widePreReact (const TEvent& event, - Context& context); + Context& context) noexcept; - HFSM2_INLINE void widePreExitGuard (Context& context); + HFSM2_INLINE void widePreExitGuard (Context& context) noexcept; - HFSM2_INLINE void widePostExit (Context& context); + HFSM2_INLINE void widePostExit (Context& context) noexcept; }; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -133,44 +133,44 @@ struct B_ using TFirst::regionId; #ifdef HFSM2_ENABLE_UTILITY_THEORY - HFSM2_INLINE Rank rank (const Control&) { return Rank {0}; } - HFSM2_INLINE Utility utility (const Control&) { return Utility{1}; } + HFSM2_INLINE Rank rank (const Control&) noexcept { return Rank {0}; } + HFSM2_INLINE Utility utility (const Control&) noexcept { return Utility{1}; } #endif - HFSM2_INLINE void entryGuard (GuardControl&) {} + HFSM2_INLINE void entryGuard (GuardControl&) noexcept {} - HFSM2_INLINE void enter (PlanControl&) {} - HFSM2_INLINE void reenter (PlanControl&) {} + HFSM2_INLINE void enter (PlanControl&) noexcept {} + HFSM2_INLINE void reenter (PlanControl&) noexcept {} - HFSM2_INLINE void update (FullControl&) {} + HFSM2_INLINE void update (FullControl&) noexcept {} template HFSM2_INLINE void react (const TEvent&, - FullControl&) {} + FullControl&) noexcept {} - HFSM2_INLINE void exitGuard (GuardControl&) {} + HFSM2_INLINE void exitGuard (GuardControl&) noexcept {} - HFSM2_INLINE void exit (PlanControl&) {} + HFSM2_INLINE void exit (PlanControl&) noexcept {} #ifdef HFSM2_ENABLE_PLANS - HFSM2_INLINE void planSucceeded (FullControl& control) { control.succeed(); } - HFSM2_INLINE void planFailed (FullControl& control) { control.fail(); } + HFSM2_INLINE void planSucceeded (FullControl& control) noexcept { control.succeed(); } + HFSM2_INLINE void planFailed (FullControl& control) noexcept { control.fail(); } #endif - HFSM2_INLINE void widePreEntryGuard(Context& context); + HFSM2_INLINE void widePreEntryGuard(Context& context) noexcept; - HFSM2_INLINE void widePreEnter (Context& context); - HFSM2_INLINE void widePreReenter (Context& context); + HFSM2_INLINE void widePreEnter (Context& context) noexcept; + HFSM2_INLINE void widePreReenter (Context& context) noexcept; - HFSM2_INLINE void widePreUpdate (Context& context); + HFSM2_INLINE void widePreUpdate (Context& context) noexcept; template HFSM2_INLINE void widePreReact (const TEvent& event, - Context& context); + Context& context) noexcept; - HFSM2_INLINE void widePreExitGuard (Context& context); + HFSM2_INLINE void widePreExitGuard (Context& context) noexcept; - HFSM2_INLINE void widePostExit (Context& context); + HFSM2_INLINE void widePostExit (Context& context) noexcept; }; //------------------------------------------------------------------------------ diff --git a/include/hfsm2/detail/structure/injections.inl b/include/hfsm2/detail/structure/injections.inl index a457f35..92f7a6a 100644 --- a/include/hfsm2/detail/structure/injections.inl +++ b/include/hfsm2/detail/structure/injections.inl @@ -5,7 +5,7 @@ namespace detail { template void -B_::widePreEntryGuard(Context& context) { +B_::widePreEntryGuard(Context& context) noexcept { TF::preEntryGuard(context); B_::widePreEntryGuard(context); } @@ -14,7 +14,7 @@ B_::widePreEntryGuard(Context& context) { template void -B_::widePreEnter(Context& context) { +B_::widePreEnter(Context& context) noexcept { TF::preEnter(context); B_::widePreEnter(context); } @@ -23,7 +23,7 @@ B_::widePreEnter(Context& context) { template void -B_::widePreReenter(Context& context) { +B_::widePreReenter(Context& context) noexcept { TF::preReenter(context); B_::widePreReenter(context); } @@ -32,7 +32,7 @@ B_::widePreReenter(Context& context) { template void -B_::widePreUpdate(Context& context) { +B_::widePreUpdate(Context& context) noexcept { TF::preUpdate(context); B_::widePreUpdate(context); } @@ -43,7 +43,7 @@ template template void B_::widePreReact(const TEvent& event, - Context& context) + Context& context) noexcept { TF::preReact(event, context); B_::widePreReact(event, context); @@ -53,7 +53,7 @@ B_::widePreReact(const TEvent& event, template void -B_::widePreExitGuard(Context& context) { +B_::widePreExitGuard(Context& context) noexcept { TF::preExitGuard(context); B_::widePreExitGuard(context); } @@ -62,7 +62,7 @@ B_::widePreExitGuard(Context& context) { template void -B_::widePostExit(Context& context) { +B_::widePostExit(Context& context) noexcept { TF::postExit(context); B_::widePostExit(context); } @@ -71,7 +71,7 @@ B_::widePostExit(Context& context) { template void -B_::widePreEntryGuard(Context& context) { +B_::widePreEntryGuard(Context& context) noexcept { TF::preEntryGuard(context); } @@ -79,7 +79,7 @@ B_::widePreEntryGuard(Context& context) { template void -B_::widePreEnter(Context& context) { +B_::widePreEnter(Context& context) noexcept { TF::preEnter(context); } @@ -87,7 +87,7 @@ B_::widePreEnter(Context& context) { template void -B_::widePreReenter(Context& context) { +B_::widePreReenter(Context& context) noexcept { TF::preReenter(context); } @@ -95,7 +95,7 @@ B_::widePreReenter(Context& context) { template void -B_::widePreUpdate(Context& context) { +B_::widePreUpdate(Context& context) noexcept { TF::preUpdate(context); } @@ -105,7 +105,7 @@ template template void B_::widePreReact(const TEvent& event, - Context& context) + Context& context) noexcept { TF::preReact(event, context); } @@ -114,7 +114,7 @@ B_::widePreReact(const TEvent& event, template void -B_::widePreExitGuard(Context& context) { +B_::widePreExitGuard(Context& context) noexcept { TF::preExitGuard(context); } @@ -122,7 +122,7 @@ B_::widePreExitGuard(Context& context) { template void -B_::widePostExit(Context& context) { +B_::widePostExit(Context& context) noexcept { TF::postExit(context); } diff --git a/include/hfsm2/detail/structure/orthogonal.hpp b/include/hfsm2/detail/structure/orthogonal.hpp index 963122a..2eafab9 100644 --- a/include/hfsm2/detail/structure/orthogonal.hpp +++ b/include/hfsm2/detail/structure/orthogonal.hpp @@ -39,7 +39,7 @@ struct O_ final { using StateParents = typename Registry::StateParents; using OrthoForks = typename Registry::OrthoForks; using ProngBits = typename OrthoForks::Bits; - using ProngConstBits= typename OrthoForks::ConstBits; + using ProngCBits = typename OrthoForks::CBits; using Control = ControlT; using ScopedOrigin = typename Control::Origin; @@ -87,10 +87,10 @@ struct O_ final { //---------------------------------------------------------------------- HFSM2_INLINE ProngBits orthoRequested( Registry& registry) { return registry.orthoRequested.template bits(); } - HFSM2_INLINE ProngConstBits orthoRequested(const Registry& registry) const { return registry.orthoRequested.template bits(); } + HFSM2_INLINE ProngCBits orthoRequested(const Registry& registry) const { return registry.orthoRequested.template bits(); } HFSM2_INLINE ProngBits orthoRequested( Control& control) { return orthoRequested(control._registry); } - HFSM2_INLINE ProngConstBits orthoRequested(const Control& control) const { return orthoRequested(control._registry); } + HFSM2_INLINE ProngCBits orthoRequested(const Control& control) const { return orthoRequested(control._registry); } HFSM2_INLINE void deepRegister (Registry& registry, const Parent parent); diff --git a/include/hfsm2/detail/structure/orthogonal.inl b/include/hfsm2/detail/structure/orthogonal.inl index 3ff3651..62373b1 100644 --- a/include/hfsm2/detail/structure/orthogonal.inl +++ b/include/hfsm2/detail/structure/orthogonal.inl @@ -20,7 +20,7 @@ O_::deepRegister(Registry& registry, template bool O_::deepForwardEntryGuard(GuardControl& control) { - const ProngConstBits requested = orthoRequested(static_cast(control)); + const ProngCBits requested = orthoRequested(static_cast(control)); ScopedRegion region{control, REGION_ID, HEAD_ID, REGION_SIZE}; @@ -144,7 +144,7 @@ O_::deepReact(FullControl& control, template bool O_::deepForwardExitGuard(GuardControl& control) { - const ProngConstBits requested = orthoRequested(static_cast(control)); + const ProngCBits requested = orthoRequested(static_cast(control)); ScopedRegion region{control, REGION_ID, HEAD_ID, REGION_SIZE}; @@ -192,7 +192,7 @@ O_::deepForwardActive(Control& control, { HFSM2_ASSERT(control._registry.isActive(HEAD_ID)); - const ProngConstBits requested = orthoRequested(static_cast(control)); + const ProngCBits requested = orthoRequested(static_cast(control)); HFSM2_ASSERT(!!requested); _subStates.wideForwardActive(control, request, requested); @@ -207,7 +207,7 @@ O_::deepForwardRequest(Control& control, { HFSM2_IF_TRANSITION_HISTORY(control.pinLastTransition(HEAD_ID, request.index)); - const ProngConstBits requested = orthoRequested(static_cast(control)); + const ProngCBits requested = orthoRequested(static_cast(control)); if (requested) _subStates.wideForwardRequest(control, request); diff --git a/include/hfsm2/detail/structure/orthogonal_sub.hpp b/include/hfsm2/detail/structure/orthogonal_sub.hpp index ab67f3f..278bdd3 100644 --- a/include/hfsm2/detail/structure/orthogonal_sub.hpp +++ b/include/hfsm2/detail/structure/orthogonal_sub.hpp @@ -34,7 +34,7 @@ struct OS_ final { using StateParents = typename Registry::StateParents; using OrthoForks = typename Registry::OrthoForks; using ProngBits = typename OrthoForks::Bits; - using ProngConstBits= typename OrthoForks::ConstBits; + using ProngCBits= typename OrthoForks::CBits; using Control = ControlT ; using PlanControl = PlanControlT ; @@ -77,7 +77,7 @@ struct OS_ final { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE bool wideForwardEntryGuard(GuardControl& control, const ProngConstBits prongs); + HFSM2_INLINE bool wideForwardEntryGuard(GuardControl& control, const ProngCBits prongs); HFSM2_INLINE bool wideForwardEntryGuard(GuardControl& control); HFSM2_INLINE bool wideEntryGuard (GuardControl& control); @@ -91,7 +91,7 @@ struct OS_ final { template HFSM2_INLINE Status wideReact (FullControl& control, const TEvent& event); - HFSM2_INLINE bool wideForwardExitGuard (GuardControl& control, const ProngConstBits prongs); + HFSM2_INLINE bool wideForwardExitGuard (GuardControl& control, const ProngCBits prongs); HFSM2_INLINE bool wideForwardExitGuard (GuardControl& control); HFSM2_INLINE bool wideExitGuard (GuardControl& control); @@ -101,7 +101,7 @@ struct OS_ final { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE void wideForwardActive (Control& control, const Request request, const ProngConstBits prongs); + HFSM2_INLINE void wideForwardActive (Control& control, const Request request, const ProngCBits prongs); HFSM2_INLINE void wideForwardRequest (Control& control, const Request request); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -181,7 +181,7 @@ struct OS_ final { using StateParents = typename Registry::StateParents; using OrthoForks = typename Registry::OrthoForks; using ProngBits = typename OrthoForks::Bits; - using ProngConstBits= typename OrthoForks::ConstBits; + using ProngCBits= typename OrthoForks::CBits; using Control = ControlT ; using PlanControl = PlanControlT ; @@ -213,7 +213,7 @@ struct OS_ final { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE bool wideForwardEntryGuard(GuardControl& control, const ProngConstBits prongs); + HFSM2_INLINE bool wideForwardEntryGuard(GuardControl& control, const ProngCBits prongs); HFSM2_INLINE bool wideForwardEntryGuard(GuardControl& control); HFSM2_INLINE bool wideEntryGuard (GuardControl& control); @@ -227,7 +227,7 @@ struct OS_ final { template HFSM2_INLINE Status wideReact (FullControl& control, const TEvent& event); - HFSM2_INLINE bool wideForwardExitGuard (GuardControl& control, const ProngConstBits prongs); + HFSM2_INLINE bool wideForwardExitGuard (GuardControl& control, const ProngCBits prongs); HFSM2_INLINE bool wideForwardExitGuard (GuardControl& control); HFSM2_INLINE bool wideExitGuard (GuardControl& control); @@ -237,7 +237,7 @@ struct OS_ final { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE void wideForwardActive (Control& control, const Request request, const ProngConstBits prongs); + HFSM2_INLINE void wideForwardActive (Control& control, const Request request, const ProngCBits prongs); HFSM2_INLINE void wideForwardRequest (Control& control, const Request request); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/include/hfsm2/detail/structure/orthogonal_sub_1.inl b/include/hfsm2/detail/structure/orthogonal_sub_1.inl index 8bc864c..98fc941 100644 --- a/include/hfsm2/detail/structure/orthogonal_sub_1.inl +++ b/include/hfsm2/detail/structure/orthogonal_sub_1.inl @@ -43,7 +43,7 @@ OS_::wideRegister(Registry& registry, template bool OS_::wideForwardEntryGuard(GuardControl& control, - const ProngConstBits prongs) + const ProngCBits prongs) { const bool i = prongs.get(PRONG_INDEX) ? initial .deepForwardEntryGuard(control) : false; @@ -128,7 +128,7 @@ OS_::wideReact(FullControl& control, template bool OS_::wideForwardExitGuard(GuardControl& control, - const ProngConstBits prongs) + const ProngCBits prongs) { const bool i = prongs.get(PRONG_INDEX) ? initial .deepForwardExitGuard(control) : false; @@ -184,7 +184,7 @@ template void OS_::wideForwardActive(Control& control, const Request request, - const ProngConstBits prongs) + const ProngCBits prongs) { if (prongs.get(PRONG_INDEX)) initial.deepForwardActive(control, request); diff --git a/include/hfsm2/detail/structure/orthogonal_sub_2.inl b/include/hfsm2/detail/structure/orthogonal_sub_2.inl index a36c025..21926b9 100644 --- a/include/hfsm2/detail/structure/orthogonal_sub_2.inl +++ b/include/hfsm2/detail/structure/orthogonal_sub_2.inl @@ -16,7 +16,7 @@ OS_::wideRegister(Registry& registry, template bool OS_::wideForwardEntryGuard(GuardControl& control, - const ProngConstBits prongs) + const ProngCBits prongs) { return prongs.get(PRONG_INDEX) ? initial.deepForwardEntryGuard(control) : false; @@ -86,7 +86,7 @@ OS_::wideReact(FullControl& control, template bool OS_::wideForwardExitGuard(GuardControl& control, - const ProngConstBits prongs) + const ProngCBits prongs) { return prongs.get(PRONG_INDEX) ? initial.deepForwardExitGuard(control) : false; @@ -130,7 +130,7 @@ template void OS_::wideForwardActive(Control& control, const Request request, - const ProngConstBits prongs) + const ProngCBits prongs) { if (prongs.get(PRONG_INDEX)) initial.deepForwardActive(control, request); diff --git a/include/hfsm2/detail/structure/state.hpp b/include/hfsm2/detail/structure/state.hpp index 05b502d..87a4bfa 100644 --- a/include/hfsm2/detail/structure/state.hpp +++ b/include/hfsm2/detail/structure/state.hpp @@ -44,8 +44,8 @@ struct S_ final { template struct Accessor { - HFSM2_INLINE static T& get( S_& ) { HFSM2_BREAK(); return *reinterpret_cast(0); } - HFSM2_INLINE static const T& get(const S_& ) { HFSM2_BREAK(); return *reinterpret_cast(0); } + HFSM2_INLINE static T& get( S_& ) noexcept { HFSM2_BREAK(); return *reinterpret_cast(0); } + HFSM2_INLINE static const T& get(const S_& ) noexcept { HFSM2_BREAK(); return *reinterpret_cast(0); } }; #ifdef __clang__ @@ -54,83 +54,85 @@ struct S_ final { template <> struct Accessor { - HFSM2_INLINE static Head& get( S_& s) { return s._headBox.get(); } - HFSM2_INLINE static const Head& get(const S_& s) { return s._headBox.get(); } + HFSM2_INLINE static Head& get( S_& s) noexcept { return s._headBox.get(); } + HFSM2_INLINE static const Head& get(const S_& s) noexcept { return s._headBox.get(); } }; template - HFSM2_INLINE T& access() { return Accessor::get(*this); } + HFSM2_INLINE T& access() noexcept { return Accessor::get(*this); } template - HFSM2_INLINE const T& access() const { return Accessor::get(*this); } + HFSM2_INLINE const T& access() const noexcept { return Accessor::get(*this); } #endif //---------------------------------------------------------------------- - HFSM2_INLINE Parent stateParent (Control& control) { return control._registry.stateParents[STATE_ID]; } + HFSM2_INLINE Parent stateParent (Control& control) noexcept { return control._registry.stateParents[STATE_ID]; } - HFSM2_INLINE void deepRegister (Registry& registry, const Parent parent); + HFSM2_INLINE void deepRegister (Registry& registry, + const Parent parent) noexcept; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #ifdef HFSM2_ENABLE_UTILITY_THEORY - HFSM2_INLINE Rank wrapRank (Control& control); - HFSM2_INLINE Utility wrapUtility (Control& control); + HFSM2_INLINE Rank wrapRank (Control& control) noexcept; + HFSM2_INLINE Utility wrapUtility (Control& control) noexcept; #endif // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE bool deepForwardEntryGuard(GuardControl&) { return false; } - HFSM2_INLINE bool deepEntryGuard (GuardControl& control); + HFSM2_INLINE bool deepForwardEntryGuard(GuardControl& ) noexcept { return false; } + HFSM2_INLINE bool deepEntryGuard (GuardControl& control) noexcept; - HFSM2_INLINE void deepConstruct (PlanControl& control); + HFSM2_INLINE void deepConstruct (PlanControl& control) noexcept; - HFSM2_INLINE void deepEnter (PlanControl& control); - HFSM2_INLINE void deepReenter (PlanControl& control); + HFSM2_INLINE void deepEnter (PlanControl& control) noexcept; + HFSM2_INLINE void deepReenter (PlanControl& control) noexcept; - HFSM2_INLINE Status deepUpdate (FullControl& control); + HFSM2_INLINE Status deepUpdate (FullControl& control) noexcept; template - HFSM2_INLINE Status deepReact (FullControl& control, const TEvent& event); + HFSM2_INLINE Status deepReact (FullControl& control, + const TEvent& event) noexcept; - HFSM2_INLINE bool deepForwardExitGuard (GuardControl&) { return false; } - HFSM2_INLINE bool deepExitGuard (GuardControl& control); + HFSM2_INLINE bool deepForwardExitGuard (GuardControl& ) noexcept { return false; } + HFSM2_INLINE bool deepExitGuard (GuardControl& control) noexcept; - HFSM2_INLINE void deepExit (PlanControl& control); + HFSM2_INLINE void deepExit (PlanControl& control) noexcept; - HFSM2_INLINE void deepDestruct (PlanControl& control); + HFSM2_INLINE void deepDestruct (PlanControl& control) noexcept; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #ifdef HFSM2_ENABLE_PLANS - HFSM2_INLINE void wrapPlanSucceeded (FullControl& control); - HFSM2_INLINE void wrapPlanFailed (FullControl& control); + HFSM2_INLINE void wrapPlanSucceeded (FullControl& control) noexcept; + HFSM2_INLINE void wrapPlanFailed (FullControl& control) noexcept; #endif // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE void deepForwardActive (Control&, const Request ) {} - HFSM2_INLINE void deepForwardRequest (Control& control, const Request request); + HFSM2_INLINE void deepForwardActive (Control&, const Request ) noexcept {} + HFSM2_INLINE void deepForwardRequest (Control& control, const Request request) noexcept; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE void deepRequestChange (Control& control, const Request request); - HFSM2_INLINE void deepRequestRestart (Control& control, const Request request); - HFSM2_INLINE void deepRequestResume (Control& control, const Request request); + HFSM2_INLINE void deepRequestChange (Control& control, const Request request) noexcept; + HFSM2_INLINE void deepRequestRestart (Control& control, const Request request) noexcept; + HFSM2_INLINE void deepRequestResume (Control& control, const Request request) noexcept; #ifdef HFSM2_ENABLE_UTILITY_THEORY - HFSM2_INLINE void deepRequestUtilize (Control& control, const Request request); - HFSM2_INLINE void deepRequestRandomize (Control& control, const Request request); + HFSM2_INLINE void deepRequestUtilize (Control& control, const Request request) noexcept; + HFSM2_INLINE void deepRequestRandomize (Control& control, const Request request) noexcept; - HFSM2_INLINE UP deepReportChange (Control& control); - HFSM2_INLINE UP deepReportUtilize (Control& control); - HFSM2_INLINE Rank deepReportRank (Control& control); - HFSM2_INLINE Utility deepReportRandomize (Control& control); + HFSM2_INLINE UP deepReportChange (Control& control) noexcept; + HFSM2_INLINE UP deepReportUtilize (Control& control) noexcept; + HFSM2_INLINE Rank deepReportRank (Control& control) noexcept; + HFSM2_INLINE Utility deepReportRandomize (Control& control) noexcept; #endif // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE void deepChangeToRequested(Control&) {} + HFSM2_INLINE void deepChangeToRequested(Control&) noexcept {} //---------------------------------------------------------------------- @@ -138,11 +140,11 @@ struct S_ final { using WriteStream = typename TArgs::WriteStream; using ReadStream = typename TArgs::ReadStream; - HFSM2_INLINE void deepSaveActive (const Registry&, WriteStream&) const {} - HFSM2_INLINE void deepSaveResumable(const Registry&, WriteStream&) const {} + HFSM2_INLINE void deepSaveActive (const Registry&, WriteStream&) const noexcept {} + HFSM2_INLINE void deepSaveResumable(const Registry&, WriteStream&) const noexcept {} - HFSM2_INLINE void deepLoadRequested( Registry&, ReadStream& ) const {} - HFSM2_INLINE void deepLoadResumable( Registry&, ReadStream& ) const {} + HFSM2_INLINE void deepLoadRequested( Registry&, ReadStream& ) const noexcept {} + HFSM2_INLINE void deepLoadResumable( Registry&, ReadStream& ) const noexcept {} #endif //---------------------------------------------------------------------- @@ -151,12 +153,12 @@ struct S_ final { using StructureStateInfos = typename TArgs::StructureStateInfos; using RegionType = typename StructureStateInfo::RegionType; - static const char* name(); + static const char* name() noexcept; void deepGetNames(const Long parent, const RegionType region, const Short depth, - StructureStateInfos& stateInfos) const; + StructureStateInfos& stateInfos) const noexcept; #endif //---------------------------------------------------------------------- @@ -181,7 +183,7 @@ struct S_ final { void log(TReturn(THost::*)(TParams...), Logger& logger, Context& context, - const Method method) const + const Method method) const noexcept { logger.recordMethod(context, STATE_ID, method); } @@ -192,7 +194,7 @@ struct S_ final { void log(TReturn(Empty::*)(TParams...), Logger&, Context&, - const Method) const + const Method) const noexcept {} #endif diff --git a/include/hfsm2/detail/structure/state.inl b/include/hfsm2/detail/structure/state.inl index 4d33efe..b0af93d 100644 --- a/include/hfsm2/detail/structure/state.inl +++ b/include/hfsm2/detail/structure/state.inl @@ -5,7 +5,7 @@ namespace detail { template struct RegisterT { - using StateParents = StaticArray; + using StateParents = StaticArrayT; using StateList = typename TA::StateList; static constexpr StateID STATE_ID = NS; @@ -13,7 +13,7 @@ struct RegisterT { static HFSM2_INLINE void execute(StateParents& stateParents, - const Parent parent) + const Parent parent) noexcept { static constexpr auto HEAD_ID = index(); StaticAssertEquality(); @@ -26,11 +26,11 @@ struct RegisterT { template struct RegisterT> { - using StateParents = StaticArray; + using StateParents = StaticArrayT; static HFSM2_INLINE void - execute(StateParents&, const Parent) {} + execute(StateParents&, const Parent) noexcept {} }; //////////////////////////////////////////////////////////////////////////////// @@ -38,7 +38,7 @@ struct RegisterT> { template void S_::deepRegister(Registry& registry, - const Parent parent) + const Parent parent) noexcept { using Register = RegisterT; Register::execute(registry.stateParents, parent); @@ -50,7 +50,7 @@ S_::deepRegister(Registry& registry, template typename S_::Rank -S_::wrapRank(Control& control) { +S_::wrapRank(Control& control) noexcept { HFSM2_LOG_STATE_METHOD(&Head::rank, Method::RANK); @@ -61,7 +61,7 @@ S_::wrapRank(Control& control) { template typename S_::Utility -S_::wrapUtility(Control& control) { +S_::wrapUtility(Control& control) noexcept { HFSM2_LOG_STATE_METHOD(&Head::utility, Method::UTILITY); @@ -71,10 +71,11 @@ S_::wrapUtility(Control& control) { #endif //------------------------------------------------------------------------------ +// COMMON template bool -S_::deepEntryGuard(GuardControl& control) { +S_::deepEntryGuard(GuardControl& control) noexcept { HFSM2_LOG_STATE_METHOD(&Head::entryGuard, Method::ENTRY_GUARD); @@ -91,11 +92,12 @@ S_::deepEntryGuard(GuardControl& control) { template void -S_::deepConstruct(PlanControl& HFSM2_IF_LOG_INTERFACE(control)) { -#ifdef HFSM2_ENABLE_PLANS - HFSM2_ASSERT(!control._planData.tasksSuccesses.template get()); - HFSM2_ASSERT(!control._planData.tasksFailures .template get()); -#endif +S_::deepConstruct(PlanControl& + #if defined HFSM2_ENABLE_PLANS || defined HFSM2_ENABLE_LOG_INTERFACE + control + #endif + ) noexcept { + HFSM2_IF_PLANS(control._planData.verifyEmptyStatus(STATE_ID)); HFSM2_LOG_STATE_METHOD(&Head::enter, Method::CONSTRUCT); @@ -107,7 +109,7 @@ S_::deepConstruct(PlanControl& HFSM2_IF_LOG_INTERFACE(control)) { template void -S_::deepEnter(PlanControl& control) { +S_::deepEnter(PlanControl& control) noexcept { HFSM2_LOG_STATE_METHOD(&Head::enter, Method::ENTER); @@ -121,11 +123,8 @@ S_::deepEnter(PlanControl& control) { template void -S_::deepReenter(PlanControl& control) { -#ifdef HFSM2_ENABLE_PLANS - HFSM2_ASSERT(!control._planData.tasksSuccesses.template get()); - HFSM2_ASSERT(!control._planData.tasksFailures .template get()); -#endif +S_::deepReenter(PlanControl& control) noexcept { + HFSM2_IF_PLANS(control._planData.verifyEmptyStatus(STATE_ID)); HFSM2_LOG_STATE_METHOD(&Head::reenter, Method::REENTER); @@ -143,7 +142,7 @@ S_::deepReenter(PlanControl& control) { template Status -S_::deepUpdate(FullControl& control) { +S_::deepUpdate(FullControl& control) noexcept { HFSM2_LOG_STATE_METHOD(&Head::update, Method::UPDATE); @@ -161,7 +160,7 @@ template template Status S_::deepReact(FullControl& control, - const TEvent& event) + const TEvent& event) noexcept { auto reaction = static_cast(&Head::react); @@ -180,7 +179,7 @@ S_::deepReact(FullControl& control, template bool -S_::deepExitGuard(GuardControl& control) { +S_::deepExitGuard(GuardControl& control) noexcept { HFSM2_LOG_STATE_METHOD(&Head::exitGuard, Method::EXIT_GUARD); @@ -198,7 +197,7 @@ S_::deepExitGuard(GuardControl& control) { template void -S_::deepExit(PlanControl& control) { +S_::deepExit(PlanControl& control) noexcept { HFSM2_LOG_STATE_METHOD(&Head::exit, Method::EXIT); @@ -221,17 +220,14 @@ S_::deepDestruct(PlanControl& #if defined HFSM2_ENABLE_LOG_INTERFACE || defined HFSM2_ENABLE_PLANS control #endif - ) + ) noexcept { HFSM2_LOG_STATE_METHOD(&Head::exit, Method::DESTRUCT); _headBox.destruct(); -#ifdef HFSM2_ENABLE_PLANS - control._planData.tasksSuccesses.template clear(); - control._planData.tasksFailures .template clear(); -#endif + HFSM2_IF_PLANS(control._planData.clearTaskStatus(STATE_ID)); } //------------------------------------------------------------------------------ @@ -240,7 +236,7 @@ S_::deepDestruct(PlanControl& template void -S_::wrapPlanSucceeded(FullControl& control) { +S_::wrapPlanSucceeded(FullControl& control) noexcept { HFSM2_LOG_STATE_METHOD(&Head::planSucceeded, Method::PLAN_SUCCEEDED); @@ -253,7 +249,7 @@ S_::wrapPlanSucceeded(FullControl& control) { template void -S_::wrapPlanFailed(FullControl& control) { +S_::wrapPlanFailed(FullControl& control) noexcept { HFSM2_LOG_STATE_METHOD(&Head::planFailed, Method::PLAN_FAILED); @@ -269,7 +265,7 @@ S_::wrapPlanFailed(FullControl& control) { template void S_::deepForwardRequest(Control& HFSM2_IF_TRANSITION_HISTORY(control), - const Request HFSM2_IF_TRANSITION_HISTORY(request)) + const Request HFSM2_IF_TRANSITION_HISTORY(request)) noexcept { HFSM2_IF_TRANSITION_HISTORY(control.pinLastTransition(STATE_ID, request.index)); } @@ -279,7 +275,7 @@ S_::deepForwardRequest(Control& HFSM2_IF_TRANSITION_HISTORY(control template void S_::deepRequestChange(Control& HFSM2_IF_TRANSITION_HISTORY(control), - const Request HFSM2_IF_TRANSITION_HISTORY(request)) + const Request HFSM2_IF_TRANSITION_HISTORY(request)) noexcept { HFSM2_IF_TRANSITION_HISTORY(control.pinLastTransition(STATE_ID, request.index)); } @@ -289,7 +285,7 @@ S_::deepRequestChange(Control& HFSM2_IF_TRANSITION_HISTORY(control) template void S_::deepRequestRestart(Control& HFSM2_IF_TRANSITION_HISTORY(control), - const Request HFSM2_IF_TRANSITION_HISTORY(request)) + const Request HFSM2_IF_TRANSITION_HISTORY(request)) noexcept { HFSM2_IF_TRANSITION_HISTORY(control.pinLastTransition(STATE_ID, request.index)); } @@ -299,7 +295,7 @@ S_::deepRequestRestart(Control& HFSM2_IF_TRANSITION_HISTORY(control template void S_::deepRequestResume(Control& HFSM2_IF_TRANSITION_HISTORY(control), - const Request HFSM2_IF_TRANSITION_HISTORY(request)) + const Request HFSM2_IF_TRANSITION_HISTORY(request)) noexcept { HFSM2_IF_TRANSITION_HISTORY(control.pinLastTransition(STATE_ID, request.index)); } @@ -311,7 +307,7 @@ S_::deepRequestResume(Control& HFSM2_IF_TRANSITION_HISTORY(control) template void S_::deepRequestUtilize(Control& HFSM2_IF_TRANSITION_HISTORY(control), - const Request HFSM2_IF_TRANSITION_HISTORY(request)) + const Request HFSM2_IF_TRANSITION_HISTORY(request)) noexcept { HFSM2_IF_TRANSITION_HISTORY(control.pinLastTransition(STATE_ID, request.index)); } @@ -321,7 +317,7 @@ S_::deepRequestUtilize(Control& HFSM2_IF_TRANSITION_HISTORY(control template void S_::deepRequestRandomize(Control& HFSM2_IF_TRANSITION_HISTORY(control), - const Request HFSM2_IF_TRANSITION_HISTORY(request)) + const Request HFSM2_IF_TRANSITION_HISTORY(request)) noexcept { HFSM2_IF_TRANSITION_HISTORY(control.pinLastTransition(STATE_ID, request.index)); } @@ -330,7 +326,7 @@ S_::deepRequestRandomize(Control& HFSM2_IF_TRANSITION_HISTORY(contr template typename S_::UP -S_::deepReportChange(Control& control) { +S_::deepReportChange(Control& control) noexcept { const Utility utility = wrapUtility(control); const Parent parent = stateParent(control); @@ -342,7 +338,7 @@ S_::deepReportChange(Control& control) { template typename S_::UP -S_::deepReportUtilize(Control& control) { +S_::deepReportUtilize(Control& control) noexcept { const Utility utility = wrapUtility(control); const Parent parent = stateParent(control); @@ -353,7 +349,7 @@ S_::deepReportUtilize(Control& control) { template typename S_::Rank -S_::deepReportRank(Control& control) { +S_::deepReportRank(Control& control) noexcept { return wrapRank(control); } @@ -361,7 +357,7 @@ S_::deepReportRank(Control& control) { template typename S_::Utility -S_::deepReportRandomize(Control& control) { +S_::deepReportRandomize(Control& control) noexcept { return wrapUtility(control); } @@ -373,7 +369,7 @@ S_::deepReportRandomize(Control& control) { template const char* -S_::name() { +S_::name() noexcept { if (HeadBox::isBare()) return ""; else { @@ -412,7 +408,7 @@ void S_::deepGetNames(const Long parent, const RegionType region, const Short depth, - StructureStateInfos& _stateInfos) const + StructureStateInfos& _stateInfos) const noexcept { _stateInfos.append(StructureStateInfo{parent, region, depth, name()}); } diff --git a/include/hfsm2/detail/structure/state_box.hpp b/include/hfsm2/detail/structure/state_box.hpp index 52c2c7c..a490bed 100644 --- a/include/hfsm2/detail/structure/state_box.hpp +++ b/include/hfsm2/detail/structure/state_box.hpp @@ -5,7 +5,7 @@ namespace hfsm2 { template struct Guard { template - static void execute(hfsm2::detail::GuardControlT&) {} + static HFSM2_INLINE void execute(hfsm2::detail::GuardControlT&) noexcept {} }; namespace detail { @@ -20,22 +20,22 @@ template struct DynamicBox final { using Type = T; - static constexpr bool isBare() { return false; } + static constexpr bool isBare() noexcept { return false; } union { Type t_; }; - HFSM2_INLINE DynamicBox() {} - HFSM2_INLINE ~DynamicBox() {} + HFSM2_INLINE DynamicBox() noexcept {} + HFSM2_INLINE ~DynamicBox() noexcept {} - HFSM2_INLINE void guard(GuardControlT& control) { Guard::execute(control); } + HFSM2_INLINE void guard(GuardControlT& control) noexcept { Guard::execute(control); } - HFSM2_INLINE void construct(); - HFSM2_INLINE void destruct(); + HFSM2_INLINE void construct() noexcept; + HFSM2_INLINE void destruct() noexcept; - HFSM2_INLINE Type& get() { HFSM2_ASSERT(initialized_); return t_; } - HFSM2_INLINE const Type& get() const { HFSM2_ASSERT(initialized_); return t_; } + HFSM2_INLINE Type& get() noexcept { HFSM2_ASSERT(initialized_); return t_; } + HFSM2_INLINE const Type& get() const noexcept { HFSM2_ASSERT(initialized_); return t_; } HFSM2_IF_ASSERT(bool initialized_ = false); @@ -48,17 +48,17 @@ template struct StaticBox final { using Type = T; - static constexpr bool isBare() { return std::is_base_of>::value; } + static constexpr bool isBare() noexcept { return std::is_base_of>::value; } Type t_; - HFSM2_INLINE void guard(GuardControlT& control); + HFSM2_INLINE void guard(GuardControlT& control) noexcept; - HFSM2_INLINE void construct() {} - HFSM2_INLINE void destruct() {} + HFSM2_INLINE void construct() noexcept {} + HFSM2_INLINE void destruct() noexcept {} - HFSM2_INLINE Type& get() { return t_; } - HFSM2_INLINE const Type& get() const { return t_; } + HFSM2_INLINE Type& get() noexcept { return t_; } + HFSM2_INLINE const Type& get() const noexcept { return t_; } HFSM2_IF_DEBUG(const std::type_index TYPE = isBare() ? typeid(None) : typeid(Type)); }; @@ -67,11 +67,11 @@ struct StaticBox final { template struct BoxifyT final { - using Type = typename std::conditional< + using Type = Conditional< std::is_base_of::value, DynamicBox, StaticBox - >::type; + >; }; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/include/hfsm2/detail/structure/state_box.inl b/include/hfsm2/detail/structure/state_box.inl index 18a93fe..0c4d8f1 100644 --- a/include/hfsm2/detail/structure/state_box.inl +++ b/include/hfsm2/detail/structure/state_box.inl @@ -5,7 +5,7 @@ namespace detail { template void -DynamicBox::construct() { +DynamicBox::construct() noexcept { HFSM2_ASSERT(!initialized_); new(&t_) T{}; @@ -17,7 +17,7 @@ DynamicBox::construct() { template void -DynamicBox::destruct() { +DynamicBox::destruct() noexcept { HFSM2_ASSERT(initialized_); t_.~T(); @@ -29,7 +29,7 @@ DynamicBox::destruct() { template void -StaticBox::guard(GuardControlT& control) { +StaticBox::guard(GuardControlT& control) noexcept { t_.widePreEntryGuard(control.context()); t_. entryGuard(control); } diff --git a/include/hfsm2/machine.hpp b/include/hfsm2/machine.hpp index da6f0c9..ee98ddb 100644 --- a/include/hfsm2/machine.hpp +++ b/include/hfsm2/machine.hpp @@ -1,4 +1,6 @@ // HFSM2 (hierarchical state machine for games and interactive applications) +// 1.8.0 (2021-01-15) +// // Created by Andrew Gresyk // // Licensed under the MIT License; @@ -7,7 +9,7 @@ // // MIT License // -// Copyright (c) 2020 +// Copyright (c) 2021 // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -29,12 +31,16 @@ #pragma once +#define HFSM2_VERSION_MAJOR 1 +#define HFSM2_VERSION_MINOR 8 +#define HFSM2_VERSION_PATCH 0 + #include // uint32_t, uint64_t #include // memcpy_s() #include #include -#include // std::conditional<>, move(), forward() +#include // move(), forward() #if defined _DEBUG && _MSC_VER #include // __debugbreak() @@ -106,61 +112,71 @@ //------------------------------------------------------------------------------ +#ifndef HFSM2_DISABLE_TYPEINDEX + #define HFSM2_IF_TYPEINDEX(...) __VA_ARGS__ + #define HFSM2_TYPEINDEX_MASK (1 << 0) +#else + #define HFSM2_IF_TYPEINDEX(...) + #define HFSM2_TYPEINDEX_MASK (0 << 0) +#endif + +//------------------------------------------------------------------------------ + #ifdef HFSM2_ENABLE_UTILITY_THEORY #define HFSM2_IF_UTILITY_THEORY(...) __VA_ARGS__ - #define HFSM2_UTILITY_THEORY_MASK (1 << 0) + #define HFSM2_UTILITY_THEORY_MASK (1 << 1) #else #define HFSM2_IF_UTILITY_THEORY(...) - #define HFSM2_UTILITY_THEORY_MASK (0 << 0) + #define HFSM2_UTILITY_THEORY_MASK (0 << 1) #endif //------------------------------------------------------------------------------ #ifdef HFSM2_ENABLE_PLANS #define HFSM2_IF_PLANS(...) __VA_ARGS__ - #define HFSM2_PLANS_MASK (1 << 1) + #define HFSM2_PLANS_MASK (1 << 2) #else #define HFSM2_IF_PLANS(...) - #define HFSM2_PLANS_MASK (0 << 1) + #define HFSM2_PLANS_MASK (0 << 2) #endif //------------------------------------------------------------------------------ #ifdef HFSM2_ENABLE_SERIALIZATION #define HFSM2_IF_SERIALIZATION(...) __VA_ARGS__ - #define HFSM2_SERIALIZATION_MASK (1 << 2) + #define HFSM2_SERIALIZATION_MASK (1 << 3) #else #define HFSM2_IF_SERIALIZATION(...) - #define HFSM2_SERIALIZATION_MASK (0 << 2) + #define HFSM2_SERIALIZATION_MASK (0 << 3) #endif //------------------------------------------------------------------------------ #ifdef HFSM2_ENABLE_TRANSITION_HISTORY #define HFSM2_IF_TRANSITION_HISTORY(...) __VA_ARGS__ - #define HFSM2_TRANSITION_HISTORY_MASK (1 << 3) + #define HFSM2_TRANSITION_HISTORY_MASK (1 << 4) #else #define HFSM2_IF_TRANSITION_HISTORY(...) - #define HFSM2_TRANSITION_HISTORY_MASK (0 << 3) + #define HFSM2_TRANSITION_HISTORY_MASK (0 << 4) #endif //------------------------------------------------------------------------------ #ifdef HFSM2_ENABLE_STRUCTURE_REPORT #define HFSM2_IF_STRUCTURE_REPORT(...) __VA_ARGS__ - #define HFSM2_STRUCTURE_REPORT_MASK (1 << 4) + #define HFSM2_STRUCTURE_REPORT_MASK (1 << 5) #else #define HFSM2_IF_STRUCTURE_REPORT(...) - #define HFSM2_STRUCTURE_REPORT_MASK (0 << 4) + #define HFSM2_STRUCTURE_REPORT_MASK (0 << 5) #endif //////////////////////////////////////////////////////////////////////////////// #ifdef HFSM2_ENABLE_VERBOSE_DEBUG_LOG #define HFSM2_ENABLE_LOG_INTERFACE - #define HFSM2_VERBOSE_DEBUG_LOG_MASK (1 << 5) + #define HFSM2_VERBOSE_DEBUG_LOG_MASK (1 << 6) #else - #define HFSM2_VERBOSE_DEBUG_LOG_MASK (0 << 5) + #define HFSM2_VERBOSE_DEBUG_LOG_MASK (0 << 6) #endif // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -168,7 +184,7 @@ #ifdef HFSM2_ENABLE_LOG_INTERFACE #define HFSM2_IF_LOG_INTERFACE(...) __VA_ARGS__ - #define HFSM2_LOG_INTERFACE_MASK (1 << 6) + #define HFSM2_LOG_INTERFACE_MASK (1 << 7) #define HFSM2_LOG_TRANSITION(CONTEXT, ORIGIN, TYPE, DESTINATION) \ if (_logger) \ @@ -205,7 +221,7 @@ #else #define HFSM2_IF_LOG_INTERFACE(...) - #define HFSM2_LOG_INTERFACE_MASK (0 << 6) + #define HFSM2_LOG_INTERFACE_MASK (0 << 7) #define HFSM2_LOG_TRANSITION(CONTEXT, ORIGIN, TYPE, DESTINATION) @@ -249,18 +265,20 @@ namespace hfsm2 { using FeatureTag = uint8_t; -constexpr FeatureTag HFSM2_FEATURE_TAG = HFSM2_UTILITY_THEORY_MASK | - HFSM2_PLANS_MASK | - HFSM2_SERIALIZATION_MASK | - HFSM2_TRANSITION_HISTORY_MASK | - HFSM2_STRUCTURE_REPORT_MASK | - HFSM2_VERBOSE_DEBUG_LOG_MASK | - HFSM2_LOG_INTERFACE_MASK; +constexpr FeatureTag HFSM2_FEATURE_TAG = HFSM2_TYPEINDEX_MASK + | HFSM2_PLANS_MASK + | HFSM2_UTILITY_THEORY_MASK + | HFSM2_SERIALIZATION_MASK + | HFSM2_TRANSITION_HISTORY_MASK + | HFSM2_STRUCTURE_REPORT_MASK + | HFSM2_VERBOSE_DEBUG_LOG_MASK + | HFSM2_LOG_INTERFACE_MASK; } //------------------------------------------------------------------------------ +#undef HFSM2_TYPEINDEX_MASK #undef HFSM2_UTILITY_THEORY_MASK #undef HFSM2_PLANS_MASK #undef HFSM2_SERIALIZATION_MASK @@ -315,19 +333,34 @@ namespace detail { //////////////////////////////////////////////////////////////////////////////// +template +struct ConditionalT { + using Type = TT; +}; + +template +struct ConditionalT { + using Type = TF; +}; + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +template +using Conditional = typename ConditionalT::Type; + +//////////////////////////////////////////////////////////////////////////////// + template -HFSM2_INLINE -void -fill(T& a, const char value) { +HFSM2_INLINE void +fill(T& a, const char value) noexcept { memset(&a, (int) value, sizeof(a)); } //------------------------------------------------------------------------------ template -constexpr -unsigned -count(const T(&)[NCount]) { +constexpr unsigned +count(const T(&)[NCount]) noexcept { return NCount; } @@ -348,9 +381,11 @@ struct Max { //------------------------------------------------------------------------------ template -constexpr -T -min(const T t1, const T t2) { return t1 < t2 ? t1 : t2; } +constexpr T +min(const T t1, const T t2) noexcept { + return t1 < t2 ? + t1 : t2; +} //------------------------------------------------------------------------------ @@ -359,10 +394,10 @@ template struct UnsignedCapacityT { static constexpr Long CAPACITY = NCapacity; - using Type = typename std::conditional::type>::type>::type; + using Type = Conditional>>; static_assert(CAPACITY <= UINT64_MAX, "STATIC ASSERT"); }; @@ -376,32 +411,31 @@ template struct UnsignedBitWidthT { static constexpr Short BIT_WIDTH = NBitWidth; - using Type = typename std::conditional::type>::type>::type; + using Type = Conditional>>; static_assert(BIT_WIDTH <= 64, "STATIC ASSERT"); }; +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + template using UnsignedBitWidth = typename UnsignedBitWidthT::Type; //------------------------------------------------------------------------------ -constexpr -Long -roundUp(const Long x, - const Long to) -{ - return (x + (to - 1)) / to; +template +constexpr T1 +contain(const T1 x, const T2 to) noexcept { + return (x + (T1) to - 1) / ((T1) to); } //------------------------------------------------------------------------------ -constexpr -Short -bitWidth(const Short x) { +constexpr Short +bitWidth(const Short x) noexcept { return x <= 2 ? 1 : x <= 4 ? 2 : x <= 8 ? 3 : @@ -415,8 +449,8 @@ bitWidth(const Short x) { //------------------------------------------------------------------------------ template -void -overwrite(TTo& to, const TFrom& from) { +HFSM2_INLINE void +overwrite(TTo& to, const TFrom& from) noexcept { static_assert(sizeof(TTo) == sizeof(TFrom), "STATIC ASSERT"); #if defined(__GNUC__) || defined(__GNUG__) @@ -429,7 +463,8 @@ overwrite(TTo& to, const TFrom& from) { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - template -TO convert(const TI& in) { +HFSM2_INLINE TO +convert(const TI& in) noexcept { TO out; overwrite(out, in); @@ -463,31 +498,31 @@ namespace detail { //////////////////////////////////////////////////////////////////////////////// template -class Iterator { +class IteratorT { public: using Container = TContainer; using Item = typename Container::Item; template - friend class Array; + friend class ArrayT; private: - HFSM2_INLINE Iterator(Container& container, - const Long cursor) + HFSM2_INLINE IteratorT(Container& container, + const Long cursor) noexcept : _container{container} , _cursor{cursor} {} public: - HFSM2_INLINE bool operator != (const Iterator& dummy) const; + HFSM2_INLINE bool operator != (const IteratorT& other) const noexcept; - HFSM2_INLINE Iterator& operator ++(); + HFSM2_INLINE IteratorT& operator ++() noexcept; - HFSM2_INLINE Item& operator *() { return _container[_cursor]; } - HFSM2_INLINE const Item& operator *() const { return _container[_cursor]; } + HFSM2_INLINE Item& operator *() noexcept { return _container[_cursor]; } + HFSM2_INLINE const Item& operator *() const noexcept { return _container[_cursor]; } - HFSM2_INLINE Item* operator->() { return &_container[_cursor]; } - HFSM2_INLINE const Item* operator->() const { return &_container[_cursor]; } + HFSM2_INLINE Item* operator->() noexcept { return &_container[_cursor]; } + HFSM2_INLINE const Item* operator->() const noexcept { return &_container[_cursor]; } private: Container& _container; @@ -498,29 +533,29 @@ class Iterator { //------------------------------------------------------------------------------ template -class Iterator { +class IteratorT { public: using Container = TContainer; using Item = typename Container::Item; template - friend class Array; + friend class ArrayT; private: - HFSM2_INLINE Iterator(const Container& container, - const Long cursor) + HFSM2_INLINE IteratorT(const Container& container, + const Long cursor) noexcept : _container{container} , _cursor{cursor} {} public: - HFSM2_INLINE bool operator != (const Iterator& dummy) const; + HFSM2_INLINE bool operator != (const IteratorT& other) const noexcept; - HFSM2_INLINE Iterator& operator ++(); + HFSM2_INLINE IteratorT& operator ++() noexcept; - HFSM2_INLINE const Item& operator *() const { return _container[_cursor]; } + HFSM2_INLINE const Item& operator *() const noexcept { return _container[_cursor]; } - HFSM2_INLINE const Item* operator->() const { return &operator *(); } + HFSM2_INLINE const Item* operator->() const noexcept { return &operator *(); } private: const Container& _container; @@ -540,8 +575,8 @@ namespace detail { template bool -Iterator::operator != (const Iterator& HFSM2_IF_ASSERT(dummy)) const { - HFSM2_ASSERT(&_container == &dummy._container); +IteratorT::operator != (const IteratorT& HFSM2_IF_ASSERT(other)) const noexcept { + HFSM2_ASSERT(&_container == &other._container); return _cursor != _container.limit(); } @@ -549,8 +584,8 @@ Iterator::operator != (const Iterator& HFSM2_IF_ASSERT(dummy)) const { //------------------------------------------------------------------------------ template -Iterator& -Iterator::operator ++() { +IteratorT& +IteratorT::operator ++() noexcept { _cursor = _container.next(_cursor); return *this; @@ -560,8 +595,8 @@ Iterator::operator ++() { template bool -Iterator::operator != (const Iterator& HFSM2_IF_ASSERT(dummy)) const { - HFSM2_ASSERT(&_container == &dummy._container); +IteratorT::operator != (const IteratorT& HFSM2_IF_ASSERT(other)) const noexcept { + HFSM2_ASSERT(&_container == &other._container); return _cursor != _container.limit(); } @@ -569,8 +604,8 @@ Iterator::operator != (const Iterator& HFSM2_IF_ASSERT(dummy)) //------------------------------------------------------------------------------ template -Iterator& -Iterator::operator ++() { +IteratorT& +IteratorT::operator ++() noexcept { _cursor = _container.next(_cursor); return *this; @@ -586,7 +621,7 @@ namespace detail { //////////////////////////////////////////////////////////////////////////////// template -class StaticArray { +class StaticArrayT { public: static constexpr Long CAPACITY = NCapacity; static constexpr Long DUMMY = INVALID_LONG; @@ -595,27 +630,27 @@ class StaticArray { using Index = UnsignedCapacity; public: - HFSM2_INLINE StaticArray() = default; - HFSM2_INLINE StaticArray(const Item filler); + HFSM2_INLINE StaticArrayT() = default; + HFSM2_INLINE StaticArrayT(const Item filler) noexcept; template - HFSM2_INLINE Item& operator[] (const N i); + HFSM2_INLINE Item& operator[] (const N i) noexcept; template - HFSM2_INLINE const Item& operator[] (const N i) const; + HFSM2_INLINE const Item& operator[] (const N i) const noexcept; - HFSM2_INLINE Long count() const { return CAPACITY; } + HFSM2_INLINE Long count() const noexcept { return CAPACITY; } - HFSM2_INLINE void fill(const Item filler); - HFSM2_INLINE void clear() { fill(INVALID_SHORT); } + HFSM2_INLINE void fill(const Item filler) noexcept; + HFSM2_INLINE void clear() noexcept { fill(INVALID_SHORT); } - HFSM2_INLINE Iterator< StaticArray> begin() { return Iterator< StaticArray>(*this, 0); } - HFSM2_INLINE Iterator begin() const { return Iterator(*this, 0); } - HFSM2_INLINE Iterator cbegin() const { return Iterator(*this, 0); } + HFSM2_INLINE IteratorT< StaticArrayT> begin() noexcept { return IteratorT< StaticArrayT>(*this, 0); } + HFSM2_INLINE IteratorT begin() const noexcept { return IteratorT(*this, 0); } + HFSM2_INLINE IteratorT cbegin() const noexcept { return IteratorT(*this, 0); } - HFSM2_INLINE Iterator< StaticArray> end() { return Iterator< StaticArray>(*this, DUMMY); } - HFSM2_INLINE Iterator end() const { return Iterator(*this, DUMMY); } - HFSM2_INLINE Iterator cend() const { return Iterator(*this, DUMMY); } + HFSM2_INLINE IteratorT< StaticArrayT> end() noexcept { return IteratorT< StaticArrayT>(*this, DUMMY); } + HFSM2_INLINE IteratorT end() const noexcept { return IteratorT(*this, DUMMY); } + HFSM2_INLINE IteratorT cend() const noexcept { return IteratorT(*this, DUMMY); } private: Item _items[CAPACITY]; @@ -624,19 +659,19 @@ class StaticArray { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - template -struct StaticArray { +struct StaticArrayT { using Item = T; - HFSM2_INLINE StaticArray() = default; - HFSM2_INLINE StaticArray(const Item) {} + HFSM2_INLINE StaticArrayT() = default; + HFSM2_INLINE StaticArrayT(const Item) noexcept {} }; //------------------------------------------------------------------------------ template -class Array { +class ArrayT { template - friend class Iterator; + friend class IteratorT; public: static constexpr Long CAPACITY = NCapacity; @@ -646,37 +681,37 @@ class Array { using Index = UnsignedCapacity; public: - HFSM2_INLINE void clear() { _count = 0; } + HFSM2_INLINE void clear() noexcept { _count = 0; } // TODO: replace with 'emplace<>()'? template - HFSM2_INLINE Long append(const TValue& value); + HFSM2_INLINE Long append(const TValue& value) noexcept; template - HFSM2_INLINE Long append(TValue&& value); + HFSM2_INLINE Long append( TValue&& value) noexcept; template - HFSM2_INLINE Item& operator[] (const N i); + HFSM2_INLINE Item& operator[] (const N i) noexcept; template - HFSM2_INLINE const Item& operator[] (const N i) const; + HFSM2_INLINE const Item& operator[] (const N i) const noexcept; - HFSM2_INLINE Long count() const { return _count; } + HFSM2_INLINE Long count() const noexcept { return _count; } template - Array& operator += (const Array& other); + HFSM2_INLINE ArrayT& operator += (const ArrayT& other) noexcept; - HFSM2_INLINE Iterator< Array> begin() { return Iterator< Array>(*this, 0); } - HFSM2_INLINE Iterator begin() const { return Iterator(*this, 0); } - HFSM2_INLINE Iterator cbegin() const { return Iterator(*this, 0); } + HFSM2_INLINE IteratorT< ArrayT> begin() noexcept { return IteratorT< ArrayT>(*this, 0); } + HFSM2_INLINE IteratorT begin() const noexcept { return IteratorT(*this, 0); } + HFSM2_INLINE IteratorT cbegin() const noexcept { return IteratorT(*this, 0); } - HFSM2_INLINE Iterator< Array> end() { return Iterator< Array>(*this, DUMMY); } - HFSM2_INLINE Iterator end() const { return Iterator(*this, DUMMY); } - HFSM2_INLINE Iterator cend() const { return Iterator(*this, DUMMY); } + HFSM2_INLINE IteratorT< ArrayT> end() noexcept { return IteratorT< ArrayT>(*this, DUMMY); } + HFSM2_INLINE IteratorT end() const noexcept { return IteratorT(*this, DUMMY); } + HFSM2_INLINE IteratorT cend() const noexcept { return IteratorT(*this, DUMMY); } private: - HFSM2_INLINE Long next(const Long i) const { return i + 1; } - HFSM2_INLINE Long limit() const { return _count; } + HFSM2_INLINE Long next(const Long i) const noexcept { return i + 1; } + HFSM2_INLINE Long limit() const noexcept { return _count; } private: Long _count = 0; @@ -696,7 +731,7 @@ class Array { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - template -class Array { +class ArrayT { public: static constexpr Long CAPACITY = 0; static constexpr Long DUMMY = INVALID_LONG; @@ -716,7 +751,7 @@ namespace detail { //////////////////////////////////////////////////////////////////////////////// template -StaticArray::StaticArray(const Item filler) { +StaticArrayT::StaticArrayT(const Item filler) noexcept { fill(filler); } @@ -725,7 +760,7 @@ StaticArray::StaticArray(const Item filler) { template template T& -StaticArray::operator[] (const N i) { +StaticArrayT::operator[] (const N i) noexcept { HFSM2_ASSERT(0 <= i && i < CAPACITY); return _items[(Index) i]; @@ -736,7 +771,7 @@ StaticArray::operator[] (const N i) { template template const T& -StaticArray::operator[] (const N i) const { +StaticArrayT::operator[] (const N i) const noexcept { HFSM2_ASSERT(0 <= i && i < CAPACITY); return _items[(Index) i]; @@ -746,7 +781,7 @@ StaticArray::operator[] (const N i) const { template void -StaticArray::fill(const Item filler) { +StaticArrayT::fill(const Item filler) noexcept { for (Long i = 0; i < CAPACITY; ++i) _items[i] = filler; } @@ -756,7 +791,7 @@ StaticArray::fill(const Item filler) { template template Long -Array::append(const TValue& value) { +ArrayT::append(const TValue& value) noexcept { HFSM2_ASSERT(_count < CAPACITY); new (&_items[_count]) Item{value}; @@ -769,7 +804,7 @@ Array::append(const TValue& value) { template template Long -Array::append(TValue&& value) { +ArrayT::append(TValue&& value) noexcept { HFSM2_ASSERT(_count < CAPACITY); new (&_items[_count]) Item{std::move(value)}; @@ -782,7 +817,7 @@ Array::append(TValue&& value) { template template T& -Array::operator[] (const N i) { +ArrayT::operator[] (const N i) noexcept { HFSM2_ASSERT(0 <= i && i < CAPACITY); return _items[(Index) i]; @@ -793,7 +828,7 @@ Array::operator[] (const N i) { template template const T& -Array::operator[] (const N i) const { +ArrayT::operator[] (const N i) const noexcept { HFSM2_ASSERT(0 <= i && i < CAPACITY); return _items[(Index) i]; @@ -803,8 +838,8 @@ Array::operator[] (const N i) const { template template -Array& -Array::operator += (const Array& other) { +ArrayT& +ArrayT::operator += (const ArrayT& other) noexcept { for (const auto& item : other) append(item); @@ -822,7 +857,7 @@ namespace detail { struct Units { inline Units(Short unit_ = INVALID_SHORT, - Short width_ = INVALID_SHORT) + Short width_ = INVALID_SHORT) noexcept : unit {unit_ } , width{width_} {} @@ -833,44 +868,46 @@ struct Units { //------------------------------------------------------------------------------ -template -class BitArray final { +template +class BitArrayT final { public: using Index = TIndex; using Unit = unsigned char; - static constexpr Index CAPACITY = NCapacity; + static constexpr Index UNIT_COUNT = NUnitCount; + static constexpr Index UNIT_WIDTH = sizeof(Unit) * 8; + static constexpr Index BIT_COUNT = UNIT_COUNT * UNIT_WIDTH; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - class Bits { template - friend class BitArray; + friend class BitArrayT; private: HFSM2_INLINE explicit Bits(Unit* const storage, - const Index width) + const Index width) noexcept : _storage{storage} , _width{width} {} public: - HFSM2_INLINE explicit operator bool() const; + HFSM2_INLINE explicit operator bool() const noexcept; - HFSM2_INLINE void clear(); + HFSM2_INLINE void clear() noexcept; template - HFSM2_INLINE bool get() const; + HFSM2_INLINE bool get() const noexcept; template - HFSM2_INLINE void set(); + HFSM2_INLINE void set() noexcept; template - HFSM2_INLINE void clear(); + HFSM2_INLINE void clear() noexcept; - HFSM2_INLINE bool get (const Index index) const; - HFSM2_INLINE void set (const Index index); - HFSM2_INLINE void clear(const Index index); + HFSM2_INLINE bool get (const Index index) const noexcept; + HFSM2_INLINE void set (const Index index) noexcept; + HFSM2_INLINE void clear(const Index index) noexcept; private: Unit* const _storage; @@ -879,24 +916,24 @@ class BitArray final { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - class ConstBits { + class CBits { template - friend class BitArray; + friend class BitArrayT; private: - HFSM2_INLINE explicit ConstBits(const Unit* const storage, - const Index width) + HFSM2_INLINE explicit CBits(const Unit* const storage, + const Index width) noexcept : _storage{storage} , _width{width} {} public: - HFSM2_INLINE explicit operator bool() const; + HFSM2_INLINE explicit operator bool() const noexcept; template - HFSM2_INLINE bool get() const; + HFSM2_INLINE bool get() const noexcept; - HFSM2_INLINE bool get(const Index index) const; + HFSM2_INLINE bool get(const Index index) const noexcept; private: const Unit* const _storage; @@ -906,45 +943,44 @@ class BitArray final { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - public: - BitArray() { + BitArrayT() noexcept { clear(); } - HFSM2_INLINE void clear(); + HFSM2_INLINE void clear() noexcept; template - HFSM2_INLINE bool get() const; + HFSM2_INLINE bool get() const noexcept; template - HFSM2_INLINE void set(); + HFSM2_INLINE void set() noexcept; template - HFSM2_INLINE void clear(); + HFSM2_INLINE void clear() noexcept; - HFSM2_INLINE bool get (const Index index) const; - HFSM2_INLINE void set (const Index index); - HFSM2_INLINE void clear(const Index index); + HFSM2_INLINE bool get (const Index index) const noexcept; + HFSM2_INLINE void set (const Index index) noexcept; + HFSM2_INLINE void clear(const Index index) noexcept; template - HFSM2_INLINE Bits bits(); + HFSM2_INLINE Bits bits() noexcept; template - HFSM2_INLINE ConstBits bits() const; + HFSM2_INLINE CBits bits() const noexcept; - - HFSM2_INLINE Bits bits(const Units& units); - HFSM2_INLINE ConstBits bits(const Units& units) const; + HFSM2_INLINE Bits bits(const Units& units) noexcept; + HFSM2_INLINE CBits bits(const Units& units) const noexcept; private: - Unit _storage[CAPACITY]; + Unit _storage[UNIT_COUNT]; }; //------------------------------------------------------------------------------ template -class BitArray final { +class BitArrayT final { public: - HFSM2_INLINE void clear() {} + HFSM2_INLINE void clear() noexcept {} }; //////////////////////////////////////////////////////////////////////////////// @@ -958,15 +994,15 @@ namespace detail { //////////////////////////////////////////////////////////////////////////////// template -BitArray::Bits::operator bool() const { - const Short fullUnits = _width / (sizeof(Unit) * 8); +BitArrayT::Bits::operator bool() const noexcept { + const Short fullUnits = _width / UNIT_WIDTH; // TODO: cover this case for (Index i = 0; i < fullUnits; ++i) if (_storage[i]) return true; - const Short bit = _width % (sizeof(Unit) * 8); + const Short bit = _width % UNIT_WIDTH; const Unit mask = (1 << bit) - 1; const Unit& u = _storage[fullUnits]; @@ -977,10 +1013,10 @@ BitArray::Bits::operator bool() const { template void -BitArray::Bits::clear() { - const Index count = (_width + 7) / (sizeof(Unit) * 8); +BitArrayT::Bits::clear() noexcept { + const Index unitCount = contain(_width, UNIT_WIDTH); - for (Index i = 0; i < count; ++i) + for (Index i = 0; i < unitCount; ++i) _storage[i] = Unit{0}; } @@ -989,12 +1025,12 @@ BitArray::Bits::clear() { template template bool -BitArray::Bits::get() const { +BitArrayT::Bits::get() const noexcept { constexpr Index INDEX = NIndex; HFSM2_ASSERT(INDEX < _width); - constexpr Index BIT_UNIT = INDEX / (sizeof(Unit) * 8); - constexpr Index BIT_INDEX = INDEX % (sizeof(Unit) * 8); + constexpr Index BIT_UNIT = INDEX / UNIT_WIDTH; + constexpr Index BIT_INDEX = INDEX % UNIT_WIDTH; constexpr Unit MASK = 1 << BIT_INDEX; return (_storage[BIT_UNIT] & MASK) != 0; @@ -1005,12 +1041,12 @@ BitArray::Bits::get() const { template template void -BitArray::Bits::set() { +BitArrayT::Bits::set() noexcept { constexpr Index INDEX = NIndex; HFSM2_ASSERT(INDEX < _width); - constexpr Index BIT_UNIT = INDEX / (sizeof(Unit) * 8); - constexpr Index BIT_INDEX = INDEX % (sizeof(Unit) * 8); + constexpr Index BIT_UNIT = INDEX / UNIT_WIDTH; + constexpr Index BIT_INDEX = INDEX % UNIT_WIDTH; constexpr Unit MASK = 1 << BIT_INDEX; _storage[BIT_UNIT] |= MASK; @@ -1021,12 +1057,12 @@ BitArray::Bits::set() { template template void -BitArray::Bits::clear() { +BitArrayT::Bits::clear() noexcept { constexpr Index INDEX = NIndex; HFSM2_ASSERT(INDEX < _width); - constexpr Index BIT_UNIT = INDEX / (sizeof(Unit) * 8); - constexpr Index BIT_INDEX = INDEX % (sizeof(Unit) * 8); + constexpr Index BIT_UNIT = INDEX / UNIT_WIDTH; + constexpr Index BIT_INDEX = INDEX % UNIT_WIDTH; constexpr Unit MASK = 1 << BIT_INDEX; _storage[BIT_UNIT] &= ~MASK; @@ -1036,11 +1072,11 @@ BitArray::Bits::clear() { template bool -BitArray::Bits::get(const Index index) const { +BitArrayT::Bits::get(const Index index) const noexcept { HFSM2_ASSERT(index < _width); - const Index unit = index / (sizeof(Unit) * 8); - const Index bit = index % (sizeof(Unit) * 8); + const Index unit = index / UNIT_WIDTH; + const Index bit = index % UNIT_WIDTH; const Unit mask = 1 << bit; return (_storage[unit] & mask) != 0; @@ -1050,11 +1086,11 @@ BitArray::Bits::get(const Index index) const { template void -BitArray::Bits::set(const Index index) { +BitArrayT::Bits::set(const Index index) noexcept { HFSM2_ASSERT(index < _width); - const Index unit = index / (sizeof(Unit) * 8); - const Index bit = index % (sizeof(Unit) * 8); + const Index unit = index / UNIT_WIDTH; + const Index bit = index % UNIT_WIDTH; const Unit mask = 1 << bit; _storage[unit] |= mask; @@ -1064,11 +1100,11 @@ BitArray::Bits::set(const Index index) { template void -BitArray::Bits::clear(const Index index) { +BitArrayT::Bits::clear(const Index index) noexcept { HFSM2_ASSERT(index < _width); - const Index unit = index / (sizeof(Unit) * 8); - const Index bit = index % (sizeof(Unit) * 8); + const Index unit = index / UNIT_WIDTH; + const Index bit = index % UNIT_WIDTH; const Unit mask = 1 << bit; _storage[unit] &= ~mask; @@ -1077,14 +1113,14 @@ BitArray::Bits::clear(const Index index) { //////////////////////////////////////////////////////////////////////////////// template -BitArray::ConstBits::operator bool() const { - const Short fullUnits = _width / (sizeof(Unit) * 8); +BitArrayT::CBits::operator bool() const noexcept { + const Short fullUnits = _width / UNIT_WIDTH; for (Index i = 0; i < fullUnits; ++i) if (_storage[i]) return true; - const Short bit = _width % (sizeof(Unit) * 8); + const Short bit = _width % UNIT_WIDTH; const Unit mask = (1 << bit) - 1; const Unit& u = _storage[fullUnits]; @@ -1096,12 +1132,12 @@ BitArray::ConstBits::operator bool() const { template template bool -BitArray::ConstBits::get() const { +BitArrayT::CBits::get() const noexcept { constexpr Index INDEX = NIndex; static_assert(INDEX < _width, ""); - constexpr Index BIT_UNIT = INDEX / (sizeof(Unit) * 8); - constexpr Index BIT_INDEX = INDEX % (sizeof(Unit) * 8); + constexpr Index BIT_UNIT = INDEX / UNIT_WIDTH; + constexpr Index BIT_INDEX = INDEX % UNIT_WIDTH; constexpr Unit MASK = 1 << BIT_INDEX; return (_storage[BIT_UNIT] & MASK) != 0; @@ -1111,11 +1147,11 @@ BitArray::ConstBits::get() const { template bool -BitArray::ConstBits::get(const Index index) const { +BitArrayT::CBits::get(const Index index) const noexcept { HFSM2_ASSERT(index < _width); - const Index unit = index / (sizeof(Unit) * 8); - const Index bit = index % (sizeof(Unit) * 8); + const Index unit = index / UNIT_WIDTH; + const Index bit = index % UNIT_WIDTH; const Unit mask = 1 << bit; return (_storage[unit] & mask) != 0; @@ -1125,7 +1161,7 @@ BitArray::ConstBits::get(const Index index) const { template void -BitArray::clear() { +BitArrayT::clear() noexcept { for (Unit& unit: _storage) unit = Unit{0}; } @@ -1135,12 +1171,12 @@ BitArray::clear() { template template bool -BitArray::get() const { +BitArrayT::get() const noexcept { constexpr Index INDEX = NIndex; - static_assert(INDEX < CAPACITY, ""); + static_assert(INDEX < BIT_COUNT, ""); - constexpr Index BIT_UNIT = INDEX / (sizeof(Unit) * 8); - constexpr Index BIT_INDEX = INDEX % (sizeof(Unit) * 8); + constexpr Index BIT_UNIT = INDEX / UNIT_WIDTH; + constexpr Index BIT_INDEX = INDEX % UNIT_WIDTH; constexpr Unit MASK = 1 << BIT_INDEX; return (_storage[BIT_UNIT] & MASK) != 0; @@ -1151,12 +1187,12 @@ BitArray::get() const { template template void -BitArray::set() { +BitArrayT::set() noexcept { constexpr Index INDEX = NIndex; - static_assert(INDEX < CAPACITY, ""); + static_assert(INDEX < BIT_COUNT, ""); - constexpr Index BIT_UNIT = INDEX / (sizeof(Unit) * 8); - constexpr Index BIT_INDEX = INDEX % (sizeof(Unit) * 8); + constexpr Index BIT_UNIT = INDEX / UNIT_WIDTH; + constexpr Index BIT_INDEX = INDEX % UNIT_WIDTH; constexpr Unit MASK = 1 << BIT_INDEX; _storage[BIT_UNIT] |= MASK; @@ -1167,12 +1203,12 @@ BitArray::set() { template template void -BitArray::clear() { +BitArrayT::clear() noexcept { constexpr Index INDEX = NIndex; - static_assert(INDEX < CAPACITY, ""); + static_assert(INDEX < BIT_COUNT, ""); - constexpr Index BIT_UNIT = INDEX / (sizeof(Unit) * 8); - constexpr Index BIT_INDEX = INDEX % (sizeof(Unit) * 8); + constexpr Index BIT_UNIT = INDEX / UNIT_WIDTH; + constexpr Index BIT_INDEX = INDEX % UNIT_WIDTH; constexpr Unit MASK = 1 << BIT_INDEX; _storage[BIT_UNIT] &= ~MASK; @@ -1182,11 +1218,11 @@ BitArray::clear() { template bool -BitArray::get(const Index index) const { - HFSM2_ASSERT(index < CAPACITY); +BitArrayT::get(const Index index) const noexcept { + HFSM2_ASSERT(index < BIT_COUNT); - const Index unit = index / (sizeof(Unit) * 8); - const Index bit = index % (sizeof(Unit) * 8); + const Index unit = index / UNIT_WIDTH; + const Index bit = index % UNIT_WIDTH; const Unit mask = 1 << bit; return (_storage[unit] & mask) != 0; @@ -1196,11 +1232,11 @@ BitArray::get(const Index index) const { template void -BitArray::set(const Index index) { - HFSM2_ASSERT(index < CAPACITY); +BitArrayT::set(const Index index) noexcept { + HFSM2_ASSERT(index < BIT_COUNT); - const Index unit = index / (sizeof(Unit) * 8); - const Index bit = index % (sizeof(Unit) * 8); + const Index unit = index / UNIT_WIDTH; + const Index bit = index % UNIT_WIDTH; const Unit mask = 1 << bit; _storage[unit] |= mask; @@ -1210,11 +1246,11 @@ BitArray::set(const Index index) { template void -BitArray::clear(const Index index) { - HFSM2_ASSERT(index < CAPACITY); +BitArrayT::clear(const Index index) noexcept { + HFSM2_ASSERT(index < BIT_COUNT); - const Index unit = index / (sizeof(Unit) * 8); - const Index bit = index % (sizeof(Unit) * 8); + const Index unit = index / UNIT_WIDTH; + const Index bit = index % UNIT_WIDTH; const Unit mask = 1 << bit; _storage[unit] &= ~mask; @@ -1224,11 +1260,11 @@ BitArray::clear(const Index index) { template template -typename BitArray::Bits -BitArray::bits() { +typename BitArrayT::Bits +BitArrayT::bits() noexcept { constexpr Short UNIT = NUnit; constexpr Short WIDTH = NWidth; - static_assert(UNIT + (WIDTH + 7) / (sizeof(Unit) * 8) <= CAPACITY, ""); + static_assert(UNIT + contain(WIDTH, UNIT_WIDTH) <= UNIT_COUNT, ""); return Bits{_storage + UNIT, WIDTH}; } @@ -1237,21 +1273,21 @@ BitArray::bits() { template template -typename BitArray::ConstBits -BitArray::bits() const { +typename BitArrayT::CBits +BitArrayT::bits() const noexcept { constexpr Short UNIT = NUnit; constexpr Short WIDTH = NWidth; - static_assert(UNIT + (WIDTH + 7) / (sizeof(Unit) * 8) <= CAPACITY, ""); + static_assert(UNIT + contain(WIDTH, UNIT_WIDTH) <= UNIT_COUNT, ""); - return ConstBits{_storage + UNIT, WIDTH}; + return CBits{_storage + UNIT, WIDTH}; } //------------------------------------------------------------------------------ template -typename BitArray::Bits -BitArray::bits(const Units& units) { - HFSM2_ASSERT(units.unit + (units.width + 7) / (sizeof(Unit) * 8) <= CAPACITY); +typename BitArrayT::Bits +BitArrayT::bits(const Units& units) noexcept { + HFSM2_ASSERT(units.unit + contain(units.width, UNIT_WIDTH) <= UNIT_COUNT); return Bits{_storage + units.unit, units.width}; } @@ -1259,33 +1295,35 @@ BitArray::bits(const Units& units) { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - template -typename BitArray::ConstBits -BitArray::bits(const Units& units) const { - HFSM2_ASSERT(units.unit + (units.width + 7) / (sizeof(Unit) * 8) <= CAPACITY); +typename BitArrayT::CBits +BitArrayT::bits(const Units& units) const noexcept { + HFSM2_ASSERT(units.unit + contain(units.width, UNIT_WIDTH) <= UNIT_COUNT); - return ConstBits{_storage + units.unit, units.width}; + return CBits{_storage + units.unit, units.width}; } //////////////////////////////////////////////////////////////////////////////// } } +#ifdef HFSM2_ENABLE_SERIALIZATION + namespace hfsm2 { namespace detail { //------------------------------------------------------------------------------ template -struct StreamBuffer { +struct StreamBufferT { static constexpr Long BIT_CAPACITY = NBitCapacity; - static constexpr Long BYTE_COUNT = roundUp(BIT_CAPACITY, 8); + static constexpr Long BYTE_COUNT = contain(BIT_CAPACITY, 8u); using Size = UnsignedCapacity; using Data = uint8_t[BYTE_COUNT]; - void clear(); + void clear() noexcept; - //Size write(const uint8_t byte); + //Size write(const uint8_t byte) noexcept; Size bitSize; Data payload; @@ -1294,17 +1332,17 @@ struct StreamBuffer { //////////////////////////////////////////////////////////////////////////////// template -class BitWriteStream final { +class BitWriteStreamT final { public: static constexpr Long BIT_CAPACITY = NBitCapacity; - using Buffer = StreamBuffer; + using Buffer = StreamBufferT; public: - BitWriteStream(Buffer& _buffer); + BitWriteStreamT(Buffer& _buffer) noexcept; template - void write(const UnsignedBitWidth item); + void write(const UnsignedBitWidth item) noexcept; private: Buffer& _buffer; @@ -1313,21 +1351,21 @@ class BitWriteStream final { //------------------------------------------------------------------------------ template -class BitReadStream final { +class BitReadStreamT final { public: static constexpr Long BIT_CAPACITY = NBitCapacity; - using Buffer = StreamBuffer; + using Buffer = StreamBufferT; public: - BitReadStream(const Buffer& buffer) + BitReadStreamT(const Buffer& buffer) noexcept : _buffer{buffer} {} template - UnsignedBitWidth read(); + UnsignedBitWidth read() noexcept; - Long cursor() const { return _cursor; } + Long cursor() const noexcept { return _cursor; } private: const Buffer& _buffer; @@ -1340,6 +1378,8 @@ class BitReadStream final { } } +#ifdef HFSM2_ENABLE_SERIALIZATION + namespace hfsm2 { namespace detail { @@ -1347,7 +1387,7 @@ namespace detail { template void -StreamBuffer::clear() { +StreamBufferT::clear() noexcept { bitSize = 0; fill(payload, 0); } @@ -1355,7 +1395,7 @@ StreamBuffer::clear() { //////////////////////////////////////////////////////////////////////////////// template -BitWriteStream::BitWriteStream(Buffer& buffer) +BitWriteStreamT::BitWriteStreamT(Buffer& buffer) noexcept : _buffer{buffer} { _buffer.clear(); @@ -1366,7 +1406,7 @@ BitWriteStream::BitWriteStream(Buffer& buffer) template template void -BitWriteStream::write(const UnsignedBitWidth item) { +BitWriteStreamT::write(const UnsignedBitWidth item) noexcept { constexpr Short BIT_WIDTH = NBitWidth; static_assert(BIT_WIDTH > 0, "STATIC ASSERT"); @@ -1397,7 +1437,7 @@ BitWriteStream::write(const UnsignedBitWidth item) { template template UnsignedBitWidth -BitReadStream::read() { +BitReadStreamT::read() noexcept { constexpr Short BIT_WIDTH = NBitWidth; static_assert(BIT_WIDTH > 0, "STATIC ASSERT"); @@ -1432,232 +1472,10 @@ BitReadStream::read() { } } -namespace hfsm2 { -namespace detail { - -//////////////////////////////////////////////////////////////////////////////// - -template -class List { -public: - using Index = Long; - - static constexpr Index CAPACITY = NCapacity; - - static constexpr Index INVALID = Index (-1); - -private: - using Item = TItem; - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - struct Cell { - Item item; - Index prev; - Index next; - }; - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -public: - template - Index emplace(TArgs... args); - - void remove(const Index i); - - HFSM2_INLINE Item& operator[] (const Index i); - HFSM2_INLINE const Item& operator[] (const Index i) const; - - HFSM2_INLINE Index count() const { return _count; } - -private: - HFSM2_IF_ASSERT(void verifyStructure(const Index occupied = INVALID) const); - -private: - Cell _cells[CAPACITY]; - Index _vacantHead = 0; - Index _vacantTail = 0; - Index _last = 0; - Index _count = 0; -}; - -//------------------------------------------------------------------------------ - -template -class List {}; - -//////////////////////////////////////////////////////////////////////////////// - -} -} - -namespace hfsm2 { -namespace detail { - -//////////////////////////////////////////////////////////////////////////////// - -template -template -Long -List::emplace(TA... args) { - if (_count < CAPACITY) { - HFSM2_ASSERT(_vacantHead < CAPACITY); - HFSM2_ASSERT(_vacantTail < CAPACITY); - - const Index index = _vacantHead; - auto& cell = _cells[index]; - ++_count; - - if (_vacantHead != _vacantTail) { - // recycle - HFSM2_ASSERT(cell.prev == INVALID); - HFSM2_ASSERT(cell.next != INVALID); - - _vacantHead = cell.next; - - auto& head = _cells[_vacantHead]; - HFSM2_ASSERT(head.prev == index); - head.prev = INVALID; - } else if (_last < CAPACITY - 1) { - // grow - ++_last; - _vacantHead = _last; - _vacantTail = _last; - - auto& vacant = _cells[_vacantHead]; - vacant.prev = INVALID; - vacant.next = INVALID; - } else { - HFSM2_ASSERT(_count == CAPACITY); - - _vacantHead = INVALID; - _vacantTail = INVALID; - } - - HFSM2_IF_ASSERT(verifyStructure()); - - new (&cell.item) Item{std::forward(args)...}; - - return index; - } else { - // full - HFSM2_ASSERT(_vacantHead == INVALID); - HFSM2_ASSERT(_vacantTail == INVALID); - HFSM2_ASSERT(_count == CAPACITY); - HFSM2_BREAK(); - - return INVALID; - } -} - -//------------------------------------------------------------------------------ - -template -void -List::remove(const Index i) { - HFSM2_ASSERT(i < CAPACITY && _count); - - auto& fresh = _cells[i]; - - if (_count < CAPACITY) { - HFSM2_ASSERT(_vacantHead < CAPACITY); - HFSM2_ASSERT(_vacantTail < CAPACITY); - - fresh.prev = INVALID; - fresh.next = _vacantHead; - - auto& head = _cells[_vacantHead]; - head.prev = i; - - _vacantHead = i; - } else { - // 0 -> 1 - HFSM2_ASSERT(_count == CAPACITY); - HFSM2_ASSERT(_vacantHead == INVALID); - HFSM2_ASSERT(_vacantTail == INVALID); - - fresh.prev = INVALID; - fresh.next = INVALID; - - _vacantHead = i; - _vacantTail = i; - } - - --_count; - - HFSM2_IF_ASSERT(verifyStructure()); -} - -//------------------------------------------------------------------------------ - -template -T& -List::operator[] (const Index i) { - HFSM2_IF_ASSERT(verifyStructure()); - - return _cells[i].item; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -template -const T& -List::operator[] (const Index i) const { - HFSM2_IF_ASSERT(verifyStructure()); - - return _cells[i].item; -} - -//------------------------------------------------------------------------------ - -#ifdef HFSM2_ENABLE_ASSERT - -template -void -List::verifyStructure(const Index occupied) const { - if (_count < CAPACITY) { - HFSM2_ASSERT(_vacantHead < CAPACITY); - HFSM2_ASSERT(_vacantTail < CAPACITY); - - HFSM2_ASSERT(_cells[_vacantHead].prev == INVALID); - HFSM2_ASSERT(_cells[_vacantTail].next == INVALID); - - auto emptyCount = 1; - - for (auto c = _vacantHead; c != _vacantTail; ) { - HFSM2_ASSERT(occupied != c); - - const auto& current = _cells[c]; - - const auto f = current.next; - if (f != INVALID) { - // next - const auto& following = _cells[f]; - - HFSM2_ASSERT(following.prev == c); - - c = f; - continue; - } else { - // end - HFSM2_ASSERT(_vacantTail == c); - HFSM2_ASSERT(_count == CAPACITY - emptyCount); - - break; - } - } - } else { - HFSM2_ASSERT(_vacantHead == INVALID); - HFSM2_ASSERT(_vacantTail == INVALID); - } -} #endif -//////////////////////////////////////////////////////////////////////////////// - -} -} +#endif #ifdef HFSM2_ENABLE_UTILITY_THEORY namespace hfsm2 { @@ -1672,13 +1490,13 @@ namespace hfsm2 { class SplitMix64 { public: - inline SplitMix64() {} - inline SplitMix64(const uint64_t seed); + inline SplitMix64() noexcept {} + inline SplitMix64(const uint64_t seed) noexcept; - inline uint64_t next(); + inline uint64_t next() noexcept; private: - inline uint64_t raw(); + inline uint64_t raw() noexcept; private: @@ -1694,18 +1512,18 @@ class SplitMix64 { class XoShiRo256Plus { public: - inline XoShiRo256Plus(); - inline XoShiRo256Plus(const uint64_t s); - inline XoShiRo256Plus(const uint64_t(& s)[4]); + inline XoShiRo256Plus() noexcept; + inline XoShiRo256Plus(const uint64_t s) noexcept; + inline XoShiRo256Plus(const uint64_t(& s)[4]) noexcept; - inline void seed(const uint64_t s); - inline void seed(const uint64_t(& s)[4]); + inline void seed(const uint64_t s) noexcept; + inline void seed(const uint64_t(& s)[4]) noexcept; - inline float next(); - inline void jump(); + inline float next() noexcept; + inline void jump() noexcept; private: - inline uint64_t raw(); + inline uint64_t raw() noexcept; private: uint64_t _state[4]; @@ -1721,13 +1539,13 @@ class XoShiRo256Plus { class SplitMix32 { public: - inline SplitMix32() {} - inline SplitMix32(const uint32_t seed); + inline SplitMix32() noexcept {} + inline SplitMix32(const uint32_t seed) noexcept; - inline uint32_t next(); + inline uint32_t next() noexcept; private: - inline uint32_t raw(); + inline uint32_t raw() noexcept; private: uint32_t _state; @@ -1742,18 +1560,18 @@ class SplitMix32 { class XoShiRo128Plus { public: - inline XoShiRo128Plus(); - inline XoShiRo128Plus(const uint32_t s); - inline XoShiRo128Plus(const uint32_t(& s)[4]); + inline XoShiRo128Plus() noexcept; + inline XoShiRo128Plus(const uint32_t s) noexcept; + inline XoShiRo128Plus(const uint32_t(& s)[4]) noexcept; - inline void seed(const uint32_t s); - inline void seed(const uint32_t(& s)[4]); + inline void seed(const uint32_t s) noexcept; + inline void seed(const uint32_t(& s)[4]) noexcept; - inline float next(); - inline void jump(); + inline float next() noexcept; + inline void jump() noexcept; private: - inline uint32_t raw(); + inline uint32_t raw() noexcept; private: uint32_t _state[4]; @@ -1762,12 +1580,12 @@ class XoShiRo128Plus { //------------------------------------------------------------------------------ template -class RandomT; +class RNGT; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - template <> -class RandomT +class RNGT : public HFSM2_64BIT_OR_32BIT(XoShiRo256Plus, XoShiRo128Plus) { public: @@ -1791,7 +1609,7 @@ namespace detail { inline float -uniformReal(const uint32_t uint) { +uniformReal(const uint32_t uint) noexcept { const auto real = convert(UINT32_C(0x7F) << 23 | uint >> 9); return real - 1.0f; @@ -1801,7 +1619,7 @@ uniformReal(const uint32_t uint) { inline double -uniformReal(const uint64_t uint) { +uniformReal(const uint64_t uint) noexcept { const auto real = convert(UINT64_C(0x3FF) << 52 | uint >> 12); return real - 1.0; @@ -1811,7 +1629,7 @@ uniformReal(const uint64_t uint) { inline uint32_t -rotl(const uint32_t x, const uint32_t k) { +rotl(const uint32_t x, const uint32_t k) noexcept { return (x << k) | (x >> (32 - k)); } @@ -1819,7 +1637,7 @@ rotl(const uint32_t x, const uint32_t k) { inline uint64_t -rotl(const uint64_t x, const uint64_t k) { +rotl(const uint64_t x, const uint64_t k) noexcept { return (x << k) | (x >> (64 - k)); } @@ -1827,14 +1645,14 @@ rotl(const uint64_t x, const uint64_t k) { //////////////////////////////////////////////////////////////////////////////// -SplitMix64::SplitMix64(const uint64_t seed) +SplitMix64::SplitMix64(const uint64_t seed) noexcept : _state{seed} {} //------------------------------------------------------------------------------ uint64_t -SplitMix64::next() { +SplitMix64::next() noexcept { for (;;) if (const uint64_t number = raw()) return number; @@ -1843,7 +1661,7 @@ SplitMix64::next() { //------------------------------------------------------------------------------ uint64_t -SplitMix64::raw() { +SplitMix64::raw() noexcept { uint64_t z = (_state += 0x9e3779b97f4a7c15); z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9; z = (z ^ (z >> 27)) * 0x94d049bb133111eb; @@ -1853,7 +1671,7 @@ SplitMix64::raw() { //////////////////////////////////////////////////////////////////////////////// -XoShiRo256Plus::XoShiRo256Plus() { +XoShiRo256Plus::XoShiRo256Plus() noexcept { SplitMix64 generator; _state[0] = generator.next(); @@ -1864,20 +1682,20 @@ XoShiRo256Plus::XoShiRo256Plus() { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -XoShiRo256Plus::XoShiRo256Plus(const uint64_t s) { +XoShiRo256Plus::XoShiRo256Plus(const uint64_t s) noexcept { seed(s); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -XoShiRo256Plus::XoShiRo256Plus(const uint64_t(& s)[4]) { +XoShiRo256Plus::XoShiRo256Plus(const uint64_t(& s)[4]) noexcept { seed(s); } //------------------------------------------------------------------------------ void -XoShiRo256Plus::seed(const uint64_t s) { +XoShiRo256Plus::seed(const uint64_t s) noexcept { SplitMix64 generator{s}; _state[0] = generator.next(); @@ -1889,7 +1707,7 @@ XoShiRo256Plus::seed(const uint64_t s) { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void -XoShiRo256Plus::seed(const uint64_t(& s)[4]) { +XoShiRo256Plus::seed(const uint64_t(& s)[4]) noexcept { _state[0] = s[0]; _state[1] = s[1]; _state[2] = s[2]; @@ -1899,14 +1717,14 @@ XoShiRo256Plus::seed(const uint64_t(& s)[4]) { //------------------------------------------------------------------------------ float -XoShiRo256Plus::next() { +XoShiRo256Plus::next() noexcept { return detail::uniformReal((uint32_t) raw()); } //------------------------------------------------------------------------------ void -XoShiRo256Plus::jump() { +XoShiRo256Plus::jump() noexcept { static const uint64_t JUMP[] = { 0x180ec6d33cfd0aba, 0xd5a61266f0c9392c, 0xa9582618e03fc9aa, 0x39abdc4529b1661c }; uint64_t s0 = 0; @@ -1934,7 +1752,7 @@ XoShiRo256Plus::jump() { //------------------------------------------------------------------------------ uint64_t -XoShiRo256Plus::raw() { +XoShiRo256Plus::raw() noexcept { const uint64_t result_plus = _state[0] + _state[3]; const uint64_t t = _state[1] << 17; @@ -1953,14 +1771,14 @@ XoShiRo256Plus::raw() { //////////////////////////////////////////////////////////////////////////////// -SplitMix32::SplitMix32(const uint32_t seed) +SplitMix32::SplitMix32(const uint32_t seed) noexcept : _state{seed} {} //------------------------------------------------------------------------------ uint32_t -SplitMix32::next() { +SplitMix32::next() noexcept { for (;;) if (const uint32_t number = raw()) return number; @@ -1969,7 +1787,7 @@ SplitMix32::next() { //------------------------------------------------------------------------------ uint32_t -SplitMix32::raw() { +SplitMix32::raw() noexcept { uint32_t z = (_state += 0x9E3779B9); z = (z ^ (z >> 16)) * 0x85ebca6b; z = (z ^ (z >> 13)) * 0xc2b2ae35; @@ -1979,7 +1797,7 @@ SplitMix32::raw() { //////////////////////////////////////////////////////////////////////////////// -XoShiRo128Plus::XoShiRo128Plus() { +XoShiRo128Plus::XoShiRo128Plus() noexcept { SplitMix32 generator; _state[0] = generator.next(); @@ -1990,20 +1808,20 @@ XoShiRo128Plus::XoShiRo128Plus() { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -XoShiRo128Plus::XoShiRo128Plus(const uint32_t s) { +XoShiRo128Plus::XoShiRo128Plus(const uint32_t s) noexcept { seed(s); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -XoShiRo128Plus::XoShiRo128Plus(const uint32_t(& s)[4]) { +XoShiRo128Plus::XoShiRo128Plus(const uint32_t(& s)[4]) noexcept { seed(s); } //------------------------------------------------------------------------------ void -XoShiRo128Plus::seed(const uint32_t s) { +XoShiRo128Plus::seed(const uint32_t s) noexcept { SplitMix32 generator{s}; _state[0] = generator.next(); @@ -2015,7 +1833,7 @@ XoShiRo128Plus::seed(const uint32_t s) { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void -XoShiRo128Plus::seed(const uint32_t(& s)[4]) { +XoShiRo128Plus::seed(const uint32_t(& s)[4]) noexcept { _state[0] = s[0]; _state[1] = s[1]; _state[2] = s[2]; @@ -2025,14 +1843,14 @@ XoShiRo128Plus::seed(const uint32_t(& s)[4]) { //------------------------------------------------------------------------------ float -XoShiRo128Plus::next() { +XoShiRo128Plus::next() noexcept { return detail::uniformReal(raw()); } //------------------------------------------------------------------------------ void -XoShiRo128Plus::jump() { +XoShiRo128Plus::jump() noexcept { static const uint32_t JUMP[] = { 0x8764000b, 0xf542d2d3, 0x6fa035c3, 0x77f2db5b }; uint32_t s0 = 0; @@ -2060,7 +1878,7 @@ XoShiRo128Plus::jump() { //------------------------------------------------------------------------------ uint32_t -XoShiRo128Plus::raw() { +XoShiRo128Plus::raw() noexcept { const uint32_t result_plus = _state[0] + _state[3]; const uint32_t t = _state[1] << 9; @@ -2083,303 +1901,102 @@ XoShiRo128Plus::raw() { #endif namespace hfsm2 { - -//////////////////////////////////////////////////////////////////////////////// - -#if 0 - namespace detail { -template -struct IndexConstant {}; - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -template -struct IndexSequence { - using Type = IndexSequence; -}; - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -template -struct MakeIndexSequenceT {}; - -template -struct MakeIndexSequenceT, - IndexSequence> - : MakeIndexSequenceT, - IndexSequence> -{}; - -template -struct MakeIndexSequenceT, - IndexSequence> - : IndexSequence -{}; - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -template -using MakeIndexSequence = typename MakeIndexSequenceT, - IndexSequence<>>::Type; - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -template -using IndexSequenceFor = MakeIndexSequence; - //////////////////////////////////////////////////////////////////////////////// -template -struct ITL_EntryT {}; - -template -struct ITL_EntryN - : ITL_EntryT -{}; - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -template -struct ITL_Impl; - -template -struct ITL_Impl, Ts...> - : ITL_EntryN... -{ - template - static constexpr Long select(ITL_EntryN) { return (Long) N; } -}; - -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - template -struct TypeList - : private detail::ITL_Impl, Ts...> -{ - using Base = detail::ITL_Impl, Ts...>; - +struct TL_ { static constexpr Long SIZE = sizeof...(Ts); - - template - static constexpr Long index() { - return Base::template select(TypeList{}); - } }; -template -constexpr Long index () { return TList::template index (); } - -template -constexpr bool contains() { return std::is_base_of, TList>::value; } - -//////////////////////////////////////////////////////////////////////////////// - -namespace detail { - -template -struct PrependT; - -template -struct PrependT> { - using Type = TypeList; -}; - -} - -template -using Prepend = typename detail::PrependT::Type; - //------------------------------------------------------------------------------ -namespace detail { - -template -struct MergeT; - -template -struct MergeT, TypeList> { - using Type = TypeList; -}; - -} - -template -using Merge = typename detail::MergeT::Type; - -//------------------------------------------------------------------------------ - -namespace detail { - -template -struct LowerT; - -template -using Lower = typename LowerT::Type; - -template -struct LowerT { - using Type = typename std::conditional< - (I < H), - Prepend>, - Lower - >::type; -}; - -template -struct LowerT { - using Type = TypeList<>; -}; - -} - -template -using LHalf = detail::Lower; - -//------------------------------------------------------------------------------ - -namespace detail { - -template -struct UpperT; - -template -using Upper = typename UpperT::Type; - -template -struct UpperT { - using Type = typename std::conditional< - (I < H), - UpperT, - TypeList - >::type; -}; - -template -struct UpperT { - using Type = TypeList<>; -}; - -} - -template -using RHalf = detail::Upper; - -//////////////////////////////////////////////////////////////////////////////// - -#else - -template -struct TypeList { - static constexpr Long SIZE = sizeof...(Ts); -}; - -//------------------------------------------------------------------------------ - -namespace detail { - template struct Const { - static constexpr Long Value = N; + static constexpr Long VALUE = N; }; //------------------------------------------------------------------------------ -template +template struct PrependT; template -struct PrependT> { - using Type = TypeList; +struct PrependT> { + using Type = TL_; }; -} - template -using Prepend = typename detail::PrependT::Type; +using PrependTypes = typename PrependT::Type; //------------------------------------------------------------------------------ -namespace detail { - -template +template struct MergeT; template -struct MergeT, TypeList> { - using Type = TypeList; +struct MergeT, TL_> { + using Type = TL_; }; -} - template -using Merge = typename detail::MergeT::Type; +using Merge = typename MergeT::Type; //------------------------------------------------------------------------------ -namespace detail { - template struct LowerT; -template -using Lower = typename LowerT::Type; +template +using LowerTypes = typename LowerT::Type; -template -struct LowerT { - using Type = typename std::conditional< - (I < H), - Prepend>, - Lower - >::type; -}; +template +struct LowerT { + using LTypeList = typename LowerT::Type; -template -struct LowerT { - using Type = TypeList<>; + using Type = Conditional< + (NIndex < NHalf), + PrependTypes, + LTypeList + >; }; -} +template +struct LowerT { + using Type = TL_<>; +}; template -using LHalf = detail::Lower; +using LHalfTypes = LowerTypes; //------------------------------------------------------------------------------ -namespace detail { - template struct UpperT; -template -using Upper = typename UpperT::Type; +template +using UpperTypes = typename UpperT::Type; -template -struct UpperT { - using Type = typename std::conditional< - (I < H), - Upper, - TypeList - >::type; +template +struct UpperT { + using Type = Conditional< + (NIndex < NHalf), + UpperTypes, + TL_ + >; }; -template -struct UpperT { - using Type = TypeList<>; +template +struct UpperT { + using Type = TL_<>; }; -} - template -using RHalf = detail::Upper; +using RHalfTypes = UpperTypes; //------------------------------------------------------------------------------ -namespace detail { - template struct FindImpl : Const @@ -2401,23 +2018,21 @@ template struct Find; template -struct Find> +struct Find, T> : FindImpl<0, T, Ts...> {}; -} +//////////////////////////////////////////////////////////////////////////////// -//------------------------------------------------------------------------------ +} template -constexpr Long index () { return detail::Find::Value; } +constexpr Long index () noexcept { return detail::Find::VALUE; } template -constexpr bool contains() { return index() != INVALID_LONG; } - -#endif +constexpr bool contains() noexcept { return index() != INVALID_LONG; } -//////////////////////////////////////////////////////////////////////////////// +//------------------------------------------------------------------------------ } @@ -2481,7 +2096,7 @@ enum class StatusEvent : uint8_t { static inline const char* -stateName(const std::type_index stateType) { +stateName(const std::type_index stateType) noexcept { const char* const raw = stateType.name(); #if defined(_MSC_VER) @@ -2507,7 +2122,7 @@ stateName(const std::type_index stateType) { static inline const char* -methodName(const Method method) { +methodName(const Method method) noexcept { switch (method) { #ifdef HFSM2_ENABLE_UTILITY_THEORY @@ -2540,7 +2155,7 @@ methodName(const Method method) { static inline const char* -transitionName(const TransitionType type) { +transitionName(const TransitionType type) noexcept { switch (type) { case TransitionType::CHANGE: return "changeTo"; case TransitionType::RESTART: return "restart"; @@ -2571,12 +2186,12 @@ namespace detail { #endif struct alignas(4) TransitionBase { - HFSM2_INLINE TransitionBase() = default; + constexpr TransitionBase() noexcept = default; //---------------------------------------------------------------------- HFSM2_INLINE TransitionBase(const StateID destination_, - const TransitionType type_) + const TransitionType type_) noexcept : destination{destination_} , type{type_} {} @@ -2585,15 +2200,15 @@ struct alignas(4) TransitionBase { HFSM2_INLINE TransitionBase(const StateID origin_, const StateID destination_, - const TransitionType type_) - : origin{origin_} + const TransitionType type_) noexcept + : origin {origin_} , destination{destination_} - , type{type_} + , type {type_} {} //---------------------------------------------------------------------- - HFSM2_INLINE bool operator == (const TransitionBase& other) const { + HFSM2_INLINE bool operator == (const TransitionBase& other) const noexcept { return origin == other.origin && destination == other.destination && method == other.method && @@ -2621,15 +2236,19 @@ struct alignas(4) TransitionT using Payload = TPayload; using Storage = typename std::aligned_storage::type; - HFSM2_INLINE TransitionT() = default; - using TransitionBase::TransitionBase; //---------------------------------------------------------------------- + HFSM2_INLINE TransitionT() noexcept { + new (&storage) Payload{}; + } + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + HFSM2_INLINE TransitionT(const StateID destination, const TransitionType type, - const Payload& payload) + const Payload& payload) noexcept : TransitionBase{destination, type} , payloadSet{true} { @@ -2640,7 +2259,7 @@ struct alignas(4) TransitionT HFSM2_INLINE TransitionT(const StateID destination, const TransitionType type, - Payload&& payload) + Payload&& payload) noexcept : TransitionBase{destination, type} , payloadSet{true} { @@ -2652,7 +2271,7 @@ struct alignas(4) TransitionT HFSM2_INLINE TransitionT(const StateID origin, const StateID destination, const TransitionType type, - const Payload& payload) + const Payload& payload) noexcept : TransitionBase{origin, destination, type} , payloadSet{true} { @@ -2664,7 +2283,7 @@ struct alignas(4) TransitionT HFSM2_INLINE TransitionT(const StateID origin, const StateID destination, const TransitionType type, - Payload&& payload) + Payload&& payload) noexcept : TransitionBase{origin, destination, type} , payloadSet{true} { @@ -2673,7 +2292,7 @@ struct alignas(4) TransitionT //---------------------------------------------------------------------- - HFSM2_INLINE bool operator == (const TransitionT& other) const { + HFSM2_INLINE bool operator == (const TransitionT& other) const noexcept { return TransitionBase::operator == (other) && (payloadSet == other.payloadSet); // (!payloadSet && !other.payloadSet || payload == other.payload); @@ -2735,13 +2354,13 @@ struct LoggerInterfaceT { virtual void recordMethod(Context& /*context*/, const StateID /*origin*/, - const Method /*method*/) + const Method /*method*/) noexcept {} virtual void recordTransition(Context& /*context*/, const StateID /*origin*/, const TransitionType /*transitionType*/, - const StateID /*target*/) + const StateID /*target*/) noexcept {} #ifdef HFSM2_ENABLE_PLANS @@ -2749,18 +2368,18 @@ struct LoggerInterfaceT { virtual void recordTaskStatus(Context& /*context*/, const RegionID /*region*/, const StateID /*origin*/, - const StatusEvent /*event*/) + const StatusEvent /*event*/) noexcept {} virtual void recordPlanStatus(Context& /*context*/, const RegionID /*region*/, - const StatusEvent /*event*/) + const StatusEvent /*event*/) noexcept {} #endif virtual void recordCancelledPending(Context& /*context*/, - const StateID /*origin*/) + const StateID /*origin*/) noexcept {} #ifdef HFSM2_ENABLE_UTILITY_THEORY @@ -2768,13 +2387,13 @@ struct LoggerInterfaceT { virtual void recordUtilityResolution(Context& /*context*/, const StateID /*head*/, const StateID /*prong*/, - const Utilty /*utilty*/) + const Utilty /*utilty*/) noexcept {} virtual void recordRandomResolution(Context& /*context*/, const StateID /*head*/, const StateID /*prong*/, - const Utilty /*utilty*/) + const Utilty /*utilty*/) noexcept {} #endif @@ -2825,14 +2444,14 @@ struct alignas(alignof(void*)) StructureStateInfo { COUNT }; - StructureStateInfo() = default; + StructureStateInfo() noexcept = default; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE StructureStateInfo(const Long parent_, const RegionType regionType_, const Short depth_, - const char* const name_) + const char* const name_) noexcept : name{name_} , parent{parent_} , regionType{regionType_ } @@ -2867,24 +2486,40 @@ namespace detail { //////////////////////////////////////////////////////////////////////////////// -#pragma pack(push, 2) +#pragma pack(push, 1) struct TaskBase { - HFSM2_INLINE TaskBase() {} + HFSM2_INLINE TaskBase() noexcept {} HFSM2_INLINE TaskBase(const StateID origin_, const StateID destination_, - const TransitionType type_) + const TransitionType type_) noexcept : origin{origin_} , destination{destination_} , type{type_} {} - StateID origin = INVALID_STATE_ID; - StateID destination = INVALID_STATE_ID; + static_assert(sizeof(Long) == sizeof(StateID), ""); + + union { + StateID origin = INVALID_STATE_ID; + Long prev; + }; + + union { + StateID destination = INVALID_STATE_ID; + Long next; + }; + TransitionType type = TransitionType::COUNT; }; +inline bool operator == (const TaskBase& lhs, const TaskBase& rhs) noexcept { + return lhs.origin == rhs.origin && + lhs.destination == rhs.destination && + lhs.type == rhs.type; +} + //------------------------------------------------------------------------------ template @@ -2898,7 +2533,7 @@ struct TaskT // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE TaskT() { + HFSM2_INLINE TaskT() noexcept { new (&storage) Payload{}; } @@ -2907,7 +2542,7 @@ struct TaskT HFSM2_INLINE TaskT(const StateID origin, const StateID destination, const TransitionType type, - const Payload& payload) + const Payload& payload) noexcept : TaskBase{origin, destination, type} , payloadSet{true} { @@ -2919,7 +2554,7 @@ struct TaskT HFSM2_INLINE TaskT(const StateID origin, const StateID destination, const TransitionType type, - Payload&& payload) + Payload&& payload) noexcept : TaskBase{origin, destination, type} , payloadSet{true} { @@ -2928,8 +2563,8 @@ struct TaskT // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool payloadSet = false; Storage storage; + bool payloadSet = false; }; //------------------------------------------------------------------------------ @@ -2941,8 +2576,237 @@ struct TaskT using TaskBase::TaskBase; }; +#pragma pack(pop) + +//////////////////////////////////////////////////////////////////////////////// + +template +class TaskListT { +public: + using Index = Long; + + static constexpr Index CAPACITY = NCapacity; + + static constexpr Index INVALID = Index (-1); + +private: + using Payload = TPayload; + using Item = TaskT; + +public: + template + Index emplace(TArgs&&... args) noexcept; + + void remove(const Index i) noexcept; + + HFSM2_INLINE Item& operator[] (const Index i) noexcept; + HFSM2_INLINE const Item& operator[] (const Index i) const noexcept; + + HFSM2_INLINE Index count() const noexcept { return _count; } + +private: + HFSM2_IF_ASSERT(void verifyStructure(const Index occupied = INVALID) const noexcept); + +private: + Item _items[CAPACITY]; + Index _vacantHead = 0; + Index _vacantTail = 0; + Index _last = 0; + Index _count = 0; +}; + +//------------------------------------------------------------------------------ + +template +class TaskListT {}; + +//////////////////////////////////////////////////////////////////////////////// + +} +} + +#ifdef HFSM2_ENABLE_PLANS + +namespace hfsm2 { +namespace detail { + +//////////////////////////////////////////////////////////////////////////////// + +template +template +Long +TaskListT::emplace(TA&&... args) noexcept { + if (_count < CAPACITY) { + HFSM2_ASSERT(_vacantHead < CAPACITY); + HFSM2_ASSERT(_vacantTail < CAPACITY); + + const Index index = _vacantHead; + auto& cell = _items[index]; + ++_count; + + if (_vacantHead != _vacantTail) { + // recycle + HFSM2_ASSERT(cell.prev == INVALID); + HFSM2_ASSERT(cell.next != INVALID); + + _vacantHead = cell.next; + + auto& head = _items[_vacantHead]; + HFSM2_ASSERT(head.prev == index); + head.prev = INVALID; + } else if (_last < CAPACITY - 1) { + // grow + ++_last; + _vacantHead = _last; + _vacantTail = _last; + + auto& vacant = _items[_vacantHead]; + vacant.prev = INVALID; + vacant.next = INVALID; + } else { + HFSM2_ASSERT(_count == CAPACITY); + + _vacantHead = INVALID; + _vacantTail = INVALID; + } + + HFSM2_IF_ASSERT(verifyStructure()); + + new (&cell) Item{std::forward(args)...}; + + return index; + } else { + // full + HFSM2_ASSERT(_vacantHead == INVALID); + HFSM2_ASSERT(_vacantTail == INVALID); + HFSM2_ASSERT(_count == CAPACITY); + HFSM2_BREAK(); + + return INVALID; + } +} + +//------------------------------------------------------------------------------ + +template +void +TaskListT::remove(const Index i) noexcept { + HFSM2_ASSERT(i < CAPACITY && _count); + + auto& fresh = _items[i]; + + if (_count < CAPACITY) { + HFSM2_ASSERT(_vacantHead < CAPACITY); + HFSM2_ASSERT(_vacantTail < CAPACITY); + + fresh.prev = INVALID; + fresh.next = _vacantHead; + + auto& head = _items[_vacantHead]; + head.prev = i; + + _vacantHead = i; + } else { + // 0 -> 1 + HFSM2_ASSERT(_count == CAPACITY); + HFSM2_ASSERT(_vacantHead == INVALID); + HFSM2_ASSERT(_vacantTail == INVALID); + + fresh.prev = INVALID; + fresh.next = INVALID; + + _vacantHead = i; + _vacantTail = i; + } + + --_count; + + HFSM2_IF_ASSERT(verifyStructure()); +} + +//------------------------------------------------------------------------------ + +template +typename TaskListT::Item& +TaskListT::operator[] (const Index i) noexcept { + HFSM2_IF_ASSERT(verifyStructure()); + + return _items[i]; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +template +const typename TaskListT::Item& +TaskListT::operator[] (const Index i) const noexcept { + HFSM2_IF_ASSERT(verifyStructure()); + + return _items[i]; +} + //------------------------------------------------------------------------------ +#ifdef HFSM2_ENABLE_ASSERT + +template +void +TaskListT::verifyStructure(const Index occupied) const noexcept { + if (_count < CAPACITY) { + HFSM2_ASSERT(_vacantHead < CAPACITY); + HFSM2_ASSERT(_vacantTail < CAPACITY); + + HFSM2_ASSERT(_items[_vacantHead].prev == INVALID); + HFSM2_ASSERT(_items[_vacantTail].next == INVALID); + + auto emptyCount = 1; + + for (auto c = _vacantHead; c != _vacantTail; ) { + HFSM2_ASSERT(occupied != c); + + const auto& current = _items[c]; + + const auto f = current.next; + if (f != INVALID) { + // next + const auto& following = _items[f]; + + HFSM2_ASSERT(following.prev == c); + + c = f; + continue; + } else { + // end + HFSM2_ASSERT(_vacantTail == c); + HFSM2_ASSERT(_count == CAPACITY - emptyCount); + + break; + } + } + } else { + HFSM2_ASSERT(_vacantHead == INVALID); + HFSM2_ASSERT(_vacantTail == INVALID); + } +} + +#endif + +//////////////////////////////////////////////////////////////////////////////// + +} +} + +#endif + +#endif +#ifdef HFSM2_ENABLE_PLANS + +namespace hfsm2 { +namespace detail { + +//////////////////////////////////////////////////////////////////////////////// + +#pragma pack(push, 2) + struct TaskLink { Long prev = INVALID_LONG; Long next = INVALID_LONG; @@ -3007,14 +2871,14 @@ struct PlanDataT; - using Tasks = List; - using TaskLinks = StaticArray; - using Payloads = StaticArray; + using Task = TaskT; + using Tasks = TaskListT ; + using TaskLinks = StaticArrayT; + using Payloads = StaticArrayT; - using TasksBounds = Array; - using TasksBits = BitArray; - using RegionBits = BitArray; + using TasksBounds = ArrayT ; + using TasksBits = BitArrayT; + using RegionBits = BitArrayT; Tasks tasks; TaskLinks taskLinks; @@ -3026,9 +2890,12 @@ struct PlanDataT; - using Tasks = List; - using TaskLinks = StaticArray; + using Tasks = TaskListT; + using TaskLinks = StaticArrayT; - using TasksBounds = Array; - using TasksBits = BitArray; - using RegionBits = BitArray; + using TasksBounds = ArrayT ; + using TasksBits = BitArrayT; + using RegionBits = BitArrayT; Tasks tasks; TaskLinks taskLinks; @@ -3078,9 +2945,12 @@ struct PlanDataT> { + void clearTaskStatus (const StateID) noexcept {} + void verifyEmptyStatus(const StateID) const noexcept {} + #ifdef HFSM2_ENABLE_ASSERT - void verifyPlans() const {} + void verifyPlans() const noexcept {} #endif }; @@ -3124,12 +2997,39 @@ namespace detail { //////////////////////////////////////////////////////////////////////////////// +template +void +PlanDataT>::clearTaskStatus(const StateID stateId) noexcept { + if (stateId != INVALID_STATE_ID) { + tasksSuccesses.clear(stateId); + tasksFailures .clear(stateId); + } +} + +//------------------------------------------------------------------------------ + +template +void +PlanDataT>::verifyEmptyStatus(const StateID HFSM2_IF_ASSERT(stateId)) const noexcept { +#ifdef HFSM2_ENABLE_ASSERT + + if (stateId != INVALID_STATE_ID) { + HFSM2_ASSERT(!tasksSuccesses.get(stateId)); + HFSM2_ASSERT(!tasksFailures .get(stateId)); + } + +#endif +} + +//------------------------------------------------------------------------------ + #ifdef HFSM2_ENABLE_ASSERT template void -PlanDataT>::verifyPlans() const { +PlanDataT>::verifyPlans() const noexcept { Long planCount = 0; + for (RegionID regionId = 0; regionId < REGION_COUNT; ++regionId) planCount += verifyPlan(regionId); @@ -3140,7 +3040,7 @@ PlanDataT>::verifyPla template Long -PlanDataT>::verifyPlan(const RegionID regionId) const { +PlanDataT>::verifyPlan(const RegionID regionId) const noexcept { Long length = 0; const Bounds& bounds = tasksBounds[regionId]; @@ -3159,9 +3059,8 @@ PlanDataT>::verifyPla if (fast != INVALID_LONG) { fast = taskLinks[fast].next; - if (fast != INVALID_LONG) { + if (fast != INVALID_LONG) fast = taskLinks[fast].next; - } HFSM2_ASSERT(fast == INVALID_LONG || slow != fast); } @@ -3177,12 +3076,43 @@ PlanDataT>::verifyPla return length; } +#endif + //////////////////////////////////////////////////////////////////////////////// template void -PlanDataT>::verifyPlans() const { +PlanDataT>::clearTaskStatus(const StateID stateId) noexcept { + if (stateId != INVALID_STATE_ID) { + tasksSuccesses.clear(stateId); + tasksFailures .clear(stateId); + } +} + +//------------------------------------------------------------------------------ + +template +void +PlanDataT>::verifyEmptyStatus(const StateID HFSM2_IF_ASSERT(stateId)) const noexcept { +#ifdef HFSM2_ENABLE_ASSERT + + if (stateId != INVALID_STATE_ID) { + HFSM2_ASSERT(!tasksSuccesses.get(stateId)); + HFSM2_ASSERT(!tasksFailures .get(stateId)); + } + +#endif +} + +//------------------------------------------------------------------------------ + +#ifdef HFSM2_ENABLE_ASSERT + +template +void +PlanDataT>::verifyPlans() const noexcept { Long planCount = 0; + for (RegionID regionId = 0; regionId < REGION_COUNT; ++regionId) planCount += verifyPlan(regionId); @@ -3193,7 +3123,7 @@ PlanDataT>::verifyPl template Long -PlanDataT>::verifyPlan(const RegionID regionId) const { +PlanDataT>::verifyPlan(const RegionID regionId) const noexcept { Long length = 0; const Bounds& bounds = tasksBounds[regionId]; @@ -3212,9 +3142,8 @@ PlanDataT>::verifyPl if (fast != INVALID_LONG) { fast = taskLinks[fast].next; - if (fast != INVALID_LONG) { + if (fast != INVALID_LONG) fast = taskLinks[fast].next; - } HFSM2_ASSERT(fast == INVALID_LONG || slow != fast); } @@ -3258,11 +3187,11 @@ struct Status { bool outerTransition = false; inline Status(const Result result_ = Result::NONE, - const bool outerTransition_ = false); + const bool outerTransition_ = false) noexcept; - inline explicit operator bool() const { return result != Result::NONE || outerTransition; } + inline explicit operator bool() const noexcept { return result != Result::NONE || outerTransition; } - inline void clear(); + inline void clear() noexcept; }; #pragma pack(pop) @@ -3270,7 +3199,7 @@ struct Status { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - inline Status -combine(const Status lhs, const Status rhs) { +combine(const Status lhs, const Status rhs) noexcept { const Status::Result result = lhs.result > rhs.result ? lhs.result : rhs.result; @@ -3282,7 +3211,7 @@ combine(const Status lhs, const Status rhs) { #ifdef HFSM2_ENABLE_PLANS template -class ConstPlanT { +class CPlanT { template friend class ControlT; @@ -3309,19 +3238,19 @@ class ConstPlanT { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - struct Iterator { - HFSM2_INLINE Iterator(const ConstPlanT& plan); + struct IteratorT { + HFSM2_INLINE IteratorT(const CPlanT& plan) noexcept; - HFSM2_INLINE explicit operator bool() const; + HFSM2_INLINE explicit operator bool() const noexcept; - HFSM2_INLINE void operator ++(); + HFSM2_INLINE void operator ++() noexcept; - HFSM2_INLINE const Task& operator *() const { return _plan._planData.tasks[_curr]; } - HFSM2_INLINE const Task* operator ->() const { return &_plan._planData.tasks[_curr]; } + HFSM2_INLINE const Task& operator *() const noexcept { return _plan._planData.tasks[_curr]; } + HFSM2_INLINE const Task* operator ->() const noexcept { return &_plan._planData.tasks[_curr]; } - HFSM2_INLINE Long next() const; + HFSM2_INLINE Long next() const noexcept; - const ConstPlanT& _plan; + const CPlanT& _plan; Long _curr; Long _next; }; @@ -3329,19 +3258,19 @@ class ConstPlanT { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - private: - HFSM2_INLINE ConstPlanT(const PlanData& planData, - const RegionID regionId); + HFSM2_INLINE CPlanT(const PlanData& planData, + const RegionID regionId) noexcept; template - static constexpr StateID stateId() { return index(); } + static constexpr StateID stateId() noexcept { return index(); } template - static constexpr RegionID regionId() { return (RegionID) index(); } + static constexpr RegionID regionId() noexcept { return (RegionID) index(); } public: - HFSM2_INLINE explicit operator bool() const; + HFSM2_INLINE explicit operator bool() const noexcept; - HFSM2_INLINE Iterator first() { return Iterator{*this}; } + HFSM2_INLINE IteratorT first() noexcept { return IteratorT{*this}; } private: const PlanData& _planData; @@ -3368,22 +3297,22 @@ class PlanBaseT { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - struct Iterator { - HFSM2_INLINE Iterator(PlanBaseT& plan); + struct IteratorT { + HFSM2_INLINE IteratorT(PlanBaseT& plan) noexcept; - HFSM2_INLINE explicit operator bool() const; + HFSM2_INLINE explicit operator bool() const noexcept; - HFSM2_INLINE void operator ++(); + HFSM2_INLINE void operator ++() noexcept; - HFSM2_INLINE Task& operator *() { return _plan._planData.tasks[_curr]; } - HFSM2_INLINE const Task& operator *() const { return _plan._planData.tasks[_curr]; } + HFSM2_INLINE Task& operator *() noexcept { return _plan._planData.tasks[_curr]; } + HFSM2_INLINE const Task& operator *() const noexcept { return _plan._planData.tasks[_curr]; } - HFSM2_INLINE Task* operator ->() { return &_plan._planData.tasks[_curr]; } - HFSM2_INLINE const Task* operator ->() const { return &_plan._planData.tasks[_curr]; } + HFSM2_INLINE Task* operator ->() noexcept { return &_plan._planData.tasks[_curr]; } + HFSM2_INLINE const Task* operator ->() const noexcept { return &_plan._planData.tasks[_curr]; } - HFSM2_INLINE void remove(); + HFSM2_INLINE void remove() noexcept; - HFSM2_INLINE Long next() const; + HFSM2_INLINE Long next() const noexcept; PlanBaseT& _plan; Long _curr; @@ -3392,20 +3321,20 @@ class PlanBaseT { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - struct ConstIterator { - HFSM2_INLINE ConstIterator(const PlanBaseT& plan); + struct CIterator { + HFSM2_INLINE CIterator(const PlanBaseT& plan) noexcept; - HFSM2_INLINE explicit operator bool() const; + HFSM2_INLINE explicit operator bool() const noexcept; - HFSM2_INLINE void operator ++(); + HFSM2_INLINE void operator ++() noexcept; - HFSM2_INLINE Task& operator *() { return _plan._planData.tasks[_curr]; } - HFSM2_INLINE const Task& operator *() const { return _plan._planData.tasks[_curr]; } + HFSM2_INLINE Task& operator *() noexcept { return _plan._planData.tasks[_curr]; } + HFSM2_INLINE const Task& operator *() const noexcept { return _plan._planData.tasks[_curr]; } - HFSM2_INLINE Task* operator ->() { return &_plan._planData.tasks[_curr]; } - HFSM2_INLINE const Task* operator ->() const { return &_plan._planData.tasks[_curr]; } + HFSM2_INLINE Task* operator ->() noexcept { return &_plan._planData.tasks[_curr]; } + HFSM2_INLINE const Task* operator ->() const noexcept { return &_plan._planData.tasks[_curr]; } - HFSM2_INLINE Long next() const; + HFSM2_INLINE Long next() const noexcept; const PlanBaseT& _plan; Long _curr; @@ -3416,25 +3345,25 @@ class PlanBaseT { protected: HFSM2_INLINE PlanBaseT(PlanData& planData, - const RegionID regionId); + const RegionID regionId) noexcept; template - static constexpr StateID stateId() { return index(); } + static constexpr StateID stateId() noexcept { return index(); } template - static constexpr RegionID regionId() { return (RegionID) index(); } + static constexpr RegionID regionId() noexcept { return (RegionID) index(); } bool append(const StateID origin, const StateID destination, - const TransitionType transitionType); + const TransitionType transitionType) noexcept; - bool linkTask(const Long index); + bool linkTask(const Long index) noexcept; public: - HFSM2_INLINE explicit operator bool() const; + HFSM2_INLINE explicit operator bool() const noexcept; /// @brief Clear all tasks from the plan - HFSM2_INLINE void clear(); + HFSM2_INLINE void clear() noexcept; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -3444,7 +3373,7 @@ class PlanBaseT { /// @param destination Destination state identifier /// @return Seccess if FSM total number of tasks is below task capacity /// @note use 'Config::TaskCapacityN<>' to increase task capacity if necessary - HFSM2_INLINE bool change (const StateID origin, const StateID destination) { return append(origin, destination, TransitionType::CHANGE); } + HFSM2_INLINE bool change (const StateID origin, const StateID destination) noexcept { return append(origin, destination, TransitionType::CHANGE); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, acts depending on the region type) @@ -3453,7 +3382,7 @@ class PlanBaseT { /// @return Seccess if FSM total number of tasks is below task capacity /// @note use 'Config::TaskCapacityN<>' to increase task capacity if necessary template - HFSM2_INLINE bool change (const StateID destination) { return change (stateId(), destination); } + HFSM2_INLINE bool change (const StateID destination) noexcept { return change (stateId(), destination); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, acts depending on the region type) @@ -3462,7 +3391,7 @@ class PlanBaseT { /// @return Seccess if FSM total number of tasks is below task capacity /// @note use 'Config::TaskCapacityN<>' to increase task capacity if necessary template - HFSM2_INLINE bool change () { return change (stateId(), stateId()); } + HFSM2_INLINE bool change () noexcept { return change (stateId(), stateId()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -3472,7 +3401,7 @@ class PlanBaseT { /// @param destination Destination state identifier /// @return Seccess if FSM total number of tasks is below task capacity /// @note use 'Config::TaskCapacityN<>' to increase task capacity if necessary - HFSM2_INLINE bool restart (const StateID origin, const StateID destination) { return append(origin, destination, TransitionType::RESTART); } + HFSM2_INLINE bool restart (const StateID origin, const StateID destination) noexcept { return append(origin, destination, TransitionType::RESTART); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, activates the initial state) @@ -3481,7 +3410,7 @@ class PlanBaseT { /// @return Seccess if FSM total number of tasks is below task capacity /// @note use 'Config::TaskCapacityN<>' to increase task capacity if necessary template - HFSM2_INLINE bool restart (const StateID destination) { return restart (stateId(), destination); } + HFSM2_INLINE bool restart (const StateID destination) noexcept { return restart (stateId(), destination); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, activates the initial state) @@ -3490,7 +3419,7 @@ class PlanBaseT { /// @return Seccess if FSM total number of tasks is below task capacity /// @note use 'Config::TaskCapacityN<>' to increase task capacity if necessary template - HFSM2_INLINE bool restart () { return restart (stateId(), stateId()); } + HFSM2_INLINE bool restart () noexcept { return restart (stateId(), stateId()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -3500,7 +3429,7 @@ class PlanBaseT { /// @param destination Destination state identifier /// @return Seccess if FSM total number of tasks is below task capacity /// @note use 'Config::TaskCapacityN<>' to increase task capacity if necessary - HFSM2_INLINE bool resume (const StateID origin, const StateID destination) { return append(origin, destination, TransitionType::RESUME); } + HFSM2_INLINE bool resume (const StateID origin, const StateID destination) noexcept { return append(origin, destination, TransitionType::RESUME); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, activates the state that was active previously) @@ -3509,7 +3438,7 @@ class PlanBaseT { /// @return Seccess if FSM total number of tasks is below task capacity /// @note use 'Config::TaskCapacityN<>' to increase task capacity if necessary template - HFSM2_INLINE bool resume (const StateID destination) { return resume (stateId(), destination); } + HFSM2_INLINE bool resume (const StateID destination) noexcept { return resume (stateId(), destination); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, activates the state that was active previously) @@ -3518,7 +3447,7 @@ class PlanBaseT { /// @return Seccess if FSM total number of tasks is below task capacity /// @note use 'Config::TaskCapacityN<>' to increase task capacity if necessary template - HFSM2_INLINE bool resume () { return resume (stateId(), stateId()); } + HFSM2_INLINE bool resume () noexcept { return resume (stateId(), stateId()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -3531,7 +3460,7 @@ class PlanBaseT { /// @return Seccess if FSM total number of tasks is below task capacity /// @note use 'Config::TaskCapacityN<>' to increase task capacity if necessary /// @see HFSM2_ENABLE_UTILITY_THEORY - HFSM2_INLINE bool utilize (const StateID origin, const StateID destination) { return append(origin, destination, TransitionType::UTILIZE); } + HFSM2_INLINE bool utilize (const StateID origin, const StateID destination) noexcept { return append(origin, destination, TransitionType::UTILIZE); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, activates the state with the highest 'utility()' among those with the highest 'rank()') @@ -3541,7 +3470,7 @@ class PlanBaseT { /// @note use 'Config::TaskCapacityN<>' to increase task capacity if necessary /// @see HFSM2_ENABLE_UTILITY_THEORY template - HFSM2_INLINE bool utilize (const StateID destination) { return utilize (stateId(), destination); } + HFSM2_INLINE bool utilize (const StateID destination) noexcept { return utilize (stateId(), destination); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, activates the state with the highest 'utility()' among those with the highest 'rank()') @@ -3551,7 +3480,7 @@ class PlanBaseT { /// @note use 'Config::TaskCapacityN<>' to increase task capacity if necessary /// @see HFSM2_ENABLE_UTILITY_THEORY template - HFSM2_INLINE bool utilize () { return utilize (stateId(), stateId()); } + HFSM2_INLINE bool utilize () noexcept { return utilize (stateId(), stateId()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -3562,7 +3491,7 @@ class PlanBaseT { /// @return Seccess if FSM total number of tasks is below task capacity /// @note use 'Config::TaskCapacityN<>' to increase task capacity if necessary /// @see HFSM2_ENABLE_UTILITY_THEORY - HFSM2_INLINE bool randomize(const StateID origin, const StateID destination) { return append(origin, destination, TransitionType::RANDOMIZE); } + HFSM2_INLINE bool randomize(const StateID origin, const StateID destination) noexcept { return append(origin, destination, TransitionType::RANDOMIZE); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, uses weighted random to activate the state proportional to 'utility()' among those with the highest 'rank()') @@ -3572,7 +3501,7 @@ class PlanBaseT { /// @note use 'Config::TaskCapacityN<>' to increase task capacity if necessary /// @see HFSM2_ENABLE_UTILITY_THEORY template - HFSM2_INLINE bool randomize(const StateID destination) { return randomize(stateId(), destination); } + HFSM2_INLINE bool randomize(const StateID destination) noexcept { return randomize(stateId(), destination); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, uses weighted random to activate the state proportional to 'utility()' among those with the highest 'rank()') @@ -3582,7 +3511,7 @@ class PlanBaseT { /// @note use 'Config::TaskCapacityN<>' to increase task capacity if necessary /// @see HFSM2_ENABLE_UTILITY_THEORY template - HFSM2_INLINE bool randomize() { return randomize(stateId(), stateId()); } + HFSM2_INLINE bool randomize() noexcept { return randomize(stateId(), stateId()); } #endif @@ -3593,7 +3522,7 @@ class PlanBaseT { /// @param destination Destination state identifier /// @return Seccess if FSM total number of tasks is below task capacity /// @note use 'Config::TaskCapacityN<>' to increase task capacity if necessary - HFSM2_INLINE bool schedule (const StateID origin, const StateID destination) { return append(origin, destination, TransitionType::SCHEDULE); } + HFSM2_INLINE bool schedule (const StateID origin, const StateID destination) noexcept { return append(origin, destination, TransitionType::SCHEDULE); } /// @brief Add a task to schedule a transition to 'destination' if 'origin' completes with 'success()' /// @tparam TOrigin Origin state type @@ -3601,7 +3530,7 @@ class PlanBaseT { /// @return Seccess if FSM total number of tasks is below task capacity /// @note use 'Config::TaskCapacityN<>' to increase task capacity if necessary template - HFSM2_INLINE bool schedule (const StateID destination) { return schedule (stateId(), destination); } + HFSM2_INLINE bool schedule (const StateID destination) noexcept { return schedule (stateId(), destination); } /// @brief Add a task to schedule a transition to 'destination' if 'origin' completes with 'success()' /// @tparam TOrigin Origin state type @@ -3609,20 +3538,20 @@ class PlanBaseT { /// @return Seccess if FSM total number of tasks is below task capacity /// @note use 'Config::TaskCapacityN<>' to increase task capacity if necessary template - HFSM2_INLINE bool schedule () { return schedule (stateId(), stateId()); } + HFSM2_INLINE bool schedule () noexcept { return schedule (stateId(), stateId()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /// @brief Begin iteration over plan tasks for the current region - /// @return Iterator to the first task - HFSM2_INLINE Iterator first() { return Iterator{*this}; } + /// @return IteratorT to the first task + HFSM2_INLINE IteratorT first() noexcept { return IteratorT{*this}; } /// @brief Begin iteration over plan tasks - /// @return ConstIterator to the first task - HFSM2_INLINE ConstIterator first() const { return ConstIterator{*this}; } + /// @return CIterator to the first task + HFSM2_INLINE CIterator first() const noexcept { return CIterator{*this}; } private: - void remove(const Long task); + void remove(const Long task) noexcept; protected: PlanData& _planData; @@ -3705,12 +3634,12 @@ class PlanT' to increase task capacity if necessary - HFSM2_INLINE bool changeWith (const StateID origin, const StateID destination, const Payload& payload) { return append (origin , destination , TransitionType::CHANGE , payload ); } + HFSM2_INLINE bool changeWith (const StateID origin, const StateID destination, const Payload& payload) noexcept { return append(origin , destination , TransitionType::CHANGE , payload ); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, acts depending on the region type) @@ -3731,7 +3660,7 @@ class PlanT' to increase task capacity if necessary - HFSM2_INLINE bool changeWith (const StateID origin, const StateID destination, Payload&& payload) { return append (origin , destination , TransitionType::CHANGE , std::move(payload)); } + HFSM2_INLINE bool changeWith (const StateID origin, const StateID destination, Payload&& payload) noexcept { return append(origin , destination , TransitionType::CHANGE , std::move(payload)); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, acts depending on the region type) @@ -3741,7 +3670,7 @@ class PlanT' to increase task capacity if necessary template - HFSM2_INLINE bool changeWith ( const StateID destination, const Payload& payload) { return changeWith (PlanBase::template stateId(), destination , payload ); } + HFSM2_INLINE bool changeWith ( const StateID destination, const Payload& payload) noexcept { return append(PlanBase::template stateId(), destination , TransitionType::CHANGE , payload ); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, acts depending on the region type) @@ -3751,7 +3680,7 @@ class PlanT' to increase task capacity if necessary template - HFSM2_INLINE bool changeWith ( const StateID destination, Payload&& payload) { return changeWith (PlanBase::template stateId(), destination , std::move(payload)); } + HFSM2_INLINE bool changeWith ( const StateID destination, Payload&& payload) noexcept { return append(PlanBase::template stateId(), destination , TransitionType::CHANGE , std::move(payload)); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, acts depending on the region type) @@ -3761,7 +3690,7 @@ class PlanT' to increase task capacity if necessary template - HFSM2_INLINE bool changeWith ( const Payload& payload) { return changeWith (PlanBase::template stateId(), PlanBase::template stateId(), payload ); } + HFSM2_INLINE bool changeWith ( const Payload& payload) noexcept { return append(PlanBase::template stateId(), PlanBase::template stateId(), TransitionType::CHANGE , payload ); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, acts depending on the region type) @@ -3771,7 +3700,7 @@ class PlanT' to increase task capacity if necessary template - HFSM2_INLINE bool changeWith ( Payload&& payload) { return changeWith (PlanBase::template stateId(), PlanBase::template stateId(), std::move(payload)); } + HFSM2_INLINE bool changeWith ( Payload&& payload) noexcept { return append(PlanBase::template stateId(), PlanBase::template stateId(), TransitionType::CHANGE , std::move(payload)); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -3782,7 +3711,7 @@ class PlanT' to increase task capacity if necessary - HFSM2_INLINE bool restartWith (const StateID origin, const StateID destination, const Payload& payload) { return append (origin , destination , TransitionType::RESTART , payload ); } + HFSM2_INLINE bool restartWith (const StateID origin, const StateID destination, const Payload& payload) noexcept { return append(origin , destination , TransitionType::RESTART , payload ); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, activates the initial state) @@ -3791,7 +3720,7 @@ class PlanT' to increase task capacity if necessary - HFSM2_INLINE bool restartWith (const StateID origin, const StateID destination, Payload&& payload) { return append (origin , destination , TransitionType::RESTART , std::move(payload)); } + HFSM2_INLINE bool restartWith (const StateID origin, const StateID destination, Payload&& payload) noexcept { return append(origin , destination , TransitionType::RESTART , std::move(payload)); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, activates the initial state) @@ -3801,7 +3730,7 @@ class PlanT' to increase task capacity if necessary template - HFSM2_INLINE bool restartWith ( const StateID destination, const Payload& payload) { return restartWith (PlanBase::template stateId(), destination , payload ); } + HFSM2_INLINE bool restartWith ( const StateID destination, const Payload& payload) noexcept { return append(PlanBase::template stateId(), destination , TransitionType::RESTART , payload ); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, activates the initial state) @@ -3811,7 +3740,7 @@ class PlanT' to increase task capacity if necessary template - HFSM2_INLINE bool restartWith ( const StateID destination, Payload&& payload) { return restartWith (PlanBase::template stateId(), destination , std::move(payload)); } + HFSM2_INLINE bool restartWith ( const StateID destination, Payload&& payload) noexcept { return append(PlanBase::template stateId(), destination , TransitionType::RESTART , std::move(payload)); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, activates the initial state) @@ -3821,7 +3750,7 @@ class PlanT' to increase task capacity if necessary template - HFSM2_INLINE bool restartWith ( const Payload& payload) { return restartWith (PlanBase::template stateId(), PlanBase::template stateId(), payload ); } + HFSM2_INLINE bool restartWith ( const Payload& payload) noexcept { return append(PlanBase::template stateId(), PlanBase::template stateId(), TransitionType::RESTART , payload ); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, activates the initial state) @@ -3831,7 +3760,7 @@ class PlanT' to increase task capacity if necessary template - HFSM2_INLINE bool restartWith ( Payload&& payload) { return restartWith (PlanBase::template stateId(), PlanBase::template stateId(), std::move(payload)); } + HFSM2_INLINE bool restartWith ( Payload&& payload) noexcept { return append(PlanBase::template stateId(), PlanBase::template stateId(), TransitionType::RESTART , std::move(payload)); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -3842,7 +3771,7 @@ class PlanT' to increase task capacity if necessary - HFSM2_INLINE bool resumeWith (const StateID origin, const StateID destination, const Payload& payload) { return append (origin , destination , TransitionType::RESUME , payload ); } + HFSM2_INLINE bool resumeWith (const StateID origin, const StateID destination, const Payload& payload) noexcept { return append(origin , destination , TransitionType::RESUME , payload ); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, activates the state that was active previously) @@ -3851,7 +3780,7 @@ class PlanT' to increase task capacity if necessary - HFSM2_INLINE bool resumeWith (const StateID origin, const StateID destination, Payload&& payload) { return append (origin , destination , TransitionType::RESUME , std::move(payload)); } + HFSM2_INLINE bool resumeWith (const StateID origin, const StateID destination, Payload&& payload) noexcept { return append(origin , destination , TransitionType::RESUME , std::move(payload)); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, activates the state that was active previously) @@ -3861,7 +3790,7 @@ class PlanT' to increase task capacity if necessary template - HFSM2_INLINE bool resumeWith ( const StateID destination, const Payload& payload) { return resumeWith (PlanBase::template stateId(), destination , payload ); } + HFSM2_INLINE bool resumeWith ( const StateID destination, const Payload& payload) noexcept { return append(PlanBase::template stateId(), destination , TransitionType::RESUME , payload ); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, activates the state that was active previously) @@ -3871,7 +3800,7 @@ class PlanT' to increase task capacity if necessary template - HFSM2_INLINE bool resumeWith ( const StateID destination, Payload&& payload) { return resumeWith (PlanBase::template stateId(), destination , std::move(payload)); } + HFSM2_INLINE bool resumeWith ( const StateID destination, Payload&& payload) noexcept { return append(PlanBase::template stateId(), destination , TransitionType::RESUME , std::move(payload)); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, activates the state that was active previously) @@ -3881,7 +3810,7 @@ class PlanT' to increase task capacity if necessary template - HFSM2_INLINE bool resumeWith ( const Payload& payload) { return resumeWith (PlanBase::template stateId(), PlanBase::template stateId(), payload ); } + HFSM2_INLINE bool resumeWith ( const Payload& payload) noexcept { return append(PlanBase::template stateId(), PlanBase::template stateId(), TransitionType::RESUME , payload ); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, activates the state that was active previously) @@ -3891,7 +3820,7 @@ class PlanT' to increase task capacity if necessary template - HFSM2_INLINE bool resumeWith ( Payload&& payload) { return resumeWith (PlanBase::template stateId(), PlanBase::template stateId(), std::move(payload)); } + HFSM2_INLINE bool resumeWith ( Payload&& payload) noexcept { return append(PlanBase::template stateId(), PlanBase::template stateId(), TransitionType::RESUME , std::move(payload)); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -3905,7 +3834,7 @@ class PlanT' to increase task capacity if necessary /// @see HFSM2_ENABLE_UTILITY_THEORY - HFSM2_INLINE bool utilizeWith (const StateID origin, const StateID destination, const Payload& payload) { return append (origin , destination , TransitionType::UTILIZE , payload ); } + HFSM2_INLINE bool utilizeWith (const StateID origin, const StateID destination, const Payload& payload) noexcept { return append(origin , destination , TransitionType::UTILIZE , payload ); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, activates the state with the highest 'utility()' among those with the highest 'rank()') @@ -3915,7 +3844,7 @@ class PlanT' to increase task capacity if necessary /// @see HFSM2_ENABLE_UTILITY_THEORY - HFSM2_INLINE bool utilizeWith (const StateID origin, const StateID destination, Payload&& payload) { return append (origin , destination , TransitionType::UTILIZE , std::move(payload)); } + HFSM2_INLINE bool utilizeWith (const StateID origin, const StateID destination, Payload&& payload) noexcept { return append(origin , destination , TransitionType::UTILIZE , std::move(payload)); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, activates the state with the highest 'utility()' among those with the highest 'rank()') @@ -3926,7 +3855,7 @@ class PlanT' to increase task capacity if necessary /// @see HFSM2_ENABLE_UTILITY_THEORY template - HFSM2_INLINE bool utilizeWith ( const StateID destination, const Payload& payload) { return utilizeWith (PlanBase::template stateId(), destination , payload ); } + HFSM2_INLINE bool utilizeWith ( const StateID destination, const Payload& payload) noexcept { return append(PlanBase::template stateId(), destination , TransitionType::UTILIZE , payload ); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, activates the state with the highest 'utility()' among those with the highest 'rank()') @@ -3937,7 +3866,7 @@ class PlanT' to increase task capacity if necessary /// @see HFSM2_ENABLE_UTILITY_THEORY template - HFSM2_INLINE bool utilizeWith ( const StateID destination, Payload&& payload) { return utilizeWith (PlanBase::template stateId(), destination , std::move(payload)); } + HFSM2_INLINE bool utilizeWith ( const StateID destination, Payload&& payload) noexcept { return append(PlanBase::template stateId(), destination , TransitionType::UTILIZE , std::move(payload)); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, activates the state with the highest 'utility()' among those with the highest 'rank()') @@ -3948,7 +3877,7 @@ class PlanT' to increase task capacity if necessary /// @see HFSM2_ENABLE_UTILITY_THEORY template - HFSM2_INLINE bool utilizeWith ( const Payload& payload) { return utilizeWith (PlanBase::template stateId(), PlanBase::template stateId(), payload ); } + HFSM2_INLINE bool utilizeWith ( const Payload& payload) noexcept { return append(PlanBase::template stateId(), PlanBase::template stateId(), TransitionType::UTILIZE , payload ); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, activates the state with the highest 'utility()' among those with the highest 'rank()') @@ -3959,7 +3888,7 @@ class PlanT' to increase task capacity if necessary /// @see HFSM2_ENABLE_UTILITY_THEORY template - HFSM2_INLINE bool utilizeWith ( Payload&& payload) { return utilizeWith (PlanBase::template stateId(), PlanBase::template stateId(), std::move(payload)); } + HFSM2_INLINE bool utilizeWith ( Payload&& payload) noexcept { return append(PlanBase::template stateId(), PlanBase::template stateId(), TransitionType::UTILIZE , std::move(payload)); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -3971,7 +3900,7 @@ class PlanT' to increase task capacity if necessary /// @see HFSM2_ENABLE_UTILITY_THEORY - HFSM2_INLINE bool randomizeWith(const StateID origin, const StateID destination, const Payload& payload) { return append (origin , destination , TransitionType::RANDOMIZE, payload ); } + HFSM2_INLINE bool randomizeWith(const StateID origin, const StateID destination, const Payload& payload) noexcept { return append(origin , destination , TransitionType::RANDOMIZE, payload ); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, uses weighted random to activate the state proportional to 'utility()' among those with the highest 'rank()') @@ -3981,7 +3910,7 @@ class PlanT' to increase task capacity if necessary /// @see HFSM2_ENABLE_UTILITY_THEORY - HFSM2_INLINE bool randomizeWith(const StateID origin, const StateID destination, Payload&& payload) { return append (origin , destination , TransitionType::RANDOMIZE, std::move(payload)); } + HFSM2_INLINE bool randomizeWith(const StateID origin, const StateID destination, Payload&& payload) noexcept { return append(origin , destination , TransitionType::RANDOMIZE, std::move(payload)); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, uses weighted random to activate the state proportional to 'utility()' among those with the highest 'rank()') @@ -3992,7 +3921,7 @@ class PlanT' to increase task capacity if necessary /// @see HFSM2_ENABLE_UTILITY_THEORY template - HFSM2_INLINE bool randomizeWith( const StateID destination, const Payload& payload) { return randomizeWith(PlanBase::template stateId(), destination , payload ); } + HFSM2_INLINE bool randomizeWith( const StateID destination, const Payload& payload) noexcept { return append(PlanBase::template stateId(), destination , TransitionType::RANDOMIZE, payload ); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, uses weighted random to activate the state proportional to 'utility()' among those with the highest 'rank()') @@ -4003,7 +3932,7 @@ class PlanT' to increase task capacity if necessary /// @see HFSM2_ENABLE_UTILITY_THEORY template - HFSM2_INLINE bool randomizeWith( const StateID destination, Payload&& payload) { return randomizeWith(PlanBase::template stateId(), destination , std::move(payload)); } + HFSM2_INLINE bool randomizeWith( const StateID destination, Payload&& payload) noexcept { return append(PlanBase::template stateId(), destination , TransitionType::RANDOMIZE, std::move(payload)); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, uses weighted random to activate the state proportional to 'utility()' among those with the highest 'rank()') @@ -4014,7 +3943,7 @@ class PlanT' to increase task capacity if necessary /// @see HFSM2_ENABLE_UTILITY_THEORY template - HFSM2_INLINE bool randomizeWith( const Payload& payload) { return randomizeWith(PlanBase::template stateId(), PlanBase::template stateId(), payload ); } + HFSM2_INLINE bool randomizeWith( const Payload& payload) noexcept { return append(PlanBase::template stateId(), PlanBase::template stateId(), TransitionType::RANDOMIZE, payload ); } /// @brief Add a task to transition from 'origin' to 'destination' if 'origin' completes with 'success()' /// (if transitioning into a region, uses weighted random to activate the state proportional to 'utility()' among those with the highest 'rank()') @@ -4025,7 +3954,7 @@ class PlanT' to increase task capacity if necessary /// @see HFSM2_ENABLE_UTILITY_THEORY template - HFSM2_INLINE bool randomizeWith( Payload&& payload) { return randomizeWith(PlanBase::template stateId(), PlanBase::template stateId(), std::move(payload)); } + HFSM2_INLINE bool randomizeWith( Payload&& payload) noexcept { return append(PlanBase::template stateId(), PlanBase::template stateId(), TransitionType::RANDOMIZE, std::move(payload)); } #endif @@ -4037,7 +3966,7 @@ class PlanT' to increase task capacity if necessary - HFSM2_INLINE bool scheduleWith (const StateID origin, const StateID destination, const Payload& payload) { return append (origin , destination , TransitionType::SCHEDULE , payload ); } + HFSM2_INLINE bool scheduleWith (const StateID origin, const StateID destination, const Payload& payload) noexcept { return append(origin , destination , TransitionType::SCHEDULE , payload ); } /// @brief Add a task to schedule a transition to 'destination' if 'origin' completes with 'success()' /// @param origin Origin state identifier @@ -4045,7 +3974,7 @@ class PlanT' to increase task capacity if necessary - HFSM2_INLINE bool scheduleWith (const StateID origin, const StateID destination, Payload&& payload) { return append (origin , destination , TransitionType::SCHEDULE , std::move(payload)); } + HFSM2_INLINE bool scheduleWith (const StateID origin, const StateID destination, Payload&& payload) noexcept { return append(origin , destination , TransitionType::SCHEDULE , std::move(payload)); } /// @brief Add a task to schedule a transition to 'destination' if 'origin' completes with 'success()' /// @tparam TOrigin Origin state type @@ -4054,7 +3983,7 @@ class PlanT' to increase task capacity if necessary template - HFSM2_INLINE bool scheduleWith ( const StateID destination, const Payload& payload) { return scheduleWith (PlanBase::template stateId(), destination , payload ); } + HFSM2_INLINE bool scheduleWith ( const StateID destination, const Payload& payload) noexcept { return append(PlanBase::template stateId(), destination , TransitionType::SCHEDULE , payload ); } /// @brief Add a task to schedule a transition to 'destination' if 'origin' completes with 'success()' /// @tparam TOrigin Origin state type @@ -4063,7 +3992,7 @@ class PlanT' to increase task capacity if necessary template - HFSM2_INLINE bool scheduleWith ( const StateID destination, Payload&& payload) { return scheduleWith (PlanBase::template stateId(), destination , std::move(payload)); } + HFSM2_INLINE bool scheduleWith ( const StateID destination, Payload&& payload) noexcept { return append(PlanBase::template stateId(), destination , TransitionType::SCHEDULE , std::move(payload)); } /// @brief Add a task to schedule a transition to 'destination' if 'origin' completes with 'success()' /// @tparam TOrigin Origin state type @@ -4072,7 +4001,7 @@ class PlanT' to increase task capacity if necessary template - HFSM2_INLINE bool scheduleWith ( const Payload& payload) { return scheduleWith (PlanBase::template stateId(), PlanBase::template stateId(), payload ); } + HFSM2_INLINE bool scheduleWith ( const Payload& payload) noexcept { return append(PlanBase::template stateId(), PlanBase::template stateId(), TransitionType::SCHEDULE , payload ); } /// @brief Add a task to schedule a transition to 'destination' if 'origin' completes with 'success()' /// @tparam TOrigin Origin state type @@ -4081,7 +4010,7 @@ class PlanT' to increase task capacity if necessary template - HFSM2_INLINE bool scheduleWith ( Payload&& payload) { return scheduleWith (PlanBase::template stateId(), PlanBase::template stateId(), std::move(payload)); } + HFSM2_INLINE bool scheduleWith ( Payload&& payload) noexcept { return append(PlanBase::template stateId(), PlanBase::template stateId(), TransitionType::SCHEDULE , std::move(payload)); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -4164,7 +4093,7 @@ namespace detail { //////////////////////////////////////////////////////////////////////////////// Status::Status(const Result result_, - const bool outerTransition_) + const bool outerTransition_) noexcept : result{result_} , outerTransition{outerTransition_} {} @@ -4172,7 +4101,7 @@ Status::Status(const Result result_, //------------------------------------------------------------------------------ void -Status::clear() { +Status::clear() noexcept { result = Result::NONE; outerTransition = false; } @@ -4182,7 +4111,7 @@ Status::clear() { #ifdef HFSM2_ENABLE_PLANS template -ConstPlanT::Iterator::Iterator(const ConstPlanT& plan) +CPlanT::IteratorT::IteratorT(const CPlanT& plan) noexcept : _plan{plan} , _curr{plan._bounds.first} { @@ -4192,17 +4121,17 @@ ConstPlanT::Iterator::Iterator(const ConstPlanT& plan) //------------------------------------------------------------------------------ template -ConstPlanT::Iterator::operator bool() const { - HFSM2_ASSERT(_curr < ConstPlanT::TASK_CAPACITY || _curr == INVALID_LONG); +CPlanT::IteratorT::operator bool() const noexcept { + HFSM2_ASSERT(_curr < CPlanT::TASK_CAPACITY || _curr == INVALID_LONG); - return _curr < ConstPlanT::TASK_CAPACITY; + return _curr < CPlanT::TASK_CAPACITY; } //------------------------------------------------------------------------------ template void -ConstPlanT::Iterator::operator ++() { +CPlanT::IteratorT::operator ++() noexcept { _curr = _next; _next = next(); } @@ -4211,8 +4140,8 @@ ConstPlanT::Iterator::operator ++() { template Long -ConstPlanT::Iterator::next() const { - if (_curr < ConstPlanT::TASK_CAPACITY) { +CPlanT::IteratorT::next() const noexcept { + if (_curr < CPlanT::TASK_CAPACITY) { const TaskLink& link = _plan._planData.taskLinks[_curr]; return link.next; @@ -4226,8 +4155,8 @@ ConstPlanT::Iterator::next() const { //////////////////////////////////////////////////////////////////////////////// template -ConstPlanT::ConstPlanT(const PlanData& planData, - const RegionID regionId) +CPlanT::CPlanT(const PlanData& planData, + const RegionID regionId) noexcept : _planData{planData} , _bounds{planData.tasksBounds[regionId]} {} @@ -4235,7 +4164,7 @@ ConstPlanT::ConstPlanT(const PlanData& planData, //------------------------------------------------------------------------------ template -ConstPlanT::operator bool() const { +CPlanT::operator bool() const noexcept { if (_bounds.first < TASK_CAPACITY) { HFSM2_ASSERT(_bounds.last < TASK_CAPACITY); return true; @@ -4248,7 +4177,7 @@ ConstPlanT::operator bool() const { //////////////////////////////////////////////////////////////////////////////// template -PlanBaseT::Iterator::Iterator(PlanBaseT& plan) +PlanBaseT::IteratorT::IteratorT(PlanBaseT& plan) noexcept : _plan{plan} , _curr{plan._bounds.first} { @@ -4258,7 +4187,7 @@ PlanBaseT::Iterator::Iterator(PlanBaseT& plan) //------------------------------------------------------------------------------ template -PlanBaseT::Iterator::operator bool() const { +PlanBaseT::IteratorT::operator bool() const noexcept { HFSM2_ASSERT(_curr < PlanBaseT::TASK_CAPACITY || _curr == INVALID_LONG); return _curr < PlanBaseT::TASK_CAPACITY; @@ -4268,7 +4197,7 @@ PlanBaseT::Iterator::operator bool() const { template void -PlanBaseT::Iterator::operator ++() { +PlanBaseT::IteratorT::operator ++() noexcept { _curr = _next; _next = next(); } @@ -4277,7 +4206,7 @@ PlanBaseT::Iterator::operator ++() { template void -PlanBaseT::Iterator::remove() { +PlanBaseT::IteratorT::remove() noexcept { _plan.remove(_curr); } @@ -4285,7 +4214,7 @@ PlanBaseT::Iterator::remove() { template Long -PlanBaseT::Iterator::next() const { +PlanBaseT::IteratorT::next() const noexcept { if (_curr < PlanBaseT::TASK_CAPACITY) { const TaskLink& link = _plan._planData.taskLinks[_curr]; @@ -4300,7 +4229,7 @@ PlanBaseT::Iterator::next() const { //////////////////////////////////////////////////////////////////////////////// template -PlanBaseT::ConstIterator::ConstIterator(const PlanBaseT& plan) +PlanBaseT::CIterator::CIterator(const PlanBaseT& plan) noexcept : _plan{plan} , _curr{plan._bounds.first} { @@ -4310,7 +4239,7 @@ PlanBaseT::ConstIterator::ConstIterator(const PlanBaseT& plan) //------------------------------------------------------------------------------ template -PlanBaseT::ConstIterator::operator bool() const { +PlanBaseT::CIterator::operator bool() const noexcept { HFSM2_ASSERT(_curr < PlanBaseT::TASK_CAPACITY || _curr == INVALID_LONG); return _curr < PlanBaseT::TASK_CAPACITY; @@ -4320,7 +4249,7 @@ PlanBaseT::ConstIterator::operator bool() const { template void -PlanBaseT::ConstIterator::operator ++() { +PlanBaseT::CIterator::operator ++() noexcept { _curr = _next; _next = next(); } @@ -4329,7 +4258,7 @@ PlanBaseT::ConstIterator::operator ++() { template Long -PlanBaseT::ConstIterator::next() const { +PlanBaseT::CIterator::next() const noexcept { if (_curr < PlanBaseT::TASK_CAPACITY) { const TaskLink& link = _plan._planData.taskLinks[_curr]; @@ -4345,7 +4274,7 @@ PlanBaseT::ConstIterator::next() const { template PlanBaseT::PlanBaseT(PlanData& planData, - const RegionID regionId) + const RegionID regionId) noexcept : _planData{planData} , _regionId{regionId} , _bounds{planData.tasksBounds[regionId]} @@ -4354,7 +4283,7 @@ PlanBaseT::PlanBaseT(PlanData& planData, // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - template -PlanBaseT::operator bool() const { +PlanBaseT::operator bool() const noexcept { if (_bounds.first < TASK_CAPACITY) { HFSM2_ASSERT(_bounds.last < TASK_CAPACITY); return true; @@ -4370,7 +4299,7 @@ template bool PlanBaseT::append(const StateID origin, const StateID destination, - const TransitionType transitionType) + const TransitionType transitionType) noexcept { _planData.planExists.set(_regionId); @@ -4381,7 +4310,7 @@ PlanBaseT::append(const StateID origin, template bool -PlanBaseT::linkTask(const Long index) { +PlanBaseT::linkTask(const Long index) noexcept { if (index != Tasks::INVALID) { if (_bounds.first == INVALID_LONG) { HFSM2_ASSERT(_bounds.last == INVALID_LONG); @@ -4416,7 +4345,7 @@ PlanBaseT::linkTask(const Long index) { template void -PlanBaseT::clear() { +PlanBaseT::clear() noexcept { if (_bounds.first < TaskLinks::CAPACITY) { HFSM2_ASSERT(_bounds.last < TaskLinks::CAPACITY); @@ -4450,7 +4379,7 @@ PlanBaseT::clear() { template void -PlanBaseT::remove(const Long task) { +PlanBaseT::remove(const Long task) noexcept { HFSM2_ASSERT(_planData.planExists.get(_regionId)); HFSM2_ASSERT(_bounds.first < TaskLinks::CAPACITY); HFSM2_ASSERT(_bounds.last < TaskLinks::CAPACITY); @@ -4488,7 +4417,7 @@ bool PlanT>::append(const StateID origin, const StateID destination, const TransitionType transitionType, - const Payload& payload) + const Payload& payload) noexcept { _planData.planExists.set(_regionId); @@ -4502,7 +4431,7 @@ bool PlanT>::append(const StateID origin, const StateID destination, const TransitionType transitionType, - Payload&& payload) + Payload&& payload) noexcept { _planData.planExists.set(_regionId); @@ -4537,17 +4466,17 @@ enum Strategy { struct alignas(2 * sizeof(Short)) Parent { HFSM2_INLINE Parent() = default; - HFSM2_INLINE Parent(const ForkID forkId_) + HFSM2_INLINE Parent(const ForkID forkId_) noexcept : forkId{forkId_} {} HFSM2_INLINE Parent(const ForkID forkId_, - const Short prong_) + const Short prong_) noexcept : forkId{forkId_} , prong{prong_} {} - HFSM2_INLINE explicit operator bool() const { + HFSM2_INLINE explicit operator bool() const noexcept { return forkId != INVALID_FORK_ID && prong != INVALID_SHORT; } @@ -4624,35 +4553,35 @@ struct RegistryT; - using StateParents = StaticArray; + using StateParents = StaticArrayT; - using CompoParents = StaticArray; - using OrthoParents = StaticArray; - using OrthoUnits = StaticArray; + using CompoParents = StaticArrayT; + using OrthoParents = StaticArrayT; + using OrthoUnits = StaticArrayT; - using CompoForks = StaticArray; - using OrthoForks = BitArray ; + using CompoForks = StaticArrayT; + using OrthoForks = BitArrayT ; using OrthoBits = typename OrthoForks::Bits; - using CompoRemains = BitArray ; + using CompoRemains = BitArrayT ; using BackUp = BackUpT; - bool isActive (const StateID stateId) const; - bool isResumable (const StateID stateId) const; + bool isActive (const StateID stateId) const noexcept; + bool isResumable (const StateID stateId) const noexcept; - bool isPendingChange (const StateID stateId) const; - bool isPendingEnter (const StateID stateId) const; - bool isPendingExit (const StateID stateId) const; + bool isPendingChange (const StateID stateId) const noexcept; + bool isPendingEnter (const StateID stateId) const noexcept; + bool isPendingExit (const StateID stateId) const noexcept; - HFSM2_INLINE const Parent& forkParent(const ForkID forkId) const; + HFSM2_INLINE const Parent& forkParent(const ForkID forkId) const noexcept; - HFSM2_INLINE OrthoBits requestedOrthoFork(const ForkID forkId); + HFSM2_INLINE OrthoBits requestedOrthoFork(const ForkID forkId) noexcept; - bool requestImmediate(const Transition& request); - void requestScheduled(const StateID stateId); + bool requestImmediate(const Transition& request) noexcept; + void requestScheduled(const StateID stateId) noexcept; - void clearRequests(); - void clear(); + void clearRequests() noexcept; + void clear() noexcept; StateParents stateParents; CompoParents compoParents; @@ -4699,29 +4628,29 @@ struct RegistryT; - using StateParents = StaticArray; - using CompoParents = StaticArray; + using StateParents = StaticArrayT; + using CompoParents = StaticArrayT; - using CompoForks = StaticArray; - using OrthoForks = BitArray ; - using CompoRemains = BitArray ; + using CompoForks = StaticArrayT; + using OrthoForks = BitArrayT ; + using CompoRemains = BitArrayT ; using BackUp = BackUpT; - bool isActive (const StateID stateId) const; - bool isResumable (const StateID stateId) const; + bool isActive (const StateID stateId) const noexcept; + bool isResumable (const StateID stateId) const noexcept; - bool isPendingChange (const StateID stateId) const; - bool isPendingEnter (const StateID stateId) const; - bool isPendingExit (const StateID stateId) const; + bool isPendingChange (const StateID stateId) const noexcept; + bool isPendingEnter (const StateID stateId) const noexcept; + bool isPendingExit (const StateID stateId) const noexcept; - HFSM2_INLINE const Parent& forkParent(const ForkID forkId) const; + HFSM2_INLINE const Parent& forkParent(const ForkID forkId) const noexcept; - bool requestImmediate(const Transition& request); - void requestScheduled(const StateID stateId); + bool requestImmediate(const Transition& request) noexcept; + void requestScheduled(const StateID stateId) noexcept; - void clearRequests(); - void clear(); + void clearRequests() noexcept; + void clear() noexcept; StateParents stateParents; CompoParents compoParents; @@ -4739,7 +4668,7 @@ struct RegistryT void backup(const TRegistry& registry, - BackUpT& copy) + BackUpT& copy) noexcept { overwrite(copy.compoRequested, registry.compoRequested); overwrite(copy.orthoRequested, registry.orthoRequested); @@ -4751,7 +4680,7 @@ backup(const TRegistry& registry, template void restore(TRegistry& registry, - const BackUpT& copy) + const BackUpT& copy) noexcept { overwrite(registry.compoRequested, copy.compoRequested); overwrite(registry.orthoRequested, copy.orthoRequested); @@ -4770,7 +4699,7 @@ namespace detail { template bool -RegistryT>::isActive(const StateID stateId) const { +RegistryT>::isActive(const StateID stateId) const noexcept { if (HFSM2_CHECKED(stateId < STATE_COUNT)) for (Parent parent = stateParents[stateId]; parent; @@ -4789,7 +4718,7 @@ RegistryT bool -RegistryT>::isResumable(const StateID stateId) const { +RegistryT>::isResumable(const StateID stateId) const noexcept { if (HFSM2_CHECKED(stateId < STATE_COUNT)) for (Parent parent = stateParents[stateId]; parent; @@ -4808,7 +4737,7 @@ RegistryT bool -RegistryT>::isPendingChange(const StateID stateId) const { +RegistryT>::isPendingChange(const StateID stateId) const noexcept { if (HFSM2_CHECKED(stateId < STATE_COUNT)) for (Parent parent = stateParents[stateId]; parent; @@ -4828,7 +4757,7 @@ RegistryT bool -RegistryT>::isPendingEnter(const StateID stateId) const { +RegistryT>::isPendingEnter(const StateID stateId) const noexcept { if (HFSM2_CHECKED(stateId < STATE_COUNT)) for (Parent parent = stateParents[stateId]; parent; @@ -4848,7 +4777,7 @@ RegistryT bool -RegistryT>::isPendingExit(const StateID stateId) const { +RegistryT>::isPendingExit(const StateID stateId) const noexcept { if (HFSM2_CHECKED(stateId < STATE_COUNT)) for (Parent parent = stateParents[stateId]; parent; @@ -4868,7 +4797,7 @@ RegistryT const Parent& -RegistryT>::forkParent(const ForkID forkId) const { +RegistryT>::forkParent(const ForkID forkId) const noexcept { HFSM2_ASSERT(forkId != 0); return forkId > 0 ? @@ -4880,7 +4809,7 @@ RegistryT typename RegistryT>::OrthoBits -RegistryT>::requestedOrthoFork(const ForkID forkId) { +RegistryT>::requestedOrthoFork(const ForkID forkId) noexcept { HFSM2_ASSERT(forkId < 0); const Units& units = orthoUnits[-forkId - 1]; @@ -4891,7 +4820,7 @@ RegistryT bool -RegistryT>::requestImmediate(const Transition& request) { +RegistryT>::requestImmediate(const Transition& request) noexcept { if (request.destination == 0) return false; else if (HFSM2_CHECKED(request.destination < STATE_COUNT)) { @@ -4945,7 +4874,7 @@ RegistryT void -RegistryT>::requestScheduled(const StateID stateId) { +RegistryT>::requestScheduled(const StateID stateId) noexcept { if (HFSM2_CHECKED(stateId < STATE_COUNT)) { const Parent parent = stateParents[stateId]; @@ -4959,7 +4888,7 @@ RegistryT void -RegistryT>::clearRequests() { +RegistryT>::clearRequests() noexcept { compoRequested.clear(); orthoRequested.clear(); compoRemains .clear(); @@ -4969,7 +4898,7 @@ RegistryT void -RegistryT>::clear() { +RegistryT>::clear() noexcept { clearRequests(); compoActive .clear(); @@ -4987,7 +4916,7 @@ namespace detail { template bool -RegistryT>::isActive(const StateID stateId) const { +RegistryT>::isActive(const StateID stateId) const noexcept { if (HFSM2_CHECKED(stateId < STATE_COUNT)) { if (Parent parent = stateParents[stateId]) { HFSM2_ASSERT(parent.forkId > 0); @@ -5004,7 +4933,7 @@ RegistryT bool -RegistryT>::isResumable(const StateID stateId) const { +RegistryT>::isResumable(const StateID stateId) const noexcept { if (HFSM2_CHECKED(stateId < STATE_COUNT)) if (Parent parent = stateParents[stateId]) { HFSM2_ASSERT(parent.forkId > 0); @@ -5019,7 +4948,7 @@ RegistryT bool -RegistryT>::isPendingChange(const StateID stateId) const { +RegistryT>::isPendingChange(const StateID stateId) const noexcept { if (HFSM2_CHECKED(stateId < STATE_COUNT)) if (Parent parent = stateParents[stateId]) { HFSM2_ASSERT(parent.forkId > 0); @@ -5035,7 +4964,7 @@ RegistryT bool -RegistryT>::isPendingEnter(const StateID stateId) const { +RegistryT>::isPendingEnter(const StateID stateId) const noexcept { if (HFSM2_CHECKED(stateId < STATE_COUNT)) if (Parent parent = stateParents[stateId]) { HFSM2_ASSERT(parent.forkId > 0); @@ -5051,7 +4980,7 @@ RegistryT bool -RegistryT>::isPendingExit(const StateID stateId) const { +RegistryT>::isPendingExit(const StateID stateId) const noexcept { if (HFSM2_CHECKED(stateId < STATE_COUNT)) if (Parent parent = stateParents[stateId]) { HFSM2_ASSERT(parent.forkId > 0); @@ -5067,7 +4996,7 @@ RegistryT const Parent& -RegistryT>::forkParent(const ForkID forkId) const { +RegistryT>::forkParent(const ForkID forkId) const noexcept { HFSM2_ASSERT(forkId > 0); return compoParents[forkId - 1]; @@ -5077,7 +5006,7 @@ RegistryT bool -RegistryT>::requestImmediate(const Transition& request) { +RegistryT>::requestImmediate(const Transition& request) noexcept { // record request // promote it to all children @@ -5120,7 +5049,7 @@ RegistryT void -RegistryT>::requestScheduled(const StateID stateId) { +RegistryT>::requestScheduled(const StateID stateId) noexcept { if (HFSM2_CHECKED(stateId < STATE_COUNT)) { const Parent parent = stateParents[stateId]; @@ -5133,7 +5062,7 @@ RegistryT void -RegistryT>::clearRequests() { +RegistryT>::clearRequests() noexcept { compoRequested.clear(); orthoRequested.clear(); compoRemains .clear(); @@ -5143,7 +5072,7 @@ RegistryT void -RegistryT>::clear() { +RegistryT>::clear() noexcept { clearRequests(); compoActive .clear(); @@ -5183,11 +5112,11 @@ class ControlT { using Payload = typename TArgs::Payload; using Transition = TransitionT; - using TransitionSet = Array; - using TransitionSets = Array; + using TransitionSet = ArrayT; + using TransitionSets = ArrayT; #ifdef HFSM2_ENABLE_TRANSITION_HISTORY - using TransitionTargets = StaticArray; + using TransitionTargets = StaticArrayT; #endif #ifdef HFSM2_ENABLE_UTILITY_THEORY @@ -5196,7 +5125,7 @@ class ControlT { #ifdef HFSM2_ENABLE_PLANS using PlanData = PlanDataT; - using ConstPlan = ConstPlanT; + using CPlan = CPlanT; #endif #ifdef HFSM2_ENABLE_LOG_INTERFACE @@ -5207,9 +5136,9 @@ class ControlT { struct Origin { HFSM2_INLINE Origin(ControlT& control_, - const StateID stateId); + const StateID stateId) noexcept; - HFSM2_INLINE ~Origin(); + HFSM2_INLINE ~Origin() noexcept; ControlT& control; const StateID prevId; @@ -5219,9 +5148,9 @@ class ControlT { struct Region { HFSM2_INLINE Region(ControlT& control, - const RegionID regionId); + const RegionID regionId) noexcept; - HFSM2_INLINE ~Region(); + HFSM2_INLINE ~Region() noexcept; ControlT& control; const RegionID prevId; @@ -5236,7 +5165,7 @@ class ControlT { HFSM2_IF_PLANS(, PlanData& planData) HFSM2_IF_TRANSITION_HISTORY(, TransitionTargets& transitionTargets) HFSM2_IF_TRANSITION_HISTORY(, const TransitionSets& previousTransitions) - HFSM2_IF_LOG_INTERFACE(, Logger* const logger)) + HFSM2_IF_LOG_INTERFACE(, Logger* const logger)) noexcept : _context{context} , _registry{registry} , _requests{requests} @@ -5247,14 +5176,14 @@ class ControlT { HFSM2_IF_LOG_INTERFACE(, _logger{logger}) {} - HFSM2_INLINE void setOrigin (const StateID stateId); - HFSM2_INLINE void resetOrigin(const StateID stateId); + HFSM2_INLINE void setOrigin (const StateID stateId) noexcept; + HFSM2_INLINE void resetOrigin(const StateID stateId) noexcept; - HFSM2_INLINE void setRegion (const RegionID regionId); - HFSM2_INLINE void resetRegion(const RegionID regionId); + HFSM2_INLINE void setRegion (const RegionID regionId) noexcept; + HFSM2_INLINE void resetRegion(const RegionID regionId) noexcept; #ifdef HFSM2_ENABLE_TRANSITION_HISTORY - HFSM2_INLINE void pinLastTransition(const StateID stateId, const Short index); + HFSM2_INLINE void pinLastTransition(const StateID stateId, const Short index) noexcept; #endif public: @@ -5263,78 +5192,78 @@ class ControlT { /// @tparam TState State type /// @return Numeric state identifier template - static constexpr StateID stateId() { return index(); } + static constexpr StateID stateId() noexcept { return index(); } /// @brief Get region identifier for a region type /// @tparam TState Region head state type /// @return Numeric region identifier template - static constexpr RegionID regionId() { return (RegionID) index(); } + static constexpr RegionID regionId() noexcept { return (RegionID) index(); } /// @brief Access FSM context (data shared between states and/or data interface between FSM and external code) /// @return context /// @see Control::context() - HFSM2_INLINE Context& _() { return _context; } + HFSM2_INLINE Context& _() noexcept { return _context; } /// @brief Access FSM context (data shared between states and/or data interface between FSM and external code) /// @return context /// @see Control::context() - HFSM2_INLINE const Context& _() const { return _context; } + HFSM2_INLINE const Context& _() const noexcept { return _context; } /// @brief Access FSM context (data shared between states and/or data interface between FSM and external code) /// @return context /// @see Control::_() - HFSM2_INLINE Context& context() { return _context; } + HFSM2_INLINE Context& context() noexcept { return _context; } /// @brief Access FSM context (data shared between states and/or data interface between FSM and external code) /// @return context /// @see Control::_() - HFSM2_INLINE const Context& context() const { return _context; } + HFSM2_INLINE const Context& context() const noexcept { return _context; } //---------------------------------------------------------------------- /// @brief Inspect current transition requests /// @return Array of transition requests - HFSM2_INLINE const TransitionSet& requests() const { return _requests; } + HFSM2_INLINE const TransitionSet& requests() const noexcept { return _requests; } //---------------------------------------------------------------------- /// @brief Check if a state is active /// @param stateId State identifier /// @return State active status - HFSM2_INLINE bool isActive (const StateID stateId) const { return _registry.isActive (stateId); } + HFSM2_INLINE bool isActive (const StateID stateId) const noexcept { return _registry.isActive (stateId); } /// @brief Check if a state is active /// @tparam TState State type /// @return State active status template - HFSM2_INLINE bool isActive () const { return isActive (stateId()); } + HFSM2_INLINE bool isActive () const noexcept { return isActive (stateId()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /// @brief Check if a state is resumable (activated then deactivated previously) /// @param stateId State identifier /// @return State resumable status - HFSM2_INLINE bool isResumable(const StateID stateId) const { return _registry.isResumable(stateId); } + HFSM2_INLINE bool isResumable(const StateID stateId) const noexcept { return _registry.isResumable(stateId); } /// @brief Check if a state is resumable (activated then deactivated previously) /// @tparam TState State type /// @return State resumable status template - HFSM2_INLINE bool isResumable() const { return isResumable(stateId()); } + HFSM2_INLINE bool isResumable() const noexcept { return isResumable(stateId()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /// @brief Check if a state is scheduled to activate on the next transition to parent region /// @param stateId State identifier /// @return State scheduled status - HFSM2_INLINE bool isScheduled(const StateID stateId) const { return isResumable(stateId); } + HFSM2_INLINE bool isScheduled(const StateID stateId) const noexcept { return isResumable(stateId); } /// @brief Check if a state is scheduled to activate on the next transition to parent region /// @tparam TState State type /// @return State scheduled status template - HFSM2_INLINE bool isScheduled() const { return isResumable(stateId()); } + HFSM2_INLINE bool isScheduled() const noexcept { return isResumable(stateId()); } //---------------------------------------------------------------------- @@ -5342,24 +5271,24 @@ class ControlT { /// @brief Access read-only plan for the current region /// @return Plan for the current region - HFSM2_INLINE ConstPlan plan() const { return ConstPlan{_planData, _regionId}; } + HFSM2_INLINE CPlan plan() const noexcept { return CPlan{_planData, _regionId}; } /// @brief Access read-only plan for a region /// @param regionId Region identifier /// @return Read-only plan for the region - HFSM2_INLINE ConstPlan plan(const RegionID regionId) const { return ConstPlan{_planData, regionId}; } + HFSM2_INLINE CPlan plan(const RegionID regionId) const noexcept { return CPlan{_planData, regionId}; } /// @brief Access read-only plan for a region /// @tparam TRegion Region head state type /// @return Read-only plan for the region template - HFSM2_INLINE ConstPlan plan() { return ConstPlan{_planData, regionId()}; } + HFSM2_INLINE CPlan plan() noexcept { return CPlan{_planData, regionId()}; } /// @brief Access read-only plan for a region /// @tparam TRegion Region head state type /// @return Read-only Plan for the region template - HFSM2_INLINE ConstPlan plan() const { return ConstPlan{_planData, regionId()}; } + HFSM2_INLINE CPlan plan() const noexcept { return CPlan{_planData, regionId()}; } #endif @@ -5369,24 +5298,24 @@ class ControlT { /// @brief Get transitions processed during last 'update()', 'react()' or 'replayTransitions()' /// @return Array of last transition requests - HFSM2_INLINE const TransitionSets& previousTransitions() const { return _previousTransitions; } + HFSM2_INLINE const TransitionSets& previousTransitions() const noexcept { return _previousTransitions; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /// @brief Get the last transition that caused the state to be activated /// @param stateId State identifier /// @return Pointer to the last transition that activated the state - const Transition* lastTransition(const StateID stateId) const; + const Transition* lastTransition(const StateID stateId) const noexcept; /// @brief Get the last transition that caused the state to be activated /// @tparam TState State type /// @return Pointer to the last transition that activated the state template - const Transition* lastTransition() const { return lastTransition(stateId()); } + const Transition* lastTransition() const noexcept { return lastTransition(stateId()); } /// @brief Get the last transition that caused the current state to be activated /// @return Pointer to the last transition that activated the current state - const Transition* lastTransition() const; + const Transition* lastTransition() const noexcept; #endif @@ -5394,7 +5323,7 @@ class ControlT { protected: #ifdef HFSM2_ENABLE_LOG_INTERFACE - HFSM2_INLINE Logger* logger() { return _logger; } + HFSM2_INLINE Logger* logger() noexcept { return _logger; } #endif protected: @@ -5436,7 +5365,7 @@ class PlanControlT #ifdef HFSM2_ENABLE_PLANS using typename Control::PlanData; - using typename Control::ConstPlan; + using typename Control::CPlan; using Plan = PlanT; #endif @@ -5447,9 +5376,9 @@ class PlanControlT HFSM2_INLINE Region(PlanControlT& control, const RegionID regionId, const StateID index, - const Long size); + const Long size) noexcept; - HFSM2_INLINE ~Region(); + HFSM2_INLINE ~Region() noexcept; PlanControlT& control; const RegionID prevId; @@ -5461,43 +5390,50 @@ class PlanControlT using Control::Control; - HFSM2_INLINE void setRegion (const RegionID regionId, const StateID index, const Long size); - HFSM2_INLINE void resetRegion(const RegionID regionId, const StateID index, const Long size); + HFSM2_INLINE void setRegion(const RegionID regionId, const StateID index, const Long size) noexcept; + HFSM2_INLINE void resetRegion(const RegionID regionId, const StateID index, const Long size) noexcept; public: // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #ifdef HFSM2_ENABLE_PLANS +// COMMON /// @brief Access plan for the current region /// @return Plan for the current region - HFSM2_INLINE Plan plan() { return Plan{_planData, _regionId}; } + HFSM2_INLINE Plan plan() noexcept { return Plan{_planData, _regionId}; } + +// COMMON /// @brief Access plan for a region /// @param regionId /// @return Plan for the region - HFSM2_INLINE Plan plan(const RegionID regionId) { return Plan{_planData, regionId}; } + HFSM2_INLINE Plan plan(const RegionID regionId) noexcept { return Plan{_planData, regionId}; } /// @brief Access plan for a region /// @tparam TRegion Region head state type /// @return Plan for the region template - HFSM2_INLINE Plan plan() { return Plan{_planData, Control::template regionId()}; } + HFSM2_INLINE Plan plan() noexcept { return Plan{_planData, Control::template regionId()}; } + +// COMMON /// @brief Access plan for the current region /// @return Plan for the current region - HFSM2_INLINE ConstPlan plan() const { return ConstPlan{_planData, _regionId}; } + HFSM2_INLINE CPlan plan() const noexcept { return CPlan{_planData, _regionId}; } + +// COMMON /// @brief Access plan for a region /// @param regionId /// @return Plan for the region - HFSM2_INLINE ConstPlan plan(const RegionID regionId) const { return ConstPlan{_planData, regionId}; } + HFSM2_INLINE CPlan plan(const RegionID regionId) const noexcept { return CPlan{_planData, regionId}; } /// @brief Access plan for a region /// @tparam TRegion Region head state type /// @return Plan for the region template - HFSM2_INLINE ConstPlan plan() const { return ConstPlan{_planData, Control::template regionId()}; } + HFSM2_INLINE CPlan plan() const noexcept { return CPlan{_planData, Control::template regionId()}; } #endif @@ -5540,14 +5476,14 @@ class FullControlBaseT using typename PlanControl::Transition; #ifdef HFSM2_ENABLE_PLANS - using TasksBits = BitArray; + using TasksBits = BitArrayT; #endif // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - struct Lock { - HFSM2_INLINE Lock(FullControlBaseT& control_); - HFSM2_INLINE ~Lock(); + HFSM2_INLINE Lock(FullControlBaseT& control_) noexcept; + HFSM2_INLINE ~Lock() noexcept; FullControlBaseT* const control; }; @@ -5559,7 +5495,7 @@ class FullControlBaseT #ifdef HFSM2_ENABLE_PLANS template - Status buildPlanStatus(); + Status buildPlanStatus() noexcept; #endif @@ -5567,38 +5503,39 @@ class FullControlBaseT using PlanControl::context; //---------------------------------------------------------------------- - // Clang trips over 'stateId<>()', so give it a hint it comes from PlanControl + // COMMON /// @brief Transition into a state (if transitioning into a region, acts depending on the region type) /// @param stateId State identifier - HFSM2_INLINE void changeTo (const StateID stateId); + HFSM2_INLINE void changeTo (const StateID stateId) noexcept; /// @brief Transition into a state (if transitioning into a region, acts depending on the region type) /// @tparam TState State type template - HFSM2_INLINE void changeTo () { changeTo (PlanControl::template stateId()); } + HFSM2_INLINE void changeTo () noexcept { changeTo (PlanControl::template stateId()); } + // COMMON // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /// @brief Transition into a state (if transitioning into a region, activates the initial state) /// @param stateId State identifier - HFSM2_INLINE void restart (const StateID stateId); + HFSM2_INLINE void restart (const StateID stateId) noexcept; /// @brief Transition into a state (if transitioning into a region, activates the initial state) /// @tparam TState State type template - HFSM2_INLINE void restart () { restart (PlanControl::template stateId()); } + HFSM2_INLINE void restart () noexcept { restart (PlanControl::template stateId()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /// @brief Transition into a state (if transitioning into a region, activates the state that was active previously) /// @param stateId State identifier - HFSM2_INLINE void resume (const StateID stateId); + HFSM2_INLINE void resume (const StateID stateId) noexcept; /// @brief Transition into a state (if transitioning into a region, activates the state that was active previously) /// @tparam TState State type template - HFSM2_INLINE void resume () { resume (PlanControl::template stateId()); } + HFSM2_INLINE void resume () noexcept { resume (PlanControl::template stateId()); } //---------------------------------------------------------------------- @@ -5608,14 +5545,14 @@ class FullControlBaseT /// with the highest 'utility()' among those with the highest 'rank()') /// @param stateId State identifier /// @see HFSM2_ENABLE_UTILITY_THEORY - HFSM2_INLINE void utilize (const StateID stateId); + HFSM2_INLINE void utilize (const StateID stateId) noexcept; /// @brief Transition into a state (if transitioning into a region, activates the state /// with the highest 'utility()' among those with the highest 'rank()') /// @tparam TState State type /// @see HFSM2_ENABLE_UTILITY_THEORY template - HFSM2_INLINE void utilize () { utilize (PlanControl::template stateId()); } + HFSM2_INLINE void utilize () noexcept { utilize (PlanControl::template stateId()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -5623,14 +5560,14 @@ class FullControlBaseT /// proportional to 'utility()' among those with the highest 'rank()') /// @param stateId State identifier /// @see HFSM2_ENABLE_UTILITY_THEORY - HFSM2_INLINE void randomize(const StateID stateId); + HFSM2_INLINE void randomize(const StateID stateId) noexcept; /// @brief Transition into a state (if transitioning into a region, uses weighted random to activate the state /// proportional to 'utility()' among those with the highest 'rank()') /// @tparam TState State type /// @see HFSM2_ENABLE_UTILITY_THEORY template - HFSM2_INLINE void randomize() { randomize(PlanControl::template stateId()); } + HFSM2_INLINE void randomize() noexcept { randomize(PlanControl::template stateId()); } #endif @@ -5638,22 +5575,22 @@ class FullControlBaseT /// @brief Schedule a state to be activated when its parent region is activated /// @param stateId State identifier - HFSM2_INLINE void schedule (const StateID stateId); + HFSM2_INLINE void schedule (const StateID stateId) noexcept; /// @brief Schedule a state to be activated when its parent region is activated /// @tparam TState State type template - HFSM2_INLINE void schedule () { schedule (PlanControl::template stateId()); } + HFSM2_INLINE void schedule () noexcept { schedule (PlanControl::template stateId()); } //---------------------------------------------------------------------- #ifdef HFSM2_ENABLE_PLANS /// @brief Succeed a plan task for the current state - HFSM2_INLINE void succeed(); + HFSM2_INLINE void succeed() noexcept; /// @brief Fail a plan task for the current state - HFSM2_INLINE void fail(); + HFSM2_INLINE void fail() noexcept; #endif @@ -5758,7 +5695,7 @@ class FullControlT - Status updatePlan(TState& headState, const Status subStatus); + Status updatePlan(TState& headState, const Status subStatus) noexcept; #endif @@ -5771,56 +5708,58 @@ class FullControlT - HFSM2_INLINE void changeWith (const Payload& payload) { changeWith (FullControlBase::template stateId(), payload ); } + HFSM2_INLINE void changeWith (const Payload& payload) noexcept { changeWith (FullControlBase::template stateId(), payload ); } /// @brief Transition into a state (if transitioning into a region, acts depending on the region type) /// @tparam TState Destination state type /// @param payload Payload template - HFSM2_INLINE void changeWith ( Payload&& payload) { changeWith (FullControlBase::template stateId(), std::move(payload)); } + HFSM2_INLINE void changeWith ( Payload&& payload) noexcept { changeWith (FullControlBase::template stateId(), std::move(payload)); } + // COMMON // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /// @brief Transition into a state (if transitioning into a region, activates the initial state) /// @param stateId Destination state identifier /// @param payload Payload HFSM2_INLINE void restartWith (const StateID stateId, - const Payload& payload); + const Payload& payload) noexcept; /// @brief Transition into a state (if transitioning into a region, activates the initial state) /// @param stateId Destination state identifier /// @param payload Payload HFSM2_INLINE void restartWith (const StateID stateId, - Payload&& payload); + Payload&& payload) noexcept; /// @brief Transition into a state (if transitioning into a region, activates the initial state) /// @tparam TState Destination state type /// @param payload Payload template - HFSM2_INLINE void restartWith (const Payload& payload) { restartWith (FullControlBase::template stateId(), payload ); } + HFSM2_INLINE void restartWith (const Payload& payload) noexcept { restartWith (FullControlBase::template stateId(), payload ); } /// @brief Transition into a state (if transitioning into a region, activates the initial state) /// @tparam TState Destination state type /// @param payload Payload template - HFSM2_INLINE void restartWith ( Payload&& payload) { restartWith (FullControlBase::template stateId(), std::move(payload)); } + HFSM2_INLINE void restartWith ( Payload&& payload) noexcept { restartWith (FullControlBase::template stateId(), std::move(payload)); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -5828,25 +5767,25 @@ class FullControlT - HFSM2_INLINE void resumeWith (const Payload& payload) { resumeWith (FullControlBase::template stateId(), payload ); } + HFSM2_INLINE void resumeWith (const Payload& payload) noexcept { resumeWith (FullControlBase::template stateId(), payload ); } /// @brief Transition into a state (if transitioning into a region, activates the state that was active previously) /// @tparam TState Destination state type /// @param payload Payload template - HFSM2_INLINE void resumeWith ( Payload&& payload) { resumeWith (FullControlBase::template stateId(), std::move(payload)); } + HFSM2_INLINE void resumeWith ( Payload&& payload) noexcept { resumeWith (FullControlBase::template stateId(), std::move(payload)); } //------------------------------------------------------------------------------ @@ -5858,7 +5797,7 @@ class FullControlT - HFSM2_INLINE void utilizeWith (const Payload& payload) { utilizeWith (FullControlBase::template stateId(), payload ); } + HFSM2_INLINE void utilizeWith (const Payload& payload) noexcept { utilizeWith (FullControlBase::template stateId(), payload ); } /// @brief Transition into a state (if transitioning into a region, activates the state /// with the highest 'utility()' among those with the highest 'rank()') @@ -5882,7 +5821,7 @@ class FullControlT - HFSM2_INLINE void utilizeWith ( Payload&& payload) { utilizeWith (FullControlBase::template stateId(), std::move(payload)); } + HFSM2_INLINE void utilizeWith ( Payload&& payload) noexcept { utilizeWith (FullControlBase::template stateId(), std::move(payload)); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -5892,7 +5831,7 @@ class FullControlT - HFSM2_INLINE void randomizeWith(const Payload& payload) { randomizeWith(FullControlBase::template stateId(), payload ); } + HFSM2_INLINE void randomizeWith(const Payload& payload) noexcept { randomizeWith(FullControlBase::template stateId(), payload ); } /// @brief Transition into a state (if transitioning into a region, uses weighted random to activate the state /// proportional to 'utility()' among those with the highest 'rank()') @@ -5916,7 +5855,7 @@ class FullControlT - HFSM2_INLINE void randomizeWith( Payload&& payload) { randomizeWith(FullControlBase::template stateId(), std::move(payload)); } + HFSM2_INLINE void randomizeWith( Payload&& payload) noexcept { randomizeWith(FullControlBase::template stateId(), std::move(payload)); } #endif @@ -5926,25 +5865,25 @@ class FullControlT - HFSM2_INLINE void scheduleWith (const Payload& payload) { scheduleWith (FullControlBase::template stateId(), payload ); } + HFSM2_INLINE void scheduleWith (const Payload& payload) noexcept { scheduleWith (FullControlBase::template stateId(), payload ); } /// @brief Schedule a state to be activated when its parent region is activated /// @tparam TState Destination state type /// @param payload Payload template - HFSM2_INLINE void scheduleWith ( Payload&& payload) { scheduleWith (FullControlBase::template stateId(), std::move(payload)); } + HFSM2_INLINE void scheduleWith ( Payload&& payload) noexcept { scheduleWith (FullControlBase::template stateId(), std::move(payload)); } //------------------------------------------------------------------------------ @@ -6038,7 +5977,7 @@ class FullControlT - Status updatePlan(TState& headState, const Status subStatus); + Status updatePlan(TState& headState, const Status subStatus) noexcept; #endif @@ -6102,7 +6041,7 @@ class GuardControlT final HFSM2_IF_PLANS(, PlanData& planData) HFSM2_IF_TRANSITION_HISTORY(, TransitionTargets& transitionTargets) HFSM2_IF_TRANSITION_HISTORY(, const TransitionSets& previousTransitions) - HFSM2_IF_LOG_INTERFACE(, Logger* const logger)) + HFSM2_IF_LOG_INTERFACE(, Logger* const logger)) noexcept : FullControl{context , registry , requests @@ -6125,51 +6064,51 @@ class GuardControlT final /// @brief Check if a state is going to be activated or deactivated /// @param stateId State identifier /// @return State pending activation/deactivation status - HFSM2_INLINE bool isPendingChange(const StateID stateId) const { return _registry.isPendingChange(stateId); } + HFSM2_INLINE bool isPendingChange(const StateID stateId) const noexcept { return _registry.isPendingChange(stateId); } /// @brief Check if a state is going to be activated or deactivated /// @tparam TState State type /// @return State pending activation/deactivation status template - HFSM2_INLINE bool isPendingChange() { return isPendingChange(FullControl::template stateId()); } + HFSM2_INLINE bool isPendingChange() const noexcept { return isPendingChange(FullControl::template stateId()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /// @brief Check if a state is going to be activated /// @param stateId State identifier /// @return State pending activation status - HFSM2_INLINE bool isPendingEnter (const StateID stateId) const { return _registry.isPendingEnter (stateId); } + HFSM2_INLINE bool isPendingEnter (const StateID stateId) const noexcept { return _registry.isPendingEnter (stateId); } /// @brief Check if a state is going to be activated /// @tparam TState State type /// @return State pending activation status template - HFSM2_INLINE bool isPendingEnter () { return isPendingEnter (FullControl::template stateId()); } + HFSM2_INLINE bool isPendingEnter () const noexcept { return isPendingEnter (FullControl::template stateId()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /// @brief Check if a state is going to be deactivated /// @param stateId State identifier /// @return State pending deactivation status - HFSM2_INLINE bool isPendingExit (const StateID stateId) const { return _registry.isPendingExit (stateId); } + HFSM2_INLINE bool isPendingExit (const StateID stateId) const noexcept { return _registry.isPendingExit (stateId); } /// @brief Check if a state is going to be deactivated /// @tparam TState State type /// @return State pending deactivation status template - HFSM2_INLINE bool isPendingExit () { return isPendingExit (FullControl::template stateId()); } + HFSM2_INLINE bool isPendingExit () const noexcept { return isPendingExit (FullControl::template stateId()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE const TransitionSets& currentTransitions() const { return _currentTransitions; } + HFSM2_INLINE const TransitionSets& currentTransitions() const noexcept { return _currentTransitions; } /// @brief Get pending transition requests /// @return Array of pending transition requests - HFSM2_INLINE const TransitionSet& pendingTransitions() const { return _pendingTransitions; } + HFSM2_INLINE const TransitionSet& pendingTransitions() const noexcept { return _pendingTransitions; } /// @brief Cancel pending transition requests /// (can be used to substitute a transition into the current state with a different one) - HFSM2_INLINE void cancelPendingTransitions(); + HFSM2_INLINE void cancelPendingTransitions() noexcept; private: using FullControl::_registry; @@ -6191,10 +6130,11 @@ namespace hfsm2 { namespace detail { //////////////////////////////////////////////////////////////////////////////// +// COMMON template ControlT::Origin::Origin(ControlT& control_, - const StateID stateId) + const StateID stateId) noexcept : control{control_} , prevId{control._originId} { @@ -6204,15 +6144,16 @@ ControlT::Origin::Origin(ControlT& control_, //------------------------------------------------------------------------------ template -ControlT::Origin::~Origin() { +ControlT::Origin::~Origin() noexcept { control.resetOrigin(prevId); } +// COMMON //////////////////////////////////////////////////////////////////////////////// template ControlT::Region::Region(ControlT& control_, - const RegionID regionId) + const RegionID regionId) noexcept : control{control_} , prevId{control._regionId} { @@ -6222,7 +6163,7 @@ ControlT::Region::Region(ControlT& control_, //------------------------------------------------------------------------------ template -ControlT::Region::~Region() { +ControlT::Region::~Region() noexcept { control.resetRegion(prevId); } @@ -6230,7 +6171,7 @@ ControlT::Region::~Region() { template void -ControlT::setOrigin(const StateID stateId) { +ControlT::setOrigin(const StateID stateId) noexcept { HFSM2_ASSERT(stateId < StateList::SIZE); _originId = stateId; @@ -6240,7 +6181,7 @@ ControlT::setOrigin(const StateID stateId) { template void -ControlT::resetOrigin(const StateID stateId) { //-V524 +ControlT::resetOrigin(const StateID stateId) noexcept { //-V524 _originId = stateId; } @@ -6248,7 +6189,7 @@ ControlT::resetOrigin(const StateID stateId) { //-V524 template void -ControlT::setRegion(const RegionID regionId) { +ControlT::setRegion(const RegionID regionId) noexcept { HFSM2_ASSERT(_regionId <= regionId && regionId < RegionList::SIZE); _regionId = regionId; @@ -6258,7 +6199,7 @@ ControlT::setRegion(const RegionID regionId) { template void -ControlT::resetRegion(const RegionID regionId) { //-V524 +ControlT::resetRegion(const RegionID regionId) noexcept { //-V524 HFSM2_ASSERT(regionId <= _regionId && _regionId < RegionList::SIZE); _regionId = regionId; @@ -6271,7 +6212,7 @@ ControlT::resetRegion(const RegionID regionId) { //-V524 template void ControlT::pinLastTransition(const StateID stateId, - const Short index) + const Short index) noexcept { if (index != INVALID_SHORT) { HFSM2_ASSERT(index < TransitionSets::CAPACITY); @@ -6285,7 +6226,7 @@ ControlT::pinLastTransition(const StateID stateId, template const typename ControlT::Transition* -ControlT::lastTransition(const StateID stateId) const { +ControlT::lastTransition(const StateID stateId) const noexcept { if (HFSM2_CHECKED(stateId < StateList::SIZE)) { const Short index = _transitionTargets[stateId]; @@ -6300,7 +6241,7 @@ ControlT::lastTransition(const StateID stateId) const { template const typename ControlT::Transition* -ControlT::lastTransition() const { +ControlT::lastTransition() const noexcept { HFSM2_ASSERT(_originId < _transitionTargets.CAPACITY); return lastTransition(_originId); @@ -6314,7 +6255,7 @@ template PlanControlT::Region::Region(PlanControlT& control_, const RegionID regionId, const StateID index, - const Long size) + const Long size) noexcept : control {control_} , prevId {control._regionId} , prevIndex{control._regionStateId} @@ -6326,7 +6267,7 @@ PlanControlT::Region::Region(PlanControlT& control_, //------------------------------------------------------------------------------ template -PlanControlT::Region::~Region() { +PlanControlT::Region::~Region() noexcept { control.resetRegion(prevId, prevIndex, prevSize); control._status.clear(); @@ -6338,7 +6279,7 @@ template void PlanControlT::setRegion(const RegionID regionId, const StateID index, - const Long size) + const Long size) noexcept { HFSM2_ASSERT(_regionId <= regionId && regionId < RegionList::SIZE); HFSM2_ASSERT(_regionStateId <= index && index + size <= _regionStateId + _regionSize); @@ -6354,7 +6295,7 @@ template void PlanControlT::resetRegion(const RegionID regionId, //-V524 const StateID index, - const Long size) + const Long size) noexcept { HFSM2_ASSERT(regionId <= _regionId && _regionId < RegionList::SIZE); HFSM2_ASSERT(index <= _regionStateId && _regionStateId + _regionSize <= index + size); @@ -6367,7 +6308,7 @@ PlanControlT::resetRegion(const RegionID regionId, //-V524 //////////////////////////////////////////////////////////////////////////////// template -FullControlBaseT::Lock::Lock(FullControlBaseT& control_) +FullControlBaseT::Lock::Lock(FullControlBaseT& control_) noexcept : control{!control_._locked ? &control_ : nullptr} { if (control) @@ -6377,7 +6318,7 @@ FullControlBaseT::Lock::Lock(FullControlBaseT& control_) //------------------------------------------------------------------------------ template -FullControlBaseT::Lock::~Lock() { +FullControlBaseT::Lock::~Lock() noexcept { if (control) control->_locked = false; } @@ -6389,7 +6330,7 @@ FullControlBaseT::Lock::~Lock() { template template Status -FullControlBaseT::buildPlanStatus() { +FullControlBaseT::buildPlanStatus() noexcept { using State = TState; static constexpr StateID STATE_ID = State::STATE_ID; @@ -6420,10 +6361,11 @@ FullControlBaseT::buildPlanStatus() { #endif //------------------------------------------------------------------------------ +// COMMON template void -FullControlBaseT::changeTo(const StateID stateId) { +FullControlBaseT::changeTo(const StateID stateId) noexcept { if (!_locked) { _requests.append(Transition{_originId, stateId, TransitionType::CHANGE}); @@ -6434,11 +6376,12 @@ FullControlBaseT::changeTo(const StateID stateId) { } } +// COMMON //------------------------------------------------------------------------------ template void -FullControlBaseT::restart(const StateID stateId) { +FullControlBaseT::restart(const StateID stateId) noexcept { if (!_locked) { _requests.append(Transition{_originId, stateId, TransitionType::RESTART}); @@ -6453,7 +6396,7 @@ FullControlBaseT::restart(const StateID stateId) { template void -FullControlBaseT::resume(const StateID stateId) { +FullControlBaseT::resume(const StateID stateId) noexcept { if (!_locked) { _requests.append(Transition{_originId, stateId, TransitionType::RESUME}); @@ -6470,7 +6413,7 @@ FullControlBaseT::resume(const StateID stateId) { template void -FullControlBaseT::utilize(const StateID stateId) { +FullControlBaseT::utilize(const StateID stateId) noexcept { if (!_locked) { _requests.append(Transition{_originId, stateId, TransitionType::UTILIZE}); @@ -6485,7 +6428,7 @@ FullControlBaseT::utilize(const StateID stateId) { template void -FullControlBaseT::randomize(const StateID stateId) { +FullControlBaseT::randomize(const StateID stateId) noexcept { if (!_locked) { _requests.append(Transition{_originId, stateId, TransitionType::RANDOMIZE}); @@ -6502,7 +6445,7 @@ FullControlBaseT::randomize(const StateID stateId) { template void -FullControlBaseT::schedule(const StateID stateId) { +FullControlBaseT::schedule(const StateID stateId) noexcept { _requests.append(Transition{_originId, stateId, TransitionType::SCHEDULE}); HFSM2_LOG_TRANSITION(context(), _originId, TransitionType::SCHEDULE, stateId); @@ -6514,7 +6457,7 @@ FullControlBaseT::schedule(const StateID stateId) { template void -FullControlBaseT::succeed() { +FullControlBaseT::succeed() noexcept { _status.result = Status::Result::SUCCESS; _planData.tasksSuccesses.set(_originId); @@ -6533,7 +6476,7 @@ FullControlBaseT::succeed() { template void -FullControlBaseT::fail() { +FullControlBaseT::fail() noexcept { _status.result = Status::Result::FAILURE; _planData.tasksFailures.set(_originId); @@ -6558,7 +6501,7 @@ template Status FullControlT>::updatePlan(TState& headState, - const Status subStatus) + const Status subStatus) noexcept { using State = TState; static constexpr StateID STATE_ID = State::STATE_ID; @@ -6605,11 +6548,12 @@ FullControlT>::update #endif //------------------------------------------------------------------------------ +// COMMON template void FullControlT>::changeWith(const StateID stateId, - const Payload& payload) + const Payload& payload) noexcept { if (!_locked) { _requests.append(Transition{_originId, stateId, TransitionType::CHANGE, payload}); @@ -6624,7 +6568,7 @@ FullControlT void FullControlT>::changeWith(const StateID stateId, - Payload&& payload) + Payload&& payload) noexcept { if (!_locked) { _requests.append(Transition{_originId, stateId, TransitionType::CHANGE, std::move(payload)}); @@ -6636,12 +6580,13 @@ FullControlT void FullControlT>::restartWith(const StateID stateId, - const Payload& payload) + const Payload& payload) noexcept { if (!_locked) { _requests.append(Transition{_originId, stateId, TransitionType::RESTART, payload}); @@ -6656,7 +6601,7 @@ FullControlT void FullControlT>::restartWith(const StateID stateId, - Payload&& payload) + Payload&& payload) noexcept { if (!_locked) { _requests.append(Transition{_originId, stateId, TransitionType::RESTART, std::move(payload)}); @@ -6673,7 +6618,7 @@ FullControlT void FullControlT>::resumeWith(const StateID stateId, - const Payload& payload) + const Payload& payload) noexcept { if (!_locked) { _requests.append(Transition{_originId, stateId, TransitionType::RESUME, payload}); @@ -6688,7 +6633,7 @@ FullControlT void FullControlT>::resumeWith(const StateID stateId, - Payload&& payload) + Payload&& payload) noexcept { if (!_locked) { _requests.append(Transition{_originId, stateId, TransitionType::RESUME, std::move(payload)}); @@ -6707,7 +6652,7 @@ FullControlT void FullControlT>::utilizeWith(const StateID stateId, - const Payload& payload) + const Payload& payload) noexcept { if (!_locked) { _requests.append(Transition{_originId, stateId, TransitionType::UTILIZE, payload}); @@ -6722,7 +6667,7 @@ FullControlT void FullControlT>::utilizeWith(const StateID stateId, - Payload&& payload) + Payload&& payload) noexcept { if (!_locked) { _requests.append(Transition{_originId, stateId, TransitionType::UTILIZE, std::move(payload)}); @@ -6739,7 +6684,7 @@ FullControlT void FullControlT>::randomizeWith(const StateID stateId, - const Payload& payload) + const Payload& payload) noexcept { if (!_locked) { _requests.append(Transition{_originId, stateId, TransitionType::RANDOMIZE, payload}); @@ -6754,7 +6699,7 @@ FullControlT void FullControlT>::randomizeWith(const StateID stateId, - Payload&& payload) + Payload&& payload) noexcept { if (!_locked) { _requests.append(Transition{_originId, stateId, TransitionType::RANDOMIZE, std::move(payload)}); @@ -6773,7 +6718,7 @@ FullControlT void FullControlT>::scheduleWith(const StateID stateId, - const Payload& payload) + const Payload& payload) noexcept { _requests.append(Transition{_originId, stateId, TransitionType::SCHEDULE, payload}); @@ -6783,7 +6728,7 @@ FullControlT void FullControlT>::scheduleWith(const StateID stateId, - Payload&& payload) + Payload&& payload) noexcept { _requests.append(Transition{_originId, stateId, TransitionType::SCHEDULE, std::move(payload)}); @@ -6798,7 +6743,7 @@ template Status FullControlT>::updatePlan(TState& headState, - const Status subStatus) + const Status subStatus) noexcept { using State = TState; static constexpr StateID STATE_ID = State::STATE_ID; @@ -6848,7 +6793,7 @@ FullControlT>::updat template void -GuardControlT::cancelPendingTransitions() { +GuardControlT::cancelPendingTransitions() noexcept { _cancelled = true; HFSM2_LOG_CANCELLED_PENDING(context(), _originId); @@ -6891,26 +6836,26 @@ class InjectionT { using GuardControl = GuardControlT; public: - HFSM2_INLINE void preEntryGuard(Context&) {} + HFSM2_INLINE void preEntryGuard(Context&) noexcept {} - HFSM2_INLINE void preEnter (Context&) {} - HFSM2_INLINE void preReenter (Context&) {} + HFSM2_INLINE void preEnter (Context&) noexcept {} + HFSM2_INLINE void preReenter (Context&) noexcept {} - HFSM2_INLINE void preUpdate (Context&) {} + HFSM2_INLINE void preUpdate (Context&) noexcept {} template HFSM2_INLINE void preReact (const TEvent&, - Context&) {} + Context&) noexcept {} - HFSM2_INLINE void preExitGuard (Context&) {} + HFSM2_INLINE void preExitGuard (Context&) noexcept {} - HFSM2_INLINE void postExit (Context&) {} + HFSM2_INLINE void postExit (Context&) noexcept {} + + template + static constexpr StateID stateId() noexcept { return index(); } template - static constexpr StateID stateId() { return index(); } - - template - static constexpr RegionID regionId() { return (RegionID) index(); } + static constexpr RegionID regionId() noexcept { return (RegionID) index(); } }; //------------------------------------------------------------------------------ @@ -6948,20 +6893,20 @@ struct B_ using TFirst::stateId; using TFirst::regionId; - HFSM2_INLINE void widePreEntryGuard(Context& context); + HFSM2_INLINE void widePreEntryGuard(Context& context) noexcept; - HFSM2_INLINE void widePreEnter (Context& context); - HFSM2_INLINE void widePreReenter (Context& context); + HFSM2_INLINE void widePreEnter (Context& context) noexcept; + HFSM2_INLINE void widePreReenter (Context& context) noexcept; - HFSM2_INLINE void widePreUpdate (Context& context); + HFSM2_INLINE void widePreUpdate (Context& context) noexcept; template HFSM2_INLINE void widePreReact (const TEvent& event, - Context& context); + Context& context) noexcept; - HFSM2_INLINE void widePreExitGuard (Context& context); + HFSM2_INLINE void widePreExitGuard (Context& context) noexcept; - HFSM2_INLINE void widePostExit (Context& context); + HFSM2_INLINE void widePostExit (Context& context) noexcept; }; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -6994,44 +6939,44 @@ struct B_ using TFirst::regionId; #ifdef HFSM2_ENABLE_UTILITY_THEORY - HFSM2_INLINE Rank rank (const Control&) { return Rank {0}; } - HFSM2_INLINE Utility utility (const Control&) { return Utility{1}; } + HFSM2_INLINE Rank rank (const Control&) noexcept { return Rank {0}; } + HFSM2_INLINE Utility utility (const Control&) noexcept { return Utility{1}; } #endif - HFSM2_INLINE void entryGuard (GuardControl&) {} + HFSM2_INLINE void entryGuard (GuardControl&) noexcept {} - HFSM2_INLINE void enter (PlanControl&) {} - HFSM2_INLINE void reenter (PlanControl&) {} + HFSM2_INLINE void enter (PlanControl&) noexcept {} + HFSM2_INLINE void reenter (PlanControl&) noexcept {} - HFSM2_INLINE void update (FullControl&) {} + HFSM2_INLINE void update (FullControl&) noexcept {} template HFSM2_INLINE void react (const TEvent&, - FullControl&) {} + FullControl&) noexcept {} - HFSM2_INLINE void exitGuard (GuardControl&) {} + HFSM2_INLINE void exitGuard (GuardControl&) noexcept {} - HFSM2_INLINE void exit (PlanControl&) {} + HFSM2_INLINE void exit (PlanControl&) noexcept {} #ifdef HFSM2_ENABLE_PLANS - HFSM2_INLINE void planSucceeded (FullControl& control) { control.succeed(); } - HFSM2_INLINE void planFailed (FullControl& control) { control.fail(); } + HFSM2_INLINE void planSucceeded (FullControl& control) noexcept { control.succeed(); } + HFSM2_INLINE void planFailed (FullControl& control) noexcept { control.fail(); } #endif - HFSM2_INLINE void widePreEntryGuard(Context& context); + HFSM2_INLINE void widePreEntryGuard(Context& context) noexcept; - HFSM2_INLINE void widePreEnter (Context& context); - HFSM2_INLINE void widePreReenter (Context& context); + HFSM2_INLINE void widePreEnter (Context& context) noexcept; + HFSM2_INLINE void widePreReenter (Context& context) noexcept; - HFSM2_INLINE void widePreUpdate (Context& context); + HFSM2_INLINE void widePreUpdate (Context& context) noexcept; template HFSM2_INLINE void widePreReact (const TEvent& event, - Context& context); + Context& context) noexcept; - HFSM2_INLINE void widePreExitGuard (Context& context); + HFSM2_INLINE void widePreExitGuard (Context& context) noexcept; - HFSM2_INLINE void widePostExit (Context& context); + HFSM2_INLINE void widePostExit (Context& context) noexcept; }; //------------------------------------------------------------------------------ @@ -7077,7 +7022,7 @@ namespace detail { template void -B_::widePreEntryGuard(Context& context) { +B_::widePreEntryGuard(Context& context) noexcept { TF::preEntryGuard(context); B_::widePreEntryGuard(context); } @@ -7086,7 +7031,7 @@ B_::widePreEntryGuard(Context& context) { template void -B_::widePreEnter(Context& context) { +B_::widePreEnter(Context& context) noexcept { TF::preEnter(context); B_::widePreEnter(context); } @@ -7095,7 +7040,7 @@ B_::widePreEnter(Context& context) { template void -B_::widePreReenter(Context& context) { +B_::widePreReenter(Context& context) noexcept { TF::preReenter(context); B_::widePreReenter(context); } @@ -7104,7 +7049,7 @@ B_::widePreReenter(Context& context) { template void -B_::widePreUpdate(Context& context) { +B_::widePreUpdate(Context& context) noexcept { TF::preUpdate(context); B_::widePreUpdate(context); } @@ -7115,7 +7060,7 @@ template template void B_::widePreReact(const TEvent& event, - Context& context) + Context& context) noexcept { TF::preReact(event, context); B_::widePreReact(event, context); @@ -7125,7 +7070,7 @@ B_::widePreReact(const TEvent& event, template void -B_::widePreExitGuard(Context& context) { +B_::widePreExitGuard(Context& context) noexcept { TF::preExitGuard(context); B_::widePreExitGuard(context); } @@ -7134,7 +7079,7 @@ B_::widePreExitGuard(Context& context) { template void -B_::widePostExit(Context& context) { +B_::widePostExit(Context& context) noexcept { TF::postExit(context); B_::widePostExit(context); } @@ -7143,7 +7088,7 @@ B_::widePostExit(Context& context) { template void -B_::widePreEntryGuard(Context& context) { +B_::widePreEntryGuard(Context& context) noexcept { TF::preEntryGuard(context); } @@ -7151,7 +7096,7 @@ B_::widePreEntryGuard(Context& context) { template void -B_::widePreEnter(Context& context) { +B_::widePreEnter(Context& context) noexcept { TF::preEnter(context); } @@ -7159,7 +7104,7 @@ B_::widePreEnter(Context& context) { template void -B_::widePreReenter(Context& context) { +B_::widePreReenter(Context& context) noexcept { TF::preReenter(context); } @@ -7167,7 +7112,7 @@ B_::widePreReenter(Context& context) { template void -B_::widePreUpdate(Context& context) { +B_::widePreUpdate(Context& context) noexcept { TF::preUpdate(context); } @@ -7177,7 +7122,7 @@ template template void B_::widePreReact(const TEvent& event, - Context& context) + Context& context) noexcept { TF::preReact(event, context); } @@ -7186,7 +7131,7 @@ B_::widePreReact(const TEvent& event, template void -B_::widePreExitGuard(Context& context) { +B_::widePreExitGuard(Context& context) noexcept { TF::preExitGuard(context); } @@ -7194,7 +7139,7 @@ B_::widePreExitGuard(Context& context) { template void -B_::widePostExit(Context& context) { +B_::widePostExit(Context& context) noexcept { TF::postExit(context); } @@ -7209,7 +7154,7 @@ namespace hfsm2 { template struct Guard { template - static void execute(hfsm2::detail::GuardControlT&) {} + static HFSM2_INLINE void execute(hfsm2::detail::GuardControlT&) noexcept {} }; namespace detail { @@ -7224,22 +7169,22 @@ template struct DynamicBox final { using Type = T; - static constexpr bool isBare() { return false; } + static constexpr bool isBare() noexcept { return false; } union { Type t_; }; - HFSM2_INLINE DynamicBox() {} - HFSM2_INLINE ~DynamicBox() {} + HFSM2_INLINE DynamicBox() noexcept {} + HFSM2_INLINE ~DynamicBox() noexcept {} - HFSM2_INLINE void guard(GuardControlT& control) { Guard::execute(control); } + HFSM2_INLINE void guard(GuardControlT& control) noexcept { Guard::execute(control); } - HFSM2_INLINE void construct(); - HFSM2_INLINE void destruct(); + HFSM2_INLINE void construct() noexcept; + HFSM2_INLINE void destruct() noexcept; - HFSM2_INLINE Type& get() { HFSM2_ASSERT(initialized_); return t_; } - HFSM2_INLINE const Type& get() const { HFSM2_ASSERT(initialized_); return t_; } + HFSM2_INLINE Type& get() noexcept { HFSM2_ASSERT(initialized_); return t_; } + HFSM2_INLINE const Type& get() const noexcept { HFSM2_ASSERT(initialized_); return t_; } HFSM2_IF_ASSERT(bool initialized_ = false); @@ -7252,17 +7197,17 @@ template struct StaticBox final { using Type = T; - static constexpr bool isBare() { return std::is_base_of>::value; } + static constexpr bool isBare() noexcept { return std::is_base_of>::value; } Type t_; - HFSM2_INLINE void guard(GuardControlT& control); + HFSM2_INLINE void guard(GuardControlT& control) noexcept; - HFSM2_INLINE void construct() {} - HFSM2_INLINE void destruct() {} + HFSM2_INLINE void construct() noexcept {} + HFSM2_INLINE void destruct() noexcept {} - HFSM2_INLINE Type& get() { return t_; } - HFSM2_INLINE const Type& get() const { return t_; } + HFSM2_INLINE Type& get() noexcept { return t_; } + HFSM2_INLINE const Type& get() const noexcept { return t_; } HFSM2_IF_DEBUG(const std::type_index TYPE = isBare() ? typeid(None) : typeid(Type)); }; @@ -7271,11 +7216,11 @@ struct StaticBox final { template struct BoxifyT final { - using Type = typename std::conditional< + using Type = Conditional< std::is_base_of::value, DynamicBox, StaticBox - >::type; + >; }; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -7295,7 +7240,7 @@ namespace detail { template void -DynamicBox::construct() { +DynamicBox::construct() noexcept { HFSM2_ASSERT(!initialized_); new(&t_) T{}; @@ -7307,7 +7252,7 @@ DynamicBox::construct() { template void -DynamicBox::destruct() { +DynamicBox::destruct() noexcept { HFSM2_ASSERT(initialized_); t_.~T(); @@ -7319,7 +7264,7 @@ DynamicBox::destruct() { template void -StaticBox::guard(GuardControlT& control) { +StaticBox::guard(GuardControlT& control) noexcept { t_.widePreEntryGuard(control.context()); t_. entryGuard(control); } @@ -7374,8 +7319,8 @@ struct S_ final { template struct Accessor { - HFSM2_INLINE static T& get( S_& ) { HFSM2_BREAK(); return *reinterpret_cast(0); } - HFSM2_INLINE static const T& get(const S_& ) { HFSM2_BREAK(); return *reinterpret_cast(0); } + HFSM2_INLINE static T& get( S_& ) noexcept { HFSM2_BREAK(); return *reinterpret_cast(0); } + HFSM2_INLINE static const T& get(const S_& ) noexcept { HFSM2_BREAK(); return *reinterpret_cast(0); } }; #ifdef __clang__ @@ -7384,83 +7329,85 @@ struct S_ final { template <> struct Accessor { - HFSM2_INLINE static Head& get( S_& s) { return s._headBox.get(); } - HFSM2_INLINE static const Head& get(const S_& s) { return s._headBox.get(); } + HFSM2_INLINE static Head& get( S_& s) noexcept { return s._headBox.get(); } + HFSM2_INLINE static const Head& get(const S_& s) noexcept { return s._headBox.get(); } }; template - HFSM2_INLINE T& access() { return Accessor::get(*this); } + HFSM2_INLINE T& access() noexcept { return Accessor::get(*this); } template - HFSM2_INLINE const T& access() const { return Accessor::get(*this); } + HFSM2_INLINE const T& access() const noexcept { return Accessor::get(*this); } #endif //---------------------------------------------------------------------- - HFSM2_INLINE Parent stateParent (Control& control) { return control._registry.stateParents[STATE_ID]; } + HFSM2_INLINE Parent stateParent (Control& control) noexcept { return control._registry.stateParents[STATE_ID]; } - HFSM2_INLINE void deepRegister (Registry& registry, const Parent parent); + HFSM2_INLINE void deepRegister (Registry& registry, + const Parent parent) noexcept; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #ifdef HFSM2_ENABLE_UTILITY_THEORY - HFSM2_INLINE Rank wrapRank (Control& control); - HFSM2_INLINE Utility wrapUtility (Control& control); + HFSM2_INLINE Rank wrapRank (Control& control) noexcept; + HFSM2_INLINE Utility wrapUtility (Control& control) noexcept; #endif // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE bool deepForwardEntryGuard(GuardControl&) { return false; } - HFSM2_INLINE bool deepEntryGuard (GuardControl& control); + HFSM2_INLINE bool deepForwardEntryGuard(GuardControl& ) noexcept { return false; } + HFSM2_INLINE bool deepEntryGuard (GuardControl& control) noexcept; - HFSM2_INLINE void deepConstruct (PlanControl& control); + HFSM2_INLINE void deepConstruct (PlanControl& control) noexcept; - HFSM2_INLINE void deepEnter (PlanControl& control); - HFSM2_INLINE void deepReenter (PlanControl& control); + HFSM2_INLINE void deepEnter (PlanControl& control) noexcept; + HFSM2_INLINE void deepReenter (PlanControl& control) noexcept; - HFSM2_INLINE Status deepUpdate (FullControl& control); + HFSM2_INLINE Status deepUpdate (FullControl& control) noexcept; template - HFSM2_INLINE Status deepReact (FullControl& control, const TEvent& event); + HFSM2_INLINE Status deepReact (FullControl& control, + const TEvent& event) noexcept; - HFSM2_INLINE bool deepForwardExitGuard (GuardControl&) { return false; } - HFSM2_INLINE bool deepExitGuard (GuardControl& control); + HFSM2_INLINE bool deepForwardExitGuard (GuardControl& ) noexcept { return false; } + HFSM2_INLINE bool deepExitGuard (GuardControl& control) noexcept; - HFSM2_INLINE void deepExit (PlanControl& control); + HFSM2_INLINE void deepExit (PlanControl& control) noexcept; - HFSM2_INLINE void deepDestruct (PlanControl& control); + HFSM2_INLINE void deepDestruct (PlanControl& control) noexcept; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #ifdef HFSM2_ENABLE_PLANS - HFSM2_INLINE void wrapPlanSucceeded (FullControl& control); - HFSM2_INLINE void wrapPlanFailed (FullControl& control); + HFSM2_INLINE void wrapPlanSucceeded (FullControl& control) noexcept; + HFSM2_INLINE void wrapPlanFailed (FullControl& control) noexcept; #endif // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE void deepForwardActive (Control&, const Request ) {} - HFSM2_INLINE void deepForwardRequest (Control& control, const Request request); + HFSM2_INLINE void deepForwardActive (Control&, const Request ) noexcept {} + HFSM2_INLINE void deepForwardRequest (Control& control, const Request request) noexcept; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE void deepRequestChange (Control& control, const Request request); - HFSM2_INLINE void deepRequestRestart (Control& control, const Request request); - HFSM2_INLINE void deepRequestResume (Control& control, const Request request); + HFSM2_INLINE void deepRequestChange (Control& control, const Request request) noexcept; + HFSM2_INLINE void deepRequestRestart (Control& control, const Request request) noexcept; + HFSM2_INLINE void deepRequestResume (Control& control, const Request request) noexcept; #ifdef HFSM2_ENABLE_UTILITY_THEORY - HFSM2_INLINE void deepRequestUtilize (Control& control, const Request request); - HFSM2_INLINE void deepRequestRandomize (Control& control, const Request request); + HFSM2_INLINE void deepRequestUtilize (Control& control, const Request request) noexcept; + HFSM2_INLINE void deepRequestRandomize (Control& control, const Request request) noexcept; - HFSM2_INLINE UP deepReportChange (Control& control); - HFSM2_INLINE UP deepReportUtilize (Control& control); - HFSM2_INLINE Rank deepReportRank (Control& control); - HFSM2_INLINE Utility deepReportRandomize (Control& control); + HFSM2_INLINE UP deepReportChange (Control& control) noexcept; + HFSM2_INLINE UP deepReportUtilize (Control& control) noexcept; + HFSM2_INLINE Rank deepReportRank (Control& control) noexcept; + HFSM2_INLINE Utility deepReportRandomize (Control& control) noexcept; #endif // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE void deepChangeToRequested(Control&) {} + HFSM2_INLINE void deepChangeToRequested(Control&) noexcept {} //---------------------------------------------------------------------- @@ -7468,11 +7415,11 @@ struct S_ final { using WriteStream = typename TArgs::WriteStream; using ReadStream = typename TArgs::ReadStream; - HFSM2_INLINE void deepSaveActive (const Registry&, WriteStream&) const {} - HFSM2_INLINE void deepSaveResumable(const Registry&, WriteStream&) const {} + HFSM2_INLINE void deepSaveActive (const Registry&, WriteStream&) const noexcept {} + HFSM2_INLINE void deepSaveResumable(const Registry&, WriteStream&) const noexcept {} - HFSM2_INLINE void deepLoadRequested( Registry&, ReadStream& ) const {} - HFSM2_INLINE void deepLoadResumable( Registry&, ReadStream& ) const {} + HFSM2_INLINE void deepLoadRequested( Registry&, ReadStream& ) const noexcept {} + HFSM2_INLINE void deepLoadResumable( Registry&, ReadStream& ) const noexcept {} #endif //---------------------------------------------------------------------- @@ -7481,12 +7428,12 @@ struct S_ final { using StructureStateInfos = typename TArgs::StructureStateInfos; using RegionType = typename StructureStateInfo::RegionType; - static const char* name(); + static const char* name() noexcept; void deepGetNames(const Long parent, const RegionType region, const Short depth, - StructureStateInfos& stateInfos) const; + StructureStateInfos& stateInfos) const noexcept; #endif //---------------------------------------------------------------------- @@ -7511,7 +7458,7 @@ struct S_ final { void log(TReturn(THost::*)(TParams...), Logger& logger, Context& context, - const Method method) const + const Method method) const noexcept { logger.recordMethod(context, STATE_ID, method); } @@ -7522,7 +7469,7 @@ struct S_ final { void log(TReturn(Empty::*)(TParams...), Logger&, Context&, - const Method) const + const Method) const noexcept {} #endif @@ -7551,7 +7498,7 @@ namespace detail { template struct RegisterT { - using StateParents = StaticArray; + using StateParents = StaticArrayT; using StateList = typename TA::StateList; static constexpr StateID STATE_ID = NS; @@ -7559,7 +7506,7 @@ struct RegisterT { static HFSM2_INLINE void execute(StateParents& stateParents, - const Parent parent) + const Parent parent) noexcept { static constexpr auto HEAD_ID = index(); StaticAssertEquality(); @@ -7572,11 +7519,11 @@ struct RegisterT { template struct RegisterT> { - using StateParents = StaticArray; + using StateParents = StaticArrayT; static HFSM2_INLINE void - execute(StateParents&, const Parent) {} + execute(StateParents&, const Parent) noexcept {} }; //////////////////////////////////////////////////////////////////////////////// @@ -7584,7 +7531,7 @@ struct RegisterT> { template void S_::deepRegister(Registry& registry, - const Parent parent) + const Parent parent) noexcept { using Register = RegisterT; Register::execute(registry.stateParents, parent); @@ -7596,7 +7543,7 @@ S_::deepRegister(Registry& registry, template typename S_::Rank -S_::wrapRank(Control& control) { +S_::wrapRank(Control& control) noexcept { HFSM2_LOG_STATE_METHOD(&Head::rank, Method::RANK); @@ -7607,7 +7554,7 @@ S_::wrapRank(Control& control) { template typename S_::Utility -S_::wrapUtility(Control& control) { +S_::wrapUtility(Control& control) noexcept { HFSM2_LOG_STATE_METHOD(&Head::utility, Method::UTILITY); @@ -7617,10 +7564,11 @@ S_::wrapUtility(Control& control) { #endif //------------------------------------------------------------------------------ +// COMMON template bool -S_::deepEntryGuard(GuardControl& control) { +S_::deepEntryGuard(GuardControl& control) noexcept { HFSM2_LOG_STATE_METHOD(&Head::entryGuard, Method::ENTRY_GUARD); @@ -7637,11 +7585,12 @@ S_::deepEntryGuard(GuardControl& control) { template void -S_::deepConstruct(PlanControl& HFSM2_IF_LOG_INTERFACE(control)) { -#ifdef HFSM2_ENABLE_PLANS - HFSM2_ASSERT(!control._planData.tasksSuccesses.template get()); - HFSM2_ASSERT(!control._planData.tasksFailures .template get()); -#endif +S_::deepConstruct(PlanControl& + #if defined HFSM2_ENABLE_PLANS || defined HFSM2_ENABLE_LOG_INTERFACE + control + #endif + ) noexcept { + HFSM2_IF_PLANS(control._planData.verifyEmptyStatus(STATE_ID)); HFSM2_LOG_STATE_METHOD(&Head::enter, Method::CONSTRUCT); @@ -7653,7 +7602,7 @@ S_::deepConstruct(PlanControl& HFSM2_IF_LOG_INTERFACE(control)) { template void -S_::deepEnter(PlanControl& control) { +S_::deepEnter(PlanControl& control) noexcept { HFSM2_LOG_STATE_METHOD(&Head::enter, Method::ENTER); @@ -7667,11 +7616,8 @@ S_::deepEnter(PlanControl& control) { template void -S_::deepReenter(PlanControl& control) { -#ifdef HFSM2_ENABLE_PLANS - HFSM2_ASSERT(!control._planData.tasksSuccesses.template get()); - HFSM2_ASSERT(!control._planData.tasksFailures .template get()); -#endif +S_::deepReenter(PlanControl& control) noexcept { + HFSM2_IF_PLANS(control._planData.verifyEmptyStatus(STATE_ID)); HFSM2_LOG_STATE_METHOD(&Head::reenter, Method::REENTER); @@ -7689,7 +7635,7 @@ S_::deepReenter(PlanControl& control) { template Status -S_::deepUpdate(FullControl& control) { +S_::deepUpdate(FullControl& control) noexcept { HFSM2_LOG_STATE_METHOD(&Head::update, Method::UPDATE); @@ -7707,7 +7653,7 @@ template template Status S_::deepReact(FullControl& control, - const TEvent& event) + const TEvent& event) noexcept { auto reaction = static_cast(&Head::react); @@ -7726,7 +7672,7 @@ S_::deepReact(FullControl& control, template bool -S_::deepExitGuard(GuardControl& control) { +S_::deepExitGuard(GuardControl& control) noexcept { HFSM2_LOG_STATE_METHOD(&Head::exitGuard, Method::EXIT_GUARD); @@ -7744,7 +7690,7 @@ S_::deepExitGuard(GuardControl& control) { template void -S_::deepExit(PlanControl& control) { +S_::deepExit(PlanControl& control) noexcept { HFSM2_LOG_STATE_METHOD(&Head::exit, Method::EXIT); @@ -7767,17 +7713,14 @@ S_::deepDestruct(PlanControl& #if defined HFSM2_ENABLE_LOG_INTERFACE || defined HFSM2_ENABLE_PLANS control #endif - ) + ) noexcept { HFSM2_LOG_STATE_METHOD(&Head::exit, Method::DESTRUCT); _headBox.destruct(); -#ifdef HFSM2_ENABLE_PLANS - control._planData.tasksSuccesses.template clear(); - control._planData.tasksFailures .template clear(); -#endif + HFSM2_IF_PLANS(control._planData.clearTaskStatus(STATE_ID)); } //------------------------------------------------------------------------------ @@ -7786,7 +7729,7 @@ S_::deepDestruct(PlanControl& template void -S_::wrapPlanSucceeded(FullControl& control) { +S_::wrapPlanSucceeded(FullControl& control) noexcept { HFSM2_LOG_STATE_METHOD(&Head::planSucceeded, Method::PLAN_SUCCEEDED); @@ -7799,7 +7742,7 @@ S_::wrapPlanSucceeded(FullControl& control) { template void -S_::wrapPlanFailed(FullControl& control) { +S_::wrapPlanFailed(FullControl& control) noexcept { HFSM2_LOG_STATE_METHOD(&Head::planFailed, Method::PLAN_FAILED); @@ -7815,7 +7758,7 @@ S_::wrapPlanFailed(FullControl& control) { template void S_::deepForwardRequest(Control& HFSM2_IF_TRANSITION_HISTORY(control), - const Request HFSM2_IF_TRANSITION_HISTORY(request)) + const Request HFSM2_IF_TRANSITION_HISTORY(request)) noexcept { HFSM2_IF_TRANSITION_HISTORY(control.pinLastTransition(STATE_ID, request.index)); } @@ -7825,7 +7768,7 @@ S_::deepForwardRequest(Control& HFSM2_IF_TRANSITION_HISTORY(control template void S_::deepRequestChange(Control& HFSM2_IF_TRANSITION_HISTORY(control), - const Request HFSM2_IF_TRANSITION_HISTORY(request)) + const Request HFSM2_IF_TRANSITION_HISTORY(request)) noexcept { HFSM2_IF_TRANSITION_HISTORY(control.pinLastTransition(STATE_ID, request.index)); } @@ -7835,7 +7778,7 @@ S_::deepRequestChange(Control& HFSM2_IF_TRANSITION_HISTORY(control) template void S_::deepRequestRestart(Control& HFSM2_IF_TRANSITION_HISTORY(control), - const Request HFSM2_IF_TRANSITION_HISTORY(request)) + const Request HFSM2_IF_TRANSITION_HISTORY(request)) noexcept { HFSM2_IF_TRANSITION_HISTORY(control.pinLastTransition(STATE_ID, request.index)); } @@ -7845,7 +7788,7 @@ S_::deepRequestRestart(Control& HFSM2_IF_TRANSITION_HISTORY(control template void S_::deepRequestResume(Control& HFSM2_IF_TRANSITION_HISTORY(control), - const Request HFSM2_IF_TRANSITION_HISTORY(request)) + const Request HFSM2_IF_TRANSITION_HISTORY(request)) noexcept { HFSM2_IF_TRANSITION_HISTORY(control.pinLastTransition(STATE_ID, request.index)); } @@ -7857,7 +7800,7 @@ S_::deepRequestResume(Control& HFSM2_IF_TRANSITION_HISTORY(control) template void S_::deepRequestUtilize(Control& HFSM2_IF_TRANSITION_HISTORY(control), - const Request HFSM2_IF_TRANSITION_HISTORY(request)) + const Request HFSM2_IF_TRANSITION_HISTORY(request)) noexcept { HFSM2_IF_TRANSITION_HISTORY(control.pinLastTransition(STATE_ID, request.index)); } @@ -7867,7 +7810,7 @@ S_::deepRequestUtilize(Control& HFSM2_IF_TRANSITION_HISTORY(control template void S_::deepRequestRandomize(Control& HFSM2_IF_TRANSITION_HISTORY(control), - const Request HFSM2_IF_TRANSITION_HISTORY(request)) + const Request HFSM2_IF_TRANSITION_HISTORY(request)) noexcept { HFSM2_IF_TRANSITION_HISTORY(control.pinLastTransition(STATE_ID, request.index)); } @@ -7876,7 +7819,7 @@ S_::deepRequestRandomize(Control& HFSM2_IF_TRANSITION_HISTORY(contr template typename S_::UP -S_::deepReportChange(Control& control) { +S_::deepReportChange(Control& control) noexcept { const Utility utility = wrapUtility(control); const Parent parent = stateParent(control); @@ -7888,7 +7831,7 @@ S_::deepReportChange(Control& control) { template typename S_::UP -S_::deepReportUtilize(Control& control) { +S_::deepReportUtilize(Control& control) noexcept { const Utility utility = wrapUtility(control); const Parent parent = stateParent(control); @@ -7899,7 +7842,7 @@ S_::deepReportUtilize(Control& control) { template typename S_::Rank -S_::deepReportRank(Control& control) { +S_::deepReportRank(Control& control) noexcept { return wrapRank(control); } @@ -7907,7 +7850,7 @@ S_::deepReportRank(Control& control) { template typename S_::Utility -S_::deepReportRandomize(Control& control) { +S_::deepReportRandomize(Control& control) noexcept { return wrapUtility(control); } @@ -7919,7 +7862,7 @@ S_::deepReportRandomize(Control& control) { template const char* -S_::name() { +S_::name() noexcept { if (HeadBox::isBare()) return ""; else { @@ -7958,7 +7901,7 @@ void S_::deepGetNames(const Long parent, const RegionType region, const Short depth, - StructureStateInfos& _stateInfos) const + StructureStateInfos& _stateInfos) const noexcept { _stateInfos.append(StructureStateInfo{parent, region, depth, name()}); } @@ -8033,8 +7976,8 @@ using WrapInfo = typename WrapInfoT::Type; template struct SI_ final { using Head = THead; - using StateList = TypeList; - using RegionList = TypeList<>; + using StateList = TL_; + using RegionList = TL_<>; static constexpr Short WIDTH = 1; static constexpr Long REVERSE_DEPTH = 1; @@ -8214,15 +8157,15 @@ struct ArgsT final { static constexpr Long TASK_CAPACITY = NTaskCapacity; #endif - using Payload = TPayload; + using Payload = TPayload; #ifdef HFSM2_ENABLE_SERIALIZATION - using SerialBuffer = StreamBuffer ; - using WriteStream = BitWriteStream; - using ReadStream = BitReadStream ; + using SerialBuffer = StreamBufferT ; + using WriteStream = BitWriteStreamT; + using ReadStream = BitReadStreamT ; #endif - HFSM2_IF_STRUCTURE_REPORT(using StructureStateInfos = Array); + HFSM2_IF_STRUCTURE_REPORT(using StructureStateInfos = ArrayT); }; //------------------------------------------------------------------------------ @@ -8256,7 +8199,7 @@ template struct OS_; template -class RW_; +class RR_; //------------------------------------------------------------------------------ @@ -8334,7 +8277,7 @@ struct RF_ final { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - using Instance = RW_; + using Instance = RR_; using Control = ControlT ; using FullControl = FullControlT ; @@ -8372,13 +8315,13 @@ struct RF_ final { //---------------------------------------------------------------------- template - static constexpr bool contains() { return contains(); } + static constexpr bool contains() noexcept { return contains(); } template - static constexpr StateID stateId() { return index(); } + static constexpr StateID stateId() noexcept { return index (); } template - static constexpr RegionID regionId() { return (RegionID) index(); } + static constexpr RegionID regionId() noexcept { return (RegionID) index(); } }; //////////////////////////////////////////////////////////////////////////////// @@ -8387,7 +8330,7 @@ template struct CSubMaterialT; template -struct CSubMaterialT> { +struct CSubMaterialT> { using Type = CS_; }; @@ -8471,7 +8414,7 @@ struct CS_ final { static constexpr Short L_PRONG = PRONG_INDEX; - using LStateList = LHalf; + using LStateList = LHalfTypes; using LMaterial = CSubMaterial; + using RStateList = RHalfTypes; using RMaterial = CSubMaterial - HFSM2_INLINE T& access(); + HFSM2_INLINE T& access() noexcept; template - HFSM2_INLINE const T& access() const; + HFSM2_INLINE const T& access() const noexcept; #endif // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE void wideRegister (Registry& registry, const Parent parent); + HFSM2_INLINE void wideRegister (Registry& registry, const Parent parent) noexcept; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE bool wideForwardEntryGuard (GuardControl& control, const Short prong); - HFSM2_INLINE bool wideEntryGuard (GuardControl& control, const Short prong); + HFSM2_INLINE bool wideForwardEntryGuard (GuardControl& control, const Short prong) noexcept; + HFSM2_INLINE bool wideEntryGuard (GuardControl& control, const Short prong) noexcept; - HFSM2_INLINE void wideConstruct (PlanControl& control, const Short prong); + HFSM2_INLINE void wideConstruct (PlanControl& control, const Short prong) noexcept; - HFSM2_INLINE void wideEnter (PlanControl& control, const Short prong); - HFSM2_INLINE void wideReenter (PlanControl& control, const Short prong); + HFSM2_INLINE void wideEnter (PlanControl& control, const Short prong) noexcept; + HFSM2_INLINE void wideReenter (PlanControl& control, const Short prong) noexcept; - HFSM2_INLINE Status wideUpdate (FullControl& control, const Short prong); + HFSM2_INLINE Status wideUpdate (FullControl& control, const Short prong) noexcept; template - HFSM2_INLINE Status wideReact (FullControl& control, const TEvent& event, const Short prong); + HFSM2_INLINE Status wideReact (FullControl& control, + const TEvent& event, const Short prong) noexcept; - HFSM2_INLINE bool wideForwardExitGuard (GuardControl& control, const Short prong); - HFSM2_INLINE bool wideExitGuard (GuardControl& control, const Short prong); + HFSM2_INLINE bool wideForwardExitGuard (GuardControl& control, const Short prong) noexcept; + HFSM2_INLINE bool wideExitGuard (GuardControl& control, const Short prong) noexcept; - HFSM2_INLINE void wideExit (PlanControl& control, const Short prong); + HFSM2_INLINE void wideExit (PlanControl& control, const Short prong) noexcept; - HFSM2_INLINE void wideDestruct (PlanControl& control, const Short prong); + HFSM2_INLINE void wideDestruct (PlanControl& control, const Short prong) noexcept; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE void wideForwardActive (Control& control, const Request request, const Short prong); - HFSM2_INLINE void wideForwardRequest (Control& control, const Request request, const Short prong); + HFSM2_INLINE void wideForwardActive (Control& control, const Request request, const Short prong) noexcept; + HFSM2_INLINE void wideForwardRequest (Control& control, const Request request, const Short prong) noexcept; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE void wideRequestChangeComposite (Control& control, const Request request); - HFSM2_INLINE void wideRequestChangeResumable (Control& control, const Request request, const Short prong); + HFSM2_INLINE void wideRequestChangeComposite (Control& control, const Request request ) noexcept; + HFSM2_INLINE void wideRequestChangeResumable (Control& control, const Request request, const Short prong) noexcept; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE void wideRequestRestart (Control& control, const Request request); - HFSM2_INLINE void wideRequestResume (Control& control, const Request request, const Short prong); + HFSM2_INLINE void wideRequestRestart (Control& control, const Request request ) noexcept; + HFSM2_INLINE void wideRequestResume (Control& control, const Request request, const Short prong) noexcept; #ifdef HFSM2_ENABLE_UTILITY_THEORY /* - HFSM2_INLINE void wideRequestUtilize (Control& control, const Request request); - HFSM2_INLINE void wideRequestRandomize (Control& control, const Request request); + HFSM2_INLINE void wideRequestUtilize (Control& control, const Request request) noexcept; + HFSM2_INLINE void wideRequestRandomize (Control& control, const Request request) noexcept; */ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE UP wideReportChangeComposite (Control& control); - HFSM2_INLINE UP wideReportChangeResumable (Control& control, const Short prong); - HFSM2_INLINE UP wideReportChangeUtilitarian (Control& control); - HFSM2_INLINE Utility wideReportChangeRandom (Control& control, Utility* const options, const Rank* const ranks, const Rank top); + HFSM2_INLINE UP wideReportChangeComposite (Control& control ) noexcept; + HFSM2_INLINE UP wideReportChangeResumable (Control& control, const Short prong ) noexcept; + HFSM2_INLINE UP wideReportChangeUtilitarian (Control& control ) noexcept; + HFSM2_INLINE Utility wideReportChangeRandom (Control& control, Utility* const options, const Rank* const ranks, const Rank top) noexcept; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE UP wideReportUtilize (Control& control); - HFSM2_INLINE Rank wideReportRank (Control& control, Rank* const ranks); - HFSM2_INLINE Utility wideReportRandomize (Control& control, Utility* const options, const Rank* const ranks, const Rank top); + HFSM2_INLINE UP wideReportUtilize (Control& control ) noexcept; + HFSM2_INLINE Rank wideReportRank (Control& control, Rank* const ranks ) noexcept; + HFSM2_INLINE Utility wideReportRandomize (Control& control, Utility* const options, const Rank* const ranks, const Rank top) noexcept; #endif // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE void wideChangeToRequested (PlanControl& control, const Short prong); + HFSM2_INLINE void wideChangeToRequested (PlanControl& control, const Short prong) noexcept; //---------------------------------------------------------------------- @@ -8576,11 +8520,11 @@ struct CS_ final { using WriteStream = typename Args::WriteStream; using ReadStream = typename Args::ReadStream; - HFSM2_INLINE void wideSaveActive (const Registry& registry, WriteStream& stream, const Short prong) const; - HFSM2_INLINE void wideSaveResumable (const Registry& registry, WriteStream& stream ) const; + HFSM2_INLINE void wideSaveActive (const Registry& registry, WriteStream& stream, const Short prong) const noexcept; + HFSM2_INLINE void wideSaveResumable (const Registry& registry, WriteStream& stream ) const noexcept; - HFSM2_INLINE void wideLoadRequested ( Registry& registry, ReadStream& stream, const Short prong) const; - HFSM2_INLINE void wideLoadResumable ( Registry& registry, ReadStream& stream ) const; + HFSM2_INLINE void wideLoadRequested ( Registry& registry, ReadStream& stream, const Short prong) const noexcept; + HFSM2_INLINE void wideLoadResumable ( Registry& registry, ReadStream& stream ) const noexcept; #endif // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -8594,7 +8538,7 @@ struct CS_ final { void wideGetNames(const Long parent, const RegionType region, const Short depth, - StructureStateInfos& stateInfos) const; + StructureStateInfos& stateInfos) const noexcept; #endif //---------------------------------------------------------------------- @@ -8652,76 +8596,77 @@ struct CS_ final { #ifdef HFSM2_EXPLICIT_MEMBER_SPECIALIZATION template - HFSM2_INLINE T& access() { return state.template access(); } + HFSM2_INLINE T& access() noexcept { return state.template access(); } template - HFSM2_INLINE const T& access() const { return state.template access(); } + HFSM2_INLINE const T& access() const noexcept { return state.template access(); } #endif // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE void wideRegister (Registry& registry, const Parent parent); + HFSM2_INLINE void wideRegister (Registry& registry, const Parent parent) noexcept; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE bool wideForwardEntryGuard (GuardControl& control, const Short prong); - HFSM2_INLINE bool wideEntryGuard (GuardControl& control, const Short prong); + HFSM2_INLINE bool wideForwardEntryGuard (GuardControl& control, const Short prong) noexcept; + HFSM2_INLINE bool wideEntryGuard (GuardControl& control, const Short prong) noexcept; - HFSM2_INLINE void wideConstruct (PlanControl& control, const Short prong); + HFSM2_INLINE void wideConstruct (PlanControl& control, const Short prong) noexcept; - HFSM2_INLINE void wideEnter (PlanControl& control, const Short prong); - HFSM2_INLINE void wideReenter (PlanControl& control, const Short prong); + HFSM2_INLINE void wideEnter (PlanControl& control, const Short prong) noexcept; + HFSM2_INLINE void wideReenter (PlanControl& control, const Short prong) noexcept; - HFSM2_INLINE Status wideUpdate (FullControl& control, const Short prong); + HFSM2_INLINE Status wideUpdate (FullControl& control, const Short prong) noexcept; template - HFSM2_INLINE Status wideReact (FullControl& control, const TEvent& event, const Short prong); + HFSM2_INLINE Status wideReact (FullControl& control, + const TEvent& event, const Short prong) noexcept; - HFSM2_INLINE bool wideForwardExitGuard (GuardControl& control, const Short prong); - HFSM2_INLINE bool wideExitGuard (GuardControl& control, const Short prong); + HFSM2_INLINE bool wideForwardExitGuard (GuardControl& control, const Short prong) noexcept; + HFSM2_INLINE bool wideExitGuard (GuardControl& control, const Short prong) noexcept; - HFSM2_INLINE void wideExit (PlanControl& control, const Short prong); + HFSM2_INLINE void wideExit (PlanControl& control, const Short prong) noexcept; - HFSM2_INLINE void wideDestruct (PlanControl& control, const Short prong); + HFSM2_INLINE void wideDestruct (PlanControl& control, const Short prong) noexcept; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE void wideForwardActive (Control& control, const Request request, const Short prong); - HFSM2_INLINE void wideForwardRequest (Control& control, const Request request, const Short prong); + HFSM2_INLINE void wideForwardActive (Control& control, const Request request, const Short prong) noexcept; + HFSM2_INLINE void wideForwardRequest (Control& control, const Request request, const Short prong) noexcept; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE void wideRequestChangeComposite (Control& control, const Request request); - HFSM2_INLINE void wideRequestChangeResumable (Control& control, const Request request, const Short prong); + HFSM2_INLINE void wideRequestChangeComposite (Control& control, const Request request ) noexcept; + HFSM2_INLINE void wideRequestChangeResumable (Control& control, const Request request, const Short prong) noexcept; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE void wideRequestRestart (Control& control, const Request request); - HFSM2_INLINE void wideRequestResume (Control& control, const Request request, const Short prong); + HFSM2_INLINE void wideRequestRestart (Control& control, const Request request ) noexcept; + HFSM2_INLINE void wideRequestResume (Control& control, const Request request, const Short prong) noexcept; #ifdef HFSM2_ENABLE_UTILITY_THEORY /* - HFSM2_INLINE void wideRequestUtilize (Control& control, const Request request); - HFSM2_INLINE void wideRequestRandomize (Control& control, const Request request); + HFSM2_INLINE void wideRequestUtilize (Control& control, const Request request) noexcept; + HFSM2_INLINE void wideRequestRandomize (Control& control, const Request request) noexcept; */ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE UP wideReportChangeComposite (Control& control); - HFSM2_INLINE UP wideReportChangeResumable (Control& control, const Short prong); - HFSM2_INLINE UP wideReportChangeUtilitarian (Control& control); - HFSM2_INLINE Utility wideReportChangeRandom (Control& control, Utility* const options, const Rank* const ranks, const Rank top); + HFSM2_INLINE UP wideReportChangeComposite (Control& control ) noexcept; + HFSM2_INLINE UP wideReportChangeResumable (Control& control, const Short prong ) noexcept; + HFSM2_INLINE UP wideReportChangeUtilitarian (Control& control ) noexcept; + HFSM2_INLINE Utility wideReportChangeRandom (Control& control, Utility* const options, const Rank* const ranks, const Rank top) noexcept; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE UP wideReportUtilize (Control& control); - HFSM2_INLINE Rank wideReportRank (Control& control, Rank* const ranks); - HFSM2_INLINE Utility wideReportRandomize (Control& control, Utility* const options, const Rank* const ranks, const Rank top); + HFSM2_INLINE UP wideReportUtilize (Control& control ) noexcept; + HFSM2_INLINE Rank wideReportRank (Control& control, Rank* const ranks ) noexcept; + HFSM2_INLINE Utility wideReportRandomize (Control& control, Utility* const options, const Rank* const ranks, const Rank top) noexcept; #endif // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE void wideChangeToRequested (PlanControl& control, const Short prong); + HFSM2_INLINE void wideChangeToRequested (PlanControl& control, const Short prong) noexcept; //---------------------------------------------------------------------- @@ -8729,11 +8674,11 @@ struct CS_ final { using WriteStream = typename Args::WriteStream; using ReadStream = typename Args::ReadStream; - HFSM2_INLINE void wideSaveActive (const Registry& registry, WriteStream& stream, const Short prong) const; - HFSM2_INLINE void wideSaveResumable (const Registry& registry, WriteStream& stream ) const; + HFSM2_INLINE void wideSaveActive (const Registry& registry, WriteStream& stream, const Short prong) const noexcept; + HFSM2_INLINE void wideSaveResumable (const Registry& registry, WriteStream& stream ) const noexcept; - HFSM2_INLINE void wideLoadRequested ( Registry& registry, ReadStream& stream, const Short prong) const; - HFSM2_INLINE void wideLoadResumable ( Registry& registry, ReadStream& stream ) const; + HFSM2_INLINE void wideLoadRequested ( Registry& registry, ReadStream& stream, const Short prong) const noexcept; + HFSM2_INLINE void wideLoadResumable ( Registry& registry, ReadStream& stream ) const noexcept; #endif // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -8747,7 +8692,7 @@ struct CS_ final { void wideGetNames(const Long parent, const RegionType region, const Short depth, - StructureStateInfos& stateInfos) const; + StructureStateInfos& stateInfos) const noexcept; #endif //---------------------------------------------------------------------- @@ -8770,7 +8715,7 @@ namespace detail { template template T& -CS_::access() { +CS_::access() noexcept { return contains() ? lHalf.template access() : rHalf.template access(); @@ -8781,7 +8726,7 @@ CS_::access() { template template const T& -CS_::access() const { +CS_::access() const noexcept { return contains() ? lHalf.template access() : rHalf.template access(); @@ -8794,7 +8739,7 @@ CS_::access() const { template void CS_::wideRegister(Registry& registry, - const Parent parent) + const Parent parent) noexcept { lHalf.wideRegister(registry, Parent{parent.forkId, L_PRONG}); rHalf.wideRegister(registry, Parent{parent.forkId, R_PRONG}); @@ -8805,7 +8750,7 @@ CS_::wideRegister(Registry& registry, template bool CS_::wideForwardEntryGuard(GuardControl& control, - const Short prong) + const Short prong) noexcept { HFSM2_ASSERT(prong != INVALID_SHORT); @@ -8816,11 +8761,12 @@ CS_::wideForwardEntryGuard(GuardControl& control, } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +// COMMON template bool CS_::wideEntryGuard(GuardControl& control, - const Short prong) + const Short prong) noexcept { HFSM2_ASSERT(prong != INVALID_SHORT); @@ -8835,7 +8781,7 @@ CS_::wideEntryGuard(GuardControl& control, template void CS_::wideConstruct(PlanControl& control, - const Short prong) + const Short prong) noexcept { HFSM2_ASSERT(prong != INVALID_SHORT); @@ -8850,7 +8796,7 @@ CS_::wideConstruct(PlanControl& control, template void CS_::wideEnter(PlanControl& control, - const Short prong) + const Short prong) noexcept { HFSM2_ASSERT(prong != INVALID_SHORT); @@ -8865,7 +8811,7 @@ CS_::wideEnter(PlanControl& control, template void CS_::wideReenter(PlanControl& control, - const Short prong) + const Short prong) noexcept { HFSM2_ASSERT(prong != INVALID_SHORT); @@ -8880,7 +8826,7 @@ CS_::wideReenter(PlanControl& control, template Status CS_::wideUpdate(FullControl& control, - const Short prong) + const Short prong) noexcept { HFSM2_ASSERT(prong != INVALID_SHORT); @@ -8896,7 +8842,7 @@ template Status CS_::wideReact(FullControl& control, const TEvent& event, - const Short prong) + const Short prong) noexcept { HFSM2_ASSERT(prong != INVALID_SHORT); @@ -8910,7 +8856,7 @@ CS_::wideReact(FullControl& control, template bool CS_::wideForwardExitGuard(GuardControl& control, - const Short prong) + const Short prong) noexcept { HFSM2_ASSERT(prong != INVALID_SHORT); @@ -8921,11 +8867,12 @@ CS_::wideForwardExitGuard(GuardControl& control, } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +// COMMON template bool CS_::wideExitGuard(GuardControl& control, - const Short prong) + const Short prong) noexcept { HFSM2_ASSERT(prong != INVALID_SHORT); @@ -8940,7 +8887,7 @@ CS_::wideExitGuard(GuardControl& control, template void CS_::wideExit(PlanControl& control, - const Short prong) + const Short prong) noexcept { HFSM2_ASSERT(prong != INVALID_SHORT); @@ -8955,7 +8902,7 @@ CS_::wideExit(PlanControl& control, template void CS_::wideDestruct(PlanControl& control, - const Short prong) + const Short prong) noexcept { HFSM2_ASSERT(prong != INVALID_SHORT); @@ -8971,7 +8918,7 @@ template void CS_::wideForwardActive(Control& control, const Request request, - const Short prong) + const Short prong) noexcept { HFSM2_ASSERT(prong != INVALID_SHORT); @@ -8987,7 +8934,7 @@ template void CS_::wideForwardRequest(Control& control, const Request request, - const Short prong) + const Short prong) noexcept { HFSM2_ASSERT(prong != INVALID_SHORT); @@ -9002,7 +8949,7 @@ CS_::wideForwardRequest(Control& control, template void CS_::wideRequestChangeComposite(Control& control, - const Request request) + const Request request) noexcept { lHalf.wideRequestChangeComposite(control, request); } @@ -9013,7 +8960,7 @@ template void CS_::wideRequestChangeResumable(Control& control, const Request request, - const Short prong) + const Short prong) noexcept { HFSM2_ASSERT(prong != INVALID_SHORT); @@ -9028,7 +8975,7 @@ CS_::wideRequestChangeResumable(Control& control, template void CS_::wideRequestRestart(Control& control, - const Request request) + const Request request) noexcept { lHalf.wideRequestRestart(control, request); } @@ -9039,7 +8986,7 @@ template void CS_::wideRequestResume(Control& control, const Request request, - const Short prong) + const Short prong) noexcept { HFSM2_ASSERT(prong != INVALID_SHORT); @@ -9055,7 +9002,7 @@ CS_::wideRequestResume(Control& control, template typename TA::UP -CS_::wideReportUtilize(Control& control) { +CS_::wideReportUtilize(Control& control) noexcept { const UP l = lHalf.wideReportUtilize(control); const UP r = rHalf.wideReportUtilize(control); @@ -9068,7 +9015,7 @@ CS_::wideReportUtilize(Control& control) { template typename TA::Rank CS_::wideReportRank(Control& control, - Rank* const ranks) + Rank* const ranks) noexcept { HFSM2_ASSERT(ranks); @@ -9086,7 +9033,7 @@ typename TA::Utility CS_::wideReportRandomize(Control& control, Utility* const options, const Rank* const ranks, - const Rank top) + const Rank top) noexcept { HFSM2_ASSERT(options && ranks); @@ -9100,7 +9047,7 @@ CS_::wideReportRandomize(Control& control, template typename TA::UP -CS_::wideReportChangeComposite(Control& control) { +CS_::wideReportChangeComposite(Control& control) noexcept { return lHalf.wideReportChangeComposite(control); } @@ -9109,7 +9056,7 @@ CS_::wideReportChangeComposite(Control& control) { template typename TA::UP CS_::wideReportChangeResumable(Control& control, - const Short prong) + const Short prong) noexcept { HFSM2_ASSERT(prong != INVALID_SHORT); @@ -9123,7 +9070,7 @@ CS_::wideReportChangeResumable(Control& control, template typename TA::UP -CS_::wideReportChangeUtilitarian(Control& control) { +CS_::wideReportChangeUtilitarian(Control& control) noexcept { const UP l = lHalf.wideReportChangeUtilitarian(control); const UP r = rHalf.wideReportChangeUtilitarian(control); @@ -9138,7 +9085,7 @@ typename TA::Utility CS_::wideReportChangeRandom(Control& control, Utility* const options, const Rank* const ranks, - const Rank top) + const Rank top) noexcept { HFSM2_ASSERT(options && ranks); @@ -9151,11 +9098,12 @@ CS_::wideReportChangeRandom(Control& control, #endif //------------------------------------------------------------------------------ +// COMMON template void CS_::wideChangeToRequested(PlanControl& control, - const Short prong) + const Short prong) noexcept { HFSM2_ASSERT(prong != INVALID_SHORT); @@ -9173,7 +9121,7 @@ template void CS_::wideSaveActive(const Registry& registry, WriteStream& stream, - const Short prong) const + const Short prong) const noexcept { HFSM2_ASSERT(prong != INVALID_SHORT); @@ -9191,7 +9139,7 @@ CS_::wideSaveActive(const Registry& registry, template void CS_::wideSaveResumable(const Registry& registry, - WriteStream& stream) const + WriteStream& stream) const noexcept { lHalf.wideSaveResumable(registry, stream); rHalf.wideSaveResumable(registry, stream); @@ -9203,7 +9151,7 @@ template void CS_::wideLoadRequested(Registry& registry, ReadStream& stream, - const Short prong) const + const Short prong) const noexcept { HFSM2_ASSERT(prong != INVALID_SHORT); @@ -9221,7 +9169,7 @@ CS_::wideLoadRequested(Registry& registry, template void CS_::wideLoadResumable(Registry& registry, - ReadStream& stream) const + ReadStream& stream) const noexcept { lHalf.wideLoadResumable(registry, stream); rHalf.wideLoadResumable(registry, stream); @@ -9238,7 +9186,7 @@ void CS_::wideGetNames(const Long parent, const RegionType /*region*/, const Short depth, - StructureStateInfos& _stateInfos) const + StructureStateInfos& _stateInfos) const noexcept { lHalf.wideGetNames(parent, StructureStateInfo::RegionType::COMPOSITE, depth, _stateInfos); rHalf.wideGetNames(parent, StructureStateInfo::RegionType::COMPOSITE, depth, _stateInfos); @@ -9258,7 +9206,7 @@ namespace detail { template void CS_::wideRegister(Registry& registry, - const Parent parent) + const Parent parent) noexcept { state.deepRegister(registry, Parent{parent.forkId, PRONG_INDEX}); } @@ -9268,7 +9216,7 @@ CS_::wideRegister(Registry& registry, template bool CS_::wideForwardEntryGuard(GuardControl& control, - const Short HFSM2_IF_ASSERT(prong)) + const Short HFSM2_IF_ASSERT(prong)) noexcept { HFSM2_ASSERT(prong == PRONG_INDEX); @@ -9276,11 +9224,12 @@ CS_::wideForwardEntryGuard(GuardControl& control, } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +// COMMON template bool CS_::wideEntryGuard(GuardControl& control, - const Short HFSM2_IF_ASSERT(prong)) + const Short HFSM2_IF_ASSERT(prong)) noexcept { HFSM2_ASSERT(prong == PRONG_INDEX); @@ -9292,7 +9241,7 @@ CS_::wideEntryGuard(GuardControl& control, template void CS_::wideConstruct(PlanControl& control, - const Short HFSM2_IF_ASSERT(prong)) + const Short HFSM2_IF_ASSERT(prong)) noexcept { HFSM2_ASSERT(prong == PRONG_INDEX); @@ -9304,7 +9253,7 @@ CS_::wideConstruct(PlanControl& control, template void CS_::wideEnter(PlanControl& control, - const Short HFSM2_IF_ASSERT(prong)) + const Short HFSM2_IF_ASSERT(prong)) noexcept { HFSM2_ASSERT(prong == PRONG_INDEX); @@ -9316,7 +9265,7 @@ CS_::wideEnter(PlanControl& control, template void CS_::wideReenter(PlanControl& control, - const Short HFSM2_IF_ASSERT(prong)) + const Short HFSM2_IF_ASSERT(prong)) noexcept { HFSM2_ASSERT(prong == PRONG_INDEX); @@ -9328,7 +9277,7 @@ CS_::wideReenter(PlanControl& control, template Status CS_::wideUpdate(FullControl& control, - const Short HFSM2_IF_ASSERT(prong)) + const Short HFSM2_IF_ASSERT(prong)) noexcept { HFSM2_ASSERT(prong == PRONG_INDEX); @@ -9342,7 +9291,7 @@ template Status CS_::wideReact(FullControl& control, const TEvent& event, - const Short HFSM2_IF_ASSERT(prong)) + const Short HFSM2_IF_ASSERT(prong)) noexcept { HFSM2_ASSERT(prong == PRONG_INDEX); @@ -9354,7 +9303,7 @@ CS_::wideReact(FullControl& control, template bool CS_::wideForwardExitGuard(GuardControl& control, - const Short HFSM2_IF_ASSERT(prong)) + const Short HFSM2_IF_ASSERT(prong)) noexcept { HFSM2_ASSERT(prong == PRONG_INDEX); @@ -9362,11 +9311,12 @@ CS_::wideForwardExitGuard(GuardControl& control, } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +// COMMON template bool CS_::wideExitGuard(GuardControl& control, - const Short HFSM2_IF_ASSERT(prong)) + const Short HFSM2_IF_ASSERT(prong)) noexcept { HFSM2_ASSERT(prong == PRONG_INDEX); @@ -9378,7 +9328,7 @@ CS_::wideExitGuard(GuardControl& control, template void CS_::wideExit(PlanControl& control, - const Short HFSM2_IF_ASSERT(prong)) + const Short HFSM2_IF_ASSERT(prong)) noexcept { HFSM2_ASSERT(prong == PRONG_INDEX); @@ -9390,7 +9340,7 @@ CS_::wideExit(PlanControl& control, template void CS_::wideDestruct(PlanControl& control, - const Short HFSM2_IF_ASSERT(prong)) + const Short HFSM2_IF_ASSERT(prong)) noexcept { HFSM2_ASSERT(prong == PRONG_INDEX); @@ -9403,7 +9353,7 @@ template void CS_::wideForwardActive(Control& control, const Request request, - const Short HFSM2_IF_ASSERT(prong)) + const Short HFSM2_IF_ASSERT(prong)) noexcept { HFSM2_ASSERT(prong == PRONG_INDEX); @@ -9416,7 +9366,7 @@ template void CS_::wideForwardRequest(Control& control, const Request request, - const Short HFSM2_IF_ASSERT(prong)) + const Short HFSM2_IF_ASSERT(prong)) noexcept { HFSM2_ASSERT(prong == PRONG_INDEX); @@ -9428,7 +9378,7 @@ CS_::wideForwardRequest(Control& control, template void CS_::wideRequestChangeComposite(Control& control, - const Request request) + const Request request) noexcept { state.deepRequestChange(control, request); } @@ -9439,7 +9389,7 @@ template void CS_::wideRequestChangeResumable(Control& control, const Request request, - const Short HFSM2_IF_ASSERT(prong)) + const Short HFSM2_IF_ASSERT(prong)) noexcept { HFSM2_ASSERT(prong == PRONG_INDEX); @@ -9451,7 +9401,7 @@ CS_::wideRequestChangeResumable(Control& control, template void CS_::wideRequestRestart(Control& control, - const Request request) + const Request request) noexcept { state.deepRequestRestart(control, request); } @@ -9462,7 +9412,7 @@ template void CS_::wideRequestResume(Control& control, const Request request, - const Short HFSM2_IF_ASSERT(prong)) + const Short HFSM2_IF_ASSERT(prong)) noexcept { HFSM2_ASSERT(prong == PRONG_INDEX); @@ -9475,7 +9425,7 @@ CS_::wideRequestResume(Control& control, template typename TA::UP -CS_::wideReportUtilize(Control& control) { +CS_::wideReportUtilize(Control& control) noexcept { return state.deepReportUtilize(control); } @@ -9484,7 +9434,7 @@ CS_::wideReportUtilize(Control& control) { template typename TA::Rank CS_::wideReportRank(Control& control, - Rank* const ranks) + Rank* const ranks) noexcept { HFSM2_ASSERT(ranks); @@ -9500,7 +9450,7 @@ typename TA::Utility CS_::wideReportRandomize(Control& control, Utility* const options, const Rank* const ranks, - const Rank top) + const Rank top) noexcept { HFSM2_ASSERT(options && ranks); @@ -9514,7 +9464,7 @@ CS_::wideReportRandomize(Control& control, template typename TA::UP -CS_::wideReportChangeComposite(Control& control) { +CS_::wideReportChangeComposite(Control& control) noexcept { return state.deepReportChange(control); } @@ -9523,7 +9473,7 @@ CS_::wideReportChangeComposite(Control& control) { template typename TA::UP CS_::wideReportChangeResumable(Control& control, - const Short HFSM2_IF_ASSERT(prong)) + const Short HFSM2_IF_ASSERT(prong)) noexcept { HFSM2_ASSERT(prong == PRONG_INDEX); @@ -9534,7 +9484,7 @@ CS_::wideReportChangeResumable(Control& control, template typename TA::UP -CS_::wideReportChangeUtilitarian(Control& control) { +CS_::wideReportChangeUtilitarian(Control& control) noexcept { return state.deepReportChange(control); } @@ -9545,7 +9495,7 @@ typename TA::Utility CS_::wideReportChangeRandom(Control& control, Utility* const options, const Rank* const ranks, - const Rank top) + const Rank top) noexcept { HFSM2_ASSERT(options && ranks); @@ -9562,7 +9512,7 @@ CS_::wideReportChangeRandom(Control& control, template void CS_::wideChangeToRequested(PlanControl& control, - const Short HFSM2_IF_ASSERT(prong)) + const Short HFSM2_IF_ASSERT(prong)) noexcept { HFSM2_ASSERT(prong == PRONG_INDEX); @@ -9577,7 +9527,7 @@ template void CS_::wideSaveActive(const Registry& registry, WriteStream& stream, - const Short HFSM2_IF_ASSERT(prong)) const + const Short HFSM2_IF_ASSERT(prong)) const noexcept { HFSM2_ASSERT(prong == PRONG_INDEX); @@ -9589,7 +9539,7 @@ CS_::wideSaveActive(const Registry& registry, template void CS_::wideSaveResumable(const Registry& registry, - WriteStream& stream) const + WriteStream& stream) const noexcept { state.deepSaveResumable(registry, stream); } @@ -9600,7 +9550,7 @@ template void CS_::wideLoadRequested(Registry& registry, ReadStream& stream, - const Short HFSM2_IF_ASSERT(prong)) const + const Short HFSM2_IF_ASSERT(prong)) const noexcept { HFSM2_ASSERT(prong == PRONG_INDEX); @@ -9612,7 +9562,7 @@ CS_::wideLoadRequested(Registry& registry, template void CS_::wideLoadResumable(Registry& registry, - ReadStream& stream) const + ReadStream& stream) const noexcept { state.deepLoadResumable(registry, stream); } @@ -9628,7 +9578,7 @@ void CS_::wideGetNames(const Long parent, const RegionType /*region*/, const Short depth, - StructureStateInfos& _stateInfos) const + StructureStateInfos& _stateInfos) const noexcept { state.deepGetNames(parent, StructureStateInfo::RegionType::COMPOSITE, depth, _stateInfos); } @@ -9709,124 +9659,125 @@ struct C_ final { #ifdef HFSM2_EXPLICIT_MEMBER_SPECIALIZATION template struct Accessor { - HFSM2_INLINE static T& get( C_& c) { return c._subStates.template access(); } - HFSM2_INLINE static const T& get(const C_& c) { return c._subStates.template access(); } + HFSM2_INLINE static T& get( C_& c) noexcept { return c._subStates.template access(); } + HFSM2_INLINE static const T& get(const C_& c) noexcept { return c._subStates.template access(); } }; template <> struct Accessor { - HFSM2_INLINE static Head& get( C_& c) { return c._headState._headBox.get(); } - HFSM2_INLINE static const Head& get(const C_& c) { return c._headState._headBox.get(); } + HFSM2_INLINE static Head& get( C_& c) noexcept { return c._headState._headBox.get(); } + HFSM2_INLINE static const Head& get(const C_& c) noexcept { return c._headState._headBox.get(); } }; template - HFSM2_INLINE T& access() { return Accessor::get(*this); } + HFSM2_INLINE T& access() noexcept { return Accessor::get(*this); } template - HFSM2_INLINE const T& access() const { return Accessor::get(*this); } + HFSM2_INLINE const T& access() const noexcept { return Accessor::get(*this); } #endif //---------------------------------------------------------------------- #ifdef HFSM2_ENABLE_SERIALIZATION - HFSM2_INLINE Short compoRequested (const Registry& registry) const { return registry.compoRequested[COMPO_INDEX]; } - HFSM2_INLINE Short& compoRequested ( Registry& registry) const { return registry.compoRequested[COMPO_INDEX]; } + HFSM2_INLINE Short compoRequested (const Registry& registry) const noexcept { return registry.compoRequested[COMPO_INDEX]; } + HFSM2_INLINE Short& compoRequested ( Registry& registry) const noexcept { return registry.compoRequested[COMPO_INDEX]; } - HFSM2_INLINE Short compoActive (const Registry& registry) const { return registry.compoActive [COMPO_INDEX]; } - HFSM2_INLINE Short& compoActive ( Registry& registry) const { return registry.compoActive [COMPO_INDEX]; } + HFSM2_INLINE Short compoActive (const Registry& registry) const noexcept { return registry.compoActive [COMPO_INDEX]; } + HFSM2_INLINE Short& compoActive ( Registry& registry) const noexcept { return registry.compoActive [COMPO_INDEX]; } - HFSM2_INLINE Short compoResumable (const Registry& registry) const { return registry.compoResumable[COMPO_INDEX]; } - HFSM2_INLINE Short& compoResumable ( Registry& registry) const { return registry.compoResumable[COMPO_INDEX]; } + HFSM2_INLINE Short compoResumable (const Registry& registry) const noexcept { return registry.compoResumable[COMPO_INDEX]; } + HFSM2_INLINE Short& compoResumable ( Registry& registry) const noexcept { return registry.compoResumable[COMPO_INDEX]; } #endif - HFSM2_INLINE Short& compoRequested (Control& control) const { return control._registry.compoRequested[COMPO_INDEX]; } - HFSM2_INLINE Short& compoActive (Control& control) const { return control._registry.compoActive [COMPO_INDEX]; } - HFSM2_INLINE Short& compoResumable (Control& control) const { return control._registry.compoResumable[COMPO_INDEX]; } + HFSM2_INLINE Short& compoRequested (Control& control) const noexcept { return control._registry.compoRequested[COMPO_INDEX]; } + HFSM2_INLINE Short& compoActive (Control& control) const noexcept { return control._registry.compoActive [COMPO_INDEX]; } + HFSM2_INLINE Short& compoResumable (Control& control) const noexcept { return control._registry.compoResumable[COMPO_INDEX]; } - HFSM2_INLINE bool compoRemain (Control& control) const { return control._registry.compoRemains.template get(); } + HFSM2_INLINE bool compoRemain (Control& control) const noexcept { return control._registry.compoRemains.template get(); } #ifdef HFSM2_ENABLE_UTILITY_THEORY HFSM2_INLINE Short resolveRandom (Control& control, const Utility(& options)[Info::WIDTH], const Utility sum, - const Rank (& ranks) [Info::WIDTH], const Rank top) const; + const Rank (& ranks) [Info::WIDTH], const Rank top) const noexcept; #endif - HFSM2_INLINE void deepRegister (Registry& registry, const Parent parent); + HFSM2_INLINE void deepRegister (Registry& registry, const Parent parent) noexcept; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE bool deepForwardEntryGuard (GuardControl& control); - HFSM2_INLINE bool deepEntryGuard (GuardControl& control); + HFSM2_INLINE bool deepForwardEntryGuard (GuardControl& control) noexcept; + HFSM2_INLINE bool deepEntryGuard (GuardControl& control) noexcept; - HFSM2_INLINE void deepConstruct (PlanControl& control); + HFSM2_INLINE void deepConstruct (PlanControl& control) noexcept; - HFSM2_INLINE void deepEnter (PlanControl& control); - HFSM2_INLINE void deepReenter (PlanControl& control); + HFSM2_INLINE void deepEnter (PlanControl& control) noexcept; + HFSM2_INLINE void deepReenter (PlanControl& control) noexcept; - HFSM2_INLINE Status deepUpdate (FullControl& control); + HFSM2_INLINE Status deepUpdate (FullControl& control) noexcept; template - HFSM2_INLINE Status deepReact (FullControl& control, const TEvent& event); + HFSM2_INLINE Status deepReact (FullControl& control, + const TEvent& event) noexcept; - HFSM2_INLINE bool deepForwardExitGuard (GuardControl& control); - HFSM2_INLINE bool deepExitGuard (GuardControl& control); + HFSM2_INLINE bool deepForwardExitGuard (GuardControl& control) noexcept; + HFSM2_INLINE bool deepExitGuard (GuardControl& control) noexcept; - HFSM2_INLINE void deepExit (PlanControl& control); + HFSM2_INLINE void deepExit (PlanControl& control) noexcept; - HFSM2_INLINE void deepDestruct (PlanControl& control); + HFSM2_INLINE void deepDestruct (PlanControl& control) noexcept; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE void deepForwardActive (Control& control, const Request request); - HFSM2_INLINE void deepForwardRequest (Control& control, const Request request); + HFSM2_INLINE void deepForwardActive (Control& control, const Request request) noexcept; + HFSM2_INLINE void deepForwardRequest (Control& control, const Request request) noexcept; - HFSM2_INLINE void deepRequest (Control& control, const Request request); + HFSM2_INLINE void deepRequest (Control& control, const Request request) noexcept; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #ifdef HFSM2_EXPLICIT_MEMBER_SPECIALIZATION template - HFSM2_INLINE void deepRequestChange (Control& control, const Request request, const Short = INVALID_SHORT); + HFSM2_INLINE void deepRequestChange (Control& control, const Request request, const Short = INVALID_SHORT) noexcept; template <> - HFSM2_INLINE void deepRequestChange (Control& control, const Request request, const Short) { deepRequestChangeComposite (control, request); } + HFSM2_INLINE void deepRequestChange (Control& control, const Request request, const Short) noexcept { deepRequestChangeComposite (control, request); } template <> - HFSM2_INLINE void deepRequestChange (Control& control, const Request request, const Short) { deepRequestChangeResumable (control, request); } + HFSM2_INLINE void deepRequestChange (Control& control, const Request request, const Short) noexcept { deepRequestChangeResumable (control, request); } #ifdef HFSM2_ENABLE_UTILITY_THEORY template <> - HFSM2_INLINE void deepRequestChange(Control& control, const Request request, const Short) { deepRequestChangeUtilitarian(control, request); } + HFSM2_INLINE void deepRequestChange(Control& control, const Request request, const Short) noexcept { deepRequestChangeUtilitarian(control, request); } template <> - HFSM2_INLINE void deepRequestChange (Control& control, const Request request, const Short) { deepRequestChangeRandom (control, request); } + HFSM2_INLINE void deepRequestChange (Control& control, const Request request, const Short) noexcept { deepRequestChangeRandom (control, request); } #endif #else - HFSM2_INLINE void deepRequestChange (Control& control, const Request request); + HFSM2_INLINE void deepRequestChange (Control& control, const Request request) noexcept; #endif - HFSM2_INLINE void deepRequestChangeComposite (Control& control, const Request request); - HFSM2_INLINE void deepRequestChangeResumable (Control& control, const Request request); + HFSM2_INLINE void deepRequestChangeComposite (Control& control, const Request request) noexcept; + HFSM2_INLINE void deepRequestChangeResumable (Control& control, const Request request) noexcept; #ifdef HFSM2_ENABLE_UTILITY_THEORY - HFSM2_INLINE void deepRequestChangeUtilitarian (Control& control, const Request request); - HFSM2_INLINE void deepRequestChangeRandom (Control& control, const Request request); + HFSM2_INLINE void deepRequestChangeUtilitarian (Control& control, const Request request) noexcept; + HFSM2_INLINE void deepRequestChangeRandom (Control& control, const Request request) noexcept; #endif // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE void deepRequestRestart (Control& control, const Request request); - HFSM2_INLINE void deepRequestResume (Control& control, const Request request); + HFSM2_INLINE void deepRequestRestart (Control& control, const Request request) noexcept; + HFSM2_INLINE void deepRequestResume (Control& control, const Request request) noexcept; #ifdef HFSM2_ENABLE_UTILITY_THEORY - HFSM2_INLINE void deepRequestUtilize (Control& control, const Request request); - HFSM2_INLINE void deepRequestRandomize (Control& control, const Request request); + HFSM2_INLINE void deepRequestUtilize (Control& control, const Request request) noexcept; + HFSM2_INLINE void deepRequestRandomize (Control& control, const Request request) noexcept; #endif // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -9835,42 +9786,42 @@ struct C_ final { #ifdef HFSM2_EXPLICIT_MEMBER_SPECIALIZATION template - HFSM2_INLINE UP deepReportChange (Control& control); + HFSM2_INLINE UP deepReportChange (Control& control) noexcept; template <> - HFSM2_INLINE UP deepReportChange (Control& control) { return deepReportChangeComposite (control); } + HFSM2_INLINE UP deepReportChange (Control& control) noexcept { return deepReportChangeComposite (control); } template <> - HFSM2_INLINE UP deepReportChange (Control& control) { return deepReportChangeResumable (control); } + HFSM2_INLINE UP deepReportChange (Control& control) noexcept { return deepReportChangeResumable (control); } template <> - HFSM2_INLINE UP deepReportChange (Control& control) { return deepReportChangeUtilitarian(control); } + HFSM2_INLINE UP deepReportChange (Control& control) noexcept { return deepReportChangeUtilitarian(control); } template <> - HFSM2_INLINE UP deepReportChange (Control& control) { return deepReportChangeRandom (control); } + HFSM2_INLINE UP deepReportChange (Control& control) noexcept { return deepReportChangeRandom (control); } #else - HFSM2_INLINE UP deepReportChange (Control& control); + HFSM2_INLINE UP deepReportChange (Control& control) noexcept; #endif - HFSM2_INLINE UP deepReportChangeComposite (Control& control); - HFSM2_INLINE UP deepReportChangeResumable (Control& control); - HFSM2_INLINE UP deepReportChangeUtilitarian (Control& control); - HFSM2_INLINE UP deepReportChangeRandom (Control& control); + HFSM2_INLINE UP deepReportChangeComposite (Control& control) noexcept; + HFSM2_INLINE UP deepReportChangeResumable (Control& control) noexcept; + HFSM2_INLINE UP deepReportChangeUtilitarian (Control& control) noexcept; + HFSM2_INLINE UP deepReportChangeRandom (Control& control) noexcept; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE UP deepReportUtilize (Control& control); - HFSM2_INLINE Rank deepReportRank (Control& control); - HFSM2_INLINE Utility deepReportRandomize (Control& control); + HFSM2_INLINE UP deepReportUtilize (Control& control) noexcept; + HFSM2_INLINE Rank deepReportRank (Control& control) noexcept; + HFSM2_INLINE Utility deepReportRandomize (Control& control) noexcept; #endif // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE void deepChangeToRequested (PlanControl& control); + HFSM2_INLINE void deepChangeToRequested (PlanControl& control) noexcept; //---------------------------------------------------------------------- @@ -9878,11 +9829,11 @@ struct C_ final { using WriteStream = typename Args::WriteStream; using ReadStream = typename Args::ReadStream; - HFSM2_INLINE void deepSaveActive (const Registry& registry, WriteStream& stream) const; - HFSM2_INLINE void deepSaveResumable (const Registry& registry, WriteStream& stream) const; + HFSM2_INLINE void deepSaveActive (const Registry& registry, WriteStream& stream) const noexcept; + HFSM2_INLINE void deepSaveResumable (const Registry& registry, WriteStream& stream) const noexcept; - HFSM2_INLINE void deepLoadRequested ( Registry& registry, ReadStream& stream) const; - HFSM2_INLINE void deepLoadResumable ( Registry& registry, ReadStream& stream) const; + HFSM2_INLINE void deepLoadRequested ( Registry& registry, ReadStream& stream) const noexcept; + HFSM2_INLINE void deepLoadResumable ( Registry& registry, ReadStream& stream) const noexcept; #endif // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -9896,7 +9847,7 @@ struct C_ final { void deepGetNames(const Long parent, const RegionType region, const Short depth, - StructureStateInfos& stateInfos) const; + StructureStateInfos& stateInfos) const noexcept; #endif //---------------------------------------------------------------------- @@ -9925,7 +9876,7 @@ C_::resolveRandom(Control& control, const Utility(& options)[Info::WIDTH], const Utility sum, const Rank(& ranks)[Info::WIDTH], - const Rank top) const + const Rank top) const noexcept { const Utility random = control._rng.next(); HFSM2_ASSERT(0.0f <= random && random < 1.0f); @@ -9956,7 +9907,7 @@ C_::resolveRandom(Control& control, template void C_::deepRegister(Registry& registry, - const Parent parent) + const Parent parent) noexcept { registry.compoParents[COMPO_INDEX] = parent; @@ -9968,7 +9919,7 @@ C_::deepRegister(Registry& registry, template bool -C_::deepForwardEntryGuard(GuardControl& control) { +C_::deepForwardEntryGuard(GuardControl& control) noexcept { const Short active = compoActive (control); const Short requested = compoRequested(control); @@ -9986,7 +9937,7 @@ C_::deepForwardEntryGuard(GuardControl& control) { template bool -C_::deepEntryGuard(GuardControl& control) { +C_::deepEntryGuard(GuardControl& control) noexcept { const Short requested = compoRequested(control); HFSM2_ASSERT(requested != INVALID_SHORT); @@ -10000,7 +9951,7 @@ C_::deepEntryGuard(GuardControl& control) { template void -C_::deepConstruct(PlanControl& control) { +C_::deepConstruct(PlanControl& control) noexcept { Short& active = compoActive (control); Short& resumable = compoResumable(control); Short& requested = compoRequested(control); @@ -10023,7 +9974,7 @@ C_::deepConstruct(PlanControl& control) { template void -C_::deepEnter(PlanControl& control) { +C_::deepEnter(PlanControl& control) noexcept { const Short& active = compoActive(control); HFSM2_ASSERT(active != INVALID_SHORT); @@ -10037,7 +9988,7 @@ C_::deepEnter(PlanControl& control) { template void -C_::deepReenter(PlanControl& control) { +C_::deepReenter(PlanControl& control) noexcept { Short& active = compoActive (control); Short& resumable = compoResumable(control); Short& requested = compoRequested(control); @@ -10069,7 +10020,7 @@ C_::deepReenter(PlanControl& control) { template Status -C_::deepUpdate(FullControl& control) { +C_::deepUpdate(FullControl& control) noexcept { const Short active = compoActive(control); HFSM2_ASSERT(active != INVALID_SHORT); @@ -10103,7 +10054,7 @@ template template Status C_::deepReact(FullControl& control, - const TEvent& event) + const TEvent& event) noexcept { const Short active = compoActive(control); HFSM2_ASSERT(active != INVALID_SHORT); @@ -10137,7 +10088,7 @@ C_::deepReact(FullControl& control, template bool -C_::deepForwardExitGuard(GuardControl& control) { +C_::deepForwardExitGuard(GuardControl& control) noexcept { const Short active = compoActive(control); HFSM2_ASSERT(active != INVALID_SHORT); @@ -10153,7 +10104,7 @@ C_::deepForwardExitGuard(GuardControl& control) { template bool -C_::deepExitGuard(GuardControl& control) { +C_::deepExitGuard(GuardControl& control) noexcept { const Short active = compoActive(control); HFSM2_ASSERT(active != INVALID_SHORT); @@ -10167,7 +10118,7 @@ C_::deepExitGuard(GuardControl& control) { template void -C_::deepExit(PlanControl& control) { +C_::deepExit(PlanControl& control) noexcept { Short& active = compoActive(control); HFSM2_ASSERT(active != INVALID_SHORT); @@ -10179,7 +10130,7 @@ C_::deepExit(PlanControl& control) { template void -C_::deepDestruct(PlanControl& control) { +C_::deepDestruct(PlanControl& control) noexcept { Short& active = compoActive (control); Short& resumable = compoResumable(control); @@ -10202,7 +10153,7 @@ C_::deepDestruct(PlanControl& control) { template void C_::deepForwardActive(Control& control, - const Request request) + const Request request) noexcept { HFSM2_ASSERT(control._registry.isActive(HEAD_ID)); @@ -10221,7 +10172,7 @@ C_::deepForwardActive(Control& control, template void C_::deepForwardRequest(Control& control, - const Request request) + const Request request) noexcept { HFSM2_IF_TRANSITION_HISTORY(control.pinLastTransition(HEAD_ID, request.index)); @@ -10238,7 +10189,7 @@ C_::deepForwardRequest(Control& control, template void C_::deepRequest(Control& control, - const Request request) + const Request request) noexcept { switch (request.type) { case TransitionType::CHANGE: @@ -10277,7 +10228,7 @@ C_::deepRequest(Control& control, template void C_::deepRequestChange(Control& control, - const Request request) + const Request request) noexcept { switch (STRATEGY) { case Strategy::Composite: @@ -10312,7 +10263,7 @@ C_::deepRequestChange(Control& control, template void C_::deepRequestChangeComposite(Control& control, - const Request request) + const Request request) noexcept { HFSM2_IF_TRANSITION_HISTORY(control.pinLastTransition(HEAD_ID, request.index)); @@ -10328,7 +10279,7 @@ C_::deepRequestChangeComposite(Control& control, template void C_::deepRequestChangeResumable(Control& control, - const Request request) + const Request request) noexcept { HFSM2_IF_TRANSITION_HISTORY(control.pinLastTransition(HEAD_ID, request.index)); @@ -10348,7 +10299,7 @@ C_::deepRequestChangeResumable(Control& control, template void C_::deepRequestChangeUtilitarian(Control& control, - const Request HFSM2_IF_TRANSITION_HISTORY(request)) + const Request HFSM2_IF_TRANSITION_HISTORY(request)) noexcept { HFSM2_IF_TRANSITION_HISTORY(control.pinLastTransition(HEAD_ID, request.index)); @@ -10366,7 +10317,7 @@ C_::deepRequestChangeUtilitarian(Control& control, template void C_::deepRequestChangeRandom(Control& control, - const Request HFSM2_IF_TRANSITION_HISTORY(request)) + const Request HFSM2_IF_TRANSITION_HISTORY(request)) noexcept { HFSM2_IF_TRANSITION_HISTORY(control.pinLastTransition(HEAD_ID, request.index)); @@ -10388,7 +10339,7 @@ C_::deepRequestChangeRandom(Control& control, template void C_::deepRequestRestart(Control& control, - const Request request) + const Request request) noexcept { HFSM2_IF_TRANSITION_HISTORY(control.pinLastTransition(HEAD_ID, request.index)); @@ -10404,7 +10355,7 @@ C_::deepRequestRestart(Control& control, template void C_::deepRequestResume(Control& control, - const Request request) + const Request request) noexcept { HFSM2_IF_TRANSITION_HISTORY(control.pinLastTransition(HEAD_ID, request.index)); @@ -10424,7 +10375,7 @@ C_::deepRequestResume(Control& control, template void C_::deepRequestUtilize(Control& control, - const Request HFSM2_IF_TRANSITION_HISTORY(request)) + const Request HFSM2_IF_TRANSITION_HISTORY(request)) noexcept { HFSM2_IF_TRANSITION_HISTORY(control.pinLastTransition(HEAD_ID, request.index)); @@ -10441,7 +10392,7 @@ C_::deepRequestUtilize(Control& control, template void C_::deepRequestRandomize(Control& control, - const Request HFSM2_IF_TRANSITION_HISTORY(request)) + const Request HFSM2_IF_TRANSITION_HISTORY(request)) noexcept { HFSM2_IF_TRANSITION_HISTORY(control.pinLastTransition(HEAD_ID, request.index)); @@ -10465,7 +10416,7 @@ C_::deepRequestRandomize(Control& control, template typename TA::UP -C_::deepReportChange(Control& control) { +C_::deepReportChange(Control& control) noexcept { switch (STRATEGY) { case Strategy::Composite: return deepReportChangeComposite (control); @@ -10491,7 +10442,7 @@ C_::deepReportChange(Control& control) { template typename TA::UP -C_::deepReportChangeComposite(Control& control) { +C_::deepReportChangeComposite(Control& control) noexcept { Short& requested = compoRequested(control); requested = 0; @@ -10508,7 +10459,7 @@ C_::deepReportChangeComposite(Control& control) { template typename TA::UP -C_::deepReportChangeResumable(Control& control) { +C_::deepReportChangeResumable(Control& control) noexcept { const Short resumable = compoResumable(control); Short& requested = compoRequested(control); @@ -10528,7 +10479,7 @@ C_::deepReportChangeResumable(Control& control) { template typename TA::UP -C_::deepReportChangeUtilitarian(Control& control) { +C_::deepReportChangeUtilitarian(Control& control) noexcept { const UP h = _headState.deepReportChange(control); const UP s = _subStates.wideReportChangeUtilitarian(control); @@ -10547,7 +10498,7 @@ C_::deepReportChangeUtilitarian(Control& control) { template typename TA::UP -C_::deepReportChangeRandom(Control& control) { +C_::deepReportChangeRandom(Control& control) noexcept { const UP h = _headState.deepReportChange(control); Rank ranks[Info::WIDTH]; @@ -10570,7 +10521,7 @@ C_::deepReportChangeRandom(Control& control) { template typename TA::UP -C_::deepReportUtilize(Control& control) { +C_::deepReportUtilize(Control& control) noexcept { const UP h = _headState.deepReportUtilize(control); const UP s = _subStates.wideReportUtilize(control); @@ -10589,7 +10540,7 @@ C_::deepReportUtilize(Control& control) { template typename TA::Rank -C_::deepReportRank(Control& control) { +C_::deepReportRank(Control& control) noexcept { return _headState.wrapRank(control); } @@ -10597,7 +10548,7 @@ C_::deepReportRank(Control& control) { template typename TA::Utility -C_::deepReportRandomize(Control& control) { +C_::deepReportRandomize(Control& control) noexcept { const Utility h = _headState.wrapUtility(control); Rank ranks[Info::WIDTH]; @@ -10616,10 +10567,11 @@ C_::deepReportRandomize(Control& control) { #endif //------------------------------------------------------------------------------ +// COMMON template void -C_::deepChangeToRequested(PlanControl& control) { +C_::deepChangeToRequested(PlanControl& control) noexcept { Short& active = compoActive (control); Short& resumable = compoResumable(control); Short& requested = compoRequested(control); @@ -10661,7 +10613,7 @@ C_::deepChangeToRequested(PlanControl& control) { template void C_::deepSaveActive(const Registry& registry, - WriteStream& stream) const + WriteStream& stream) const noexcept { const Short active = compoActive (registry); const Short resumable = compoResumable(registry); @@ -10682,7 +10634,7 @@ C_::deepSaveActive(const Registry& registry, template void C_::deepSaveResumable(const Registry& registry, - WriteStream& stream) const + WriteStream& stream) const noexcept { const Short resumable = compoResumable(registry); @@ -10700,7 +10652,7 @@ C_::deepSaveResumable(const Registry& registry, template void C_::deepLoadRequested(Registry& registry, - ReadStream& stream) const + ReadStream& stream) const noexcept { Short& resumable = compoResumable(registry); Short& requested = compoRequested(registry); @@ -10722,7 +10674,7 @@ C_::deepLoadRequested(Registry& registry, template void C_::deepLoadResumable(Registry& registry, - ReadStream& stream) const + ReadStream& stream) const noexcept { Short& resumable = compoResumable(registry); @@ -10737,6 +10689,7 @@ C_::deepLoadResumable(Registry& registry, #endif +// COMMON //------------------------------------------------------------------------------ #ifdef HFSM2_ENABLE_STRUCTURE_REPORT @@ -10746,7 +10699,7 @@ void C_::deepGetNames(const Long parent, const RegionType regionType, const Short depth, - StructureStateInfos& _stateInfos) const + StructureStateInfos& _stateInfos) const noexcept { _headState.deepGetNames(parent, regionType, depth, _stateInfos); _subStates.wideGetNames(_stateInfos.count() - 1, StructureStateInfo::RegionType::COMPOSITE, depth + 1, _stateInfos); @@ -10794,7 +10747,7 @@ struct OS_ final { using StateParents = typename Registry::StateParents; using OrthoForks = typename Registry::OrthoForks; using ProngBits = typename OrthoForks::Bits; - using ProngConstBits= typename OrthoForks::ConstBits; + using ProngCBits= typename OrthoForks::CBits; using Control = ControlT ; using PlanControl = PlanControlT ; @@ -10837,7 +10790,7 @@ struct OS_ final { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE bool wideForwardEntryGuard(GuardControl& control, const ProngConstBits prongs); + HFSM2_INLINE bool wideForwardEntryGuard(GuardControl& control, const ProngCBits prongs); HFSM2_INLINE bool wideForwardEntryGuard(GuardControl& control); HFSM2_INLINE bool wideEntryGuard (GuardControl& control); @@ -10851,7 +10804,7 @@ struct OS_ final { template HFSM2_INLINE Status wideReact (FullControl& control, const TEvent& event); - HFSM2_INLINE bool wideForwardExitGuard (GuardControl& control, const ProngConstBits prongs); + HFSM2_INLINE bool wideForwardExitGuard (GuardControl& control, const ProngCBits prongs); HFSM2_INLINE bool wideForwardExitGuard (GuardControl& control); HFSM2_INLINE bool wideExitGuard (GuardControl& control); @@ -10861,7 +10814,7 @@ struct OS_ final { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE void wideForwardActive (Control& control, const Request request, const ProngConstBits prongs); + HFSM2_INLINE void wideForwardActive (Control& control, const Request request, const ProngCBits prongs); HFSM2_INLINE void wideForwardRequest (Control& control, const Request request); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -10941,7 +10894,7 @@ struct OS_ final { using StateParents = typename Registry::StateParents; using OrthoForks = typename Registry::OrthoForks; using ProngBits = typename OrthoForks::Bits; - using ProngConstBits= typename OrthoForks::ConstBits; + using ProngCBits= typename OrthoForks::CBits; using Control = ControlT ; using PlanControl = PlanControlT ; @@ -10973,7 +10926,7 @@ struct OS_ final { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE bool wideForwardEntryGuard(GuardControl& control, const ProngConstBits prongs); + HFSM2_INLINE bool wideForwardEntryGuard(GuardControl& control, const ProngCBits prongs); HFSM2_INLINE bool wideForwardEntryGuard(GuardControl& control); HFSM2_INLINE bool wideEntryGuard (GuardControl& control); @@ -10987,7 +10940,7 @@ struct OS_ final { template HFSM2_INLINE Status wideReact (FullControl& control, const TEvent& event); - HFSM2_INLINE bool wideForwardExitGuard (GuardControl& control, const ProngConstBits prongs); + HFSM2_INLINE bool wideForwardExitGuard (GuardControl& control, const ProngCBits prongs); HFSM2_INLINE bool wideForwardExitGuard (GuardControl& control); HFSM2_INLINE bool wideExitGuard (GuardControl& control); @@ -10997,7 +10950,7 @@ struct OS_ final { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HFSM2_INLINE void wideForwardActive (Control& control, const Request request, const ProngConstBits prongs); + HFSM2_INLINE void wideForwardActive (Control& control, const Request request, const ProngCBits prongs); HFSM2_INLINE void wideForwardRequest (Control& control, const Request request); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -11099,7 +11052,7 @@ OS_::wideRegister(Registry& registry, template bool OS_::wideForwardEntryGuard(GuardControl& control, - const ProngConstBits prongs) + const ProngCBits prongs) { const bool i = prongs.get(PRONG_INDEX) ? initial .deepForwardEntryGuard(control) : false; @@ -11184,7 +11137,7 @@ OS_::wideReact(FullControl& control, template bool OS_::wideForwardExitGuard(GuardControl& control, - const ProngConstBits prongs) + const ProngCBits prongs) { const bool i = prongs.get(PRONG_INDEX) ? initial .deepForwardExitGuard(control) : false; @@ -11240,7 +11193,7 @@ template void OS_::wideForwardActive(Control& control, const Request request, - const ProngConstBits prongs) + const ProngCBits prongs) { if (prongs.get(PRONG_INDEX)) initial.deepForwardActive(control, request); @@ -11446,7 +11399,7 @@ OS_::wideRegister(Registry& registry, template bool OS_::wideForwardEntryGuard(GuardControl& control, - const ProngConstBits prongs) + const ProngCBits prongs) { return prongs.get(PRONG_INDEX) ? initial.deepForwardEntryGuard(control) : false; @@ -11516,7 +11469,7 @@ OS_::wideReact(FullControl& control, template bool OS_::wideForwardExitGuard(GuardControl& control, - const ProngConstBits prongs) + const ProngCBits prongs) { return prongs.get(PRONG_INDEX) ? initial.deepForwardExitGuard(control) : false; @@ -11560,7 +11513,7 @@ template void OS_::wideForwardActive(Control& control, const Request request, - const ProngConstBits prongs) + const ProngCBits prongs) { if (prongs.get(PRONG_INDEX)) initial.deepForwardActive(control, request); @@ -11770,7 +11723,7 @@ struct O_ final { using StateParents = typename Registry::StateParents; using OrthoForks = typename Registry::OrthoForks; using ProngBits = typename OrthoForks::Bits; - using ProngConstBits= typename OrthoForks::ConstBits; + using ProngCBits = typename OrthoForks::CBits; using Control = ControlT; using ScopedOrigin = typename Control::Origin; @@ -11818,10 +11771,10 @@ struct O_ final { //---------------------------------------------------------------------- HFSM2_INLINE ProngBits orthoRequested( Registry& registry) { return registry.orthoRequested.template bits(); } - HFSM2_INLINE ProngConstBits orthoRequested(const Registry& registry) const { return registry.orthoRequested.template bits(); } + HFSM2_INLINE ProngCBits orthoRequested(const Registry& registry) const { return registry.orthoRequested.template bits(); } HFSM2_INLINE ProngBits orthoRequested( Control& control) { return orthoRequested(control._registry); } - HFSM2_INLINE ProngConstBits orthoRequested(const Control& control) const { return orthoRequested(control._registry); } + HFSM2_INLINE ProngCBits orthoRequested(const Control& control) const { return orthoRequested(control._registry); } HFSM2_INLINE void deepRegister (Registry& registry, const Parent parent); @@ -11935,7 +11888,7 @@ O_::deepRegister(Registry& registry, template bool O_::deepForwardEntryGuard(GuardControl& control) { - const ProngConstBits requested = orthoRequested(static_cast(control)); + const ProngCBits requested = orthoRequested(static_cast(control)); ScopedRegion region{control, REGION_ID, HEAD_ID, REGION_SIZE}; @@ -12059,7 +12012,7 @@ O_::deepReact(FullControl& control, template bool O_::deepForwardExitGuard(GuardControl& control) { - const ProngConstBits requested = orthoRequested(static_cast(control)); + const ProngCBits requested = orthoRequested(static_cast(control)); ScopedRegion region{control, REGION_ID, HEAD_ID, REGION_SIZE}; @@ -12107,7 +12060,7 @@ O_::deepForwardActive(Control& control, { HFSM2_ASSERT(control._registry.isActive(HEAD_ID)); - const ProngConstBits requested = orthoRequested(static_cast(control)); + const ProngCBits requested = orthoRequested(static_cast(control)); HFSM2_ASSERT(!!requested); _subStates.wideForwardActive(control, request, requested); @@ -12122,7 +12075,7 @@ O_::deepForwardRequest(Control& control, { HFSM2_IF_TRANSITION_HISTORY(control.pinLastTransition(HEAD_ID, request.index)); - const ProngConstBits requested = orthoRequested(static_cast(control)); + const ProngCBits requested = orthoRequested(static_cast(control)); if (requested) _subStates.wideForwardRequest(control, request); @@ -12384,7 +12337,7 @@ template > { using Host = C_; - HFSM2_INLINE T& get() { return Accessor{host._subStates}.get(); } + HFSM2_INLINE T& get() noexcept { return Accessor{host._subStates}.get(); } Host& host; }; @@ -12400,7 +12353,7 @@ template > { using Host = const C_; - HFSM2_INLINE const T& get() const { return Accessor{host._subStates}.get(); } + HFSM2_INLINE const T& get() const noexcept { return Accessor{host._subStates}.get(); } Host& host; }; @@ -12415,7 +12368,7 @@ template > { using Host = C_; - HFSM2_INLINE T& get() { return host._headState._headBox.get(); } + HFSM2_INLINE T& get() noexcept { return host._headState._headBox.get(); } Host& host; }; @@ -12430,7 +12383,7 @@ template > { using Host = const C_; - HFSM2_INLINE const T& get() const { return host._headState._headBox.get(); } + HFSM2_INLINE const T& get() const noexcept { return host._headState._headBox.get(); } Host& host; }; @@ -12446,7 +12399,7 @@ template > { using Host = CS_; - HFSM2_INLINE T& get() { + HFSM2_INLINE T& get() noexcept { return contains() ? Accessor{host.lHalf}.get() : Accessor{host.rHalf}.get(); @@ -12466,7 +12419,7 @@ template > { using Host = const CS_; - HFSM2_INLINE const T& get() const { + HFSM2_INLINE const T& get() const noexcept { return contains() ? Accessor{host.lHalf}.get() : Accessor{host.rHalf}.get(); @@ -12486,7 +12439,7 @@ template > { using Host = CS_; - HFSM2_INLINE T& get() { return Accessor{host.state}.get(); } + HFSM2_INLINE T& get() noexcept { return Accessor{host.state}.get(); } Host& host; }; @@ -12502,7 +12455,7 @@ template > { using Host = const CS_; - HFSM2_INLINE const T& get() const { return Accessor{host.state}.get(); } + HFSM2_INLINE const T& get() const noexcept { return Accessor{host.state}.get(); } Host& host; }; @@ -12517,7 +12470,7 @@ template > { using Host = O_; - HFSM2_INLINE T& get() { return Accessor{host._subStates}.get(); } + HFSM2_INLINE T& get() noexcept { return Accessor{host._subStates}.get(); } Host& host; }; @@ -12532,7 +12485,7 @@ template > { using Host = const O_; - HFSM2_INLINE const T& get() const { return Accessor{host._subStates}.get(); } + HFSM2_INLINE const T& get() const noexcept { return Accessor{host._subStates}.get(); } Host& host; }; @@ -12546,7 +12499,7 @@ template > { using Host = O_; - HFSM2_INLINE T& get() { return host._headState._headBox.get(); } + HFSM2_INLINE T& get() noexcept { return host._headState._headBox.get(); } Host& host; }; @@ -12560,7 +12513,7 @@ template > { using Host = const O_; - HFSM2_INLINE const T& get() const { return host._headState._headBox.get(); } + HFSM2_INLINE const T& get() const noexcept { return host._headState._headBox.get(); } Host& host; }; @@ -12575,7 +12528,7 @@ template > { using Host = OS_; - HFSM2_INLINE T& get() { + HFSM2_INLINE T& get() noexcept { return contains() ? Accessor{host.initial }.get() : Accessor{host.remaining}.get(); @@ -12594,7 +12547,7 @@ template > { using Host = const OS_; - HFSM2_INLINE const T& get() const { + HFSM2_INLINE const T& get() const noexcept { return contains() ? Accessor{host.initial }.get() : Accessor{host.remaining}.get(); @@ -12613,7 +12566,7 @@ template > { using Host = OS_; - HFSM2_INLINE T& get() { return Accessor{host.initial }.get(); } + HFSM2_INLINE T& get() noexcept { return Accessor{host.initial }.get(); } Host& host; }; @@ -12628,7 +12581,7 @@ template > { using Host = const OS_; - HFSM2_INLINE const T& get() const { return Accessor{host.initial }.get(); } + HFSM2_INLINE const T& get() const noexcept { return Accessor{host.initial }.get(); } Host& host; }; @@ -12648,7 +12601,7 @@ template > { using Host = S_; - HFSM2_INLINE T& get() { HFSM2_BREAK(); return *reinterpret_cast(0); } + HFSM2_INLINE T& get() noexcept { HFSM2_BREAK(); return *reinterpret_cast(0); } Host& host; }; @@ -12662,7 +12615,7 @@ template > { using Host = const S_; - HFSM2_INLINE const T& get() const { HFSM2_BREAK(); return *reinterpret_cast(0); } + HFSM2_INLINE const T& get() const noexcept { HFSM2_BREAK(); return *reinterpret_cast(0); } Host& host; }; @@ -12679,7 +12632,7 @@ template > { using Host = S_; - HFSM2_INLINE T& get() { return host._headBox.get(); } + HFSM2_INLINE T& get() noexcept { return host._headBox.get(); } Host& host; }; @@ -12692,7 +12645,7 @@ template > { using Host = const S_; - HFSM2_INLINE const T& get() const { return host._headBox.get(); } + HFSM2_INLINE const T& get() const noexcept { return host._headBox.get(); } Host& host; }; @@ -12721,7 +12674,7 @@ template -struct G_ { +struct G_ final { static constexpr FeatureTag FEATURE_TAG = NFeatureTag; using Context = TContext; @@ -12739,12 +12692,16 @@ struct G_ { static constexpr Long SUBSTITUTION_LIMIT = NSubstitutionLimit; #ifdef HFSM2_ENABLE_PLANS - static constexpr Long TASK_CAPACITY = NTaskCapacity; + static constexpr Long TASK_CAPACITY = NTaskCapacity; #endif using Payload = TPayload; using Transition = TransitionT; +#ifdef HFSM2_ENABLE_PLANS + using Task = TaskT; +#endif + /// @brief Set Context type /// @tparam T Context type for data shared between states and/or data interface between FSM and external code template @@ -12794,7 +12751,7 @@ struct G_ { struct UP { HFSM2_INLINE UP(const Utility utility_ = Utility{1}, - const Short prong_ = INVALID_SHORT) + const Short prong_ = INVALID_SHORT) noexcept : utility{utility_} , prong{prong_} {} @@ -12913,6 +12870,7 @@ struct M_ ; //---------------------------------------------------------------------- + // COMMON /// @brief Root ('changeTo<>()' into the root region acts as 'restart<>()') /// @tparam THead Head state @@ -12925,6 +12883,7 @@ struct M_ using PeerRoot = RF_>; + // COMMON // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /// @brief Resumable root ('changeTo<>()' into the root region acts as 'resume<>()') @@ -12989,28 +12948,7 @@ struct M_ -/// @tparam TContext Context type for data shared between states and/or data interface between FSM and external code -/// @tparam TRank Rank type for 'TRank State::rank() const' method -/// @tparam TUtility Utility type for 'TUtility State::utility() const' method -/// @tparam TRNG RNG type used in 'Random' regions -/// @tparam NSubstitutionLimit Maximum number times 'guard()' methods can substitute their states for others -/// @tparam NTaskCapacity Maximum number of tasks across all plans -/// @tparam TPayload Payload type -template - #endif - - , Long NSubstitutionLimit = 4 - HFSM2_IF_PLANS(, Long NTaskCapacity = INVALID_LONG) - , typename TPayload = void> -using ConfigT = detail::G_; - -/// @brief Type configuration for MachineT<> -using Config = ConfigT<>; +using Config = detail::G_), 4 HFSM2_IF_PLANS(, INVALID_LONG), void>; /// @brief 'Template namespace' for FSM classes /// @tparam TConfig 'ConfigT<>' type configuration for MachineT<> @@ -13036,6 +12974,7 @@ namespace detail { template class R_ { +public: static constexpr FeatureTag FEATURE_TAG = TConfig::FEATURE_TAG; using Context = typename TConfig::Context; @@ -13048,6 +12987,7 @@ class R_ { using Payload = typename TConfig::Payload; +private: using Apex = TApex; using Forward = RF_; @@ -13103,8 +13043,8 @@ class R_ { #endif #ifdef HFSM2_ENABLE_STRUCTURE_REPORT - using Prefix = StaticArray; - using Prefixes = StaticArray; + using Prefix = StaticArrayT; + using Prefixes = StaticArrayT; using StructureStateInfos = typename Args::StructureStateInfos; #endif @@ -13117,11 +13057,21 @@ class R_ { //---------------------------------------------------------------------- - explicit R_(Context& context - HFSM2_IF_UTILITY_THEORY(, RNG& rng) - HFSM2_IF_LOG_INTERFACE(, Logger* const logger = nullptr)); + HFSM2_INLINE explicit R_(Context& context + HFSM2_IF_UTILITY_THEORY(, RNG& rng) + HFSM2_IF_LOG_INTERFACE(, Logger* const logger = nullptr)) noexcept; - ~R_(); + HFSM2_INLINE ~R_() noexcept; + + //---------------------------------------------------------------------- + + /// @brief Access context + /// @return context + HFSM2_INLINE Context& context() noexcept { return _context; } + + /// @brief Access context + /// @return context + HFSM2_INLINE const Context& context() const noexcept { return _context; } //---------------------------------------------------------------------- @@ -13129,13 +13079,13 @@ class R_ { /// @tparam TState State type /// @return Numeric state identifier template - static constexpr StateID stateId() { return index(); } + static constexpr StateID stateId() noexcept { return index(); } /// @brief Get region identifier for a region type /// @tparam TState Region head state type /// @return Numeric region identifier template - static constexpr RegionID regionId() { return (RegionID) index(); } + static constexpr RegionID regionId() noexcept { return (RegionID) index(); } //---------------------------------------------------------------------- #ifdef HFSM2_EXPLICIT_MEMBER_SPECIALIZATION @@ -13156,8 +13106,8 @@ class R_ { template struct Accessor { - HFSM2_INLINE static TState& get( MaterialApex& apex) { return apex.template access(); } - HFSM2_INLINE static const TState& get(const MaterialApex& apex) { return apex.template access(); } + HFSM2_INLINE static TState& get( MaterialApex& apex) noexcept { return apex.template access(); } + HFSM2_INLINE static const TState& get(const MaterialApex& apex) noexcept { return apex.template access(); } }; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -13173,13 +13123,13 @@ class R_ { /// @tparam TState State type /// @return State instance template - HFSM2_INLINE TState& access() { return Accessor::get(_apex); } + HFSM2_INLINE TState& access() noexcept { return Accessor::get(_apex); } /// @brief Access state instance /// @tparam TState State type /// @return State instance template - HFSM2_INLINE const TState& access() const { return Accessor::get(_apex); } + HFSM2_INLINE const TState& access() const noexcept { return Accessor::get(_apex); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -13191,98 +13141,100 @@ class R_ { /// @tparam TState State type /// @return State instance template - HFSM2_INLINE TState& access() { return Accessor{_apex}.get(); } + HFSM2_INLINE TState& access() noexcept { return Accessor{_apex}.get(); } /// @brief Access state instance /// @tparam TState State type /// @return State instance template - HFSM2_INLINE const TState& access() const { return Accessor{_apex}.get(); } + HFSM2_INLINE const TState& access() const noexcept { return Accessor{_apex}.get(); } #endif //---------------------------------------------------------------------- /// @brief Trigger FSM update cycle (recursively call 'update()' on all active states, then process requested transitions) - void update(); + void update() noexcept; /// @brief Have FSM react to an event (recursively call matching 'react<>()' on all active states, then process requested transitions) /// @tparam TEvent Event type /// @param event Event to react to template - HFSM2_INLINE void react (const TEvent& event); + HFSM2_INLINE void react(const TEvent& event) noexcept; //---------------------------------------------------------------------- /// @brief Check if a state is active /// @param stateId Destination state identifier /// @return State active status - HFSM2_INLINE bool isActive (const StateID stateId) const { return _registry.isActive (stateId); } + HFSM2_INLINE bool isActive (const StateID stateId) const noexcept { return _registry.isActive (stateId); } /// @brief Check if a state is active /// @tparam TState Destination state type /// @return State active status template - HFSM2_INLINE bool isActive () const { return isActive (stateId()); } + HFSM2_INLINE bool isActive () const noexcept { return isActive (stateId()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /// @brief Check if a state is resumable (activated then deactivated previously) /// @param stateId Destination state identifier /// @return State resumable status - HFSM2_INLINE bool isResumable(const StateID stateId) const { return _registry.isResumable(stateId); } + HFSM2_INLINE bool isResumable (const StateID stateId) const noexcept { return _registry.isResumable(stateId); } /// @brief Check if a state is resumable (activated then deactivated previously) /// @tparam TState Destination state type /// @return State resumable status template - HFSM2_INLINE bool isResumable() const { return isResumable(stateId()); } + HFSM2_INLINE bool isResumable () const noexcept { return isResumable(stateId()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /// @brief Check if a state is scheduled to activate on the next transition to parent region /// @param stateId Destination state identifier /// @return State scheduled status - HFSM2_INLINE bool isScheduled(const StateID stateId) const { return isResumable(stateId); } + HFSM2_INLINE bool isScheduled (const StateID stateId) const noexcept { return isResumable(stateId); } /// @brief Check if a state is scheduled to activate on the next transition to parent region /// @tparam TState Destination state type /// @return State scheduled status template - HFSM2_INLINE bool isScheduled() const { return isResumable(); } + HFSM2_INLINE bool isScheduled () const noexcept { return isResumable(); } //------------------------------------------------------------------------------ + // COMMON /// @brief Transition into a state (if transitioning into a region, acts depending on the region type) /// @param stateId Destination state identifier - HFSM2_INLINE void changeTo (const StateID stateId); + HFSM2_INLINE void changeTo (const StateID stateId) noexcept; /// @brief Transition into a state (if transitioning into a region, acts depending on the region type) /// @tparam TState Destination state type template - HFSM2_INLINE void changeTo () { changeTo (stateId()); } + HFSM2_INLINE void changeTo () noexcept { changeTo (stateId()); } + // COMMON // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /// @brief Transition into a state (if transitioning into a region, activates the initial state) /// @param stateId Destination state identifier - HFSM2_INLINE void restart (const StateID stateId); + HFSM2_INLINE void restart (const StateID stateId) noexcept; /// @brief Transition into a state (if transitioning into a region, activates the initial state) /// @tparam TState Destination state type template - HFSM2_INLINE void restart () { restart (stateId()); } + HFSM2_INLINE void restart () noexcept { restart (stateId()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /// @brief Transition into a state (if transitioning into a region, activates the state that was active previously) /// @param stateId Destination state identifier - HFSM2_INLINE void resume (const StateID stateId); + HFSM2_INLINE void resume (const StateID stateId) noexcept; /// @brief Transition into a state (if transitioning into a region, activates the state that was active previously) /// @tparam TState Destination state type template - HFSM2_INLINE void resume () { resume (stateId()); } + HFSM2_INLINE void resume () noexcept { resume (stateId()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -13292,14 +13244,14 @@ class R_ { /// with the highest 'utility()' among those with the highest 'rank()') /// @param stateId Destination state identifier /// @see HFSM2_ENABLE_UTILITY_THEORY - HFSM2_INLINE void utilize (const StateID stateId); + HFSM2_INLINE void utilize (const StateID stateId) noexcept; /// @brief Transition into a state (if transitioning into a region, activates the state /// with the highest 'utility()' among those with the highest 'rank()') /// @tparam TState Destination state type /// @see HFSM2_ENABLE_UTILITY_THEORY template - HFSM2_INLINE void utilize () { utilize (stateId()); } + HFSM2_INLINE void utilize () noexcept { utilize (stateId()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -13307,14 +13259,14 @@ class R_ { /// proportional to 'utility()' among those with the highest 'rank()') /// @param stateId Destination state identifier /// @see HFSM2_ENABLE_UTILITY_THEORY - HFSM2_INLINE void randomize (const StateID stateId); + HFSM2_INLINE void randomize (const StateID stateId) noexcept; /// @brief Transition into a state (if transitioning into a region, uses weighted random to activate the state /// proportional to 'utility()' among those with the highest 'rank()') /// @tparam TState Destination state type /// @see HFSM2_ENABLE_UTILITY_THEORY template - HFSM2_INLINE void randomize () { randomize(stateId()); } + HFSM2_INLINE void randomize () noexcept { randomize(stateId()); } #endif @@ -13322,56 +13274,56 @@ class R_ { /// @brief Schedule a state to be activated when its parent region is activated /// @param stateId Destination state identifier - HFSM2_INLINE void schedule (const StateID stateId); + HFSM2_INLINE void schedule (const StateID stateId) noexcept; /// @brief Schedule a state to be activated when its parent region is activated /// @tparam TState Destination state type template - HFSM2_INLINE void schedule () { schedule (stateId()); } + HFSM2_INLINE void schedule () noexcept { schedule (stateId()); } //------------------------------------------------------------------------------ /// @brief Check if a state is going to be activated or deactivated /// @param stateId Destination state identifier /// @return State pending activation/deactivation status - HFSM2_INLINE bool isPendingChange(const StateID stateId) const { return _registry.isPendingChange(stateId); } + HFSM2_INLINE bool isPendingChange(const StateID stateId) const noexcept { return _registry.isPendingChange(stateId); } /// @brief Check if a state is going to be activated or deactivated /// @tparam TState Destination state type /// @return State pending activation/deactivation status template - HFSM2_INLINE bool isPendingChange() { return isPendingChange(stateId()); } + HFSM2_INLINE bool isPendingChange() noexcept { return isPendingChange(stateId()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /// @brief Check if a state is going to be activated /// @param stateId Destination state identifier /// @return State pending activation status - HFSM2_INLINE bool isPendingEnter (const StateID stateId) const { return _registry.isPendingEnter (stateId); } + HFSM2_INLINE bool isPendingEnter (const StateID stateId) const noexcept { return _registry.isPendingEnter (stateId); } /// @brief Check if a state is going to be activated /// @tparam TState Destination state type /// @return State pending activation status template - HFSM2_INLINE bool isPendingEnter () { return isPendingEnter (stateId()); } + HFSM2_INLINE bool isPendingEnter () noexcept { return isPendingEnter (stateId()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /// @brief Check if a state is going to be deactivated /// @param stateId Destination state identifier /// @return State pending deactivation status - HFSM2_INLINE bool isPendingExit (const StateID stateId) const { return _registry.isPendingExit (stateId); } + HFSM2_INLINE bool isPendingExit (const StateID stateId) const noexcept { return _registry.isPendingExit (stateId); } /// @brief Check if a state is going to be deactivated /// @tparam TState Destination state type /// @return State pending deactivation status template - HFSM2_INLINE bool isPendingExit () { return isPendingExit (stateId()); } + HFSM2_INLINE bool isPendingExit () noexcept { return isPendingExit (stateId()); } //------------------------------------------------------------------------------ /// @brief Reset FSM to initial state (recursively 'exit()' currently active states, 'enter()' initial states) - void reset(); + void reset() noexcept; //------------------------------------------------------------------------------ @@ -13385,12 +13337,12 @@ class R_ { /// @brief Serialize FSM into 'buffer' /// @param buffer 'SerialBuffer' to serialize to /// @see HFSM2_ENABLE_SERIALIZATION - void save( SerialBuffer& buffer) const; + void save( SerialBuffer& buffer) const noexcept; /// @brief De-serialize FSM from 'buffer' /// @param buffer 'SerialBuffer' to de-serialize from /// @see HFSM2_ENABLE_SERIALIZATION - void load(const SerialBuffer& buffer); + void load(const SerialBuffer& buffer) noexcept; #endif @@ -13401,7 +13353,7 @@ class R_ { /// @brief Get the list of transitions recorded during last 'update()' /// @return Array of last recorded transitions /// @see HFSM2_ENABLE_TRANSITION_HISTORY - const TransitionSets& previousTransitions() const { return _previousTransitions; } + const TransitionSets& previousTransitions() const noexcept { return _previousTransitions; } /// @brief Force process transitions (skips 'guard()' calls) /// Can be used to synchronize multiple FSMs @@ -13409,7 +13361,8 @@ class R_ { /// @param count Number of transitions /// @return Success status /// @see HFSM2_ENABLE_TRANSITION_HISTORY - bool replayTransitions(const Transition* const transitions, const uint64_t count); + bool replayTransitions(const Transition* const transitions, + const uint64_t count) noexcept; /// @brief Force process transitions (skips 'guard()' calls) /// Can be used to synchronize multiple FSMs @@ -13417,27 +13370,28 @@ class R_ { /// @return Success status /// @see HFSM2_ENABLE_TRANSITION_HISTORY template - bool replayTransitions(const Array& transitions); + bool replayTransitions(const ArrayT& transitions) noexcept; /// @brief Force process a transition (skips 'guard()' calls) /// Can be used to synchronize multiple FSMs /// @param transition 'Transition' to replay /// @return Success status /// @see HFSM2_ENABLE_TRANSITION_HISTORY - bool replayTransition (const Transition& transition) { return replayTransitions(&transition, 1); } + bool replayTransition (const Transition& transition) noexcept { return replayTransitions(&transition, 1); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /// @brief Get the last transition that caused the state to be activated /// @param stateId State identifier /// @return Pointer to the last transition that activated the state - const Transition* lastTransition(const StateID stateId) const; + const Transition* lastTransition(const StateID stateId) const noexcept; /// @brief Get the last transition that caused the state to be activated /// @tparam TState State type /// @return Pointer to the last transition that activated the state template - const Transition* lastTransition() const { return lastTransition(stateId()); } + const Transition* lastTransition() const noexcept { return lastTransition(stateId()); } #endif @@ -13447,21 +13401,21 @@ class R_ { /// @brief Array of 'StructureEntry' representing FSM structure /// @see HFSM2_ENABLE_STRUCTURE_REPORT - using Structure = Array; + using Structure = ArrayT; /// @brief Array of 'char' representing FSM activation history (negative - 'update()' cycles since deactivated, positive - 'update()' cycles since activated) /// @see HFSM2_ENABLE_STRUCTURE_REPORT - using ActivityHistory = Array; + using ActivityHistory = ArrayT; /// @brief Get the array of 'StructureEntry' representing FSM structure /// @return FSM structure /// @see HFSM2_ENABLE_STRUCTURE_REPORT - const Structure& structure() const { return _structure; } + const Structure& structure() const noexcept { return _structure; } /// @brief Get the array of 'char' representing FSM activation history (negative - 'update()' cycles since deactivated, positive - 'update()' cycles since activated) /// @return FSM activation history /// @see HFSM2_ENABLE_STRUCTURE_REPORT - const ActivityHistory& activityHistory() const { return _activityHistory; } + const ActivityHistory& activityHistory() const noexcept { return _activityHistory; } #endif @@ -13472,37 +13426,37 @@ class R_ { /// @brief Attach logger /// @param logger A logger implementing 'hfsm2::LoggerInterfaceT<>' interface /// @see HFSM2_ENABLE_LOG_INTERFACE - void attachLogger(Logger* const logger) { _logger = logger; } + HFSM2_INLINE void attachLogger(Logger* const logger) noexcept { _logger = logger; } #endif //---------------------------------------------------------------------- private: - void initialEnter(); - void processTransitions(TransitionSets& currentTransitions); + void initialEnter() noexcept; + void processTransitions(TransitionSets& currentTransitions) noexcept; - bool applyRequest (Control& control, const Transition& request, const Short index); - bool applyRequests(Control& control); + bool applyRequest (Control& control, const Transition& request, const Short index) noexcept; + bool applyRequests(Control& control) noexcept; bool cancelledByEntryGuards(const TransitionSets& currentTransitions, - const TransitionSet& pendingTransitions); + const TransitionSet& pendingTransitions) noexcept; bool cancelledByGuards(const TransitionSets& currentTransitions, - const TransitionSet& pendingTransitions); + const TransitionSet& pendingTransitions) noexcept; #ifdef HFSM2_ENABLE_TRANSITION_HISTORY bool applyRequests(Control& control, const Transition* const transitions, - const uint64_t count); + const uint64_t count) noexcept; TransitionTargets _transitionTargets; TransitionSets _previousTransitions; #endif #ifdef HFSM2_ENABLE_STRUCTURE_REPORT - void getStateNames(); - void udpateActivity(); + void getStateNames() noexcept; + void udpateActivity() noexcept; Prefixes _prefixes; StructureStateInfos _stateInfos; @@ -13512,7 +13466,7 @@ class R_ { #endif protected: - Context& _context; + Context _context; HFSM2_IF_UTILITY_THEORY(RNG& _rng); Registry _registry; @@ -13551,78 +13505,83 @@ class RP_ , TApex>; - using Payload = TPayload; - using Transition = TransitionT; + using Transition = TransitionT; public: - using Base::Base; + using Payload = typename Base::Payload; - using Base::stateId; - using Base::regionId; +#ifdef HFSM2_ENABLE_UTILITY_THEORY + using RNG = typename Base::RNG; +#endif + +public: + using Base::Base; /// @brief Get state identifier for a state type /// @tparam TState State type /// @return Numeric state identifier template - static constexpr StateID stateId() { return Base::template stateId(); } + static constexpr StateID stateId() noexcept { return Base::template stateId(); } /// @brief Get region identifier for a region type /// @tparam TState Region head state type /// @return Numeric region identifier template - static constexpr RegionID regionId() { return Base::template regionId(); } + static constexpr RegionID regionId() noexcept { return Base::template regionId(); } //------------------------------------------------------------------------------ + // COMMON /// @brief Transition into a state (if transitioning into a region, acts depending on the region type) /// @param stateId Destination state identifier /// @param payload Payload HFSM2_INLINE void changeWith (const StateID stateId, - const Payload& payload); + const Payload& payload) noexcept; /// @brief Transition into a state (if transitioning into a region, acts depending on the region type) /// @param stateId Destination state identifier /// @param payload Payload HFSM2_INLINE void changeWith (const StateID stateId, - Payload&& payload); + Payload&& payload) noexcept; /// @brief Transition into a state (if transitioning into a region, acts depending on the region type) /// @tparam TState Destination state type /// @param payload Payload template - HFSM2_INLINE void changeWith (const Payload& payload) { changeWith (stateId(), payload ); } + HFSM2_INLINE void changeWith (const Payload& payload) noexcept { changeWith (stateId(), payload ); } /// @brief Transition into a state (if transitioning into a region, acts depending on the region type) /// @tparam TState Destination state type /// @param payload Payload template - HFSM2_INLINE void changeWith ( Payload&& payload) { changeWith (stateId(), std::move(payload)); } + HFSM2_INLINE void changeWith ( Payload&& payload) noexcept { changeWith (stateId(), std::move(payload)); } + // COMMON // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /// @brief Transition into a state (if transitioning into a region, activates the initial state) /// @param stateId Destination state identifier /// @param payload Payload HFSM2_INLINE void restartWith (const StateID stateId, - const Payload& payload); + const Payload& payload) noexcept; /// @brief Transition into a state (if transitioning into a region, activates the initial state) /// @param stateId Destination state identifier /// @param payload Payload HFSM2_INLINE void restartWith (const StateID stateId, - Payload&& payload); + Payload&& payload) noexcept; /// @brief Transition into a state (if transitioning into a region, activates the initial state) /// @tparam TState Destination state type /// @param payload Payload template - HFSM2_INLINE void restartWith (const Payload& payload) { restartWith (stateId(), payload ); } + HFSM2_INLINE void restartWith (const Payload& payload) noexcept { restartWith (stateId(), payload ); } /// @brief Transition into a state (if transitioning into a region, activates the initial state) /// @tparam TState Destination state type /// @param payload Payload template - HFSM2_INLINE void restartWith ( Payload&& payload) { restartWith (stateId(), std::move(payload)); } + HFSM2_INLINE void restartWith ( Payload&& payload) noexcept { restartWith (stateId(), std::move(payload)); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -13630,25 +13589,25 @@ class RP_ - HFSM2_INLINE void resumeWith (const Payload& payload) { resumeWith (stateId(), payload ); } + HFSM2_INLINE void resumeWith (const Payload& payload) noexcept { resumeWith (stateId(), payload ); } /// @brief Transition into a state (if transitioning into a region, activates the state that was active previously) /// @tparam TState Destination state type /// @param payload Payload template - HFSM2_INLINE void resumeWith ( Payload&& payload) { resumeWith (stateId(), std::move(payload)); } + HFSM2_INLINE void resumeWith ( Payload&& payload) noexcept { resumeWith (stateId(), std::move(payload)); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -13660,7 +13619,7 @@ class RP_ - HFSM2_INLINE void utilizeWith (const Payload& payload) { utilizeWith (stateId(), payload ); } + HFSM2_INLINE void utilizeWith (const Payload& payload) noexcept { utilizeWith (stateId(), payload ); } /// @brief Transition into a state (if transitioning into a region, activates the state /// with the highest 'utility()' among those with the highest 'rank()') @@ -13684,7 +13643,7 @@ class RP_ - HFSM2_INLINE void utilizeWith ( Payload&& payload) { utilizeWith (stateId(), std::move(payload)); } + HFSM2_INLINE void utilizeWith ( Payload&& payload) noexcept { utilizeWith (stateId(), std::move(payload)); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -13694,7 +13653,7 @@ class RP_ - HFSM2_INLINE void randomizeWith(const Payload& payload) { randomizeWith(stateId(), payload ); } + HFSM2_INLINE void randomizeWith(const Payload& payload) noexcept { randomizeWith(stateId(), payload ); } /// @brief Transition into a state (if transitioning into a region, uses weighted random to activate the state /// proportional to 'utility()' among those with the highest 'rank()') @@ -13718,7 +13677,7 @@ class RP_ - HFSM2_INLINE void randomizeWith( Payload&& payload) { randomizeWith(stateId(), std::move(payload)); } + HFSM2_INLINE void randomizeWith( Payload&& payload) noexcept { randomizeWith(stateId(), std::move(payload)); } #endif @@ -13728,36 +13687,38 @@ class RP_ - HFSM2_INLINE void scheduleWith (const Payload& payload) { scheduleWith (stateId(), payload ); } + HFSM2_INLINE void scheduleWith (const Payload& payload) noexcept { scheduleWith (stateId(), payload ); } /// @brief Schedule a state to be activated when its parent region is activated /// @tparam TState Destination state type /// @param payload Payload template - HFSM2_INLINE void scheduleWith ( Payload&& payload) { scheduleWith (stateId(), std::move(payload)); } + HFSM2_INLINE void scheduleWith ( Payload&& payload) noexcept { scheduleWith (stateId(), std::move(payload)); } //------------------------------------------------------------------------------ -private: +protected: using Base::_context; + +private: using Base::_requests; HFSM2_IF_LOG_INTERFACE(using Base::_logger); }; -//------------------------------------------------------------------------------ +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - template , TApex>; +public: +#ifdef HFSM2_ENABLE_UTILITY_THEORY + using RNG = typename Base::RNG; +#endif + public: using Base::Base; }; //////////////////////////////////////////////////////////////////////////////// -/// @brief FSM Root -/// @tparam Cfg Type configuration -/// @tparam TApex Root region type -template -class RW_ final - : public RP_ +template +class RC_; + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +// TContext + +template +class RC_ , TApex> + : public RP_, TApex> { - using Base = RP_; + using Base = RP_, TApex>; public: - using Base::Base; + static constexpr FeatureTag FEATURE_TAG = Base::FEATURE_TAG; + + using Context = TContext; + using Payload = typename Base::Payload; + +#ifdef HFSM2_ENABLE_UTILITY_THEORY + using RNG = typename Base::RNG; +#endif + +#ifdef HFSM2_ENABLE_LOG_INTERFACE + using Logger = typename Base::Logger; +#endif + +public: + HFSM2_INLINE explicit RC_(Context& context + HFSM2_IF_UTILITY_THEORY(, RNG& rng) + HFSM2_IF_LOG_INTERFACE(, Logger* const logger = nullptr)) noexcept + : Base{context + HFSM2_IF_UTILITY_THEORY(, rng) + HFSM2_IF_LOG_INTERFACE(, logger)} + {} + + HFSM2_INLINE void setContext(const Context& context) noexcept { _context = context ; } + HFSM2_INLINE void setContext( Context&& context) noexcept { _context = std::move(context); } + +private: + using Base::_context; }; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// TContext == ::hfsm2::EmptyContext +// TContext& + +template +class RC_ , TApex> + : public RP_, TApex> +{ + using Base = RP_, TApex>; + +public: + static constexpr FeatureTag FEATURE_TAG = Base::FEATURE_TAG; -template < + using Context = typename Base::Context; + using Payload = typename Base::Payload; #ifdef HFSM2_ENABLE_UTILITY_THEORY - typename TRank, - typename TUtility, - typename TRNG, + using RNG = typename Base::RNG; #endif - Long NSubstitutionLimit, - HFSM2_IF_PLANS(Long NTaskCapacity,) - typename TPayload, - typename TApex> -class RW_ <::hfsm2::ConfigT<::hfsm2::EmptyContext HFSM2_IF_UTILITY_THEORY(, TRank, TUtility, TRNG), NSubstitutionLimit HFSM2_IF_PLANS(, NTaskCapacity), TPayload>, TApex> final - : public RP_<::hfsm2::ConfigT<::hfsm2::EmptyContext HFSM2_IF_UTILITY_THEORY(, TRank, TUtility, TRNG), NSubstitutionLimit HFSM2_IF_PLANS(, NTaskCapacity), TPayload>, TApex> - , ::hfsm2::EmptyContext + +#ifdef HFSM2_ENABLE_LOG_INTERFACE + using Logger = typename Base::Logger; +#endif + +public: + HFSM2_INLINE explicit RC_(Context context + HFSM2_IF_UTILITY_THEORY(, RNG& rng) + HFSM2_IF_LOG_INTERFACE(, Logger* const logger = nullptr)) noexcept + : Base{context + HFSM2_IF_UTILITY_THEORY(, rng) + HFSM2_IF_LOG_INTERFACE(, logger)} + {} + + HFSM2_INLINE void setContext(Context context) noexcept { _context = context; } + +private: + using Base::_context; +}; + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +// TContext* + +template +class RC_ , TApex> + : public RP_, TApex> { - using Cfg = ::hfsm2::ConfigT<::hfsm2::EmptyContext HFSM2_IF_UTILITY_THEORY(, TRank, TUtility, TRNG), NSubstitutionLimit HFSM2_IF_PLANS(, NTaskCapacity), TPayload>; + using Base = RP_, TApex>; + +public: + static constexpr FeatureTag FEATURE_TAG = Base::FEATURE_TAG; + + using Context = typename Base::Context; + using Payload = typename Base::Payload; #ifdef HFSM2_ENABLE_UTILITY_THEORY - using RNG = TRNG; + using RNG = typename Base::RNG; #endif - using Context = typename Cfg::Context; - using Base = RP_; +#ifdef HFSM2_ENABLE_LOG_INTERFACE + using Logger = typename Base::Logger; +#endif + +public: +#ifdef HFSM2_ENABLE_UTILITY_THEORY + + HFSM2_INLINE explicit RC_(Context context + , RNG& rng + HFSM2_IF_LOG_INTERFACE(, Logger* const logger = nullptr)) noexcept + : Base{context + , rng + HFSM2_IF_LOG_INTERFACE(, logger)} + {} + +#else + + HFSM2_INLINE explicit RC_(Context context = nullptr + HFSM2_IF_LOG_INTERFACE(, Logger* const logger = nullptr)) noexcept + : Base{context + HFSM2_IF_LOG_INTERFACE(, logger)} + {} + +#endif + + HFSM2_INLINE void setContext(Context context) noexcept { _context = context; } + +private: + using Base::_context; +}; + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +// TContext == EmptyContext + +template +class RC_ , TApex> + : public RP_, TApex> + , public EmptyContext +{ + using Base = RP_, TApex>; + +public: + static constexpr FeatureTag FEATURE_TAG = Base::FEATURE_TAG; + + using Context = typename Base::Context; + using Payload = typename Base::Payload; + +#ifdef HFSM2_ENABLE_UTILITY_THEORY + using RNG = typename Base::RNG; +#endif #ifdef HFSM2_ENABLE_LOG_INTERFACE - using Logger = typename Cfg::LoggerInterface; + using Logger = typename Base::Logger; #endif public: + #ifdef HFSM2_ENABLE_UTILITY_THEORY - explicit HFSM2_INLINE RW_(RNG& rng - HFSM2_IF_LOG_INTERFACE(, Logger* const logger = nullptr)) + HFSM2_INLINE explicit RC_(RNG& rng + HFSM2_IF_LOG_INTERFACE(, Logger* const logger = nullptr)) noexcept : Base{static_cast(*this) , rng HFSM2_IF_LOG_INTERFACE(, logger)} @@ -13839,7 +13962,7 @@ class RW_ <::hfsm2::ConfigT<::hfsm2::EmptyContext HFSM2_IF_UTILITY_THEORY(, TRa #else - explicit HFSM2_INLINE RW_(HFSM2_IF_LOG_INTERFACE( Logger* const logger = nullptr)) + HFSM2_INLINE explicit RC_(HFSM2_IF_LOG_INTERFACE(Logger* const logger = nullptr)) noexcept : Base{static_cast(*this) HFSM2_IF_LOG_INTERFACE(, logger)} {} @@ -13847,43 +13970,67 @@ class RW_ <::hfsm2::ConfigT<::hfsm2::EmptyContext HFSM2_IF_UTILITY_THEORY(, TRa #endif }; +//////////////////////////////////////////////////////////////////////////////// + +/// @brief FSM Root +/// @tparam Cfg Type configuration +/// @tparam TApex Root region type +template +class RR_ final + : public RC_ +{ + using Base = RC_; + +public: + using Base::Base; +}; + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// TRNG == ::hfsm2::RandomT +// TRNG == RNGT + +#ifdef HFSM2_ENABLE_UTILITY_THEORY -template -class RW_ <::hfsm2::ConfigT), NSubstitutionLimit HFSM2_IF_PLANS(, NTaskCapacity), TPayload>, TApex> final - : public RP_<::hfsm2::ConfigT), NSubstitutionLimit HFSM2_IF_PLANS(, NTaskCapacity), TPayload>, TApex> - HFSM2_IF_UTILITY_THEORY(, ::hfsm2::RandomT) + , Long NSubstitutionLimit + HFSM2_IF_PLANS(, Long NTaskCapacity) + , typename TPayload + , typename TApex> +class RR_ ), NSubstitutionLimit HFSM2_IF_PLANS(, NTaskCapacity), TPayload>, TApex> final + : public RC_), NSubstitutionLimit HFSM2_IF_PLANS(, NTaskCapacity), TPayload>, TApex> + HFSM2_IF_UTILITY_THEORY(, public RNGT) { - using Cfg = ::hfsm2::ConfigT), NSubstitutionLimit HFSM2_IF_PLANS(, NTaskCapacity), TPayload>; + using Base = RC_), NSubstitutionLimit HFSM2_IF_PLANS(, NTaskCapacity), TPayload>, TApex>; + +public: + static constexpr FeatureTag FEATURE_TAG = Base::FEATURE_TAG; + + using Context = typename Base::Context; + using Payload = typename Base::Payload; #ifdef HFSM2_ENABLE_UTILITY_THEORY - using RNG = ::hfsm2::RandomT; + using RNG = typename Base::RNG; #endif - using Context = typename Cfg::Context; - using Base = RP_; - #ifdef HFSM2_ENABLE_LOG_INTERFACE - using Logger = typename Cfg::LoggerInterface; + using Logger = typename Base::Logger; #endif - public: #ifdef HFSM2_ENABLE_UTILITY_THEORY - explicit HFSM2_INLINE RW_(Context& context - HFSM2_IF_LOG_INTERFACE(, Logger* const logger = nullptr)) + HFSM2_INLINE explicit RR_(Context& context + HFSM2_IF_LOG_INTERFACE(, Logger* const logger = nullptr)) noexcept : Base{context , static_cast(*this) HFSM2_IF_LOG_INTERFACE(, logger)} @@ -13892,8 +14039,8 @@ class RW_ <::hfsm2::ConfigT - -#ifdef HFSM2_ENABLE_UTILITY_THEORY +// TContext == EmptyContext +// TRNG == RNGT -template -class RW_ <::hfsm2::ConfigT<::hfsm2::EmptyContext, TRank, TUtility, ::hfsm2::RandomT, NSubstitutionLimit HFSM2_IF_PLANS(, NTaskCapacity), TPayload>, TApex> final - : public RP_<::hfsm2::ConfigT<::hfsm2::EmptyContext, TRank, TUtility, ::hfsm2::RandomT, NSubstitutionLimit HFSM2_IF_PLANS(, NTaskCapacity), TPayload>, TApex> - , ::hfsm2::EmptyContext - , ::hfsm2::RandomT +/// @brief FSM Root +/// @tparam Cfg Type configuration +/// @tparam TApex Root region type +template +class RR_ , NSubstitutionLimit HFSM2_IF_PLANS(, NTaskCapacity), TPayload>, TApex> final + : public RC_, NSubstitutionLimit HFSM2_IF_PLANS(, NTaskCapacity), TPayload>, TApex> + , public RNGT { - using Cfg = ::hfsm2::ConfigT<::hfsm2::EmptyContext, TRank, TUtility, ::hfsm2::RandomT, NSubstitutionLimit HFSM2_IF_PLANS(, NTaskCapacity), TPayload>; + using Base = RC_, NSubstitutionLimit HFSM2_IF_PLANS(, NTaskCapacity), TPayload>, TApex>; - using Context = typename Cfg::Context; - using RNG = typename Cfg::RNG; - using Base = RP_; +public: + static constexpr FeatureTag FEATURE_TAG = Base::FEATURE_TAG; + + using Context = typename Base::Context; + using Payload = typename Base::Payload; + using RNG = typename Base::RNG; #ifdef HFSM2_ENABLE_LOG_INTERFACE - using Logger = typename Cfg::LoggerInterface; + using Logger = typename Base::Logger; #endif public: - explicit HFSM2_INLINE RW_(HFSM2_IF_LOG_INTERFACE(Logger* const logger = nullptr)) - : Base{static_cast(*this) - , static_cast(*this) + HFSM2_INLINE explicit RR_(HFSM2_IF_LOG_INTERFACE(Logger* const logger = nullptr)) noexcept + : Base{static_cast(*this) HFSM2_IF_LOG_INTERFACE(, logger)} , RNG{0} {} @@ -13952,7 +14102,7 @@ namespace detail { template R_::R_(Context& context HFSM2_IF_UTILITY_THEORY(, RNG& rng) - HFSM2_IF_LOG_INTERFACE(, Logger* const logger)) + HFSM2_IF_LOG_INTERFACE(, Logger* const logger)) noexcept : _context{context} HFSM2_IF_UTILITY_THEORY(, _rng{rng}) HFSM2_IF_LOG_INTERFACE(, _logger{logger}) @@ -13967,7 +14117,7 @@ R_::R_(Context& context // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - template -R_::~R_() { +R_::~R_() noexcept { PlanControl control{_context , _registry , _requests @@ -13987,7 +14137,7 @@ R_::~R_() { template void -R_::update() { +R_::update() noexcept { FullControl control{_context , _registry , _requests @@ -14015,7 +14165,7 @@ R_::update() { template template void -R_::react(const TEvent& event) { +R_::react(const TEvent& event) noexcept { FullControl control{_context , _registry , _requests @@ -14042,7 +14192,7 @@ R_::react(const TEvent& event) { template void -R_::changeTo(const StateID stateId) { +R_::changeTo(const StateID stateId) noexcept { _requests.append(Transition{stateId, TransitionType::CHANGE}); HFSM2_LOG_TRANSITION(_context, INVALID_STATE_ID, TransitionType::CHANGE, stateId); @@ -14052,7 +14202,7 @@ R_::changeTo(const StateID stateId) { template void -R_::restart(const StateID stateId) { +R_::restart(const StateID stateId) noexcept { _requests.append(Transition{stateId, TransitionType::RESTART}); HFSM2_LOG_TRANSITION(_context, INVALID_STATE_ID, TransitionType::RESTART, stateId); @@ -14062,7 +14212,7 @@ R_::restart(const StateID stateId) { template void -R_::resume(const StateID stateId) { +R_::resume(const StateID stateId) noexcept { _requests.append(Transition{stateId, TransitionType::RESUME}); HFSM2_LOG_TRANSITION(_context, INVALID_STATE_ID, TransitionType::RESUME, stateId); @@ -14074,7 +14224,7 @@ R_::resume(const StateID stateId) { template void -R_::utilize(const StateID stateId) { +R_::utilize(const StateID stateId) noexcept { _requests.append(Transition{stateId, TransitionType::UTILIZE}); HFSM2_LOG_TRANSITION(_context, INVALID_STATE_ID, TransitionType::UTILIZE, stateId); @@ -14084,7 +14234,7 @@ R_::utilize(const StateID stateId) { template void -R_::randomize(const StateID stateId) { +R_::randomize(const StateID stateId) noexcept { _requests.append(Transition{stateId, TransitionType::RANDOMIZE}); HFSM2_LOG_TRANSITION(_context, INVALID_STATE_ID, TransitionType::RANDOMIZE, stateId); @@ -14096,7 +14246,7 @@ R_::randomize(const StateID stateId) { template void -R_::schedule(const StateID stateId) { +R_::schedule(const StateID stateId) noexcept { _requests.append(Transition{stateId, TransitionType::SCHEDULE}); HFSM2_LOG_TRANSITION(_context, INVALID_STATE_ID, TransitionType::SCHEDULE, stateId); @@ -14106,7 +14256,7 @@ R_::schedule(const StateID stateId) { template void -R_::reset() { +R_::reset() noexcept { PlanControl control{_context , _registry , _requests @@ -14139,7 +14289,7 @@ R_::reset() { template void -R_::save(SerialBuffer& _buffer) const { +R_::save(SerialBuffer& _buffer) const noexcept { WriteStream stream{_buffer}; // TODO: save _registry @@ -14156,7 +14306,7 @@ R_::save(SerialBuffer& _buffer) const { template void -R_::load(const SerialBuffer& buffer) { +R_::load(const SerialBuffer& buffer) noexcept { _requests.clear(); PlanControl control{_context @@ -14201,7 +14351,7 @@ R_::load(const SerialBuffer& buffer) { template bool R_::replayTransitions(const Transition* const transitions, - const uint64_t count) + const uint64_t count) noexcept { HFSM2_IF_TRANSITION_HISTORY(_transitionTargets.clear()); HFSM2_IF_TRANSITION_HISTORY(_previousTransitions.clear()); @@ -14241,7 +14391,7 @@ R_::replayTransitions(const Transition* const transitions, template template bool -R_::replayTransitions(const Array& transitions) { +R_::replayTransitions(const ArrayT& transitions) noexcept { if (transitions.count()) return replayTransitions(&transitions[0], transitions.count()); @@ -14253,7 +14403,7 @@ R_::replayTransitions(const Array& transitions) { template const typename R_::Transition* -R_::lastTransition(const StateID stateId) const { +R_::lastTransition(const StateID stateId) const noexcept { if (HFSM2_CHECKED(stateId < StateList::SIZE)) { const Short index = _transitionTargets[stateId]; @@ -14270,7 +14420,7 @@ R_::lastTransition(const StateID stateId) const { template void -R_::initialEnter() { +R_::initialEnter() noexcept { // TODO: //HFSM2_ASSERT(_registry.empty() == 0); HFSM2_ASSERT(_requests.count() == 0); @@ -14335,7 +14485,7 @@ R_::initialEnter() { template void -R_::processTransitions(TransitionSets& currentTransitions) { +R_::processTransitions(TransitionSets& currentTransitions) noexcept { HFSM2_ASSERT(_requests.count()); RegistryBackUp registryUndo; @@ -14388,7 +14538,7 @@ template bool R_::applyRequest(Control& control, const Transition& request, - const Short index) + const Short index) noexcept { switch (request.type) { case TransitionType::CHANGE: @@ -14423,7 +14573,7 @@ R_::applyRequest(Control& control, template bool -R_::applyRequests(Control& control) { +R_::applyRequests(Control& control) noexcept { bool changesMade = false; for (Short i = 0; i < _requests.count(); ++i) @@ -14437,7 +14587,7 @@ R_::applyRequests(Control& control) { template bool R_::cancelledByEntryGuards(const TransitionSets& currentTransitions, - const TransitionSet& pendingTransitions) + const TransitionSet& pendingTransitions) noexcept { GuardControl guardControl{_context , _registry @@ -14458,7 +14608,7 @@ R_::cancelledByEntryGuards(const TransitionSets& currentTransitions, template bool R_::cancelledByGuards(const TransitionSets& currentTransitions, - const TransitionSet& pendingTransitions) + const TransitionSet& pendingTransitions) noexcept { GuardControl guardControl{_context , _registry @@ -14483,7 +14633,7 @@ template bool R_::applyRequests(Control& control, const Transition* const transitions, - const uint64_t count) + const uint64_t count) noexcept { if (HFSM2_CHECKED(transitions && count)) { bool changesMade = false; @@ -14504,7 +14654,7 @@ R_::applyRequests(Control& control, template void -R_::getStateNames() { +R_::getStateNames() noexcept { _stateInfos.clear(); _apex.deepGetNames((Long) -1, StructureStateInfo::RegionType::COMPOSITE, 0, _stateInfos); @@ -14582,7 +14732,7 @@ R_::getStateNames() { template void -R_::udpateActivity() { +R_::udpateActivity() noexcept { for (Long s = 0, i = 0; s < _stateInfos.count(); ++s) if (_stateInfos[s].name[0] != L'\0') { _structure[i].isActive = isActive(s); @@ -14612,7 +14762,7 @@ R_::udpateActivity() { template void RP_, TA>::changeWith(const StateID stateId, - const Payload& payload) + const Payload& payload) noexcept { _requests.append(Transition{stateId, TransitionType::CHANGE, payload}); @@ -14622,7 +14772,7 @@ RP_ void RP_, TA>::changeWith(const StateID stateId, - Payload&& payload) + Payload&& payload) noexcept { _requests.append(Transition{stateId, TransitionType::CHANGE, std::move(payload)}); @@ -14634,7 +14784,7 @@ RP_ void RP_, TA>::restartWith(const StateID stateId, - const Payload& payload) + const Payload& payload) noexcept { _requests.append(Transition{stateId, TransitionType::RESTART, payload}); @@ -14644,7 +14794,7 @@ RP_ void RP_, TA>::restartWith(const StateID stateId, - Payload&& payload) + Payload&& payload) noexcept { _requests.append(Transition{stateId, TransitionType::RESTART, std::move(payload)}); @@ -14656,7 +14806,7 @@ RP_ void RP_, TA>::resumeWith(const StateID stateId, - const Payload& payload) + const Payload& payload) noexcept { _requests.append(Transition{stateId, TransitionType::RESUME, payload}); @@ -14666,7 +14816,7 @@ RP_ void RP_, TA>::resumeWith(const StateID stateId, - Payload&& payload) + Payload&& payload) noexcept { _requests.append(Transition{stateId, TransitionType::RESUME, std::move(payload)}); @@ -14680,7 +14830,7 @@ RP_ void RP_, TA>::utilizeWith(const StateID stateId, - const Payload& payload) + const Payload& payload) noexcept { _requests.append(Transition{stateId, TransitionType::UTILIZE, payload}); @@ -14690,7 +14840,7 @@ RP_ void RP_, TA>::utilizeWith(const StateID stateId, - Payload&& payload) + Payload&& payload) noexcept { _requests.append(Transition{stateId, TransitionType::UTILIZE, std::move(payload)}); @@ -14702,7 +14852,7 @@ RP_ void RP_, TA>::randomizeWith(const StateID stateId, - const Payload& payload) + const Payload& payload) noexcept { _requests.append(Transition{stateId, TransitionType::RANDOMIZE, payload}); @@ -14712,7 +14862,7 @@ RP_ void RP_, TA>::randomizeWith(const StateID stateId, - Payload&& payload) + Payload&& payload) noexcept { _requests.append(Transition{stateId, TransitionType::RANDOMIZE, std::move(payload)}); @@ -14726,7 +14876,7 @@ RP_ void RP_, TA>::scheduleWith(const StateID stateId, - const Payload& payload) + const Payload& payload) noexcept { _requests.append(Transition{stateId, TransitionType::SCHEDULE, payload}); @@ -14736,7 +14886,7 @@ RP_ void RP_, TA>::scheduleWith(const StateID stateId, - Payload&& payload) + Payload&& payload) noexcept { _requests.append(Transition{stateId, TransitionType::SCHEDULE, std::move(payload)}); @@ -14777,6 +14927,7 @@ RP_ // uint32_t, uint64_t #include // memcpy_s() #include #include -#include // std::conditional<>, move(), forward() +#include // move(), forward() #if defined _DEBUG && _MSC_VER #include // __debugbreak() @@ -49,7 +55,6 @@ #include "detail/shared/array.hpp" #include "detail/shared/bit_array.hpp" #include "detail/shared/bit_stream.hpp" -#include "detail/shared/list.hpp" #include "detail/shared/random.hpp" #include "detail/shared/type_list.hpp" @@ -57,6 +62,7 @@ #include "detail/features/logger_interface.hpp" #include "detail/features/structure_report.hpp" +#include "detail/root/task_list.hpp" #include "detail/root/plan_data.hpp" #include "detail/root/plan.hpp" #include "detail/root/registry.hpp" @@ -89,7 +95,7 @@ template -struct G_ { +struct G_ final { static constexpr FeatureTag FEATURE_TAG = NFeatureTag; using Context = TContext; @@ -107,12 +113,16 @@ struct G_ { static constexpr Long SUBSTITUTION_LIMIT = NSubstitutionLimit; #ifdef HFSM2_ENABLE_PLANS - static constexpr Long TASK_CAPACITY = NTaskCapacity; + static constexpr Long TASK_CAPACITY = NTaskCapacity; #endif using Payload = TPayload; using Transition = TransitionT; +#ifdef HFSM2_ENABLE_PLANS + using Task = TaskT; +#endif + /// @brief Set Context type /// @tparam T Context type for data shared between states and/or data interface between FSM and external code template @@ -162,7 +172,7 @@ struct G_ { struct UP { HFSM2_INLINE UP(const Utility utility_ = Utility{1}, - const Short prong_ = INVALID_SHORT) + const Short prong_ = INVALID_SHORT) noexcept : utility{utility_} , prong{prong_} {} @@ -281,6 +291,7 @@ struct M_ ; //---------------------------------------------------------------------- + // COMMON /// @brief Root ('changeTo<>()' into the root region acts as 'restart<>()') /// @tparam THead Head state @@ -293,6 +304,7 @@ struct M_ using PeerRoot = RF_>; + // COMMON // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /// @brief Resumable root ('changeTo<>()' into the root region acts as 'resume<>()') @@ -357,28 +369,7 @@ struct M_ -/// @tparam TContext Context type for data shared between states and/or data interface between FSM and external code -/// @tparam TRank Rank type for 'TRank State::rank() const' method -/// @tparam TUtility Utility type for 'TUtility State::utility() const' method -/// @tparam TRNG RNG type used in 'Random' regions -/// @tparam NSubstitutionLimit Maximum number times 'guard()' methods can substitute their states for others -/// @tparam NTaskCapacity Maximum number of tasks across all plans -/// @tparam TPayload Payload type -template - #endif - - , Long NSubstitutionLimit = 4 - HFSM2_IF_PLANS(, Long NTaskCapacity = INVALID_LONG) - , typename TPayload = void> -using ConfigT = detail::G_; - -/// @brief Type configuration for MachineT<> -using Config = ConfigT<>; +using Config = detail::G_), 4 HFSM2_IF_PLANS(, INVALID_LONG), void>; /// @brief 'Template namespace' for FSM classes /// @tparam TConfig 'ConfigT<>' type configuration for MachineT<> diff --git a/projects/visual-studio/advanced_event_handling-16.vcxproj b/projects/visual-studio/advanced_event_handling-16.vcxproj index 920572d..1f6e280 100644 --- a/projects/visual-studio/advanced_event_handling-16.vcxproj +++ b/projects/visual-studio/advanced_event_handling-16.vcxproj @@ -1,6 +1,14 @@  + + ASan + Win32 + + + ASan + x64 + Debug Win32 @@ -43,6 +51,13 @@ v142 true Unicode + + + Application + false + v142 + true + Unicode true @@ -58,6 +73,14 @@ true Unicode + + Application + false + v142 + true + Unicode + true + @@ -71,6 +94,10 @@ + + + + @@ -79,6 +106,10 @@ + + + + true @@ -86,12 +117,18 @@ false + + false + true false + + false + @@ -115,6 +152,20 @@ true + + + + + MaxSpeed + true + true + WIN32;NDEBUG;%(PreprocessorDefinitions) + + + true + true + + @@ -140,6 +191,22 @@ true + + + + + MaxSpeed + true + true + NDEBUG;%(PreprocessorDefinitions) + + + + + true + true + + diff --git a/projects/visual-studio/advanced_event_handling-clang.vcxproj b/projects/visual-studio/advanced_event_handling-clang.vcxproj index 4e47d3b..af10076 100644 --- a/projects/visual-studio/advanced_event_handling-clang.vcxproj +++ b/projects/visual-studio/advanced_event_handling-clang.vcxproj @@ -1,6 +1,14 @@  + + ASan + Win32 + + + ASan + x64 + Debug Win32 @@ -44,6 +52,14 @@ true Unicode + + Application + false + ClangCL + true + Unicode + true + Application true @@ -57,6 +73,14 @@ true Unicode + + Application + false + ClangCL + true + Unicode + true + @@ -70,6 +94,10 @@ + + + + @@ -78,6 +106,10 @@ + + + + @@ -103,6 +135,20 @@ true + + + + + MaxSpeed + true + true + WIN32;NDEBUG;%(PreprocessorDefinitions) + + + true + true + + @@ -127,6 +173,20 @@ true + + + + + MaxSpeed + true + true + NDEBUG;%(PreprocessorDefinitions) + + + true + true + + diff --git a/projects/visual-studio/basic_audio_player-16.vcxproj b/projects/visual-studio/basic_audio_player-16.vcxproj index 0d673d1..05f6d4d 100644 --- a/projects/visual-studio/basic_audio_player-16.vcxproj +++ b/projects/visual-studio/basic_audio_player-16.vcxproj @@ -1,6 +1,14 @@  + + ASan + Win32 + + + ASan + x64 + Debug Win32 @@ -43,6 +51,13 @@ v142 true Unicode + + + Application + false + v142 + true + Unicode true @@ -58,6 +73,14 @@ true Unicode + + Application + false + v142 + true + Unicode + true + @@ -71,6 +94,10 @@ + + + + @@ -79,6 +106,10 @@ + + + + true @@ -86,12 +117,18 @@ false + + false + true false + + false + @@ -117,6 +154,21 @@ true + + + + + MaxSpeed + true + true + WIN32;NDEBUG;%(PreprocessorDefinitions) + %(AdditionalOptions) /d1reportSingleClassLayoutXXX + + + true + true + + @@ -142,6 +194,22 @@ true + + + + + MaxSpeed + true + true + NDEBUG;%(PreprocessorDefinitions) + + + + + true + true + + diff --git a/projects/visual-studio/basic_audio_player-clang.vcxproj b/projects/visual-studio/basic_audio_player-clang.vcxproj index e53d4ad..c5f7895 100644 --- a/projects/visual-studio/basic_audio_player-clang.vcxproj +++ b/projects/visual-studio/basic_audio_player-clang.vcxproj @@ -1,6 +1,14 @@  + + ASan + Win32 + + + ASan + x64 + Debug Win32 @@ -44,6 +52,14 @@ true Unicode + + Application + false + ClangCL + true + Unicode + true + Application true @@ -57,6 +73,14 @@ true Unicode + + Application + false + ClangCL + true + Unicode + true + @@ -70,6 +94,10 @@ + + + + @@ -78,6 +106,10 @@ + + + + @@ -103,6 +135,20 @@ true + + + + + MaxSpeed + true + true + WIN32;NDEBUG;%(PreprocessorDefinitions) + + + true + true + + @@ -127,6 +173,20 @@ true + + + + + MaxSpeed + true + true + NDEBUG;%(PreprocessorDefinitions) + + + true + true + + diff --git a/projects/visual-studio/basic_traffic_light-16.vcxproj b/projects/visual-studio/basic_traffic_light-16.vcxproj index 67b605c..93cff9f 100644 --- a/projects/visual-studio/basic_traffic_light-16.vcxproj +++ b/projects/visual-studio/basic_traffic_light-16.vcxproj @@ -1,6 +1,14 @@  + + ASan + Win32 + + + ASan + x64 + Debug Win32 @@ -43,6 +51,13 @@ v142 true Unicode + + + Application + false + v142 + true + Unicode true @@ -58,6 +73,14 @@ true Unicode + + Application + false + v142 + true + Unicode + true + @@ -71,6 +94,10 @@ + + + + @@ -79,6 +106,10 @@ + + + + true @@ -86,12 +117,18 @@ false + + false + true false + + false + @@ -117,6 +154,21 @@ true + + + + + MaxSpeed + true + true + WIN32;NDEBUG;%(PreprocessorDefinitions) + %(AdditionalOptions) /d1reportSingleClassLayoutXXX + + + true + true + + @@ -142,6 +194,22 @@ true + + + + + MaxSpeed + true + true + NDEBUG;%(PreprocessorDefinitions) + + + + + true + true + + diff --git a/projects/visual-studio/basic_traffic_light-clang.vcxproj b/projects/visual-studio/basic_traffic_light-clang.vcxproj index cbc99d5..b6d5625 100644 --- a/projects/visual-studio/basic_traffic_light-clang.vcxproj +++ b/projects/visual-studio/basic_traffic_light-clang.vcxproj @@ -1,6 +1,14 @@  + + ASan + Win32 + + + ASan + x64 + Debug Win32 @@ -44,6 +52,14 @@ true Unicode + + Application + false + ClangCL + true + Unicode + true + Application true @@ -57,6 +73,14 @@ true Unicode + + Application + false + ClangCL + true + Unicode + true + @@ -70,6 +94,10 @@ + + + + @@ -78,6 +106,10 @@ + + + + @@ -103,6 +135,20 @@ true + + + + + MaxSpeed + true + true + WIN32;NDEBUG;%(PreprocessorDefinitions) + + + true + true + + @@ -127,6 +173,20 @@ true + + + + + MaxSpeed + true + true + NDEBUG;%(PreprocessorDefinitions) + + + true + true + + diff --git a/projects/visual-studio/calculator-16.vcxproj b/projects/visual-studio/calculator-16.vcxproj index 42d5270..3a2b845 100644 --- a/projects/visual-studio/calculator-16.vcxproj +++ b/projects/visual-studio/calculator-16.vcxproj @@ -1,6 +1,14 @@  + + ASan + Win32 + + + ASan + x64 + Debug Win32 @@ -43,6 +51,13 @@ v142 true Unicode + + + Application + false + v142 + true + Unicode true @@ -58,6 +73,14 @@ true Unicode + + Application + false + v142 + true + Unicode + true + @@ -73,6 +96,11 @@ + + + + + @@ -83,6 +111,11 @@ + + + + + true @@ -90,12 +123,18 @@ false + + false + true false + + false + @@ -119,6 +158,20 @@ true + + + + + MaxSpeed + true + true + WIN32;NDEBUG;%(PreprocessorDefinitions) + + + true + true + + @@ -144,6 +197,22 @@ true + + + + + MaxSpeed + true + true + NDEBUG;%(PreprocessorDefinitions) + + + + + true + true + + diff --git a/projects/visual-studio/calculator-clang.vcxproj b/projects/visual-studio/calculator-clang.vcxproj index 30b0710..60c3c5c 100644 --- a/projects/visual-studio/calculator-clang.vcxproj +++ b/projects/visual-studio/calculator-clang.vcxproj @@ -1,6 +1,14 @@  + + ASan + Win32 + + + ASan + x64 + Debug Win32 @@ -44,6 +52,14 @@ true Unicode + + Application + false + ClangCL + true + Unicode + true + Application true @@ -57,6 +73,14 @@ true Unicode + + Application + false + ClangCL + true + Unicode + true + @@ -72,6 +96,11 @@ + + + + + @@ -82,6 +111,11 @@ + + + + + @@ -106,6 +140,20 @@ true + + + + + MaxSpeed + true + true + WIN32;NDEBUG;%(PreprocessorDefinitions) + + + true + true + + @@ -129,6 +177,20 @@ true + + + + + MaxSpeed + true + true + NDEBUG;%(PreprocessorDefinitions) + + + true + true + + diff --git a/projects/visual-studio/debug_logger_interface-16.vcxproj b/projects/visual-studio/debug_logger_interface-16.vcxproj index 9d4adc3..fc35f85 100644 --- a/projects/visual-studio/debug_logger_interface-16.vcxproj +++ b/projects/visual-studio/debug_logger_interface-16.vcxproj @@ -1,6 +1,14 @@  + + ASan + Win32 + + + ASan + x64 + Debug Win32 @@ -43,6 +51,13 @@ v142 true Unicode + + + Application + false + v142 + true + Unicode true @@ -58,6 +73,14 @@ true Unicode + + Application + false + v142 + true + Unicode + true + @@ -71,6 +94,10 @@ + + + + @@ -79,6 +106,10 @@ + + + + true @@ -86,12 +117,18 @@ false + + false + true false + + false + @@ -115,6 +152,20 @@ true + + + + + MaxSpeed + true + true + WIN32;NDEBUG;%(PreprocessorDefinitions) + + + true + true + + @@ -140,6 +191,22 @@ true + + + + + MaxSpeed + true + true + NDEBUG;%(PreprocessorDefinitions) + + + + + true + true + + diff --git a/projects/visual-studio/debug_logger_interface-clang.vcxproj b/projects/visual-studio/debug_logger_interface-clang.vcxproj index 75526ac..846de73 100644 --- a/projects/visual-studio/debug_logger_interface-clang.vcxproj +++ b/projects/visual-studio/debug_logger_interface-clang.vcxproj @@ -1,6 +1,14 @@  + + ASan + Win32 + + + ASan + x64 + Debug Win32 @@ -44,6 +52,14 @@ true Unicode + + Application + false + ClangCL + true + Unicode + true + Application true @@ -57,6 +73,14 @@ true Unicode + + Application + false + ClangCL + true + Unicode + true + @@ -70,6 +94,10 @@ + + + + @@ -78,6 +106,10 @@ + + + + @@ -103,6 +135,20 @@ true + + + + + MaxSpeed + true + true + WIN32;NDEBUG;%(PreprocessorDefinitions) + + + true + true + + @@ -127,6 +173,20 @@ true + + + + + MaxSpeed + true + true + NDEBUG;%(PreprocessorDefinitions) + + + true + true + + diff --git a/projects/visual-studio/hfsm2-16-all.sln b/projects/visual-studio/hfsm2-16-all.sln index a4633ac..2cc5249 100644 --- a/projects/visual-studio/hfsm2-16-all.sln +++ b/projects/visual-studio/hfsm2-16-all.sln @@ -178,8 +178,10 @@ Global {31CDCC89-14CF-42A9-AB27-C2E7CFB6E98D}.Release|x64.Build.0 = Release|x64 {31CDCC89-14CF-42A9-AB27-C2E7CFB6E98D}.Release|x86.ActiveCfg = Release|Win32 {31CDCC89-14CF-42A9-AB27-C2E7CFB6E98D}.Release|x86.Build.0 = Release|Win32 - {84F7FDEF-23C4-43A0-A6AE-BEDAA1AC863C}.ASan|x64.ActiveCfg = Release|x64 - {84F7FDEF-23C4-43A0-A6AE-BEDAA1AC863C}.ASan|x86.ActiveCfg = Release|Win32 + {84F7FDEF-23C4-43A0-A6AE-BEDAA1AC863C}.ASan|x64.ActiveCfg = ASan|x64 + {84F7FDEF-23C4-43A0-A6AE-BEDAA1AC863C}.ASan|x64.Build.0 = ASan|x64 + {84F7FDEF-23C4-43A0-A6AE-BEDAA1AC863C}.ASan|x86.ActiveCfg = ASan|Win32 + {84F7FDEF-23C4-43A0-A6AE-BEDAA1AC863C}.ASan|x86.Build.0 = ASan|Win32 {84F7FDEF-23C4-43A0-A6AE-BEDAA1AC863C}.Debug|x64.ActiveCfg = Debug|x64 {84F7FDEF-23C4-43A0-A6AE-BEDAA1AC863C}.Debug|x64.Build.0 = Debug|x64 {84F7FDEF-23C4-43A0-A6AE-BEDAA1AC863C}.Debug|x86.ActiveCfg = Debug|Win32 @@ -188,8 +190,10 @@ Global {84F7FDEF-23C4-43A0-A6AE-BEDAA1AC863C}.Release|x64.Build.0 = Release|x64 {84F7FDEF-23C4-43A0-A6AE-BEDAA1AC863C}.Release|x86.ActiveCfg = Release|Win32 {84F7FDEF-23C4-43A0-A6AE-BEDAA1AC863C}.Release|x86.Build.0 = Release|Win32 - {7F102606-D08C-4F7D-94B3-FCAC473DABED}.ASan|x64.ActiveCfg = Release|x64 - {7F102606-D08C-4F7D-94B3-FCAC473DABED}.ASan|x86.ActiveCfg = Release|Win32 + {7F102606-D08C-4F7D-94B3-FCAC473DABED}.ASan|x64.ActiveCfg = ASan|x64 + {7F102606-D08C-4F7D-94B3-FCAC473DABED}.ASan|x64.Build.0 = ASan|x64 + {7F102606-D08C-4F7D-94B3-FCAC473DABED}.ASan|x86.ActiveCfg = ASan|Win32 + {7F102606-D08C-4F7D-94B3-FCAC473DABED}.ASan|x86.Build.0 = ASan|Win32 {7F102606-D08C-4F7D-94B3-FCAC473DABED}.Debug|x64.ActiveCfg = Debug|x64 {7F102606-D08C-4F7D-94B3-FCAC473DABED}.Debug|x64.Build.0 = Debug|x64 {7F102606-D08C-4F7D-94B3-FCAC473DABED}.Debug|x86.ActiveCfg = Debug|Win32 @@ -198,8 +202,10 @@ Global {7F102606-D08C-4F7D-94B3-FCAC473DABED}.Release|x64.Build.0 = Release|x64 {7F102606-D08C-4F7D-94B3-FCAC473DABED}.Release|x86.ActiveCfg = Release|Win32 {7F102606-D08C-4F7D-94B3-FCAC473DABED}.Release|x86.Build.0 = Release|Win32 - {4DDF823C-C579-4259-ABEE-535F4C73FADB}.ASan|x64.ActiveCfg = Release|x64 - {4DDF823C-C579-4259-ABEE-535F4C73FADB}.ASan|x86.ActiveCfg = Release|Win32 + {4DDF823C-C579-4259-ABEE-535F4C73FADB}.ASan|x64.ActiveCfg = ASan|x64 + {4DDF823C-C579-4259-ABEE-535F4C73FADB}.ASan|x64.Build.0 = ASan|x64 + {4DDF823C-C579-4259-ABEE-535F4C73FADB}.ASan|x86.ActiveCfg = ASan|Win32 + {4DDF823C-C579-4259-ABEE-535F4C73FADB}.ASan|x86.Build.0 = ASan|Win32 {4DDF823C-C579-4259-ABEE-535F4C73FADB}.Debug|x64.ActiveCfg = Debug|x64 {4DDF823C-C579-4259-ABEE-535F4C73FADB}.Debug|x64.Build.0 = Debug|x64 {4DDF823C-C579-4259-ABEE-535F4C73FADB}.Debug|x86.ActiveCfg = Debug|Win32 @@ -232,8 +238,10 @@ Global {D2176F37-135E-4003-9A90-7A9E78E0371F}.Release|x64.Build.0 = Release|x64 {D2176F37-135E-4003-9A90-7A9E78E0371F}.Release|x86.ActiveCfg = Release|Win32 {D2176F37-135E-4003-9A90-7A9E78E0371F}.Release|x86.Build.0 = Release|Win32 - {C8ED3DA6-A666-437C-8664-FF0FBB6533A4}.ASan|x64.ActiveCfg = Release|x64 - {C8ED3DA6-A666-437C-8664-FF0FBB6533A4}.ASan|x86.ActiveCfg = Release|Win32 + {C8ED3DA6-A666-437C-8664-FF0FBB6533A4}.ASan|x64.ActiveCfg = ASan|x64 + {C8ED3DA6-A666-437C-8664-FF0FBB6533A4}.ASan|x64.Build.0 = ASan|x64 + {C8ED3DA6-A666-437C-8664-FF0FBB6533A4}.ASan|x86.ActiveCfg = ASan|Win32 + {C8ED3DA6-A666-437C-8664-FF0FBB6533A4}.ASan|x86.Build.0 = ASan|Win32 {C8ED3DA6-A666-437C-8664-FF0FBB6533A4}.Debug|x64.ActiveCfg = Debug|x64 {C8ED3DA6-A666-437C-8664-FF0FBB6533A4}.Debug|x64.Build.0 = Debug|x64 {C8ED3DA6-A666-437C-8664-FF0FBB6533A4}.Debug|x86.ActiveCfg = Debug|Win32 @@ -242,8 +250,10 @@ Global {C8ED3DA6-A666-437C-8664-FF0FBB6533A4}.Release|x64.Build.0 = Release|x64 {C8ED3DA6-A666-437C-8664-FF0FBB6533A4}.Release|x86.ActiveCfg = Release|Win32 {C8ED3DA6-A666-437C-8664-FF0FBB6533A4}.Release|x86.Build.0 = Release|Win32 - {AC8CDAE2-11B3-449F-BB88-96CCE3DE7FB3}.ASan|x64.ActiveCfg = Release|x64 - {AC8CDAE2-11B3-449F-BB88-96CCE3DE7FB3}.ASan|x86.ActiveCfg = Release|Win32 + {AC8CDAE2-11B3-449F-BB88-96CCE3DE7FB3}.ASan|x64.ActiveCfg = ASan|x64 + {AC8CDAE2-11B3-449F-BB88-96CCE3DE7FB3}.ASan|x64.Build.0 = ASan|x64 + {AC8CDAE2-11B3-449F-BB88-96CCE3DE7FB3}.ASan|x86.ActiveCfg = ASan|Win32 + {AC8CDAE2-11B3-449F-BB88-96CCE3DE7FB3}.ASan|x86.Build.0 = ASan|Win32 {AC8CDAE2-11B3-449F-BB88-96CCE3DE7FB3}.Debug|x64.ActiveCfg = Debug|x64 {AC8CDAE2-11B3-449F-BB88-96CCE3DE7FB3}.Debug|x64.Build.0 = Debug|x64 {AC8CDAE2-11B3-449F-BB88-96CCE3DE7FB3}.Debug|x86.ActiveCfg = Debug|Win32 @@ -252,8 +262,10 @@ Global {AC8CDAE2-11B3-449F-BB88-96CCE3DE7FB3}.Release|x64.Build.0 = Release|x64 {AC8CDAE2-11B3-449F-BB88-96CCE3DE7FB3}.Release|x86.ActiveCfg = Release|Win32 {AC8CDAE2-11B3-449F-BB88-96CCE3DE7FB3}.Release|x86.Build.0 = Release|Win32 - {AD845EC6-FE78-4C15-AF5A-659FB64BBD5E}.ASan|x64.ActiveCfg = Release|x64 - {AD845EC6-FE78-4C15-AF5A-659FB64BBD5E}.ASan|x86.ActiveCfg = Release|Win32 + {AD845EC6-FE78-4C15-AF5A-659FB64BBD5E}.ASan|x64.ActiveCfg = ASan|x64 + {AD845EC6-FE78-4C15-AF5A-659FB64BBD5E}.ASan|x64.Build.0 = ASan|x64 + {AD845EC6-FE78-4C15-AF5A-659FB64BBD5E}.ASan|x86.ActiveCfg = ASan|Win32 + {AD845EC6-FE78-4C15-AF5A-659FB64BBD5E}.ASan|x86.Build.0 = ASan|Win32 {AD845EC6-FE78-4C15-AF5A-659FB64BBD5E}.Debug|x64.ActiveCfg = Debug|x64 {AD845EC6-FE78-4C15-AF5A-659FB64BBD5E}.Debug|x64.Build.0 = Debug|x64 {AD845EC6-FE78-4C15-AF5A-659FB64BBD5E}.Debug|x86.ActiveCfg = Debug|Win32 @@ -282,8 +294,10 @@ Global {5D9EAEC4-CEDD-4D4F-9538-345399DA9DA1}.Release|x64.Build.0 = Release|x64 {5D9EAEC4-CEDD-4D4F-9538-345399DA9DA1}.Release|x86.ActiveCfg = Release|Win32 {5D9EAEC4-CEDD-4D4F-9538-345399DA9DA1}.Release|x86.Build.0 = Release|Win32 - {99085F16-DA06-4072-B84E-C2D95C539ED9}.ASan|x64.ActiveCfg = Release|x64 - {99085F16-DA06-4072-B84E-C2D95C539ED9}.ASan|x86.ActiveCfg = Release|Win32 + {99085F16-DA06-4072-B84E-C2D95C539ED9}.ASan|x64.ActiveCfg = ASan|x64 + {99085F16-DA06-4072-B84E-C2D95C539ED9}.ASan|x64.Build.0 = ASan|x64 + {99085F16-DA06-4072-B84E-C2D95C539ED9}.ASan|x86.ActiveCfg = ASan|Win32 + {99085F16-DA06-4072-B84E-C2D95C539ED9}.ASan|x86.Build.0 = ASan|Win32 {99085F16-DA06-4072-B84E-C2D95C539ED9}.Debug|x64.ActiveCfg = Debug|x64 {99085F16-DA06-4072-B84E-C2D95C539ED9}.Debug|x64.Build.0 = Debug|x64 {99085F16-DA06-4072-B84E-C2D95C539ED9}.Debug|x86.ActiveCfg = Debug|Win32 @@ -292,8 +306,10 @@ Global {99085F16-DA06-4072-B84E-C2D95C539ED9}.Release|x64.Build.0 = Release|x64 {99085F16-DA06-4072-B84E-C2D95C539ED9}.Release|x86.ActiveCfg = Release|Win32 {99085F16-DA06-4072-B84E-C2D95C539ED9}.Release|x86.Build.0 = Release|Win32 - {824E695C-BC39-4A3B-B93D-A4CAAD5BD69F}.ASan|x64.ActiveCfg = Release|x64 - {824E695C-BC39-4A3B-B93D-A4CAAD5BD69F}.ASan|x86.ActiveCfg = Release|Win32 + {824E695C-BC39-4A3B-B93D-A4CAAD5BD69F}.ASan|x64.ActiveCfg = ASan|x64 + {824E695C-BC39-4A3B-B93D-A4CAAD5BD69F}.ASan|x64.Build.0 = ASan|x64 + {824E695C-BC39-4A3B-B93D-A4CAAD5BD69F}.ASan|x86.ActiveCfg = ASan|Win32 + {824E695C-BC39-4A3B-B93D-A4CAAD5BD69F}.ASan|x86.Build.0 = ASan|Win32 {824E695C-BC39-4A3B-B93D-A4CAAD5BD69F}.Debug|x64.ActiveCfg = Debug|x64 {824E695C-BC39-4A3B-B93D-A4CAAD5BD69F}.Debug|x64.Build.0 = Debug|x64 {824E695C-BC39-4A3B-B93D-A4CAAD5BD69F}.Debug|x86.ActiveCfg = Debug|Win32 @@ -322,8 +338,10 @@ Global {14AA7744-5593-4107-B22E-21025E4541C1}.Release|x64.Build.0 = Release|x64 {14AA7744-5593-4107-B22E-21025E4541C1}.Release|x86.ActiveCfg = Release|Win32 {14AA7744-5593-4107-B22E-21025E4541C1}.Release|x86.Build.0 = Release|Win32 - {4C77E622-2167-417F-A6E6-32E077D4C98E}.ASan|x64.ActiveCfg = Release|x64 - {4C77E622-2167-417F-A6E6-32E077D4C98E}.ASan|x86.ActiveCfg = Release|Win32 + {4C77E622-2167-417F-A6E6-32E077D4C98E}.ASan|x64.ActiveCfg = ASan|x64 + {4C77E622-2167-417F-A6E6-32E077D4C98E}.ASan|x64.Build.0 = ASan|x64 + {4C77E622-2167-417F-A6E6-32E077D4C98E}.ASan|x86.ActiveCfg = ASan|Win32 + {4C77E622-2167-417F-A6E6-32E077D4C98E}.ASan|x86.Build.0 = ASan|Win32 {4C77E622-2167-417F-A6E6-32E077D4C98E}.Debug|x64.ActiveCfg = Debug|x64 {4C77E622-2167-417F-A6E6-32E077D4C98E}.Debug|x64.Build.0 = Debug|x64 {4C77E622-2167-417F-A6E6-32E077D4C98E}.Debug|x86.ActiveCfg = Debug|Win32 @@ -332,8 +350,10 @@ Global {4C77E622-2167-417F-A6E6-32E077D4C98E}.Release|x64.Build.0 = Release|x64 {4C77E622-2167-417F-A6E6-32E077D4C98E}.Release|x86.ActiveCfg = Release|Win32 {4C77E622-2167-417F-A6E6-32E077D4C98E}.Release|x86.Build.0 = Release|Win32 - {33A393DF-51F8-44F8-B5C9-B254A22287A7}.ASan|x64.ActiveCfg = Release|x64 - {33A393DF-51F8-44F8-B5C9-B254A22287A7}.ASan|x86.ActiveCfg = Release|Win32 + {33A393DF-51F8-44F8-B5C9-B254A22287A7}.ASan|x64.ActiveCfg = ASan|x64 + {33A393DF-51F8-44F8-B5C9-B254A22287A7}.ASan|x64.Build.0 = ASan|x64 + {33A393DF-51F8-44F8-B5C9-B254A22287A7}.ASan|x86.ActiveCfg = ASan|Win32 + {33A393DF-51F8-44F8-B5C9-B254A22287A7}.ASan|x86.Build.0 = ASan|Win32 {33A393DF-51F8-44F8-B5C9-B254A22287A7}.Debug|x64.ActiveCfg = Debug|x64 {33A393DF-51F8-44F8-B5C9-B254A22287A7}.Debug|x64.Build.0 = Debug|x64 {33A393DF-51F8-44F8-B5C9-B254A22287A7}.Debug|x86.ActiveCfg = Debug|Win32 @@ -362,8 +382,10 @@ Global {B7C89281-0060-4468-A798-6A00309A65F1}.Release|x64.Build.0 = Release|x64 {B7C89281-0060-4468-A798-6A00309A65F1}.Release|x86.ActiveCfg = Release|Win32 {B7C89281-0060-4468-A798-6A00309A65F1}.Release|x86.Build.0 = Release|Win32 - {31FB5D4F-0DEF-45B6-8342-122873F4E2DB}.ASan|x64.ActiveCfg = Release|x64 - {31FB5D4F-0DEF-45B6-8342-122873F4E2DB}.ASan|x86.ActiveCfg = Release|Win32 + {31FB5D4F-0DEF-45B6-8342-122873F4E2DB}.ASan|x64.ActiveCfg = ASan|x64 + {31FB5D4F-0DEF-45B6-8342-122873F4E2DB}.ASan|x64.Build.0 = ASan|x64 + {31FB5D4F-0DEF-45B6-8342-122873F4E2DB}.ASan|x86.ActiveCfg = ASan|Win32 + {31FB5D4F-0DEF-45B6-8342-122873F4E2DB}.ASan|x86.Build.0 = ASan|Win32 {31FB5D4F-0DEF-45B6-8342-122873F4E2DB}.Debug|x64.ActiveCfg = Debug|x64 {31FB5D4F-0DEF-45B6-8342-122873F4E2DB}.Debug|x64.Build.0 = Debug|x64 {31FB5D4F-0DEF-45B6-8342-122873F4E2DB}.Debug|x86.ActiveCfg = Debug|Win32 @@ -372,8 +394,10 @@ Global {31FB5D4F-0DEF-45B6-8342-122873F4E2DB}.Release|x64.Build.0 = Release|x64 {31FB5D4F-0DEF-45B6-8342-122873F4E2DB}.Release|x86.ActiveCfg = Release|Win32 {31FB5D4F-0DEF-45B6-8342-122873F4E2DB}.Release|x86.Build.0 = Release|Win32 - {97ABCA86-0888-4740-B478-5F6F2E7AA976}.ASan|x64.ActiveCfg = Release|x64 - {97ABCA86-0888-4740-B478-5F6F2E7AA976}.ASan|x86.ActiveCfg = Release|Win32 + {97ABCA86-0888-4740-B478-5F6F2E7AA976}.ASan|x64.ActiveCfg = ASan|x64 + {97ABCA86-0888-4740-B478-5F6F2E7AA976}.ASan|x64.Build.0 = ASan|x64 + {97ABCA86-0888-4740-B478-5F6F2E7AA976}.ASan|x86.ActiveCfg = ASan|Win32 + {97ABCA86-0888-4740-B478-5F6F2E7AA976}.ASan|x86.Build.0 = ASan|Win32 {97ABCA86-0888-4740-B478-5F6F2E7AA976}.Debug|x64.ActiveCfg = Debug|x64 {97ABCA86-0888-4740-B478-5F6F2E7AA976}.Debug|x64.Build.0 = Debug|x64 {97ABCA86-0888-4740-B478-5F6F2E7AA976}.Debug|x86.ActiveCfg = Debug|Win32 diff --git a/projects/visual-studio/snippets-16.vcxproj b/projects/visual-studio/snippets-16.vcxproj index 6f6d75c..78c5bd3 100644 --- a/projects/visual-studio/snippets-16.vcxproj +++ b/projects/visual-studio/snippets-16.vcxproj @@ -1,6 +1,14 @@  + + ASan + Win32 + + + ASan + x64 + Debug Win32 @@ -48,6 +56,13 @@ v142 true Unicode + + + Application + false + v142 + true + Unicode true @@ -63,6 +78,14 @@ true Unicode + + Application + false + v142 + true + Unicode + true + @@ -78,6 +101,11 @@ + + + + + @@ -88,6 +116,11 @@ + + + + + true @@ -95,12 +128,18 @@ false + + false + true false + + false + @@ -124,6 +163,20 @@ true + + + + + MaxSpeed + true + true + WIN32;NDEBUG;%(PreprocessorDefinitions) + + + true + true + + @@ -147,6 +200,20 @@ true + + + + + MaxSpeed + true + true + NDEBUG;%(PreprocessorDefinitions) + + + true + true + + diff --git a/projects/visual-studio/snippets-clang.vcxproj b/projects/visual-studio/snippets-clang.vcxproj index 8183bcd..9331439 100644 --- a/projects/visual-studio/snippets-clang.vcxproj +++ b/projects/visual-studio/snippets-clang.vcxproj @@ -1,6 +1,14 @@  + + ASan + Win32 + + + ASan + x64 + Debug Win32 @@ -49,6 +57,14 @@ true Unicode + + Application + false + ClangCL + true + Unicode + true + Application true @@ -62,6 +78,14 @@ true Unicode + + Application + false + ClangCL + true + Unicode + true + @@ -77,6 +101,11 @@ + + + + + @@ -87,6 +116,11 @@ + + + + + @@ -112,6 +146,20 @@ true + + + + + MaxSpeed + true + true + WIN32;NDEBUG;%(PreprocessorDefinitions) + + + true + true + + @@ -136,6 +184,20 @@ true + + + + + MaxSpeed + true + true + NDEBUG;%(PreprocessorDefinitions) + + + true + true + + diff --git a/projects/visual-studio/test-14.vcxproj b/projects/visual-studio/test-14.vcxproj index 7de9bab..c754f24 100644 --- a/projects/visual-studio/test-14.vcxproj +++ b/projects/visual-studio/test-14.vcxproj @@ -22,9 +22,12 @@ - + + + + @@ -59,11 +62,11 @@ + - @@ -87,11 +90,11 @@ + - diff --git a/projects/visual-studio/test-14.vcxproj.filters b/projects/visual-studio/test-14.vcxproj.filters index 2f05c87..37dce0f 100644 --- a/projects/visual-studio/test-14.vcxproj.filters +++ b/projects/visual-studio/test-14.vcxproj.filters @@ -39,9 +39,6 @@ test\shared - - test\shared - test @@ -99,6 +96,18 @@ test + + test + + + test + + + test\shared + + + test\shared + @@ -113,9 +122,6 @@ hfsm\detail\shared - - hfsm\detail\shared - hfsm\detail\shared @@ -188,6 +194,9 @@ hfsm\detail\features + + hfsm\detail\root + @@ -199,9 +208,6 @@ hfsm\detail\shared - - hfsm\detail\shared - hfsm\detail\structure @@ -256,5 +262,8 @@ hfsm\detail\root + + hfsm\detail\root + \ No newline at end of file diff --git a/projects/visual-studio/test-15.vcxproj b/projects/visual-studio/test-15.vcxproj index 1fcbce1..38b0898 100644 --- a/projects/visual-studio/test-15.vcxproj +++ b/projects/visual-studio/test-15.vcxproj @@ -22,9 +22,12 @@ - + + + + @@ -54,11 +57,11 @@ + - @@ -82,11 +85,11 @@ + - diff --git a/projects/visual-studio/test-15.vcxproj.filters b/projects/visual-studio/test-15.vcxproj.filters index 6e748da..f11ca6a 100644 --- a/projects/visual-studio/test-15.vcxproj.filters +++ b/projects/visual-studio/test-15.vcxproj.filters @@ -39,9 +39,6 @@ test\shared - - test\shared - test @@ -99,6 +96,18 @@ test + + test + + + test + + + test\shared + + + test\shared + @@ -113,9 +122,6 @@ hfsm\detail\shared - - hfsm\detail\shared - hfsm\detail\shared @@ -188,6 +194,9 @@ hfsm\detail\features + + hfsm\detail\root + @@ -199,9 +208,6 @@ hfsm\detail\shared - - hfsm\detail\shared - hfsm\detail\structure @@ -256,5 +262,8 @@ hfsm\detail\root + + hfsm\detail\root + \ No newline at end of file diff --git a/projects/visual-studio/test-16.vcxproj b/projects/visual-studio/test-16.vcxproj index 339a994..2837f52 100644 --- a/projects/visual-studio/test-16.vcxproj +++ b/projects/visual-studio/test-16.vcxproj @@ -30,10 +30,12 @@ - + + + @@ -63,11 +65,11 @@ + - @@ -91,11 +93,11 @@ + - diff --git a/projects/visual-studio/test-16.vcxproj.filters b/projects/visual-studio/test-16.vcxproj.filters index 736d874..ae753d3 100644 --- a/projects/visual-studio/test-16.vcxproj.filters +++ b/projects/visual-studio/test-16.vcxproj.filters @@ -39,9 +39,6 @@ test\shared - - test\shared - test @@ -102,6 +99,15 @@ test + + test + + + test + + + test\shared + @@ -116,9 +122,6 @@ hfsm\detail\shared - - hfsm\detail\shared - hfsm\detail\shared @@ -191,6 +194,9 @@ hfsm\detail\features + + hfsm\detail\root + @@ -202,9 +208,6 @@ hfsm\detail\shared - - hfsm\detail\shared - hfsm\detail\structure @@ -259,5 +262,8 @@ hfsm\detail\root + + hfsm\detail\root + \ No newline at end of file diff --git a/projects/visual-studio/test-clang.vcxproj b/projects/visual-studio/test-clang.vcxproj index 6ee8486..6b1d17d 100644 --- a/projects/visual-studio/test-clang.vcxproj +++ b/projects/visual-studio/test-clang.vcxproj @@ -30,10 +30,12 @@ - + + + @@ -63,11 +65,11 @@ + - @@ -91,11 +93,11 @@ + - diff --git a/projects/visual-studio/test-clang.vcxproj.filters b/projects/visual-studio/test-clang.vcxproj.filters index 66bd34c..65002a3 100644 --- a/projects/visual-studio/test-clang.vcxproj.filters +++ b/projects/visual-studio/test-clang.vcxproj.filters @@ -39,9 +39,6 @@ test\shared - - test\shared - test @@ -102,6 +99,15 @@ test + + test + + + test + + + test\shared + @@ -116,9 +122,6 @@ hfsm\detail\shared - - hfsm\detail\shared - hfsm\detail\shared @@ -191,6 +194,9 @@ hfsm\detail\features + + hfsm\detail\root + @@ -202,9 +208,6 @@ hfsm\detail\shared - - hfsm\detail\shared - hfsm\detail\structure @@ -259,5 +262,8 @@ hfsm\detail\root + + hfsm\detail\root + \ No newline at end of file diff --git a/test/shared/test_bit_array.cpp b/test/shared/test_bit_array.cpp index 9669b78..3a9ea8c 100644 --- a/test/shared/test_bit_array.cpp +++ b/test/shared/test_bit_array.cpp @@ -4,10 +4,10 @@ namespace test_bit_array { //////////////////////////////////////////////////////////////////////////////// -using BitArray = hfsm2::detail::BitArray; +using BitArray = hfsm2::detail::BitArrayT; using Bits = typename BitArray::Bits; -TEST_CASE("Shared.BitArray<>", "[shared]") { +TEST_CASE("Shared.BitArrayT<>", "[shared]") { BitArray bitArray; bitArray.clear(); diff --git a/test/shared/test_bit_stream.cpp b/test/shared/test_bit_stream.cpp index 1fd7c9b..7dc6ca7 100644 --- a/test/shared/test_bit_stream.cpp +++ b/test/shared/test_bit_stream.cpp @@ -1,11 +1,12 @@ +#define HFSM2_ENABLE_SERIALIZATION #include "../tools.hpp" namespace test_bit_stream { //////////////////////////////////////////////////////////////////////////////// -using WriteStream = hfsm2::detail::BitWriteStream<46>; -using ReadStream = hfsm2::detail::BitReadStream <46>; +using WriteStream = hfsm2::detail::BitWriteStreamT<46>; +using ReadStream = hfsm2::detail::BitReadStreamT <46>; using StreamBuffer = typename WriteStream::Buffer; //------------------------------------------------------------------------------ diff --git a/test/shared/test_random.cpp b/test/shared/test_random.cpp index 0dcf64b..99a06c4 100644 --- a/test/shared/test_random.cpp +++ b/test/shared/test_random.cpp @@ -9,7 +9,7 @@ template void testUniformity(const int average) { using Type = T; - using Random = hfsm2::RandomT; + using Random = hfsm2::RNGT; Random random{0}; int histogram[10] = {0}; diff --git a/test/shared/test_list.cpp b/test/shared/test_task_list.cpp similarity index 65% rename from test/shared/test_list.cpp rename to test/shared/test_task_list.cpp index ad7588d..172d317 100644 --- a/test/shared/test_list.cpp +++ b/test/shared/test_task_list.cpp @@ -1,10 +1,11 @@ +#define HFSM2_ENABLE_PLANS #include "../tools.hpp" -namespace test_list { +namespace test_task_list { //////////////////////////////////////////////////////////////////////////////// -using List = hfsm2::detail::List; +using List = hfsm2::detail::TaskListT; //------------------------------------------------------------------------------ @@ -16,14 +17,18 @@ TEST_CASE("Shared.List<>", "[shared]") { WHEN("fill, delete and re-insert an element") { for (List::Index i = 0; i < CAPACITY; ++i) { - const auto index = list.emplace(i); + const auto index = list.emplace((hfsm2::Long) i, + (hfsm2::Long) i, + hfsm2::TransitionType::COUNT); REQUIRE(index == i); //-V521 REQUIRE(list.count() == i + 1); //-V521 } for (List::Index i = 0; i < CAPACITY; ++i) - REQUIRE(list[i] == i); //-V521 + REQUIRE(list[i] == hfsm2::detail::TaskBase{(hfsm2::Long) i, + (hfsm2::Long) i, + hfsm2::TransitionType::COUNT}); //-V521 THEN("at the start") { REQUIRE(list.count() == CAPACITY); //-V521 @@ -31,7 +36,9 @@ TEST_CASE("Shared.List<>", "[shared]") { list.remove(0); REQUIRE(list.count() == CAPACITY - 1); //-V521 - const auto index = list.emplace(0u); + const auto index = list.emplace((hfsm2::Long) 0u, + (hfsm2::Long) 0u, + hfsm2::TransitionType::COUNT); REQUIRE(index == 0); //-V521 REQUIRE(list.count() == CAPACITY); //-V521 } @@ -43,7 +50,9 @@ TEST_CASE("Shared.List<>", "[shared]") { list.remove(mid); REQUIRE(list.count() == CAPACITY - 1); //-V521 - const auto index = list.emplace(mid); + const auto index = list.emplace((hfsm2::Long) mid, + (hfsm2::Long) mid, + hfsm2::TransitionType::COUNT); REQUIRE(index == mid); //-V521 REQUIRE(list.count() == CAPACITY); //-V521 } @@ -55,7 +64,9 @@ TEST_CASE("Shared.List<>", "[shared]") { list.remove(end); REQUIRE(list.count() == CAPACITY - 1); //-V521 - const auto index = list.emplace(end); + const auto index = list.emplace((hfsm2::Long) end, + (hfsm2::Long) end, + hfsm2::TransitionType::COUNT); REQUIRE(index == end); //-V521 REQUIRE(list.count() == CAPACITY); //-V521 } @@ -63,14 +74,18 @@ TEST_CASE("Shared.List<>", "[shared]") { WHEN("fill, delete all and re-insert all elements") { for (List::Index i = 0; i < CAPACITY; ++i) { - const auto index = list.emplace(i); + const auto index = list.emplace((hfsm2::Long) i, + (hfsm2::Long) i, + hfsm2::TransitionType::COUNT); REQUIRE(index == i); //-V521 REQUIRE(list.count() == i + 1); //-V521 } for (List::Index i = 0; i < CAPACITY; ++i) - REQUIRE(list[i] == i); //-V521 + REQUIRE(list[i] == hfsm2::detail::TaskBase{(hfsm2::Long) i, + (hfsm2::Long) i, + hfsm2::TransitionType::COUNT}); //-V521 THEN("from the start") { REQUIRE(list.count() == CAPACITY); //-V521 @@ -81,7 +96,9 @@ TEST_CASE("Shared.List<>", "[shared]") { } for (List::Index i = 0; i < CAPACITY; ++i) { - const auto index = list.emplace(i); + const auto index = list.emplace((hfsm2::Long) i, + (hfsm2::Long) i, + hfsm2::TransitionType::COUNT); REQUIRE(index == CAPACITY - 1 - i); //-V521 REQUIRE(list.count() == i + 1); //-V521 @@ -101,7 +118,9 @@ TEST_CASE("Shared.List<>", "[shared]") { } for (List::Index i = 0; i < CAPACITY; ++i) { - const auto index = list.emplace(i); + const auto index = list.emplace((hfsm2::Long) i, + (hfsm2::Long) i, + hfsm2::TransitionType::COUNT); REQUIRE(index == i); //-V521 REQUIRE(list.count() == i + 1); //-V521 diff --git a/test/test_contexts.cpp b/test/test_contexts.cpp new file mode 100644 index 0000000..befca29 --- /dev/null +++ b/test/test_contexts.cpp @@ -0,0 +1,142 @@ +#include +#include + +namespace test_contexts { + +//------------------------------------------------------------------------------ + +using Context = int; + +//////////////////////////////////////////////////////////////////////////////// + +namespace value_context { + +using M = hfsm2::MachineT>; + +struct A; +struct B; + +using FSM = M::PeerRoot; + +struct A : FSM::State {}; +struct B : FSM::State {}; + +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace reference_context { + +using M = hfsm2::MachineT>; + +struct A; +struct B; + +using FSM = M::PeerRoot; + +struct A : FSM::State {}; +struct B : FSM::State {}; + +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace pointer_context { + +using M = hfsm2::MachineT>; + +struct A; +struct B; + +using FSM = M::PeerRoot; + +struct A : FSM::State {}; +struct B : FSM::State {}; + +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace no_context { + +using M = hfsm2::Machine; + +struct A; +struct B; + +using FSM = M::PeerRoot; + +struct A : FSM::State {}; +struct B : FSM::State {}; + +} + +//////////////////////////////////////////////////////////////////////////////// + +TEST_CASE("FSM.Contexts", "[machine]") { + Context primary = 7; + Context secondary = -39; + + // context is a value + { + using Instance = value_context::FSM::Instance; + static_assert(std::is_same::value, ""); + + //Instance defaultConstructed; + + const Instance constant{primary}; + REQUIRE(constant.context() == primary); + + Instance machine{primary}; + REQUIRE(machine.context() == primary); + + machine.setContext(secondary); + REQUIRE(machine.context() == secondary); + + machine.setContext(8); + REQUIRE(machine.context() == 8); + } + + // context is a reference + { + using Instance = reference_context::FSM::Instance; + static_assert(std::is_same::value, ""); + + const Instance constant{primary}; + REQUIRE(constant.context() == primary); + + Instance machine{primary}; + REQUIRE(machine.context() == primary); + + machine.setContext(secondary); + REQUIRE(machine.context() == secondary); + } + + // context is a pointer + { + using Instance = pointer_context::FSM::Instance; + static_assert(std::is_same::value, ""); + + pointer_context::FSM::Instance defaultConstructed; + REQUIRE(defaultConstructed.context() == nullptr); + + const Instance constant{&primary}; + REQUIRE(constant.context() == &primary); + + Instance machine{&primary}; + REQUIRE(machine.context() == &primary); + + machine.setContext(&secondary); + REQUIRE(machine.context() == &secondary); + } + + // empty context + { + no_context::FSM::Instance defaultConstructed; + static_assert(std::is_same::value, ""); + } +} + +//////////////////////////////////////////////////////////////////////////////// + +} diff --git a/test/test_contexts_random.cpp b/test/test_contexts_random.cpp new file mode 100644 index 0000000..83c2ca7 --- /dev/null +++ b/test/test_contexts_random.cpp @@ -0,0 +1,148 @@ +#define HFSM2_ENABLE_UTILITY_THEORY +#include +#include + +namespace test_contexts_random { + +//------------------------------------------------------------------------------ + +using Context = int; + +struct DummyRNG { + inline float next() noexcept { return 0.0f; } +}; + +//////////////////////////////////////////////////////////////////////////////// + +namespace value_context { + +using M = hfsm2::MachineT::RandomT>; + +struct A; +struct B; + +using FSM = M::PeerRoot; + +struct A : FSM::State {}; +struct B : FSM::State {}; + +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace reference_context { + +using M = hfsm2::MachineT::RandomT>; + +struct A; +struct B; + +using FSM = M::PeerRoot; + +struct A : FSM::State {}; +struct B : FSM::State {}; + +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace pointer_context { + +using M = hfsm2::MachineT::RandomT>; + +struct A; +struct B; + +using FSM = M::PeerRoot; + +struct A : FSM::State {}; +struct B : FSM::State {}; + +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace no_context { + +using M = hfsm2::MachineT>; + +struct A; +struct B; + +using FSM = M::PeerRoot; + +struct A : FSM::State {}; +struct B : FSM::State {}; + +} + +//////////////////////////////////////////////////////////////////////////////// + +TEST_CASE("FSM.Contexts Random", "[machine]") { + Context primary = 7; + Context secondary = -39; + DummyRNG rng; + + // context is a value + { + using Instance = value_context::FSM::Instance; + static_assert(std::is_same::value, ""); + + //Instance defaultConstructed; + + const Instance constant{primary, rng}; + REQUIRE(constant.context() == primary); + + Instance machine{primary, rng}; + REQUIRE(machine.context() == primary); + + machine.setContext(secondary); + REQUIRE(machine.context() == secondary); + + machine.setContext(8); + REQUIRE(machine.context() == 8); + } + + // context is a reference + { + using Instance = reference_context::FSM::Instance; + static_assert(std::is_same::value, ""); + + const Instance constant{primary, rng}; + REQUIRE(constant.context() == primary); + + Instance machine{primary, rng}; + REQUIRE(machine.context() == primary); + + machine.setContext(secondary); + REQUIRE(machine.context() == secondary); + } + + // context is a pointer + { + using Instance = pointer_context::FSM::Instance; + static_assert(std::is_same::value, ""); + + pointer_context::FSM::Instance defaultConstructed(nullptr, rng); + REQUIRE(defaultConstructed.context() == nullptr); + + const Instance constant{&primary, rng}; + REQUIRE(constant.context() == &primary); + + Instance machine{&primary, rng}; + REQUIRE(machine.context() == &primary); + + machine.setContext(&secondary); + REQUIRE(machine.context() == &secondary); + } + + // empty context + { + no_context::FSM::Instance defaultConstructed(rng); + static_assert(std::is_same::value, ""); + } +} + +//////////////////////////////////////////////////////////////////////////////// + +} diff --git a/test/test_dynamic.cpp b/test/test_dynamic.cpp index cf353a5..74c25a1 100644 --- a/test/test_dynamic.cpp +++ b/test/test_dynamic.cpp @@ -117,7 +117,7 @@ const Types all = { //------------------------------------------------------------------------------ template -using TypeList = hfsm2::TypeList; +using TypeList = hfsm2::detail::TL_; //------------------------------------------------------------------------------ diff --git a/test/tools.hpp b/test/tools.hpp index 5914247..d11fc2e 100644 --- a/test/tools.hpp +++ b/test/tools.hpp @@ -117,44 +117,44 @@ struct LoggerT void recordMethod(Context& context, const StateID origin, - const Method method) override; + const Method method) noexcept override; void recordTransition(Context& context, const StateID origin, const TransitionType transitionType, - const StateID target) override; + const StateID target) noexcept override; #ifdef HFSM2_ENABLE_PLANS void recordTaskStatus(Context& context, const RegionID region, const StateID origin, - const StatusEvent event) override; + const StatusEvent event) noexcept override; void recordPlanStatus(Context& context, const RegionID region, - const StatusEvent event) override; + const StatusEvent event) noexcept override; #endif void recordCancelledPending(Context& context, - const StateID origin) override; + const StateID origin) noexcept override; #ifdef HFSM2_ENABLE_UTILITY_THEORY void recordUtilityResolution(Context& context, const StateID head, const StateID prong, - const Utilty utilty) override; + const Utilty utilty) noexcept override; void recordRandomResolution(Context& context, const StateID head, const StateID prong, - const Utilty utilty) override; + const Utilty utilty) noexcept override; #endif - void assertSequence(const Events& reference); + void assertSequence(const Events& reference) noexcept; Events history; }; @@ -167,19 +167,19 @@ using Types = std::vector; template void assertActive(TMachine& machine, const Types& all, - const Types& toCheck); + const Types& toCheck) noexcept; template void assertResumable(TMachine& machine, const Types& all, - const Types& toCheck); + const Types& toCheck) noexcept; #ifdef HFSM2_ENABLE_TRANSITION_HISTORY template void assertLastTransitions(TMachine& machine, const Types& all, - const Types& toCheck); + const Types& toCheck) noexcept; #endif diff --git a/test/tools.inl b/test/tools.inl index 1a29192..7d250d6 100644 --- a/test/tools.inl +++ b/test/tools.inl @@ -4,7 +4,7 @@ template void LoggerT::recordMethod(Context& /*context*/, const StateID origin, - const Method method) + const Method method) noexcept { REQUIRE(hfsm2::methodName(method)); @@ -82,7 +82,7 @@ void LoggerT::recordTransition(Context& /*context*/, const StateID origin, const TransitionType transitionType, - const StateID target) + const StateID target) noexcept { REQUIRE(hfsm2::transitionName(transitionType)); @@ -129,7 +129,7 @@ void LoggerT::recordTaskStatus(Context& /*context*/, const RegionID region, const StateID origin, - const StatusEvent event) + const StatusEvent event) noexcept { switch (event) { case StatusEvent::SUCCEEDED: @@ -151,7 +151,7 @@ template void LoggerT::recordPlanStatus(Context& /*context*/, const RegionID region, - const StatusEvent event) + const StatusEvent event) noexcept { switch (event) { case StatusEvent::SUCCEEDED: @@ -178,7 +178,7 @@ void LoggerT::recordUtilityResolution(Context& /*context*/, const StateID head, const StateID prong, - const Utilty utilty) + const Utilty utilty) noexcept { history.emplace_back(head, Event::Type::UTILITY_RESOLUTION, prong, utilty); } @@ -190,7 +190,7 @@ void LoggerT::recordRandomResolution(Context& /*context*/, const StateID head, const StateID prong, - const Utilty utilty) + const Utilty utilty) noexcept { history.emplace_back(head, Event::Type::RANDOM_RESOLUTION, prong, utilty); } @@ -202,7 +202,7 @@ LoggerT::recordRandomResolution(Context& /*context*/, template void LoggerT::recordCancelledPending(Context& /*context*/, - const StateID origin) + const StateID origin) noexcept { history.emplace_back(origin, Event::Type::CANCEL_PENDING); } @@ -211,7 +211,7 @@ LoggerT::recordCancelledPending(Context& /*context*/, template void -LoggerT::assertSequence(const Events& reference) { +LoggerT::assertSequence(const Events& reference) noexcept { const auto count = std::max(history.size(), reference.size()); for (unsigned i = 0; i < count; ++i) { @@ -236,7 +236,7 @@ template void assertActive(TMachine& machine, const Types& all, - const Types& toCheck) + const Types& toCheck) noexcept { for (const auto& type : all) { if (std::find(toCheck.begin(), toCheck.end(), type) != toCheck.end()) @@ -252,7 +252,7 @@ template void assertResumable(TMachine& machine, const Types& all, - const Types& toCheck) + const Types& toCheck) noexcept { for (const auto& type : all) { if (std::find(toCheck.begin(), toCheck.end(), type) != toCheck.end()) @@ -270,7 +270,7 @@ template void assertLastTransitions(TMachine& machine, const Types& all, - const Types& toCheck) + const Types& toCheck) noexcept { for (const auto& type : all) { if (std::find(toCheck.begin(), toCheck.end(), type) != toCheck.end())