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 }
00099
00100 ~Allocator() throw ()
00101 {
00102 }
00103
00104 pointer address(reference r) const
00105 {
00106 return &r;
00107 }
00108 const_pointer address(const_reference r) const
00109 {
00110 return &r;
00111 }
00112 size_type max_size() const throw ()
00113 {
00114 return ~size_type(0);
00115 }
00116 pointer allocate(size_type n, Allocator<void>::const_pointer hint = 0)
00117 {
00118 return reinterpret_cast<pointer> (malloc(n * sizeof(T)));
00119 }
00120 void deallocate(pointer p, size_type n)
00121 {
00122 free(p);
00123 }
00124
00125 void construct(pointer p, const_reference val)
00126 {
00127 new (p) T(val);
00128 }
00129 void destroy(pointer p)
00130 {
00131 p->~T();
00132 }
00133 };
00134
00135 template<class T1, class T2>
00136 inline bool operator==(const Allocator<T1>& a1, const Allocator<T2>& a2) throw ()
00137 {
00138 return true;
00139 }
00140
00141 template<class T1, class T2>
00142 inline bool operator!=(const Allocator<T1>& a1, const Allocator<T2>& a2) throw ()
00143 {
00144 return false;
00145 }
00146
00147 }
00148
00149 #endif // TEST_ROSCP_SERIALIZATION_HELPERS_H