PcapPlusPlus  Next
AssertionUtils.h
Go to the documentation of this file.
1 #pragma once
2 
5 
6 #ifndef PCPP_ASSERT_USE_C_ASSERT
7 # define PCPP_ASSERT_USE_C_ASSERT 0
8 #endif // !PCPP_ASSERT_USE_C_ASSERT
9 
10 #include <stdexcept>
11 #if PCPP_ASSERT_USE_C_ASSERT
12 # include <cassert>
13 #else
14 # include <string>
15 # include <sstream>
16 #endif // PCPP_ASSERT_USE_C_ASSERT
17 
18 namespace pcpp
19 {
20  namespace internal
21  {
23  class AssertionError : public std::logic_error
24  {
25  public:
26  using std::logic_error::logic_error;
27  };
28  } // namespace internal
29 } // namespace pcpp
30 
31 #ifndef NDEBUG
32 # if PCPP_ASSERT_USE_C_ASSERT
33 # define PCPP_ASSERT(condition, message) assert((condition) && (message))
34 # else // !PCPP_ASSERT_USE_C_ASSERT
35 # define PCPP_ASSERT(condition, message) \
36  do \
37  { \
38  if (!(condition)) \
39  { \
40  std::stringstream ss; \
41  ss << "[PCPP] Assertion failed on [" << __FILE__ << ":" << __LINE__ << "] with: " << (message); \
42  throw pcpp::internal::AssertionError(ss.str()); \
43  } \
44  } while (false)
45 # endif // PCPP_ASSERT_USE_C_ASSERT
46 #else
47 # define PCPP_ASSERT(condition, message) (void)0;
48 #endif // !NDEBUG
A custom assertion error class derived from std::logic_error to be used with PCPP_ASSERT.
Definition: AssertionUtils.h:24
The main namespace for the PcapPlusPlus lib.
Definition: AssertionUtils.h:19