19 #ifndef SERIALIZETION_INTERNAL_H
20 #define SERIALIZETION_INTERNAL_H
27 #include <arpa/inet.h>
28 #include <boost/type_traits/is_fundamental.hpp>
32 namespace FotoSHOCKcore {
35 namespace Serialization_internal {
44 template <
typename U, U>
struct type_check;
45 template <
typename C>
static yes& test(type_check<xmlNodePtr(T::*)()
const, &C::serialize>*);
46 template <
typename C>
static no& test(...);
48 static const bool value =
sizeof(test<T>(0)) ==
sizeof(yes);
55 static xmlNodePtr serialize(C ) {
57 assert(
"Type doesn't provide the required serialize() function");
62 static C deserialize(
const xmlNodePtr ) {
64 assert(
"Type doesn't provide the required deserialize() function");
73 static xmlNodePtr serialize(T value) {
74 return value.serialize();
80 static T deserialize(
const xmlNodePtr value) {
81 return T::deserialize(value);
99 std::string tmp = os.str();
100 return xmlNewText(BAD_CAST tmp.c_str());
108 template <
typename T>
120 template <
typename T>
128 template <
typename T>
131 std::stringstream is(reinterpret_cast<const char*>(value->content));
137 template <
typename T>
143 template <
typename T>
144 T deserializeGeneral(
const xmlNodePtr value) {
145 return deserializeGeneral_impl<T>(value, boost::is_fundamental<T>());
150 inline uint64_t htonll(uint64_t value) {
154 if (*reinterpret_cast<const char*>(&test) == 1) {
156 uint64_t mask = 0; mask = ~mask;
157 const uint32_t high_part = htonl(static_cast<uint32_t>(value >> 32));
158 const uint32_t low_part = htonl(static_cast<uint32_t>(value & mask));
159 return (static_cast<uint64_t>(low_part) << 32) | high_part;
166 inline uint64_t ntohll(uint64_t value) {
170 if (*reinterpret_cast<const char*>(&test) == 1) {
171 return ( (static_cast<uint64_t>(ntohl(value))) << 32 | ntohl(value>>32) );