aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objc/utils/NSObject+MCO.h
blob: 31818ce3fe82712e1fe35e1fa9a92ab7df8dba47 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//
//  NSObject+MCO.h
//  mailcore2
//
//  Created by DINH Viêt Hoà on 1/29/13.
//  Copyright (c) 2013 MailCore. All rights reserved.
//

#ifndef __MAILCORE_NSOBJECT_MCO_H_

#define __MAILCORE_NSOBJECT_MCO_H_

#import <Foundation/Foundation.h>

#ifdef __cplusplus
#include <typeinfo>
#endif

#ifdef __cplusplus
namespace mailcore {
    class Object;
}
#endif

#define MCO_NATIVE_INSTANCE ((nativeType *) [self mco_mcObject])

#define MCO_TO_OBJC(mcValue) \
    [NSObject mco_objectWithMCObject:((mailcore::Object *) (mcValue))]

#define MCO_FROM_OBJC(type, objcValue) \
    ((type *) [(objcValue) mco_mcObject])

#define MCO_OBJC_BRIDGE_SET(setter, mcValueType, objcValue) \
    MCO_NATIVE_INSTANCE->setter((mcValueType *) [(objcValue) mco_mcObject])

#define MCO_OBJC_BRIDGE_GET(getter) \
    [NSObject mco_objectWithMCObject:MCO_NATIVE_INSTANCE->getter()]

#define MCO_OBJC_SYNTHESIZE_TYPE(objcType, mcType, setter, getter) \
- (objcType *) getter \
{ \
return MCO_OBJC_BRIDGE_GET(getter); \
} \
\
- (void) setter:(objcType *)getter \
{ \
MCO_OBJC_BRIDGE_SET(setter, mcType, getter); \
}

#define MCO_OBJC_SYNTHESIZE(type, setter, getter) \
    MCO_OBJC_SYNTHESIZE_TYPE(MCO ## type, mailcore::type, setter, getter)

#define MCO_OBJC_SYNTHESIZE_SCALAR(objcType, mcType, setter, getter) \
- (objcType) getter \
{ \
return (objcType) MCO_NATIVE_INSTANCE->getter(); \
} \
\
- (void) setter:(objcType)getter \
{ \
MCO_NATIVE_INSTANCE->setter((mcType) getter); \
}

#define MCO_OBJC_SYNTHESIZE_STRING(setter, getter) MCO_OBJC_SYNTHESIZE_TYPE(NSString, mailcore::String, setter, getter)
#define MCO_OBJC_SYNTHESIZE_ARRAY(setter, getter) MCO_OBJC_SYNTHESIZE_TYPE(NSArray, mailcore::Array, setter, getter)
#define MCO_OBJC_SYNTHESIZE_DATA(setter, getter) MCO_OBJC_SYNTHESIZE_TYPE(NSData, mailcore::Data, setter, getter)
#define MCO_OBJC_SYNTHESIZE_HASHMAP(setter, getter) MCO_OBJC_SYNTHESIZE_TYPE(NSDictionary, mailcore::HashMap, setter, getter)
#define MCO_OBJC_SYNTHESIZE_BOOL(setter, getter) MCO_OBJC_SYNTHESIZE_SCALAR(BOOL, bool, setter, getter)

#define MCO_OBJC_SYNTHESIZE_DATE(setter, getter) \
- (NSDate *) getter \
{ \
    return [NSDate dateWithTimeIntervalSince1970:MCO_NATIVE_INSTANCE->getter()]; \
} \
\
- (void) setter:(NSDate *)getter \
{ \
    MCO_NATIVE_INSTANCE->setter([getter timeIntervalSince1970]); \
}

@interface NSObject (MCO)

#ifdef __cplusplus
+ (id) mco_objectWithMCObject:(mailcore::Object *)object;

- (mailcore::Object *) mco_mcObject;
#endif

@end

#ifdef __cplusplus
extern void MCORegisterClass(Class aClass, const std::type_info * info);
#endif

#endif