Commit ba88bbe7 authored by Steven Kabbes's avatar Steven Kabbes Committed by Jacob Potter

Expose record constructors in public ObjC headers

parent 047a3afe
...@@ -7,8 +7,6 @@ ...@@ -7,8 +7,6 @@
@interface TXSItemList () @interface TXSItemList ()
- (id)initWithItemList:(TXSItemList *)itemList;
- (id)initWithItems:(NSMutableArray *)items;
- (id)initWithCppItemList:(const ::textsort::ItemList &)itemList; - (id)initWithCppItemList:(const ::textsort::ItemList &)itemList;
- (::textsort::ItemList)cppItemList; - (::textsort::ItemList)cppItemList;
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
@interface TXSItemList : NSObject @interface TXSItemList : NSObject
- (id)initWithItemList:(TXSItemList *)itemList;
- (id)initWithItems:(NSMutableArray *)items;
@property (nonatomic, readonly) NSMutableArray *items; @property (nonatomic, readonly) NSMutableArray *items;
......
...@@ -399,6 +399,7 @@ class ObjcGenerator(spec: Spec) extends Generator(spec) { ...@@ -399,6 +399,7 @@ class ObjcGenerator(spec: Spec) extends Generator(spec) {
if (r.ext.objc) { if (r.ext.objc) {
refs.body.add("#import " + q("../" + headerName(ident))) refs.body.add("#import " + q("../" + headerName(ident)))
refs.privHeader.add("#import " + q("../" + headerName(ident))) refs.privHeader.add("#import " + q("../" + headerName(ident)))
refs.header.add(s"@class ${idObjc.ty(ident.name)};")
} }
def checkMutable(tm: MExpr): Boolean = tm.base match { def checkMutable(tm: MExpr): Boolean = tm.base match {
...@@ -416,6 +417,19 @@ class ObjcGenerator(spec: Spec) extends Generator(spec) { ...@@ -416,6 +417,19 @@ class ObjcGenerator(spec: Spec) extends Generator(spec) {
} }
w.wl w.wl
w.wl(s"@interface $self : NSObject") w.wl(s"@interface $self : NSObject")
// Deep copy construtor
w.wl(s"- (id)${idObjc.method("init_with_" + ident.name)}:(${idObjc.ty(ident)} *)${idObjc.field(ident)};")
if (!r.fields.isEmpty) {
val head = r.fields.head
val skipFirst = SkipFirst()
w.w(s"- (id)${idObjc.method("init_with_" + head.ident.name)}:(${toObjcFullType(head.ty)})${idObjc.local(head.ident)}")
for (f <- r.fields) skipFirst {
w.w(s" ${idObjc.field(f.ident)}:(${toObjcFullType(f.ty)})${idObjc.field(f.ident)}")
}
w.wl(";")
}
for (f <- r.fields) { for (f <- r.fields) {
w.wl w.wl
writeDoc(w, f.doc) writeDoc(w, f.doc)
...@@ -433,16 +447,6 @@ class ObjcGenerator(spec: Spec) extends Generator(spec) { ...@@ -433,16 +447,6 @@ class ObjcGenerator(spec: Spec) extends Generator(spec) {
w.wl(s"@interface $self ()") w.wl(s"@interface $self ()")
w.wl w.wl
// Deep copy constructor // Deep copy constructor
w.wl(s"- (id)${idObjc.method("init_with_" + ident.name)}:(${idObjc.ty(ident)} *)${idObjc.field(ident)};")
if (!r.fields.isEmpty) {
val head = r.fields.head
val skipFirst = SkipFirst()
w.w(s"- (id)${idObjc.method("init_with_" + head.ident.name)}:(${toObjcFullType(head.ty)})${idObjc.local(head.ident)}")
for (f <- r.fields) skipFirst {
w.w(s" ${idObjc.field(f.ident)}:(${toObjcFullType(f.ty)})${idObjc.field(f.ident)}")
}
w.wl(";")
}
w.wl(s"- (id)${idObjc.method("init_with_cpp_" + ident.name)}:(const $cppSelf &)${idObjc.local(ident)};") w.wl(s"- (id)${idObjc.method("init_with_cpp_" + ident.name)}:(const $cppSelf &)${idObjc.local(ident)};")
w.wl(s"- ($cppSelf)${idObjc.method("cpp_" + ident.name)};") w.wl(s"- ($cppSelf)${idObjc.method("cpp_" + ident.name)};")
w.wl w.wl
...@@ -455,7 +459,6 @@ class ObjcGenerator(spec: Spec) extends Generator(spec) { ...@@ -455,7 +459,6 @@ class ObjcGenerator(spec: Spec) extends Generator(spec) {
w.wl w.wl
w.wl(s"@implementation $self") w.wl(s"@implementation $self")
w.wl w.wl
// Deep copy construtor
w.wl(s"- (id)${idObjc.method("init_with_" + ident.name)}:(${idObjc.ty(ident)} *)${idObjc.local(ident)}") w.wl(s"- (id)${idObjc.method("init_with_" + ident.name)}:(${idObjc.ty(ident)} *)${idObjc.local(ident)}")
w.braced { w.braced {
w.w("if (self = [super init])").braced { w.w("if (self = [super init])").braced {
......
...@@ -7,8 +7,6 @@ ...@@ -7,8 +7,6 @@
@interface DBClientReturnedRecord () @interface DBClientReturnedRecord ()
- (id)initWithClientReturnedRecord:(DBClientReturnedRecord *)clientReturnedRecord;
- (id)initWithContent:(NSString *)content;
- (id)initWithCppClientReturnedRecord:(const ClientReturnedRecord &)clientReturnedRecord; - (id)initWithCppClientReturnedRecord:(const ClientReturnedRecord &)clientReturnedRecord;
- (ClientReturnedRecord)cppClientReturnedRecord; - (ClientReturnedRecord)cppClientReturnedRecord;
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
@interface DBClientReturnedRecord : NSObject @interface DBClientReturnedRecord : NSObject
- (id)initWithClientReturnedRecord:(DBClientReturnedRecord *)clientReturnedRecord;
- (id)initWithContent:(NSString *)content;
@property (nonatomic, readonly) NSString *content; @property (nonatomic, readonly) NSString *content;
......
...@@ -7,8 +7,6 @@ ...@@ -7,8 +7,6 @@
@interface DBMapListRecord () @interface DBMapListRecord ()
- (id)initWithMapListRecord:(DBMapListRecord *)mapListRecord;
- (id)initWithMapList:(NSMutableArray *)mapList;
- (id)initWithCppMapListRecord:(const MapListRecord &)mapListRecord; - (id)initWithCppMapListRecord:(const MapListRecord &)mapListRecord;
- (MapListRecord)cppMapListRecord; - (MapListRecord)cppMapListRecord;
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
@interface DBMapListRecord : NSObject @interface DBMapListRecord : NSObject
- (id)initWithMapListRecord:(DBMapListRecord *)mapListRecord;
- (id)initWithMapList:(NSMutableArray *)mapList;
@property (nonatomic, readonly) NSMutableArray *mapList; @property (nonatomic, readonly) NSMutableArray *mapList;
......
...@@ -7,8 +7,6 @@ ...@@ -7,8 +7,6 @@
@interface DBMapRecord () @interface DBMapRecord ()
- (id)initWithMapRecord:(DBMapRecord *)mapRecord;
- (id)initWithMap:(NSMutableDictionary *)map;
- (id)initWithCppMapRecord:(const MapRecord &)mapRecord; - (id)initWithCppMapRecord:(const MapRecord &)mapRecord;
- (MapRecord)cppMapRecord; - (MapRecord)cppMapRecord;
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
@interface DBMapRecord : NSObject @interface DBMapRecord : NSObject
- (id)initWithMapRecord:(DBMapRecord *)mapRecord;
- (id)initWithMap:(NSMutableDictionary *)map;
@property (nonatomic, readonly) NSMutableDictionary *map; @property (nonatomic, readonly) NSMutableDictionary *map;
......
...@@ -7,8 +7,6 @@ ...@@ -7,8 +7,6 @@
@interface DBNestedCollection () @interface DBNestedCollection ()
- (id)initWithNestedCollection:(DBNestedCollection *)nestedCollection;
- (id)initWithSetList:(NSMutableArray *)setList;
- (id)initWithCppNestedCollection:(const NestedCollection &)nestedCollection; - (id)initWithCppNestedCollection:(const NestedCollection &)nestedCollection;
- (NestedCollection)cppNestedCollection; - (NestedCollection)cppNestedCollection;
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
@interface DBNestedCollection : NSObject @interface DBNestedCollection : NSObject
- (id)initWithNestedCollection:(DBNestedCollection *)nestedCollection;
- (id)initWithSetList:(NSMutableArray *)setList;
@property (nonatomic, readonly) NSMutableArray *setList; @property (nonatomic, readonly) NSMutableArray *setList;
......
...@@ -7,8 +7,6 @@ ...@@ -7,8 +7,6 @@
@interface DBPrimitiveList () @interface DBPrimitiveList ()
- (id)initWithPrimitiveList:(DBPrimitiveList *)primitiveList;
- (id)initWithList:(NSMutableArray *)list;
- (id)initWithCppPrimitiveList:(const PrimitiveList &)primitiveList; - (id)initWithCppPrimitiveList:(const PrimitiveList &)primitiveList;
- (PrimitiveList)cppPrimitiveList; - (PrimitiveList)cppPrimitiveList;
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
@interface DBPrimitiveList : NSObject @interface DBPrimitiveList : NSObject
- (id)initWithPrimitiveList:(DBPrimitiveList *)primitiveList;
- (id)initWithList:(NSMutableArray *)list;
@property (nonatomic, readonly) NSMutableArray *list; @property (nonatomic, readonly) NSMutableArray *list;
......
...@@ -7,8 +7,6 @@ ...@@ -7,8 +7,6 @@
@interface DBRecordWithDerivings () @interface DBRecordWithDerivings ()
- (id)initWithRecordWithDerivings:(DBRecordWithDerivings *)recordWithDerivings;
- (id)initWithKey1:(int32_t)key1 key2:(NSString *)key2;
- (id)initWithCppRecordWithDerivings:(const RecordWithDerivings &)recordWithDerivings; - (id)initWithCppRecordWithDerivings:(const RecordWithDerivings &)recordWithDerivings;
- (RecordWithDerivings)cppRecordWithDerivings; - (RecordWithDerivings)cppRecordWithDerivings;
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
@interface DBRecordWithDerivings : NSObject @interface DBRecordWithDerivings : NSObject
- (id)initWithRecordWithDerivings:(DBRecordWithDerivings *)recordWithDerivings;
- (id)initWithKey1:(int32_t)key1 key2:(NSString *)key2;
@property (nonatomic, readonly) int32_t key1; @property (nonatomic, readonly) int32_t key1;
......
...@@ -7,8 +7,6 @@ ...@@ -7,8 +7,6 @@
@interface DBRecordWithNestedDerivings () @interface DBRecordWithNestedDerivings ()
- (id)initWithRecordWithNestedDerivings:(DBRecordWithNestedDerivings *)recordWithNestedDerivings;
- (id)initWithKey:(int32_t)key rec:(DBRecordWithDerivings *)rec;
- (id)initWithCppRecordWithNestedDerivings:(const RecordWithNestedDerivings &)recordWithNestedDerivings; - (id)initWithCppRecordWithNestedDerivings:(const RecordWithNestedDerivings &)recordWithNestedDerivings;
- (RecordWithNestedDerivings)cppRecordWithNestedDerivings; - (RecordWithNestedDerivings)cppRecordWithNestedDerivings;
......
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
@interface DBRecordWithNestedDerivings : NSObject @interface DBRecordWithNestedDerivings : NSObject
- (id)initWithRecordWithNestedDerivings:(DBRecordWithNestedDerivings *)recordWithNestedDerivings;
- (id)initWithKey:(int32_t)key rec:(DBRecordWithDerivings *)rec;
@property (nonatomic, readonly) int32_t key; @property (nonatomic, readonly) int32_t key;
......
...@@ -7,8 +7,6 @@ ...@@ -7,8 +7,6 @@
@interface DBSetRecord () @interface DBSetRecord ()
- (id)initWithSetRecord:(DBSetRecord *)setRecord;
- (id)initWithSet:(NSMutableSet *)set;
- (id)initWithCppSetRecord:(const SetRecord &)setRecord; - (id)initWithCppSetRecord:(const SetRecord &)setRecord;
- (SetRecord)cppSetRecord; - (SetRecord)cppSetRecord;
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
@interface DBSetRecord : NSObject @interface DBSetRecord : NSObject
- (id)initWithSetRecord:(DBSetRecord *)setRecord;
- (id)initWithSet:(NSMutableSet *)set;
@property (nonatomic, readonly) NSMutableSet *set; @property (nonatomic, readonly) NSMutableSet *set;
......
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