Embedded Multicore Building Blocks V1.0.0
function.h
1 /*
2  * Copyright (c) 2014-2017, Siemens AG. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  *
10  * 2. Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24  * POSSIBILITY OF SUCH DAMAGE.
25  */
26 
27 #ifndef EMBB_BASE_FUNCTION_H_
28 #define EMBB_BASE_FUNCTION_H_
29 
37 namespace embb {
38 namespace base {
39 
45 class Placeholder {
46  public:
47  class Arg_1 {};
48  class Arg_2 {};
49  class Arg_3 {};
50  class Arg_4 {};
51  class Arg_5 {};
52 
56  static Arg_1 _1;
57 
61  static Arg_2 _2;
62 
66  static Arg_3 _3;
67 
71  static Arg_4 _4;
72 
76  static Arg_5 _5;
77 };
78 
79 } // namespace base
80 } // namespace embb
81 
82 #ifdef DOXYGEN
83 
84 namespace embb {
85 namespace base {
86 
93 template <typename ReturnType, ...>
94 class Function {
95  public:
101  template <class ClassType>
102  explicit Function(
103  ClassType const & obj
104  );
105 
110  explicit Function(
111  ReturnType(*func)(...)
112  );
113 
118  template <class ClassType>
119  Function(
120  ClassType & obj,
121  ReturnType(ClassType::*func)(...)
123  );
124 
128  Function(
129  Function const & func
130  );
131 
135  ~Function();
136 
140  void operator = (
141  ReturnType(*func)(...)
142  );
143 
147  void operator = (
148  Function & func
149  );
150 
154  template <class C>
155  void operator = (
156  C const & obj
157  );
158 
163  ReturnType operator () (...);
164 };
165 
178 template <class ClassType, typename ReturnType, ...>
179 Function<ReturnType, [Arg1, ..., Arg5]> MakeFunction(
180  ClassType& obj,
182  ReturnType(ClassType::*func)([Arg1, ..., Arg5])
184  );
185 
196 template <typename ReturnType, ...>
197 Function<ReturnType, [Arg1, ..., Arg5]> MakeFunction(
198  ReturnType(*func)([Arg1, ..., Arg5])
200  );
201 
217 template <typename ReturnType, UnboundArgument, Arg1, ...>
219  Function<ReturnType, Arg1[, ..., Arg5]> func,
221  Arg1 value1,
225  ...
226  );
227 
228 } // namespace base
229 } // namespace embb
230 
231 #else // DOXYGEN
232 
233 #include <embb/base/internal/function0.h>
234 #include <embb/base/internal/function1.h>
235 #include <embb/base/internal/function2.h>
236 #include <embb/base/internal/function3.h>
237 #include <embb/base/internal/function4.h>
238 #include <embb/base/internal/function5.h>
239 
240 #endif // DOXYGEN
241 
242 #endif // EMBB_BASE_FUNCTION_H_
Definition: lock_free_mpmc_queue.h:40
static Arg_2 _2
Placeholder variable to be used in Bind() for keeping one argument unbound.
Definition: function.h:61
Function< ReturnType[, UnboundArgument]> Bind(Function< ReturnType, Arg1[,..., Arg5]> func, Arg1 value1,...)
Binds given values as arguments of func into a new Function.
Function< ReturnType,[Arg1,..., Arg5]> MakeFunction(ReturnType(*func)([Arg1,..., Arg5]))
Wraps a function pointer into a Function.
static Arg_1 _1
Placeholder variable to be used in Bind() for keeping one argument unbound.
Definition: function.h:56
static Arg_4 _4
Placeholder variable to be used in Bind() for keeping one argument unbound.
Definition: function.h:71
static Arg_3 _3
Placeholder variable to be used in Bind() for keeping one argument unbound.
Definition: function.h:66
static Arg_5 _5
Placeholder variable to be used in Bind() for keeping one argument unbound.
Definition: function.h:76
Wraps function pointers, member function pointers, and functors with up to five arguments.
Definition: function.h:94
Provides placeholders for Function arguments used in Bind()
Definition: function.h:45