vector_multi_array_adapter.h
Go to the documentation of this file.
1 /*
2  * (C) 2017, Intermodalics BVBA
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * 3. Neither the name of the copyright holder nor the names of its contributors
13  * may be used to endorse or promote products derived from this software
14  * without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
19  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
22  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #ifndef STD_MSGS_VECTOR_MULTI_ARRAY_ADAPTER_H
31 #define STD_MSGS_VECTOR_MULTI_ARRAY_ADAPTER_H
32 
33 #include <std_msgs/Float32MultiArray.h>
34 #include <std_msgs/Float64MultiArray.h>
35 #include <std_msgs/Int16MultiArray.h>
36 #include <std_msgs/Int32MultiArray.h>
37 #include <std_msgs/Int64MultiArray.h>
38 #include <std_msgs/Int8MultiArray.h>
39 #include <std_msgs/UInt16MultiArray.h>
40 #include <std_msgs/UInt32MultiArray.h>
41 #include <std_msgs/UInt64MultiArray.h>
42 #include <std_msgs/UInt8MultiArray.h>
43 
44 #include <ros/assert.h>
45 #include <ros/message_traits.h>
46 #include <ros/serialization.h>
47 
48 namespace std_msgs {
49 
50 // container for a std::vector<T, ContainerAllocator> with pointer semantics
51 template <typename T, class ContainerAllocator = std::allocator<T> >
53 {
54 public:
55  typedef std::vector<T, ContainerAllocator> VectorType;
56 
58  : vector_(&owned_vector_) {}
59  VectorMultiArrayAdapter(VectorType &v)
60  : vector_(&v) {}
61  VectorMultiArrayAdapter(const VectorType &v)
62  : vector_(const_cast<VectorType*>(&v)) {}
63 
64  VectorType *operator->() { return vector_; }
65  const VectorType *operator->() const { return vector_; }
66  VectorType &operator*() { return *vector_; }
67  const VectorType &operator*() const { return *vector_; }
68 
69 private:
70  VectorType owned_vector_;
71  VectorType* vector_;
72 };
73 
74 } // namespace std_msgs
75 
76 
77 #define STD_MSGS_DEFINE_MULTIARRAY_TRAITS(value_type, msg, static_md5sum1, static_md5sum2) \
78  namespace ros \
79  { \
80  namespace message_traits \
81  { \
82  \
83  template <class ContainerAllocator> struct MD5Sum<std_msgs::VectorMultiArrayAdapter<value_type, ContainerAllocator> > \
84  { \
85  static const char* value() \
86  { \
87  ROS_STATIC_ASSERT(MD5Sum<std_msgs::msg>::static_value1 == static_md5sum1); \
88  ROS_STATIC_ASSERT(MD5Sum<std_msgs::msg>::static_value2 == static_md5sum2); \
89  return MD5Sum<std_msgs::msg>::value(); \
90  } \
91  \
92  static const char* value(const std_msgs::VectorMultiArrayAdapter<value_type, ContainerAllocator> &) \
93  { \
94  return value(); \
95  } \
96  }; \
97  \
98  template <class ContainerAllocator> struct DataType<std_msgs::VectorMultiArrayAdapter<value_type, ContainerAllocator> > \
99  { \
100  static const char* value() \
101  { \
102  return DataType<std_msgs::msg>::value(); \
103  } \
104  \
105  static const char* value(const std_msgs::VectorMultiArrayAdapter<value_type, ContainerAllocator> &) \
106  { \
107  return value(); \
108  } \
109  }; \
110  \
111  template <class ContainerAllocator> struct Definition<std_msgs::VectorMultiArrayAdapter<value_type, ContainerAllocator> > \
112  { \
113  static const char* value() \
114  { \
115  return Definition<std_msgs::msg>::value(); \
116  } \
117  \
118  static const char* value(const std_msgs::VectorMultiArrayAdapter<value_type, ContainerAllocator> &) \
119  { \
120  return value(); \
121  } \
122  }; \
123  \
124  } \
125  }
126 
127 STD_MSGS_DEFINE_MULTIARRAY_TRAITS(float, Float32MultiArray, 0x6a40e0ffa6a17a50ULL, 0x3ac3f8616991b1f6ULL)
128 STD_MSGS_DEFINE_MULTIARRAY_TRAITS(double, Float64MultiArray, 0x4b7d974086d4060eULL, 0x7db4613a7e6c3ba4ULL)
129 STD_MSGS_DEFINE_MULTIARRAY_TRAITS(int16_t, Int16MultiArray, 0xd9338d7f523fcb69ULL, 0x2fae9d0a0e9f067cULL)
130 STD_MSGS_DEFINE_MULTIARRAY_TRAITS(int32_t, Int32MultiArray, 0x1d99f79f8b325b44ULL, 0xfee908053e9c945bULL)
131 STD_MSGS_DEFINE_MULTIARRAY_TRAITS(int64_t, Int64MultiArray, 0x54865aa6c65be044ULL, 0x8113a2afc6a49270ULL)
132 STD_MSGS_DEFINE_MULTIARRAY_TRAITS(int8_t, Int8MultiArray, 0xd7c1af35a1b4781bULL, 0xbe79e03dd94b7c13ULL)
133 STD_MSGS_DEFINE_MULTIARRAY_TRAITS(uint16_t, UInt16MultiArray, 0x52f264f1c973c4b7ULL, 0x3790d384c6cb4484ULL)
134 STD_MSGS_DEFINE_MULTIARRAY_TRAITS(uint32_t, UInt32MultiArray, 0x4d6a180abc9be191ULL, 0xb96a7eda6c8a233dULL)
135 STD_MSGS_DEFINE_MULTIARRAY_TRAITS(uint64_t, UInt64MultiArray, 0x6088f127afb1d6c7ULL, 0x2927aa1247e945afULL)
136 STD_MSGS_DEFINE_MULTIARRAY_TRAITS(uint8_t, UInt8MultiArray, 0x82373f1612381bb6ULL, 0xee473b5cd6f5d89cULL)
137 
138 namespace ros {
139 namespace serialization {
140 
141 template <typename T, class ContainerAllocator>
142 struct Serializer<std_msgs::VectorMultiArrayAdapter<T, ContainerAllocator> >
143 {
145 
146  template<typename Stream>
147  inline static void write(Stream& stream, const AdaptedType& v)
148  {
149  // Note: We mimic serialization of a std_msgs/MultiArrayLayout here because
150  // we cannot use a static const instance here due to the variable field dim[0].size.
151  stream.next((uint32_t)1); // layout.dim.size()
152  stream.next(std::string()); // layout.dim[0].label
153  stream.next((uint32_t)v->size()); // layout.dim[0].size
154  stream.next((uint32_t)1); // layout.dim[0].stride
155  stream.next((uint32_t)0); // layout.data_offset
156  stream.next(*v);
157  }
158 
159  template<typename Stream>
160  inline static void read(Stream& stream, AdaptedType& v)
161  {
162  std_msgs::MultiArrayLayout_<ContainerAllocator> layout;
163  stream.next(layout); // layout is ignored on read!
164  stream.next(*v);
165  }
166 
167  inline static uint32_t serializedLength(const AdaptedType& v)
168  {
169  return 20 + serializationLength(*v);
170  }
171 };
172 
173 } // namespace serialization
174 } // namespace ros
175 
176 #endif // STD_MSGS_VECTOR_MULTI_ARRAY_ADAPTER_H
__int64 int64_t
std::vector< T, ContainerAllocator > VectorType
#define STD_MSGS_DEFINE_MULTIARRAY_TRAITS(value_type, msg, static_md5sum1, static_md5sum2)
uint32_t serializationLength(const T &t)


rtt_std_msgs
Author(s):
autogenerated on Mon May 10 2021 02:45:14