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

Refactored interface code generation to utilize translation types like JNI does

parent 0807100b
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from example.djinni
#import "TXSSortItems.h"
#include "sort_items.hpp"
#import <Foundation/Foundation.h>
#include <memory>
@interface TXSSortItems ()
static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file");
@property (nonatomic, readonly) std::shared_ptr<::textsort::SortItems> cppRef;
@class TXSSortItems;
+ (id)sortItemsWithCpp:(const std::shared_ptr<::textsort::SortItems> &)cppRef;
namespace djinni_generated {
struct SortItems
{
using CppType = std::shared_ptr<::textsort::SortItems>;
using ObjcType = TXSSortItems*;
static CppType toCpp(ObjcType objc);
static ObjcType fromCpp(const CppType& cpp);
};
} // namespace djinni_generated
@end
......@@ -2,15 +2,14 @@
// This file generated by Djinni from example.djinni
#import "TXSSortItems+Private.h"
#import "TXSSortItems.h"
#import "DJICppWrapperCache+Private.h"
#import "DJIDate.h"
#import "DJIError.h"
#import "DJIMarshal+Private.h"
#import "TXSItemList+Private.h"
#import "TXSSortItems+Private.h"
#import "TXSSortItems.h"
#import "TXSSortOrder.h"
#import "TXSTextboxListenerObjcProxy+Private.h"
#import "TXSTextboxListener+Private.h"
#include <exception>
#include <utility>
#include <vector>
......@@ -18,44 +17,53 @@
static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file");
@interface TXSSortItems ()
@property (nonatomic, readonly) std::shared_ptr<djinni::DbxCppWrapperCache<::textsort::SortItems>> cache;
@property (nonatomic, readonly) djinni::DbxCppWrapperCache<::textsort::SortItems>::Handle cppRef;
- (id)initWithCpp:(const std::shared_ptr<::textsort::SortItems>&)cppRef;
@end
@implementation TXSSortItems
namespace djinni_generated {
- (id)initWithCpp:(const std::shared_ptr<::textsort::SortItems> &)cppRef cache:(const std::shared_ptr<djinni::DbxCppWrapperCache<::textsort::SortItems>> &)cache
auto SortItems::toCpp(ObjcType objc) -> CppType
{
if (self = [super init]) {
_cppRef = cppRef;
_cache = cache;
}
return self;
return objc ? objc.cppRef.get() : nullptr;
}
- (void)dealloc
auto SortItems::fromCpp(const CppType& cpp) -> ObjcType
{
_cache->remove(_cppRef);
return !cpp ? nil : djinni::DbxCppWrapperCache<::textsort::SortItems>::getInstance()->get(cpp, [] (const auto& p)
{
return [[TXSSortItems alloc] initWithCpp:p];
});
}
+ (id)sortItemsWithCpp:(const std::shared_ptr<::textsort::SortItems> &)cppRef
} // namespace djinni_generated
@implementation TXSSortItems
- (id)initWithCpp:(const std::shared_ptr<::textsort::SortItems>&)cppRef
{
const auto & cache = djinni::DbxCppWrapperCache<::textsort::SortItems>::getInstance();
return cache->get(cppRef, [&] (const std::shared_ptr<::textsort::SortItems> & p) { return [[TXSSortItems alloc] initWithCpp:p cache:cache]; });
if (self = [super init]) {
_cppRef.assign(cppRef);
}
return self;
}
- (void)sort:(TXSSortOrder)order items:(TXSItemList *)items {
try {
::textsort::sort_order cppOrder = ::djinni::Enum<::textsort::sort_order, TXSSortOrder>::toCpp(order);
::textsort::ItemList cppItems = std::move([items cppItemList]);
_cppRef->sort(std::move(cppOrder), std::move(cppItems));
_cppRef.get()->sort(std::move(cppOrder), std::move(cppItems));
} DJINNI_TRANSLATE_EXCEPTIONS()
}
+ (TXSSortItems *)createWithListener:(id<TXSTextboxListener>)listener {
try {
std::shared_ptr<::textsort::TextboxListener> cppListener = ::djinni_generated::TextboxListenerObjcProxy::textbox_listener_with_objc(listener);
std::shared_ptr<::textsort::TextboxListener> cppListener = ::djinni_generated::TextboxListener::toCpp(listener);
std::shared_ptr<::textsort::SortItems> cppRet = ::textsort::SortItems::create_with_listener(std::move(cppListener));
TXSSortItems* objcRet = [TXSSortItems sortItemsWithCpp:cppRet];
TXSSortItems* objcRet = ::djinni_generated::SortItems::fromCpp(cppRet);
return objcRet;
} DJINNI_TRANSLATE_EXCEPTIONS()
}
......
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from example.djinni
#include "textbox_listener.hpp"
#include <memory>
static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file");
@protocol TXSTextboxListener;
namespace djinni_generated {
struct TextboxListener
{
using CppType = std::shared_ptr<::textsort::TextboxListener>;
using ObjcType = id<TXSTextboxListener>;
static CppType toCpp(ObjcType objc);
static ObjcType fromCpp(const CppType& cpp);
};
} // namespace djinni_generated
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from example.djinni
#import "TXSTextboxListener+Private.h"
#import "TXSTextboxListener.h"
#import "DJIObjcWrapperCache+Private.h"
#import "TXSItemList+Private.h"
#include <vector>
static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file");
namespace { // anonymous namespace
class ObjcProxy final
: public ::textsort::TextboxListener
, public ::djinni::DbxObjcWrapperCache<ObjcProxy>::Handle
{
public:
using Handle::Handle;
void update (const ::textsort::ItemList & items) override;
};
} // end anonymous namespace
namespace djinni_generated {
auto TextboxListener::toCpp(ObjcType objc) -> CppType
{
return objc ? djinni::DbxObjcWrapperCache<ObjcProxy>::getInstance()->get(objc) : nullptr;
}
auto TextboxListener::fromCpp(const CppType& cpp) -> ObjcType
{
assert(!cpp || dynamic_cast<ObjcProxy*>(cpp.get()));
return cpp ? static_cast<ObjcProxy&>(*cpp).Handle::get() : nil;
}
} // namespace djinni_generated
void ObjcProxy::update (const ::textsort::ItemList & items)
{
@autoreleasepool {
TXSItemList *cpp_items = [[TXSItemList alloc] initWithCppItemList:items];
[Handle::get() update:cpp_items];
}
}
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from example.djinni
#import "TXSTextboxListener.h"
#include "textbox_listener.hpp"
#import "DJIObjcWrapperCache+Private.h"
#import <Foundation/Foundation.h>
#include <memory>
namespace djinni_generated {
class TextboxListenerObjcProxy final : public ::textsort::TextboxListener
{
public:
const id <TXSTextboxListener> _objcRef;
const std::shared_ptr<djinni::DbxObjcWrapperCache<TextboxListenerObjcProxy>> _cache;
explicit TextboxListenerObjcProxy (id objcRef);
virtual ~TextboxListenerObjcProxy () override;
static std::shared_ptr<::textsort::TextboxListener> textbox_listener_with_objc (id<TXSTextboxListener> objcRef);
virtual void update (const ::textsort::ItemList & items) override;
};
} // namespace djinni_generated
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from example.djinni
#import "TXSTextboxListenerObjcProxy+Private.h"
#import "TXSItemList+Private.h"
#import "TXSTextboxListener.h"
#include <vector>
namespace djinni_generated {
TextboxListenerObjcProxy::TextboxListenerObjcProxy (id objcRef)
: _objcRef((assert([[objcRef class] conformsToProtocol:@protocol(TXSTextboxListener)]), objcRef)),
_cache(djinni::DbxObjcWrapperCache<TextboxListenerObjcProxy>::getInstance())
{}
TextboxListenerObjcProxy::~TextboxListenerObjcProxy ()
{
_cache->remove(_objcRef);
}
std::shared_ptr<::textsort::TextboxListener> TextboxListenerObjcProxy::textbox_listener_with_objc (id<TXSTextboxListener> objcRef)
{
return djinni::DbxObjcWrapperCache<TextboxListenerObjcProxy>::getInstance()->get(objcRef);
}
void TextboxListenerObjcProxy::update (const ::textsort::ItemList & items)
{
@autoreleasepool {
TXSItemList *cpp_items = [[TXSItemList alloc] initWithCppItemList:items];
[_objcRef update:cpp_items];
}
}
} // namespace djinni_generated
This diff is collapsed.
......@@ -225,6 +225,14 @@ abstract class Generator(spec: Spec)
}
}
def wrapAnonymousNamespace(w: IndentWriter, f: IndentWriter => Unit) {
w.wl("namespace { // anonymous namespace")
w.wl
f(w)
w.wl
w.wl("} // end anonymous namespace")
}
def writeHppFileGeneric(folder: File, namespace: Option[String], fileIdentStyle: IdentConverter)(name: String, origin: String, includes: Iterable[String], fwds: Iterable[String], f: IndentWriter => Unit, f2: IndentWriter => Unit) {
createFile(folder, fileIdentStyle(name) + "." + spec.cppHeaderExt, (w: IndentWriter) => {
w.wl("// AUTOGENERATED FILE - DO NOT MODIFY!")
......
......@@ -60,6 +60,22 @@ public:
}
}
class Handle {
public:
Handle() = default;
~Handle() {
if (_ptr) {
_cache->remove(_ptr);
}
}
void assign(const std::shared_ptr<T>& ptr) { _ptr = ptr; }
const std::shared_ptr<T>& get() const noexcept { return _ptr; }
private:
const std::shared_ptr<DbxCppWrapperCache> _cache = getInstance();
std::shared_ptr<T> _ptr;
};
private:
std::unordered_map<T*, __weak id> m_mapping;
std::mutex m_mutex;
......
......@@ -25,12 +25,12 @@ struct Bool {
struct Boxed {
using ObjcType = NSNumber*;
static CppType toCpp(ObjcType x) noexcept { return [x boolValue] ? true : false; }
static ObjcType fromCpp(CppType x) noexcept { return [NSNumber numberWithChar:x ? YES : NO]; }
static CppType toCpp(ObjcType x) noexcept { assert(x); return [x boolValue] ? true : false; }
static ObjcType fromCpp(CppType x) noexcept { return [NSNumber numberWithBool:x ? YES : NO]; }
};
};
template<class T>
template<class Self, class T>
struct Primitive {
using CppType = T;
using ObjcType = T;
......@@ -39,7 +39,7 @@ struct Primitive {
static ObjcType fromCpp(CppType x) noexcept { return x; }
};
struct I8 : public Primitive<int8_t> {
struct I8 : public Primitive<I8, int8_t> {
struct Boxed {
using ObjcType = NSNumber*;
static CppType toCpp(ObjcType x) noexcept { return [x charValue]; }
......@@ -47,7 +47,7 @@ struct I8 : public Primitive<int8_t> {
};
};
struct I16 : public Primitive<int16_t> {
struct I16 : public Primitive<I16, int16_t> {
struct Boxed {
using ObjcType = NSNumber*;
static CppType toCpp(ObjcType x) noexcept { return [x shortValue]; }
......@@ -55,7 +55,7 @@ struct I16 : public Primitive<int16_t> {
};
};
struct I32 : public Primitive<int32_t> {
struct I32 : public Primitive<I32, int32_t> {
struct Boxed {
using ObjcType = NSNumber*;
static CppType toCpp(ObjcType x) noexcept { return [x intValue]; }
......@@ -63,7 +63,7 @@ struct I32 : public Primitive<int32_t> {
};
};
struct I64 : public Primitive<int64_t> {
struct I64 : public Primitive<I64, int64_t> {
struct Boxed {
using ObjcType = NSNumber*;
static CppType toCpp(ObjcType x) noexcept { return [x longLongValue]; }
......@@ -71,7 +71,7 @@ struct I64 : public Primitive<int64_t> {
};
};
struct F64 : public Primitive<double> {
struct F64 : public Primitive<F64, double> {
struct Boxed {
using ObjcType = NSNumber*;
static CppType toCpp(ObjcType x) noexcept { return [x doubleValue]; }
......
......@@ -57,6 +57,22 @@ public:
}
}
class Handle {
public:
Handle(id obj) : _obj(obj) { };
~Handle() {
if (_obj) {
_cache->remove(_obj);
}
}
id get() const noexcept { return _obj; }
private:
const std::shared_ptr<DbxObjcWrapperCache> _cache = getInstance();
const id _obj;
};
private:
NSMapTable *m_mapping;
std::mutex m_mutex;
......
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from client_interface.djinni
#include "client_interface.hpp"
#include <memory>
static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file");
@protocol DBClientInterface;
namespace djinni_generated {
struct ClientInterface
{
using CppType = std::shared_ptr<::ClientInterface>;
using ObjcType = id<DBClientInterface>;
static CppType toCpp(ObjcType objc);
static ObjcType fromCpp(const CppType& cpp);
};
} // namespace djinni_generated
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from client_interface.djinni
#import "DBClientInterfaceObjcProxy+Private.h"
#import "DBClientInterface+Private.h"
#import "DBClientInterface.h"
#import "DBClientReturnedRecord+Private.h"
#import "DJIMarshal+Private.h"
#import "DJIObjcWrapperCache+Private.h"
#include <vector>
namespace djinni_generated {
static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file");
namespace { // anonymous namespace
class ObjcProxy final
: public ::ClientInterface
, public ::djinni::DbxObjcWrapperCache<ObjcProxy>::Handle
{
public:
using Handle::Handle;
::ClientReturnedRecord get_record (int64_t record_id, const std::string & utf8string) override;
};
} // end anonymous namespace
ClientInterfaceObjcProxy::ClientInterfaceObjcProxy (id objcRef)
: _objcRef((assert([[objcRef class] conformsToProtocol:@protocol(DBClientInterface)]), objcRef)),
_cache(djinni::DbxObjcWrapperCache<ClientInterfaceObjcProxy>::getInstance())
{}
namespace djinni_generated {
ClientInterfaceObjcProxy::~ClientInterfaceObjcProxy ()
auto ClientInterface::toCpp(ObjcType objc) -> CppType
{
_cache->remove(_objcRef);
return objc ? djinni::DbxObjcWrapperCache<ObjcProxy>::getInstance()->get(objc) : nullptr;
}
std::shared_ptr<::ClientInterface> ClientInterfaceObjcProxy::client_interface_with_objc (id<DBClientInterface> objcRef)
auto ClientInterface::fromCpp(const CppType& cpp) -> ObjcType
{
return djinni::DbxObjcWrapperCache<ClientInterfaceObjcProxy>::getInstance()->get(objcRef);
assert(!cpp || dynamic_cast<ObjcProxy*>(cpp.get()));
return cpp ? static_cast<ObjcProxy&>(*cpp).Handle::get() : nil;
}
::ClientReturnedRecord ClientInterfaceObjcProxy::get_record (int64_t record_id, const std::string & utf8string)
} // 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 = [_objcRef getRecord:cpp_record_id utf8string:cpp_utf8string];
DBClientReturnedRecord * objcRet = [Handle::get() getRecord:cpp_record_id utf8string:cpp_utf8string];
::ClientReturnedRecord cppRet = std::move([objcRet cppClientReturnedRecord]);
return cppRet;
}
}
} // namespace djinni_generated
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from client_interface.djinni
#import "DBClientInterface.h"
#include "client_interface.hpp"
#import "DJIObjcWrapperCache+Private.h"
#import <Foundation/Foundation.h>
#include <memory>
namespace djinni_generated {
class ClientInterfaceObjcProxy final : public ::ClientInterface
{
public:
const id <DBClientInterface> _objcRef;
const std::shared_ptr<djinni::DbxObjcWrapperCache<ClientInterfaceObjcProxy>> _cache;
explicit ClientInterfaceObjcProxy (id objcRef);
virtual ~ClientInterfaceObjcProxy () override;
static std::shared_ptr<::ClientInterface> client_interface_with_objc (id<DBClientInterface> objcRef);
virtual ::ClientReturnedRecord get_record (int64_t record_id, const std::string & utf8string) override;
};
} // namespace djinni_generated
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from exception.djinni
#import "DBCppException.h"
#include "cpp_exception.hpp"
#import <Foundation/Foundation.h>
#include <memory>
@interface DBCppException ()
static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file");
@property (nonatomic, readonly) std::shared_ptr<::CppException> cppRef;
@class DBCppException;
+ (id)cppExceptionWithCpp:(const std::shared_ptr<::CppException> &)cppRef;
namespace djinni_generated {
struct CppException
{
using CppType = std::shared_ptr<::CppException>;
using ObjcType = DBCppException*;
static CppType toCpp(ObjcType objc);
static ObjcType fromCpp(const CppType& cpp);
};
} // namespace djinni_generated
@end
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from exception.djinni
#import "DBCppException+Private.h"
#import "DBCppException+Private.h"
#import "DBCppException.h"
#import "DBCppException+Private.h"
#import "DJICppWrapperCache+Private.h"
#import "DJIDate.h"
#import "DJIError.h"
......@@ -15,34 +15,43 @@
static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file");
@interface DBCppException ()
@property (nonatomic, readonly) std::shared_ptr<djinni::DbxCppWrapperCache<::CppException>> cache;
@property (nonatomic, readonly) djinni::DbxCppWrapperCache<::CppException>::Handle cppRef;
- (id)initWithCpp:(const std::shared_ptr<::CppException>&)cppRef;
@end
@implementation DBCppException
namespace djinni_generated {
- (id)initWithCpp:(const std::shared_ptr<::CppException> &)cppRef cache:(const std::shared_ptr<djinni::DbxCppWrapperCache<::CppException>> &)cache
auto CppException::toCpp(ObjcType objc) -> CppType
{
if (self = [super init]) {
_cppRef = cppRef;
_cache = cache;
}
return self;
return objc ? objc.cppRef.get() : nullptr;
}
- (void)dealloc
auto CppException::fromCpp(const CppType& cpp) -> ObjcType
{
_cache->remove(_cppRef);
return !cpp ? nil : djinni::DbxCppWrapperCache<::CppException>::getInstance()->get(cpp, [] (const auto& p)
{
return [[DBCppException alloc] initWithCpp:p];
});
}
+ (id)cppExceptionWithCpp:(const std::shared_ptr<::CppException> &)cppRef
} // namespace djinni_generated
@implementation DBCppException
- (id)initWithCpp:(const std::shared_ptr<::CppException>&)cppRef
{
const auto & cache = djinni::DbxCppWrapperCache<::CppException>::getInstance();
return cache->get(cppRef, [&] (const std::shared_ptr<::CppException> & p) { return [[DBCppException alloc] initWithCpp:p cache:cache]; });
if (self = [super init]) {
_cppRef.assign(cppRef);
}
return self;
}
- (int32_t)throwAnException {
try {
int32_t cppRet = _cppRef->throw_an_exception();
int32_t cppRet = _cppRef.get()->throw_an_exception();
int32_t objcRet = ::djinni::I32::fromCpp(cppRet);
return objcRet;
} DJINNI_TRANSLATE_EXCEPTIONS()
......@@ -51,7 +60,7 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th
+ (DBCppException *)get {
try {
std::shared_ptr<::CppException> cppRet = ::CppException::get();
DBCppException* objcRet = [DBCppException cppExceptionWithCpp:cppRet];
DBCppException* objcRet = ::djinni_generated::CppException::fromCpp(cppRet);
return objcRet;
} DJINNI_TRANSLATE_EXCEPTIONS()
}
......
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from test.djinni
#import "DBTestHelpers.h"
#include "test_helpers.hpp"
#import <Foundation/Foundation.h>
#include <memory>
@interface DBTestHelpers ()
static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file");
@property (nonatomic, readonly) std::shared_ptr<::TestHelpers> cppRef;
@class DBTestHelpers;
+ (id)testHelpersWithCpp:(const std::shared_ptr<::TestHelpers> &)cppRef;
namespace djinni_generated {
struct TestHelpers
{
using CppType = std::shared_ptr<::TestHelpers>;
using ObjcType = DBTestHelpers*;
static CppType toCpp(ObjcType objc);
static ObjcType fromCpp(const CppType& cpp);
};
} // namespace djinni_generated
@end
......@@ -2,14 +2,13 @@
// This file generated by Djinni from test.djinni
#import "DBTestHelpers+Private.h"
#import "DBTestHelpers.h"
#import "DBAssortedIntegers+Private.h"
#import "DBClientInterfaceObjcProxy+Private.h"
#import "DBColor.h"
#import "DBClientInterface+Private.h"
#import "DBMapListRecord+Private.h"
#import "DBNestedCollection+Private.h"
#import "DBPrimitiveList+Private.h"
#import "DBSetRecord+Private.h"
#import "DBTestHelpers.h"
#import "DBToken+Private.h"
#import "DJICppWrapperCache+Private.h"
#import "DJIDate.h"
......@@ -22,29 +21,38 @@
static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file");
@interface DBTestHelpers ()
@property (nonatomic, readonly) std::shared_ptr<djinni::DbxCppWrapperCache<::TestHelpers>> cache;
@property (nonatomic, readonly) djinni::DbxCppWrapperCache<::TestHelpers>::Handle cppRef;
- (id)initWithCpp:(const std::shared_ptr<::TestHelpers>&)cppRef;
@end
@implementation DBTestHelpers
namespace djinni_generated {
- (id)initWithCpp:(const std::shared_ptr<::TestHelpers> &)cppRef cache:(const std::shared_ptr<djinni::DbxCppWrapperCache<::TestHelpers>> &)cache
auto TestHelpers::toCpp(ObjcType objc) -> CppType
{
if (self = [super init]) {
_cppRef = cppRef;
_cache = cache;
}
return self;
return objc ? objc.cppRef.get() : nullptr;
}
- (void)dealloc
auto TestHelpers::fromCpp(const CppType& cpp) -> ObjcType
{
_cache->remove(_cppRef);
return !cpp ? nil : djinni::DbxCppWrapperCache<::TestHelpers>::getInstance()->get(cpp, [] (const auto& p)
{
return [[DBTestHelpers alloc] initWithCpp:p];
});
}
+ (id)testHelpersWithCpp:(const std::shared_ptr<::TestHelpers> &)cppRef
} // namespace djinni_generated
@implementation DBTestHelpers
- (id)initWithCpp:(const std::shared_ptr<::TestHelpers>&)cppRef
{
const auto & cache = djinni::DbxCppWrapperCache<::TestHelpers>::getInstance();
return cache->get(cppRef, [&] (const std::shared_ptr<::TestHelpers> & p) { return [[DBTestHelpers alloc] initWithCpp:p cache:cache]; });
if (self = [super init]) {
_cppRef.assign(cppRef);
}
return self;
}
+ (DBSetRecord *)getSetRecord {
......@@ -181,14 +189,14 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th
+ (void)checkClientInterfaceAscii:(id<DBClientInterface>)i {
try {
std::shared_ptr<::ClientInterface> cppI = ::djinni_generated::ClientInterfaceObjcProxy::client_interface_with_objc(i);
std::shared_ptr<::ClientInterface> cppI = ::djinni_generated::ClientInterface::toCpp(i);
::TestHelpers::check_client_interface_ascii(std::move(cppI));
} DJINNI_TRANSLATE_EXCEPTIONS()
}
+ (void)checkClientInterfaceNonascii:(id<DBClientInterface>)i {
try {
std::shared_ptr<::ClientInterface> cppI = ::djinni_generated::ClientInterfaceObjcProxy::client_interface_with_objc(i);
std::shared_ptr<::ClientInterface> cppI = ::djinni_generated::ClientInterface::toCpp(i);
::TestHelpers::check_client_interface_nonascii(std::move(cppI));
} DJINNI_TRANSLATE_EXCEPTIONS()
}
......@@ -207,9 +215,9 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th
+ (DBToken *)tokenId:(DBToken *)t {
try {
std::shared_ptr<::Token> cppT = t.cppRef;
std::shared_ptr<::Token> cppT = ::djinni_generated::Token::toCpp(t);
std::shared_ptr<::Token> cppRet = ::TestHelpers::token_id(std::move(cppT));
DBToken* objcRet = [DBToken tokenWithCpp:cppRet];
DBToken* objcRet = ::djinni_generated::Token::fromCpp(cppRet);
return objcRet;
} DJINNI_TRANSLATE_EXCEPTIONS()
}
......@@ -217,21 +225,21 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th
+ (DBToken *)createCppToken {
try {
std::shared_ptr<::Token> cppRet = ::TestHelpers::create_cpp_token();
DBToken* objcRet = [DBToken tokenWithCpp:cppRet];
DBToken* objcRet = ::djinni_generated::Token::fromCpp(cppRet);
return objcRet;
} DJINNI_TRANSLATE_EXCEPTIONS()
}
+ (void)checkCppToken:(DBToken *)t {
try {
std::shared_ptr<::Token> cppT = t.cppRef;
std::shared_ptr<::Token> cppT = ::djinni_generated::Token::toCpp(t);
::TestHelpers::check_cpp_token(std::move(cppT));
} DJINNI_TRANSLATE_EXCEPTIONS()
}
+ (int64_t)cppTokenId:(DBToken *)t {
try {
std::shared_ptr<::Token> cppT = t.cppRef;
std::shared_ptr<::Token> cppT = ::djinni_generated::Token::toCpp(t);
int64_t cppRet = ::TestHelpers::cpp_token_id(std::move(cppT));
int64_t objcRet = ::djinni::I64::fromCpp(cppRet);
return objcRet;
......
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from token.djinni
#import "DBToken.h"
#include "token.hpp"
#import <Foundation/Foundation.h>
#include <memory>
@interface DBToken ()
static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file");
@property (nonatomic, readonly) std::shared_ptr<::Token> cppRef;
@class DBToken;
+ (id)tokenWithCpp:(const std::shared_ptr<::Token> &)cppRef;
namespace djinni_generated {
struct Token
{
using CppType = std::shared_ptr<::Token>;
using ObjcType = DBToken*;
static CppType toCpp(ObjcType objc);
static ObjcType fromCpp(const CppType& cpp);
};
} // namespace djinni_generated
@end
......@@ -13,29 +13,38 @@
static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file");
@interface DBToken ()
@property (nonatomic, readonly) std::shared_ptr<djinni::DbxCppWrapperCache<::Token>> cache;
@property (nonatomic, readonly) djinni::DbxCppWrapperCache<::Token>::Handle cppRef;
- (id)initWithCpp:(const std::shared_ptr<::Token>&)cppRef;
@end
@implementation DBToken
namespace djinni_generated {
- (id)initWithCpp:(const std::shared_ptr<::Token> &)cppRef cache:(const std::shared_ptr<djinni::DbxCppWrapperCache<::Token>> &)cache
auto Token::toCpp(ObjcType objc) -> CppType
{
if (self = [super init]) {
_cppRef = cppRef;
_cache = cache;
}
return self;
return objc ? objc.cppRef.get() : nullptr;
}
- (void)dealloc
auto Token::fromCpp(const CppType& cpp) -> ObjcType
{
_cache->remove(_cppRef);
return !cpp ? nil : djinni::DbxCppWrapperCache<::Token>::getInstance()->get(cpp, [] (const auto& p)
{
return [[DBToken alloc] initWithCpp:p];
});
}
+ (id)tokenWithCpp:(const std::shared_ptr<::Token> &)cppRef
} // namespace djinni_generated
@implementation DBToken
- (id)initWithCpp:(const std::shared_ptr<::Token>&)cppRef
{
const auto & cache = djinni::DbxCppWrapperCache<::Token>::getInstance();
return cache->get(cppRef, [&] (const std::shared_ptr<::Token> & p) { return [[DBToken alloc] initWithCpp:p cache:cache]; });
if (self = [super init]) {
_cppRef.assign(cppRef);
}
return self;
}
@end
#import "DBClientInterfaceImpl.h"
#import "DBClientInterfaceObjcProxy+Private.h"
#import "DBClientInterface+Private.h"
#import "DBTestHelpers.h"
#import <XCTest/XCTest.h>
......@@ -37,8 +37,8 @@
@autoreleasepool {
id <DBClientInterface> objcClientInterface = [[DBClientInterfaceImpl alloc] init];
objcClientInterfaceWeak = objcClientInterface;
cppClientInterface1 = ::djinni_generated::ClientInterfaceObjcProxy::client_interface_with_objc(objcClientInterface);
cppClientInterface2 = ::djinni_generated::ClientInterfaceObjcProxy::client_interface_with_objc(objcClientInterface);
cppClientInterface1 = ::djinni_generated::ClientInterface::toCpp(objcClientInterface);
cppClientInterface2 = ::djinni_generated::ClientInterface::toCpp(objcClientInterface);
XCTAssertEqual(cppClientInterface1, cppClientInterface2);
}
XCTAssertNotNil(objcClientInterfaceWeak);
......
#import "DBCppException.h"
#import "DBCppException+Private.h"
#import <XCTest/XCTest.h>
......@@ -20,7 +21,7 @@
}
- (void)testThrown {
DBCppException* objcInterface = [DBCppException cppExceptionWithCpp:(std::make_shared<CppExceptionImpl>())];
DBCppException* objcInterface = ::djinni_generated::CppException::fromCpp(std::make_shared<CppExceptionImpl>());
NSString *exceptionName = nil;
@try {
......@@ -35,8 +36,8 @@
std::shared_ptr<CppException> cppInterface = std::make_shared<CppExceptionImpl>();
std::weak_ptr<CppException> weakCppInterface(cppInterface);
@autoreleasepool {
DBCppException* objcInterface1 = [DBCppException cppExceptionWithCpp:cppInterface];
DBCppException* objcInterface2 = [DBCppException cppExceptionWithCpp:cppInterface];
DBCppException* objcInterface1 = ::djinni_generated::CppException::fromCpp(cppInterface);
DBCppException* objcInterface2 = ::djinni_generated::CppException::fromCpp(cppInterface);
XCTAssertEqual(objcInterface1, objcInterface2, @"The same wrapper should be returned");
cppInterface.reset();
......
......@@ -26,7 +26,6 @@
6D66A8A91A3B09F000B312E8 /* DBConstantTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 6D66A8A81A3B09F000B312E8 /* DBConstantTests.mm */; };
A239F37A1AF400C600DF27C8 /* DJIDate.mm in Sources */ = {isa = PBXBuildFile; fileRef = A239F3781AF400C600DF27C8 /* DJIDate.mm */; };
A242494C1AF192E0003BF8F0 /* DBAssortedIntegers.mm in Sources */ = {isa = PBXBuildFile; fileRef = A242491B1AF192E0003BF8F0 /* DBAssortedIntegers.mm */; };
A242494D1AF192E0003BF8F0 /* DBClientInterfaceObjcProxy.mm in Sources */ = {isa = PBXBuildFile; fileRef = A242491E1AF192E0003BF8F0 /* DBClientInterfaceObjcProxy.mm */; };
A242494E1AF192E0003BF8F0 /* DBClientReturnedRecord.mm in Sources */ = {isa = PBXBuildFile; fileRef = A24249211AF192E0003BF8F0 /* DBClientReturnedRecord.mm */; };
A24249501AF192E0003BF8F0 /* DBConstants.mm in Sources */ = {isa = PBXBuildFile; fileRef = A24249271AF192E0003BF8F0 /* DBConstants.mm */; };
A24249511AF192E0003BF8F0 /* DBCppException.mm in Sources */ = {isa = PBXBuildFile; fileRef = A242492A1AF192E0003BF8F0 /* DBCppException.mm */; };
......@@ -48,6 +47,7 @@
A278D45319BA3601006FD937 /* test_helpers.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A278D45219BA3601006FD937 /* test_helpers.cpp */; };
A2A162D21AF190D200C0B00A /* DJIDate.mm in Sources */ = {isa = PBXBuildFile; fileRef = A2A162D11AF190D200C0B00A /* DJIDate.mm */; };
A2CB54B419BA6E6000A9E600 /* DJIError.mm in Sources */ = {isa = PBXBuildFile; fileRef = A2CB54B319BA6E6000A9E600 /* DJIError.mm */; };
A2CCB9421AF80DFC00E6230A /* DBClientInterface.mm in Sources */ = {isa = PBXBuildFile; fileRef = A2CCB9401AF80DFC00E6230A /* DBClientInterface.mm */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
......@@ -105,8 +105,6 @@
A242491A1AF192E0003BF8F0 /* DBAssortedIntegers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DBAssortedIntegers.h; sourceTree = "<group>"; };
A242491B1AF192E0003BF8F0 /* DBAssortedIntegers.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DBAssortedIntegers.mm; sourceTree = "<group>"; };
A242491C1AF192E0003BF8F0 /* DBClientInterface.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DBClientInterface.h; sourceTree = "<group>"; };
A242491D1AF192E0003BF8F0 /* DBClientInterfaceObjcProxy+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "DBClientInterfaceObjcProxy+Private.h"; sourceTree = "<group>"; };
A242491E1AF192E0003BF8F0 /* DBClientInterfaceObjcProxy.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DBClientInterfaceObjcProxy.mm; sourceTree = "<group>"; };
A242491F1AF192E0003BF8F0 /* DBClientReturnedRecord+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "DBClientReturnedRecord+Private.h"; sourceTree = "<group>"; };
A24249201AF192E0003BF8F0 /* DBClientReturnedRecord.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DBClientReturnedRecord.h; sourceTree = "<group>"; };
A24249211AF192E0003BF8F0 /* DBClientReturnedRecord.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DBClientReturnedRecord.mm; sourceTree = "<group>"; };
......@@ -175,6 +173,8 @@
A2A162D01AF190D200C0B00A /* DJIDate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DJIDate.h; path = "../../../../djinni/support-lib/objc/DJIDate.h"; sourceTree = "<group>"; };
A2A162D11AF190D200C0B00A /* DJIDate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = DJIDate.mm; path = "../../../../djinni/support-lib/objc/DJIDate.mm"; sourceTree = "<group>"; };
A2CB54B319BA6E6000A9E600 /* DJIError.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DJIError.mm; sourceTree = "<group>"; };
A2CCB9401AF80DFC00E6230A /* DBClientInterface.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DBClientInterface.mm; sourceTree = "<group>"; };
A2CCB9411AF80DFC00E6230A /* DBClientInterface+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "DBClientInterface+Private.h"; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
......@@ -295,12 +295,12 @@
A24249181AF192E0003BF8F0 /* generated-objc */ = {
isa = PBXGroup;
children = (
A2CCB9401AF80DFC00E6230A /* DBClientInterface.mm */,
A2CCB9411AF80DFC00E6230A /* DBClientInterface+Private.h */,
A24249191AF192E0003BF8F0 /* DBAssortedIntegers+Private.h */,
A242491A1AF192E0003BF8F0 /* DBAssortedIntegers.h */,
A242491B1AF192E0003BF8F0 /* DBAssortedIntegers.mm */,
A242491C1AF192E0003BF8F0 /* DBClientInterface.h */,
A242491D1AF192E0003BF8F0 /* DBClientInterfaceObjcProxy+Private.h */,
A242491E1AF192E0003BF8F0 /* DBClientInterfaceObjcProxy.mm */,
A242491F1AF192E0003BF8F0 /* DBClientReturnedRecord+Private.h */,
A24249201AF192E0003BF8F0 /* DBClientReturnedRecord.h */,
A24249211AF192E0003BF8F0 /* DBClientReturnedRecord.mm */,
......@@ -475,6 +475,7 @@
A24249551AF192E0003BF8F0 /* DBMapRecord.mm in Sources */,
A24249581AF192E0003BF8F0 /* DBRecordWithDerivings.mm in Sources */,
A242495C1AF192E0003BF8F0 /* DBToken.mm in Sources */,
A2CCB9421AF80DFC00E6230A /* DBClientInterface.mm in Sources */,
A24249531AF192E0003BF8F0 /* DBMapDateRecord.mm in Sources */,
A24249501AF192E0003BF8F0 /* DBConstants.mm in Sources */,
A2CB54B419BA6E6000A9E600 /* DJIError.mm in Sources */,
......@@ -483,7 +484,6 @@
A24249751AF192FC003BF8F0 /* record_with_derivings.cpp in Sources */,
A24249541AF192E0003BF8F0 /* DBMapListRecord.mm in Sources */,
A239F37A1AF400C600DF27C8 /* DJIDate.mm in Sources */,
A242494D1AF192E0003BF8F0 /* DBClientInterfaceObjcProxy.mm in Sources */,
A24249731AF192FC003BF8F0 /* assorted_integers.cpp in Sources */,
A24249561AF192E0003BF8F0 /* DBNestedCollection.mm in Sources */,
);
......
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