framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
base_types.hpp
Go to the documentation of this file.
1 // Copyright (C) 2012 iwg molw5
2 // For conditions of distribution and use, see copyright notice in COPYING
3 
74 #pragma once
75 
76 #include <type_traits>
77 #include <algorithm>
78 
80 
81 namespace framework
82 {
83  namespace serializable
84  {
85  template <typename T>
86  using reference_base = typename std::remove_cv <typename std::remove_reference <T>::type>::type;
87 
91  template <typename Input, typename T>
92  typename std::enable_if <
93  std::is_arithmetic <T>::value,
94  bool
95  >::type read_dispatch (T*, Input& in, T& out);
96 
100  template <typename Output, typename T>
101  typename std::enable_if <
102  std::is_arithmetic <T>::value,
103  bool
104  >::type write_dispatch (T*, T in, Output& out);
105 
112  template <typename Specification, typename... Args>
114  auto dispatch_read (Args&&... args) ->
115  decltype(read_dispatch(
116  static_cast <Specification*> (nullptr),
117  std::forward <Args> (args)...))
118  {
119  return read_dispatch(
120  static_cast <Specification*> (nullptr),
121  std::forward <Args> (args)...);
122  }
123 
130  template <typename Specification, typename... Args>
132  auto dispatch_write (Args&&... args) ->
133  decltype(write_dispatch(
134  static_cast <Specification*> (nullptr),
135  std::forward <Args> (args)...))
136  {
137  return write_dispatch(
138  static_cast <Specification*> (nullptr),
139  std::forward <Args> (args)...);
140  }
141 
154  template <std::size_t N, typename Stream>
155  bool stream_read (Stream&& stream, void* s);
156 
167  template <typename Stream>
168  bool stream_read (Stream&& stream, void* s, std::size_t n);
169 
182  template <std::size_t N, typename Stream>
183  bool stream_write (Stream&& stream, void const* s);
184 
195  template <typename Stream>
196  bool stream_write (Stream&& stream, void const* s, std::size_t n);
197 
208  template <typename Input, typename Output>
210  auto read (Input&& in, Output&& out) ->
211  decltype(dispatch_read <reference_base <Output>> (
212  std::forward <Input> (in),
213  std::forward <Output> (out)))
214  {
215  return dispatch_read <reference_base <Output>> (
216  std::forward <Input> (in),
217  std::forward <Output> (out));
218  }
219 
226  template <typename Input, typename Output>
228  auto write (Input&& in, Output&& out) ->
229  decltype(dispatch_write <reference_base <Input>> (
230  std::forward <Input> (in),
231  std::forward <Output> (out)))
232  {
233  return dispatch_write <reference_base <Input>> (
234  std::forward <Input> (in),
235  std::forward <Output> (out));
236  }
237  }
238 }
239 
240 #include <framework/serializable/base_types.inl>