C++ API Reference for Intel® Data Analytics Acceleration Library 2019 Update 4

error_handling_helpers.h
1 /* file: error_handling_helpers.h */
2 /*******************************************************************************
3 * Copyright 2014-2019 Intel Corporation.
4 *
5 * This software and the related documents are Intel copyrighted materials, and
6 * your use of them is governed by the express license under which they were
7 * provided to you (License). Unless the License provides otherwise, you may not
8 * use, modify, copy, publish, distribute, disclose or transmit this software or
9 * the related documents without Intel's prior written permission.
10 *
11 * This software and the related documents are provided as is, with no express
12 * or implied warranties, other than those that are expressly stated in the
13 * License.
14 *******************************************************************************/
15 
16 #ifndef __SERVICES_INTERNAL_ERROR_HANDLING_HELPERS_H__
17 #define __SERVICES_INTERNAL_ERROR_HANDLING_HELPERS_H__
18 
19 #include "services/error_handling.h"
20 #include "services/daal_shared_ptr.h"
21 
22 namespace daal
23 {
24 namespace services
25 {
26 namespace internal
27 {
28 
29 inline void tryAssignStatus(Status *status, const Status &statusToAssign)
30 {
31  if (status) { *status |= statusToAssign; }
32 }
33 
34 inline void tryAssignStatusAndThrow(Status *status, const Status &statusToAssign)
35 {
36  if (status)
37  {
38  *status |= statusToAssign;
39  services::throwIfPossible(*status);
40  }
41  else
42  {
43  services::throwIfPossible(statusToAssign);
44  }
45 }
46 
47 template<typename T>
48 inline SharedPtr<T> wrapShared(T *object, Status *status = NULL)
49 {
50  if (!object)
51  {
52  tryAssignStatus(status, ErrorMemoryAllocationFailed);
53  }
54  return SharedPtr<T>(object);
55 }
56 
57 template<typename T>
58 inline SharedPtr<T> wrapSharedAndTryThrow(T *object, Status *status = NULL)
59 {
60  if (!object)
61  {
62  tryAssignStatusAndThrow(status, ErrorMemoryAllocationFailed);
63  }
64  return SharedPtr<T>(object);
65 }
66 
67 } // namespace internal
68 } // namespace services
69 } // namespace daal
70 
71 #endif
daal
Definition: algorithm_base_common.h:31
daal::services::ErrorMemoryAllocationFailed
Definition: error_indexes.h:146

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