Add printing capabilities for Digest
This commit is contained in:
1 parent
d94542d36d
commit
b080dbf676
2 files changed
+37
No files matched your search
@@ -26,7 +26,16 @@
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/exception/errinfo_at_line.hpp>
|
||||
|
||||
// for printing, may be disabled in optimized build
|
||||
#include <boost/archive/iterators/base64_from_binary.hpp>
|
||||
#include <boost/archive/iterators/base64_from_binary.hpp>
|
||||
#include <boost/archive/iterators/transform_width.hpp>
|
||||
|
||||
using namespace boost;
|
||||
using namespace std;
|
||||
|
||||
using namespace boost::archive::iterators;
|
||||
typedef base64_from_binary<transform_width<string::const_iterator, 6, 8> > base64_t;
|
||||
|
||||
namespace Sync {
|
||||
|
||||
@@ -128,5 +137,27 @@ Digest::operator << (const Digest &src)
|
||||
}
|
||||
|
||||
|
||||
std::ostream&
|
||||
Digest::print (std::ostream &os) const
|
||||
{
|
||||
BOOST_ASSERT (m_hashLength != 0);
|
||||
|
||||
ostreambuf_iterator<char> out_it (os); // ostream iterator
|
||||
// need to encode to base64
|
||||
copy (base64_t (reinterpret_cast<const char*> (m_buffer)),
|
||||
base64_t (reinterpret_cast<const char*> (m_buffer+m_hashLength)),
|
||||
out_it);
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
std::ostream &
|
||||
operator << (std::ostream &os, const Digest &digest)
|
||||
{
|
||||
digest.print (os);
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
} // Sync
|
||||
|
||||
@@ -96,6 +96,9 @@ public:
|
||||
// template<class INT>
|
||||
// inline Digest &
|
||||
// operator << (INT value);
|
||||
|
||||
std::ostream&
|
||||
print (std::ostream &os) const;
|
||||
|
||||
private:
|
||||
/**
|
||||
@@ -141,6 +144,9 @@ Digest::operator << (uint32_t value)
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::ostream &
|
||||
operator << (std::ostream &os, const Digest &digest);
|
||||
|
||||
// template<class INT>
|
||||
// Digest &
|
||||
// Digest::operator << (INT value)
|
||||
|
||||
Reference in new issue
Block a user