aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objc/utils
diff options
context:
space:
mode:
authorGravatar Hoa V. DINH <dinh.viet.hoa@gmail.com>2014-01-30 23:37:54 -0800
committerGravatar Hoa V. DINH <dinh.viet.hoa@gmail.com>2014-01-30 23:37:54 -0800
commit0f09edb01731f9ed0a9c5b6946e261322ad808fe (patch)
tree04d49575ea4be57c9c0218cef09678b8a97a3926 /src/objc/utils
parentfeb34ca2dee213eb430309ad2a770631f4fb4631 (diff)
Added Set to Obj-C bridging
Diffstat (limited to 'src/objc/utils')
-rw-r--r--src/objc/utils/NSObject+MCO.mm7
-rw-r--r--src/objc/utils/NSSet+MCO.h25
-rw-r--r--src/objc/utils/NSSet+MCO.mm45
3 files changed, 77 insertions, 0 deletions
diff --git a/src/objc/utils/NSObject+MCO.mm b/src/objc/utils/NSObject+MCO.mm
index 9c6f4fa7..4887080f 100644
--- a/src/objc/utils/NSObject+MCO.mm
+++ b/src/objc/utils/NSObject+MCO.mm
@@ -15,6 +15,7 @@
#import "NSDictionary+MCO.h"
#import "NSArray+MCO.h"
#import "NSValue+MCO.h"
+#import "NSSet+MCO.h"
#include "MCBaseTypes.h"
#include "MCUtils.h"
@@ -95,6 +96,9 @@ static Class classWithTypeInfo(const std::type_info * info)
else if (objectType == typeid(mailcore::Array).hash_code()) {
return [NSArray mco_arrayWithMCArray:(mailcore::Array *) object];
}
+ else if (objectType == typeid(mailcore::Set).hash_code()) {
+ return [NSSet mco_setWithMCSet:(mailcore::Set *) object];
+ }
else {
Class aClass = classWithTypeInfo(&typeid(* object));
MCAssert(aClass != nil);
@@ -124,6 +128,9 @@ static Class classWithTypeInfo(const std::type_info * info)
else if ([self isKindOfClass:[NSDictionary class]]) {
return [(NSDictionary *) self mco_mcHashMap];
}
+ else if ([self isKindOfClass:[NSSet class]]) {
+ return [(NSSet *) self mco_mcSet];
+ }
else {
MCAssert(0);
return nil;
diff --git a/src/objc/utils/NSSet+MCO.h b/src/objc/utils/NSSet+MCO.h
new file mode 100644
index 00000000..17bd1bf4
--- /dev/null
+++ b/src/objc/utils/NSSet+MCO.h
@@ -0,0 +1,25 @@
+//
+// NSSet+MCO.h
+// mailcore2
+//
+// Created by Hoa V. DINH on 1/29/14.
+// Copyright (c) 2014 MailCore. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+#ifdef __cplusplus
+namespace mailcore {
+ class Set;
+}
+#endif
+
+@interface NSSet (MCO)
+
+#ifdef __cplusplus
++ (NSSet *) mco_setWithMCSet:(mailcore::Set *)cppSet;
+
+- (mailcore::Set *) mco_mcSet;
+#endif
+
+@end
diff --git a/src/objc/utils/NSSet+MCO.mm b/src/objc/utils/NSSet+MCO.mm
new file mode 100644
index 00000000..690cfe77
--- /dev/null
+++ b/src/objc/utils/NSSet+MCO.mm
@@ -0,0 +1,45 @@
+//
+// NSSet+MCO.m
+// mailcore2
+//
+// Created by Hoa V. DINH on 1/29/14.
+// Copyright (c) 2014 MailCore. All rights reserved.
+//
+
+#import "NSSet+MCO.h"
+
+#include "MCSet.h"
+#include "MCArray.h"
+#import "NSObject+MCO.h"
+
+@implementation NSSet (MCO)
+
++ (id) mco_objectWithMCObject:(mailcore::Object *)object
+{
+ return [self mco_setWithMCSet:(mailcore::Set *) object];
+}
+
++ (NSSet *) mco_setWithMCSet:(mailcore::Set *)cppSet
+{
+ if (cppSet == NULL)
+ return nil;
+
+ NSMutableSet * result = [NSMutableSet set];
+ mailcore::Array * array = cppSet->allObjects();
+ for(unsigned int i = 0 ; i < array->count() ; i ++) {
+ [result addObject:[NSObject mco_objectWithMCObject:array->objectAtIndex(i)]];
+ }
+ return result;
+}
+
+- (mailcore::Set *) mco_mcSet
+{
+ mailcore::Set * result = mailcore::Set::set();
+ NSArray * array = [self allObjects];
+ for(unsigned int i = 0 ; i < [array count] ; i ++) {
+ result->addObject([[array objectAtIndex:i] mco_mcObject]);
+ }
+ return result;
+}
+
+@end