formatted with correct clang-format
This commit is contained in:
parent
d86419c29c
commit
389c21b435
|
@ -0,0 +1,121 @@
|
|||
---
|
||||
Language: Cpp
|
||||
# BasedOnStyle: LLVM
|
||||
AccessModifierOffset: -2
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignConsecutiveAssignments: false
|
||||
AlignConsecutiveDeclarations: false
|
||||
AlignEscapedNewlines: Right
|
||||
AlignOperands: true
|
||||
AlignTrailingComments: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
AllowShortBlocksOnASingleLine: false
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: All
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AlwaysBreakAfterDefinitionReturnType: None
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: false
|
||||
AlwaysBreakTemplateDeclarations: MultiLine
|
||||
BinPackArguments: true
|
||||
BinPackParameters: true
|
||||
BraceWrapping:
|
||||
AfterClass: false
|
||||
AfterControlStatement: false
|
||||
AfterEnum: false
|
||||
AfterFunction: false
|
||||
AfterNamespace: false
|
||||
AfterObjCDeclaration: false
|
||||
AfterStruct: false
|
||||
AfterUnion: false
|
||||
AfterExternBlock: false
|
||||
BeforeCatch: false
|
||||
BeforeElse: false
|
||||
IndentBraces: false
|
||||
SplitEmptyFunction: true
|
||||
SplitEmptyRecord: true
|
||||
SplitEmptyNamespace: true
|
||||
BreakBeforeBinaryOperators: None
|
||||
BreakBeforeBraces: Attach
|
||||
BreakBeforeInheritanceComma: false
|
||||
BreakInheritanceList: BeforeColon
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializersBeforeComma: false
|
||||
BreakConstructorInitializers: BeforeColon
|
||||
BreakAfterJavaFieldAnnotations: false
|
||||
BreakStringLiterals: true
|
||||
ColumnLimit: 80
|
||||
CommentPragmas: '^ IWYU pragma:'
|
||||
CompactNamespaces: false
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
ContinuationIndentWidth: 4
|
||||
Cpp11BracedListStyle: true
|
||||
DerivePointerAlignment: false
|
||||
DisableFormat: false
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
FixNamespaceComments: true
|
||||
ForEachMacros:
|
||||
- foreach
|
||||
- Q_FOREACH
|
||||
- BOOST_FOREACH
|
||||
IncludeBlocks: Preserve
|
||||
IncludeCategories:
|
||||
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
|
||||
Priority: 2
|
||||
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
|
||||
Priority: 3
|
||||
- Regex: '.*'
|
||||
Priority: 1
|
||||
IncludeIsMainRegex: '(Test)?$'
|
||||
IndentCaseLabels: false
|
||||
IndentPPDirectives: None
|
||||
IndentWidth: 2
|
||||
IndentWrappedFunctionNames: false
|
||||
JavaScriptQuotes: Leave
|
||||
JavaScriptWrapImports: true
|
||||
KeepEmptyLinesAtTheStartOfBlocks: true
|
||||
MacroBlockBegin: ''
|
||||
MacroBlockEnd: ''
|
||||
MaxEmptyLinesToKeep: 1
|
||||
NamespaceIndentation: None
|
||||
ObjCBinPackProtocolList: Auto
|
||||
ObjCBlockIndentWidth: 2
|
||||
ObjCSpaceAfterProperty: false
|
||||
ObjCSpaceBeforeProtocolList: true
|
||||
PenaltyBreakAssignment: 2
|
||||
PenaltyBreakBeforeFirstCallParameter: 19
|
||||
PenaltyBreakComment: 300
|
||||
PenaltyBreakFirstLessLess: 120
|
||||
PenaltyBreakString: 1000
|
||||
PenaltyBreakTemplateDeclaration: 10
|
||||
PenaltyExcessCharacter: 1000000
|
||||
PenaltyReturnTypeOnItsOwnLine: 60
|
||||
PointerAlignment: Right
|
||||
ReflowComments: true
|
||||
SortIncludes: true
|
||||
SortUsingDeclarations: true
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceAfterTemplateKeyword: true
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeCpp11BracedList: false
|
||||
SpaceBeforeCtorInitializerColon: true
|
||||
SpaceBeforeInheritanceColon: true
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceBeforeRangeBasedForLoopColon: true
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 1
|
||||
SpacesInAngles: false
|
||||
SpacesInContainerLiterals: true
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInParentheses: false
|
||||
SpacesInSquareBrackets: false
|
||||
Standard: Cpp11
|
||||
StatementMacros:
|
||||
- Q_UNUSED
|
||||
- QT_REQUIRE_VERSION
|
||||
TabWidth: 4
|
||||
UseTab: ForIndentation
|
||||
...
|
||||
|
128
source/async.cpp
128
source/async.cpp
|
@ -4,43 +4,43 @@
|
|||
|
||||
namespace gin {
|
||||
namespace {
|
||||
thread_local EventLoop* local_loop = nullptr;
|
||||
thread_local EventLoop *local_loop = nullptr;
|
||||
}
|
||||
|
||||
Event::Event(EventLoop& loop) : loop{loop} {}
|
||||
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;
|
||||
}
|
||||
// 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;
|
||||
// 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;
|
||||
}
|
||||
// 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;
|
||||
}
|
||||
// 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);
|
||||
loop.setRunnable(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -48,19 +48,19 @@ void Event::armLater() {
|
|||
assert(&loop == local_loop);
|
||||
|
||||
if (prev == nullptr) {
|
||||
next = *loop.later_insert_point;
|
||||
prev = loop.later_insert_point;
|
||||
*prev = this;
|
||||
if (next) {
|
||||
next->prev = &next;
|
||||
}
|
||||
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.later_insert_point = &next;
|
||||
if (loop.tail == prev) {
|
||||
loop.tail = &next;
|
||||
}
|
||||
|
||||
loop.setRunnable(true);
|
||||
loop.setRunnable(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -68,38 +68,38 @@ void Event::armLast() {
|
|||
assert(&loop == local_loop);
|
||||
|
||||
if (prev == nullptr) {
|
||||
next = *loop.later_insert_point;
|
||||
prev = loop.later_insert_point;
|
||||
*prev = this;
|
||||
if (next) {
|
||||
next->prev = &next;
|
||||
}
|
||||
next = *loop.later_insert_point;
|
||||
prev = loop.later_insert_point;
|
||||
*prev = this;
|
||||
if (next) {
|
||||
next->prev = &next;
|
||||
}
|
||||
|
||||
if (loop.tail == prev) {
|
||||
loop.tail = &next;
|
||||
}
|
||||
if (loop.tail == prev) {
|
||||
loop.tail = &next;
|
||||
}
|
||||
|
||||
loop.setRunnable(true);
|
||||
loop.setRunnable(true);
|
||||
}
|
||||
}
|
||||
|
||||
void Event::disarm() {
|
||||
if (!prev) {
|
||||
if (loop.tail == &next) {
|
||||
loop.tail = 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -119,11 +119,11 @@ void EventLoop::leaveScope() {
|
|||
local_loop = nullptr;
|
||||
}
|
||||
|
||||
bool EventLoop::wait(const std::chrono::steady_clock::duration& duration) {
|
||||
bool EventLoop::wait(const std::chrono::steady_clock::duration &duration) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool EventLoop::wait(const std::chrono::steady_clock::time_point& time_point) {
|
||||
bool EventLoop::wait(const std::chrono::steady_clock::time_point &time_point) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -131,19 +131,19 @@ bool EventLoop::wait() { return false; }
|
|||
|
||||
bool EventLoop::poll() { return false; }
|
||||
|
||||
WaitScope::WaitScope(EventLoop& loop) : loop{loop} { loop.enterScope(); }
|
||||
WaitScope::WaitScope(EventLoop &loop) : loop{loop} { loop.enterScope(); }
|
||||
|
||||
WaitScope::~WaitScope() { loop.leaveScope(); }
|
||||
|
||||
void WaitScope::wait() { loop.wait(); }
|
||||
|
||||
void WaitScope::wait(const std::chrono::steady_clock::duration& duration) {
|
||||
void WaitScope::wait(const std::chrono::steady_clock::duration &duration) {
|
||||
loop.wait(duration);
|
||||
}
|
||||
|
||||
void WaitScope::wait(const std::chrono::steady_clock::time_point& time_point) {
|
||||
void WaitScope::wait(const std::chrono::steady_clock::time_point &time_point) {
|
||||
loop.wait(time_point);
|
||||
}
|
||||
|
||||
void WaitScope::poll() { loop.poll(); }
|
||||
} // namespace gin
|
||||
} // namespace gin
|
|
@ -7,62 +7,56 @@
|
|||
|
||||
namespace gin {
|
||||
class ConveyorNode {
|
||||
public:
|
||||
public:
|
||||
virtual ~ConveyorNode() = default;
|
||||
};
|
||||
|
||||
class ConveyorBase {
|
||||
private:
|
||||
private:
|
||||
Own<ConveyorNode> node;
|
||||
|
||||
public:
|
||||
public:
|
||||
virtual ~ConveyorBase() = default;
|
||||
};
|
||||
|
||||
template <typename Func, typename T>
|
||||
struct ReturnTypeHelper {
|
||||
template <typename Func, typename T> struct ReturnTypeHelper {
|
||||
typedef decltype(instance<Func>()(instance<T>())) Type;
|
||||
};
|
||||
template <typename Func>
|
||||
struct ReturnTypeHelper<Func, void> {
|
||||
template <typename Func> struct ReturnTypeHelper<Func, void> {
|
||||
typedef decltype(instance<Func>()()) Type;
|
||||
};
|
||||
|
||||
template <typename Func, typename T>
|
||||
using ReturnType = typename ReturnTypeHelper<Func, T>::Type;
|
||||
|
||||
template <typename T>
|
||||
class Conveyor;
|
||||
template <typename T> class Conveyor;
|
||||
|
||||
template <typename T> Conveyor<T> chainedConveyorType(T *);
|
||||
|
||||
template <typename T> Conveyor<T> chainedConveyorType(Conveyor<T> *);
|
||||
|
||||
template <typename T>
|
||||
Conveyor<T> chainedConveyorType(T*);
|
||||
|
||||
template <typename T>
|
||||
Conveyor<T> chainedConveyorType(Conveyor<T>*);
|
||||
|
||||
template <typename T>
|
||||
using ChainedConveyors = decltype(chainedConveyorType((T*)nullptr));
|
||||
using ChainedConveyors = decltype(chainedConveyorType((T *)nullptr));
|
||||
|
||||
template <typename Func, typename T>
|
||||
using ConveyorResult = ChainedConveyors<ReturnType<Func, T>>;
|
||||
|
||||
template <typename T>
|
||||
class Conveyor : public ConveyorBase {
|
||||
private:
|
||||
public:
|
||||
template <typename T> class Conveyor : public ConveyorBase {
|
||||
private:
|
||||
public:
|
||||
template <typename Func, typename ErrorFunc>
|
||||
ConveyorResult<Func, T> then(Func&& func, ErrorFunc&& error_func);
|
||||
ConveyorResult<Func, T> 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);
|
||||
public:
|
||||
Event(EventLoop &loop);
|
||||
virtual ~Event();
|
||||
|
||||
virtual void fire() = 0;
|
||||
|
@ -74,12 +68,12 @@ class Event {
|
|||
};
|
||||
|
||||
class EventLoop {
|
||||
private:
|
||||
private:
|
||||
friend class Event;
|
||||
Event* head = nullptr;
|
||||
Event** tail = &head;
|
||||
Event** next_insert_point = &head;
|
||||
Event** later_insert_point = &head;
|
||||
Event *head = nullptr;
|
||||
Event **tail = &head;
|
||||
Event **next_insert_point = &head;
|
||||
Event **later_insert_point = &head;
|
||||
|
||||
bool is_runnable = false;
|
||||
|
||||
|
@ -90,44 +84,43 @@ class EventLoop {
|
|||
void enterScope();
|
||||
void leaveScope();
|
||||
|
||||
public:
|
||||
public:
|
||||
EventLoop();
|
||||
~EventLoop();
|
||||
|
||||
bool wait();
|
||||
bool wait(const std::chrono::steady_clock::duration&);
|
||||
bool wait(const std::chrono::steady_clock::time_point&);
|
||||
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);
|
||||
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 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 <typename T>
|
||||
class ConvertConveyorNode : public ConveyorNode {};
|
||||
template <typename T> class ConvertConveyorNode : public ConveyorNode {};
|
||||
|
||||
template <typename T, size_t S>
|
||||
class ArrayBufferConveyorNode : public ConveyorNode, public Event {
|
||||
private:
|
||||
private:
|
||||
std::array<T, S> storage;
|
||||
|
||||
public:
|
||||
public:
|
||||
};
|
||||
} // namespace gin
|
||||
} // namespace gin
|
||||
// Template inlining
|
||||
namespace ent {}
|
||||
|
|
|
@ -11,35 +11,28 @@ namespace gin {
|
|||
#define GIN_CONCAT(x, y) GIN_CONCAT_(x, y)
|
||||
#define GIN_UNIQUE_NAME(prefix) GIN_CONCAT(prefix, __LINE__)
|
||||
|
||||
#define GIN_FORBID_COPY(classname) \
|
||||
classname(const classname&) = delete; \
|
||||
classname& operator=(const classname&) = delete
|
||||
#define GIN_FORBID_COPY(classname) \
|
||||
classname(const classname &) = delete; \
|
||||
classname &operator=(const classname &) = delete
|
||||
|
||||
template <typename T>
|
||||
using Maybe = std::optional<T>;
|
||||
template <typename T> using Maybe = std::optional<T>;
|
||||
|
||||
template <typename T>
|
||||
using Own = std::unique_ptr<T>;
|
||||
template <typename T> using Own = std::unique_ptr<T>;
|
||||
|
||||
template <typename T>
|
||||
using Our = std::shared_ptr<T>;
|
||||
template <typename T> using Our = std::shared_ptr<T>;
|
||||
|
||||
template <typename T>
|
||||
using Lent = std::weak_ptr<T>;
|
||||
template <typename T> using Lent = std::weak_ptr<T>;
|
||||
|
||||
template <typename T, class... Args>
|
||||
Own<T> heap(Args&&... args) {
|
||||
template <typename T, class... Args> Own<T> heap(Args &&... args) {
|
||||
return std::make_unique<T>(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename T, class... Args>
|
||||
Our<T> share(Args&&... args) {
|
||||
template <typename T, class... Args> Our<T> share(Args &&... args) {
|
||||
return std::make_shared<T>(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
struct Void {};
|
||||
|
||||
template <typename T>
|
||||
T instance() noexcept;
|
||||
template <typename T> T instance() noexcept;
|
||||
|
||||
} // namespace gin
|
||||
} // namespace gin
|
|
@ -3,15 +3,15 @@
|
|||
namespace gin {
|
||||
Error::Error() : error_{0} {}
|
||||
|
||||
Error::Error(const std::string& msg) : error_message{msg}, error_{1} {}
|
||||
Error::Error(const std::string &msg) : error_message{msg}, error_{1} {}
|
||||
|
||||
Error::Error(const std::string& msg, int8_t code)
|
||||
Error::Error(const std::string &msg, int8_t code)
|
||||
: error_message{msg}, error_{code} {}
|
||||
|
||||
Error::Error(const Error& error)
|
||||
Error::Error(const Error &error)
|
||||
: error_message{error.error_message}, error_{error.error_} {}
|
||||
|
||||
const std::string& Error::message() const { return error_message; }
|
||||
const std::string &Error::message() const { return error_message; }
|
||||
|
||||
bool Error::failed() const { return error_ != 0; }
|
||||
|
||||
|
@ -19,9 +19,9 @@ bool Error::isCritical() const { return error_ < 0; }
|
|||
|
||||
bool Error::isRecoverable() const { return error_ > 0; }
|
||||
|
||||
Error criticalError(const std::string& msg) { return Error{msg, -1}; }
|
||||
Error criticalError(const std::string &msg) { return Error{msg, -1}; }
|
||||
|
||||
Error recoverableError(const std::string& msg) { return Error{msg, 1}; }
|
||||
Error recoverableError(const std::string &msg) { return Error{msg, 1}; }
|
||||
|
||||
Error noError() { return Error{}; }
|
||||
} // namespace gin
|
||||
} // namespace gin
|
||||
|
|
|
@ -5,53 +5,52 @@
|
|||
|
||||
namespace gin {
|
||||
class Error {
|
||||
private:
|
||||
private:
|
||||
std::string error_message;
|
||||
int8_t error_;
|
||||
|
||||
public:
|
||||
public:
|
||||
Error();
|
||||
Error(const std::string& msg);
|
||||
Error(const std::string& msg, int8_t code);
|
||||
Error(const Error& error);
|
||||
Error(const std::string &msg);
|
||||
Error(const std::string &msg, int8_t code);
|
||||
Error(const Error &error);
|
||||
|
||||
const std::string& message() const;
|
||||
const std::string &message() const;
|
||||
bool failed() const;
|
||||
|
||||
bool isCritical() const;
|
||||
bool isRecoverable() const;
|
||||
};
|
||||
|
||||
Error criticalError(const std::string& msg);
|
||||
Error recoverableError(const std::string& msg);
|
||||
Error criticalError(const std::string &msg);
|
||||
Error recoverableError(const std::string &msg);
|
||||
Error noError();
|
||||
|
||||
class ErrorOrValue {
|
||||
public:
|
||||
public:
|
||||
virtual ~ErrorOrValue() = default;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class ErrorOr : public ErrorOrValue {
|
||||
private:
|
||||
template <typename T> class ErrorOr : public ErrorOrValue {
|
||||
private:
|
||||
std::variant<T, Error> 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<T>(value_or_error); }
|
||||
|
||||
bool isError() const { return std::holds_alternative<Error>(value_or_error); }
|
||||
|
||||
const Error& error() const { return std::get<Error>(value_or_error); }
|
||||
const Error &error() const { return std::get<Error>(value_or_error); }
|
||||
|
||||
T& value() { return std::get<T>(value_or_error); }
|
||||
T &value() { return std::get<T>(value_or_error); }
|
||||
|
||||
const T& value() const { return std::get<T>(value_or_error); }
|
||||
const T &value() const { return std::get<T>(value_or_error); }
|
||||
};
|
||||
} // namespace gin
|
||||
} // namespace gin
|
||||
|
|
|
@ -4,48 +4,46 @@
|
|||
#include <cstdint>
|
||||
|
||||
namespace gin {
|
||||
template <typename T, size_t M, size_t N>
|
||||
class Matrix {
|
||||
private:
|
||||
template <typename T, size_t M, size_t N> class Matrix {
|
||||
private:
|
||||
std::array<T, M * N> data;
|
||||
|
||||
public:
|
||||
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 <size_t K>
|
||||
Matrix<T, M, K> operator*(const Matrix<T, N, K>& rhs) const;
|
||||
Matrix<T, M, K> operator*(const Matrix<T, N, K> &rhs) const;
|
||||
|
||||
Vector<T, M> operator*(const Vector<T, N>& rhs) const;
|
||||
Vector<T, M> operator*(const Vector<T, N> &rhs) const;
|
||||
};
|
||||
|
||||
template <typename T, size_t N>
|
||||
class Vector {
|
||||
private:
|
||||
template <typename T, size_t N> class Vector {
|
||||
private:
|
||||
std::array<T, N> data;
|
||||
|
||||
public:
|
||||
public:
|
||||
Vector();
|
||||
|
||||
T operator*(const Vector<T, N>& rhs) const;
|
||||
T operator*(const Vector<T, N> &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
|
||||
} // namespace gin
|
||||
|
||||
namespace gin {
|
||||
// column major is "i + j * M";
|
||||
template <typename T, size_t M, size_t N>
|
||||
T& Matrix<T, M, N>::operator()(size_t i, size_t j) {
|
||||
T &Matrix<T, M, N>::operator()(size_t i, size_t j) {
|
||||
assert(i < M && j < N);
|
||||
return data[i * N + j];
|
||||
}
|
||||
template <typename T, size_t M, size_t N>
|
||||
const T& Matrix<T, M, N>::operator()(size_t i, size_t j) const {
|
||||
const T &Matrix<T, M, N>::operator()(size_t i, size_t j) const {
|
||||
assert(i < M && j < N);
|
||||
return data[i * N + j];
|
||||
}
|
||||
} // namespace gin
|
||||
} // namespace gin
|
Loading…
Reference in New Issue