38inline bool hexdecode(
const char *from, std::size_t length,
void *to) {
40 for (i = 0; i < length; i++) {
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;
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;
57 *(
reinterpret_cast<unsigned char *
>(to) + i) = v;
62inline void get(std::istream &input,
bool &
res) {
65 if (sres ==
"false") {
67 }
else if (sres ==
"true") {
70 input.setstate(std::ios_base::failbit);
75typename std::enable_if<std::is_integral<T>::value,
void>::type
80inline void getvar(std::istream &input, std::size_t length,
void *
res) {
83 if (sres.length() != 2 * length || !
hexdecode(sres.data(), length,
res)) {
84 input.setstate(std::ios_base::failbit);
89typename std::enable_if<std::is_standard_layout<T>::value && !std::is_scalar<T>::value,
void>::type
94inline void get(std::istream &input, std::vector<char> &
res) {
99 }
else if (sres.length() % 2 != 0) {
100 input.setstate(std::ios_base::failbit);
102 std::size_t length = sres.length() / 2;
105 input.setstate(std::ios_base::failbit);
110#if !defined(_MSC_VER) || _MSC_VER >= 1800
112template<
typename T,
typename... TT>
113typename std::enable_if<(
sizeof...(TT) > 0),
void>::type
114get(std::istream &input,
T &
res, TT &... resres) {
116 get(input, resres...);
120#include <boost/preprocessor/cat.hpp>
121#include <boost/preprocessor/repetition/enum_binary_params.hpp>
122#include <boost/preprocessor/repetition/enum_params.hpp>
123#include <boost/preprocessor/repetition/repeat.hpp>
124#include <boost/preprocessor/repetition/repeat_from_to.hpp>
126#define NESTED_GET(z, n, data) get(input, BOOST_PP_CAT(res, n));
127#define GET(z, n, data) \
128template<BOOST_PP_ENUM_PARAMS(n, typename T)> \
129void get(std::istream &input, BOOST_PP_ENUM_BINARY_PARAMS(n, T, &res)) { \
130 BOOST_PP_REPEAT(n, NESTED_GET, ~) \
132BOOST_PP_REPEAT_FROM_TO(2, 5, GET, ~)
void getvar(std::istream &input, std::size_t length, void *res)
bool hexdecode(const char *from, std::size_t length, void *to)
void get(std::istream &input, bool &res)