GraphLab: Distributed Graph-Parallel API  2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
function_ret_type.hpp
1 /*
2  * Copyright (c) 2009 Carnegie Mellon University.
3  * All rights reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing,
12  * software distributed under the License is distributed on an "AS
13  * IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14  * express or implied. See the License for the specific language
15  * governing permissions and limitations under the License.
16  *
17  * For more about this software visit:
18  *
19  * http://www.graphlab.ml.cmu.edu
20  *
21  */
22 
23 
24 #ifndef FUNCTION_RETURN_TYPE_HPP
25 #define FUNCTION_RETURN_TYPE_HPP
26 #include <boost/preprocessor.hpp>
27 #include <graphlab/rpc/function_arg_types_def.hpp>
28 namespace graphlab {
29 namespace dc_impl {
30 
31 
32 /**
33 \ingroup rpc
34 \internal
35 
36 This struct performs two duties.
37 Firstly, it provides a consistent interface through a function called ::fcallN<F>
38 to complete a function call with a variable number of arguments.
39 Next, it provides the type of the return value of the function in ::type.
40 If the return type is void, it is promoted to an int. This makes the output
41 type of the function call be always serializable, simplifying the implementation
42 of "requests".
43 */
44 template <typename RetType>
45 struct function_ret_type {
46  typedef RetType type;
47 
48  #define GENARGS(Z,N,_) BOOST_PP_CAT(__GLRPC_R, N) BOOST_PP_CAT(i, N)
49 
50  #define FCALL(Z, N, _) \
51  template <typename F> \
52  static RetType BOOST_PP_CAT(fcall, N)(F f BOOST_PP_COMMA_IF(N) BOOST_PP_ENUM(N, GENARGS, _)){ \
53  return f(BOOST_PP_ENUM_PARAMS(N, i)); \
54  }
55 
56  BOOST_PP_REPEAT(8, FCALL , _ )
57 
58  #undef FCALL
59  #undef GENARGS
60 
61 };
62 
63 template <>
64 struct function_ret_type<void> {
65  typedef size_t type;
66 
67  #define GENARGS(Z,N,_) BOOST_PP_CAT(__GLRPC_R, N) BOOST_PP_CAT(i, N)
68 
69  #define FCALL(Z, N, _) \
70  template <typename F> \
71  static size_t BOOST_PP_CAT(fcall, N)(F f BOOST_PP_COMMA_IF(N) BOOST_PP_ENUM(N, GENARGS, _)){ \
72  f(BOOST_PP_ENUM_PARAMS(N, i)); \
73  return 0; \
74  }
75 
76  BOOST_PP_REPEAT(8, FCALL , _ )
77 
78  #undef FCALL
79  #undef GENARGS
80 
81 };
82 #include <graphlab/rpc/function_arg_types_undef.hpp>
83 
84 
85 } // namespace dc_impl
86 } // namespace graphlab
87 
88 #include <graphlab/rpc/mem_function_arg_types_def.hpp>
89 
90 namespace graphlab {
91 namespace dc_impl {
92 
93 /**
94 This struct performs two duties.
95 Firstly, it provides a consistent interface through a function called ::fcallN<F>
96 to complete a \b member function call with a variable number of arguments.
97 Next, it provides the type of the return value of the function in ::type.
98 If the return type is void, it is promoted to an int. This makes the output
99 type of the function call be always serializable, simplifying the implementation
100 of "requests".
101 */
102 template <typename RetType>
103 struct mem_function_ret_type {
104  typedef RetType type;
105 
106  #define GENARGS(Z,N,_) BOOST_PP_CAT(__GLRPC_R, N) BOOST_PP_CAT(i, N)
107 
108  #define FCALL(Z, N, _) \
109  template <typename F, typename T> \
110  static RetType BOOST_PP_CAT(fcall, N)(F f , T t BOOST_PP_COMMA_IF(N) BOOST_PP_ENUM(N, GENARGS, _)){ \
111  return (t->*f)(BOOST_PP_ENUM_PARAMS(N, i)); \
112  }
113 
114  BOOST_PP_REPEAT(8, FCALL , _ )
115 
116  #undef FCALL
117  #undef GENARGS
118 
119 };
120 
121 template <>
122 struct mem_function_ret_type<void> {
123  typedef size_t type;
124 
125  #define GENARGS(Z,N,_) BOOST_PP_CAT(__GLRPC_R, N) BOOST_PP_CAT(i, N)
126 
127  #define FCALL(Z, N, _) \
128  template <typename F, typename T> \
129  static size_t BOOST_PP_CAT(fcall, N)(F f , T t BOOST_PP_COMMA_IF(N) BOOST_PP_ENUM(N, GENARGS, _)){ \
130  (t->*f)(BOOST_PP_ENUM_PARAMS(N, i)); \
131  return 0; \
132  }
133 
134  BOOST_PP_REPEAT(8, FCALL , _ )
135 
136  #undef FCALL
137  #undef GENARGS
138 
139 };
140 
141 
142 
143 
144 } // namespace dc_impl
145 } // namespace graphlab
146 
147 #include <graphlab/rpc/mem_function_arg_types_undef.hpp>
148 
149 #endif
150