libfoedus-core
FOEDUS Core Library
foedus::assorted::HexString Struct Reference

Equivalent to std::hex in case the stream doesn't support it. More...

Detailed Description

Equivalent to std::hex in case the stream doesn't support it.

Use it as follows.

std::cout << Hex("aabc") << ...
// will output "0x61616263".

Definition at line 143 of file assorted_func.hpp.

#include <assorted_func.hpp>

Collaboration diagram for foedus::assorted::HexString:

Public Member Functions

 HexString (const std::string &str, uint32_t max_bytes=64U)
 

Public Attributes

std::string str_
 
uint32_t max_bytes_
 

Friends

std::ostream & operator<< (std::ostream &o, const HexString &v)
 

Constructor & Destructor Documentation

foedus::assorted::HexString::HexString ( const std::string &  str,
uint32_t  max_bytes = 64U 
)
inline

Definition at line 144 of file assorted_func.hpp.

145  : str_(str), max_bytes_(max_bytes) {}

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  o,
const HexString v 
)
friend

Definition at line 123 of file assorted_func.cpp.

123  {
124  // Same above
125  o << "0x";
126  for (uint32_t i = 0; i < v.str_.size() && i < v.max_bytes_; ++i) {
127  if (i > 0 && i % 8U == 0) {
128  o << " "; // put space for every 8 bytes for readability
129  }
130  o << kUpperHexChars[(v.str_[i] >> 4) & 0xFU] << kUpperHexChars[v.str_[i] & 0xFU];
131  }
132  if (v.max_bytes_ != -1U && v.str_.size() > v.max_bytes_) {
133  o << " ...(" << (v.str_.size() - v.max_bytes_) << " more bytes)";
134  }
135  return o;
136 }
const char * kUpperHexChars

Member Data Documentation

uint32_t foedus::assorted::HexString::max_bytes_

Definition at line 148 of file assorted_func.hpp.

Referenced by foedus::assorted::operator<<().

std::string foedus::assorted::HexString::str_

Definition at line 147 of file assorted_func.hpp.

Referenced by foedus::assorted::operator<<().


The documentation for this struct was generated from the following file: