byte_order.h
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Point Cloud Library (PCL) - www.pointclouds.org
00005  *  Copyright (c) 2007-2012, Ares Lagae
00006  *  Copyright (c) 2012, Willow Garage, Inc.
00007  *  All rights reserved.
00008  *
00009  *  Redistribution and use in source and binary forms, with or without
00010  *  modification, are permitted provided that the following conditions
00011  *  are met:
00012  *
00013  *   * Redistributions of source code must retain the above copyright
00014  *     notice, this list of conditions and the following disclaimer.
00015  *   * Redistributions in binary form must reproduce the above
00016  *     copyright notice, this list of conditions and the following
00017  *     disclaimer in the documentation and/or other materials provided
00018  *     with the distribution.
00019  *   * Neither the name of the copyright holder(s) nor the names of its
00020  *     contributors may be used to endorse or promote products derived
00021  *     from this software without specific prior written permission.
00022  *
00023  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00024  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00025  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00026  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00027  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00028  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00029  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00030  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00032  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00033  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00034  *  POSSIBILITY OF SUCH DAMAGE.
00035  *  
00036  * $Id$
00037  *
00038  */
00039 
00040 #ifndef PCL_IO_PLY_BYTE_ORDER_H
00041 #define PCL_IO_PLY_BYTE_ORDER_H
00042 
00043 #include <boost/detail/endian.hpp>
00044 
00045 namespace pcl
00046 {
00047   namespace io
00048   {
00049     namespace ply
00050     {
00057       enum byte_order
00058       {
00059         little_endian_byte_order,
00060         big_endian_byte_order,
00061 #if defined(BOOST_BIG_ENDIAN)
00062         host_byte_order = big_endian_byte_order,
00063 #elif defined(BOOST_LITTLE_ENDIAN)
00064         host_byte_order = little_endian_byte_order,
00065 #else
00066 #error "unable to determine system endianness"
00067 #endif
00068         network_byte_order = big_endian_byte_order
00069       };
00070       
00071       template <std::size_t N>
00072       void swap_byte_order (char* bytes);
00073 
00074       template <>
00075       inline void swap_byte_order<1> (char*) {}
00076 
00077       template <>
00078       inline void swap_byte_order<2> (char* bytes)
00079       {
00080         std::swap (bytes[0], bytes[1]);
00081       }
00082 
00083       template <>
00084         inline void swap_byte_order<4> (char* bytes)
00085       {
00086         std::swap (bytes[0], bytes[3]);
00087         std::swap (bytes[1], bytes[2]);
00088       }
00089       
00090       template <>
00091         inline void swap_byte_order<8> (char* bytes)
00092       {
00093         std::swap (bytes[0], bytes[7]);
00094         std::swap (bytes[1], bytes[6]);
00095         std::swap (bytes[2], bytes[5]);
00096         std::swap (bytes[3], bytes[4]);
00097       }
00098       
00099       template <typename T>
00100       void swap_byte_order (T& value)
00101       {
00102         swap_byte_order<sizeof (T)> (reinterpret_cast<char*> (&value));
00103       }
00104 
00105     } // namespace ply
00106   } // namespace io
00107 } // namespace pcl
00108 
00109 #endif // PLY_BYTE_ORDER_H


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:22:36