37inline bool hexdecode(
const char *from, std::size_t length,
void *to) {
39 for (i = 0; i < length; i++) {
41 if (from[2 * i] >=
'0' && from[2 * i] <=
'9') {
42 v = from[2 * i] -
'0';
43 }
else if (from[2 * i] >=
'a' && from[2 * i] <=
'f') {
44 v = from[2 * i] -
'a' + 10;
49 if (from[2 * i + 1] >=
'0' && from[2 * i + 1] <=
'9') {
50 v |= from[2 * i + 1] -
'0';
51 }
else if (from[2 * i + 1] >=
'a' && from[2 * i + 1] <=
'f') {
52 v |= from[2 * i + 1] -
'a' + 10;
56 *(
reinterpret_cast<unsigned char *
>(to) + i) = v;
61inline void get(std::istream &input,
bool &
res) {
64 if (sres ==
"false") {
66 }
else if (sres ==
"true") {
69 input.setstate(std::ios_base::failbit);
74typename std::enable_if<std::is_integral<T>::value,
void>::type
79inline void getvar(std::istream &input, std::size_t length,
void *
res) {
82 if (sres.length() != 2 * length || !
hexdecode(sres.data(), length,
res)) {
83 input.setstate(std::ios_base::failbit);
88typename std::enable_if<std::is_standard_layout<T>::value && !std::is_scalar<T>::value,
void>::type
93inline void get(std::istream &input, std::vector<char> &
res) {
98 }
else if (sres.length() % 2 != 0) {
99 input.setstate(std::ios_base::failbit);
101 std::size_t length = sres.length() / 2;
104 input.setstate(std::ios_base::failbit);
109#if !defined(_MSC_VER) || _MSC_VER >= 1800
111template<
typename T,
typename... TT>
112typename std::enable_if<(
sizeof...(TT) > 0),
void>::type
113get(std::istream &input,
T &
res, TT &... resres) {
115 get(input, resres...);
119#include <boost/preprocessor/cat.hpp>
120#include <boost/preprocessor/repetition/enum_binary_params.hpp>
121#include <boost/preprocessor/repetition/enum_params.hpp>
122#include <boost/preprocessor/repetition/repeat.hpp>
123#include <boost/preprocessor/repetition/repeat_from_to.hpp>
125#define NESTED_GET(z, n, data) get(input, BOOST_PP_CAT(res, n));
126#define GET(z, n, data) \
127template<BOOST_PP_ENUM_PARAMS(n, typename T)> \
128void get(std::istream &input, BOOST_PP_ENUM_BINARY_PARAMS(n, T, &res)) { \
129 BOOST_PP_REPEAT(n, NESTED_GET, ~) \
131BOOST_PP_REPEAT_FROM_TO(2, 5, GET, ~)
const char * res
Definition hmac_keccak.cpp:42
void getvar(std::istream &input, std::size_t length, void *res)
Definition io.h:79
bool hexdecode(const char *from, std::size_t length, void *to)
Definition io.h:37
void get(std::istream &input, bool &res)
Definition io.h:61