/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2011 - 2018 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
object = new T(stream);
}
+ // *& deserialization template to simplify rest of the code
+ template <typename T>
+ static inline void DeserializePtr(IStream &stream, T *&value)
+ {
+ T *tmp = new T;
+ std::unique_ptr<T> ptr(tmp);
+ Deserialize(stream, *tmp);
+ ptr.release();
+ value = tmp;
+ }
+
// char
static void Deserialize(IStream &stream, char &value)
{
}
static void Deserialize(IStream &stream, char *&value)
{
- value = new char;
- stream.Read(sizeof(*value), value);
+ DeserializePtr(stream, value);
}
// unsigned char
}
static void Deserialize(IStream &stream, unsigned char *&value)
{
- value = new unsigned char;
- stream.Read(sizeof(*value), value);
+ DeserializePtr(stream, value);
}
// unsigned int32
}
static void Deserialize(IStream &stream, uint32_t *&value)
{
- value = new uint32_t;
- stream.Read(sizeof(*value), value);
+ DeserializePtr(stream, value);
}
// int32
}
static void Deserialize(IStream &stream, int32_t *&value)
{
- value = new int32_t;
- stream.Read(sizeof(*value), value);
+ DeserializePtr(stream, value);
}
// unsigned int64
}
static void Deserialize(IStream &stream, uint64_t *&value)
{
- value = new uint64_t;
- stream.Read(sizeof(*value), value);
+ DeserializePtr(stream, value);
}
// int64
}
static void Deserialize(IStream &stream, int64_t *&value)
{
- value = new int64_t;
- stream.Read(sizeof(*value), value);
+ DeserializePtr(stream, value);
}
// bool
}
static void Deserialize(IStream &stream, bool *&value)
{
- value = new bool;
- stream.Read(sizeof(*value), value);
+ DeserializePtr(stream, value);
}
template <typename T, typename R, typename A>
template <typename T>
static void Deserialize(IStream &stream, std::list<T> *&list)
{
- list = new std::list<T>;
- Deserialize(stream, *list);
+ DeserializePtr(stream, list);
}
// RawBuffer
template <typename A>
static void Deserialize(IStream &stream, std::vector<unsigned char, A> *&vec)
{
- vec = new std::vector<unsigned char, A>;
- Deserialize(stream, *vec);
+ DeserializePtr<std::vector<unsigned char, A>>(stream, vec);
}
// std::vector
template <typename T, typename A>
static void Deserialize(IStream &stream, std::vector<T, A> *&vec)
{
- vec = new std::vector<T, A>;
- Deserialize(stream, *vec);
+ DeserializePtr(stream, vec);
}
// std::pair
template <typename A, typename B>
static void Deserialize(IStream &stream, std::pair<A, B> *&p)
{
- p = new std::pair<A, B>;
- Deserialize(stream, *p);
+ DeserializePtr(stream, p);
}
// std::map
template <typename K, typename T>
static void Deserialize(IStream &stream, std::map<K, T> *&map)
{
- map = new std::map<K, T>;
- Deserialize(stream, *map);
+ DeserializePtr(stream, map);
}
}; // struct Deserialization
Deserialization::Deserialize(stream, f);
Deserializer<Args...>::Deserialize(stream, args...);
}
+
+ static void Deserialize(IStream &stream, First *&f, Args &... args)
+ {
+ First *tmp = NULL;
+ Deserialization::Deserialize(stream, tmp);
+ std::unique_ptr<First> ptr(tmp);
+ Deserializer<Args...>::Deserialize(stream, args...);
+ ptr.release();
+ f = tmp;
+ }
+
};
// end of recursion