]>
git.saurik.com Git - cydia.git/blob - Menes/Function.h
1 /* Cydia - iPhone UIKit Front-End for Debian APT
2 * Copyright (C) 2008-2015 Jay Freeman (saurik)
5 /* GNU General Public License, Version 3 {{{ */
7 * Cydia is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published
9 * by the Free Software Foundation, either version 3 of the License,
10 * or (at your option) any later version.
12 * Cydia is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Cydia. If not, see <http://www.gnu.org/licenses/>.
22 #ifndef Menes_Function_H
23 #define Menes_Function_H
25 template <typename Result_
, typename
... Args_
>
38 Abstract(const Abstract
&) = delete;
39 Abstract
&operator =(const Abstract
&) = delete;
49 if (--references_
== 0)
53 virtual Result_
operator()(Args_
... args
) const = 0;
56 template <typename Callable_
>
64 Concrete(const Callable_
&callable
) :
69 virtual Result_
operator()(Args_
... args
) const {
70 return callable_(args
...);
78 if (abstract_
!= NULL
)
82 void Copy(Abstract
*abstract
) {
89 template <typename Callable_
>
90 void Assign(const Callable_
&callable
) {
91 Copy(new Concrete
<Callable_
>(callable
));
100 Function(decltype(nullptr)) :
105 Function(const Function
&function
) :
106 abstract_(function
.abstract_
)
111 template <typename Callable_
>
112 Function(const Callable_
&callable
) :
122 Function
&operator =(decltype(nullptr)) {
127 Function
&operator =(const Function
&function
) {
128 Copy(function
.abstract_
);
132 Result_
operator()(Args_
... args
) const {
133 return (*abstract_
)(args
...);
141 template <typename Callable_
>
142 Function
&operator =(const Callable_
&callable
) {
147 operator bool() const {
148 return abstract_
!= NULL
;
152 #endif//Menes_Function_H