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