- Updated Coding Standards and adjusted code to fit.
- Restructured test for organization purposes
This commit is contained in:
@@ -38,21 +38,21 @@
|
||||
namespace fennec
|
||||
{
|
||||
|
||||
template<class T, class Alloc>
|
||||
template<class TypeT, class Alloc>
|
||||
class dynarray
|
||||
{
|
||||
public:
|
||||
using element_t = T;
|
||||
using element_t = TypeT;
|
||||
using alloc_t = Alloc;
|
||||
|
||||
///
|
||||
/// \brief Default Constructor, initializes an empty allocation.
|
||||
dynarray() : _alloc(), _size(0) {}
|
||||
dynarray() : _alloc(8), _size(0) {}
|
||||
|
||||
///
|
||||
/// \breif Alloc Constructor, initalize empty allocation with allocator instance.
|
||||
/// \param alloc An allocator object to copy, for instances where the allocator needs to be initialized with some data.
|
||||
dynarray(const alloc_t& alloc) : _alloc(alloc), _size(0) {}
|
||||
dynarray(const alloc_t& alloc) : _alloc(8, alloc), _size(0) {}
|
||||
|
||||
///
|
||||
/// \brief Create an allocation with a size of `n` elements. All elements are initialized with the default constructor.
|
||||
@@ -62,10 +62,16 @@ public:
|
||||
for(; n > 0; --n, ++addr) { fennec::construct(addr); }
|
||||
}
|
||||
|
||||
dynarray(size_t n, const alloc_t& alloc) : _alloc(n, alloc), _size(n)
|
||||
{
|
||||
element_t* addr = _alloc.data();
|
||||
for(; n > 0; --n, ++addr) { fennec::construct(addr); }
|
||||
}
|
||||
|
||||
///
|
||||
/// \brief Create an allocation of size `n`, with each element constructed using the copy constructor
|
||||
/// \brief n the number of elements
|
||||
dynarray(size_t n, const element_t& val)
|
||||
dynarray(size_t n, const TypeT& val)
|
||||
{
|
||||
element_t* addr = _alloc.data();
|
||||
for(; n > 0; --n, ++addr) { fennec::construct(addr, val); }
|
||||
@@ -84,7 +90,73 @@ public:
|
||||
for(; n > 0; --n, ++addr) { fennec::destruct(addr); }
|
||||
}
|
||||
|
||||
size_t size() const { return _size; }
|
||||
|
||||
size_t capacity() const { return _alloc.capacity(); }
|
||||
|
||||
TypeT& operator[](size_t i) { return _alloc.data()[i]; }
|
||||
const TypeT& operator[](size_t i) const { return _alloc.data()[i]; }
|
||||
|
||||
void insert(size_t i, const TypeT& val)
|
||||
{
|
||||
// Grow if the size has reached the capacity of the allocation
|
||||
if(_size == capacity()) _grow();
|
||||
|
||||
// Move the data if we are not inserting at the end of the array
|
||||
if((i = fennec::min(i, _size) < _size) {
|
||||
fennec::memmove(
|
||||
_alloc.data() + i
|
||||
, _alloc.data() + i + 1
|
||||
, (_size - i) * sizeof(TypeT));
|
||||
}
|
||||
|
||||
// Insert the element
|
||||
fennec::construct(_alloc.data() + i, val);
|
||||
}
|
||||
|
||||
void insert(size_t i, TypeT&& val)
|
||||
{
|
||||
// Grow if the size has reached the capacity of the allocation
|
||||
if(_size == capacity()) _grow();
|
||||
|
||||
// Move the data if we are not inserting at the end of the array
|
||||
if((i = fennec::min(i, _size) < _size) {
|
||||
fennec::memmove(
|
||||
_alloc.data() + i
|
||||
, _alloc.data() + i + 1
|
||||
, (_size - i) * sizeof(TypeT));
|
||||
}
|
||||
|
||||
// Insert the element
|
||||
fennec::construct(_alloc.data() + i, fennec::forward(val));
|
||||
}
|
||||
|
||||
template<typename...ArgsT>
|
||||
void emplace(size_t i, ArgsT...args)
|
||||
{
|
||||
// Grow if the size has reached the capacity of the allocation
|
||||
if(_size == capacity()) _grow();
|
||||
|
||||
// Move the data if we are not inserting at the end of the array
|
||||
if((i = fennec::min(i, _size) < _size) {
|
||||
fennec::memmove(
|
||||
_alloc.data() + i
|
||||
, _alloc.data() + i + 1
|
||||
, (_size - i) * sizeof(TypeT));
|
||||
}
|
||||
|
||||
// Insert the element
|
||||
fennec::construct(_alloc.data() + i, fennec::forward<ArgsT>(args)...);
|
||||
}
|
||||
|
||||
void push_back(const TypeT& val) { insert(_size, val); }
|
||||
void push_back(TypeT&& val) { insert(_size, fennec::forward(val)); }
|
||||
|
||||
template<typename...ArgsT> void emplace_back(ArgsT...args) { emplace(_size, fennec::forward<ArgsT>(args)...); }
|
||||
|
||||
private:
|
||||
void _grow() const { _alloc.reallocate(_alloc.capacity() * 2); }
|
||||
|
||||
allocation<element_t, alloc_t> _alloc;
|
||||
size_t _size;
|
||||
};
|
||||
|
||||
@@ -31,23 +31,30 @@
|
||||
///
|
||||
/// \page page_fennec_documentation Documentation
|
||||
///
|
||||
/// \section page_documentation_contents Main Page
|
||||
/// \section page_fennec_documentation_pages Pages
|
||||
/// 1. \ref introduction "Introduction"
|
||||
/// 2. \ref introduction "Building from Source"
|
||||
/// 1. \ref building-from-source "Building from Source"
|
||||
/// 2. \ref building-from-terminal "Building from Terminal"
|
||||
/// 3. \ref running-the-test-suite "Running the Test Suite"
|
||||
/// 3. \ref usage "Usage"
|
||||
/// 4. \ref contribution "Contribution"
|
||||
///
|
||||
/// \section Libraries
|
||||
/// \anchor libraries
|
||||
/// - \subpage page_fennec_lang
|
||||
/// - \subpage page_fennec_math
|
||||
/// 1. \ref coding-standards "Coding Standards"
|
||||
/// 2. \ref building-from-source "Building from Source"
|
||||
/// 1. \ref building-from-terminal "Building from Terminal"
|
||||
/// 2. \ref building-on-windows "Building on Windows"
|
||||
/// 3. \ref running-the-test-suite "Running the Test Suite"
|
||||
/// 4. \ref usage "Usage"
|
||||
/// 5. \ref contribution "Contribution"
|
||||
/// 6. \subpage page_fennec_libraries
|
||||
/// 1. \ref page_fennec_lang "C++ Language Library"
|
||||
/// 2. \ref page_fennec_math "Math Library"
|
||||
///
|
||||
/// \copyright Copyright © 2025 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html))
|
||||
///
|
||||
|
||||
///
|
||||
/// \page page_fennec_libraries Libraries
|
||||
///
|
||||
/// | Library | Brief |
|
||||
/// | :------------------------ | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
||||
/// | \subpage page_fennec_lang | Implementation for functions and classes related to the C++ Language, including base types, common utility functions, and metaprogramming templates |
|
||||
/// | \subpage page_fennec_math | Implementation of math functions according to the [OpenGL 4.6 Shading Language Specification](https://registry.khronos.org/OpenGL/specs/gl/GLSLangSpec.4.60.pdf). Additional extensions are provided for other common math functions. |
|
||||
|
||||
#ifndef FENNEC_CORE_ENGINE_H
|
||||
#define FENNEC_CORE_ENGINE_H
|
||||
|
||||
|
||||
@@ -29,8 +29,8 @@
|
||||
///
|
||||
|
||||
|
||||
#ifndef CONDITIONAL_TYPES_H
|
||||
#define CONDITIONAL_TYPES_H
|
||||
#ifndef FENNEC_LANG_CONDITIONAL_TYPES_H
|
||||
#define FENNEC_LANG_CONDITIONAL_TYPES_H
|
||||
|
||||
#include <fennec/lang/type_transforms.h>
|
||||
#include <fennec/lang/types.h>
|
||||
@@ -106,4 +106,4 @@ using detect_t
|
||||
|
||||
}
|
||||
|
||||
#endif //CONDITIONAL_TYPES_H
|
||||
#endif // FENNEC_LANG_CONDITIONAL_TYPES_H
|
||||
|
||||
@@ -29,7 +29,6 @@ namespace detail
|
||||
{
|
||||
|
||||
// Nothing interesting to note here
|
||||
|
||||
template<typename> struct __is_void : false_type {};
|
||||
template<> struct __is_void<void> : true_type {};
|
||||
|
||||
|
||||
@@ -27,6 +27,9 @@
|
||||
///
|
||||
///
|
||||
|
||||
#ifndef FENNEC_LANG_FLOAT_H
|
||||
#define FENNEC_LANG_FLOAT_H
|
||||
|
||||
#include <fennec/memory/bits.h>
|
||||
|
||||
#define FLT_HAS_INFINITY 1
|
||||
@@ -80,3 +83,5 @@
|
||||
#define DBL_SIGNALING_NAN fennec::bit_cast<double>(0x7ff4000000000000l)
|
||||
#define DBL_DENORM_MIN fennec::bit_cast<double>(0x1l)
|
||||
#define DBL_ROUND_ERR fennec::bit_cast<double>(0x3fe0000000000000l)
|
||||
|
||||
#endif // FENNEC_LANG_FLOAT_H
|
||||
|
||||
@@ -28,8 +28,8 @@
|
||||
///
|
||||
///
|
||||
|
||||
#ifndef LANG_H
|
||||
#define LANG_H
|
||||
#ifndef FENNEC_LANG_H
|
||||
#define FENNEC_LANG_H
|
||||
|
||||
///
|
||||
/// \page page_fennec_lang C++ Language Library
|
||||
@@ -38,4 +38,4 @@
|
||||
///
|
||||
///
|
||||
|
||||
#endif //LANG_H
|
||||
#endif // FENNEC_LANG_H
|
||||
|
||||
@@ -28,8 +28,8 @@
|
||||
///
|
||||
///
|
||||
|
||||
#ifndef UTILITY_H
|
||||
#define UTILITY_H
|
||||
#ifndef FENNEC_LANG_UTILITY_H
|
||||
#define FENNEC_LANG_UTILITY_H
|
||||
|
||||
#include <fennec/lang/type_transforms.h>
|
||||
|
||||
@@ -78,4 +78,4 @@ template<typename T> constexpr const remove_reference_t<T>& copy(T&& x) noexcept
|
||||
|
||||
}
|
||||
|
||||
#endif //UTILITY_H
|
||||
#endif // FENNEC_LANG_UTILITY_H
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
// =====================================================================================================================
|
||||
|
||||
#ifndef FWD_H
|
||||
#define FWD_H
|
||||
#ifndef FENNEC_MATH_DETAIL_FWD_H
|
||||
#define FENNEC_MATH_DETAIL_FWD_H
|
||||
|
||||
#include <fennec/math/detail/__types.h>
|
||||
|
||||
@@ -36,4 +36,4 @@ template<typename ScalarT, size_t RowsV, size_t ColsV> using mat
|
||||
|
||||
}
|
||||
|
||||
#endif //FWD_H
|
||||
#endif // FENNEC_MATH_DETAIL_FWD_H
|
||||
|
||||
@@ -37,8 +37,8 @@
|
||||
///
|
||||
///
|
||||
|
||||
#ifndef MATRIX_H
|
||||
#define MATRIX_H
|
||||
#ifndef FENNEC_MATH_MATRIX_H
|
||||
#define FENNEC_MATH_MATRIX_H
|
||||
|
||||
#include <fennec/math/detail/__fwd.h>
|
||||
|
||||
@@ -378,4 +378,4 @@ private:
|
||||
}
|
||||
|
||||
|
||||
#endif //MATRIX_H
|
||||
#endif // FENNEC_MATH_MATRIX_H
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
|
||||
#ifndef FENNEC_MATH_RELATIONAL_H
|
||||
#define FENNEC_MATH_RELATIONAL_H
|
||||
|
||||
#include <fennec/lang/types.h>
|
||||
|
||||
// TODO: Document
|
||||
|
||||
@@ -67,4 +67,4 @@ using uint = unsigned int;
|
||||
|
||||
}
|
||||
|
||||
#endif //TYPES_H
|
||||
#endif // FENNEC_MATH_SCALAR_H
|
||||
|
||||
@@ -28,8 +28,8 @@
|
||||
///
|
||||
///
|
||||
|
||||
#ifndef SWIZZLE_H
|
||||
#define SWIZZLE_H
|
||||
#ifndef FENNEC_MATH_SWIZZLE_H
|
||||
#define FENNEC_MATH_SWIZZLE_H
|
||||
|
||||
#include <fennec/lang/sequences.h>
|
||||
#include <fennec/math/swizzle_storage.h>
|
||||
@@ -82,4 +82,4 @@ private:
|
||||
|
||||
}
|
||||
|
||||
#endif //SWIZZLE_H
|
||||
#endif // FENNEC_MATH_SWIZZLE_H
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
// =====================================================================================================================
|
||||
|
||||
|
||||
#ifndef SWIZZLE_STORAGE_H
|
||||
#define SWIZZLE_STORAGE_H
|
||||
#ifndef FENNEC_MATH_SWIZZLE_STORAGE_H
|
||||
#define FENNEC_MATH_SWIZZLE_STORAGE_H
|
||||
|
||||
namespace fennec
|
||||
{
|
||||
@@ -54,4 +54,4 @@ struct swizzle_storage
|
||||
}
|
||||
|
||||
|
||||
#endif //SWIZZLE_STORAGE_H
|
||||
#endif // FENNEC_MATH_SWIZZLE_STORAGE_H
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
// =====================================================================================================================
|
||||
|
||||
|
||||
#ifndef VECTOR_BASE_H
|
||||
#define VECTOR_BASE_H
|
||||
#ifndef FENNEC_MATH_VECTOR_BASE_H
|
||||
#define FENNEC_MATH_VECTOR_BASE_H
|
||||
|
||||
#include <fennec/math/detail/__fwd.h>
|
||||
|
||||
@@ -95,4 +95,4 @@ using vector_base_type = typename vector_base_type_helper<ScalarT, SizeV>::Stora
|
||||
|
||||
}
|
||||
|
||||
#endif //VECTOR_BASE_H
|
||||
#endif // FENNEC_MATH_VECTOR_BASE_H
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
// =====================================================================================================================
|
||||
|
||||
|
||||
#ifndef VECTOR_STORAGE_H
|
||||
#define VECTOR_STORAGE_H
|
||||
#ifndef FENNEC_MATH_VECTOR_STORAGE_H
|
||||
#define FENNEC_MATH_VECTOR_STORAGE_H
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wpedantic"
|
||||
@@ -633,4 +633,4 @@ struct vector_storage<4, SwizzleGenT, DataT>
|
||||
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
#endif //VECTOR_STORAGE_H
|
||||
#endif // FENNEC_MATH_VECTOR_STORAGE_H
|
||||
|
||||
@@ -40,6 +40,12 @@ struct nothrow_t { explicit nothrow_t() noexcept { } };
|
||||
template<typename TypeT> void construct(TypeT* ptr)
|
||||
{ ptr->TypeT(); }
|
||||
|
||||
template<typename TypeT> void construct(TypeT* ptr, const TypeT& val)
|
||||
{ ptr->TypeT(val); }
|
||||
|
||||
template<typename TypeT> void construct(TypeT* ptr, TypeT&& val)
|
||||
{ ptr->TypeT(fennec::forward(val)); }
|
||||
|
||||
template<typename TypeT, typename...ArgsT> void construct(TypeT* ptr, ArgsT...args)
|
||||
{ ptr->TypeT(fennec::forward(args)...); }
|
||||
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
// =====================================================================================================================
|
||||
|
||||
#ifndef FENNEC_LANG_POINTERS_H
|
||||
#define FENNEC_LANG_POINTERS_H
|
||||
#ifndef FENNEC_MEMORY_POINTERS_H
|
||||
#define FENNEC_MEMORY_POINTERS_H
|
||||
|
||||
#include <fennec/lang/type_traits.h>
|
||||
|
||||
@@ -132,4 +132,4 @@ private:
|
||||
|
||||
}
|
||||
|
||||
#endif // FENNEC_LANG_POINTERS_H
|
||||
#endif // FENNEC_MEMORY_POINTERS_H
|
||||
|
||||
Reference in New Issue
Block a user