rmw  master
C API providing a middleware abstraction layer which is used to implement the rest of ROS.
Macros
macros.hpp File Reference
#include <iostream>
#include <sstream>
#include <string>
#include "rmw/error_handling.h"
#include "rmw/impl/config.h"
#include "rmw/impl/cpp/demangle.hpp"

Go to the source code of this file.

Macros

#define RMW_TRY_PLACEMENT_NEW(Destination, BufferForNew, FailureAction, Type, ...)
 
#define RMW_TRY_DESTRUCTOR(Statement, Type, FailureAction)
 
#define RMW_TRY_DESTRUCTOR_FROM_WITHIN_FAILURE(Statement, Type)
 
#define RMW_CHECK_TYPE_IDENTIFIERS_MATCH(ElementName, ElementTypeID, ExpectedTypeID, OnFailure)
 

Macro Definition Documentation

◆ RMW_TRY_PLACEMENT_NEW

#define RMW_TRY_PLACEMENT_NEW (   Destination,
  BufferForNew,
  FailureAction,
  Type,
  ... 
)
Value:
try { \
Destination = new(BufferForNew) Type(__VA_ARGS__); \
} catch(const std::exception & exception) { \
RMW_SET_ERROR_MSG(( \
std::string("caught C++ exception ") + rmw::impl::cpp::demangle(exception) + \
" constructing " #Type ": " + exception.what() \
).c_str()); \
FailureAction; \
} catch(...) { \
RMW_SET_ERROR_MSG("caught unknown C++ exception constructing " #Type); \
FailureAction; \
}
std::string demangle(const T &instance)
Return the demangle name of the instance of type T.
Definition: demangle.hpp:39

◆ RMW_TRY_DESTRUCTOR

#define RMW_TRY_DESTRUCTOR (   Statement,
  Type,
  FailureAction 
)
Value:
try { \
Statement; \
} catch(const std::exception & exception) { \
RMW_SET_ERROR_MSG(( \
std::string("caught C++ exception in destructor of " #Type ": ") + \
rmw::impl::cpp::demangle(exception) + ": " + exception.what() \
).c_str()); \
FailureAction; \
} catch(...) { \
RMW_SET_ERROR_MSG("caught unknown C++ exception in destructor of " #Type); \
FailureAction; \
}
std::string demangle(const T &instance)
Return the demangle name of the instance of type T.
Definition: demangle.hpp:39

◆ RMW_TRY_DESTRUCTOR_FROM_WITHIN_FAILURE

#define RMW_TRY_DESTRUCTOR_FROM_WITHIN_FAILURE (   Statement,
  Type 
)
Value:
try { \
Statement; \
} catch(const std::exception & exception) { \
std::stringstream ss; \
ss << "caught C++ exception in destructor of " #Type " while handling a failure: " \
<< rmw::impl::cpp::demangle(exception) << ": " << exception.what() \
<< ", at: " << __FILE__ << ":" << __LINE__ << '\n'; \
(std::cerr << ss.str()).flush(); \
} catch(...) { \
std::stringstream ss; \
ss << "caught unknown C++ exception in destructor of " #Type \
<< " while handling a failure at: " << __FILE__ << ":" << __LINE__ << '\n'; \
(std::cerr << ss.str()).flush(); \
}
std::string demangle(const T &instance)
Return the demangle name of the instance of type T.
Definition: demangle.hpp:39

◆ RMW_CHECK_TYPE_IDENTIFIERS_MATCH

#define RMW_CHECK_TYPE_IDENTIFIERS_MATCH (   ElementName,
  ElementTypeID,
  ExpectedTypeID,
  OnFailure 
)
Value:
{ \
if (ElementTypeID != ExpectedTypeID) { \
size_t __bytes_that_would_have_been_written = snprintf( \
NULL, 0, \
#ElementName " implementation '%s'(%p) does not match rmw implementation '%s'(%p)", \
ElementTypeID, reinterpret_cast<const void *>(ElementTypeID), \
ExpectedTypeID, reinterpret_cast<const void *>(ExpectedTypeID)); \
char * __msg = \
reinterpret_cast<char *>(rmw_allocate(__bytes_that_would_have_been_written + 1)); \
snprintf( \
__msg, __bytes_that_would_have_been_written + 1, \
#ElementName " implementation '%s'(%p) does not match rmw implementation '%s'(%p)", \
ElementTypeID, reinterpret_cast<const void *>(ElementTypeID), \
ExpectedTypeID, reinterpret_cast<const void *>(ExpectedTypeID)); \
RMW_SET_ERROR_MSG(__msg); \
rmw_free(__msg); \
OnFailure; \
} \
}
void * rmw_allocate(size_t size)