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

inlined all serialization functions

parent 3f5284af
......@@ -103,14 +103,14 @@ struct serializer;
template<class A, typename T>
struct serializer<A,T,true> {
static void apply(A& ar, T&& t) {
static inline void apply(A& ar, T&& t) {
t.serialize(ar);
}
};
template<class A, typename T>
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,
"Undefined \"serialize\" member function");
}
......@@ -120,7 +120,7 @@ struct serializer<A,T,false> {
* Generic serialize method calling apply on a serializer.
*/
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));
}
......@@ -133,14 +133,14 @@ struct saver;
template<class A, typename T>
struct saver<A,T,true> {
static void apply(A& ar, T& t) {
static inline void apply(A& ar, T& t) {
t.save(ar);
}
};
template<class A, typename T>
struct saver<A,T,false> {
static void apply(A& ar, T& t) {
static inline void apply(A& ar, T& t) {
serialize(ar,t);
}
};
......@@ -167,14 +167,14 @@ struct loader;
template<class A, typename T>
struct loader<A,T,true> {
static void apply(A& ar, T& t) {
static inline void apply(A& ar, T& t) {
t.load(ar);
}
};
template<class A, typename T>
struct loader<A,T,false> {
static void apply(A& ar, T& t) {
static inline void apply(A& ar, T& t) {
serialize(ar,t);
}
};
......@@ -192,13 +192,13 @@ inline void load(A& ar, T& t) {
* objects passed as arguments.
*/
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);
serialize_many(ar, std::forward<Tn>(rest)...);
}
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);
}
......
......@@ -14,26 +14,26 @@ namespace thallium {
namespace detail {
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) {
ar & elem;
}
}
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);
}
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++) {
ar & v[i];
}
}
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);
}
......
......@@ -11,13 +11,13 @@
namespace thallium {
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.imag();
}
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.imag();
}
......
......@@ -11,7 +11,7 @@
namespace thallium {
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();
ar.write(&size);
for(auto& item : l) {
......@@ -20,7 +20,7 @@ void save(A& ar, std::deque<T,Alloc>& l) {
}
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;
l.clear();
ar.read(&size);
......
......@@ -11,7 +11,7 @@
namespace thallium {
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();
ar.write(&size);
for(auto& item : l) {
......@@ -20,7 +20,7 @@ void save(A& ar, std::forward_list<T,Alloc>& l) {
}
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;
l.clear();
ar.read(&size);
......
......@@ -11,7 +11,7 @@
namespace thallium {
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();
ar.write(&size);
for(auto& item : l) {
......@@ -20,7 +20,7 @@ void save(A& ar, std::list<T,Alloc>& l) {
}
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;
l.clear();
ar.read(&size);
......
......@@ -6,7 +6,7 @@
namespace thallium {
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();
ar.write(&size);
for(auto& elem : 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>
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;
ar.read(&size);
m.clear();
......
......@@ -11,7 +11,7 @@
namespace thallium {
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();
ar.write(&size);
for(auto& elem : 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>
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;
ar.read(&size);
m.clear();
......
......@@ -12,7 +12,7 @@
namespace thallium {
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();
ar.write(&size);
for(auto& elem : s) {
......@@ -21,7 +21,7 @@ void save(A& ar, std::multiset<T,Compare,Alloc>& s) {
}
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;
s.clear();
ar.read(&size);
......
......@@ -11,7 +11,7 @@
namespace thallium {
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.second;
}
......
......@@ -12,7 +12,7 @@
namespace thallium {
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();
ar.write(&size);
for(auto& elem : s) {
......@@ -21,7 +21,7 @@ void save(A& ar, std::set<T,Compare,Alloc>& s) {
}
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;
s.clear();
ar.read(&size);
......
......@@ -7,14 +7,14 @@
namespace thallium {
template<class A>
void save(A& ar, std::string& s) {
inline void save(A& ar, std::string& s) {
size_t size = s.size();
ar.write(&size);
ar.write((const char*)(&s[0]), size);
}
template<class A>
void load(A& ar, std::string& s) {
inline void load(A& ar, std::string& s) {
size_t size;
s.clear();
ar.read(&size);
......
......@@ -16,7 +16,7 @@ template<size_t N>
struct tuple_serializer {
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);
ar & std::get<N-1>(t);
}
......@@ -26,18 +26,18 @@ template<>
struct tuple_serializer<0> {
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>
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);
}
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);
}
......
......@@ -11,7 +11,7 @@
namespace thallium {
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();
ar.write(&size);
for(auto& elem : 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>
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;
ar.read(&size);
m.clear();
......
......@@ -11,7 +11,7 @@
namespace thallium {
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();
ar.write(&size);
for(auto& elem : 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>
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;
ar.read(&size);
m.clear();
......
......@@ -12,25 +12,25 @@
namespace thallium {
template<class A, typename V, class Hash, class Pred, class Alloc>
void save(A& ar, std::unordered_multiset<V,Hash,Pred,Alloc>& s) {
size_t size = s.size();
ar.write(&size);
for(auto& elem : s) {
ar & elem;
}
inline void save(A& ar, std::unordered_multiset<V,Hash,Pred,Alloc>& s) {
size_t size = s.size();
ar.write(&size);
for(auto& elem : s) {
ar & elem;
}
}
template<class A, typename V, class Hash, class Pred, class Alloc>
void load(A& ar, std::unordered_multiset<V,Hash,Pred,Alloc>& s) {
size_t size;
ar.read(&size);
s.clear();
s.reserve(size);
for(unsigned int i=0; i<size; i++) {
V item;;
ar & item;
s.insert(std::move(item));
}
inline void load(A& ar, std::unordered_multiset<V,Hash,Pred,Alloc>& s) {
size_t size;
ar.read(&size);
s.clear();
s.reserve(size);
for(unsigned int i=0; i<size; i++) {
V item;;
ar & item;
s.insert(std::move(item));
}
}
}
......
......@@ -12,7 +12,7 @@
namespace thallium {
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();
ar.write(&size);
for(auto& elem : 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>
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;
ar.read(&size);
s.clear();
......
......@@ -14,7 +14,7 @@ namespace thallium {
namespace detail {
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();
ar.write(&size);
for(auto& elem : v) {
......@@ -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>
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();
ar.write(&size);
ar.write(&v[0],size);
}
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;
ar.read(&size);
v.clear();
......@@ -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>
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;
ar.read(&size);
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