mirror of
https://github.com/EnderIce2/Fennix.git
synced 2025-07-01 02:19:15 +00:00
Merge remote-tracking branch 'Kernel/master'
This commit is contained in:
327
Kernel/include_std/algorithm
Normal file
327
Kernel/include_std/algorithm
Normal file
@ -0,0 +1,327 @@
|
||||
/*
|
||||
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 <utility>
|
||||
|
||||
namespace std
|
||||
{
|
||||
template <typename InputIt, typename OutputIt>
|
||||
OutputIt copy(InputIt first, InputIt last, OutputIt result)
|
||||
{
|
||||
while (first != last)
|
||||
{
|
||||
*result = *first;
|
||||
++result;
|
||||
++first;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template <class BidirIt1, class BidirIt2>
|
||||
BidirIt2 copy_backward(BidirIt1 first, BidirIt1 last, BidirIt2 d_last)
|
||||
{
|
||||
while (first != last)
|
||||
{
|
||||
*(--d_last) = *(--last);
|
||||
}
|
||||
return d_last;
|
||||
}
|
||||
|
||||
template <typename InputIt, typename OutputIt, typename UnaryOperation>
|
||||
OutputIt transform(InputIt first, InputIt last, OutputIt result, UnaryOperation op)
|
||||
{
|
||||
while (first != last)
|
||||
{
|
||||
*result = op(*first);
|
||||
++first;
|
||||
++result;
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
void swap(T &a, T &b) noexcept(std::is_nothrow_move_constructible<T>::value && std::is_nothrow_move_assignable<T>::value)
|
||||
{
|
||||
T temp = std::move(a);
|
||||
a = std::move(b);
|
||||
b = std::move(temp);
|
||||
}
|
||||
|
||||
template <class T2, std::size_t N>
|
||||
void swap(T2 (&a)[N], T2 (&b)[N]) noexcept(std::is_nothrow_swappable_v<T2>)
|
||||
{
|
||||
for (std::size_t i = 0; i < N; ++i)
|
||||
std::swap(a[i], b[i]);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
constexpr const T &min(const T &a, const T &b)
|
||||
{
|
||||
return (a < b) ? a : b;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
constexpr const T &max(const T &a, const T &b)
|
||||
{
|
||||
return (a > b) ? a : b;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
constexpr const T &clamp(const T &v, const T &lo, const T &hi)
|
||||
{
|
||||
return std::max(lo, std::min(v, hi));
|
||||
}
|
||||
|
||||
template <class T, class Compare>
|
||||
constexpr const T &clamp(const T &v, const T &lo, const T &hi, Compare comp)
|
||||
{
|
||||
return comp(v, lo) ? lo : comp(hi, v) ? hi
|
||||
: v;
|
||||
}
|
||||
|
||||
template <class ForwardIt1, class ForwardIt2>
|
||||
ForwardIt1 search(ForwardIt1 first, ForwardIt1 last,
|
||||
ForwardIt2 s_first, ForwardIt2 s_last)
|
||||
{
|
||||
for (; first != last; ++first)
|
||||
{
|
||||
ForwardIt1 it = first;
|
||||
for (ForwardIt2 s_it = s_first;; ++it, ++s_it)
|
||||
{
|
||||
if (s_it == s_last)
|
||||
return first;
|
||||
if (it == last)
|
||||
return last;
|
||||
if (!(*it == *s_it))
|
||||
break;
|
||||
}
|
||||
}
|
||||
return last;
|
||||
}
|
||||
|
||||
template <class InputIt, class T>
|
||||
constexpr InputIt find(InputIt first, InputIt last, const T &value)
|
||||
{
|
||||
for (; first != last; ++first)
|
||||
if (*first == value)
|
||||
return first;
|
||||
|
||||
return last;
|
||||
}
|
||||
|
||||
template <class InputIt, class UnaryPred>
|
||||
constexpr InputIt find_if(InputIt first, InputIt last, UnaryPred p)
|
||||
{
|
||||
for (; first != last; ++first)
|
||||
if (p(*first))
|
||||
return first;
|
||||
|
||||
return last;
|
||||
}
|
||||
|
||||
template <class InputIt, class UnaryPred>
|
||||
constexpr InputIt find_if_not(InputIt first, InputIt last, UnaryPred q)
|
||||
{
|
||||
for (; first != last; ++first)
|
||||
if (!q(*first))
|
||||
return first;
|
||||
|
||||
return last;
|
||||
}
|
||||
|
||||
template <class ForwardIt1, class ForwardIt2>
|
||||
ForwardIt1 find_end(ForwardIt1 first, ForwardIt1 last,
|
||||
ForwardIt2 s_first, ForwardIt2 s_last)
|
||||
{
|
||||
if (s_first == s_last)
|
||||
return last;
|
||||
ForwardIt1 result = last;
|
||||
while (true)
|
||||
{
|
||||
ForwardIt1 new_result = std::search(first, last, s_first, s_last);
|
||||
if (new_result == last)
|
||||
return result;
|
||||
result = new_result;
|
||||
first = new_result;
|
||||
++first;
|
||||
}
|
||||
}
|
||||
|
||||
template <class InputIt, class ForwardIt>
|
||||
InputIt find_first_of(InputIt first, InputIt last,
|
||||
ForwardIt s_first, ForwardIt s_last)
|
||||
{
|
||||
for (; first != last; ++first)
|
||||
for (ForwardIt it = s_first; it != s_last; ++it)
|
||||
if (*first == *it)
|
||||
return first;
|
||||
return last;
|
||||
}
|
||||
|
||||
template <class ForwardIt, class T>
|
||||
ForwardIt remove(ForwardIt first, ForwardIt last, const T &value)
|
||||
{
|
||||
first = std::find(first, last, value);
|
||||
if (first != last)
|
||||
for (ForwardIt i = first; ++i != last;)
|
||||
if (!(*i == value))
|
||||
*first++ = std::move(*i);
|
||||
return first;
|
||||
}
|
||||
|
||||
template <class ForwardIt, class UnaryPred>
|
||||
ForwardIt remove_if(ForwardIt first, ForwardIt last, UnaryPred p)
|
||||
{
|
||||
first = std::find_if(first, last, p);
|
||||
if (first != last)
|
||||
for (ForwardIt i = first; ++i != last;)
|
||||
if (!p(*i))
|
||||
*first++ = std::move(*i);
|
||||
return first;
|
||||
}
|
||||
|
||||
template <class ForwardIt, class T>
|
||||
void fill(ForwardIt first, ForwardIt last, const T &value)
|
||||
{
|
||||
for (; first != last; ++first)
|
||||
*first = value;
|
||||
}
|
||||
|
||||
template <class OutputIt, class Size, class T>
|
||||
OutputIt fill_n(OutputIt first, Size count, const T &value)
|
||||
{
|
||||
for (Size i = 0; i < count; ++i)
|
||||
{
|
||||
*first = value;
|
||||
++first;
|
||||
}
|
||||
return first;
|
||||
}
|
||||
|
||||
template <class InputIt1, class InputIt2>
|
||||
constexpr bool equal(InputIt1 first1, InputIt1 last1, InputIt2 first2)
|
||||
{
|
||||
while (first1 != last1)
|
||||
{
|
||||
if (!(*first1 == *first2))
|
||||
return false;
|
||||
|
||||
++first1;
|
||||
++first2;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class ExecutionPolicy, class ForwardIt1, class ForwardIt2>
|
||||
bool equal(ExecutionPolicy &&policy, ForwardIt1 first1, ForwardIt1 last1, ForwardIt2 first2)
|
||||
{
|
||||
while (first1 != last1)
|
||||
{
|
||||
if (!(*first1 == *first2))
|
||||
return false;
|
||||
|
||||
++first1;
|
||||
++first2;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class InputIt1, class InputIt2, class BinaryPred>
|
||||
constexpr bool equal(InputIt1 first1, InputIt1 last1, InputIt2 first2, BinaryPred p)
|
||||
{
|
||||
while (first1 != last1)
|
||||
{
|
||||
if (!p(*first1, *first2))
|
||||
return false;
|
||||
|
||||
++first1;
|
||||
++first2;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class ExecutionPolicy, class ForwardIt1, class ForwardIt2, class BinaryPred>
|
||||
bool equal(ExecutionPolicy &&policy, ForwardIt1 first1, ForwardIt1 last1, ForwardIt2 first2, BinaryPred p)
|
||||
{
|
||||
while (first1 != last1)
|
||||
{
|
||||
if (!p(*first1, *first2))
|
||||
return false;
|
||||
|
||||
++first1;
|
||||
++first2;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class InputIt1, class InputIt2>
|
||||
constexpr bool equal(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2)
|
||||
{
|
||||
while (first1 != last1)
|
||||
{
|
||||
if (!(*first1 == *first2))
|
||||
return false;
|
||||
|
||||
++first1;
|
||||
++first2;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class ExecutionPolicy, class ForwardIt1, class ForwardIt2>
|
||||
bool equal(ExecutionPolicy &&policy, ForwardIt1 first1, ForwardIt1 last1, ForwardIt2 first2, ForwardIt2 last2)
|
||||
{
|
||||
while (first1 != last1)
|
||||
{
|
||||
if (!(*first1 == *first2))
|
||||
return false;
|
||||
|
||||
++first1;
|
||||
++first2;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class InputIt1, class InputIt2, class BinaryPred>
|
||||
constexpr bool equal(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, BinaryPred p)
|
||||
{
|
||||
while (first1 != last1)
|
||||
{
|
||||
if (!p(*first1, *first2))
|
||||
return false;
|
||||
|
||||
++first1;
|
||||
++first2;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class ExecutionPolicy, class ForwardIt1, class ForwardIt2, class BinaryPred>
|
||||
bool equal(ExecutionPolicy &&policy, ForwardIt1 first1, ForwardIt1 last1, ForwardIt2 first2, ForwardIt2 last2, BinaryPred p)
|
||||
{
|
||||
while (first1 != last1)
|
||||
{
|
||||
if (!p(*first1, *first2))
|
||||
return false;
|
||||
|
||||
++first1;
|
||||
++first2;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
50
Kernel/include_std/assert.h
Normal file
50
Kernel/include_std/assert.h
Normal file
@ -0,0 +1,50 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifndef __FENNIX_KERNEL_ASSERT_H__
|
||||
#define __FENNIX_KERNEL_ASSERT_H__
|
||||
|
||||
#include <debug.h>
|
||||
|
||||
EXTERNC void __attribute__((noreturn)) HandleAssertionFailed(const char *File, int Line,
|
||||
const char *Expression);
|
||||
|
||||
#define assert(x) \
|
||||
do \
|
||||
{ \
|
||||
if (__builtin_expect(!!(!(x)), 0)) \
|
||||
{ \
|
||||
error("Assertion failed! [%s]", #x); \
|
||||
HandleAssertionFailed(__FILE__, __LINE__, #x); \
|
||||
__builtin_unreachable(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define assert_allow_continue(x) \
|
||||
do \
|
||||
{ \
|
||||
if (__builtin_expect(!!(!(x)), 0)) \
|
||||
{ \
|
||||
error("Assertion failed! [%s]", #x); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#if __STDC_VERSION__ >= 201112L && !defined(__cplusplus)
|
||||
#define static_assert _Static_assert
|
||||
#endif
|
||||
|
||||
#endif // !__FENNIX_KERNEL_ASSERT_H__
|
666
Kernel/include_std/atomic
Normal file
666
Kernel/include_std/atomic
Normal file
@ -0,0 +1,666 @@
|
||||
/*
|
||||
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 <types.h>
|
||||
#include <cstddef>
|
||||
#include <debug.h>
|
||||
|
||||
namespace std
|
||||
{
|
||||
#define _atomic(T) T
|
||||
#define builtin_atomic_n(name) __atomic_##name##_n
|
||||
#define builtin_atomic(name) __atomic_##name
|
||||
|
||||
/**
|
||||
* Specifies the memory ordering constraints for atomic operations.
|
||||
*
|
||||
* This enum specifies the possible values for the memory order
|
||||
* parameter of atomic operations.
|
||||
*
|
||||
* Possible values are:
|
||||
*
|
||||
* - memory_order_relaxed: There are no synchronization
|
||||
* or ordering constraints imposed on other reads or writes,
|
||||
* only this operation's atomicity is guaranteed.
|
||||
*
|
||||
* - memory_order_consume: A load operation with this
|
||||
* memory order performs a consume operation on the
|
||||
* affected memory location: no reads or writes in the
|
||||
* current thread dependent on the value currently loaded
|
||||
* can be reordered before this load.
|
||||
*
|
||||
* - memory_order_acquire: A load operation with this
|
||||
* memory order performs the acquire operation on the
|
||||
* affected memory location: no reads or writes in the
|
||||
* current thread can be reordered before this load.
|
||||
*
|
||||
* - memory_order_release: A store operation with this
|
||||
* memory order performs the release operation: no reads
|
||||
* or writes in the current thread can be reordered after
|
||||
* this store.
|
||||
*
|
||||
* - memory_order_acq_rel: A read-modify-write operation
|
||||
* with this memory order is both an acquire operation
|
||||
* and a release operation.
|
||||
*
|
||||
* - memory_order_seq_cst: A load operation with this
|
||||
* memory order performs an acquire operation, a store
|
||||
* performs a release operation, and read-modify-write
|
||||
* performs both an acquire operation and a release
|
||||
* operation, plus a single total order exists in which
|
||||
* all threads observe all modifications in the same order.
|
||||
*/
|
||||
enum class memory_order : int
|
||||
{
|
||||
relaxed = __ATOMIC_RELAXED,
|
||||
consume = __ATOMIC_CONSUME,
|
||||
acquire = __ATOMIC_ACQUIRE,
|
||||
release = __ATOMIC_RELEASE,
|
||||
acq_rel = __ATOMIC_ACQ_REL,
|
||||
seq_cst = __ATOMIC_SEQ_CST
|
||||
};
|
||||
|
||||
/**
|
||||
* Relaxed memory order
|
||||
*
|
||||
* No synchronization or ordering constraints
|
||||
* imposed on other reads or writes.
|
||||
* Only atomicity is guaranteed. */
|
||||
inline constexpr memory_order memory_order_relaxed =
|
||||
memory_order::relaxed;
|
||||
|
||||
/**
|
||||
* Consume memory order
|
||||
*
|
||||
* A load operation with this memory order
|
||||
* performs a consume operation on the affected
|
||||
* memory location. No reads or writes in the
|
||||
* current thread dependent on the value
|
||||
* currently loaded can be reordered before this
|
||||
* load. Writes to data-dependent variables in
|
||||
* other threads that release the same atomic
|
||||
* variable are visible in the current thread.
|
||||
*/
|
||||
inline constexpr memory_order memory_order_consume =
|
||||
memory_order::consume;
|
||||
|
||||
/** Acquire memory order
|
||||
*
|
||||
* A load operation with this memory order
|
||||
* performs the acquire operation on the affected
|
||||
* memory location. No reads or writes in the
|
||||
* current thread can be reordered before this
|
||||
* load. All writes in other threads that release
|
||||
* the same atomic variable are visible in the
|
||||
* current thread. */
|
||||
inline constexpr memory_order memory_order_acquire =
|
||||
memory_order::acquire;
|
||||
|
||||
/** Release memory order
|
||||
*
|
||||
* A store operation with this memory order
|
||||
* performs the release operation. No reads or
|
||||
* writes in the current thread can be reordered
|
||||
* after this store. All writes in the current
|
||||
* thread are visible in other threads that acquire
|
||||
* the same atomic variable, and writes that carry
|
||||
* a dependency into the atomic variable become
|
||||
* visible in other threads that consume the same
|
||||
* atomic. */
|
||||
inline constexpr memory_order memory_order_release =
|
||||
memory_order::release;
|
||||
|
||||
/** Acquire-release memory order
|
||||
*
|
||||
* A read-modify-write operation with this memory
|
||||
* order is both an acquire operation and a release
|
||||
* operation. No memory reads or writes in the
|
||||
* current thread can be reordered before the load,
|
||||
* nor after the store. All writes in other threads
|
||||
* that release the same atomic variable are visible
|
||||
* before the modification, and the modification is
|
||||
* visible in other threads that acquire the same
|
||||
* atomic variable. */
|
||||
inline constexpr memory_order memory_order_acq_rel =
|
||||
memory_order::acq_rel;
|
||||
|
||||
/** Sequentially-consistent memory order
|
||||
*
|
||||
* A load operation with this memory order performs
|
||||
* an acquire operation, a store performs a release
|
||||
* operation, and read-modify-write performs both an
|
||||
* acquire operation and a release operation.
|
||||
* Additionally, a single total order exists in which
|
||||
* all threads observe all modifications in the same
|
||||
* order. */
|
||||
inline constexpr memory_order memory_order_seq_cst =
|
||||
memory_order::seq_cst;
|
||||
|
||||
template <typename T>
|
||||
class atomic
|
||||
{
|
||||
_atomic(T) value;
|
||||
|
||||
public:
|
||||
atomic() : value(0) {}
|
||||
atomic(T desired) : value(desired) {}
|
||||
// atomic(const atomic &) = delete;
|
||||
|
||||
/**
|
||||
* Load the value of the atomic variable
|
||||
*
|
||||
* @note Order must be one of memory_order::relaxed,
|
||||
* memory_order::consume, memory_order::acquire or
|
||||
* memory_order::seq_cst
|
||||
*
|
||||
* @param order Memory order constraint to use
|
||||
* @return The value of the atomic variable
|
||||
*/
|
||||
inline __always_inline T load(memory_order order = memory_order::seq_cst) const
|
||||
{
|
||||
return builtin_atomic_n(load)(&this->value,
|
||||
static_cast<int>(order));
|
||||
}
|
||||
|
||||
/**
|
||||
* @copydoc load()
|
||||
*/
|
||||
inline __always_inline T load(memory_order order = memory_order::seq_cst) const volatile
|
||||
{
|
||||
return builtin_atomic_n(load)(&this->value,
|
||||
static_cast<int>(order));
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the value of the atomic variable
|
||||
*
|
||||
* @note Order must be one of memory_order::relaxed,
|
||||
* memory_order::release or memory_order::seq_cst
|
||||
*
|
||||
* @param desired The value to store
|
||||
* @param order Memory order constraint to use
|
||||
*/
|
||||
inline __always_inline void store(T desired, memory_order order = memory_order::seq_cst)
|
||||
{
|
||||
builtin_atomic_n(store)(&this->value, desired,
|
||||
static_cast<int>(order));
|
||||
}
|
||||
|
||||
/**
|
||||
* @copydoc store()
|
||||
*/
|
||||
inline __always_inline void store(T desired,
|
||||
memory_order order = memory_order::seq_cst) volatile
|
||||
{
|
||||
builtin_atomic_n(store)(&this->value, desired,
|
||||
static_cast<int>(order));
|
||||
}
|
||||
|
||||
/**
|
||||
* Exchange the value of the atomic variable
|
||||
*
|
||||
* @param desired The value to exchange
|
||||
* @param order Memory order constraint to use
|
||||
* @return The value of the atomic variable before the exchange
|
||||
*/
|
||||
inline __always_inline T exchange(T desired, memory_order order = memory_order::seq_cst)
|
||||
{
|
||||
return builtin_atomic_n(exchange)(&this->value, desired,
|
||||
static_cast<int>(order));
|
||||
}
|
||||
|
||||
/**
|
||||
* @copydoc exchange()
|
||||
*/
|
||||
inline __always_inline T exchange(T desired,
|
||||
memory_order order = memory_order::seq_cst) volatile
|
||||
{
|
||||
return builtin_atomic_n(exchange)(&this->value, desired,
|
||||
static_cast<int>(order));
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare and exchange the value of the atomic variable
|
||||
*
|
||||
* @param expected The expected value
|
||||
* @param desired The desired value
|
||||
* @param success Memory order constraint to use if the exchange succeeds
|
||||
* @param failure Memory order constraint to use if the exchange fails
|
||||
* @return True if the exchange succeeded, false otherwise
|
||||
*/
|
||||
inline __always_inline bool compare_exchange_weak(T &expected, T desired,
|
||||
memory_order success,
|
||||
memory_order failure)
|
||||
{
|
||||
return builtin_atomic(compare_exchange_weak)(&this->value, &expected,
|
||||
desired, false, success,
|
||||
failure);
|
||||
}
|
||||
|
||||
/**
|
||||
* @copydoc compare_exchange_weak()
|
||||
*/
|
||||
inline __always_inline bool compare_exchange_weak(T &expected, T desired,
|
||||
memory_order success,
|
||||
memory_order failure) volatile
|
||||
{
|
||||
return builtin_atomic(compare_exchange_weak)(&this->value, &expected,
|
||||
desired, false, success,
|
||||
failure);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare and exchange the value of the atomic variable
|
||||
*
|
||||
* @param expected The expected value
|
||||
* @param desired The desired value
|
||||
* @param order Memory order constraint to use
|
||||
* @return True if the exchange succeeded, false otherwise
|
||||
*/
|
||||
inline __always_inline bool compare_exchange_weak(T &expected, T desired,
|
||||
memory_order order =
|
||||
memory_order_seq_cst)
|
||||
{
|
||||
return builtin_atomic(compare_exchange_weak)(&this->value, &expected,
|
||||
desired, false, order,
|
||||
static_cast<int>(order));
|
||||
}
|
||||
|
||||
/**
|
||||
* @copydoc compare_exchange_weak()
|
||||
*/
|
||||
inline __always_inline bool compare_exchange_weak(T &expected, T desired,
|
||||
memory_order order =
|
||||
memory_order_seq_cst) volatile
|
||||
{
|
||||
return builtin_atomic(compare_exchange_weak)(&this->value, &expected,
|
||||
desired, false, order,
|
||||
static_cast<int>(order));
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare and exchange the value of the atomic variable
|
||||
*
|
||||
* @param expected The expected value
|
||||
* @param desired The desired value
|
||||
* @param success Memory order constraint to use if the exchange succeeds
|
||||
* @param failure Memory order constraint to use if the exchange fails
|
||||
* @return True if the exchange succeeded, false otherwise
|
||||
*/
|
||||
inline __always_inline bool compare_exchange_strong(T &expected, T desired,
|
||||
memory_order success,
|
||||
memory_order failure)
|
||||
{
|
||||
return builtin_atomic(compare_exchange_strong)(&this->value, &expected,
|
||||
desired, true, success,
|
||||
failure);
|
||||
}
|
||||
|
||||
/**
|
||||
* @copydoc compare_exchange_strong()
|
||||
*/
|
||||
inline __always_inline bool compare_exchange_strong(T &expected, T desired,
|
||||
memory_order success,
|
||||
memory_order failure) volatile
|
||||
{
|
||||
return builtin_atomic(compare_exchange_strong)(&this->value, &expected,
|
||||
desired, true, success,
|
||||
failure);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare and exchange the value of the atomic variable
|
||||
*
|
||||
* @param expected The expected value
|
||||
* @param desired The desired value
|
||||
* @param order Memory order constraint to use
|
||||
* @return True if the exchange succeeded, false otherwise
|
||||
*/
|
||||
inline __always_inline bool compare_exchange_strong(T &expected, T desired,
|
||||
memory_order order =
|
||||
memory_order_seq_cst)
|
||||
{
|
||||
return builtin_atomic(compare_exchange_strong)(&this->value, &expected,
|
||||
desired, true, order,
|
||||
static_cast<int>(order));
|
||||
}
|
||||
|
||||
/**
|
||||
* @copydoc compare_exchange_strong()
|
||||
*/
|
||||
inline __always_inline bool compare_exchange_strong(T &expected, T desired,
|
||||
memory_order order =
|
||||
memory_order_seq_cst) volatile
|
||||
{
|
||||
return builtin_atomic(compare_exchange_strong)(&this->value, &expected,
|
||||
desired, true, order,
|
||||
static_cast<int>(order));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch and add the value of the atomic variable
|
||||
*
|
||||
* @param arg The value to add
|
||||
* @param order Memory order constraint to use
|
||||
* @return The value of the atomic variable before the addition
|
||||
*/
|
||||
inline __always_inline T fetch_add(T arg, memory_order order =
|
||||
memory_order_seq_cst)
|
||||
{
|
||||
return builtin_atomic(fetch_add)(&this->value, arg,
|
||||
static_cast<int>(order));
|
||||
}
|
||||
|
||||
/**
|
||||
* @copydoc fetch_add()
|
||||
*/
|
||||
inline __always_inline T fetch_add(T arg, memory_order order =
|
||||
memory_order_seq_cst) volatile
|
||||
{
|
||||
return builtin_atomic(fetch_add)(&this->value, arg,
|
||||
static_cast<int>(order));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch and subtract the value of the atomic variable
|
||||
*
|
||||
* @param arg The value to subtract
|
||||
* @param order Memory order constraint to use
|
||||
* @return The value of the atomic variable before the subtraction
|
||||
*/
|
||||
inline __always_inline T fetch_sub(T arg, memory_order order =
|
||||
memory_order_seq_cst)
|
||||
{
|
||||
return builtin_atomic(fetch_sub)(&this->value, arg,
|
||||
static_cast<int>(order));
|
||||
}
|
||||
|
||||
/**
|
||||
* @copydoc fetch_sub()
|
||||
*/
|
||||
inline __always_inline T fetch_sub(T arg, memory_order order =
|
||||
memory_order_seq_cst) volatile
|
||||
{
|
||||
return builtin_atomic(fetch_sub)(&this->value, arg,
|
||||
static_cast<int>(order));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch and bitwise AND the value of the atomic variable
|
||||
*
|
||||
* @param arg The value to AND
|
||||
* @param order Memory order constraint to use
|
||||
* @return The value of the atomic variable before the AND
|
||||
*/
|
||||
inline __always_inline T fetch_and(T arg, memory_order order =
|
||||
memory_order_seq_cst)
|
||||
{
|
||||
return builtin_atomic(fetch_and)(&this->value, arg,
|
||||
static_cast<int>(order));
|
||||
}
|
||||
|
||||
/**
|
||||
* @copydoc fetch_and()
|
||||
*/
|
||||
inline __always_inline T fetch_and(T arg, memory_order order =
|
||||
memory_order_seq_cst) volatile
|
||||
{
|
||||
return builtin_atomic(fetch_and)(&this->value, arg,
|
||||
static_cast<int>(order));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch and bitwise OR the value of the atomic variable
|
||||
*
|
||||
* @param arg The value to OR
|
||||
* @param order Memory order constraint to use
|
||||
* @return The value of the atomic variable before the OR
|
||||
*/
|
||||
inline __always_inline T fetch_or(T arg, memory_order order =
|
||||
memory_order_seq_cst)
|
||||
{
|
||||
return builtin_atomic(fetch_or)(&this->value, arg,
|
||||
static_cast<int>(order));
|
||||
}
|
||||
|
||||
/**
|
||||
* @copydoc fetch_or()
|
||||
*/
|
||||
inline __always_inline T fetch_or(T arg, memory_order order =
|
||||
memory_order_seq_cst) volatile
|
||||
{
|
||||
return builtin_atomic(fetch_or)(&this->value, arg,
|
||||
static_cast<int>(order));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch and bitwise XOR the value of the atomic variable
|
||||
*
|
||||
* @param arg The value to XOR
|
||||
* @param order Memory order constraint to use
|
||||
* @return The value of the atomic variable before the XOR
|
||||
*/
|
||||
inline __always_inline T fetch_xor(T arg, memory_order order =
|
||||
memory_order_seq_cst)
|
||||
{
|
||||
return builtin_atomic(fetch_xor)(&this->value, arg,
|
||||
static_cast<int>(order));
|
||||
}
|
||||
|
||||
/**
|
||||
* @copydoc fetch_xor()
|
||||
*/
|
||||
inline __always_inline T fetch_xor(T arg, memory_order order =
|
||||
memory_order_seq_cst) volatile
|
||||
{
|
||||
return builtin_atomic(fetch_xor)(&this->value, arg,
|
||||
static_cast<int>(order));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch and bitwise NAND the value of the atomic variable
|
||||
*
|
||||
* @param arg The value to NAND
|
||||
* @param order Memory order constraint to use
|
||||
* @return The value of the atomic variable before the NAND
|
||||
*/
|
||||
inline __always_inline T fetch_nand(T arg, memory_order order =
|
||||
memory_order_seq_cst)
|
||||
{
|
||||
return builtin_atomic(fetch_nand)(&this->value, arg,
|
||||
static_cast<int>(order));
|
||||
}
|
||||
|
||||
/**
|
||||
* @copydoc fetch_nand()
|
||||
*/
|
||||
inline __always_inline T fetch_nand(T arg, memory_order order =
|
||||
memory_order_seq_cst) volatile
|
||||
{
|
||||
return builtin_atomic(fetch_nand)(&this->value, arg,
|
||||
static_cast<int>(order));
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify all threads waiting on this atomic variable
|
||||
*/
|
||||
void notify_all() { stub; }
|
||||
|
||||
/**
|
||||
* @copydoc notify_all()
|
||||
*/
|
||||
void notify_all() volatile { stub; }
|
||||
|
||||
/**
|
||||
* Notify one thread waiting on this atomic variable
|
||||
*/
|
||||
void notify_one() { stub; }
|
||||
|
||||
/**
|
||||
* @copydoc notify_one()
|
||||
*/
|
||||
void notify_one() volatile { stub; }
|
||||
|
||||
/**
|
||||
* Wait for the atomic variable to change
|
||||
*
|
||||
* @param old The value to wait for
|
||||
* @param order Memory order constraint to use
|
||||
*/
|
||||
void wait(T old, memory_order order =
|
||||
memory_order::seq_cst) const
|
||||
{
|
||||
while (this->load(order) == old)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether this atomic type is lock-free
|
||||
* @return True if this atomic type is lock-free
|
||||
*/
|
||||
bool is_lock_free() const
|
||||
{
|
||||
stub;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @copydoc is_lock_free()
|
||||
*/
|
||||
bool is_lock_free() const volatile
|
||||
{
|
||||
stub;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Equals true if this atomic type is always lock-free
|
||||
*/
|
||||
static constexpr bool is_always_lock_free = true;
|
||||
|
||||
/************************************************/
|
||||
T operator++() { return this->fetch_add(1) + 1; }
|
||||
// T operator++() volatile { return this->fetch_add(1) + 1; }
|
||||
|
||||
T operator++(int) { return this->fetch_add(1); }
|
||||
// T operator++(int) volatile { return this->fetch_add(1); }
|
||||
/************************************************/
|
||||
T operator--() { return this->fetch_sub(1) - 1; }
|
||||
// T operator--() volatile { return this->fetch_sub(1) - 1; }
|
||||
|
||||
T operator--(int) { return this->fetch_sub(1); }
|
||||
// T operator--(int) volatile { return this->fetch_sub(1); }
|
||||
/************************************************/
|
||||
T operator+=(T arg) { return this->fetch_add(arg) + arg; }
|
||||
// T operator+=(T arg) volatile { return this->fetch_add(arg) + arg; }
|
||||
|
||||
// T operator+=(ptrdiff_t arg) { return this->fetch_add(arg) + arg; }
|
||||
// T operator+=(ptrdiff_t arg) volatile { return this->fetch_add(arg) + arg; }
|
||||
/************************************************/
|
||||
T operator-=(T arg) { return this->fetch_sub(arg) - arg; }
|
||||
// T operator-=(T arg) volatile { return this->fetch_sub(arg) - arg; }
|
||||
|
||||
// T operator-=(ptrdiff_t arg) { return this->fetch_sub(arg) - arg; }
|
||||
// T operator-=(ptrdiff_t arg) volatile { return this->fetch_sub(arg) - arg; }
|
||||
/************************************************/
|
||||
T operator&=(T arg) { return this->fetch_and(arg) & arg; }
|
||||
// T operator&=(T arg) volatile { return this->fetch_and(arg) & arg; }
|
||||
|
||||
T operator|=(T arg) { return this->fetch_or(arg) | arg; }
|
||||
// T operator|=(T arg) volatile { return this->fetch_or(arg) | arg; }
|
||||
|
||||
T operator^=(T arg) { return this->fetch_xor(arg) ^ arg; }
|
||||
// T operator^=(T arg) volatile { return this->fetch_xor(arg) ^ arg; }
|
||||
/************************************************/
|
||||
T operator=(T desired)
|
||||
{
|
||||
this->store(desired);
|
||||
return desired;
|
||||
}
|
||||
// T operator=(T desired) volatile
|
||||
// {
|
||||
// this->store(desired);
|
||||
// return desired;
|
||||
// }
|
||||
|
||||
atomic &operator=(const atomic &other) = delete;
|
||||
atomic &operator=(const atomic &other) volatile = delete;
|
||||
/************************************************/
|
||||
|
||||
/* non standard functions */
|
||||
|
||||
T operator->() { return this->load(); }
|
||||
T operator~() { return this->fetch_nand(-1); }
|
||||
|
||||
operator bool() { return this->load() != 0; }
|
||||
operator T() const { return this->load(); }
|
||||
|
||||
bool operator==(const atomic &other) const { return this->load() == other.load(); }
|
||||
bool operator==(T other) const { return this->load() == other; }
|
||||
};
|
||||
|
||||
typedef atomic<bool> atomic_bool;
|
||||
typedef atomic<char> atomic_char;
|
||||
typedef atomic<signed char> atomic_schar;
|
||||
typedef atomic<unsigned char> atomic_uchar;
|
||||
typedef atomic<short> atomic_short;
|
||||
typedef atomic<unsigned short> atomic_ushort;
|
||||
typedef atomic<int> atomic_int;
|
||||
typedef atomic<unsigned int> atomic_uint;
|
||||
typedef atomic<long> atomic_long;
|
||||
typedef atomic<unsigned long> atomic_ulong;
|
||||
typedef atomic<long long> atomic_llong;
|
||||
typedef atomic<unsigned long long> atomic_ullong;
|
||||
typedef atomic<char16_t> atomic_char16_t;
|
||||
typedef atomic<char32_t> atomic_char32_t;
|
||||
typedef atomic<wchar_t> atomic_wchar_t;
|
||||
typedef atomic<int8_t> atomic_int8_t;
|
||||
typedef atomic<uint8_t> atomic_uint8_t;
|
||||
typedef atomic<int16_t> atomic_int16_t;
|
||||
typedef atomic<uint16_t> atomic_uint16_t;
|
||||
typedef atomic<int32_t> atomic_int32_t;
|
||||
typedef atomic<uint32_t> atomic_uint32_t;
|
||||
typedef atomic<int64_t> atomic_int64_t;
|
||||
typedef atomic<uint64_t> atomic_uint64_t;
|
||||
typedef atomic<int_least8_t> atomic_int_least8_t;
|
||||
typedef atomic<uint_least8_t> atomic_uint_least8_t;
|
||||
typedef atomic<int_least16_t> atomic_int_least16_t;
|
||||
typedef atomic<uint_least16_t> atomic_uint_least16_t;
|
||||
typedef atomic<int_least32_t> atomic_int_least32_t;
|
||||
typedef atomic<uint_least32_t> atomic_uint_least32_t;
|
||||
typedef atomic<int_least64_t> atomic_int_least64_t;
|
||||
typedef atomic<uint_least64_t> atomic_uint_least64_t;
|
||||
typedef atomic<int_fast8_t> atomic_int_fast8_t;
|
||||
typedef atomic<uint_fast8_t> atomic_uint_fast8_t;
|
||||
typedef atomic<int_fast16_t> atomic_int_fast16_t;
|
||||
typedef atomic<uint_fast16_t> atomic_uint_fast16_t;
|
||||
typedef atomic<int_fast32_t> atomic_int_fast32_t;
|
||||
typedef atomic<uint_fast32_t> atomic_uint_fast32_t;
|
||||
typedef atomic<int_fast64_t> atomic_int_fast64_t;
|
||||
typedef atomic<uint_fast64_t> atomic_uint_fast64_t;
|
||||
typedef atomic<intptr_t> atomic_intptr_t;
|
||||
typedef atomic<uintptr_t> atomic_uintptr_t;
|
||||
typedef atomic<size_t> atomic_size_t;
|
||||
typedef atomic<ptrdiff_t> atomic_ptrdiff_t;
|
||||
typedef atomic<intmax_t> atomic_intmax_t;
|
||||
typedef atomic<uintmax_t> atomic_uintmax_t;
|
||||
}
|
||||
|
||||
#undef builtin_atomic_n
|
||||
#undef builtin_atomic
|
294
Kernel/include_std/bitset
Normal file
294
Kernel/include_std/bitset
Normal file
@ -0,0 +1,294 @@
|
||||
/*
|
||||
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 <string>
|
||||
|
||||
namespace std
|
||||
{
|
||||
template <std::size_t N>
|
||||
class bitset
|
||||
{
|
||||
private:
|
||||
unsigned long long m_bits;
|
||||
|
||||
public:
|
||||
class reference
|
||||
{
|
||||
private:
|
||||
unsigned long long &m_bits;
|
||||
std::size_t m_pos;
|
||||
|
||||
public:
|
||||
reference(unsigned long long &bits, std::size_t pos) : m_bits(bits), m_pos(pos) {}
|
||||
~reference() {}
|
||||
|
||||
reference &operator=(bool x)
|
||||
{
|
||||
if (x)
|
||||
m_bits |= (1 << m_pos);
|
||||
else
|
||||
m_bits &= ~(1 << m_pos);
|
||||
return *this;
|
||||
}
|
||||
|
||||
reference &operator=(const reference &x)
|
||||
{
|
||||
if (x)
|
||||
m_bits |= (1 << m_pos);
|
||||
else
|
||||
m_bits &= ~(1 << m_pos);
|
||||
return *this;
|
||||
}
|
||||
|
||||
operator bool() const
|
||||
{
|
||||
return (m_bits & (1 << m_pos)) != 0;
|
||||
}
|
||||
|
||||
bool operator~() const
|
||||
{
|
||||
return (m_bits & (1 << m_pos)) == 0;
|
||||
}
|
||||
|
||||
reference &flip()
|
||||
{
|
||||
m_bits ^= (1 << m_pos);
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
constexpr bitset() : m_bits(0) {}
|
||||
constexpr bitset(unsigned long long bits) : m_bits(bits) {}
|
||||
|
||||
template <class CharT>
|
||||
explicit bitset(const CharT *str,
|
||||
std::size_t n = std::size_t(-1),
|
||||
CharT zero = CharT('0'),
|
||||
CharT one = CharT('1'))
|
||||
{
|
||||
m_bits = 0;
|
||||
std::size_t len = n == std::size_t(-1) ? std::char_traits<CharT>::length(str) : n;
|
||||
for (std::size_t i = 0; i < len; i++)
|
||||
{ /* FIXME: This is a hack, but it works for now. */
|
||||
if (CharT('0') != zero || CharT('1') != one)
|
||||
{
|
||||
if (str[i] == zero)
|
||||
m_bits &= ~(1ULL << i);
|
||||
else if (str[i] == one)
|
||||
m_bits |= (1ULL << i);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (str[i] == zero)
|
||||
m_bits |= (0ULL << (N - 1 - i));
|
||||
else if (str[i] == one)
|
||||
m_bits |= (1ULL << (N - 1 - i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool operator==(const bitset &rhs) const
|
||||
{
|
||||
return m_bits == rhs.m_bits;
|
||||
}
|
||||
|
||||
bool operator[](std::size_t pos) const
|
||||
{
|
||||
return (m_bits & (1 << pos)) != 0;
|
||||
}
|
||||
|
||||
reference operator[](std::size_t pos)
|
||||
{
|
||||
return reference(m_bits, pos);
|
||||
}
|
||||
|
||||
bool test(std::size_t pos) const
|
||||
{
|
||||
return (m_bits & (1ULL << pos)) != 0;
|
||||
}
|
||||
|
||||
bool all() const
|
||||
{
|
||||
return m_bits == (1ULL << N) - 1;
|
||||
}
|
||||
|
||||
bool any() const
|
||||
{
|
||||
return m_bits != 0;
|
||||
}
|
||||
|
||||
bool none() const
|
||||
{
|
||||
return m_bits == 0;
|
||||
}
|
||||
|
||||
std::size_t count() const
|
||||
{
|
||||
std::size_t count = 0;
|
||||
for (std::size_t i = 0; i < N; i++)
|
||||
{
|
||||
if (test(i))
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
std::size_t size() const
|
||||
{
|
||||
return N;
|
||||
}
|
||||
|
||||
bitset &operator&=(const bitset &other)
|
||||
{
|
||||
m_bits &= other.m_bits;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bitset &operator|=(const bitset &other)
|
||||
{
|
||||
m_bits |= other.m_bits;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bitset &operator^=(const bitset &other)
|
||||
{
|
||||
m_bits ^= other.m_bits;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bitset operator~() const
|
||||
{
|
||||
return bitset(~m_bits);
|
||||
}
|
||||
|
||||
bitset operator<<(std::size_t pos) const
|
||||
{
|
||||
return bitset(m_bits << pos);
|
||||
}
|
||||
|
||||
bitset &operator<<=(std::size_t pos)
|
||||
{
|
||||
m_bits <<= pos;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bitset operator>>(std::size_t pos) const
|
||||
{
|
||||
return bitset(m_bits >> pos);
|
||||
}
|
||||
|
||||
bitset &operator>>=(std::size_t pos)
|
||||
{
|
||||
m_bits >>= pos;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bitset &set()
|
||||
{
|
||||
m_bits = (1ULL << N) - 1;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bitset &set(std::size_t pos, bool value = true)
|
||||
{
|
||||
if (value)
|
||||
m_bits |= (1ULL << pos);
|
||||
else
|
||||
m_bits &= ~(1ULL << pos);
|
||||
return *this;
|
||||
}
|
||||
|
||||
bitset &reset()
|
||||
{
|
||||
m_bits = 0;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bitset &reset(std::size_t pos)
|
||||
{
|
||||
m_bits &= ~(1 << pos);
|
||||
return *this;
|
||||
}
|
||||
|
||||
bitset &flip()
|
||||
{
|
||||
m_bits = ~m_bits;
|
||||
m_bits &= ((1ULL << N) - 1);
|
||||
return *this;
|
||||
}
|
||||
|
||||
bitset &flip(std::size_t pos)
|
||||
{
|
||||
m_bits ^= (1ULL << pos);
|
||||
m_bits &= ((1ULL << N) - 1);
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::string to_string(char zero = '0', char one = '1') const
|
||||
{
|
||||
std::string str;
|
||||
for (std::size_t i = N; i > 0; i--)
|
||||
{
|
||||
if (test(i - 1))
|
||||
str += one;
|
||||
else
|
||||
str += zero;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
unsigned long to_ulong() const
|
||||
{
|
||||
return static_cast<unsigned long>(m_bits);
|
||||
}
|
||||
|
||||
unsigned long long to_ullong() const
|
||||
{
|
||||
return m_bits;
|
||||
}
|
||||
};
|
||||
|
||||
template <std::size_t N>
|
||||
std::bitset<N> operator&(const std::bitset<N> &lhs,
|
||||
const std::bitset<N> &rhs)
|
||||
{
|
||||
std::bitset<N> result(lhs);
|
||||
result &= rhs;
|
||||
return result;
|
||||
}
|
||||
|
||||
template <std::size_t N>
|
||||
std::bitset<N> operator|(const std::bitset<N> &lhs,
|
||||
const std::bitset<N> &rhs)
|
||||
{
|
||||
std::bitset<N> result(lhs);
|
||||
result |= rhs;
|
||||
return result;
|
||||
}
|
||||
|
||||
template <std::size_t N>
|
||||
std::bitset<N> operator^(const std::bitset<N> &lhs,
|
||||
const std::bitset<N> &rhs)
|
||||
{
|
||||
std::bitset<N> result(lhs);
|
||||
result ^= rhs;
|
||||
return result;
|
||||
}
|
||||
}
|
19
Kernel/include_std/cassert
Normal file
19
Kernel/include_std/cassert
Normal file
@ -0,0 +1,19 @@
|
||||
/*
|
||||
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 <assert.h>
|
37
Kernel/include_std/cctype
Normal file
37
Kernel/include_std/cctype
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
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
|
||||
|
||||
namespace std
|
||||
{
|
||||
inline int tolower(int ch)
|
||||
{
|
||||
if (ch >= 'A' && ch <= 'Z')
|
||||
return ch + ('a' - 'A');
|
||||
else
|
||||
return ch;
|
||||
}
|
||||
|
||||
inline int toupper(int ch)
|
||||
{
|
||||
if (ch >= 'a' && ch <= 'z')
|
||||
return ch - ('a' - 'A');
|
||||
else
|
||||
return ch;
|
||||
}
|
||||
}
|
75
Kernel/include_std/cfloat
Normal file
75
Kernel/include_std/cfloat
Normal file
@ -0,0 +1,75 @@
|
||||
/*
|
||||
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
|
||||
|
||||
#define INFINITY (__builtin_inff())
|
||||
#define NAN (__builtin_nanf(""))
|
||||
#define FLT_ROUNDS 1
|
||||
#define FLT_EVAL_METHOD __FLT_EVAL_METHOD__
|
||||
|
||||
#define FLT_HAS_SUBNORM __FLT_HAS_DENORM__
|
||||
#define DBL_HAS_SUBNORM __DBL_HAS_DENORM__
|
||||
#define LDBL_HAS_SUBNORM __LDBL_HAS_DENORM__
|
||||
|
||||
#define FLT_RADIX __FLT_RADIX__
|
||||
|
||||
#define FLT_MANT_DIG __FLT_MANT_DIG__
|
||||
#define DBL_MANT_DIG __DBL_MANT_DIG__
|
||||
#define LDBL_MANT_DIG __LDBL_MANT_DIG__
|
||||
|
||||
#define FLT_DECIMAL_DIG __FLT_DECIMAL_DIG__
|
||||
#define DBL_DECIMAL_DIG __DBL_DECIMAL_DIG__
|
||||
#define LDBL_DECIMAL_DIG __LDBL_DECIMAL_DIG__
|
||||
|
||||
#define DECIMAL_DIG __DECIMAL_DIG__
|
||||
|
||||
#define FLT_DIG __FLT_DIG__
|
||||
#define DBL_DIG __DBL_DIG__
|
||||
#define LDBL_DIG __LDBL_DIG__
|
||||
|
||||
#define FLT_MIN_EXP __FLT_MIN_EXP__
|
||||
#define DBL_MIN_EXP __DBL_MIN_EXP__
|
||||
#define LDBL_MIN_EXP __LDBL_MIN_EXP__
|
||||
|
||||
#define FLT_MIN_10_EXP __FLT_MIN_10_EXP__
|
||||
#define DBL_MIN_10_EXP __DBL_MIN_10_EXP__
|
||||
#define LDBL_MIN_10_EXP __LDBL_MIN_10_EXP__
|
||||
|
||||
#define FLT_MAX_EXP __FLT_MAX_EXP__
|
||||
#define DBL_MAX_EXP __DBL_MAX_EXP__
|
||||
#define LDBL_MAX_EXP __LDBL_MAX_EXP__
|
||||
|
||||
#define FLT_MAX_10_EXP __FLT_MAX_10_EXP__
|
||||
#define DBL_MAX_10_EXP __DBL_MAX_10_EXP__
|
||||
#define LDBL_MAX_10_EXP __LDBL_MAX_10_EXP__
|
||||
|
||||
#define FLT_MAX __FLT_MAX__
|
||||
#define DBL_MAX __DBL_MAX__
|
||||
#define LDBL_MAX __LDBL_MAX__
|
||||
|
||||
#define FLT_EPSILON __FLT_EPSILON__
|
||||
#define DBL_EPSILON __DBL_EPSILON__
|
||||
#define LDBL_EPSILON __LDBL_EPSILON__
|
||||
|
||||
#define FLT_MIN __FLT_MIN__
|
||||
#define DBL_MIN __DBL_MIN__
|
||||
#define LDBL_MIN __LDBL_MIN__
|
||||
|
||||
#define FLT_TRUE_MIN __FLT_DENORM_MIN__
|
||||
#define DBL_TRUE_MIN __DBL_DENORM_MIN__
|
||||
#define LDBL_TRUE_MIN __LDBL_DENORM_MIN__
|
56
Kernel/include_std/climits
Normal file
56
Kernel/include_std/climits
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#undef CHAR_BIT
|
||||
#undef SCHAR_MIN
|
||||
#undef SCHAR_MAX
|
||||
#undef UCHAR_MAX
|
||||
#undef CHAR_MIN
|
||||
#undef CHAR_MAX
|
||||
#undef MB_LEN_MAX
|
||||
#undef SHRT_MIN
|
||||
#undef SHRT_MAX
|
||||
#undef USHRT_MAX
|
||||
#undef INT_MIN
|
||||
#undef INT_MAX
|
||||
#undef UINT_MAX
|
||||
#undef LONG_MIN
|
||||
#undef LONG_MAX
|
||||
#undef ULONG_MAX
|
||||
#undef LLONG_MIN
|
||||
#undef LLONG_MAX
|
||||
#undef ULLONG_MAX
|
||||
|
||||
#define CHAR_BIT __CHAR_BIT__
|
||||
#define SCHAR_MIN (-SCHAR_MAX - 1)
|
||||
#define SCHAR_MAX __SCHAR_MAX__
|
||||
#define UCHAR_MAX (SCHAR_MAX * 2 + 1)
|
||||
#define CHAR_MIN 0
|
||||
#define CHAR_MAX SCHAR_MAX
|
||||
#define MB_LEN_MAX 1
|
||||
#define SHRT_MIN (-SHRT_MAX - 1)
|
||||
#define SHRT_MAX __SHRT_MAX__
|
||||
#define USHRT_MAX (SHRT_MAX * 2 + 1)
|
||||
#define INT_MIN (-INT_MAX - 1)
|
||||
#define INT_MAX __INT_MAX__
|
||||
#define UINT_MAX (INT_MAX * 2U + 1U)
|
||||
#define LONG_MIN (-LONG_MAX - 1L)
|
||||
#define LONG_MAX __LONG_MAX__
|
||||
#define ULONG_MAX (LONG_MAX * 2UL + 1UL)
|
||||
#define LLONG_MIN (-LLONG_MAX - 1LL)
|
||||
#define LLONG_MAX __LONG_LONG_MAX__
|
||||
#define ULLONG_MAX (LLONG_MAX * 2ULL + 1ULL)
|
181
Kernel/include_std/cmath
Normal file
181
Kernel/include_std/cmath
Normal file
@ -0,0 +1,181 @@
|
||||
/*
|
||||
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 <cfloat>
|
||||
#include <type_traits>
|
||||
|
||||
namespace std
|
||||
{
|
||||
constexpr double sin(double x)
|
||||
{
|
||||
const int NUM_TERMS = 10;
|
||||
|
||||
double result = 0.0;
|
||||
double term = x;
|
||||
|
||||
for (int i = 1; i <= NUM_TERMS; ++i)
|
||||
{
|
||||
result += term;
|
||||
term *= -x * x / ((2 * i) * (2 * i + 1));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
constexpr float powf(float base, float exp)
|
||||
{
|
||||
float result = 1.0;
|
||||
for (int i = 0; i < (int)exp; ++i)
|
||||
result *= base;
|
||||
return result;
|
||||
}
|
||||
|
||||
constexpr double pow(double base, double exp)
|
||||
{
|
||||
double result = 1.0;
|
||||
for (int i = 0; i < (int)exp; ++i)
|
||||
result *= base;
|
||||
return result;
|
||||
}
|
||||
|
||||
constexpr long double powl(long double base, long double exp)
|
||||
{
|
||||
long double result = 1.0;
|
||||
for (long i = 0; i < (long)exp; ++i)
|
||||
result *= base;
|
||||
return result;
|
||||
}
|
||||
|
||||
constexpr float fabsf(float num)
|
||||
{
|
||||
if (num < 0)
|
||||
return -num;
|
||||
return num;
|
||||
}
|
||||
|
||||
constexpr double fabs(double num)
|
||||
{
|
||||
if (num < 0)
|
||||
return -num;
|
||||
return num;
|
||||
}
|
||||
|
||||
constexpr long double fabsl(long double num)
|
||||
{
|
||||
if (num < 0)
|
||||
return -num;
|
||||
return num;
|
||||
}
|
||||
|
||||
template <class Integer>
|
||||
constexpr bool isinf(Integer num)
|
||||
{
|
||||
union
|
||||
{
|
||||
unsigned long u;
|
||||
double f;
|
||||
} ieee754;
|
||||
ieee754.f = num;
|
||||
|
||||
bool a = ((unsigned)(ieee754.u >> 32) & 0x7fffffff) == 0x7ff00000;
|
||||
bool b = ((unsigned)ieee754.u == 0);
|
||||
return a && b;
|
||||
}
|
||||
|
||||
template <class Integer>
|
||||
constexpr bool isnan(Integer num)
|
||||
{
|
||||
return num != num;
|
||||
}
|
||||
|
||||
template <class Integer>
|
||||
constexpr double fabs(Integer num)
|
||||
{
|
||||
return num < 0 ? -num : num;
|
||||
}
|
||||
|
||||
template <class Integer>
|
||||
constexpr double remainder(Integer x, Integer y)
|
||||
{
|
||||
return x - (int)(x / y) * y;
|
||||
}
|
||||
|
||||
template <class Integer>
|
||||
constexpr double copysign(Integer mag, Integer sgn)
|
||||
{
|
||||
return (sgn < 0) ? -mag : mag;
|
||||
}
|
||||
|
||||
template <class Integer>
|
||||
constexpr bool signbit(Integer num)
|
||||
{
|
||||
return num < 0;
|
||||
}
|
||||
|
||||
template <class Integer>
|
||||
constexpr double fmod(Integer x, Integer y)
|
||||
{
|
||||
double result = std::remainder(std::fabs(x), y = std::fabs(y));
|
||||
if (std::signbit(result))
|
||||
result += (double)y;
|
||||
return std::copysign(result, x);
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wfloat-equal"
|
||||
|
||||
template <class Integer>
|
||||
constexpr double ceil(Integer num)
|
||||
{
|
||||
// int i = (int)num;
|
||||
// return i + (i < num);
|
||||
|
||||
double remainder = std::fmod((double)num, 1.0);
|
||||
return num >= 0 ? (remainder == 0 ? num : num + 1 - remainder) : num - remainder;
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
template <class Integer>
|
||||
constexpr double trunc(Integer num)
|
||||
{
|
||||
if (std::isinf(num))
|
||||
return num;
|
||||
|
||||
if (std::isnan(num))
|
||||
return num;
|
||||
|
||||
return static_cast<int>(num);
|
||||
}
|
||||
|
||||
template <class Integer>
|
||||
constexpr double exp(Integer num)
|
||||
{
|
||||
double result = 1.0;
|
||||
double term = 1.0;
|
||||
|
||||
for (int i = 1; i <= 10; ++i)
|
||||
{
|
||||
term *= static_cast<double>(num) / i;
|
||||
result += term;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
26
Kernel/include_std/concepts
Normal file
26
Kernel/include_std/concepts
Normal file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
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 <type_traits>
|
||||
|
||||
namespace std
|
||||
{
|
||||
template <class T>
|
||||
concept integral = std::is_integral_v<T>;
|
||||
}
|
189
Kernel/include_std/coroutine
Normal file
189
Kernel/include_std/coroutine
Normal file
@ -0,0 +1,189 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
namespace std
|
||||
{
|
||||
#if __cpp_impl_coroutine
|
||||
namespace detail
|
||||
{
|
||||
template <class, class...>
|
||||
struct coroutine_traits_base
|
||||
{
|
||||
};
|
||||
|
||||
template <class R, class... Args>
|
||||
requires requires { typename R::promise_type; }
|
||||
struct coroutine_traits_base<R, Args...>
|
||||
{
|
||||
using promise_type = R::promise_type;
|
||||
};
|
||||
}
|
||||
|
||||
template <class R, class... Args>
|
||||
struct coroutine_traits : detail::coroutine_traits_base<R, Args...>
|
||||
{
|
||||
};
|
||||
|
||||
template <class Promise = void>
|
||||
struct coroutine_handle;
|
||||
|
||||
struct noop_coroutine_promise;
|
||||
template <>
|
||||
struct coroutine_handle<noop_coroutine_promise>;
|
||||
using noop_coroutine_handle = coroutine_handle<noop_coroutine_promise>;
|
||||
noop_coroutine_handle noop_coroutine() noexcept;
|
||||
|
||||
template <class T>
|
||||
struct hash;
|
||||
template <class P>
|
||||
struct hash<coroutine_handle<P>>;
|
||||
|
||||
template <>
|
||||
struct coroutine_handle<void>
|
||||
{
|
||||
private:
|
||||
void *ptr;
|
||||
|
||||
public:
|
||||
constexpr coroutine_handle() noexcept : ptr(nullptr) {}
|
||||
constexpr coroutine_handle(nullptr_t __nul) noexcept : ptr(__nul) {}
|
||||
|
||||
coroutine_handle &operator=(nullptr_t) noexcept
|
||||
{
|
||||
ptr = nullptr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr void *address() const noexcept { return ptr; }
|
||||
|
||||
static constexpr coroutine_handle from_address(void *addr)
|
||||
{
|
||||
coroutine_handle temp;
|
||||
temp.ptr = addr;
|
||||
return temp;
|
||||
}
|
||||
|
||||
constexpr explicit operator bool() const noexcept { return bool(ptr); }
|
||||
bool done() const { return __builtin_coro_done(ptr); }
|
||||
void operator()() const { resume(); }
|
||||
void resume() const { __builtin_coro_resume(ptr); }
|
||||
void destroy() const { __builtin_coro_destroy(ptr); }
|
||||
};
|
||||
|
||||
constexpr bool operator==(coroutine_handle<> x, coroutine_handle<> y) noexcept
|
||||
{
|
||||
return x.address() == y.address();
|
||||
}
|
||||
|
||||
// constexpr strong_ordering operator<=>(coroutine_handle<> x, coroutine_handle<> y) noexcept;
|
||||
|
||||
template <class Promise>
|
||||
struct coroutine_handle
|
||||
{
|
||||
private:
|
||||
void *ptr;
|
||||
|
||||
public:
|
||||
constexpr coroutine_handle() noexcept : ptr(nullptr) {}
|
||||
constexpr coroutine_handle(nullptr_t) noexcept : ptr(nullptr) {}
|
||||
|
||||
static coroutine_handle from_promise(Promise &promise)
|
||||
{
|
||||
coroutine_handle temp;
|
||||
temp.ptr = __builtin_coro_promise((char *)&promise, __alignof(Promise), true);
|
||||
return temp;
|
||||
}
|
||||
|
||||
coroutine_handle &operator=(nullptr_t) noexcept
|
||||
{
|
||||
ptr = nullptr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr void *address() const noexcept { return ptr; }
|
||||
|
||||
static constexpr coroutine_handle from_address(void *addr)
|
||||
{
|
||||
coroutine_handle temp;
|
||||
temp.ptr = addr;
|
||||
return temp;
|
||||
}
|
||||
|
||||
constexpr operator coroutine_handle<>() const noexcept
|
||||
{
|
||||
return coroutine_handle<>::from_address(address());
|
||||
}
|
||||
|
||||
constexpr explicit operator bool() const noexcept { return bool(ptr); }
|
||||
bool done() const { return __builtin_coro_done(ptr); }
|
||||
void operator()() const { resume(); }
|
||||
void resume() const { __builtin_coro_resume(ptr); }
|
||||
void destroy() const { __builtin_coro_destroy(ptr); }
|
||||
Promise &promise() const { return *static_cast<Promise *>(ptr); }
|
||||
};
|
||||
|
||||
struct noop_coroutine_promise
|
||||
{
|
||||
};
|
||||
|
||||
template <>
|
||||
struct coroutine_handle<noop_coroutine_promise>
|
||||
{
|
||||
private:
|
||||
static struct __chframe
|
||||
{
|
||||
static void __stub_resume() {}
|
||||
void (*__a)() = __stub_resume;
|
||||
void (*__b)() = __stub_resume;
|
||||
struct noop_coroutine_promise __c;
|
||||
} __frame;
|
||||
void *ptr = &__frame;
|
||||
|
||||
explicit coroutine_handle() noexcept = default;
|
||||
friend coroutine_handle noop_coroutine() noexcept;
|
||||
|
||||
public:
|
||||
constexpr operator coroutine_handle<>() const noexcept { return coroutine_handle<>::from_address(address()); }
|
||||
constexpr explicit operator bool() const noexcept { return true; }
|
||||
constexpr bool done() const noexcept { return false; }
|
||||
constexpr void operator()() const noexcept {}
|
||||
constexpr void resume() const noexcept {}
|
||||
constexpr void destroy() const noexcept {}
|
||||
noop_coroutine_promise &promise() const noexcept { return __frame.__c; }
|
||||
constexpr void *address() const noexcept { return ptr; }
|
||||
};
|
||||
|
||||
inline noop_coroutine_handle::__chframe noop_coroutine_handle::__frame{};
|
||||
noop_coroutine_handle noop_coroutine() noexcept { return noop_coroutine_handle(); }
|
||||
|
||||
struct suspend_never
|
||||
{
|
||||
constexpr bool await_ready() const noexcept { return true; }
|
||||
constexpr void await_suspend(coroutine_handle<>) const noexcept {}
|
||||
constexpr void await_resume() const noexcept {}
|
||||
};
|
||||
|
||||
struct suspend_always
|
||||
{
|
||||
constexpr bool await_ready() const noexcept { return false; }
|
||||
constexpr void await_suspend(coroutine_handle<>) const noexcept {}
|
||||
constexpr void await_resume() const noexcept {}
|
||||
};
|
||||
#else
|
||||
#error "kernel requires -fcoroutines"
|
||||
#endif
|
||||
}
|
27
Kernel/include_std/cstddef
Normal file
27
Kernel/include_std/cstddef
Normal file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
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
|
||||
|
||||
namespace std
|
||||
{
|
||||
typedef __SIZE_TYPE__ size_t;
|
||||
typedef __PTRDIFF_TYPE__ ptrdiff_t;
|
||||
using nullptr_t = decltype(nullptr);
|
||||
}
|
||||
|
||||
static_assert(sizeof(std::nullptr_t) == sizeof(void *));
|
19
Kernel/include_std/cstring
Normal file
19
Kernel/include_std/cstring
Normal file
@ -0,0 +1,19 @@
|
||||
/*
|
||||
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 <convert.h>
|
51
Kernel/include_std/ctype.h
Normal file
51
Kernel/include_std/ctype.h
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifndef __FENNIX_KERNEL_C_TYPE_H__
|
||||
#define __FENNIX_KERNEL_C_TYPE_H__
|
||||
|
||||
#include <types.h>
|
||||
|
||||
START_EXTERNC
|
||||
|
||||
int isalnum(int);
|
||||
int isalpha(int);
|
||||
int isascii(int);
|
||||
|
||||
int isblank(int);
|
||||
int iscntrl(int);
|
||||
int isdigit(int);
|
||||
int isgraph(int);
|
||||
int islower(int);
|
||||
int isprint(int);
|
||||
int ispunct(int);
|
||||
int isspace(int);
|
||||
int isupper(int);
|
||||
int isxdigit(int);
|
||||
|
||||
int toascii(int);
|
||||
int tolower(int);
|
||||
int toupper(int);
|
||||
|
||||
#ifndef __cplusplus /* This conflicts with std */
|
||||
#define _toupper(c) ((c) - 0x20 * (((c) >= 'a') && ((c) <= 'z')))
|
||||
#define _tolower(c) ((c) + 0x20 * (((c) >= 'A') && ((c) <= 'Z')))
|
||||
#endif
|
||||
|
||||
END_EXTERNC
|
||||
|
||||
#endif // !__FENNIX_KERNEL_C_TYPE_H__
|
31
Kernel/include_std/dlfcn.h
Normal file
31
Kernel/include_std/dlfcn.h
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifndef __FENNIX_KERNEL_DLFCN_H__
|
||||
#define __FENNIX_KERNEL_DLFCN_H__
|
||||
|
||||
#include <types.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
const char *dli_fname;
|
||||
void *dli_fbase;
|
||||
const char *dli_sname;
|
||||
void *dli_saddr;
|
||||
} Dl_info;
|
||||
|
||||
#endif // !__FENNIX_KERNEL_DLFCN_H__
|
23
Kernel/include_std/errno.h
Normal file
23
Kernel/include_std/errno.h
Normal file
@ -0,0 +1,23 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifndef __FENNIX_KERNEL_STD_ERRNO_H__
|
||||
#define __FENNIX_KERNEL_STD_ERRNO_H__
|
||||
|
||||
#include <interface/errno.h>
|
||||
|
||||
#endif // !__FENNIX_KERNEL_STD_ERRNO_H__
|
47
Kernel/include_std/exception
Normal file
47
Kernel/include_std/exception
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifndef __FENNIX_KERNEL_EXCEPTION_H__
|
||||
#define __FENNIX_KERNEL_EXCEPTION_H__
|
||||
|
||||
#include <types.h>
|
||||
|
||||
namespace std
|
||||
{
|
||||
class exception
|
||||
{
|
||||
public:
|
||||
exception() noexcept {}
|
||||
exception(const exception &) noexcept = default;
|
||||
virtual ~exception() noexcept = default;
|
||||
exception &operator=(const exception &) noexcept = default;
|
||||
virtual const char *what() const noexcept { return "Exception"; }
|
||||
};
|
||||
|
||||
typedef void (*terminate_handler)();
|
||||
typedef void (*unexpected_handler)();
|
||||
|
||||
[[noreturn]] void terminate() noexcept;
|
||||
std::terminate_handler set_terminate(std::terminate_handler f) noexcept;
|
||||
std::terminate_handler get_terminate() noexcept;
|
||||
|
||||
[[noreturn]] void unexpected();
|
||||
std::unexpected_handler set_unexpected(std::unexpected_handler f) noexcept;
|
||||
std::unexpected_handler get_unexpected() noexcept;
|
||||
}
|
||||
|
||||
#endif // !__FENNIX_KERNEL_EXCEPTION_H__
|
30
Kernel/include_std/float.h
Normal file
30
Kernel/include_std/float.h
Normal file
@ -0,0 +1,30 @@
|
||||
/*
|
||||
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
|
||||
|
||||
/* Stubs */
|
||||
#define FLT_RADIX 2
|
||||
#if a64
|
||||
#define DBL_MANT_DIG 53
|
||||
#define DBL_MAX_10_EXP 308
|
||||
#define DBL_MAX 1.7976931348623157e+308
|
||||
#elif a32
|
||||
#define DBL_MANT_DIG 24
|
||||
#define DBL_MAX_10_EXP 38
|
||||
#define DBL_MAX 3.4028234663852886e+38
|
||||
#endif
|
254
Kernel/include_std/functional
Normal file
254
Kernel/include_std/functional
Normal file
@ -0,0 +1,254 @@
|
||||
/*
|
||||
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 <types.h>
|
||||
#include <algorithm>
|
||||
#include <typeinfo>
|
||||
|
||||
namespace std
|
||||
{
|
||||
template <typename T = void>
|
||||
struct equal_to
|
||||
{
|
||||
bool operator()(const T &lhs, const T &rhs) const
|
||||
{
|
||||
return lhs == rhs;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Key>
|
||||
struct hash
|
||||
{
|
||||
size_t operator()(const Key &key) const
|
||||
{
|
||||
#if defined(a64)
|
||||
static_assert(sizeof(uintptr_t) == sizeof(uint64_t));
|
||||
const uint64_t FNV_OFFSET_BASIS = 14695981039346656037ull;
|
||||
const uint64_t FNV_PRIME = 1099511628211ull;
|
||||
#elif defined(a32)
|
||||
static_assert(sizeof(uintptr_t) == sizeof(uint32_t));
|
||||
const uint32_t FNV_OFFSET_BASIS = 2166136261u;
|
||||
const uint32_t FNV_PRIME = 16777619u;
|
||||
#else
|
||||
#error "Unsupported architecture"
|
||||
#endif
|
||||
|
||||
const uint8_t *data = reinterpret_cast<const uint8_t *>(&key);
|
||||
const size_t size = sizeof(Key);
|
||||
uintptr_t hash = FNV_OFFSET_BASIS;
|
||||
|
||||
for (size_t i = 0; i < size; ++i)
|
||||
{
|
||||
hash ^= static_cast<uintptr_t>(data[i]);
|
||||
hash *= FNV_PRIME;
|
||||
}
|
||||
|
||||
return static_cast<size_t>(hash);
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class reference_wrapper;
|
||||
|
||||
template <class>
|
||||
class function; /* undefined */
|
||||
|
||||
template <class R, class... Args>
|
||||
class function<R(Args...)>
|
||||
{
|
||||
private:
|
||||
class impl_base
|
||||
{
|
||||
public:
|
||||
virtual ~impl_base() = default;
|
||||
virtual R invoke(Args...) const = 0;
|
||||
#ifdef __GXX_RTTI
|
||||
virtual const std::type_info &target_type() const noexcept = 0;
|
||||
#endif
|
||||
virtual impl_base *clone() const = 0;
|
||||
};
|
||||
|
||||
template <class F>
|
||||
class impl : public impl_base
|
||||
{
|
||||
public:
|
||||
F _f;
|
||||
|
||||
template <class G>
|
||||
impl(G &&f)
|
||||
: _f(std::forward<G>(f))
|
||||
{
|
||||
}
|
||||
|
||||
R invoke(Args... args) const override
|
||||
{
|
||||
return _f(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
#ifdef __GXX_RTTI
|
||||
const std::type_info &target_type() const noexcept override
|
||||
{
|
||||
return typeid(F);
|
||||
}
|
||||
#endif
|
||||
|
||||
impl_base *clone() const override
|
||||
{
|
||||
return new impl<F>(_f);
|
||||
}
|
||||
};
|
||||
|
||||
impl_base *_ptr;
|
||||
|
||||
public:
|
||||
using result_type = R;
|
||||
|
||||
function() noexcept
|
||||
: _ptr(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
function(std::nullptr_t) noexcept
|
||||
: _ptr(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
function(const function &other)
|
||||
: _ptr(other._ptr)
|
||||
{
|
||||
}
|
||||
|
||||
function(function &&other) noexcept
|
||||
: _ptr(other._ptr)
|
||||
{
|
||||
other._ptr = nullptr;
|
||||
}
|
||||
|
||||
template <class F>
|
||||
function(F &&f)
|
||||
: _ptr(new impl<F>(std::forward<F>(f)))
|
||||
{
|
||||
}
|
||||
|
||||
~function()
|
||||
{
|
||||
delete _ptr;
|
||||
}
|
||||
|
||||
function &operator=(const function &other)
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
delete _ptr;
|
||||
_ptr = other._ptr ? other._ptr->clone() : nullptr;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
function &operator=(function &&other)
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
delete _ptr;
|
||||
_ptr = other._ptr;
|
||||
other._ptr = nullptr;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
function &operator=(std::nullptr_t) noexcept
|
||||
{
|
||||
delete _ptr;
|
||||
_ptr = nullptr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class F>
|
||||
function &operator=(F &&f)
|
||||
{
|
||||
delete _ptr;
|
||||
_ptr = new impl<F>(std::forward<F>(f));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class F>
|
||||
function &operator=(std::reference_wrapper<F> f) noexcept
|
||||
{
|
||||
delete _ptr;
|
||||
_ptr = new impl<std::reference_wrapper<F>>(f);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void swap(function &other) noexcept
|
||||
{
|
||||
std::swap(_ptr, other._ptr);
|
||||
}
|
||||
|
||||
explicit operator bool() const noexcept
|
||||
{
|
||||
return _ptr != nullptr;
|
||||
}
|
||||
|
||||
R operator()(Args... args) const
|
||||
{
|
||||
return _ptr->invoke(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
#ifdef __GXX_RTTI
|
||||
const std::type_info &target_type() const noexcept
|
||||
{
|
||||
return _ptr ? _ptr->target_type() : typeid(void);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
T *target() noexcept
|
||||
{
|
||||
return _ptr && _ptr->target_type() == typeid(T) ? &static_cast<impl<T> *>(_ptr)->_f : nullptr;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
const T *target() const noexcept
|
||||
{
|
||||
return _ptr && _ptr->target_type() == typeid(T) ? &static_cast<impl<T> *>(_ptr)->_f : nullptr;
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
template <class R, class... Args>
|
||||
void swap(std::function<R(Args...)> &lhs, std::function<R(Args...)> &rhs) noexcept
|
||||
{
|
||||
lhs.swap(rhs);
|
||||
}
|
||||
|
||||
template <class R, class... ArgTypes>
|
||||
|
||||
bool operator==(const std::function<R(ArgTypes...)> &f, std::nullptr_t) noexcept
|
||||
{
|
||||
return !f;
|
||||
}
|
||||
|
||||
template <class T = void>
|
||||
struct less
|
||||
{
|
||||
constexpr bool operator()(const T &lhs, const T &rhs) const
|
||||
{
|
||||
return lhs < rhs;
|
||||
}
|
||||
};
|
||||
}
|
62
Kernel/include_std/initializer_list
Normal file
62
Kernel/include_std/initializer_list
Normal file
@ -0,0 +1,62 @@
|
||||
/*
|
||||
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>
|
||||
|
||||
namespace std
|
||||
{
|
||||
template <typename _E>
|
||||
class initializer_list
|
||||
{
|
||||
public:
|
||||
typedef _E value_type;
|
||||
typedef const _E &reference;
|
||||
typedef const _E &const_reference;
|
||||
typedef size_t size_type;
|
||||
typedef const _E *iterator;
|
||||
typedef const _E *const_iterator;
|
||||
|
||||
private:
|
||||
iterator array;
|
||||
size_type len;
|
||||
|
||||
public:
|
||||
constexpr initializer_list(const_iterator a, size_type l)
|
||||
: array(a), len(l) {}
|
||||
|
||||
constexpr initializer_list()
|
||||
: array(nullptr), len(0) {}
|
||||
|
||||
constexpr size_type size() const { return len; }
|
||||
constexpr const_iterator begin() const { return array; }
|
||||
constexpr const_iterator end() const { return begin() + size(); }
|
||||
};
|
||||
|
||||
template <class E>
|
||||
constexpr const E *begin(initializer_list<E> il)
|
||||
{
|
||||
return il.begin();
|
||||
}
|
||||
|
||||
template <class E>
|
||||
constexpr const E *end(initializer_list<E> il)
|
||||
{
|
||||
return il.end();
|
||||
}
|
||||
}
|
23
Kernel/include_std/inttypes.h
Normal file
23
Kernel/include_std/inttypes.h
Normal file
@ -0,0 +1,23 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifndef __FENNIX_KERNEL_INTTYPES_H__
|
||||
#define __FENNIX_KERNEL_INTTYPES_H__
|
||||
|
||||
#include <types.h>
|
||||
|
||||
#endif // !__FENNIX_KERNEL_INTTYPES_H__
|
286
Kernel/include_std/ios
Normal file
286
Kernel/include_std/ios
Normal file
@ -0,0 +1,286 @@
|
||||
/*
|
||||
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 <system_error>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <locale>
|
||||
|
||||
#ifdef in
|
||||
#undef in
|
||||
#endif /* deprecated macro in */
|
||||
|
||||
namespace std
|
||||
{
|
||||
enum class io_errc
|
||||
{
|
||||
stream = 1,
|
||||
};
|
||||
|
||||
typedef long long streamsize;
|
||||
|
||||
class ios_base
|
||||
{
|
||||
public:
|
||||
#pragma region Member types and constants
|
||||
|
||||
typedef int openmode;
|
||||
static constexpr openmode app = 1;
|
||||
static constexpr openmode binary = 2;
|
||||
static constexpr openmode in = 4;
|
||||
static constexpr openmode out = 8;
|
||||
static constexpr openmode trunc = 16;
|
||||
static constexpr openmode ate = 32;
|
||||
static constexpr openmode noreplace = 64;
|
||||
|
||||
typedef int fmtflags;
|
||||
static constexpr fmtflags dec = 1;
|
||||
static constexpr fmtflags oct = 2;
|
||||
static constexpr fmtflags hex = 4;
|
||||
static constexpr fmtflags basefield = dec | oct | hex;
|
||||
|
||||
static constexpr fmtflags left = 1;
|
||||
static constexpr fmtflags right = 2;
|
||||
static constexpr fmtflags internal = 4;
|
||||
static constexpr fmtflags adjustfield = left | right | internal;
|
||||
|
||||
static constexpr fmtflags scientific = 1;
|
||||
static constexpr fmtflags fixed = 2;
|
||||
static constexpr fmtflags floatfield = scientific | fixed;
|
||||
|
||||
static constexpr fmtflags boolalpha = 1;
|
||||
static constexpr fmtflags showbase = 2;
|
||||
static constexpr fmtflags showpoint = 4;
|
||||
static constexpr fmtflags showpos = 8;
|
||||
static constexpr fmtflags skipws = 16;
|
||||
static constexpr fmtflags unitbuf = 32;
|
||||
static constexpr fmtflags uppercase = 64;
|
||||
|
||||
typedef int iostate;
|
||||
static constexpr iostate goodbit = 0;
|
||||
static constexpr iostate badbit = 1;
|
||||
static constexpr iostate failbit = 2;
|
||||
static constexpr iostate eofbit = 4;
|
||||
|
||||
typedef int seekdir;
|
||||
static constexpr seekdir beg = 0;
|
||||
static constexpr seekdir end = 1;
|
||||
static constexpr seekdir cur = 2;
|
||||
|
||||
enum event
|
||||
{
|
||||
erase_event,
|
||||
imbue_event,
|
||||
copyfmt_event
|
||||
};
|
||||
|
||||
typedef void (*event_callback)(event type, ios_base &ios, int index);
|
||||
|
||||
#pragma endregion Member types and constants
|
||||
|
||||
#pragma region Member Functions
|
||||
|
||||
protected:
|
||||
ios_base();
|
||||
|
||||
public:
|
||||
ios_base(const ios_base &) = delete;
|
||||
virtual ~ios_base() = default;
|
||||
ios_base &operator=(const ios_base &) = delete;
|
||||
|
||||
#pragma endregion Member Functions
|
||||
|
||||
#pragma region Formatting
|
||||
|
||||
fmtflags flags() const
|
||||
{
|
||||
return _flags;
|
||||
}
|
||||
|
||||
fmtflags flags(fmtflags flags)
|
||||
{
|
||||
fmtflags old = _flags;
|
||||
_flags = flags;
|
||||
return old;
|
||||
}
|
||||
|
||||
fmtflags setf(fmtflags flags)
|
||||
{
|
||||
fmtflags old = _flags;
|
||||
_flags |= flags;
|
||||
return old;
|
||||
}
|
||||
|
||||
fmtflags setf(fmtflags flags, fmtflags mask)
|
||||
{
|
||||
fmtflags old = _flags;
|
||||
_flags &= ~mask;
|
||||
_flags |= flags;
|
||||
return old;
|
||||
}
|
||||
|
||||
void unsetf(fmtflags flags)
|
||||
{
|
||||
_flags &= ~flags;
|
||||
}
|
||||
|
||||
streamsize precision() const
|
||||
{
|
||||
return _precision;
|
||||
}
|
||||
|
||||
streamsize precision(streamsize new_precision)
|
||||
{
|
||||
streamsize old = _precision;
|
||||
_precision = new_precision;
|
||||
return old;
|
||||
}
|
||||
|
||||
streamsize width() const
|
||||
{
|
||||
return _width;
|
||||
}
|
||||
|
||||
streamsize width(streamsize new_width)
|
||||
{
|
||||
streamsize old = _width;
|
||||
_width = new_width;
|
||||
return old;
|
||||
}
|
||||
|
||||
#pragma endregion Formatting
|
||||
|
||||
#pragma region Locales
|
||||
|
||||
std::locale imbue(const std::locale &loc)
|
||||
{
|
||||
std::locale old = _loc;
|
||||
_loc = loc;
|
||||
__call_event(imbue_event, *this, 0);
|
||||
return old;
|
||||
}
|
||||
|
||||
std::locale getloc() const
|
||||
{
|
||||
return _loc;
|
||||
}
|
||||
|
||||
#pragma endregion Locales
|
||||
|
||||
#pragma region Internal Extensible Array
|
||||
|
||||
static int xalloc()
|
||||
{
|
||||
static int index = 0;
|
||||
return index++;
|
||||
}
|
||||
|
||||
long &iword(int index)
|
||||
{
|
||||
static std::vector<long> iwords;
|
||||
if ((size_t)index >= iwords.size())
|
||||
iwords.resize(index + 1);
|
||||
return iwords[index];
|
||||
}
|
||||
|
||||
void *&pword(int index)
|
||||
{
|
||||
static std::vector<void *> pwords;
|
||||
if ((size_t)index >= pwords.size())
|
||||
pwords.resize(index + 1);
|
||||
return pwords[index];
|
||||
}
|
||||
|
||||
#pragma endregion Internal Extensible Array
|
||||
|
||||
#pragma region Miscellaneous
|
||||
|
||||
void register_callback(event_callback function, int index)
|
||||
{
|
||||
_event_callback = function;
|
||||
__call_event(imbue_event, *this, index);
|
||||
}
|
||||
|
||||
static bool sync_with_stdio(bool sync = true)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
#pragma endregion Miscellaneous
|
||||
|
||||
#pragma region Member Classes
|
||||
|
||||
class failure
|
||||
{
|
||||
public:
|
||||
explicit failure(const std::string &message, const std::error_code &ec = std::io_errc::stream)
|
||||
{
|
||||
}
|
||||
|
||||
explicit failure(const char *message, const std::error_code &ec = std::io_errc::stream)
|
||||
{
|
||||
}
|
||||
|
||||
failure(const failure &other) noexcept
|
||||
{
|
||||
}
|
||||
|
||||
failure &operator=(const failure &other) noexcept
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
virtual const char *what() const noexcept
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
class Init
|
||||
{
|
||||
public:
|
||||
Init() = default;
|
||||
~Init() = default;
|
||||
};
|
||||
|
||||
#pragma endregion Member Classes
|
||||
|
||||
private:
|
||||
fmtflags _flags = skipws;
|
||||
streamsize _precision = 6;
|
||||
streamsize _width = 0;
|
||||
std::locale _loc = std::locale::classic();
|
||||
|
||||
static event_callback _event_callback;
|
||||
|
||||
static void __call_event(event type, ios_base &ios, int index)
|
||||
{
|
||||
if (_event_callback)
|
||||
_event_callback(type, ios, index);
|
||||
}
|
||||
};
|
||||
|
||||
template <class CharT, class Traits = std::char_traits<CharT>>
|
||||
class basic_ios : public std::ios_base
|
||||
{
|
||||
};
|
||||
|
||||
typedef basic_ios<char> ios;
|
||||
typedef basic_ios<wchar_t> wios;
|
||||
}
|
36
Kernel/include_std/iostream
Normal file
36
Kernel/include_std/iostream
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
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 <ostream>
|
||||
#include <istream>
|
||||
|
||||
namespace std
|
||||
{
|
||||
extern std::istream cin;
|
||||
extern std::wistream wcin;
|
||||
|
||||
extern std::ostream cout;
|
||||
extern std::wostream wcout;
|
||||
|
||||
extern std::ostream cerr;
|
||||
extern std::wostream wcerr;
|
||||
|
||||
extern std::ostream clog;
|
||||
extern std::wostream wclog;
|
||||
}
|
79
Kernel/include_std/istream
Normal file
79
Kernel/include_std/istream
Normal file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
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 <streambuf>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
#include <ios>
|
||||
|
||||
namespace std
|
||||
{
|
||||
template <class CharT, class Traits = std::char_traits<CharT>>
|
||||
class basic_istream : virtual public std::basic_ios<CharT, Traits>
|
||||
{
|
||||
};
|
||||
|
||||
template <class CharT, class Traits = std::char_traits<CharT>>
|
||||
class basic_iostream : public basic_istream<CharT, Traits>, public basic_ostream<CharT, Traits>
|
||||
{
|
||||
private:
|
||||
void init(std::basic_streambuf<CharT, Traits> *sb)
|
||||
{
|
||||
this->basic_istream<CharT, Traits>::rdbuf(sb);
|
||||
this->basic_ostream<CharT, Traits>::rdbuf(sb);
|
||||
}
|
||||
|
||||
public:
|
||||
typedef CharT char_type;
|
||||
typedef Traits::char_type traits_type;
|
||||
typedef Traits::int_type int_type;
|
||||
typedef Traits::pos_type pos_type;
|
||||
typedef Traits::off_type off_type;
|
||||
|
||||
explicit basic_iostream(std::basic_streambuf<CharT, Traits> *sb)
|
||||
{
|
||||
this->init(sb);
|
||||
}
|
||||
|
||||
basic_iostream(const basic_iostream &other) = delete;
|
||||
virtual ~basic_iostream() = default;
|
||||
|
||||
basic_iostream &operator=(const basic_iostream &other) = delete;
|
||||
|
||||
protected:
|
||||
basic_iostream(basic_iostream &&other)
|
||||
{
|
||||
this->rdbuf(other.rdbuf());
|
||||
other.rdbuf(nullptr);
|
||||
}
|
||||
|
||||
basic_iostream &operator=(basic_iostream &&other);
|
||||
|
||||
void swap(basic_iostream &other)
|
||||
{
|
||||
std::swap(this->rdbuf(), other.rdbuf());
|
||||
}
|
||||
};
|
||||
|
||||
typedef basic_istream<char> istream;
|
||||
typedef basic_istream<wchar_t> wistream;
|
||||
|
||||
typedef basic_iostream<char> iostream;
|
||||
typedef basic_iostream<wchar_t> wiostream;
|
||||
}
|
138
Kernel/include_std/iterator
Normal file
138
Kernel/include_std/iterator
Normal file
@ -0,0 +1,138 @@
|
||||
/*
|
||||
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
|
||||
|
||||
namespace std
|
||||
{
|
||||
struct input_iterator_tag
|
||||
{
|
||||
};
|
||||
|
||||
struct output_iterator_tag
|
||||
{
|
||||
};
|
||||
|
||||
struct forward_iterator_tag : public input_iterator_tag
|
||||
{
|
||||
};
|
||||
|
||||
struct bidirectional_iterator_tag : public forward_iterator_tag
|
||||
{
|
||||
};
|
||||
|
||||
struct random_access_iterator_tag : public bidirectional_iterator_tag
|
||||
{
|
||||
};
|
||||
|
||||
struct contiguous_iterator_tag : public random_access_iterator_tag
|
||||
{
|
||||
};
|
||||
|
||||
template <class Iter>
|
||||
struct iterator_traits
|
||||
{
|
||||
public:
|
||||
using difference_type = typename Iter::difference_type;
|
||||
using value_type = typename Iter::value_type;
|
||||
using pointer = typename Iter::pointer;
|
||||
using reference = typename Iter::reference;
|
||||
using iterator_category = typename Iter::iterator_category;
|
||||
};
|
||||
|
||||
template <class InputIt>
|
||||
constexpr typename std::iterator_traits<InputIt>::difference_type __do_distance(InputIt first, InputIt last, std::input_iterator_tag)
|
||||
{
|
||||
typename std::iterator_traits<InputIt>::difference_type result = 0;
|
||||
while (first != last)
|
||||
{
|
||||
++first;
|
||||
++result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template <class InputIt>
|
||||
constexpr typename std::iterator_traits<InputIt>::difference_type __do_distance(InputIt first, InputIt last, std::random_access_iterator_tag)
|
||||
{
|
||||
return last - first;
|
||||
}
|
||||
|
||||
template <class InputIt>
|
||||
constexpr typename std::iterator_traits<InputIt>::difference_type distance(InputIt first, InputIt last)
|
||||
{
|
||||
return __do_distance(first, last, typename std::iterator_traits<InputIt>::iterator_category());
|
||||
}
|
||||
|
||||
template <class InputIt>
|
||||
void __do_advance(InputIt &it, typename std::iterator_traits<InputIt>::difference_type n, std::input_iterator_tag)
|
||||
{
|
||||
while (n > 0)
|
||||
{
|
||||
--n;
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
template <class InputIt>
|
||||
void __do_advance(InputIt &it, typename std::iterator_traits<InputIt>::difference_type n, std::bidirectional_iterator_tag)
|
||||
{
|
||||
while (n > 0)
|
||||
{
|
||||
--n;
|
||||
++it;
|
||||
}
|
||||
while (n < 0)
|
||||
{
|
||||
++n;
|
||||
--it;
|
||||
}
|
||||
}
|
||||
|
||||
template <class InputIt>
|
||||
void __do_advance(InputIt &it, typename std::iterator_traits<InputIt>::difference_type n, std::random_access_iterator_tag)
|
||||
{
|
||||
it += n;
|
||||
}
|
||||
|
||||
template <class InputIt, class Distance>
|
||||
constexpr void advance(InputIt &it, Distance n)
|
||||
{
|
||||
__do_advance(it, typename std::iterator_traits<InputIt>::difference_type(n),
|
||||
typename std::iterator_traits<InputIt>::iterator_category());
|
||||
}
|
||||
|
||||
template <class BidirIt>
|
||||
constexpr BidirIt prev(BidirIt it, typename std::iterator_traits<BidirIt>::difference_type n = 1)
|
||||
{
|
||||
std::advance(it, -n);
|
||||
return it;
|
||||
}
|
||||
|
||||
template <class InputIt>
|
||||
constexpr InputIt next(InputIt it, typename std::iterator_traits<InputIt>::difference_type n = 1)
|
||||
{
|
||||
std::advance(it, n);
|
||||
return it;
|
||||
}
|
||||
|
||||
struct default_sentinel_t
|
||||
{
|
||||
};
|
||||
|
||||
inline constexpr default_sentinel_t default_sentinel{};
|
||||
}
|
940
Kernel/include_std/limits
Normal file
940
Kernel/include_std/limits
Normal file
@ -0,0 +1,940 @@
|
||||
/*
|
||||
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 <climits>
|
||||
#include <cfloat>
|
||||
|
||||
namespace std
|
||||
{
|
||||
enum float_round_style
|
||||
{
|
||||
round_indeterminate = -1,
|
||||
round_toward_zero = 0,
|
||||
round_to_nearest = 1,
|
||||
round_toward_infinity = 2,
|
||||
round_toward_neg_infinity = 3,
|
||||
};
|
||||
|
||||
enum float_denorm_style
|
||||
{
|
||||
denorm_indeterminate = -1,
|
||||
denorm_absent = 0,
|
||||
denorm_present = 1
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class numeric_limits
|
||||
{
|
||||
public:
|
||||
static constexpr bool is_specialized = false;
|
||||
|
||||
static constexpr T min() { return T(); }
|
||||
static constexpr T max() { return T(); }
|
||||
static constexpr T lowest() { return T(); }
|
||||
|
||||
static constexpr int digits = 0;
|
||||
static constexpr int digits10 = 0;
|
||||
static constexpr int max_digits10 = 0;
|
||||
|
||||
static constexpr bool is_signed = false;
|
||||
static constexpr bool is_integer = false;
|
||||
static constexpr bool is_exact = false;
|
||||
static constexpr int radix = 0;
|
||||
static constexpr T epsilon() { return T(); }
|
||||
static constexpr T round_error() { return T(); }
|
||||
|
||||
static constexpr int min_exponent = 0;
|
||||
static constexpr int min_exponent10 = 0;
|
||||
static constexpr int max_exponent = 0;
|
||||
static constexpr int max_exponent10 = 0;
|
||||
|
||||
static constexpr bool has_infinity = false;
|
||||
static constexpr bool has_quiet_NaN = false;
|
||||
static constexpr bool has_signaling_NaN = false;
|
||||
static constexpr float_denorm_style has_denorm = denorm_absent;
|
||||
static constexpr bool has_denorm_loss = false;
|
||||
static constexpr T infinity() { return T(); }
|
||||
static constexpr T quiet_NaN() { return T(); }
|
||||
static constexpr T signaling_NaN() { return T(); }
|
||||
static constexpr T denorm_min() { return T(); }
|
||||
|
||||
static constexpr bool is_iec559 = false;
|
||||
static constexpr bool is_bounded = false;
|
||||
static constexpr bool is_modulo = false;
|
||||
|
||||
static constexpr bool traps = false;
|
||||
static constexpr bool tinyness_before = false;
|
||||
static constexpr float_round_style round_style = round_toward_zero;
|
||||
};
|
||||
|
||||
template <>
|
||||
class numeric_limits<bool>
|
||||
{
|
||||
public:
|
||||
static constexpr bool is_specialized = true;
|
||||
|
||||
static constexpr bool min() { return false; }
|
||||
static constexpr bool max() { return true; }
|
||||
static constexpr bool lowest() { return false; }
|
||||
|
||||
static constexpr int digits = 1;
|
||||
static constexpr int digits10 = 0;
|
||||
static constexpr int max_digits10 = 0;
|
||||
|
||||
static constexpr bool is_signed = false;
|
||||
static constexpr bool is_integer = true;
|
||||
static constexpr bool is_exact = true;
|
||||
static constexpr int radix = 2;
|
||||
static constexpr bool epsilon() { return 0; }
|
||||
static constexpr bool round_error() { return 0; }
|
||||
|
||||
static constexpr int min_exponent = 0;
|
||||
static constexpr int min_exponent10 = 0;
|
||||
static constexpr int max_exponent = 0;
|
||||
static constexpr int max_exponent10 = 0;
|
||||
|
||||
static constexpr bool has_infinity = false;
|
||||
static constexpr bool has_quiet_NaN = false;
|
||||
static constexpr bool has_signaling_NaN = false;
|
||||
static constexpr float_denorm_style has_denorm = denorm_absent;
|
||||
static constexpr bool has_denorm_loss = false;
|
||||
static constexpr bool infinity() { return 0; }
|
||||
static constexpr bool quiet_NaN() { return 0; }
|
||||
static constexpr bool signaling_NaN() { return 0; }
|
||||
static constexpr bool denorm_min() { return 0; }
|
||||
|
||||
static constexpr bool is_iec559 = false;
|
||||
static constexpr bool is_bounded = true;
|
||||
static constexpr bool is_modulo = false;
|
||||
|
||||
static constexpr bool traps = false;
|
||||
static constexpr bool tinyness_before = false;
|
||||
static constexpr float_round_style round_style = round_toward_zero;
|
||||
};
|
||||
|
||||
template <>
|
||||
class numeric_limits<char>
|
||||
{
|
||||
public:
|
||||
static constexpr bool is_specialized = true;
|
||||
|
||||
static constexpr char min() { return CHAR_MIN; }
|
||||
static constexpr char max() { return CHAR_MAX; }
|
||||
static constexpr char lowest() { return CHAR_MIN; }
|
||||
|
||||
static constexpr int digits = CHAR_BIT;
|
||||
static constexpr int digits10 = 0;
|
||||
static constexpr int max_digits10 = 0;
|
||||
|
||||
static constexpr bool is_signed = CHAR_MIN < 0;
|
||||
static constexpr bool is_integer = true;
|
||||
static constexpr bool is_exact = true;
|
||||
static constexpr int radix = 2;
|
||||
static constexpr char epsilon() { return 0; }
|
||||
static constexpr char round_error() { return 0; }
|
||||
|
||||
static constexpr int min_exponent = 0;
|
||||
static constexpr int min_exponent10 = 0;
|
||||
static constexpr int max_exponent = 0;
|
||||
static constexpr int max_exponent10 = 0;
|
||||
|
||||
static constexpr bool has_infinity = false;
|
||||
static constexpr bool has_quiet_NaN = false;
|
||||
static constexpr bool has_signaling_NaN = false;
|
||||
static constexpr float_denorm_style has_denorm = denorm_absent;
|
||||
static constexpr bool has_denorm_loss = false;
|
||||
static constexpr char infinity() { return 0; }
|
||||
static constexpr char quiet_NaN() { return 0; }
|
||||
static constexpr char signaling_NaN() { return 0; }
|
||||
static constexpr char denorm_min() { return 0; }
|
||||
|
||||
static constexpr bool is_iec559 = false;
|
||||
static constexpr bool is_bounded = true;
|
||||
static constexpr bool is_modulo = true;
|
||||
|
||||
static constexpr bool traps = false;
|
||||
static constexpr bool tinyness_before = false;
|
||||
static constexpr float_round_style round_style = round_toward_zero;
|
||||
};
|
||||
|
||||
template <>
|
||||
class numeric_limits<signed char>
|
||||
{
|
||||
public:
|
||||
static constexpr bool is_specialized = true;
|
||||
|
||||
static constexpr signed char min() { return SCHAR_MIN; }
|
||||
static constexpr signed char max() { return SCHAR_MAX; }
|
||||
static constexpr signed char lowest() { return SCHAR_MIN; }
|
||||
|
||||
static constexpr int digits = CHAR_BIT - 1;
|
||||
static constexpr int digits10 = 0;
|
||||
static constexpr int max_digits10 = 0;
|
||||
|
||||
static constexpr bool is_signed = true;
|
||||
static constexpr bool is_integer = true;
|
||||
static constexpr bool is_exact = true;
|
||||
static constexpr int radix = 2;
|
||||
static constexpr signed char epsilon() { return 0; }
|
||||
static constexpr signed char round_error() { return 0; }
|
||||
|
||||
static constexpr int min_exponent = 0;
|
||||
static constexpr int min_exponent10 = 0;
|
||||
static constexpr int max_exponent = 0;
|
||||
static constexpr int max_exponent10 = 0;
|
||||
|
||||
static constexpr bool has_infinity = false;
|
||||
static constexpr bool has_quiet_NaN = false;
|
||||
static constexpr bool has_signaling_NaN = false;
|
||||
static constexpr float_denorm_style has_denorm = denorm_absent;
|
||||
static constexpr bool has_denorm_loss = false;
|
||||
static constexpr signed char infinity() { return 0; }
|
||||
static constexpr signed char quiet_NaN() { return 0; }
|
||||
static constexpr signed char signaling_NaN() { return 0; }
|
||||
static constexpr signed char denorm_min() { return 0; }
|
||||
|
||||
static constexpr bool is_iec559 = false;
|
||||
static constexpr bool is_bounded = true;
|
||||
static constexpr bool is_modulo = true;
|
||||
|
||||
static constexpr bool traps = false;
|
||||
static constexpr bool tinyness_before = false;
|
||||
static constexpr float_round_style round_style = round_toward_zero;
|
||||
};
|
||||
|
||||
template <>
|
||||
class numeric_limits<unsigned char>
|
||||
{
|
||||
public:
|
||||
static constexpr bool is_specialized = true;
|
||||
|
||||
static constexpr unsigned char min() { return 0; }
|
||||
static constexpr unsigned char max() { return UCHAR_MAX; }
|
||||
static constexpr unsigned char lowest() { return 0; }
|
||||
|
||||
static constexpr int digits = CHAR_BIT;
|
||||
static constexpr int digits10 = 0;
|
||||
static constexpr int max_digits10 = 0;
|
||||
|
||||
static constexpr bool is_signed = false;
|
||||
static constexpr bool is_integer = true;
|
||||
static constexpr bool is_exact = true;
|
||||
static constexpr int radix = 2;
|
||||
static constexpr unsigned char epsilon() { return 0; }
|
||||
static constexpr unsigned char round_error() { return 0; }
|
||||
|
||||
static constexpr int min_exponent = 0;
|
||||
static constexpr int min_exponent10 = 0;
|
||||
static constexpr int max_exponent = 0;
|
||||
static constexpr int max_exponent10 = 0;
|
||||
|
||||
static constexpr bool has_infinity = false;
|
||||
static constexpr bool has_quiet_NaN = false;
|
||||
static constexpr bool has_signaling_NaN = false;
|
||||
static constexpr float_denorm_style has_denorm = denorm_absent;
|
||||
static constexpr bool has_denorm_loss = false;
|
||||
static constexpr unsigned char infinity() { return 0; }
|
||||
static constexpr unsigned char quiet_NaN() { return 0; }
|
||||
static constexpr unsigned char signaling_NaN() { return 0; }
|
||||
static constexpr unsigned char denorm_min() { return 0; }
|
||||
|
||||
static constexpr bool is_iec559 = false;
|
||||
static constexpr bool is_bounded = true;
|
||||
static constexpr bool is_modulo = true;
|
||||
|
||||
static constexpr bool traps = false;
|
||||
static constexpr bool tinyness_before = false;
|
||||
static constexpr float_round_style round_style = round_toward_zero;
|
||||
};
|
||||
|
||||
template <>
|
||||
class numeric_limits<wchar_t>
|
||||
{
|
||||
public:
|
||||
static constexpr bool is_specialized = true;
|
||||
|
||||
static constexpr wchar_t min() { return __WCHAR_MIN__; }
|
||||
static constexpr wchar_t max() { return __WCHAR_MAX__; }
|
||||
static constexpr wchar_t lowest() { return __WCHAR_MIN__; }
|
||||
|
||||
static constexpr int digits = CHAR_BIT * sizeof(wchar_t) - 1;
|
||||
static constexpr int digits10 = 0;
|
||||
static constexpr int max_digits10 = 0;
|
||||
|
||||
static constexpr bool is_signed = __WCHAR_MIN__ < 0;
|
||||
static constexpr bool is_integer = true;
|
||||
static constexpr bool is_exact = true;
|
||||
static constexpr int radix = 2;
|
||||
static constexpr wchar_t epsilon() { return 0; }
|
||||
static constexpr wchar_t round_error() { return 0; }
|
||||
|
||||
static constexpr int min_exponent = 0;
|
||||
static constexpr int min_exponent10 = 0;
|
||||
static constexpr int max_exponent = 0;
|
||||
static constexpr int max_exponent10 = 0;
|
||||
|
||||
static constexpr bool has_infinity = false;
|
||||
static constexpr bool has_quiet_NaN = false;
|
||||
static constexpr bool has_signaling_NaN = false;
|
||||
static constexpr float_denorm_style has_denorm = denorm_absent;
|
||||
static constexpr bool has_denorm_loss = false;
|
||||
static constexpr wchar_t infinity() { return 0; }
|
||||
static constexpr wchar_t quiet_NaN() { return 0; }
|
||||
static constexpr wchar_t signaling_NaN() { return 0; }
|
||||
static constexpr wchar_t denorm_min() { return 0; }
|
||||
|
||||
static constexpr bool is_iec559 = false;
|
||||
static constexpr bool is_bounded = true;
|
||||
static constexpr bool is_modulo = true;
|
||||
|
||||
static constexpr bool traps = false;
|
||||
static constexpr bool tinyness_before = false;
|
||||
static constexpr float_round_style round_style = round_toward_zero;
|
||||
};
|
||||
|
||||
template <>
|
||||
class numeric_limits<char8_t>
|
||||
{
|
||||
public:
|
||||
static constexpr bool is_specialized = true;
|
||||
|
||||
static constexpr char8_t min() { return 0; }
|
||||
static constexpr char8_t max() { return UCHAR_MAX; }
|
||||
static constexpr char8_t lowest() { return 0; }
|
||||
|
||||
static constexpr int digits = CHAR_BIT;
|
||||
static constexpr int digits10 = 0;
|
||||
static constexpr int max_digits10 = 0;
|
||||
|
||||
static constexpr bool is_signed = false;
|
||||
static constexpr bool is_integer = true;
|
||||
static constexpr bool is_exact = true;
|
||||
static constexpr int radix = 2;
|
||||
static constexpr char8_t epsilon() { return 0; }
|
||||
static constexpr char8_t round_error() { return 0; }
|
||||
|
||||
static constexpr int min_exponent = 0;
|
||||
static constexpr int min_exponent10 = 0;
|
||||
static constexpr int max_exponent = 0;
|
||||
static constexpr int max_exponent10 = 0;
|
||||
|
||||
static constexpr bool has_infinity = false;
|
||||
static constexpr bool has_quiet_NaN = false;
|
||||
static constexpr bool has_signaling_NaN = false;
|
||||
static constexpr float_denorm_style has_denorm = denorm_absent;
|
||||
static constexpr bool has_denorm_loss = false;
|
||||
static constexpr char8_t infinity() { return 0; }
|
||||
static constexpr char8_t quiet_NaN() { return 0; }
|
||||
static constexpr char8_t signaling_NaN() { return 0; }
|
||||
static constexpr char8_t denorm_min() { return 0; }
|
||||
|
||||
static constexpr bool is_iec559 = false;
|
||||
static constexpr bool is_bounded = true;
|
||||
static constexpr bool is_modulo = true;
|
||||
|
||||
static constexpr bool traps = false;
|
||||
static constexpr bool tinyness_before = false;
|
||||
static constexpr float_round_style round_style = round_toward_zero;
|
||||
};
|
||||
|
||||
template <>
|
||||
class numeric_limits<char16_t>
|
||||
{
|
||||
public:
|
||||
static constexpr bool is_specialized = true;
|
||||
|
||||
static constexpr char16_t min() { return 0; }
|
||||
static constexpr char16_t max() { return USHRT_MAX; }
|
||||
static constexpr char16_t lowest() { return 0; }
|
||||
|
||||
static constexpr int digits = CHAR_BIT * sizeof(char16_t) - 1;
|
||||
static constexpr int digits10 = 0;
|
||||
static constexpr int max_digits10 = 0;
|
||||
|
||||
static constexpr bool is_signed = false;
|
||||
static constexpr bool is_integer = true;
|
||||
static constexpr bool is_exact = true;
|
||||
static constexpr int radix = 2;
|
||||
static constexpr char16_t epsilon() { return 0; }
|
||||
static constexpr char16_t round_error() { return 0; }
|
||||
|
||||
static constexpr int min_exponent = 0;
|
||||
static constexpr int min_exponent10 = 0;
|
||||
static constexpr int max_exponent = 0;
|
||||
static constexpr int max_exponent10 = 0;
|
||||
|
||||
static constexpr bool has_infinity = false;
|
||||
static constexpr bool has_quiet_NaN = false;
|
||||
static constexpr bool has_signaling_NaN = false;
|
||||
static constexpr float_denorm_style has_denorm = denorm_absent;
|
||||
static constexpr bool has_denorm_loss = false;
|
||||
static constexpr char16_t infinity() { return 0; }
|
||||
static constexpr char16_t quiet_NaN() { return 0; }
|
||||
static constexpr char16_t signaling_NaN() { return 0; }
|
||||
static constexpr char16_t denorm_min() { return 0; }
|
||||
|
||||
static constexpr bool is_iec559 = false;
|
||||
static constexpr bool is_bounded = true;
|
||||
static constexpr bool is_modulo = true;
|
||||
|
||||
static constexpr bool traps = false;
|
||||
static constexpr bool tinyness_before = false;
|
||||
static constexpr float_round_style round_style = round_toward_zero;
|
||||
};
|
||||
|
||||
template <>
|
||||
class numeric_limits<char32_t>
|
||||
{
|
||||
public:
|
||||
static constexpr bool is_specialized = true;
|
||||
|
||||
static constexpr char32_t min() { return 0; }
|
||||
static constexpr char32_t max() { return UINT_MAX; }
|
||||
static constexpr char32_t lowest() { return 0; }
|
||||
|
||||
static constexpr int digits = CHAR_BIT * sizeof(char32_t) - 1;
|
||||
static constexpr int digits10 = 0;
|
||||
static constexpr int max_digits10 = 0;
|
||||
|
||||
static constexpr bool is_signed = false;
|
||||
static constexpr bool is_integer = true;
|
||||
static constexpr bool is_exact = true;
|
||||
static constexpr int radix = 2;
|
||||
static constexpr char32_t epsilon() { return 0; }
|
||||
static constexpr char32_t round_error() { return 0; }
|
||||
|
||||
static constexpr int min_exponent = 0;
|
||||
static constexpr int min_exponent10 = 0;
|
||||
static constexpr int max_exponent = 0;
|
||||
static constexpr int max_exponent10 = 0;
|
||||
|
||||
static constexpr bool has_infinity = false;
|
||||
static constexpr bool has_quiet_NaN = false;
|
||||
static constexpr bool has_signaling_NaN = false;
|
||||
static constexpr float_denorm_style has_denorm = denorm_absent;
|
||||
static constexpr bool has_denorm_loss = false;
|
||||
static constexpr char32_t infinity() { return 0; }
|
||||
static constexpr char32_t quiet_NaN() { return 0; }
|
||||
static constexpr char32_t signaling_NaN() { return 0; }
|
||||
static constexpr char32_t denorm_min() { return 0; }
|
||||
|
||||
static constexpr bool is_iec559 = false;
|
||||
static constexpr bool is_bounded = true;
|
||||
static constexpr bool is_modulo = true;
|
||||
|
||||
static constexpr bool traps = false;
|
||||
static constexpr bool tinyness_before = false;
|
||||
static constexpr float_round_style round_style = round_toward_zero;
|
||||
};
|
||||
|
||||
template <>
|
||||
class numeric_limits<short>
|
||||
{
|
||||
public:
|
||||
static constexpr bool is_specialized = true;
|
||||
|
||||
static constexpr short min() { return SHRT_MIN; }
|
||||
static constexpr short max() { return SHRT_MAX; }
|
||||
static constexpr short lowest() { return SHRT_MIN; }
|
||||
|
||||
static constexpr int digits = CHAR_BIT * sizeof(short) - 1;
|
||||
static constexpr int digits10 = 0;
|
||||
static constexpr int max_digits10 = 0;
|
||||
|
||||
static constexpr bool is_signed = true;
|
||||
static constexpr bool is_integer = true;
|
||||
static constexpr bool is_exact = true;
|
||||
static constexpr int radix = 2;
|
||||
static constexpr short epsilon() { return 0; }
|
||||
static constexpr short round_error() { return 0; }
|
||||
|
||||
static constexpr int min_exponent = 0;
|
||||
static constexpr int min_exponent10 = 0;
|
||||
static constexpr int max_exponent = 0;
|
||||
static constexpr int max_exponent10 = 0;
|
||||
|
||||
static constexpr bool has_infinity = false;
|
||||
static constexpr bool has_quiet_NaN = false;
|
||||
static constexpr bool has_signaling_NaN = false;
|
||||
static constexpr float_denorm_style has_denorm = denorm_absent;
|
||||
static constexpr bool has_denorm_loss = false;
|
||||
static constexpr short infinity() { return 0; }
|
||||
static constexpr short quiet_NaN() { return 0; }
|
||||
static constexpr short signaling_NaN() { return 0; }
|
||||
static constexpr short denorm_min() { return 0; }
|
||||
|
||||
static constexpr bool is_iec559 = false;
|
||||
static constexpr bool is_bounded = true;
|
||||
static constexpr bool is_modulo = true;
|
||||
|
||||
static constexpr bool traps = false;
|
||||
static constexpr bool tinyness_before = false;
|
||||
static constexpr float_round_style round_style = round_toward_zero;
|
||||
};
|
||||
|
||||
template <>
|
||||
class numeric_limits<unsigned short>
|
||||
{
|
||||
public:
|
||||
static constexpr bool is_specialized = true;
|
||||
|
||||
static constexpr unsigned short min() { return 0; }
|
||||
static constexpr unsigned short max() { return USHRT_MAX; }
|
||||
static constexpr unsigned short lowest() { return 0; }
|
||||
|
||||
static constexpr int digits = CHAR_BIT * sizeof(unsigned short);
|
||||
static constexpr int digits10 = 0;
|
||||
static constexpr int max_digits10 = 0;
|
||||
|
||||
static constexpr bool is_signed = false;
|
||||
static constexpr bool is_integer = true;
|
||||
static constexpr bool is_exact = true;
|
||||
static constexpr int radix = 2;
|
||||
static constexpr unsigned short epsilon() { return 0; }
|
||||
static constexpr unsigned short round_error() { return 0; }
|
||||
|
||||
static constexpr int min_exponent = 0;
|
||||
static constexpr int min_exponent10 = 0;
|
||||
static constexpr int max_exponent = 0;
|
||||
static constexpr int max_exponent10 = 0;
|
||||
|
||||
static constexpr bool has_infinity = false;
|
||||
static constexpr bool has_quiet_NaN = false;
|
||||
static constexpr bool has_signaling_NaN = false;
|
||||
static constexpr float_denorm_style has_denorm = denorm_absent;
|
||||
static constexpr bool has_denorm_loss = false;
|
||||
static constexpr unsigned short infinity() { return 0; }
|
||||
static constexpr unsigned short quiet_NaN() { return 0; }
|
||||
static constexpr unsigned short signaling_NaN() { return 0; }
|
||||
static constexpr unsigned short denorm_min() { return 0; }
|
||||
|
||||
static constexpr bool is_iec559 = false;
|
||||
static constexpr bool is_bounded = true;
|
||||
static constexpr bool is_modulo = true;
|
||||
|
||||
static constexpr bool traps = false;
|
||||
static constexpr bool tinyness_before = false;
|
||||
static constexpr float_round_style round_style = round_toward_zero;
|
||||
};
|
||||
|
||||
template <>
|
||||
class numeric_limits<int>
|
||||
{
|
||||
public:
|
||||
static constexpr bool is_specialized = true;
|
||||
|
||||
static constexpr int min() { return INT_MIN; }
|
||||
static constexpr int max() { return INT_MAX; }
|
||||
static constexpr int lowest() { return INT_MIN; }
|
||||
|
||||
static constexpr int digits = CHAR_BIT * sizeof(int) - 1;
|
||||
static constexpr int digits10 = 0;
|
||||
static constexpr int max_digits10 = 0;
|
||||
|
||||
static constexpr bool is_signed = true;
|
||||
static constexpr bool is_integer = true;
|
||||
static constexpr bool is_exact = true;
|
||||
static constexpr int radix = 2;
|
||||
static constexpr int epsilon() { return 0; }
|
||||
static constexpr int round_error() { return 0; }
|
||||
|
||||
static constexpr int min_exponent = 0;
|
||||
static constexpr int min_exponent10 = 0;
|
||||
static constexpr int max_exponent = 0;
|
||||
static constexpr int max_exponent10 = 0;
|
||||
|
||||
static constexpr bool has_infinity = false;
|
||||
static constexpr bool has_quiet_NaN = false;
|
||||
static constexpr bool has_signaling_NaN = false;
|
||||
static constexpr float_denorm_style has_denorm = denorm_absent;
|
||||
static constexpr bool has_denorm_loss = false;
|
||||
static constexpr int infinity() { return 0; }
|
||||
static constexpr int quiet_NaN() { return 0; }
|
||||
static constexpr int signaling_NaN() { return 0; }
|
||||
static constexpr int denorm_min() { return 0; }
|
||||
|
||||
static constexpr bool is_iec559 = false;
|
||||
static constexpr bool is_bounded = true;
|
||||
static constexpr bool is_modulo = true;
|
||||
|
||||
static constexpr bool traps = false;
|
||||
static constexpr bool tinyness_before = false;
|
||||
static constexpr float_round_style round_style = round_toward_zero;
|
||||
};
|
||||
|
||||
template <>
|
||||
class numeric_limits<unsigned int>
|
||||
{
|
||||
public:
|
||||
static constexpr bool is_specialized = true;
|
||||
|
||||
static constexpr unsigned int min() { return 0; }
|
||||
static constexpr unsigned int max() { return UINT_MAX; }
|
||||
static constexpr unsigned int lowest() { return 0; }
|
||||
|
||||
static constexpr int digits = CHAR_BIT * sizeof(unsigned int);
|
||||
static constexpr int digits10 = 0;
|
||||
static constexpr int max_digits10 = 0;
|
||||
|
||||
static constexpr bool is_signed = false;
|
||||
static constexpr bool is_integer = true;
|
||||
static constexpr bool is_exact = true;
|
||||
static constexpr int radix = 2;
|
||||
static constexpr unsigned int epsilon() { return 0; }
|
||||
static constexpr unsigned int round_error() { return 0; }
|
||||
|
||||
static constexpr int min_exponent = 0;
|
||||
static constexpr int min_exponent10 = 0;
|
||||
static constexpr int max_exponent = 0;
|
||||
static constexpr int max_exponent10 = 0;
|
||||
|
||||
static constexpr bool has_infinity = false;
|
||||
static constexpr bool has_quiet_NaN = false;
|
||||
static constexpr bool has_signaling_NaN = false;
|
||||
static constexpr float_denorm_style has_denorm = denorm_absent;
|
||||
static constexpr bool has_denorm_loss = false;
|
||||
static constexpr unsigned int infinity() { return 0; }
|
||||
static constexpr unsigned int quiet_NaN() { return 0; }
|
||||
static constexpr unsigned int signaling_NaN() { return 0; }
|
||||
static constexpr unsigned int denorm_min() { return 0; }
|
||||
|
||||
static constexpr bool is_iec559 = false;
|
||||
static constexpr bool is_bounded = true;
|
||||
static constexpr bool is_modulo = true;
|
||||
|
||||
static constexpr bool traps = false;
|
||||
static constexpr bool tinyness_before = false;
|
||||
static constexpr float_round_style round_style = round_toward_zero;
|
||||
};
|
||||
|
||||
template <>
|
||||
class numeric_limits<long>
|
||||
{
|
||||
public:
|
||||
static constexpr bool is_specialized = true;
|
||||
|
||||
static constexpr long min() { return LONG_MIN; }
|
||||
static constexpr long max() { return LONG_MAX; }
|
||||
static constexpr long lowest() { return LONG_MIN; }
|
||||
|
||||
static constexpr int digits = CHAR_BIT * sizeof(long) - 1;
|
||||
static constexpr int digits10 = 0;
|
||||
static constexpr int max_digits10 = 0;
|
||||
|
||||
static constexpr bool is_signed = true;
|
||||
static constexpr bool is_integer = true;
|
||||
static constexpr bool is_exact = true;
|
||||
static constexpr int radix = 2;
|
||||
static constexpr long epsilon() { return 0; }
|
||||
static constexpr long round_error() { return 0; }
|
||||
|
||||
static constexpr int min_exponent = 0;
|
||||
static constexpr int min_exponent10 = 0;
|
||||
static constexpr int max_exponent = 0;
|
||||
static constexpr int max_exponent10 = 0;
|
||||
|
||||
static constexpr bool has_infinity = false;
|
||||
static constexpr bool has_quiet_NaN = false;
|
||||
static constexpr bool has_signaling_NaN = false;
|
||||
static constexpr float_denorm_style has_denorm = denorm_absent;
|
||||
static constexpr bool has_denorm_loss = false;
|
||||
static constexpr long infinity() { return 0; }
|
||||
static constexpr long quiet_NaN() { return 0; }
|
||||
static constexpr long signaling_NaN() { return 0; }
|
||||
static constexpr long denorm_min() { return 0; }
|
||||
|
||||
static constexpr bool is_iec559 = false;
|
||||
static constexpr bool is_bounded = true;
|
||||
static constexpr bool is_modulo = true;
|
||||
|
||||
static constexpr bool traps = false;
|
||||
static constexpr bool tinyness_before = false;
|
||||
static constexpr float_round_style round_style = round_toward_zero;
|
||||
};
|
||||
|
||||
template <>
|
||||
class numeric_limits<unsigned long>
|
||||
{
|
||||
public:
|
||||
static constexpr bool is_specialized = true;
|
||||
|
||||
static constexpr unsigned long min() { return 0; }
|
||||
static constexpr unsigned long max() { return ULONG_MAX; }
|
||||
static constexpr unsigned long lowest() { return 0; }
|
||||
|
||||
static constexpr int digits = CHAR_BIT * sizeof(unsigned long);
|
||||
static constexpr int digits10 = 0;
|
||||
static constexpr int max_digits10 = 0;
|
||||
|
||||
static constexpr bool is_signed = false;
|
||||
static constexpr bool is_integer = true;
|
||||
static constexpr bool is_exact = true;
|
||||
static constexpr int radix = 2;
|
||||
static constexpr unsigned long epsilon() { return 0; }
|
||||
static constexpr unsigned long round_error() { return 0; }
|
||||
|
||||
static constexpr int min_exponent = 0;
|
||||
static constexpr int min_exponent10 = 0;
|
||||
static constexpr int max_exponent = 0;
|
||||
static constexpr int max_exponent10 = 0;
|
||||
|
||||
static constexpr bool has_infinity = false;
|
||||
static constexpr bool has_quiet_NaN = false;
|
||||
static constexpr bool has_signaling_NaN = false;
|
||||
static constexpr float_denorm_style has_denorm = denorm_absent;
|
||||
static constexpr bool has_denorm_loss = false;
|
||||
static constexpr unsigned long infinity() { return 0; }
|
||||
static constexpr unsigned long quiet_NaN() { return 0; }
|
||||
static constexpr unsigned long signaling_NaN() { return 0; }
|
||||
static constexpr unsigned long denorm_min() { return 0; }
|
||||
|
||||
static constexpr bool is_iec559 = false;
|
||||
static constexpr bool is_bounded = true;
|
||||
static constexpr bool is_modulo = true;
|
||||
|
||||
static constexpr bool traps = false;
|
||||
static constexpr bool tinyness_before = false;
|
||||
static constexpr float_round_style round_style = round_toward_zero;
|
||||
};
|
||||
|
||||
template <>
|
||||
class numeric_limits<long long>
|
||||
{
|
||||
public:
|
||||
static constexpr bool is_specialized = true;
|
||||
|
||||
static constexpr long long min() { return LLONG_MIN; }
|
||||
static constexpr long long max() { return LLONG_MAX; }
|
||||
static constexpr long long lowest() { return LLONG_MIN; }
|
||||
|
||||
static constexpr int digits = CHAR_BIT * sizeof(long long) - 1;
|
||||
static constexpr int digits10 = 0;
|
||||
static constexpr int max_digits10 = 0;
|
||||
|
||||
static constexpr bool is_signed = true;
|
||||
static constexpr bool is_integer = true;
|
||||
static constexpr bool is_exact = true;
|
||||
static constexpr int radix = 2;
|
||||
static constexpr long long epsilon() { return 0; }
|
||||
static constexpr long long round_error() { return 0; }
|
||||
|
||||
static constexpr int min_exponent = 0;
|
||||
static constexpr int min_exponent10 = 0;
|
||||
static constexpr int max_exponent = 0;
|
||||
static constexpr int max_exponent10 = 0;
|
||||
|
||||
static constexpr bool has_infinity = false;
|
||||
static constexpr bool has_quiet_NaN = false;
|
||||
static constexpr bool has_signaling_NaN = false;
|
||||
static constexpr float_denorm_style has_denorm = denorm_absent;
|
||||
static constexpr bool has_denorm_loss = false;
|
||||
static constexpr long long infinity() { return 0; }
|
||||
static constexpr long long quiet_NaN() { return 0; }
|
||||
static constexpr long long signaling_NaN() { return 0; }
|
||||
static constexpr long long denorm_min() { return 0; }
|
||||
|
||||
static constexpr bool is_iec559 = false;
|
||||
static constexpr bool is_bounded = true;
|
||||
static constexpr bool is_modulo = true;
|
||||
|
||||
static constexpr bool traps = false;
|
||||
static constexpr bool tinyness_before = false;
|
||||
static constexpr float_round_style round_style = round_toward_zero;
|
||||
};
|
||||
|
||||
template <>
|
||||
class numeric_limits<unsigned long long>
|
||||
{
|
||||
public:
|
||||
static constexpr bool is_specialized = true;
|
||||
|
||||
static constexpr unsigned long long min() { return 0; }
|
||||
static constexpr unsigned long long max() { return ULLONG_MAX; }
|
||||
static constexpr unsigned long long lowest() { return 0; }
|
||||
|
||||
static constexpr int digits = CHAR_BIT * sizeof(unsigned long long);
|
||||
static constexpr int digits10 = 0;
|
||||
static constexpr int max_digits10 = 0;
|
||||
|
||||
static constexpr bool is_signed = false;
|
||||
static constexpr bool is_integer = true;
|
||||
static constexpr bool is_exact = true;
|
||||
static constexpr int radix = 2;
|
||||
static constexpr unsigned long long epsilon() { return 0; }
|
||||
static constexpr unsigned long long round_error() { return 0; }
|
||||
|
||||
static constexpr int min_exponent = 0;
|
||||
static constexpr int min_exponent10 = 0;
|
||||
static constexpr int max_exponent = 0;
|
||||
static constexpr int max_exponent10 = 0;
|
||||
|
||||
static constexpr bool has_infinity = false;
|
||||
static constexpr bool has_quiet_NaN = false;
|
||||
static constexpr bool has_signaling_NaN = false;
|
||||
static constexpr float_denorm_style has_denorm = denorm_absent;
|
||||
static constexpr bool has_denorm_loss = false;
|
||||
static constexpr unsigned long long infinity() { return 0; }
|
||||
static constexpr unsigned long long quiet_NaN() { return 0; }
|
||||
static constexpr unsigned long long signaling_NaN() { return 0; }
|
||||
static constexpr unsigned long long denorm_min() { return 0; }
|
||||
|
||||
static constexpr bool is_iec559 = false;
|
||||
static constexpr bool is_bounded = true;
|
||||
static constexpr bool is_modulo = true;
|
||||
|
||||
static constexpr bool traps = false;
|
||||
static constexpr bool tinyness_before = false;
|
||||
static constexpr float_round_style round_style = round_toward_zero;
|
||||
};
|
||||
|
||||
template <>
|
||||
class numeric_limits<float>
|
||||
{
|
||||
public:
|
||||
static constexpr bool is_specialized = true;
|
||||
|
||||
static constexpr float min() { return FLT_MIN; }
|
||||
static constexpr float max() { return FLT_MAX; }
|
||||
static constexpr float lowest() { return -FLT_MAX; }
|
||||
|
||||
static constexpr int digits = FLT_MANT_DIG;
|
||||
static constexpr int digits10 = FLT_DIG;
|
||||
static constexpr int max_digits10 = FLT_DECIMAL_DIG;
|
||||
|
||||
static constexpr bool is_signed = true;
|
||||
static constexpr bool is_integer = false;
|
||||
static constexpr bool is_exact = false;
|
||||
static constexpr int radix = FLT_RADIX;
|
||||
static constexpr float epsilon() { return FLT_EPSILON; }
|
||||
static constexpr float round_error() { return 0.5f; }
|
||||
|
||||
static constexpr int min_exponent = FLT_MIN_EXP;
|
||||
static constexpr int min_exponent10 = FLT_MIN_10_EXP;
|
||||
static constexpr int max_exponent = FLT_MAX_EXP;
|
||||
static constexpr int max_exponent10 = FLT_MAX_10_EXP;
|
||||
|
||||
static constexpr bool has_infinity = true;
|
||||
static constexpr bool has_quiet_NaN = true;
|
||||
static constexpr bool has_signaling_NaN = true;
|
||||
static constexpr float_denorm_style has_denorm = denorm_present;
|
||||
static constexpr bool has_denorm_loss = true;
|
||||
static constexpr float infinity() { return INFINITY; }
|
||||
static constexpr float quiet_NaN() { return NAN; }
|
||||
static constexpr float signaling_NaN() { return NAN; }
|
||||
static constexpr float denorm_min() { return FLT_TRUE_MIN; }
|
||||
|
||||
static constexpr bool is_iec559 = true;
|
||||
static constexpr bool is_bounded = true;
|
||||
static constexpr bool is_modulo = false;
|
||||
|
||||
static constexpr bool traps = true;
|
||||
static constexpr bool tinyness_before = false;
|
||||
static constexpr float_round_style round_style = round_to_nearest;
|
||||
};
|
||||
|
||||
template <>
|
||||
class numeric_limits<double>
|
||||
{
|
||||
public:
|
||||
static constexpr bool is_specialized = true;
|
||||
|
||||
static constexpr double min() { return DBL_MIN; }
|
||||
static constexpr double max() { return DBL_MAX; }
|
||||
static constexpr double lowest() { return -DBL_MAX; }
|
||||
|
||||
static constexpr int digits = DBL_MANT_DIG;
|
||||
static constexpr int digits10 = DBL_DIG;
|
||||
static constexpr int max_digits10 = DBL_DECIMAL_DIG;
|
||||
|
||||
static constexpr bool is_signed = true;
|
||||
static constexpr bool is_integer = false;
|
||||
static constexpr bool is_exact = false;
|
||||
static constexpr int radix = FLT_RADIX;
|
||||
static constexpr double epsilon() { return DBL_EPSILON; }
|
||||
static constexpr double round_error() { return 0.5; }
|
||||
|
||||
static constexpr int min_exponent = DBL_MIN_EXP;
|
||||
static constexpr int min_exponent10 = DBL_MIN_10_EXP;
|
||||
static constexpr int max_exponent = DBL_MAX_EXP;
|
||||
static constexpr int max_exponent10 = DBL_MAX_10_EXP;
|
||||
|
||||
static constexpr bool has_infinity = true;
|
||||
static constexpr bool has_quiet_NaN = true;
|
||||
static constexpr bool has_signaling_NaN = true;
|
||||
static constexpr float_denorm_style has_denorm = denorm_present;
|
||||
static constexpr bool has_denorm_loss = true;
|
||||
static constexpr double infinity() { return INFINITY; }
|
||||
static constexpr double quiet_NaN() { return NAN; }
|
||||
static constexpr double signaling_NaN() { return NAN; }
|
||||
static constexpr double denorm_min() { return DBL_TRUE_MIN; }
|
||||
|
||||
static constexpr bool is_iec559 = true;
|
||||
static constexpr bool is_bounded = true;
|
||||
static constexpr bool is_modulo = false;
|
||||
|
||||
static constexpr bool traps = true;
|
||||
static constexpr bool tinyness_before = false;
|
||||
static constexpr float_round_style round_style = round_to_nearest;
|
||||
};
|
||||
|
||||
template <>
|
||||
class numeric_limits<long double>
|
||||
{
|
||||
public:
|
||||
static constexpr bool is_specialized = true;
|
||||
|
||||
static constexpr long double min() { return LDBL_MIN; }
|
||||
static constexpr long double max() { return LDBL_MAX; }
|
||||
static constexpr long double lowest() { return -LDBL_MAX; }
|
||||
|
||||
static constexpr int digits = LDBL_MANT_DIG;
|
||||
static constexpr int digits10 = LDBL_DIG;
|
||||
static constexpr int max_digits10 = LDBL_DECIMAL_DIG;
|
||||
|
||||
static constexpr bool is_signed = true;
|
||||
static constexpr bool is_integer = false;
|
||||
static constexpr bool is_exact = false;
|
||||
static constexpr int radix = FLT_RADIX;
|
||||
static constexpr long double epsilon() { return LDBL_EPSILON; }
|
||||
static constexpr long double round_error() { return 0.5L; }
|
||||
|
||||
static constexpr int min_exponent = LDBL_MIN_EXP;
|
||||
static constexpr int min_exponent10 = LDBL_MIN_10_EXP;
|
||||
static constexpr int max_exponent = LDBL_MAX_EXP;
|
||||
static constexpr int max_exponent10 = LDBL_MAX_10_EXP;
|
||||
|
||||
static constexpr bool has_infinity = true;
|
||||
static constexpr bool has_quiet_NaN = true;
|
||||
static constexpr bool has_signaling_NaN = true;
|
||||
static constexpr float_denorm_style has_denorm = denorm_present;
|
||||
static constexpr bool has_denorm_loss = true;
|
||||
static constexpr long double infinity() { return INFINITY; }
|
||||
static constexpr long double quiet_NaN() { return NAN; }
|
||||
static constexpr long double signaling_NaN() { return NAN; }
|
||||
static constexpr long double denorm_min() { return LDBL_TRUE_MIN; }
|
||||
|
||||
static constexpr bool is_iec559 = true;
|
||||
static constexpr bool is_bounded = true;
|
||||
static constexpr bool is_modulo = false;
|
||||
|
||||
static constexpr bool traps = true;
|
||||
static constexpr bool tinyness_before = false;
|
||||
static constexpr float_round_style round_style = round_to_nearest;
|
||||
};
|
||||
}
|
138
Kernel/include_std/limits.h
Normal file
138
Kernel/include_std/limits.h
Normal file
@ -0,0 +1,138 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifndef __FENNIX_KERNEL_LIMITS_H__
|
||||
#define __FENNIX_KERNEL_LIMITS_H__
|
||||
|
||||
#undef CHAR_BIT
|
||||
#define CHAR_BIT __CHAR_BIT__
|
||||
|
||||
#ifndef MB_LEN_MAX
|
||||
#define MB_LEN_MAX 1
|
||||
#endif
|
||||
|
||||
#undef SCHAR_MIN
|
||||
#define SCHAR_MIN (-SCHAR_MAX - 1)
|
||||
#undef SCHAR_MAX
|
||||
#define SCHAR_MAX __SCHAR_MAX__
|
||||
|
||||
#undef UCHAR_MAX
|
||||
#if __SCHAR_MAX__ == __INT_MAX__
|
||||
#define UCHAR_MAX (SCHAR_MAX * 2U + 1U)
|
||||
#else
|
||||
#define UCHAR_MAX (SCHAR_MAX * 2 + 1)
|
||||
#endif
|
||||
|
||||
#ifdef __CHAR_UNSIGNED__
|
||||
#undef CHAR_MIN
|
||||
#if __SCHAR_MAX__ == __INT_MAX__
|
||||
#define CHAR_MIN 0U
|
||||
#else
|
||||
#define CHAR_MIN 0
|
||||
#endif
|
||||
#undef CHAR_MAX
|
||||
#define CHAR_MAX UCHAR_MAX
|
||||
#else
|
||||
#undef CHAR_MIN
|
||||
#define CHAR_MIN SCHAR_MIN
|
||||
#undef CHAR_MAX
|
||||
#define CHAR_MAX SCHAR_MAX
|
||||
#endif
|
||||
|
||||
#undef SHRT_MIN
|
||||
#define SHRT_MIN (-SHRT_MAX - 1)
|
||||
#undef SHRT_MAX
|
||||
#define SHRT_MAX __SHRT_MAX__
|
||||
|
||||
#undef USHRT_MAX
|
||||
#if __SHRT_MAX__ == __INT_MAX__
|
||||
#define USHRT_MAX (SHRT_MAX * 2U + 1U)
|
||||
#else
|
||||
#define USHRT_MAX (SHRT_MAX * 2 + 1)
|
||||
#endif
|
||||
|
||||
#undef INT_MIN
|
||||
#define INT_MIN (-INT_MAX - 1)
|
||||
#undef INT_MAX
|
||||
#define INT_MAX __INT_MAX__
|
||||
|
||||
#undef UINT_MAX
|
||||
#define UINT_MAX (INT_MAX * 2U + 1U)
|
||||
|
||||
#undef LONG_MIN
|
||||
#define LONG_MIN (-LONG_MAX - 1L)
|
||||
#undef LONG_MAX
|
||||
#define LONG_MAX __LONG_MAX__
|
||||
|
||||
#undef ULONG_MAX
|
||||
#define ULONG_MAX (LONG_MAX * 2UL + 1UL)
|
||||
|
||||
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
|
||||
#undef LLONG_MIN
|
||||
#define LLONG_MIN (-LLONG_MAX - 1LL)
|
||||
#undef LLONG_MAX
|
||||
#define LLONG_MAX __LONG_LONG_MAX__
|
||||
|
||||
#undef ULLONG_MAX
|
||||
#define ULLONG_MAX (LLONG_MAX * 2ULL + 1ULL)
|
||||
#endif
|
||||
|
||||
#if defined(__GNU_LIBRARY__) ? defined(__USE_GNU) : !defined(__STRICT_ANSI__)
|
||||
#undef LONG_LONG_MIN
|
||||
#define LONG_LONG_MIN (-LONG_LONG_MAX - 1LL)
|
||||
#undef LONG_LONG_MAX
|
||||
#define LONG_LONG_MAX __LONG_LONG_MAX__
|
||||
|
||||
#undef ULONG_LONG_MAX
|
||||
#define ULONG_LONG_MAX (LONG_LONG_MAX * 2ULL + 1ULL)
|
||||
#endif
|
||||
|
||||
#if (defined __STDC_WANT_IEC_60559_BFP_EXT__ || (defined(__STDC_VERSION__) && __STDC_VERSION__ > 201710L))
|
||||
#undef CHAR_WIDTH
|
||||
#define CHAR_WIDTH __SCHAR_WIDTH__
|
||||
#undef SCHAR_WIDTH
|
||||
#define SCHAR_WIDTH __SCHAR_WIDTH__
|
||||
#undef UCHAR_WIDTH
|
||||
#define UCHAR_WIDTH __SCHAR_WIDTH__
|
||||
#undef SHRT_WIDTH
|
||||
#define SHRT_WIDTH __SHRT_WIDTH__
|
||||
#undef USHRT_WIDTH
|
||||
#define USHRT_WIDTH __SHRT_WIDTH__
|
||||
#undef INT_WIDTH
|
||||
#define INT_WIDTH __INT_WIDTH__
|
||||
#undef UINT_WIDTH
|
||||
#define UINT_WIDTH __INT_WIDTH__
|
||||
#undef LONG_WIDTH
|
||||
#define LONG_WIDTH __LONG_WIDTH__
|
||||
#undef ULONG_WIDTH
|
||||
#define ULONG_WIDTH __LONG_WIDTH__
|
||||
#undef LLONG_WIDTH
|
||||
#define LLONG_WIDTH __LONG_LONG_WIDTH__
|
||||
#undef ULLONG_WIDTH
|
||||
#define ULLONG_WIDTH __LONG_LONG_WIDTH__
|
||||
#endif
|
||||
|
||||
#if defined(__STDC_VERSION__) && __STDC_VERSION__ > 201710L
|
||||
#undef BOOL_MAX
|
||||
#define BOOL_MAX 1
|
||||
#undef BOOL_WIDTH
|
||||
#define BOOL_WIDTH 1
|
||||
#endif
|
||||
|
||||
#define MAX_ARG 0x20000
|
||||
|
||||
#endif // !__FENNIX_KERNEL_LIMITS_H__
|
1028
Kernel/include_std/list
Normal file
1028
Kernel/include_std/list
Normal file
File diff suppressed because it is too large
Load Diff
159
Kernel/include_std/locale
Normal file
159
Kernel/include_std/locale
Normal file
@ -0,0 +1,159 @@
|
||||
/*
|
||||
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 <cassert>
|
||||
#include <string>
|
||||
|
||||
namespace std
|
||||
{
|
||||
class locale
|
||||
{
|
||||
public:
|
||||
#pragma region Member Types
|
||||
|
||||
class id
|
||||
{
|
||||
public:
|
||||
id() = default;
|
||||
id(const id &) = delete;
|
||||
};
|
||||
|
||||
class facet
|
||||
{
|
||||
private:
|
||||
std::size_t refs;
|
||||
|
||||
public:
|
||||
explicit facet(std::size_t refs = 0)
|
||||
{
|
||||
this->refs = refs;
|
||||
}
|
||||
|
||||
facet(const facet &) = delete;
|
||||
|
||||
protected:
|
||||
virtual ~facet() = default;
|
||||
};
|
||||
|
||||
typedef int category;
|
||||
|
||||
#pragma endregion Member Types
|
||||
|
||||
#pragma region Member Objects
|
||||
|
||||
static const category none = 0;
|
||||
static const category collate = 1;
|
||||
static const category ctype = 2;
|
||||
static const category monetary = 4;
|
||||
static const category numeric = 8;
|
||||
static const category time = 16;
|
||||
static const category messages = 32;
|
||||
static const category all = collate | ctype | monetary | numeric | time | messages;
|
||||
|
||||
#pragma endregion Member Objects
|
||||
|
||||
#pragma region Member Functions
|
||||
|
||||
locale() noexcept
|
||||
{
|
||||
assert(!"Function not implemented");
|
||||
}
|
||||
|
||||
locale(const locale &other) noexcept
|
||||
{
|
||||
assert(!"Function not implemented");
|
||||
}
|
||||
|
||||
explicit locale(const char *std_name)
|
||||
{
|
||||
assert(!"Function not implemented");
|
||||
}
|
||||
|
||||
explicit locale(const std::string &std_name)
|
||||
{
|
||||
assert(!"Function not implemented");
|
||||
}
|
||||
|
||||
locale(const locale &other, const char *std_name, category cats)
|
||||
{
|
||||
assert(!"Function not implemented");
|
||||
}
|
||||
|
||||
locale(const locale &other, const std::string &std_name, category cats)
|
||||
{
|
||||
assert(!"Function not implemented");
|
||||
}
|
||||
|
||||
template <class Facet>
|
||||
locale(const locale &other, Facet *f)
|
||||
{
|
||||
assert(!"Function not implemented");
|
||||
}
|
||||
|
||||
locale(const locale &other, const locale &one, category cats)
|
||||
{
|
||||
assert(!"Function not implemented");
|
||||
}
|
||||
|
||||
~locale()
|
||||
{
|
||||
assert(!"Function not implemented");
|
||||
}
|
||||
|
||||
const locale &operator=(const locale &other) noexcept
|
||||
{
|
||||
assert(!"Function not implemented");
|
||||
}
|
||||
|
||||
template <class Facet>
|
||||
locale combine(const locale &other) const
|
||||
{
|
||||
assert(!"Function not implemented");
|
||||
}
|
||||
|
||||
std::string name() const
|
||||
{
|
||||
assert(!"Function not implemented");
|
||||
}
|
||||
|
||||
bool operator==(const locale &other) const
|
||||
{
|
||||
assert(!"Function not implemented");
|
||||
}
|
||||
|
||||
template <class CharT, class Traits, class Alloc>
|
||||
bool operator()(const basic_string<CharT, Traits, Alloc> &s1, const basic_string<CharT, Traits, Alloc> &s2) const
|
||||
{
|
||||
assert(!"Function not implemented");
|
||||
}
|
||||
|
||||
static locale global(const locale &loc)
|
||||
{
|
||||
assert(!"Function not implemented");
|
||||
}
|
||||
|
||||
static const locale &classic()
|
||||
{
|
||||
assert(!"Function not implemented");
|
||||
}
|
||||
|
||||
#pragma endregion Member Functions
|
||||
};
|
||||
}
|
21
Kernel/include_std/math.h
Normal file
21
Kernel/include_std/math.h
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifndef _MATH_H
|
||||
#define _MATH_H
|
||||
|
||||
#endif // !_MATH_H
|
606
Kernel/include_std/memory
Normal file
606
Kernel/include_std/memory
Normal file
@ -0,0 +1,606 @@
|
||||
/*
|
||||
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 <type_traits>
|
||||
#include <functional>
|
||||
#include <cstddef>
|
||||
#include <utility>
|
||||
#include <limits>
|
||||
#include <new>
|
||||
|
||||
#include <debug.h>
|
||||
|
||||
namespace std
|
||||
{
|
||||
namespace __memory__detail
|
||||
{
|
||||
template <class>
|
||||
constexpr bool is_unbounded_array_v = false;
|
||||
template <class T>
|
||||
constexpr bool is_unbounded_array_v<T[]> = true;
|
||||
|
||||
template <class>
|
||||
constexpr bool is_bounded_array_v = false;
|
||||
template <class T, std::size_t N>
|
||||
constexpr bool is_bounded_array_v<T[N]> = true;
|
||||
}
|
||||
|
||||
template <class T, class... Args>
|
||||
constexpr T *construct_at(T *p, Args &&...args)
|
||||
{
|
||||
return ::new (static_cast<void *>(p)) T(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
constexpr void destroy_at(T *p)
|
||||
{
|
||||
p->~T();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
T *addressof(T &arg)
|
||||
{
|
||||
return reinterpret_cast<T *>(&const_cast<char &>(reinterpret_cast<const volatile char &>(arg)));
|
||||
}
|
||||
|
||||
template <class T>
|
||||
const T *addressof(const T &&) = delete;
|
||||
|
||||
template <class InputIt, class Size, class NoThrowForwardIt>
|
||||
NoThrowForwardIt uninitialized_copy_n(InputIt first, Size count, NoThrowForwardIt d_first)
|
||||
{
|
||||
using ValueType = typename std::iterator_traits<NoThrowForwardIt>::value_type;
|
||||
NoThrowForwardIt current = d_first;
|
||||
try
|
||||
{
|
||||
for (Size i = 0; i < count; ++i, (void)++current, ++first)
|
||||
{
|
||||
::new (static_cast<void *>(std::addressof(*current))) ValueType(*first);
|
||||
}
|
||||
return current;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
for (; d_first != current; ++d_first)
|
||||
{
|
||||
d_first->~ValueType();
|
||||
}
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
template <class ExecutionPolicy, class ForwardIt, class Size, class NoThrowForwardIt>
|
||||
NoThrowForwardIt uninitialized_copy_n(ExecutionPolicy &&policy, ForwardIt first, Size count, NoThrowForwardIt d_first)
|
||||
{
|
||||
return uninitialized_copy_n(first, count, d_first);
|
||||
}
|
||||
|
||||
template <class ForwardIt, class Size, class T>
|
||||
ForwardIt uninitialized_fill_n(ForwardIt first, Size count, const T &value)
|
||||
{
|
||||
using V = typename std::iterator_traits<ForwardIt>::value_type;
|
||||
ForwardIt current = first;
|
||||
try
|
||||
{
|
||||
for (; count > 0; ++current, (void)--count)
|
||||
::new (static_cast<void *>(std::addressof(*current))) V(value);
|
||||
return current;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
for (; first != current; ++first)
|
||||
first->~V();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
template <class ExecutionPolicy, class ForwardIt, class Size, class T>
|
||||
ForwardIt uninitialized_fill_n(ExecutionPolicy &&policy, ForwardIt first, Size count, const T &value)
|
||||
{
|
||||
return uninitialized_fill_n(first, count, value);
|
||||
}
|
||||
|
||||
template <class Ptr>
|
||||
struct pointer_traits
|
||||
{
|
||||
using pointer = Ptr;
|
||||
using element_type = typename Ptr::element_type;
|
||||
using difference_type = typename Ptr::difference_type;
|
||||
|
||||
template <class U>
|
||||
using rebind = typename Ptr::template rebind<U>;
|
||||
|
||||
static pointer pointer_to(element_type &r) noexcept
|
||||
{
|
||||
return Ptr::pointer_to(r);
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct pointer_traits<T *>
|
||||
{
|
||||
using pointer = T *;
|
||||
using element_type = T;
|
||||
using difference_type = std::ptrdiff_t;
|
||||
|
||||
template <class U>
|
||||
using rebind = U *;
|
||||
|
||||
static pointer pointer_to(element_type &r) noexcept
|
||||
{
|
||||
return std::addressof(r);
|
||||
}
|
||||
};
|
||||
|
||||
template <class Pointer, class SizeType = std::size_t>
|
||||
struct allocation_result
|
||||
{
|
||||
Pointer ptr;
|
||||
SizeType count;
|
||||
};
|
||||
|
||||
template <class Alloc>
|
||||
struct allocator_traits
|
||||
{
|
||||
typedef Alloc allocator_type;
|
||||
typedef typename Alloc::value_type value_type;
|
||||
typedef typename Alloc::pointer pointer;
|
||||
typedef typename Alloc::const_pointer const_pointer;
|
||||
// typedef typename Alloc::void_pointer void_pointer;
|
||||
// typedef typename Alloc::const_void_pointer const_void_pointer;
|
||||
// typedef typename std::pointer_traits<pointer>::rebind<void> void_pointer;
|
||||
// typedef typename std::pointer_traits<pointer>::rebind<const void> const_void_pointer;
|
||||
typedef typename Alloc::difference_type difference_type;
|
||||
typedef typename Alloc::size_type size_type;
|
||||
// typedef typename Alloc::propagate_on_container_copy_assignment propagate_on_container_copy_assignment;
|
||||
typedef typename std::false_type propagate_on_container_copy_assignment;
|
||||
typedef typename Alloc::propagate_on_container_move_assignment propagate_on_container_move_assignment;
|
||||
typedef typename std::false_type propagate_on_container_swap;
|
||||
typedef typename Alloc::is_always_equal is_always_equal;
|
||||
|
||||
template <class T>
|
||||
using rebind_alloc = typename Alloc::template rebind<T>::other;
|
||||
template <class T>
|
||||
using rebind_traits = allocator_traits<rebind_alloc<T>>;
|
||||
|
||||
[[nodiscard]] static constexpr pointer allocate(Alloc &a, size_type n)
|
||||
{
|
||||
return a.allocate(n);
|
||||
}
|
||||
|
||||
// [[nodiscard]] static constexpr pointer allocate(Alloc &a, size_type n, const_void_pointer hint)
|
||||
// {
|
||||
// return a.allocate(n, hint);
|
||||
// }
|
||||
|
||||
[[nodiscard]] static constexpr std::allocation_result<pointer, size_type> allocate_at_least(Alloc &a, size_type n)
|
||||
{
|
||||
return a.allocate_at_least(n);
|
||||
}
|
||||
|
||||
static constexpr void deallocate(Alloc &a, pointer p, size_type n)
|
||||
{
|
||||
a.deallocate(p, n);
|
||||
}
|
||||
|
||||
template <class T, class... Args>
|
||||
static constexpr void construct(Alloc &a, T *p, Args &&...args)
|
||||
{
|
||||
std::construct_at(p, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static constexpr void destroy(Alloc &a, T *p)
|
||||
{
|
||||
std::destroy_at(p);
|
||||
}
|
||||
|
||||
static constexpr size_type max_size(const Alloc &a)
|
||||
{
|
||||
return a.max_size();
|
||||
}
|
||||
|
||||
static constexpr Alloc select_on_container_copy_construction(const Alloc &a)
|
||||
{
|
||||
return a;
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct allocator
|
||||
{
|
||||
public:
|
||||
typedef T value_type;
|
||||
typedef T *pointer;
|
||||
typedef const T *const_pointer;
|
||||
typedef T &reference;
|
||||
typedef const T &const_reference;
|
||||
typedef std::size_t size_type;
|
||||
typedef std::ptrdiff_t difference_type;
|
||||
typedef std::true_type propagate_on_container_move_assignment;
|
||||
typedef std::true_type is_always_equal;
|
||||
|
||||
template <class U>
|
||||
struct rebind
|
||||
{
|
||||
typedef allocator<U> other;
|
||||
};
|
||||
|
||||
allocator() {}
|
||||
allocator(const allocator &other) {}
|
||||
template <class U>
|
||||
allocator(const allocator<U> &other) {}
|
||||
~allocator() {}
|
||||
|
||||
pointer allocate(size_type n, const void *hint = 0)
|
||||
{
|
||||
return static_cast<pointer>(::operator new(n * sizeof(T)));
|
||||
}
|
||||
|
||||
std::allocation_result<T *, std::size_t> allocate_at_least(std::size_t n)
|
||||
{
|
||||
return {static_cast<T *>(::operator new(n * sizeof(T))), n};
|
||||
}
|
||||
|
||||
void deallocate(T *p, std::size_t n)
|
||||
{
|
||||
::operator delete(p);
|
||||
}
|
||||
|
||||
pointer address(reference x) const { return &x; }
|
||||
const_pointer address(const_reference x) const { return &x; }
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct default_delete
|
||||
{
|
||||
constexpr default_delete() noexcept = default;
|
||||
|
||||
template <class U>
|
||||
constexpr default_delete(const default_delete<U> &d) noexcept {}
|
||||
|
||||
constexpr void operator()(T *ptr) const { delete ptr; }
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct default_delete<T[]>
|
||||
{
|
||||
constexpr default_delete() noexcept = default;
|
||||
|
||||
template <class U>
|
||||
constexpr default_delete(const default_delete<U[]> &d) noexcept {}
|
||||
|
||||
template <class U>
|
||||
constexpr void operator()(U *ptr) const { delete[] ptr; }
|
||||
};
|
||||
|
||||
template <class T, class Deleter = std::default_delete<T>>
|
||||
class unique_ptr
|
||||
{
|
||||
public:
|
||||
using pointer = T *; // std::remove_reference<Deleter>::type::pointer;
|
||||
using element_type = T;
|
||||
using deleter_type = Deleter;
|
||||
|
||||
private:
|
||||
pointer _ptr;
|
||||
|
||||
public:
|
||||
#pragma region Member Functions
|
||||
|
||||
constexpr unique_ptr() noexcept : _ptr(nullptr) {}
|
||||
|
||||
constexpr unique_ptr(std::nullptr_t) noexcept : _ptr(nullptr) {}
|
||||
|
||||
constexpr explicit unique_ptr(pointer p) noexcept : _ptr(p) {}
|
||||
|
||||
// constexpr unique_ptr(pointer p, /* TODO */ d1) noexcept : _ptr(p) {}
|
||||
|
||||
// constexpr unique_ptr(pointer p, /* TODO */ d2) noexcept : _ptr(p) {}
|
||||
|
||||
constexpr unique_ptr(unique_ptr &&u) noexcept : _ptr(u.release()) {}
|
||||
|
||||
template <class U, class E>
|
||||
constexpr unique_ptr(unique_ptr<U, E> &&u) noexcept : _ptr(u.release()) {}
|
||||
|
||||
unique_ptr(const unique_ptr &) = delete;
|
||||
|
||||
~unique_ptr()
|
||||
{
|
||||
if (_ptr == nullptr)
|
||||
return;
|
||||
Deleter d;
|
||||
d(_ptr);
|
||||
}
|
||||
|
||||
constexpr unique_ptr &operator=(unique_ptr &&r) noexcept
|
||||
{
|
||||
reset(r.release());
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class U, class E>
|
||||
constexpr unique_ptr &operator=(unique_ptr<U, E> &&r) noexcept
|
||||
{
|
||||
reset(r.release());
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr unique_ptr &operator=(std::nullptr_t) noexcept
|
||||
{
|
||||
reset();
|
||||
return *this;
|
||||
}
|
||||
|
||||
unique_ptr &operator=(const unique_ptr &) = delete;
|
||||
|
||||
#pragma endregion Member Functions
|
||||
|
||||
#pragma region Modifiers
|
||||
|
||||
constexpr pointer release() noexcept
|
||||
{
|
||||
pointer p = _ptr;
|
||||
_ptr = nullptr;
|
||||
return p;
|
||||
}
|
||||
|
||||
constexpr void reset(pointer ptr = pointer()) noexcept
|
||||
{
|
||||
Deleter d;
|
||||
d(_ptr);
|
||||
_ptr = ptr;
|
||||
}
|
||||
|
||||
void swap(unique_ptr &other) noexcept
|
||||
{
|
||||
pointer tmp = _ptr;
|
||||
_ptr = other._ptr;
|
||||
other._ptr = tmp;
|
||||
}
|
||||
|
||||
#pragma endregion Modifiers
|
||||
|
||||
#pragma region Observers
|
||||
|
||||
constexpr pointer get() const noexcept { return _ptr; }
|
||||
constexpr Deleter &get_deleter() noexcept { return _ptr; }
|
||||
constexpr const Deleter &get_deleter() const noexcept { return _ptr; }
|
||||
constexpr explicit operator bool() const noexcept { return get() != nullptr; }
|
||||
|
||||
#pragma endregion Observers
|
||||
|
||||
#pragma region Element Access
|
||||
|
||||
constexpr typename std::add_lvalue_reference<T>::type operator*() const noexcept(noexcept(*std::declval<pointer>())) { return *_ptr; }
|
||||
constexpr pointer operator->() const noexcept { return _ptr; }
|
||||
|
||||
#pragma endregion Element Access
|
||||
};
|
||||
|
||||
template <class T, class Deleter>
|
||||
class unique_ptr<T[], Deleter>
|
||||
{
|
||||
public:
|
||||
using pointer = T *; // std::remove_reference<Deleter>::type::pointer;
|
||||
using element_type = T;
|
||||
using deleter_type = Deleter;
|
||||
|
||||
private:
|
||||
pointer _ptr;
|
||||
|
||||
public:
|
||||
#pragma region Member Functions
|
||||
|
||||
constexpr unique_ptr() noexcept : _ptr(nullptr) {}
|
||||
|
||||
constexpr unique_ptr(std::nullptr_t) noexcept : _ptr(nullptr) {}
|
||||
|
||||
template <class U>
|
||||
constexpr explicit unique_ptr(U p) noexcept : _ptr(p) {}
|
||||
|
||||
// template <class U>
|
||||
// constexpr unique_ptr(U p, /* TODO */ d1) noexcept : _ptr(p) {}
|
||||
|
||||
// template <class U>
|
||||
// constexpr unique_ptr(U p, /* TODO */ d2) noexcept : _ptr(p) {}
|
||||
|
||||
constexpr unique_ptr(unique_ptr &&u) noexcept : _ptr(u.release()) {}
|
||||
|
||||
template <class U, class E>
|
||||
constexpr unique_ptr(unique_ptr<U, E> &&u) noexcept : _ptr(u.release()) {}
|
||||
|
||||
unique_ptr(const unique_ptr &) = delete;
|
||||
|
||||
~unique_ptr()
|
||||
{
|
||||
if (_ptr == nullptr)
|
||||
return;
|
||||
Deleter d;
|
||||
d(_ptr);
|
||||
}
|
||||
|
||||
constexpr unique_ptr &operator=(unique_ptr &&r) noexcept
|
||||
{
|
||||
reset(r.release());
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class U, class E>
|
||||
constexpr unique_ptr &operator=(unique_ptr<U, E> &&r) noexcept
|
||||
{
|
||||
reset(r.release());
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr unique_ptr &operator=(std::nullptr_t) noexcept
|
||||
{
|
||||
reset();
|
||||
return *this;
|
||||
}
|
||||
|
||||
unique_ptr &operator=(const unique_ptr &) = delete;
|
||||
|
||||
#pragma endregion Member Functions
|
||||
|
||||
#pragma region Modifiers
|
||||
|
||||
constexpr pointer release() noexcept
|
||||
{
|
||||
pointer p = _ptr;
|
||||
_ptr = nullptr;
|
||||
return p;
|
||||
}
|
||||
|
||||
template <class U>
|
||||
constexpr void reset(U ptr) noexcept
|
||||
{
|
||||
Deleter d;
|
||||
d(_ptr);
|
||||
_ptr = ptr;
|
||||
}
|
||||
|
||||
constexpr void reset(std::nullptr_t = nullptr) noexcept
|
||||
{
|
||||
Deleter d;
|
||||
d(_ptr);
|
||||
_ptr = nullptr;
|
||||
}
|
||||
|
||||
void swap(unique_ptr &other) noexcept
|
||||
{
|
||||
pointer tmp = _ptr;
|
||||
_ptr = other._ptr;
|
||||
other._ptr = tmp;
|
||||
}
|
||||
|
||||
#pragma endregion Modifiers
|
||||
|
||||
#pragma region Observers
|
||||
|
||||
constexpr pointer get() const noexcept { return _ptr; }
|
||||
constexpr Deleter &get_deleter() noexcept { return _ptr; }
|
||||
constexpr const Deleter &get_deleter() const noexcept { return _ptr; }
|
||||
constexpr explicit operator bool() const noexcept { return get() != nullptr; }
|
||||
|
||||
#pragma endregion Observers
|
||||
|
||||
#pragma region Element Access
|
||||
|
||||
constexpr T &operator[](std::size_t i) const { return _ptr[i]; }
|
||||
|
||||
#pragma endregion Element Access
|
||||
};
|
||||
|
||||
template <class T, class... Args>
|
||||
std::enable_if_t<!std::is_array<T>::value, std::unique_ptr<T>>
|
||||
make_unique(Args &&...args)
|
||||
{
|
||||
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
template <class T>
|
||||
std::enable_if_t<__memory__detail::is_unbounded_array_v<T>, std::unique_ptr<T>>
|
||||
make_unique(std::size_t n)
|
||||
{
|
||||
return std::unique_ptr<T>(new std::remove_extent_t<T>[n]());
|
||||
}
|
||||
|
||||
template <class T, class... Args>
|
||||
std::enable_if_t<__memory__detail::is_bounded_array_v<T>> make_unique(Args &&...) = delete;
|
||||
|
||||
template <class T>
|
||||
requires(!std::is_array_v<T>)
|
||||
std::unique_ptr<T> make_unique_for_overwrite()
|
||||
{
|
||||
return std::unique_ptr<T>(new T);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
requires std::is_unbounded_array_v<T>
|
||||
std::unique_ptr<T> make_unique_for_overwrite(std::size_t n)
|
||||
{
|
||||
return std::unique_ptr<T>(new std::remove_extent_t<T>[n]);
|
||||
}
|
||||
|
||||
template <class T, class... Args>
|
||||
requires std::is_bounded_array_v<T>
|
||||
void make_unique_for_overwrite(Args &&...) = delete;
|
||||
|
||||
template <class T1, class D1, class T2, class D2>
|
||||
constexpr bool operator==(const unique_ptr<T1, D1> &x, const unique_ptr<T2, D2> &y) { return x.get() == y.get(); }
|
||||
|
||||
template <class T1, class D1, class T2, class D2>
|
||||
bool operator<(const unique_ptr<T1, D1> &x, const unique_ptr<T2, D2> &y)
|
||||
{
|
||||
return std::less<typename std::common_type<typename unique_ptr<T1, D1>::pointer, typename unique_ptr<T2, D2>::pointer>::type>()(x.get(), y.get());
|
||||
}
|
||||
|
||||
template <class T1, class D1, class T2, class D2>
|
||||
bool operator<=(const unique_ptr<T1, D1> &x, const unique_ptr<T2, D2> &y) { return !(y < x); }
|
||||
|
||||
template <class T1, class D1, class T2, class D2>
|
||||
bool operator>(const unique_ptr<T1, D1> &x, const unique_ptr<T2, D2> &y) { return y < x; }
|
||||
|
||||
template <class T1, class D1, class T2, class D2>
|
||||
bool operator>=(const unique_ptr<T1, D1> &x, const unique_ptr<T2, D2> &y) { return !(x < y); }
|
||||
|
||||
// operator<=>(const unique_ptr<T1, D1> &x, const unique_ptr<T2, D2> &y);
|
||||
|
||||
template <class T, class D>
|
||||
constexpr bool operator==(const unique_ptr<T, D> &x, std::nullptr_t) noexcept { return !x; }
|
||||
|
||||
template <class T, class D>
|
||||
constexpr bool operator<(const unique_ptr<T, D> &x, std::nullptr_t) { return std::less<typename unique_ptr<T, D>::pointer>()(x.get(), nullptr); }
|
||||
|
||||
template <class T, class D>
|
||||
constexpr bool operator<(std::nullptr_t, const unique_ptr<T, D> &y) { return std::less<typename unique_ptr<T, D>::pointer>()(nullptr, y.get()); }
|
||||
|
||||
template <class T, class D>
|
||||
constexpr bool operator<=(const unique_ptr<T, D> &x, std::nullptr_t) { return !(nullptr < x); }
|
||||
|
||||
template <class T, class D>
|
||||
constexpr bool operator<=(std::nullptr_t, const unique_ptr<T, D> &y) { return !(y < nullptr); }
|
||||
|
||||
template <class T, class D>
|
||||
constexpr bool operator>(const unique_ptr<T, D> &x, std::nullptr_t) { return nullptr < x; }
|
||||
|
||||
template <class T, class D>
|
||||
constexpr bool operator>(std::nullptr_t, const unique_ptr<T, D> &y) { return y < nullptr; }
|
||||
|
||||
template <class T, class D>
|
||||
constexpr bool operator>=(const unique_ptr<T, D> &x, std::nullptr_t) { return !(x < nullptr); }
|
||||
|
||||
template <class T, class D>
|
||||
constexpr bool operator>=(std::nullptr_t, const unique_ptr<T, D> &y) { return !(nullptr < y); }
|
||||
|
||||
// operator<=>(const unique_ptr<T, D> &x, std::nullptr_t);
|
||||
|
||||
// template <class CharT, class Traits, class Y, class D>
|
||||
// std::basic_ostream<CharT, Traits> &operator<<(std::basic_ostream<CharT, Traits> &os, const std::unique_ptr<Y, D> &p)
|
||||
// {
|
||||
// return os << p.get();
|
||||
// }
|
||||
|
||||
template <class T, class D>
|
||||
void swap(std::unique_ptr<T, D> &lhs, std::unique_ptr<T, D> &rhs) noexcept
|
||||
{
|
||||
lhs.swap(rhs);
|
||||
}
|
||||
}
|
23
Kernel/include_std/memory.h
Normal file
23
Kernel/include_std/memory.h
Normal file
@ -0,0 +1,23 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifndef __FENNIX_KERNEL_STD_MEMORY_H__
|
||||
#define __FENNIX_KERNEL_STD_MEMORY_H__
|
||||
|
||||
#include <convert.h>
|
||||
|
||||
#endif // !__FENNIX_KERNEL_STD_MEMORY_H__
|
93
Kernel/include_std/mutex
Normal file
93
Kernel/include_std/mutex
Normal file
@ -0,0 +1,93 @@
|
||||
/*
|
||||
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 <types.h>
|
||||
|
||||
#include <task.hpp>
|
||||
#include <atomic>
|
||||
#include <vector>
|
||||
|
||||
namespace std
|
||||
{
|
||||
struct defer_lock_t
|
||||
{
|
||||
explicit defer_lock_t() = default;
|
||||
};
|
||||
|
||||
struct try_to_lock_t
|
||||
{
|
||||
explicit try_to_lock_t() = default;
|
||||
};
|
||||
struct adopt_lock_t
|
||||
{
|
||||
explicit adopt_lock_t() = default;
|
||||
};
|
||||
|
||||
/**
|
||||
* A mutex implementation.
|
||||
*
|
||||
* @note The TaskManager must be
|
||||
* initialized before using this class.
|
||||
*/
|
||||
class mutex
|
||||
{
|
||||
private:
|
||||
atomic_bool Locked = false;
|
||||
list<Tasking::TCB *> Waiting;
|
||||
Tasking::TCB *Holder = nullptr;
|
||||
|
||||
public:
|
||||
void lock();
|
||||
bool try_lock();
|
||||
void unlock();
|
||||
|
||||
mutex();
|
||||
mutex(const mutex &) = delete;
|
||||
~mutex();
|
||||
};
|
||||
|
||||
template <class Mutex>
|
||||
class lock_guard
|
||||
{
|
||||
private:
|
||||
Mutex &mutexRef;
|
||||
|
||||
public:
|
||||
explicit lock_guard(Mutex &m)
|
||||
: mutexRef(m)
|
||||
{
|
||||
mutexRef.lock();
|
||||
}
|
||||
|
||||
lock_guard(Mutex &m, adopt_lock_t t)
|
||||
: mutexRef(m)
|
||||
{
|
||||
/* Do nothing */
|
||||
}
|
||||
|
||||
lock_guard(const lock_guard &) = delete;
|
||||
|
||||
~lock_guard()
|
||||
{
|
||||
mutexRef.unlock();
|
||||
}
|
||||
|
||||
lock_guard &operator=(const lock_guard &) = delete;
|
||||
};
|
||||
}
|
143
Kernel/include_std/new
Normal file
143
Kernel/include_std/new
Normal file
@ -0,0 +1,143 @@
|
||||
/*
|
||||
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);
|
26
Kernel/include_std/optional
Normal file
26
Kernel/include_std/optional
Normal file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
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 <concepts>
|
||||
|
||||
namespace std
|
||||
{
|
||||
template <class T>
|
||||
class optional;
|
||||
}
|
40
Kernel/include_std/ostream
Normal file
40
Kernel/include_std/ostream
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
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 <string>
|
||||
#include <ios>
|
||||
|
||||
namespace std
|
||||
{
|
||||
template <class CharT, class Traits = std::char_traits<CharT>>
|
||||
class basic_ostream : virtual public std::basic_ios<CharT, Traits>
|
||||
{
|
||||
};
|
||||
|
||||
template <class CharT, class Traits>
|
||||
std::basic_ostream<CharT, Traits> &endl(std::basic_ostream<CharT, Traits> &os)
|
||||
{
|
||||
os.put(os.widen('\n'));
|
||||
os.flush();
|
||||
return os;
|
||||
}
|
||||
|
||||
typedef basic_ostream<char> ostream;
|
||||
typedef basic_ostream<wchar_t> wostream;
|
||||
}
|
21
Kernel/include_std/pthread.h
Normal file
21
Kernel/include_std/pthread.h
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifndef _PTHREAD_H
|
||||
#define _PTHREAD_H
|
||||
|
||||
#endif // !_PTHREAD_H
|
28
Kernel/include_std/ranges
Normal file
28
Kernel/include_std/ranges
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
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
|
||||
|
||||
namespace std
|
||||
{
|
||||
struct from_range_t
|
||||
{
|
||||
explicit from_range_t() = default;
|
||||
};
|
||||
|
||||
inline constexpr std::from_range_t from_range{};
|
||||
}
|
18
Kernel/include_std/sched.h
Normal file
18
Kernel/include_std/sched.h
Normal file
@ -0,0 +1,18 @@
|
||||
/*
|
||||
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
|
23
Kernel/include_std/signal.h
Normal file
23
Kernel/include_std/signal.h
Normal file
@ -0,0 +1,23 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifndef __FENNIX_KERNEL_STD_SIGNAL_H__
|
||||
#define __FENNIX_KERNEL_STD_SIGNAL_H__
|
||||
|
||||
#include <types.h>
|
||||
|
||||
#endif // !__FENNIX_KERNEL_STD_SIGNAL_H__
|
23
Kernel/include_std/stdarg.h
Normal file
23
Kernel/include_std/stdarg.h
Normal file
@ -0,0 +1,23 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifndef __FENNIX_KERNEL_STDARG_H__
|
||||
#define __FENNIX_KERNEL_STDARG_H__
|
||||
|
||||
#include <types.h>
|
||||
|
||||
#endif // !__FENNIX_KERNEL_STDARG_H__
|
88
Kernel/include_std/stdatomic.h
Normal file
88
Kernel/include_std/stdatomic.h
Normal file
@ -0,0 +1,88 @@
|
||||
/*
|
||||
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
|
||||
|
||||
typedef enum
|
||||
{
|
||||
memory_order_relaxed = __ATOMIC_RELAXED,
|
||||
memory_order_consume = __ATOMIC_CONSUME,
|
||||
memory_order_acquire = __ATOMIC_ACQUIRE,
|
||||
memory_order_release = __ATOMIC_RELEASE,
|
||||
memory_order_acq_rel = __ATOMIC_ACQ_REL,
|
||||
memory_order_seq_cst = __ATOMIC_SEQ_CST
|
||||
} memory_order;
|
||||
|
||||
#define atomic_store_explicit(object, desired, order) \
|
||||
__atomic_store_n(object, desired, order)
|
||||
|
||||
#define atomic_store(object, desired) \
|
||||
__atomic_store_n(object, desired, __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_load_explicit(object, order) \
|
||||
__atomic_load_n(object, order)
|
||||
|
||||
#define atomic_load(object) \
|
||||
__atomic_load_n(object, __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_exchange_explicit(object, desired, order) \
|
||||
__atomic_exchange_n(object, desired, order)
|
||||
|
||||
#define atomic_exchange(object, desired) \
|
||||
__atomic_exchange_n(object, desired, __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_compare_exchange_strong_explicit(object, expected, desired, success, failure) \
|
||||
__atomic_compare_exchange_n(object, expected, desired, 0, success, failure)
|
||||
|
||||
#define atomic_compare_exchange_strong(object, expected, desired) \
|
||||
__atomic_compare_exchange_n(object, expected, desired, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_compare_exchange_weak_explicit(object, expected, desired, success, failure) \
|
||||
__atomic_compare_exchange_n(object, expected, desired, 1, success, failure)
|
||||
|
||||
#define atomic_compare_exchange_weak(object, expected, desired) \
|
||||
__atomic_compare_exchange_n(object, expected, desired, 1, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_fetch_add(object, operand) \
|
||||
__atomic_fetch_add(object, operand, __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_fetch_add_explicit(object, operand, order) \
|
||||
__atomic_fetch_add(object, operand, order)
|
||||
|
||||
#define atomic_fetch_sub(object, operand) \
|
||||
__atomic_fetch_sub(object, operand, __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_fetch_sub_explicit(object, operand, order) \
|
||||
__atomic_fetch_sub(object, operand, order)
|
||||
|
||||
#define atomic_fetch_or(object, operand) \
|
||||
__atomic_fetch_or(object, operand, __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_fetch_or_explicit(object, operand, order) \
|
||||
__atomic_fetch_or(object, operand, order)
|
||||
|
||||
#define atomic_fetch_xor(object, operand) \
|
||||
__atomic_fetch_xor(object, operand, __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_fetch_xor_explicit(object, operand, order) \
|
||||
__atomic_fetch_xor(object, operand, order)
|
||||
|
||||
#define atomic_fetch_and(object, operand) \
|
||||
__atomic_fetch_and(object, operand, __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_fetch_and_explicit(object, operand, order) \
|
||||
__atomic_fetch_and(object, operand, order)
|
35
Kernel/include_std/stdbool.h
Normal file
35
Kernel/include_std/stdbool.h
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifndef __FENNIX_KERNEL_header_H__
|
||||
#define __FENNIX_KERNEL_header_H__
|
||||
|
||||
#include <types.h>
|
||||
|
||||
#ifndef __cplusplus
|
||||
|
||||
#define bool _Bool
|
||||
#define true 1
|
||||
#define false 0
|
||||
|
||||
#else
|
||||
|
||||
#define _Bool bool
|
||||
|
||||
#endif // !__cplusplus
|
||||
|
||||
#endif // !__FENNIX_KERNEL_header_H__
|
23
Kernel/include_std/stddef.h
Normal file
23
Kernel/include_std/stddef.h
Normal file
@ -0,0 +1,23 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifndef __FENNIX_KERNEL_STDDEF_STUB_H__
|
||||
#define __FENNIX_KERNEL_STDDEF_STUB_H__
|
||||
|
||||
#include <types.h>
|
||||
|
||||
#endif // !__FENNIX_KERNEL_STDDEF_STUB_H__
|
119
Kernel/include_std/stdexcept
Normal file
119
Kernel/include_std/stdexcept
Normal file
@ -0,0 +1,119 @@
|
||||
/*
|
||||
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 <convert.h>
|
||||
#include <cassert>
|
||||
#include <new>
|
||||
|
||||
namespace std
|
||||
{
|
||||
class __simple_string
|
||||
{
|
||||
private:
|
||||
char *data;
|
||||
size_t size;
|
||||
|
||||
public:
|
||||
__simple_string()
|
||||
: data(nullptr),
|
||||
size(0)
|
||||
{
|
||||
}
|
||||
|
||||
__simple_string(const char *str)
|
||||
: data(nullptr),
|
||||
size(0)
|
||||
{
|
||||
size = strlen(str);
|
||||
data = new char[size + 1];
|
||||
assert(data != nullptr);
|
||||
memcpy(data, str, size);
|
||||
data[size] = '\0';
|
||||
}
|
||||
|
||||
__simple_string(const __simple_string &other)
|
||||
: data(nullptr),
|
||||
size(0)
|
||||
{
|
||||
size = other.size;
|
||||
data = new char[size + 1];
|
||||
assert(data != nullptr);
|
||||
memcpy(data, other.data, size);
|
||||
data[size] = '\0';
|
||||
}
|
||||
|
||||
~__simple_string()
|
||||
{
|
||||
if (data)
|
||||
delete[] data;
|
||||
}
|
||||
|
||||
const char *c_str() const { return data; }
|
||||
|
||||
__simple_string &operator=(const __simple_string &other)
|
||||
{
|
||||
if (data)
|
||||
delete[] data;
|
||||
|
||||
size = other.size;
|
||||
data = new char[size + 1];
|
||||
assert(data != nullptr);
|
||||
memcpy(data, other.data, size);
|
||||
data[size] = '\0';
|
||||
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
class runtime_error : public exception
|
||||
{
|
||||
};
|
||||
|
||||
class logic_error : public exception
|
||||
{
|
||||
private:
|
||||
__simple_string msg;
|
||||
|
||||
public:
|
||||
logic_error(const char *what_arg) : msg(what_arg) {}
|
||||
logic_error(const logic_error &other) : msg(other.msg) {}
|
||||
|
||||
logic_error &operator=(const logic_error &other) noexcept
|
||||
{
|
||||
msg = other.msg;
|
||||
return *this;
|
||||
}
|
||||
|
||||
virtual const char *what() const noexcept
|
||||
{
|
||||
return msg.c_str();
|
||||
}
|
||||
};
|
||||
|
||||
class out_of_range : public logic_error
|
||||
{
|
||||
public:
|
||||
out_of_range(const char *what_arg) : logic_error(what_arg) {}
|
||||
out_of_range(const out_of_range &other) = default;
|
||||
out_of_range &operator=(const out_of_range &) = default;
|
||||
out_of_range(out_of_range &&) = default;
|
||||
out_of_range &operator=(out_of_range &&) = default;
|
||||
virtual ~out_of_range() = default;
|
||||
};
|
||||
}
|
21
Kernel/include_std/stdint.h
Normal file
21
Kernel/include_std/stdint.h
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifndef _STDINT_H
|
||||
#define _STDINT_H
|
||||
|
||||
#endif // !_STDINT_H
|
56
Kernel/include_std/stdio.h
Normal file
56
Kernel/include_std/stdio.h
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifndef __FENNIX_KERNEL_STDIO_H__
|
||||
#define __FENNIX_KERNEL_STDIO_H__
|
||||
|
||||
#include <types.h>
|
||||
|
||||
START_EXTERNC
|
||||
|
||||
#define FILENAME_MAX 4096
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int st;
|
||||
} FILE;
|
||||
|
||||
extern FILE *stdin;
|
||||
extern FILE *stdout;
|
||||
extern FILE *stderr;
|
||||
|
||||
#define stdin stdin
|
||||
#define stdout stdout
|
||||
#define stderr stderr
|
||||
|
||||
int printf(const char *format, ...) __attribute__((format(__printf__, (1), (2))));
|
||||
int vprintf(const char *format, va_list arg) __attribute__((format(__printf__, ((1)), (0))));
|
||||
int sprintf(char *s, const char *format, ...) __attribute__((format(__printf__, (2), (3))));
|
||||
int vsprintf(char *s, const char *format, va_list arg) __attribute__((format(__printf__, ((2)), (0))));
|
||||
int snprintf(char *s, size_t count, const char *format, ...) __attribute__((format(__printf__, (3), (4))));
|
||||
int vsnprintf(char *s, size_t count, const char *format, va_list arg) __attribute__((format(__printf__, ((3)), (0))));
|
||||
|
||||
int asprintf(char **strp, const char *fmt, ...) __attribute__((format(__printf__, (2), (3))));
|
||||
int vasprintf(char **strp, const char *fmt, va_list ap) __attribute__((format(__printf__, ((2)), (0))));
|
||||
|
||||
int fprintf(FILE *stream, const char *format, ...) __attribute__((format(__printf__, (2), (3))));
|
||||
|
||||
int fputs(const char *s, FILE *stream);
|
||||
|
||||
END_EXTERNC
|
||||
|
||||
#endif // !__FENNIX_KERNEL_STDIO_H__
|
41
Kernel/include_std/stdlib.h
Normal file
41
Kernel/include_std/stdlib.h
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifndef __FENNIX_KERNEL_STDLIB_H__
|
||||
#define __FENNIX_KERNEL_STDLIB_H__
|
||||
|
||||
#include <types.h>
|
||||
|
||||
START_EXTERNC
|
||||
|
||||
#ifndef __FENNIX_KERNEL_INTERNAL_MEMORY_H__
|
||||
|
||||
void *malloc(size_t Size);
|
||||
void *calloc(size_t n, size_t Size);
|
||||
void *realloc(void *Address, size_t Size);
|
||||
void free(void *Address);
|
||||
|
||||
#endif // !__FENNIX_KERNEL_INTERNAL_MEMORY_H__
|
||||
|
||||
void abort();
|
||||
|
||||
#define EXIT_FAILURE 1
|
||||
#define EXIT_SUCCESS 0
|
||||
|
||||
END_EXTERNC
|
||||
|
||||
#endif // !__FENNIX_KERNEL_STDLIB_H__
|
312
Kernel/include_std/streambuf
Normal file
312
Kernel/include_std/streambuf
Normal file
@ -0,0 +1,312 @@
|
||||
/*
|
||||
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 <algorithm>
|
||||
#include <string>
|
||||
#include <locale>
|
||||
#include <ios>
|
||||
|
||||
namespace std
|
||||
{
|
||||
template <class CharT, class Traits = std::char_traits<CharT>>
|
||||
class basic_streambuf
|
||||
{
|
||||
public:
|
||||
typedef CharT char_type;
|
||||
typedef Traits::char_type traits_type;
|
||||
typedef Traits::int_type int_type;
|
||||
typedef Traits::pos_type pos_type;
|
||||
typedef Traits::off_type off_type;
|
||||
|
||||
private:
|
||||
char_type *_eback;
|
||||
char_type *_gptr;
|
||||
char_type *_egptr;
|
||||
char_type *_pbase;
|
||||
char_type *_pptr;
|
||||
char_type *_epptr;
|
||||
|
||||
public:
|
||||
virtual ~basic_streambuf();
|
||||
|
||||
#pragma region Locales
|
||||
|
||||
std::locale pubimbue(const std::locale &loc)
|
||||
{
|
||||
return imbue(loc);
|
||||
}
|
||||
|
||||
std::locale getloc() const
|
||||
{
|
||||
return imbue(std::locale());
|
||||
}
|
||||
|
||||
#pragma endregion Locales
|
||||
|
||||
#pragma region Positioning
|
||||
|
||||
basic_streambuf<CharT, Traits> *pubsetbuf(char_type *s, std::streamsize n)
|
||||
{
|
||||
return setbuf(s, n);
|
||||
}
|
||||
|
||||
pos_type pubseekoff(off_type off, std::ios_base::seekdir dir, std::ios_base::openmode which = ios_base::in | ios_base::out)
|
||||
{
|
||||
return seekoff(off, dir, which);
|
||||
}
|
||||
|
||||
pos_type pubseekpos(pos_type pos, std::ios_base::openmode which = std::ios_base::in | std::ios_base::out)
|
||||
{
|
||||
return seekpos(pos, which);
|
||||
}
|
||||
|
||||
int pubsync()
|
||||
{
|
||||
return sync();
|
||||
}
|
||||
|
||||
#pragma endregion Positioning
|
||||
|
||||
#pragma region Get Area
|
||||
|
||||
std::streamsize in_avail()
|
||||
{
|
||||
return egptr() - gptr();
|
||||
}
|
||||
|
||||
int_type snextc()
|
||||
{
|
||||
return gptr() == egptr() ? Traits::eof() : Traits::to_int_type(*gptr());
|
||||
}
|
||||
|
||||
int_type sgetc()
|
||||
{
|
||||
return gptr() == egptr() ? underflow() : Traits::to_int_type(*gptr());
|
||||
}
|
||||
|
||||
std::streamsize sgetn(char_type *s, std::streamsize count)
|
||||
{
|
||||
std::streamsize copied = 0;
|
||||
while (copied < count)
|
||||
{
|
||||
if (gptr() == egptr())
|
||||
{
|
||||
if (underflow() == Traits::eof())
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
*s++ = *gptr();
|
||||
++copied;
|
||||
}
|
||||
return copied;
|
||||
}
|
||||
|
||||
#pragma endregion Get Area
|
||||
|
||||
#pragma region Put Area
|
||||
|
||||
int_type sputc(char_type ch)
|
||||
{
|
||||
if (pptr() == epptr())
|
||||
{
|
||||
if (overflow(Traits::to_int_type(ch)) == Traits::eof())
|
||||
{
|
||||
return Traits::eof();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
*pptr() = ch;
|
||||
pbump(1);
|
||||
}
|
||||
return Traits::to_int_type(ch);
|
||||
}
|
||||
|
||||
std::streamsize sputn(const char_type *s, std::streamsize count)
|
||||
{
|
||||
return xsputn(s, count);
|
||||
}
|
||||
|
||||
#pragma endregion Put Area
|
||||
|
||||
#pragma region Putback
|
||||
|
||||
int_type sputbackc(char_type c)
|
||||
{
|
||||
if (gptr() == eback() || !Traits::eq(c, gptr()[-1]))
|
||||
{
|
||||
return Traits::eof();
|
||||
}
|
||||
gbump(-1);
|
||||
return Traits::to_int_type(c);
|
||||
}
|
||||
|
||||
int_type sungetc()
|
||||
{
|
||||
if (gptr() == eback())
|
||||
{
|
||||
return Traits::eof();
|
||||
}
|
||||
gbump(-1);
|
||||
return Traits::to_int_type(*gptr());
|
||||
}
|
||||
|
||||
#pragma endregion Putback
|
||||
|
||||
protected:
|
||||
basic_streambuf()
|
||||
: _eback(nullptr),
|
||||
_gptr(nullptr),
|
||||
_egptr(nullptr),
|
||||
_pbase(nullptr),
|
||||
_pptr(nullptr),
|
||||
_epptr(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
basic_streambuf(const basic_streambuf &rhs)
|
||||
: _eback(rhs._eback),
|
||||
_gptr(rhs._gptr),
|
||||
_egptr(rhs._egptr),
|
||||
_pbase(rhs._pbase),
|
||||
_pptr(rhs._pptr),
|
||||
_epptr(rhs._epptr)
|
||||
{
|
||||
}
|
||||
|
||||
basic_streambuf &operator=(const basic_streambuf &other)
|
||||
{
|
||||
if (this == &other)
|
||||
return *this;
|
||||
|
||||
_eback = other._eback;
|
||||
_gptr = other._gptr;
|
||||
_egptr = other._egptr;
|
||||
_pbase = other._pbase;
|
||||
_pptr = other._pptr;
|
||||
_epptr = other._epptr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
void swap(basic_streambuf &other)
|
||||
{
|
||||
std::swap(_eback, other._eback);
|
||||
std::swap(_gptr, other._gptr);
|
||||
std::swap(_egptr, other._egptr);
|
||||
std::swap(_pbase, other._pbase);
|
||||
std::swap(_pptr, other._pptr);
|
||||
std::swap(_epptr, other._epptr);
|
||||
}
|
||||
|
||||
#pragma region Locales
|
||||
|
||||
virtual void imbue(const std::locale &loc) = 0;
|
||||
|
||||
#pragma endregion Locales
|
||||
|
||||
#pragma region Positioning
|
||||
|
||||
virtual basic_streambuf<CharT, Traits> *setbuf(char_type *s, std::streamsize n) = 0;
|
||||
virtual pos_type seekoff(off_type off, std::ios_base::seekdir dir, std::ios_base::openmode which = ios_base::in | ios_base::out) = 0;
|
||||
virtual pos_type seekpos(pos_type pos, std::ios_base::openmode which = std::ios_base::in | std::ios_base::out) = 0;
|
||||
virtual int sync() = 0;
|
||||
|
||||
#pragma endregion Positioning
|
||||
|
||||
#pragma region Get Area
|
||||
|
||||
virtual std::streamsize showmanyc() = 0;
|
||||
virtual int_type underflow() = 0;
|
||||
virtual int_type uflow() = 0;
|
||||
virtual std::streamsize xsgetn(char_type *s, std::streamsize count) = 0;
|
||||
|
||||
char_type *eback() const
|
||||
{
|
||||
return _eback;
|
||||
}
|
||||
|
||||
char_type *gptr() const
|
||||
{
|
||||
return _gptr;
|
||||
}
|
||||
|
||||
char_type *egptr() const
|
||||
{
|
||||
return _egptr;
|
||||
}
|
||||
|
||||
void gbump(int count)
|
||||
{
|
||||
_gptr += count;
|
||||
}
|
||||
|
||||
void setg(char_type *gbeg, char_type *gcurr, char_type *gend)
|
||||
{
|
||||
_eback = gbeg;
|
||||
_gptr = gcurr;
|
||||
_egptr = gend;
|
||||
}
|
||||
|
||||
#pragma endregion Get Area
|
||||
|
||||
#pragma region Put Area
|
||||
|
||||
virtual std::streamsize xsputn(const char_type *s, std::streamsize count) = 0;
|
||||
virtual int_type overflow(int_type ch = Traits::eof()) = 0;
|
||||
|
||||
char_type *pbase() const
|
||||
{
|
||||
return _pbase;
|
||||
}
|
||||
|
||||
char_type *pptr() const
|
||||
{
|
||||
return _pptr;
|
||||
}
|
||||
|
||||
char_type *epptr() const
|
||||
{
|
||||
return _epptr;
|
||||
}
|
||||
|
||||
void pbump(int count)
|
||||
{
|
||||
_pptr += count;
|
||||
}
|
||||
|
||||
void setp(char_type *pbeg, char_type *pend)
|
||||
{
|
||||
_pbase = pbeg;
|
||||
_pptr = pbeg;
|
||||
_epptr = pend;
|
||||
}
|
||||
|
||||
#pragma endregion Put Area
|
||||
|
||||
#pragma region Putback
|
||||
|
||||
virtual int_type pbackfail(int_type c = Traits::eof()) = 0;
|
||||
|
||||
#pragma endregion Putback
|
||||
};
|
||||
|
||||
typedef basic_streambuf<char> streambuf;
|
||||
typedef basic_streambuf<wchar_t> wstreambuf;
|
||||
}
|
2477
Kernel/include_std/string
Normal file
2477
Kernel/include_std/string
Normal file
File diff suppressed because it is too large
Load Diff
23
Kernel/include_std/string.h
Normal file
23
Kernel/include_std/string.h
Normal file
@ -0,0 +1,23 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifndef _STRING_H
|
||||
#define _STRING_H
|
||||
|
||||
#include <convert.h>
|
||||
|
||||
#endif // !_STRING_H
|
62
Kernel/include_std/string_view
Normal file
62
Kernel/include_std/string_view
Normal file
@ -0,0 +1,62 @@
|
||||
/*
|
||||
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 <string>
|
||||
#include <ostream>
|
||||
|
||||
namespace std
|
||||
{
|
||||
typedef basic_string_view<char> string_view;
|
||||
typedef basic_string_view<wchar_t> wstring_view;
|
||||
typedef basic_string_view<char8_t> u8string_view;
|
||||
typedef basic_string_view<char16_t> u16string_view;
|
||||
typedef basic_string_view<char32_t> u32string_view;
|
||||
|
||||
template <class CharT, class Traits>
|
||||
std::basic_ostream<CharT, Traits> &operator<<(std::basic_ostream<CharT, Traits> &os, std::basic_string_view<CharT, Traits> v)
|
||||
{
|
||||
os.write(v.data(), v.size());
|
||||
return os;
|
||||
}
|
||||
|
||||
constexpr std::string_view operator""sv(const char *str, std::size_t len) noexcept
|
||||
{
|
||||
return std::string_view{str, len};
|
||||
}
|
||||
|
||||
constexpr std::u8string_view operator""sv(const char8_t *str, std::size_t len) noexcept
|
||||
{
|
||||
return std::u8string_view{str, len};
|
||||
}
|
||||
|
||||
constexpr std::u16string_view operator""sv(const char16_t *str, std::size_t len) noexcept
|
||||
{
|
||||
return std::u16string_view{str, len};
|
||||
}
|
||||
|
||||
constexpr std::u32string_view operator""sv(const char32_t *str, std::size_t len) noexcept
|
||||
{
|
||||
return std::u32string_view{str, len};
|
||||
}
|
||||
|
||||
constexpr std::wstring_view operator""sv(const wchar_t *str, std::size_t len) noexcept
|
||||
{
|
||||
return std::wstring_view{str, len};
|
||||
}
|
||||
}
|
21
Kernel/include_std/strings.h
Normal file
21
Kernel/include_std/strings.h
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifndef _STRINGS_H
|
||||
#define _STRINGS_H
|
||||
|
||||
#endif // !_STRINGS_H
|
79
Kernel/include_std/stropts.h
Normal file
79
Kernel/include_std/stropts.h
Normal file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifndef _STROPTS_H
|
||||
#define _STROPTS_H
|
||||
|
||||
#define __SID ('S' << 8)
|
||||
|
||||
#define I_NREAD (__SID | 1)
|
||||
#define I_PUSH (__SID | 2)
|
||||
#define I_POP (__SID | 3)
|
||||
#define I_LOOK (__SID | 4)
|
||||
#define I_FLUSH (__SID | 5)
|
||||
#define I_SRDOPT (__SID | 6)
|
||||
#define I_GRDOPT (__SID | 7)
|
||||
#define I_STR (__SID | 8)
|
||||
#define I_SETSIG (__SID | 9)
|
||||
#define I_GETSIG (__SID | 10)
|
||||
#define I_FIND (__SID | 11)
|
||||
#define I_LINK (__SID | 12)
|
||||
#define I_UNLINK (__SID | 13)
|
||||
#define I_PEEK (__SID | 15)
|
||||
#define I_FDINSERT (__SID | 16)
|
||||
#define I_SENDFD (__SID | 17)
|
||||
#define I_RECVFD (__SID | 14)
|
||||
#define I_SWROPT (__SID | 19)
|
||||
#define I_GWROPT (__SID | 20)
|
||||
#define I_LIST (__SID | 21)
|
||||
#define I_PLINK (__SID | 22)
|
||||
#define I_PUNLINK (__SID | 23)
|
||||
#define I_FLUSHBAND (__SID | 28)
|
||||
#define I_CKBAND (__SID | 29)
|
||||
#define I_GETBAND (__SID | 30)
|
||||
#define I_ATMARK (__SID | 31)
|
||||
#define I_SETCLTIME (__SID | 32)
|
||||
#define I_GETCLTIME (__SID | 33)
|
||||
#define I_CANPUT (__SID | 34)
|
||||
|
||||
#define TCGETS 0x5401
|
||||
#define TCSETS 0x5402
|
||||
#define TCSETSW 0x5403
|
||||
#define TCSETSF 0x5404
|
||||
#define TCGETA 0x5405
|
||||
#define TCSETA 0x5406
|
||||
#define TCSETAW 0x5407
|
||||
#define TCSETAF 0x5408
|
||||
#define TCSBRK 0x5409
|
||||
#define TCXONC 0x540A
|
||||
#define TCFLSH 0x540B
|
||||
#define TIOCEXCL 0x540C
|
||||
#define TIOCNXCL 0x540D
|
||||
#define TIOCSCTTY 0x540E
|
||||
#define TIOCGPGRP 0x540F
|
||||
#define TIOCSPGRP 0x5410
|
||||
#define TIOCOUTQ 0x5411
|
||||
#define TIOCSTI 0x5412
|
||||
#define TIOCGWINSZ 0x5413
|
||||
#define TIOCSWINSZ 0x5414
|
||||
#define TIOCMGET 0x5415
|
||||
#define TIOCMBIS 0x5416
|
||||
#define TIOCMBIC 0x5417
|
||||
#define TIOCMSET 0x5418
|
||||
#define TIOCGSID 0x5429
|
||||
|
||||
#endif
|
45
Kernel/include_std/sys/mman.h
Normal file
45
Kernel/include_std/sys/mman.h
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
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 <types.h>
|
||||
|
||||
/* stubs for rpmalloc.c */
|
||||
|
||||
#ifndef MAP_PRIVATE
|
||||
#define MAP_PRIVATE 0x0
|
||||
#endif
|
||||
|
||||
#ifndef MAP_ANONYMOUS
|
||||
#define MAP_ANONYMOUS 0x0
|
||||
#endif
|
||||
|
||||
#ifndef PROT_READ
|
||||
#define PROT_READ 0x0
|
||||
#endif
|
||||
|
||||
#ifndef PROT_WRITE
|
||||
#define PROT_WRITE 0x0
|
||||
#endif
|
||||
|
||||
#ifndef MAP_FAILED
|
||||
#define MAP_FAILED 0x0
|
||||
#endif
|
||||
|
||||
#ifndef POSIX_MADV_DONTNEED
|
||||
#define POSIX_MADV_DONTNEED 0x0
|
||||
#endif
|
21
Kernel/include_std/sys/stat.h
Normal file
21
Kernel/include_std/sys/stat.h
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifndef _SYS_STAT_H
|
||||
#define _SYS_STAT_H
|
||||
|
||||
#endif // !_SYS_STAT_H
|
21
Kernel/include_std/sys/types.h
Normal file
21
Kernel/include_std/sys/types.h
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifndef _SYS_TYPES_H
|
||||
#define _SYS_TYPES_H
|
||||
|
||||
#endif // !_SYS_TYPES_H
|
58
Kernel/include_std/system_error
Normal file
58
Kernel/include_std/system_error
Normal file
@ -0,0 +1,58 @@
|
||||
/*
|
||||
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
|
||||
|
||||
namespace std
|
||||
{
|
||||
class error_category
|
||||
{
|
||||
/* https://en.cppreference.com/w/cpp/error/error_category */
|
||||
};
|
||||
|
||||
class error_code
|
||||
{
|
||||
public:
|
||||
error_code() noexcept
|
||||
{
|
||||
}
|
||||
|
||||
error_code(int ec, const error_category &ecat) noexcept
|
||||
{
|
||||
}
|
||||
|
||||
template <class ErrorCodeEnum>
|
||||
error_code(ErrorCodeEnum e) noexcept
|
||||
{
|
||||
}
|
||||
|
||||
error_code(const error_code &other) = default;
|
||||
error_code(error_code &&other) = default;
|
||||
|
||||
template <class ErrorCodeEnum>
|
||||
error_code &operator=(ErrorCodeEnum e) noexcept
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
error_code &operator=(const error_code &other) = default;
|
||||
|
||||
error_code &operator=(error_code &&other) = default;
|
||||
|
||||
/* https://en.cppreference.com/w/cpp/error/error_code */
|
||||
};
|
||||
}
|
190
Kernel/include_std/termios.h
Normal file
190
Kernel/include_std/termios.h
Normal file
@ -0,0 +1,190 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifndef __FENNIX_KERNEL_TERMIOS_H__
|
||||
#define __FENNIX_KERNEL_TERMIOS_H__
|
||||
|
||||
#include <types.h>
|
||||
|
||||
/* c_cc */
|
||||
#define VINTR 0
|
||||
#define VQUIT 1
|
||||
#define VERASE 2
|
||||
#define VKILL 3
|
||||
#define VEOF 4
|
||||
#define VTIME 5
|
||||
#define VMIN 6
|
||||
#define VSWTC 7
|
||||
#define VSTART 8
|
||||
#define VSTOP 9
|
||||
#define VSUSP 10
|
||||
#define VEOL 11
|
||||
#define VREPRINT 12
|
||||
#define VDISCARD 13
|
||||
#define VWERASE 14
|
||||
#define VLNEXT 15
|
||||
#define VEOL2 16
|
||||
|
||||
/* c_iflag */
|
||||
#define IGNBRK 0000001
|
||||
#define BRKINT 0000002
|
||||
#define IGNPAR 0000004
|
||||
#define PARMRK 0000010
|
||||
#define INPCK 0000020
|
||||
#define ISTRIP 0000040
|
||||
#define INLCR 0000100
|
||||
#define IGNCR 0000200
|
||||
#define ICRNL 0000400
|
||||
#define IUCLC 0001000
|
||||
#define IXON 0002000
|
||||
#define IXANY 0004000
|
||||
#define IXOFF 0010000
|
||||
#define IMAXBEL 0020000
|
||||
#define IUTF8 0040000
|
||||
|
||||
/* c_lflag */
|
||||
#define ISIG 0000001
|
||||
#define ICANON 0000002
|
||||
#define XCASE 0000004
|
||||
#define ECHO 0000010
|
||||
#define ECHOE 0000020
|
||||
#define ECHOK 0000040
|
||||
#define ECHONL 0000100
|
||||
#define NOFLSH 0000200
|
||||
#define TOSTOP 0000400
|
||||
#define ECHOCTL 0001000
|
||||
#define ECHOPRT 0002000
|
||||
#define ECHOKE 0004000
|
||||
#define FLUSHO 0010000
|
||||
#define PENDIN 0040000
|
||||
#define IEXTEN 0100000
|
||||
#define EXTPROC 0200000
|
||||
|
||||
/* c_oflag */
|
||||
#define OPOST 0000001
|
||||
#define OLCUC 0000002
|
||||
#define ONLCR 0000004
|
||||
#define OCRNL 0000010
|
||||
#define ONOCR 0000020
|
||||
#define ONLRET 0000040
|
||||
#define OFILL 0000100
|
||||
#define OFDEL 0000200
|
||||
#define NLDLY 0000400
|
||||
#define NL0 0000000
|
||||
#define NL1 0000400
|
||||
#define CRDLY 0003000
|
||||
#define _CR0 0000000
|
||||
#define _CR1 0001000
|
||||
#define _CR2 0002000
|
||||
#define _CR3 0003000
|
||||
#define TABDLY 0014000
|
||||
#define TAB0 0000000
|
||||
#define TAB1 0004000
|
||||
#define TAB2 0010000
|
||||
#define TAB3 0014000
|
||||
#define XTABS 0014000
|
||||
#define BSDLY 0020000
|
||||
#define BS0 0000000
|
||||
#define BS1 0020000
|
||||
#define VTDLY 0040000
|
||||
#define VT0 0000000
|
||||
#define VT1 0040000
|
||||
#define FFDLY 0100000
|
||||
#define FF0 0000000
|
||||
#define FF1 0100000
|
||||
|
||||
/* c_cflag */
|
||||
#define CBAUD 0010017
|
||||
#define _B0 0000000
|
||||
#define B50 0000001
|
||||
#define B75 0000002
|
||||
#define B110 0000003
|
||||
#define B134 0000004
|
||||
#define B150 0000005
|
||||
#define B200 0000006
|
||||
#define B300 0000007
|
||||
#define B600 0000010
|
||||
#define B1200 0000011
|
||||
#define B1800 0000012
|
||||
#define B2400 0000013
|
||||
#define B4800 0000014
|
||||
#define B9600 0000015
|
||||
#define B19200 0000016
|
||||
#define B38400 0000017
|
||||
#define EXTA B19200
|
||||
#define EXTB B38400
|
||||
#define CSIZE 0000060
|
||||
#define CS5 0000000
|
||||
#define CS6 0000020
|
||||
#define CS7 0000040
|
||||
#define CS8 0000060
|
||||
#define CSTOPB 0000100
|
||||
#define CREAD 0000200
|
||||
#define PARENB 0000400
|
||||
#define PARODD 0001000
|
||||
#define HUPCL 0002000
|
||||
#define CLOCAL 0004000
|
||||
#define CBAUDEX 0010000
|
||||
#define BOTHER 0010000
|
||||
#define B57600 0010001
|
||||
#define B115200 0010002
|
||||
#define B230400 0010003
|
||||
#define B460800 0010004
|
||||
#define B500000 0010005
|
||||
#define B576000 0010006
|
||||
#define B921600 0010007
|
||||
#define B1000000 0010010
|
||||
#define B1152000 0010011
|
||||
#define B1500000 0010012
|
||||
#define B2000000 0010013
|
||||
#define B2500000 0010014
|
||||
#define B3000000 0010015
|
||||
#define B3500000 0010016
|
||||
#define B4000000 0010017
|
||||
#define CIBAUD 002003600000
|
||||
#define CMSPAR 010000000000
|
||||
#define CRTSCTS 020000000000
|
||||
|
||||
typedef unsigned char cc_t;
|
||||
typedef unsigned int speed_t;
|
||||
typedef unsigned int tcflag_t;
|
||||
|
||||
#define NCCS 32
|
||||
struct termios
|
||||
{
|
||||
tcflag_t c_iflag;
|
||||
tcflag_t c_oflag;
|
||||
tcflag_t c_cflag;
|
||||
tcflag_t c_lflag;
|
||||
cc_t c_cc[NCCS];
|
||||
};
|
||||
|
||||
struct winsize
|
||||
{
|
||||
unsigned short ws_row;
|
||||
unsigned short ws_col;
|
||||
unsigned short ws_xpixel;
|
||||
unsigned short ws_ypixel;
|
||||
};
|
||||
|
||||
struct ttysize
|
||||
{
|
||||
int ts_lines;
|
||||
int ts_cols;
|
||||
};
|
||||
|
||||
#endif // !__FENNIX_KERNEL_TERMIOS_H__
|
81
Kernel/include_std/thread
Normal file
81
Kernel/include_std/thread
Normal file
@ -0,0 +1,81 @@
|
||||
/*
|
||||
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 <convert.h>
|
||||
#include <task.hpp>
|
||||
#include <debug.h>
|
||||
#include <smp.hpp>
|
||||
|
||||
extern Tasking::Task *TaskManager;
|
||||
|
||||
namespace std
|
||||
{
|
||||
class thread
|
||||
{
|
||||
private:
|
||||
Tasking::TCB *Task = nullptr;
|
||||
|
||||
public:
|
||||
thread() = default;
|
||||
thread(const thread &) = delete;
|
||||
thread(thread &&) = delete;
|
||||
thread &operator=(const thread &) = delete;
|
||||
thread &operator=(thread &&) = delete;
|
||||
|
||||
template <class Function, class... Args>
|
||||
explicit thread(Function &&f, Args &&...args)
|
||||
{
|
||||
Task = TaskManager->CreateThread(thisProcess, (Tasking::IP)f);
|
||||
Task->SYSV_ABI_Call(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
~thread()
|
||||
{
|
||||
if (Task)
|
||||
Task->SendSignal(SIGKILL);
|
||||
}
|
||||
|
||||
void join()
|
||||
{
|
||||
TaskManager->WaitForThread(Task);
|
||||
}
|
||||
|
||||
bool joinable() const
|
||||
{
|
||||
return Task != nullptr;
|
||||
}
|
||||
|
||||
void detach()
|
||||
{
|
||||
Task = nullptr;
|
||||
}
|
||||
|
||||
void swap(thread &other) noexcept
|
||||
{
|
||||
Tasking::TCB *temp = Task;
|
||||
Task = other.Task;
|
||||
other.Task = temp;
|
||||
}
|
||||
|
||||
Tasking::TCB *native_handle()
|
||||
{
|
||||
return Task;
|
||||
}
|
||||
};
|
||||
}
|
29
Kernel/include_std/time.h
Normal file
29
Kernel/include_std/time.h
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifndef _TIME_H
|
||||
#define _TIME_H
|
||||
|
||||
#include <types.h>
|
||||
|
||||
struct timespec
|
||||
{
|
||||
time_t tv_sec; /* seconds */
|
||||
long tv_nsec; /* nanoseconds */
|
||||
};
|
||||
|
||||
#endif // !_TIME_H
|
27
Kernel/include_std/tuple
Normal file
27
Kernel/include_std/tuple
Normal file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
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 <type_traits>
|
||||
#include <cstddef>
|
||||
|
||||
namespace std
|
||||
{
|
||||
template <class... Types>
|
||||
class tuple;
|
||||
}
|
662
Kernel/include_std/type_traits
Normal file
662
Kernel/include_std/type_traits
Normal file
@ -0,0 +1,662 @@
|
||||
/*
|
||||
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
|
||||
|
||||
namespace std
|
||||
{
|
||||
template <class T>
|
||||
struct add_cv
|
||||
{
|
||||
typedef const volatile T type;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct add_const
|
||||
{
|
||||
typedef const T type;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct add_volatile
|
||||
{
|
||||
typedef volatile T type;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
using add_cv_t = typename add_cv<T>::type;
|
||||
|
||||
template <class T>
|
||||
using add_const_t = typename add_const<T>::type;
|
||||
|
||||
template <class T>
|
||||
using add_volatile_t = typename add_volatile<T>::type;
|
||||
|
||||
template <typename T>
|
||||
struct is_trivially_copyable
|
||||
{
|
||||
static constexpr bool value = __is_trivially_copyable(T);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct remove_reference
|
||||
{
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct remove_reference<T &>
|
||||
{
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct remove_reference<T &&>
|
||||
{
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
using remove_reference_t = typename remove_reference<T>::type;
|
||||
|
||||
template <class T, T v>
|
||||
struct integral_constant
|
||||
{
|
||||
static constexpr T value = v;
|
||||
typedef T value_type;
|
||||
typedef integral_constant type;
|
||||
constexpr operator value_type() const noexcept { return value; }
|
||||
constexpr value_type operator()() const noexcept { return value; }
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_array : public integral_constant<bool, false>
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_array<T[]> : public integral_constant<bool, true>
|
||||
{
|
||||
};
|
||||
|
||||
template <class T, __SIZE_TYPE__ N>
|
||||
struct is_array<T[N]> : public integral_constant<bool, true>
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
inline constexpr bool is_array_v = is_array<T>::value;
|
||||
|
||||
template <bool B, class T, class F>
|
||||
struct conditional
|
||||
{
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
template <class T, class F>
|
||||
struct conditional<false, T, F>
|
||||
{
|
||||
typedef F type;
|
||||
};
|
||||
|
||||
template <bool B, class T, class F>
|
||||
using conditional_t = typename conditional<B, T, F>::type;
|
||||
|
||||
template <class T>
|
||||
struct type_identity
|
||||
{
|
||||
using type = T;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
using type_identity_t = type_identity<T>::type;
|
||||
|
||||
template <class T>
|
||||
auto __try_add_pointer(int) -> type_identity<typename std::remove_reference<T>::type *>;
|
||||
|
||||
template <class T>
|
||||
auto __try_add_pointer(...) -> type_identity<T>;
|
||||
|
||||
template <class T>
|
||||
struct add_pointer : decltype(__try_add_pointer<T>(0))
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
using add_pointer_t = typename add_pointer<T>::type;
|
||||
|
||||
template <class T>
|
||||
struct remove_extent
|
||||
{
|
||||
using type = T;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct remove_extent<T[]>
|
||||
{
|
||||
using type = T;
|
||||
};
|
||||
|
||||
template <class T, __SIZE_TYPE__ N>
|
||||
struct remove_extent<T[N]>
|
||||
{
|
||||
using type = T;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
using remove_extent_t = typename remove_extent<T>::type;
|
||||
|
||||
template <class T>
|
||||
struct remove_cv
|
||||
{
|
||||
typedef T type;
|
||||
};
|
||||
template <class T>
|
||||
struct remove_cv<const T>
|
||||
{
|
||||
typedef T type;
|
||||
};
|
||||
template <class T>
|
||||
struct remove_cv<volatile T>
|
||||
{
|
||||
typedef T type;
|
||||
};
|
||||
template <class T>
|
||||
struct remove_cv<const volatile T>
|
||||
{
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct remove_const
|
||||
{
|
||||
typedef T type;
|
||||
};
|
||||
template <class T>
|
||||
struct remove_const<const T>
|
||||
{
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct remove_volatile
|
||||
{
|
||||
typedef T type;
|
||||
};
|
||||
template <class T>
|
||||
struct remove_volatile<volatile T>
|
||||
{
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
using remove_cv_t = typename remove_cv<T>::type;
|
||||
|
||||
template <class T>
|
||||
using remove_const_t = typename remove_const<T>::type;
|
||||
|
||||
template <class T>
|
||||
using remove_volatile_t = typename remove_volatile<T>::type;
|
||||
|
||||
template <class T>
|
||||
struct is_lvalue_reference : public integral_constant<bool, false>
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_lvalue_reference<T &> : public integral_constant<bool, true>
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
inline constexpr bool is_lvalue_reference_v = is_lvalue_reference<T>::value;
|
||||
|
||||
template <class T>
|
||||
struct is_const : public integral_constant<bool, false>
|
||||
{
|
||||
};
|
||||
template <class T>
|
||||
struct is_const<const T> : public integral_constant<bool, true>
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
inline constexpr bool is_const_v = is_const<T>::value;
|
||||
|
||||
template <class T>
|
||||
struct is_reference : public integral_constant<bool, false>
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_reference<T &> : public integral_constant<bool, true>
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_reference<T &&> : public integral_constant<bool, true>
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
inline constexpr bool is_reference_v = is_reference<T>::value;
|
||||
|
||||
template <class T>
|
||||
struct is_function : std::integral_constant<
|
||||
bool,
|
||||
!std::is_const<const T>::value && !std::is_reference<T>::value>
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct decay
|
||||
{
|
||||
private:
|
||||
typedef typename std::remove_reference<T>::type U;
|
||||
|
||||
public:
|
||||
typedef typename std::conditional<
|
||||
std::is_array<U>::value,
|
||||
typename std::add_pointer<typename std::remove_extent<U>::type>::type,
|
||||
typename std::conditional<
|
||||
std::is_function<U>::value,
|
||||
typename std::add_pointer<U>::type,
|
||||
typename std::remove_cv<U>::type>::type>::type type;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
using decay_t = typename decay<T>::type;
|
||||
|
||||
template <bool B>
|
||||
using bool_constant = integral_constant<bool, B>;
|
||||
|
||||
template <class T>
|
||||
struct is_integral : bool_constant < requires(T t, T *p, void (*f)(T))
|
||||
{
|
||||
reinterpret_cast<T>(t);
|
||||
f(0);
|
||||
p + t;
|
||||
} > {};
|
||||
|
||||
template <class T>
|
||||
constexpr bool is_integral_v = is_integral<T>::value;
|
||||
|
||||
typedef integral_constant<bool, true> true_type;
|
||||
typedef integral_constant<bool, false> false_type;
|
||||
|
||||
template <bool, class T = void>
|
||||
struct enable_if
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct enable_if<true, T>
|
||||
{
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
template <bool B, class T = void>
|
||||
using enable_if_t = typename enable_if<B, T>::type;
|
||||
|
||||
template <class T>
|
||||
auto __try_add_lvalue_reference(int) -> type_identity<T &>;
|
||||
|
||||
template <class T>
|
||||
auto __try_add_lvalue_reference(...) -> type_identity<T>;
|
||||
|
||||
template <class T>
|
||||
auto __try_add_rvalue_reference(int) -> type_identity<T &&>;
|
||||
|
||||
template <class T>
|
||||
auto __try_add_rvalue_reference(...) -> type_identity<T>;
|
||||
|
||||
template <class T>
|
||||
struct add_lvalue_reference : decltype(__try_add_lvalue_reference<T>(0))
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct add_rvalue_reference : decltype(__try_add_rvalue_reference<T>(0))
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
using add_lvalue_reference_t = typename add_lvalue_reference<T>::type;
|
||||
|
||||
template <class T>
|
||||
using add_rvalue_reference_t = typename add_rvalue_reference<T>::type;
|
||||
|
||||
template <typename T>
|
||||
typename std::add_rvalue_reference<T>::type declval() noexcept
|
||||
{
|
||||
static_assert(false, "declval not allowed in an evaluated context");
|
||||
}
|
||||
|
||||
template <class T, class... Args>
|
||||
struct is_constructible : public integral_constant<bool, __is_constructible(T, Args...)>
|
||||
{
|
||||
};
|
||||
|
||||
template <class T, class... Args>
|
||||
struct is_trivially_constructible : public integral_constant<bool, __is_trivially_constructible(T, Args...)>
|
||||
{
|
||||
};
|
||||
|
||||
template <class T, class... Args>
|
||||
struct is_nothrow_constructible : public integral_constant<bool, __is_nothrow_constructible(T, Args...)>
|
||||
{
|
||||
};
|
||||
|
||||
template <class T, class... Args>
|
||||
inline constexpr bool is_constructible_v = is_constructible<T, Args...>::value;
|
||||
|
||||
template <class T, class... Args>
|
||||
inline constexpr bool is_trivially_constructible_v = is_trivially_constructible<T, Args...>::value;
|
||||
|
||||
template <class T, class... Args>
|
||||
inline constexpr bool is_nothrow_constructible_v = is_nothrow_constructible<T, Args...>::value;
|
||||
|
||||
template <class T>
|
||||
struct is_default_constructible : std::is_constructible<T>
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_trivially_default_constructible : std::is_trivially_constructible<T>
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_nothrow_default_constructible : std::is_nothrow_constructible<T>
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
inline constexpr bool is_default_constructible_v = is_default_constructible<T>::value;
|
||||
|
||||
template <class T>
|
||||
inline constexpr bool is_trivially_default_constructible_v = is_trivially_default_constructible<T>::value;
|
||||
|
||||
template <class T>
|
||||
inline constexpr bool is_nothrow_default_constructible_v = is_nothrow_default_constructible<T>::value;
|
||||
|
||||
template <class T, class U>
|
||||
struct is_assignable : public integral_constant<bool, __is_assignable(T, U)>
|
||||
{
|
||||
};
|
||||
|
||||
template <class T, class U>
|
||||
struct is_trivially_assignable : public integral_constant<bool, __is_trivially_assignable(T, U)>
|
||||
{
|
||||
};
|
||||
|
||||
template <class T, class U>
|
||||
struct is_nothrow_assignable : public integral_constant<bool, __is_nothrow_assignable(T, U)>
|
||||
{
|
||||
};
|
||||
|
||||
template <class T, class U>
|
||||
inline constexpr bool is_assignable_v = is_assignable<T, U>::value;
|
||||
|
||||
template <class T, class U>
|
||||
inline constexpr bool is_trivially_assignable_v = is_trivially_assignable<T, U>::value;
|
||||
|
||||
template <class T, class U>
|
||||
inline constexpr bool is_nothrow_assignable_v = is_nothrow_assignable<T, U>::value;
|
||||
|
||||
template <class T>
|
||||
struct is_move_assignable : std::is_assignable<typename std::add_lvalue_reference<T>::type, typename std::add_rvalue_reference<T>::type>
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_trivially_move_assignable : std::is_trivially_assignable<typename std::add_lvalue_reference<T>::type, typename std::add_rvalue_reference<T>::type>
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_nothrow_move_assignable : std::is_nothrow_assignable<typename std::add_lvalue_reference<T>::type, typename std::add_rvalue_reference<T>::type>
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
inline constexpr bool is_move_assignable_v = is_move_assignable<T>::value;
|
||||
|
||||
template <class T>
|
||||
inline constexpr bool is_trivially_move_assignable_v = is_trivially_move_assignable<T>::value;
|
||||
|
||||
template <class T>
|
||||
inline constexpr bool is_nothrow_move_assignable_v = is_nothrow_move_assignable<T>::value;
|
||||
|
||||
template <class T>
|
||||
struct is_move_constructible : std::is_constructible<T, typename std::add_rvalue_reference<T>::type>
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_trivially_move_constructible : std::is_trivially_constructible<T, typename std::add_rvalue_reference<T>::type>
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_nothrow_move_constructible : std::is_nothrow_constructible<T, typename std::add_rvalue_reference<T>::type>
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
inline constexpr bool is_move_constructible_v = is_move_constructible<T>::value;
|
||||
|
||||
template <class T>
|
||||
inline constexpr bool is_trivially_move_constructible_v = is_trivially_move_constructible<T>::value;
|
||||
|
||||
template <class T>
|
||||
inline constexpr bool is_nothrow_move_constructible_v = is_nothrow_move_constructible<T>::value;
|
||||
|
||||
template <typename T>
|
||||
typename std::remove_reference<T>::type &&__type_traits_move(T &&arg)
|
||||
{
|
||||
return static_cast<typename std::remove_reference<T>::type &&>(arg);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void __type_traits_swap(T &a, T &b)
|
||||
{
|
||||
T temp = __type_traits_move(a);
|
||||
a = __type_traits_move(b);
|
||||
b = __type_traits_move(temp);
|
||||
}
|
||||
|
||||
template <class T, class U>
|
||||
struct is_swappable_with
|
||||
{
|
||||
template <class X, class Y,
|
||||
typename = decltype(__type_traits_swap(std::declval<X>(), std::declval<Y>())),
|
||||
typename = decltype(__type_traits_swap(std::declval<Y>(), std::declval<X>()))>
|
||||
static std::true_type test(int);
|
||||
|
||||
template <class, class>
|
||||
static std::false_type test(...);
|
||||
|
||||
static constexpr bool value = decltype(test<T, U>(0))::value;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_swappable
|
||||
{
|
||||
static constexpr bool value = is_swappable_with<T, T>::value;
|
||||
};
|
||||
|
||||
template <class T, class U>
|
||||
struct is_nothrow_swappable_with
|
||||
{
|
||||
template <class X, class Y,
|
||||
typename = decltype(__type_traits_swap(std::declval<X>(), std::declval<Y>())),
|
||||
typename = decltype(__type_traits_swap(std::declval<Y>(), std::declval<X>()))>
|
||||
static std::true_type test(int);
|
||||
|
||||
template <class, class>
|
||||
static std::false_type test(...);
|
||||
|
||||
static constexpr bool value = decltype(test<T, U>(0))::value;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_nothrow_swappable
|
||||
{
|
||||
static constexpr bool value = is_nothrow_swappable_with<T, T>::value;
|
||||
};
|
||||
|
||||
template <class T, class U>
|
||||
inline constexpr bool is_swappable_with_v = is_swappable_with<T, U>::value;
|
||||
|
||||
template <class T>
|
||||
inline constexpr bool is_swappable_v = is_swappable<T>::value;
|
||||
|
||||
template <class T, class U>
|
||||
inline constexpr bool is_nothrow_swappable_with_v = is_nothrow_swappable_with<T, U>::value;
|
||||
|
||||
template <class T>
|
||||
inline constexpr bool is_nothrow_swappable_v = is_nothrow_swappable<T>::value;
|
||||
|
||||
template <class T>
|
||||
struct is_copy_constructible : std::is_constructible<T, typename std::add_lvalue_reference<typename std::add_const<T>::type>::type>
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_trivially_copy_constructible : std::is_trivially_constructible<T, typename std::add_lvalue_reference<typename std::add_const<T>::type>::type>
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_nothrow_copy_constructible : std::is_nothrow_constructible<T, typename std::add_lvalue_reference<typename std::add_const<T>::type>::type>
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
inline constexpr bool is_copy_constructible_v = is_copy_constructible<T>::value;
|
||||
|
||||
template <class T>
|
||||
inline constexpr bool is_trivially_copy_constructible_v = is_trivially_copy_constructible<T>::value;
|
||||
|
||||
template <class T>
|
||||
inline constexpr bool is_nothrow_copy_constructible_v = is_nothrow_copy_constructible<T>::value;
|
||||
|
||||
template <class T, class U>
|
||||
struct is_same : std::false_type
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_same<T, T> : std::true_type
|
||||
{
|
||||
};
|
||||
|
||||
template <class T, class U>
|
||||
inline constexpr bool is_same_v = is_same<T, U>::value;
|
||||
|
||||
template <class T>
|
||||
struct is_unbounded_array : std::false_type
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_unbounded_array<T[]> : std::true_type
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
inline constexpr bool is_unbounded_array_v = is_unbounded_array<T>::value;
|
||||
|
||||
template <class T>
|
||||
struct is_bounded_array : std::false_type
|
||||
{
|
||||
};
|
||||
|
||||
template <class T, __SIZE_TYPE__ N>
|
||||
struct is_bounded_array<T[N]> : std::true_type
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
inline constexpr bool is_bounded_array_v = is_bounded_array<T>::value;
|
||||
|
||||
template <class...>
|
||||
struct common_type
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct common_type<T> : common_type<T, T>
|
||||
{
|
||||
};
|
||||
|
||||
namespace __type_traits_detail
|
||||
{
|
||||
template <class...>
|
||||
using void_t = void;
|
||||
|
||||
template <class T1, class T2>
|
||||
using conditional_result_t = decltype(false ? std::declval<T1>() : std::declval<T2>());
|
||||
|
||||
template <class, class, class = void>
|
||||
struct decay_conditional_result
|
||||
{
|
||||
};
|
||||
|
||||
template <class T1, class T2>
|
||||
struct decay_conditional_result<T1, T2, void_t<conditional_result_t<T1, T2>>> : std::decay<conditional_result_t<T1, T2>>
|
||||
{
|
||||
};
|
||||
|
||||
template <class T1, class T2, class = void>
|
||||
struct common_type_2_impl : decay_conditional_result<const T1 &, const T2 &>
|
||||
{
|
||||
};
|
||||
|
||||
template <class T1, class T2>
|
||||
struct common_type_2_impl<T1, T2, void_t<conditional_result_t<T1, T2>>> : decay_conditional_result<T1, T2>
|
||||
{
|
||||
};
|
||||
|
||||
template <class AlwaysVoid, class T1, class T2, class... R>
|
||||
struct common_type_multi_impl
|
||||
{
|
||||
};
|
||||
|
||||
template <class T1, class T2, class... R>
|
||||
struct common_type_multi_impl<void_t<typename common_type<T1, T2>::type>, T1, T2, R...> : common_type<typename common_type<T1, T2>::type, R...>
|
||||
{
|
||||
};
|
||||
}
|
||||
|
||||
template <class T1, class T2>
|
||||
struct common_type<T1, T2> : std::conditional<std::is_same<T1, typename std::decay<T1>::type>::value &&
|
||||
std::is_same<T2, typename std::decay<T2>::type>::value,
|
||||
__type_traits_detail::common_type_2_impl<T1, T2>,
|
||||
common_type<typename std::decay<T1>::type, typename std::decay<T2>::type>>::type
|
||||
{
|
||||
};
|
||||
|
||||
template <class T1, class T2, class... R>
|
||||
struct common_type<T1, T2, R...> : __type_traits_detail::common_type_multi_impl<void, T1, T2, R...>
|
||||
{
|
||||
};
|
||||
|
||||
template <class... T>
|
||||
using common_type_t = typename common_type<T...>::type;
|
||||
}
|
338
Kernel/include_std/typeinfo
Normal file
338
Kernel/include_std/typeinfo
Normal file
@ -0,0 +1,338 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifndef __FENNIX_KERNEL_TYPEINFO_H__
|
||||
#define __FENNIX_KERNEL_TYPEINFO_H__
|
||||
|
||||
#include <exception>
|
||||
#include <cstddef>
|
||||
|
||||
namespace __cxxabiv1
|
||||
{
|
||||
class __class_type_info;
|
||||
class __si_class_type_info;
|
||||
}
|
||||
|
||||
namespace std
|
||||
{
|
||||
class type_info
|
||||
{
|
||||
protected:
|
||||
const char *Name;
|
||||
explicit type_info(const char *n) : Name(n) {}
|
||||
|
||||
public:
|
||||
type_info() = delete;
|
||||
type_info(const type_info &) = delete;
|
||||
virtual ~type_info();
|
||||
|
||||
type_info &operator=(const type_info &) = delete;
|
||||
type_info &operator=(type_info &&) = delete;
|
||||
|
||||
constexpr bool operator==(const type_info &rhs) const noexcept
|
||||
{
|
||||
return this == &rhs;
|
||||
}
|
||||
|
||||
bool before(const type_info &rhs) const noexcept
|
||||
{
|
||||
return (Name[0] == '*' && rhs.Name[0] == '*')
|
||||
? Name < rhs.Name
|
||||
: __builtin_strcmp(Name, rhs.Name) < 0;
|
||||
}
|
||||
|
||||
std::size_t hash_code() const noexcept
|
||||
{
|
||||
return reinterpret_cast<std::size_t>(this);
|
||||
}
|
||||
|
||||
const char *name() const noexcept
|
||||
{
|
||||
return Name[0] == '*' ? Name + 1 : Name;
|
||||
}
|
||||
|
||||
virtual bool __is_pointer_p() const
|
||||
{
|
||||
return Name[0] == '*';
|
||||
}
|
||||
|
||||
virtual bool __is_function_p() const
|
||||
{
|
||||
return Name[0] == '(';
|
||||
}
|
||||
|
||||
virtual bool __do_catch(const type_info *ThrowType, void **ThrowObject, unsigned Outer) const;
|
||||
virtual bool __do_upcast(const __cxxabiv1::__class_type_info *Target, void **ObjectPointer) const;
|
||||
};
|
||||
|
||||
class bad_cast : public exception
|
||||
{
|
||||
public:
|
||||
bad_cast() noexcept {}
|
||||
virtual ~bad_cast() noexcept;
|
||||
virtual const char *what() const noexcept;
|
||||
};
|
||||
|
||||
class bad_typeid : public exception
|
||||
{
|
||||
public:
|
||||
bad_typeid() noexcept {}
|
||||
virtual ~bad_typeid() noexcept;
|
||||
virtual const char *what() const noexcept;
|
||||
};
|
||||
}
|
||||
|
||||
namespace __cxxabiv1
|
||||
{
|
||||
class __pbase_type_info : public std::type_info
|
||||
{
|
||||
public:
|
||||
unsigned int Flags;
|
||||
const std::type_info *Pointee;
|
||||
|
||||
explicit __pbase_type_info(const char *n, int Qualifiers, const std::type_info *Type)
|
||||
: std::type_info(n),
|
||||
Flags(Qualifiers),
|
||||
Pointee(Type)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~__pbase_type_info();
|
||||
|
||||
enum __masks
|
||||
{
|
||||
__const_mask = 0x1,
|
||||
__volatile_mask = 0x2,
|
||||
__restrict_mask = 0x4,
|
||||
__incomplete_mask = 0x8,
|
||||
__incomplete_class_mask = 0x10,
|
||||
__transaction_safe_mask = 0x20,
|
||||
__noexcept_mask = 0x40
|
||||
};
|
||||
|
||||
protected:
|
||||
__pbase_type_info(const __pbase_type_info &);
|
||||
|
||||
__pbase_type_info &operator=(const __pbase_type_info &);
|
||||
|
||||
virtual bool __do_catch(const std::type_info *ThrowType,
|
||||
void **ThrowObject,
|
||||
unsigned int Outer) const;
|
||||
|
||||
inline bool __pointer_catch(const __pbase_type_info *ThrownType,
|
||||
void **ThrowObject,
|
||||
unsigned Outer) const
|
||||
{
|
||||
return Pointee->__do_catch(ThrownType->Pointee, ThrowObject, Outer + 2);
|
||||
}
|
||||
};
|
||||
|
||||
class __pointer_type_info : public __pbase_type_info
|
||||
{
|
||||
public:
|
||||
explicit __pointer_type_info(const char *n,
|
||||
int Qualifiers,
|
||||
const std::type_info *Type)
|
||||
: __pbase_type_info(n, Qualifiers, Type) {}
|
||||
virtual ~__pointer_type_info();
|
||||
|
||||
protected:
|
||||
virtual bool __is_pointer_p() const;
|
||||
|
||||
virtual bool __pointer_catch(const __pbase_type_info *ThrowType,
|
||||
void **ThrowObject,
|
||||
unsigned Outer) const;
|
||||
};
|
||||
|
||||
/* FIXME: stub */
|
||||
class __pointer_to_member_type_info : public __pbase_type_info
|
||||
{
|
||||
};
|
||||
|
||||
class __fundamental_type_info : public std::type_info
|
||||
{
|
||||
public:
|
||||
explicit __fundamental_type_info(const char *n) : std::type_info(n) {}
|
||||
virtual ~__fundamental_type_info();
|
||||
};
|
||||
|
||||
class __base_class_type_info
|
||||
{
|
||||
public:
|
||||
const __class_type_info *BaseType;
|
||||
#ifdef __LP64__
|
||||
long long OffsetFlags;
|
||||
#else
|
||||
long OffsetFlags;
|
||||
#endif
|
||||
|
||||
enum __offset_flags_masks
|
||||
{
|
||||
__virtual_mask = 0x1,
|
||||
__public_mask = 0x2,
|
||||
__hwm_bit = 0x2,
|
||||
__offset_shift = 0x8
|
||||
};
|
||||
|
||||
bool __is_virtual_p() const
|
||||
{
|
||||
return OffsetFlags & __virtual_mask;
|
||||
}
|
||||
|
||||
bool __is_public_p() const
|
||||
{
|
||||
return OffsetFlags & __public_mask;
|
||||
}
|
||||
|
||||
ptrdiff_t __offset() const
|
||||
{
|
||||
return static_cast<ptrdiff_t>(OffsetFlags) >> __offset_shift;
|
||||
}
|
||||
};
|
||||
|
||||
class __class_type_info : public std::type_info
|
||||
{
|
||||
public:
|
||||
explicit __class_type_info(const char *n)
|
||||
: std::type_info(n) {}
|
||||
virtual ~__class_type_info();
|
||||
|
||||
enum __sub_kind
|
||||
{
|
||||
__unknown = 0,
|
||||
__not_contained,
|
||||
__contained_ambig,
|
||||
__contained_virtual_mask = __base_class_type_info::__virtual_mask,
|
||||
__contained_public_mask = __base_class_type_info::__public_mask,
|
||||
__contained_mask = 1 << __base_class_type_info::__hwm_bit,
|
||||
__contained_private = __contained_mask,
|
||||
__contained_public = __contained_mask | __contained_public_mask
|
||||
};
|
||||
|
||||
struct __upcast_result
|
||||
{
|
||||
const void *dst_ptr;
|
||||
__sub_kind part2dst;
|
||||
int src_details;
|
||||
const __class_type_info *base_type;
|
||||
|
||||
__upcast_result(int d)
|
||||
: dst_ptr(NULL),
|
||||
part2dst(__unknown),
|
||||
src_details(d),
|
||||
base_type(NULL) {}
|
||||
};
|
||||
|
||||
struct __dyncast_result
|
||||
{
|
||||
const void *dst_ptr;
|
||||
__sub_kind whole2dst;
|
||||
__sub_kind whole2src;
|
||||
__sub_kind dst2src;
|
||||
int whole_details;
|
||||
|
||||
__dyncast_result(int details_ = 0x10 /*__vmi_class_type_info::__flags_unknown_mask*/)
|
||||
: dst_ptr(NULL),
|
||||
whole2dst(__unknown),
|
||||
whole2src(__unknown),
|
||||
dst2src(__unknown),
|
||||
whole_details(details_) {}
|
||||
|
||||
protected:
|
||||
__dyncast_result(const __dyncast_result &);
|
||||
|
||||
__dyncast_result &
|
||||
operator=(const __dyncast_result &);
|
||||
};
|
||||
|
||||
virtual __sub_kind __do_find_public_src(ptrdiff_t SourceToDestination,
|
||||
const void *ObjectPointer,
|
||||
const __class_type_info *SourceType,
|
||||
const void *SubroutinePointer) const;
|
||||
|
||||
virtual bool __do_upcast(const __class_type_info *Destination,
|
||||
const void *Object,
|
||||
__upcast_result &__restrict Result) const;
|
||||
|
||||
virtual bool __do_dyncast(ptrdiff_t SourceToDestination,
|
||||
__sub_kind AccessPath,
|
||||
const __class_type_info *DestinationType,
|
||||
const void *ObjectPointer,
|
||||
const __class_type_info *SourceType,
|
||||
const void *SourcePointer,
|
||||
__dyncast_result &Result) const;
|
||||
|
||||
protected:
|
||||
virtual bool __do_upcast(const __class_type_info *DestinationType,
|
||||
void **ObjectPointer) const;
|
||||
|
||||
virtual bool __do_catch(const type_info *ThrowType,
|
||||
void **ThrowObject,
|
||||
unsigned Outer) const;
|
||||
};
|
||||
|
||||
class __vmi_class_type_info : public __class_type_info
|
||||
{
|
||||
public:
|
||||
enum __flags_masks
|
||||
{
|
||||
__non_diamond_repeat_mask = 0x1,
|
||||
__diamond_shaped_mask = 0x2,
|
||||
__flags_unknown_mask = 0x10
|
||||
};
|
||||
|
||||
virtual ~__vmi_class_type_info();
|
||||
|
||||
virtual bool __do_upcast(const __class_type_info *target, void **thrown_object) const;
|
||||
virtual void *cast_to(void *obj, const struct __class_type_info *other) const;
|
||||
};
|
||||
|
||||
class __si_class_type_info : public __class_type_info
|
||||
{
|
||||
public:
|
||||
const __class_type_info *BaseType;
|
||||
|
||||
explicit __si_class_type_info(const char *n,
|
||||
const __class_type_info *Base)
|
||||
: __class_type_info(n),
|
||||
BaseType(Base) {}
|
||||
virtual ~__si_class_type_info();
|
||||
|
||||
protected:
|
||||
__si_class_type_info(const __si_class_type_info &);
|
||||
|
||||
__si_class_type_info &operator=(const __si_class_type_info &);
|
||||
|
||||
virtual bool __do_dyncast(ptrdiff_t SourceToDestination, __sub_kind AccessPath,
|
||||
const __class_type_info *DestinationType, const void *ObjectPointer,
|
||||
const __class_type_info *SourceType, const void *SourcePointer,
|
||||
__dyncast_result &Result) const;
|
||||
|
||||
virtual __sub_kind __do_find_public_src(ptrdiff_t SourceToDestination,
|
||||
const void *ObjectPointer,
|
||||
const __class_type_info *SourceType,
|
||||
const void *SubroutinePointer) const;
|
||||
|
||||
virtual bool __do_upcast(const __class_type_info *Destination,
|
||||
const void *Object,
|
||||
__upcast_result &__restrict Result) const;
|
||||
};
|
||||
|
||||
static const __class_type_info *const nonvirtual_base_type = static_cast<const __class_type_info *>(0) + 1;
|
||||
}
|
||||
|
||||
#endif // !__FENNIX_KERNEL_TYPEINFO_H__
|
26
Kernel/include_std/unistd.h
Normal file
26
Kernel/include_std/unistd.h
Normal file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifndef _UNISTD_H
|
||||
#define _UNISTD_H
|
||||
|
||||
#include <types.h>
|
||||
|
||||
#define _SC_PAGESIZE 30
|
||||
#define _SC_PAGE_SIZE _SC_PAGESIZE
|
||||
|
||||
#endif // !_UNISTD_H
|
1280
Kernel/include_std/unordered_map
Normal file
1280
Kernel/include_std/unordered_map
Normal file
File diff suppressed because it is too large
Load Diff
252
Kernel/include_std/utility
Normal file
252
Kernel/include_std/utility
Normal file
@ -0,0 +1,252 @@
|
||||
/*
|
||||
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 <type_traits>
|
||||
#include <algorithm>
|
||||
#include <tuple>
|
||||
|
||||
namespace std
|
||||
{
|
||||
struct piecewise_construct_t
|
||||
{
|
||||
explicit piecewise_construct_t() = default;
|
||||
};
|
||||
|
||||
inline constexpr std::piecewise_construct_t piecewise_construct{};
|
||||
|
||||
template <typename T>
|
||||
typename std::remove_reference<T>::type &&move(T &&arg)
|
||||
{
|
||||
return static_cast<typename std::remove_reference<T>::type &&>(arg);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void __utility_swap(T &a, T &b)
|
||||
{
|
||||
T temp = std::move(a);
|
||||
a = std::move(b);
|
||||
b = std::move(temp);
|
||||
}
|
||||
|
||||
template <class T, T... Ints>
|
||||
class integer_sequence
|
||||
{
|
||||
public:
|
||||
typedef T value_type;
|
||||
|
||||
static constexpr std::size_t size() noexcept { return sizeof...(Ints); }
|
||||
};
|
||||
|
||||
template <std::size_t... Ints>
|
||||
using index_sequence = std::integer_sequence<std::size_t, Ints...>;
|
||||
|
||||
template <class T, T N>
|
||||
using make_integer_sequence = std::integer_sequence<T, N>;
|
||||
|
||||
template <std::size_t N>
|
||||
using make_index_sequence = std::make_integer_sequence<std::size_t, N>;
|
||||
|
||||
template <class... T>
|
||||
using index_sequence_for = std::make_index_sequence<sizeof...(T)>;
|
||||
|
||||
template <class T>
|
||||
constexpr T &&forward(std::remove_reference_t<T> &t) noexcept
|
||||
{
|
||||
return static_cast<T &&>(t);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
constexpr T &&forward(std::remove_reference_t<T> &&t) noexcept
|
||||
{
|
||||
static_assert(!std::is_lvalue_reference<T>::value, "Can't forward an rvalue as an lvalue.");
|
||||
return static_cast<T &&>(t);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2>
|
||||
struct pair
|
||||
{
|
||||
typedef T1 first_type;
|
||||
typedef T2 second_type;
|
||||
|
||||
first_type first;
|
||||
second_type second;
|
||||
|
||||
template <typename U1 = T1,
|
||||
typename U2 = T2,
|
||||
typename std::enable_if<std::is_default_constructible<U1>::value &&
|
||||
std::is_default_constructible<U2>::value,
|
||||
int>::type = true>
|
||||
constexpr pair()
|
||||
: first(),
|
||||
second()
|
||||
{
|
||||
}
|
||||
|
||||
template <typename U1 = T1,
|
||||
typename U2 = T2,
|
||||
typename std::enable_if<!std::is_default_constructible<U1>::value ||
|
||||
!std::is_default_constructible<U2>::value,
|
||||
int>::type = false>
|
||||
explicit constexpr pair()
|
||||
: first(),
|
||||
second()
|
||||
{
|
||||
}
|
||||
|
||||
template <typename U1 = T1,
|
||||
typename U2 = T2,
|
||||
typename std::enable_if<std::is_copy_constructible<U1>::value &&
|
||||
std::is_copy_constructible<U2>::value,
|
||||
int>::type = true>
|
||||
constexpr pair(const T1 &x, const T2 &y)
|
||||
: first(x),
|
||||
second(y)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename U1 = T1,
|
||||
typename U2 = T2,
|
||||
typename std::enable_if<!std::is_copy_constructible<U1>::value ||
|
||||
!std::is_copy_constructible<U2>::value,
|
||||
int>::type = false>
|
||||
explicit constexpr pair(const T1 &x, const T2 &y)
|
||||
: first(x),
|
||||
second(y)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename U1 = T1,
|
||||
typename U2 = T2,
|
||||
typename std::enable_if<std::is_move_constructible<U1>::value &&
|
||||
std::is_move_constructible<U2>::value,
|
||||
int>::type = true>
|
||||
constexpr pair(U1 &&x, U2 &&y)
|
||||
: first(std::forward<U1>(x)),
|
||||
second(std::forward<U2>(y))
|
||||
{
|
||||
}
|
||||
|
||||
template <typename U1 = T1,
|
||||
typename U2 = T2,
|
||||
typename std::enable_if<!std::is_move_constructible<U1>::value ||
|
||||
!std::is_move_constructible<U2>::value,
|
||||
int>::type = false>
|
||||
explicit constexpr pair(T1 &&x, T2 &&y)
|
||||
: first(std::forward<T1>(x)),
|
||||
second(std::forward<T2>(y)){};
|
||||
|
||||
template <typename U1 = T1,
|
||||
typename U2 = T2,
|
||||
typename std::enable_if<std::is_copy_constructible<U1>::value &&
|
||||
std::is_copy_constructible<U2>::value,
|
||||
int>::type = true>
|
||||
constexpr pair(const pair<U1, U2> &p)
|
||||
: first(p.first),
|
||||
second(p.second)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename U1 = T1,
|
||||
typename U2 = T2,
|
||||
typename std::enable_if<!std::is_copy_constructible<U1>::value ||
|
||||
!std::is_copy_constructible<U2>::value,
|
||||
int>::type = false>
|
||||
explicit constexpr pair(const pair<U1, U2> &p)
|
||||
: first(p.first),
|
||||
second(p.second)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename U1 = T1,
|
||||
typename U2 = T2,
|
||||
typename std::enable_if<std::is_move_constructible<U1>::value &&
|
||||
std::is_move_constructible<U2>::value,
|
||||
int>::type = true>
|
||||
constexpr pair(pair<U1, U2> &&p)
|
||||
: first(std::forward<U1>(p.first)),
|
||||
second(std::forward<U2>(p.second))
|
||||
{
|
||||
}
|
||||
|
||||
template <typename U1 = T1,
|
||||
typename U2 = T2,
|
||||
typename std::enable_if<!std::is_move_constructible<U1>::value ||
|
||||
!std::is_move_constructible<U2>::value,
|
||||
int>::type = false>
|
||||
explicit constexpr pair(pair<U1, U2> &&p)
|
||||
: first(std::forward<U1>(p.first)),
|
||||
second(std::forward<U2>(p.second))
|
||||
{
|
||||
}
|
||||
|
||||
template <class... Args1, class... Args2>
|
||||
constexpr pair(std::piecewise_construct_t, std::tuple<Args1...> first_args, std::tuple<Args2...> second_args)
|
||||
: pair(first_args, second_args, std::index_sequence_for<Args1...>(), std::index_sequence_for<Args2...>())
|
||||
{
|
||||
}
|
||||
|
||||
pair(const pair &p) = default;
|
||||
pair(pair &&p) = default;
|
||||
|
||||
constexpr pair &operator=(const pair &other)
|
||||
{
|
||||
first = other.first;
|
||||
second = other.second;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class U1, class U2>
|
||||
constexpr pair &operator=(const pair<U1, U2> &other)
|
||||
{
|
||||
first = other.first;
|
||||
second = other.second;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr pair &operator=(pair &&other) noexcept(std::is_nothrow_move_assignable<T1>::value && std::is_nothrow_move_assignable<T2>::value)
|
||||
{
|
||||
first = std::move(other.first);
|
||||
second = std::move(other.second);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class U1, class U2>
|
||||
constexpr pair &operator=(pair<U1, U2> &&p)
|
||||
{
|
||||
first = std::forward<U1>(p.first);
|
||||
second = std::forward<U2>(p.second);
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr void swap(pair &other) noexcept(std::is_nothrow_swappable_v<first_type> && std::is_nothrow_swappable_v<second_type>)
|
||||
{
|
||||
__utility_swap(first, other.first);
|
||||
__utility_swap(second, other.second);
|
||||
}
|
||||
};
|
||||
|
||||
template <class T1, class T2>
|
||||
std::pair<typename std::decay<T1>::type, typename std::decay<T2>::type> make_pair(T1 &&t, T2 &&u)
|
||||
{
|
||||
typedef typename std::decay<T1>::type first_type;
|
||||
typedef typename std::decay<T2>::type second_type;
|
||||
typedef pair<first_type, second_type> pair_type;
|
||||
return pair_type(std::forward<T1>(t), std::forward<T2>(u));
|
||||
}
|
||||
}
|
34
Kernel/include_std/utsname.h
Normal file
34
Kernel/include_std/utsname.h
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifndef __FENNIX_KERNEL_UTSNAME_H__
|
||||
#define __FENNIX_KERNEL_UTSNAME_H__
|
||||
|
||||
#include <types.h>
|
||||
|
||||
#define _UTSNAME_LENGTH 65
|
||||
|
||||
struct utsname
|
||||
{
|
||||
char sysname[_UTSNAME_LENGTH];
|
||||
char nodename[_UTSNAME_LENGTH];
|
||||
char release[_UTSNAME_LENGTH];
|
||||
char version[_UTSNAME_LENGTH];
|
||||
char machine[_UTSNAME_LENGTH];
|
||||
};
|
||||
|
||||
#endif // !__FENNIX_KERNEL_UTSNAME_H__
|
1023
Kernel/include_std/vector
Normal file
1023
Kernel/include_std/vector
Normal file
File diff suppressed because it is too large
Load Diff
21
Kernel/include_std/wchar.h
Normal file
21
Kernel/include_std/wchar.h
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifndef _WCHAR_H
|
||||
#define _WCHAR_H
|
||||
|
||||
#endif // !_WCHAR_H
|
Reference in New Issue
Block a user