23 std::memcpy(
this, &other,
sizeof(
IRObject));
27 std::memcpy(
this, &other,
sizeof(
IRObject));
28 std::memset(&other, 0,
sizeof(
IRObject));
46 return static_cast<T
>(
i);
51 return static_cast<T
>(
f);
56 return GetScalar<typename std::underlying_type<T>::type>();
60 typename std::enable_if<std::is_same<T, std::string>::value, T>
::type GetScalar() {
61 if (
type == Type::String)
62 return std::string(
s);
63 else if (
type == Type::ShortString)
64 return std::string(
ss);
69 typename std::enable_if<std::is_integral<T>::value,
void>
::type SetScalar(T val) {
70 i =
static_cast<int64_t
>(val);
75 typename std::enable_if<std::is_floating_point<T>::value,
void>
::type SetScalar(T val) {
76 f =
static_cast<double>(val);
82 SetScalar<typename std::underlying_type<T>::type>(val);
86 typename std::enable_if<std::is_same<T, std::string>::value,
void>
::type SetScalar(T val) {
87 size_t size = val.size();
90 strcpy(
s, val.c_str());
93 strcpy(
ss, val.c_str());
95 type = Type::ShortString;
114 template <
typename T>
116 typename std::enable_if<std::is_integral<T>::value || std::is_floating_point<T>::value ||
117 std::is_same<T, std::string>::value || std::is_enum<T>::value,
125 template <
typename T>
126 static typename std::enable_if<
133 for (
const auto& elem : val) {
140 template <
class TupType,
unsigned... I>
146 template <
typename... Args>
148 unsigned size =
sizeof...(Args);
157 template <
typename T1,
typename T2>
167 template <
typename T>
168 static typename std::enable_if<std::is_integral<T>::value || std::is_enum<T>::value, T>
::type
171 throw std::runtime_error(
"Invalid type conversion.");
176 template <
typename T>
177 static typename std::enable_if<std::is_floating_point<T>::value, T>
::type ToCorpus(
180 throw std::runtime_error(
"Invalid type conversion.");
185 template <
typename T>
186 static typename std::enable_if<std::is_same<T, std::string>::value, T>
::type ToCorpus(
189 throw std::runtime_error(
"Invalid type conversion.");
195 template <
typename TupType,
unsigned... I>
197 return std::make_tuple(
198 ToCorpus<
typename std::tuple_element<I, TupType>::type>(*(children + I))...);
201 template <
typename T>
202 static typename std::enable_if<
206 throw std::runtime_error(
"Invalid type conversion.");
212 for (
int i = 0;
i < c.size;
i++) {
213 val.insert(val.end(), ToCorpus<typename T::value_type>(c.children[
i]));
219 template <
typename T>
220 static typename std::enable_if<detail::is_specialization<T, std::tuple>::value, T>
::type
223 throw std::runtime_error(
"Invalid type conversion.");
225 return parse_tuple<T>(obj.
o + 1,
detail::gen_seq<std::tuple_size<T>::value>{});
228 template <
typename T>
229 static typename std::enable_if<detail::is_specialization<T, std::pair>::value, T>
::type
232 throw std::runtime_error(
"Invalid type conversion.");
#define ZEROERR_SUPPRESS_COMMON_WARNINGS_POP
Definition: config.h:265
#define ZEROERR_SUPPRESS_COMMON_WARNINGS_PUSH
Definition: config.h:218
Definition: benchmark.cpp:17
Definition: serialization.h:101
int64_t size
Definition: serialization.h:102
IRObject * children
Definition: serialization.h:103
Definition: serialization.h:17
static std::enable_if< std::is_integral< T >::value||std::is_enum< T >::value, T >::type ToCorpus(IRObject obj)
Definition: serialization.h:169
static IRObject FromBinary(std::vector< uint8_t > bin)
Definition: serialization.cpp:151
static void handle_tuple(const TupType &_tup, IRObject *children, detail::seq< I... >)
Definition: serialization.h:141
static std::enable_if< std::is_integral< T >::value||std::is_floating_point< T >::value||std::is_same< T, std::string >::value||std::is_enum< T >::value, IRObject >::type FromCorpus(T val)
Definition: serialization.h:119
IRObject()
Definition: serialization.h:18
static std::enable_if< detail::is_container< T >::value &&!std::is_same< T, std::string >::value, T >::type ToCorpus(IRObject obj)
Definition: serialization.h:204
void SetChildren(IRObject *children)
Definition: serialization.h:107
static IRObject FromCorpus(const std::pair< T1, T2 > &val)
Definition: serialization.h:158
std::enable_if< std::is_enum< T >::value, void >::type SetScalar(T val)
Definition: serialization.h:81
std::enable_if< std::is_enum< T >::value, T >::type GetScalar()
Definition: serialization.h:55
std::enable_if< std::is_same< T, std::string >::value, void >::type SetScalar(T val)
Definition: serialization.h:86
static std::enable_if< std::is_floating_point< T >::value, T >::type ToCorpus(IRObject obj)
Definition: serialization.h:177
Childrens GetChildren()
Definition: serialization.h:105
static TupType parse_tuple(IRObject *children, detail::seq< I... >)
Definition: serialization.h:196
void SetScalar(const IRObject &obj)
Definition: serialization.h:99
static std::string ToString(IRObject obj)
Definition: serialization.cpp:133
static std::vector< uint8_t > ToBinary(IRObject obj)
Definition: serialization.cpp:146
IRObject & operator=(const IRObject &other)
Definition: serialization.h:22
static std::enable_if< detail::is_specialization< T, std::pair >::value, T >::type ToCorpus(IRObject obj)
Definition: serialization.h:230
IRObject * o
Definition: serialization.h:39
static IRObject * alloc(size_t size)
Definition: serialization.cpp:7
std::enable_if< std::is_same< T, std::string >::value, T >::type GetScalar()
Definition: serialization.h:60
static IRObject FromString(std::string str)
Definition: serialization.cpp:139
IRObject(IRObject &&other)
Definition: serialization.h:21
char others[7]
Definition: serialization.h:41
std::enable_if< std::is_floating_point< T >::value, void >::type SetScalar(T val)
Definition: serialization.h:75
std::enable_if< std::is_integral< T >::value, void >::type SetScalar(T val)
Definition: serialization.h:69
static char * alloc_str(size_t size)
Definition: serialization.cpp:13
static std::enable_if< std::is_same< T, std::string >::value, T >::type ToCorpus(IRObject obj)
Definition: serialization.h:186
~IRObject()
Definition: serialization.h:19
char * s
Definition: serialization.h:37
double f
Definition: serialization.h:36
IRObject(const IRObject &other)
Definition: serialization.h:20
static std::enable_if< detail::is_specialization< T, std::tuple >::value, T >::type ToCorpus(IRObject obj)
Definition: serialization.h:221
char ss[8]
Definition: serialization.h:38
int64_t i
Definition: serialization.h:35
IRObject & operator=(IRObject &&other)
Definition: serialization.h:26
static IRObject FromCorpus(const std::tuple< Args... > &val)
Definition: serialization.h:147
std::enable_if< std::is_floating_point< T >::value, T >::type GetScalar()
Definition: serialization.h:50
std::enable_if< std::is_integral< T >::value, T >::type GetScalar()
Definition: serialization.h:45
static std::enable_if< detail::is_container< T >::value &&!std::is_same< T, std::string >::value, IRObject >::type FromCorpus(const T &val)
Definition: serialization.h:128
Type
Definition: serialization.h:32
@ Undefined
Definition: serialization.h:32
@ ShortString
Definition: serialization.h:32
@ Int
Definition: serialization.h:32
@ String
Definition: serialization.h:32
@ Float
Definition: serialization.h:32
@ Object
Definition: serialization.h:32
unsigned type
Definition: serialization.h:42
Definition: typetraits.h:58
Definition: typetraits.h:91
Definition: typetraits.h:55