iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
StateDefinition.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_STATEDEFINITION_H
37 #define INCLUDE_NRT_PROBABILISTIC_TYPES_STATEDEFINITION_H
38 
39 #include <boost/preprocessor/seq/for_each.hpp>
40 #include <boost/preprocessor/seq/for_each_i.hpp>
41 #include <boost/preprocessor/seq/enum.hpp>
42 #include <boost/preprocessor/punctuation/comma_if.hpp>
43 #include <boost/mpl/begin_end.hpp>
44 #include <boost/mpl/vector.hpp>
45 #include <boost/mpl/insert_range.hpp>
46 #include <boost/mpl/at.hpp>
47 #include <boost/mpl/size.hpp>
48 #include <boost/mpl/find.hpp>
49 #include <boost/mpl/contains.hpp>
51 
52 /*! Create a State Field Group
53  State Field Groups are used to specify the dimensions of a StateDefinition.
54 
55  The syntax is as follows:
56  @code
57  NRT_STATE_FIELD_GROUP(GroupName, (field1)(field2)(field3)(etc));
58  @endcode
59 
60  This creates a new class called GroupName, which has the following child-classes:
61  @code
62  GroupName::field1
63  GroupName::field2
64  GroupName::field3
65  GroupName::etc
66  @endcode
67 
68  \ingroup probabilistic */
69 #define NRT_STATE_FIELD_GROUP(StateFieldsName, Fields) \
70  NRT_CREATE_STATE_FIELD_GROUP(StateFieldsName, Fields)
71 
72 namespace nrt
73 {
74  //! A State Definition is a collection of State Field Groups used in a probability distribution
75  /*! \tparam FieldGroups A variadic list of NRT_STATE_FIELD_GROUPs that will be included in the State Definition
76 
77  @code
78  // Create a State Fields group called Velocity2D that is composed of two elements: vx, and vy
79  NRT_STATE_FIELD_GROUP(Position2D,(x)(y));
80 
81  // Create a State Fields group called Position2D that is composed of two elements: x, and y
82  NRT_STATE_FIELD_GROUP(Velocity2D,(x)(y));
83 
84  // Create a new State Definition called "VehicleState" that can be used to keep track of
85  // 2D positions and velocities
86  typedef StateDefinition<Position2D, Velocity2D> VehicleState;
87  @endcode
88 
89  \ingroup probabilistic */
90  template<class ...FieldGroups>
91  class StateDefinition : public StateDefinitionBase
92  {
93  public:
94 
95  //! A boost::mpl::vector containing a concatenation of all fields
96  typedef typename nrt::ConcatenateFields<FieldGroups...>::fields fields;
97 
98  //! A boost::mpl::vector containing a concatenation of all groups
99  typedef typename nrt::ConcatenateFieldGroups<FieldGroups...>::groups groups;
100 
101  //! The total number of fields in this State Definition
102  static size_t const num_fields=boost::mpl::size<fields>::value;
103 
104  //! Does this State Definition contain the given field?
105  template<class Field>
106  static constexpr bool contains_field()
107  {
108  return
109  std::is_same
110  <
111  boost::mpl::bool_<true>,
112  typename boost::mpl::contains<fields, Field>::type
113  >::value;
114  }
115 
116  //! Does this State Definition contain the given field group?
117  template<class Group>
118  static constexpr bool contains_field_group()
119  {
120  return
121  std::is_same
122  <
123  boost::mpl::bool_<true>,
124  typename boost::mpl::contains<groups, Group>::type
125  >::value;
126  }
127  };
128 }
129 
130 #endif // INCLUDE_NRT_PROBABILISTIC_TYPES_STATEDEFINITION_H