35 #include <type_traits> 38 inline 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;
62 inline void get(std::istream &input,
bool &
res) {
65 if (sres ==
"false") {
67 }
else if (sres ==
"true") {
70 input.setstate(std::ios_base::failbit);
76 get(std::istream &input,
T &
res) {
80 inline 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);
90 get(std::istream &input,
T &
res) {
94 inline 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 112 template<
typename T,
typename... TT>
114 get(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) \ 128 template<BOOST_PP_ENUM_PARAMS(n, typename T)> \ 129 void get(std::istream &input, BOOST_PP_ENUM_BINARY_PARAMS(n, T, &res)) { \ 130 BOOST_PP_REPEAT(n, NESTED_GET, ~) \ 132 BOOST_PP_REPEAT_FROM_TO(2, 5, GET, ~)
void getvar(std::istream &input, std::size_t length, void *res)
const GenericPointer< typename T::ValueType > T2 value
typename std::enable_if< C >::type enable_if
bool hexdecode(const char *from, std::size_t length, void *to)