helpers.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009, Willow Garage, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of Willow Garage, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #ifndef TEST_ROSCP_SERIALIZATION_HELPERS_H
31 #define TEST_ROSCP_SERIALIZATION_HELPERS_H
32 
33 #include <boost/shared_array.hpp>
34 #include <ros/serialization.h>
35 
36 namespace test_roscpp
37 {
38 namespace ser = ros::serialization;
39 namespace mt = ros::message_traits;
41 
42 template<typename T>
43 Array serializeAndDeserialize(const T& ser_val, T& deser_val)
44 {
45  uint32_t len = ser::serializationLength(ser_val);
46  boost::shared_array<uint8_t> b(new uint8_t[len]);
47  ser::OStream ostream(b.get(), len);
48  ser::serialize(ostream, ser_val);
49  ser::IStream istream(b.get(), len);
50  ser::deserialize(istream, deser_val);
51 
52  return b;
53 }
54 
55 template<class T> class Allocator;
56 
57 // specialize for void:
58 template<>
59 class Allocator<void>
60 {
61 public:
62  typedef void* pointer;
63  typedef const void* const_pointer;
64  // reference to void members are impossible.
65  typedef void value_type;
66 
67  template<class U>
68  struct rebind
69  {
71  };
72 };
73 
74 template<class T>
75 class Allocator
76 {
77 public:
78  typedef size_t size_type;
79  typedef ptrdiff_t difference_type;
80  typedef T* pointer;
81  typedef const T* const_pointer;
82  typedef T& reference;
83  typedef const T& const_reference;
84  typedef T value_type;
85 
86  template<class U>
87  struct rebind
88  {
90  };
91 
92  Allocator() throw ()
93  {
94  }
95  template<class U>
96  Allocator(const Allocator<U>& u) throw ()
97  {
98  (void)u;
99  }
100 
101  ~Allocator() throw ()
102  {
103  }
104 
105  pointer address(reference r) const
106  {
107  return &r;
108  }
109  const_pointer address(const_reference r) const
110  {
111  return &r;
112  }
113  size_type max_size() const throw ()
114  {
115  return ~size_type(0);
116  }
117  pointer allocate(size_type n, Allocator<void>::const_pointer hint = 0)
118  {
119  (void)hint;
120  return reinterpret_cast<pointer> (malloc(n * sizeof(T)));
121  }
122  void deallocate(pointer p, size_type n)
123  {
124  (void)n;
125  free(p);
126  }
127 
128  void construct(pointer p, const_reference val)
129  {
130  new (p) T(val);
131  }
132  void destroy(pointer p)
133  {
134  p->~T();
135  }
136 };
137 
138 template<class T1, class T2>
139 inline bool operator==(const Allocator<T1>&, const Allocator<T2>&) throw ()
140 {
141  return true;
142 }
143 
144 template<class T1, class T2>
145 inline bool operator!=(const Allocator<T1>&, const Allocator<T2>&) throw ()
146 {
147  return false;
148 }
149 
150 }
151 
152 #endif // TEST_ROSCP_SERIALIZATION_HELPERS_H
size_type max_size() const
Definition: helpers.h:113
bool operator!=(const Allocator< T1 > &, const Allocator< T2 > &)
Definition: helpers.h:145
Allocator(const Allocator< U > &u)
Definition: helpers.h:96
void destroy(pointer p)
Definition: helpers.h:132
ptrdiff_t difference_type
Definition: helpers.h:79
void construct(pointer p, const_reference val)
Definition: helpers.h:128
bool operator==(const Allocator< T1 > &, const Allocator< T2 > &)
Definition: helpers.h:139
void deallocate(pointer p, size_type n)
Definition: helpers.h:122
const T & const_reference
Definition: helpers.h:83
const T * const_pointer
Definition: helpers.h:81
pointer address(reference r) const
Definition: helpers.h:105
Array serializeAndDeserialize(const T &ser_val, T &deser_val)
Definition: helpers.h:43
pointer allocate(size_type n, Allocator< void >::const_pointer hint=0)
Definition: helpers.h:117
boost::shared_array< uint8_t > Array
Definition: helpers.h:40
const_pointer address(const_reference r) const
Definition: helpers.h:109
const void * const_pointer
Definition: helpers.h:63


test_roscpp
Author(s): Morgan Quigley, Josh Faust, Brian Gerkey, Troy Straszheim, Dirk Thomas
autogenerated on Mon Nov 2 2020 03:52:46