Commit bb0a5840 authored by Matthieu Dorier's avatar Matthieu Dorier

added operator() in archives

parent f6f46b4b
# master
* Added copy() function in serialization archives. This function
acts like a read() for input archive, and like a write() for
output archives. This allows writing a single serialize() function
instead of load()/store() functions in many situations.
* Added operator() to input and output archives to enable a syntax
similar to that of the cereal library.
......@@ -60,17 +60,35 @@ public:
/**
* Operator to get C++ objects of type T from the archive.
* The object should either be a basic type, or an STL container
* (in which case the appropriate hgcxx/hg_stl/stl_* header should
* be included for this function to be properly instanciated), or
* any object for which either a serialize member function or
* (in which case the appropriate thallium/serialization/stl/ header
* should be included for this function to be properly instanciated),
* or any object for which either a serialize member function or
* a load member function has been provided.
*/
template<typename T>
buffer_input_archive& operator&(T&& obj) {
inline buffer_input_archive& operator&(T&& obj) {
read_impl(std::forward<T>(obj), std::is_arithmetic<typename std::decay<T>::type>());
return *this;
}
/**
* @brief Parenthesis operator with one argument, equivalent to & operator.
*/
template<typename T>
inline buffer_input_archive& operator()(T&& obj) {
return (*this) & std::forward<T>(obj);
}
/**
* @brief Parenthesis operator with multiple arguments.
* ar(x,y,z) is equivalent to ar & x & y & z.
*/
template<typename T, typename ... Targs>
inline buffer_input_archive& operator()(T&& obj, Targs&&... others) {
(*this) & std::forward<T>(obj);
return (*this)(std::forward<Targs>(others)...);
}
/**
* Operator >> is equivalent to operator &.
* \see operator&
......
......@@ -68,11 +68,29 @@ public:
* a load member function has been provided.
*/
template<typename T>
buffer_output_archive& operator&(T&& obj) {
inline buffer_output_archive& operator&(T&& obj) {
write_impl(std::forward<T>(obj), std::is_arithmetic<typename std::decay<T>::type>());
return *this;
}
/**
* @brief Parenthesis operator with one argument, equivalent to & operator.
*/
template<typename T>
inline buffer_output_archive& operator()(T&& obj) {
return (*this) & std::forward<T>(obj);
}
/**
* @brief Parenthesis operator with multiple arguments.
* ar(x,y,z) is equivalent to ar & x & y & z.
*/
template<typename T, typename ... Targs>
inline buffer_output_archive& operator()(T&& obj, Targs&&... others) {
(*this) & std::forward<T>(obj);
return (*this)(std::forward<Targs>(others)...);
}
/**
* Operator << is equivalent to operator &.
* \see operator&
......
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