From 417b0295be1dcea6a229400ad795618c39d9045e Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Sun, 12 May 2019 23:35:19 +0200 Subject: [PATCH] Add C++ compatibility --- m-core.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/m-core.h b/m-core.h index 03bc4d7b..62a316c0 100644 --- a/m-core.h +++ b/m-core.h @@ -2577,6 +2577,22 @@ typedef enum m_serial_return_code_e { M_SERIAL_OK_DONE = 0, M_SERIAL_OK_CONTINUE = 1, M_SERIAL_FAIL = 2 } m_serial_return_code_t; +#if defined(__cplusplus) +// C++ doesn't allow mixing enum and integer, so we provided overloaded operators. +inline void operator|(m_serial_return_code_t &a, m_serial_return_code_t b) +{ + a = static_cast(static_cast(a) | static_cast(b)); +} +inline m_serial_return_code_t operator|=(m_serial_return_code_t a, m_serial_return_code_t b) +{ + return static_cast(static_cast(a) | static_cast(b)); +} +inline m_serial_return_code_t operator&(m_serial_return_code_t a, m_serial_return_code_t b) +{ + return static_cast(static_cast(a) & static_cast(b)); +} +#endif + /* Maximum data size of a serializator structure * Can be overloaded by user */ #ifndef M_SERIAL_MAX_DATA_SIZE