Style fixes.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-04-28 16:55:00 +02:00
parent 8111d5ea0a
commit 2e227a2688
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
9 changed files with 3040 additions and 827 deletions

View File

@ -12,7 +12,11 @@
ss << #expr << "\""; \ ss << #expr << "\""; \
throw std::logic_error(ss.str()); \ throw std::logic_error(ss.str()); \
} }
#define AssertForEach(iterator, assertion) { for (auto item: iterator) Assert(assertion)} #define AssertForEach(iterator, assertion) \
{ \
for (auto item : iterator) \
Assert(assertion) \
}
#else #else
// Assert is empty if NO_ASSERT is defined. // Assert is empty if NO_ASSERT is defined.
#define Assert(expr) ; #define Assert(expr) ;

View File

@ -11,14 +11,13 @@ namespace Arbutils::Collections {
using iterator = typename std::unordered_map<KeyT, ValueT>::iterator; using iterator = typename std::unordered_map<KeyT, ValueT>::iterator;
using const_iterator = typename std::unordered_map<KeyT, ValueT>::const_iterator; using const_iterator = typename std::unordered_map<KeyT, ValueT>::const_iterator;
public: public:
Dictionary() : _map() {} Dictionary() : _map() {}
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(){ inline void Clear() { _map.clear(); }
_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});
@ -28,7 +27,6 @@ namespace Arbutils::Collections {
#endif #endif
} }
inline void Set(const KeyT& key, const ValueT& value) { _map[key] = value; } inline void Set(const KeyT& key, const ValueT& value) { _map[key] = value; }
[[nodiscard]] inline ValueT& Get(const KeyT& key) { [[nodiscard]] inline ValueT& Get(const KeyT& key) {
@ -39,9 +37,7 @@ namespace Arbutils::Collections {
#endif #endif
} }
[[nodiscard]] inline const ValueT& Get(const KeyT& key) const { [[nodiscard]] inline const ValueT& Get(const KeyT& key) const { return _map.at(key); }
return _map.at(key);
}
inline bool TryGet(const KeyT& key, ValueT& out) const { inline bool TryGet(const KeyT& key, ValueT& out) const {
const auto& find = _map.find(key); const auto& find = _map.find(key);
@ -52,9 +48,7 @@ namespace Arbutils::Collections {
return true; return true;
} }
inline void Remove(const KeyT& key){ inline void Remove(const KeyT& key) { _map.erase(key); }
_map.erase(key);
}
[[nodiscard]] inline size_t Count() const { return _map.size(); } [[nodiscard]] inline size_t Count() const { return _map.size(); }

File diff suppressed because one or more lines are too long

View File

@ -2,8 +2,7 @@
#define ARBUTILS_BORROWEDPTR_HPP #define ARBUTILS_BORROWEDPTR_HPP
namespace Arbutils::Memory { namespace Arbutils::Memory {
template <class> template <class> class NonNullBorrowedPtr;
class NonNullBorrowedPtr;
template <class T> class BorrowedPtr { template <class T> class BorrowedPtr {
T* _ptr; T* _ptr;
@ -16,9 +15,7 @@ namespace Arbutils::Memory {
inline constexpr const T* GetUnsafe() const noexcept { return _ptr; } inline constexpr const T* GetUnsafe() const noexcept { return _ptr; }
inline constexpr bool IsNull() const noexcept { return _ptr == nullptr; } inline constexpr bool IsNull() const noexcept { return _ptr == nullptr; }
inline NonNullBorrowedPtr<T> GetNonNull() const { inline NonNullBorrowedPtr<T> GetNonNull() const { return NonNullBorrowedPtr<T>(_ptr); }
return NonNullBorrowedPtr<T>(_ptr);
}
T* operator->() noexcept { return _ptr; } T* operator->() noexcept { return _ptr; }
T* operator->() const noexcept { return _ptr; } T* operator->() const noexcept { return _ptr; }

View File

@ -4,8 +4,7 @@
#include "BorrowedPtr.hpp" #include "BorrowedPtr.hpp"
namespace Arbutils::Memory { namespace Arbutils::Memory {
template <class> template <class> class BorrowedPtr;
class BorrowedPtr;
template <class T> class NonNullBorrowedPtr { template <class T> class NonNullBorrowedPtr {
private: private:
@ -18,9 +17,7 @@ namespace Arbutils::Memory {
inline constexpr T* GetUnsafe() noexcept { return _ptr; } inline constexpr T* GetUnsafe() noexcept { return _ptr; }
inline constexpr const T* GetUnsafe() const noexcept { return _ptr; } inline constexpr const T* GetUnsafe() const noexcept { return _ptr; }
inline BorrowedPtr<T> GetOptional() const { inline BorrowedPtr<T> GetOptional() const { return BorrowedPtr<T>(_ptr); }
return BorrowedPtr<T>(_ptr);
}
T* operator->() noexcept { return _ptr; } T* operator->() noexcept { return _ptr; }
T* operator->() const noexcept { return _ptr; } T* operator->() const noexcept { return _ptr; }

View File

@ -2,8 +2,8 @@
#define ARBUTILS_NONNULLOWNPTR_HPP #define ARBUTILS_NONNULLOWNPTR_HPP
#include "../Assert.hpp" #include "../Assert.hpp"
#include "NonNullBorrowedPtr.hpp"
#include "BorrowedPtr.hpp" #include "BorrowedPtr.hpp"
#include "NonNullBorrowedPtr.hpp"
namespace Arbutils::Memory { namespace Arbutils::Memory {
template <class T> class NonNullOwnPtr { template <class T> class NonNullOwnPtr {

View File

@ -15,7 +15,7 @@ TEST_CASE("Use const string in unordered_map", "[Utilities]") {
TEST_CASE("Use const string in switch case", "[Utilities]") { TEST_CASE("Use const string in switch case", "[Utilities]") {
auto val = Arbutils::ConstString("foobar"); auto val = Arbutils::ConstString("foobar");
switch (val){ switch (val) {
case "foo"_c: FAIL(); break; case "foo"_c: FAIL(); break;
case "bar"_c: FAIL(); break; case "bar"_c: FAIL(); break;
case "foobar"_c: SUCCEED(); break; case "foobar"_c: SUCCEED(); break;
@ -34,7 +34,7 @@ TEST_CASE("Use insensitive const string in unordered_map", "[Utilities]") {
TEST_CASE("Use case insensitive const string in switch case", "[Utilities]") { TEST_CASE("Use case insensitive const string in switch case", "[Utilities]") {
auto val = Arbutils::CaseInsensitiveConstString("foobar"); auto val = Arbutils::CaseInsensitiveConstString("foobar");
switch (val){ switch (val) {
case "foo"_cnc: FAIL(); break; case "foo"_cnc: FAIL(); break;
case "bar"_cnc: FAIL(); break; case "bar"_cnc: FAIL(); break;
case "FOObAr"_cnc: SUCCEED(); break; case "FOObAr"_cnc: SUCCEED(); break;
@ -45,8 +45,9 @@ TEST_CASE("Use case insensitive const string in switch case", "[Utilities]") {
#ifndef WINDOWS #ifndef WINDOWS
__attribute__((optnone)) __attribute__((optnone))
#endif #endif
static Arbutils::CaseInsensitiveConstString TestCreateConstString(){ static Arbutils::CaseInsensitiveConstString
char originalVal [7]; TestCreateConstString() {
char originalVal[7];
originalVal[0] = 'f'; originalVal[0] = 'f';
originalVal[1] = 'o'; originalVal[1] = 'o';
originalVal[2] = 'o'; originalVal[2] = 'o';
@ -65,13 +66,9 @@ TEST_CASE("Out of scope char* doesn't lose reference", "[Utilities]") {
TEST_CASE("Literal conststring to non literal, then use", "[Utilities]") { TEST_CASE("Literal conststring to non literal, then use", "[Utilities]") {
Arbutils::CaseInsensitiveConstString val; Arbutils::CaseInsensitiveConstString val;
{ { val = "foobar"_cnc; }
val = "foobar"_cnc;
}
INFO(val.c_str()); INFO(val.c_str());
REQUIRE(strcmp(val.c_str(), "foobar") == 0); REQUIRE(strcmp(val.c_str(), "foobar") == 0);
} }
#endif #endif

View File

@ -19,7 +19,6 @@ TEST_CASE("Create List from initializer list", "[Utilities]") {
CHECK(ls.At(3) == -500); CHECK(ls.At(3) == -500);
} }
TEST_CASE("Create List, insert values, retrieve values", "[Utilities]") { TEST_CASE("Create List, insert values, retrieve values", "[Utilities]") {
auto ls = List<int>(); auto ls = List<int>();
ls.Append(5); ls.Append(5);
@ -40,7 +39,7 @@ TEST_CASE("Create List, insert values, iterate over values", "[Utilities]") {
ls.Append(200); ls.Append(200);
ls.Append(500); ls.Append(500);
for (auto v: ls){ for (auto v : ls) {
CHECK(ls.Contains(v)); CHECK(ls.Contains(v));
} }
} }
@ -48,7 +47,7 @@ TEST_CASE("Create List, insert values, iterate over values", "[Utilities]") {
TEST_CASE("Create const List, iterate over values", "[Utilities]") { TEST_CASE("Create const List, iterate over values", "[Utilities]") {
const auto& ls = List<int>({10, 100, 50}); const auto& ls = List<int>({10, 100, 50});
for (auto v: ls){ for (auto v : ls) {
CHECK(ls.Contains(v)); CHECK(ls.Contains(v));
} }
} }
@ -68,7 +67,4 @@ TEST_CASE("Test IndexOf", "[Utilities]") {
CHECK(ls.IndexOf(684) == -1); CHECK(ls.IndexOf(684) == -1);
} }
#endif #endif

View File

@ -3,10 +3,8 @@
#include "../src/Memory/NonNullOwnPtr.hpp" #include "../src/Memory/NonNullOwnPtr.hpp"
#include "../src/Memory/OwnPtr.hpp" #include "../src/Memory/OwnPtr.hpp"
struct TestClass{ struct TestClass {
bool GetTestBool(){ bool GetTestBool() { return true; }
return true;
}
}; };
TEST_CASE("Access OwnPtr", "[Utilities]") { TEST_CASE("Access OwnPtr", "[Utilities]") {
@ -23,5 +21,4 @@ TEST_CASE("Instantiate NonNullOwnPtr fails with nullptr", "[Utilities]") {
CHECK_THROWS(Arbutils::Memory::NonNullOwnPtr<TestClass>(nullptr)); CHECK_THROWS(Arbutils::Memory::NonNullOwnPtr<TestClass>(nullptr));
} }
#endif #endif