helpers.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2009, Willow Garage, Inc.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of Willow Garage, Inc. nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
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 // specialize for void:
00058 template<>
00059 class Allocator<void>
00060 {
00061 public:
00062   typedef void* pointer;
00063   typedef const void* const_pointer;
00064   // reference to void members are impossible.
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


test_roscpp
Author(s): Morgan Quigley, Josh Faust, Brian Gerkey, Troy Straszheim
autogenerated on Thu Jun 6 2019 21:10:42