diff options
Diffstat (limited to 'src/common/Utilities')
23 files changed, 56 insertions, 71 deletions
diff --git a/src/common/Utilities/AsyncCallbackProcessor.h b/src/common/Utilities/AsyncCallbackProcessor.h index 54b981cbcb..68566809a6 100644 --- a/src/common/Utilities/AsyncCallbackProcessor.h +++ b/src/common/Utilities/AsyncCallbackProcessor.h @@ -18,7 +18,6 @@ #ifndef AsyncCallbackProcessor_h__ #define AsyncCallbackProcessor_h__ -#include "Define.h" #include <algorithm> #include <vector> diff --git a/src/common/Utilities/ByteConverter.h b/src/common/Utilities/ByteConverter.h index 4a96d773cb..ff0818bd6b 100644 --- a/src/common/Utilities/ByteConverter.h +++ b/src/common/Utilities/ByteConverter.h @@ -27,7 +27,7 @@ namespace ByteConverter { - template<size_t T> + template<std::size_t T> inline void convert(char* val) { std::swap(*val, *(val + T - 1)); diff --git a/src/common/Utilities/CircularBuffer.h b/src/common/Utilities/CircularBuffer.h index 898ab1a11e..4c23099c9e 100644 --- a/src/common/Utilities/CircularBuffer.h +++ b/src/common/Utilities/CircularBuffer.h @@ -17,7 +17,7 @@ template <typename T> class CircularBuffer { public: - explicit CircularBuffer(size_t size) : + explicit CircularBuffer(std::size_t size) : buf_(std::unique_ptr<T[]>(new T[size])), max_size_(size) { @@ -52,14 +52,14 @@ public: return full_; } - [[nodiscard]] size_t capacity() const + [[nodiscard]] std::size_t capacity() const { return max_size_; } - [[nodiscard]] size_t size() const + [[nodiscard]] std::size_t size() const { - size_t size = max_size_; + std::size_t size = max_size_; if (!full_) { @@ -95,9 +95,9 @@ public: private: std::mutex mutex_; std::unique_ptr<T[]> buf_; - size_t head_ = 0; - size_t tail_ = 0; - const size_t max_size_; + std::size_t head_ = 0; + std::size_t tail_ = 0; + const std::size_t max_size_; bool full_ = false; }; #endif diff --git a/src/common/Utilities/Containers.h b/src/common/Utilities/Containers.h index c77a48be7e..3a5c3b1809 100644 --- a/src/common/Utilities/Containers.h +++ b/src/common/Utilities/Containers.h @@ -23,8 +23,6 @@ #include <algorithm> #include <iterator> #include <stdexcept> -#include <type_traits> -#include <utility> #include <vector> namespace Acore @@ -51,13 +49,13 @@ namespace Acore using reference = T&; using difference_type = std::ptrdiff_t; - CheckedBufferOutputIterator(T* buf, size_t n) : _buf(buf), _end(buf + n) {} + CheckedBufferOutputIterator(T* buf, std::size_t n) : _buf(buf), _end(buf + n) {} T& operator*() const { check(); return *_buf; } CheckedBufferOutputIterator& operator++() { check(); ++_buf; return *this; } CheckedBufferOutputIterator operator++(int) { CheckedBufferOutputIterator v = *this; operator++(); return v; } - [[nodiscard]] size_t remaining() const { return (_end - _buf); } + [[nodiscard]] std::size_t remaining() const { return (_end - _buf); } private: T* _buf; diff --git a/src/common/Utilities/EventProcessor.h b/src/common/Utilities/EventProcessor.h index 0ebd48077b..3e7896bb33 100644 --- a/src/common/Utilities/EventProcessor.h +++ b/src/common/Utilities/EventProcessor.h @@ -22,7 +22,6 @@ #include "Duration.h" #include "Random.h" #include <map> -#include <type_traits> class EventProcessor; diff --git a/src/common/Utilities/Geometry.h b/src/common/Utilities/Geometry.h index f5912c8381..75affe53bc 100644 --- a/src/common/Utilities/Geometry.h +++ b/src/common/Utilities/Geometry.h @@ -24,9 +24,7 @@ #ifndef _ACORE_GEOMETRY_H #define _ACORE_GEOMETRY_H -#include "Define.h" #include <cstdlib> -#include <iostream> #include <math.h> [[nodiscard]] inline float getAngle(float startX, float startY, float destX, float destY) diff --git a/src/common/Utilities/IteratorPair.h b/src/common/Utilities/IteratorPair.h index c1e512c28b..385c77a864 100644 --- a/src/common/Utilities/IteratorPair.h +++ b/src/common/Utilities/IteratorPair.h @@ -18,7 +18,6 @@ #ifndef IteratorPair_h__ #define IteratorPair_h__ -#include "Define.h" #include <utility> namespace Acore diff --git a/src/common/Utilities/MathUtil.h b/src/common/Utilities/MathUtil.h index fad8317c30..f1df43e7db 100644 --- a/src/common/Utilities/MathUtil.h +++ b/src/common/Utilities/MathUtil.h @@ -58,7 +58,7 @@ inline T mean(Container&& c) template <typename T> inline T median(std::vector<T> a) { - size_t n = a.size(); + std::size_t n = a.size(); // If size of the arr[] is even if (n % 2 == 0) { diff --git a/src/common/Utilities/Physics.h b/src/common/Utilities/Physics.h index 8aff22f683..3f4d93a67d 100644 --- a/src/common/Utilities/Physics.h +++ b/src/common/Utilities/Physics.h @@ -25,9 +25,6 @@ #define _ACORE_PHYSICS_H #include "Geometry.h" -#include <cmath> -#include <cstdlib> -#include <iostream> using namespace std; diff --git a/src/common/Utilities/Random.cpp b/src/common/Utilities/Random.cpp index f80e023079..40090caa15 100644 --- a/src/common/Utilities/Random.cpp +++ b/src/common/Utilities/Random.cpp @@ -86,7 +86,7 @@ double rand_chance() return urd(engine); } -uint32 urandweighted(size_t count, double const* chances) +uint32 urandweighted(std::size_t count, double const* chances) { std::discrete_distribution<uint32> dd(chances, chances + count); return dd(engine); diff --git a/src/common/Utilities/Random.h b/src/common/Utilities/Random.h index 9b1867e281..07bc91d3ae 100644 --- a/src/common/Utilities/Random.h +++ b/src/common/Utilities/Random.h @@ -47,7 +47,7 @@ AC_COMMON_API double rand_norm(); AC_COMMON_API double rand_chance(); /* Return a random number in the range 0..count (exclusive) with each value having a different chance of happening */ -AC_COMMON_API uint32 urandweighted(size_t count, double const* chances); +AC_COMMON_API uint32 urandweighted(std::size_t count, double const* chances); /* Return true if a random roll fits in the specified chance (range 0-100). */ inline bool roll_chance_f(float chance) diff --git a/src/common/Utilities/SFMTRand.cpp b/src/common/Utilities/SFMTRand.cpp index fccd41aab8..c109924dbb 100644 --- a/src/common/Utilities/SFMTRand.cpp +++ b/src/common/Utilities/SFMTRand.cpp @@ -26,7 +26,7 @@ #include <mm_malloc.h> #elif defined(__GNUC__) static __inline__ void *__attribute__((__always_inline__, __nodebug__, __malloc__)) - _mm_malloc(size_t __size, size_t __align) + _mm_malloc(std::size_t __size, std::size_t __align) { if (__align == 1) { @@ -78,7 +78,7 @@ uint32 SFMTRand::RandomUInt32() // Output random bits return sfmt_genrand_uint32(&_state); } -void* SFMTRand::operator new(size_t size, std::nothrow_t const&) +void* SFMTRand::operator new(std::size_t size, std::nothrow_t const&) { return _mm_malloc(size, 16); } @@ -88,7 +88,7 @@ void SFMTRand::operator delete(void* ptr, std::nothrow_t const&) _mm_free(ptr); } -void* SFMTRand::operator new(size_t size) +void* SFMTRand::operator new(std::size_t size) { return _mm_malloc(size, 16); } @@ -98,7 +98,7 @@ void SFMTRand::operator delete(void* ptr) _mm_free(ptr); } -void* SFMTRand::operator new[](size_t size, std::nothrow_t const&) +void* SFMTRand::operator new[](std::size_t size, std::nothrow_t const&) { return _mm_malloc(size, 16); } @@ -108,7 +108,7 @@ void SFMTRand::operator delete[](void* ptr, std::nothrow_t const&) _mm_free(ptr); } -void* SFMTRand::operator new[](size_t size) +void* SFMTRand::operator new[](std::size_t size) { return _mm_malloc(size, 16); } diff --git a/src/common/Utilities/SFMTRand.h b/src/common/Utilities/SFMTRand.h index 30981b47df..e24cfe198d 100644 --- a/src/common/Utilities/SFMTRand.h +++ b/src/common/Utilities/SFMTRand.h @@ -30,13 +30,13 @@ class SFMTRand public: SFMTRand(); uint32 RandomUInt32(); // Output random bits - void* operator new(size_t size, std::nothrow_t const&); + void* operator new(std::size_t size, std::nothrow_t const&); void operator delete(void* ptr, std::nothrow_t const&); - void* operator new(size_t size); + void* operator new(std::size_t size); void operator delete(void* ptr); - void* operator new[](size_t size, std::nothrow_t const&); + void* operator new[](std::size_t size, std::nothrow_t const&); void operator delete[](void* ptr, std::nothrow_t const&); - void* operator new[](size_t size); + void* operator new[](std::size_t size); void operator delete[](void* ptr); private: sfmt_t _state; diff --git a/src/common/Utilities/SmartEnum.h b/src/common/Utilities/SmartEnum.h index e6e0be2572..fd00b83625 100644 --- a/src/common/Utilities/SmartEnum.h +++ b/src/common/Utilities/SmartEnum.h @@ -37,10 +37,10 @@ namespace Acore::Impl::EnumUtilsImpl template <typename Enum> struct EnumUtils { - static size_t Count(); + static std::size_t Count(); static EnumText ToString(Enum value); - static Enum FromIndex(size_t index); - static size_t ToIndex(Enum index); + static Enum FromIndex(std::size_t index); + static std::size_t ToIndex(Enum index); }; } @@ -48,11 +48,11 @@ class EnumUtils { public: template <typename Enum> - static size_t Count() { return Acore::Impl::EnumUtilsImpl::EnumUtils<Enum>::Count(); } + static std::size_t Count() { return Acore::Impl::EnumUtilsImpl::EnumUtils<Enum>::Count(); } template <typename Enum> static EnumText ToString(Enum value) { return Acore::Impl::EnumUtilsImpl::EnumUtils<Enum>::ToString(value); } template <typename Enum> - static Enum FromIndex(size_t index) { return Acore::Impl::EnumUtilsImpl::EnumUtils<Enum>::FromIndex(index); } + static Enum FromIndex(std::size_t index) { return Acore::Impl::EnumUtilsImpl::EnumUtils<Enum>::FromIndex(index); } template <typename Enum> static uint32 ToIndex(Enum value) { return Acore::Impl::EnumUtilsImpl::EnumUtils<Enum>::ToIndex(value);} @@ -84,7 +84,7 @@ public: using difference_type = std::ptrdiff_t; Iterator() : _index(EnumUtils::Count<Enum>()) {} - explicit Iterator(size_t index) : _index(index) { } + explicit Iterator(std::size_t index) : _index(index) { } bool operator==(const Iterator& other) const { return other._index == _index; } bool operator!=(const Iterator& other) const { return !operator==(other); } diff --git a/src/common/Utilities/StartProcess.h b/src/common/Utilities/StartProcess.h index 6b564cb9e1..6de13d1be9 100644 --- a/src/common/Utilities/StartProcess.h +++ b/src/common/Utilities/StartProcess.h @@ -20,7 +20,6 @@ #include "Define.h" #include <future> -#include <memory> #include <string> #include <vector> diff --git a/src/common/Utilities/StringConvert.h b/src/common/Utilities/StringConvert.h index bd02cf3ea2..4f51b9746e 100644 --- a/src/common/Utilities/StringConvert.h +++ b/src/common/Utilities/StringConvert.h @@ -219,7 +219,7 @@ namespace Acore::Impl::StringConvertImpl } tmp.append(str); - size_t n; + std::size_t n; T val = static_cast<T>(std::stold(tmp, &n)); if (n != tmp.length()) { diff --git a/src/common/Utilities/TaskScheduler.cpp b/src/common/Utilities/TaskScheduler.cpp index 1d0bf89e6e..1e4e0222da 100644 --- a/src/common/Utilities/TaskScheduler.cpp +++ b/src/common/Utilities/TaskScheduler.cpp @@ -31,7 +31,7 @@ TaskScheduler& TaskScheduler::Update(success_t const& callback) return *this; } -TaskScheduler& TaskScheduler::Update(size_t const milliseconds, success_t const& callback) +TaskScheduler& TaskScheduler::Update(std::size_t const milliseconds, success_t const& callback) { return Update(std::chrono::milliseconds(milliseconds), callback); } diff --git a/src/common/Utilities/TaskScheduler.h b/src/common/Utilities/TaskScheduler.h index a256be6801..145489e086 100644 --- a/src/common/Utilities/TaskScheduler.h +++ b/src/common/Utilities/TaskScheduler.h @@ -19,14 +19,11 @@ #define _TASK_SCHEDULER_H_ #include "Util.h" -#include <algorithm> #include <chrono> #include <functional> -#include <memory> #include <optional> #include <queue> #include <set> -#include <utility> #include <vector> class TaskContext; @@ -209,7 +206,7 @@ public: /// Update the scheduler with a difftime in ms. /// Calls the optional callback on successfully finish. - TaskScheduler& Update(size_t const milliseconds, success_t const& callback = EmptyCallback); + TaskScheduler& Update(std::size_t const milliseconds, success_t const& callback = EmptyCallback); /// Update the scheduler with a difftime. /// Calls the optional callback on successfully finish. diff --git a/src/common/Utilities/Tokenize.cpp b/src/common/Utilities/Tokenize.cpp index 98ba213a61..3ceb57f087 100644 --- a/src/common/Utilities/Tokenize.cpp +++ b/src/common/Utilities/Tokenize.cpp @@ -21,8 +21,8 @@ std::vector<std::string_view> Acore::Tokenize(std::string_view str, char sep, bo { std::vector<std::string_view> tokens; - size_t start = 0; - for (size_t end = str.find(sep); end != std::string_view::npos; end = str.find(sep, start)) + std::size_t start = 0; + for (std::size_t end = str.find(sep); end != std::string_view::npos; end = str.find(sep, start)) { if (keepEmpty || (start < end)) { diff --git a/src/common/Utilities/Tokenize.h b/src/common/Utilities/Tokenize.h index a871c83be9..6ee20ca53e 100644 --- a/src/common/Utilities/Tokenize.h +++ b/src/common/Utilities/Tokenize.h @@ -18,7 +18,6 @@ #ifndef _ACORE_TOKENIZE_H_ #define _ACORE_TOKENIZE_H_ -#include "Common.h" #include <string_view> #include <vector> diff --git a/src/common/Utilities/Tuples.h b/src/common/Utilities/Tuples.h index 886faac51d..f648e20e64 100644 --- a/src/common/Utilities/Tuples.h +++ b/src/common/Utilities/Tuples.h @@ -48,7 +48,7 @@ namespace Acore namespace Impl { - template <class T, class Tuple, size_t... I> + template <class T, class Tuple, std::size_t... I> T* new_from_tuple(Tuple&& args, std::index_sequence<I...>) { return new T(std::get<I>(std::forward<Tuple>(args))...); diff --git a/src/common/Utilities/Util.cpp b/src/common/Utilities/Util.cpp index ee397dd4dd..0652e56673 100644 --- a/src/common/Utilities/Util.cpp +++ b/src/common/Utilities/Util.cpp @@ -33,10 +33,10 @@ void stripLineInvisibleChars(std::string& str) { static std::string const invChars = " \t\7\n"; - size_t wpos = 0; + std::size_t wpos = 0; bool space = false; - for (size_t pos = 0; pos < str.size(); ++pos) + for (std::size_t pos = 0; pos < str.size(); ++pos) { if (invChars.find(str[pos]) != std::string::npos) { @@ -242,7 +242,7 @@ uint32 GetPID() return uint32(pid); } -size_t utf8length(std::string& utf8str) +std::size_t utf8length(std::string& utf8str) { try { @@ -255,11 +255,11 @@ size_t utf8length(std::string& utf8str) } } -void utf8truncate(std::string& utf8str, size_t len) +void utf8truncate(std::string& utf8str, std::size_t len) { try { - size_t wlen = utf8::distance(utf8str.c_str(), utf8str.c_str() + utf8str.size()); + std::size_t wlen = utf8::distance(utf8str.c_str(), utf8str.c_str() + utf8str.size()); if (wlen <= len) { return; @@ -278,7 +278,7 @@ void utf8truncate(std::string& utf8str, size_t len) } } -bool Utf8toWStr(char const* utf8str, size_t csize, wchar_t* wstr, size_t& wsize) +bool Utf8toWStr(char const* utf8str, std::size_t csize, wchar_t* wstr, std::size_t& wsize) { try { @@ -330,7 +330,7 @@ bool Utf8toWStr(std::string_view utf8str, std::wstring& wstr) return true; } -bool WStrToUtf8(wchar_t const* wstr, size_t size, std::string& utf8str) +bool WStrToUtf8(wchar_t const* wstr, std::size_t size, std::string& utf8str) { try { @@ -512,14 +512,14 @@ void vutf8printf(FILE* out, const char* str, va_list* ap) char temp_buf[32 * 1024]; wchar_t wtemp_buf[32 * 1024]; - size_t temp_len = vsnprintf(temp_buf, 32 * 1024, str, *ap); + std::size_t temp_len = vsnprintf(temp_buf, 32 * 1024, str, *ap); //vsnprintf returns -1 if the buffer is too small - if (temp_len == size_t(-1)) + if (temp_len == std::size_t(-1)) { temp_len = 32 * 1024 - 1; } - size_t wtemp_len = 32 * 1024 - 1; + std::size_t wtemp_len = 32 * 1024 - 1; Utf8toWStr(temp_buf, temp_len, wtemp_buf, wtemp_len); CharToOemBuffW(&wtemp_buf[0], &temp_buf[0], uint32(wtemp_len + 1)); @@ -542,7 +542,7 @@ bool Utf8ToUpperOnlyLatin(std::string& utf8String) return WStrToUtf8(wstr, utf8String); } -std::string Acore::Impl::ByteArrayToHexStr(uint8 const* bytes, size_t arrayLen, bool reverse /* = false */) +std::string Acore::Impl::ByteArrayToHexStr(uint8 const* bytes, std::size_t arrayLen, bool reverse /* = false */) { int32 init = 0; int32 end = arrayLen; @@ -566,7 +566,7 @@ std::string Acore::Impl::ByteArrayToHexStr(uint8 const* bytes, size_t arrayLen, return ss.str(); } -void Acore::Impl::HexStrToByteArray(std::string_view str, uint8* out, size_t outlen, bool reverse /*= false*/) +void Acore::Impl::HexStrToByteArray(std::string_view str, uint8* out, std::size_t outlen, bool reverse /*= false*/) { ASSERT(str.size() == (2 * outlen)); diff --git a/src/common/Utilities/Util.h b/src/common/Utilities/Util.h index ddc72c10d9..e5ced06991 100644 --- a/src/common/Utilities/Util.h +++ b/src/common/Utilities/Util.h @@ -85,9 +85,9 @@ inline T RoundToInterval(T& num, T floor, T ceil) AC_COMMON_API bool Utf8toWStr(std::string_view utf8str, std::wstring& wstr); // in wsize==max size of buffer, out wsize==real string size -AC_COMMON_API bool Utf8toWStr(char const* utf8str, size_t csize, wchar_t* wstr, size_t& wsize); +AC_COMMON_API bool Utf8toWStr(char const* utf8str, std::size_t csize, wchar_t* wstr, std::size_t& wsize); -inline bool Utf8toWStr(std::string_view utf8str, wchar_t* wstr, size_t& wsize) +inline bool Utf8toWStr(std::string_view utf8str, wchar_t* wstr, std::size_t& wsize) { return Utf8toWStr(utf8str.data(), utf8str.size(), wstr, wsize); } @@ -95,11 +95,11 @@ inline bool Utf8toWStr(std::string_view utf8str, wchar_t* wstr, size_t& wsize) AC_COMMON_API bool WStrToUtf8(std::wstring_view wstr, std::string& utf8str); // size==real string size -AC_COMMON_API bool WStrToUtf8(wchar_t const* wstr, size_t size, std::string& utf8str); +AC_COMMON_API bool WStrToUtf8(wchar_t const* wstr, std::size_t size, std::string& utf8str); // set string to "" if invalid utf8 sequence -size_t utf8length(std::string& utf8str); -void utf8truncate(std::string& utf8str, size_t len); +std::size_t utf8length(std::string& utf8str); +void utf8truncate(std::string& utf8str, std::size_t len); inline bool isBasicLatinCharacter(wchar_t wchar) { @@ -373,8 +373,8 @@ uint32 GetPID(); namespace Acore::Impl { - AC_COMMON_API std::string ByteArrayToHexStr(uint8 const* bytes, size_t length, bool reverse = false); - AC_COMMON_API void HexStrToByteArray(std::string_view str, uint8* out, size_t outlen, bool reverse = false); + AC_COMMON_API std::string ByteArrayToHexStr(uint8 const* bytes, std::size_t length, bool reverse = false); + AC_COMMON_API void HexStrToByteArray(std::string_view str, uint8* out, std::size_t outlen, bool reverse = false); } template<typename Container> @@ -383,13 +383,13 @@ std::string ByteArrayToHexStr(Container const& c, bool reverse = false) return Acore::Impl::ByteArrayToHexStr(std::data(c), std::size(c), reverse); } -template<size_t Size> +template<std::size_t Size> void HexStrToByteArray(std::string_view str, std::array<uint8, Size>& buf, bool reverse = false) { Acore::Impl::HexStrToByteArray(str, buf.data(), Size, reverse); } -template<size_t Size> +template<std::size_t Size> std::array<uint8, Size> HexStrToByteArray(std::string_view str, bool reverse = false) { std::array<uint8, Size> arr; @@ -433,7 +433,7 @@ public: m_list.remove(t); return *this; } - size_t size() + std::size_t size() { return m_list.size(); } |