Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef TEST_ROSCP_SERIALIZATION_HELPERS_H
00031 #define TEST_ROSCP_SERIALIZATION_HELPERS_H
00032
00033 #include <boost/shared_array.hpp>
00034 #include <ros/serialization.h>
00035
00036 namespace test_roscpp
00037 {
00038 namespace ser = ros::serialization;
00039 namespace mt = ros::message_traits;
00040 typedef boost::shared_array<uint8_t> Array;
00041
00042 template<typename T>
00043 Array serializeAndDeserialize(const T& ser_val, T& deser_val)
00044 {
00045 uint32_t len = ser::serializationLength(ser_val);
00046 boost::shared_array<uint8_t> b(new uint8_t[len]);
00047 ser::OStream ostream(b.get(), len);
00048 ser::serialize(ostream, ser_val);
00049 ser::IStream istream(b.get(), len);
00050 ser::deserialize(istream, deser_val);
00051
00052 return b;
00053 }
00054
00055 template<class T> class Allocator;
00056
00057
00058 template<>
00059 class Allocator<void>
00060 {
00061 public:
00062 typedef void* pointer;
00063 typedef const void* const_pointer;
00064
00065 typedef void value_type;
00066
00067 template<class U>
00068 struct rebind
00069 {
00070 typedef Allocator<U> other;
00071 };
00072 };
00073
00074 template<class T>
00075 class Allocator
00076 {
00077 public:
00078 typedef size_t size_type;
00079 typedef ptrdiff_t difference_type;
00080 typedef T* pointer;
00081 typedef const T* const_pointer;
00082 typedef T& reference;
00083 typedef const T& const_reference;
00084 typedef T value_type;
00085
00086 template<class U>
00087 struct rebind
00088 {
00089 typedef Allocator<U> other;
00090 };
00091
00092 Allocator() throw ()
00093 {
00094 }
00095 template<class U>
00096 Allocator(const Allocator<U>& u) throw ()
00097 {
00098 (void)u;
00099 }
00100
00101 ~Allocator() throw ()
00102 {
00103 }
00104
00105 pointer address(reference r) const
00106 {
00107 return &r;
00108 }
00109 const_pointer address(const_reference r) const
00110 {
00111 return &r;
00112 }
00113 size_type max_size() const throw ()
00114 {
00115 return ~size_type(0);
00116 }
00117 pointer allocate(size_type n, Allocator<void>::const_pointer hint = 0)
00118 {
00119 (void)hint;
00120 return reinterpret_cast<pointer> (malloc(n * sizeof(T)));
00121 }
00122 void deallocate(pointer p, size_type n)
00123 {
00124 (void)n;
00125 free(p);
00126 }
00127
00128 void construct(pointer p, const_reference val)
00129 {
00130 new (p) T(val);
00131 }
00132 void destroy(pointer p)
00133 {
00134 p->~T();
00135 }
00136 };
00137
00138 template<class T1, class T2>
00139 inline bool operator==(const Allocator<T1>&, const Allocator<T2>&) throw ()
00140 {
00141 return true;
00142 }
00143
00144 template<class T1, class T2>
00145 inline bool operator!=(const Allocator<T1>&, const Allocator<T2>&) throw ()
00146 {
00147 return false;
00148 }
00149
00150 }
00151
00152 #endif // TEST_ROSCP_SERIALIZATION_HELPERS_H