Commit 70fa4335 authored by Matthieu Dorier's avatar Matthieu Dorier

inlined all serialization functions

parent 3f5284af
...@@ -103,14 +103,14 @@ struct serializer; ...@@ -103,14 +103,14 @@ struct serializer;
template<class A, typename T> template<class A, typename T>
struct serializer<A,T,true> { struct serializer<A,T,true> {
static void apply(A& ar, T&& t) { static inline void apply(A& ar, T&& t) {
t.serialize(ar); t.serialize(ar);
} }
}; };
template<class A, typename T> template<class A, typename T>
struct serializer<A,T,false> { struct serializer<A,T,false> {
static void apply(A& ar, T&& t) { static inline void apply(A& ar, T&& t) {
static_assert(has_serialize_method<A,T>::value, static_assert(has_serialize_method<A,T>::value,
"Undefined \"serialize\" member function"); "Undefined \"serialize\" member function");
} }
...@@ -120,7 +120,7 @@ struct serializer<A,T,false> { ...@@ -120,7 +120,7 @@ struct serializer<A,T,false> {
* Generic serialize method calling apply on a serializer. * Generic serialize method calling apply on a serializer.
*/ */
template<class A, typename T> template<class A, typename T>
void serialize(A& ar, T& t) { inline void serialize(A& ar, T& t) {
serializer<A,T,has_serialize_method<A,T>::value>::apply(ar,std::forward<T>(t)); serializer<A,T,has_serialize_method<A,T>::value>::apply(ar,std::forward<T>(t));
} }
...@@ -133,14 +133,14 @@ struct saver; ...@@ -133,14 +133,14 @@ struct saver;
template<class A, typename T> template<class A, typename T>
struct saver<A,T,true> { struct saver<A,T,true> {
static void apply(A& ar, T& t) { static inline void apply(A& ar, T& t) {
t.save(ar); t.save(ar);
} }
}; };
template<class A, typename T> template<class A, typename T>
struct saver<A,T,false> { struct saver<A,T,false> {
static void apply(A& ar, T& t) { static inline void apply(A& ar, T& t) {
serialize(ar,t); serialize(ar,t);
} }
}; };
...@@ -167,14 +167,14 @@ struct loader; ...@@ -167,14 +167,14 @@ struct loader;
template<class A, typename T> template<class A, typename T>
struct loader<A,T,true> { struct loader<A,T,true> {
static void apply(A& ar, T& t) { static inline void apply(A& ar, T& t) {
t.load(ar); t.load(ar);
} }
}; };
template<class A, typename T> template<class A, typename T>
struct loader<A,T,false> { struct loader<A,T,false> {
static void apply(A& ar, T& t) { static inline void apply(A& ar, T& t) {
serialize(ar,t); serialize(ar,t);
} }
}; };
...@@ -192,13 +192,13 @@ inline void load(A& ar, T& t) { ...@@ -192,13 +192,13 @@ inline void load(A& ar, T& t) {
* objects passed as arguments. * objects passed as arguments.
*/ */
template<class A, typename T1, typename... Tn> template<class A, typename T1, typename... Tn>
void serialize_many(A& ar, T1&& t1, Tn&&... rest) { inline void serialize_many(A& ar, T1&& t1, Tn&&... rest) {
ar & std::forward<T1>(t1); ar & std::forward<T1>(t1);
serialize_many(ar, std::forward<Tn>(rest)...); serialize_many(ar, std::forward<Tn>(rest)...);
} }
template<class A, typename T> template<class A, typename T>
void serialize_many(A& ar, T&& t) { inline void serialize_many(A& ar, T&& t) {
ar & std::forward<T>(t); ar & std::forward<T>(t);
} }
......
...@@ -14,26 +14,26 @@ namespace thallium { ...@@ -14,26 +14,26 @@ namespace thallium {
namespace detail { namespace detail {
template<class A, typename T, size_t N, bool b> template<class A, typename T, size_t N, bool b>
void save_array_impl(A& ar, std::array<T,N>& v, const std::integral_constant<bool, b>&) { inline void save_array_impl(A& ar, std::array<T,N>& v, const std::integral_constant<bool, b>&) {
for(auto& elem : v) { for(auto& elem : v) {
ar & elem; ar & elem;
} }
} }
template<class A, typename T, size_t N> template<class A, typename T, size_t N>
void save_array_impl(A& ar, std::array<T,N>& v, const std::true_type&) { inline void save_array_impl(A& ar, std::array<T,N>& v, const std::true_type&) {
ar.write(&v[0],N); ar.write(&v[0],N);
} }
template<class A, typename T, size_t N, bool b> template<class A, typename T, size_t N, bool b>
void load_array_impl(A& ar, std::array<T,N>& v, const std::integral_constant<bool, b>&) { inline void load_array_impl(A& ar, std::array<T,N>& v, const std::integral_constant<bool, b>&) {
for(unsigned int i=0; i<N; i++) { for(unsigned int i=0; i<N; i++) {
ar & v[i]; ar & v[i];
} }
} }
template<class A, typename T, size_t N> template<class A, typename T, size_t N>
void load_array_impl(A& ar, std::array<T,N>& v, const std::true_type&) { inline void load_array_impl(A& ar, std::array<T,N>& v, const std::true_type&) {
ar.read(&v[0],N); ar.read(&v[0],N);
} }
......
...@@ -11,13 +11,13 @@ ...@@ -11,13 +11,13 @@
namespace thallium { namespace thallium {
template<class A, class T> template<class A, class T>
void save(A& ar, std::complex<T>& t) { inline void save(A& ar, std::complex<T>& t) {
ar & t.real(); ar & t.real();
ar & t.imag(); ar & t.imag();
} }
template<class A, typename T> template<class A, typename T>
void load(A& ar, std::complex<T>& t) { inline void load(A& ar, std::complex<T>& t) {
ar & t.real(); ar & t.real();
ar & t.imag(); ar & t.imag();
} }
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
namespace thallium { namespace thallium {
template<class A, typename T, typename Alloc> template<class A, typename T, typename Alloc>
void save(A& ar, std::deque<T,Alloc>& l) { inline void save(A& ar, std::deque<T,Alloc>& l) {
size_t size = l.size(); size_t size = l.size();
ar.write(&size); ar.write(&size);
for(auto& item : l) { for(auto& item : l) {
...@@ -20,7 +20,7 @@ void save(A& ar, std::deque<T,Alloc>& l) { ...@@ -20,7 +20,7 @@ void save(A& ar, std::deque<T,Alloc>& l) {
} }
template<class A, typename T, typename Alloc> template<class A, typename T, typename Alloc>
void load(A& ar, std::deque<T,Alloc>& l) { inline void load(A& ar, std::deque<T,Alloc>& l) {
size_t size; size_t size;
l.clear(); l.clear();
ar.read(&size); ar.read(&size);
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
namespace thallium { namespace thallium {
template<class A, typename T, typename Alloc> template<class A, typename T, typename Alloc>
void save(A& ar, std::forward_list<T,Alloc>& l) { inline void save(A& ar, std::forward_list<T,Alloc>& l) {
size_t size = l.size(); size_t size = l.size();
ar.write(&size); ar.write(&size);
for(auto& item : l) { for(auto& item : l) {
...@@ -20,7 +20,7 @@ void save(A& ar, std::forward_list<T,Alloc>& l) { ...@@ -20,7 +20,7 @@ void save(A& ar, std::forward_list<T,Alloc>& l) {
} }
template<class A, typename T, typename Alloc> template<class A, typename T, typename Alloc>
void load(A& ar, std::forward_list<T,Alloc>& l) { inline void load(A& ar, std::forward_list<T,Alloc>& l) {
size_t size; size_t size;
l.clear(); l.clear();
ar.read(&size); ar.read(&size);
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
namespace thallium { namespace thallium {
template<class A, typename T, typename Alloc> template<class A, typename T, typename Alloc>
void save(A& ar, std::list<T,Alloc>& l) { inline void save(A& ar, std::list<T,Alloc>& l) {
size_t size = l.size(); size_t size = l.size();
ar.write(&size); ar.write(&size);
for(auto& item : l) { for(auto& item : l) {
...@@ -20,7 +20,7 @@ void save(A& ar, std::list<T,Alloc>& l) { ...@@ -20,7 +20,7 @@ void save(A& ar, std::list<T,Alloc>& l) {
} }
template<class A, typename T, typename Alloc> template<class A, typename T, typename Alloc>
void load(A& ar, std::list<T,Alloc>& l) { inline void load(A& ar, std::list<T,Alloc>& l) {
size_t size; size_t size;
l.clear(); l.clear();
ar.read(&size); ar.read(&size);
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
namespace thallium { namespace thallium {
template<class A, typename K, typename V, class Compare, class Alloc> template<class A, typename K, typename V, class Compare, class Alloc>
void save(A& ar, std::map<K,V,Compare,Alloc>& m) { inline void save(A& ar, std::map<K,V,Compare,Alloc>& m) {
size_t size = m.size(); size_t size = m.size();
ar.write(&size); ar.write(&size);
for(auto& elem : m) { for(auto& elem : m) {
...@@ -16,7 +16,7 @@ void save(A& ar, std::map<K,V,Compare,Alloc>& m) { ...@@ -16,7 +16,7 @@ void save(A& ar, std::map<K,V,Compare,Alloc>& m) {
} }
template<class A, typename K, typename V, class Compare, class Alloc> template<class A, typename K, typename V, class Compare, class Alloc>
void load(A& ar, std::map<K,V,Compare,Alloc>& m) { inline void load(A& ar, std::map<K,V,Compare,Alloc>& m) {
size_t size; size_t size;
ar.read(&size); ar.read(&size);
m.clear(); m.clear();
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
namespace thallium { namespace thallium {
template<class A, typename K, typename V, class Compare, class Alloc> template<class A, typename K, typename V, class Compare, class Alloc>
void save(A& ar, std::multimap<K,V,Compare,Alloc>& m) { inline void save(A& ar, std::multimap<K,V,Compare,Alloc>& m) {
size_t size = m.size(); size_t size = m.size();
ar.write(&size); ar.write(&size);
for(auto& elem : m) { for(auto& elem : m) {
...@@ -21,7 +21,7 @@ void save(A& ar, std::multimap<K,V,Compare,Alloc>& m) { ...@@ -21,7 +21,7 @@ void save(A& ar, std::multimap<K,V,Compare,Alloc>& m) {
} }
template<class A, typename K, typename V, class Compare, class Alloc> template<class A, typename K, typename V, class Compare, class Alloc>
void load(A& ar, std::multimap<K,V,Compare,Alloc>& m) { inline void load(A& ar, std::multimap<K,V,Compare,Alloc>& m) {
size_t size; size_t size;
ar.read(&size); ar.read(&size);
m.clear(); m.clear();
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
namespace thallium { namespace thallium {
template<class A, typename T, class Compare, class Alloc> template<class A, typename T, class Compare, class Alloc>
void save(A& ar, std::multiset<T,Compare,Alloc>& s) { inline void save(A& ar, std::multiset<T,Compare,Alloc>& s) {
size_t size = s.size(); size_t size = s.size();
ar.write(&size); ar.write(&size);
for(auto& elem : s) { for(auto& elem : s) {
...@@ -21,7 +21,7 @@ void save(A& ar, std::multiset<T,Compare,Alloc>& s) { ...@@ -21,7 +21,7 @@ void save(A& ar, std::multiset<T,Compare,Alloc>& s) {
} }
template<class A, typename T, class Compare, class Alloc> template<class A, typename T, class Compare, class Alloc>
void load(A& ar, std::multiset<T,Compare,Alloc>& s) { inline void load(A& ar, std::multiset<T,Compare,Alloc>& s) {
size_t size; size_t size;
s.clear(); s.clear();
ar.read(&size); ar.read(&size);
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
namespace thallium { namespace thallium {
template<typename A, typename T1, typename T2> template<typename A, typename T1, typename T2>
void serialize(A& a, std::pair<T1,T2>& p) { inline void serialize(A& a, std::pair<T1,T2>& p) {
a & p.first; a & p.first;
a & p.second; a & p.second;
} }
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
namespace thallium { namespace thallium {
template<class A, typename T, class Compare, class Alloc> template<class A, typename T, class Compare, class Alloc>
void save(A& ar, std::set<T,Compare,Alloc>& s) { inline void save(A& ar, std::set<T,Compare,Alloc>& s) {
size_t size = s.size(); size_t size = s.size();
ar.write(&size); ar.write(&size);
for(auto& elem : s) { for(auto& elem : s) {
...@@ -21,7 +21,7 @@ void save(A& ar, std::set<T,Compare,Alloc>& s) { ...@@ -21,7 +21,7 @@ void save(A& ar, std::set<T,Compare,Alloc>& s) {
} }
template<class A, typename T, class Compare, class Alloc> template<class A, typename T, class Compare, class Alloc>
void load(A& ar, std::set<T,Compare,Alloc>& s) { inline void load(A& ar, std::set<T,Compare,Alloc>& s) {
size_t size; size_t size;
s.clear(); s.clear();
ar.read(&size); ar.read(&size);
......
...@@ -7,14 +7,14 @@ ...@@ -7,14 +7,14 @@
namespace thallium { namespace thallium {
template<class A> template<class A>
void save(A& ar, std::string& s) { inline void save(A& ar, std::string& s) {
size_t size = s.size(); size_t size = s.size();
ar.write(&size); ar.write(&size);
ar.write((const char*)(&s[0]), size); ar.write((const char*)(&s[0]), size);
} }
template<class A> template<class A>
void load(A& ar, std::string& s) { inline void load(A& ar, std::string& s) {
size_t size; size_t size;
s.clear(); s.clear();
ar.read(&size); ar.read(&size);
......
...@@ -16,7 +16,7 @@ template<size_t N> ...@@ -16,7 +16,7 @@ template<size_t N>
struct tuple_serializer { struct tuple_serializer {
template<class A, class... Types> template<class A, class... Types>
static void apply(A& ar, std::tuple<Types...>& t) { static inline void apply(A& ar, std::tuple<Types...>& t) {
tuple_serializer<N-1>::apply(ar,t); tuple_serializer<N-1>::apply(ar,t);
ar & std::get<N-1>(t); ar & std::get<N-1>(t);
} }
...@@ -26,18 +26,18 @@ template<> ...@@ -26,18 +26,18 @@ template<>
struct tuple_serializer<0> { struct tuple_serializer<0> {
template<class A, class... Types> template<class A, class... Types>
static void apply(A& ar, std::tuple<Types...>& t) {} static inline void apply(A& ar, std::tuple<Types...>& t) {}
}; };
} }
template<class A, class... Types> template<class A, class... Types>
void save(A& ar, std::tuple<Types...>& t) { inline void save(A& ar, std::tuple<Types...>& t) {
detail::tuple_serializer<sizeof...(Types)>::apply(ar,t); detail::tuple_serializer<sizeof...(Types)>::apply(ar,t);
} }
template<class A, typename... Types> template<class A, typename... Types>
void load(A& ar, std::tuple<Types...>& t) { inline void load(A& ar, std::tuple<Types...>& t) {
detail::tuple_serializer<sizeof...(Types)>::apply(ar,t); detail::tuple_serializer<sizeof...(Types)>::apply(ar,t);
} }
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
namespace thallium { namespace thallium {
template<class A, typename K, typename V, class Hash, class Pred, class Alloc> template<class A, typename K, typename V, class Hash, class Pred, class Alloc>
void save(A& ar, std::unordered_map<K,V,Hash,Pred,Alloc>& m) { inline void save(A& ar, std::unordered_map<K,V,Hash,Pred,Alloc>& m) {
size_t size = m.size(); size_t size = m.size();
ar.write(&size); ar.write(&size);
for(auto& elem : m) { for(auto& elem : m) {
...@@ -21,7 +21,7 @@ void save(A& ar, std::unordered_map<K,V,Hash,Pred,Alloc>& m) { ...@@ -21,7 +21,7 @@ void save(A& ar, std::unordered_map<K,V,Hash,Pred,Alloc>& m) {
} }
template<class A, typename K, typename V, class Hash, class Pred, class Alloc> template<class A, typename K, typename V, class Hash, class Pred, class Alloc>
void load(A& ar, std::unordered_map<K,V,Hash,Pred,Alloc>& m) { inline void load(A& ar, std::unordered_map<K,V,Hash,Pred,Alloc>& m) {
size_t size; size_t size;
ar.read(&size); ar.read(&size);
m.clear(); m.clear();
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
namespace thallium { namespace thallium {
template<class A, typename K, typename V, class Hash, class Pred, class Alloc> template<class A, typename K, typename V, class Hash, class Pred, class Alloc>
void save(A& ar, std::unordered_multimap<K,V,Hash,Pred,Alloc>& m) { inline void save(A& ar, std::unordered_multimap<K,V,Hash,Pred,Alloc>& m) {
size_t size = m.size(); size_t size = m.size();
ar.write(&size); ar.write(&size);
for(auto& elem : m) { for(auto& elem : m) {
...@@ -21,7 +21,7 @@ void save(A& ar, std::unordered_multimap<K,V,Hash,Pred,Alloc>& m) { ...@@ -21,7 +21,7 @@ void save(A& ar, std::unordered_multimap<K,V,Hash,Pred,Alloc>& m) {
} }
template<class A, typename K, typename V, class Hash, class Pred, class Alloc> template<class A, typename K, typename V, class Hash, class Pred, class Alloc>
void load(A& ar, std::unordered_multimap<K,V,Hash,Pred,Alloc>& m) { inline void load(A& ar, std::unordered_multimap<K,V,Hash,Pred,Alloc>& m) {
size_t size; size_t size;
ar.read(&size); ar.read(&size);
m.clear(); m.clear();
......
...@@ -12,25 +12,25 @@ ...@@ -12,25 +12,25 @@
namespace thallium { namespace thallium {
template<class A, typename V, class Hash, class Pred, class Alloc> template<class A, typename V, class Hash, class Pred, class Alloc>
void save(A& ar, std::unordered_multiset<V,Hash,Pred,Alloc>& s) { inline void save(A& ar, std::unordered_multiset<V,Hash,Pred,Alloc>& s) {
size_t size = s.size(); size_t size = s.size();
ar.write(&size); ar.write(&size);
for(auto& elem : s) { for(auto& elem : s) {
ar & elem; ar & elem;
} }
} }
template<class A, typename V, class Hash, class Pred, class Alloc> template<class A, typename V, class Hash, class Pred, class Alloc>
void load(A& ar, std::unordered_multiset<V,Hash,Pred,Alloc>& s) { inline void load(A& ar, std::unordered_multiset<V,Hash,Pred,Alloc>& s) {
size_t size; size_t size;
ar.read(&size); ar.read(&size);
s.clear(); s.clear();
s.reserve(size); s.reserve(size);
for(unsigned int i=0; i<size; i++) { for(unsigned int i=0; i<size; i++) {
V item;; V item;;
ar & item; ar & item;
s.insert(std::move(item)); s.insert(std::move(item));
} }
} }
} }
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
namespace thallium { namespace thallium {
template<class A, typename V, class Hash, class Pred, class Alloc> template<class A, typename V, class Hash, class Pred, class Alloc>
void save(A& ar, std::unordered_set<V,Hash,Pred,Alloc>& s) { inline void save(A& ar, std::unordered_set<V,Hash,Pred,Alloc>& s) {
size_t size = s.size(); size_t size = s.size();
ar.write(&size); ar.write(&size);
for(auto& elem : s) { for(auto& elem : s) {
...@@ -21,7 +21,7 @@ void save(A& ar, std::unordered_set<V,Hash,Pred,Alloc>& s) { ...@@ -21,7 +21,7 @@ void save(A& ar, std::unordered_set<V,Hash,Pred,Alloc>& s) {
} }
template<class A, typename V, class Hash, class Pred, class Alloc> template<class A, typename V, class Hash, class Pred, class Alloc>
void load(A& ar, std::unordered_set<V,Hash,Pred,Alloc>& s) { inline void load(A& ar, std::unordered_set<V,Hash,Pred,Alloc>& s) {
size_t size; size_t size;
ar.read(&size); ar.read(&size);
s.clear(); s.clear();
......
...@@ -14,7 +14,7 @@ namespace thallium { ...@@ -14,7 +14,7 @@ namespace thallium {
namespace detail { namespace detail {
template<class A, typename T, class Alloc, bool b> template<class A, typename T, class Alloc, bool b>
void save_vector_impl(A& ar, std::vector<T,Alloc>& v, const std::integral_constant<bool, b>&) { inline void save_vector_impl(A& ar, std::vector<T,Alloc>& v, const std::integral_constant<bool, b>&) {
size_t size = v.size(); size_t size = v.size();
ar.write(&size); ar.write(&size);
for(auto& elem : v) { for(auto& elem : v) {
...@@ -23,14 +23,14 @@ void save_vector_impl(A& ar, std::vector<T,Alloc>& v, const std::integral_consta ...@@ -23,14 +23,14 @@ void save_vector_impl(A& ar, std::vector<T,Alloc>& v, const std::integral_consta
} }
template<class A, typename T, class Alloc> template<class A, typename T, class Alloc>
void save_vector_impl(A& ar, std::vector<T,Alloc>& v, const std::true_type&) { inline void save_vector_impl(A& ar, std::vector<T,Alloc>& v, const std::true_type&) {
size_t size = v.size(); size_t size = v.size();
ar.write(&size); ar.write(&size);
ar.write(&v[0],size); ar.write(&v[0],size);
} }
template<class A, typename T, class Alloc, bool b> template<class A, typename T, class Alloc, bool b>
void load_vector_impl(A& ar, std::vector<T,Alloc>& v, const std::integral_constant<bool, b>&) { inline void load_vector_impl(A& ar, std::vector<T,Alloc>& v, const std::integral_constant<bool, b>&) {
size_t size; size_t size;
ar.read(&size); ar.read(&size);
v.clear(); v.clear();
...@@ -41,7 +41,7 @@ void load_vector_impl(A& ar, std::vector<T,Alloc>& v, const std::integral_consta ...@@ -41,7 +41,7 @@ void load_vector_impl(A& ar, std::vector<T,Alloc>& v, const std::integral_consta
} }
template<class A, typename T, class Alloc> template<class A, typename T, class Alloc>
void load_vector_impl(A& ar, std::vector<T,Alloc>& v, const std::true_type&) { inline void load_vector_impl(A& ar, std::vector<T,Alloc>& v, const std::true_type&) {
size_t size; size_t size;
ar.read(&size); ar.read(&size);
v.clear(); v.clear();
......
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