Electroneum
Loading...
Searching...
No Matches
io.h File Reference
#include <cstddef>
#include <ios>
#include <iostream>
#include <type_traits>
#include <vector>
Include dependency graph for io.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

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)

Function Documentation

◆ 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") {
66 res = false;
67 } else if (sres == "true") {
68 res = true;
69 } else {
70 input.setstate(std::ios_base::failbit);
71 }
72}
const char * res

◆ 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") {
98 res.clear();
99 } else if (sres.length() % 2 != 0) {
100 input.setstate(std::ios_base::failbit);
101 } else {
102 std::size_t length = sres.length() / 2;
103 res.resize(length);
104 if (!hexdecode(sres.data(), length, res.data())) {
105 input.setstate(std::ios_base::failbit);
106 }
107 }
108}
bool hexdecode(const char *from, std::size_t length, void *to)
Definition io.h:38
Here is the call graph for this function:

◆ get() [3/5]

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 )

Definition at line 90 of file io.h.

90 {
91 getvar(input, sizeof(T), &res);
92}
void getvar(std::istream &input, std::size_t length, void *res)
Definition io.h:80
#define T(x)
Here is the call graph for this function:

◆ get() [4/5]

template<typename T>
std::enable_if< std::is_integral< T >::value, void >::type get ( std::istream & input,
T & res )

Definition at line 76 of file io.h.

76 {
77 input >> res;
78}

◆ 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 {
115 get(input, res);
116 get(input, resres...);
117}
void get(std::istream &input, bool &res)
Definition io.h:62
Here is the call graph for this function:

◆ 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}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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}
Here is the caller graph for this function: