diff options
author | HampusM <hampus@hampusmat.com> | 2022-04-24 17:13:52 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-06-13 17:56:58 +0200 |
commit | db6edcd473a684420e9a7611b24462df21165c1b (patch) | |
tree | 9646bdb4f5f6e339a0a01873b44e0b185476ce56 /src | |
parent | b36d072ad7a7b9c6e30fcb25d6bbb001a8393468 (diff) |
style: improve function and brace styling
Diffstat (limited to 'src')
52 files changed, 414 insertions, 234 deletions
diff --git a/src/DI/alloc_functor.tpp b/src/DI/alloc_functor.tpp index d3f6946..9611a3d 100644 --- a/src/DI/alloc_functor.tpp +++ b/src/DI/alloc_functor.tpp @@ -18,29 +18,41 @@ auto InvokeReturnWrapper<Return>::call(Args &&...args) -> Return ALLOC_FUNCTOR_TEMPLATE ALLOC_FUNCTOR::AllocFunctor(Target &&function) - : _function(std::piecewise_construct, std::forward_as_tuple(std::move(function)), - std::forward_as_tuple()) + : _function( + std::piecewise_construct, + std::forward_as_tuple(std::move(function)), + std::forward_as_tuple() + ) { } ALLOC_FUNCTOR_TEMPLATE ALLOC_FUNCTOR::AllocFunctor(const Target &function, const Alloc &allocator) - : _function(std::piecewise_construct, std::forward_as_tuple(function), - std::forward_as_tuple(allocator)) + : _function( + std::piecewise_construct, + std::forward_as_tuple(function), + std::forward_as_tuple(allocator) + ) { } ALLOC_FUNCTOR_TEMPLATE ALLOC_FUNCTOR::AllocFunctor(const Target &function, Alloc &&allocator) - : _function(std::piecewise_construct, std::forward_as_tuple(function), - std::forward_as_tuple(std::move(allocator))) + : _function( + std::piecewise_construct, + std::forward_as_tuple(function), + std::forward_as_tuple(std::move(allocator)) + ) { } ALLOC_FUNCTOR_TEMPLATE ALLOC_FUNCTOR::AllocFunctor(Target &&function, Alloc &&allocator) - : _function(std::piecewise_construct, std::forward_as_tuple(std::move(function)), - std::forward_as_tuple(std::move(allocator))) + : _function( + std::piecewise_construct, + std::forward_as_tuple(std::move(function)), + std::forward_as_tuple(std::move(allocator)) + ) { } @@ -75,8 +87,10 @@ auto ALLOC_FUNCTOR::clone() const -> AllocFunctor * using Destructor = AllocDestructor<AllocHelper>; - auto hold = std::unique_ptr<AllocFunctor, Destructor>(alloc_helper.allocate(1), - _Dp(alloc_helper, 1)); + auto hold = std::unique_ptr<AllocFunctor, Destructor>( + alloc_helper.allocate(1), + _Dp(alloc_helper, 1) + ); ::new (static_cast<void *>(hold.get())) AllocFunctor(_function.first(), _Alloc(alloc_helper)); diff --git a/src/DI/allocation.tpp b/src/DI/allocation.tpp index 245ce99..8753970 100644 --- a/src/DI/allocation.tpp +++ b/src/DI/allocation.tpp @@ -3,8 +3,10 @@ #include "allocation.hpp" template <class Allocator> -AllocDestructor<Allocator>::AllocDestructor(Allocator &allocator, - Size alloc_size) noexcept +AllocDestructor<Allocator>::AllocDestructor( + Allocator &allocator, + Size alloc_size +) noexcept : _allocator(allocator), _size(alloc_size) { } diff --git a/src/DI/auto_wirable.tpp b/src/DI/auto_wirable.tpp index 0a9ca93..4ad34c4 100644 --- a/src/DI/auto_wirable.tpp +++ b/src/DI/auto_wirable.tpp @@ -4,7 +4,8 @@ template <class Interface, class ObjectImpl, class... Dependencies> auto AutoWirable<Interface, ObjectImpl, Dependencies...>::resolve( - const Container &container) noexcept -> std::unique_ptr<Interface> + const Container &container +) noexcept -> std::unique_ptr<Interface> { return std::make_unique<ObjectImpl>(container.get<Dependencies>()...); } diff --git a/src/DI/compressed_pair.hpp b/src/DI/compressed_pair.hpp index 6e05e29..b8646db 100644 --- a/src/DI/compressed_pair.hpp +++ b/src/DI/compressed_pair.hpp @@ -33,8 +33,8 @@ struct IntegerSequence template <size_t SizeOne, size_t SizeTwo> using MakeIndices = - typename __make_integer_seq<IntegerSequence, size_t, - SizeOne - SizeTwo>::template ToTupleIndices<SizeTwo>; + typename __make_integer_seq<IntegerSequence, size_t, SizeOne - SizeTwo>:: + template ToTupleIndices<SizeTwo>; template <size_t SizeOne, size_t SizeTwo = 0> requires(SizeTwo <= SizeOne) struct MakeTupleIndices @@ -64,9 +64,11 @@ struct CompressedPairElement } template <class... Args, size_t... Indexes> - constexpr CompressedPairElement(std::piecewise_construct_t /*unused*/, - std::tuple<Args...> args, - TupleIndices<Indexes...> /*unused*/) + constexpr CompressedPairElement( + std::piecewise_construct_t /*unused*/, + std::tuple<Args...> args, + TupleIndices<Indexes...> /*unused*/ + ) : _value(std::forward<Args>(std::get<Indexes>(args))...) { } @@ -107,9 +109,11 @@ struct CompressedPairElement<Value, Idx> : private Value } template <class... Args, size_t... Indexes> - constexpr CompressedPairElement(std::piecewise_construct_t /*unused*/, - std::tuple<Args...> args, - TupleIndices<Indexes...> /*unused*/) + constexpr CompressedPairElement( + std::piecewise_construct_t /*unused*/, + std::tuple<Args...> args, + TupleIndices<Indexes...> /*unused*/ + ) : Value(std::forward<Args>(std::get<Indexes>(args))...) { } @@ -146,13 +150,21 @@ public: } template <class... ArgsOne, class... ArgsTwo> - constexpr CompressedPair(std::piecewise_construct_t piecewise_construct, - std::tuple<ArgsOne...> first_args, - std::tuple<ArgsTwo...> second_args) - : BaseOne(piecewise_construct, std::move(first_args), - typename MakeTupleIndices<sizeof...(ArgsOne)>::type()), - BaseTwo(piecewise_construct, std::move(second_args), - typename MakeTupleIndices<sizeof...(ArgsTwo)>::type()) + constexpr CompressedPair( + std::piecewise_construct_t piecewise_construct, + std::tuple<ArgsOne...> first_args, + std::tuple<ArgsTwo...> second_args + ) + : BaseOne( + piecewise_construct, + std::move(first_args), + typename MakeTupleIndices<sizeof...(ArgsOne)>::type() + ), + BaseTwo( + piecewise_construct, + std::move(second_args), + typename MakeTupleIndices<sizeof...(ArgsTwo)>::type() + ) { } diff --git a/src/DI/container.cpp b/src/DI/container.cpp index 1b5dc55..f27b1fa 100644 --- a/src/DI/container.cpp +++ b/src/DI/container.cpp @@ -1,6 +1,9 @@ #include "container.hpp" -void Container::add(BaseObjectType type, const WrapperPtr<IGenericWrapper> &wrapper) noexcept +void Container::add( + BaseObjectType type, + const WrapperPtr<IGenericWrapper> &wrapper +) noexcept { - _bindings.insert({type, wrapper}); + _bindings.insert({ type, wrapper }); } diff --git a/src/DI/container.tpp b/src/DI/container.tpp index 13397bc..d81a0cc 100644 --- a/src/DI/container.tpp +++ b/src/DI/container.tpp @@ -22,8 +22,10 @@ void BindingBuilder<Interface>::to() noexcept auto wrapper = Container::WrapperPtr<Wrapper>(new Wrapper(*_container)); - _container->add(ObjectType<Interface>(), - std::dynamic_pointer_cast<IGenericWrapper>(wrapper)); + _container->add( + ObjectType<Interface>(), + std::dynamic_pointer_cast<IGenericWrapper>(wrapper) + ); } template <typename Interface> @@ -35,8 +37,10 @@ void BindingBuilder<Interface>::to_factory(FactoryFunc factory) noexcept auto wrapper = Container::WrapperPtr<Wrapper>(new Wrapper(factory)); - _container->add(ObjectType<Interface>(), - std::dynamic_pointer_cast<IGenericWrapper>(wrapper)); + _container->add( + ObjectType<Interface>(), + std::dynamic_pointer_cast<IGenericWrapper>(wrapper) + ); } template <typename Interface> @@ -60,7 +64,8 @@ auto Container::get() const noexcept -> std::unique_ptr<Interface> } auto wrapper = std::dynamic_pointer_cast<IWrapper<std::unique_ptr<Interface>>>( - _bindings.at(interface_type)); + _bindings.at(interface_type) + ); return wrapper->get(); } @@ -69,8 +74,9 @@ template <typename AFactory> requires IsFactory<AFactory> auto Container::get() const noexcept -> AFactory { - auto wrapper = std::dynamic_pointer_cast<IWrapper<AFactory>>( - _bindings.at(ObjectType<AFactory>())); + auto wrapper = + std::dynamic_pointer_cast<IWrapper<AFactory>>(_bindings.at(ObjectType<AFactory>()) + ); return wrapper->get(); } diff --git a/src/DI/copyable_functor.tpp b/src/DI/copyable_functor.tpp index 9895397..d8da3bb 100644 --- a/src/DI/copyable_functor.tpp +++ b/src/DI/copyable_functor.tpp @@ -50,8 +50,10 @@ auto COPYABLE_FUNCTOR::clone() const -> ICopyableFunctor<Return(Args...)> * using Destructor = AllocDestructor<AllocHelper>; - auto hold = std::unique_ptr<CopyableFunctor, Destructor>(alloc_helper.allocate(1), - Destructor(alloc_helper, 1)); + auto hold = std::unique_ptr<CopyableFunctor, Destructor>( + alloc_helper.allocate(1), + Destructor(alloc_helper, 1) + ); ::new (static_cast<void *>(hold.get())) CopyableFunctor(_functor.target(), Allocator(alloc_helper)); diff --git a/src/DI/factory.hpp b/src/DI/factory.hpp index 13d0eb5..035e557 100644 --- a/src/DI/factory.hpp +++ b/src/DI/factory.hpp @@ -83,7 +83,9 @@ struct is_core_convertible : public std::false_type template <class Tp, class Up> struct is_core_convertible< - Tp, Up, decltype(static_cast<void (*)(Up)>(0)(static_cast<Tp (*)()>(0)()))> + Tp, + Up, + decltype(static_cast<void (*)(Up)>(0)(static_cast<Tp (*)()>(0)()))> : public std::true_type { }; @@ -154,8 +156,9 @@ private: template <class Return, class... Args> Factory(Return (*)(Args...)) -> Factory<Return(Args...)>; -template <class Function, - class Stripped = strip_signature_t<decltype(&Function::operator())>> +template < + class Function, + class Stripped = strip_signature_t<decltype(&Function::operator())>> Factory(Function) -> Factory<Stripped>; template <class Return, class... Args> diff --git a/src/DI/function_wrapper.tpp b/src/DI/function_wrapper.tpp index d672a49..c7afc3d 100644 --- a/src/DI/function_wrapper.tpp +++ b/src/DI/function_wrapper.tpp @@ -5,7 +5,8 @@ #include "function_wrapper.hpp" template <class Interface> -FunctionWrapper<Interface>::FunctionWrapper(Interface func) noexcept : _func(std::move(func)) +FunctionWrapper<Interface>::FunctionWrapper(Interface func) noexcept + : _func(std::move(func)) { } diff --git a/src/DI/object_type.cpp b/src/DI/object_type.cpp index 64a23fa..d7116e8 100644 --- a/src/DI/object_type.cpp +++ b/src/DI/object_type.cpp @@ -17,10 +17,11 @@ auto BaseObjectType::hash() const noexcept -> std::size_t auto BaseObjectType::name() const noexcept -> std::string_view { - return {_type_info.name()}; + return { _type_info.name() }; } -auto ObjectTypeHasher::operator()(const BaseObjectType &object_type) const noexcept -> std::size_t +auto ObjectTypeHasher::operator()(const BaseObjectType &object_type) const noexcept + -> std::size_t { return object_type.hash(); } diff --git a/src/DI/value_functor.tpp b/src/DI/value_functor.tpp index 3665f18..a41d1c2 100644 --- a/src/DI/value_functor.tpp +++ b/src/DI/value_functor.tpp @@ -39,7 +39,9 @@ VALUE_FUNCTOR::ValueFunctor(Function &&function, const Allocator &allocator) using Destructor = AllocDestructor<FunctorAlloc>; auto hold = std::unique_ptr<TargetFunctor, Destructor>( - functor_alloc.allocate(1), Destructor(functor_alloc, 1)); + functor_alloc.allocate(1), + Destructor(functor_alloc, 1) + ); ::new (static_cast<void *>(hold.get())) Functor(std::forward<Function>(function), Allocator(allocator)); diff --git a/src/argument_parser.cpp b/src/argument_parser.cpp index fd18bc7..367262f 100644 --- a/src/argument_parser.cpp +++ b/src/argument_parser.cpp @@ -21,7 +21,7 @@ void optarg_error(char arg, const std::string_view &error) noexcept */ auto get_str_optarg() noexcept -> std::string_view { - return {optarg}; + return { optarg }; } /** @@ -44,16 +44,19 @@ auto get_uint_optarg(char arg, bool check_zero = false) noexcept -> uint32_t } // namespace ArgumentParser::ArgumentParser( - IRandomNumberGeneratorFactory random_number_generator_factory) noexcept + IRandomNumberGeneratorFactory random_number_generator_factory +) noexcept : _random_number_generator_factory(random_number_generator_factory) { } auto ArgumentParser::parse( - const std::vector<option> &options, const std::string_view &short_options, + const std::vector<option> &options, + const std::string_view &short_options, const int &argc, - char *const *argv) noexcept -> ParsedArguments // NOLINT(cppcoreguidelines-avoid-c-arrays, - // modernize-avoid-c-arrays) + char *const *argv +) noexcept -> ParsedArguments // NOLINT(cppcoreguidelines-avoid-c-arrays, + // modernize-avoid-c-arrays) { // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) const auto args = std::vector<std::string_view>(argv, argv + argc); @@ -63,8 +66,9 @@ auto ArgumentParser::parse( ParsedArguments parsed_arguments; char arg = 0; - while ((arg = static_cast<char>(getopt_long(argc, argv, short_options.data(), - options.data(), nullptr))) != -1) + while ((arg = static_cast<char>( + getopt_long(argc, argv, short_options.data(), options.data(), nullptr) + )) != -1) { switch (arg) { diff --git a/src/argument_parser.hpp b/src/argument_parser.hpp index bee7c84..25243a3 100644 --- a/src/argument_parser.hpp +++ b/src/argument_parser.hpp @@ -13,14 +13,16 @@ class ArgumentParser public AutoWirable<IArgumentParser, ArgumentParser, IRandomNumberGeneratorFactory> { public: - explicit ArgumentParser( - IRandomNumberGeneratorFactory random_number_generator_factory) noexcept; + explicit ArgumentParser(IRandomNumberGeneratorFactory random_number_generator_factory + ) noexcept; auto parse( - const std::vector<option> &options, const std::string_view &short_options, + const std::vector<option> &options, + const std::string_view &short_options, const int &argc, - char *const *argv) noexcept -> ParsedArguments override; // NOLINT(cppcoreguidelines-avoid-c-arrays, - // modernize-avoid-c-arrays) + char *const *argv + ) noexcept -> ParsedArguments override; // NOLINT(cppcoreguidelines-avoid-c-arrays, + // modernize-avoid-c-arrays) private: IRandomNumberGeneratorFactory _random_number_generator_factory; diff --git a/src/bootstrap.cpp b/src/bootstrap.cpp index 22fe472..f36bc6a 100644 --- a/src/bootstrap.cpp +++ b/src/bootstrap.cpp @@ -49,9 +49,11 @@ auto bootstrap() noexcept -> Container container.bind<ISeedGenerator>().to<SeedGenerator>(); container.bind<IGameFactory>().to_factory( - [&container](const std::shared_ptr<IWindow> &window, - const std::shared_ptr<IScene> &scene, - const std::shared_ptr<ICursorController> &cursor_controller) + [&container]( + const std::shared_ptr<IWindow> &window, + const std::shared_ptr<IScene> &scene, + const std::shared_ptr<ICursorController> &cursor_controller + ) { std::shared_ptr<IStatusLine> statusline = container.get<IStatusLineFactory>()(cursor_controller, window); @@ -62,50 +64,65 @@ auto bootstrap() noexcept -> Container std::shared_ptr<IStatusUpdater> status_updater = container.get<IStatusUpdaterFactory>()(statusline, generation_tracker); - return std::make_unique<Game>(window, scene, cursor_controller, statusline, - generation_tracker, status_updater); - }); + return std::make_unique<Game>( + window, + scene, + cursor_controller, + statusline, + generation_tracker, + status_updater + ); + } + ); container.bind<IRandomNumberGeneratorFactory>().to_factory( [](const uint32_t &seed) { return std::make_unique<RandomNumberGenerator>(seed); - }); + } + ); container.bind<IMatrixFactory<std::string_view>>().to_factory( [](const Bounds &bounds) { return std::make_unique<Matrix<std::string_view>>(bounds); - }); + } + ); container.bind<ISceneFactory>().to_factory( - [&container](const std::shared_ptr<ICursorController> &cursor_controller, - const std::shared_ptr<IWindow> &window) + [&container]( + const std::shared_ptr<ICursorController> &cursor_controller, + const std::shared_ptr<IWindow> &window + ) { auto matrix_factory = container.get<IMatrixFactory<std::string_view>>(); return std::make_unique<Scene>(matrix_factory, cursor_controller, window); - }); + } + ); container.bind<IStatusLineFactory>().to_factory( [](const std::shared_ptr<ICursorController> &cursor_controller, const std::shared_ptr<IWindow> &window) { return std::make_unique<StatusLine>(cursor_controller, window); - }); + } + ); container.bind<IStatusUpdaterFactory>().to_factory( [](const std::shared_ptr<IStatusLine> &statusline, const std::shared_ptr<IGenerationTracker> &generation_tracker) { return std::make_unique<StatusUpdater>(statusline, generation_tracker); - }); + } + ); container.bind<IGenerationTrackerFactory>().to_factory( [](bool is_paused) { return std::make_unique<GenerationTracker>(is_paused); - }); + } + ); return container; } diff --git a/src/commands/insert_cell.cpp b/src/commands/insert_cell.cpp index 86a5a52..3aa0fc8 100644 --- a/src/commands/insert_cell.cpp +++ b/src/commands/insert_cell.cpp @@ -4,7 +4,8 @@ InsertCellCommand::InsertCellCommand( const std::shared_ptr<ICursorController> &cursor_controller, - const std::shared_ptr<IScene> &scene) noexcept + const std::shared_ptr<IScene> &scene +) noexcept : _cursor_controller(cursor_controller), _scene(scene) { } diff --git a/src/commands/insert_cell.hpp b/src/commands/insert_cell.hpp index cf04203..7518ece 100644 --- a/src/commands/insert_cell.hpp +++ b/src/commands/insert_cell.hpp @@ -9,8 +9,10 @@ class InsertCellCommand : public ICommand { public: - InsertCellCommand(const std::shared_ptr<ICursorController> &cursor_controller, - const std::shared_ptr<IScene> &scene) noexcept; + InsertCellCommand( + const std::shared_ptr<ICursorController> &cursor_controller, + const std::shared_ptr<IScene> &scene + ) noexcept; void execute() noexcept override; diff --git a/src/commands/move_cursor.cpp b/src/commands/move_cursor.cpp index 1d2b4e8..fe2f05f 100644 --- a/src/commands/move_cursor.cpp +++ b/src/commands/move_cursor.cpp @@ -1,8 +1,10 @@ #include "move_cursor.hpp" MoveCursorCommand::MoveCursorCommand( - const Vector2 &direction, const std::shared_ptr<ICursorController> &cursor_controller, - const std::shared_ptr<IWindow> &window) noexcept + const Vector2 &direction, + const std::shared_ptr<ICursorController> &cursor_controller, + const std::shared_ptr<IWindow> &window +) noexcept : _direction(direction), _cursor_controller(cursor_controller), _window(window) { diff --git a/src/commands/move_cursor.hpp b/src/commands/move_cursor.hpp index ff4723d..88d9c42 100644 --- a/src/commands/move_cursor.hpp +++ b/src/commands/move_cursor.hpp @@ -11,9 +11,11 @@ class MoveCursorCommand : public ICommand { public: - MoveCursorCommand(const Vector2 &direction, - const std::shared_ptr<ICursorController> &cursor_controller, - const std::shared_ptr<IWindow> &window) noexcept; + MoveCursorCommand( + const Vector2 &direction, + const std::shared_ptr<ICursorController> &cursor_controller, + const std::shared_ptr<IWindow> &window + ) noexcept; void execute() noexcept override; diff --git a/src/commands/toggle_pause.cpp b/src/commands/toggle_pause.cpp index d978bc6..434330e 100644 --- a/src/commands/toggle_pause.cpp +++ b/src/commands/toggle_pause.cpp @@ -5,7 +5,8 @@ TogglePauseCommand::TogglePauseCommand( std::shared_ptr<IGenerationTracker> generation_tracker, - std::shared_ptr<IStatusLine> statusline) noexcept + std::shared_ptr<IStatusLine> statusline +) noexcept : _generation_tracker(std::move(generation_tracker)), _statusline(std::move(statusline)) { @@ -19,7 +20,10 @@ void TogglePauseCommand::execute() noexcept _statusline->set_status( StatusLineSection::B, - fmt::format("Paused: {} Generation: {}", - _generation_tracker->get_is_paused() ? "yes" : "no", - _generation_tracker->get_current_generation())); + fmt::format( + "Paused: {} Generation: {}", + _generation_tracker->get_is_paused() ? "yes" : "no", + _generation_tracker->get_current_generation() + ) + ); } diff --git a/src/commands/toggle_pause.hpp b/src/commands/toggle_pause.hpp index 4e05323..e243cc3 100644 --- a/src/commands/toggle_pause.hpp +++ b/src/commands/toggle_pause.hpp @@ -9,8 +9,10 @@ class TogglePauseCommand : public ICommand { public: - explicit TogglePauseCommand(std::shared_ptr<IGenerationTracker> generation_tracker, - std::shared_ptr<IStatusLine> statusline) noexcept; + explicit TogglePauseCommand( + std::shared_ptr<IGenerationTracker> generation_tracker, + std::shared_ptr<IStatusLine> statusline + ) noexcept; void execute() noexcept override; diff --git a/src/conversion.hpp b/src/conversion.hpp index f0bbc04..3b5a9df 100644 --- a/src/conversion.hpp +++ b/src/conversion.hpp @@ -9,8 +9,11 @@ template <typename ResultType> class ConversionResult { public: - explicit ConversionResult(const bool &success_, const ResultType &result_, - const std::string_view &fail_reason_ = "") noexcept + explicit ConversionResult( + const bool &success_, + const ResultType &result_, + const std::string_view &fail_reason_ = "" + ) noexcept : success(success_), result(result_), fail_reason(fail_reason_) { } diff --git a/src/engine/data/bounds.hpp b/src/engine/data/bounds.hpp index 5444503..731db5c 100644 --- a/src/engine/data/bounds.hpp +++ b/src/engine/data/bounds.hpp @@ -34,7 +34,8 @@ public: void set_height(Value height) noexcept; - [[nodiscard]] auto validate_coords(const Vector2 &coords) const noexcept -> CoordsValidation; + [[nodiscard]] auto validate_coords(const Vector2 &coords) const noexcept + -> CoordsValidation; auto operator*=(const Bounds &rhs) noexcept -> const Bounds &; auto operator+=(const Bounds &rhs) noexcept -> const Bounds &; diff --git a/src/engine/data/vector2.cpp b/src/engine/data/vector2.cpp index 0554930..6d8ebad 100644 --- a/src/engine/data/vector2.cpp +++ b/src/engine/data/vector2.cpp @@ -22,10 +22,10 @@ void Vector2::set_y(Vector2::Value y) noexcept _y = y; } -auto Vector2::to_direction(const Vector2 &direction, - Vector2::Value amount) const noexcept -> Vector2 +auto Vector2::to_direction(const Vector2 &direction, Vector2::Value amount) const noexcept + -> Vector2 { - return *this + (direction * Vector2({.x = amount, .y = amount})); + return *this + (direction * Vector2({ .x = amount, .y = amount })); } auto Vector2::operator+=(const Vector2 &rhs) noexcept -> const Vector2 & diff --git a/src/engine/data/vector2.hpp b/src/engine/data/vector2.hpp index 95baf1c..a6de35e 100644 --- a/src/engine/data/vector2.hpp +++ b/src/engine/data/vector2.hpp @@ -30,8 +30,9 @@ public: void set_y(Value y) noexcept; - [[nodiscard]] auto to_direction(const Vector2 &direction, - Vector2::Value amount) const noexcept -> Vector2; + [[nodiscard]] auto + to_direction(const Vector2 &direction, Vector2::Value amount) const noexcept + -> Vector2; auto operator+=(const Vector2 &rhs) noexcept -> const Vector2 &; auto operator-=(const Vector2 &rhs) noexcept -> const Vector2 &; @@ -47,7 +48,7 @@ public: */ static constexpr auto up() noexcept -> Vector2 { - return Vector2({.x = 0, .y = -1}); + return Vector2({ .x = 0, .y = -1 }); } /** @@ -55,7 +56,7 @@ public: */ static constexpr auto down() noexcept -> Vector2 { - return Vector2({.x = 0, .y = 1}); + return Vector2({ .x = 0, .y = 1 }); } /** @@ -64,7 +65,7 @@ public: static constexpr auto left() noexcept -> Vector2 { - return Vector2({.x = -1, .y = 0}); + return Vector2({ .x = -1, .y = 0 }); } /** @@ -72,7 +73,7 @@ public: */ static constexpr auto right() noexcept -> Vector2 { - return Vector2({.x = 1, .y = 0}); + return Vector2({ .x = 1, .y = 0 }); } private: diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index a05fed9..3bf8503 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -5,10 +5,13 @@ #include <thread> #include <utility> -CLIGameEngine::CLIGameEngine(IGameFactory game_factory, ISceneFactory scene_factory, - std::shared_ptr<IInputHandler> input_handler, - std::shared_ptr<ICursorController> cursor_controller, - std::shared_ptr<IWindow> window) noexcept +CLIGameEngine::CLIGameEngine( + IGameFactory game_factory, + ISceneFactory scene_factory, + std::shared_ptr<IInputHandler> input_handler, + std::shared_ptr<ICursorController> cursor_controller, + std::shared_ptr<IWindow> window +) noexcept : _game_factory(std::move(game_factory)), _scene_factory(std::move(scene_factory)), _input_handler(std::move(input_handler)), @@ -35,7 +38,8 @@ void CLIGameEngine::start() noexcept _input_handler->leave_raw_mode(); game->on_exit(); - })); + } + )); _configure_input(game->get_input_config()); @@ -43,7 +47,8 @@ void CLIGameEngine::start() noexcept [this]() { _input_handler->listen(); - })); + } + )); while (true) { @@ -52,7 +57,8 @@ void CLIGameEngine::start() noexcept } void CLIGameEngine::_configure_input( - const std::unordered_map<char, std::shared_ptr<ICommand>> &input_config) noexcept + const std::unordered_map<char, std::shared_ptr<ICommand>> &input_config +) noexcept { for (const auto &config_pair : input_config) { diff --git a/src/engine/engine.hpp b/src/engine/engine.hpp index 32afa56..c13245f 100644 --- a/src/engine/engine.hpp +++ b/src/engine/engine.hpp @@ -12,16 +12,24 @@ #include <memory> #include <unordered_map> -class CLIGameEngine - : public ICLIGameEngine, - public AutoWirable<ICLIGameEngine, CLIGameEngine, IGameFactory, ISceneFactory, - IInputHandler, ICursorController, IWindow> +class CLIGameEngine : public ICLIGameEngine, + public AutoWirable< + ICLIGameEngine, + CLIGameEngine, + IGameFactory, + ISceneFactory, + IInputHandler, + ICursorController, + IWindow> { public: - CLIGameEngine(IGameFactory game_factory, ISceneFactory scene_factory, - std::shared_ptr<IInputHandler> input_handler, - std::shared_ptr<ICursorController> cursor_controller, - std::shared_ptr<IWindow> window) noexcept; + CLIGameEngine( + IGameFactory game_factory, + ISceneFactory scene_factory, + std::shared_ptr<IInputHandler> input_handler, + std::shared_ptr<ICursorController> cursor_controller, + std::shared_ptr<IWindow> window + ) noexcept; void start() noexcept override; @@ -34,5 +42,6 @@ private: std::shared_ptr<IWindow> _window; void _configure_input( - const std::unordered_map<char, std::shared_ptr<ICommand>> &input_config) noexcept; + const std::unordered_map<char, std::shared_ptr<ICommand>> &input_config + ) noexcept; }; diff --git a/src/engine/graphics/scene.cpp b/src/engine/graphics/scene.cpp index c27a6d5..d5cf89b 100644 --- a/src/engine/graphics/scene.cpp +++ b/src/engine/graphics/scene.cpp @@ -8,11 +8,13 @@ #include <iostream> #include <utility> -Scene::Scene(IMatrixFactory<std::string_view> matrix_factory, - std::shared_ptr<ICursorController> cursor_controller, - std::shared_ptr<IWindow> window) noexcept +Scene::Scene( + IMatrixFactory<std::string_view> matrix_factory, + std::shared_ptr<ICursorController> cursor_controller, + std::shared_ptr<IWindow> window +) noexcept : _is_shown(false), - _matrix(matrix_factory(window->size() - Bounds({.width = 0U, .height = 1U}))), + _matrix(matrix_factory(window->size() - Bounds({ .width = 0U, .height = 1U }))), _cursor_controller(std::move(cursor_controller)), _window(std::move(window)) { @@ -45,7 +47,8 @@ void Scene::leave() noexcept _is_shown = false; } -auto Scene::get_matrix() const noexcept -> const std::shared_ptr<IMatrix<std::string_view>> & +auto Scene::get_matrix() const noexcept + -> const std::shared_ptr<IMatrix<std::string_view>> & { return _matrix; } diff --git a/src/engine/graphics/scene.hpp b/src/engine/graphics/scene.hpp index 3dcaa2d..aaf0095 100644 --- a/src/engine/graphics/scene.hpp +++ b/src/engine/graphics/scene.hpp @@ -15,16 +15,18 @@ constexpr fmt::string_view DISABLE_ALT_BUFFER = "{esc}[?1049l"; class Scene : public IScene { public: - explicit Scene(IMatrixFactory<std::string_view> matrix_factory, - std::shared_ptr<ICursorController> cursor_controller, - std::shared_ptr<IWindow> window) noexcept; + explicit Scene( + IMatrixFactory<std::string_view> matrix_factory, + std::shared_ptr<ICursorController> cursor_controller, + std::shared_ptr<IWindow> window + ) noexcept; void enter() noexcept override; void leave() noexcept override; - [[nodiscard]] auto - get_matrix() const noexcept -> const std::shared_ptr<IMatrix<std::string_view>> & override; + [[nodiscard]] auto get_matrix() const noexcept + -> const std::shared_ptr<IMatrix<std::string_view>> & override; private: bool _is_shown; diff --git a/src/engine/graphics/window.cpp b/src/engine/graphics/window.cpp index bb33402..2d880fc 100644 --- a/src/engine/graphics/window.cpp +++ b/src/engine/graphics/window.cpp @@ -9,5 +9,5 @@ auto Window::size() const noexcept -> Bounds // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) ioctl(0, TIOCGWINSZ, &window_size); - return Bounds({window_size.ws_col, window_size.ws_row}); + return Bounds({ window_size.ws_col, window_size.ws_row }); } diff --git a/src/engine/matrix_iterator.tpp b/src/engine/matrix_iterator.tpp index 031136c..9697861 100644 --- a/src/engine/matrix_iterator.tpp +++ b/src/engine/matrix_iterator.tpp @@ -35,13 +35,15 @@ auto MatrixRowIterator<Element>::operator*() const noexcept -> Element & } template <typename Element> -auto MatrixRowIterator<Element>::operator==(const MatrixRowIterator &rhs) const noexcept -> bool +auto MatrixRowIterator<Element>::operator==(const MatrixRowIterator &rhs) const noexcept + -> bool { return _column_ptr == rhs._column_ptr; } template <typename Element> -auto MatrixRowIterator<Element>::operator!=(const MatrixRowIterator &rhs) const noexcept -> bool +auto MatrixRowIterator<Element>::operator!=(const MatrixRowIterator &rhs) const noexcept + -> bool { return _column_ptr != rhs._column_ptr; } @@ -69,8 +71,10 @@ auto MatrixRow<Element>::end() const noexcept -> MatrixRowIterator<Element> // Matrix iterator template <typename Element> -MatrixIterator<Element>::MatrixIterator(RowPtr row_ptr, - const uint32_t &column_cnt) noexcept +MatrixIterator<Element>::MatrixIterator( + RowPtr row_ptr, + const uint32_t &column_cnt +) noexcept : _row_ptr(row_ptr), _column_cnt(column_cnt) { } diff --git a/src/engine/user/cursor.cpp b/src/engine/user/cursor.cpp index 2b240b9..71f02da 100644 --- a/src/engine/user/cursor.cpp +++ b/src/engine/user/cursor.cpp @@ -5,14 +5,17 @@ #include <cstdlib> #include <iostream> -CursorController::CursorController() noexcept : _position({.x = 0, .y = 0}) {} +CursorController::CursorController() noexcept : _position({ .x = 0, .y = 0 }) {} void CursorController::move(const Vector2 &direction, const uint32_t &amount) noexcept { auto direction_format = direction_format_map.at(direction); - fmt::print(fmt::runtime(direction_format.data()), fmt::arg("esc", ESC), - fmt::arg("amount", amount)); + fmt::print( + fmt::runtime(direction_format.data()), + fmt::arg("esc", ESC), + fmt::arg("amount", amount) + ); std::cout.flush(); _position = _position.to_direction(direction, static_cast<Vector2::Value>(amount)); @@ -22,8 +25,12 @@ void CursorController::move(const Vector2 &direction, const uint32_t &amount) no void CursorController::move_to(const Vector2 &position, bool silent) noexcept { - fmt::print(MOVE_CURSOR_TO, fmt::arg("esc", ESC), fmt::arg("row", position.get_y()), - fmt::arg("column", position.get_x())); + fmt::print( + MOVE_CURSOR_TO, + fmt::arg("esc", ESC), + fmt::arg("row", position.get_y()), + fmt::arg("column", position.get_x()) + ); std::cout.flush(); _position = position; @@ -66,19 +73,21 @@ void CursorController::show() noexcept std::cout.flush(); } -void CursorController::subscribe(const Event &event, - const Subscriber &subscriber) noexcept +void CursorController::subscribe( + const Event &event, + const Subscriber &subscriber +) noexcept { if (_subscribers.count(event) == 0) { - _subscribers.insert({event, std::vector<Subscriber>()}); + _subscribers.insert({ event, std::vector<Subscriber>() }); } _subscribers.at(event).push_back(subscriber); } -void CursorController::notify_subscribers(const Event &event, - const Context &context) const noexcept +void CursorController::notify_subscribers(const Event &event, const Context &context) + const noexcept { if (_subscribers.count(event) == 0) { diff --git a/src/engine/user/cursor.hpp b/src/engine/user/cursor.hpp index fcdfd3b..9d614f1 100644 --- a/src/engine/user/cursor.hpp +++ b/src/engine/user/cursor.hpp @@ -23,11 +23,11 @@ constexpr fmt::string_view REQUEST_CURSOR_POSITION = "{esc}[6n"; constexpr fmt::string_view CURSOR_VISIBLE = "{esc}[?25h"; constexpr fmt::string_view CURSOR_INVISIBLE = "{esc}[?25l"; -const std::unordered_map<Vector2, std::string_view, Vector2Hasher> direction_format_map = - {{Vector2::up(), MOVE_CURSOR_UP}, - {Vector2::down(), MOVE_CURSOR_DOWN}, - {Vector2::left(), MOVE_CURSOR_LEFT}, - {Vector2::right(), MOVE_CURSOR_RIGHT}}; +const std::unordered_map<Vector2, std::string_view, Vector2Hasher> + direction_format_map = { { Vector2::up(), MOVE_CURSOR_UP }, + { Vector2::down(), MOVE_CURSOR_DOWN }, + { Vector2::left(), MOVE_CURSOR_LEFT }, + { Vector2::right(), MOVE_CURSOR_RIGHT } }; class CursorController : public ICursorController, public AutoWirable<ICursorController, CursorController> @@ -49,8 +49,8 @@ public: void subscribe(const Event &event, const Subscriber &subscriber) noexcept override; - void notify_subscribers(const Event &event, - const Context &context) const noexcept override; + void notify_subscribers(const Event &event, const Context &context) + const noexcept override; private: Vector2 _position; diff --git a/src/engine/user/input.cpp b/src/engine/user/input.cpp index 1d6bc09..d335fc9 100644 --- a/src/engine/user/input.cpp +++ b/src/engine/user/input.cpp @@ -14,15 +14,17 @@ void InputHandler::listen() const noexcept } void InputHandler::subscribe( - const Event &event, const std::shared_ptr<ISubscriber<Context>> &subscriber) noexcept + const Event &event, + const std::shared_ptr<ISubscriber<Context>> &subscriber +) noexcept { auto event_index = _event_as_index(event); _subscribers.at(event_index).push_back(subscriber); } -void InputHandler::notify_subscribers(const Event &event, - const Context &context) const noexcept +void InputHandler::notify_subscribers(const Event &event, const Context &context) + const noexcept { auto event_index = _event_as_index(event); diff --git a/src/engine/user/input.hpp b/src/engine/user/input.hpp index 410f3a6..6a7bf26 100644 --- a/src/engine/user/input.hpp +++ b/src/engine/user/input.hpp @@ -17,20 +17,22 @@ public: void listen() const noexcept override; - void - subscribe(const Event &event, - const std::shared_ptr<ISubscriber<Context>> &subscriber) noexcept override; + void subscribe( + const Event &event, + const std::shared_ptr<ISubscriber<Context>> &subscriber + ) noexcept override; - void notify_subscribers(const Event &event, - const Context &context) const noexcept override; + void notify_subscribers(const Event &event, const Context &context) + const noexcept override; void enter_raw_mode() noexcept override; void leave_raw_mode() noexcept override; private: - std::array<std::vector<std::shared_ptr<ISubscriber<Context>>>, - static_cast<std::size_t>(CHAR_MAX * 2U)> + std::array< + std::vector<std::shared_ptr<ISubscriber<Context>>>, + static_cast<std::size_t>(CHAR_MAX * 2U)> _subscribers; std::shared_ptr<termios> _original_termios = nullptr; diff --git a/src/game/game.cpp b/src/game/game.cpp index 88b9584..1a69e2e 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -9,11 +9,14 @@ #include <iostream> #include <utility> -Game::Game(std::shared_ptr<IWindow> window, std::shared_ptr<IScene> scene, - std::shared_ptr<ICursorController> cursor_controller, - std::shared_ptr<IStatusLine> statusline, - std::shared_ptr<IGenerationTracker> generation_tracker, - std::shared_ptr<IStatusUpdater> status_updater) noexcept +Game::Game( + std::shared_ptr<IWindow> window, + std::shared_ptr<IScene> scene, + std::shared_ptr<ICursorController> cursor_controller, + std::shared_ptr<IStatusLine> statusline, + std::shared_ptr<IGenerationTracker> generation_tracker, + std::shared_ptr<IStatusUpdater> status_updater +) noexcept : _window(std::move(window)), _scene(std::move(scene)), _cursor_controller(std::move(cursor_controller)), @@ -32,8 +35,8 @@ void Game::on_start() noexcept const auto window_size = _window->size(); const auto center_position = - Vector2({.x = static_cast<Vector2::Value>(window_size.get_width()) / 2, - .y = static_cast<Vector2::Value>(window_size.get_height()) / 2}); + Vector2({ .x = static_cast<Vector2::Value>(window_size.get_width()) / 2, + .y = static_cast<Vector2::Value>(window_size.get_height()) / 2 }); _cursor_controller->move_to(center_position); @@ -60,15 +63,32 @@ void Game::on_exit() const noexcept auto Game::get_input_config() const noexcept -> std::unordered_map<char, std::shared_ptr<ICommand>> { - return {{'q', std::make_shared<QuitCommand>()}, - {'i', std::make_shared<InsertCellCommand>(_cursor_controller, _scene)}, - {'p', std::make_shared<TogglePauseCommand>(_generation_tracker, _statusline)}, - {'k', std::make_shared<MoveCursorCommand>(Vector2::up(), _cursor_controller, - _window)}, - {'j', std::make_shared<MoveCursorCommand>(Vector2::down(), _cursor_controller, - _window)}, - {'h', std::make_shared<MoveCursorCommand>(Vector2::left(), _cursor_controller, - _window)}, - {'l', std::make_shared<MoveCursorCommand>(Vector2::right(), - _cursor_controller, _window)}}; + return { { 'q', std::make_shared<QuitCommand>() }, + { 'i', std::make_shared<InsertCellCommand>(_cursor_controller, _scene) }, + { 'p', + std::make_shared<TogglePauseCommand>(_generation_tracker, _statusline) }, + { 'k', + std::make_shared<MoveCursorCommand>( + Vector2::up(), + _cursor_controller, + _window + ) }, + { 'j', + std::make_shared<MoveCursorCommand>( + Vector2::down(), + _cursor_controller, + _window + ) }, + { 'h', + std::make_shared<MoveCursorCommand>( + Vector2::left(), + _cursor_controller, + _window + ) }, + { 'l', + std::make_shared<MoveCursorCommand>( + Vector2::right(), + _cursor_controller, + _window + ) } }; } diff --git a/src/game/game.hpp b/src/game/game.hpp index dfbe619..9f08158 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -13,11 +13,14 @@ class Game : public IGame { public: - Game(std::shared_ptr<IWindow> window, std::shared_ptr<IScene> scene, - std::shared_ptr<ICursorController> cursor_controller, - std::shared_ptr<IStatusLine> statusline, - std::shared_ptr<IGenerationTracker> generation_tracker, - std::shared_ptr<IStatusUpdater> status_updater) noexcept; + Game( + std::shared_ptr<IWindow> window, + std::shared_ptr<IScene> scene, + std::shared_ptr<ICursorController> cursor_controller, + std::shared_ptr<IStatusLine> statusline, + std::shared_ptr<IGenerationTracker> generation_tracker, + std::shared_ptr<IStatusUpdater> status_updater + ) noexcept; void on_start() noexcept override; diff --git a/src/game/status_updater.cpp b/src/game/status_updater.cpp index 18c535e..1cfd1d2 100644 --- a/src/game/status_updater.cpp +++ b/src/game/status_updater.cpp @@ -5,7 +5,8 @@ StatusUpdater::StatusUpdater( std::shared_ptr<IStatusLine> statusline, - std::shared_ptr<IGenerationTracker> generation_tracker) noexcept + std::shared_ptr<IGenerationTracker> generation_tracker +) noexcept : _statusline(std::move(statusline)), _generation_tracker(std::move(generation_tracker)) { @@ -15,11 +16,15 @@ void StatusUpdater::update(const Vector2 &context) noexcept { _statusline->set_status( StatusLineSection::A, - fmt::format("X: {} Y {}", context.get_x(), context.get_y())); + fmt::format("X: {} Y {}", context.get_x(), context.get_y()) + ); _statusline->set_status( StatusLineSection::B, - fmt::format("Paused: {} Generation: {}", - _generation_tracker->get_is_paused() ? "yes" : "no", - _generation_tracker->get_current_generation())); + fmt::format( + "Paused: {} Generation: {}", + _generation_tracker->get_is_paused() ? "yes" : "no", + _generation_tracker->get_current_generation() + ) + ); } diff --git a/src/game/status_updater.hpp b/src/game/status_updater.hpp index 3b76d3b..0fd38a7 100644 --- a/src/game/status_updater.hpp +++ b/src/game/status_updater.hpp @@ -14,7 +14,8 @@ class StatusUpdater : public IStatusUpdater public: explicit StatusUpdater( std::shared_ptr<IStatusLine> statusline, - std::shared_ptr<IGenerationTracker> generation_tracker) noexcept; + std::shared_ptr<IGenerationTracker> generation_tracker + ) noexcept; void update(const Vector2 &context) noexcept override; diff --git a/src/game/statusline.cpp b/src/game/statusline.cpp index 6becb38..d764d60 100644 --- a/src/game/statusline.cpp +++ b/src/game/statusline.cpp @@ -7,8 +7,10 @@ #include <string> #include <utility> -StatusLine::StatusLine(std::shared_ptr<ICursorController> cursor_controller, - std::shared_ptr<IWindow> window) noexcept +StatusLine::StatusLine( + std::shared_ptr<ICursorController> cursor_controller, + std::shared_ptr<IWindow> window +) noexcept : _cursor_controller(std::move(cursor_controller)), _window(std::move(window)) { constexpr uint32_t SECTION_A_LENGTH = 20; @@ -30,8 +32,10 @@ void StatusLine::initialize_background() noexcept _move_back(previous_position); } -void StatusLine::set_status(StatusLineSection section, - const std::string_view &str) noexcept +void StatusLine::set_status( + StatusLineSection section, + const std::string_view &statusline_str +) noexcept { _clear_section(section); @@ -43,7 +47,9 @@ void StatusLine::set_status(StatusLineSection section, auto section_length = _sections_lengths[section]; - auto status = str.length() > section_length ? str.substr(0, section_length) : str; + auto status = statusline_str.length() > section_length + ? statusline_str.substr(0, section_length) + : statusline_str; fmt::print("{}{}", background_color, status); fmt::print(RESET_ALL_MODES, fmt::arg("esc", ESC)); @@ -61,7 +67,7 @@ auto StatusLine::_move_to_statusline(int32_t x) noexcept -> Vector2 auto window_height = static_cast<Vector2::Value>(window_size.get_height()); - _cursor_controller->move_to(Vector2({.x = x, .y = window_height}), true); + _cursor_controller->move_to(Vector2({ .x = x, .y = window_height }), true); return previous_position; } @@ -80,8 +86,9 @@ auto StatusLine::_get_section_start_x(StatusLineSection section) const noexcept while (section_index > 0) { - section_start += static_cast<int32_t>( - _sections_lengths.at(StatusLineSection(section_index - 1))); + section_start += + static_cast<int32_t>(_sections_lengths.at(StatusLineSection(section_index - 1) + )); section_index--; } diff --git a/src/game/statusline.hpp b/src/game/statusline.hpp index 9e85008..66ce2c4 100644 --- a/src/game/statusline.hpp +++ b/src/game/statusline.hpp @@ -17,13 +17,17 @@ constexpr uint32_t STATUSBAR_COLOR = 0x1A1A1AU; class StatusLine : public IStatusLine { public: - StatusLine(std::shared_ptr<ICursorController> cursor_controller, - std::shared_ptr<IWindow> window) noexcept; + StatusLine( + std::shared_ptr<ICursorController> cursor_controller, + std::shared_ptr<IWindow> window + ) noexcept; void initialize_background() noexcept override; - void set_status(StatusLineSection section, - const std::string_view &str) noexcept override; + void set_status( + StatusLineSection section, + const std::string_view &status_str + ) noexcept override; private: std::unordered_map<StatusLineSection, uint32_t> _sections_lengths; diff --git a/src/game_of_life.cpp b/src/game_of_life.cpp index 098ec32..a6c327d 100644 --- a/src/game_of_life.cpp +++ b/src/game_of_life.cpp @@ -6,9 +6,9 @@ #include <getopt.h> #include <vector> -const std::vector<option> options = {option({"seed", required_argument, nullptr, 's'}), - option({"help", no_argument, nullptr, 'h'}), - option({nullptr, 0, nullptr, 0})}; +const std::vector<option> options = { option({ "seed", required_argument, nullptr, 's' }), + option({ "help", no_argument, nullptr, 'h' }), + option({ nullptr, 0, nullptr, 0 }) }; auto main(int argc, char *argv[]) noexcept -> int { diff --git a/src/interfaces/argument_parser.hpp b/src/interfaces/argument_parser.hpp index 8769698..d2dfb03 100644 --- a/src/interfaces/argument_parser.hpp +++ b/src/interfaces/argument_parser.hpp @@ -18,9 +18,11 @@ class IArgumentParser public: virtual ~IArgumentParser() noexcept = default; - virtual auto parse(const std::vector<option> &options, - const std::string_view &short_options, const int &argc, - char *const *argv) noexcept - -> ParsedArguments = 0; // NOLINT(cppcoreguidelines-avoid-c-arrays, - // modernize-avoid-c-arrays) + virtual auto parse( + const std::vector<option> &options, + const std::string_view &short_options, + const int &argc, + char *const *argv + ) noexcept -> ParsedArguments = 0; // NOLINT(cppcoreguidelines-avoid-c-arrays, + // modernize-avoid-c-arrays) }; diff --git a/src/interfaces/cursor.hpp b/src/interfaces/cursor.hpp index f6521cb..053ff40 100644 --- a/src/interfaces/cursor.hpp +++ b/src/interfaces/cursor.hpp @@ -35,9 +35,9 @@ public: virtual void show() noexcept = 0; - void subscribe(const Event &event, - const Subscriber &subscriber) noexcept override = 0; + void + subscribe(const Event &event, const Subscriber &subscriber) noexcept override = 0; - void notify_subscribers(const Event &event, - const Context &context) const noexcept override = 0; + void notify_subscribers(const Event &event, const Context &context) + const noexcept override = 0; }; diff --git a/src/interfaces/game.hpp b/src/interfaces/game.hpp index 0f5c895..6d247d9 100644 --- a/src/interfaces/game.hpp +++ b/src/interfaces/game.hpp @@ -33,5 +33,7 @@ using IGameFactory = std::unique_ptr<IGame> (*)( */ using IGameFactory = Factory<std::unique_ptr<IGame>( - const std::shared_ptr<IWindow> &window, const std::shared_ptr<IScene> &scene, - const std::shared_ptr<ICursorController> &cursor_controller)>; + const std::shared_ptr<IWindow> &window, + const std::shared_ptr<IScene> &scene, + const std::shared_ptr<ICursorController> &cursor_controller +)>; diff --git a/src/interfaces/input.hpp b/src/interfaces/input.hpp index b71de67..df4abb8 100644 --- a/src/interfaces/input.hpp +++ b/src/interfaces/input.hpp @@ -19,10 +19,11 @@ public: void subscribe( const Event &event, - const std::shared_ptr<ISubscriber<Context>> &subscriber) noexcept override = 0; + const std::shared_ptr<ISubscriber<Context>> &subscriber + ) noexcept override = 0; - void notify_subscribers(const Event &event, - const Context &context) const noexcept override = 0; + void notify_subscribers(const Event &event, const Context &context) + const noexcept override = 0; virtual void enter_raw_mode() noexcept = 0; diff --git a/src/interfaces/publisher.hpp b/src/interfaces/publisher.hpp index ef1e61c..4e66d64 100644 --- a/src/interfaces/publisher.hpp +++ b/src/interfaces/publisher.hpp @@ -12,10 +12,11 @@ class IPublisher public: virtual ~IPublisher() noexcept = default; - virtual void - subscribe(const Event &event, - const std::shared_ptr<ISubscriber<Context>> &subscriber) noexcept = 0; + virtual void subscribe( + const Event &event, + const std::shared_ptr<ISubscriber<Context>> &subscriber + ) noexcept = 0; - virtual void notify_subscribers(const Event &event, - const Context &context) const noexcept = 0; + virtual void + notify_subscribers(const Event &event, const Context &context) const noexcept = 0; }; diff --git a/src/interfaces/randomization.hpp b/src/interfaces/randomization.hpp index 4abad1d..26426e3 100644 --- a/src/interfaces/randomization.hpp +++ b/src/interfaces/randomization.hpp @@ -25,8 +25,8 @@ public: * @param a A number lower than b * @param b A number greater than a */ - [[nodiscard]] virtual auto in_range(const uint32_t &a, - const uint32_t &b) const noexcept -> uint32_t = 0; + [[nodiscard]] virtual auto + in_range(const uint32_t &a, const uint32_t &b) const noexcept -> uint32_t = 0; }; using IRandomNumberGeneratorFactory = diff --git a/src/interfaces/scene.hpp b/src/interfaces/scene.hpp index 0a51b6e..88cb3b1 100644 --- a/src/interfaces/scene.hpp +++ b/src/interfaces/scene.hpp @@ -24,4 +24,5 @@ public: using ISceneFactory = Factory<std::unique_ptr<IScene>( const std::shared_ptr<ICursorController> &cursor_controller, - const std::shared_ptr<IWindow> &window)>; + const std::shared_ptr<IWindow> &window +)>; diff --git a/src/interfaces/status_updater.hpp b/src/interfaces/status_updater.hpp index e5081ef..83b2bf2 100644 --- a/src/interfaces/status_updater.hpp +++ b/src/interfaces/status_updater.hpp @@ -18,4 +18,5 @@ public: using IStatusUpdaterFactory = Factory<std::unique_ptr<IStatusUpdater>( const std::shared_ptr<IStatusLine> &statusline, - const std::shared_ptr<IGenerationTracker> &generation_tracker)>; + const std::shared_ptr<IGenerationTracker> &generation_tracker +)>; diff --git a/src/interfaces/statusline.hpp b/src/interfaces/statusline.hpp index bbd8e4a..c104fad 100644 --- a/src/interfaces/statusline.hpp +++ b/src/interfaces/statusline.hpp @@ -21,10 +21,13 @@ public: virtual void initialize_background() noexcept = 0; - virtual void set_status(StatusLineSection section, - const std::string_view &str) noexcept = 0; + virtual void set_status( + StatusLineSection section, + const std::string_view &status_str + ) noexcept = 0; }; using IStatusLineFactory = Factory<std::unique_ptr<IStatusLine>( const std::shared_ptr<ICursorController> &cursor_controller, - const std::shared_ptr<IWindow> &window)>; + const std::shared_ptr<IWindow> &window +)>; diff --git a/src/util/color.cpp b/src/util/color.cpp index 8ec3ad4..8f23f41 100644 --- a/src/util/color.cpp +++ b/src/util/color.cpp @@ -5,11 +5,13 @@ auto get_foreground_esc_seq(const uint32_t &color) noexcept -> std::string { return { - fmt::detail::make_foreground_color<char>(fmt::detail::color_type(color)).begin()}; + fmt::detail::make_foreground_color<char>(fmt::detail::color_type(color)).begin() + }; } auto get_background_esc_seq(const uint32_t &color) noexcept -> std::string { return { - fmt::detail::make_background_color<char>(fmt::detail::color_type(color)).begin()}; + fmt::detail::make_background_color<char>(fmt::detail::color_type(color)).begin() + }; } diff --git a/src/util/function.tpp b/src/util/function.tpp index 6ff939b..0a7a6d6 100644 --- a/src/util/function.tpp +++ b/src/util/function.tpp @@ -45,15 +45,15 @@ constexpr inline auto extract_signature(Function const & /*unused*/) noexcept } template <typename Function, typename Return, typename... Args> -inline auto get_normalized_lambda(Function &&func, - Signature<Return(Args...)> /*unused*/) noexcept +inline auto +get_normalized_lambda(Function &&func, Signature<Return(Args...)> /*unused*/) noexcept { // Static copy of func. This will make it accessible for the lambda without using a // lamda capture static auto static_func = Function(std::forward<Function>(func)); - return +[](Args... args) noexcept( - noexcept(std::declval<Function>()(std::forward<Args>(args)...))) -> Return + return +[](Args... args) noexcept(noexcept(std::declval<Function>( + )(std::forward<Args>(args)...))) -> Return { return static_func(std::forward<Args>(args)...); }; @@ -70,6 +70,8 @@ inline auto get_normalized_lambda(Function &&func, template <typename Function> constexpr auto normalize_lambda(Function &&func) noexcept { - return get_normalized_lambda(std::forward<Function>(func), - extract_signature(std::forward<Function>(func))); + return get_normalized_lambda( + std::forward<Function>(func), + extract_signature(std::forward<Function>(func)) + ); } |