Revision: 44377 http://brlcad.svn.sourceforge.net/brlcad/?rev=44377&view=rev Author: davidloman Date: 2011-04-14 12:10:43 +0000 (Thu, 14 Apr 2011)
Log Message: ----------- Add toHexString() to ByteBuffer. Aids in troubleshooting. Modified Paths: -------------- geomcore/trunk/include/ByteBuffer.h geomcore/trunk/src/utility/ByteBuffer.cxx Modified: geomcore/trunk/include/ByteBuffer.h =================================================================== --- geomcore/trunk/include/ByteBuffer.h 2011-04-14 11:21:45 UTC (rev 44376) +++ geomcore/trunk/include/ByteBuffer.h 2011-04-14 12:10:43 UTC (rev 44377) @@ -223,6 +223,17 @@ toString(); /** + * <p>Returns a string with the hexadecimal contents of this buffer. + * If printToPosition is set to <i>true</i>, bytes index ZERO to the + * buffer's current position only are printed. If set to <i>false</i>, + * all bytes in the buffer are printed.</p> + * + * @return A HEX string + */ + std::string + toHexString(bool printToPosition = true); + + /** * Relative <i>get</i> method for reading a 16 bit value. * * <p> Reads the next two bytes at this buffer's current position, Modified: geomcore/trunk/src/utility/ByteBuffer.cxx =================================================================== --- geomcore/trunk/src/utility/ByteBuffer.cxx 2011-04-14 11:21:45 UTC (rev 44376) +++ geomcore/trunk/src/utility/ByteBuffer.cxx 2011-04-14 12:10:43 UTC (rev 44377) @@ -178,6 +178,31 @@ return out; } +std::string +ByteBuffer::toHexString(bool printToPosition) +{ + std::stringstream ss; + ss << prefix; + + uint32_t len = 0; + if (printToPosition){ + len = this->position(); + ss << " (Position: " << len << " bytes) "; + } else { + len = this->capacity(); + ss << " (Capacity: " << len << " bytes) "; + } + + char* p = this->array(); + for (int i = 0; i<len;i++) + { + ss << std::hex << *p ; + p++; + } + + return ss.str(); +} + uint16_t ByteBuffer::get16bit() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Benefiting from Server Virtualization: Beyond Initial Workload Consolidation -- Increasing the use of server virtualization is a top priority.Virtualization can reduce costs, simplify management, and improve application availability and disaster protection. Learn more about boosting the value of server virtualization. http://p.sf.net/sfu/vmware-sfdev2dev _______________________________________________ BRL-CAD Source Commits mailing list brlcad-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/brlcad-commits