6 #ifndef TURI_SERIALIZE_HPP 7 #include <core/storage/serialization/serialize.hpp> 12 #ifndef TURI_IARCHIVE_HPP 13 #define TURI_IARCHIVE_HPP 16 #include <core/logging/assertions.hpp> 17 #include <core/storage/serialization/is_pod.hpp> 18 #include <core/storage/serialization/has_load.hpp> 19 #include <core/storage/serialization/dir_archive.hpp> 62 std::istream* in = NULL;
64 const char* buf = NULL;
78 inline iarchive(
const char* buf,
size_t len)
79 : buf(buf), off(0), len(len) { }
103 inline void read(
char* c,
size_t l) {
105 memcpy(c, buf + off, l);
117 template <
typename T>
120 memcpy(&c, buf + off,
sizeof(T));
123 in->read(reinterpret_cast<char*>(&c),
sizeof(T));
129 return in == NULL ? off > len : in->fail();
132 std::string get_prefix() {
133 ASSERT_NE(dir, NULL);
162 inline void read(
char* c,
size_t len) {
170 template <
typename T>
182 std::string get_prefix() {
183 return iarc->get_prefix();
193 : iarc(new
iarchive(instream)), mine(true) {}
200 : iarc(&iarc), mine(false) {}
206 namespace archive_detail {
209 template <
typename InArcType,
typename T>
210 struct deserialize_hard_or_soft_fail {
211 inline static void exec(InArcType& iarc, T& t) {
217 template <
typename T>
218 struct deserialize_hard_or_soft_fail<iarchive_soft_fail, T> {
219 inline static void exec(iarchive_soft_fail& iarc, T& t) {
220 load_or_fail(*(iarc.iarc), t);
231 template <
typename InArcType,
typename T,
bool IsPOD,
typename Enable =
void>
232 struct deserialize_impl {
233 inline static void exec(InArcType& iarc, T& t) {
234 deserialize_hard_or_soft_fail<InArcType, T>::exec(iarc, t);
239 template <
typename InArcType,
typename T>
240 struct deserialize_impl<InArcType, T, true>{
241 inline static void exec(InArcType& iarc, T &t) {
253 template <
typename T>
255 archive_detail::deserialize_impl<
iarchive,
266 template <
typename T>
280 const size_t length) {
281 iarc.
read(reinterpret_cast<char*>(str), (std::streamsize)length);
282 assert(!iarc.
fail());
293 const size_t length) {
294 iarc.
read(reinterpret_cast<char*>(str), (std::streamsize)length);
295 assert(!iarc.
fail());
314 #define BEGIN_OUT_OF_PLACE_LOAD(arc, tname, tval) \ 315 namespace turi{ namespace archive_detail { \ 316 template <typename InArcType> \ 317 struct deserialize_impl<InArcType, tname, false>{ \ 318 static void exec(InArcType& arc, tname & tval) { 320 #define END_OUT_OF_PLACE_LOAD() } }; } } iarchive_soft_fail(iarchive &iarc)
The serialization input archive object which, provided with a reference to an istream, will read from the istream, providing deserialization capabilities.
general_ifstream * get_input_stream()
bool fail()
Returns true if the underlying stream is in a failure state.
iarchive_soft_fail(std::istream &instream)
void read(char *c, size_t len)
char read_char()
Directly reads a single character from the input stream.
iarchive(std::istream &instream)
std::string get_next_read_prefix()
bool fail()
Returns true if the underlying stream is in a failure state.
void read(char *c, size_t l)
char read_char()
Directly reads a single character from the input stream.
Tests if T is a POD type.
When this archive is used to deserialize an object, and the object does not support serialization...