::value, void>::type
- safeDelete(T*& pointer) {
- if (pointer == nullptr)
- return;
- delete pointer;
- pointer = nullptr;
- }
- /// @brief Gets value of const char* but if it is nullptr, a string nullptr is returned
- static inline const char* charPtrVal(const char* pointer) {
- return pointer == nullptr ? base::consts::kNullPointer : pointer;
- }
- /// @brief Aborts application due with user-defined status
- static inline void abort(int status, const std::string& reason = std::string()) {
- // Both status and reason params are there for debugging with tools like gdb etc
- ELPP_UNUSED(status);
- ELPP_UNUSED(reason);
-#if defined(ELPP_COMPILER_MSVC) && defined(_M_IX86) && defined(_DEBUG)
- // Ignore msvc critical error dialog - break instead (on debug mode)
- _asm int 3
-#else
- ::abort();
-#endif // defined(ELPP_COMPILER_MSVC) && defined(_M_IX86) && defined(_DEBUG)
- }
- /// @brief Bitwise operations for C++11 strong enum class. This casts e into Flag_T and returns value after bitwise operation
- /// Use these function as flag = bitwise::Or(MyEnum::val1, flag);
- namespace bitwise {
- template
- static inline base::type::EnumType And(Enum e, base::type::EnumType flag) {
- return static_cast(flag) & static_cast(e);
- }
- template
- static inline base::type::EnumType Not(Enum e, base::type::EnumType flag) {
- return static_cast(flag) & ~(static_cast(e));
- }
- template
- static inline base::type::EnumType Or(Enum e, base::type::EnumType flag) {
- return static_cast(flag) | static_cast(e);
- }
- } // namespace bitwise
- template
- static inline void addFlag(Enum e, base::type::EnumType* flag) {
- *flag = base::utils::bitwise::Or(e, *flag);
- }
- template
- static inline void removeFlag(Enum e, base::type::EnumType* flag) {
- *flag = base::utils::bitwise::Not(e, *flag);
- }
- template
- static inline bool hasFlag(Enum e, base::type::EnumType flag) {
- return base::utils::bitwise::And(e, flag) > 0x0;
- }
- } // namespace utils
- namespace threading {
-#if ELPP_THREADING_ENABLED
-# if !ELPP_USE_STD_THREADING
- namespace internal {
- /// @brief A mutex wrapper for compiler that dont yet support std::mutex
- class Mutex : base::NoCopy {
- public:
- Mutex(void) {
-# if ELPP_OS_UNIX
- pthread_mutex_init(&m_underlyingMutex, nullptr);
-# elif ELPP_OS_WINDOWS
- InitializeCriticalSection(&m_underlyingMutex);
-# endif // ELPP_OS_UNIX
- }
-
- virtual ~Mutex(void) {
-# if ELPP_OS_UNIX
- pthread_mutex_destroy(&m_underlyingMutex);
-# elif ELPP_OS_WINDOWS
- DeleteCriticalSection(&m_underlyingMutex);
-# endif // ELPP_OS_UNIX
- }
-
- inline void lock(void) {
-# if ELPP_OS_UNIX
- pthread_mutex_lock(&m_underlyingMutex);
-# elif ELPP_OS_WINDOWS
- EnterCriticalSection(&m_underlyingMutex);
-# endif // ELPP_OS_UNIX
- }
-
- inline bool try_lock(void) {
-# if ELPP_OS_UNIX
- return (pthread_mutex_trylock(&m_underlyingMutex) == 0);
-# elif ELPP_OS_WINDOWS
- return TryEnterCriticalSection(&m_underlyingMutex);
-# endif // ELPP_OS_UNIX
- }
-
- inline void unlock(void) {
-# if ELPP_OS_UNIX
- pthread_mutex_unlock(&m_underlyingMutex);
-# elif ELPP_OS_WINDOWS
- LeaveCriticalSection(&m_underlyingMutex);
-# endif // ELPP_OS_UNIX
- }
-
- private:
-# if ELPP_OS_UNIX
- pthread_mutex_t m_underlyingMutex;
-# elif ELPP_OS_WINDOWS
- CRITICAL_SECTION m_underlyingMutex;
-# endif // ELPP_OS_UNIX
- };
- /// @brief Scoped lock for compiler that dont yet support std::lock_guard
- template