Commit 16d4d5d8 authored by Davis King's avatar Davis King

Added serialization support for std::deque.

parent a3dad7ac
......@@ -62,6 +62,7 @@
- std::string
- std::wstring
- std::vector
- std::deque
- std::map
- std::set
- std::pair
......@@ -79,6 +80,7 @@
- std::string
- std::wstring
- std::vector
- std::deque
- std::map
- std::set
- std::pair
......@@ -143,6 +145,7 @@
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <complex>
#include <map>
#include <set>
......@@ -652,6 +655,18 @@ namespace dlib
std::istream& in
);
template <typename T, typename alloc>
void serialize (
const std::deque<T,alloc>& item,
std::ostream& out
);
template <typename T, typename alloc>
void deserialize (
std::deque<T,alloc>& item,
std::istream& in
);
inline void serialize (
const std::string& item,
std::ostream& out
......@@ -1035,6 +1050,44 @@ namespace dlib
{ throw serialization_error(e.info + "\n while deserializing object of type std::vector"); }
}
// ----------------------------------------------------------------------------------------
template <typename T, typename alloc>
void serialize (
const std::deque<T,alloc>& item,
std::ostream& out
)
{
try
{
const unsigned long size = static_cast<unsigned long>(item.size());
serialize(size,out);
for (unsigned long i = 0; i < item.size(); ++i)
serialize(item[i],out);
}
catch (serialization_error& e)
{ throw serialization_error(e.info + "\n while serializing object of type std::deque"); }
}
template <typename T, typename alloc>
void deserialize (
std::deque<T, alloc>& item,
std::istream& in
)
{
try
{
unsigned long size;
deserialize(size,in);
item.resize(size);
for (unsigned long i = 0; i < size; ++i)
deserialize(item[i],in);
}
catch (serialization_error& e)
{ throw serialization_error(e.info + "\n while deserializing object of type std::deque"); }
}
// ----------------------------------------------------------------------------------------
inline void serialize (
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment