Turi Create  4.0
issue.hpp
1 /* Copyright © 2017 Apple Inc. All rights reserved.
2  *
3  * Use of this source code is governed by a BSD-3-clause license that can
4  * be found in the LICENSE.txt file or at https://opensource.org/licenses/BSD-3-Clause
5  */
6 #ifndef CPPIPC_CLIENT_ISSUE_HPP
7 #define CPPIPC_CLIENT_ISSUE_HPP
8 #include <tuple>
9 #include <boost/function.hpp>
10 #include <boost/type_traits.hpp>
11 #include <boost/function_types/function_type.hpp>
12 #include <boost/function_types/parameter_types.hpp>
13 #include <core/storage/serialization/iarchive.hpp>
14 #include <core/storage/serialization/oarchive.hpp>
15 #include <core/generics/remove_member_pointer.hpp>
16 #include <core/system/cppipc/util/generics/member_function_return_type.hpp>
17 #include <core/system/cppipc/util/generics/tuple.hpp>
18 #include <core/system/cppipc/ipc_object_base.hpp>
19 #include <type_traits>
20 
21 namespace cppipc {
22 
23 namespace detail{
24 /**
25  * \internal
26  * \ingroup cppipc
27  * Overload of issue_disect when the tuple list is not empty.
28  * Here we serialize the left most argument, shift the tuple and recursively
29  * forward the call.
30 */
31 template <typename ArgumentTuple, typename... Args>
32 struct issue_disect { };
33 
34 /**
35  * Overload of issue_disect when the tuple list is not empty.
36  * Here we serialize the left most argument, shift the tuple and recursively
37  * forward the call.
38  */
39 template <typename ArgumentTuple, typename Arg, typename... Args>
40 struct issue_disect<ArgumentTuple, Arg, Args...> {
41  static void exec(turi::oarchive& msg,
42  const Arg& a, const Args&... args) {
43  static_assert(1 + sizeof...(Args) == std::tuple_size<ArgumentTuple>::value, "Argument Count Mismatch");
44  typedef typename std::tuple_element<0, ArgumentTuple>::type arg_type;
45 
46  typedef typename std::decay<arg_type>::type decayed_arg_type;
47  if (std::is_same<decayed_arg_type, Arg>::value) {
48  msg << a;
49  } else {
50  msg << (decayed_arg_type)(a);
51  }
52  typedef typename left_shift_tuple<ArgumentTuple>::type shifted_tuple;
54  }
55 };
56 
57 /**
58  * \internal
59  * \ingroup cppipc
60  * Overload of execute_disect when the tuple list is empty,
61  * and there are no arguments. There is nothing to do here.
62  */
63 template <typename... Args>
64 struct issue_disect<std::tuple<>, Args...> {
65  static void exec(turi::oarchive& msg, const Args&... args) {
66  static_assert(sizeof...(Args) == 0, "Too Many Arguments");
67  }
68 };
69 } // namespace detail
70 
71 
72 /**
73  * \internal
74  * \ingroup cppipc
75  * Casts the arguments into the required types for the member function
76  * and serializes it into the output archive
77  */
78 template <typename MemFn, typename... Args>
80  MemFn fn,
81  const Args&... args) {
82  typedef typename boost::remove_member_pointer<MemFn>::type fntype;
83  typedef typename function_args_to_tuple<fntype>::type tuple;
84 
86 }
87 
88 } // cppipc
89 
90 #endif
STL namespace.
The serialization output archive object which, provided with a reference to an ostream, will write to the ostream, providing serialization capabilities.
Definition: oarchive.hpp:80
void issue(turi::oarchive &msg, MemFn fn, const Args &... args)
Definition: issue.hpp:79