Follow code style with noexcept, add Const() function to BorrowedPtr to return a const pointer of itself.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
893aa969d5
commit
f59ec6c957
|
@ -17,7 +17,7 @@ namespace ArbUt {
|
||||||
explicit Dictionary(size_t capacity) : _map(capacity) {}
|
explicit Dictionary(size_t capacity) : _map(capacity) {}
|
||||||
explicit Dictionary(const std::initializer_list<std::pair<const KeyT, ValueT>>& l) : _map(l) {}
|
explicit Dictionary(const std::initializer_list<std::pair<const KeyT, ValueT>>& l) : _map(l) {}
|
||||||
|
|
||||||
inline void Clear() { _map.clear(); }
|
inline void Clear() noexcept { _map.clear(); }
|
||||||
|
|
||||||
inline void Insert(const KeyT& key, const ValueT& value) {
|
inline void Insert(const KeyT& key, const ValueT& value) {
|
||||||
[[maybe_unused]] const auto& v = _map.insert({key, value});
|
[[maybe_unused]] const auto& v = _map.insert({key, value});
|
||||||
|
@ -39,7 +39,7 @@ namespace ArbUt {
|
||||||
|
|
||||||
[[nodiscard]] inline const ValueT& Get(const KeyT& key) const { return _map.at(key); }
|
[[nodiscard]] inline const ValueT& Get(const KeyT& key) const { return _map.at(key); }
|
||||||
|
|
||||||
inline bool TryGet(const KeyT& key, ValueT& out) const {
|
inline bool TryGet(const KeyT& key, ValueT& out) const noexcept {
|
||||||
const auto& find = _map.find(key);
|
const auto& find = _map.find(key);
|
||||||
if (find == _map.end()) {
|
if (find == _map.end()) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -50,21 +50,21 @@ namespace ArbUt {
|
||||||
|
|
||||||
inline void Remove(const KeyT& key) { _map.erase(key); }
|
inline void Remove(const KeyT& key) { _map.erase(key); }
|
||||||
|
|
||||||
[[nodiscard]] inline size_t Count() const { return _map.size(); }
|
[[nodiscard]] inline size_t Count() const noexcept { return _map.size(); }
|
||||||
|
|
||||||
inline bool Has(const KeyT& key) const noexcept { return _map.find(key) != _map.end(); }
|
inline bool Has(const KeyT& key) const noexcept { return _map.find(key) != _map.end(); }
|
||||||
|
|
||||||
inline ValueT& operator[](const KeyT& key) { return Get(key); }
|
inline ValueT& operator[](const KeyT& key) { return Get(key); }
|
||||||
inline const ValueT& operator[](const KeyT& key) const { return Get(key); }
|
inline const ValueT& operator[](const KeyT& key) const { return Get(key); }
|
||||||
|
|
||||||
iterator begin() { return _map.begin(); }
|
iterator begin() noexcept { return _map.begin(); }
|
||||||
const_iterator begin() const { return _map.begin(); }
|
const_iterator begin() const noexcept { return _map.begin(); }
|
||||||
|
|
||||||
iterator end() { return _map.end(); }
|
iterator end() noexcept { return _map.end(); }
|
||||||
const_iterator end() const { return _map.end(); }
|
const_iterator end() const { return _map.end(); }
|
||||||
|
|
||||||
const std::unordered_map<KeyT, ValueT>& GetStdMap() const { return _map; }
|
const std::unordered_map<KeyT, ValueT>& GetStdMap() const noexcept { return _map; }
|
||||||
std::unordered_map<KeyT, ValueT>& GetStdMap() { return _map; }
|
std::unordered_map<KeyT, ValueT>& GetStdMap() noexcept { return _map; }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,12 +15,12 @@ namespace ArbUt {
|
||||||
using const_iterator = typename std::vector<ValueT>::const_iterator;
|
using const_iterator = typename std::vector<ValueT>::const_iterator;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
List() : _vector() {}
|
List() noexcept : _vector() {}
|
||||||
explicit List(size_t capacity) : _vector() { _vector.reserve(capacity); }
|
explicit List(size_t capacity) : _vector() { _vector.reserve(capacity); }
|
||||||
List(const std::initializer_list<ValueT>& l) : _vector(l) {}
|
List(const std::initializer_list<ValueT>& l) noexcept : _vector(l) {}
|
||||||
List(const ValueT* begin, const ValueT* end) : _vector(begin, end) {}
|
List(const ValueT* begin, const ValueT* end) noexcept : _vector(begin, end) {}
|
||||||
|
|
||||||
inline void Clear() { _vector.clear(); }
|
inline void Clear() noexcept { _vector.clear(); }
|
||||||
|
|
||||||
inline reference At(size_t index) {
|
inline reference At(size_t index) {
|
||||||
#ifndef NO_ASSERT
|
#ifndef NO_ASSERT
|
||||||
|
@ -64,7 +64,7 @@ namespace ArbUt {
|
||||||
/// Find the index of the first occurrence of a value in the list, return -1 if none is found.
|
/// Find the index of the first occurrence of a value in the list, return -1 if none is found.
|
||||||
/// \param value The value we want the index for.
|
/// \param value The value we want the index for.
|
||||||
/// \return The index of the first occurrence of the value in the list, or -1 if none is found.
|
/// \return The index of the first occurrence of the value in the list, or -1 if none is found.
|
||||||
inline size_t IndexOf(const ValueT& value) const {
|
inline size_t IndexOf(const ValueT& value) const noexcept {
|
||||||
const auto& it = std::find(_vector.begin(), _vector.end(), value);
|
const auto& it = std::find(_vector.begin(), _vector.end(), value);
|
||||||
if (it == _vector.end())
|
if (it == _vector.end())
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -78,23 +78,23 @@ namespace ArbUt {
|
||||||
inline reference operator[](size_t index) { return At(index); }
|
inline reference operator[](size_t index) { return At(index); }
|
||||||
inline const const_reference& operator[](size_t index) const { return At(index); }
|
inline const const_reference& operator[](size_t index) const { return At(index); }
|
||||||
|
|
||||||
inline size_t Count() const { return _vector.size(); }
|
inline size_t Count() const noexcept { return _vector.size(); }
|
||||||
inline void Reserve(size_t size) { _vector.reserve(size); }
|
inline void Reserve(size_t size) { _vector.reserve(size); }
|
||||||
inline void Resize(size_t size) { _vector.resize(size); }
|
inline void Resize(size_t size) { _vector.resize(size); }
|
||||||
inline void Resize(size_t size, const ValueT& defaultValue) { _vector.resize(size, defaultValue); }
|
inline void Resize(size_t size, const ValueT& defaultValue) { _vector.resize(size, defaultValue); }
|
||||||
|
|
||||||
inline void Remove(size_t index) { _vector.erase(_vector.begin() + index); }
|
inline void Remove(size_t index) { _vector.erase(_vector.begin() + index); }
|
||||||
|
|
||||||
iterator begin() { return _vector.begin(); }
|
iterator begin() noexcept { return _vector.begin(); }
|
||||||
const_iterator begin() const { return _vector.begin(); }
|
const_iterator begin() const noexcept { return _vector.begin(); }
|
||||||
|
|
||||||
iterator end() { return _vector.end(); }
|
iterator end() noexcept { return _vector.end(); }
|
||||||
const_iterator end() const { return _vector.end(); }
|
const_iterator end() const noexcept { return _vector.end(); }
|
||||||
|
|
||||||
const ValueT* RawData() const { return _vector.data(); }
|
const ValueT* RawData() const noexcept { return _vector.data(); }
|
||||||
|
|
||||||
const std::vector<ValueT>& GetStdList() const { return _vector; }
|
const std::vector<ValueT>& GetStdList() const noexcept { return _vector; }
|
||||||
std::vector<ValueT>& GetStdList() { return _vector; }
|
std::vector<ValueT>& GetStdList() noexcept { return _vector; }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,19 +17,19 @@ namespace ArbUt {
|
||||||
__ConstStringCharHolder& operator=(const __ConstStringCharHolder& other) = delete;
|
__ConstStringCharHolder& operator=(const __ConstStringCharHolder& other) = delete;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
__ConstStringCharHolder(const char* value, size_t size) : _value(new char[size + 1]), _references(1) {
|
__ConstStringCharHolder(const char* value, size_t size) noexcept : _value(new char[size + 1]), _references(1) {
|
||||||
strncpy(_value, value, size + 1);
|
strncpy(_value, value, size + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
~__ConstStringCharHolder() { delete[] _value; }
|
~__ConstStringCharHolder() noexcept { delete[] _value; }
|
||||||
|
|
||||||
inline void RemoveReference() {
|
inline void RemoveReference() noexcept {
|
||||||
if (--_references <= 0) {
|
if (--_references <= 0) {
|
||||||
delete this;
|
delete this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
inline void AddReference() { _references++; }
|
inline void AddReference() noexcept { _references++; }
|
||||||
inline constexpr const char* GetValue() const { return _value; }
|
inline constexpr const char* GetValue() const noexcept { return _value; }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
25
src/Enum.hpp
25
src/Enum.hpp
|
@ -52,21 +52,22 @@
|
||||||
MACRO_UTILS_FOR_EACH_WITH_VALUE(ENUM_VALUE, startValue + ___MACRO_UTILS_NARGS(values) - 1, values) \
|
MACRO_UTILS_FOR_EACH_WITH_VALUE(ENUM_VALUE, startValue + ___MACRO_UTILS_NARGS(values) - 1, values) \
|
||||||
}; \
|
}; \
|
||||||
class name##Helper { \
|
class name##Helper { \
|
||||||
inline static uint32_t constexpr ConstHash(char const* input) { \
|
inline static uint32_t constexpr ConstHash(char const* input) noexcept { \
|
||||||
return *input ? static_cast<uint32_t>(*input) + 33 * ConstHash(input + 1) : 5381; \
|
return *input ? static_cast<uint32_t>(*input) + 33 * ConstHash(input + 1) : 5381; \
|
||||||
} \
|
} \
|
||||||
inline static constexpr char charToLower(const char c) { \
|
inline static constexpr char charToLower(const char c) noexcept { \
|
||||||
return (c >= 'A' && c <= 'Z') ? c + ('a' - 'A') : c; \
|
return (c >= 'A' && c <= 'Z') ? c + ('a' - 'A') : c; \
|
||||||
} \
|
} \
|
||||||
inline static uint32_t constexpr ConstHashCI(char const* input) { \
|
inline static uint32_t constexpr ConstHashCI(char const* input) noexcept { \
|
||||||
return charToLower(*input) ? static_cast<uint32_t>(charToLower(*input)) + 33 * ConstHashCI(input + 1) \
|
return charToLower(*input) ? static_cast<uint32_t>(charToLower(*input)) + 33 * ConstHashCI(input + 1) \
|
||||||
: 5381; \
|
: 5381; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
public: \
|
public: \
|
||||||
constexpr static const char* ToString(name value) { \
|
constexpr static const char* ToString(name value) noexcept { \
|
||||||
switch (value) { MACRO_UTILS_FOR_EACH(ENUM_CASE, name, values) } \
|
switch (value) { MACRO_UTILS_FOR_EACH(ENUM_CASE, name, values) } \
|
||||||
auto v = static_cast<int>(value); \
|
/*If we haven't found a value, we want to stringify the number*/ \
|
||||||
|
auto v = static_cast<type>(value); \
|
||||||
auto size = (int)((ceil(log10(v)) + 1) * sizeof(char)); \
|
auto size = (int)((ceil(log10(v)) + 1) * sizeof(char)); \
|
||||||
char* snum = new char[size + 1]; \
|
char* snum = new char[size + 1]; \
|
||||||
sprintf(snum, "%d", v); \
|
sprintf(snum, "%d", v); \
|
||||||
|
@ -78,21 +79,21 @@
|
||||||
switch (ConstHash(input)) { MACRO_UTILS_FOR_EACH(ENUM_PARSE_CASE, name, values) } \
|
switch (ConstHash(input)) { MACRO_UTILS_FOR_EACH(ENUM_PARSE_CASE, name, values) } \
|
||||||
throw std::runtime_error("Invalid " #name " string."); \
|
throw std::runtime_error("Invalid " #name " string."); \
|
||||||
} \
|
} \
|
||||||
constexpr static bool TryParse(const char* input, name& out, bool caseInsensitive = false) { \
|
constexpr static bool TryParse(const char* input, name& out, bool caseInsensitive = false) noexcept { \
|
||||||
if (caseInsensitive) \
|
if (caseInsensitive) \
|
||||||
return TryParseCaseInsensitive(input, out); \
|
return TryParseCaseInsensitive(input, out); \
|
||||||
switch (ConstHash(input)) { MACRO_UTILS_FOR_EACH(ENUM_TRY_PARSE_CASE, name, values) } \
|
switch (ConstHash(input)) { MACRO_UTILS_FOR_EACH(ENUM_TRY_PARSE_CASE, name, values) } \
|
||||||
return false; \
|
return false; \
|
||||||
} \
|
} \
|
||||||
static std::vector<name> GetValues() { return {MACRO_UTILS_FOR_EACH(ARRAY_NAME, name, values)}; } \
|
static std::vector<name> GetValues() noexcept { return {MACRO_UTILS_FOR_EACH(ARRAY_NAME, name, values)}; } \
|
||||||
constexpr static name Last() { return name::MACRO_UTILS_GET_LAST(values); } \
|
constexpr static name Last() noexcept { return name::MACRO_UTILS_GET_LAST(values); } \
|
||||||
constexpr static name First() { return name::MACRO_UTILS_GET_FIRST(values); } \
|
constexpr static name First() noexcept { return name::MACRO_UTILS_GET_FIRST(values); } \
|
||||||
constexpr static name Highest() { \
|
constexpr static name Highest() noexcept { \
|
||||||
int64_t highest = -9223372036854775807; \
|
int64_t highest = -9223372036854775807; \
|
||||||
MACRO_UTILS_FOR_EACH(ENUM_GET_HIGHEST, name, values) \
|
MACRO_UTILS_FOR_EACH(ENUM_GET_HIGHEST, name, values) \
|
||||||
return (name)highest; \
|
return (name)highest; \
|
||||||
} \
|
} \
|
||||||
constexpr static name Lowest() { \
|
constexpr static name Lowest() noexcept { \
|
||||||
int64_t lowest = 9223372036854775807; \
|
int64_t lowest = 9223372036854775807; \
|
||||||
MACRO_UTILS_FOR_EACH(ENUM_GET_LOWEST, name, values) \
|
MACRO_UTILS_FOR_EACH(ENUM_GET_LOWEST, name, values) \
|
||||||
return (name)lowest; \
|
return (name)lowest; \
|
||||||
|
@ -103,7 +104,7 @@
|
||||||
switch (ConstHashCI(input)) { MACRO_UTILS_FOR_EACH(ENUM_PARSE_CASE_INSENSITIVE, name, values) } \
|
switch (ConstHashCI(input)) { MACRO_UTILS_FOR_EACH(ENUM_PARSE_CASE_INSENSITIVE, name, values) } \
|
||||||
throw std::runtime_error("Invalid " #name " string."); \
|
throw std::runtime_error("Invalid " #name " string."); \
|
||||||
} \
|
} \
|
||||||
constexpr static bool TryParseCaseInsensitive(const char* input, name& out) { \
|
constexpr static bool TryParseCaseInsensitive(const char* input, name& out) noexcept { \
|
||||||
switch (ConstHashCI(input)) { MACRO_UTILS_FOR_EACH(ENUM_TRY_PARSE_CASE_INSENSITIVE, name, values) } \
|
switch (ConstHashCI(input)) { MACRO_UTILS_FOR_EACH(ENUM_TRY_PARSE_CASE_INSENSITIVE, name, values) } \
|
||||||
return false; \
|
return false; \
|
||||||
} \
|
} \
|
||||||
|
|
|
@ -12,14 +12,14 @@ namespace ArbUt {
|
||||||
T* _raw;
|
T* _raw;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline BorrowedPtr<T>() : _raw(nullptr){};
|
inline BorrowedPtr<T>() noexcept : _raw(nullptr){};
|
||||||
inline BorrowedPtr<T>(T* ptr) : _raw(ptr){};
|
inline BorrowedPtr<T>(T* ptr) noexcept : _raw(ptr){};
|
||||||
inline BorrowedPtr(const BorrowedPtr<T>& other) : _raw(other._raw){};
|
inline BorrowedPtr<T>(const BorrowedPtr<T>& other) noexcept : _raw(other._raw){};
|
||||||
inline BorrowedPtr(const std::unique_ptr<T>& other) : _raw(other.get()){};
|
inline BorrowedPtr<T>(const std::unique_ptr<T>& other) noexcept : _raw(other.get()){};
|
||||||
|
|
||||||
~BorrowedPtr() = default;
|
~BorrowedPtr() noexcept = default;
|
||||||
|
|
||||||
inline BorrowedPtr<T>& operator=(const BorrowedPtr<T>& rhs) {
|
inline BorrowedPtr<T>& operator=(const BorrowedPtr<T>& rhs) noexcept {
|
||||||
_raw = rhs._raw;
|
_raw = rhs._raw;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@ -27,17 +27,21 @@ namespace ArbUt {
|
||||||
inline T* operator->() const noexcept { return _raw; }
|
inline T* operator->() const noexcept { return _raw; }
|
||||||
inline T* GetRaw() const noexcept { return _raw; }
|
inline T* GetRaw() const noexcept { return _raw; }
|
||||||
|
|
||||||
inline bool operator==(const BorrowedPtr& rhs) const { return _raw == rhs._raw; }
|
inline bool operator==(const BorrowedPtr& rhs) const noexcept { return _raw == rhs._raw; }
|
||||||
inline bool operator!=(const BorrowedPtr& rhs) const { return _raw != rhs._raw; }
|
inline bool operator!=(const BorrowedPtr& rhs) const noexcept { return _raw != rhs._raw; }
|
||||||
|
|
||||||
[[nodiscard]] inline constexpr bool IsNull() const noexcept { return _raw == nullptr; }
|
[[nodiscard]] inline constexpr bool IsNull() const noexcept { return _raw == nullptr; }
|
||||||
|
|
||||||
|
inline BorrowedPtr<const T> Const() const noexcept {
|
||||||
|
return BorrowedPtr<const T>(_raw);
|
||||||
|
}
|
||||||
|
|
||||||
template <class TCast> inline BorrowedPtr<TCast> As() const {
|
template <class TCast> inline BorrowedPtr<TCast> As() const {
|
||||||
auto cast = dynamic_cast<TCast*>(_raw);
|
auto cast = dynamic_cast<TCast*>(_raw);
|
||||||
return BorrowedPtr<TCast>(cast);
|
return BorrowedPtr<TCast>(cast);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class TCast> inline bool TryAs(BorrowedPtr<TCast>& out) const {
|
template <class TCast> inline bool TryAs(BorrowedPtr<TCast>& out) const noexcept {
|
||||||
auto cast = dynamic_cast<TCast*>(_raw);
|
auto cast = dynamic_cast<TCast*>(_raw);
|
||||||
if (cast == nullptr)
|
if (cast == nullptr)
|
||||||
return false;
|
return false;
|
||||||
|
@ -45,7 +49,7 @@ namespace ArbUt {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class TCast> inline BorrowedPtr<TCast> ForceAs() const {
|
template <class TCast> inline BorrowedPtr<TCast> ForceAs() const noexcept {
|
||||||
auto cast = reinterpret_cast<TCast*>(_raw);
|
auto cast = reinterpret_cast<TCast*>(_raw);
|
||||||
return BorrowedPtr<TCast>(cast);
|
return BorrowedPtr<TCast>(cast);
|
||||||
}
|
}
|
||||||
|
@ -53,11 +57,9 @@ namespace ArbUt {
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace std {
|
namespace std {
|
||||||
|
|
||||||
template <class T> struct hash<ArbUt::BorrowedPtr<T>> {
|
template <class T> struct hash<ArbUt::BorrowedPtr<T>> {
|
||||||
std::size_t operator()(const ArbUt::BorrowedPtr<T>& k) const { return (size_t)k.GetRaw(); }
|
std::size_t operator()(const ArbUt::BorrowedPtr<T>& k) const { return (size_t)k.GetRaw(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // ARBUTILS_BORROWEDPTR_HPP
|
#endif // ARBUTILS_BORROWEDPTR_HPP
|
||||||
|
|
|
@ -15,17 +15,17 @@ namespace ArbUt {
|
||||||
using const_iterator = typename std::vector<ValueT*>::const_iterator;
|
using const_iterator = typename std::vector<ValueT*>::const_iterator;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline UniquePtrList() : _vector() {}
|
inline UniquePtrList() noexcept : _vector() {}
|
||||||
inline UniquePtrList(std::vector<ValueT*> vec) : _vector(vec) {}
|
inline UniquePtrList(const std::vector<ValueT*>& vec) noexcept : _vector(vec) {}
|
||||||
explicit inline UniquePtrList(size_t capacity) : _vector() { _vector.reserve(capacity); }
|
explicit inline UniquePtrList(size_t capacity) : _vector() { _vector.reserve(capacity); }
|
||||||
inline UniquePtrList(const std::initializer_list<ValueT*>& l) : _vector(l) {}
|
inline UniquePtrList(const std::initializer_list<ValueT*>& l) noexcept : _vector(l) {}
|
||||||
inline UniquePtrList(ValueT* const* begin, ValueT* const* end) : _vector(begin, end) {}
|
inline UniquePtrList(ValueT* const* begin, ValueT* const* end) noexcept : _vector(begin, end) {}
|
||||||
|
|
||||||
UniquePtrList(const UniquePtrList<ValueT>&) = delete;
|
UniquePtrList(const UniquePtrList<ValueT>&) = delete;
|
||||||
UniquePtrList<ValueT>& operator=(const UniquePtrList<ValueT>&) = delete;
|
UniquePtrList<ValueT>& operator=(const UniquePtrList<ValueT>&) = delete;
|
||||||
~UniquePtrList() { Clear(); }
|
~UniquePtrList() noexcept { Clear(); }
|
||||||
|
|
||||||
inline void Clear() {
|
inline void Clear() noexcept {
|
||||||
for (auto& i : _vector) {
|
for (auto& i : _vector) {
|
||||||
delete i;
|
delete i;
|
||||||
}
|
}
|
||||||
|
@ -54,14 +54,14 @@ namespace ArbUt {
|
||||||
_vector.erase(_vector.begin() + index);
|
_vector.erase(_vector.begin() + index);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Contains(const BorrowedPtr<ValueT>& value) const {
|
inline bool Contains(const BorrowedPtr<ValueT>& value) const noexcept {
|
||||||
return std::find(_vector.begin(), _vector.end(), value) != _vector.end();
|
return std::find(_vector.begin(), _vector.end(), value) != _vector.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Find the index of the first occurrence of a value in the list, return -1 if none is found.
|
/// Find the index of the first occurrence of a value in the list, return -1 if none is found.
|
||||||
/// \param value The value we want the index for.
|
/// \param value The value we want the index for.
|
||||||
/// \return The index of the first occurrence of the value in the list, or -1 if none is found.
|
/// \return The index of the first occurrence of the value in the list, or -1 if none is found.
|
||||||
inline size_t IndexOf(const BorrowedPtr<ValueT>& value) const {
|
inline size_t IndexOf(const BorrowedPtr<ValueT>& value) const noexcept {
|
||||||
const auto& it = std::find(_vector.begin(), _vector.end(), value);
|
const auto& it = std::find(_vector.begin(), _vector.end(), value);
|
||||||
if (it == _vector.end())
|
if (it == _vector.end())
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -71,17 +71,17 @@ namespace ArbUt {
|
||||||
inline void Append(ValueT* value) { _vector.push_back(value); }
|
inline void Append(ValueT* value) { _vector.push_back(value); }
|
||||||
inline BorrowedPtr<ValueT> operator[](size_t index) const { return At(index); }
|
inline BorrowedPtr<ValueT> operator[](size_t index) const { return At(index); }
|
||||||
|
|
||||||
inline size_t Count() const { return _vector.size(); }
|
inline size_t Count() const noexcept { return _vector.size(); }
|
||||||
|
|
||||||
iterator begin() { return _vector.begin(); }
|
iterator begin() noexcept { return _vector.begin(); }
|
||||||
iterator end() { return _vector.end(); }
|
iterator end() noexcept { return _vector.end(); }
|
||||||
const_iterator begin() const { return _vector.begin(); }
|
const_iterator begin() const noexcept { return _vector.begin(); }
|
||||||
const_iterator end() const { return _vector.end(); }
|
const_iterator end() const noexcept { return _vector.end(); }
|
||||||
|
|
||||||
ValueT* const* RawData() const { return _vector.data(); }
|
ValueT* const* RawData() const noexcept { return _vector.data(); }
|
||||||
|
|
||||||
const std::vector<ValueT*>& GetStdList() const { return _vector; }
|
const std::vector<ValueT*>& GetStdList() const noexcept { return _vector; }
|
||||||
std::vector<ValueT*>& GetStdList() { return _vector; }
|
std::vector<ValueT*>& GetStdList() noexcept { return _vector; }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,8 +77,8 @@ namespace ArbUt {
|
||||||
|
|
||||||
class Random : public BaseRandom<pcg32> {
|
class Random : public BaseRandom<pcg32> {
|
||||||
public:
|
public:
|
||||||
constexpr Random() : BaseRandom() {}
|
constexpr Random() noexcept : BaseRandom() {}
|
||||||
explicit constexpr Random(uint_fast32_t seed) : BaseRandom(seed) {}
|
explicit constexpr Random(uint_fast32_t seed) noexcept : BaseRandom(seed) {}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif // ARBUTILS_RANDOM_HPP
|
#endif // ARBUTILS_RANDOM_HPP
|
||||||
|
|
|
@ -26,16 +26,19 @@
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
public: \
|
public: \
|
||||||
name(const char* str, size_t size) \
|
name(const char* str, size_t size) noexcept \
|
||||||
: _str(new __ConstStringCharHolder(str, size)), _length(size), _hash(Hash(str)) {} \
|
: _str(new __ConstStringCharHolder(str, size)), _length(size), _hash(Hash(str)) {} \
|
||||||
\
|
\
|
||||||
name() : _str(GetEmptyString()), _length(0), _hash(Hash("")) { GetEmptyString()->AddReference(); }; \
|
name() noexcept : _str(GetEmptyString()), _length(0), _hash(Hash("")) { \
|
||||||
explicit name(const char* str) : name(str, Length(str)){}; \
|
GetEmptyString()->AddReference(); \
|
||||||
explicit name(const std::string& str) : name(str.c_str(), str.size()){}; \
|
}; \
|
||||||
|
explicit name(const char* str) noexcept : name(str, Length(str)){}; \
|
||||||
|
explicit name(const std::string& str) noexcept : name(str.c_str(), str.size()){}; \
|
||||||
\
|
\
|
||||||
/* Copy operators */ \
|
/* Copy operators */ \
|
||||||
name(const name& other) : _str(other.CloneHolder()), _length(other._length), _hash(other._hash) {} \
|
name(const name& other) noexcept \
|
||||||
name& operator=(const name& other) { \
|
: _str(other.CloneHolder()), _length(other._length), _hash(other._hash) {} \
|
||||||
|
name& operator=(const name& other) noexcept { \
|
||||||
if (_str == other._str) { \
|
if (_str == other._str) { \
|
||||||
_str->AddReference(); \
|
_str->AddReference(); \
|
||||||
return *this; \
|
return *this; \
|
||||||
|
@ -47,10 +50,12 @@
|
||||||
return *this; \
|
return *this; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
~name() { _str->RemoveReference(); } \
|
~name() noexcept { _str->RemoveReference(); } \
|
||||||
\
|
\
|
||||||
[[nodiscard]] inline constexpr const char* c_str() const noexcept { return _str->GetValue(); } \
|
[[nodiscard]] inline constexpr const char* c_str() const noexcept { return _str->GetValue(); } \
|
||||||
[[nodiscard]] inline std::string std_str() const { return std::string(_str->GetValue(), _length); } \
|
[[nodiscard]] inline std::string std_str() const noexcept { \
|
||||||
|
return std::string(_str->GetValue(), _length); \
|
||||||
|
} \
|
||||||
\
|
\
|
||||||
[[nodiscard]] inline constexpr size_t Length() const noexcept { return _length; } \
|
[[nodiscard]] inline constexpr size_t Length() const noexcept { return _length; } \
|
||||||
\
|
\
|
||||||
|
@ -58,21 +63,23 @@
|
||||||
inline constexpr bool Empty() const noexcept { return _length == 0; } \
|
inline constexpr bool Empty() const noexcept { return _length == 0; } \
|
||||||
\
|
\
|
||||||
constexpr std::size_t operator()(name const& s) const noexcept { return s.GetHash(); } \
|
constexpr std::size_t operator()(name const& s) const noexcept { return s.GetHash(); } \
|
||||||
inline constexpr operator uint32_t() const { return _hash; } \
|
inline constexpr operator uint32_t() const noexcept { return _hash; } \
|
||||||
\
|
\
|
||||||
inline constexpr bool operator==(const name& rhs) const { return _hash == rhs._hash; } \
|
inline constexpr bool operator==(const name& rhs) const noexcept { return _hash == rhs._hash; } \
|
||||||
inline constexpr bool operator!=(const name& rhs) const { return _hash != rhs._hash; } \
|
inline constexpr bool operator!=(const name& rhs) const noexcept { return _hash != rhs._hash; } \
|
||||||
inline STDSTRINGCONSTEXPR bool operator==(const std::string& rhs) const { \
|
inline STDSTRINGCONSTEXPR bool operator==(const std::string& rhs) const noexcept { \
|
||||||
return _hash == Hash(rhs.c_str()); \
|
return _hash == Hash(rhs.c_str()); \
|
||||||
} \
|
} \
|
||||||
inline STDSTRINGCONSTEXPR bool operator!=(const std::string& rhs) const { \
|
inline STDSTRINGCONSTEXPR bool operator!=(const std::string& rhs) const noexcept { \
|
||||||
return _hash != Hash(rhs.c_str()); \
|
return _hash != Hash(rhs.c_str()); \
|
||||||
} \
|
} \
|
||||||
inline constexpr bool operator==(const char* rhs) const { return _hash == Hash(rhs); } \
|
inline constexpr bool operator==(const char* rhs) const noexcept { return _hash == Hash(rhs); } \
|
||||||
inline constexpr bool operator!=(const char* rhs) const { return _hash != Hash(rhs); } \
|
inline constexpr bool operator!=(const char* rhs) const noexcept { return _hash != Hash(rhs); } \
|
||||||
\
|
\
|
||||||
inline static constexpr uint32_t GetHash(const char* val) { return Hash(val); } \
|
inline static constexpr uint32_t GetHash(const char* val) noexcept { return Hash(val); } \
|
||||||
inline static STDSTRINGCONSTEXPR uint32_t GetHash(const std::string& val) { return Hash(val.c_str()); } \
|
inline static STDSTRINGCONSTEXPR uint32_t GetHash(const std::string& val) noexcept { \
|
||||||
|
return Hash(val.c_str()); \
|
||||||
|
} \
|
||||||
}; \
|
}; \
|
||||||
\
|
\
|
||||||
class name##_Literal { \
|
class name##_Literal { \
|
||||||
|
@ -83,11 +90,12 @@
|
||||||
\
|
\
|
||||||
hashFunction; \
|
hashFunction; \
|
||||||
\
|
\
|
||||||
inline static int constexpr Length(const char* str) { return *str ? 1 + Length(str + 1) : 0; } \
|
inline static int constexpr Length(const char* str) noexcept { return *str ? 1 + Length(str + 1) : 0; } \
|
||||||
\
|
\
|
||||||
public: \
|
public: \
|
||||||
constexpr name##_Literal(const char* str, size_t size) : _str(str), _length(size), _hash(Hash(str)) {} \
|
constexpr name##_Literal(const char* str, size_t size) noexcept \
|
||||||
explicit name##_Literal(const char* str) : name##_Literal(str, Length(str)){}; \
|
: _str(str), _length(size), _hash(Hash(str)) {} \
|
||||||
|
explicit name##_Literal(const char* str) noexcept : name##_Literal(str, Length(str)){}; \
|
||||||
[[nodiscard]] inline constexpr const char* c_str() const noexcept { return _str; } \
|
[[nodiscard]] inline constexpr const char* c_str() const noexcept { return _str; } \
|
||||||
[[nodiscard]] inline constexpr size_t Length() const noexcept { return _length; } \
|
[[nodiscard]] inline constexpr size_t Length() const noexcept { return _length; } \
|
||||||
\
|
\
|
||||||
|
@ -95,19 +103,19 @@
|
||||||
inline constexpr bool Empty() const noexcept { return _length == 0; } \
|
inline constexpr bool Empty() const noexcept { return _length == 0; } \
|
||||||
\
|
\
|
||||||
constexpr std::size_t operator()(name##_Literal const& s) const noexcept { return s.GetHash(); } \
|
constexpr std::size_t operator()(name##_Literal const& s) const noexcept { return s.GetHash(); } \
|
||||||
inline constexpr operator uint32_t() const { return _hash; } \
|
inline constexpr operator uint32_t() const noexcept { return _hash; } \
|
||||||
inline operator name() const { return name(_str, _length); } \
|
inline operator name() const noexcept { return name(_str, _length); } \
|
||||||
\
|
\
|
||||||
inline constexpr bool operator==(const name##_Literal& rhs) const { return _hash == rhs._hash; } \
|
inline constexpr bool operator==(const name##_Literal& rhs) const noexcept { return _hash == rhs._hash; } \
|
||||||
inline constexpr bool operator!=(const name##_Literal& rhs) const { return _hash != rhs._hash; } \
|
inline constexpr bool operator!=(const name##_Literal& rhs) const noexcept { return _hash != rhs._hash; } \
|
||||||
inline STDSTRINGCONSTEXPR bool operator==(const std::string& rhs) const { \
|
inline STDSTRINGCONSTEXPR bool operator==(const std::string& rhs) const noexcept { \
|
||||||
return _hash == Hash(rhs.c_str()); \
|
return _hash == Hash(rhs.c_str()); \
|
||||||
} \
|
} \
|
||||||
inline STDSTRINGCONSTEXPR bool operator!=(const std::string& rhs) const { \
|
inline STDSTRINGCONSTEXPR bool operator!=(const std::string& rhs) const noexcept { \
|
||||||
return _hash != Hash(rhs.c_str()); \
|
return _hash != Hash(rhs.c_str()); \
|
||||||
} \
|
} \
|
||||||
inline constexpr bool operator==(const char* rhs) const { return _hash == Hash(rhs); } \
|
inline constexpr bool operator==(const char* rhs) const noexcept { return _hash == Hash(rhs); } \
|
||||||
inline constexpr bool operator!=(const char* rhs) const { return _hash != Hash(rhs); } \
|
inline constexpr bool operator!=(const char* rhs) const noexcept { return _hash != Hash(rhs); } \
|
||||||
}; \
|
}; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
|
|
Loading…
Reference in New Issue