YPC  0.2.0
csv_read_assign_helper.h
1 #pragma once
2 #include <boost/preprocessor/arithmetic/inc.hpp>
3 #include <boost/preprocessor/punctuation/comma_if.hpp>
4 #include <boost/preprocessor/repetition/enum.hpp>
5 #include <boost/preprocessor/repetition/repeat.hpp>
6 #include <ff/net/middleware/ntpackage.h>
7 #include <ff/util/ntobject.h>
8 
9 #define DECL_TYPENAME(z, n, text) typename text##n
10 #define DECL_TYPE(z, n, text) text##n
11 #define DECL_VAR_DECL(z, n, text) \
12  typename ::ff::util::internal::nt_traits<text##n>::type t##n;
13 #define DECL_VAR(z, n, text) text##n
14 
15 #define AH(z, num, _) \
16  template <BOOST_PP_ENUM(BOOST_PP_INC(num), DECL_TYPENAME, T)> \
17  struct assign_helper< \
18  ::ff::util::ntobject<BOOST_PP_ENUM(BOOST_PP_INC(num), DECL_TYPE, T)>> { \
19  template <typename RT> \
20  static bool read_row( \
21  RT *reader, \
22  ::ff::util::ntobject<BOOST_PP_ENUM(BOOST_PP_INC(num), DECL_TYPE, T)> \
23  &v) { \
24  BOOST_PP_REPEAT(BOOST_PP_INC(num), DECL_VAR_DECL, T); \
25  bool rv = \
26  reader->read_row(BOOST_PP_ENUM(BOOST_PP_INC(num), DECL_VAR, t)); \
27  if (!rv) { \
28  return false; \
29  } \
30  v.template set<BOOST_PP_ENUM(BOOST_PP_INC(num), DECL_TYPE, T)>( \
31  BOOST_PP_ENUM(BOOST_PP_INC(num), DECL_VAR, t)); \
32  return rv; \
33  } \
34  }; \
35  \
36  template <uint32_t PackageID, \
37  BOOST_PP_ENUM(BOOST_PP_INC(num), DECL_TYPENAME, T)> \
38  struct assign_helper<::ff::net::ntpackage< \
39  PackageID, BOOST_PP_ENUM(BOOST_PP_INC(num), DECL_TYPE, T)>> { \
40  template <typename RT> \
41  static bool read_row( \
42  RT *reader, \
43  ::ff::net::ntpackage<PackageID, BOOST_PP_ENUM(BOOST_PP_INC(num), \
44  DECL_TYPE, T)> &v) { \
45  BOOST_PP_REPEAT(BOOST_PP_INC(num), DECL_VAR_DECL, T); \
46  bool rv = \
47  reader->read_row(BOOST_PP_ENUM(BOOST_PP_INC(num), DECL_VAR, t)); \
48  if (!rv) { \
49  return false; \
50  } \
51  v.template set<BOOST_PP_ENUM(BOOST_PP_INC(num), DECL_TYPE, T)>( \
52  BOOST_PP_ENUM(BOOST_PP_INC(num), DECL_VAR, t)); \
53  return true; \
54  } \
55  };
56 
57 namespace ypc {
58 namespace plugins {
59 namespace internal {
60 template <typename NT> struct assign_helper {};
61 // AH(1, 1, nil)
62 BOOST_PP_REPEAT(64, AH, nil)
63 } // namespace internal
64 } // namespace plugins
65 } // namespace ypc
ypc::plugins::internal::assign_helper
Definition: csv_read_assign_helper.h:60