framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Namespaces | Constant Groups | Functions
base_types.hpp File Reference

Fundamental serializable definitions. More...

#include <type_traits>
#include <algorithm>
#include <framework/common/common_macros.hpp>
#include <framework/serializable/base_types.inl>

Go to the source code of this file.

Namespaces

 framework
 Framework namespace.
 
 framework::serializable
 Serializable namespace.
 

Constant Groups

 framework
 Framework namespace.
 
 framework::serializable
 Serializable namespace.
 

Functions

template<typename Input , typename T >
std::enable_if
< std::is_arithmetic< T >
::value, bool >::type 
framework::serializable::read_dispatch (T *, Input &in, T &out)
 Arithmetic read overload.
 
template<typename Output , typename T >
std::enable_if
< std::is_arithmetic< T >
::value, bool >::type 
framework::serializable::write_dispatch (T *, T in, Output &out)
 Arithmetic write overload.
 
template<typename Specification , typename... Args>
FRAMEWORK_ALWAYS_INLINE auto framework::serializable::dispatch_read (Args &&...args) -> decltype(read_dispatch(static_cast< Specification * >(nullptr), std::forward< Args >(args)...))
 Dispatched read forwarder. More...
 
template<typename Specification , typename... Args>
FRAMEWORK_ALWAYS_INLINE auto framework::serializable::dispatch_write (Args &&...args) -> decltype(write_dispatch(static_cast< Specification * >(nullptr), std::forward< Args >(args)...))
 Dispatched write forwarder. More...
 
template<std::size_t N, typename Stream >
bool framework::serializable::stream_read (Stream &&stream, void *s)
 Stream read forwarder. More...
 
template<typename Stream >
bool framework::serializable::stream_read (Stream &&stream, void *s, std::size_t n)
 Stream read forwarder. More...
 
template<std::size_t N, typename Stream >
bool framework::serializable::stream_write (Stream &&stream, void const *s)
 Stream write forwarder. More...
 
template<typename Stream >
bool framework::serializable::stream_write (Stream &&stream, void const *s, std::size_t n)
 Stream write forwarder. More...
 
template<typename Input , typename Output >
FRAMEWORK_ALWAYS_INLINE auto framework::serializable::read (Input &&in, Output &&out) -> decltype(dispatch_read< reference_base< Output >>(std::forward< Input >(in), std::forward< Output >(out)))
 Read forwarder. More...
 
template<typename Input , typename Output >
FRAMEWORK_ALWAYS_INLINE auto framework::serializable::write (Input &&in, Output &&out) -> decltype(dispatch_write< reference_base< Input >>(std::forward< Input >(in), std::forward< Output >(out)))
 Write forwarder. More...
 

Detailed Description

Fundamental serializable definitions.

Provides the fundamental definitions extended by the remainder of this library to support specific types of serialization. Marshalling of data is performed using a collection of read/write method overloads, invoked as follows:

dispatch_read <Specification> (in, out);
dispatch_write <Specification> (in, out);

or through the following equivalent syntax:

read_dispatch((Specification*)nullptr, in, out);
write_dispatch((Specification*)nullptr, in, out);

It is important to note that the Specification provided to the above is used exclusively to define how the object is to be serialized. Specifically, there is no fundamental requirement that Specification match the associated input or output object above This allows code to alter how the serialization of a class takes place without altering it's definition - for example, the following is well defined:

struct S1 : serializable <S1,
value <NAME("Field 1"), int>,
value <NAME("Field 2"), float>,
value <NAME("Field 3"), double>,
value <NAME("Field 4"), short>>
{
} s1 {1, 2.0f, 3.0, 4};
struct S2 : serializable <S2,
value <NAME("Field 1"), int>,
value <NAME("Field 3"), double>>
{
} s2 {0, 0};
std::stringstream ss;
dispatch_write <S2> (s1, ss);
dispatch_read <S2> (ss, s2);

More commonly the alias template may be used to define part of the object's specification for use cases similar to the above. For example, the following computes a header-only checksum of the associated object:

using Header = alias <
value <NAME("Field 1"), int>,
value <NAME("Field 2"), float>>;
struct S1 : serializable <S1, Header,
value <NAME("Field 3"), double>,
value <NAME("Field 4"), short>>
{
} s1 {1, 2.0f, 3.0, 4};
internet_checksum chk;
dispatch_write <Header> (s1, chk);