Coder Social home page Coder Social logo

p-groarke / fea_state_machines Goto Github PK

View Code? Open in Web Editor NEW
22.0 4.0 2.0 101 KB

A Buffet Of C++17 State Machines

License: BSD 3-Clause "New" or "Revised" License

CMake 2.74% C++ 97.26%
state-machines state-machine fsm fsm-library hfsm state-charts cpp17 header-only

fea_state_machines's Introduction


This repository is inactive and kept for posterity's sake.

Any further development will happen in fea_libs. Cheers.



fea_state_machines

Build status Build Status

A buffet of state machines.

Available Machines

Each header contains a more detailed explanation of the state machine's features, design and limitations. Here is a quick overview.

fsm.hpp

This is a stack based state machine. It is very fast and supports the most essential fsm features. Under the hood, it uses std::array and std::function. This is a great fsm if you need many machines running concurrently, or you need a very fast runtime machine. The design is very simple, making it robust and easy to debug.

hfsm.hpp

This is the "big boi". A full implementation of a hierarchical finite state machine (aka state chart). It is a heap fsm, evaluation uses a queue to process your events. It has all the bells and whistles : transition guards, auto transition guards, history state, parallel states, parent/children states, etc. Use this for very complex behavior you need to manage.

constexpr_fsm.hpp

This is a compile-time executable state machine. It is mostly a novel design to experiment with the possibilities opened up when creating a truly constexpr state machine. The features are quite limited, though you have the added benefit of compile-time validation. For experimentation only, a thorough deep-dive is available in this blog post.

inlined_fsm

TODO: This will be a mirror state machine to fsm.hpp. It should have a reasonable amount of features, with less overhead using std::tuple and storing your functions directly without the need of std::function or C pointers. If this gains feature parity with fsm.hpp, it will replace it.

Build

fea_state_machines is a header only state machine lib with no dependencies other than the stl.

The unit tests depend on gtest. They are not built by default.

Install recent conan, cmake and compiler.

mkdir build && cd build
cmake .. -DBUILD_TESTING=On && cmake --build . --config debug
bin/fea_state_machines_tests.exe

// Optionally
cmake --build . --target install

fea_state_machines's People

Contributors

p-groarke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

griels swmobile

fea_state_machines's Issues

Question regarding member function

The machine now supports member function callbacks.
When using member function callbacks, add an object pointer as the first argument to your callback, like you would with std::function.
For example : fea::fsm_builder<my_transitions, my_states, void(MyObj*, bool, int)>
Then, add events using references to your member function pointer : add_event<fsm_event::on_enter>(&MyObj::my_enter_func)

Regarding this:
Before that, I've used member funtions like this:
add_event<fsm_event::on_enter>(std::bind(&MyObj::MyEnterFnc, this, std::placeholders::_1, std::placeholders::_2));

Do you know if there are some performance / memory differences between those two?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.