diff --git a/CMakeLists.txt b/CMakeLists.txt index 41f6fa1..6ebcc99 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -90,17 +90,20 @@ add_library(fennec STATIC # SCENE ================================================================================================================ - include/fennec/scene/scene.h + include/fennec/scene/scene.h source/scene/scene.cpp include/fennec/scene/component.h include/fennec/scene/scene_node.h include/fennec/scene/node2d.h + include/fennec/scene/forward.h -# Renderers ============================================================================================================ + +# RENDERERS ============================================================================================================ include/fennec/renderers/interface/forward.h include/fennec/renderers/interface/gfxcontext.h include/fennec/renderers/interface/gfxsubpass.h + include/fennec/renderers/interface/gfxresourcepool.h # CONTAINERS =========================================================================================================== @@ -128,40 +131,48 @@ add_library(fennec STATIC include/fennec/containers/detail/_tuple.h -# LANG ================================================================================================================= - include/fennec/lang/lang.h - include/fennec/lang/metaprogramming.h +# langcpp ================================================================================================================= + include/fennec/langcpp/lang.h + include/fennec/langcpp/metaprogramming.h - include/fennec/lang/bits.h - include/fennec/lang/constants.h - include/fennec/lang/conditional_types.h - include/fennec/lang/hashing.h - include/fennec/lang/intrinsics.h - include/fennec/lang/limits.h - include/fennec/lang/numeric_transforms.h - include/fennec/lang/const_sequences.h - include/fennec/lang/startup.h - include/fennec/lang/type_identity.h - include/fennec/lang/type_operators.h - include/fennec/lang/type_sequences.h - include/fennec/lang/type_traits.h - include/fennec/lang/type_transforms.h - include/fennec/lang/typed.h - include/fennec/lang/types.h - include/fennec/lang/utility.h - include/fennec/lang/integer.h + include/fennec/langcpp/bits.h + include/fennec/langcpp/constants.h + include/fennec/langcpp/conditional_types.h + include/fennec/langcpp/hashing.h + include/fennec/langcpp/intrinsics.h + include/fennec/langcpp/limits.h + include/fennec/langcpp/numeric_transforms.h + include/fennec/langcpp/const_sequences.h + include/fennec/langcpp/startup.h + include/fennec/langcpp/type_identity.h + include/fennec/langcpp/type_operators.h + include/fennec/langcpp/type_sequences.h + include/fennec/langcpp/type_traits.h + include/fennec/langcpp/type_transforms.h + include/fennec/langcpp/types.h + include/fennec/langcpp/utility.h + include/fennec/langcpp/integer.h - include/fennec/lang/assert.h source/lang/assert.cpp + include/fennec/langcpp/assert.h source/langcpp/assert.cpp - include/fennec/lang/detail/_bits.h - include/fennec/lang/detail/_int.h - include/fennec/lang/detail/_numeric_transforms.h - include/fennec/lang/detail/_stdlib.h - include/fennec/lang/detail/_type_traits.h - include/fennec/lang/detail/_type_transforms.h - include/fennec/lang/detail/_type_sequences.h - include/fennec/lang/detail/_typeuuid.h + include/fennec/langcpp/detail/_bits.h + include/fennec/langcpp/detail/_int.h + include/fennec/langcpp/detail/_numeric_transforms.h + include/fennec/langcpp/detail/_stdlib.h + include/fennec/langcpp/detail/_type_traits.h + include/fennec/langcpp/detail/_type_transforms.h + include/fennec/langcpp/detail/_type_sequences.h + + +# RTTI ================================================================================================================= + include/fennec/rtti/typeid.h + include/fennec/rtti/type_data.h + + + include/fennec/rtti/detail/_typeid.h + include/fennec/rtti/detail/_type_name.h + include/fennec/rtti/detail/_constants.h # MEMORY =============================================================================================================== @@ -216,22 +227,22 @@ add_library(fennec STATIC include/fennec/math/detail/_vector_traits.h -# langproc ================================================================================================================ +# lang ================================================================================================================ # Strings - include/fennec/langproc/strings/locale.h - include/fennec/langproc/strings/cstring.h - include/fennec/langproc/strings/string.h - include/fennec/langproc/strings/format.h + include/fennec/lang/strings/locale.h + include/fennec/lang/strings/cstring.h + include/fennec/lang/strings/string.h + include/fennec/lang/strings/format.h - include/fennec/langproc/strings/detail/_ctype.h + include/fennec/lang/strings/detail/_ctype.h # Filesystem - include/fennec/langproc/filesystem/file.h source/langproc/filesystem/file.cpp - include/fennec/langproc/filesystem/path.h source/langproc/filesystem/path.cpp + include/fennec/lang/filesystem/file.h source/lang/filesystem/file.cpp + include/fennec/lang/filesystem/path.h source/lang/filesystem/path.cpp # Compile - include/fennec/langproc/compile/tokenizer.h + include/fennec/lang/compile/tokenizer.h # PLATFORM ============================================================================================================= @@ -240,14 +251,17 @@ add_library(fennec STATIC include/fennec/platform/interface/platform.h source/platform/interface/platform.cpp include/fennec/platform/interface/window.h -# RENDERER ============================================================================================================= +# GRAPHICS ============================================================================================================= - include/fennec/renderers/interface/gfxresourcepool.h + include/fennec/gfx3d/mesh_instance.h # EXTRA SOURCES ======================================================================================================== ${FENNEC_EXTRA_SOURCES} - include/fennec/gfx3d/mesh_instance.h + include/fennec/rtti/type.h + include/fennec/rtti/enable.h + include/fennec/rtti/forward.h + include/fennec/rtti/typelist.h ) add_dependencies(fennec metaprogramming fennec-dependencies) diff --git a/README.md b/README.md index 22cffb3..1dd49a4 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ fennec Standards: - Header Guards should be implemented using `#ifndef`, `#define`, and `#endif` for portability. The naming convention for Header Guards is as follows: `___H`. - I.E. the engine file `fennec/lang/utility.h` has the Header Guard `FENNEC_LANG_UTILITY_H`. + I.E. the engine file `fennec/langcpp/utility.h` has the Header Guard `FENNEC_LANG_UTILITY_H`. * Helper Functions, in the case of classes, should be private. In the case of global functions, helpers should be placed in a similarly named file in a subdirectory and namespace diff --git a/cmake/gcc.cmake b/cmake/gcc.cmake index 53569fa..9ef7621 100644 --- a/cmake/gcc.cmake +++ b/cmake/gcc.cmake @@ -22,4 +22,9 @@ add_compile_options("-Wall" "-Wextra" "-pedantic" "-Werror" "-fms-extensions") fennec_add_link_options("-nostdlib" "-fno-exceptions" "-fno-rtti" "-fdiagnostics-all-candidates") -fennec_add_definitions(_GLIBCXX_INCLUDE_NEXT_C_HEADERS=1 FENNEC_COMPILER_GCC=1 FENNEC_NO_INLINE=[[gnu::noinline]]) +fennec_add_definitions( + _GLIBCXX_INCLUDE_NEXT_C_HEADERS=1 + FENNEC_COMPILER_GCC=1 + FENNEC_NO_INLINE=[[gnu::noinline]] + FENNEC_FUNCTION_NAME=__PRETTY_FUNCTION__ +) diff --git a/doxy/header.html b/doxy/header.html index 583d0a2..273e732 100644 --- a/doxy/header.html +++ b/doxy/header.html @@ -1,6 +1,6 @@ - + diff --git a/include/fennec/containers/array.h b/include/fennec/containers/array.h index 61eb02c..1a00dd3 100644 --- a/include/fennec/containers/array.h +++ b/include/fennec/containers/array.h @@ -32,8 +32,8 @@ #ifndef FENNEC_CONTAINERS_ARRAY_H #define FENNEC_CONTAINERS_ARRAY_H -#include -#include +#include +#include namespace fennec { diff --git a/include/fennec/containers/detail/_tuple.h b/include/fennec/containers/detail/_tuple.h index 96af8f1..4cc96e7 100644 --- a/include/fennec/containers/detail/_tuple.h +++ b/include/fennec/containers/detail/_tuple.h @@ -18,8 +18,8 @@ #ifndef FENNEC_CONTAINERS_DETAIL_TUPLE_H #define FENNEC_CONTAINERS_DETAIL_TUPLE_H -#include -#include +#include +#include namespace fennec::detail { diff --git a/include/fennec/containers/dynarray.h b/include/fennec/containers/dynarray.h index 253c694..6839c95 100644 --- a/include/fennec/containers/dynarray.h +++ b/include/fennec/containers/dynarray.h @@ -31,7 +31,8 @@ #ifndef FENNEC_CONTAINERS_DYNARRAY_H #define FENNEC_CONTAINERS_DYNARRAY_H -#include +#include +#include #include #include @@ -60,7 +61,7 @@ namespace fennec /// /// \tparam TypeT value type template> -class dynarray { +struct dynarray { public: // Definitions ========================================================================================================= @@ -174,6 +175,51 @@ public: } } + /// + /// \brief Array Copy Constructor + /// \tparam N The length of the array, automatically deduced + /// \param arr The array to copy + template + constexpr dynarray(const TypeT (&arr)[N]) + : _alloc(N) + , _size(N) { + for (size_t i = 0; i < N; ++i) { + _alloc[i] = arr[i]; + } + } + + /// + /// \brief Array Move Constructor + /// \tparam N The length of the array, automatically deduced + /// \param arr The array to move + template + constexpr dynarray(TypeT (&&arr)[N]) + : _alloc(N) + , _size(N) { + for (size_t i = 0; i < N; ++i) { + _alloc[i] = fennec::move(arr[i]); + } + } + + template + constexpr dynarray(const dynarray& conv) + : _alloc(conv.size()) + , _size(conv.size()) { + size_t i = 0; + for (const auto& it : conv) { + fennec::construct(&_alloc[i++], it); + } + } + + constexpr dynarray(std::initializer_list l, const alloc_t& alloc = alloc_t()) + : _alloc(l.size(), alloc) + , _size(l.size()) { + size_t i = 0; + for (auto& it : l) { + fennec::construct(&_alloc[i++], fennec::move(it)); + } + } + /// /// \brief Copy Constructor, uses the copy constructor to copy each element /// \param arr the dynarray to copy @@ -236,6 +282,36 @@ public: return *this; } + /// + /// \brief Array Copy Assignment Operator + /// \tparam N the length of the array + /// \param arr the array to copy + /// \returns A dynarray after having copied each element of `arr` + template + constexpr dynarray& operator=(const TypeT (&arr)[N]) { + this->clear(); + _alloc.creallocate(_size = N); + for (size_t i = 0; i < _size; ++i) { + fennec::construct(&_alloc[i], fennec::copy(arr[i])); + } + return *this; + } + + /// + /// \brief Array Copy Assignment Operator + /// \tparam N the length of the array + /// \param arr the array to copy + /// \returns A dynarray after having moved each element of `arr` + template + constexpr dynarray& operator=(TypeT (&&arr)[N]) { + this->clear(); + _alloc.creallocate(_size = N); + for (size_t i = 0; i < _size; ++i) { + fennec::construct(&_alloc[i], fennec::move(arr[i])); + } + return *this; + } + /// @} // Properties ========================================================================================================== diff --git a/include/fennec/containers/map.h b/include/fennec/containers/map.h index 374ad84..b84181a 100644 --- a/include/fennec/containers/map.h +++ b/include/fennec/containers/map.h @@ -291,7 +291,9 @@ private: ~U() { fennec::destruct(&root); } - } trick = { .root = { KeyT(fennec::forward(args)...), 0 } }; + } trick = { + .root = { KeyT(fennec::forward(args)...), 0 } + }; return _set.find(trick.val); } diff --git a/include/fennec/containers/optional.h b/include/fennec/containers/optional.h index 006acfd..62a88a4 100644 --- a/include/fennec/containers/optional.h +++ b/include/fennec/containers/optional.h @@ -31,10 +31,10 @@ #ifndef FENNEC_CONTAINERS_OPTIONAL_H #define FENNEC_CONTAINERS_OPTIONAL_H -#include +#include #include -#include +#include namespace fennec { diff --git a/include/fennec/containers/pair.h b/include/fennec/containers/pair.h index e66b49e..87f8bc8 100644 --- a/include/fennec/containers/pair.h +++ b/include/fennec/containers/pair.h @@ -32,8 +32,8 @@ #define FENNEC_CONTAINERS_PAIR_H #include -#include -#include +#include +#include namespace fennec { diff --git a/include/fennec/containers/priority_queue.h b/include/fennec/containers/priority_queue.h index bb64a51..b56faf3 100644 --- a/include/fennec/containers/priority_queue.h +++ b/include/fennec/containers/priority_queue.h @@ -32,8 +32,8 @@ #define FENNEC_CONTAINERS_PRIORITY_QUEUE_H #include -#include -#include +#include +#include #include // Binary heaps are just kinda busted. diff --git a/include/fennec/containers/rdtree.h b/include/fennec/containers/rdtree.h index 3fc1fbe..3a8186d 100644 --- a/include/fennec/containers/rdtree.h +++ b/include/fennec/containers/rdtree.h @@ -34,6 +34,8 @@ #include #include #include +#include + #include namespace fennec @@ -194,7 +196,7 @@ public: /// \param i The id of the node to check /// \returns The id of the child node constexpr size_t child(size_t i, size_t n = 0) const { - if (i >= _table.capacity()) return npos; + if (i >= _table.capacity() && n != npos) return npos; size_t c = i == npos ? npos : _table[i].child; if (n != 0) return next(c, n == npos ? npos : n - 1); @@ -205,7 +207,7 @@ public: /// \param i The id of the node to check /// \returns The id of the next node constexpr size_t next(size_t i, size_t n = 0) const { - if (i >= _table.capacity()) return npos; + if (i >= _table.capacity() && n != npos) return npos; if (i == npos) { return npos; } @@ -332,7 +334,7 @@ public: /// /// \brief Insertion, creates a node in the tree with parent `parent` /// \param parent the parent node, if `npos` sets the value of the root node - /// \param next the next node, as an index relative to the parent + /// \param next the next node, as an index relative to the parent, i.e. parent[0] == parent.child, parent[1] == parent.child.next /// \param val the value to insert /// \returns the index of the created node constexpr size_t insert(size_t parent, size_t next, const value_t& val) { @@ -349,10 +351,33 @@ public: return this->_insert(parent, next, fennec::forward(val)); } + constexpr size_t insert(size_t parent, size_t next, const rdtree& tree) { + list> visit; + visit.push_front({ root, parent }); + size_t res = npos; + + while (not visit.empty()) { + auto node = visit.front(); + visit.pop_front(); + + size_t p = this->_insert(node.second, node.second == parent ? next : npos, tree[node.first]); + + res = (res == npos) ? p : res; + + size_t c = tree.child(node.first, npos); + while (c != npos) { + visit.push_front({ c, p }); + c = tree._table[c].prev; + } + } + + return res; + } + /// /// \brief Insertion, creates a node in the tree with parent `parent` /// \param parent the parent node, if `npos` sets the value of the root node - /// \param next the next node, as an index relative to the parent + /// \param next the next node, as an index relative to the parent, i.e. parent[0] == parent.child, parent[1] == parent.child.next /// \param args the args to construct the value to insert /// \returns the index of the created node template @@ -390,6 +415,8 @@ public: } + + // Traversal =========================================================================================================== /// diff --git a/include/fennec/containers/sequence.h b/include/fennec/containers/sequence.h index b335544..91fa732 100644 --- a/include/fennec/containers/sequence.h +++ b/include/fennec/containers/sequence.h @@ -39,7 +39,7 @@ #include #include #include -#include +#include #include // https://en.wikipedia.org/wiki/Red%E2%80%93black_tree diff --git a/include/fennec/containers/set.h b/include/fennec/containers/set.h index 1008abc..368520a 100644 --- a/include/fennec/containers/set.h +++ b/include/fennec/containers/set.h @@ -35,10 +35,10 @@ #include #include -#include +#include #include #include -#include +#include namespace fennec { @@ -330,7 +330,7 @@ public: while (_alloc[i = (i + 1) % capacity()].value) { if (_alloc[i].psl == 0) break; - fennec::swap(_alloc[i - 1].value, _alloc[i].value); + fennec::swap(_alloc[p].value, _alloc[i].value); --_alloc[p].psl, --_sumpsl; p = i; } diff --git a/include/fennec/containers/tuple.h b/include/fennec/containers/tuple.h index 44a2980..1cf3f84 100644 --- a/include/fennec/containers/tuple.h +++ b/include/fennec/containers/tuple.h @@ -32,7 +32,7 @@ #define FENNEC_CONTAINERS_TUPLE_H #include -#include +#include namespace fennec { @@ -83,6 +83,8 @@ struct tuple : public detail::_tuple, T template using elem_t = typename nth_element::type; + static constexpr size_t size = sizeof...(TypesT); + template tuple(ArgsT&&...args) : base_t(fennec::forward(args)...) { diff --git a/include/fennec/core/event.h b/include/fennec/core/event.h index 4ce443a..cb51316 100644 --- a/include/fennec/core/event.h +++ b/include/fennec/core/event.h @@ -19,8 +19,10 @@ #ifndef FENNEC_CORE_EVENT_H #define FENNEC_CORE_EVENT_H -#include -#include +#include +#include + +#include namespace fennec { @@ -37,18 +39,8 @@ public: /// /// \brief Main event interface, includes static methods for registering listeners and dispatching events -struct event : typed { - - // Delete default constructor to enforce type scheme - event() = delete; - - /// - /// \brief Event Constructor, stores the event type - /// \tparam EventT The type of the event - template - event(EventT* type) - : typed(type) { - } +struct event { + virtual ~event() = default; /// /// \brief Registers a listener for the event type @@ -67,6 +59,8 @@ struct event : typed { static void add_listener(event_listener* listener, uint64_t type); static void remove_listener(event_listener* listener); static void dispatch(event* event); + + FENNEC_RTTI_ENABLE(); }; } diff --git a/include/fennec/core/system.h b/include/fennec/core/system.h index d8a35dc..9e15c29 100644 --- a/include/fennec/core/system.h +++ b/include/fennec/core/system.h @@ -18,7 +18,7 @@ #ifndef FENNEC_CORE_SYSTEM_H #define FENNEC_CORE_SYSTEM_H -#include +#include namespace fennec { diff --git a/include/fennec/langproc/compile/tokenizer.h b/include/fennec/lang/compile/tokenizer.h similarity index 98% rename from include/fennec/langproc/compile/tokenizer.h rename to include/fennec/lang/compile/tokenizer.h index 6381faf..6f75957 100644 --- a/include/fennec/langproc/compile/tokenizer.h +++ b/include/fennec/lang/compile/tokenizer.h @@ -34,7 +34,7 @@ #include #include #include -#include +#include // // escape sequences are tricky, sometimes they must be separated by white space, diff --git a/include/fennec/langproc/filesystem/detail/_stdio.h b/include/fennec/lang/filesystem/detail/_stdio.h similarity index 100% rename from include/fennec/langproc/filesystem/detail/_stdio.h rename to include/fennec/lang/filesystem/detail/_stdio.h diff --git a/include/fennec/langproc/filesystem/file.h b/include/fennec/lang/filesystem/file.h similarity index 98% rename from include/fennec/langproc/filesystem/file.h rename to include/fennec/lang/filesystem/file.h index 0626441..806034a 100644 --- a/include/fennec/langproc/filesystem/file.h +++ b/include/fennec/lang/filesystem/file.h @@ -19,11 +19,11 @@ #ifndef FENNEC_LANGPROC_IO_FILE_H #define FENNEC_LANGPROC_IO_FILE_H -#include +#include -#include -#include -#include +#include +#include +#include namespace fennec { diff --git a/include/fennec/langproc/filesystem/path.h b/include/fennec/lang/filesystem/path.h similarity index 98% rename from include/fennec/langproc/filesystem/path.h rename to include/fennec/lang/filesystem/path.h index b1f83bc..d72dee0 100644 --- a/include/fennec/langproc/filesystem/path.h +++ b/include/fennec/lang/filesystem/path.h @@ -19,8 +19,8 @@ #ifndef FENNEC_LANGPROC_IO_PATH_H #define FENNEC_LANGPROC_IO_PATH_H -#include -#include +#include +#include namespace fennec { diff --git a/include/fennec/langproc/strings/cstring.h b/include/fennec/lang/strings/cstring.h similarity index 99% rename from include/fennec/langproc/strings/cstring.h rename to include/fennec/lang/strings/cstring.h index 4edf8cc..f4c7bdb 100644 --- a/include/fennec/langproc/strings/cstring.h +++ b/include/fennec/lang/strings/cstring.h @@ -19,10 +19,10 @@ #ifndef FENNEC_LANGPROC_STRINGS_CSTRING_H #define FENNEC_LANGPROC_STRINGS_CSTRING_H -#include +#include #include -#include +#include #include #include diff --git a/include/fennec/langproc/strings/detail/_ctype.h b/include/fennec/lang/strings/detail/_ctype.h similarity index 100% rename from include/fennec/langproc/strings/detail/_ctype.h rename to include/fennec/lang/strings/detail/_ctype.h diff --git a/include/fennec/langproc/strings/detail/_locale.h b/include/fennec/lang/strings/detail/_locale.h similarity index 100% rename from include/fennec/langproc/strings/detail/_locale.h rename to include/fennec/lang/strings/detail/_locale.h diff --git a/include/fennec/langproc/strings/format.h b/include/fennec/lang/strings/format.h similarity index 98% rename from include/fennec/langproc/strings/format.h rename to include/fennec/lang/strings/format.h index 200b0f9..ae02441 100644 --- a/include/fennec/langproc/strings/format.h +++ b/include/fennec/lang/strings/format.h @@ -31,8 +31,8 @@ #ifndef FENNEC_LANGPROC_STRINGS_FORMAT_H #define FENNEC_LANGPROC_STRINGS_FORMAT_H #include -#include -#include +#include +#include namespace fennec { diff --git a/include/fennec/langproc/strings/locale.h b/include/fennec/lang/strings/locale.h similarity index 96% rename from include/fennec/langproc/strings/locale.h rename to include/fennec/lang/strings/locale.h index 93b5b32..1dffbeb 100644 --- a/include/fennec/langproc/strings/locale.h +++ b/include/fennec/lang/strings/locale.h @@ -19,7 +19,7 @@ #ifndef FENNEC_LANGPROC_STRINGS_LOCALE_H #define FENNEC_LANGPROC_STRINGS_LOCALE_H -#include +#include namespace fennec { diff --git a/include/fennec/langproc/strings/string.h b/include/fennec/lang/strings/string.h similarity index 97% rename from include/fennec/langproc/strings/string.h rename to include/fennec/lang/strings/string.h index 1098ca4..45de979 100644 --- a/include/fennec/langproc/strings/string.h +++ b/include/fennec/lang/strings/string.h @@ -19,10 +19,10 @@ #ifndef FENNEC_LANGPROC_STRINGS_STRING_H #define FENNEC_LANGPROC_STRINGS_STRING_H -#include -#include +#include +#include -#include +#include #include #include @@ -134,8 +134,14 @@ public: return *this; } - constexpr _string& operator=(const _string& str) = default; - constexpr _string& operator=(_string&& str) noexcept = default; + constexpr _string& operator=(const _string& str) { + _str = str._str; + return *this; + } + constexpr _string& operator=(_string&& str) noexcept { + _str = fennec::move(str._str); + return *this; + } // Properties ========================================================================================================== diff --git a/include/fennec/langproc/strings/wcstring.h b/include/fennec/lang/strings/wcstring.h similarity index 99% rename from include/fennec/langproc/strings/wcstring.h rename to include/fennec/lang/strings/wcstring.h index bece5ba..33e51e9 100644 --- a/include/fennec/langproc/strings/wcstring.h +++ b/include/fennec/lang/strings/wcstring.h @@ -19,10 +19,10 @@ #ifndef FENNEC_LANGPROC_STRINGS_wcstring_H #define FENNEC_LANGPROC_STRINGS_wcstring_H -#include +#include #include -#include +#include #include diff --git a/include/fennec/langproc/strings/wstring.h b/include/fennec/lang/strings/wstring.h similarity index 98% rename from include/fennec/langproc/strings/wstring.h rename to include/fennec/lang/strings/wstring.h index fc41c6f..696140b 100644 --- a/include/fennec/langproc/strings/wstring.h +++ b/include/fennec/lang/strings/wstring.h @@ -19,10 +19,10 @@ #ifndef FENNEC_LANGPROC_wstringS_WSTRING_H #define FENNEC_LANGPROC_wstringS_WSTRING_H -#include -#include +#include +#include -#include +#include #include #include diff --git a/include/fennec/lang/type_traits.h b/include/fennec/lang/type_traits.h deleted file mode 100644 index eacab7b..0000000 --- a/include/fennec/lang/type_traits.h +++ /dev/null @@ -1,495 +0,0 @@ -// ===================================================================================================================== -// 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 . -// ===================================================================================================================== - -/// -/// \file type_traits.h -/// \brief \ref fennec_lang_type_traits -/// -/// -/// \details -/// \author Medusa Slockbower -/// -/// \copyright Copyright © 2025 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html)) -/// -/// - -#ifndef FENNEC_LANG_TYPE_TRAITS_H -#define FENNEC_LANG_TYPE_TRAITS_H - -/// -/// \page fennec_lang_type_traits Type Traits -/// -/// \brief Part of the fennec metaprogramming library. This header defines structures for accessing traits of types -/// at compile time. -/// -/// \code #include \endcode -/// -/// -/// -///
Syntax -/// Description -///

-/// \ref fennec::is_void "is_void::value"
-/// \ref fennec::is_void_v "is_void_v" -///
-/// \copydetails fennec::is_void -/// -///

-/// \ref fennec::is_bool "is_bool::value"
-/// \ref fennec::is_bool_v "is_bool_v" -///
-/// \copydetails fennec::is_bool -/// -///

-/// \ref fennec::is_integral "is_integral::value"
-/// \ref fennec::is_integral_v "is_integral_v" -///
-/// \copydetails fennec::is_integral -/// -///

-/// \ref fennec::is_signed "is_signed::value"
-/// \ref fennec::is_signed_v "is_signed_v" -///
-/// \copydetails fennec::is_signed -/// -///

-/// \ref fennec::is_unsigned "is_unsigned::value"
-/// \ref fennec::is_unsigned_v "is_unsigned_v" -///
-/// \copydetails fennec::is_unsigned -/// -///

-/// \ref fennec::is_floating_point "is_floating_point::value"
-/// \ref fennec::is_floating_point_v "is_floating_point_v" -///
-/// \copydetails fennec::is_floating_point -/// -///

-/// \ref fennec::is_arithmetic "is_arithmetic::value"
-/// \ref fennec::is_arithmetic_v "is_arithmetic_v" -///
-/// \copydetails fennec::is_arithmetic -/// -///

-/// \ref fennec::is_same "is_same::value"
-/// \ref fennec::is_same_v "is_same_v" -///
-/// \copydetails fennec::is_same -/// -///

-/// \ref fennec::is_convertible "is_convertible::value"
-/// \ref fennec::is_convertible_v "is_convertible_v" -///
-/// \copydetails fennec::is_convertible -/// -///

-/// \ref fennec::is_constructible "is_constructible::value"
-/// \ref fennec::is_constructible_v "is_constructible_v" -///
-/// \copydoc fennec::is_constructible -/// -///
-/// - -#include -#include -#include - -namespace fennec -{ - -// fennec::declval ===================================================================================================== - -template auto declval() noexcept -> decltype(detail::_declval(0)) { - static_assert(detail::_declval_protector{}, "declval must not be used"); - return detail::_declval(0); -} - -constexpr inline bool is_constant_evaluated() noexcept { - if consteval { - return true; - } else { - return false; - } -} - - -// fennec::is_void ===================================================================================================== - -/// -/// \brief check if \p T is of type void -/// -/// \details Stores a boolean value in `is_void::value`, representing whether the provided type is of base type void. -/// \tparam T type to check -template struct is_void - : detail::_is_void>{}; - -/// -/// \brief shorthand for ```is_void::value``` -/// \tparam T type to check -template constexpr bool_t is_void_v = is_void::value; - - - -// fennec::is_bool ===================================================================================================== - -/// -/// \brief check if \p T is of type bool -/// -/// \details Stores a boolean value in `is_bool::value`, representing whether the provided type is of base type bool. -/// \tparam T type to check -template struct is_bool - : detail::_is_bool>{}; - -/// -/// \brief shorthand for ```is_bool::value``` -/// \tparam T type to check -template constexpr bool_t is_bool_v = is_bool::value; - - - -// fennec::is_null_pointer ============================================================================================= - -/// -/// \brief check if \p T is of type nullptr_t -/// -/// \details Stores a boolean value in `is_null_pointer::value`, representing whether the provided type is of base type nullptr_t. -/// \tparam T type to check -template struct is_null_pointer - : detail::_is_null_pointer>{}; - -/// -/// \brief shorthand for ```is_null_pointer::value``` -/// \tparam T type to check -template constexpr bool_t is_null_pointer_v = is_null_pointer::value; - - - -// fennec::is_array ==================================================================================================== - -#ifdef FENNEC_BUILTIN_IS_ARRAY - -/// -/// \brief check if \p T is of an array type -/// \tparam T type to check -template struct is_array - : bool_constant {}; - -#else - -/// -/// \brief check if \p T is of an array type -/// \tparam T type to check -template struct is_array - : false_type {}; - -// overload for a sized array type -template struct is_array - : true_type {}; - -// overload for a generic array type -template struct is_array - : true_type {}; - -#endif - -/// -/// \brief shorthand for ```is_array::value``` -/// \tparam T type to check -template constexpr bool_t is_array_v = is_array::value; - -// fennec::is_class ==================================================================================================== - -/// -/// \brief check if \p T is a class -/// \tparam T type to check -template struct is_class - : bool_constant {}; - -/// -/// \brief check if \p T is a class -/// \tparam T type to check -template constexpr size_t is_class_v = is_class::value; - - - -// Integral Types ====================================================================================================== - -/// -/// \brief check if \p T is of an integral -/// -/// \details Stores a boolean value in `is_integral::value`, representing whether the provided type is of a base integer type. -/// \tparam T type to check -template struct is_integral - : detail::_is_integral> {}; - -/// -/// \brief shorthand for ```is_integral::value``` -/// \tparam T type to check -template constexpr bool_t is_integral_v = is_integral::value; - - -/// -/// \brief check if \p T is of a signed integral -/// -/// \details Checks if type `T` is a signed type i.e. `T(-1) < T(0)` and stores it in `is_same::value`. -/// \tparam T type to check -template struct is_signed - : detail::_is_signed> {}; - -/// -/// \brief shorthand for ```is_signed::value``` -/// \tparam T type to check -template constexpr bool_t is_signed_v = is_signed::value; - - -/// -/// \brief check if \p T is of an unsigned integral -/// -/// \details Checks if type `T` is an unsigned type i.e. `T(-1) > T(0)` and stores it in `is_same::value`. -/// \tparam T type to check -template struct is_unsigned - : detail::_is_unsigned> {}; - -/// -/// \brief shorthand for ```is_unsigned::value``` -/// \tparam T type to check -template constexpr bool_t is_unsigned_v = is_unsigned::value; - - - -// Floating Point Types ================================================================================================ - -/// -/// \brief check if \p T is of a floating point type -/// -/// \details Checks if type `T` is a floating point type and store it in `is_same::value`. -/// \tparam T type to check -template struct is_floating_point - : detail::_is_floating_point>{}; - -/// -/// \brief shorthand for ```is_floating_point::value``` -/// \tparam T type to check -template constexpr bool_t is_floating_point_v = is_floating_point {}; - - -// Pointer Types ======================================================================================================= - -/// -/// \brief check if \p T is of a floating point type -/// -/// \details Checks if type `T` is a floating point type and store it in `is_same::value`. -/// \tparam T type to check -template struct is_pointer - : detail::_is_pointer>{}; - -/// -/// \brief shorthand for ```is_floating_point::value``` -/// \tparam T type to check -template constexpr bool_t is_pointer_v = is_pointer {}; - - - -// Arithmetic Types ==================================================================================================== - -/// -/// \brief check if \p T is an arithmetic type -/// -/// \details Checks if type `T` is a built-in type with arithmetic operators and store it in `is_same::value`. -/// \tparam T type to check -template struct is_arithmetic - : bool_constant or is_floating_point_v>{}; - -/// -/// \brief shorthand for ```is_arithmetic::value``` -/// \tparam T type to check -template constexpr bool_t is_arithmetic_v = is_arithmetic::value; - - -// fennec::is_fundamental ============================================================================================== - -/// -/// \brief check if \p T is a fundamental type, i.e. arithmetic, void, or nullptr_t -/// \tparam T type to check -template struct is_fundamental - : bool_constant || is_void_v || is_null_pointer_v>{}; - -/// -/// \brief shorthand for ```is_fundamental::value``` -/// \tparam T type to check -template constexpr bool_t is_fundamental_v = is_fundamental::value; - - -// fennec::is_same ===================================================================================================== - -/// -/// \brief check if the two types are identical -/// -/// \details Checks if `T0` and `T1` are identical and store it in `is_same::value` -/// \tparam T0 first type to check -/// \tparam T1 second type to check -template struct is_same : false_type {}; - -// true case -template struct is_same : true_type {}; - -/// -/// \brief shorthand for ```is_same::value``` -/// \tparam T type to check -template constexpr bool_t is_same_v = is_same {}; - -// fennec::is_convertible ============================================================================================== - -/// -/// \brief check if type `T0` can be converted `T1` -/// -/// \details Checks if `TypeT0` -/// \tparam FromT First type -/// \tparam ToT Second type -template struct is_convertible - : bool_constant {}; - -/// -/// \brief shorthand for `can_convert::value` -/// \param FromT First type -/// \param ToT Second type -template constexpr bool_t is_convertible_v = is_convertible{}; - - -// fennec::is_constructible ============================================================================================ - -/// -/// \brief Check if `ClassT` can be constructed with `ArgsT,` i.e. `ClassT(ArgsT...)`. -/// This may be read as "is `ClassT` constructible with `ArgsT`" -/// \tparam ClassT The class type to test -/// \tparam ArgsT The arguments for the specific constructor -template struct is_constructible - : bool_constant {}; - -/// -/// \brief Shorthand for `is_constructible::value` -template constexpr bool_t is_constructible_v = is_constructible{}; - - - -/// -/// \brief Check if `ClassT` is default constructible -/// \tparam ClassT The class type to test -template struct is_default_constructible - : bool_constant {}; - -/// -/// \brief Shorthand for `is_default_constructible::value` -template constexpr bool_t is_default_constructible_v = is_default_constructible{}; - - - -/// -/// \brief Check if `ClassT` is copy constructible -/// \tparam ClassT The class type to test -template struct is_copy_constructible - : bool_constant)> {}; - -/// -/// \brief Shorthand for `is_copy_constructible::value` -template constexpr bool_t is_copy_constructible_v = is_copy_constructible{}; - - - -/// -/// \brief Check if `ClassT` is copy constructible -/// \tparam ClassT The class type to test -template struct is_move_constructible - : bool_constant)> {}; - -/// -/// \brief Shorthand for `is_copy_constructible::value` -template constexpr bool_t is_move_constructible_v = is_move_constructible{}; - - - -/// -/// \brief Check if `ClassT` is trivially constructible -/// \tparam ClassT The class type to test -template struct is_trivially_constructible - : bool_constant {}; - -/// -/// \brief Shorthand for `is_trivially_constructible::value` -template constexpr bool_t is_trivially_constructible_v = is_trivially_constructible{}; - - -// fennec::is_trivially_destructible =================================================================================== - -/// -/// \brief Check if `ClassT` is trivially destructible -/// \tparam ClassT The class type to test -template struct is_trivially_destructible - : bool_constant {}; - -/// -/// \brief Shorthand for `is_trivially_destructible::value` -template constexpr bool_t is_trivially_destructible_v = is_trivially_destructible{}; - - -// fennec::is_assignable =============================================================================================== - -/// -/// \brief Check if `ClassT` can be constructed with `ArgsT,` i.e. `ClassT(ArgsT...)`. -/// This may be read as "is `ClassT` constructible with `ArgsT`" -/// \tparam ClassAT The class type to test -/// \tparam ClassBT The arguments for the specific constructor -template struct is_assignable - : bool_constant {}; - -/// -/// \brief Shorthand for `is_constructible::value` -template constexpr bool_t is_assignable_v = is_assignable{}; - - -// fennec::is_copy_assignable ========================================================================================== - -/// -/// \brief Check if `ClassT` is copy assignable -/// \tparam ClassT The class type to test -template struct is_copy_assignable - : bool_constant, add_lvalue_reference_t)> {}; - -/// -/// \brief Shorthand for `is_copy_assignable::value` -template constexpr bool_t is_copy_assignable_v = is_copy_assignable{}; - - -// fennec::is_move_assignable ========================================================================================== - -/// -/// \brief Check if `ClassT` is move assignable -/// \tparam ClassT The class type to test -template struct is_move_assignable - : bool_constant, add_rvalue_reference_t)> {}; - -/// -/// \brief Shorthand for `is_move_assignable::value` -template constexpr bool_t is_move_assignable_v = is_move_assignable{}; - -// - -} - -#endif // FENNEC_LANG_TYPE_TRAITS_H diff --git a/include/fennec/lang/assert.h b/include/fennec/langcpp/assert.h similarity index 98% rename from include/fennec/lang/assert.h rename to include/fennec/langcpp/assert.h index fe799fa..34dafc3 100644 --- a/include/fennec/lang/assert.h +++ b/include/fennec/langcpp/assert.h @@ -34,7 +34,7 @@ /// /// \page fennec_lang_assert Assertions /// -/// \code #include \endcode +/// \code #include \endcode /// /// This header contains macros for making assertions about code behaviour. /// diff --git a/include/fennec/lang/bits.h b/include/fennec/langcpp/bits.h similarity index 98% rename from include/fennec/lang/bits.h rename to include/fennec/langcpp/bits.h index f9e6966..bfe0c0d 100644 --- a/include/fennec/lang/bits.h +++ b/include/fennec/langcpp/bits.h @@ -34,7 +34,7 @@ /// /// \page fennec_lang_bit_manipulation Bit Manipulation /// -/// \code #include \endcode +/// \code #include \endcode /// /// This header contains definitions for manipulating the bits of a provided object or pointer. /// @@ -79,9 +79,9 @@ /// /// -#include +#include #include -#include +#include namespace fennec { diff --git a/include/fennec/lang/compare.h b/include/fennec/langcpp/compare.h similarity index 98% rename from include/fennec/lang/compare.h rename to include/fennec/langcpp/compare.h index 649d864..a3af03f 100644 --- a/include/fennec/lang/compare.h +++ b/include/fennec/langcpp/compare.h @@ -19,7 +19,7 @@ #ifndef FENNEC_LANG_COMPARE_H #define FENNEC_LANG_COMPARE_H -#include +#include namespace fennec { diff --git a/include/fennec/lang/conditional_types.h b/include/fennec/langcpp/conditional_types.h similarity index 98% rename from include/fennec/lang/conditional_types.h rename to include/fennec/langcpp/conditional_types.h index e38613a..572303d 100644 --- a/include/fennec/lang/conditional_types.h +++ b/include/fennec/langcpp/conditional_types.h @@ -32,12 +32,12 @@ #ifndef FENNEC_LANG_CONDITIONAL_TYPES_H #define FENNEC_LANG_CONDITIONAL_TYPES_H -#include +#include /// /// \page fennec_lang_conditional_types Conditional Types /// -/// \code #include \endcode +/// \code #include \endcode /// /// This header contains various compile-time functions for conditionally setting types, detecting types, or /// conditionally enabling functions.

diff --git a/include/fennec/lang/const_sequences.h b/include/fennec/langcpp/const_sequences.h similarity index 98% rename from include/fennec/lang/const_sequences.h rename to include/fennec/langcpp/const_sequences.h index 2d6ef1d..a118146 100644 --- a/include/fennec/lang/const_sequences.h +++ b/include/fennec/langcpp/const_sequences.h @@ -36,7 +36,7 @@ /// /// \brief This header is part of the metaprogramming library. It defines structures for sequences of values, used during compile time. /// -/// \code #include \endcode +/// \code #include \endcode /// /// ///
Syntax @@ -70,7 +70,7 @@ ///
/// -#include +#include namespace fennec { diff --git a/include/fennec/lang/constants.h b/include/fennec/langcpp/constants.h similarity index 97% rename from include/fennec/lang/constants.h rename to include/fennec/langcpp/constants.h index 1535ed4..0c6ab41 100644 --- a/include/fennec/lang/constants.h +++ b/include/fennec/langcpp/constants.h @@ -31,7 +31,7 @@ #ifndef FENNEC_LANG_CONSTANTS_H #define FENNEC_LANG_CONSTANTS_H -#include +#include /// /// @@ -40,7 +40,7 @@ /// \brief This header is part of the metaprogramming library. It defines structures for constant values, /// used during compile time. /// -/// \code #include \endcode +/// \code #include \endcode /// /// ///
Syntax diff --git a/include/fennec/lang/detail/_bits.h b/include/fennec/langcpp/detail/_bits.h similarity index 99% rename from include/fennec/lang/detail/_bits.h rename to include/fennec/langcpp/detail/_bits.h index 5732a9e..709b965 100644 --- a/include/fennec/lang/detail/_bits.h +++ b/include/fennec/langcpp/detail/_bits.h @@ -19,7 +19,7 @@ #ifndef FENNEC_LANG_DETAIL_BITS_H #define FENNEC_LANG_DETAIL_BITS_H -#include +#include namespace fennec::detail { diff --git a/include/fennec/lang/detail/_int.h b/include/fennec/langcpp/detail/_int.h similarity index 100% rename from include/fennec/lang/detail/_int.h rename to include/fennec/langcpp/detail/_int.h diff --git a/include/fennec/lang/detail/_numeric_transforms.h b/include/fennec/langcpp/detail/_numeric_transforms.h similarity index 97% rename from include/fennec/lang/detail/_numeric_transforms.h rename to include/fennec/langcpp/detail/_numeric_transforms.h index 64880f9..e7c9e18 100644 --- a/include/fennec/lang/detail/_numeric_transforms.h +++ b/include/fennec/langcpp/detail/_numeric_transforms.h @@ -19,8 +19,8 @@ #ifndef FENNEC_LANG_DETAIL_NUMERIC_TRANSFORMS_H #define FENNEC_LANG_DETAIL_NUMERIC_TRANSFORMS_H -#include -#include +#include +#include namespace fennec::detail { diff --git a/include/fennec/lang/detail/_stdlib.h b/include/fennec/langcpp/detail/_stdlib.h similarity index 100% rename from include/fennec/lang/detail/_stdlib.h rename to include/fennec/langcpp/detail/_stdlib.h diff --git a/include/fennec/lang/detail/_type_sequences.h b/include/fennec/langcpp/detail/_type_sequences.h similarity index 97% rename from include/fennec/lang/detail/_type_sequences.h rename to include/fennec/langcpp/detail/_type_sequences.h index 614cc03..2d3b10b 100644 --- a/include/fennec/lang/detail/_type_sequences.h +++ b/include/fennec/langcpp/detail/_type_sequences.h @@ -19,7 +19,7 @@ #ifndef FENNEC_LANG_DETAIL_TYPE_SEQUENCES_H #define FENNEC_LANG_DETAIL_TYPE_SEQUENCES_H -#include +#include namespace fennec::detail { diff --git a/include/fennec/lang/detail/_type_traits.h b/include/fennec/langcpp/detail/_type_traits.h similarity index 82% rename from include/fennec/lang/detail/_type_traits.h rename to include/fennec/langcpp/detail/_type_traits.h index c335876..853754a 100644 --- a/include/fennec/lang/detail/_type_traits.h +++ b/include/fennec/langcpp/detail/_type_traits.h @@ -19,8 +19,7 @@ #ifndef FENNEC_LANG_DETAIL_TYPE_TRAITS_H #define FENNEC_LANG_DETAIL_TYPE_TRAITS_H -#include -#include +#include namespace fennec::detail { @@ -70,6 +69,27 @@ namespace fennec::detail template struct _declval_protector : bool_constant {}; + template struct _is_complete { + template + static auto test(U*) -> bool_constant; + static auto test(...) -> false_type; + using type = decltype(_is_complete::test(static_cast(nullptr))); + }; + + template struct _is_destructible { + template().~T())> + static auto test(int) -> true_type; + static auto test(...) -> false_type; + using type = decltype(test(0)); + }; + + template struct _is_nothrow_destructible { + template().~T()))> + static auto test(int) -> true_type; + static auto test(...) -> false_type; + using type = decltype(test(0)); + }; + } #endif // FENNEC_LANG_DETAIL_TYPE_TRAITS_H diff --git a/include/fennec/lang/detail/_type_transforms.h b/include/fennec/langcpp/detail/_type_transforms.h similarity index 97% rename from include/fennec/lang/detail/_type_transforms.h rename to include/fennec/langcpp/detail/_type_transforms.h index bfa4ee1..3dbec66 100644 --- a/include/fennec/lang/detail/_type_transforms.h +++ b/include/fennec/langcpp/detail/_type_transforms.h @@ -19,7 +19,7 @@ #ifndef FENNEC_LANG_DETAIL_TYPE_TRANSFORMS_H #define FENNEC_LANG_DETAIL_TYPE_TRANSFORMS_H -#include +#include namespace fennec::detail { diff --git a/include/fennec/lang/float.h b/include/fennec/langcpp/float.h similarity index 99% rename from include/fennec/lang/float.h rename to include/fennec/langcpp/float.h index 1cca5dd..f674c5e 100644 --- a/include/fennec/lang/float.h +++ b/include/fennec/langcpp/float.h @@ -30,7 +30,7 @@ #ifndef FENNEC_LANG_FLOAT_H #define FENNEC_LANG_FLOAT_H -#include +#include #undef FLT_HAS_INFINITY #undef FLT_HAS_QUIET_NAN diff --git a/include/fennec/lang/hashing.h b/include/fennec/langcpp/hashing.h similarity index 97% rename from include/fennec/lang/hashing.h rename to include/fennec/langcpp/hashing.h index 40a2e62..0509db3 100644 --- a/include/fennec/lang/hashing.h +++ b/include/fennec/langcpp/hashing.h @@ -19,8 +19,8 @@ #ifndef FENNEC_LANG_HASHING_H #define FENNEC_LANG_HASHING_H -#include -#include +#include +#include namespace fennec { diff --git a/include/fennec/lang/integer.h b/include/fennec/langcpp/integer.h similarity index 100% rename from include/fennec/lang/integer.h rename to include/fennec/langcpp/integer.h diff --git a/include/fennec/lang/intrinsics.h b/include/fennec/langcpp/intrinsics.h similarity index 99% rename from include/fennec/lang/intrinsics.h rename to include/fennec/langcpp/intrinsics.h index 9e05bde..98fa596 100644 --- a/include/fennec/lang/intrinsics.h +++ b/include/fennec/langcpp/intrinsics.h @@ -33,7 +33,7 @@ /// \brief This header contains definitions for compiler intrinsics necessary for implementing functions of the /// C++ stdlib. /// -/// \code{.cpp}#include \endcode +/// \code{.cpp}#include \endcode /// /// /// diff --git a/include/fennec/lang/lang.h b/include/fennec/langcpp/lang.h similarity index 91% rename from include/fennec/lang/lang.h rename to include/fennec/langcpp/lang.h index 52e0754..436e3b1 100644 --- a/include/fennec/lang/lang.h +++ b/include/fennec/langcpp/lang.h @@ -17,7 +17,7 @@ // ===================================================================================================================== /// -/// \file lang.h +/// \file langcpp.h /// \brief \ref fennec_lang /// /// @@ -31,10 +31,10 @@ #ifndef FENNEC_LANG_H #define FENNEC_LANG_H -#include -#include -#include -#include +#include +#include +#include +#include /// /// \page fennec_lang C++ Language Library diff --git a/include/fennec/lang/limits.h b/include/fennec/langcpp/limits.h similarity index 99% rename from include/fennec/lang/limits.h rename to include/fennec/langcpp/limits.h index f87df2b..f8f9eea 100644 --- a/include/fennec/lang/limits.h +++ b/include/fennec/langcpp/limits.h @@ -39,7 +39,7 @@ /// floats and integers. There are overloads for all builtin types, and overloads for other types are included in /// their own header. /// -/// \code{.cpp}#include \endcode +/// \code{.cpp}#include \endcode /// /// \section fennec_lang_limits_numeric_limits Numeric Limits ///
@@ -197,11 +197,11 @@ /// /// -#include -#include +#include +#include -#include -#include +#include +#include namespace fennec { diff --git a/include/fennec/lang/metaprogramming.h b/include/fennec/langcpp/metaprogramming.h similarity index 100% rename from include/fennec/lang/metaprogramming.h rename to include/fennec/langcpp/metaprogramming.h diff --git a/include/fennec/lang/numeric_transforms.h b/include/fennec/langcpp/numeric_transforms.h similarity index 94% rename from include/fennec/lang/numeric_transforms.h rename to include/fennec/langcpp/numeric_transforms.h index be636ed..7aa5c20 100644 --- a/include/fennec/lang/numeric_transforms.h +++ b/include/fennec/langcpp/numeric_transforms.h @@ -33,7 +33,7 @@ /// /// \page fennec_lang_numeric_transforms Numeric Transforms /// -/// \code #include \endcode +/// \code #include \endcode /// /// This header contains various compile-time functions for changing the characteristics of a provided type /// @@ -54,8 +54,8 @@ /// ///
-#include -#include +#include +#include namespace fennec { diff --git a/include/fennec/lang/startup.h b/include/fennec/langcpp/startup.h similarity index 100% rename from include/fennec/lang/startup.h rename to include/fennec/langcpp/startup.h diff --git a/include/fennec/lang/type_identity.h b/include/fennec/langcpp/type_identity.h similarity index 97% rename from include/fennec/lang/type_identity.h rename to include/fennec/langcpp/type_identity.h index cf0e419..2c91345 100644 --- a/include/fennec/lang/type_identity.h +++ b/include/fennec/langcpp/type_identity.h @@ -25,7 +25,7 @@ /// \brief Part of the fennec metaprogramming library. This header defines structures for copying types with different traits /// or rather, transform them, at compile time. /// -/// \code #include \endcode +/// \code #include \endcode /// /// /// diff --git a/include/fennec/lang/type_operators.h b/include/fennec/langcpp/type_operators.h similarity index 100% rename from include/fennec/lang/type_operators.h rename to include/fennec/langcpp/type_operators.h diff --git a/include/fennec/lang/type_sequences.h b/include/fennec/langcpp/type_sequences.h similarity index 96% rename from include/fennec/lang/type_sequences.h rename to include/fennec/langcpp/type_sequences.h index 22ed6dc..611c08e 100644 --- a/include/fennec/lang/type_sequences.h +++ b/include/fennec/langcpp/type_sequences.h @@ -36,7 +36,7 @@ /// /// \brief This header is part of the metaprogramming library. It defines structures for sequences of types, used during compile time. /// -/// \code #include \endcode +/// \code #include \endcode /// ///
///
Syntax @@ -54,7 +54,7 @@ ///
/// -#include +#include namespace fennec { diff --git a/include/fennec/langcpp/type_traits.h b/include/fennec/langcpp/type_traits.h new file mode 100644 index 0000000..b6519cc --- /dev/null +++ b/include/fennec/langcpp/type_traits.h @@ -0,0 +1,854 @@ +// ===================================================================================================================== +// 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 . +// ===================================================================================================================== + +/// +/// \file type_traits.h +/// \brief \ref fennec_lang_type_traits +/// +/// +/// \details +/// \author Medusa Slockbower +/// +/// \copyright Copyright © 2025 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html)) +/// +/// + +#ifndef FENNEC_LANG_TYPE_TRAITS_H +#define FENNEC_LANG_TYPE_TRAITS_H + +/// +/// \page fennec_lang_type_traits Type Traits +/// +/// \brief Part of the fennec metaprogramming library. This header defines structures for accessing traits of types +/// at compile time. +/// +/// \code #include \endcode +/// +/// +/// +/// \section Primary Type Categories +/// +/// +///
Syntax +/// Description +///

+/// \ref fennec::is_void "is_void::value"
+/// \ref fennec::is_void_v "is_void_v" +///
+/// \copydetails fennec::is_void +/// +///

+/// \ref fennec::is_null_pointer "is_null_pointer::value"
+/// \ref fennec::is_null_pointer_v "is_null_pointer_v" +///
+/// \copydetails fennec::is_null_pointer +/// +///

+/// \ref fennec::is_bool "is_bool::value"
+/// \ref fennec::is_bool_v "is_bool_v" +///
+/// \copydetails fennec::is_bool +/// +///

+/// \ref fennec::is_integral "is_integral::value"
+/// \ref fennec::is_integral_v "is_integral_v" +///
+/// \copydetails fennec::is_integral +/// +///

+/// \ref fennec::is_floating_point "is_floating_point::value"
+/// \ref fennec::is_floating_point_v "is_floating_point_v" +///
+/// \copydetails fennec::is_floating_point +/// +///

+/// \ref fennec::is_array "is_array::value"
+/// \ref fennec::is_array_v "is_array_v" +///
+/// \copydetails fennec::is_array +/// +///

+/// \ref fennec::is_enum "is_enum::value"
+/// \ref fennec::is_enum_v "is_enum_v" +///
+/// \copydetails fennec::is_enum +/// +///

+/// \ref fennec::is_union "is_union::value"
+/// \ref fennec::is_union_v "is_union_v" +///
+/// \copydetails fennec::is_union +/// +///

+/// \ref fennec::is_class "is_class::value"
+/// \ref fennec::is_class_v "is_class_v" +///
+/// \copydetails fennec::is_class +/// +///

+/// \ref fennec::is_function "is_function::value"
+/// \ref fennec::is_function_v "is_function_v" +///
+/// \copydetails fennec::is_function +/// +///

+/// \ref fennec::is_pointer "is_pointer::value"
+/// \ref fennec::is_pointer_v "is_pointer_v" +///
+/// \copydetails fennec::is_pointer +/// +///

+/// \ref fennec::is_lvalue_reference "is_lvalue_reference::value"
+/// \ref fennec::is_lvalue_reference_v "is_lvalue_reference_v" +///
+/// \copydetails fennec::is_lvalue_reference +/// +///

+/// \ref fennec::is_rvalue_reference "is_rvalue_reference::value"
+/// \ref fennec::is_rvalue_reference_v "is_rvalue_reference_v" +///
+/// \copydetails fennec::is_rvalue_reference +/// +///

+/// \ref fennec::is_member_object_pointer "is_member_object_pointer::value"
+/// \ref fennec::is_member_object_pointer_v "is_member_object_pointer_v" +///
+/// \copydetails fennec::is_member_object_pointer +/// +///

+/// \ref fennec::is_member_function_pointer "is_member_function_pointer::value"
+/// \ref fennec::is_member_function_pointer_v "is_member_function_pointer_v" +///
+/// \copydetails fennec::is_member_function_pointer +/// +///
+/// +/// +/// +/// \section Composite Type Categories +/// +/// +///
Syntax +/// Description +/// +///

+/// \ref fennec::is_fundamental "is_fundamental::value"
+/// \ref fennec::is_fundamental_v "is_fundamental_v" +///
+/// \copydetails fennec::is_fundamental +/// +///

+/// \ref fennec::is_arithmetic "is_arithmetic::value"
+/// \ref fennec::is_arithmetic_v "is_arithmetic_v" +///
+/// \copydetails fennec::is_arithmetic +/// +///

+/// \ref fennec::is_scalar "is_scalar::value"
+/// \ref fennec::is_scalar_v "is_scalar_v" +///
+/// \copydetails fennec::is_scalar +/// +///

+/// \ref fennec::is_object "is_object::value"
+/// \ref fennec::is_object_v "is_object_v" +///
+/// \copydetails fennec::is_object +/// +///

+/// \ref fennec::is_compound "is_compound::value"
+/// \ref fennec::is_compound_v "is_compound_v" +///
+/// \copydetails fennec::is_compound +/// +///

+/// \ref fennec::is_reference "is_reference::value"
+/// \ref fennec::is_reference_v "is_reference_v" +///
+/// \copydetails fennec::is_reference +/// +///

+/// \ref fennec::is_member_pointer "is_member_pointer::value"
+/// \ref fennec::is_member_pointer_v "is_member_pointer_v" +///
+/// \copydetails fennec::is_member_pointer +/// +///
+/// +/// +/// +/// \section Type Properties +/// +/// +///
Syntax +/// Description +/// +///

+/// \ref fennec::is_const "is_const::value"
+/// \ref fennec::is_const_v "is_const_v" +///
+/// \copydetails fennec::is_const +/// +///

+/// \ref fennec::is_volatile "is_volatile::value"
+/// \ref fennec::is_volatile_v "is_volatile_v" +///
+/// \copydetails fennec::is_volatile +/// +///

+/// \ref fennec::is_trivial "is_trivial::value"
+/// \ref fennec::is_trivial_v "is_trivial_v" +///
+/// \copydetails fennec::is_trivial +/// +///

+/// \ref fennec::is_trivially_copyable "is_trivially_copyable::value"
+/// \ref fennec::is_trivially_copyable_v "is_trivially_copyable_v" +///
+/// \copydetails fennec::is_trivially_copyable +/// +///

+/// \ref fennec::is_standard_layout "is_standard_layout::value"
+/// \ref fennec::is_standard_layout_v "is_standard_layout_v" +///
+/// \copydetails fennec::is_standard_layout +/// +///

+/// \ref fennec::has_unique_object_representations "has_unique_object_representations::value"
+/// \ref fennec::has_unique_object_representations_v "has_unique_object_representations_v" +///
+/// \copydetails fennec::has_unique_object_representations +/// +///

+/// \ref fennec::is_empty "is_empty::value"
+/// \ref fennec::is_empty_v "is_empty_v" +///
+/// \copydetails fennec::is_empty +/// +///

+/// \ref fennec::is_polymorphic "is_polymorphic::value"
+/// \ref fennec::is_polymorphic_v "is_polymorphic_v" +///
+/// \copydetails fennec::is_polymorphic +/// +///

+/// \ref fennec::is_abstract "is_abstract::value"
+/// \ref fennec::is_abstract_v "is_abstract_v" +///
+/// \copydetails fennec::is_abstract +/// +///

+/// \ref fennec::is_complete "is_complete::value"
+/// \ref fennec::is_complete_v "is_complete_v" +///
+/// \copydetails fennec::is_complete +/// +///

+/// \ref fennec::is_final "is_final::value"
+/// \ref fennec::is_final_v "is_final_v" +///
+/// \copydetails fennec::is_final +/// +///

+/// \ref fennec::is_aggregate "is_aggregate::value"
+/// \ref fennec::is_aggregate_v "is_aggregate_v" +///
+/// \copydetails fennec::is_aggregate +/// +///

+/// \ref fennec::is_implicit_lifetime "is_implicit_lifetime::value"
+/// \ref fennec::is_implicit_lifetime_v "is_implicit_lifetime_v" +///
+/// \copydetails fennec::is_implicit_lifetime +/// +///

+/// \ref fennec::is_signed "is_signed::value"
+/// \ref fennec::is_signed_v "is_signed_v" +///
+/// \copydetails fennec::is_signed +/// +///

+/// \ref fennec::is_unsigned "is_unsigned::value"
+/// \ref fennec::is_unsigned_v "is_unsigned_v" +///
+/// \copydetails fennec::is_unsigned +/// +///

+/// \ref fennec::is_bounded_array "is_bounded_array::value"
+/// \ref fennec::is_bounded_array_v "is_bounded_array_v" +///
+/// \copydetails fennec::is_bounded_array +/// +///

+/// \ref fennec::is_unbounded_array "is_unbounded_array::value"
+/// \ref fennec::is_unbounded_array_v "is_unbounded_array_v" +///
+/// \copydetails fennec::is_unbounded_array +/// +///

+/// \ref fennec::is_scoped_enum "is_scoped_enum::value"
+/// \ref fennec::is_scoped_enum_v "is_scoped_enum_v" +///
+/// \copydetails fennec::is_scoped_enum +/// +///
+/// +/// +/// +/// \section Supported Operations +/// +/// +///
Syntax +/// Description +/// +///

+/// \ref fennec::is_convertible "is_convertible::value"
+/// \ref fennec::is_convertible_v "is_convertible_v" +///
+/// \copydetails fennec::is_convertible +/// +///

+/// \ref fennec::is_constructible "is_constructible::value"
+/// \ref fennec::is_constructible_v "is_constructible_v" +/// \ref fennec::is_trivially_constructible "is_trivially_constructible::value"
+/// \ref fennec::is_trivially_constructible_v "is_trivially_constructible_v" +/// \ref fennec::is_nothrow_constructible "is_nothrow_constructible::value"
+/// \ref fennec::is_nothrow_constructible_v "is_nothrow_constructible_v" +///
+/// \copydetails fennec::is_constructible +/// +///

+/// \ref fennec::is_default_constructible "is_default_constructible::value"
+/// \ref fennec::is_default_constructible_v "is_default_constructible_v" +/// \ref fennec::is_trivially_default_constructible "is_trivially_default_constructible::value"
+/// \ref fennec::is_trivially_default_constructible_v "is_trivially_default_constructible_v" +/// \ref fennec::is_nothrow_default_constructible "is_nothrow_default_constructible::value"
+/// \ref fennec::is_nothrow_default_constructible_v "is_nothrow_default_constructible_v" +///
+/// \copydetails fennec::is_default_constructible +/// +///

+/// \ref fennec::is_copy_constructible "is_copy_constructible::value"
+/// \ref fennec::is_copy_constructible_v "is_copy_constructible_v" +/// \ref fennec::is_trivially_copy_constructible "is_trivially_copy_constructible::value"
+/// \ref fennec::is_trivially_copy_constructible_v "is_trivially_copy_constructible_v" +/// \ref fennec::is_nothrow_copy_constructible "is_nothrow_copy_constructible::value"
+/// \ref fennec::is_nothrow_copy_constructible_v "is_nothrow_copy_constructible_v" +///
+/// \copydetails fennec::is_copy_constructible +/// +///

+/// \ref fennec::is_move_constructible "is_move_constructible::value"
+/// \ref fennec::is_move_constructible_v "is_move_constructible_v" +/// \ref fennec::is_trivially_move_constructible "is_trivially_move_constructible::value"
+/// \ref fennec::is_trivially_move_constructible_v "is_trivially_move_constructible_v" +/// \ref fennec::is_nothrow_move_constructible "is_nothrow_move_constructible::value"
+/// \ref fennec::is_nothrow_move_constructible_v "is_nothrow_move_constructible_v" +///
+/// \movedetails fennec::is_move_constructible +/// +///

+/// \ref fennec::is_assignable "is_assignable::value"
+/// \ref fennec::is_assignable_v "is_assignable_v" +/// \ref fennec::is_trivially_assignable "is_trivially_assignable::value"
+/// \ref fennec::is_trivially_assignable_v "is_trivially_assignable_v" +/// \ref fennec::is_nothrow_assignable "is_nothrow_assignable::value"
+/// \ref fennec::is_nothrow_assignable_v "is_nothrow_assignable_v" +///
+/// \copydetails fennec::is_assignable +/// +///

+/// \ref fennec::is_copy_assignable "is_copy_assignable::value"
+/// \ref fennec::is_copy_assignable_v "is_copy_assignable_v" +/// \ref fennec::is_trivially_copy_assignable "is_trivially_copy_assignable::value"
+/// \ref fennec::is_trivially_copy_assignable_v "is_trivially_copy_assignable_v" +/// \ref fennec::is_nothrow_copy_assignable "is_nothrow_copy_assignable::value"
+/// \ref fennec::is_nothrow_copy_assignable_v "is_nothrow_copy_assignable_v" +///
+/// \copydetails fennec::is_copy_assignable +/// +///

+/// \ref fennec::is_move_assignable "is_move_assignable::value"
+/// \ref fennec::is_move_assignable_v "is_move_assignable_v" +/// \ref fennec::is_trivially_move_assignable "is_trivially_move_assignable::value"
+/// \ref fennec::is_trivially_move_assignable_v "is_trivially_move_assignable_v" +/// \ref fennec::is_nothrow_move_assignable "is_nothrow_move_assignable::value"
+/// \ref fennec::is_nothrow_move_assignable_v "is_nothrow_move_assignable_v" +///
+/// \movedetails fennec::is_move_assignable +/// +///

+/// \ref fennec::is_destructible "is_destructible::value"
+/// \ref fennec::is_destructible_v "is_destructible_v" +/// \ref fennec::is_trivially_destructible "is_trivially_destructible::value"
+/// \ref fennec::is_trivially_destructible_v "is_trivially_destructible_v" +/// \ref fennec::is_nothrow_destructible "is_nothrow_destructible::value"
+/// \ref fennec::is_nothrow_destructible_v "is_nothrow_destructible_v" +///
+/// \copydetails fennec::is_destructible +/// +///

+/// \ref fennec::has_virtual_destructor "has_virtual_destructor::value"
+/// \ref fennec::has_virtual_destructor_v "has_virtual_destructor_v" +///
+/// \copydetails fennec::has_virtual_destructor +/// +///
+/// +/// +/// +/// \section Type Relationships +/// +/// +///
Syntax +/// Description +/// +///

+/// \ref fennec::is_same "is_same::value"
+/// \ref fennec::is_same_v "is_same_v" +///
+/// \copydetails fennec::is_same +/// +///
+/// + +#include +#include +#include + +namespace fennec +{ + +// fennec::declval ===================================================================================================== + +template auto declval() noexcept -> decltype(detail::_declval(0)) { + static_assert(detail::_declval_protector{}, "declval must not be used"); + return detail::_declval(0); +} + +constexpr inline bool is_constant_evaluated() noexcept { + if consteval { + return true; + } else { + return false; + } +} + + +// fennec::is_void ===================================================================================================== + +/// +/// \brief check if \p T is of type void +/// +/// \details Stores a boolean value in `is_void::value`, representing whether the provided type is of base type void. +/// \tparam T type to check +template struct is_void + : detail::_is_void>{}; + +/// +/// \brief shorthand for ```is_void::value``` +/// \tparam T type to check +template constexpr bool_t is_void_v = is_void::value; + + + +// fennec::is_null_pointer ============================================================================================= + +/// +/// \brief check if \p T is of type nullptr_t +/// +/// \details Stores a boolean value in `is_null_pointer::value`, representing whether the provided type is of base type nullptr_t. +/// \tparam T type to check +template struct is_null_pointer + : detail::_is_null_pointer>{}; + +/// +/// \brief shorthand for ```is_null_pointer::value``` +/// \tparam T type to check +template constexpr bool_t is_null_pointer_v = is_null_pointer::value; + + + +// fennec::is_array ==================================================================================================== + +#ifdef FENNEC_BUILTIN_IS_ARRAY + +/// +/// \brief check if \p T is of an array type +/// \tparam T type to check +template struct is_array + : bool_constant {}; + +#else + +/// +/// \brief check if \p T is of an array type +/// \tparam T type to check +template struct is_array + : false_type {}; + +// overload for a sized array type +template struct is_array + : true_type {}; + +// overload for a generic array type +template struct is_array + : true_type {}; + +#endif + +/// +/// \brief shorthand for ```is_array::value``` +/// \tparam T type to check +template constexpr bool_t is_array_v = is_array::value; + +// fennec::is_class ==================================================================================================== + +/// +/// \brief check if \p T is a class +/// \tparam T type to check +template struct is_class + : bool_constant {}; + +/// +/// \brief check if \p T is a class +/// \tparam T type to check +template constexpr size_t is_class_v = is_class::value; + + + +// Integral Types ====================================================================================================== + + + +// fennec::is_bool ===================================================================================================== + +/// +/// \brief check if \p T is of type bool +/// +/// \details Stores a boolean value in `is_bool::value`, representing whether the provided type is of base type bool. +/// \tparam T type to check +template struct is_bool + : detail::_is_bool>{}; + +/// +/// \brief shorthand for ```is_bool::value``` +/// \tparam T type to check +template constexpr bool_t is_bool_v = is_bool::value; + +/// +/// \brief check if \p T is of an integral +/// +/// \details Stores a boolean value in `is_integral::value`, representing whether the provided type is of a base integer type. +/// \tparam T type to check +template struct is_integral + : detail::_is_integral> {}; + +/// +/// \brief shorthand for ```is_integral::value``` +/// \tparam T type to check +template constexpr bool_t is_integral_v = is_integral::value; + + +/// +/// \brief check if \p T is of a signed integral +/// +/// \details Checks if type `T` is a signed type i.e. `T(-1) < T(0)` and stores it in `is_same::value`. +/// \tparam T type to check +template struct is_signed + : detail::_is_signed> {}; + +/// +/// \brief shorthand for ```is_signed::value``` +/// \tparam T type to check +template constexpr bool_t is_signed_v = is_signed::value; + + +/// +/// \brief check if \p T is of an unsigned integral +/// +/// \details Checks if type `T` is an unsigned type i.e. `T(-1) > T(0)` and stores it in `is_same::value`. +/// \tparam T type to check +template struct is_unsigned + : detail::_is_unsigned> {}; + +/// +/// \brief shorthand for ```is_unsigned::value``` +/// \tparam T type to check +template constexpr bool_t is_unsigned_v = is_unsigned::value; + + + +// Floating Point Types ================================================================================================ + +/// +/// \brief check if \p T is of a floating point type +/// +/// \details Checks if type `T` is a floating point type and store it in `is_same::value`. +/// \tparam T type to check +template struct is_floating_point + : detail::_is_floating_point>{}; + +/// +/// \brief shorthand for ```is_floating_point::value``` +/// \tparam T type to check +template constexpr bool_t is_floating_point_v = is_floating_point {}; + + +// Pointer Types ======================================================================================================= + +/// +/// \brief check if \p T is of a floating point type +/// +/// \details Checks if type `T` is a floating point type and store it in `is_same::value`. +/// \tparam T type to check +template struct is_pointer + : detail::_is_pointer>{}; + +/// +/// \brief shorthand for ```is_floating_point::value``` +/// \tparam T type to check +template constexpr bool_t is_pointer_v = is_pointer {}; + + + +// Arithmetic Types ==================================================================================================== + +/// +/// \brief check if \p T is an arithmetic type +/// +/// \details Checks if type `T` is a built-in type with arithmetic operators and store it in `is_same::value`. +/// \tparam T type to check +template struct is_arithmetic + : bool_constant or is_floating_point_v>{}; + +/// +/// \brief shorthand for ```is_arithmetic::value``` +/// \tparam T type to check +template constexpr bool_t is_arithmetic_v = is_arithmetic::value; + + +// fennec::is_fundamental ============================================================================================== + +/// +/// \brief check if \p T is a fundamental type, i.e. arithmetic, void, or nullptr_t +/// \tparam T type to check +template struct is_fundamental + : bool_constant || is_void_v || is_null_pointer_v>{}; + +/// +/// \brief shorthand for ```is_fundamental::value``` +/// \tparam T type to check +template constexpr bool_t is_fundamental_v = is_fundamental::value; + + +// fennec::is_same ===================================================================================================== + +/// +/// \brief check if the two types are identical +/// +/// \details Checks if `T0` and `T1` are identical and store it in `is_same::value` +/// \tparam T0 first type to check +/// \tparam T1 second type to check +template struct is_same : false_type {}; + +// true case +template struct is_same : true_type {}; + +/// +/// \brief shorthand for ```is_same::value``` +/// \tparam T0 first type to check +/// \tparam T1 second type to check +template constexpr bool_t is_same_v = is_same {}; + +// fennec::is_complete ============================================================================================== + +/// +/// \brief check if type `T` is complete +/// +/// \details Checks if `T` +/// \tparam T type to check +template struct is_complete : detail::_is_complete::type {}; + +/// +/// \brief shorthand for `is_complete::value` +/// \tparam T type to check +template constexpr bool_t is_complete_v = is_complete{}; + +// fennec::is_convertible ============================================================================================== + +/// +/// \brief check if type `T0` can be converted `T1` +/// +/// \details Checks if `TypeT0` +/// \tparam FromT First type +/// \tparam ToT Second type +template struct is_convertible + : bool_constant {}; + +/// +/// \brief shorthand for `can_convert::value` +/// \param FromT First type +/// \param ToT Second type +template constexpr bool_t is_convertible_v = is_convertible{}; + + +// fennec::is_constructible ============================================================================================ + +/// +/// \brief Check if `ClassT` can be constructed with `ArgsT,` i.e. `ClassT(ArgsT...)`. +/// This may be read as "is `ClassT` constructible with `ArgsT`" +/// \tparam ClassT The class type to test +/// \tparam ArgsT The arguments for the specific constructor +template struct is_constructible + : bool_constant {}; + +/// +/// \brief Shorthand for `is_constructible::value` +template constexpr bool_t is_constructible_v = is_constructible{}; + + + +/// +/// \brief Check if `ClassT` is trivially constructible +/// \tparam ClassT The class type to test +template struct is_trivially_constructible + : bool_constant {}; + +/// +/// \brief Shorthand for `is_trivially_constructible::value` +template constexpr bool_t is_trivially_constructible_v = is_trivially_constructible{}; + + + +/// +/// \brief Check if `ClassT` is default constructible +/// \tparam ClassT The class type to test +template struct is_default_constructible + : bool_constant {}; + +/// +/// \brief Shorthand for `is_default_constructible::value` +template constexpr bool_t is_default_constructible_v = is_default_constructible{}; + + + +/// +/// \brief Check if `ClassT` is copy constructible +/// \tparam ClassT The class type to test +template struct is_copy_constructible + : bool_constant)> {}; + +/// +/// \brief Shorthand for `is_copy_constructible::value` +template constexpr bool_t is_copy_constructible_v = is_copy_constructible{}; + + + +/// +/// \brief Check if `ClassT` is copy constructible +/// \tparam ClassT The class type to test +template struct is_move_constructible + : bool_constant)> {}; + +/// +/// \brief Shorthand for `is_copy_constructible::value` +template constexpr bool_t is_move_constructible_v = is_move_constructible{}; + + +// fennec::is_destructible =================================================================================== + +/// +/// \brief Check if `ClassT` is destructible +/// \tparam ClassT The class type to test +template struct is_destructible + : detail::_is_destructible::type {}; + +/// +/// \brief Shorthand for `is_destructible::value` +template constexpr bool_t is_destructible_v = is_destructible{}; + + + +/// +/// \brief Check if `ClassT` is trivially destructible +/// \tparam ClassT The class type to test +template struct is_trivially_destructible + : bool_constant {}; + +/// +/// \brief Shorthand for `is_trivially_destructible::value` +template constexpr bool_t is_trivially_destructible_v = is_trivially_destructible{}; + + + +/// +/// \brief Check if `ClassT` is nothrow destructible +/// \tparam ClassT The class type to test +template struct is_nothrow_destructible + : detail::_is_nothrow_destructible::type {}; + +/// +/// \brief Shorthand for `is_nothrow_destructible::value` +template constexpr bool_t is_nothrow_destructible_v = is_nothrow_destructible{}; + + +// fennec::is_assignable =============================================================================================== + +/// +/// \brief Check if `ClassT` can be constructed with `ArgsT,` i.e. `ClassT(ArgsT...)`. +/// This may be read as "is `ClassT` constructible with `ArgsT`" +/// \tparam ClassAT The class type to test +/// \tparam ClassBT The arguments for the specific constructor +template struct is_assignable + : bool_constant {}; + +/// +/// \brief Shorthand for `is_constructible::value` +template constexpr bool_t is_assignable_v = is_assignable{}; + + +// fennec::is_copy_assignable ========================================================================================== + +/// +/// \brief Check if `ClassT` is copy assignable +/// \tparam ClassT The class type to test +template struct is_copy_assignable + : bool_constant, add_lvalue_reference_t)> {}; + +/// +/// \brief Shorthand for `is_copy_assignable::value` +template constexpr bool_t is_copy_assignable_v = is_copy_assignable{}; + + +// fennec::is_move_assignable ========================================================================================== + +/// +/// \brief Check if `ClassT` is move assignable +/// \tparam ClassT The class type to test +template struct is_move_assignable + : bool_constant, add_rvalue_reference_t)> {}; + +/// +/// \brief Shorthand for `is_move_assignable::value` +template constexpr bool_t is_move_assignable_v = is_move_assignable{}; + + +} + +#endif // FENNEC_LANG_TYPE_TRAITS_H diff --git a/include/fennec/lang/type_transforms.h b/include/fennec/langcpp/type_transforms.h similarity index 92% rename from include/fennec/lang/type_transforms.h rename to include/fennec/langcpp/type_transforms.h index b81016d..7f9cab2 100644 --- a/include/fennec/lang/type_transforms.h +++ b/include/fennec/langcpp/type_transforms.h @@ -31,8 +31,9 @@ #ifndef FENNEC_LANG_TYPE_TRANSFORMS_H #define FENNEC_LANG_TYPE_TRANSFORMS_H -#include -#include +#include +#include +#include /// /// \page fennec_lang_type_transforms Type Transforms @@ -40,7 +41,7 @@ /// \brief Part of the fennec metaprogramming library. This header defines structures for copying types with different traits /// or rather, transform them, at compile time. /// -/// \code #include \endcode +/// \code #include \endcode /// /// /// @@ -154,6 +155,20 @@ template struct remove_pointer : type_identity {}; template using remove_pointer_t = typename remove_pointer::type; +/// +/// \brief removes all pointer levels from \p T +/// +/// \details removes all pointers from the provided type such that `T*`, `T**`, etc. becomes `T` +/// \tparam T Resultant Type +template struct strip_pointers : conditional_t< + detail::_is_pointer::value, + strip_pointers>, + type_identity + > {}; + +template using strip_pointers_t = strip_pointers::type; + + // Reference Conversions =============================================================================================== @@ -347,6 +362,20 @@ template struct remove_cvr : type_identity::type` template using remove_cvr_t = typename remove_cvr::type; + + +/// +/// \brief removes references and pointers as well as the const and volatile qualifiers from the provided type \p T +/// +/// \details removes const and volatile from the provided type such that +/// \tparam T Reference Type +template struct remove_cvrp : type_identity>>> {}; + + +/// +/// \brief shorthand for `typename remove_cvrp_t::type` +template using remove_cvrp_t = typename remove_cvrp::type; + } #endif // FENNEC_LANG_TYPE_TRANSFORMS_H diff --git a/include/fennec/lang/types.h b/include/fennec/langcpp/types.h similarity index 98% rename from include/fennec/lang/types.h rename to include/fennec/langcpp/types.h index 0bb0f49..d8f0520 100644 --- a/include/fennec/lang/types.h +++ b/include/fennec/langcpp/types.h @@ -34,7 +34,7 @@ /// /// \page fennec_lang_types Types /// -/// \code #include \endcode +/// \code #include \endcode /// /// \brief This header contains definitions for the built-in types of the C++ language. /// @@ -201,9 +201,9 @@ /// /// -#include +#include -#include +#include namespace fennec { diff --git a/include/fennec/lang/utility.h b/include/fennec/langcpp/utility.h similarity index 92% rename from include/fennec/lang/utility.h rename to include/fennec/langcpp/utility.h index 33b41f7..1743881 100644 --- a/include/fennec/lang/utility.h +++ b/include/fennec/langcpp/utility.h @@ -36,7 +36,7 @@ /// /// \brief This header contains common utility functions related to the C++ language. /// -/// \code #include \endcode +/// \code #include \endcode /// ///
///
Syntax @@ -59,8 +59,8 @@ ///
/// -#include -#include +#include +#include namespace fennec { @@ -123,9 +123,19 @@ constexpr void swap(T& x, T& y) noexcept { /// \param x first value /// \param y second value template constexpr void swap(T& x, T& y) noexcept { + +#if FENNEC_COMPILER_GCC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" +#endif + T a = fennec::move(x); x = fennec::move(y); y = fennec::move(a); + +#if FENNEC_COMPILER_GCC +#pragma GCC diagnostic pop +#endif } } diff --git a/include/fennec/math/common.h b/include/fennec/math/common.h index 3f93219..2f68d99 100644 --- a/include/fennec/math/common.h +++ b/include/fennec/math/common.h @@ -271,7 +271,7 @@ #include -#include +#include #include diff --git a/include/fennec/math/detail/_types.h b/include/fennec/math/detail/_types.h index e5ed2d2..7a15da3 100644 --- a/include/fennec/math/detail/_types.h +++ b/include/fennec/math/detail/_types.h @@ -19,7 +19,7 @@ #ifndef FENNEC_MATH_DETAIL_TYPES_H #define FENNEC_MATH_DETAIL_TYPES_H -#include +#include namespace fennec { diff --git a/include/fennec/math/detail/_vector_traits.h b/include/fennec/math/detail/_vector_traits.h index 3051f59..e9d026f 100644 --- a/include/fennec/math/detail/_vector_traits.h +++ b/include/fennec/math/detail/_vector_traits.h @@ -21,7 +21,7 @@ #include -#include +#include #include namespace fennec diff --git a/include/fennec/math/ext/common.h b/include/fennec/math/ext/common.h index ef00b5d..18b02fd 100644 --- a/include/fennec/math/ext/common.h +++ b/include/fennec/math/ext/common.h @@ -19,7 +19,7 @@ #ifndef FENNEC_MATH_EXT_COMMON_H #define FENNEC_MATH_EXT_COMMON_H -#include +#include #include #include diff --git a/include/fennec/math/relational.h b/include/fennec/math/relational.h index b92e042..6309468 100644 --- a/include/fennec/math/relational.h +++ b/include/fennec/math/relational.h @@ -111,7 +111,7 @@ /// /// -#include +#include namespace fennec { diff --git a/include/fennec/math/scalar.h b/include/fennec/math/scalar.h index d584d77..2831640 100644 --- a/include/fennec/math/scalar.h +++ b/include/fennec/math/scalar.h @@ -57,7 +57,7 @@ /// /// -#include +#include #include #include diff --git a/include/fennec/math/swizzle.h b/include/fennec/math/swizzle.h index e2fb5e0..5d9ab43 100644 --- a/include/fennec/math/swizzle.h +++ b/include/fennec/math/swizzle.h @@ -41,7 +41,7 @@ /// /// -#include +#include #include diff --git a/include/fennec/math/vector.h b/include/fennec/math/vector.h index d5d3eba..80919c2 100644 --- a/include/fennec/math/vector.h +++ b/include/fennec/math/vector.h @@ -108,9 +108,9 @@ #include #include -#include -#include -#include +#include +#include +#include namespace fennec { diff --git a/include/fennec/memory/allocator.h b/include/fennec/memory/allocator.h index f15b07e..647d762 100644 --- a/include/fennec/memory/allocator.h +++ b/include/fennec/memory/allocator.h @@ -35,10 +35,10 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include #include @@ -366,7 +366,8 @@ public: constexpr allocation(size_t n, const alloc_t& alloc) noexcept : _alloc(alloc) , _data(nullptr) - , _capacity(0) { + , _capacity(0) + , _alignment(zero()) { callocate(n); } @@ -450,7 +451,7 @@ public: /// \param alloc the allocation to copy /// \returns a reference to `this` constexpr allocation& operator=(const allocation& alloc) { - allocation::allocate(alloc.capacity()); + allocation::allocate(alloc.capacity(), alloc.alignment()); fennec::memmove(_data, alloc, size()); return *this; } @@ -465,12 +466,13 @@ public: fennec::swap(_alloc, alloc._alloc); fennec::swap(_data, alloc._data); fennec::swap(_capacity, alloc._capacity); + fennec::swap(_alignment, alloc._alignment); return *this; } - // Allocation and Deallocation ===================================================================================== +// Allocation and Deallocation ========================================================================================= /// /// \brief Allocate a block of memory for the allocation. @@ -627,6 +629,10 @@ public: return _data; } + constexpr align_t alignment() const { + return _alignment; + } + protected: alloc_t _alloc; // Allocator object value_t* _data; // Handle for the memory block diff --git a/include/fennec/memory/bytes.h b/include/fennec/memory/bytes.h index eaaf262..cb8128e 100644 --- a/include/fennec/memory/bytes.h +++ b/include/fennec/memory/bytes.h @@ -19,9 +19,9 @@ #ifndef FENNEC_LANG_BYTES_H #define FENNEC_LANG_BYTES_H -#include -#include -#include +#include +#include +#include namespace fennec { diff --git a/include/fennec/memory/common.h b/include/fennec/memory/common.h index b64dfa0..c503550 100644 --- a/include/fennec/memory/common.h +++ b/include/fennec/memory/common.h @@ -32,7 +32,7 @@ #ifndef FENNEC_MEMORY_H #define FENNEC_MEMORY_H -#include +#include #include namespace fennec diff --git a/include/fennec/memory/detail/_ptr_traits.h b/include/fennec/memory/detail/_ptr_traits.h index dd1661e..b149575 100644 --- a/include/fennec/memory/detail/_ptr_traits.h +++ b/include/fennec/memory/detail/_ptr_traits.h @@ -19,10 +19,10 @@ #ifndef FENNEC_MEMORY_DETAIL_PTR_TRAITS_H #define FENNEC_MEMORY_DETAIL_PTR_TRAITS_H -#include -#include -#include -#include +#include +#include +#include +#include namespace fennec { diff --git a/include/fennec/memory/new.h b/include/fennec/memory/new.h index a099288..8a78c35 100644 --- a/include/fennec/memory/new.h +++ b/include/fennec/memory/new.h @@ -32,8 +32,8 @@ #ifndef FENNEC_MEMORY_NEW_H #define FENNEC_MEMORY_NEW_H -#include -#include +#include +#include namespace fennec { diff --git a/include/fennec/memory/pointer_traits.h b/include/fennec/memory/pointer_traits.h index bdfbff1..46bd6eb 100644 --- a/include/fennec/memory/pointer_traits.h +++ b/include/fennec/memory/pointer_traits.h @@ -19,7 +19,7 @@ #ifndef FENNEC_MEMORY_PTR_TRAITS_H #define FENNEC_MEMORY_PTR_TRAITS_H -#include +#include #include namespace fennec diff --git a/include/fennec/memory/pointers.h b/include/fennec/memory/pointers.h index 1c4ac4f..5a13479 100644 --- a/include/fennec/memory/pointers.h +++ b/include/fennec/memory/pointers.h @@ -19,7 +19,7 @@ #ifndef FENNEC_MEMORY_POINTERS_H #define FENNEC_MEMORY_POINTERS_H -#include +#include namespace fennec { @@ -45,7 +45,7 @@ struct default_delete /// \param ptr Memory resource to delete constexpr void operator()(TypeT* ptr) const noexcept { static_assert(not is_void_v, "cannot delete a pointer to an incomplete type"); - static_assert(not sizeof(TypeT) > 0, "cannot delete a pointer to an incomplete type"); + static_assert(is_complete_v, "cannot delete a pointer to an incomplete type"); delete ptr; } }; @@ -70,7 +70,7 @@ struct default_delete 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"); - static_assert(not sizeof(TypeT) > 0, "cannot delete a pointer to an incomplete type"); + static_assert(is_complete_v, "cannot delete a pointer to an incomplete type"); delete[] ptr; } }; @@ -91,6 +91,9 @@ public: /// \brief pointer to element type using pointer_t = element_t*; + /// \brief pointer to element type + using const_pointer_t = const element_t*; + /// \brief the deleter using delete_t = DeleteT; @@ -100,7 +103,7 @@ public: /// /// \brief Nullptr Constructor, creates a unique_ptr that owns nothing. - constexpr unique_ptr(nullptr_t) noexcept : unique_ptr(nullptr) {} + constexpr unique_ptr(nullptr_t) noexcept : unique_ptr(nullptr, delete_t()) {} /// /// \brief Pointer Constructor, creates a unique_ptr that owns `ptr` with deleter `del` @@ -115,7 +118,7 @@ public: /// \brief Pointer Constructor, creates a unique_ptr that owns `ptr` with deleter `del` /// \param ptr The resource to own /// \param del The deleter - explicit constexpr unique_ptr(pointer_t ptr, delete_t&& del) + explicit constexpr unique_ptr(pointer_t ptr, delete_t&& del = delete_t()) : _delete(del) , _handle(ptr) { } @@ -152,12 +155,39 @@ public: return retval; } + pointer_t get() { + return _handle; + } + + bool empty() { + return _handle == nullptr; + } + + pointer_t operator->() { + return _handle; + } + + const_pointer_t operator->() const { + return _handle; + } + private: delete_t _delete; pointer_t _handle; }; +/// +/// \brief Creates a unique pointer holding an object of type `TypeT` +/// \tparam TypeT The type +/// \tparam ArgsT The constructor arguments, automatically deduced +/// \param args The constructor arguments +/// \returns A unique pointer holding a heap allocated object of type `TypeT` constructed with arguments `args` +template +unique_ptr make_unique(ArgsT&&...args) { + return unique_ptr(new TypeT(fennec::forward(args)...)); +} + } #endif // FENNEC_MEMORY_POINTERS_H diff --git a/include/fennec/platform/interface/platform.h b/include/fennec/platform/interface/platform.h index f291e79..313bad1 100644 --- a/include/fennec/platform/interface/platform.h +++ b/include/fennec/platform/interface/platform.h @@ -21,9 +21,8 @@ #include #include -#include -#include -#include +#include +#include #include #include @@ -61,7 +60,7 @@ namespace fennec { -class platform : public typed { +class platform { public: using shared_object = struct shared_object; using symbol = void*; @@ -131,9 +130,8 @@ public: protected: template - explicit platform(const cstring& name, PlatformT* type) - : typed(type) - , name(name) { + explicit platform(const cstring& name, PlatformT*) + : name(name) { assertf(globals.singleton == nullptr, "Conflicting platform implementations!"); globals.singleton = this; } diff --git a/include/fennec/platform/interface/window.h b/include/fennec/platform/interface/window.h index 745683f..a32deab 100644 --- a/include/fennec/platform/interface/window.h +++ b/include/fennec/platform/interface/window.h @@ -31,8 +31,8 @@ #ifndef FENNEC_PLATFORM_INTERFACE_WINDOW_H #define FENNEC_PLATFORM_INTERFACE_WINDOW_H -#include -#include +#include +#include #include namespace fennec diff --git a/include/fennec/renderers/interface/gfxcontext.h b/include/fennec/renderers/interface/gfxcontext.h index 3b3f13a..d83c1b1 100644 --- a/include/fennec/renderers/interface/gfxcontext.h +++ b/include/fennec/renderers/interface/gfxcontext.h @@ -31,8 +31,8 @@ #ifndef FENNEC_RENDERERS_INTERFACE_GFXCONTEXT_H #define FENNEC_RENDERERS_INTERFACE_GFXCONTEXT_H -#include -#include +#include +#include #include #include diff --git a/include/fennec/renderers/interface/gfxpass.h b/include/fennec/renderers/interface/gfxpass.h index 7cc0577..8fe6f34 100644 --- a/include/fennec/renderers/interface/gfxpass.h +++ b/include/fennec/renderers/interface/gfxpass.h @@ -31,8 +31,8 @@ #ifndef FENNEC_PLATFORM_INTERFACE_GFXCONTEXT_H #define FENNEC_PLATFORM_INTERFACE_GFXCONTEXT_H -#include -#include +#include +#include #include namespace fennec diff --git a/include/fennec/rtti/detail/_constants.h b/include/fennec/rtti/detail/_constants.h new file mode 100644 index 0000000..b61bd1e --- /dev/null +++ b/include/fennec/rtti/detail/_constants.h @@ -0,0 +1,33 @@ +// ===================================================================================================================== +// 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_RTTI_DETAIL_CONSTANTS_H +#define FENNEC_RTTI_DETAIL_CONSTANTS_H + +#include + +namespace fennec::detail +{ + +// const char* fennec::detail::f() [with T = void] +inline static constexpr size_t type_name_f_heading = 42; +inline static constexpr size_t type_name_f_footing = 1; + +} + +#endif // FENNEC_RTTI_DETAIL_CONSTANTS_H diff --git a/include/fennec/rtti/detail/_type_name.h b/include/fennec/rtti/detail/_type_name.h new file mode 100644 index 0000000..194e2de --- /dev/null +++ b/include/fennec/rtti/detail/_type_name.h @@ -0,0 +1,53 @@ +// ===================================================================================================================== +// 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 . +// ===================================================================================================================== + +/// +/// \file _type_name.h +/// \brief +/// +/// +/// \details +/// \author Medusa Slockbower +/// +/// \copyright Copyright © 2025 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html)) +/// +/// + +#ifndef FENNEC_RTTI_DETAIL_TYPE_NAME_H +#define FENNEC_RTTI_DETAIL_TYPE_NAME_H + +#include +#include + +namespace fennec::detail +{ + +template +inline static const char* f() { + static constexpr const char* name = FENNEC_FUNCTION_NAME; + return name + type_name_f_heading; +} + +template +inline static string_view type_name() { + return string_view(f(), ::strlen(f()) - type_name_f_footing); +} + +} + +#endif // FENNEC_RTTI_DETAIL_TYPE_NAME_H \ No newline at end of file diff --git a/include/fennec/lang/detail/_typeuuid.h b/include/fennec/rtti/detail/_typeid.h similarity index 97% rename from include/fennec/lang/detail/_typeuuid.h rename to include/fennec/rtti/detail/_typeid.h index ef1f632..7fa996a 100644 --- a/include/fennec/lang/detail/_typeuuid.h +++ b/include/fennec/rtti/detail/_typeid.h @@ -19,7 +19,7 @@ #ifndef FENNEC_LANG_DETAIL_TYPEUUID_H #define FENNEC_LANG_DETAIL_TYPEUUID_H -#include +#include namespace fennec::detail { diff --git a/include/fennec/rtti/enable.h b/include/fennec/rtti/enable.h new file mode 100644 index 0000000..4e26aae --- /dev/null +++ b/include/fennec/rtti/enable.h @@ -0,0 +1,42 @@ +// ===================================================================================================================== +// 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 . +// ===================================================================================================================== + +/// +/// \file enable.h +/// \brief +/// +/// +/// \details +/// \author Medusa Slockbower +/// +/// \copyright Copyright © 2025 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html)) +/// +/// + +#ifndef FENNEC_RTTI_ENABLE_H +#define FENNEC_RTTI_ENABLE_H + +#include +#include + +#define FENNEC_RTTI_ENABLE(...) \ +public: \ + using super_class_list = fennec::typelist<__VA_ARGS__>; \ + virtual fennec::type get_type() { return fennec::type::get_from_instance(this); } + +#endif // FENNEC_RTTI_ENABLE_H \ No newline at end of file diff --git a/include/fennec/rtti/forward.h b/include/fennec/rtti/forward.h new file mode 100644 index 0000000..35620fa --- /dev/null +++ b/include/fennec/rtti/forward.h @@ -0,0 +1,34 @@ +// ===================================================================================================================== +// 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 . +// ===================================================================================================================== + +/// +/// \file forward.h +/// \brief +/// +/// +/// \details +/// \author Medusa Slockbower +/// +/// \copyright Copyright © 2025 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html)) +/// +/// + +#ifndef FENNEC_RTTI_FORWARD_H +#define FENNEC_RTTI_FORWARD_H + +#endif // FENNEC_RTTI_FORWARD_H \ No newline at end of file diff --git a/include/fennec/rtti/type.h b/include/fennec/rtti/type.h new file mode 100644 index 0000000..78d5806 --- /dev/null +++ b/include/fennec/rtti/type.h @@ -0,0 +1,86 @@ +// ===================================================================================================================== +// 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 . +// ===================================================================================================================== + +/// +/// \file type.h +/// \brief +/// +/// +/// \details +/// \author Medusa Slockbower +/// +/// \copyright Copyright © 2025 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html)) +/// +/// + +#ifndef FENNEC_RTTI_TYPE_H +#define FENNEC_RTTI_TYPE_H + +#include +#include + +namespace fennec +{ + +struct type { + + const string& name() const { + return _data->name; + } + + uint64_t id() const { + return _data->uuid; + } + + dynarray supertypes() const { + return _data->supers; + } + + dynarray subtypes() const { + return _data->subs; + } + + bool operator==(const type& c) const { + return _data == c._data; + } + + /// + /// \brief Get the type info of the specified type + /// \tparam TypeT The type to check + /// \returns A type struct containing information about TypeT + template + static type get() { return type(static_cast(nullptr)); } + + template + static type get_from_instance(TypeT* t) { return type(t); } + +private: + const type_data* const _data; + + template + type(TypeT*) : _data(type_storage::get_data()) { + } + +public: + type(type_data* d) : _data(d) { } +}; + + +} + +#endif // FENNEC_RTTI_TYPE_H \ No newline at end of file diff --git a/include/fennec/rtti/type_data.h b/include/fennec/rtti/type_data.h new file mode 100644 index 0000000..2d6d98f --- /dev/null +++ b/include/fennec/rtti/type_data.h @@ -0,0 +1,111 @@ +// ===================================================================================================================== +// 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 . +// ===================================================================================================================== + +/// +/// \file type_data.h +/// \brief +/// +/// +/// \details +/// \author Medusa Slockbower +/// +/// \copyright Copyright © 2025 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html)) +/// +/// + +#ifndef FENNEC_RTTI_TYPE_DATA_H +#define FENNEC_RTTI_TYPE_DATA_H + +#include +#include +#include +#include +#include +#include +#include + +namespace fennec +{ + +struct type_data { + uint64_t uuid; + string name; + + type_data* raw_type; + dynarray supers; + dynarray subs; +}; + +struct type_storage { +private: + template using _super_class_list = typename ClassT::super_class_list; + + static dynarray>& _typelist() { + static dynarray> typelist; + return typelist; + } + + template + static unique_ptr _make_data() { + using raw_t = remove_cvrp_t; + using supers_t = detect_t, _super_class_list, T>; + + auto res = fennec::unique_ptr(new type_data{ + .uuid = typeuuid(), + .name = detail::type_name(), + + .raw_type = typeuuid() == typeuuid() ? nullptr : type_storage::get_data(), + .supers = type_storage::get_data(supers_t{}), + .subs = {} + }); + + for (type_data* t : res->supers) { + t->subs.push_back(res.get()); + } + + return res; + } + +public: + template + static type_data* get_data() { + auto& typelist = _typelist(); + uint64_t uuid = typeuuid(); + + if (typelist.size() <= uuid) { + typelist.resize(uuid * 2); + } + + if (typelist[uuid].empty()) { + typelist[uuid] = fennec::forward>(_make_data()); + } + + return typelist[uuid].get(); + } + + template + static dynarray get_data(typelist) { + return { + get_data()... + }; + } +}; + +} + +#endif // FENNEC_RTTI_TYPE_DATA_H \ No newline at end of file diff --git a/include/fennec/lang/typed.h b/include/fennec/rtti/typeid.h similarity index 73% rename from include/fennec/lang/typed.h rename to include/fennec/rtti/typeid.h index 3d3f9c5..9a7524d 100644 --- a/include/fennec/lang/typed.h +++ b/include/fennec/rtti/typeid.h @@ -19,11 +19,8 @@ #ifndef FENNEC_LANG_TYPEUUID_H #define FENNEC_LANG_TYPEUUID_H -#include -#include -#include - -#include +#include +#include namespace fennec { @@ -40,27 +37,6 @@ FENNEC_NO_INLINE uint64_t typeuuid() { return id = detail::_typeuuid(); } -template -struct typed { -public: - const uint64_t type; - - template - bool is_type() const { - return type == typeuuid(); - } - - template - typed(TypeT*) - : type(typeuuid()) { - } - - template - static uint64_t id() { - return typeuuid(); - } -}; - } #endif // FENNEC_LANG_TYPEUUID_H diff --git a/include/fennec/rtti/typelist.h b/include/fennec/rtti/typelist.h new file mode 100644 index 0000000..75af0ba --- /dev/null +++ b/include/fennec/rtti/typelist.h @@ -0,0 +1,46 @@ +// ===================================================================================================================== +// 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 . +// ===================================================================================================================== + +/// +/// \file typelist.h +/// \brief +/// +/// +/// \details +/// \author Medusa Slockbower +/// +/// \copyright Copyright © 2025 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html)) +/// +/// + +#ifndef FENNEC_RTTI_TYPELIST_H +#define FENNEC_RTTI_TYPELIST_H + +#include + +namespace fennec +{ + +template +struct typelist { + static constexpr size_t size = sizeof...(TypesT); +}; + +} + +#endif // FENNEC_RTTI_TYPELIST_H \ No newline at end of file diff --git a/include/fennec/scene/component.h b/include/fennec/scene/component.h index 06e17f7..f43c448 100644 --- a/include/fennec/scene/component.h +++ b/include/fennec/scene/component.h @@ -23,10 +23,11 @@ #include #include #include -#include -#include -#include -#include +#include +#include +#include + +#include #define FENNEC_REGISTER_COMPONENT(T, p) \ FENNEC_STATIC_CONSTRUCTOR(T) { \ @@ -36,152 +37,15 @@ namespace fennec { -class component : public typed { +class component { public: -// TYPEDEFS & CONSTANTS ================================================================================================ - using component_create = component* (*)(size_t, size_t); - using component_destroy = void (*)(component*); - - -// TYPE OPERATIONS ===================================================================================================== - - struct typeinfo { - string name; - component_create create; - - typeinfo() - : name("") - , create(nullptr) { - } - - typeinfo(const string& name, - component_create create) - : name(name) - , create(create) { - } - }; - - struct typeentry { - string name; - uint64_t type; - }; - - using typelist_t = dynarray>; - using typetree_t = rdtree; - - -// Private Registry ==================================================================================================== -private: - - static typelist_t _typelist; // Actual list of types - static typetree_t _typetree; // Tree for displaying types under subfolders - - static constexpr size_t npos = typetree_t::npos; - static constexpr size_t root = typetree_t::root; - - static void _register_type( uint64_t id, const path& path, - component_create create) { - // Register the type - if (id > _typelist.size()) { - _typelist.resize(id + 1); - } - _typelist[id] = typeinfo{ path.filename(), create }; - - // Create tree entry - size_t node = root; - path::iterator it = path.begin(); - while (it != path.end()) { - string name = *it++; - size_t parent = node; - bool end = it == path.end(); - - node = _typetree.child(parent); - - while (node != npos && _typetree[node].type != id) { - node = _typetree.next(node); - } - - if (node == npos) { - node = _typetree.emplace( - parent, npos, - name, end ? id : nullid - ); - } - } - } - - /// - /// \brief Default creation function for a component - /// \tparam ComponentT Type of the component - /// \param node The node to associate the component with - /// \returns The component created by this function - template - static constexpr component* default_create(size_t scene, size_t node) { - return new ComponentT(scene, node); - } - - -// Public Registry ===================================================================================================== -public: - - static constexpr const typetree_t& typelist() { - return _typetree; - } - - template - static constexpr const typeinfo& type_info() { - const auto& it = _typelist[id()]; - assert(it, "Unregistered type provided to component::type_info, see stacktrace for more info."); - return *it; - } - - static constexpr const typeinfo& type_info(uint64_t type) { - const auto& it = _typelist[type]; - assert(it, "Unregistered type provided to component::type_info, see stacktrace for more info."); - return *it; - } - - /// - /// \brief Register a type with the component system - /// \tparam ComponentT The component type - /// \param path The name of the type - /// \param create The function used to create a component, given a scene node. **MUST NOT BE NULL** - template - static void register_type(const path& path, - component_create create = default_create) { - component::_register_type(id(), path, create); - } - - /// - /// \brief Create a component of type `type` - /// \param type The type to create - /// \param node The node to associate the component with - /// \returns The created component - static component* create(uint64_t type, size_t scene, size_t node) { - auto& typei = _typelist[type]; - return typei->create(scene, node); - } - - /// - /// \brief Create a component of type `type` - /// \tparam ComponentT The type to create - /// \param node The node to associate the component with - /// \returns The created component - template - static component* create(size_t scene, size_t node) { - auto& typei = _typelist[id()]; - return typei->create(scene, node); - } - // MEMBERS ============================================================================================================= public: - const size_t node; + scene_node* const node; - template - component(ComponentT* type, size_t node) - : typed(type) - , node(node) { + component(scene_node* node) + : node(node) { } }; diff --git a/include/fennec/scene/forward.h b/include/fennec/scene/forward.h new file mode 100644 index 0000000..d4cae38 --- /dev/null +++ b/include/fennec/scene/forward.h @@ -0,0 +1,43 @@ +// ===================================================================================================================== +// 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 . +// ===================================================================================================================== + +/// +/// \file forward.h +/// \brief +/// +/// +/// \details +/// \author Medusa Slockbower +/// +/// \copyright Copyright © 2025 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html)) +/// +/// + +#ifndef FENNEC_SCENE_FORWARD_H +#define FENNEC_SCENE_FORWARD_H + +namespace fennec +{ + +class scene; +struct scene_node; +class component; + +} + +#endif // FENNEC_SCENE_FORWARD_H \ No newline at end of file diff --git a/include/fennec/scene/node2d.h b/include/fennec/scene/node2d.h index 7a98ce1..2e52908 100644 --- a/include/fennec/scene/node2d.h +++ b/include/fennec/scene/node2d.h @@ -33,11 +33,23 @@ #include #include + +#include + #include + namespace fennec { +struct node2d; + +struct transform_update_2d : event { + node2d* node; + + FENNEC_RTTI_ENABLE(event); +}; + struct node2d : scene_node { // Definitions ========================================================================================================= @@ -52,8 +64,21 @@ public: /// /// \brief Default Constructor, initializes an identity matrix. - node2d(size_t id, size_t scene, const string& name) - : scene_node(name, id, scene) + /// \details This is the default node2d constructor, for inheritance, use the typed constructor + node2d(fennec::scene* scn, size_t id, const string& name) + : scene_node(scn, id, name) + , _mobility(mobility_free) + , _position(0, 0) + , _scale(1, 1) + , _shear(0, 0) + , _rotation(0) { + } + + /// + /// \brief Default Typed Constructor, initializes an identity matrix with proper typing for inheritance. + template + node2d(fennec::scene* scn, size_t id, const string& name, TypeT* type) + : scene_node(scn, id, name, type) , _mobility(mobility_free) , _position(0, 0) , _scale(1, 1) @@ -123,7 +148,7 @@ public: // Get parent - _recalculate(); + // Propagate down diff --git a/include/fennec/scene/scene.h b/include/fennec/scene/scene.h index 4fadfa9..32479c8 100644 --- a/include/fennec/scene/scene.h +++ b/include/fennec/scene/scene.h @@ -20,9 +20,9 @@ #define FENNEC_CORE_SCENE_H #include -#include -#include -#include +#include + +#include namespace fennec @@ -33,7 +33,7 @@ namespace fennec /// \details This structure only contains the names of nodes and defers storage for components to /// their respective systems. Simple components may be isolated, \see components.h for more info. /// The hierarchy should be displayed using pre-order traversal. -class scene : public rdtree { +class scene : private rdtree { // Access ============================================================================================================== public: @@ -42,44 +42,16 @@ public: /// \details If multiple nodes have the same name, finds the first one in pre-order traversal. /// \param name The name of the node to search for /// \returns The id of the node, `npos` if not found. - size_t operator[](const cstring& name) const { - list parse; - parse.push_back(root); - while (not parse.empty()) { - size_t n = parse.front(); - if (_table[n].value->name == name) { - return n; - } - - // Pre-Order traversal - parse.push_front(next(n)); - parse.push_front(child(n)); - parse.pop_front(); - } - return npos; - } + scene_node* operator[](const cstring& name) const; /// /// \brief Find a node by name. /// \details If multiple nodes have the same name, finds the first one in pre-order traversal. /// \param name The name of the node to search for /// \returns The id of the node, `npos` if not found. - size_t operator[](const string& name) const { - list parse; - parse.push_back(root); - while (not parse.empty()) { - size_t n = parse.front(); - if (_table[n].value->name == name) { - return n; - } + scene_node* operator[](const string& name) const; + - // Pre-Order traversal - parse.push_front(next(n)); - parse.push_front(child(n)); - parse.pop_front(); - } - return npos; - } }; } diff --git a/include/fennec/scene/scene_node.h b/include/fennec/scene/scene_node.h index f297235..1b00985 100644 --- a/include/fennec/scene/scene_node.h +++ b/include/fennec/scene/scene_node.h @@ -31,51 +31,32 @@ #ifndef FENNEC_SCENE_NODE_H #define FENNEC_SCENE_NODE_H -#include -#include -#include +#include -#include +#include +#include namespace fennec { -struct scene_node_ref { - size_t scene; - size_t id; -}; - -struct scene_node : typed { +struct scene_node { // Public Members ====================================================================================================== public: - union { - struct { - const size_t scene; - const size_t id; - }; - const scene_node_ref ref; - }; + scene* const scene; + const size_t id; string name; - scene_node(size_t scene, size_t id, string name) - : scene(scene), id(id), name(std::move(name)) { - } - - template - component* add_component() { - _components.push_back(component::create(scene, id)); - return _components.back(); - } - - component* add_component(uint64_t type) { - _components.push_back(component::create(type, scene, id)); - return _components.back(); + scene_node(fennec::scene* scn, size_t id, const string& name) + : scene(scn), id(id) + , name(fennec::move(name)) { } private: dynarray _components; + + FENNEC_RTTI_ENABLE(); }; } diff --git a/metaprogramming/CMakeLists.txt b/metaprogramming/CMakeLists.txt index 5c1a710..beea5f2 100644 --- a/metaprogramming/CMakeLists.txt +++ b/metaprogramming/CMakeLists.txt @@ -5,12 +5,17 @@ set(CMAKE_CXX_STANDARD 23) add_executable(fennec-metaprogramming main.cpp float.h - integer.h) + integer.h + type_name.h) + +target_compile_definitions(fennec-metaprogramming PUBLIC + ${FENNEC_COMPILE_DEFINITIONS} +) add_custom_command( OUTPUT .metaprogramming COMMAND fennec-metaprogramming - WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/../include/fennec/lang" + WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/../include/" COMMENT "Generating intrinsics" VERBATIM ) diff --git a/metaprogramming/float.h b/metaprogramming/float.h index 7b3d5ed..8870e4a 100644 --- a/metaprogramming/float.h +++ b/metaprogramming/float.h @@ -24,7 +24,7 @@ inline void float_h() { - std::ofstream out("float.h"); + std::ofstream out("fennec/langcpp/float.h"); out << "// =====================================================================================================================" << std::endl; out << "// fennec, a free and open source game engine" << std::endl; @@ -64,7 +64,7 @@ inline void float_h() out << "" << std::endl; - out << "#include " << std::endl; + out << "#include " << std::endl; out << "" << std::endl; diff --git a/metaprogramming/integer.h b/metaprogramming/integer.h index d2aef65..4cba69e 100644 --- a/metaprogramming/integer.h +++ b/metaprogramming/integer.h @@ -24,7 +24,7 @@ inline void integer_h() { - std::ofstream out("integer.h"); + std::ofstream out("fennec/langcpp/integer.h"); out << "// =====================================================================================================================" << std::endl; out << "// fennec, a free and open source game engine" << std::endl; diff --git a/metaprogramming/main.cpp b/metaprogramming/main.cpp index 09c88a8..fd8ce48 100644 --- a/metaprogramming/main.cpp +++ b/metaprogramming/main.cpp @@ -21,9 +21,11 @@ #include "float.h" #include "integer.h" +#include "type_name.h" int main(int, const char**) { float_h(); integer_h(); + type_name_h(); } diff --git a/metaprogramming/type_name.h b/metaprogramming/type_name.h new file mode 100644 index 0000000..0319c65 --- /dev/null +++ b/metaprogramming/type_name.h @@ -0,0 +1,107 @@ +// ===================================================================================================================== +// 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 . +// ===================================================================================================================== + +/// +/// \file type_name.h +/// \brief +/// +/// +/// \details +/// \author Medusa Slockbower +/// +/// \copyright Copyright © 2025 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html)) +/// +/// + +#ifndef FENNEC_METAPROGRAMMING_TYPE_NAME_H +#define FENNEC_METAPROGRAMMING_TYPE_NAME_H + +#include + +namespace fennec::detail +{ + +template +inline static const char* f() { + return __PRETTY_FUNCTION__; +} + +} + +inline void type_name_h() +{ + + std::ofstream out("fennec/rtti/detail/_constants.h"); + + out << "// =====================================================================================================================" << std::endl; + out << "// fennec, a free and open source game engine" << std::endl; + out << "// Copyright © 2025 Medusa Slockbower" << std::endl; + out << "//" << std::endl; + out << "// This program is free software: you can redistribute it and/or modify" << std::endl; + out << "// it under the terms of the GNU General Public License as published by" << std::endl; + out << "// the Free Software Foundation, either version 3 of the License, or" << std::endl; + out << "// (at your option) any later version." << std::endl; + out << "//" << std::endl; + out << "// This program is distributed in the hope that it will be useful," << std::endl; + out << "// but WITHOUT ANY WARRANTY; without even the implied warranty of" << std::endl; + out << "// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the" << std::endl; + out << "// GNU General Public License for more details." << std::endl; + out << "//" << std::endl; + out << "// You should have received a copy of the GNU General Public License" << std::endl; + out << "// along with this program. If not, see ." << std::endl; + out << "// =====================================================================================================================" << std::endl; + + out << "" << std::endl; + + out << "#ifndef FENNEC_RTTI_DETAIL_CONSTANTS_H" << std::endl; + out << "#define FENNEC_RTTI_DETAIL_CONSTANTS_H" << std::endl; + + out << "" << std::endl; + + out << "#include " << std::endl; + + out << "" << std::endl; + + out << "namespace fennec::detail" << std::endl; + out << "{" << std::endl; + out << "" << std::endl; + + + std::string str = fennec::detail::f(); + size_t heading = str.find("void"); + size_t footing = str.size() - (heading + 4); + + out << "// " << str << std::endl; + out << "inline static constexpr size_t type_name_f_heading = " << heading << ";" << std::endl; + out << "inline static constexpr size_t type_name_f_footing = " << footing << ";" << std::endl; + + + out << "" << std::endl; + out << "}" << std::endl; + + out << "" << std::endl; + + out << "#endif // FENNEC_RTTI_DETAIL_CONSTANTS_H" << std::endl; + + out.close(); + + return; +} + + +#endif // FENNEC_METAPROGRAMMING_TYPE_NAME_H \ No newline at end of file diff --git a/planning/CONTENTS.md b/planning/CONTENTS.md index 594b2fc..222ce3f 100644 --- a/planning/CONTENTS.md +++ b/planning/CONTENTS.md @@ -11,7 +11,7 @@ * [Introduction](#introduction) * [Definitions](#definitions) * [Libraries](#libraries) - * [C++ Language Library](./CPP_LANGUAGE.md#c-language-library-lang) + * [C++ Language Library](./CPP_LANGUAGE.md#c-language-library-langcpp) * [Platform Support Library](./PLATFORM_SUPPORT.md#platform-support-library-platform) @@ -71,8 +71,8 @@ denote implementation and testing progress. The symbols are defined below. ## Libraries - - [C++ Language Library](./CPP_LANGUAGE.md#c-language-library-lang) + - [C++ Language Library](./CPP_LANGUAGE.md#c-language-library-langcpp) - [Platform Support Library](./PLATFORM_SUPPORT.md#platform-support-library-platform) - [Memory Library](./MEMORY.md#memory-library-memory) - [Containers Library](./CONTAINERS.md#containers-library-containers) - - [Language Processing Library](./LANGUAGE_PROCESSING.md#language-processing-library-langproc) \ No newline at end of file + - [Language Processing Library](./LANGUAGE_PROCESSING.md#language-processing-library-lang) \ No newline at end of file diff --git a/planning/CPP_LANGUAGE.md b/planning/CPP_LANGUAGE.md index 8e8a092..4e82157 100644 --- a/planning/CPP_LANGUAGE.md +++ b/planning/CPP_LANGUAGE.md @@ -1,13 +1,13 @@ -# C++ Language Library (`lang`) +# C++ Language Library (`langcpp`) ## Table of Contents * [Home](./CONTENTS.md#planning-documentation-for-fennec) -* [C++ Language Library](#c-language-library-lang) +* [C++ Language Library](#c-language-library-langcpp) * [Table of Contents](#table-of-contents) * [Introduction](#introduction) * [Implementation](#implementation) diff --git a/planning/LANGUAGE_PROCESSING.md b/planning/LANGUAGE_PROCESSING.md index 69b94b7..9450847 100644 --- a/planning/LANGUAGE_PROCESSING.md +++ b/planning/LANGUAGE_PROCESSING.md @@ -1,16 +1,16 @@ -# Language Processing Library (`langproc`) +# Language Processing Library (`lang`) ## Table of Contents * [Home](./CONTENTS.md#planning-documentation-for-fennec) -* [Language Processing Library (`langproc`)](#language-processing-library-langproc) +* [Language Processing Library (`lang`)](#language-processing-library-lang) * [Table of Contents](#table-of-contents) * [Introduction](#introduction) - * [String Analysis (`langproc/strings`)](#string-analysis-langprocstrings) + * [String Analysis (`lang/strings`)](#string-analysis-langprocstrings) * [Implementation](#implementation) * [File System (`filesystem`)](#file-system-filesystem) * [Implementation](#implementation-1) @@ -27,7 +27,7 @@ and programming languages. this is through Doxygen and LaTeX. Consider including binaries with releases. -## String Analysis (`langproc/strings`) +## String Analysis (`lang/strings`)   fennec reimplements the C++ Strings Library as a submodule of this library. This is because C++ `std::string` has a lot of overhead. I would say that `std::string` @@ -61,7 +61,7 @@ is create C++ classes that handle file streams, directory streams, and file path -## Interpreter (`langproc/parse`) +## Interpreter (`lang/parse`)   This submodule will contain classes for parsing data. We will need to be able to do the following things to achieve support for files that adhere to a @@ -96,7 +96,7 @@ data values (e.g. floats, ints, etc.) to a readable language (e.g. ascii/utf8/ut -## Formats (`langproc/formats`) +## Formats (`lang/formats`)   This submodule will contain classes for processing a variety of file formats. diff --git a/source/core/event.cpp b/source/core/event.cpp index 8e989a3..441c2a2 100644 --- a/source/core/event.cpp +++ b/source/core/event.cpp @@ -39,7 +39,7 @@ void event::remove_listener(event_listener* listener) { } void event::dispatch(event* event) { - for (auto& it : listeners[event->type]) { + for (auto& it : listeners[event->get_type().id()]) { it->handle_event(event); } } diff --git a/source/langproc/filesystem/file.cpp b/source/lang/filesystem/file.cpp similarity index 99% rename from source/langproc/filesystem/file.cpp rename to source/lang/filesystem/file.cpp index f5cebc8..2265495 100644 --- a/source/langproc/filesystem/file.cpp +++ b/source/lang/filesystem/file.cpp @@ -21,8 +21,8 @@ #include #include -#include -#include +#include +#include #ifdef FENNEC_COMPILER_MSVC diff --git a/source/langproc/filesystem/path.cpp b/source/lang/filesystem/path.cpp similarity index 97% rename from source/langproc/filesystem/path.cpp rename to source/lang/filesystem/path.cpp index 4ace64b..57fc745 100644 --- a/source/langproc/filesystem/path.cpp +++ b/source/lang/filesystem/path.cpp @@ -17,7 +17,7 @@ // ===================================================================================================================== -#include +#include namespace fennec { diff --git a/source/lang/assert.cpp b/source/langcpp/assert.cpp similarity index 97% rename from source/lang/assert.cpp rename to source/langcpp/assert.cpp index 2851d29..adf325e 100644 --- a/source/lang/assert.cpp +++ b/source/langcpp/assert.cpp @@ -16,7 +16,7 @@ // along with this program. If not, see . // ===================================================================================================================== -#include +#include using assert_handler = void (*)(const char *, const char *, int , const char *); diff --git a/source/memory/new.cpp b/source/memory/new.cpp index dc2b694..8c3513b 100644 --- a/source/memory/new.cpp +++ b/source/memory/new.cpp @@ -16,7 +16,7 @@ // along with this program. If not, see . // ===================================================================================================================== -#include +#include #include diff --git a/source/platform/linux/platform.cpp b/source/platform/linux/platform.cpp index 3175c5d..74a1f8f 100644 --- a/source/platform/linux/platform.cpp +++ b/source/platform/linux/platform.cpp @@ -16,10 +16,10 @@ // along with this program. If not, see . // ===================================================================================================================== -#include +#include #include -#include +#include namespace fennec { diff --git a/source/scene/scene.cpp b/source/scene/scene.cpp new file mode 100644 index 0000000..835a1a4 --- /dev/null +++ b/source/scene/scene.cpp @@ -0,0 +1,71 @@ +// ===================================================================================================================== +// 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 . +// ===================================================================================================================== + +/// +/// \file scene.h +/// \brief +/// +/// +/// \details +/// \author Medusa Slockbower +/// +/// \copyright Copyright © 2025 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html)) +/// +/// + +#include +#include + +namespace fennec +{ + +scene_node* scene::operator[](const cstring& name) const { + list parse; + parse.push_back(root); + while (not parse.empty()) { + size_t n = parse.front(); + if (_table[n].value->name == name) { + return _table[n].value; + } + + // Pre-Order traversal + parse.push_front(next(n)); + parse.push_front(child(n)); + parse.pop_front(); + } + return nullptr; +} + +scene_node* scene::operator[](const string& name) const { + list parse; + parse.push_back(root); + while (not parse.empty()) { + size_t n = parse.front(); + if (_table[n].value->name == name) { + return _table[n].value; + } + + // Pre-Order traversal + parse.push_front(next(n)); + parse.push_front(child(n)); + parse.pop_front(); + } + return nullptr; +} + +} diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 226776b..47d89e7 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -8,8 +8,10 @@ add_executable(fennec-test main.cpp tests/containers/performance/test_iterator_visitor.h tests/containers/test_sequence.h - tests/langproc/test_format.h + tests/lang/test_format.h tests/containers/test_priority_queue.h + tests/lang/strings/test_string.h + tests/test_rtti.h ) target_compile_definitions(fennec-test PUBLIC FENNEC_TEST_CWD="${CMAKE_SOURCE_DIR}/bin/${FENNEC_BUILD_NAME}" diff --git a/test/main.cpp b/test/main.cpp index 433ef20..5fdcd93 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -24,6 +24,7 @@ #include "tests/test_containers.h" #include "tests/test_langproc.h" #include "tests/test_platform.h" +#include "tests/test_rtti.h" int main(int, char **) { @@ -58,5 +59,10 @@ int main(int, char **) fennec::test::fennec_test_platform(); fennec_test_spacer(3); + fennec_test_header("rtti library"); + fennec_test_spacer(2); + fennec::test::fennec_test_rtti(); + fennec_test_spacer(3); + return 0; } diff --git a/test/printing.h b/test/printing.h index 723cf3e..7f23483 100644 --- a/test/printing.h +++ b/test/printing.h @@ -20,14 +20,17 @@ #define FENNEC_TEST_PRINTING_H #include -#include -#include + +#include +#include #include #include #include #include +#include + namespace fennec { @@ -73,6 +76,11 @@ inline std::ostream& operator<<(std::ostream& os, const path& str) { return os << str.str(); } +// Helper for printing types +inline std::ostream& operator<<(std::ostream& os, const type& t) { + return os << t.name(); +} + } } diff --git a/test/test.h b/test/test.h index 441f166..4145b63 100644 --- a/test/test.h +++ b/test/test.h @@ -23,7 +23,7 @@ #include #include -#include +#include #include #include "printing.h" diff --git a/test/tests/containers/test_map.h b/test/tests/containers/test_map.h index a0afb8d..201c878 100644 --- a/test/tests/containers/test_map.h +++ b/test/tests/containers/test_map.h @@ -20,7 +20,7 @@ #define FENNEC_TEST_CONTAINERS_MAP_H #include -#include +#include namespace fennec::test { diff --git a/test/tests/containers/test_rdtree.h b/test/tests/containers/test_rdtree.h index da471bd..2a309d2 100644 --- a/test/tests/containers/test_rdtree.h +++ b/test/tests/containers/test_rdtree.h @@ -53,6 +53,10 @@ inline void fennec_test_containers_rdtree() { assertf(next == rdtree::npos || test.prev(next) == l, "Tree Construct Test Failed"); } + tree_t insert; + insert.insert(npos, 0, test); + assertf(insert.size() == test.size(), "Tree Insert Tree Test Failed"); + fennec_test_spacer(1); test.erase(0); diff --git a/test/tests/containers/test_tuple.h b/test/tests/containers/test_tuple.h index 996c1c4..ca479d4 100644 --- a/test/tests/containers/test_tuple.h +++ b/test/tests/containers/test_tuple.h @@ -19,7 +19,7 @@ #ifndef FENNEC_TEST_CONTAINERS_TUPLE_H #define FENNEC_TEST_CONTAINERS_TUPLE_H #include -#include +#include namespace fennec { diff --git a/test/tests/langproc/strings/test_cstring.h b/test/tests/lang/strings/test_cstring.h similarity index 97% rename from test/tests/langproc/strings/test_cstring.h rename to test/tests/lang/strings/test_cstring.h index 93d1702..ff0f9bb 100644 --- a/test/tests/langproc/strings/test_cstring.h +++ b/test/tests/lang/strings/test_cstring.h @@ -21,7 +21,7 @@ #include "../../../test.h" -#include +#include namespace fennec::test { @@ -45,7 +45,6 @@ namespace fennec::test fennec_test_run(str.find("World"), static_cast(6)); fennec_test_run(str.rfind('o'), static_cast(7)); fennec_test_run(str.rfind("World"), static_cast(6)); - } } diff --git a/test/tests/lang/strings/test_string.h b/test/tests/lang/strings/test_string.h new file mode 100644 index 0000000..0b0368b --- /dev/null +++ b/test/tests/lang/strings/test_string.h @@ -0,0 +1,57 @@ +// ===================================================================================================================== +// 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 . +// ===================================================================================================================== + +/// +/// \file test_string.h +/// \brief +/// +/// +/// \details +/// \author Medusa Slockbower +/// +/// \copyright Copyright © 2025 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html)) +/// +/// + +#ifndef FENNEC_TEST_LANGPROC_STRINGS_STRING_H +#define FENNEC_TEST_LANGPROC_STRINGS_STRING_H + +#include + +#include "../../../test.h" + +namespace fennec::test +{ + +inline void fennec_test_langproc_strings_string() { + + string test0 = string("test0"); + string test1 = string("test1"); + + fennec_test_run(test0, test0); + fennec_test_run(test1, test1); + + fennec_test_spacer(1); + + fennec_test_run(test1 = test0, test0); + +} + +} + +#endif // FENNEC_TEST_LANGPROC_STRINGS_STRING_H \ No newline at end of file diff --git a/test/tests/langproc/test_format.h b/test/tests/lang/test_format.h similarity index 97% rename from test/tests/langproc/test_format.h rename to test/tests/lang/test_format.h index 7dc3ab4..a7e6256 100644 --- a/test/tests/langproc/test_format.h +++ b/test/tests/lang/test_format.h @@ -30,7 +30,7 @@ #ifndef FENNEC_TEST_LANGPROC_FORMAT_H #define FENNEC_TEST_LANGPROC_FORMAT_H -#include +#include namespace fennec { diff --git a/test/tests/langproc/test_io.h b/test/tests/lang/test_io.h similarity index 97% rename from test/tests/langproc/test_io.h rename to test/tests/lang/test_io.h index 63e1408..3b1d243 100644 --- a/test/tests/langproc/test_io.h +++ b/test/tests/lang/test_io.h @@ -21,8 +21,8 @@ #include "../../test.h" -#include -#include +#include +#include namespace fennec::test { diff --git a/test/tests/langproc/test_strings.h b/test/tests/lang/test_strings.h similarity index 89% rename from test/tests/langproc/test_strings.h rename to test/tests/lang/test_strings.h index b4a14f3..826642a 100644 --- a/test/tests/langproc/test_strings.h +++ b/test/tests/lang/test_strings.h @@ -21,6 +21,7 @@ #include "../../test.h" #include "./strings/test_cstring.h" +#include "./strings/test_string.h" namespace fennec::test { @@ -32,6 +33,12 @@ namespace fennec::test fennec_test_langproc_strings_cstring(); fennec_test_spacer(3); + + fennec_test_subheader("string"); + fennec_test_spacer(2); + fennec_test_langproc_strings_string(); + fennec_test_spacer(3); + // TODO } diff --git a/test/tests/lang/test_bits.h b/test/tests/langcpp/test_bits.h similarity index 96% rename from test/tests/lang/test_bits.h rename to test/tests/langcpp/test_bits.h index ed33d2a..4b42f2c 100644 --- a/test/tests/lang/test_bits.h +++ b/test/tests/langcpp/test_bits.h @@ -19,8 +19,8 @@ #ifndef FENNEC_TEST_LANG_BITS_H #define FENNEC_TEST_LANG_BITS_H -#include -#include +#include +#include #include "../../test.h" diff --git a/test/tests/lang/test_conditional_types.h b/test/tests/langcpp/test_conditional_types.h similarity index 100% rename from test/tests/lang/test_conditional_types.h rename to test/tests/langcpp/test_conditional_types.h diff --git a/test/tests/lang/test_hashing.h b/test/tests/langcpp/test_hashing.h similarity index 98% rename from test/tests/lang/test_hashing.h rename to test/tests/langcpp/test_hashing.h index 78f24da..6011b01 100644 --- a/test/tests/lang/test_hashing.h +++ b/test/tests/langcpp/test_hashing.h @@ -19,7 +19,7 @@ #ifndef FENNEC_TEST_LANG_HASHING_H #define FENNEC_TEST_LANG_HASHING_H -#include +#include #include "../../test.h" namespace fennec::test diff --git a/test/tests/lang/test_sequences.h b/test/tests/langcpp/test_sequences.h similarity index 97% rename from test/tests/lang/test_sequences.h rename to test/tests/langcpp/test_sequences.h index 9b213f5..7690269 100644 --- a/test/tests/lang/test_sequences.h +++ b/test/tests/langcpp/test_sequences.h @@ -19,7 +19,7 @@ #ifndef FENNEC_TEST_LANG_SEQUENCES_H #define FENNEC_TEST_LANG_SEQUENCES_H -#include +#include namespace fennec::test { diff --git a/test/tests/test_lang.h b/test/tests/test_lang.h index 0b4cfb3..8fd1628 100644 --- a/test/tests/test_lang.h +++ b/test/tests/test_lang.h @@ -19,9 +19,9 @@ #ifndef FENNEC_TEST_LANG_H #define FENNEC_TEST_LANG_H -#include "lang/test_bits.h" -#include "lang/test_conditional_types.h" -#include "lang/test_hashing.h" +#include "langcpp/test_bits.h" +#include "langcpp/test_conditional_types.h" +#include "langcpp/test_hashing.h" namespace fennec::test { diff --git a/test/tests/test_langproc.h b/test/tests/test_langproc.h index 7278f89..bef9054 100644 --- a/test/tests/test_langproc.h +++ b/test/tests/test_langproc.h @@ -21,9 +21,9 @@ #include "../test.h" -#include "./langproc/test_strings.h" -#include "./langproc/test_io.h" -#include "langproc/test_format.h" +#include "./lang/test_strings.h" +#include "./lang/test_io.h" +#include "lang/test_format.h" namespace fennec::test { diff --git a/test/tests/test_rtti.h b/test/tests/test_rtti.h new file mode 100644 index 0000000..3d20aad --- /dev/null +++ b/test/tests/test_rtti.h @@ -0,0 +1,67 @@ +// ===================================================================================================================== +// 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 . +// ===================================================================================================================== + +/// +/// \file test_rtti.h +/// \brief +/// +/// +/// \details +/// \author Medusa Slockbower +/// +/// \copyright Copyright © 2025 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html)) +/// +/// + +#ifndef FENNEC_TEST_RTTI_H +#define FENNEC_TEST_RTTI_H + +#include +#include +#include +#include +#include + +#include "../test.h" + + +namespace fennec::test +{ + +struct rtti_test_base { + FENNEC_RTTI_ENABLE(); +}; + +struct rtti_test_sub : rtti_test_base { + FENNEC_RTTI_ENABLE(rtti_test_base); +}; + +inline void fennec_test_rtti() { + + fennec_test_run(string(detail::type_name()), string("int")); + fennec_test_run(type::get(), type::get()); + + fennec_test_run(type::get().name(), string(detail::type_name())); + fennec_test_run(type::get().supertypes()[0].name(), string(detail::type_name())); + fennec_test_run(type::get().subtypes()[0].name(), string(detail::type_name())); + +} + +} + +#endif // FENNEC_TEST_RTTI_H \ No newline at end of file