HLAbuffer.cc

Go to the documentation of this file.
00001 // ----------------------------------------------------------------------------
00002 // HLAbuffer.cc - IEEE 1516.2 compliant datatypes
00003 // Copyright (C) 2008  Petr Gotthard <petr.gotthard@centrum.cz>
00004 //
00005 // This library is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License version 2.1, as published by the Free Software Foundation.
00008 //
00009 // This library is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // Lesser General Public License for more details.
00013 //
00014 // $Id: HLAbuffer.cc,v 1.2 2008/11/19 10:25:03 gotthardp Exp $
00015 // ----------------------------------------------------------------------------
00016 
00017 #include "HLAbuffer.hh"
00018 
00019 #include <iomanip>
00020 
00021 // #define HLATYPES_IEEE1516_DISPLAYPRINTABLE
00022 
00023 namespace libhla {
00024 
00025 __HLAbuffer::BufferList __HLAbuffer::gBuffers;
00026 
00027 const bool
00028 __HLAbuffer::__is_big_endian()
00029 {
00030 #ifdef HOST_IS_BIG_ENDIAN 
00031     return true;
00032 #else 
00033     return false;
00034 #endif 
00035 }
00036 
00037 const bool
00038 __HLAbuffer::__is_little_endian()
00039 {
00040 #ifdef HOST_IS_BIG_ENDIAN 
00041     return false;
00042 #else 
00043     return true;
00044 #endif 
00045 }
00046 
00048 std::ostream& __print_buffer(std::ostream& stream, const void *buffer, size_t length)
00049 {
00050     static const size_t cBytesPerLine = 16;
00051     size_t offset = 0;
00052 
00053     while (length != 0) {
00054         stream << std::hex << std::setfill('0') << std::setw(4) << (unsigned)offset << ": ";
00055 
00056         size_t i = std::min(cBytesPerLine, length);
00057         const unsigned char* p = (const unsigned char*)buffer;
00058 
00059         for (size_t j = i; j > 0; j--)
00060             stream << " " << std::hex << std::setfill('0') << std::setw(2) << (unsigned)*p++;
00061 
00062 #ifdef HLATYPES_IEEE1516_DISPLAYPRINTABLE
00063         for(size_t j = cBytesPerLine - i; j > 0; j--)
00064             stream << "   ";
00065 
00066         stream << "   ";
00067 
00068         p = (const unsigned char*)buffer;
00069         for (size_t j = i; j > 0; j--) {
00070             char ch = *p++;
00071             stream << (isprint(ch) ? ch : ' ');
00072         }
00073 #endif
00074         stream << std::endl;
00075         buffer = (const unsigned char*)buffer + i;
00076         length -= i;
00077         offset += i;
00078     }
00079 
00080     return stream;
00081 }
00082 
00083 } // namespace libhla
00084 
00085 // $Id: HLAbuffer.cc,v 1.2 2008/11/19 10:25:03 gotthardp Exp $
00086 

Generated on Thu Apr 30 15:53:49 2009 for CERTIDeveloperDocumentation by doxygen 1.5.5