10 #ifndef __PION_PIONBLOB_HEADER__
11 #define __PION_PIONBLOB_HEADER__
14 #include <boost/detail/atomic_count.hpp>
15 #include <boost/functional/hash.hpp>
16 #include <pion/PionConfig.hpp>
26 template <
typename CharType,
typename AllocType>
33 BlobData(AllocType& blob_alloc,
const std::size_t len) :
36 *((CharType*)(
this) +
sizeof(
struct BlobData) + len) =
'\0';
40 inline const CharType *
get(void)
const {
41 return ((CharType*)(
this) +
sizeof(
struct BlobData));
45 inline CharType *
get(void) {
46 return ((CharType*)(
this) +
sizeof(
struct BlobData));
70 static inline BlobData *
create(AllocType& blob_alloc,
const std::size_t len) {
108 BlobParams(AllocType& blob_alloc,
const CharType *ptr,
const std::size_t len)
109 : m_alloc(blob_alloc), m_ptr(ptr), m_len(len)
113 const CharType * m_ptr;
155 PionBlob(AllocType& blob_alloc,
const CharType* ptr,
const std::size_t len) :
168 PionBlob(AllocType& blob_alloc,
const std::string& str) :
206 inline void set(AllocType& blob_alloc,
const CharType* ptr,
const std::size_t len) {
218 inline void set(AllocType& blob_alloc,
const std::string& str) {
232 inline CharType *
reserve(AllocType& blob_alloc,
const std::size_t len) {
239 inline const CharType *
get(void)
const {
244 inline std::size_t
size(
void)
const {
283 if (
size() != str.size())
302 const int val = memcmp(
get(), blob.
get(), len);
315 const int val = memcmp(
get(), blob.
get(), len);
326 const std::size_t len = (
size() < str.size() ?
size() : str.size());
328 const int val = memcmp(
get(), str.c_str(), len);
334 return (
size() < str.size());
339 const std::size_t len = (
size() < str.size() ?
size() : str.size());
341 const int val = memcmp(
get(), str.c_str(), len);
347 return (
size() > str.size());
353 template <
typename CharType,
typename AllocType>
354 static inline std::size_t hash_value(
const PionBlob<CharType,AllocType>& blob) {
355 return (blob.empty() ? 0 : boost::hash_range(blob.get(), blob.get() + blob.size()));
362 inline unsigned long getValue(
unsigned char c)
const {
363 unsigned long result;
365 case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
368 case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
371 case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
382 template <
typename CharType,
typename AllocType>
384 if (blob.
size() != 36)
385 return hash_value(blob);
387 const char *
const data = blob.
get();
389 std::size_t seed = 0;
400 boost::hash_combine(seed, n);
411 boost::hash_combine(seed, n);
422 boost::hash_combine(seed, n);
433 boost::hash_combine(seed, n);
446 template <
typename CharType,
typename AllocType>
447 bool operator()(
const PionBlob<CharType, AllocType>& _Keyval1,
const PionBlob<CharType, AllocType>& _Keyval2)
const {
448 return _Keyval1 < _Keyval2;