From 9c87f9d9c86ae2bc93037b2315747e21bfa287f2 Mon Sep 17 00:00:00 2001 From: "keldu.magnus" Date: Sun, 9 Aug 2020 02:09:49 +0200 Subject: [PATCH] this time the correct clang-format has been used --- .clang-format | 4 +- source/async.cpp | 160 ++++++++++++++++++++-------------------- source/async.h | 112 ++++++++++++++-------------- source/async.o | Bin 33104 -> 33104 bytes source/common.h | 8 +- source/error.cpp | 4 +- source/error.h | 54 +++++++------- source/linear_algebra.h | 40 +++++----- 8 files changed, 192 insertions(+), 190 deletions(-) diff --git a/.clang-format b/.clang-format index b34109e..ec3b65b 100644 --- a/.clang-format +++ b/.clang-format @@ -71,7 +71,7 @@ IncludeCategories: IncludeIsMainRegex: '(Test)?$' IndentCaseLabels: false IndentPPDirectives: None -IndentWidth: 2 +IndentWidth: 4 IndentWrappedFunctionNames: false JavaScriptQuotes: Leave JavaScriptWrapImports: true @@ -116,6 +116,6 @@ StatementMacros: - Q_UNUSED - QT_REQUIRE_VERSION TabWidth: 4 -UseTab: ForIndentation +UseTab: ForContinuationAndIndentation ... diff --git a/source/async.cpp b/source/async.cpp index 44b6ba7..8567478 100644 --- a/source/async.cpp +++ b/source/async.cpp @@ -12,95 +12,95 @@ Event::Event(EventLoop &loop) : loop{loop} {} Event::~Event() { disarm(); } void Event::armNext() { - assert(&loop == local_loop); - if (prev == nullptr) { - // Push the next_insert_point back by one - // and inserts itself before that - next = *loop.next_insert_point; - prev = loop.next_insert_point; - *prev = this; - if (next) { - next->prev = &next; + assert(&loop == local_loop); + if (prev == nullptr) { + // Push the next_insert_point back by one + // and inserts itself before that + next = *loop.next_insert_point; + prev = loop.next_insert_point; + *prev = this; + if (next) { + next->prev = &next; + } + + // Set the new insertion ptr location to next + loop.next_insert_point = &next; + + // Pushes back the later insert point if it was pointing at the + // previous event + if (loop.later_insert_point == prev) { + loop.later_insert_point = &next; + } + + // If tail points at the same location then + // we are at the end and have to update tail then. + // Technically should be possible by checking if + // next is a `nullptr` + if (loop.tail == prev) { + loop.tail = &next; + } + + loop.setRunnable(true); } - - // Set the new insertion ptr location to next - loop.next_insert_point = &next; - - // Pushes back the later insert point if it was pointing at the - // previous event - if (loop.later_insert_point == prev) { - loop.later_insert_point = &next; - } - - // If tail points at the same location then - // we are at the end and have to update tail then. - // Technically should be possible by checking if - // next is a `nullptr` - if (loop.tail == prev) { - loop.tail = &next; - } - - loop.setRunnable(true); - } } void Event::armLater() { - assert(&loop == local_loop); + assert(&loop == local_loop); - if (prev == nullptr) { - next = *loop.later_insert_point; - prev = loop.later_insert_point; - *prev = this; - if (next) { - next->prev = &next; + if (prev == nullptr) { + next = *loop.later_insert_point; + prev = loop.later_insert_point; + *prev = this; + if (next) { + next->prev = &next; + } + + loop.later_insert_point = &next; + if (loop.tail == prev) { + loop.tail = &next; + } + + loop.setRunnable(true); } - - loop.later_insert_point = &next; - if (loop.tail == prev) { - loop.tail = &next; - } - - loop.setRunnable(true); - } } void Event::armLast() { - assert(&loop == local_loop); + assert(&loop == local_loop); - if (prev == nullptr) { - next = *loop.later_insert_point; - prev = loop.later_insert_point; - *prev = this; - if (next) { - next->prev = &next; + if (prev == nullptr) { + next = *loop.later_insert_point; + prev = loop.later_insert_point; + *prev = this; + if (next) { + next->prev = &next; + } + + if (loop.tail == prev) { + loop.tail = &next; + } + + loop.setRunnable(true); } - - if (loop.tail == prev) { - loop.tail = &next; - } - - loop.setRunnable(true); - } } void Event::disarm() { - if (!prev) { - if (loop.tail == &next) { - loop.tail = prev; - } + if (!prev) { + if (loop.tail == &next) { + loop.tail = prev; + } - if (loop.next_insert_point == &next) { - loop.next_insert_point = prev; - } + if (loop.next_insert_point == &next) { + loop.next_insert_point = prev; + } - *prev = next; - if (next) { - next->prev = prev; - } + *prev = next; + if (next) { + next->prev = prev; + } - prev = nullptr; - next = nullptr; - } + prev = nullptr; + next = nullptr; + } } void EventLoop::setRunnable(bool runnable) { is_runnable = runnable; } @@ -110,21 +110,21 @@ EventLoop::EventLoop() {} EventLoop::~EventLoop() { assert(local_loop != this); } void EventLoop::enterScope() { - assert(!local_loop); - local_loop = this; + assert(!local_loop); + local_loop = this; } void EventLoop::leaveScope() { - assert(local_loop == this); - local_loop = nullptr; + assert(local_loop == this); + local_loop = nullptr; } bool EventLoop::wait(const std::chrono::steady_clock::duration &duration) { - return false; + return false; } bool EventLoop::wait(const std::chrono::steady_clock::time_point &time_point) { - return false; + return false; } bool EventLoop::wait() { return false; } @@ -138,11 +138,11 @@ WaitScope::~WaitScope() { loop.leaveScope(); } void WaitScope::wait() { loop.wait(); } void WaitScope::wait(const std::chrono::steady_clock::duration &duration) { - loop.wait(duration); + loop.wait(duration); } void WaitScope::wait(const std::chrono::steady_clock::time_point &time_point) { - loop.wait(time_point); + loop.wait(time_point); } void WaitScope::poll() { loop.poll(); } diff --git a/source/async.h b/source/async.h index 4fd48e1..60d42c1 100644 --- a/source/async.h +++ b/source/async.h @@ -7,23 +7,23 @@ namespace gin { class ConveyorNode { -public: - virtual ~ConveyorNode() = default; + public: + virtual ~ConveyorNode() = default; }; class ConveyorBase { -private: - Own node; + private: + Own node; -public: - virtual ~ConveyorBase() = default; + public: + virtual ~ConveyorBase() = default; }; template struct ReturnTypeHelper { - typedef decltype(instance()(instance())) Type; + typedef decltype(instance()(instance())) Type; }; template struct ReturnTypeHelper { - typedef decltype(instance()()) Type; + typedef decltype(instance()()) Type; }; template @@ -42,84 +42,84 @@ template using ConveyorResult = ChainedConveyors>; template class Conveyor : public ConveyorBase { -private: -public: - template - ConveyorResult then(Func &&func, ErrorFunc &&error_func); + private: + public: + template + ConveyorResult then(Func &&func, ErrorFunc &&error_func); }; class EventLoop; class Event { -private: - EventLoop &loop; - Event **prev = nullptr; - Event *next = nullptr; + private: + EventLoop &loop; + Event **prev = nullptr; + Event *next = nullptr; -public: - Event(EventLoop &loop); - virtual ~Event(); + public: + Event(EventLoop &loop); + virtual ~Event(); - virtual void fire() = 0; + virtual void fire() = 0; - void armNext(); - void armLater(); - void armLast(); - void disarm(); + void armNext(); + void armLater(); + void armLast(); + void disarm(); }; class EventLoop { -private: - friend class Event; - Event *head = nullptr; - Event **tail = &head; - Event **next_insert_point = &head; - Event **later_insert_point = &head; + private: + friend class Event; + Event *head = nullptr; + Event **tail = &head; + Event **next_insert_point = &head; + Event **later_insert_point = &head; - bool is_runnable = false; + bool is_runnable = false; - // functions - void setRunnable(bool runnable); + // functions + void setRunnable(bool runnable); - friend class WaitScope; - void enterScope(); - void leaveScope(); + friend class WaitScope; + void enterScope(); + void leaveScope(); -public: - EventLoop(); - ~EventLoop(); + public: + EventLoop(); + ~EventLoop(); - bool wait(); - bool wait(const std::chrono::steady_clock::duration &); - bool wait(const std::chrono::steady_clock::time_point &); - bool poll(); + bool wait(); + bool wait(const std::chrono::steady_clock::duration &); + bool wait(const std::chrono::steady_clock::time_point &); + bool poll(); }; class WaitScope { -private: - EventLoop &loop; + private: + EventLoop &loop; -public: - WaitScope(EventLoop &loop); - ~WaitScope(); + public: + WaitScope(EventLoop &loop); + ~WaitScope(); - void wait(); - void wait(const std::chrono::steady_clock::duration &); - void wait(const std::chrono::steady_clock::time_point &); - void poll(); + void wait(); + void wait(const std::chrono::steady_clock::duration &); + void wait(const std::chrono::steady_clock::time_point &); + void poll(); }; class InputConveyorNode : public ConveyorNode { -public: + public: }; template class ConvertConveyorNode : public ConveyorNode {}; template class ArrayBufferConveyorNode : public ConveyorNode, public Event { -private: - std::array storage; + private: + std::array storage; -public: + public: }; } // namespace gin // Template inlining diff --git a/source/async.o b/source/async.o index e5541785b80860b965f3f3a8ea0c6db903449264..fe64a8a2423b33e9cec715c10c0e2069c9537135 100644 GIT binary patch delta 1100 zcma))&uddb5XX1lWHv7^n!c)S(>7_-f>e-D!5#-T=bqZ+zsmP3cf7UCOC0<#eP7 zGPgc9gxBCyVXgS(_aHlS>yhdiN3v zi*PACP@V{sf^R}&T4~&)(QlwC!Hb}QzJl+hCrHm|cphjZ@<&9DY0Mk)8IgGfKO=Hj z!&4$X1;0oE%5^#KgsQsMjt3)Qlt@30*{BDgsgr`U`u zEwbFeT?z)+)+$noC5<@+!x|mB4>C1pCK;hn!(szR6%;I;({P;un6Sh82AOA5eX!3m zG-!=$!G3o3VEQmSJGd=p+BlnPJDZ^mDL7`G4RPbDac0||HM=OayPh#!%hZ)dmFh8y zbp)@a!V8st_V9_ewvF|?r5)3LHq4IAg5KD7`%DVIu5ks5D`jhj8tnk@h5`S;*YixsVM#c&w=^} zcz7odR#8EZYSDxApcg$9wB%3~6vTfa;MtkoXI>-?1v5F$Axg@|&xC&zpE_X+11*Q*rC zQpaQyb}}>lftYQB|U zXFzV(@RZ0N1;0p9l$+qZ2{i+ch}@#!cR==OSSHf-H_BrT;xiii2v3q!!lbHVnr<%F zsA7UbTjW|DvkJ&(Of4goSkzchuuUV7B zQ(4$$85(qkYr$@I_TbY)v%#)`8 diff --git a/source/common.h b/source/common.h index 7f2d59b..ea0f099 100644 --- a/source/common.h +++ b/source/common.h @@ -12,8 +12,8 @@ namespace gin { #define GIN_UNIQUE_NAME(prefix) GIN_CONCAT(prefix, __LINE__) #define GIN_FORBID_COPY(classname) \ - classname(const classname &) = delete; \ - classname &operator=(const classname &) = delete + classname(const classname &) = delete; \ + classname &operator=(const classname &) = delete template using Maybe = std::optional; @@ -24,11 +24,11 @@ template using Our = std::shared_ptr; template using Lent = std::weak_ptr; template Own heap(Args &&... args) { - return std::make_unique(std::forward(args)...); + return std::make_unique(std::forward(args)...); } template Our share(Args &&... args) { - return std::make_shared(std::forward(args)...); + return std::make_shared(std::forward(args)...); } struct Void {}; diff --git a/source/error.cpp b/source/error.cpp index 60c8eab..ada8285 100644 --- a/source/error.cpp +++ b/source/error.cpp @@ -6,10 +6,10 @@ Error::Error() : error_{0} {} Error::Error(const std::string &msg) : error_message{msg}, error_{1} {} Error::Error(const std::string &msg, int8_t code) - : error_message{msg}, error_{code} {} + : error_message{msg}, error_{code} {} Error::Error(const Error &error) - : error_message{error.error_message}, error_{error.error_} {} + : error_message{error.error_message}, error_{error.error_} {} const std::string &Error::message() const { return error_message; } diff --git a/source/error.h b/source/error.h index 91790f5..85abdfc 100644 --- a/source/error.h +++ b/source/error.h @@ -5,21 +5,21 @@ namespace gin { class Error { -private: - std::string error_message; - int8_t error_; + private: + std::string error_message; + int8_t error_; -public: - Error(); - Error(const std::string &msg); - Error(const std::string &msg, int8_t code); - Error(const Error &error); + public: + Error(); + Error(const std::string &msg); + Error(const std::string &msg, int8_t code); + Error(const Error &error); - const std::string &message() const; - bool failed() const; + const std::string &message() const; + bool failed() const; - bool isCritical() const; - bool isRecoverable() const; + bool isCritical() const; + bool isRecoverable() const; }; Error criticalError(const std::string &msg); @@ -27,30 +27,32 @@ Error recoverableError(const std::string &msg); Error noError(); class ErrorOrValue { -public: - virtual ~ErrorOrValue() = default; + public: + virtual ~ErrorOrValue() = default; }; template class ErrorOr : public ErrorOrValue { -private: - std::variant value_or_error; + private: + std::variant value_or_error; -public: - ErrorOr(const T &value) : value_or_error{value} {} + public: + ErrorOr(const T &value) : value_or_error{value} {} - ErrorOr(T &&value) : value_or_error{std::move(value)} {} + ErrorOr(T &&value) : value_or_error{std::move(value)} {} - ErrorOr(const Error &error) : value_or_error{error} {} - ErrorOr(Error &&error) : value_or_error{std::move(error)} {} + ErrorOr(const Error &error) : value_or_error{error} {} + ErrorOr(Error &&error) : value_or_error{std::move(error)} {} - bool isValue() const { return std::holds_alternative(value_or_error); } + bool isValue() const { return std::holds_alternative(value_or_error); } - bool isError() const { return std::holds_alternative(value_or_error); } + bool isError() const { + return std::holds_alternative(value_or_error); + } - const Error &error() const { return std::get(value_or_error); } + const Error &error() const { return std::get(value_or_error); } - T &value() { return std::get(value_or_error); } + T &value() { return std::get(value_or_error); } - const T &value() const { return std::get(value_or_error); } + const T &value() const { return std::get(value_or_error); } }; } // namespace gin diff --git a/source/linear_algebra.h b/source/linear_algebra.h index c0fc8fe..de83d2d 100644 --- a/source/linear_algebra.h +++ b/source/linear_algebra.h @@ -5,32 +5,32 @@ namespace gin { template class Matrix { -private: - std::array data; + private: + std::array data; -public: - Matrix(); + public: + Matrix(); - T &operator()(size_t i, size_t j); - const T &operator()(size_t i, size_t j) const; + T &operator()(size_t i, size_t j); + const T &operator()(size_t i, size_t j) const; - template - Matrix operator*(const Matrix &rhs) const; + template + Matrix operator*(const Matrix &rhs) const; - Vector operator*(const Vector &rhs) const; + Vector operator*(const Vector &rhs) const; }; template class Vector { -private: - std::array data; + private: + std::array data; -public: - Vector(); + public: + Vector(); - T operator*(const Vector &rhs) const; + T operator*(const Vector &rhs) const; - T &operator()(size_t i); - const T &operator()(size_t i) const; + T &operator()(size_t i); + const T &operator()(size_t i) const; }; } // namespace gin @@ -38,12 +38,12 @@ namespace gin { // column major is "i + j * M"; template T &Matrix::operator()(size_t i, size_t j) { - assert(i < M && j < N); - return data[i * N + j]; + assert(i < M && j < N); + return data[i * N + j]; } template const T &Matrix::operator()(size_t i, size_t j) const { - assert(i < M && j < N); - return data[i * N + j]; + assert(i < M && j < N); + return data[i * N + j]; } } // namespace gin \ No newline at end of file