From db6edcd473a684420e9a7611b24462df21165c1b Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 24 Apr 2022 17:13:52 +0200 Subject: style: improve function and brace styling --- .clang-format | 8 +++++- src/DI/alloc_functor.tpp | 34 ++++++++++++++++------- src/DI/allocation.tpp | 6 ++-- src/DI/auto_wirable.tpp | 3 +- src/DI/compressed_pair.hpp | 42 ++++++++++++++++++---------- src/DI/container.cpp | 7 +++-- src/DI/container.tpp | 20 +++++++++----- src/DI/copyable_functor.tpp | 6 ++-- src/DI/factory.hpp | 9 ++++-- src/DI/function_wrapper.tpp | 3 +- src/DI/object_type.cpp | 5 ++-- src/DI/value_functor.tpp | 4 ++- src/argument_parser.cpp | 18 +++++++----- src/argument_parser.hpp | 12 ++++---- src/bootstrap.cpp | 45 ++++++++++++++++++++---------- src/commands/insert_cell.cpp | 3 +- src/commands/insert_cell.hpp | 6 ++-- src/commands/move_cursor.cpp | 6 ++-- src/commands/move_cursor.hpp | 8 ++++-- src/commands/toggle_pause.cpp | 12 +++++--- src/commands/toggle_pause.hpp | 6 ++-- src/conversion.hpp | 7 +++-- src/engine/data/bounds.hpp | 3 +- src/engine/data/vector2.cpp | 6 ++-- src/engine/data/vector2.hpp | 13 +++++---- src/engine/engine.cpp | 20 +++++++++----- src/engine/engine.hpp | 27 ++++++++++++------ src/engine/graphics/scene.cpp | 13 +++++---- src/engine/graphics/scene.hpp | 12 ++++---- src/engine/graphics/window.cpp | 2 +- src/engine/matrix_iterator.tpp | 12 +++++--- src/engine/user/cursor.cpp | 29 +++++++++++++------- src/engine/user/cursor.hpp | 14 +++++----- src/engine/user/input.cpp | 8 ++++-- src/engine/user/input.hpp | 16 ++++++----- src/game/game.cpp | 56 ++++++++++++++++++++++++++------------ src/game/game.hpp | 13 +++++---- src/game/status_updater.cpp | 15 ++++++---- src/game/status_updater.hpp | 3 +- src/game/statusline.cpp | 23 ++++++++++------ src/game/statusline.hpp | 12 +++++--- src/game_of_life.cpp | 6 ++-- src/interfaces/argument_parser.hpp | 12 ++++---- src/interfaces/cursor.hpp | 8 +++--- src/interfaces/game.hpp | 6 ++-- src/interfaces/input.hpp | 7 +++-- src/interfaces/publisher.hpp | 11 ++++---- src/interfaces/randomization.hpp | 4 +-- src/interfaces/scene.hpp | 3 +- src/interfaces/status_updater.hpp | 3 +- src/interfaces/statusline.hpp | 9 ++++-- src/util/color.cpp | 6 ++-- src/util/function.tpp | 14 ++++++---- 53 files changed, 421 insertions(+), 235 deletions(-) diff --git a/.clang-format b/.clang-format index 4147c1f..782b0a9 100644 --- a/.clang-format +++ b/.clang-format @@ -10,4 +10,10 @@ IndentCaseLabels: false ColumnLimit: 90 AccessModifierOffset: -4 AlwaysBreakTemplateDeclarations: Yes -ConstructorInitializerAllOnOneLineOrOnePerLine: Yes +ConstructorInitializerAllOnOneLineOrOnePerLine: true +AllowAllArgumentsOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: false +BinPackArguments: false +BinPackParameters: false +AlignAfterOpenBracket: BlockIndent +Cpp11BracedListStyle: false 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::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; - auto hold = std::unique_ptr(alloc_helper.allocate(1), - _Dp(alloc_helper, 1)); + auto hold = std::unique_ptr( + alloc_helper.allocate(1), + _Dp(alloc_helper, 1) + ); ::new (static_cast(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 -AllocDestructor::AllocDestructor(Allocator &allocator, - Size alloc_size) noexcept +AllocDestructor::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 auto AutoWirable::resolve( - const Container &container) noexcept -> std::unique_ptr + const Container &container +) noexcept -> std::unique_ptr { return std::make_unique(container.get()...); } 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 using MakeIndices = - typename __make_integer_seq::template ToTupleIndices; + typename __make_integer_seq:: + template ToTupleIndices; template requires(SizeTwo <= SizeOne) struct MakeTupleIndices @@ -64,9 +64,11 @@ struct CompressedPairElement } template - constexpr CompressedPairElement(std::piecewise_construct_t /*unused*/, - std::tuple args, - TupleIndices /*unused*/) + constexpr CompressedPairElement( + std::piecewise_construct_t /*unused*/, + std::tuple args, + TupleIndices /*unused*/ + ) : _value(std::forward(std::get(args))...) { } @@ -107,9 +109,11 @@ struct CompressedPairElement : private Value } template - constexpr CompressedPairElement(std::piecewise_construct_t /*unused*/, - std::tuple args, - TupleIndices /*unused*/) + constexpr CompressedPairElement( + std::piecewise_construct_t /*unused*/, + std::tuple args, + TupleIndices /*unused*/ + ) : Value(std::forward(std::get(args))...) { } @@ -146,13 +150,21 @@ public: } template - constexpr CompressedPair(std::piecewise_construct_t piecewise_construct, - std::tuple first_args, - std::tuple second_args) - : BaseOne(piecewise_construct, std::move(first_args), - typename MakeTupleIndices::type()), - BaseTwo(piecewise_construct, std::move(second_args), - typename MakeTupleIndices::type()) + constexpr CompressedPair( + std::piecewise_construct_t piecewise_construct, + std::tuple first_args, + std::tuple second_args + ) + : BaseOne( + piecewise_construct, + std::move(first_args), + typename MakeTupleIndices::type() + ), + BaseTwo( + piecewise_construct, + std::move(second_args), + typename MakeTupleIndices::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 &wrapper) noexcept +void Container::add( + BaseObjectType type, + const WrapperPtr &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::to() noexcept auto wrapper = Container::WrapperPtr(new Wrapper(*_container)); - _container->add(ObjectType(), - std::dynamic_pointer_cast(wrapper)); + _container->add( + ObjectType(), + std::dynamic_pointer_cast(wrapper) + ); } template @@ -35,8 +37,10 @@ void BindingBuilder::to_factory(FactoryFunc factory) noexcept auto wrapper = Container::WrapperPtr(new Wrapper(factory)); - _container->add(ObjectType(), - std::dynamic_pointer_cast(wrapper)); + _container->add( + ObjectType(), + std::dynamic_pointer_cast(wrapper) + ); } template @@ -60,7 +64,8 @@ auto Container::get() const noexcept -> std::unique_ptr } auto wrapper = std::dynamic_pointer_cast>>( - _bindings.at(interface_type)); + _bindings.at(interface_type) + ); return wrapper->get(); } @@ -69,8 +74,9 @@ template requires IsFactory auto Container::get() const noexcept -> AFactory { - auto wrapper = std::dynamic_pointer_cast>( - _bindings.at(ObjectType())); + auto wrapper = + std::dynamic_pointer_cast>(_bindings.at(ObjectType()) + ); 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 * using Destructor = AllocDestructor; - auto hold = std::unique_ptr(alloc_helper.allocate(1), - Destructor(alloc_helper, 1)); + auto hold = std::unique_ptr( + alloc_helper.allocate(1), + Destructor(alloc_helper, 1) + ); ::new (static_cast(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 struct is_core_convertible< - Tp, Up, decltype(static_cast(0)(static_cast(0)()))> + Tp, + Up, + decltype(static_cast(0)(static_cast(0)()))> : public std::true_type { }; @@ -154,8 +156,9 @@ private: template Factory(Return (*)(Args...)) -> Factory; -template > +template < + class Function, + class Stripped = strip_signature_t> Factory(Function) -> Factory; template 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 -FunctionWrapper::FunctionWrapper(Interface func) noexcept : _func(std::move(func)) +FunctionWrapper::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; auto hold = std::unique_ptr( - functor_alloc.allocate(1), Destructor(functor_alloc, 1)); + functor_alloc.allocate(1), + Destructor(functor_alloc, 1) + ); ::new (static_cast(hold.get())) Functor(std::forward(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