14 #define ADTF_UCOM_PROVIDES_IFUNCTION 1
27 template <
typename Signature>
33 template <
typename ResultType,
typename ...Arguments>
40 virtual ResultType
operator()(Arguments... args)
const = 0;
46 template <
typename Signature>
52 template <
typename Signature>
58 template <
typename ResultType,
typename ...Arguments>
67 m_fnFunction(fnFunction)
78 ResultType operator()(Arguments... args)
const override
80 return m_fnFunction(std::forward<Arguments>(args)...);
84 std::function<ResultType(Arguments...)> m_fnFunction;
92 template <
typename Function>
93 struct function_traits :
public function_traits<decltype(&Function::operator())>
97 template <
typename ClassType,
typename ReturnType,
typename... Arguments>
98 struct function_traits<ReturnType(ClassType::*)(Arguments...) const>
100 using return_type = ReturnType;
102 template <std::
size_t Index>
103 using argument =
typename std::tuple_element<Index, std::tuple<Arguments...>>::type;
105 static constexpr std::size_t argument_count =
sizeof...(Arguments);
108 template <
typename ClassType,
typename ReturnType,
typename... Arguments>
109 struct function_traits<ReturnType(ClassType::*)(Arguments...)>
111 using return_type = ReturnType;
113 template <std::
size_t Index>
114 using argument =
typename std::tuple_element<Index, std::tuple<Arguments...>>::type;
116 static constexpr std::size_t argument_count =
sizeof...(Arguments);
119 template<
typename FunctionTraits,
typename Unused>
122 template<
typename FunctionTraits, std::size_t... Indices>
123 struct signature<FunctionTraits, std::index_sequence<Indices...>>
125 using type =
typename FunctionTraits::return_type(
typename FunctionTraits::template argument<Indices>...);
128 template<
typename Callable,
typename FunctionTraits = function_traits<std::remove_reference_t<Callable>>>
129 using signature_t =
typename signature<FunctionTraits, std::make_index_sequence<FunctionTraits::argument_count>>::type;
131 template <
typename Signature>
134 template <
typename ResultType,
typename ...Arguments>
135 class function_ptr<ResultType(Arguments...)>:
public object_ptr<ifunction<ResultType(Arguments...)>>
138 using base_type =
object_ptr<ifunction<ResultType(Arguments...)>>;
140 using base_type::base_type;
142 ResultType operator()(Arguments... args)
const
144 return (*this->Get())(std::forward<Arguments>(args)...);
158 template <
typename Callable,
typename Signature = detail::signature_t<Callable>>
170 template <
typename Callable,
typename Signature = detail::signature_t<Callable>>
173 return ant::make_object_ptr<function_wrapper<Signature>>(std::forward<Callable>(fnCallback));
181 template <
typename Signature>
184 return std::function<Signature>(std::ref(fnFunction));
192 template <
typename Signature>
195 return std::function<Signature>(detail::function_ptr<Signature>(pFunction));
200 using nitro::ifunction;
202 using nitro::function_wrapper;
Copyright © Audi Electronics Venture GmbH.
Base class for every interface type within the uCOM.
Base object pointer to realize binary compatible reference counting in interface methods.
Object pointer implementation used for reference counting on objects of type IObject.
Use this template if you want to implement an ucom::ant::IObject based Interface and/or subclass an e...
function_wrapper(std::function< ResultType(Arguments...)> fnFunction)
Constructor that initializes the object with the given function reference.
Implements iucom_function for the given signature.
virtual ResultType operator()(Arguments... args) const =0
The call operator which calls the referenced function.
Interface for functions that can be passed via IObject interfaces.
ant::object_ptr< ifunction< Signature > > make_function_ptr(Callable &&fnCallback)
creates an object_ptr shared pointer to an ucom_function pointing to the given callable.
function_wrapper< Signature > make_function(Callable &&fnCallback)
creates a ucom_function object for the given callable.
std::function< Signature > to_std_function(const ifunction< Signature > &fnFunction)
Helper conversion to a std::function object.
ant::iobject_ptr< ifunction< Signature > > ifunction_ptr
Interface for shared pointers to iucom_function.
ant::object_ptr< T > object_ptr
Alias always bringing the latest version of ant::object_ptr into scope.
Namespace for entire ADTF SDK.
Copyright © Audi Electronics Venture GmbH.
Copyright © Audi Electronics Venture GmbH.
Copyright © Audi Electronics Venture GmbH.