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