diff --git a/CMakeLists.txt b/CMakeLists.txt index 37f6177..4271823 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() diff --git a/doxy/DoxyLayout.xml b/doxy/DoxyLayout.xml index f87b016..5e7c7bd 100644 --- a/doxy/DoxyLayout.xml +++ b/doxy/DoxyLayout.xml @@ -5,7 +5,6 @@ - diff --git a/doxy/Doxyfile b/doxy/Doxyfile index b886496..26d134c 100644 --- a/doxy/Doxyfile +++ b/doxy/Doxyfile @@ -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 diff --git a/doxy/Doxyfile.in b/doxy/Doxyfile.in index 41f9c09..c460a84 100644 --- a/doxy/Doxyfile.in +++ b/doxy/Doxyfile.in @@ -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 diff --git a/include/fennec/containers/array.h b/include/fennec/containers/array.h index 74b4dfe..a6c792d 100644 --- a/include/fennec/containers/array.h +++ b/include/fennec/containers/array.h @@ -18,7 +18,7 @@ /// /// \file array.h -/// \brief fennec::array definition & implementation +/// \brief statically allocated array wrapper /// /// /// \details diff --git a/include/fennec/containers/dynarray.h b/include/fennec/containers/dynarray.h index 69aca4d..a6a0a64 100644 --- a/include/fennec/containers/dynarray.h +++ b/include/fennec/containers/dynarray.h @@ -18,7 +18,7 @@ /// /// \file dynarray.h -/// \brief fennec::array definition & implementation +/// \brief dynamically allocated array wrapper /// /// /// \details @@ -78,10 +78,10 @@ public: } template - 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(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(val)); } template - 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(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(val)); } - template void emplace_back(ArgsT...args) { emplace(_size, fennec::forward(args)...); } + template void emplace_back(ArgsT...args) { dynarray::emplace(_size, fennec::forward(args)...); } private: void _grow() const { _alloc.reallocate(_alloc.capacity() * 2); } diff --git a/include/fennec/fproc/filesystem/path.h b/include/fennec/fproc/filesystem/path.h new file mode 100644 index 0000000..24911e8 --- /dev/null +++ b/include/fennec/fproc/filesystem/path.h @@ -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 . +// ===================================================================================================================== + +#ifndef FENNEC_FPROC_FILESYSTEM_PATH_H +#define FENNEC_FPROC_FILESYSTEM_PATH_H + +namespace fennec +{ + +struct path +{ + +}; + +} + +#endif // FENNEC_FPROC_FILESYSTEM_PATH_H diff --git a/include/fennec/fproc/io/detail/__stdio.h b/include/fennec/fproc/io/detail/__stdio.h new file mode 100644 index 0000000..0591ce7 --- /dev/null +++ b/include/fennec/fproc/io/detail/__stdio.h @@ -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 . +// ===================================================================================================================== + +#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 +#pragma pop_macro("__cplusplus") + +#if _MSC_VER +#pragma warning(pop) +#endif + +#endif // FENNEC_FPROC_STRINGS_DETAIL_CTYPE_H diff --git a/include/fennec/fproc/io/file.h b/include/fennec/fproc/io/file.h index 8897e60..d450175 100644 --- a/include/fennec/fproc/io/file.h +++ b/include/fennec/fproc/io/file.h @@ -20,9 +20,9 @@ #define FENNEC_FPROC_IO_FILE_H #include +#include 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; diff --git a/include/fennec/fproc/strings/cstring.h b/include/fennec/fproc/strings/cstring.h index 4a2f613..28bc66f 100644 --- a/include/fennec/fproc/strings/cstring.h +++ b/include/fennec/fproc/strings/cstring.h @@ -118,9 +118,11 @@ public: str._const = true; } + // TODO: Document constexpr cstring(const cstring&) = delete; constexpr ~cstring() = default; + // TODO: Document template constexpr cstring& operator=(char(&str)[n]) { assert(_str[n - 1] == '\0', "Invalid NTBS."); @@ -128,6 +130,7 @@ public: return *this; } + // TODO: Document template 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; diff --git a/include/fennec/fproc/strings/string.h b/include/fennec/fproc/strings/string.h index 7939681..eabb56e 100644 --- a/include/fennec/fproc/strings/string.h +++ b/include/fennec/fproc/strings/string.h @@ -24,17 +24,23 @@ #include #include -#include +#include namespace fennec { +// Forward def +template> 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> -struct string +struct _string { public: using alloc_t = allocation; @@ -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 ========================================================================================================== diff --git a/include/fennec/lang/assert.h b/include/fennec/lang/assert.h index fda3f56..66df303 100644 --- a/include/fennec/lang/assert.h +++ b/include/fennec/lang/assert.h @@ -16,9 +16,49 @@ // along with this program. If not, see . // ===================================================================================================================== +/// +/// \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 \endcode +/// +/// This header contains macros for making assertions about code behaviour. +/// +/// fennec defines the following assert implementations: +/// +/// +///
Syntax +/// Description +///

+/// assert(expr, desc) +///
+/// Make an assertion with expression `expr` and provide a description `desc`. +/// +///

+/// assertd(expr, desc) +///
+/// 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. +/// +///
+/// +/// +/// + #if _MSC_VER #define __PRETTY_FUNCTION__ __FUNCSIG__ #endif diff --git a/include/fennec/lang/bits.h b/include/fennec/lang/bits.h index 76b1633..37c9bf0 100644 --- a/include/fennec/lang/bits.h +++ b/include/fennec/lang/bits.h @@ -80,7 +80,7 @@ /// #include -#include +#include #include 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); } diff --git a/include/fennec/lang/conditional_types.h b/include/fennec/lang/conditional_types.h index 90f7fc0..19c5894 100644 --- a/include/fennec/lang/conditional_types.h +++ b/include/fennec/lang/conditional_types.h @@ -44,8 +44,8 @@ /// Syntax /// Description ///
-/// \ref fennec::conditional "typename conditional::type"
-/// \ref fennec::conditional_t "conditional_t" +/// \ref fennec::conditional "typename conditional::type"
+/// \ref fennec::conditional_t "conditional_t" /// /// \copydetails fennec::conditional /// @@ -56,8 +56,8 @@ /// \copydetails fennec::detect /// ///
-/// \ref fennec::enable_if "typename enable_if::type"
-/// \ref fennec::enable_if_t "enable_if_t" +/// \ref fennec::enable_if "typename enable_if::type"
+/// \ref fennec::enable_if_t "enable_if_t" /// /// \copydetails fennec::enable_if /// @@ -65,7 +65,6 @@ /// #include -#include 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 +template struct conditional; /// /// \brief Shorthand for ```typename conditional::type``` -template +template using conditional_t = typename conditional::type; @@ -153,12 +152,12 @@ struct detect /// /// \tparam B A boolean value /// \tparam T The type to conditionally define -template +template struct enable_if {}; /// /// \brief Shorthand for ```typename enable_if::type``` -template +template using enable_if_t = typename enable_if::type; // true case diff --git a/include/fennec/lang/constants.h b/include/fennec/lang/constants.h index 91f38d8..562fa5c 100644 --- a/include/fennec/lang/constants.h +++ b/include/fennec/lang/constants.h @@ -49,12 +49,12 @@ /// \copydetails fennec::integral_constant /// ///
-/// \ref fennec::bool_constant "bool_constant::type"
+/// \ref fennec::bool_constant "bool_constant::type"
/// /// \copydetails fennec::bool_constant /// ///
-/// \ref fennec::bool_constant "bool_constant::type"
+/// \ref fennec::bool_constant "bool_constant::type"
/// /// \copydetails fennec::bool_constant /// @@ -90,7 +90,7 @@ template struct integral_constant /// /// \details /// \tparam ValueV value of the constant -template +template struct bool_constant : integral_constant {}; diff --git a/include/fennec/lang/lang.h b/include/fennec/lang/lang.h index 0403e37..52e0754 100644 --- a/include/fennec/lang/lang.h +++ b/include/fennec/lang/lang.h @@ -31,9 +31,8 @@ #ifndef FENNEC_LANG_H #define FENNEC_LANG_H +#include #include -#include -#include #include #include @@ -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 diff --git a/include/fennec/lang/type_traits.h b/include/fennec/lang/type_traits.h index a0190d1..d2d4256 100644 --- a/include/fennec/lang/type_traits.h +++ b/include/fennec/lang/type_traits.h @@ -92,10 +92,10 @@ /// \copydetails fennec::is_same /// ///
-/// \ref fennec::can_convert "can_convert::value"
-/// \ref fennec::can_convert_v "can_convert_v" +/// \ref fennec::is_convertible "is_convertible::value"
+/// \ref fennec::is_convertible_v "is_convertible_v" /// -/// \copydetails fennec::can_convert +/// \copydetails fennec::is_convertible /// ///
/// \ref fennec::is_constructible "is_constructible::value"
@@ -334,8 +334,8 @@ template struct is_convertible /// \brief shorthand for `can_convert::value` /// \param FromT First type /// \param ToT Second type -template using is_convertible_v - = typename is_convertible::type; +template constexpr bool_t is_convertible_v + = is_convertible{}; // fennec::is_constructible =============================================================================================== diff --git a/include/fennec/lang/types.h b/include/fennec/lang/types.h index 7662a84..73a694d 100644 --- a/include/fennec/lang/types.h +++ b/include/fennec/lang/types.h @@ -34,6 +34,8 @@ /// /// \page fennec_lang_types Types /// +/// \code #include \endcode +/// /// \brief This header contains definitions for the built-in types of the C++ language. /// /// diff --git a/include/fennec/memory/allocator.h b/include/fennec/memory/allocator.h index 8b3e21e..f54d4cb 100644 --- a/include/fennec/memory/allocator.h +++ b/include/fennec/memory/allocator.h @@ -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 . // ===================================================================================================================== +/// +/// \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 + #include #include #include #include + #include + + namespace fennec { +/// +/// \brief Helper structure for obtaining traits of an allocator class +/// \tparam Alloc The allocator class to analyze template 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 -class allocation +struct allocation { public: /// \brief alias for the allocator type diff --git a/include/fennec/memory/common.h b/include/fennec/memory/common.h new file mode 100644 index 0000000..3072399 --- /dev/null +++ b/include/fennec/memory/common.h @@ -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 . +// ===================================================================================================================== + +/// +/// \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 +#include + +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 +constexpr TypeT* addressof(TypeT& obj) { return FENNEC_BUILTIN_ADDRESSOF(obj); } + +/// +/// \brief Finds the first occurence of ```static_cast(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 diff --git a/include/fennec/memory/memory.h b/include/fennec/memory/memory.h index ae45709..cff8f2e 100644 --- a/include/fennec/memory/memory.h +++ b/include/fennec/memory/memory.h @@ -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 . // ===================================================================================================================== +/// +/// \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 -#include - -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 -constexpr TypeT* addressof(TypeT& obj) { return FENNEC_BUILTIN_ADDRESSOF(obj); } - +/// \page fennec_lang C++ Language Library /// -/// \brief Finds the first occurence of ```static_cast(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 -/// -/// \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 diff --git a/include/fennec/memory/new.h b/include/fennec/memory/new.h index 315811e..87aab6a 100644 --- a/include/fennec/memory/new.h +++ b/include/fennec/memory/new.h @@ -16,6 +16,18 @@ // along with this program. If not, see . // ===================================================================================================================== +/// +/// \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 diff --git a/include/fennec/memory/pointers.h b/include/fennec/memory/pointers.h index fa334fb..16715ce 100644 --- a/include/fennec/memory/pointers.h +++ b/include/fennec/memory/pointers.h @@ -24,6 +24,9 @@ namespace fennec { +/// +/// \brief Struct for wrapping C++ `delete` +/// \tparam TypeT The type of the buffer to be deleted template struct default_delete { @@ -48,6 +51,7 @@ struct default_delete } }; +// Overload for Arrays template struct default_delete { @@ -58,13 +62,13 @@ struct default_delete /// /// \brief Conversion Constructor /// \tparam ConvT of other deleter - template requires requires { is_convertible{}.value == true; } + template requires requires { is_convertible_v == true; } constexpr default_delete(const default_delete&) noexcept {} /// /// \brief Function Call Operator, calls `delete` on `ptr` /// \param ptr Memory resource to delete - template requires requires { is_convertible{}.value == true; } + template requires requires { is_convertible_v == true; } constexpr void operator()(TypeT* ptr) const noexcept { static_assert(not is_void_v, "cannot delete a pointer to an incomplete type"); @@ -73,6 +77,12 @@ struct default_delete } }; + + +/// +/// \brief +/// \tparam TypeT +/// \tparam DeleteT template> 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: diff --git a/source/fproc/io/file.cpp b/source/fproc/io/file.cpp new file mode 100644 index 0000000..da6d3a1 --- /dev/null +++ b/source/fproc/io/file.cpp @@ -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 . +// =====================================================================================================================