rttr  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros Pages
method_container.h
Go to the documentation of this file.
1 /************************************************************************************
2 * *
3 * Copyright (c) 2014 Axel Menzel <info@axelmenzel.de> *
4 * *
5 * This file is part of RTTR (Run Time Type Reflection) *
6 * License: MIT License *
7 * *
8 * Permission is hereby granted, free of charge, to any person obtaining *
9 * a copy of this software and associated documentation files (the "Software"), *
10 * to deal in the Software without restriction, including without limitation *
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense, *
12 * and/or sell copies of the Software, and to permit persons to whom the *
13 * Software is furnished to do so, subject to the following conditions: *
14 * *
15 * The above copyright notice and this permission notice shall be included in *
16 * all copies or substantial portions of the Software. *
17 * *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *
24 * SOFTWARE. *
25 * *
26 *************************************************************************************/
27 
28 #ifndef __RTTR_METHOD_CONTAINER_H__
29 #define __RTTR_METHOD_CONTAINER_H__
30 
34 #include "rttr/detail/argument.h"
35 #include "rttr/detail/instance.h"
38 #include "rttr/variant.h"
39 
40 
41 #include <functional>
42 #include <string>
43 
44 namespace rttr
45 {
46 namespace detail
47 {
48 
49 template<typename F, typename Policy>
50 class method_container : public method_container_base
51 {
52  public:
53  method_container(const std::string& name, const type declaring_type, F func_acc)
54  : method_container_base(name, declaring_type),
55  _func_acc(func_acc)
56  { }
57 
58  bool is_static() const { return method_accessor<F, Policy>::is_static(); }
59  type get_return_type() const { return method_accessor<F, Policy>::get_return_type(); }
60  std::vector<bool> get_is_reference() const { return method_accessor<F, Policy>::get_is_reference(); }
61  std::vector<bool> get_is_const() const { return method_accessor<F, Policy>::get_is_const(); }
62  std::vector<type> get_parameter_types() const { return method_accessor<F, Policy>::get_parameter_types(); }
63 
64  variant invoke(detail::instance& object) const
65  {
66  return method_accessor<F, Policy>::invoke(_func_acc, object);
67  }
68 
69  variant invoke(detail::instance& object, detail::argument& arg1) const
70  {
71  return method_accessor<F, Policy>::invoke(_func_acc, object, arg1);
72  }
73  variant invoke(detail::instance& object, detail::argument& arg1, detail::argument& arg2) const
74  {
75  return method_accessor<F, Policy>::invoke(_func_acc, object, arg1, arg2);
76  }
77  variant invoke(detail::instance& object, detail::argument& arg1, detail::argument& arg2, detail::argument& arg3) const
78  {
79  return method_accessor<F, Policy>::invoke(_func_acc, object, arg1, arg2, arg3);
80  }
81  variant invoke(detail::instance& object, detail::argument& arg1, detail::argument& arg2, detail::argument& arg3, detail::argument& arg4) const
82  {
83  return method_accessor<F, Policy>::invoke(_func_acc, object, arg1, arg2, arg3, arg4);
84  }
85  variant invoke(detail::instance& object, detail::argument& arg1, detail::argument& arg2, detail::argument& arg3, detail::argument& arg4, detail::argument& arg5) const
86  {
87  return method_accessor<F, Policy>::invoke(_func_acc, object, arg1, arg2, arg3, arg4, arg5);
88  }
89  variant invoke(detail::instance& object, detail::argument& arg1, detail::argument& arg2, detail::argument& arg3, detail::argument& arg4, detail::argument& arg5, detail::argument& arg6) const
90  {
91  return method_accessor<F, Policy>::invoke(_func_acc, object, arg1, arg2, arg3, arg4, arg5, arg6);
92  }
93 
94  variant invoke_variadic(detail::instance& object, std::vector<detail::argument>& args) const
95  {
96  return method_accessor<F, Policy>::invoke(_func_acc, object, args);
97  }
98 
99  private:
100  F _func_acc;
101 };
102 
103 } // end namespace detail
104 } // end namespace rttr
105 
106 #endif // __RTTR_METHOD_CONTAINER_H__