RTI Connext Traditional C++ API  Version 6.0.0
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExceptionHelper.hpp
1 /*
2 (c) Copyright, Real-Time Innovations, 2018.
3 All rights reserved.
4 
5 No duplications, whole or partial, manual or electronic, may be made
6 without express written permission. Any such copies, or
7 revisions thereof, must display this notice unaltered.
8 This code contains trade secrets of Real-Time Innovations, Inc.
9 */
10 
11 
12 #ifndef RTI_DDS_FLAT_EXCEPTIONHELPER_HPP_
13 #define RTI_DDS_FLAT_EXCEPTIONHELPER_HPP_
14 
15 //
16 // Enable debug assertions (RTI_FLAT_ASSERT) in debug mode
17 //
18 #if !defined(NDEBUG)
19 #define RTI_FLAT_DATA_ENABLE_DEBUG_ASSERTIONS
20 #endif
21 
22 //
23 // Error handling without C++ exceptions (traditional C++ and Micro C++ APIs)
24 //
25 #ifdef RTI_FLAT_DATA_NO_EXCEPTIONS
26  // TODO: use MSG
27  #ifdef RTI_FLAT_DATA_ENABLE_DEBUG_ASSERTIONS
28  #define RTI_FLAT_ASSERT(COND, ACTION) \
29  if (!(COND)) { \
30  RTIXCdrFlatData_logPreconditionError(__FILE__, __LINE__, "Assertion failure: " #COND); \
31  ACTION; \
32  }
33  #else
34  #define RTI_FLAT_ASSERT(COND, ACTION)
35  #endif
36 
37  // CR decission: Log error messages. Export function for each log kind (serialize, deserialize, precondition, skip)
38  // pass type/field (if possible) to serialization errors
39  #define RTI_FLAT_OFFSET_CHECK_NOT_NULL(ACTION) \
40  if (this->is_null()) { \
41  RTIXCdrFlatData_logPreconditionError(__FILE__, __LINE__, "null offset"); \
42  ACTION; \
43  }
44 
45  #define RTI_FLAT_CHECK_PRECONDITION(COND, ACTION) \
46  if (!(COND)) { \
47  RTIXCdrFlatData_logPreconditionError(__FILE__, __LINE__, "Precondition failure: " #COND); \
48  ACTION; \
49  }
50 
51  #define RTI_FLAT_BUILDER_CHECK_NOT_BOUND(ACTION) \
52  if (bind_position_) { \
53  RTIXCdrFlatData_logPreconditionError(__FILE__, __LINE__, "Builder is currently bound - call finish() first"); \
54  ACTION; \
55  }
56 
57  #define RTI_FLAT_BUILDER_CHECK_CAN_FINISH(ACTION) \
58  if (!is_nested()) { \
59  RTIXCdrFlatData_logPreconditionError(__FILE__, __LINE__, "This is not a member builder; call finish_sample() instead"); \
60  ACTION; \
61  }
62 
63  #define RTI_FLAT_BUILDER_CHECK_CAN_FINISH_SAMPLE(ACTION) \
64  if (is_nested()) { \
65  RTIXCdrFlatData_logPreconditionError(__FILE__, __LINE__, "This is a member builder; call finish() instead"); \
66  ACTION; \
67  }
68 
69  #define RTI_FLAT_BUILDER_CHECK_VALID(ACTION) \
70  if (!is_valid()) { \
71  RTIXCdrFlatData_logPreconditionError(__FILE__, __LINE__, "This Builder is not valid"); \
72  ACTION; \
73  }
74 
75  #define RTI_FLAT_BUILDER_CHECK_CREATE_BUILDER(BUILDER, ACTION) \
76  if (!BUILDER.is_valid()) { \
77  set_failure(); \
78  RTIXCdrFlatData_logCreationError(__FILE__, __LINE__, "Builder"); \
79  ACTION; \
80  }
81 
82  #define RTI_FLAT_BUILDER_OUT_OF_RESOURCES_ERROR(ACTION) \
83  set_failure(); \
84  RTIXCdrFlatData_logBuilderOutOfResources(__FILE__, __LINE__); \
85  ACTION
86 
87  #define RTI_FLAT_BUILDER_PRECONDITION_ERROR(MSG, ACTION) \
88  set_failure(); \
89  RTIXCdrFlatData_logPreconditionError(__FILE__, __LINE__, MSG); \
90  ACTION
91 
92 //
93 // Error handling with C++ exceptions (modern C++ API)
94 //
95 #else // !RTI_FLAT_DATA_NO_EXCEPTIONS
96 
97  #ifdef RTI_FLAT_DATA_ENABLE_DEBUG_ASSERTIONS
98  #define RTI_FLAT_ASSERT(COND, ACTION) \
99  if (!(COND)) throw dds::core::PreconditionNotMetError("Assertion failure: " #COND)
100  #else
101  #define RTI_FLAT_ASSERT(COND, ACTION)
102  #endif
103 
104  #define RTI_FLAT_OFFSET_CHECK_NOT_NULL(ACTION) \
105  if (this->is_null()) throw dds::core::NullReferenceError("null offset")
106 
107  #define RTI_FLAT_CHECK_PRECONDITION(COND, ACTION) \
108  if (!(COND)) throw dds::core::PreconditionNotMetError("Precondition failure: " #COND)
109 
110  #define RTI_FLAT_BUILDER_CHECK_NOT_BOUND(ACTION) \
111  if (bind_position_) \
112  throw dds::core::PreconditionNotMetError( \
113  "Builder is currently bound - call finish() first")
114 
115  #define RTI_FLAT_BUILDER_CHECK_CAN_FINISH(ACTION) \
116  if (!is_nested()) \
117  throw dds::core::PreconditionNotMetError( \
118  "This is not a member builder; call finish_sample() instead")
119 
120  #define RTI_FLAT_BUILDER_CHECK_CAN_FINISH_SAMPLE(ACTION) \
121  if (is_nested()) \
122  throw dds::core::PreconditionNotMetError( \
123  "This is a member builder; call finish() instead")
124 
125  #define RTI_FLAT_BUILDER_CHECK_VALID(ACTION) \
126  if (!is_valid()) \
127  throw dds::core::PreconditionNotMetError("This Builder is not valid")
128 
129  // With exceptions, nothing to check (exception would have been thrown)
130  #define RTI_FLAT_BUILDER_CHECK_CREATE_BUILDER(BUILDER, ACTION)
131 
132  #define RTI_FLAT_BUILDER_OUT_OF_RESOURCES_ERROR(ACTION) \
133  throw dds::core::OutOfResourcesError("builder reached end of buffer")
134 
135  #define RTI_FLAT_BUILDER_PRECONDITION_ERROR(MSG, ACTION) \
136  throw dds::core::PreconditionNotMetError(MSG)
137 
138 
139 #endif // RTI_FLAT_DATA_NO_EXCEPTIONS
140 
141 //
142 // Error checking (other than assertions) in release mode is enabled unless
143 // the sources are compiled with -DRTI_FLAT_DATA_DISABLE_ERROR_CHECKING
144 //
145 // In that case, most error checks that deal with preconditions due to incorrect
146 // usage of the API are disabled in release mode. This would lead to undefined
147 // behavior in case of bad usage, but can improve performance.
148 //
149 #if defined(RTI_FLAT_DATA_ENABLE_DEBUG_ASSERTIONS) \
150  || !defined(RTI_FLAT_DATA_DISABLE_ERROR_CHECKING)
151 #define RTI_FLAT_DATA_ENABLE_ERROR_CHECKING
152 #endif
153 
154 #ifndef RTI_FLAT_DATA_ENABLE_ERROR_CHECKING
155 
156  #define RTI_FLAT_OFFSET_CHECK_NOT_NULL(ACTION)
157  #define RTI_FLAT_ASSERT(COND, ACTION)
158  #define RTI_FLAT_CHECK_PRECONDITION(COND, ACTION)
159  #define RTI_FLAT_BUILDER_CHECK_NOT_BOUND(ACTION)
160  #define RTI_FLAT_BUILDER_CHECK_CAN_FINISH(ACTION)
161  #define RTI_FLAT_BUILDER_CHECK_CAN_FINISH_SAMPLE(ACTION)
162  #define RTI_FLAT_BUILDER_CHECK_VALID(ACTION)
163  #define RTI_FLAT_BUILDER_CHECK_CREATE_BUILDER(BUILDER, ACTION)
164 
165 #endif // RTI_FLAT_DATA_ENABLE_ERROR_CHECKING
166 
167 namespace rti { namespace flat { namespace detail {
168 
169 } } }
170 
171 #endif // RTI_DDS_FLAT_EXCEPTIONHELPER_HPP_
172 

RTI Connext Traditional C++ API Version 6.0.0 Copyright © Sun Mar 3 2019 Real-Time Innovations, Inc