#include <cstddef>
#include <ios>
#include <iostream>
#include <type_traits>
#include <vector>
Go to the source code of this file.
|
| bool | hexdecode (const char *from, std::size_t length, void *to) |
| void | get (std::istream &input, bool &res) |
| template<typename T> |
| std::enable_if< std::is_integral< T >::value, void >::type | get (std::istream &input, T &res) |
| void | getvar (std::istream &input, std::size_t length, void *res) |
| template<typename T> |
| std::enable_if< std::is_standard_layout< T >::value &&!std::is_scalar< T >::value, void >::type | get (std::istream &input, T &res) |
| void | get (std::istream &input, std::vector< char > &res) |
| template<typename T, typename... TT> |
| std::enable_if<(sizeof...(TT)>0), void >::type | get (std::istream &input, T &res, TT &... resres) |
◆ get() [1/5]
| void get |
( |
std::istream & | input, |
|
|
bool & | res ) |
|
inline |
Definition at line 62 of file io.h.
62 {
63 std::string sres;
64 input >> sres;
65 if (sres == "false") {
67 } else if (sres == "true") {
69 } else {
70 input.setstate(std::ios_base::failbit);
71 }
72}
◆ get() [2/5]
| void get |
( |
std::istream & | input, |
|
|
std::vector< char > & | res ) |
|
inline |
Definition at line 94 of file io.h.
94 {
95 std::string sres;
96 input >> sres;
97 if (sres == "x") {
99 } else if (sres.length() % 2 != 0) {
100 input.setstate(std::ios_base::failbit);
101 } else {
102 std::size_t length = sres.length() / 2;
105 input.setstate(std::ios_base::failbit);
106 }
107 }
108}
bool hexdecode(const char *from, std::size_t length, void *to)
◆ get() [3/5]
| std::enable_if< std::is_standard_layout< T >::value &&!std::is_scalar< T >::value, void >::type get |
( |
std::istream & | input, |
|
|
T & | res ) |
Definition at line 90 of file io.h.
90 {
92}
void getvar(std::istream &input, std::size_t length, void *res)
◆ get() [4/5]
| std::enable_if< std::is_integral< T >::value, void >::type get |
( |
std::istream & | input, |
|
|
T & | res ) |
Definition at line 76 of file io.h.
◆ get() [5/5]
template<typename
T, typename... TT>
| std::enable_if<(sizeof...(TT)>0), void >::type get |
( |
std::istream & | input, |
|
|
T & | res, |
|
|
TT &... | resres ) |
Definition at line 114 of file io.h.
114 {
116 get(input, resres...);
117}
void get(std::istream &input, bool &res)
◆ getvar()
| void getvar |
( |
std::istream & | input, |
|
|
std::size_t | length, |
|
|
void * | res ) |
|
inline |
Definition at line 80 of file io.h.
80 {
81 std::string sres;
82 input >> sres;
83 if (sres.length() != 2 * length || !
hexdecode(sres.data(), length,
res)) {
84 input.setstate(std::ios_base::failbit);
85 }
86}
◆ hexdecode()
| bool hexdecode |
( |
const char * | from, |
|
|
std::size_t | length, |
|
|
void * | to ) |
|
inline |
Definition at line 38 of file io.h.
38 {
39 std::size_t i;
40 for (i = 0; i < length; i++) {
41 int v = 0;
42 if (from[2 * i] >= '0' && from[2 * i] <= '9') {
43 v = from[2 * i] - '0';
44 } else if (from[2 * i] >= 'a' && from[2 * i] <= 'f') {
45 v = from[2 * i] - 'a' + 10;
46 } else {
47 return false;
48 }
49 v <<= 4;
50 if (from[2 * i + 1] >= '0' && from[2 * i + 1] <= '9') {
51 v |= from[2 * i + 1] - '0';
52 } else if (from[2 * i + 1] >= 'a' && from[2 * i + 1] <= 'f') {
53 v |= from[2 * i + 1] - 'a' + 10;
54 } else {
55 return false;
56 }
57 *(reinterpret_cast<unsigned char *>(to) + i) = v;
58 }
59 return true;
60}