24 #ifndef PPL_Checked_Number_templates_hh
25 #define PPL_Checked_Number_templates_hh 1
27 #include "assertions.hh"
36 if (std::numeric_limits<T>::is_exact) {
43 const std::ios::fmtflags old_flags = s.setf(std::ios::hex,
45 const unsigned char* p =
reinterpret_cast<const unsigned char*
>(&t);
46 for (
unsigned i = 0; i <
sizeof(T); ++i) {
47 s << std::setw(2) << std::setfill('0') << static_cast<unsigned>(p[i]);
51 s <<
" (" << t <<
")";
58 if (std::numeric_limits<T>::is_exact) {
67 if (!(s >> str) || str.size() != 2*
sizeof(T)) {
70 unsigned char* p =
reinterpret_cast<unsigned char*
>(&t);
72 for (
unsigned i = 0; i <
sizeof(T); ++i) {
73 unsigned byte_value = 0;
74 for (
unsigned j = 0; j < 2; ++j) {
76 unsigned half_byte_value;
78 switch (str[2*i + j]) {
111 half_byte_value = 10;
115 half_byte_value = 11;
119 half_byte_value = 12;
123 half_byte_value = 13;
127 half_byte_value = 14;
131 half_byte_value = 15;
136 byte_value += half_byte_value;
138 PPL_ASSERT(byte_value <= 255);
139 p[i] =
static_cast<unsigned char>(byte_value);
145 const std::string::size_type sz = str.size();
146 return sz > 2 && str[0] ==
'(' && str[sz-1] ==
')';
152 #endif // !defined(PPL_Checked_Number_templates_hh)
Enable_If< Is_Native_Or_Checked< T >::value, void >::type ascii_dump(std::ostream &s, const T &t)
Enable_If< Is_Native_Or_Checked< T >::value, bool >::type ascii_load(std::istream &s, T &t)
The entire library is confined to this namespace.