/*
 * Copyright (C) 2020-2021 Aloysius Indrayanto
 *
 * This file is part of the eCxx library, see LICENSE file for the license details.
 */

/*
 * This is a special header file for compatibility with the C++ STL and Arduino library part
 */


#ifndef ECXX_PLATFORM_NODEMCU_LIBCPPCOMPAT_NEW_H
#define ECXX_PLATFORM_NODEMCU_LIBCPPCOMPAT_NEW_H


//
// Include C++ header files
//
#include <cstddef>
#include <exception>


//
// Emulate some C++ STL features as minimum as possible
//
namespace std {


    // Emulate std::bad_alloc
    class bad_alloc : public exception  {
        public:
            bad_alloc() throw()
            {}

            virtual ~bad_alloc() throw();

            virtual const char* what() const throw();
    };


    // Emulate std::nothrow_t and std::nothrow
    // NOTE : See also the aliases definition at the end of "../CoreSys.h"
    struct nothrow_t {};
    extern const nothrow_t nothrow;


} // namespace std


//
// Prototypes of operator new and delete
//
void* operator new     (size_t                       );
void* operator new[]   (size_t                       );

void  operator delete  (void*                        ) noexcept;
void  operator delete[](void*                        ) noexcept;

void* operator new     (size_t, const std::nothrow_t&) noexcept;
void* operator new[]   (size_t, const std::nothrow_t&) noexcept;

void  operator delete  (void*,  const std::nothrow_t&) noexcept;
void  operator delete[](void*,  const std::nothrow_t&) noexcept;


#endif
