iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
StateDefImpl.H
Go to the documentation of this file.
1 /*! @file
2  @author Laurent Itti
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_STATEDEFIMPL_H
37 #define INCLUDE_NRT_PROBABILISTIC_TYPES_DETAILS_STATEDEFIMPL_H
38 
39 // ######################################################################
40 template <typename Head, typename ...Tail> inline
42  nrt::StateAccessorCore<Head>(data), nrt::StateAccessor<Tail...>(&data[Head::size])
43 { }
44 
45 // ######################################################################
46 template <typename Head, typename ...Tail> template <class Elem> inline
47 typename std::enable_if<std::is_same<Elem, Head>::value, Elem &>::type
49 { return StateAccessorCore<Head>::get(); };
50 
51 template <typename Head, typename ...Tail> template <class Elem> inline
52 typename std::enable_if<!std::is_same<Elem, Head>::value, Elem &>::type
54 { return StateAccessor<Tail...>::template get<Elem>(); };
55 
56 template <typename Head, typename ...Tail> template <class Elem> inline
57 typename std::enable_if<std::is_same<Elem, Head>::value, Elem const &>::type
59 { return StateAccessorCore<Head>::get(); };
60 
61 template <typename Head, typename ...Tail> template <class Elem> inline
62 typename std::enable_if<!std::is_same<Elem, Head>::value, Elem const &>::type
64 { return StateAccessor<Tail...>::template get<Elem>(); };
65 
66 template <typename Head, typename ...Tail> template <class Elem> inline
67 typename std::enable_if<std::is_same<Elem, Head>::value, size_t const>::type
69 { return 0; };
70 
71 template <typename Head, typename ...Tail> template <class Elem> inline
72 typename std::enable_if<!std::is_same<Elem, Head>::value, size_t const>::type
74 { return nrt::StateAccessorCore<Head>::size + nrt::StateAccessor<Tail...>::template index<Elem>(); };
75 
76 template <typename Head, typename ...Tail> inline
77 void nrt::StateAccessor<Head, Tail...>::print(std::ostream & os) const
78 { os << nrt::StateAccessorCore<Head>::get() << ' '; nrt::StateAccessor<Tail...>::print(os); };
79 
80 // ######################################################################
81 
82 template <typename ...Elements> inline
84  nrt::StateAccessor<Elements...>(&data[0]), baseaddress(&data[0])
85 {
86  //for (size_t i = 0; i < nrt::StateAccessor<Elements...>::size; ++i) data[i] = 0.0;
87  // std::cout << "data address " << &data[0]<<std::endl;
88 }
89 
90 template <typename ...Elements> inline
92  nrt::StateAccessor<Elements...>(data), baseaddress(data)
93 { }
94 
95 template <typename ...Elements> inline
96 size_t const nrt::StateDef<Elements...>::indexof(double & addr)
97 { return &addr - baseaddress; }
98 
99 template <typename ...Elements> inline
100 double & nrt::StateDef<Elements...>::operator[](size_t const idx)
101 { return *(baseaddress + idx); }
102 
103 template <typename ...Elements> inline
104 double const & nrt::StateDef<Elements...>::operator[](size_t const idx) const
105 { return *(baseaddress + idx); }
106 
107 
108 // ######################################################################
109 template <typename ...Elements>
110 std::ostream & operator<<(std::ostream & os, nrt::StateDef<Elements...> const & state)
111 { os << "{ "; state.print(os); os << '}'; return os; }
112 
113 
114 #endif // INCLUDE_NRT_PROBABILISTIC_TYPES_DETAILS_STATEDEFIMPL_H