1- /* *
1+ /*
22 * Copyright (c) 2009 Carnegie Mellon University.
33 * All rights reserved.
44 *
2929#define ARCHIVE_BASIC_TYPES_HPP
3030
3131#include < string>
32- #include < graphlab/serialization/integer.hpp>
3332#include < graphlab/serialization/serializable_pod.hpp>
3433#include < graphlab/logger/assertions.hpp>
3534
36- /* **************************************************************************
37- * Basic Serializers *
38- ***************************************************************************/
39- // generate the operator<< call for a whole bunch of integer types
40-
41-
42- #define INT_SERIALIZE (tname ) \
43- template <typename OutArcType> \
44- struct serialize_impl <OutArcType, tname, false >{ \
45- static void exec (OutArcType& oarc, const tname& t) { \
46- oarc.write (reinterpret_cast <const char *>(&t), sizeof (tname)); \
47- } \
48- }; \
49- template <typename InArcType> \
50- struct deserialize_impl <InArcType, tname, false >{ \
51- static void exec (InArcType& iarc, tname& t) { \
52- decompress_int<InArcType, tname>(iarc, t); \
53- } \
54- };
55-
56-
57-
5835
5936namespace graphlab {
6037 class oarchive ;
@@ -64,21 +41,6 @@ namespace graphlab {
6441
6542namespace graphlab {
6643 namespace archive_detail {
67- /*
68- * Generate serializers and deserializers for all integer types
69- */
70- INT_SERIALIZE (bool );
71- INT_SERIALIZE (char );
72- INT_SERIALIZE (unsigned char );
73- INT_SERIALIZE (short );
74- INT_SERIALIZE (unsigned short );
75- INT_SERIALIZE (int );
76- INT_SERIALIZE (long );
77- INT_SERIALIZE (long long );
78- INT_SERIALIZE (unsigned long );
79- INT_SERIALIZE (unsigned int );
80- INT_SERIALIZE (unsigned long long );
81-
8244
8345 /* * Serialization of null terminated const char* strings.
8446 * This is necessary to serialize constant strings like
@@ -92,7 +54,7 @@ namespace graphlab {
9254 // save the length
9355 // ++ for the \0
9456 size_t length = strlen (s); length++;
95- serialize_impl<OutArcType, size_t , false >:: exec ( oarc, length) ;
57+ oarc << length;
9658 oarc.write (reinterpret_cast <const char *>(s), length);
9759 DASSERT_FALSE (oarc.fail ());
9860 }
@@ -104,7 +66,7 @@ namespace graphlab {
10466 struct serialize_impl <OutArcType, char [len], false > {
10567 static void exec (OutArcType& oarc, const char s[len] ) {
10668 size_t length = len;
107- serialize_impl<OutArcType, size_t , false >:: exec ( oarc, length) ;
69+ oarc << length;
10870 oarc.write (reinterpret_cast <const char *>(s), length);
10971 DASSERT_FALSE (oarc.fail ());
11072 }
@@ -118,7 +80,7 @@ namespace graphlab {
11880 // save the length
11981 // ++ for the \0
12082 size_t length = strlen (s); length++;
121- serialize_impl<OutArcType, size_t , false >:: exec ( oarc, length) ;
83+ oarc << length;
12284 oarc.write (reinterpret_cast <const char *>(s), length);
12385 DASSERT_FALSE (oarc.fail ());
12486 }
@@ -130,7 +92,7 @@ namespace graphlab {
13092 static void exec (InArcType& iarc, char *& s) {
13193 // Save the length and check if lengths match
13294 size_t length;
133- deserialize_impl<InArcType, size_t , false >:: exec (iarc, length) ;
95+ iarc >> length;
13496 s = new char [length];
13597 // operator>> the rest
13698 iarc.read (reinterpret_cast <char *>(s), length);
@@ -143,7 +105,7 @@ namespace graphlab {
143105 struct deserialize_impl <InArcType, char [len], false > {
144106 static void exec (InArcType& iarc, char s[len]) {
145107 size_t length;
146- deserialize_impl<InArcType, size_t , false >:: exec (iarc, length) ;
108+ iarc >> length;
147109 ASSERT_LE (length, len);
148110 iarc.read (reinterpret_cast <char *>(s), length);
149111 DASSERT_FALSE (iarc.fail ());
@@ -157,7 +119,7 @@ namespace graphlab {
157119 struct serialize_impl <OutArcType, std::string, false > {
158120 static void exec (OutArcType& oarc, const std::string& s) {
159121 size_t length = s.length ();
160- serialize_impl<OutArcType, size_t , false >:: exec ( oarc, length) ;
122+ oarc << length;
161123 oarc.write (reinterpret_cast <const char *>(s.c_str ()),
162124 (std::streamsize)length);
163125 DASSERT_FALSE (oarc.fail ());
@@ -171,7 +133,7 @@ namespace graphlab {
171133 static void exec (InArcType& iarc, std::string& s) {
172134 // read the length
173135 size_t length;
174- deserialize_impl<InArcType, size_t , false >:: exec (iarc, length) ;
136+ iarc >> length;
175137 // resize the string and read the characters
176138 s.resize (length);
177139 iarc.read (const_cast <char *>(s.c_str ()), (std::streamsize)length);
@@ -183,10 +145,7 @@ namespace graphlab {
183145 template <typename OutArcType, typename T, typename U>
184146 struct serialize_impl <OutArcType, std::pair<T, U>, false > {
185147 static void exec (OutArcType& oarc, const std::pair<T, U>& s) {
186- serialize_impl<OutArcType,
187- T, gl_is_pod<T>::value >::exec (oarc, s.first );
188- serialize_impl<OutArcType,
189- U, gl_is_pod<U>::value >::exec (oarc, s.second );
148+ oarc << s.first << s.second ;
190149 }
191150 };
192151
@@ -195,10 +154,7 @@ namespace graphlab {
195154 template <typename InArcType, typename T, typename U>
196155 struct deserialize_impl <InArcType, std::pair<T, U>, false > {
197156 static void exec (InArcType& iarc, std::pair<T, U>& s) {
198- deserialize_impl<InArcType,
199- T, gl_is_pod<T>::value >::exec (iarc, s.first );
200- deserialize_impl<InArcType,
201- U, gl_is_pod<U>::value >::exec (iarc, s.second );
157+ iarc >> s.first >> s.second ;
202158 }
203159 };
204160
0 commit comments