00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "HLAbuffer.hh"
00018
00019 #include <iomanip>
00020
00021
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 }
00084
00085
00086