iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
StateDefinitionHelpers.H
Go to the documentation of this file.
1 /*! @file
2  @author Randolph Voorhies (voorhies at usc dot edu)
3  @copyright GNU Public License (GPL v3)
4  @section License
5  @verbatim
6  // ////////////////////////////////////////////////////////////////////////
7  // The iLab Neuromorphic Robotics Toolkit (NRT) //
8  // Copyright 2010-2012 by the University of Southern California (USC) //
9  // and the iLab at USC. //
10  // //
11  // iLab - University of Southern California //
12  // Hedco Neurociences Building, Room HNB-10 //
13  // Los Angeles, Ca 90089-2520 - USA //
14  // //
15  // See http://ilab.usc.edu for information about this project. //
16  // ////////////////////////////////////////////////////////////////////////
17  // This file is part of The iLab Neuromorphic Robotics Toolkit. //
18  // //
19  // The iLab Neuromorphic Robotics Toolkit is free software: you can //
20  // redistribute it and/or modify it under the terms of the GNU General //
21  // Public License as published by the Free Software Foundation, either //
22  // version 3 of the License, or (at your option) any later version. //
23  // //
24  // The iLab Neuromorphic Robotics Toolkit is distributed in the hope //
25  // that it will be useful, but WITHOUT ANY WARRANTY; without even the //
26  // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //
27  // PURPOSE. See the GNU General Public License for more details. //
28  // //
29  // You should have received a copy of the GNU General Public License //
30  // along with The iLab Neuromorphic Robotics Toolkit. If not, see //
31  // <http://www.gnu.org/licenses/>. //
32  // ////////////////////////////////////////////////////////////////////////
33  @endverbatim */
34 
35 
36 #ifndef INCLUDE_NRT_PROBABILISTIC_TYPES_DETAILS_STATEDEFINITIONHELPERS_H
37 #define INCLUDE_NRT_PROBABILISTIC_TYPES_DETAILS_STATEDEFINITIONHELPERS_H
38 
39 #define STATE_FIELD_GROUP_STRUCT_NAME(r, data, elem) \
40  BOOST_PP_CAT(NRT_STATE_FIELD_GROUP_STRUCT_,BOOST_PP_CAT(data,BOOST_PP_CAT(_,elem)))
41 
42 #define DEF_STATE_FIELD_GROUP_STRUCT(r, data, elem) \
43  class STATE_FIELD_GROUP_STRUCT_NAME(r, data, elem) : public nrt::StateFieldBase {};
44 
45 #define DEF_STATE_FIELD_GROUP(r, data, elem) \
46  typedef STATE_FIELD_GROUP_STRUCT_NAME(r, data, elem) elem;
47 
48 #define NRT_CREATE_STATE_FIELD_GROUP(StateFieldGroupName, Fields) \
49  BOOST_PP_SEQ_FOR_EACH(DEF_STATE_FIELD_GROUP_STRUCT,StateFieldGroupName, Fields) \
50  class StateFieldGroupName : public nrt::StateFieldGroupBase { \
51  public: \
52  BOOST_PP_SEQ_FOR_EACH(DEF_STATE_FIELD_GROUP, StateFieldGroupName, Fields) \
53  typedef boost::mpl::vector< \
54  BOOST_PP_SEQ_ENUM(Fields) \
55  > fields; \
56  static size_t const num_fields = boost::mpl::size<fields>::value; \
57  }
58 
59 namespace nrt
60 {
61  template <class ... StateFields> struct ConcatenateFields { };
62  template <> struct ConcatenateFields<>
63  {
64  typedef boost::mpl::vector<> fields;
65  };
66 
67  template<class Head, class ... Tail>
68  struct ConcatenateFields<Head, Tail...>
69  {
70  typedef Head head;
71  typedef typename head::fields headfields;
72  typedef typename ConcatenateFields<Tail...>::fields tailfields;
73 
74  typedef
75  typename boost::mpl::insert_range
76  <
77  headfields,
78  typename boost::mpl::end<headfields>::type,
79  tailfields
80  >::type fields;
81  };
82 
83  template<class ...FieldGroups> struct ConcatenateFieldGroups { };
84  template <> struct ConcatenateFieldGroups<>
85  {
86  typedef boost::mpl::vector<> groups;
87  };
88 
89  template<class Head, class ...Tail>
90  struct ConcatenateFieldGroups<Head, Tail...>
91  {
92  typedef typename ConcatenateFieldGroups<Tail...>::groups tailgroups;
93  typedef
94  typename boost::mpl::push_front
95  <
96  tailgroups,
97  Head
98  >::type groups;
99  };
100 
101  class StateDefinitionBase {};
102  class StateFieldGroupBase {};
103  class StateFieldBase {};
104 
105  template<class Field>
106  constexpr bool is_state_field()
107  {
108  return std::is_base_of<StateFieldBase, Field>::value;
109  }
110 
111  template<class Field1, class Field2>
112  constexpr bool are_state_fields()
113  {
114  return std::is_base_of<StateFieldBase, Field1>::value &&
115  std::is_base_of<StateFieldBase, Field2>::value;
116  }
117 
118  template<class Group>
119  constexpr bool is_state_field_group()
120  {
121  return std::is_base_of<StateFieldGroupBase, Group>::value;
122  };
123 
124  template<class Group1, class Group2>
125  constexpr bool are_state_field_groups()
126  {
127  return std::is_base_of<StateFieldGroupBase, Group1>::value &&
128  std::is_base_of<StateFieldGroupBase, Group2>::value;
129  };
130 }
131 
132 #endif // INCLUDE_NRT_PROBABILISTIC_TYPES_DETAILS_STATEDEFINITIONHELPERS_H
133