// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from exception.djinni

#import "DBCppException+Private.h"
#import "DBCppException.h"
#import "DBCppException+Private.h"
#import "DJICppWrapperCache+Private.h"
#import "DJIDate.h"
#import "DJIError.h"
#import "DJIMarshal+Private.h"
#include <exception>
#include <utility>
#include <vector>

static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file");

@interface DBCppException ()

@property (nonatomic, readonly) djinni::DbxCppWrapperCache<::CppException>::Handle cppRef;

- (id)initWithCpp:(const std::shared_ptr<::CppException>&)cppRef;

@end

namespace djinni_generated {

auto CppException::toCpp(ObjcType objc) -> CppType
{
    return objc ? objc.cppRef.get() : nullptr;
}

auto CppException::fromCpp(const CppType& cpp) -> ObjcType
{
    return !cpp ? nil : djinni::DbxCppWrapperCache<::CppException>::getInstance()->get(cpp, [] (const auto& p)
    {
        return [[DBCppException alloc] initWithCpp:p];
    });
}

}  // namespace djinni_generated

@implementation DBCppException

- (id)initWithCpp:(const std::shared_ptr<::CppException>&)cppRef
{
    if (self = [super init]) {
        _cppRef.assign(cppRef);
    }
    return self;
}

- (int32_t)throwAnException {
    try {
        int32_t cppRet = _cppRef.get()->throw_an_exception();
        int32_t objcRet = ::djinni::I32::fromCpp(cppRet);
        return objcRet;
    } DJINNI_TRANSLATE_EXCEPTIONS()
}

+ (DBCppException *)get {
    try {
        std::shared_ptr<::CppException> cppRet = ::CppException::get();
        DBCppException* objcRet = ::djinni_generated::CppException::fromCpp(cppRet);
        return objcRet;
    } DJINNI_TRANSLATE_EXCEPTIONS()
}

@end
