Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix HAVE_FOOBAR flags handling
[simgrid.git] / include / xbt / automaton.hpp
1 /* Copyright (c) 2015. 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 {
15 namespace xbt {
16
17 /** Add a proposition to an automaton (the C++ way)
18  *
19  *  This API hides all the callback and dynamic allocation hell from
20  *  the used which can use C++ style functors and lambda expressions.
21  */
22 template<class F>
23 xbt_automaton_propositional_symbol_t add_proposition(
24   xbt_automaton_t a, const char* id, F f)
25 {
26   F* callback = new F(std::move(f));
27   return xbt_automaton_propositional_symbol_new_callback(
28     a, id,
29     [](void* callback) -> int { return (*(F*)callback)(); },
30     callback,
31     [](void* callback) -> void { delete (F*)callback; }
32   );
33 }
34
35 }
36 }
37 #endif