1 | /** @file
|
---|
2 | *
|
---|
3 | * VBoxCocoa Helper
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2009-2010 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifndef __VBoxCocoa_h__
|
---|
19 | #define __VBoxCocoa_h__
|
---|
20 |
|
---|
21 | /* Macro which add a typedef of the given Cocoa class in an appropriate form
|
---|
22 | * for the current context. This means void* in the C/CPP context and
|
---|
23 | * NSWhatever* in the ObjC/ObjCPP context. Use
|
---|
24 | * NativeNSWhateverRef/ConstNativeNSWhateverRef when you reference the Cocoa
|
---|
25 | * type somewhere. The use of this prevents extensive casting of void* to the
|
---|
26 | * right type in the Cocoa context. */
|
---|
27 | #ifdef __OBJC__
|
---|
28 | #define ADD_COCOA_NATIVE_REF(CocoaClass) \
|
---|
29 | @class CocoaClass; \
|
---|
30 | typedef CocoaClass *Native##CocoaClass##Ref; \
|
---|
31 | typedef const CocoaClass *ConstNative##CocoaClass##Ref
|
---|
32 | #else /* __OBJC__ */
|
---|
33 | #define ADD_COCOA_NATIVE_REF(CocoaClass) \
|
---|
34 | typedef void *Native##CocoaClass##Ref; \
|
---|
35 | typedef const void *ConstNative##CocoaClass##Ref
|
---|
36 | #endif /* __OBJC__ */
|
---|
37 |
|
---|
38 | /* Check for OBJC++ */
|
---|
39 | #if defined(__OBJC__) && defined (__cplusplus)
|
---|
40 |
|
---|
41 | /* Global includes */
|
---|
42 | #import <Foundation/NSAutoreleasePool.h>
|
---|
43 |
|
---|
44 | /* Helper class for automatic creation & destroying of a cocoa auto release
|
---|
45 | pool. */
|
---|
46 | class CocoaAutoreleasePool
|
---|
47 | {
|
---|
48 | public:
|
---|
49 | inline CocoaAutoreleasePool()
|
---|
50 | {
|
---|
51 | mPool = [[NSAutoreleasePool alloc] init];
|
---|
52 | }
|
---|
53 | inline ~CocoaAutoreleasePool()
|
---|
54 | {
|
---|
55 | [mPool release];
|
---|
56 | }
|
---|
57 |
|
---|
58 | private:
|
---|
59 | NSAutoreleasePool *mPool;
|
---|
60 | };
|
---|
61 |
|
---|
62 | #endif /* __OBJC__ */
|
---|
63 |
|
---|
64 | #endif /* __VBoxCocoa_h__ */
|
---|
65 |
|
---|