// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com) // This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once #ifndef NAZARA_CORE_ALGORITHM_HPP #define NAZARA_CORE_ALGORITHM_HPP #include #include #include #include #include #include #include #include #include #include namespace Nz { class ByteArray; template decltype(auto) AccessByOffset(void* basePtr, std::size_t offset); template decltype(auto) AccessByOffset(const void* basePtr, std::size_t offset); template constexpr T Align(T offset, T alignment); template constexpr T AlignPow2(T offset, T alignment); template decltype(auto) Apply(F&& fn, Tuple&& t); template decltype(auto) Apply(O& object, F&& fn, Tuple&& t); template constexpr std::size_t BitCount(); template ByteArray ComputeHash(HashType hash, const T& v); template ByteArray ComputeHash(AbstractHash& hash, const T& v); template constexpr std::size_t CountOf(T(&name)[N]) noexcept; template std::size_t CountOf(const T& c); constexpr UInt32 CRC32(const UInt8* data, std::size_t size) noexcept; constexpr UInt32 CRC32(const char* str) noexcept; constexpr UInt32 CRC32(const std::string_view& str) noexcept; template constexpr std::size_t CountOf(const char(&str)[N]) noexcept; inline bool HashAppend(AbstractHash* hash, const std::string_view& v); template void HashCombine(std::size_t& seed, const T& v); template bool IsPowerOfTwo(T value); template V& Retrieve(std::unordered_map& map, const K& key); template const V& Retrieve(const std::unordered_map& map, const K& key); template T ReverseBits(T integer); template To SafeCast(From&& value); templatestd::unique_ptr StaticUniquePointerCast(std::unique_ptr&& ptr); template constexpr auto UnderlyingCast(T value) -> std::underlying_type_t; template struct AlwaysFalse : std::false_type {}; // Helper for std::visit template struct Overloaded : Ts... { using Ts::operator()...; }; template Overloaded(Ts...) -> Overloaded; template struct OverloadResolver { template constexpr auto operator()(R(T::* ptr)(Args...)) const noexcept { return ptr; } template constexpr auto operator()(R(T::* ptr)(Args...) const) const noexcept { return ptr; } template constexpr auto operator()(R(*ptr)(Args...)) const noexcept { return ptr; } }; template constexpr OverloadResolver Overload = {}; template struct PointedType { using type = void; //< FIXME: I can't make SFINAE work }; template using Pointer = T*; template bool Serialize(SerializationContext& context, T&& value); inline bool Serialize(SerializationContext& context, bool value, TypeTag); inline bool Serialize(SerializationContext& context, const std::string& value, TypeTag); template std::enable_if_t::value, bool> Serialize(SerializationContext& context, T value, TypeTag); template bool Unserialize(SerializationContext& context, T* value); inline bool Unserialize(SerializationContext& context, bool* value, TypeTag); inline bool Unserialize(SerializationContext& context, std::string* value, TypeTag); template std::enable_if_t::value, bool> Unserialize(SerializationContext& context, T* value, TypeTag); } #include #endif // NAZARA_CORE_ALGORITHM_HPP