From 662860f03cdff8ea18b691dca1f3c84a4aaf07d5 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 21 Oct 2024 20:24:25 +0200 Subject: IMP: Major refactor of header and source files extensions. Signed-off-by: Amlal El Mahrouss --- dev/LibC++/base_alloc.h | 49 +++++++++++++++++ dev/LibC++/base_alloc.hxx | 49 ----------------- dev/LibC++/base_exception.h | 30 ++++++++++ dev/LibC++/base_exception.hxx | 30 ---------- dev/LibC++/defines.h | 125 ++++++++++++++++++++++++++++++++++++++++++ dev/LibC++/defines.hxx | 125 ------------------------------------------ dev/LibC++/exit.h | 21 +++++++ dev/LibC++/exit.hxx | 21 ------- dev/LibC++/math.h | 62 +++++++++++++++++++++ dev/LibC++/math.hxx | 62 --------------------- 10 files changed, 287 insertions(+), 287 deletions(-) create mode 100644 dev/LibC++/base_alloc.h delete mode 100644 dev/LibC++/base_alloc.hxx create mode 100644 dev/LibC++/base_exception.h delete mode 100644 dev/LibC++/base_exception.hxx create mode 100644 dev/LibC++/defines.h delete mode 100644 dev/LibC++/defines.hxx create mode 100644 dev/LibC++/exit.h delete mode 100644 dev/LibC++/exit.hxx create mode 100644 dev/LibC++/math.h delete mode 100644 dev/LibC++/math.hxx (limited to 'dev/LibC++') diff --git a/dev/LibC++/base_alloc.h b/dev/LibC++/base_alloc.h new file mode 100644 index 0000000..51ed861 --- /dev/null +++ b/dev/LibC++/base_alloc.h @@ -0,0 +1,49 @@ +/* ------------------------------------------- + + Copyright ZKA Web Services Co. + +------------------------------------------- */ + +#pragma once + +#include + +namespace std::base_alloc +{ + /// @brief allocate a new class. + /// @tparam KindClass the class type to allocate. + template + inline KindClass* allocate(Args&&... args) + { + return new KindClass(forward(args)...); + } + + /// @brief allocate a new class. + /// @note aborts on error. + /// @tparam KindClass the class type to allocate. + template + inline KindClass* allocate_nothrow(Args&&... args) noexcept + { + return allocate(forward(args)...); + } + + /// @brief free a class. + /// @tparam KindClass the class type to allocate. + template + inline void release(KindClass ptr) + { + if (!ptr) + return; + + delete ptr; + } + + /// @brief destroy and free a class. + /// @note aborts on error. + /// @tparam KindClass the class type to allocate. + template + inline void release_nothrow(KindClass ptr) noexcept + { + release(ptr); + } +} // namespace std::base_alloc diff --git a/dev/LibC++/base_alloc.hxx b/dev/LibC++/base_alloc.hxx deleted file mode 100644 index 51ed861..0000000 --- a/dev/LibC++/base_alloc.hxx +++ /dev/null @@ -1,49 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Web Services Co. - -------------------------------------------- */ - -#pragma once - -#include - -namespace std::base_alloc -{ - /// @brief allocate a new class. - /// @tparam KindClass the class type to allocate. - template - inline KindClass* allocate(Args&&... args) - { - return new KindClass(forward(args)...); - } - - /// @brief allocate a new class. - /// @note aborts on error. - /// @tparam KindClass the class type to allocate. - template - inline KindClass* allocate_nothrow(Args&&... args) noexcept - { - return allocate(forward(args)...); - } - - /// @brief free a class. - /// @tparam KindClass the class type to allocate. - template - inline void release(KindClass ptr) - { - if (!ptr) - return; - - delete ptr; - } - - /// @brief destroy and free a class. - /// @note aborts on error. - /// @tparam KindClass the class type to allocate. - template - inline void release_nothrow(KindClass ptr) noexcept - { - release(ptr); - } -} // namespace std::base_alloc diff --git a/dev/LibC++/base_exception.h b/dev/LibC++/base_exception.h new file mode 100644 index 0000000..9efe209 --- /dev/null +++ b/dev/LibC++/base_exception.h @@ -0,0 +1,30 @@ +/* ------------------------------------------- + + Copyright ZKA Web Services Co. + +------------------------------------------- */ + +#pragma once + +#include +#include + +namespace std +{ + inline void __throw_general(void) + { + exit(33); + } + + inline void __throw_domain_error(const char* error) + { + __throw_general(); + __builtin_unreachable(); // prevent from continuing. + } + + inline void __throw_bad_array_new_length(void) + { + __throw_general(); + __builtin_unreachable(); // prevent from continuing. + } +} // namespace std diff --git a/dev/LibC++/base_exception.hxx b/dev/LibC++/base_exception.hxx deleted file mode 100644 index 9efe209..0000000 --- a/dev/LibC++/base_exception.hxx +++ /dev/null @@ -1,30 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Web Services Co. - -------------------------------------------- */ - -#pragma once - -#include -#include - -namespace std -{ - inline void __throw_general(void) - { - exit(33); - } - - inline void __throw_domain_error(const char* error) - { - __throw_general(); - __builtin_unreachable(); // prevent from continuing. - } - - inline void __throw_bad_array_new_length(void) - { - __throw_general(); - __builtin_unreachable(); // prevent from continuing. - } -} // namespace std diff --git a/dev/LibC++/defines.h b/dev/LibC++/defines.h new file mode 100644 index 0000000..c65b254 --- /dev/null +++ b/dev/LibC++/defines.h @@ -0,0 +1,125 @@ +/* ------------------------------------------- + + Copyright ZKA Web Services Co. + +------------------------------------------- */ + +#ifndef __NDK_DEFINES_HXX__ +#define __NDK_DEFINES_HXX__ + +#include +#include + +#ifndef __GNUC__ + +typedef __SIZE_TYPE__ size_t; + +#ifdef __LP64__ +typedef long int ssize_t; +#else +typedef int ssize_t; +#endif // __LP64__ + +typedef void* ptr_type; +typedef __SIZE_TYPE__ size_type; + +typedef size_t ptrdiff_t; +typedef size_t uintptr_t; +typedef void* voidptr_t; +typedef void* any_t; +typedef char* caddr_t; + +#ifndef NULL +#define NULL ((voidptr_t)0) +#endif // !null + +#ifdef __GNUC__ +#include +#elif defined(__NDK__) +#define __alloca(sz) __ndk_alloca(sz) +#endif + +#define __deref(ptr) (*(ptr)) + +#ifdef __cplusplus +#define __init_decl() \ + extern "C" \ + { +#define __fini_decl() \ + } \ + ; +#else +#define __init_decl() +#define __fini_decl() +#endif + +#if __has_builtin(__builtin_alloca) +#define alloca(sz) __builtin_alloca(sz) +#ifdef __alloca +#undef __alloca +#endif +#define __alloca alloca +#else +#warning ! alloca not detected ! +#endif + +typedef long long off_t; +typedef unsigned long long uoff_t; + +typedef union float_cast { + struct + { + unsigned int mantissa : 23; + unsigned int exponent : 8; + unsigned int sign : 1; + }; + + float f; +} __attribute__((packed)) float_cast_t; + +typedef union double_cast { + struct + { + unsigned long long int mantissa : 52; + unsigned int exponent : 11; + unsigned int sign : 1; + }; + + double f; +} __attribute__((packed)) double_cast_t; + +#endif // ifndef __GNUC__ + +/// Include these helpers as well. + +#ifdef __STD_CXX__ + +#include +#include + +#endif // ifdef __STD_CXX__ + +namespace std +{ + /// @brief Forward object. + /// @tparam Args the object type. + /// @param arg the object. + /// @return object's rvalue + template + inline Args&& forward(Args& arg) + { + return static_cast(arg); + } + + /// @brief Move object. + /// @tparam Args the object type. + /// @param arg the object. + /// @return object's rvalue + template + inline Args&& move(Args&& arg) + { + return static_cast(arg); + } +} // namespace std + +#endif /* __NDK_DEFINES_HXX__ */ diff --git a/dev/LibC++/defines.hxx b/dev/LibC++/defines.hxx deleted file mode 100644 index c65b254..0000000 --- a/dev/LibC++/defines.hxx +++ /dev/null @@ -1,125 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Web Services Co. - -------------------------------------------- */ - -#ifndef __NDK_DEFINES_HXX__ -#define __NDK_DEFINES_HXX__ - -#include -#include - -#ifndef __GNUC__ - -typedef __SIZE_TYPE__ size_t; - -#ifdef __LP64__ -typedef long int ssize_t; -#else -typedef int ssize_t; -#endif // __LP64__ - -typedef void* ptr_type; -typedef __SIZE_TYPE__ size_type; - -typedef size_t ptrdiff_t; -typedef size_t uintptr_t; -typedef void* voidptr_t; -typedef void* any_t; -typedef char* caddr_t; - -#ifndef NULL -#define NULL ((voidptr_t)0) -#endif // !null - -#ifdef __GNUC__ -#include -#elif defined(__NDK__) -#define __alloca(sz) __ndk_alloca(sz) -#endif - -#define __deref(ptr) (*(ptr)) - -#ifdef __cplusplus -#define __init_decl() \ - extern "C" \ - { -#define __fini_decl() \ - } \ - ; -#else -#define __init_decl() -#define __fini_decl() -#endif - -#if __has_builtin(__builtin_alloca) -#define alloca(sz) __builtin_alloca(sz) -#ifdef __alloca -#undef __alloca -#endif -#define __alloca alloca -#else -#warning ! alloca not detected ! -#endif - -typedef long long off_t; -typedef unsigned long long uoff_t; - -typedef union float_cast { - struct - { - unsigned int mantissa : 23; - unsigned int exponent : 8; - unsigned int sign : 1; - }; - - float f; -} __attribute__((packed)) float_cast_t; - -typedef union double_cast { - struct - { - unsigned long long int mantissa : 52; - unsigned int exponent : 11; - unsigned int sign : 1; - }; - - double f; -} __attribute__((packed)) double_cast_t; - -#endif // ifndef __GNUC__ - -/// Include these helpers as well. - -#ifdef __STD_CXX__ - -#include -#include - -#endif // ifdef __STD_CXX__ - -namespace std -{ - /// @brief Forward object. - /// @tparam Args the object type. - /// @param arg the object. - /// @return object's rvalue - template - inline Args&& forward(Args& arg) - { - return static_cast(arg); - } - - /// @brief Move object. - /// @tparam Args the object type. - /// @param arg the object. - /// @return object's rvalue - template - inline Args&& move(Args&& arg) - { - return static_cast(arg); - } -} // namespace std - -#endif /* __NDK_DEFINES_HXX__ */ diff --git a/dev/LibC++/exit.h b/dev/LibC++/exit.h new file mode 100644 index 0000000..0878e43 --- /dev/null +++ b/dev/LibC++/exit.h @@ -0,0 +1,21 @@ +/* ------------------------------------------- + + Copyright ZKA Web Services Co. + +------------------------------------------- */ + +#pragma once + +/// @brief CRT exit, with exit code (!!! exits all threads. !!!) +/// @param code +/// @return +extern "C" int exit(int code); + +/// @brief Standard C++ namespace +namespace std +{ + inline int exit(int code) + { + exit(code); + } +} // namespace std diff --git a/dev/LibC++/exit.hxx b/dev/LibC++/exit.hxx deleted file mode 100644 index 0878e43..0000000 --- a/dev/LibC++/exit.hxx +++ /dev/null @@ -1,21 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Web Services Co. - -------------------------------------------- */ - -#pragma once - -/// @brief CRT exit, with exit code (!!! exits all threads. !!!) -/// @param code -/// @return -extern "C" int exit(int code); - -/// @brief Standard C++ namespace -namespace std -{ - inline int exit(int code) - { - exit(code); - } -} // namespace std diff --git a/dev/LibC++/math.h b/dev/LibC++/math.h new file mode 100644 index 0000000..b6cd6a8 --- /dev/null +++ b/dev/LibC++/math.h @@ -0,0 +1,62 @@ +/* ------------------------------------------- + + Copyright ZKA Web Services Co. + +------------------------------------------- */ + +#pragma once + +#include + +/// @file Math.hxx +/// @brief Math functions. + +#ifdef __ZKA_USE_DOUBLE__ +typedef double real_type; +#else +typedef float real_type; +#endif + +namespace std::math +{ + /// @brief Power function, with Repeat argument. + template + inline real_type pow(real_type in) + { + if (Exponent == 0) + return 1; // Any number to the power of 0 is 1. + + if (Exponent == 1) + return in; // Any number to the power of 1 is itself. + + size_t cnt = Exponent; + + real_type result = 1; + + for (auto i = 0; i < cnt; ++i) + result *= in; + + return result; + } + + /// @brief Square of function, with Base template argument. + /// @param of Base argument to find sqquare of + template + inline real_type sqr(real_type in) + { + if (in == 0) + return 0; + + return pow<1 / Base>(in); + } + + /// @brief Linear interpolation equation solver. + /// @param from where? + /// @param to to? + /// @param Updated diff value according to difference. + inline real_type lerp(real_type to, real_type from, real_type stat) + { + real_type diff = (to - from); + return from + (diff * stat); + } +} // namespace std::math diff --git a/dev/LibC++/math.hxx b/dev/LibC++/math.hxx deleted file mode 100644 index b6cd6a8..0000000 --- a/dev/LibC++/math.hxx +++ /dev/null @@ -1,62 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Web Services Co. - -------------------------------------------- */ - -#pragma once - -#include - -/// @file Math.hxx -/// @brief Math functions. - -#ifdef __ZKA_USE_DOUBLE__ -typedef double real_type; -#else -typedef float real_type; -#endif - -namespace std::math -{ - /// @brief Power function, with Repeat argument. - template - inline real_type pow(real_type in) - { - if (Exponent == 0) - return 1; // Any number to the power of 0 is 1. - - if (Exponent == 1) - return in; // Any number to the power of 1 is itself. - - size_t cnt = Exponent; - - real_type result = 1; - - for (auto i = 0; i < cnt; ++i) - result *= in; - - return result; - } - - /// @brief Square of function, with Base template argument. - /// @param of Base argument to find sqquare of - template - inline real_type sqr(real_type in) - { - if (in == 0) - return 0; - - return pow<1 / Base>(in); - } - - /// @brief Linear interpolation equation solver. - /// @param from where? - /// @param to to? - /// @param Updated diff value according to difference. - inline real_type lerp(real_type to, real_type from, real_type stat) - { - real_type diff = (to - from); - return from + (diff * stat); - } -} // namespace std::math -- cgit v1.2.3