mirror of
https://github.com/USCiLab/cereal.git
synced 2025-10-18 01:45:52 +02:00
Added unit tests for complex and bitset
Made all template functions for the various types inline
This commit is contained in:
@@ -7,7 +7,7 @@
|
|||||||
namespace cereal
|
namespace cereal
|
||||||
{
|
{
|
||||||
//! Saving for std::array primitive types to binary
|
//! Saving for std::array primitive types to binary
|
||||||
template <class T, size_t N>
|
template <class T, size_t N> inline
|
||||||
typename std::enable_if<std::is_arithmetic<T>::value, void>::type
|
typename std::enable_if<std::is_arithmetic<T>::value, void>::type
|
||||||
save( BinaryOutputArchive & ar, std::array<T, N> const & array )
|
save( BinaryOutputArchive & ar, std::array<T, N> const & array )
|
||||||
{
|
{
|
||||||
@@ -15,7 +15,7 @@ namespace cereal
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! Loading for std::array primitive types to binary
|
//! Loading for std::array primitive types to binary
|
||||||
template <class T, size_t N>
|
template <class T, size_t N> inline
|
||||||
typename std::enable_if<std::is_arithmetic<T>::value, void>::type
|
typename std::enable_if<std::is_arithmetic<T>::value, void>::type
|
||||||
load( BinaryInputArchive & ar, std::array<T, N> & array )
|
load( BinaryInputArchive & ar, std::array<T, N> & array )
|
||||||
{
|
{
|
||||||
@@ -23,7 +23,7 @@ namespace cereal
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! Saving for std::array all other types to binary
|
//! Saving for std::array all other types to binary
|
||||||
template <class T, size_t N>
|
template <class T, size_t N> inline
|
||||||
typename std::enable_if<!std::is_arithmetic<T>::value, void>::type
|
typename std::enable_if<!std::is_arithmetic<T>::value, void>::type
|
||||||
save( BinaryOutputArchive & ar, std::array<T, N> const & array )
|
save( BinaryOutputArchive & ar, std::array<T, N> const & array )
|
||||||
{
|
{
|
||||||
@@ -32,7 +32,7 @@ namespace cereal
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! Loading for std::array all other types to binary
|
//! Loading for std::array all other types to binary
|
||||||
template <class T, size_t N>
|
template <class T, size_t N> inline
|
||||||
typename std::enable_if<!std::is_arithmetic<T>::value, void>::type
|
typename std::enable_if<!std::is_arithmetic<T>::value, void>::type
|
||||||
load( BinaryInputArchive & ar, std::array<T, N> & array )
|
load( BinaryInputArchive & ar, std::array<T, N> & array )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,11 +11,17 @@ namespace cereal
|
|||||||
enum class type : uint8_t
|
enum class type : uint8_t
|
||||||
{
|
{
|
||||||
ulong,
|
ulong,
|
||||||
uulong,
|
ullong,
|
||||||
string
|
string
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
template <class Archive> inline
|
||||||
|
CEREAL_ARCHIVE_RESTRICT_SERIALIZE(BinaryInputArchive, BinaryOutputArchive)
|
||||||
|
serialize( Archive & ar, type & t )
|
||||||
|
{
|
||||||
|
ar & reinterpret_cast<uint8_t &>( t );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//! Serializing (save) for std::bitset to binary
|
//! Serializing (save) for std::bitset to binary
|
||||||
template <size_t N> inline
|
template <size_t N> inline
|
||||||
@@ -31,8 +37,8 @@ namespace cereal
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
auto const b = bits.to_uulong();
|
auto const b = bits.to_ullong();
|
||||||
ar & bitset_detail::type::uulong;
|
ar & bitset_detail::type::ullong;
|
||||||
ar & b;
|
ar & b;
|
||||||
}
|
}
|
||||||
catch( std::overflow_error const & e )
|
catch( std::overflow_error const & e )
|
||||||
@@ -59,7 +65,7 @@ namespace cereal
|
|||||||
bits = std::bitset<N>( b );
|
bits = std::bitset<N>( b );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case bitset_detail::type::uulong:
|
case bitset_detail::type::ullong:
|
||||||
{
|
{
|
||||||
unsigned long long b;
|
unsigned long long b;
|
||||||
ar & b;
|
ar & b;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
namespace cereal
|
namespace cereal
|
||||||
{
|
{
|
||||||
//! Saving for std::deque to binary
|
//! Saving for std::deque to binary
|
||||||
template <class T, class A>
|
template <class T, class A> inline
|
||||||
void save( BinaryOutputArchive & ar, std::deque<T, A> const & deque )
|
void save( BinaryOutputArchive & ar, std::deque<T, A> const & deque )
|
||||||
{
|
{
|
||||||
ar & deque.size();
|
ar & deque.size();
|
||||||
@@ -17,7 +17,7 @@ namespace cereal
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! Loading for std::deque to binary
|
//! Loading for std::deque to binary
|
||||||
template <class T, class A>
|
template <class T, class A> inline
|
||||||
void load( BinaryInputArchive & ar, std::deque<T, A> & deque )
|
void load( BinaryInputArchive & ar, std::deque<T, A> & deque )
|
||||||
{
|
{
|
||||||
size_t size;
|
size_t size;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
namespace cereal
|
namespace cereal
|
||||||
{
|
{
|
||||||
//! Saving for std::forward_list all other types to binary
|
//! Saving for std::forward_list all other types to binary
|
||||||
template <class T, class A>
|
template <class T, class A> inline
|
||||||
void save( BinaryOutputArchive & ar, std::forward_list<T, A> const & forward_list )
|
void save( BinaryOutputArchive & ar, std::forward_list<T, A> const & forward_list )
|
||||||
{
|
{
|
||||||
// save position for size of list
|
// save position for size of list
|
||||||
@@ -28,7 +28,7 @@ namespace cereal
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! Saving for std::forward_list all other types to binary (non-const version)
|
//! Saving for std::forward_list all other types to binary (non-const version)
|
||||||
template <class T, class A>
|
template <class T, class A> inline
|
||||||
void save( BinaryOutputArchive & ar, std::forward_list<T, A> & forward_list )
|
void save( BinaryOutputArchive & ar, std::forward_list<T, A> & forward_list )
|
||||||
{
|
{
|
||||||
// save position for size of list
|
// save position for size of list
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
namespace cereal
|
namespace cereal
|
||||||
{
|
{
|
||||||
//! Saving for std::list to binary
|
//! Saving for std::list to binary
|
||||||
template <class T, class A>
|
template <class T, class A> inline
|
||||||
void save( BinaryOutputArchive & ar, std::list<T, A> const & list )
|
void save( BinaryOutputArchive & ar, std::list<T, A> const & list )
|
||||||
{
|
{
|
||||||
ar & list.size();
|
ar & list.size();
|
||||||
@@ -17,7 +17,7 @@ namespace cereal
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! Loading for std::list to binary
|
//! Loading for std::list to binary
|
||||||
template <class T, class A>
|
template <class T, class A> inline
|
||||||
void load( BinaryInputArchive & ar, std::list<T, A> & list )
|
void load( BinaryInputArchive & ar, std::list<T, A> & list )
|
||||||
{
|
{
|
||||||
size_t size;
|
size_t size;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
namespace cereal
|
namespace cereal
|
||||||
{
|
{
|
||||||
//! Saving for std::map to binary
|
//! Saving for std::map to binary
|
||||||
template <class K, class T, class C, class A>
|
template <class K, class T, class C, class A> inline
|
||||||
void save( BinaryOutputArchive & ar, std::map<K, T, C, A> const & map )
|
void save( BinaryOutputArchive & ar, std::map<K, T, C, A> const & map )
|
||||||
{
|
{
|
||||||
ar & map.size();
|
ar & map.size();
|
||||||
@@ -20,7 +20,7 @@ namespace cereal
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! Loading for std::map to binary
|
//! Loading for std::map to binary
|
||||||
template <class K, class T, class C, class A>
|
template <class K, class T, class C, class A> inline
|
||||||
void load( BinaryInputArchive & ar, std::map<K, T, C, A> & map )
|
void load( BinaryInputArchive & ar, std::map<K, T, C, A> & map )
|
||||||
{
|
{
|
||||||
size_t size;
|
size_t size;
|
||||||
@@ -38,7 +38,7 @@ namespace cereal
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! Saving for std::multimap to binary
|
//! Saving for std::multimap to binary
|
||||||
template <class K, class T, class C, class A>
|
template <class K, class T, class C, class A> inline
|
||||||
void save( BinaryOutputArchive & ar, std::multimap<K, T, C, A> const & multimap )
|
void save( BinaryOutputArchive & ar, std::multimap<K, T, C, A> const & multimap )
|
||||||
{
|
{
|
||||||
ar & multimap.size();
|
ar & multimap.size();
|
||||||
@@ -51,7 +51,7 @@ namespace cereal
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! Loading for std::multimap to binary
|
//! Loading for std::multimap to binary
|
||||||
template <class K, class T, class C, class A>
|
template <class K, class T, class C, class A> inline
|
||||||
void load( BinaryInputArchive & ar, std::multimap<K, T, C, A> & multimap )
|
void load( BinaryInputArchive & ar, std::multimap<K, T, C, A> & multimap )
|
||||||
{
|
{
|
||||||
size_t size;
|
size_t size;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
namespace cereal
|
namespace cereal
|
||||||
{
|
{
|
||||||
//! Saving std::shared_ptr to binary
|
//! Saving std::shared_ptr to binary
|
||||||
template <class T>
|
template <class T> inline
|
||||||
void save( BinaryOutputArchive & ar, std::shared_ptr<T> const & ptr )
|
void save( BinaryOutputArchive & ar, std::shared_ptr<T> const & ptr )
|
||||||
{
|
{
|
||||||
uint32_t id = ar.registerSharedPointer( ptr.get() );
|
uint32_t id = ar.registerSharedPointer( ptr.get() );
|
||||||
@@ -20,7 +20,7 @@ namespace cereal
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! Loading std::shared_ptr to binary
|
//! Loading std::shared_ptr to binary
|
||||||
template <class T>
|
template <class T> inline
|
||||||
void load( BinaryInputArchive & ar, std::shared_ptr<T> & ptr )
|
void load( BinaryInputArchive & ar, std::shared_ptr<T> & ptr )
|
||||||
{
|
{
|
||||||
uint32_t id;
|
uint32_t id;
|
||||||
@@ -40,7 +40,7 @@ namespace cereal
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! Saving std::weak_ptr to binary
|
//! Saving std::weak_ptr to binary
|
||||||
template <class T>
|
template <class T> inline
|
||||||
void save( BinaryOutputArchive & ar, std::weak_ptr<T> const & ptr )
|
void save( BinaryOutputArchive & ar, std::weak_ptr<T> const & ptr )
|
||||||
{
|
{
|
||||||
auto sptr = ptr.lock();
|
auto sptr = ptr.lock();
|
||||||
@@ -48,7 +48,7 @@ namespace cereal
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! Loading std::weak_ptr from binary
|
//! Loading std::weak_ptr from binary
|
||||||
template <class T>
|
template <class T> inline
|
||||||
void load( BinaryInputArchive & ar, std::weak_ptr<T> & ptr )
|
void load( BinaryInputArchive & ar, std::weak_ptr<T> & ptr )
|
||||||
{
|
{
|
||||||
std::shared_ptr<T> sptr;
|
std::shared_ptr<T> sptr;
|
||||||
@@ -57,14 +57,14 @@ namespace cereal
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! Saving std::unique_ptr to binary
|
//! Saving std::unique_ptr to binary
|
||||||
template <class T, class D>
|
template <class T, class D> inline
|
||||||
void save( BinaryOutputArchive & ar, std::unique_ptr<T, D> const & ptr )
|
void save( BinaryOutputArchive & ar, std::unique_ptr<T, D> const & ptr )
|
||||||
{
|
{
|
||||||
ar & *ptr;
|
ar & *ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Loading std::unique_ptr from binary
|
//! Loading std::unique_ptr from binary
|
||||||
template <class T, class D>
|
template <class T, class D> inline
|
||||||
void load( BinaryInputArchive & ar, std::unique_ptr<T, D> & ptr )
|
void load( BinaryInputArchive & ar, std::unique_ptr<T, D> & ptr )
|
||||||
{
|
{
|
||||||
ptr.reset(new T);
|
ptr.reset(new T);
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace cereal
|
|||||||
namespace queue_detail
|
namespace queue_detail
|
||||||
{
|
{
|
||||||
//! Allows access to the protected container in queue
|
//! Allows access to the protected container in queue
|
||||||
template <class T, class C>
|
template <class T, class C> inline
|
||||||
C const & container( std::queue<T, C> const & queue )
|
C const & container( std::queue<T, C> const & queue )
|
||||||
{
|
{
|
||||||
struct H : public std::queue<T, C>
|
struct H : public std::queue<T, C>
|
||||||
@@ -24,7 +24,7 @@ namespace cereal
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! Allows access to the protected container in priority queue
|
//! Allows access to the protected container in priority queue
|
||||||
template <class T, class C, class Comp>
|
template <class T, class C, class Comp> inline
|
||||||
C const & container( std::priority_queue<T, C, Comp> const & priority_queue )
|
C const & container( std::priority_queue<T, C, Comp> const & priority_queue )
|
||||||
{
|
{
|
||||||
struct H : public std::priority_queue<T, C, Comp>
|
struct H : public std::priority_queue<T, C, Comp>
|
||||||
@@ -37,9 +37,9 @@ namespace cereal
|
|||||||
|
|
||||||
return H::get( priority_queue );
|
return H::get( priority_queue );
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Allows access to the protected comparator in priority queue
|
//! Allows access to the protected comparator in priority queue
|
||||||
template <class T, class C, class Comp>
|
template <class T, class C, class Comp> inline
|
||||||
Comp const & comparator( std::priority_queue<T, C, Comp> const & priority_queue )
|
Comp const & comparator( std::priority_queue<T, C, Comp> const & priority_queue )
|
||||||
{
|
{
|
||||||
struct H : public std::priority_queue<T, C, Comp>
|
struct H : public std::priority_queue<T, C, Comp>
|
||||||
@@ -55,14 +55,14 @@ namespace cereal
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! Saving for std::queue to binary
|
//! Saving for std::queue to binary
|
||||||
template <class T, class C>
|
template <class T, class C> inline
|
||||||
void save( BinaryOutputArchive & ar, std::queue<T, C> const & queue )
|
void save( BinaryOutputArchive & ar, std::queue<T, C> const & queue )
|
||||||
{
|
{
|
||||||
ar & queue_detail::container( queue );
|
ar & queue_detail::container( queue );
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Loading for std::queue to binary
|
//! Loading for std::queue to binary
|
||||||
template <class T, class C>
|
template <class T, class C> inline
|
||||||
void load( BinaryInputArchive & ar, std::queue<T, C> & queue )
|
void load( BinaryInputArchive & ar, std::queue<T, C> & queue )
|
||||||
{
|
{
|
||||||
C container;
|
C container;
|
||||||
@@ -71,7 +71,7 @@ namespace cereal
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! Saving for std::priority_queue to binary
|
//! Saving for std::priority_queue to binary
|
||||||
template <class T, class C, class Comp>
|
template <class T, class C, class Comp> inline
|
||||||
void save( BinaryOutputArchive & ar, std::priority_queue<T, C, Comp> const & priority_queue )
|
void save( BinaryOutputArchive & ar, std::priority_queue<T, C, Comp> const & priority_queue )
|
||||||
{
|
{
|
||||||
ar & queue_detail::comparator( priority_queue );
|
ar & queue_detail::comparator( priority_queue );
|
||||||
@@ -79,12 +79,12 @@ namespace cereal
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! Loading for std::priority_queue to binary
|
//! Loading for std::priority_queue to binary
|
||||||
template <class T, class C, class Comp>
|
template <class T, class C, class Comp> inline
|
||||||
void load( BinaryInputArchive & ar, std::priority_queue<T, C, Comp> & priority_queue )
|
void load( BinaryInputArchive & ar, std::priority_queue<T, C, Comp> & priority_queue )
|
||||||
{
|
{
|
||||||
Comp comparator;
|
Comp comparator;
|
||||||
ar & comparator;
|
ar & comparator;
|
||||||
|
|
||||||
C container;
|
C container;
|
||||||
ar & container;
|
ar & container;
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
namespace cereal
|
namespace cereal
|
||||||
{
|
{
|
||||||
//! Saving for std::set to binary
|
//! Saving for std::set to binary
|
||||||
template <class K, class C, class A>
|
template <class K, class C, class A> inline
|
||||||
void save( BinaryOutputArchive & ar, std::set<K, C, A> const & set )
|
void save( BinaryOutputArchive & ar, std::set<K, C, A> const & set )
|
||||||
{
|
{
|
||||||
ar & set.size();
|
ar & set.size();
|
||||||
@@ -17,7 +17,7 @@ namespace cereal
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! Loading for std::set to binary
|
//! Loading for std::set to binary
|
||||||
template <class K, class C, class A>
|
template <class K, class C, class A> inline
|
||||||
void load( BinaryInputArchive & ar, std::set<K, C, A> & set )
|
void load( BinaryInputArchive & ar, std::set<K, C, A> & set )
|
||||||
{
|
{
|
||||||
size_t size;
|
size_t size;
|
||||||
@@ -33,7 +33,7 @@ namespace cereal
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! Saving for std::multiset to binary
|
//! Saving for std::multiset to binary
|
||||||
template <class K, class C, class A>
|
template <class K, class C, class A> inline
|
||||||
void save( BinaryOutputArchive & ar, std::multiset<K, C, A> const & multiset )
|
void save( BinaryOutputArchive & ar, std::multiset<K, C, A> const & multiset )
|
||||||
{
|
{
|
||||||
ar & multiset.size();
|
ar & multiset.size();
|
||||||
@@ -43,7 +43,7 @@ namespace cereal
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! Loading for std::multiset to binary
|
//! Loading for std::multiset to binary
|
||||||
template <class K, class C, class A>
|
template <class K, class C, class A> inline
|
||||||
void load( BinaryInputArchive & ar, std::multiset<K, C, A> & multiset )
|
void load( BinaryInputArchive & ar, std::multiset<K, C, A> & multiset )
|
||||||
{
|
{
|
||||||
size_t size;
|
size_t size;
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace cereal
|
|||||||
namespace stack_detail
|
namespace stack_detail
|
||||||
{
|
{
|
||||||
//! Allows access to the protected container in stack
|
//! Allows access to the protected container in stack
|
||||||
template <class T, class C>
|
template <class T, class C> inline
|
||||||
C const & container( std::stack<T, C> const & stack )
|
C const & container( std::stack<T, C> const & stack )
|
||||||
{
|
{
|
||||||
struct H : public std::stack<T, C>
|
struct H : public std::stack<T, C>
|
||||||
@@ -25,14 +25,14 @@ namespace cereal
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! Saving for std::stack to binary
|
//! Saving for std::stack to binary
|
||||||
template <class T, class C>
|
template <class T, class C> inline
|
||||||
void save( BinaryOutputArchive & ar, std::stack<T, C> const & stack )
|
void save( BinaryOutputArchive & ar, std::stack<T, C> const & stack )
|
||||||
{
|
{
|
||||||
ar & stack_detail::container( stack );
|
ar & stack_detail::container( stack );
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Loading for std::stack to binary
|
//! Loading for std::stack to binary
|
||||||
template <class T, class C>
|
template <class T, class C> inline
|
||||||
void load( BinaryInputArchive & ar, std::stack<T, C> & stack )
|
void load( BinaryInputArchive & ar, std::stack<T, C> & stack )
|
||||||
{
|
{
|
||||||
C container;
|
C container;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
namespace cereal
|
namespace cereal
|
||||||
{
|
{
|
||||||
//! Serialization for basic_string types to binary
|
//! Serialization for basic_string types to binary
|
||||||
template<class CharT, class Traits, class Alloc>
|
template<class CharT, class Traits, class Alloc> inline
|
||||||
void save(BinaryOutputArchive & ar, std::basic_string<CharT, Traits, Alloc> const & str)
|
void save(BinaryOutputArchive & ar, std::basic_string<CharT, Traits, Alloc> const & str)
|
||||||
{
|
{
|
||||||
// Save number of chars + the data
|
// Save number of chars + the data
|
||||||
@@ -16,7 +16,7 @@ namespace cereal
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! Serialization for basic_string types from binary
|
//! Serialization for basic_string types from binary
|
||||||
template<class CharT, class Traits, class Alloc>
|
template<class CharT, class Traits, class Alloc> inline
|
||||||
void load(BinaryInputArchive & ar, std::basic_string<CharT, Traits, Alloc> & str)
|
void load(BinaryInputArchive & ar, std::basic_string<CharT, Traits, Alloc> & str)
|
||||||
{
|
{
|
||||||
size_t size;
|
size_t size;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
namespace cereal
|
namespace cereal
|
||||||
{
|
{
|
||||||
//! Saving for std::unordered_map to binary
|
//! Saving for std::unordered_map to binary
|
||||||
template <class K, class T, class H, class KE, class A>
|
template <class K, class T, class H, class KE, class A> inline
|
||||||
void save( BinaryOutputArchive & ar, std::unordered_map<K, T, H, KE, A> const & unordered_map )
|
void save( BinaryOutputArchive & ar, std::unordered_map<K, T, H, KE, A> const & unordered_map )
|
||||||
{
|
{
|
||||||
ar & unordered_map.size();
|
ar & unordered_map.size();
|
||||||
@@ -20,7 +20,7 @@ namespace cereal
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! Loading for std::unordered_map to binary
|
//! Loading for std::unordered_map to binary
|
||||||
template <class K, class T, class H, class KE, class A>
|
template <class K, class T, class H, class KE, class A> inline
|
||||||
void load( BinaryInputArchive & ar, std::unordered_map<K, T, H, KE, A> & unordered_map )
|
void load( BinaryInputArchive & ar, std::unordered_map<K, T, H, KE, A> & unordered_map )
|
||||||
{
|
{
|
||||||
size_t size;
|
size_t size;
|
||||||
@@ -40,7 +40,7 @@ namespace cereal
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! Saving for std::unordered_multimap to binary
|
//! Saving for std::unordered_multimap to binary
|
||||||
template <class K, class T, class H, class KE, class A>
|
template <class K, class T, class H, class KE, class A> inline
|
||||||
void save( BinaryOutputArchive & ar, std::unordered_multimap<K, T, H, KE, A> const & unordered_multimap )
|
void save( BinaryOutputArchive & ar, std::unordered_multimap<K, T, H, KE, A> const & unordered_multimap )
|
||||||
{
|
{
|
||||||
ar & unordered_multimap.size();
|
ar & unordered_multimap.size();
|
||||||
@@ -53,7 +53,7 @@ namespace cereal
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! Loading for std::unordered_multimap to binary
|
//! Loading for std::unordered_multimap to binary
|
||||||
template <class K, class T, class H, class KE, class A>
|
template <class K, class T, class H, class KE, class A> inline
|
||||||
void load( BinaryInputArchive & ar, std::unordered_multimap<K, T, H, KE, A> & unordered_multimap )
|
void load( BinaryInputArchive & ar, std::unordered_multimap<K, T, H, KE, A> & unordered_multimap )
|
||||||
{
|
{
|
||||||
size_t size;
|
size_t size;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
namespace cereal
|
namespace cereal
|
||||||
{
|
{
|
||||||
//! Saving for std::unordered_set to binary
|
//! Saving for std::unordered_set to binary
|
||||||
template <class K, class H, class KE, class A>
|
template <class K, class H, class KE, class A> inline
|
||||||
void save( BinaryOutputArchive & ar, std::unordered_set<K, H, KE, A> const & unordered_set )
|
void save( BinaryOutputArchive & ar, std::unordered_set<K, H, KE, A> const & unordered_set )
|
||||||
{
|
{
|
||||||
ar & unordered_set.size();
|
ar & unordered_set.size();
|
||||||
@@ -17,7 +17,7 @@ namespace cereal
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! Loading for std::unordered_set to binary
|
//! Loading for std::unordered_set to binary
|
||||||
template <class K, class H, class KE, class A>
|
template <class K, class H, class KE, class A> inline
|
||||||
void load( BinaryInputArchive & ar, std::unordered_set<K, H, KE, A> & unordered_set )
|
void load( BinaryInputArchive & ar, std::unordered_set<K, H, KE, A> & unordered_set )
|
||||||
{
|
{
|
||||||
size_t size;
|
size_t size;
|
||||||
@@ -35,7 +35,7 @@ namespace cereal
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! Saving for std::unordered_multiset to binary
|
//! Saving for std::unordered_multiset to binary
|
||||||
template <class K, class H, class KE, class A>
|
template <class K, class H, class KE, class A> inline
|
||||||
void save( BinaryOutputArchive & ar, std::unordered_multiset<K, H, KE, A> const & unordered_multiset )
|
void save( BinaryOutputArchive & ar, std::unordered_multiset<K, H, KE, A> const & unordered_multiset )
|
||||||
{
|
{
|
||||||
ar & unordered_multiset.size();
|
ar & unordered_multiset.size();
|
||||||
@@ -45,7 +45,7 @@ namespace cereal
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! Loading for std::unordered_multiset to binary
|
//! Loading for std::unordered_multiset to binary
|
||||||
template <class K, class H, class KE, class A>
|
template <class K, class H, class KE, class A> inline
|
||||||
void load( BinaryInputArchive & ar, std::unordered_multiset<K, H, KE, A> & unordered_multiset )
|
void load( BinaryInputArchive & ar, std::unordered_multiset<K, H, KE, A> & unordered_multiset )
|
||||||
{
|
{
|
||||||
size_t size;
|
size_t size;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
namespace cereal
|
namespace cereal
|
||||||
{
|
{
|
||||||
//! Serialization for std::vectors of arithmetic (but not bool) types to binary
|
//! Serialization for std::vectors of arithmetic (but not bool) types to binary
|
||||||
template <class T, class A>
|
template <class T, class A> inline
|
||||||
typename std::enable_if<std::is_arithmetic<T>::value && !std::is_same<T, bool>::value, void>::type
|
typename std::enable_if<std::is_arithmetic<T>::value && !std::is_same<T, bool>::value, void>::type
|
||||||
save( BinaryOutputArchive & ar, std::vector<T, A> const & vector )
|
save( BinaryOutputArchive & ar, std::vector<T, A> const & vector )
|
||||||
{
|
{
|
||||||
@@ -19,7 +19,7 @@ namespace cereal
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! Serialization for std::vectors of arithmetic (but not bool) types to binary
|
//! Serialization for std::vectors of arithmetic (but not bool) types to binary
|
||||||
template <class T, class A>
|
template <class T, class A> inline
|
||||||
typename std::enable_if<std::is_arithmetic<T>::value && !std::is_same<T, bool>::value, void>::type
|
typename std::enable_if<std::is_arithmetic<T>::value && !std::is_same<T, bool>::value, void>::type
|
||||||
load( BinaryInputArchive & ar, std::vector<T, A> & vector )
|
load( BinaryInputArchive & ar, std::vector<T, A> & vector )
|
||||||
{
|
{
|
||||||
@@ -34,7 +34,7 @@ namespace cereal
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! Serialization for non-arithmetic (and bool) vector types to binary
|
//! Serialization for non-arithmetic (and bool) vector types to binary
|
||||||
template <class T, class A>
|
template <class T, class A> inline
|
||||||
typename std::enable_if<!std::is_arithmetic<T>::value || std::is_same<T, bool>::value, void>::type
|
typename std::enable_if<!std::is_arithmetic<T>::value || std::is_same<T, bool>::value, void>::type
|
||||||
save( BinaryOutputArchive & ar, std::vector<T, A> const & vector )
|
save( BinaryOutputArchive & ar, std::vector<T, A> const & vector )
|
||||||
{
|
{
|
||||||
@@ -44,7 +44,7 @@ namespace cereal
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! Serialization for non-arithmetic (and bool) vector types from binary
|
//! Serialization for non-arithmetic (and bool) vector types from binary
|
||||||
template <class T, class A>
|
template <class T, class A> inline
|
||||||
typename std::enable_if<!std::is_arithmetic<T>::value || std::is_same<T, bool>::value, void>::type
|
typename std::enable_if<!std::is_arithmetic<T>::value || std::is_same<T, bool>::value, void>::type
|
||||||
load( BinaryInputArchive & ar, std::vector<T, A> & vector )
|
load( BinaryInputArchive & ar, std::vector<T, A> & vector )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
#include <cereal/binary_archive/utility.hpp>
|
#include <cereal/binary_archive/utility.hpp>
|
||||||
#include <cereal/binary_archive/tuple.hpp>
|
#include <cereal/binary_archive/tuple.hpp>
|
||||||
#include <cereal/binary_archive/bitset.hpp>
|
#include <cereal/binary_archive/bitset.hpp>
|
||||||
|
#include <cereal/binary_archive/complex.hpp>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <random>
|
#include <random>
|
||||||
|
|
||||||
@@ -154,6 +155,15 @@ std::basic_string<C> random_basic_string(std::mt19937 & gen)
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
std::string random_binary_string(std::mt19937 & gen)
|
||||||
|
{
|
||||||
|
std::string s(N, ' ');
|
||||||
|
for(auto & c : s )
|
||||||
|
c = std::uniform_int_distribution<char>('0', '1')(gen);
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
// ######################################################################
|
// ######################################################################
|
||||||
BOOST_AUTO_TEST_CASE( binary_pod )
|
BOOST_AUTO_TEST_CASE( binary_pod )
|
||||||
{
|
{
|
||||||
@@ -1668,3 +1678,84 @@ BOOST_AUTO_TEST_CASE( binary_tuple )
|
|||||||
BOOST_CHECK_EQUAL( i_espltuple == o_espltuple, true );
|
BOOST_CHECK_EQUAL( i_espltuple == o_espltuple, true );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ######################################################################
|
||||||
|
BOOST_AUTO_TEST_CASE( binary_complex )
|
||||||
|
{
|
||||||
|
std::random_device rd;
|
||||||
|
std::mt19937 gen(rd());
|
||||||
|
|
||||||
|
auto rngF = [&](){ return random_value<float>(gen); };
|
||||||
|
auto rngD = [&](){ return random_value<double>(gen); };
|
||||||
|
auto rngLD = [&](){ return random_value<long double>(gen); };
|
||||||
|
|
||||||
|
for(int i=0; i<100; ++i)
|
||||||
|
{
|
||||||
|
std::ostringstream os;
|
||||||
|
cereal::BinaryOutputArchive oar(os);
|
||||||
|
|
||||||
|
std::complex<float> o_float( rngF(), rngF() );
|
||||||
|
std::complex<double> o_double( rngD(), rngD() );
|
||||||
|
std::complex<long double> o_ldouble( rngLD(), rngLD() );
|
||||||
|
|
||||||
|
oar & o_float;
|
||||||
|
oar & o_double;
|
||||||
|
oar & o_ldouble;
|
||||||
|
|
||||||
|
std::istringstream is(os.str());
|
||||||
|
cereal::BinaryInputArchive iar(is);
|
||||||
|
|
||||||
|
std::complex<float> i_float;
|
||||||
|
std::complex<double> i_double;
|
||||||
|
std::complex<long double> i_ldouble;
|
||||||
|
|
||||||
|
iar & i_float;
|
||||||
|
iar & i_double;
|
||||||
|
iar & i_ldouble;
|
||||||
|
|
||||||
|
BOOST_CHECK_EQUAL( o_float, i_float );
|
||||||
|
BOOST_CHECK_EQUAL( o_double, i_double );
|
||||||
|
BOOST_CHECK_EQUAL( o_ldouble, i_ldouble );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ######################################################################
|
||||||
|
BOOST_AUTO_TEST_CASE( binary_bitset )
|
||||||
|
{
|
||||||
|
std::random_device rd;
|
||||||
|
std::mt19937 gen(rd());
|
||||||
|
|
||||||
|
auto rng32 = [&](){ return random_binary_string<32>( gen ); };
|
||||||
|
auto rng65 = [&](){ return random_binary_string<65>( gen ); };
|
||||||
|
auto rng256 = [&](){ return random_binary_string<256>( gen ); };
|
||||||
|
|
||||||
|
for(int i=0; i<100; ++i)
|
||||||
|
{
|
||||||
|
std::ostringstream os;
|
||||||
|
cereal::BinaryOutputArchive oar(os);
|
||||||
|
|
||||||
|
std::bitset<32> o_bit32( rng32() );
|
||||||
|
std::bitset<65> o_bit65( rng65() );
|
||||||
|
std::bitset<256> o_bit256( rng256() );
|
||||||
|
|
||||||
|
oar & o_bit32;
|
||||||
|
oar & o_bit65;
|
||||||
|
oar & o_bit256;
|
||||||
|
|
||||||
|
std::istringstream is(os.str());
|
||||||
|
cereal::BinaryInputArchive iar(is);
|
||||||
|
|
||||||
|
std::bitset<32> i_bit32;
|
||||||
|
std::bitset<65> i_bit65;
|
||||||
|
std::bitset<256> i_bit256;
|
||||||
|
|
||||||
|
iar & i_bit32;
|
||||||
|
iar & i_bit65;
|
||||||
|
iar & i_bit256;
|
||||||
|
|
||||||
|
BOOST_CHECK_EQUAL( o_bit32, i_bit32 );
|
||||||
|
BOOST_CHECK_EQUAL( o_bit65, i_bit65 );
|
||||||
|
BOOST_CHECK_EQUAL( o_bit256, i_bit256 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user