KukaNanopb.hpp
Go to the documentation of this file.
1 /// @file KukaNanopb.hpp
2 ///
3 /// Enable boost::range to be used for nanopb repeated int and repeated double types
4 ///
5 /// @see http://www.boost.org/doc/libs/1_57_0/libs/range/doc/html/range/reference/extending/method_2.html
6 
7 #ifndef _NANOPB_HPP_
8 #define _NANOPB_HPP_
9 
10 #include <iterator> // for std::iterator_traits, std::distance()
11 #include <boost/range.hpp>
12 #include <boost/type_traits.hpp>
13 #include "pb_frimessages_callbacks.h"
14 
15 #ifdef BOOST_LIB_STD_CXX
16 /// @todo remove this when the libc++ bug linked below has been resolved
17 /// @see https://groups.google.com/forum/#!topic/boost-devel-archive/Pj0qsPYyFH0
18 /// @see https://svn.boost.org/trac/boost/ticket/9431
19 namespace std {
20  template<> struct iterator_traits<tRepeatedDoubleArguments> {
21  typedef std::ptrdiff_t difference_type;
22  typedef double value_type;
23  typedef double* pointer;
24  typedef double& reference;
25  typedef std::random_access_iterator_tag iterator_category;
26  };
27 }
28 
29 /// @todo remove this when the libc++ bug linked below has been resolved
30 /// @see https://groups.google.com/forum/#!topic/boost-devel-archive/Pj0qsPYyFH0
31 /// @see https://svn.boost.org/trac/boost/ticket/9431
32 namespace std {
33  template<> struct iterator_traits<tRepeatedIntArguments> {
34  typedef std::ptrdiff_t difference_type;
35  typedef int64_t value_type;
36  typedef int64_t* pointer;
37  typedef int64_t& reference;
38  typedef std::random_access_iterator_tag iterator_category;
39  };
40 }
41 #endif
42 
43 namespace boost
44 {
45  //
46  // Specialize metafunctions. We must include the range.hpp header.
47  // We must open the 'boost' namespace.
48  //
49  template<>
50  struct range_mutable_iterator< tRepeatedDoubleArguments >
51  {
52  typedef double* type;
53  };
54 
55  template<>
56  struct range_const_iterator< tRepeatedDoubleArguments >
57  {
58  //
59  // Remark: this is defined similar to 'range_iterator'
60  // because the 'Pair' type does not distinguish
61  // between an iterator and a const_iterator.
62  //
63  typedef const double* type;
64  };
65 
66  //
67  // Specialize metafunctions. We must include the range.hpp header.
68  // We must open the 'boost' namespace.
69  //
70 
71  template<>
72  struct range_mutable_iterator< tRepeatedIntArguments >
73  {
74  typedef int64_t* type;
75  };
76 
77  template<>
78  struct range_const_iterator< tRepeatedIntArguments >
79  {
80  //
81  // Remark: this is defined similar to 'range_iterator'
82  // because the 'Pair' type does not distinguish
83  // between an iterator and a const_iterator.
84  //
85  typedef const int64_t* type;
86  };
87 
88 } // namespace 'boost'
89 
90 
91  template<typename T> typename boost::range_mutable_iterator<T>::type range_begin(T&);
92  template<typename T> typename boost::range_const_iterator<T>::type range_begin(const T&);
93  template<typename T> typename boost::range_mutable_iterator<T>::type range_end(T&);
94  template<typename T> typename boost::range_const_iterator<T>::type range_end(const T&);
95  //
96  // The required functions. These should be defined in
97  // the same namespace as 'Pair', in this case
98  // in namespace 'Foo'.
99  //
100  template<>
101  inline double* range_begin( tRepeatedDoubleArguments& x )
102  {
103  return x.value;
104  }
105 
106  template<>
107  inline const double* range_begin( const tRepeatedDoubleArguments& x )
108  {
109  return x.value;
110  }
111 
112  template<>
113  inline double* range_end( tRepeatedDoubleArguments& x )
114  {
115  return x.value+x.size;
116  }
117 
118  template<>
119  inline const double* range_end( const tRepeatedDoubleArguments& x )
120  {
121  return x.value+x.size;
122  }
123 
124 
125 
126  template<>
127  inline int64_t* range_begin( repeatedIntArguments& x )
128  {
129  return x.value;
130  }
131 
132  template<>
133  inline const int64_t* range_begin( const tRepeatedIntArguments& x )
134  {
135  return x.value;
136  }
137 
138  template<>
139  inline int64_t* range_end( repeatedIntArguments& x )
140  {
141  return x.value+x.size;
142  }
143 
144  template<>
145  inline const int64_t* range_end( const repeatedIntArguments& x )
146  {
147  return x.value+x.size;
148  }
149 
150 
151 #endif
STL namespace.
boost::range_mutable_iterator< T >::type range_begin(T &)
boost::range_mutable_iterator< T >::type range_end(T &)