1 /* Cydia - iPhone UIKit Front-End for Debian APT
2 * Copyright (C) 2008-2012 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 "CyteKit/UCPlatform.h"
27 #include <CoreFoundation/CoreFoundation.h>
28 #include <Foundation/Foundation.h>
30 template <typename Type_
, unsigned Delegate_
>
31 struct MenesObjectHandle_
;
33 template <typename Type_
>
34 struct MenesObjectHandle_
<Type_
, 0> {
35 static _finline
void Execute(Type_
*value
) {
39 template <typename Type_
>
40 struct MenesObjectHandle_
<Type_
, 1> {
41 static _finline
void Execute(Type_
*value
) {
42 [value setDelegate
:nil
];
46 template <typename Type_
>
47 struct MenesObjectHandle_
<Type_
, 2> {
48 static _finline
void Execute(Type_
*value
) {
49 [value setDelegate
:nil
];
50 [value setDataSource
:nil
];
54 template <typename Type_
, unsigned Delegate_
= 0>
55 class MenesObjectHandle
{
59 _finline
void Retain_() {
61 CFRetain((CFTypeRef
) value_
);
64 _finline
void Release_(Type_
*value
) {
66 MenesObjectHandle_
<Type_
, Delegate_
>::Execute(value
);
67 CFRelease((CFTypeRef
) value
);
72 _finline
MenesObjectHandle(const MenesObjectHandle
&rhs
) :
73 value_(rhs
.value_
== nil
? nil
: (Type_
*) CFRetain((CFTypeRef
) rhs
.value_
))
77 _finline
MenesObjectHandle(Type_
*value
= NULL
, bool mended
= false) :
84 _finline
~MenesObjectHandle() {
88 _finline
operator Type_
*() const {
92 _finline Type_
*operator ->() const {
96 _finline MenesObjectHandle
&operator =(Type_
*value
) {
97 if (value_
!= value
) {
105 _finline MenesObjectHandle
&operator =(const MenesObjectHandle
&value
) {
106 return this->operator =(value
.operator Type_
*());
110 #define _H MenesObjectHandle
112 #define rproperty_(Class, field) \
113 - (typeof(((Class*)nil)->_##field.operator->())) field { \
117 #define wproperty_(Class, field, Field) \
118 - (void) set##Field:(typeof(((Class*)nil)->_##field.operator->()))field { \
122 #define roproperty(Class, field) \
123 @implementation Class (Menes_##field) \
124 rproperty_(Class, field) \
127 #define rwproperty(Class, field, Field) \
128 @implementation Class (Menes_##field) \
129 rproperty_(Class, field) \
130 wproperty_(Class, field, Field) \
133 #endif//Menes_ObjectHandle_H