Fawkes API  Fawkes Development Version
protoboard_types.h
1 
2 /***************************************************************************
3  * Protoboard plugin template
4  * - General forward declarations
5  *
6  * Copyright 2019 Victor MatarĂ©
7  ****************************************************************************/
8 
9 /* This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU Library General Public License for more details.
18  *
19  * Read the full text in the LICENSE.GPL file in the doc directory.
20  */
21 
22 #ifndef PROTOBOARD_TYPES_H_
23 #define PROTOBOARD_TYPES_H_
24 
25 #include <boost/bimap.hpp>
26 #include <memory>
27 #include <unordered_map>
28 
29 namespace protoboard {
30 
31 class pb_convert;
32 
33 typedef std::unordered_map<std::string, std::shared_ptr<pb_convert>> pb_conversion_map;
34 
35 /**
36  * Helper structure to wrap a list of types into a single type.
37  */
38 template <typename... Ts>
39 struct type_list
40 {
41 };
42 
43 class BlackboardManager;
44 
45 template <class IfaceT>
47 
48 /**
49  * A compile-time constant bidirectional map that can be used to match blackboard interface enum
50  * values to ProtoBuf's enum values
51  * @tparam pbEnumT a ProtoBuf enum type
52  * @tparam bbEnumT a blackboard interface enum type
53  */
54 template <class pbEnumT, class bbEnumT>
55 class enum_map
56 {
57 private:
58  typedef boost::bimap<pbEnumT, bbEnumT> bimapT;
59 
60 public:
61  /**
62  * constexpr constructor
63  * @param init A curly-brace initializer list that defines the entire mapping
64  */
65  constexpr enum_map(std::initializer_list<typename bimapT::value_type> init)
66  : list(init), map(list.begin(), list.end())
67  {
68  }
69 
70  /**
71  * @param v a ProtoBuf enum value
72  * @return the mapped blackboard interface enum value
73  */
74  constexpr const bbEnumT &
75  of(pbEnumT v) const
76  {
77  return map.left.at(v);
78  }
79 
80  /**
81  * @param v a blackboard interface enum value
82  * @return the mapped ProtoBuf enum value
83  */
84  constexpr const pbEnumT &
85  of(bbEnumT v) const
86  {
87  return map.right.at(v);
88  }
89 
90 private:
91  const std::vector<typename bimapT::value_type> list;
92  const bimapT map;
93 };
94 
95 } // namespace protoboard
96 
97 #endif // PROTOBOARD_TYPES_H_
The main thread that is woken each time a message arrives on any of the interfaces watched by a bb_if...
A compile-time constant bidirectional map that can be used to match blackboard interface enum values ...
constexpr const pbEnumT & of(bbEnumT v) const
constexpr enum_map(std::initializer_list< typename bimapT::value_type > init)
constexpr constructor
constexpr const bbEnumT & of(pbEnumT v) const
Helper structure to wrap a list of types into a single type.