onnxruntime/objectivec/src/ort_env.mm
Edward Chen 830f0b45d0
Update Objective-C API (#7567)
Update Objective-C API to be more usable from Swift. E.g., to allow conversion from Objective-C methods with trailing NSError** parameter to throwing Swift methods.
Update CMake Objective-C framework setup.
2021-05-05 15:56:55 -07:00

40 lines
855 B
Text

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#import "src/ort_env_internal.h"
#include <optional>
#include "core/session/onnxruntime_cxx_api.h"
#import "src/error_utils.h"
#import "src/ort_enums_internal.h"
NS_ASSUME_NONNULL_BEGIN
@implementation ORTEnv {
std::optional<Ort::Env> _env;
}
- (nullable instancetype)initWithLoggingLevel:(ORTLoggingLevel)loggingLevel
error:(NSError**)error {
self = [super init];
if (self) {
try {
const auto CAPILoggingLevel = PublicToCAPILoggingLevel(loggingLevel);
_env = Ort::Env{CAPILoggingLevel};
} catch (const Ort::Exception& e) {
ORTSaveExceptionToError(e, error);
self = nil;
}
}
return self;
}
- (Ort::Env&)CXXAPIOrtEnv {
return *_env;
}
@end
NS_ASSUME_NONNULL_END