Commit 5fb9e457 authored by Miro Knejp's avatar Miro Knejp Committed by Jacob Potter

Refactored remaining opaque code generation to utilize translation types like JNI does

Also includes:
- Use helper function for printing Objc function calls and signatures
- Consistently apply "field" and "local" identifiery styles to Objc record parameters
- Further imporvements to Objcpp generator
  - Separation of output format and semantics
  - Consistent printing of call signatures
  - Avoiding local temporaries where feasible
- Fixed double "auto ret =" in +o methods with a return value

Plus some additional fixes

[written by mknejp, rebased/squashed/fixed up by j4cbo]
parent 8b58e79c
...@@ -14,27 +14,12 @@ namespace djinni_generated { ...@@ -14,27 +14,12 @@ namespace djinni_generated {
auto ItemList::toCpp(ObjcType obj) -> CppType auto ItemList::toCpp(ObjcType obj) -> CppType
{ {
assert(obj); assert(obj);
std::vector<std::string> items; return {::djinni::List<::djinni::String>::toCpp(obj.items)};
items.reserve([obj.items count]);
for (NSString *objcValue_0 in obj.items) {
std::string cppValue_0 = ::djinni::String::toCpp(objcValue_0);
items.push_back(std::move(cppValue_0));
}
return ::textsort::ItemList(
items);
} }
auto ItemList::fromCpp(const CppType& cpp) -> ObjcType auto ItemList::fromCpp(const CppType& cpp) -> ObjcType
{ {
std::vector<NSString *> itemsTempVector; return [[TXSItemList alloc] initWithItems:(::djinni::List<::djinni::String>::fromCpp(cpp.items))];
itemsTempVector.reserve(cpp.items.size());
for (const auto & cppValue_0 : cpp.items) {
NSString *objcValue_0 = ::djinni::String::fromCpp(cppValue_0);
itemsTempVector.push_back(objcValue_0);
}
NSArray *items = [NSArray arrayWithObjects:&itemsTempVector[0] count:itemsTempVector.size()];
return [[TXSItemList alloc]
initWithItems:items];
} }
} // namespace djinni_generated } // namespace djinni_generated
...@@ -10,13 +10,19 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th ...@@ -10,13 +10,19 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th
namespace djinni_generated { namespace djinni_generated {
struct SortItems class SortItems
{ {
public:
using CppType = std::shared_ptr<::textsort::SortItems>; using CppType = std::shared_ptr<::textsort::SortItems>;
using ObjcType = TXSSortItems*; using ObjcType = TXSSortItems*;
using Boxed = SortItems;
static CppType toCpp(ObjcType objc); static CppType toCpp(ObjcType objc);
static ObjcType fromCpp(const CppType& cpp); static ObjcType fromCpp(const CppType& cpp);
private:
class ObjcProxy;
}; };
} // namespace djinni_generated } // namespace djinni_generated
......
...@@ -10,7 +10,8 @@ ...@@ -10,7 +10,8 @@
@interface TXSSortItems : NSObject @interface TXSSortItems : NSObject
- (void)sort:(TXSSortOrder)order items:(TXSItemList *)items; - (void)sort:(TXSSortOrder)order
items:(TXSItemList *)items;
+ (TXSSortItems *)createWithListener:(id<TXSTextboxListener>)listener; + (TXSSortItems *)createWithListener:(id<TXSTextboxListener>)listener;
......
...@@ -51,20 +51,18 @@ auto SortItems::fromCpp(const CppType& cpp) -> ObjcType ...@@ -51,20 +51,18 @@ auto SortItems::fromCpp(const CppType& cpp) -> ObjcType
return self; return self;
} }
- (void)sort:(TXSSortOrder)order items:(TXSItemList *)items { - (void)sort:(TXSSortOrder)order
items:(TXSItemList *)items {
try { try {
::textsort::sort_order cppOrder = ::djinni::Enum<::textsort::sort_order, TXSSortOrder>::toCpp(order); _cppRef.get()->sort(::djinni::Enum<::textsort::sort_order, TXSSortOrder>::toCpp(order),
::textsort::ItemList cppItems = ::djinni_generated::ItemList::toCpp(items); ::djinni_generated::ItemList::toCpp(items));
_cppRef.get()->sort(std::move(cppOrder), std::move(cppItems));
} DJINNI_TRANSLATE_EXCEPTIONS() } DJINNI_TRANSLATE_EXCEPTIONS()
} }
+ (TXSSortItems *)createWithListener:(id<TXSTextboxListener>)listener { + (TXSSortItems *)createWithListener:(id<TXSTextboxListener>)listener {
try { try {
std::shared_ptr<::textsort::TextboxListener> cppListener = ::djinni_generated::TextboxListener::toCpp(listener); auto r = ::textsort::SortItems::create_with_listener(::djinni_generated::TextboxListener::toCpp(listener));
std::shared_ptr<::textsort::SortItems> cppRet = ::textsort::SortItems::create_with_listener(std::move(cppListener)); return ::djinni_generated::SortItems::fromCpp(r);
TXSSortItems* objcRet = ::djinni_generated::SortItems::fromCpp(cppRet);
return objcRet;
} DJINNI_TRANSLATE_EXCEPTIONS() } DJINNI_TRANSLATE_EXCEPTIONS()
} }
......
...@@ -10,13 +10,19 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th ...@@ -10,13 +10,19 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th
namespace djinni_generated { namespace djinni_generated {
struct TextboxListener class TextboxListener
{ {
public:
using CppType = std::shared_ptr<::textsort::TextboxListener>; using CppType = std::shared_ptr<::textsort::TextboxListener>;
using ObjcType = id<TXSTextboxListener>; using ObjcType = id<TXSTextboxListener>;
using Boxed = TextboxListener;
static CppType toCpp(ObjcType objc); static CppType toCpp(ObjcType objc);
static ObjcType fromCpp(const CppType& cpp); static ObjcType fromCpp(const CppType& cpp);
private:
class ObjcProxy;
}; };
} // namespace djinni_generated } // namespace djinni_generated
......
...@@ -9,21 +9,22 @@ ...@@ -9,21 +9,22 @@
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");
namespace { // anonymous namespace namespace djinni_generated {
class ObjcProxy final class TextboxListener::ObjcProxy final
: public ::textsort::TextboxListener : public ::textsort::TextboxListener
, public ::djinni::DbxObjcWrapperCache<ObjcProxy>::Handle , public ::djinni::DbxObjcWrapperCache<ObjcProxy>::Handle
{ {
public: public:
using Handle::Handle; using Handle::Handle;
void update (const ::textsort::ItemList & items) override; void update(const ::textsort::ItemList & items) override
{
@autoreleasepool {
[Handle::get() update:(::djinni_generated::ItemList::fromCpp(items))];
}
}
}; };
} // end anonymous namespace
namespace djinni_generated {
auto TextboxListener::toCpp(ObjcType objc) -> CppType auto TextboxListener::toCpp(ObjcType objc) -> CppType
{ {
return objc ? djinni::DbxObjcWrapperCache<ObjcProxy>::getInstance()->get(objc) : nullptr; return objc ? djinni::DbxObjcWrapperCache<ObjcProxy>::getInstance()->get(objc) : nullptr;
...@@ -36,11 +37,3 @@ auto TextboxListener::fromCpp(const CppType& cpp) -> ObjcType ...@@ -36,11 +37,3 @@ auto TextboxListener::fromCpp(const CppType& cpp) -> ObjcType
} }
} // namespace djinni_generated } // namespace djinni_generated
void ObjcProxy::update (const ::textsort::ItemList & items)
{
@autoreleasepool {
TXSItemList *cpp_items = ::djinni_generated::ItemList::fromCpp(items);
[Handle::get() update:cpp_items];
}
}
...@@ -29,6 +29,9 @@ class CppMarshal(spec: Spec) extends Marshal(spec) { ...@@ -29,6 +29,9 @@ class CppMarshal(spec: Spec) extends Marshal(spec) {
override def fieldType(tm: MExpr): String = typename(tm) override def fieldType(tm: MExpr): String = typename(tm)
override def fqFieldType(tm: MExpr): String = fqTypename(tm) override def fqFieldType(tm: MExpr): String = fqTypename(tm)
override def toCpp(tm: MExpr, expr: String): String = throw new AssertionError("cpp to cpp conversion")
override def fromCpp(tm: MExpr, expr: String): String = throw new AssertionError("cpp to cpp conversion")
private def toCppType(ty: TypeRef, namespace: Option[String] = None): String = toCppType(ty.resolved, namespace) private def toCppType(ty: TypeRef, namespace: Option[String] = None): String = toCppType(ty.resolved, namespace)
private def toCppType(tm: MExpr, namespace: Option[String]): String = { private def toCppType(tm: MExpr, namespace: Option[String]): String = {
def base(m: Meta): String = m match { def base(m: Meta): String = m match {
......
...@@ -21,6 +21,9 @@ class JavaMarshal(spec: Spec) extends Marshal(spec) { ...@@ -21,6 +21,9 @@ class JavaMarshal(spec: Spec) extends Marshal(spec) {
override def fieldType(tm: MExpr): String = typename(tm) override def fieldType(tm: MExpr): String = typename(tm)
override def fqFieldType(tm: MExpr): String = fqTypename(tm) override def fqFieldType(tm: MExpr): String = fqTypename(tm)
override def toCpp(tm: MExpr, expr: String): String = throw new AssertionError("direct java to cpp conversion not possible")
override def fromCpp(tm: MExpr, expr: String): String = throw new AssertionError("direct cpp to java conversion not possible")
private def toJavaType(tm: MExpr, packageName: Option[String]): String = { private def toJavaType(tm: MExpr, packageName: Option[String]): String = {
def f(tm: MExpr, needRef: Boolean): String = { def f(tm: MExpr, needRef: Boolean): String = {
tm.base match { tm.base match {
......
...@@ -29,6 +29,12 @@ abstract class Marshal(spec: Spec) { ...@@ -29,6 +29,12 @@ abstract class Marshal(spec: Spec) {
def fieldType(ty: TypeRef): String = fieldType(ty.resolved) def fieldType(ty: TypeRef): String = fieldType(ty.resolved)
def fqFieldType(tm: MExpr): String def fqFieldType(tm: MExpr): String
def fqFieldType(ty: TypeRef): String = fqFieldType(ty.resolved) def fqFieldType(ty: TypeRef): String = fqFieldType(ty.resolved)
// Generate code for an expression that transforms an expression `expr` of the non-C++ type `tm` to its C++ counterpart
def toCpp(tm: MExpr, expr: String): String = ""
def toCpp(ty: TypeRef, expr: String): String = toCpp(ty.resolved, expr)
// Generate code for an expression that transforms an expression `expr` of the C++ type `tm` to its non-C++ counterpart
def fromCpp(tm: MExpr, expr: String): String = ""
def fromCpp(ty: TypeRef, expr: String): String = fromCpp(ty.resolved, expr)
implicit def identToString(ident: Ident): String = ident.name implicit def identToString(ident: Ident): String = ident.name
protected val idCpp = spec.cppIdentStyle protected val idCpp = spec.cppIdentStyle
......
...@@ -155,12 +155,8 @@ class ObjcGenerator(spec: Spec) extends Generator(spec) { ...@@ -155,12 +155,8 @@ class ObjcGenerator(spec: Spec) extends Generator(spec) {
def writeObjcFuncDecl(method: Interface.Method, w: IndentWriter) { def writeObjcFuncDecl(method: Interface.Method, w: IndentWriter) {
val label = if (method.static) "+" else "-" val label = if (method.static) "+" else "-"
val ret = marshal.returnType(method.ret) val ret = marshal.returnType(method.ret)
w.w(s"$label ($ret)${idObjc.method(method.ident)}") val decl = s"$label ($ret)${idObjc.method(method.ident)}"
val skipFirst = SkipFirst() writeAlignedObjcCall(w, decl, method.params, "", p => (idObjc.field(p.ident), s"(${marshal.paramType(p.ty)})${idObjc.local(p.ident)}"))
for (p <- method.params) {
skipFirst { w.w(s" ${idObjc.local(p.ident)}") }
w.w(s":(${marshal.paramType(p.ty)})${idObjc.local(p.ident)}")
}
} }
writeObjcFile(headerName(ident), origin, refs.header, w => { writeObjcFile(headerName(ident), origin, refs.header, w => {
...@@ -187,7 +183,7 @@ class ObjcGenerator(spec: Spec) extends Generator(spec) { ...@@ -187,7 +183,7 @@ class ObjcGenerator(spec: Spec) extends Generator(spec) {
refs.body.add("#import " + q(spec.objcIncludePrefix + headerName(ident))) refs.body.add("#import " + q(spec.objcIncludePrefix + headerName(ident)))
if (i.consts.nonEmpty) { if (i.consts.nonEmpty) {
writeObjcFile(bodyName(ident.name), origin, refs.body, w => { writeObjcFile(bodyName(ident.name + "_constants"), origin, refs.body, w => { // TODO(j4cbo): this is named differently because otherwise it conflicts with interface +c wrappers
generateObjcConstants(w, i.consts, self) generateObjcConstants(w, i.consts, self)
}) })
} }
...@@ -223,14 +219,13 @@ class ObjcGenerator(spec: Spec) extends Generator(spec) { ...@@ -223,14 +219,13 @@ class ObjcGenerator(spec: Spec) extends Generator(spec) {
w.wl(s"@interface $self : NSObject") w.wl(s"@interface $self : NSObject")
// Deep copy construtor // Deep copy construtor
w.wl(s"- (id)${idObjc.method("init_with_" + ident.name)}:($self *)${idObjc.field(ident)};") w.wl(s"- (id)${idObjc.method("init_with_" + ident.name)}:($self *)${idObjc.local(ident)};")
if (!r.fields.isEmpty) { if (!r.fields.isEmpty) {
val head = r.fields.head val head = r.fields.head
val skipFirst = SkipFirst() val skipFirst = SkipFirst()
w.w(s"- (id)${idObjc.method("init_with_" + head.ident.name)}:(${marshal.paramType(head.ty)})${idObjc.local(head.ident)}") val first = if(r.fields.isEmpty) "" else IdentStyle.camelUpper("with_" + r.fields.head.ident.name)
for (f <- r.fields) skipFirst { val decl = s"- (id)init$first"
w.w(s" ${idObjc.field(f.ident)}:(${marshal.paramType(f.ty)})${idObjc.field(f.ident)}") writeAlignedObjcCall(w, decl, r.fields, "", f => (idObjc.field(f.ident), s"(${marshal.paramType(f.ty)})${idObjc.local(f.ident)}"))
}
w.wl(";") w.wl(";")
} }
...@@ -275,10 +270,8 @@ class ObjcGenerator(spec: Spec) extends Generator(spec) { ...@@ -275,10 +270,8 @@ class ObjcGenerator(spec: Spec) extends Generator(spec) {
if (!r.fields.isEmpty) { if (!r.fields.isEmpty) {
val head = r.fields.head val head = r.fields.head
val skipFirst = SkipFirst() val skipFirst = SkipFirst()
w.w(s"- (id)${idObjc.method("init_with_" + head.ident.name)}:(${marshal.paramType(head.ty)})${idObjc.field(head.ident)}") val decl = s"- (id)${idObjc.method("init_with_" + head.ident.name)}"
for (f <- r.fields) skipFirst { writeAlignedObjcCall(w, decl, r.fields, "", f => (idObjc.field(f.ident), s"(${marshal.paramType(f.ty)})${idObjc.local(f.ident)}"))
w.w(s" ${idObjc.field(f.ident.name)}:(${marshal.paramType(f.ty)})${idObjc.local(f.ident)}")
}
w.wl w.wl
w.braced { w.braced {
w.w("if (self = [super init])").braced { w.w("if (self = [super init])").braced {
......
...@@ -25,6 +25,9 @@ class ObjcMarshal(spec: Spec) extends Marshal(spec) { ...@@ -25,6 +25,9 @@ class ObjcMarshal(spec: Spec) extends Marshal(spec) {
override def fieldType(tm: MExpr): String = paramType(tm) override def fieldType(tm: MExpr): String = paramType(tm)
override def fqFieldType(tm: MExpr): String = fqParamType(tm) override def fqFieldType(tm: MExpr): String = fqParamType(tm)
override def toCpp(tm: MExpr, expr: String): String = throw new AssertionError("direct objc to cpp conversion not possible")
override def fromCpp(tm: MExpr, expr: String): String = throw new AssertionError("direct cpp to objc conversion not possible")
// Return value: (Type_Name, Is_Class_Or_Not) // Return value: (Type_Name, Is_Class_Or_Not)
def toObjcType(ty: TypeRef): (String, Boolean) = toObjcType(ty.resolved, false) def toObjcType(ty: TypeRef): (String, Boolean) = toObjcType(ty.resolved, false)
def toObjcType(ty: TypeRef, needRef: Boolean): (String, Boolean) = toObjcType(ty.resolved, needRef) def toObjcType(ty: TypeRef, needRef: Boolean): (String, Boolean) = toObjcType(ty.resolved, needRef)
......
This diff is collapsed.
...@@ -5,6 +5,8 @@ import djinni.generatorTools._ ...@@ -5,6 +5,8 @@ import djinni.generatorTools._
import djinni.meta._ import djinni.meta._
class ObjcppMarshal(spec: Spec) extends Marshal(spec) { class ObjcppMarshal(spec: Spec) extends Marshal(spec) {
private val cppMarshal = new CppMarshal(spec)
private val objcMarshal = new ObjcMarshal(spec)
override def typename(tm: MExpr): String = throw new AssertionError("not applicable") override def typename(tm: MExpr): String = throw new AssertionError("not applicable")
def typename(name: String, ty: TypeDef): String = throw new AssertionError("not applicable") def typename(name: String, ty: TypeDef): String = throw new AssertionError("not applicable")
...@@ -21,48 +23,58 @@ class ObjcppMarshal(spec: Spec) extends Marshal(spec) { ...@@ -21,48 +23,58 @@ class ObjcppMarshal(spec: Spec) extends Marshal(spec) {
override def fieldType(tm: MExpr): String = throw new AssertionError("not applicable") override def fieldType(tm: MExpr): String = throw new AssertionError("not applicable")
override def fqFieldType(tm: MExpr): String = throw new AssertionError("not applicable") override def fqFieldType(tm: MExpr): String = throw new AssertionError("not applicable")
// Name for the autogenerated proxy class wrapping +o interfaces override def toCpp(tm: MExpr, expr: String): String = {
val helper = helperName(tm) + helperTemplates(tm)
s"$helper::toCpp($expr)"
}
override def fromCpp(tm: MExpr, expr: String): String = {
val helper = helperName(tm) + helperTemplates(tm)
s"$helper::fromCpp($expr)"
}
def helperClass(name: String) = idCpp.ty(name) def helperClass(name: String) = idCpp.ty(name)
def fqHelperClass(name: String) = withNs(Some(spec.objcppNamespace), helperClass(name))
// Return value: (Type_Name, Is_Class_Or_Not) private def helperName(tm: MExpr): String = tm.base match {
def toObjcType(ty: TypeRef): (String, Boolean) = toObjcType(ty.resolved, false) case d: MDef => d.defType match {
def toObjcType(ty: TypeRef, needRef: Boolean): (String, Boolean) = toObjcType(ty.resolved, needRef) case DEnum => withNs(Some("djinni"), s"Enum<${cppMarshal.fqTypename(tm)}, ${objcMarshal.fqTypename(tm)}>")
def toObjcType(tm: MExpr): (String, Boolean) = toObjcType(tm, false) case _ => withNs(Some(spec.objcppNamespace), helperClass(d.name))
def toObjcType(tm: MExpr, needRef: Boolean): (String, Boolean) = {
def f(tm: MExpr, needRef: Boolean): (String, Boolean) = {
tm.base match {
case MOptional =>
// We use "nil" for the empty optional.
assert(tm.args.size == 1)
val arg = tm.args.head
arg.base match {
case MOptional => throw new AssertionError("nested optional?")
case m => f(arg, true)
}
case o =>
val base = o match {
case p: MPrimitive => if (needRef) (p.objcBoxed, true) else (p.objcName, false)
case MString => ("NSString", true)
case MDate => ("NSDate", true)
case MBinary => ("NSData", true)
case MOptional => throw new AssertionError("optional should have been special cased")
case MList => ("NSArray", true)
case MSet => ("NSSet", true)
case MMap => ("NSDictionary", true)
case d: MDef => d.defType match {
case DEnum => if (needRef) ("NSNumber", true) else (idObjc.ty(d.name), false)
case DRecord => (idObjc.ty(d.name), true)
case DInterface =>
val ext = d.body.asInstanceOf[Interface].ext
(idObjc.ty(d.name), false)
}
case p: MParam => throw new AssertionError("Parameter should not happen at Obj-C top level")
}
base
}
} }
f(tm, needRef) case o => withNs(Some("djinni"), o match {
case p: MPrimitive => p.idlName match {
case "i8" => "I8"
case "i16" => "I16"
case "i32" => "I32"
case "i64" => "I64"
case "f64" => "F64"
case "bool" => "Bool"
}
case MOptional => "Optional"
case MBinary => "Binary"
case MDate => "Date"
case MString => "String"
case MList => "List"
case MSet => "Set"
case MMap => "Map"
case d: MDef => throw new AssertionError("unreachable")
case p: MParam => throw new AssertionError("not applicable")
})
} }
private def helperTemplates(tm: MExpr): String = tm.base match {
case MOptional =>
assert(tm.args.size == 1)
val argHelperClass = helperName(tm.args.head) + helperTemplates(tm.args.head)
s"<${spec.cppOptionalTemplate}, $argHelperClass>"
case MList | MSet =>
assert(tm.args.size == 1)
val argHelperClass = helperName(tm.args.head) + helperTemplates(tm.args.head)
s"<$argHelperClass>"
case MMap =>
assert(tm.args.size == 2)
val keyHelperClass = helperName(tm.args.head) + helperTemplates(tm.args.head)
val valueHelperClass = helperName(tm.args.tail.head) + helperTemplates(tm.args.tail.head)
s"<$keyHelperClass, $valueHelperClass>"
case _ =>
""
}
} }
...@@ -295,6 +295,27 @@ abstract class Generator(spec: Spec) ...@@ -295,6 +295,27 @@ abstract class Generator(spec: Spec)
case Some(s) => "::" + s + "::" + t case Some(s) => "::" + s + "::" + t
} }
def writeAlignedCall(w: IndentWriter, call: String, params: Seq[Field], end: String, f: Field => String) = {
w.w(call)
val skipFirst = new SkipFirst
params.foreach(p => {
skipFirst { w.wl(","); w.w(" " * call.length()) }
w.w(f(p))
})
w.w(end)
}
def writeAlignedObjcCall(w: IndentWriter, call: String, params: Seq[Field], end: String, f: Field => (String, String)) = {
w.w(call)
val skipFirst = new SkipFirst
params.foreach(p => {
val (name, value) = f(p)
skipFirst { w.wl; w.w(" " * math.max(0, call.length() - name.length)); w.w(name) }
w.w(":" + value)
})
w.w(end)
}
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
def writeDoc(w: IndentWriter, doc: Doc) { def writeDoc(w: IndentWriter, doc: Doc) {
......
...@@ -11,6 +11,10 @@ ...@@ -11,6 +11,10 @@
#include <cstdint> #include <cstdint>
#include <string> #include <string>
#include <vector> #include <vector>
#include <chrono>
#include <unordered_set>
#include <unordered_map>
#include "DJIDate.h"
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");
...@@ -111,6 +115,23 @@ struct String { ...@@ -111,6 +115,23 @@ struct String {
} }
}; };
struct Date {
using CppType = std::chrono::system_clock::time_point;
using ObjcType = NSDate*;
using Boxed = Date;
static CppType toCpp(ObjcType date) {
return ::djinni::convert_date([date timeIntervalSince1970]);
}
static ObjcType fromCpp(const CppType& date) {
return [NSDate dateWithTimeIntervalSince1970:
::std::chrono::duration_cast<::std::chrono::duration<double>>(date.time_since_epoch()).count()];
}
};
struct Binary { struct Binary {
using CppType = std::vector<uint8_t>; using CppType = std::vector<uint8_t>;
using ObjcType = NSData*; using ObjcType = NSData*;
...@@ -129,4 +150,115 @@ struct Binary { ...@@ -129,4 +150,115 @@ struct Binary {
} }
}; };
template<template<class> class OptionalType, class T>
class Optional {
public:
using CppType = OptionalType<typename T::CppType>;
using ObjcType = typename T::Boxed::ObjcType;
using Boxed = Optional;
static CppType toCpp(ObjcType obj) {
return obj ? CppType(T::Boxed::toCpp(obj)) : CppType();
}
static ObjcType fromCpp(const CppType& opt) {
return opt ? T::Boxed::fromCpp(*opt) : nil;
}
};
template<class T>
class List {
using ECppType = typename T::CppType;
using EObjcType = typename T::Boxed::ObjcType;
public:
using CppType = std::vector<ECppType>;
using ObjcType = NSArray*;
using Boxed = List;
static CppType toCpp(ObjcType array) {
assert(array);
auto v = CppType();
v.reserve(array.count);
for(EObjcType value in array)
v.push_back(T::Boxed::toCpp(value));
return v;
}
static ObjcType fromCpp(const CppType& v) {
assert(v.size() <= std::numeric_limits<NSUInteger>::max());
auto array = [NSMutableArray arrayWithCapacity:static_cast<NSUInteger>(v.size())];
for(const auto& value : v) {
[array addObject:T::Boxed::fromCpp(value)];
}
return array;
}
};
template<class T>
class Set {
using ECppType = typename T::CppType;
using EObjcType = typename T::Boxed::ObjcType;
public:
using CppType = std::unordered_set<ECppType>;
using ObjcType = NSSet*;
using Boxed = Set;
static CppType toCpp(ObjcType set) {
assert(set);
auto s = CppType();
for(EObjcType value in set) {
s.insert(T::Boxed::toCpp(value));
}
return s;
}
static ObjcType fromCpp(const CppType& s) {
assert(s.size() <= std::numeric_limits<NSUInteger>::max());
auto set = [NSMutableSet setWithCapacity:static_cast<NSUInteger>(s.size())];
for(const auto& value : s) {
[set addObject:T::Boxed::fromCpp(value)];
}
return set;
}
};
template<class Key, class Value>
class Map {
using CppKeyType = typename Key::CppType;
using CppValueType = typename Value::CppType;
using ObjcKeyType = typename Key::Boxed::ObjcType;
using ObjcValueType = typename Value::Boxed::ObjcType;
public:
using CppType = std::unordered_map<CppKeyType, CppValueType>;
using ObjcType = NSDictionary*;
using Boxed = Map;
static CppType toCpp(ObjcType map) {
assert(map);
__block auto m = CppType();
m.reserve(map.count);
[map enumerateKeysAndObjectsUsingBlock:^(ObjcKeyType key, ObjcValueType obj, BOOL *) {
m.emplace(Key::Boxed::toCpp(key), Value::Boxed::toCpp(obj));
}];
return m;
}
static ObjcType fromCpp(const CppType& m) {
assert(m.size() <= std::numeric_limits<NSUInteger>::max());
auto map = [NSMutableDictionary dictionaryWithCapacity:static_cast<NSUInteger>(m.size())];
for(const auto& kvp : m) {
[map setObject:Value::Boxed::fromCpp(kvp.second) forKey:Key::Boxed::fromCpp(kvp.first)];
}
return map;
}
};
} // namespace djinni } // namespace djinni
...@@ -14,80 +14,26 @@ namespace djinni_generated { ...@@ -14,80 +14,26 @@ namespace djinni_generated {
auto AssortedIntegers::toCpp(ObjcType obj) -> CppType auto AssortedIntegers::toCpp(ObjcType obj) -> CppType
{ {
assert(obj); assert(obj);
int8_t eight = ::djinni::I8::toCpp(obj.eight); return {::djinni::I8::toCpp(obj.eight),
int16_t sixteen = ::djinni::I16::toCpp(obj.sixteen); ::djinni::I16::toCpp(obj.sixteen),
int32_t thirtytwo = ::djinni::I32::toCpp(obj.thirtytwo); ::djinni::I32::toCpp(obj.thirtytwo),
int64_t sixtyfour = ::djinni::I64::toCpp(obj.sixtyfour); ::djinni::I64::toCpp(obj.sixtyfour),
std::experimental::optional<int8_t> o_eight; ::djinni::Optional<std::experimental::optional, ::djinni::I8>::toCpp(obj.oEight),
if (obj.oEight != nil) { ::djinni::Optional<std::experimental::optional, ::djinni::I16>::toCpp(obj.oSixteen),
int8_t optValue = ::djinni::I8::Boxed::toCpp(obj.oEight); ::djinni::Optional<std::experimental::optional, ::djinni::I32>::toCpp(obj.oThirtytwo),
o_eight = optValue; ::djinni::Optional<std::experimental::optional, ::djinni::I64>::toCpp(obj.oSixtyfour)};
}
std::experimental::optional<int16_t> o_sixteen;
if (obj.oSixteen != nil) {
int16_t optValue = ::djinni::I16::Boxed::toCpp(obj.oSixteen);
o_sixteen = optValue;
}
std::experimental::optional<int32_t> o_thirtytwo;
if (obj.oThirtytwo != nil) {
int32_t optValue = ::djinni::I32::Boxed::toCpp(obj.oThirtytwo);
o_thirtytwo = optValue;
}
std::experimental::optional<int64_t> o_sixtyfour;
if (obj.oSixtyfour != nil) {
int64_t optValue = ::djinni::I64::Boxed::toCpp(obj.oSixtyfour);
o_sixtyfour = optValue;
}
return ::AssortedIntegers(
eight,
sixteen,
thirtytwo,
sixtyfour,
o_eight,
o_sixteen,
o_thirtytwo,
o_sixtyfour);
} }
auto AssortedIntegers::fromCpp(const CppType& cpp) -> ObjcType auto AssortedIntegers::fromCpp(const CppType& cpp) -> ObjcType
{ {
int8_t eight = ::djinni::I8::fromCpp(cpp.eight); return [[DBAssortedIntegers alloc] initWithEight:(::djinni::I8::fromCpp(cpp.eight))
int16_t sixteen = ::djinni::I16::fromCpp(cpp.sixteen); sixteen:(::djinni::I16::fromCpp(cpp.sixteen))
int32_t thirtytwo = ::djinni::I32::fromCpp(cpp.thirtytwo); thirtytwo:(::djinni::I32::fromCpp(cpp.thirtytwo))
int64_t sixtyfour = ::djinni::I64::fromCpp(cpp.sixtyfour); sixtyfour:(::djinni::I64::fromCpp(cpp.sixtyfour))
NSNumber *oEight; oEight:(::djinni::Optional<std::experimental::optional, ::djinni::I8>::fromCpp(cpp.o_eight))
if (cpp.o_eight) { oSixteen:(::djinni::Optional<std::experimental::optional, ::djinni::I16>::fromCpp(cpp.o_sixteen))
oEight = ::djinni::I8::Boxed::fromCpp((*(cpp.o_eight))); oThirtytwo:(::djinni::Optional<std::experimental::optional, ::djinni::I32>::fromCpp(cpp.o_thirtytwo))
} else { oSixtyfour:(::djinni::Optional<std::experimental::optional, ::djinni::I64>::fromCpp(cpp.o_sixtyfour))];
oEight = nil;
}
NSNumber *oSixteen;
if (cpp.o_sixteen) {
oSixteen = ::djinni::I16::Boxed::fromCpp((*(cpp.o_sixteen)));
} else {
oSixteen = nil;
}
NSNumber *oThirtytwo;
if (cpp.o_thirtytwo) {
oThirtytwo = ::djinni::I32::Boxed::fromCpp((*(cpp.o_thirtytwo)));
} else {
oThirtytwo = nil;
}
NSNumber *oSixtyfour;
if (cpp.o_sixtyfour) {
oSixtyfour = ::djinni::I64::Boxed::fromCpp((*(cpp.o_sixtyfour)));
} else {
oSixtyfour = nil;
}
return [[DBAssortedIntegers alloc]
initWithEight:eight
sixteen:sixteen
thirtytwo:thirtytwo
sixtyfour:sixtyfour
oEight:oEight
oSixteen:oSixteen
oThirtytwo:oThirtytwo
oSixtyfour:oSixtyfour];
} }
} // namespace djinni_generated } // namespace djinni_generated
...@@ -5,7 +5,14 @@ ...@@ -5,7 +5,14 @@
@interface DBAssortedIntegers : NSObject @interface DBAssortedIntegers : NSObject
- (id)initWithAssortedIntegers:(DBAssortedIntegers *)assortedIntegers; - (id)initWithAssortedIntegers:(DBAssortedIntegers *)assortedIntegers;
- (id)initWithEight:(int8_t)eight sixteen:(int16_t)sixteen thirtytwo:(int32_t)thirtytwo sixtyfour:(int64_t)sixtyfour oEight:(NSNumber *)oEight oSixteen:(NSNumber *)oSixteen oThirtytwo:(NSNumber *)oThirtytwo oSixtyfour:(NSNumber *)oSixtyfour; - (id)initWithEight:(int8_t)eight
sixteen:(int16_t)sixteen
thirtytwo:(int32_t)thirtytwo
sixtyfour:(int64_t)sixtyfour
oEight:(NSNumber *)oEight
oSixteen:(NSNumber *)oSixteen
oThirtytwo:(NSNumber *)oThirtytwo
oSixtyfour:(NSNumber *)oSixtyfour;
@property (nonatomic, readonly) int8_t eight; @property (nonatomic, readonly) int8_t eight;
......
...@@ -37,7 +37,14 @@ ...@@ -37,7 +37,14 @@
return self; return self;
} }
- (id)initWithEight:(int8_t)eight sixteen:(int16_t)sixteen thirtytwo:(int32_t)thirtytwo sixtyfour:(int64_t)sixtyfour oEight:(NSNumber *)oEight oSixteen:(NSNumber *)oSixteen oThirtytwo:(NSNumber *)oThirtytwo oSixtyfour:(NSNumber *)oSixtyfour - (id)initWithEight:(int8_t)eight
sixteen:(int16_t)sixteen
thirtytwo:(int32_t)thirtytwo
sixtyfour:(int64_t)sixtyfour
oEight:(NSNumber *)oEight
oSixteen:(NSNumber *)oSixteen
oThirtytwo:(NSNumber *)oThirtytwo
oSixtyfour:(NSNumber *)oSixtyfour
{ {
if (self = [super init]) { if (self = [super init]) {
_eight = eight; _eight = eight;
......
...@@ -10,13 +10,19 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th ...@@ -10,13 +10,19 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th
namespace djinni_generated { namespace djinni_generated {
struct ClientInterface class ClientInterface
{ {
public:
using CppType = std::shared_ptr<::ClientInterface>; using CppType = std::shared_ptr<::ClientInterface>;
using ObjcType = id<DBClientInterface>; using ObjcType = id<DBClientInterface>;
using Boxed = ClientInterface;
static CppType toCpp(ObjcType objc); static CppType toCpp(ObjcType objc);
static ObjcType fromCpp(const CppType& cpp); static ObjcType fromCpp(const CppType& cpp);
private:
class ObjcProxy;
}; };
} // namespace djinni_generated } // namespace djinni_generated
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
@protocol DBClientInterface @protocol DBClientInterface
/** Returns record of given string */ /** Returns record of given string */
- (DBClientReturnedRecord *)getRecord:(int64_t)recordId utf8string:(NSString *)utf8string; - (DBClientReturnedRecord *)getRecord:(int64_t)recordId
utf8string:(NSString *)utf8string;
@end @end
...@@ -10,21 +10,24 @@ ...@@ -10,21 +10,24 @@
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");
namespace { // anonymous namespace namespace djinni_generated {
class ObjcProxy final class ClientInterface::ObjcProxy final
: public ::ClientInterface : public ::ClientInterface
, public ::djinni::DbxObjcWrapperCache<ObjcProxy>::Handle , public ::djinni::DbxObjcWrapperCache<ObjcProxy>::Handle
{ {
public: public:
using Handle::Handle; using Handle::Handle;
::ClientReturnedRecord get_record (int64_t record_id, const std::string & utf8string) override; ::ClientReturnedRecord get_record(int64_t record_id, const std::string & utf8string) override
{
@autoreleasepool {
auto r = [Handle::get() getRecord:(::djinni::I64::fromCpp(record_id))
utf8string:(::djinni::String::fromCpp(utf8string))];
return ::djinni_generated::ClientReturnedRecord::toCpp(r);
}
}
}; };
} // end anonymous namespace
namespace djinni_generated {
auto ClientInterface::toCpp(ObjcType objc) -> CppType auto ClientInterface::toCpp(ObjcType objc) -> CppType
{ {
return objc ? djinni::DbxObjcWrapperCache<ObjcProxy>::getInstance()->get(objc) : nullptr; return objc ? djinni::DbxObjcWrapperCache<ObjcProxy>::getInstance()->get(objc) : nullptr;
...@@ -37,14 +40,3 @@ auto ClientInterface::fromCpp(const CppType& cpp) -> ObjcType ...@@ -37,14 +40,3 @@ auto ClientInterface::fromCpp(const CppType& cpp) -> ObjcType
} }
} // namespace djinni_generated } // namespace djinni_generated
::ClientReturnedRecord ObjcProxy::get_record (int64_t record_id, const std::string & utf8string)
{
@autoreleasepool {
int64_t cpp_record_id = ::djinni::I64::fromCpp(record_id);
NSString *cpp_utf8string = ::djinni::String::fromCpp(utf8string);
DBClientReturnedRecord * objcRet = [Handle::get() getRecord:cpp_record_id utf8string:cpp_utf8string];
::ClientReturnedRecord cppRet = ::djinni_generated::ClientReturnedRecord::toCpp(objcRet);
return cppRet;
}
}
...@@ -14,20 +14,14 @@ namespace djinni_generated { ...@@ -14,20 +14,14 @@ namespace djinni_generated {
auto ClientReturnedRecord::toCpp(ObjcType obj) -> CppType auto ClientReturnedRecord::toCpp(ObjcType obj) -> CppType
{ {
assert(obj); assert(obj);
int64_t record_id = ::djinni::I64::toCpp(obj.recordId); return {::djinni::I64::toCpp(obj.recordId),
std::string content = ::djinni::String::toCpp(obj.content); ::djinni::String::toCpp(obj.content)};
return ::ClientReturnedRecord(
record_id,
content);
} }
auto ClientReturnedRecord::fromCpp(const CppType& cpp) -> ObjcType auto ClientReturnedRecord::fromCpp(const CppType& cpp) -> ObjcType
{ {
int64_t recordId = ::djinni::I64::fromCpp(cpp.record_id); return [[DBClientReturnedRecord alloc] initWithRecordId:(::djinni::I64::fromCpp(cpp.record_id))
NSString *content = ::djinni::String::fromCpp(cpp.content); content:(::djinni::String::fromCpp(cpp.content))];
return [[DBClientReturnedRecord alloc]
initWithRecordId:recordId
content:content];
} }
} // namespace djinni_generated } // namespace djinni_generated
...@@ -5,7 +5,8 @@ ...@@ -5,7 +5,8 @@
@interface DBClientReturnedRecord : NSObject @interface DBClientReturnedRecord : NSObject
- (id)initWithClientReturnedRecord:(DBClientReturnedRecord *)clientReturnedRecord; - (id)initWithClientReturnedRecord:(DBClientReturnedRecord *)clientReturnedRecord;
- (id)initWithRecordId:(int64_t)recordId content:(NSString *)content; - (id)initWithRecordId:(int64_t)recordId
content:(NSString *)content;
@property (nonatomic, readonly) int64_t recordId; @property (nonatomic, readonly) int64_t recordId;
......
...@@ -15,7 +15,8 @@ ...@@ -15,7 +15,8 @@
return self; return self;
} }
- (id)initWithRecordId:(int64_t)recordId content:(NSString *)content - (id)initWithRecordId:(int64_t)recordId
content:(NSString *)content
{ {
if (self = [super init]) { if (self = [super init]) {
_recordId = recordId; _recordId = recordId;
......
...@@ -15,20 +15,14 @@ namespace djinni_generated { ...@@ -15,20 +15,14 @@ namespace djinni_generated {
auto Constants::toCpp(ObjcType obj) -> CppType auto Constants::toCpp(ObjcType obj) -> CppType
{ {
assert(obj); assert(obj);
int32_t some_integer = ::djinni::I32::toCpp(obj.someInteger); return {::djinni::I32::toCpp(obj.someInteger),
std::string some_string = ::djinni::String::toCpp(obj.someString); ::djinni::String::toCpp(obj.someString)};
return ::Constants(
some_integer,
some_string);
} }
auto Constants::fromCpp(const CppType& cpp) -> ObjcType auto Constants::fromCpp(const CppType& cpp) -> ObjcType
{ {
int32_t someInteger = ::djinni::I32::fromCpp(cpp.some_integer); return [[DBConstants alloc] initWithSomeInteger:(::djinni::I32::fromCpp(cpp.some_integer))
NSString *someString = ::djinni::String::fromCpp(cpp.some_string); someString:(::djinni::String::fromCpp(cpp.some_string))];
return [[DBConstants alloc]
initWithSomeInteger:someInteger
someString:someString];
} }
} // namespace djinni_generated } // namespace djinni_generated
...@@ -6,7 +6,8 @@ ...@@ -6,7 +6,8 @@
@interface DBConstants : NSObject @interface DBConstants : NSObject
- (id)initWithConstants:(DBConstants *)constants; - (id)initWithConstants:(DBConstants *)constants;
- (id)initWithSomeInteger:(int32_t)someInteger someString:(NSString *)someString; - (id)initWithSomeInteger:(int32_t)someInteger
someString:(NSString *)someString;
@property (nonatomic, readonly) int32_t someInteger; @property (nonatomic, readonly) int32_t someInteger;
......
...@@ -39,7 +39,8 @@ DBConstants * const DBConstantsObjectConstant = [[DBConstants alloc] initWithSom ...@@ -39,7 +39,8 @@ DBConstants * const DBConstantsObjectConstant = [[DBConstants alloc] initWithSom
return self; return self;
} }
- (id)initWithSomeInteger:(int32_t)someInteger someString:(NSString *)someString - (id)initWithSomeInteger:(int32_t)someInteger
someString:(NSString *)someString
{ {
if (self = [super init]) { if (self = [super init]) {
_someInteger = someInteger; _someInteger = someInteger;
......
...@@ -10,13 +10,19 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th ...@@ -10,13 +10,19 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th
namespace djinni_generated { namespace djinni_generated {
struct CppException class CppException
{ {
public:
using CppType = std::shared_ptr<::CppException>; using CppType = std::shared_ptr<::CppException>;
using ObjcType = DBCppException*; using ObjcType = DBCppException*;
using Boxed = CppException;
static CppType toCpp(ObjcType objc); static CppType toCpp(ObjcType objc);
static ObjcType fromCpp(const CppType& cpp); static ObjcType fromCpp(const CppType& cpp);
private:
class ObjcProxy;
}; };
} // namespace djinni_generated } // namespace djinni_generated
......
...@@ -51,17 +51,15 @@ auto CppException::fromCpp(const CppType& cpp) -> ObjcType ...@@ -51,17 +51,15 @@ auto CppException::fromCpp(const CppType& cpp) -> ObjcType
- (int32_t)throwAnException { - (int32_t)throwAnException {
try { try {
int32_t cppRet = _cppRef.get()->throw_an_exception(); auto r = _cppRef.get()->throw_an_exception();
int32_t objcRet = ::djinni::I32::fromCpp(cppRet); return ::djinni::I32::fromCpp(r);
return objcRet;
} DJINNI_TRANSLATE_EXCEPTIONS() } DJINNI_TRANSLATE_EXCEPTIONS()
} }
+ (DBCppException *)get { + (DBCppException *)get {
try { try {
std::shared_ptr<::CppException> cppRet = ::CppException::get(); auto r = ::CppException::get();
DBCppException* objcRet = ::djinni_generated::CppException::fromCpp(cppRet); return ::djinni_generated::CppException::fromCpp(r);
return objcRet;
} DJINNI_TRANSLATE_EXCEPTIONS() } DJINNI_TRANSLATE_EXCEPTIONS()
} }
......
...@@ -14,17 +14,12 @@ namespace djinni_generated { ...@@ -14,17 +14,12 @@ namespace djinni_generated {
auto DateRecord::toCpp(ObjcType obj) -> CppType auto DateRecord::toCpp(ObjcType obj) -> CppType
{ {
assert(obj); assert(obj);
std::chrono::system_clock::time_point created_at = ::djinni::convert_date([obj.createdAt timeIntervalSince1970]); return {::djinni::Date::toCpp(obj.createdAt)};
return ::DateRecord(
created_at);
} }
auto DateRecord::fromCpp(const CppType& cpp) -> ObjcType auto DateRecord::fromCpp(const CppType& cpp) -> ObjcType
{ {
NSDate *createdAt = [NSDate dateWithTimeIntervalSince1970: return [[DBDateRecord alloc] initWithCreatedAt:(::djinni::Date::fromCpp(cpp.created_at))];
std::chrono::duration_cast<std::chrono::duration<double>>(cpp.created_at.time_since_epoch()).count()];
return [[DBDateRecord alloc]
initWithCreatedAt:createdAt];
} }
} // namespace djinni_generated } // namespace djinni_generated
...@@ -14,32 +14,12 @@ namespace djinni_generated { ...@@ -14,32 +14,12 @@ namespace djinni_generated {
auto MapDateRecord::toCpp(ObjcType obj) -> CppType auto MapDateRecord::toCpp(ObjcType obj) -> CppType
{ {
assert(obj); assert(obj);
std::unordered_map<std::string, std::chrono::system_clock::time_point> dates_by_id; return {::djinni::Map<::djinni::String, ::djinni::Date>::toCpp(obj.datesById)};
for (id objcKey_0 in obj.datesById) {
std::string cppKey_0 = ::djinni::String::toCpp(objcKey_0);
std::chrono::system_clock::time_point cppValue_0 = ::djinni::convert_date([[obj.datesById objectForKey:objcKey_0] timeIntervalSince1970]);
dates_by_id.emplace(std::move(cppKey_0), std::move(cppValue_0));
}
return ::MapDateRecord(
dates_by_id);
} }
auto MapDateRecord::fromCpp(const CppType& cpp) -> ObjcType auto MapDateRecord::fromCpp(const CppType& cpp) -> ObjcType
{ {
std::vector<NSString *> datesByIdTempKeyVector; return [[DBMapDateRecord alloc] initWithDatesById:(::djinni::Map<::djinni::String, ::djinni::Date>::fromCpp(cpp.dates_by_id))];
datesByIdTempKeyVector.reserve(cpp.dates_by_id.size());
std::vector<NSDate *> datesByIdTempValueVector;
datesByIdTempValueVector.reserve(cpp.dates_by_id.size());
for (const auto & cppPair_0 : cpp.dates_by_id) {
NSString *objcKey_0 = ::djinni::String::fromCpp(cppPair_0.first);
NSDate *objcValue_0 = [NSDate dateWithTimeIntervalSince1970:
std::chrono::duration_cast<std::chrono::duration<double>>(cppPair_0.second.time_since_epoch()).count()];
datesByIdTempKeyVector.push_back(objcKey_0);
datesByIdTempValueVector.push_back(objcValue_0);
}
NSDictionary *datesById = [NSDictionary dictionaryWithObjects:&datesByIdTempValueVector[0] forKeys:&datesByIdTempKeyVector[0] count:cpp.dates_by_id.size()];
return [[DBMapDateRecord alloc]
initWithDatesById:datesById];
} }
} // namespace djinni_generated } // namespace djinni_generated
...@@ -14,42 +14,12 @@ namespace djinni_generated { ...@@ -14,42 +14,12 @@ namespace djinni_generated {
auto MapListRecord::toCpp(ObjcType obj) -> CppType auto MapListRecord::toCpp(ObjcType obj) -> CppType
{ {
assert(obj); assert(obj);
std::vector<std::unordered_map<std::string, int64_t>> map_list; return {::djinni::List<::djinni::Map<::djinni::String, ::djinni::I64>>::toCpp(obj.mapList)};
map_list.reserve([obj.mapList count]);
for (NSDictionary *objcValue_0 in obj.mapList) {
std::unordered_map<std::string, int64_t> cppValue_0;
for (id objcKey_1 in objcValue_0) {
std::string cppKey_1 = ::djinni::String::toCpp(objcKey_1);
int64_t cppValue_1 = ::djinni::I64::Boxed::toCpp([objcValue_0 objectForKey:objcKey_1]);
cppValue_0.emplace(std::move(cppKey_1), std::move(cppValue_1));
}
map_list.push_back(std::move(cppValue_0));
}
return ::MapListRecord(
map_list);
} }
auto MapListRecord::fromCpp(const CppType& cpp) -> ObjcType auto MapListRecord::fromCpp(const CppType& cpp) -> ObjcType
{ {
std::vector<NSDictionary *> mapListTempVector; return [[DBMapListRecord alloc] initWithMapList:(::djinni::List<::djinni::Map<::djinni::String, ::djinni::I64>>::fromCpp(cpp.map_list))];
mapListTempVector.reserve(cpp.map_list.size());
for (const auto & cppValue_0 : cpp.map_list) {
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) {
NSString *objcKey_1 = ::djinni::String::fromCpp(cppPair_1.first);
NSNumber *objcValue_1 = ::djinni::I64::Boxed::fromCpp(cppPair_1.second);
objcValue_0TempKeyVector.push_back(objcKey_1);
objcValue_0TempValueVector.push_back(objcValue_1);
}
NSDictionary *objcValue_0 = [NSDictionary dictionaryWithObjects:&objcValue_0TempValueVector[0] forKeys:&objcValue_0TempKeyVector[0] count:cppValue_0.size()];
mapListTempVector.push_back(objcValue_0);
}
NSArray *mapList = [NSArray arrayWithObjects:&mapListTempVector[0] count:mapListTempVector.size()];
return [[DBMapListRecord alloc]
initWithMapList:mapList];
} }
} // namespace djinni_generated } // namespace djinni_generated
...@@ -14,31 +14,12 @@ namespace djinni_generated { ...@@ -14,31 +14,12 @@ namespace djinni_generated {
auto MapRecord::toCpp(ObjcType obj) -> CppType auto MapRecord::toCpp(ObjcType obj) -> CppType
{ {
assert(obj); assert(obj);
std::unordered_map<std::string, int64_t> map; return {::djinni::Map<::djinni::String, ::djinni::I64>::toCpp(obj.map)};
for (id objcKey_0 in obj.map) {
std::string cppKey_0 = ::djinni::String::toCpp(objcKey_0);
int64_t cppValue_0 = ::djinni::I64::Boxed::toCpp([obj.map objectForKey:objcKey_0]);
map.emplace(std::move(cppKey_0), std::move(cppValue_0));
}
return ::MapRecord(
map);
} }
auto MapRecord::fromCpp(const CppType& cpp) -> ObjcType auto MapRecord::fromCpp(const CppType& cpp) -> ObjcType
{ {
std::vector<NSString *> mapTempKeyVector; return [[DBMapRecord alloc] initWithMap:(::djinni::Map<::djinni::String, ::djinni::I64>::fromCpp(cpp.map))];
mapTempKeyVector.reserve(cpp.map.size());
std::vector<NSNumber *> mapTempValueVector;
mapTempValueVector.reserve(cpp.map.size());
for (const auto & cppPair_0 : cpp.map) {
NSString *objcKey_0 = ::djinni::String::fromCpp(cppPair_0.first);
NSNumber *objcValue_0 = ::djinni::I64::Boxed::fromCpp(cppPair_0.second);
mapTempKeyVector.push_back(objcKey_0);
mapTempValueVector.push_back(objcValue_0);
}
NSDictionary *map = [NSDictionary dictionaryWithObjects:&mapTempValueVector[0] forKeys:&mapTempKeyVector[0] count:cpp.map.size()];
return [[DBMapRecord alloc]
initWithMap:map];
} }
} // namespace djinni_generated } // namespace djinni_generated
...@@ -14,37 +14,12 @@ namespace djinni_generated { ...@@ -14,37 +14,12 @@ namespace djinni_generated {
auto NestedCollection::toCpp(ObjcType obj) -> CppType auto NestedCollection::toCpp(ObjcType obj) -> CppType
{ {
assert(obj); assert(obj);
std::vector<std::unordered_set<std::string>> set_list; return {::djinni::List<::djinni::Set<::djinni::String>>::toCpp(obj.setList)};
set_list.reserve([obj.setList count]);
for (NSSet *objcValue_0 in obj.setList) {
std::unordered_set<std::string> cppValue_0;
for (NSString *objcValue_1 in objcValue_0) {
std::string cppValue_1 = ::djinni::String::toCpp(objcValue_1);
cppValue_0.insert(std::move(cppValue_1));
}
set_list.push_back(std::move(cppValue_0));
}
return ::NestedCollection(
set_list);
} }
auto NestedCollection::fromCpp(const CppType& cpp) -> ObjcType auto NestedCollection::fromCpp(const CppType& cpp) -> ObjcType
{ {
std::vector<NSSet *> setListTempVector; return [[DBNestedCollection alloc] initWithSetList:(::djinni::List<::djinni::Set<::djinni::String>>::fromCpp(cpp.set_list))];
setListTempVector.reserve(cpp.set_list.size());
for (const auto & cppValue_0 : cpp.set_list) {
std::vector<NSString *> objcValue_0TempVector;
objcValue_0TempVector.reserve(cppValue_0.size());
for (const auto & cppValue_1 : cppValue_0) {
NSString *objcValue_1 = ::djinni::String::fromCpp(cppValue_1);
objcValue_0TempVector.push_back(objcValue_1);
}
NSSet *objcValue_0 = [NSSet setWithObjects:&objcValue_0TempVector[0] count:objcValue_0TempVector.size()];
setListTempVector.push_back(objcValue_0);
}
NSArray *setList = [NSArray arrayWithObjects:&setListTempVector[0] count:setListTempVector.size()];
return [[DBNestedCollection alloc]
initWithSetList:setList];
} }
} // namespace djinni_generated } // namespace djinni_generated
...@@ -14,27 +14,12 @@ namespace djinni_generated { ...@@ -14,27 +14,12 @@ namespace djinni_generated {
auto PrimitiveList::toCpp(ObjcType obj) -> CppType auto PrimitiveList::toCpp(ObjcType obj) -> CppType
{ {
assert(obj); assert(obj);
std::vector<int64_t> list; return {::djinni::List<::djinni::I64>::toCpp(obj.list)};
list.reserve([obj.list count]);
for (NSNumber *objcValue_0 in obj.list) {
int64_t cppValue_0 = ::djinni::I64::Boxed::toCpp(objcValue_0);
list.push_back(std::move(cppValue_0));
}
return ::PrimitiveList(
list);
} }
auto PrimitiveList::fromCpp(const CppType& cpp) -> ObjcType auto PrimitiveList::fromCpp(const CppType& cpp) -> ObjcType
{ {
std::vector<NSNumber *> listTempVector; return [[DBPrimitiveList alloc] initWithList:(::djinni::List<::djinni::I64>::fromCpp(cpp.list))];
listTempVector.reserve(cpp.list.size());
for (const auto & cppValue_0 : cpp.list) {
NSNumber *objcValue_0 = ::djinni::I64::Boxed::fromCpp(cppValue_0);
listTempVector.push_back(objcValue_0);
}
NSArray *list = [NSArray arrayWithObjects:&listTempVector[0] count:listTempVector.size()];
return [[DBPrimitiveList alloc]
initWithList:list];
} }
} // namespace djinni_generated } // namespace djinni_generated
...@@ -14,20 +14,14 @@ namespace djinni_generated { ...@@ -14,20 +14,14 @@ namespace djinni_generated {
auto RecordWithDerivings::toCpp(ObjcType obj) -> CppType auto RecordWithDerivings::toCpp(ObjcType obj) -> CppType
{ {
assert(obj); assert(obj);
int32_t key1 = ::djinni::I32::toCpp(obj.key1); return {::djinni::I32::toCpp(obj.key1),
std::string key2 = ::djinni::String::toCpp(obj.key2); ::djinni::String::toCpp(obj.key2)};
return ::RecordWithDerivings(
key1,
key2);
} }
auto RecordWithDerivings::fromCpp(const CppType& cpp) -> ObjcType auto RecordWithDerivings::fromCpp(const CppType& cpp) -> ObjcType
{ {
int32_t key1 = ::djinni::I32::fromCpp(cpp.key1); return [[DBRecordWithDerivings alloc] initWithKey1:(::djinni::I32::fromCpp(cpp.key1))
NSString *key2 = ::djinni::String::fromCpp(cpp.key2); key2:(::djinni::String::fromCpp(cpp.key2))];
return [[DBRecordWithDerivings alloc]
initWithKey1:key1
key2:key2];
} }
} // namespace djinni_generated } // namespace djinni_generated
...@@ -5,7 +5,8 @@ ...@@ -5,7 +5,8 @@
@interface DBRecordWithDerivings : NSObject @interface DBRecordWithDerivings : NSObject
- (id)initWithRecordWithDerivings:(DBRecordWithDerivings *)recordWithDerivings; - (id)initWithRecordWithDerivings:(DBRecordWithDerivings *)recordWithDerivings;
- (id)initWithKey1:(int32_t)key1 key2:(NSString *)key2; - (id)initWithKey1:(int32_t)key1
key2:(NSString *)key2;
@property (nonatomic, readonly) int32_t key1; @property (nonatomic, readonly) int32_t key1;
......
...@@ -15,7 +15,8 @@ ...@@ -15,7 +15,8 @@
return self; return self;
} }
- (id)initWithKey1:(int32_t)key1 key2:(NSString *)key2 - (id)initWithKey1:(int32_t)key1
key2:(NSString *)key2
{ {
if (self = [super init]) { if (self = [super init]) {
_key1 = key1; _key1 = key1;
......
...@@ -15,20 +15,14 @@ namespace djinni_generated { ...@@ -15,20 +15,14 @@ namespace djinni_generated {
auto RecordWithNestedDerivings::toCpp(ObjcType obj) -> CppType auto RecordWithNestedDerivings::toCpp(ObjcType obj) -> CppType
{ {
assert(obj); assert(obj);
int32_t key = ::djinni::I32::toCpp(obj.key); return {::djinni::I32::toCpp(obj.key),
::RecordWithDerivings rec = ::djinni_generated::RecordWithDerivings::toCpp(obj.rec); ::djinni_generated::RecordWithDerivings::toCpp(obj.rec)};
return ::RecordWithNestedDerivings(
key,
rec);
} }
auto RecordWithNestedDerivings::fromCpp(const CppType& cpp) -> ObjcType auto RecordWithNestedDerivings::fromCpp(const CppType& cpp) -> ObjcType
{ {
int32_t key = ::djinni::I32::fromCpp(cpp.key); return [[DBRecordWithNestedDerivings alloc] initWithKey:(::djinni::I32::fromCpp(cpp.key))
DBRecordWithDerivings *rec = ::djinni_generated::RecordWithDerivings::fromCpp(cpp.rec); rec:(::djinni_generated::RecordWithDerivings::fromCpp(cpp.rec))];
return [[DBRecordWithNestedDerivings alloc]
initWithKey:key
rec:rec];
} }
} // namespace djinni_generated } // namespace djinni_generated
...@@ -6,7 +6,8 @@ ...@@ -6,7 +6,8 @@
@interface DBRecordWithNestedDerivings : NSObject @interface DBRecordWithNestedDerivings : NSObject
- (id)initWithRecordWithNestedDerivings:(DBRecordWithNestedDerivings *)recordWithNestedDerivings; - (id)initWithRecordWithNestedDerivings:(DBRecordWithNestedDerivings *)recordWithNestedDerivings;
- (id)initWithKey:(int32_t)key rec:(DBRecordWithDerivings *)rec; - (id)initWithKey:(int32_t)key
rec:(DBRecordWithDerivings *)rec;
@property (nonatomic, readonly) int32_t key; @property (nonatomic, readonly) int32_t key;
......
...@@ -16,7 +16,8 @@ ...@@ -16,7 +16,8 @@
return self; return self;
} }
- (id)initWithKey:(int32_t)key rec:(DBRecordWithDerivings *)rec - (id)initWithKey:(int32_t)key
rec:(DBRecordWithDerivings *)rec
{ {
if (self = [super init]) { if (self = [super init]) {
_key = key; _key = key;
......
...@@ -14,26 +14,12 @@ namespace djinni_generated { ...@@ -14,26 +14,12 @@ namespace djinni_generated {
auto SetRecord::toCpp(ObjcType obj) -> CppType auto SetRecord::toCpp(ObjcType obj) -> CppType
{ {
assert(obj); assert(obj);
std::unordered_set<std::string> set; return {::djinni::Set<::djinni::String>::toCpp(obj.set)};
for (NSString *objcValue_0 in obj.set) {
std::string cppValue_0 = ::djinni::String::toCpp(objcValue_0);
set.insert(std::move(cppValue_0));
}
return ::SetRecord(
set);
} }
auto SetRecord::fromCpp(const CppType& cpp) -> ObjcType auto SetRecord::fromCpp(const CppType& cpp) -> ObjcType
{ {
std::vector<NSString *> setTempVector; return [[DBSetRecord alloc] initWithSet:(::djinni::Set<::djinni::String>::fromCpp(cpp.set))];
setTempVector.reserve(cpp.set.size());
for (const auto & cppValue_0 : cpp.set) {
NSString *objcValue_0 = ::djinni::String::fromCpp(cppValue_0);
setTempVector.push_back(objcValue_0);
}
NSSet *set = [NSSet setWithObjects:&setTempVector[0] count:setTempVector.size()];
return [[DBSetRecord alloc]
initWithSet:set];
} }
} // namespace djinni_generated } // namespace djinni_generated
...@@ -10,13 +10,19 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th ...@@ -10,13 +10,19 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th
namespace djinni_generated { namespace djinni_generated {
struct TestHelpers class TestHelpers
{ {
public:
using CppType = std::shared_ptr<::TestHelpers>; using CppType = std::shared_ptr<::TestHelpers>;
using ObjcType = DBTestHelpers*; using ObjcType = DBTestHelpers*;
using Boxed = TestHelpers;
static CppType toCpp(ObjcType objc); static CppType toCpp(ObjcType objc);
static ObjcType fromCpp(const CppType& cpp); static ObjcType fromCpp(const CppType& cpp);
private:
class ObjcProxy;
}; };
} // namespace djinni_generated } // namespace djinni_generated
......
...@@ -10,13 +10,19 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th ...@@ -10,13 +10,19 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th
namespace djinni_generated { namespace djinni_generated {
struct Token class Token
{ {
public:
using CppType = std::shared_ptr<::Token>; using CppType = std::shared_ptr<::Token>;
using ObjcType = DBToken*; using ObjcType = DBToken*;
using Boxed = Token;
static CppType toCpp(ObjcType objc); static CppType toCpp(ObjcType objc);
static ObjcType fromCpp(const CppType& cpp); static ObjcType fromCpp(const CppType& cpp);
private:
class ObjcProxy;
}; };
} // namespace djinni_generated } // namespace djinni_generated
......
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