C++ API Reference for Intel® Data Analytics Acceleration Library 2020 Update 1

error_handling_helpers.h
1 /* file: error_handling_helpers.h */
2 /*******************************************************************************
3 * Copyright 2014-2020 Intel Corporation
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *******************************************************************************/
17 
18 #ifndef __SERVICES_INTERNAL_ERROR_HANDLING_HELPERS_H__
19 #define __SERVICES_INTERNAL_ERROR_HANDLING_HELPERS_H__
20 
21 #include "services/error_handling.h"
22 #include "services/daal_shared_ptr.h"
23 
24 namespace daal
25 {
26 namespace services
27 {
28 namespace internal
29 {
30 
31 inline void tryAssignStatus(Status *status, const Status &statusToAssign)
32 {
33  if (status) { *status |= statusToAssign; }
34 }
35 
36 inline void tryAssignStatusAndThrow(Status *status, const Status &statusToAssign)
37 {
38  if (status)
39  {
40  *status |= statusToAssign;
41  services::throwIfPossible(*status);
42  }
43  else
44  {
45  services::throwIfPossible(statusToAssign);
46  }
47 }
48 
49 template<typename T>
50 inline SharedPtr<T> wrapShared(T *object, Status *status = NULL)
51 {
52  if (!object)
53  {
54  tryAssignStatus(status, ErrorMemoryAllocationFailed);
55  }
56  return SharedPtr<T>(object);
57 }
58 
59 template<typename T>
60 inline SharedPtr<T> wrapSharedAndTryThrow(T *object, Status *status = NULL)
61 {
62  if (!object)
63  {
64  tryAssignStatusAndThrow(status, ErrorMemoryAllocationFailed);
65  }
66  return SharedPtr<T>(object);
67 }
68 
69 } // namespace internal
70 } // namespace services
71 } // namespace daal
72 
73 #endif
daal::services::ErrorMemoryAllocationFailed
Definition: error_indexes.h:150

For more complete information about compiler optimizations, see our Optimization Notice.