- Fixed some circular includes

- Documentation
 - File Declaration, TODO: Implementation
This commit is contained in:
2025-07-07 21:13:07 -04:00
parent 17d8218124
commit 2573de0904
24 changed files with 445 additions and 154 deletions

View File

@@ -76,7 +76,7 @@ add_library(fennec STATIC
include/fennec/memory/new.h source/memory/new.cpp
include/fennec/memory/allocator.h
include/fennec/memory/memory.h
include/fennec/memory/common.h
include/fennec/memory/pointers.h
include/fennec/memory/ptr_traits.h
@@ -124,6 +124,9 @@ add_library(fennec STATIC
include/fennec/fproc/strings/cstring.h
include/fennec/fproc/strings/locale.h
include/fennec/fproc/io/file.h
source/fproc/io/file.cpp
include/fennec/fproc/filesystem/path.h
include/fennec/memory/memory.h
)
# add metaprogramming templates as a dependency and also force documentation to be generated when fennec is compiled
@@ -182,7 +185,7 @@ if(DOXYGEN_FOUND)
# Target for cleaning docs
add_custom_target(fennecdocs-clean ALL
COMMAND ${CMAKE_COMMAND} -E remove -f "${PROJECT_SOURCE_DIR}/docs/"
COMMAND ${CMAKE_COMMAND} -E remove -f "${PROJECT_SOURCE_DIR}/docs"
COMMENT "Cleaning Doxygen Documentation"
VERBATIM)
else()

View File

@@ -5,7 +5,6 @@
<navindex>
<tab type="mainpage" visible="yes" title=""/>
<tab type="pages" visible="yes" title="" intro=""/>
<tab type=""
<tab type="topics" visible="yes" title="" intro=""/>
<tab type="modules" visible="yes" title="" intro="">
<tab type="modulelist" visible="yes" title="" intro=""/>

View File

@@ -943,8 +943,8 @@ WARN_LOGFILE =
# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
# Note: If this tag is empty the current directory is searched.
INPUT = "/home/medusa/Documents/Work/Personal/fennec/include/" \
"/home/medusa/Documents/Work/Personal/fennec/source/" \
INPUT = "/home/medusa/Documents/Work/Personal/fennec/include" \
"/home/medusa/Documents/Work/Personal/fennec/source" \
"/home/medusa/Documents/Work/Personal/fennec/README.md"
# This tag can be used to specify the character encoding of the source files
@@ -1079,7 +1079,7 @@ EXCLUDE_SYMBOLS =
# that contain example code fragments that are included (see the \include
# command).
EXAMPLE_PATH = "/home/medusa/Documents/Work/Personal/fennec"
EXAMPLE_PATH = "/home/medusa/Documents/Work/Personal/fennec/examples"
# If the value of the EXAMPLE_PATH tag contains directories, you can use the
# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and

View File

@@ -943,8 +943,8 @@ WARN_LOGFILE =
# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
# Note: If this tag is empty the current directory is searched.
INPUT = "@PROJECT_SOURCE_DIR@/include/" \
"@PROJECT_SOURCE_DIR@/source/" \
INPUT = "@PROJECT_SOURCE_DIR@/include" \
"@PROJECT_SOURCE_DIR@/source" \
"@PROJECT_SOURCE_DIR@/README.md"
# This tag can be used to specify the character encoding of the source files
@@ -1079,7 +1079,7 @@ EXCLUDE_SYMBOLS =
# that contain example code fragments that are included (see the \include
# command).
EXAMPLE_PATH = "@PROJECT_SOURCE_DIR@"
EXAMPLE_PATH = "@PROJECT_SOURCE_DIR@/examples"
# If the value of the EXAMPLE_PATH tag contains directories, you can use the
# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and

View File

@@ -18,7 +18,7 @@
///
/// \file array.h
/// \brief fennec::array definition & implementation
/// \brief statically allocated array wrapper
///
///
/// \details

View File

@@ -18,7 +18,7 @@
///
/// \file dynarray.h
/// \brief fennec::array definition & implementation
/// \brief dynamically allocated array wrapper
///
///
/// \details
@@ -78,10 +78,10 @@ public:
}
template<typename...ArgsT>
dynarray(size_t n, ArgsT...args)
dynarray(size_t n, ArgsT&&...args)
{
element_t* addr = _alloc.data();
for(; n > 0; --n, ++addr) { fennec::construct(addr, args...); }
for(; n > 0; --n, ++addr) { fennec::construct(addr, fennec::forward<ArgsT>(args)...); }
}
~dynarray()
@@ -94,8 +94,8 @@ public:
size_t capacity() const { return _alloc.capacity(); }
TypeT& operator[](size_t i) { return _alloc.data()[i]; }
const TypeT& operator[](size_t i) const { return _alloc.data()[i]; }
TypeT& operator[](size_t i) { assertd(i < _size, "Array Out of Bounds"); return _alloc.data()[i]; }
const TypeT& operator[](size_t i) const { assertd(i < _size, "Array Out of Bounds"); return _alloc.data()[i]; }
void insert(size_t i, const TypeT& val)
{
@@ -103,7 +103,7 @@ public:
if(_size == capacity()) _grow();
// Move the data if we are not inserting at the end of the array
if((i = fennec::min(i, _size) < _size) {
if((i = min(i, _size)) < _size) {
fennec::memmove(
_alloc.data() + i
, _alloc.data() + i + 1
@@ -120,7 +120,7 @@ public:
if(_size == capacity()) _grow();
// Move the data if we are not inserting at the end of the array
if((i = fennec::min(i, _size) < _size) {
if((i = min(i, _size)) < _size) {
fennec::memmove(
_alloc.data() + i
, _alloc.data() + i + 1
@@ -128,17 +128,17 @@ public:
}
// Insert the element
fennec::construct(_alloc.data() + i, fennec::forward(val));
fennec::construct(_alloc.data() + i, fennec::forward<TypeT>(val));
}
template<typename...ArgsT>
void emplace(size_t i, ArgsT...args)
void emplace(size_t i, ArgsT&&...args)
{
// Grow if the size has reached the capacity of the allocation
if(_size == capacity()) _grow();
// Move the data if we are not inserting at the end of the array
if((i = fennec::min(i, _size) < _size) {
if((i = min(i, _size)) < _size) {
fennec::memmove(
_alloc.data() + i
, _alloc.data() + i + 1
@@ -149,10 +149,10 @@ public:
fennec::construct(_alloc.data() + i, fennec::forward<ArgsT>(args)...);
}
void push_back(const TypeT& val) { insert(_size, val); }
void push_back(TypeT&& val) { insert(_size, fennec::forward(val)); }
void push_back(const TypeT& val) { dynarray::insert(_size, val); }
void push_back(TypeT&& val) { dynarray::insert(_size, fennec::forward<TypeT>(val)); }
template<typename...ArgsT> void emplace_back(ArgsT...args) { emplace(_size, fennec::forward<ArgsT>(args)...); }
template<typename...ArgsT> void emplace_back(ArgsT...args) { dynarray::emplace(_size, fennec::forward<ArgsT>(args)...); }
private:
void _grow() const { _alloc.reallocate(_alloc.capacity() * 2); }

View File

@@ -0,0 +1,32 @@
// =====================================================================================================================
// fennec, a free and open source game engine
// Copyright © 2025 Medusa Slockbower
//
// This program 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.
//
// This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
// =====================================================================================================================
#ifndef FENNEC_FPROC_FILESYSTEM_PATH_H
#define FENNEC_FPROC_FILESYSTEM_PATH_H
namespace fennec
{
struct path
{
};
}
#endif // FENNEC_FPROC_FILESYSTEM_PATH_H

View File

@@ -0,0 +1,36 @@
// =====================================================================================================================
// fennec, a free and open source game engine
// Copyright © 2025 Medusa Slockbower
//
// This program 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.
//
// This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
// =====================================================================================================================
#ifndef FENNEC_FPROC_STRINGS_DETAIL_CTYPE_H
#define FENNEC_FPROC_STRINGS_DETAIL_CTYPE_H
#if _MSC_VER
#pragma warning(push)
#pragma warning(disable:4117)
#endif
#pragma push_macro("__cplusplus")
#undef __cplusplus
#include <stdio.h>
#pragma pop_macro("__cplusplus")
#if _MSC_VER
#pragma warning(pop)
#endif
#endif // FENNEC_FPROC_STRINGS_DETAIL_CTYPE_H

View File

@@ -20,9 +20,9 @@
#define FENNEC_FPROC_IO_FILE_H
#include <fennec/fproc/strings/cstring.h>
#include <fennec/fproc/strings/string.h>
struct FILE;
struct stat;
namespace fennec
{
@@ -33,10 +33,42 @@ public:
file();
~file();
file(const cstring& filename, const cstring& mode);
file(const string& filename, const cstring& mode);
file(const file&) = delete;
// File Access =========================================================================================================
void open(const cstring& filename, const cstring& mode);
void open(const string& filename, const cstring& mode);
void close();
void commit();
// File Operations =====================================================================================================
void erase();
void rename(const cstring& str);
void rename(const string& str);
// File Positioning ====================================================================================================
size_t get_pos();
void set_pos(size_t i);
void rewind();
// Error Handling ======================================================================================================
bool check_error();
string get_error();
void clear_error();
//
private:
FILE* _handle;

View File

@@ -118,9 +118,11 @@ public:
str._const = true;
}
// TODO: Document
constexpr cstring(const cstring&) = delete;
constexpr ~cstring() = default;
// TODO: Document
template<size_t n>
constexpr cstring& operator=(char(&str)[n]) {
assert(_str[n - 1] == '\0', "Invalid NTBS.");
@@ -128,6 +130,7 @@ public:
return *this;
}
// TODO: Document
template<size_t n>
constexpr cstring& operator=(const char(&str)[n]) {
assert(str[n - 1] == '\0', "Invalid NTBS.");
@@ -135,6 +138,7 @@ public:
return *this;
}
// TODO: Document
constexpr cstring& operator=(cstring&& str) noexcept
{
_cstr = str._cstr; str._cstr = nullptr;

View File

@@ -24,17 +24,23 @@
#include <fennec/lang/assert.h>
#include <fennec/memory/allocator.h>
#include <fennec/memory/memory.h>
#include <fennec/memory/common.h>
namespace fennec
{
// Forward def
template<typename AllocT = allocator<char>> struct _string;
// Alias for default allocator
using string = _string<>;
///
/// \brief Struct for wrapping c-style strings
///
/// \details behaviour guarantees that the underlying string is null-terminated
template<typename AllocT = allocator<char>>
struct string
struct _string
{
public:
using alloc_t = allocation<char, AllocT>;
@@ -44,7 +50,7 @@ public:
///
/// \brief Default Constructor, initializes empty string
constexpr string()
constexpr _string()
: _str()
{ }
@@ -53,8 +59,8 @@ public:
/// \param n the number of characters
///
/// \details adds additional character for null termination.
constexpr string(size_t n)
: string('\0', n)
constexpr _string(size_t n)
: _string('\0', n)
{ }
///
@@ -63,7 +69,7 @@ public:
/// \param n the number of characters
///
/// \details adds additional character for null termination.
constexpr string(char c, size_t n)
constexpr _string(char c, size_t n)
: _str(n + 1)
{ fennec::memset(_str, c, n); _str[n] = '\0'; }
@@ -74,24 +80,24 @@ public:
///
/// \details adds additional character for null termination. Ignores whether str is null-terminated.
/// This constructor makes the assumption that `len` is the intended number of characters.
constexpr string(const cstring& str)
constexpr _string(const cstring& str)
: _str(str, str.size() + 1)
{ _str[str.size()] = '\0'; }
///
/// \brief String Copy Constructor
/// \param str the string to copy
constexpr string(const string& str)
: string(str, str.size() - 1)
constexpr _string(const string& str)
: _string(str, str.size() - 1)
{ }
constexpr string(string&& str) noexcept
constexpr _string(_string&& str) noexcept
: _str(fennec::move(str._str))
{ }
///
/// \brief String Destructor, cleans up the underlying allocation
constexpr ~string() = default; // allocation cleans up itself
constexpr ~_string() = default; // allocation cleans up itself
// Properties ==========================================================================================================

View File

@@ -16,9 +16,49 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// =====================================================================================================================
///
/// \file assert.h
/// \brief \ref fennec_lang_assert
///
///
/// \details
/// \author Medusa Slockbower
///
/// \copyright Copyright © 2025 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html))
///
///
#ifndef FENNEC_LANG_ASSERT_H
#define FENNEC_LANG_ASSERT_H
///
/// \page fennec_lang_assert Assertions
///
/// \code #include <fennec/lang/assert.h> \endcode
///
/// This header contains macros for making assertions about code behaviour.
///
/// fennec defines the following assert implementations:
///
/// <table width="100%" class="fieldtable" id="table_fennec_lang_bits">
/// <tr><th style="vertical-align: top">Syntax
/// <th style="vertical-align: top">Description
/// <tr><td width="50%" style="vertical-align: top"> <br>
/// assert(expr, desc)
/// <td width="50%" style="vertical-align: top">
/// Make an assertion with expression `expr` and provide a description `desc`.
///
/// <tr><td width="50%" style="vertical-align: top"> <br>
/// assertd(expr, desc)
/// <td width="50%" style="vertical-align: top">
/// Make an assertion, ***only in debug mode***, with expression `expr` and provide a description `desc`.
/// This should be used when the branching caused by `assert` would hinder performance in release mode.
///
/// </table>
///
///
///
#if _MSC_VER
#define __PRETTY_FUNCTION__ __FUNCSIG__
#endif

View File

@@ -80,7 +80,7 @@
///
#include <fennec/lang/intrinsics.h>
#include <fennec/memory/memory.h>
#include <fennec/memory/common.h>
#include <fennec/lang/detail/__bits.h>
namespace fennec
@@ -138,9 +138,11 @@ constexpr void* bit_and(void* arr, const void* mask, size_t n)
/// \brief Safe version of fennec::bit_and
///
/// \details Safe version of fennec::bit_and
/// \copydetails fennec::bit_and
/// \param arr the array of bytes to modify
/// \param n0 the size of arr in bytes
/// \param mask the mask to and against arr
/// \param n1 the size of mask in bytes
/// \returns the pointer arr
constexpr void* bit_and_s(void* arr, size_t n0, const void* mask, size_t n1)
{ return bit_and(arr, mask, n0 < n1 ? n0 : n1); }
@@ -175,9 +177,11 @@ constexpr void* bit_or(void* arr, const void* mask, size_t n)
/// \brief Safe version of fennec::bit_or
///
/// \details Safe version of fennec::bit_or
/// \copydetails fennec::bit_or
/// \param arr the array of bytes to modify
/// \param n0 the size of arr in bytes
/// \param mask the mask to or against arr
/// \param n1 the size of mask in bytes
/// \returns the pointer arr
constexpr void* bit_or_s(void* arr, size_t n0, const void* mask, size_t n1)
{ return bit_or(arr, mask, n0 < n1 ? n0 : n1); }
@@ -212,9 +216,11 @@ constexpr void* bit_xor(void* arr, const void* mask, size_t n)
/// \brief Safe version of fennec::bit_xor
///
/// \details Safe version of fennec::bit_xor
/// \copydetails fennec::bit_xor
/// \param arr the array of bytes to modify
/// \param n0 the size of arr in bytes
/// \param mask the mask to or against arr
/// \param n1 the size of mask in bytes
/// \returns the pointer arr
constexpr void* bit_xor_s(void* arr, size_t n0, const void* mask, size_t n1)
{ return bit_xor(arr, mask, n0 < n1 ? n0 : n1); }

View File

@@ -44,8 +44,8 @@
/// <tr><th style="vertical-align: top">Syntax
/// <th style="vertical-align: top">Description
/// <tr><td width="50%" style="vertical-align: top"> <br>
/// \ref fennec::conditional "typename conditional<bool_t B, TrueT, FalseT>::type"<br>
/// \ref fennec::conditional_t "conditional_t<bool_t B, TrueT, FalseT>"
/// \ref fennec::conditional "typename conditional<bool B, TrueT, FalseT>::type"<br>
/// \ref fennec::conditional_t "conditional_t<bool B, TrueT, FalseT>"
/// <td width="50%" style="vertical-align: top">
/// \copydetails fennec::conditional
///
@@ -56,8 +56,8 @@
/// \copydetails fennec::detect
///
/// <tr><td width="50%" style="vertical-align: top"> <br>
/// \ref fennec::enable_if "typename enable_if<bool_t B, TypeT>::type"<br>
/// \ref fennec::enable_if_t "enable_if_t<bool_t B, TypeT>"
/// \ref fennec::enable_if "typename enable_if<bool B, TypeT>::type"<br>
/// \ref fennec::enable_if_t "enable_if_t<bool B, TypeT>"
/// <td width="50%" style="vertical-align: top">
/// \copydetails fennec::enable_if
/// </table>
@@ -65,7 +65,6 @@
///
#include <fennec/lang/type_transforms.h>
#include <fennec/lang/types.h>
namespace fennec
{
@@ -80,13 +79,13 @@ namespace fennec
/// \tparam B the value of the condition
/// \tparam TrueT type to use when \f$B == true\f$
/// \tparam FalseT type to use when \f$B == false\f$
template<bool_t B, typename TrueT, typename FalseT>
template<bool B, typename TrueT, typename FalseT>
struct conditional;
///
/// \brief Shorthand for ```typename conditional<ConditionV, TrueT, FalseT>::type```
template<bool_t B, typename TrueT, typename FalseT>
template<bool B, typename TrueT, typename FalseT>
using conditional_t
= typename conditional<B, TrueT, FalseT>::type;
@@ -153,12 +152,12 @@ struct detect<DefaultT, DetectT, ArgsT...>
///
/// \tparam B A boolean value
/// \tparam T The type to conditionally define
template<bool_t B, typename T = void>
template<bool B, typename T = void>
struct enable_if {};
///
/// \brief Shorthand for ```typename enable_if<B, T>::type```
template<bool_t B, typename T = void>
template<bool B, typename T = void>
using enable_if_t = typename enable_if<B, T>::type;
// true case

View File

@@ -49,12 +49,12 @@
/// \copydetails fennec::integral_constant
///
/// <tr><td width="50%" style="vertical-align: top"> <br>
/// \ref fennec::bool_constant "bool_constant<bool_t ValueV>::type"<br>
/// \ref fennec::bool_constant "bool_constant<bool ValueV>::type"<br>
/// <td width="50%" style="vertical-align: top">
/// \copydetails fennec::bool_constant
///
/// <tr><td width="50%" style="vertical-align: top"> <br>
/// \ref fennec::bool_constant "bool_constant<bool_t ValueV>::type"<br>
/// \ref fennec::bool_constant "bool_constant<bool ValueV>::type"<br>
/// <td width="50%" style="vertical-align: top">
/// \copydetails fennec::bool_constant
///
@@ -90,7 +90,7 @@ template<typename IntT, IntT ValueV> struct integral_constant
///
/// \details
/// \tparam ValueV value of the constant
template<bool_t ValueV>
template<bool ValueV>
struct bool_constant
: integral_constant<bool_t, ValueV> {};

View File

@@ -31,9 +31,8 @@
#ifndef FENNEC_LANG_H
#define FENNEC_LANG_H
#include <fennec/lang/assert.h>
#include <fennec/lang/bits.h>
#include <fennec/lang/intrinsics.h>
#include <fennec/lang/limits.h>
#include <fennec/lang/types.h>
#include <fennec/lang/utility.h>
@@ -42,6 +41,7 @@
///
/// This library implements the parts of the C++ stdlib that relate to built-in types and metaprogramming.
///
/// - \subpage fennec_lang_assert
/// - \subpage fennec_lang_bit_manipulation
/// - \subpage fennec_lang_intrinsics
/// - \subpage fennec_lang_limits

View File

@@ -92,10 +92,10 @@
/// \copydetails fennec::is_same
///
/// <tr><td width="50%" style="vertical-align: top"> <br>
/// \ref fennec::can_convert "can_convert<TypeT0, TypeT1>::value"<br>
/// \ref fennec::can_convert_v "can_convert_v<TypeT>"
/// \ref fennec::is_convertible "is_convertible<TypeT0, TypeT1>::value"<br>
/// \ref fennec::is_convertible_v "is_convertible_v<TypeT>"
/// <td width="50%" style="vertical-align: top">
/// \copydetails fennec::can_convert
/// \copydetails fennec::is_convertible
///
/// <tr><td width="50%" style="vertical-align: top"> <br>
/// \ref fennec::is_constructible "is_constructible<ClassT, ArgsT...>::value"<br>
@@ -334,8 +334,8 @@ template<typename FromT, typename ToT> struct is_convertible
/// \brief shorthand for `can_convert<TypeT0, TypeT1>::value`
/// \param FromT First type
/// \param ToT Second type
template<typename FromT, typename ToT> using is_convertible_v
= typename is_convertible<FromT, ToT>::type;
template<typename FromT, typename ToT> constexpr bool_t is_convertible_v
= is_convertible<FromT, ToT>{};
// fennec::is_constructible ===============================================================================================

View File

@@ -34,6 +34,8 @@
///
/// \page fennec_lang_types Types
///
/// \code #include <fennec/lang/types.h> \endcode
///
/// \brief This header contains definitions for the built-in types of the C++ language.
///
/// <table width="100%" class="fieldtable" id="table_fennec_lang_types">

View File

@@ -1,4 +1,4 @@
// =====================================================================================================================
2// =====================================================================================================================
// fennec, a free and open source game engine
// Copyright (C) 2025 Medusa Slockbower
//
@@ -16,20 +16,39 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// =====================================================================================================================
///
/// \file allocator.h
/// \brief This header contains structures and classes related to allocating blocks of memory
///
///
/// \details
/// \author Medusa Slockbower
///
/// \copyright Copyright © 2025 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html))
///
///
#ifndef FENNEC_MEMORY_ALLOCATOR_H
#define FENNEC_MEMORY_ALLOCATOR_H
#include <fennec/memory/ptr_traits.h>
#include <fennec/lang/conditional_types.h>
#include <fennec/lang/numeric_transforms.h>
#include <fennec/lang/types.h>
#include <fennec/lang/type_traits.h>
#include <fennec/math/common.h>
namespace fennec
{
///
/// \brief Helper structure for obtaining traits of an allocator class
/// \tparam Alloc The allocator class to analyze
template<class Alloc>
struct allocator_traits
{
@@ -158,14 +177,14 @@ public:
///
/// \brief Container to hold an allocation
/// \brief Container to hold a memory allocation
/// \tparam T The data type of the allocation
///
/// \details This simply acts as a proxy for allocating memory. It does not call any constructors or
/// initialize any values as if they were the provided data type. Any operations present work
/// only on individual bytes.
template<typename T, class AllocT>
class allocation
struct allocation
{
public:
/// \brief alias for the allocator type

View File

@@ -0,0 +1,127 @@
// =====================================================================================================================
// fennec, a free and open source game engine
// Copyright (C) 2025 Medusa Slockbower
//
// This program 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.
//
// This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
// =====================================================================================================================
///
/// \file common.h
/// \brief This header contains functions related to analyzing, modifying or copying buffers interpreted as bytes
///
///
/// \details
/// \author Medusa Slockbower
///
/// \copyright Copyright © 2025 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html))
///
///
#ifndef FENNEC_MEMORY_H
#define FENNEC_MEMORY_H
#include <fennec/lang/type_traits.h>
#include <fennec/memory/detail/__string.h>
namespace fennec
{
///
/// \brief Returns the address of an object regardless of whether the `&` operators is implemented.
/// \tparam TypeT The type of the objects
/// \param obj The object to find the address of
/// \return The true address of the
template<typename TypeT>
constexpr TypeT* addressof(TypeT& obj) { return FENNEC_BUILTIN_ADDRESSOF(obj); }
///
/// \brief Finds the first occurence of ```static_cast<uint8_t>(ch)``` in the first \f$n\f$ bytes
/// \param arr Pointer to the object, interpreted as an array of bytes
/// \param ch The byte to search for
/// \param n The number of bytes to search
/// \returns A pointer to the location of \f$ch\f$, otherwise \f$nullptr\f$ if \f$ch\f$ is not found.
using ::memchr;
using ::wmemchr;
///
/// \brief Compares the bytes of \f$lhs\f$ with \f$rhs\f$.
/// \param lhs The first object, interpreted as an array of bytes
/// \param rhs The second object, interpreted as an array of bytes
/// \param n The number of bytes to parse
/// \returns \f$0\f$ if the first \f$n\f$ bytes of \f$lhs\f$ and \f$rhs\f$ are equivalent. Otherwise, returns \f$1\f$
/// for the first byte \f$b\f$ where \f$lhs[b] > \f$ rhs[b]\f$, and \f$-1\f$ for \f$
using ::memcmp;
using ::wmemcmp;
///
/// \brief Safe version of memcmp
/// \copydoc fennec::memcmp
/// \param n0 The size, in bytes, of lhs
/// \param n1 The size, in bytes, of rhs
constexpr int memcmp_s(const void* lhs, size_t n0, const void* rhs, size_t n1)
{ return memcmp(lhs, rhs, n0 < n1 ? n0 : n1); }
///
/// \brief Copies the first \f$n\f$ bytes of \f$src\f$ to \f$dst\f$.
/// \param dst The destination object, interpreted as an array of bytes
/// \param src The source object, interpreted as an array of bytes
/// \param n The number of bytes to copy
/// \returns \f$dst\f$
///
/// \details memcpy does not do any checking for whether \f$dst\f$ and \f$src\f$ overlap. Let \f$k\f$ be the number of
/// bytes of which \f$dst\f$ and \f$src\f$. If \f$k > 0 & src < dst\f$ then the first \f$k\f$ elements of
/// \f$src\f$ will be repeated in \f$dst\f$ with a period of \f$k\f$.
///
/// A full mathematical proof of this function is possible in Set Theory.
using ::memcpy;
using ::wmemcpy;
///
/// \brief Safe version of memcpy
/// \copydoc fennec::memcpy
/// \param n0 The size, in bytes, of dst
/// \param n1 The size, in bytes, of src
constexpr void* memcpy_s(void* dst, size_t n0, const void* src, size_t n1)
{ return memcpy(dst, src, n0 < n1 ? n0 : n1); }
///
/// \brief Copies the first \f$n\f$ bytes of \f$src\f$ to \f$dst\f$, with overlap correction..
/// \param dst The destination object, interpreted as an array of bytes
/// \param src The source object, interpreted as an array of bytes
/// \param n The number of bytes to copy
/// \returns \f$dst\f$
using ::memmove;
using ::wmemmove;
///
/// \brief Safe version of memmove
/// \copydoc fennec::memmove
/// \param n0 The size, in bytes, of dst
/// \param n1 The size, in bytes, of src
constexpr void* memmove_s(void* dst, size_t n0, const void* src, size_t n1)
{ return memmove(dst, src, n0 < n1 ? n0 : n1); }
///
/// \brief Sets all bytes of \f$dst\f$ to \f$ch\f$, interpreted as an \f$uint8_t\f$
/// \param dst The destination object, interpreted as an array of bytes
/// \param ch The value, interpreted as an \f$uint8_t\f$
/// \param n The number of bytes to set
/// \returns \f$dst\f$
using ::memset;
using ::wmemset;
}
#endif // FENNEC_MEMORY_H

View File

@@ -1,6 +1,6 @@
// =====================================================================================================================
// fennec, a free and open source game engine
// Copyright (C) 2025 Medusa Slockbower
// Copyright © 2025 Medusa Slockbower
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@@ -16,100 +16,36 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// =====================================================================================================================
///
/// \file memory.h
/// \brief \ref
///
///
/// \details
/// \author Medusa Slockbower
///
/// \copyright Copyright © 2025 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html))
///
///
#ifndef FENNEC_MEMORY_H
#define FENNEC_MEMORY_H
#include <fennec/lang/type_traits.h>
#include <fennec/memory/detail/__string.h>
namespace fennec
{
#ifndef FENNEC_MEMORY_MEMORY_H
#define FENNEC_MEMORY_MEMORY_H
///
/// \brief Returns the address of an object regardless of whether the `&` operators is implemented.
/// \tparam TypeT The type of the objects
/// \param obj The object to find the address of
/// \return The true address of the
template<typename TypeT>
constexpr TypeT* addressof(TypeT& obj) { return FENNEC_BUILTIN_ADDRESSOF(obj); }
/// \page fennec_lang C++ Language Library
///
/// \brief Finds the first occurence of ```static_cast<uint8_t>(ch)``` in the first \f$n\f$ bytes
/// \param arr Pointer to the object, interpreted as an array of bytes
/// \param ch The byte to search for
/// \param n The number of bytes to search
/// \returns A pointer to the location of \f$ch\f$, otherwise \f$nullptr\f$ if \f$ch\f$ is not found.
using ::memchr;
using ::wmemchr;
/// This library implements the parts of the C++ stdlib that relate to built-in types and metaprogramming.
///
/// \brief Compares the bytes of \f$lhs\f$ with \f$rhs\f$.
/// \param lhs The first object, interpreted as an array of bytes
/// \param rhs The second object, interpreted as an array of bytes
/// \param n The number of bytes to parse
/// \returns \f$0\f$ if the first \f$n\f$ bytes of \f$lhs\f$ and \f$rhs\f$ are equivalent. Otherwise, returns \f$1\f$
/// for the first byte \f$b\f$ where \f$lhs[b] > \f$ rhs[b]\f$, and \f$-1\f$ for \f$
using ::memcmp;
using ::wmemcmp;
/// - \subpage fennec_lang_assert
/// - \subpage fennec_lang_bit_manipulation
/// - \subpage fennec_lang_intrinsics
/// - \subpage fennec_lang_limits
/// - \subpage fennec_lang_metaprogramming
/// - \subpage fennec_lang_types
/// - \subpage fennec_lang_utility
///
/// \brief Safe version of memcmp
/// \copydoc fennec::memcmp
/// \param n0 The size, in bytes, of lhs
/// \param n1 The size, in bytes, of rhs
constexpr int memcmp_s(const void* lhs, size_t n0, const void* rhs, size_t n1)
{ return memcmp(lhs, rhs, n0 < n1 ? n0 : n1); }
///
/// \brief Copies the first \f$n\f$ bytes of \f$src\f$ to \f$dst\f$.
/// \param dst The destination object, interpreted as an array of bytes
/// \param src The source object, interpreted as an array of bytes
/// \param n The number of bytes to copy
/// \returns \f$dst\f$
///
/// \details memcpy does not do any checking for whether \f$dst\f$ and \f$src\f$ overlap. Let \f$k\f$ be the number of
/// bytes of which \f$dst\f$ and \f$src\f$. If \f$k > 0 & src < dst\f$ then the first \f$k\f$ elements of
/// \f$src\f$ will be repeated in \f$dst\f$ with a period of \f$k\f$.
///
/// A full mathematical proof of this function is possible in Set Theory.
using ::memcpy;
using ::wmemcpy;
///
/// \brief Safe version of memcpy
/// \copydoc fennec::memcpy
/// \param n0 The size, in bytes, of dst
/// \param n1 The size, in bytes, of src
constexpr void* memcpy_s(void* dst, size_t n0, const void* src, size_t n1)
{ return memcpy(dst, src, n0 < n1 ? n0 : n1); }
#include <fennec/memory/common.h>
///
/// \brief Copies the first \f$n\f$ bytes of \f$src\f$ to \f$dst\f$, with overlap correction..
/// \param dst The destination object, interpreted as an array of bytes
/// \param src The source object, interpreted as an array of bytes
/// \param n The number of bytes to copy
/// \returns \f$dst\f$
using ::memmove;
using ::wmemmove;
///
/// \brief Safe version of memmove
/// \copydoc fennec::memmove
/// \param n0 The size, in bytes, of dst
/// \param n1 The size, in bytes, of src
constexpr void* memmove_s(void* dst, size_t n0, const void* src, size_t n1)
{ return memmove(dst, src, n0 < n1 ? n0 : n1); }
///
/// \brief Sets all bytes of \f$dst\f$ to \f$ch\f$, interpreted as an \f$uint8_t\f$
/// \param dst The destination object, interpreted as an array of bytes
/// \param ch The value, interpreted as an \f$uint8_t\f$
/// \param n The number of bytes to set
/// \returns \f$dst\f$
using ::memset;
using ::wmemset;
}
#endif // FENNEC_MEMORY_H
#endif // FENNEC_MEMORY_MEMORY_H

View File

@@ -16,6 +16,18 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// =====================================================================================================================
///
/// \file new.h
/// \brief This header contains functions related to analyzing, modifying or copying buffers interpreted as bytes
///
///
/// \details
/// \author Medusa Slockbower
///
/// \copyright Copyright © 2025 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html))
///
///
#ifndef FENNEC_MEMORY_NEW_H
#define FENNEC_MEMORY_NEW_H

View File

@@ -24,6 +24,9 @@
namespace fennec
{
///
/// \brief Struct for wrapping C++ `delete`
/// \tparam TypeT The type of the buffer to be deleted
template<typename TypeT>
struct default_delete
{
@@ -48,6 +51,7 @@ struct default_delete
}
};
// Overload for Arrays
template<typename TypeT>
struct default_delete<TypeT[]>
{
@@ -58,13 +62,13 @@ struct default_delete<TypeT[]>
///
/// \brief Conversion Constructor
/// \tparam ConvT of other deleter
template<class ConvT> requires requires { is_convertible<ConvT(*)[], TypeT(*)[]>{}.value == true; }
template<class ConvT> requires requires { is_convertible_v<ConvT(*)[], TypeT(*)[]> == true; }
constexpr default_delete(const default_delete<ConvT(*)[]>&) noexcept {}
///
/// \brief Function Call Operator, calls `delete` on `ptr`
/// \param ptr Memory resource to delete
template<class ArrT> requires requires { is_convertible<ArrT(*)[], TypeT(*)[]>{}.value == true; }
template<class ArrT> requires requires { is_convertible_v<ArrT(*)[], TypeT(*)[]> == true; }
constexpr void operator()(TypeT* ptr) const noexcept
{
static_assert(not is_void_v<TypeT>, "cannot delete a pointer to an incomplete type");
@@ -73,6 +77,12 @@ struct default_delete<TypeT[]>
}
};
///
/// \brief
/// \tparam TypeT
/// \tparam DeleteT
template<typename TypeT, class DeleteT = default_delete<TypeT>>
class unique_ptr
{
@@ -118,11 +128,22 @@ public:
/// \brief Default Constructor, if it owns a resource, it deletes it using `delete_t`
constexpr ~unique_ptr() { if(_handle) _delete(_handle); }
constexpr unique_ptr& operator=(const unique_ptr&) = delete;
constexpr unique_ptr& operator=(unique_ptr&& r) noexcept
{ _handle = r._handle; r._handle = nullptr; return *this; }
{
_delete = r._delete;
_handle = r._handle;
r._handle = nullptr;
return *this;
}
pointer_t release() { pointer_t retval = _handle; _handle = nullptr; return retval; }
pointer_t release()
{
pointer_t retval = _handle;
_handle = nullptr;
return retval;
}
private:

17
source/fproc/io/file.cpp Normal file
View File

@@ -0,0 +1,17 @@
// =====================================================================================================================
// fennec, a free and open source game engine
// Copyright © 2025 Medusa Slockbower
//
// This program 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.
//
// This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
// =====================================================================================================================