/*
	This file is part of Fennix Kernel.

	Fennix Kernel is free software: you can redistribute it and/or
	modify it under the terms of the GNU General Public License as
	published by the Free Software Foundation, either version 3 of
	the License, or (at your option) any later version.

	Fennix Kernel is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/

#pragma once

#include <cstddef>
#include <exception>

namespace std
{
	enum class align_val_t : std::size_t
	{
	};

	struct nothrow_t
	{
		explicit nothrow_t() = default;
	};

	extern const std::nothrow_t nothrow;

	struct destroying_delete_t
	{
		explicit destroying_delete_t() = default;
	};

	inline constexpr destroying_delete_t destroying_delete{};

	typedef void (*new_handler)();
	std::new_handler set_new_handler(std::new_handler new_p) noexcept;
	std::new_handler get_new_handler() noexcept;

	class bad_alloc : public exception
	{
	public:
		bad_alloc() noexcept = default;
		bad_alloc(const bad_alloc &other) noexcept = default;

		bad_alloc &operator=(const bad_alloc &other) noexcept = default;

		virtual const char *what() const noexcept
		{
			return "bad_alloc";
		}
	};

	class bad_array_new_length : public bad_alloc
	{
	public:
		bad_array_new_length() noexcept = default;
		bad_array_new_length(const bad_array_new_length &other) noexcept = default;
		virtual ~bad_array_new_length() = default;

		bad_array_new_length &operator=(const bad_array_new_length &other) noexcept
		{
			return *this;
		}

		virtual const char *what() const noexcept
		{
			return "bad_array_new_length";
		}
	};
}

[[nodiscard]] void *operator new(std::size_t count);
[[nodiscard]] void *operator new[](std::size_t count);
[[nodiscard]] void *operator new(std::size_t count, std::align_val_t al);
[[nodiscard]] void *operator new[](std::size_t count, std::align_val_t al);

[[nodiscard]] void *operator new(std::size_t count, const std::nothrow_t &tag) noexcept;
[[nodiscard]] void *operator new[](std::size_t count, const std::nothrow_t &tag) noexcept;
[[nodiscard]] void *operator new(std::size_t count, std::align_val_t al, const std::nothrow_t &) noexcept;
[[nodiscard]] void *operator new[](std::size_t count, std::align_val_t al, const std::nothrow_t &) noexcept;

[[nodiscard]] void *operator new(std::size_t count, void *ptr) noexcept;
[[nodiscard]] void *operator new[](std::size_t count, void *ptr) noexcept;

// void *operator new(std::size_t count, ...);
// void *operator new[](std::size_t count, ...);
// void *operator new(std::size_t count, std::align_val_t al, ...);
// void *operator new[](std::size_t count, std::align_val_t al, ...);

// void *T::operator new(std::size_t count);
// void *T::operator new[](std::size_t count);
// void *T::operator new(std::size_t count, std::align_val_t al);
// void *T::operator new[](std::size_t count, std::align_val_t al);

// void *T::operator new(std::size_t count, ...);
// void *T::operator new[](std::size_t count, ...);
// void *T::operator new(std::size_t count, std::align_val_t al, ...);
// void *T::operator new[](std::size_t count, std::align_val_t al, ...);

void operator delete(void *ptr) noexcept;
void operator delete[](void *ptr) noexcept;
// void operator delete(void *ptr, std::align_val_t al) noexcept;
// void operator delete[](void *ptr, std::align_val_t al) noexcept;
void operator delete(void *ptr, std::size_t sz) noexcept;
// void operator delete[](void *ptr, std::size_t sz) noexcept;
// void operator delete(void *ptr, std::size_t sz, std::align_val_t al) noexcept;
// void operator delete[](void *ptr, std::size_t sz, std::align_val_t al) noexcept;

// void operator delete(void *ptr, const std::nothrow_t &tag) noexcept;
// void operator delete[](void *ptr, const std::nothrow_t &tag) noexcept;
// void operator delete(void *ptr, std::align_val_t al, const std::nothrow_t &tag) noexcept;
// void operator delete[](void *ptr, std::align_val_t al, const std::nothrow_t &tag) noexcept;

// void operator delete(void *ptr, void *place) noexcept;
// void operator delete[](void *ptr, void *place) noexcept;

// void operator delete(void *ptr, ...);
// void operator delete[](void *ptr, ...);

// void T::operator delete(void *ptr);
// void T::operator delete[](void *ptr);
// void T::operator delete(void *ptr, std::align_val_t al);
// void T::operator delete[](void *ptr, std::align_val_t al);
// void T::operator delete(void *ptr, std::size_t sz);
// void T::operator delete[](void *ptr, std::size_t sz);
// void T::operator delete(void *ptr, std::size_t sz, std::align_val_t al);
// void T::operator delete[](void *ptr, std::size_t sz, std::align_val_t al);

// void T::operator delete(void *ptr, args...);
// void T::operator delete[](void *ptr, args...);

// void T::operator delete(T *ptr, std::destroying_delete_t);
// void T::operator delete(T *ptr, std::destroying_delete_t, std::align_val_t al);
// void T::operator delete(T *ptr, std::destroying_delete_t, std::size_t sz);
// void T::operator delete(T *ptr, std::destroying_delete_t, std::size_t sz, std::align_val_t al);
