24 #ifndef GRAPHLAB_SERIALIZE_HPP
25 #include <graphlab/serialization/serialize.hpp>
30 #ifndef GRAPHLAB_IARCHIVE_HPP
31 #define GRAPHLAB_IARCHIVE_HPP
34 #include <graphlab/logger/assertions.hpp>
35 #include <graphlab/serialization/is_pod.hpp>
36 #include <graphlab/serialization/has_load.hpp>
100 inline void read(
char* c,
size_t l) {
102 memcpy(c, buf + off, l);
112 return in == NULL ? off > len : in->fail();
122 : in(&instream), buf(NULL), off(0), len(0) { }
124 inline iarchive(
const char* buf,
size_t len)
125 : in(NULL), buf(buf), off(0), len(len) { }
154 inline void read(
char* c,
size_t len) {
170 : iarc(new
iarchive(instream)), mine(true) {}
177 : iarc(&iarc), mine(false) {}
183 namespace archive_detail {
186 template <
typename InArcType,
typename T>
187 struct deserialize_hard_or_soft_fail {
188 inline static void exec(InArcType& iarc, T& t) {
194 template <
typename T>
195 struct deserialize_hard_or_soft_fail<iarchive_soft_fail, T> {
196 inline static void exec(iarchive_soft_fail& iarc, T& t) {
197 load_or_fail(*(iarc.iarc), t);
208 template <
typename InArcType,
typename T,
bool IsPOD>
209 struct deserialize_impl {
210 inline static void exec(InArcType& iarc, T& t) {
211 deserialize_hard_or_soft_fail<InArcType, T>::exec(iarc, t);
216 template <
typename InArcType,
typename T>
217 struct deserialize_impl<InArcType, T, true>{
218 inline static void exec(InArcType& iarc, T &t) {
219 iarc.read(reinterpret_cast<char*>(&t),
231 template <
typename T>
232 inline iarchive& operator>>(iarchive& iarc, T &t) {
233 archive_detail::deserialize_impl<iarchive,
235 gl_is_pod<T>::value >::exec(iarc, t);
244 template <
typename T>
245 inline iarchive_soft_fail& operator>>(iarchive_soft_fail& iarc, T &t) {
246 archive_detail::deserialize_impl<iarchive_soft_fail,
248 gl_is_pod<T>::value >::exec(iarc, t);
256 inline iarchive& deserialize(iarchive& iarc,
258 const size_t length) {
259 iarc.read(reinterpret_cast<char*>(str), (std::streamsize)length);
260 assert(!iarc.fail());
269 inline iarchive_soft_fail& deserialize(iarchive_soft_fail& iarc,
271 const size_t length) {
272 iarc.read(reinterpret_cast<char*>(str), (std::streamsize)length);
273 assert(!iarc.fail());
292 #define BEGIN_OUT_OF_PLACE_LOAD(arc, tname, tval) \
293 namespace graphlab{ namespace archive_detail { \
294 template <typename InArcType> \
295 struct deserialize_impl<InArcType, tname, false>{ \
296 static void exec(InArcType& arc, tname & tval) {
298 #define END_OUT_OF_PLACE_LOAD() } }; } }