iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
StateVectorImpl.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 #include <nrt/Core/Debugging/Log.H>
36 // ######################################################################
37 template <class StateDef>
39  itsVector(nrt::StateVector<StateDef>::Vector::Zero())
40 { }
41 
42 // ######################################################################
43 template <class StateDef>
45  itsVector(vector)
46 { }
47 
48 // ######################################################################
49 template <class StateDef>
50 template<class Field>
51  typename std::enable_if
52  <
53  nrt::is_state_field<Field>(),
54  double &
55  >::type
57 {
58  static_assert(StateDef::template contains_field<Field>(),
59  "Trying to access an element with a State Field "
60  "that is not part of the State Definition");
61  size_t const fieldIdx = boost::mpl::find<typename StateDef::fields, Field>::type::pos::value;
62  return itsVector(fieldIdx, 0);
63 }
64 
65 // ######################################################################
66 template <class StateDef>
67 template<class Field>
68  typename std::enable_if
69  <
70  nrt::is_state_field<Field>(),
71  double
72  >::type
74 {
75  static_assert(StateDef::template contains_field<Field>(),
76  "Trying to access an element with a State Field "
77  "that is not part of the State Definition");
78  size_t const fieldIdx = boost::mpl::find<typename StateDef::fields, Field>::type::pos::value;
79  return itsVector(fieldIdx, 0);
80 }
81 
82 // ######################################################################
83 template <class StateDef>
84 template<class FieldGroup>
85  typename std::enable_if
86  <
87  nrt::is_state_field_group<FieldGroup>(),
88  Eigen::Block<typename nrt::StateVector<StateDef>::Vector, FieldGroup::num_fields, 1>
89  >::type
91 {
92  static_assert(StateDef::template contains_field_group<FieldGroup>(),
93  "Trying to access a State Field Group "
94  "that is not part of the State Definition");
95  typedef typename boost::mpl::at_c<typename FieldGroup::fields, 0>::type first_type;
96  size_t const fieldIdx = boost::mpl::find<typename StateDef::fields, first_type>::type::pos::value;
97  return itsVector.template block<FieldGroup::num_fields, 1>(fieldIdx, 0);
98 }
99 
100 // ######################################################################
101 template <class StateDef>
102 template<class FieldGroup>
103  typename std::enable_if
104  <
105  nrt::is_state_field_group<FieldGroup>(),
106  Eigen::Block<typename nrt::StateVector<StateDef>::Vector const, FieldGroup::num_fields, 1>
107  >::type
109 {
110  static_assert(StateDef::template contains_field_group<FieldGroup>(),
111  "Trying to access a State Field Group "
112  "that is not part of the State Definition");
113  typedef typename boost::mpl::at_c<typename FieldGroup::fields, 0>::type first_type;
114  size_t const fieldIdx = boost::mpl::find<typename StateDef::fields, first_type>::type::pos::value;
115  return itsVector.template block<FieldGroup::num_fields, 1>(fieldIdx, 0);
116 }
117 
118 // ######################################################################
119 template <class StateDef>
120 template<typename Void>
121  typename std::enable_if
122  <
123  std::is_void<Void>::value,
124  typename nrt::StateVector<StateDef>::Vector &
125  >::type
127 {
128  return itsVector;
129 }
130 
131 // ######################################################################
132 template <class StateDef>
133 template<typename Void>
134  typename std::enable_if
135  <
136  std::is_void<Void>::value,
137  typename nrt::StateVector<StateDef>::Vector
138  >::type
140 {
141  return itsVector;
142 }