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

Added serialization support for std::deque.

parent a3dad7ac
...@@ -62,6 +62,7 @@ ...@@ -62,6 +62,7 @@
- std::string - std::string
- std::wstring - std::wstring
- std::vector - std::vector
- std::deque
- std::map - std::map
- std::set - std::set
- std::pair - std::pair
...@@ -79,6 +80,7 @@ ...@@ -79,6 +80,7 @@
- std::string - std::string
- std::wstring - std::wstring
- std::vector - std::vector
- std::deque
- std::map - std::map
- std::set - std::set
- std::pair - std::pair
...@@ -143,6 +145,7 @@ ...@@ -143,6 +145,7 @@
#include <fstream> #include <fstream>
#include <string> #include <string>
#include <vector> #include <vector>
#include <deque>
#include <complex> #include <complex>
#include <map> #include <map>
#include <set> #include <set>
...@@ -652,6 +655,18 @@ namespace dlib ...@@ -652,6 +655,18 @@ namespace dlib
std::istream& in 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 ( inline void serialize (
const std::string& item, const std::string& item,
std::ostream& out std::ostream& out
...@@ -1035,6 +1050,44 @@ namespace dlib ...@@ -1035,6 +1050,44 @@ namespace dlib
{ throw serialization_error(e.info + "\n while deserializing object of type std::vector"); } { 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 ( 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