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_ObjectHandle_H
23 #define Menes_ObjectHandle_H
25 #include <CoreFoundation/CoreFoundation.h>
26 #include <Foundation/Foundation.h>
28 template <typename Type_
, unsigned Delegate_
>
29 struct MenesObjectHandle_
;
31 template <typename Type_
>
32 struct MenesObjectHandle_
<Type_
, 0> {
33 static _finline
void Execute(Type_
*value
) {
37 template <typename Type_
>
38 struct MenesObjectHandle_
<Type_
, 1> {
39 static _finline
void Execute(Type_
*value
) {
40 [value setDelegate
:nil
];
44 template <typename Type_
>
45 struct MenesObjectHandle_
<Type_
, 2> {
46 static _finline
void Execute(Type_
*value
) {
47 [value setDelegate
:nil
];
48 [value setDataSource
:nil
];
52 template <typename Type_
, unsigned Delegate_
= 0>
53 class MenesObjectHandle
{
57 _finline
void Retain_() {
59 CFRetain((CFTypeRef
) value_
);
62 _finline
void Release_(Type_
*value
) {
64 MenesObjectHandle_
<Type_
, Delegate_
>::Execute(value
);
65 CFRelease((CFTypeRef
) value
);
70 _finline
MenesObjectHandle(const MenesObjectHandle
&rhs
) :
71 value_(rhs
.value_
== nil
? nil
: (Type_
*) CFRetain((CFTypeRef
) rhs
.value_
))
75 _finline
MenesObjectHandle(Type_
*value
= NULL
, bool mended
= false) :
82 _finline
~MenesObjectHandle() {
86 _finline
operator Type_
*() const {
90 _finline Type_
*operator ->() const {
94 _finline MenesObjectHandle
&operator =(Type_
*value
) {
95 if (value_
!= value
) {
103 _finline MenesObjectHandle
&operator =(const MenesObjectHandle
&value
) {
104 return this->operator =(value
.operator Type_
*());
108 #define _H MenesObjectHandle
110 #define rproperty_(Class, field) \
111 - (typeof(((Class*)nil)->_##field.operator->())) field { \
115 #define wproperty_(Class, field, Field) \
116 - (void) set##Field:(typeof(((Class*)nil)->_##field.operator->()))field { \
120 #define roproperty(Class, field) \
121 @implementation Class (Menes_##field) \
122 rproperty_(Class, field) \
125 #define rwproperty(Class, field, Field) \
126 @implementation Class (Menes_##field) \
127 rproperty_(Class, field) \
128 wproperty_(Class, field, Field) \
131 // XXX: I hate clang. Apple: please get over your petty hatred of GPL and fix your gcc fork
132 #define synchronized(lock) \
133 synchronized(static_cast<NSObject *>(lock))
135 #endif//Menes_ObjectHandle_H