Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / include / details / ie_exception_conversion.hpp
1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4
5 /**
6  * @brief A header file that provides macros to handle no exception methods
7  * @file ie_exception_conversion.hpp
8  */
9 #pragma once
10 #include <ie_common.h>
11
12 #define CALL_STATUS_FNC(function, ...)\
13 ResponseDesc resp;\
14 auto res = actual->function(__VA_ARGS__, &resp);\
15 if (res != OK) InferenceEngine::details::extract_exception(res, resp.msg);
16
17 #define CALL_STATUS_FNC_NO_ARGS(function)\
18 ResponseDesc resp;\
19 auto res = actual->function(&resp);\
20 if (res != OK) InferenceEngine::details::extract_exception(res, resp.msg);
21
22
23 #define CALL_FNC(function, ...)\
24 ResponseDesc resp;\
25 auto result = actual->function(__VA_ARGS__, &resp);\
26 if (resp.msg[0] != '\0') {\
27     THROW_IE_EXCEPTION << resp.msg;\
28 }\
29 return result;
30
31 #define CALL_FNC_REF(function, ...)\
32 ResponseDesc resp;\
33 auto & result = actual->function(__VA_ARGS__, &resp);\
34 if (resp.msg[0] != '\0') {\
35     THROW_IE_EXCEPTION << resp.msg;\
36 }\
37 return result;
38
39 #define CALL_FNC_NO_ARGS(function)\
40 ResponseDesc resp;\
41 auto result = actual->function(&resp);\
42 if (resp.msg[0] != '\0') {\
43     THROW_IE_EXCEPTION << resp.msg;\
44 }\
45 return result;
46
47 #define CALL_FNC_NO_ARGS_REF(function)\
48 ResponseDesc resp;\
49 auto & result = actual->function(&resp);\
50 if (resp.msg[0] != '\0') {\
51     THROW_IE_EXCEPTION << resp.msg;\
52 }\
53 return result;
54
55 namespace InferenceEngine {
56 namespace details {
57
58 inline void extract_exception(StatusCode status, char *msg) {
59     switch (status) {
60         case NOT_IMPLEMENTED:throw NotImplemented(msg);
61         case NETWORK_NOT_LOADED:throw NetworkNotLoaded(msg);
62         case PARAMETER_MISMATCH:throw ParameterMismatch(msg);
63         case NOT_FOUND:throw NotFound(msg);
64         case OUT_OF_BOUNDS:throw OutOfBounds(msg);
65         case UNEXPECTED:throw Unexpected(msg);
66         case REQUEST_BUSY:throw RequestBusy(msg);
67         case RESULT_NOT_READY:throw ResultNotReady(msg);
68         case NOT_ALLOCATED:throw NotAllocated(msg);
69         case INFER_NOT_STARTED:throw InferNotStarted(msg);
70         case NETWORK_NOT_READ:throw NetworkNotRead(msg);
71         default:THROW_IE_EXCEPTION << msg;
72     }
73 }
74
75 }  // namespace details
76 }  // namespace InferenceEngine