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 << "\""; \
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
// Assert is empty if NO_ASSERT is defined.
#define Assert(expr) ;

View File

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

File diff suppressed because one or more lines are too long

View File

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

View File

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

View File

@ -2,8 +2,8 @@
#define ARBUTILS_NONNULLOWNPTR_HPP
#include "../Assert.hpp"
#include "NonNullBorrowedPtr.hpp"
#include "BorrowedPtr.hpp"
#include "NonNullBorrowedPtr.hpp"
namespace Arbutils::Memory {
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]") {
auto val = Arbutils::ConstString("foobar");
switch (val){
switch (val) {
case "foo"_c: FAIL(); break;
case "bar"_c: FAIL(); 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]") {
auto val = Arbutils::CaseInsensitiveConstString("foobar");
switch (val){
switch (val) {
case "foo"_cnc: FAIL(); break;
case "bar"_cnc: FAIL(); break;
case "FOObAr"_cnc: SUCCEED(); break;
@ -45,8 +45,9 @@ TEST_CASE("Use case insensitive const string in switch case", "[Utilities]") {
#ifndef WINDOWS
__attribute__((optnone))
#endif
static Arbutils::CaseInsensitiveConstString TestCreateConstString(){
char originalVal [7];
static Arbutils::CaseInsensitiveConstString
TestCreateConstString() {
char originalVal[7];
originalVal[0] = 'f';
originalVal[1] = '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]") {
Arbutils::CaseInsensitiveConstString val;
{
val = "foobar"_cnc;
}
{ val = "foobar"_cnc; }
INFO(val.c_str());
REQUIRE(strcmp(val.c_str(), "foobar") == 0);
}
#endif

View File

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

View File

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