Commit f351fad5 authored by Davis King's avatar Davis King

Added serialization support for std::set.

parent 8a843211
...@@ -54,6 +54,7 @@ ...@@ -54,6 +54,7 @@
- std::wstring - std::wstring
- std::vector - std::vector
- std::map - std::map
- std::set
- std::pair - std::pair
- std::complex - std::complex
- dlib::uint64 - dlib::uint64
...@@ -69,6 +70,7 @@ ...@@ -69,6 +70,7 @@
- std::wstring - std::wstring
- std::vector - std::vector
- std::map - std::map
- std::set
- std::pair - std::pair
- std::complex - std::complex
- dlib::uint64 - dlib::uint64
...@@ -123,6 +125,7 @@ ...@@ -123,6 +125,7 @@
#include <vector> #include <vector>
#include <complex> #include <complex>
#include <map> #include <map>
#include <set>
#include <limits> #include <limits>
#include "uintn.h" #include "uintn.h"
#include "interfaces/enumerable.h" #include "interfaces/enumerable.h"
...@@ -565,6 +568,18 @@ namespace dlib ...@@ -565,6 +568,18 @@ namespace dlib
std::istream& in std::istream& in
); );
template <typename domain, typename compare, typename alloc>
void serialize (
const std::set<domain, compare, alloc>& item,
std::ostream& out
);
template <typename domain, typename compare, typename alloc>
void deserialize (
std::set<domain, compare, alloc>& item,
std::istream& in
);
template <typename T, typename alloc> template <typename T, typename alloc>
void serialize ( void serialize (
const std::vector<T,alloc>& item, const std::vector<T,alloc>& item,
...@@ -744,6 +759,53 @@ namespace dlib ...@@ -744,6 +759,53 @@ namespace dlib
{ throw serialization_error(e.info + "\n while deserializing object of type std::map"); } { throw serialization_error(e.info + "\n while deserializing object of type std::map"); }
} }
// ----------------------------------------------------------------------------------------
template <typename domain, typename compare, typename alloc>
void serialize (
const std::set<domain, compare, alloc>& item,
std::ostream& out
)
{
try
{
const unsigned long size = static_cast<unsigned long>(item.size());
serialize(size,out);
typename std::set<domain,compare,alloc>::const_iterator i;
for (i = item.begin(); i != item.end(); ++i)
{
serialize(*i,out);
}
}
catch (serialization_error& e)
{ throw serialization_error(e.info + "\n while serializing object of type std::set"); }
}
template <typename domain, typename compare, typename alloc>
void deserialize (
std::set<domain, compare, alloc>& item,
std::istream& in
)
{
try
{
item.clear();
unsigned long size;
deserialize(size,in);
domain d;
for (unsigned long i = 0; i < size; ++i)
{
deserialize(d,in);
item.insert(d);
}
}
catch (serialization_error& e)
{ throw serialization_error(e.info + "\n while deserializing object of type std::set"); }
}
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
template <typename T, typename alloc> template <typename T, typename alloc>
......
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