Commit a659825a authored by Alan Rogers's avatar Alan Rogers Committed by Jacob Potter

Use immutable collection for Marshalling MList, MSet, and MMap to ObjectiveC

A previous solution to this was to simply return a `-copy`'ed version of the mutable collections we had constructed. But that comes with a slight cost.

This diff, makes use of `+[NSArray arrayWithObjects:count:]`, `+[NSSet setWithObjects:count:]` and `+[NSDictionary dictionaryWithObjects:forKeys:count:]` to construct the collections from `std::vector`s of the appropriate ObjC classes.

The only additional allocation we're doing now is of a single (2 for MMap) std::vector. We're also making use of `reserve()` to ensure we're not reallocating as the vectors are populated.
parent fa4a2ed4
...@@ -191,12 +191,12 @@ The available data types for a record are: ...@@ -191,12 +191,12 @@ The available data types for a record are:
- Strings (`string`) - Strings (`string`)
- Binary (`binary`). This is implemented as `std::vector<uint8_t>` in C++, `byte[]` in Java, - Binary (`binary`). This is implemented as `std::vector<uint8_t>` in C++, `byte[]` in Java,
and `NSData` in Objective-C. and `NSData` in Objective-C.
- List (`list<type>`). This is `vector<T>` in C++, `ArrayList` in Java, and `NSMutableArray` - List (`list<type>`). This is `vector<T>` in C++, `ArrayList` in Java, and `NSArray`
in Objective-C. Primitives in a list will be boxed in Java and Objective-C. in Objective-C. Primitives in a list will be boxed in Java and Objective-C.
- Set (`set<type>`). This is `set<T>` in C++, `TreeSet` in Java, and `NSMutableSet` in - Set (`set<type>`). This is `set<T>` in C++, `TreeSet` in Java, and `NSSet` in
Objective-C. Primitives in a set will be boxed in Java and Objective-C. Objective-C. Primitives in a set will be boxed in Java and Objective-C.
- Map (`map<typeA, typeB>`). This is `unordered_map<K, V>` in C++, `HashMap` in Java, and - Map (`map<typeA, typeB>`). This is `unordered_map<K, V>` in C++, `HashMap` in Java, and
`NSMutableDictionary` in Objective-C. Primitives in a map will be boxed in Java and Objective-C. `NSDictionary` in Objective-C. Primitives in a map will be boxed in Java and Objective-C.
- Enumerations - Enumerations
- Optionals (`optional<typeA>`). This is `std::experimental::optional<T>` in C++11, object / - Optionals (`optional<typeA>`). This is `std::experimental::optional<T>` in C++11, object /
boxed primitive reference in Java (which can be `null`), and object / NSNumber strong boxed primitive reference in Java (which can be `null`), and object / NSNumber strong
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#import "DJIDate.h" #import "DJIDate.h"
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#include <utility> #include <utility>
#include <vector>
static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file");
...@@ -13,13 +14,14 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th ...@@ -13,13 +14,14 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th
- (id)initWithItemList:(TXSItemList *)itemList - (id)initWithItemList:(TXSItemList *)itemList
{ {
if (self = [super init]) { if (self = [super init]) {
NSMutableArray *_itemsTempArray = [NSMutableArray arrayWithCapacity:[itemList.items count]]; std::vector<NSString *> _itemsTempVector;
_itemsTempVector.reserve([itemList.items count]);
for (NSString *currentValue_0 in itemList.items) { for (NSString *currentValue_0 in itemList.items) {
id copiedValue_0; NSString *copiedValue_0;
copiedValue_0 = [currentValue_0 copy]; copiedValue_0 = [currentValue_0 copy];
[_itemsTempArray addObject:copiedValue_0]; _itemsTempVector.push_back(copiedValue_0);
} }
_items = _itemsTempArray; _items = [NSArray arrayWithObjects:&_itemsTempVector[0] count:_itemsTempVector.size()];
} }
return self; return self;
} }
...@@ -35,14 +37,15 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th ...@@ -35,14 +37,15 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th
- (id)initWithCppItemList:(const ::textsort::ItemList &)itemList - (id)initWithCppItemList:(const ::textsort::ItemList &)itemList
{ {
if (self = [super init]) { if (self = [super init]) {
NSMutableArray *_itemsTempArray = [NSMutableArray arrayWithCapacity:itemList.items.size()]; std::vector<NSString *> _itemsTempVector;
_itemsTempVector.reserve(itemList.items.size());
for (const auto & cppValue_0 : itemList.items) { for (const auto & cppValue_0 : itemList.items) {
NSString *objcValue_0 = [[NSString alloc] initWithBytes:cppValue_0.data() NSString *objcValue_0 = [[NSString alloc] initWithBytes:cppValue_0.data()
length:cppValue_0.length() length:cppValue_0.length()
encoding:NSUTF8StringEncoding]; encoding:NSUTF8StringEncoding];
[_itemsTempArray addObject:objcValue_0]; _itemsTempVector.push_back(objcValue_0);
} }
_items = _itemsTempArray; _items = [NSArray arrayWithObjects:&_itemsTempVector[0] count:_itemsTempVector.size()];
} }
return self; return self;
} }
......
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
- (IBAction)sort:(id)sender - (IBAction)sort:(id)sender
{ {
NSString *str = self.textView.text; NSString *str = self.textView.text;
NSMutableArray *strList = [NSMutableArray arrayWithArray:[str componentsSeparatedByString:@"\n"]]; NSArray *strList = [str componentsSeparatedByString:@"\n"];
TXSItemList *list = [[TXSItemList alloc] initWithItems:strList]; TXSItemList *list = [[TXSItemList alloc] initWithItems:strList];
[_sortItemInterface sort:TXSSortOrderAscending items:list]; [_sortItemInterface sort:TXSSortOrderAscending items:list];
} }
......
...@@ -402,6 +402,7 @@ class ObjcGenerator(spec: Spec) extends Generator(spec) { ...@@ -402,6 +402,7 @@ class ObjcGenerator(spec: Spec) extends Generator(spec) {
refs.body.add("#import <Foundation/Foundation.h>") refs.body.add("#import <Foundation/Foundation.h>")
refs.body.add("#include <utility>") refs.body.add("#include <utility>")
refs.body.add("#include <vector>")
refs.body.add("!#import " + q(privateHeaderName(objcName))) refs.body.add("!#import " + q(privateHeaderName(objcName)))
refs.body.add("#import " + q("DJIDate.h")) refs.body.add("#import " + q("DJIDate.h"))
...@@ -644,39 +645,45 @@ class ObjcGenerator(spec: Spec) extends Generator(spec) { ...@@ -644,39 +645,45 @@ class ObjcGenerator(spec: Spec) extends Generator(spec) {
case MList => { case MList => {
val copyName = "copiedValue_" + valueLevel val copyName = "copiedValue_" + valueLevel
val currentName = "currentValue_" + valueLevel val currentName = "currentValue_" + valueLevel
w.wl(s"NSMutableArray *${to}TempArray = [NSMutableArray arrayWithCapacity:[$from count]];") w.wl(s"std::vector<${toObjcTypeDef(tm.args.head, true)}> ${to}TempVector;")
w.wl(s"${to}TempVector.reserve([$from count]);")
w.w(s"for (${toObjcTypeDef(tm.args.head, true)}$currentName in $from)").braced { w.w(s"for (${toObjcTypeDef(tm.args.head, true)}$currentName in $from)").braced {
w.wl(s"id $copyName;") w.wl(s"${toObjcTypeDef(tm.args.head, true)}$copyName;")
f(copyName, currentName, tm.args.head, true, w, valueLevel + 1) f(copyName, currentName, tm.args.head, true, w, valueLevel + 1)
w.wl(s"[${to}TempArray addObject:$copyName];") w.wl(s"${to}TempVector.push_back($copyName);")
} }
w.wl(s"$to = ${to}TempArray;") w.wl(s"$to = [NSArray arrayWithObjects:&${to}TempVector[0] count:${to}TempVector.size()];")
} }
case MSet => { case MSet => {
val copyName = "copiedValue_" + valueLevel val copyName = "copiedValue_" + valueLevel
val currentName = "currentValue_" + valueLevel val currentName = "currentValue_" + valueLevel
w.wl(s"NSMutableSet *${to}TempSet = [NSMutableSet setWithCapacity:[$from count]];") w.wl(s"std::vector<${toObjcTypeDef(tm.args.head, true)}> ${to}TempVector;")
w.wl(s"${to}TempVector.reserve([$from count]);")
w.w(s"for (${toObjcTypeDef(tm.args.head, true)}$currentName in $from)").braced { w.w(s"for (${toObjcTypeDef(tm.args.head, true)}$currentName in $from)").braced {
w.wl(s"id $copyName;") w.wl(s"${toObjcTypeDef(tm.args.head, true)}$copyName;")
f(copyName, currentName, tm.args.head, true, w, valueLevel + 1) f(copyName, currentName, tm.args.head, true, w, valueLevel + 1)
w.wl(s"[${to}TempSet addObject:$copyName];") w.wl(s"${to}TempVector.push_back($copyName);")
} }
w.wl(s"$to = ${to}TempSet;") w.wl(s"$to = [NSSet setWithObjects:&${to}TempVector[0] count:${to}TempVector.size()];")
} }
case MMap => { case MMap => {
w.wl(s"NSMutableDictionary *${to}TempDictionary = [NSMutableDictionary dictionaryWithCapacity:[$from count]];") val keyType = toObjcTypeDef(tm.args.apply(0), true)
val valueType = toObjcTypeDef(tm.args.apply(1), true)
w.wl(s"std::vector<$keyType> ${to}TempKeyVector;")
w.wl(s"${to}TempKeyVector.reserve([$from count]);")
w.wl(s"std::vector<$valueType> ${to}TempValueVector;")
w.wl(s"${to}TempValueVector.reserve([$from count]);")
val keyName = "key_" + valueLevel val keyName = "key_" + valueLevel
val valueName = "value_" + valueLevel val valueName = "value_" + valueLevel
val copiedKeyName = "copiedKey_" + valueLevel
val copiedValueName = "copiedValue_" + valueLevel val copiedValueName = "copiedValue_" + valueLevel
w.w(s"for (id $keyName in $from)").braced { w.w(s"for ($keyType$keyName in $from)").braced {
w.wl(s"id $copiedKeyName, $copiedValueName;") w.wl(s"$valueType$copiedValueName;")
f(copiedKeyName, keyName, tm.args.apply(0), true, w, valueLevel + 1) w.wl(s"${to}TempKeyVector.push_back($keyName);")
w.wl(s"id $valueName = [$from objectForKey:$keyName];") w.wl(s"$valueType$valueName = [$from objectForKey:$keyName];")
f(copiedValueName, valueName, tm.args.apply(1), true, w, valueLevel + 1) f(copiedValueName, valueName, tm.args.apply(1), true, w, valueLevel + 1)
w.wl(s"[${to}TempDictionary setObject:$copiedValueName forKey:$copiedKeyName];") w.wl(s"${to}TempValueVector.push_back($copiedValueName);")
} }
w.wl(s"$to = ${to}TempDictionary;") w.wl(s"$to = [NSDictionary dictionaryWithObjects:&${to}TempValueVector[0] forKeys:&${to}TempKeyVector[0] count:[$from count]];")
} }
case d: MDef => { case d: MDef => {
val typeName = d.name val typeName = d.name
...@@ -748,34 +755,40 @@ class ObjcGenerator(spec: Spec) extends Generator(spec) { ...@@ -748,34 +755,40 @@ class ObjcGenerator(spec: Spec) extends Generator(spec) {
case MList => case MList =>
val objcName = "objcValue_" + valueLevel val objcName = "objcValue_" + valueLevel
val cppName = "cppValue_" + valueLevel val cppName = "cppValue_" + valueLevel
w.wl(s"NSMutableArray *${objcIdent}TempArray = [NSMutableArray arrayWithCapacity:${cppIdent}.size()];") w.wl(s"std::vector<${toObjcTypeDef(tm.args.head, true)}> ${objcIdent}TempVector;")
w.wl(s"${objcIdent}TempVector.reserve(${cppIdent}.size());")
w.w(s"for (const auto & $cppName : ${cppIdent})") w.w(s"for (const auto & $cppName : ${cppIdent})")
w.braced { w.braced {
f(objcName, cppName, tm.args.head, true, true, w, valueLevel + 1) f(objcName, cppName, tm.args.head, true, true, w, valueLevel + 1)
w.wl(s"[${objcIdent}TempArray addObject:$objcName];") w.wl(s"${objcIdent}TempVector.push_back($objcName);")
} }
w.wl(s"$objcType$objcIdent = ${objcIdent}TempArray;") w.wl(s"$objcType$objcIdent = [NSArray arrayWithObjects:&${objcIdent}TempVector[0] count:${objcIdent}TempVector.size()];")
case MSet => case MSet =>
val objcName = "objcValue_" + valueLevel val objcName = "objcValue_" + valueLevel
val cppName = "cppValue_" + valueLevel val cppName = "cppValue_" + valueLevel
w.wl(s"NSMutableSet *${objcIdent}TempSet = [NSMutableSet setWithCapacity:${cppIdent}.size()];") w.wl(s"std::vector<${toObjcTypeDef(tm.args.head, true)}> ${objcIdent}TempVector;")
w.wl(s"${objcIdent}TempVector.reserve(${cppIdent}.size());")
w.w(s"for (const auto & $cppName : ${cppIdent})") w.w(s"for (const auto & $cppName : ${cppIdent})")
w.braced { w.braced {
f(objcName, cppName, tm.args.head, true, true, w, valueLevel + 1) f(objcName, cppName, tm.args.head, true, true, w, valueLevel + 1)
w.wl(s"[${objcIdent}TempSet addObject:$objcName];") w.wl(s"${objcIdent}TempVector.push_back($objcName);")
} }
w.wl(s"$objcType$objcIdent = ${objcIdent}TempSet;") w.wl(s"$objcType$objcIdent = [NSSet setWithObjects:&${objcIdent}TempVector[0] count:${objcIdent}TempVector.size()];")
case MMap => { case MMap => {
val cppPairName = "cppPair_" + valueLevel val cppPairName = "cppPair_" + valueLevel
val objcKeyName = "objcKey_" + valueLevel val objcKeyName = "objcKey_" + valueLevel
val objcValueName = "objcValue_" + valueLevel val objcValueName = "objcValue_" + valueLevel
w.wl(s"NSMutableDictionary *${objcIdent}TempDictionary = [NSMutableDictionary dictionaryWithCapacity:${cppIdent}.size()];") w.wl(s"std::vector<${toObjcTypeDef(tm.args.apply(0), true)}> ${objcIdent}TempKeyVector;")
w.wl(s"${objcIdent}TempKeyVector.reserve(${cppIdent}.size());")
w.wl(s"std::vector<${toObjcTypeDef(tm.args.apply(1), true)}> ${objcIdent}TempValueVector;")
w.wl(s"${objcIdent}TempValueVector.reserve(${cppIdent}.size());")
w.w(s"for (const auto & $cppPairName : ${cppIdent})").braced { w.w(s"for (const auto & $cppPairName : ${cppIdent})").braced {
f(objcKeyName, cppPairName + ".first", tm.args.apply(0), true, true, w, valueLevel + 1) f(objcKeyName, cppPairName + ".first", tm.args.apply(0), true, true, w, valueLevel + 1)
f(objcValueName, cppPairName + ".second", tm.args.apply(1), true, true, w, valueLevel + 1) f(objcValueName, cppPairName + ".second", tm.args.apply(1), true, true, w, valueLevel + 1)
w.wl(s"[${objcIdent}TempDictionary setObject:$objcValueName forKey:$objcKeyName];") w.wl(s"${objcIdent}TempKeyVector.push_back($objcKeyName);")
w.wl(s"${objcIdent}TempValueVector.push_back($objcValueName);")
} }
w.wl(s"$objcType$objcIdent = ${objcIdent}TempDictionary;") w.wl(s"$objcType$objcIdent = [NSDictionary dictionaryWithObjects:&${objcIdent}TempValueVector[0] forKeys:&${objcIdent}TempKeyVector[0] count:${cppIdent}.size()];")
} }
case d: MDef => { case d: MDef => {
val typeName = d.name val typeName = d.name
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#import "DJIDate.h" #import "DJIDate.h"
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#include <utility> #include <utility>
#include <vector>
static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file");
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#import "DJIDate.h" #import "DJIDate.h"
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#include <utility> #include <utility>
#include <vector>
static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file");
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#import "DJIDate.h" #import "DJIDate.h"
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#include <utility> #include <utility>
#include <vector>
#pragma clang diagnostic push #pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-variable" #pragma clang diagnostic ignored "-Wunused-variable"
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#import "DJIDate.h" #import "DJIDate.h"
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#include <utility> #include <utility>
#include <vector>
static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file");
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#import "DJIDate.h" #import "DJIDate.h"
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#include <utility> #include <utility>
#include <vector>
static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file");
...@@ -13,15 +14,18 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th ...@@ -13,15 +14,18 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th
- (id)initWithMapDateRecord:(DBMapDateRecord *)mapDateRecord - (id)initWithMapDateRecord:(DBMapDateRecord *)mapDateRecord
{ {
if (self = [super init]) { if (self = [super init]) {
NSMutableDictionary *_datesByIdTempDictionary = [NSMutableDictionary dictionaryWithCapacity:[mapDateRecord.datesById count]]; std::vector<NSString *> _datesByIdTempKeyVector;
for (id key_0 in mapDateRecord.datesById) { _datesByIdTempKeyVector.reserve([mapDateRecord.datesById count]);
id copiedKey_0, copiedValue_0; std::vector<NSDate *> _datesByIdTempValueVector;
copiedKey_0 = [key_0 copy]; _datesByIdTempValueVector.reserve([mapDateRecord.datesById count]);
id value_0 = [mapDateRecord.datesById objectForKey:key_0]; for (NSString *key_0 in mapDateRecord.datesById) {
NSDate *copiedValue_0;
_datesByIdTempKeyVector.push_back(key_0);
NSDate *value_0 = [mapDateRecord.datesById objectForKey:key_0];
copiedValue_0 = [value_0 copy]; copiedValue_0 = [value_0 copy];
[_datesByIdTempDictionary setObject:copiedValue_0 forKey:copiedKey_0]; _datesByIdTempValueVector.push_back(copiedValue_0);
} }
_datesById = _datesByIdTempDictionary; _datesById = [NSDictionary dictionaryWithObjects:&_datesByIdTempValueVector[0] forKeys:&_datesByIdTempKeyVector[0] count:[mapDateRecord.datesById count]];
} }
return self; return self;
} }
...@@ -37,16 +41,20 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th ...@@ -37,16 +41,20 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th
- (id)initWithCppMapDateRecord:(const MapDateRecord &)mapDateRecord - (id)initWithCppMapDateRecord:(const MapDateRecord &)mapDateRecord
{ {
if (self = [super init]) { if (self = [super init]) {
NSMutableDictionary *_datesByIdTempDictionary = [NSMutableDictionary dictionaryWithCapacity:mapDateRecord.dates_by_id.size()]; std::vector<NSString *> _datesByIdTempKeyVector;
_datesByIdTempKeyVector.reserve(mapDateRecord.dates_by_id.size());
std::vector<NSDate *> _datesByIdTempValueVector;
_datesByIdTempValueVector.reserve(mapDateRecord.dates_by_id.size());
for (const auto & cppPair_0 : mapDateRecord.dates_by_id) { for (const auto & cppPair_0 : mapDateRecord.dates_by_id) {
NSString *objcKey_0 = [[NSString alloc] initWithBytes:cppPair_0.first.data() NSString *objcKey_0 = [[NSString alloc] initWithBytes:cppPair_0.first.data()
length:cppPair_0.first.length() length:cppPair_0.first.length()
encoding:NSUTF8StringEncoding]; encoding:NSUTF8StringEncoding];
NSDate *objcValue_0 = [NSDate dateWithTimeIntervalSince1970: NSDate *objcValue_0 = [NSDate dateWithTimeIntervalSince1970:
std::chrono::duration_cast<std::chrono::duration<double>>(cppPair_0.second.time_since_epoch()).count()]; std::chrono::duration_cast<std::chrono::duration<double>>(cppPair_0.second.time_since_epoch()).count()];
[_datesByIdTempDictionary setObject:objcValue_0 forKey:objcKey_0]; _datesByIdTempKeyVector.push_back(objcKey_0);
_datesByIdTempValueVector.push_back(objcValue_0);
} }
_datesById = _datesByIdTempDictionary; _datesById = [NSDictionary dictionaryWithObjects:&_datesByIdTempValueVector[0] forKeys:&_datesByIdTempKeyVector[0] count:mapDateRecord.dates_by_id.size()];
} }
return self; return self;
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#import "DJIDate.h" #import "DJIDate.h"
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#include <utility> #include <utility>
#include <vector>
static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file");
...@@ -13,21 +14,25 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th ...@@ -13,21 +14,25 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th
- (id)initWithMapListRecord:(DBMapListRecord *)mapListRecord - (id)initWithMapListRecord:(DBMapListRecord *)mapListRecord
{ {
if (self = [super init]) { if (self = [super init]) {
NSMutableArray *_mapListTempArray = [NSMutableArray arrayWithCapacity:[mapListRecord.mapList count]]; std::vector<NSDictionary *> _mapListTempVector;
_mapListTempVector.reserve([mapListRecord.mapList count]);
for (NSDictionary *currentValue_0 in mapListRecord.mapList) { for (NSDictionary *currentValue_0 in mapListRecord.mapList) {
id copiedValue_0; NSDictionary *copiedValue_0;
NSMutableDictionary *copiedValue_0TempDictionary = [NSMutableDictionary dictionaryWithCapacity:[currentValue_0 count]]; std::vector<NSString *> copiedValue_0TempKeyVector;
for (id key_1 in currentValue_0) { copiedValue_0TempKeyVector.reserve([currentValue_0 count]);
id copiedKey_1, copiedValue_1; std::vector<NSNumber *> copiedValue_0TempValueVector;
copiedKey_1 = [key_1 copy]; copiedValue_0TempValueVector.reserve([currentValue_0 count]);
id value_1 = [currentValue_0 objectForKey:key_1]; for (NSString *key_1 in currentValue_0) {
NSNumber *copiedValue_1;
copiedValue_0TempKeyVector.push_back(key_1);
NSNumber *value_1 = [currentValue_0 objectForKey:key_1];
copiedValue_1 = value_1; copiedValue_1 = value_1;
[copiedValue_0TempDictionary setObject:copiedValue_1 forKey:copiedKey_1]; copiedValue_0TempValueVector.push_back(copiedValue_1);
} }
copiedValue_0 = copiedValue_0TempDictionary; copiedValue_0 = [NSDictionary dictionaryWithObjects:&copiedValue_0TempValueVector[0] forKeys:&copiedValue_0TempKeyVector[0] count:[currentValue_0 count]];
[_mapListTempArray addObject:copiedValue_0]; _mapListTempVector.push_back(copiedValue_0);
} }
_mapList = _mapListTempArray; _mapList = [NSArray arrayWithObjects:&_mapListTempVector[0] count:_mapListTempVector.size()];
} }
return self; return self;
} }
...@@ -43,20 +48,25 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th ...@@ -43,20 +48,25 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th
- (id)initWithCppMapListRecord:(const MapListRecord &)mapListRecord - (id)initWithCppMapListRecord:(const MapListRecord &)mapListRecord
{ {
if (self = [super init]) { if (self = [super init]) {
NSMutableArray *_mapListTempArray = [NSMutableArray arrayWithCapacity:mapListRecord.map_list.size()]; std::vector<NSDictionary *> _mapListTempVector;
_mapListTempVector.reserve(mapListRecord.map_list.size());
for (const auto & cppValue_0 : mapListRecord.map_list) { for (const auto & cppValue_0 : mapListRecord.map_list) {
NSMutableDictionary *objcValue_0TempDictionary = [NSMutableDictionary dictionaryWithCapacity:cppValue_0.size()]; std::vector<NSString *> objcValue_0TempKeyVector;
objcValue_0TempKeyVector.reserve(cppValue_0.size());
std::vector<NSNumber *> objcValue_0TempValueVector;
objcValue_0TempValueVector.reserve(cppValue_0.size());
for (const auto & cppPair_1 : cppValue_0) { for (const auto & cppPair_1 : cppValue_0) {
NSString *objcKey_1 = [[NSString alloc] initWithBytes:cppPair_1.first.data() NSString *objcKey_1 = [[NSString alloc] initWithBytes:cppPair_1.first.data()
length:cppPair_1.first.length() length:cppPair_1.first.length()
encoding:NSUTF8StringEncoding]; encoding:NSUTF8StringEncoding];
NSNumber *objcValue_1 = [NSNumber numberWithLongLong:cppPair_1.second]; NSNumber *objcValue_1 = [NSNumber numberWithLongLong:cppPair_1.second];
[objcValue_0TempDictionary setObject:objcValue_1 forKey:objcKey_1]; objcValue_0TempKeyVector.push_back(objcKey_1);
objcValue_0TempValueVector.push_back(objcValue_1);
} }
NSDictionary *objcValue_0 = objcValue_0TempDictionary; NSDictionary *objcValue_0 = [NSDictionary dictionaryWithObjects:&objcValue_0TempValueVector[0] forKeys:&objcValue_0TempKeyVector[0] count:cppValue_0.size()];
[_mapListTempArray addObject:objcValue_0]; _mapListTempVector.push_back(objcValue_0);
} }
_mapList = _mapListTempArray; _mapList = [NSArray arrayWithObjects:&_mapListTempVector[0] count:_mapListTempVector.size()];
} }
return self; return self;
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#import "DJIDate.h" #import "DJIDate.h"
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#include <utility> #include <utility>
#include <vector>
static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file");
...@@ -13,15 +14,18 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th ...@@ -13,15 +14,18 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th
- (id)initWithMapRecord:(DBMapRecord *)mapRecord - (id)initWithMapRecord:(DBMapRecord *)mapRecord
{ {
if (self = [super init]) { if (self = [super init]) {
NSMutableDictionary *_mapTempDictionary = [NSMutableDictionary dictionaryWithCapacity:[mapRecord.map count]]; std::vector<NSString *> _mapTempKeyVector;
for (id key_0 in mapRecord.map) { _mapTempKeyVector.reserve([mapRecord.map count]);
id copiedKey_0, copiedValue_0; std::vector<NSNumber *> _mapTempValueVector;
copiedKey_0 = [key_0 copy]; _mapTempValueVector.reserve([mapRecord.map count]);
id value_0 = [mapRecord.map objectForKey:key_0]; for (NSString *key_0 in mapRecord.map) {
NSNumber *copiedValue_0;
_mapTempKeyVector.push_back(key_0);
NSNumber *value_0 = [mapRecord.map objectForKey:key_0];
copiedValue_0 = value_0; copiedValue_0 = value_0;
[_mapTempDictionary setObject:copiedValue_0 forKey:copiedKey_0]; _mapTempValueVector.push_back(copiedValue_0);
} }
_map = _mapTempDictionary; _map = [NSDictionary dictionaryWithObjects:&_mapTempValueVector[0] forKeys:&_mapTempKeyVector[0] count:[mapRecord.map count]];
} }
return self; return self;
} }
...@@ -37,15 +41,19 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th ...@@ -37,15 +41,19 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th
- (id)initWithCppMapRecord:(const MapRecord &)mapRecord - (id)initWithCppMapRecord:(const MapRecord &)mapRecord
{ {
if (self = [super init]) { if (self = [super init]) {
NSMutableDictionary *_mapTempDictionary = [NSMutableDictionary dictionaryWithCapacity:mapRecord.map.size()]; std::vector<NSString *> _mapTempKeyVector;
_mapTempKeyVector.reserve(mapRecord.map.size());
std::vector<NSNumber *> _mapTempValueVector;
_mapTempValueVector.reserve(mapRecord.map.size());
for (const auto & cppPair_0 : mapRecord.map) { for (const auto & cppPair_0 : mapRecord.map) {
NSString *objcKey_0 = [[NSString alloc] initWithBytes:cppPair_0.first.data() NSString *objcKey_0 = [[NSString alloc] initWithBytes:cppPair_0.first.data()
length:cppPair_0.first.length() length:cppPair_0.first.length()
encoding:NSUTF8StringEncoding]; encoding:NSUTF8StringEncoding];
NSNumber *objcValue_0 = [NSNumber numberWithLongLong:cppPair_0.second]; NSNumber *objcValue_0 = [NSNumber numberWithLongLong:cppPair_0.second];
[_mapTempDictionary setObject:objcValue_0 forKey:objcKey_0]; _mapTempKeyVector.push_back(objcKey_0);
_mapTempValueVector.push_back(objcValue_0);
} }
_map = _mapTempDictionary; _map = [NSDictionary dictionaryWithObjects:&_mapTempValueVector[0] forKeys:&_mapTempKeyVector[0] count:mapRecord.map.size()];
} }
return self; return self;
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#import "DJIDate.h" #import "DJIDate.h"
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#include <utility> #include <utility>
#include <vector>
static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file");
...@@ -13,19 +14,21 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th ...@@ -13,19 +14,21 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th
- (id)initWithNestedCollection:(DBNestedCollection *)nestedCollection - (id)initWithNestedCollection:(DBNestedCollection *)nestedCollection
{ {
if (self = [super init]) { if (self = [super init]) {
NSMutableArray *_setListTempArray = [NSMutableArray arrayWithCapacity:[nestedCollection.setList count]]; std::vector<NSSet *> _setListTempVector;
_setListTempVector.reserve([nestedCollection.setList count]);
for (NSSet *currentValue_0 in nestedCollection.setList) { for (NSSet *currentValue_0 in nestedCollection.setList) {
id copiedValue_0; NSSet *copiedValue_0;
NSMutableSet *copiedValue_0TempSet = [NSMutableSet setWithCapacity:[currentValue_0 count]]; std::vector<NSString *> copiedValue_0TempVector;
copiedValue_0TempVector.reserve([currentValue_0 count]);
for (NSString *currentValue_1 in currentValue_0) { for (NSString *currentValue_1 in currentValue_0) {
id copiedValue_1; NSString *copiedValue_1;
copiedValue_1 = [currentValue_1 copy]; copiedValue_1 = [currentValue_1 copy];
[copiedValue_0TempSet addObject:copiedValue_1]; copiedValue_0TempVector.push_back(copiedValue_1);
} }
copiedValue_0 = copiedValue_0TempSet; copiedValue_0 = [NSSet setWithObjects:&copiedValue_0TempVector[0] count:copiedValue_0TempVector.size()];
[_setListTempArray addObject:copiedValue_0]; _setListTempVector.push_back(copiedValue_0);
} }
_setList = _setListTempArray; _setList = [NSArray arrayWithObjects:&_setListTempVector[0] count:_setListTempVector.size()];
} }
return self; return self;
} }
...@@ -41,19 +44,21 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th ...@@ -41,19 +44,21 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th
- (id)initWithCppNestedCollection:(const NestedCollection &)nestedCollection - (id)initWithCppNestedCollection:(const NestedCollection &)nestedCollection
{ {
if (self = [super init]) { if (self = [super init]) {
NSMutableArray *_setListTempArray = [NSMutableArray arrayWithCapacity:nestedCollection.set_list.size()]; std::vector<NSSet *> _setListTempVector;
_setListTempVector.reserve(nestedCollection.set_list.size());
for (const auto & cppValue_0 : nestedCollection.set_list) { for (const auto & cppValue_0 : nestedCollection.set_list) {
NSMutableSet *objcValue_0TempSet = [NSMutableSet setWithCapacity:cppValue_0.size()]; std::vector<NSString *> objcValue_0TempVector;
objcValue_0TempVector.reserve(cppValue_0.size());
for (const auto & cppValue_1 : cppValue_0) { for (const auto & cppValue_1 : cppValue_0) {
NSString *objcValue_1 = [[NSString alloc] initWithBytes:cppValue_1.data() NSString *objcValue_1 = [[NSString alloc] initWithBytes:cppValue_1.data()
length:cppValue_1.length() length:cppValue_1.length()
encoding:NSUTF8StringEncoding]; encoding:NSUTF8StringEncoding];
[objcValue_0TempSet addObject:objcValue_1]; objcValue_0TempVector.push_back(objcValue_1);
} }
NSSet *objcValue_0 = objcValue_0TempSet; NSSet *objcValue_0 = [NSSet setWithObjects:&objcValue_0TempVector[0] count:objcValue_0TempVector.size()];
[_setListTempArray addObject:objcValue_0]; _setListTempVector.push_back(objcValue_0);
} }
_setList = _setListTempArray; _setList = [NSArray arrayWithObjects:&_setListTempVector[0] count:_setListTempVector.size()];
} }
return self; return self;
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#import "DJIDate.h" #import "DJIDate.h"
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#include <utility> #include <utility>
#include <vector>
static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file");
...@@ -13,13 +14,14 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th ...@@ -13,13 +14,14 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th
- (id)initWithPrimitiveList:(DBPrimitiveList *)primitiveList - (id)initWithPrimitiveList:(DBPrimitiveList *)primitiveList
{ {
if (self = [super init]) { if (self = [super init]) {
NSMutableArray *_listTempArray = [NSMutableArray arrayWithCapacity:[primitiveList.list count]]; std::vector<NSNumber *> _listTempVector;
_listTempVector.reserve([primitiveList.list count]);
for (NSNumber *currentValue_0 in primitiveList.list) { for (NSNumber *currentValue_0 in primitiveList.list) {
id copiedValue_0; NSNumber *copiedValue_0;
copiedValue_0 = currentValue_0; copiedValue_0 = currentValue_0;
[_listTempArray addObject:copiedValue_0]; _listTempVector.push_back(copiedValue_0);
} }
_list = _listTempArray; _list = [NSArray arrayWithObjects:&_listTempVector[0] count:_listTempVector.size()];
} }
return self; return self;
} }
...@@ -35,12 +37,13 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th ...@@ -35,12 +37,13 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th
- (id)initWithCppPrimitiveList:(const PrimitiveList &)primitiveList - (id)initWithCppPrimitiveList:(const PrimitiveList &)primitiveList
{ {
if (self = [super init]) { if (self = [super init]) {
NSMutableArray *_listTempArray = [NSMutableArray arrayWithCapacity:primitiveList.list.size()]; std::vector<NSNumber *> _listTempVector;
_listTempVector.reserve(primitiveList.list.size());
for (const auto & cppValue_0 : primitiveList.list) { for (const auto & cppValue_0 : primitiveList.list) {
NSNumber *objcValue_0 = [NSNumber numberWithLongLong:cppValue_0]; NSNumber *objcValue_0 = [NSNumber numberWithLongLong:cppValue_0];
[_listTempArray addObject:objcValue_0]; _listTempVector.push_back(objcValue_0);
} }
_list = _listTempArray; _list = [NSArray arrayWithObjects:&_listTempVector[0] count:_listTempVector.size()];
} }
return self; return self;
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#import "DJIDate.h" #import "DJIDate.h"
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#include <utility> #include <utility>
#include <vector>
static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file");
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#import "DJIDate.h" #import "DJIDate.h"
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#include <utility> #include <utility>
#include <vector>
static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file");
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#import "DJIDate.h" #import "DJIDate.h"
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#include <utility> #include <utility>
#include <vector>
static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file");
...@@ -13,13 +14,14 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th ...@@ -13,13 +14,14 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th
- (id)initWithSetRecord:(DBSetRecord *)setRecord - (id)initWithSetRecord:(DBSetRecord *)setRecord
{ {
if (self = [super init]) { if (self = [super init]) {
NSMutableSet *_setTempSet = [NSMutableSet setWithCapacity:[setRecord.set count]]; std::vector<NSString *> _setTempVector;
_setTempVector.reserve([setRecord.set count]);
for (NSString *currentValue_0 in setRecord.set) { for (NSString *currentValue_0 in setRecord.set) {
id copiedValue_0; NSString *copiedValue_0;
copiedValue_0 = [currentValue_0 copy]; copiedValue_0 = [currentValue_0 copy];
[_setTempSet addObject:copiedValue_0]; _setTempVector.push_back(copiedValue_0);
} }
_set = _setTempSet; _set = [NSSet setWithObjects:&_setTempVector[0] count:_setTempVector.size()];
} }
return self; return self;
} }
...@@ -35,14 +37,15 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th ...@@ -35,14 +37,15 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th
- (id)initWithCppSetRecord:(const SetRecord &)setRecord - (id)initWithCppSetRecord:(const SetRecord &)setRecord
{ {
if (self = [super init]) { if (self = [super init]) {
NSMutableSet *_setTempSet = [NSMutableSet setWithCapacity:setRecord.set.size()]; std::vector<NSString *> _setTempVector;
_setTempVector.reserve(setRecord.set.size());
for (const auto & cppValue_0 : setRecord.set) { for (const auto & cppValue_0 : setRecord.set) {
NSString *objcValue_0 = [[NSString alloc] initWithBytes:cppValue_0.data() NSString *objcValue_0 = [[NSString alloc] initWithBytes:cppValue_0.data()
length:cppValue_0.length() length:cppValue_0.length()
encoding:NSUTF8StringEncoding]; encoding:NSUTF8StringEncoding];
[_setTempSet addObject:objcValue_0]; _setTempVector.push_back(objcValue_0);
} }
_set = _setTempSet; _set = [NSSet setWithObjects:&_setTempVector[0] count:_setTempVector.size()];
} }
return self; return self;
} }
......
...@@ -95,15 +95,19 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th ...@@ -95,15 +95,19 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th
+ (NSDictionary *)getMap { + (NSDictionary *)getMap {
try { try {
std::unordered_map<std::string, int64_t> cppRet = TestHelpers::get_map(); std::unordered_map<std::string, int64_t> cppRet = TestHelpers::get_map();
NSMutableDictionary *objcRetTempDictionary = [NSMutableDictionary dictionaryWithCapacity:cppRet.size()]; std::vector<NSString *> objcRetTempKeyVector;
objcRetTempKeyVector.reserve(cppRet.size());
std::vector<NSNumber *> objcRetTempValueVector;
objcRetTempValueVector.reserve(cppRet.size());
for (const auto & cppPair_0 : cppRet) { for (const auto & cppPair_0 : cppRet) {
NSString *objcKey_0 = [[NSString alloc] initWithBytes:cppPair_0.first.data() NSString *objcKey_0 = [[NSString alloc] initWithBytes:cppPair_0.first.data()
length:cppPair_0.first.length() length:cppPair_0.first.length()
encoding:NSUTF8StringEncoding]; encoding:NSUTF8StringEncoding];
NSNumber *objcValue_0 = [NSNumber numberWithLongLong:cppPair_0.second]; NSNumber *objcValue_0 = [NSNumber numberWithLongLong:cppPair_0.second];
[objcRetTempDictionary setObject:objcValue_0 forKey:objcKey_0]; objcRetTempKeyVector.push_back(objcKey_0);
objcRetTempValueVector.push_back(objcValue_0);
} }
NSDictionary *objcRet = objcRetTempDictionary; NSDictionary *objcRet = [NSDictionary dictionaryWithObjects:&objcRetTempValueVector[0] forKeys:&objcRetTempKeyVector[0] count:cppRet.size()];
return objcRet; return objcRet;
} DJINNI_TRANSLATE_EXCEPTIONS() } DJINNI_TRANSLATE_EXCEPTIONS()
} }
...@@ -125,15 +129,19 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th ...@@ -125,15 +129,19 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th
+ (NSDictionary *)getEmptyMap { + (NSDictionary *)getEmptyMap {
try { try {
std::unordered_map<std::string, int64_t> cppRet = TestHelpers::get_empty_map(); std::unordered_map<std::string, int64_t> cppRet = TestHelpers::get_empty_map();
NSMutableDictionary *objcRetTempDictionary = [NSMutableDictionary dictionaryWithCapacity:cppRet.size()]; std::vector<NSString *> objcRetTempKeyVector;
objcRetTempKeyVector.reserve(cppRet.size());
std::vector<NSNumber *> objcRetTempValueVector;
objcRetTempValueVector.reserve(cppRet.size());
for (const auto & cppPair_0 : cppRet) { for (const auto & cppPair_0 : cppRet) {
NSString *objcKey_0 = [[NSString alloc] initWithBytes:cppPair_0.first.data() NSString *objcKey_0 = [[NSString alloc] initWithBytes:cppPair_0.first.data()
length:cppPair_0.first.length() length:cppPair_0.first.length()
encoding:NSUTF8StringEncoding]; encoding:NSUTF8StringEncoding];
NSNumber *objcValue_0 = [NSNumber numberWithLongLong:cppPair_0.second]; NSNumber *objcValue_0 = [NSNumber numberWithLongLong:cppPair_0.second];
[objcRetTempDictionary setObject:objcValue_0 forKey:objcKey_0]; objcRetTempKeyVector.push_back(objcKey_0);
objcRetTempValueVector.push_back(objcValue_0);
} }
NSDictionary *objcRet = objcRetTempDictionary; NSDictionary *objcRet = [NSDictionary dictionaryWithObjects:&objcRetTempValueVector[0] forKeys:&objcRetTempKeyVector[0] count:cppRet.size()];
return objcRet; return objcRet;
} DJINNI_TRANSLATE_EXCEPTIONS() } DJINNI_TRANSLATE_EXCEPTIONS()
} }
......
...@@ -39,15 +39,15 @@ ...@@ -39,15 +39,15 @@
MapRecord cppMapRecord{ {} }; MapRecord cppMapRecord{ {} };
DBMapRecord *objcMapRecord = [[DBMapRecord alloc] initWithCppMapRecord:cppMapRecord]; DBMapRecord *objcMapRecord = [[DBMapRecord alloc] initWithCppMapRecord:cppMapRecord];
XCTAssertEqual([objcMapRecord.map count], 0, @"Count 0 expected, actual: %lu", (unsigned long)[objcMapRecord.map count]); XCTAssertEqual([objcMapRecord.map count], (NSUInteger)0, @"Count 0 expected, actual: %lu", (unsigned long)[objcMapRecord.map count]);
} }
- (void)testObjcToCppEmpty - (void)testObjcToCppEmpty
{ {
DBMapRecord *objcMapRecord = [[DBMapRecord alloc] initWithMap:[[NSMutableDictionary alloc] init]]; DBMapRecord *objcMapRecord = [[DBMapRecord alloc] initWithMap:[[NSDictionary alloc] init]];
MapRecord cppMapRecord = [objcMapRecord cppMapRecord]; MapRecord cppMapRecord = [objcMapRecord cppMapRecord];
auto & cppMap = cppMapRecord.map; auto & cppMap = cppMapRecord.map;
XCTAssertEqual(cppMap.size(), 0, @"Count 0 expected, actual: %zd", cppMap.size()); XCTAssertEqual(cppMap.size(), (size_t)0, @"Count 0 expected, actual: %zd", cppMap.size());
} }
- (void)testCppMapListToObjc - (void)testCppMapListToObjc
...@@ -55,23 +55,23 @@ ...@@ -55,23 +55,23 @@
MapListRecord cppMapListRecord{ { [self getCppMap] } }; MapListRecord cppMapListRecord{ { [self getCppMap] } };
DBMapListRecord *objcMapListRecord = [[DBMapListRecord alloc] initWithCppMapListRecord:cppMapListRecord]; DBMapListRecord *objcMapListRecord = [[DBMapListRecord alloc] initWithCppMapListRecord:cppMapListRecord];
NSArray *objcMapList = objcMapListRecord.mapList; NSArray *objcMapList = objcMapListRecord.mapList;
XCTAssertEqual([objcMapList count], 1, @"List with 1 map expected, actual no: %lu", (unsigned long)[objcMapList count]); XCTAssertEqual([objcMapList count], (NSUInteger)1, @"List with 1 map expected, actual no: %lu", (unsigned long)[objcMapList count]);
[self checkObjcMap:[objcMapList objectAtIndex:0]]; [self checkObjcMap:[objcMapList objectAtIndex:0]];
} }
- (void)testObjcMapListToCpp - (void)testObjcMapListToCpp
{ {
NSMutableArray *objcMapList = [[NSMutableArray alloc] initWithObjects:[self getObjcMap], nil]; NSArray *objcMapList = [[NSArray alloc] initWithObjects:[self getObjcMap], nil];
DBMapListRecord *objcMapListRecord = [[DBMapListRecord alloc] initWithMapList:objcMapList]; DBMapListRecord *objcMapListRecord = [[DBMapListRecord alloc] initWithMapList:objcMapList];
auto cppMapListRecord = [objcMapListRecord cppMapListRecord]; auto cppMapListRecord = [objcMapListRecord cppMapListRecord];
auto & cppMapList = cppMapListRecord.map_list; auto & cppMapList = cppMapListRecord.map_list;
XCTAssertEqual(cppMapList.size(), 1, @"List with 1 map expected, actual no: %zd", cppMapList.size()); XCTAssertEqual(cppMapList.size(), (size_t)1, @"List with 1 map expected, actual no: %zd", cppMapList.size());
[self checkCppMap:cppMapList[0]]; [self checkCppMap:cppMapList[0]];
} }
- (void)checkCppMap:(const std::unordered_map<std::string, int64_t>)cppMap - (void)checkCppMap:(const std::unordered_map<std::string, int64_t>)cppMap
{ {
XCTAssertEqual(cppMap.size(), 3, @"Count 3 expected, actual: %zd", cppMap.size()); XCTAssertEqual(cppMap.size(), (size_t)3, @"Count 3 expected, actual: %zd", cppMap.size());
XCTAssertEqual(cppMap.at("String1"), 1, @"\"String1 -> 1\" expected"); XCTAssertEqual(cppMap.at("String1"), 1, @"\"String1 -> 1\" expected");
XCTAssertEqual(cppMap.at("String2"), 2, @"\"String2 -> 2\" expected"); XCTAssertEqual(cppMap.at("String2"), 2, @"\"String2 -> 2\" expected");
XCTAssertEqual(cppMap.at("String3"), 3, @"\"String3 -> 3\" expected"); XCTAssertEqual(cppMap.at("String3"), 3, @"\"String3 -> 3\" expected");
...@@ -79,10 +79,10 @@ ...@@ -79,10 +79,10 @@
- (void)checkObjcMap:(NSDictionary *)objcMap - (void)checkObjcMap:(NSDictionary *)objcMap
{ {
XCTAssertEqual([objcMap count], 3, @"Count 3 expected, actual: %lu", (unsigned long)[objcMap count]); XCTAssertEqual([objcMap count], (NSUInteger)3, @"Count 3 expected, actual: %lu", (unsigned long)[objcMap count]);
XCTAssertEqual([objcMap objectForKey:@"String1"], [NSNumber numberWithLongLong:1], @"\"String1 -> 1\" expected"); XCTAssertEqual([objcMap objectForKey:@"String1"], @1, @"\"String1 -> 1\" expected");
XCTAssertEqual([objcMap objectForKey:@"String2"], [NSNumber numberWithLongLong:2], @"\"String2 -> 2\" expected"); XCTAssertEqual([objcMap objectForKey:@"String2"], @2, @"\"String2 -> 2\" expected");
XCTAssertEqual([objcMap objectForKey:@"String3"], [NSNumber numberWithLongLong:3], @"\"String3 -> 3\" expected"); XCTAssertEqual([objcMap objectForKey:@"String3"], @3, @"\"String3 -> 3\" expected");
} }
- (std::unordered_map<std::string, int64_t>)getCppMap - (std::unordered_map<std::string, int64_t>)getCppMap
...@@ -94,13 +94,9 @@ ...@@ -94,13 +94,9 @@
}; };
} }
- (NSMutableDictionary *)getObjcMap - (NSDictionary *)getObjcMap
{ {
NSMutableDictionary *objcMap = [[NSMutableDictionary alloc] initWithCapacity:3]; return @{ @"String1": @1, @"String2": @2, @"String3": @3 };
[objcMap setObject:[NSNumber numberWithLongLong:1] forKey:@"String1"];
[objcMap setObject:[NSNumber numberWithLongLong:2] forKey:@"String2"];
[objcMap setObject:[NSNumber numberWithLongLong:3] forKey:@"String3"];
return objcMap;
} }
......
...@@ -4,12 +4,10 @@ ...@@ -4,12 +4,10 @@
#include "nested_collection.hpp" #include "nested_collection.hpp"
static NestedCollection cppNestedCollection { { {u8"String1", u8"String2"}, {u8"StringA", u8"StringB"} } }; static NestedCollection cppNestedCollection { { {u8"String1", u8"String2"}, {u8"StringA", u8"StringB"} } };
static DBNestedCollection *objcNestedCollection = static DBNestedCollection *objcNestedCollection = [[DBNestedCollection alloc] initWithSetList:@[
[[DBNestedCollection alloc] [NSSet setWithArray:@[ @"String1", @"String2" ]],
initWithSetList:[[NSMutableArray alloc] [NSSet setWithArray:@[ @"StringA", @"StringB" ]],
initWithObjects:[[NSMutableSet alloc] initWithObjects:@"String1", @"String2", nil], ]];
[[NSMutableSet alloc] initWithObjects:@"StringA", @"StringB", nil],
nil]];
@interface DBNestedCollectionTests : XCTestCase @interface DBNestedCollectionTests : XCTestCase
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
static PrimitiveList cppPrimitiveList { { 1, 2, 3 } }; static PrimitiveList cppPrimitiveList { { 1, 2, 3 } };
static DBPrimitiveList *objcPrimitiveList = [[DBPrimitiveList alloc] initWithList: static DBPrimitiveList *objcPrimitiveList = [[DBPrimitiveList alloc] initWithList:
[[NSMutableArray alloc] initWithObjects:[NSNumber numberWithLongLong:1], [[NSArray alloc] initWithObjects:[NSNumber numberWithLongLong:1],
[NSNumber numberWithLongLong:2], [NSNumber numberWithLongLong:2],
[NSNumber numberWithLongLong:3], [NSNumber numberWithLongLong:3],
nil]]; nil]];
...@@ -29,8 +29,8 @@ static DBPrimitiveList *objcPrimitiveList = [[DBPrimitiveList alloc] initWithLis ...@@ -29,8 +29,8 @@ static DBPrimitiveList *objcPrimitiveList = [[DBPrimitiveList alloc] initWithLis
- (void)testObjcCopyConstructor - (void)testObjcCopyConstructor
{ {
DBPrimitiveList *copy = [[DBPrimitiveList alloc] initWithPrimitiveList:objcPrimitiveList]; DBPrimitiveList *copy = [[DBPrimitiveList alloc] initWithPrimitiveList:objcPrimitiveList];
XCTAssertNotEqual(copy.list, objcPrimitiveList.list, @"The two NSMutableArray should not be the same object."); XCTAssertNotEqual(copy.list, objcPrimitiveList.list, @"The two NSArrays should not be the same object.");
XCTAssertEqualObjects(copy.list, objcPrimitiveList.list, @"The two NSMutableArray should have the same content."); XCTAssertEqualObjects(copy.list, objcPrimitiveList.list, @"The two NSArrays should have the same content.");
} }
- (void)testObjcToCppConverter - (void)testObjcToCppConverter
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
- (DBSetRecord *)getObjcSetRecord - (DBSetRecord *)getObjcSetRecord
{ {
NSMutableSet *set = [[NSMutableSet alloc] initWithObjects:@"StringA", @"StringB", @"StringC", nil]; NSSet *set = [[NSSet alloc] initWithObjects:@"StringA", @"StringB", @"StringC", nil];
DBSetRecord *objcSetRecord = [[DBSetRecord alloc] initWithSet:set]; DBSetRecord *objcSetRecord = [[DBSetRecord alloc] initWithSet:set];
return objcSetRecord; return objcSetRecord;
} }
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
SetRecord cppSetRecord = [self getCppSetRecord]; SetRecord cppSetRecord = [self getCppSetRecord];
DBSetRecord *objcSetRecord = [[DBSetRecord alloc] initWithCppSetRecord:cppSetRecord]; DBSetRecord *objcSetRecord = [[DBSetRecord alloc] initWithCppSetRecord:cppSetRecord];
XCTAssertEqual([objcSetRecord.set count], 3, @"Set length 3 expected, actual: %lu", (unsigned long)[objcSetRecord.set count]); XCTAssertEqual([objcSetRecord.set count], (NSUInteger)3, @"Set length 3 expected, actual: %lu", (unsigned long)[objcSetRecord.set count]);
XCTAssert([objcSetRecord.set containsObject:@"StringA"], @"\"StringA\" expected but does not exist"); XCTAssert([objcSetRecord.set containsObject:@"StringA"], @"\"StringA\" expected but does not exist");
XCTAssert([objcSetRecord.set containsObject:@"StringB"], @"\"StringB\" expected but does not exist"); XCTAssert([objcSetRecord.set containsObject:@"StringB"], @"\"StringB\" expected but does not exist");
XCTAssert([objcSetRecord.set containsObject:@"StringC"], @"\"StringC\" expected but does not exist"); XCTAssert([objcSetRecord.set containsObject:@"StringC"], @"\"StringC\" expected but does not exist");
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
SetRecord cppSetRecord = [objcSetRecord cppSetRecord]; SetRecord cppSetRecord = [objcSetRecord cppSetRecord];
auto & cppSet = cppSetRecord.set; auto & cppSet = cppSetRecord.set;
XCTAssertEqual(cppSet.size(), 3, @"Set length 3 expected, actual: %zd", cppSet.size()); XCTAssertEqual(cppSet.size(), (NSUInteger)3, @"Set length 3 expected, actual: %zd", cppSet.size());
XCTAssertNotEqual(cppSet.find("StringA"), cppSet.end(), @"\"StringA\" expected but does not exist"); XCTAssertNotEqual(cppSet.find("StringA"), cppSet.end(), @"\"StringA\" expected but does not exist");
XCTAssertNotEqual(cppSet.find("StringB"), cppSet.end(), @"\"StringB\" expected but does not exist"); XCTAssertNotEqual(cppSet.find("StringB"), cppSet.end(), @"\"StringB\" expected but does not exist");
XCTAssertNotEqual(cppSet.find("StringC"), cppSet.end(), @"\"StringC\" expected but does not exist"); XCTAssertNotEqual(cppSet.find("StringC"), cppSet.end(), @"\"StringC\" expected but does not exist");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment