ByteOrderConversion.cpp
Go to the documentation of this file.
00001 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
00002 
00003 // -- BEGIN LICENSE BLOCK ----------------------------------------------
00004 // This file is part of FZIs ic_workspace.
00005 //
00006 // This program is free software licensed under the LGPL
00007 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
00008 // You can find a copy of this license in LICENSE folder in the top
00009 // directory of the source code.
00010 //
00011 // © Copyright 2014 FZI Forschungszentrum Informatik, Karlsruhe, Germany
00012 //
00013 // -- END LICENSE BLOCK ------------------------------------------------
00014 
00015 //----------------------------------------------------------------------
00023 //----------------------------------------------------------------------
00024 
00025 # include <icl_comm/ByteOrderConversion.h>
00026 
00027 
00028 
00029 namespace icl_comm {
00030 
00031 std::ostream& operator << (std::ostream& o, const ArrayBuilder& ab)
00032 {
00033   for (size_t i = 0; i < ab.array.size(); i++)
00034   {
00035     o << "0x" << std::setw(2) << std::setfill('0') << std::hex << static_cast<int>(ab.array[i]) << " ";
00036   }
00037   // Reset Output stream to decimal output .. otherwise it may confuse people
00038   std::cout << std::dec ;
00039   return o;
00040 }
00041 
00042 template <>
00043 size_t toLittleEndian<float>(const float& data, std::vector<uint8_t>& array, size_t& write_pos)
00044 {
00046   return toLittleEndian(*(reinterpret_cast<const uint32_t*>(&data)),array,write_pos);
00047 }
00048 
00049 template <>
00050 size_t toLittleEndian<double>(const double& data, std::vector<uint8_t>& array, size_t& write_pos)
00051 {
00053   return toLittleEndian(*(reinterpret_cast<const uint64_t*>(&data)),array,write_pos);
00054 
00055 }
00056 
00057 template <>
00058 size_t fromLittleEndian<float>(float& data, std::vector<uint8_t>& array, size_t& read_pos)
00059 {
00061   return fromLittleEndian(*(reinterpret_cast<uint32_t*>(&data)),array,read_pos);
00062 }
00063 
00064 template <>
00065 size_t fromLittleEndian<double>(double& data, std::vector<uint8_t>& array, size_t& read_pos)
00066 {
00068   return fromLittleEndian(*(reinterpret_cast<uint64_t*>(&data)),array,read_pos);
00069 
00070 }
00071 
00072 void ArrayBuilder::reset(size_t array_size)
00073 {
00074   array.clear();
00075   write_pos = 0;
00076   read_pos = 0;
00077   array.resize(array_size,0);
00078 }
00079 
00080 
00081 }


schunk_svh_driver
Author(s): Georg Heppner
autogenerated on Fri Aug 28 2015 12:59:18