Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
18a7d6b69387dbd6224f150f62b177ff0a7cc3ac
[simgrid.git] / include / xbt / automaton.hpp
1 /* Copyright (c) 2015-2023. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #ifndef XBT_AUTOMATON_HPP
8 #define XBT_AUTOMATON_HPP
9
10 #include <utility>
11
12 #include <xbt/automaton.h>
13
14 namespace simgrid::xbt {
15
16 /** Add a proposition to an automaton (the C++ way)
17  *
18  *  This API hides all the callback and dynamic allocation hell from
19  *  the used which can use C++ style functors and lambda expressions.
20  */
21 template <class F> xbt_automaton_propositional_symbol_t add_proposition(const_xbt_automaton_t a, const char* id, F f)
22 {
23   auto* callback = new F(std::move(f));
24   return xbt_automaton_propositional_symbol_new_callback(
25       a, id, [](auto* cb) -> int { return (*(F*)cb)(); }, callback, [](auto* cb) -> void { delete (F*)cb; });
26 }
27
28 } // namespace simgrid::xbt
29 #endif