From eb70728053531e56aca6aad2e696453a2b3b88b2 Mon Sep 17 00:00:00 2001 From: Tim Ebbeke Date: Sun, 24 Nov 2024 14:55:54 +0100 Subject: [PATCH 01/19] Added OBSERVED_BUNDLE_FILES to watch file changes --- cmake/frontend/emscripten.cmake | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cmake/frontend/emscripten.cmake b/cmake/frontend/emscripten.cmake index 8e61c12..c1cd356 100644 --- a/cmake/frontend/emscripten.cmake +++ b/cmake/frontend/emscripten.cmake @@ -3,7 +3,7 @@ function(nui_prepare_emscripten_target) NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS "NO_INLINE;NO_INLINE_INJECT;LEAN_INDEX_HTML" "TARGET;PREJS;STATIC;UNPACKED_MODE" - "EMSCRIPTEN_LINK_OPTIONS;EMSCRIPTEN_COMPILE_OPTIONS;PARCEL_ARGS;NPM_INSTALL_ARGS" + "EMSCRIPTEN_LINK_OPTIONS;EMSCRIPTEN_COMPILE_OPTIONS;PARCEL_ARGS;NPM_INSTALL_ARGS;OBSERVED_BUNDLE_FILES" ${ARGN} ) @@ -43,7 +43,8 @@ function(nui_prepare_emscripten_target) ) add_custom_command( - OUTPUT "${CMAKE_BINARY_DIR}/bin/index.html" + OUTPUT "${CMAKE_BINARY_DIR}/bin/index.html" + DEPENDS ${NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_OBSERVED_BUNDLE_FILES} COMMAND ${CMAKE_COMMAND} -E copy_directory "${NUI_SOURCE_DIRECTORY}/nui/js" "${NUI_MODULE_BUILD_DIR}/nui-js" COMMAND ${CMAKE_COMMAND} -E rm -rf "${CMAKE_BINARY_DIR}/static" COMMAND ${CMAKE_COMMAND} -E copy_directory ${NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_STATIC} "${CMAKE_BINARY_DIR}/static" From 914f6db5a98810167b08a331ee9d4a0c2489f169 Mon Sep 17 00:00:00 2001 From: Tim Ebbeke Date: Tue, 26 Nov 2024 21:37:55 +0100 Subject: [PATCH 02/19] Tidy html_element.hpp --- .clang-tidy | 6 +++++ .../frontend/elements/impl/html_element.hpp | 25 +++++++++++-------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 1df1ea1..679a7a4 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -8,6 +8,7 @@ Checks: '-*, llvm-*, -llvm-header-guard, -llvm-include-order, + -llvm-namespace-comment, clang-analyzer-*, modernize-*, -modernize-use-trailing-return-type, @@ -25,14 +26,19 @@ Checks: '-*, -readability-named-parameter, -readability-redundant-access-specifiers, -readability-magic-numbers, + -readability-braces-around-statements, hicpp-*, -hicpp-avoid-c-arrays, -hicpp-uppercase-literal-suffix, -hicpp-noexcept-move, -hicpp-vararg, -hicpp-member-init, + -hicpp-braces-around-statements, misc-*, -misc-non-private-member-variables-in-classes' +CheckOptions: + - key: AllowPartialMove + value: true # Disabled Options Explanation: # CppCoreGuidelines: diff --git a/nui/include/nui/frontend/elements/impl/html_element.hpp b/nui/include/nui/frontend/elements/impl/html_element.hpp index bd4a5ec..6a58154 100644 --- a/nui/include/nui/frontend/elements/impl/html_element.hpp +++ b/nui/include/nui/frontend/elements/impl/html_element.hpp @@ -21,8 +21,6 @@ #include #include #include -#include -#include namespace Nui { @@ -49,7 +47,7 @@ namespace Nui struct TrivialRenderer { public: - TrivialRenderer(HtmlElem htmlElement); + explicit TrivialRenderer(HtmlElem htmlElement); std::shared_ptr operator()(Dom::Element& parentElement, Renderer const& gen) const; private: @@ -63,7 +61,10 @@ namespace Nui HtmlElement(HtmlElement const&) = default; HtmlElement(HtmlElement&&) = default; + HtmlElement& operator=(HtmlElement const&) = default; + HtmlElement& operator=(HtmlElement&&) = default; virtual ~HtmlElement() = default; + HtmlElement(char const* name, HtmlElementBridge const* bridge, std::vector const& attributes) : name_{name} , bridge_{bridge} @@ -158,12 +159,13 @@ namespace Nui } template + // NOLINTNEXTLINE(cppcoreguidelines-missing-std-forward) auto rangeRender(RangeType&& valueRange, GeneratorT&& elementRenderer) && { return [self = this->clone(), rangeRenderer = std::make_shared< Detail::RangeRenderer, GeneratorT, RangeType::isRandomAccess>>( - std::move(valueRange).underlying(), std::forward(elementRenderer))]( + std::forward(valueRange).underlying(), std::forward(elementRenderer))]( auto& parentElement, Renderer const& gen) mutable { if (gen.type == RendererType::Inplace) throw std::runtime_error("fragments are not supported for range generators"); @@ -202,7 +204,7 @@ namespace Nui } // Trivial case: - auto operator()() && + auto operator()() const&& { return std::function(Dom::Element&, Renderer const&)>{ TrivialRenderer{this->clone()}}; @@ -224,7 +226,7 @@ namespace Nui return materialized; }; } - auto operator()(std::string_view view) && + auto operator()(std::string_view view) const&& { return [self = this->clone(), view](auto& parentElement, Renderer const& gen) { auto materialized = renderElement(gen, parentElement, self); @@ -232,7 +234,7 @@ namespace Nui return materialized; }; } - auto operator()(char const* text) && + auto operator()(char const* text) const&& { return [self = this->clone(), text](auto& parentElement, Renderer const& gen) { auto materialized = renderElement(gen, parentElement, self); @@ -311,6 +313,7 @@ namespace Nui return std::move(*this).rangeRender(std::move(mapPair.first), std::move(mapPair.second)); } template + // NOLINTNEXTLINE(cppcoreguidelines-missing-std-forward): false positive auto operator()(UnoptimizedRange&& unoptimizedRange, GeneratorT&& elementRenderer) && { return [self = this->clone(), @@ -328,7 +331,7 @@ namespace Nui } // Observed text and number content functions: - inline auto operator()(Observed const& observedString) && + auto operator()(Observed const& observedString) && { return std::move(*this).operator()(observe(observedString), [&observedString]() -> std::string { return observedString.value(); @@ -343,17 +346,17 @@ namespace Nui }); } - inline std::vector const& attributes() const + std::vector const& attributes() const { return attributes_; } - inline char const* name() const + char const* name() const { return name_; } - inline HtmlElementBridge const* bridge() const + HtmlElementBridge const* bridge() const { return bridge_; } From 3893b562b66312141b48e699fa2aa6fa7de05c8f Mon Sep 17 00:00:00 2001 From: Tim Ebbeke Date: Tue, 26 Nov 2024 21:51:54 +0100 Subject: [PATCH 03/19] Tidy: rpc_hub.hpp --- .clang-tidy | 1 + nui/include/nui/backend/rpc_hub.hpp | 18 ++++++++---------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 679a7a4..88b1429 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -27,6 +27,7 @@ Checks: '-*, -readability-redundant-access-specifiers, -readability-magic-numbers, -readability-braces-around-statements, + -readability-identifier-length, hicpp-*, -hicpp-avoid-c-arrays, -hicpp-uppercase-literal-suffix, diff --git a/nui/include/nui/backend/rpc_hub.hpp b/nui/include/nui/backend/rpc_hub.hpp index 6fee3bb..7dc17fb 100644 --- a/nui/include/nui/backend/rpc_hub.hpp +++ b/nui/include/nui/backend/rpc_hub.hpp @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include @@ -40,7 +39,7 @@ namespace Nui template constexpr static auto wrapFunction(FunctionT&& func) { - return [func = std::move(func)](nlohmann::json const& args) mutable { + return [func = std::forward(func)](nlohmann::json const& args) mutable { func(args); }; } @@ -52,7 +51,7 @@ namespace Nui template constexpr static auto wrapFunction(FunctionT&& func) { - return [func = std::move(func)](nlohmann::json const& args) mutable { + return [func = std::forward(func)](nlohmann::json const& args) mutable { func(extractJsonMember(args[Is])...); }; } @@ -78,7 +77,7 @@ namespace Nui class RpcHub { public: - RpcHub(Window& window); + explicit RpcHub(Window& window); ~RpcHub() = default; RpcHub(const RpcHub&) = delete; RpcHub& operator=(const RpcHub&) = delete; @@ -153,13 +152,15 @@ namespace Nui template void callRemote(std::string const& name, Arg&& arg) const { - nlohmann::json j = arg; - callRemoteImpl(name, std::move(j)); + nlohmann::json json = std::forward(arg); + callRemoteImpl(name, json); } void callRemote(std::string const& name, nlohmann::json const& json) const { callRemoteImpl(name, json); } + // I dont want to remove this overload in case there are some rvalue nlohmanns? + // NOLINTNEXTLINE(cppcoreguidelines-rvalue-reference-param-not-moved) void callRemote(std::string const& name, nlohmann::json&& json) const { callRemoteImpl(name, json); @@ -238,10 +239,7 @@ namespace Nui }}}) .first->second.get(); } - else - { - return iter->second.get(); - } + return iter->second.get(); } private: From 93e72ac37411977a59f5741d843befa5fb6de475 Mon Sep 17 00:00:00 2001 From: Tim Ebbeke Date: Tue, 26 Nov 2024 22:18:34 +0100 Subject: [PATCH 04/19] Tidy registry. --- nui/include/nui/data_structures/selectables_registry.hpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/nui/include/nui/data_structures/selectables_registry.hpp b/nui/include/nui/data_structures/selectables_registry.hpp index 209478b..62142b2 100644 --- a/nui/include/nui/data_structures/selectables_registry.hpp +++ b/nui/include/nui/data_structures/selectables_registry.hpp @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include @@ -66,6 +65,7 @@ namespace Nui ItemWithId(ItemWithId&&) = default; ItemWithId& operator=(ItemWithId const&) = default; ItemWithId& operator=(ItemWithId&&) = default; + ~ItemWithId() = default; /// @brief Compares the id of the item. bool operator<(ItemWithId const& other) const @@ -197,7 +197,7 @@ namespace Nui using IteratorBase::operator=; using IteratorBase::wrappedIterator_; - ConstIterator(typename ItemContainerType::iterator iter) + explicit ConstIterator(typename ItemContainerType::iterator iter) : IteratorBase{std::move(iter)} {} @@ -400,6 +400,9 @@ namespace Nui { ++itemCount_; ++result; + // selected is a set item, and therefore immutable, so we need to const_cast to move it. + // this would break the set, but its cleared afterwards anyway. + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast) entry->item = std::move(const_cast(selected).item); } } From bea830060a69d9046f341b4854fd75301a7e48fe Mon Sep 17 00:00:00 2001 From: Tim Ebbeke Date: Tue, 26 Nov 2024 22:18:44 +0100 Subject: [PATCH 05/19] Tidy event registry. --- nui/include/nui/event_system/event_registry.hpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/nui/include/nui/event_system/event_registry.hpp b/nui/include/nui/event_system/event_registry.hpp index 2e36752..0887a6d 100644 --- a/nui/include/nui/event_system/event_registry.hpp +++ b/nui/include/nui/event_system/event_registry.hpp @@ -4,9 +4,7 @@ #include #include -#include #include -#include namespace Nui { From 680b3bdce35978af1a56bf12f28d90b58836b91c Mon Sep 17 00:00:00 2001 From: Tim Ebbeke Date: Tue, 26 Nov 2024 22:19:34 +0100 Subject: [PATCH 06/19] Tidy event. --- .clang-tidy | 1 + nui/include/nui/event_system/event.hpp | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 88b1429..2a28f03 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -35,6 +35,7 @@ Checks: '-*, -hicpp-vararg, -hicpp-member-init, -hicpp-braces-around-statements, + -hicpp-named-parameter, misc-*, -misc-non-private-member-variables-in-classes' CheckOptions: diff --git a/nui/include/nui/event_system/event.hpp b/nui/include/nui/event_system/event.hpp index 5ab1b8a..cfdd432 100644 --- a/nui/include/nui/event_system/event.hpp +++ b/nui/include/nui/event_system/event.hpp @@ -10,7 +10,13 @@ namespace Nui { virtual bool call(std::size_t eventId) = 0; virtual bool valid() const = 0; + virtual ~EventImpl() = default; + EventImpl() = default; + EventImpl(EventImpl const&) = default; + EventImpl(EventImpl&&) = default; + EventImpl& operator=(EventImpl const&) = default; + EventImpl& operator=(EventImpl&&) = default; }; struct TwoFunctorEventImpl : public EventImpl @@ -39,7 +45,7 @@ namespace Nui class Event { public: - Event( + explicit Event( std::function action, std::function valid = [] { @@ -51,8 +57,9 @@ namespace Nui Event(Event&&) = default; Event& operator=(Event const&) = delete; Event& operator=(Event&&) = default; + ~Event() = default; - operator bool() const + explicit operator bool() const { return impl_->valid(); } From 0156de422df4479117d79765111d46ef31e76b07 Mon Sep 17 00:00:00 2001 From: Tim Ebbeke Date: Tue, 26 Nov 2024 22:22:21 +0100 Subject: [PATCH 07/19] Tidy observed value combinator. --- .../nui/event_system/observed_value_combinator.hpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/nui/include/nui/event_system/observed_value_combinator.hpp b/nui/include/nui/event_system/observed_value_combinator.hpp index de62151..0d2afcb 100644 --- a/nui/include/nui/event_system/observed_value_combinator.hpp +++ b/nui/include/nui/event_system/observed_value_combinator.hpp @@ -75,8 +75,7 @@ namespace Nui std::tuple...>&& observedValues() && { - return std::move( - const_cast...>&>(observedValues_)); + return std::move(observedValues_); } bool isAnyExpired() const @@ -98,7 +97,7 @@ namespace Nui } protected: - const std::tuple...> observedValues_; + std::tuple...> observedValues_; }; template @@ -135,7 +134,7 @@ namespace Nui } protected: - const RendererType generator_; + RendererType generator_; }; template @@ -145,7 +144,7 @@ namespace Nui public: using ObservedValueCombinatorWithGenerator:: ObservedValueCombinatorWithGenerator; - ObservedValueCombinatorWithPropertyGenerator( + explicit ObservedValueCombinatorWithPropertyGenerator( ObservedValueCombinatorWithGenerator&& other) : ObservedValueCombinatorWithGenerator{std::move(other)} {} From 3c0c4126f06b6c48e45cfbdb80d23738513b4bde Mon Sep 17 00:00:00 2001 From: Tim Ebbeke Date: Tue, 26 Nov 2024 22:27:19 +0100 Subject: [PATCH 08/19] Tidy observed value. --- .../nui/event_system/observed_value.hpp | 46 +++++++++++++------ 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/nui/include/nui/event_system/observed_value.hpp b/nui/include/nui/event_system/observed_value.hpp index faa1244..30dc5c5 100644 --- a/nui/include/nui/event_system/observed_value.hpp +++ b/nui/include/nui/event_system/observed_value.hpp @@ -18,7 +18,6 @@ #include #include #include -#include namespace Nui { @@ -36,26 +35,47 @@ namespace Nui {} virtual ~ObservedBase() = default; ObservedBase(ObservedBase const&) = delete; - ObservedBase(ObservedBase&& other) + ObservedBase(ObservedBase&& other) noexcept : eventContext_{other.eventContext_} , attachedEvents_{} , attachedOneshotEvents_{} { // events are outside the value logic of the observed class. the contained value is moved, but the events // are merged. - for (auto& event : other.attachedEvents_) - attachedEvents_.push_back(std::move(event)); - for (auto& event : other.attachedOneshotEvents_) - attachedOneshotEvents_.push_back(std::move(event)); + try + { + attachedEvents_.reserve(attachedEvents_.size() + other.attachedEvents_.size()); + attachedOneshotEvents_.reserve(attachedOneshotEvents_.size() + other.attachedOneshotEvents_.size()); + + for (auto& event : other.attachedEvents_) + attachedEvents_.push_back(std::move(event)); + for (auto& event : other.attachedOneshotEvents_) + attachedOneshotEvents_.push_back(std::move(event)); + } + catch (...) + { + std::terminate(); + } } ObservedBase& operator=(ObservedBase const&) = delete; - ObservedBase& operator=(ObservedBase&& other) + ObservedBase& operator=(ObservedBase&& other) noexcept { eventContext_ = other.eventContext_; - for (auto& event : other.attachedEvents_) - attachedEvents_.push_back(std::move(event)); - for (auto& event : other.attachedOneshotEvents_) - attachedOneshotEvents_.push_back(std::move(event)); + try + { + attachedEvents_.reserve(attachedEvents_.size() + other.attachedEvents_.size()); + attachedOneshotEvents_.reserve(attachedOneshotEvents_.size() + other.attachedOneshotEvents_.size()); + + for (auto& event : other.attachedEvents_) + attachedEvents_.push_back(std::move(event)); + for (auto& event : other.attachedOneshotEvents_) + attachedOneshotEvents_.push_back(std::move(event)); + } + catch (...) + { + std::terminate(); + } + return *this; } @@ -1438,8 +1458,8 @@ namespace Nui return observedValue; } template - inline auto - operator--(ModifiableObserved& observedValue, int) -> Detail::PickFirst_t()--)> + inline auto operator--(ModifiableObserved& observedValue, int) + -> Detail::PickFirst_t()--)> { auto tmp = observedValue.value(); --observedValue.value(); From f69ad37f383a8c7a75416bfa5ec71d5f21ed53a9 Mon Sep 17 00:00:00 2001 From: Tim Ebbeke Date: Tue, 26 Nov 2024 22:55:58 +0100 Subject: [PATCH 09/19] Tidy observed value. --- .../nui/event_system/observed_value.hpp | 110 ++++++++++++++---- .../frontend/utility/fragment_listener.cpp | 3 +- 2 files changed, 88 insertions(+), 25 deletions(-) diff --git a/nui/include/nui/event_system/observed_value.hpp b/nui/include/nui/event_system/observed_value.hpp index 30dc5c5..17c43d7 100644 --- a/nui/include/nui/event_system/observed_value.hpp +++ b/nui/include/nui/event_system/observed_value.hpp @@ -1,6 +1,5 @@ #pragma once -#include #include #include #include @@ -18,6 +17,8 @@ #include #include #include +#include +#include namespace Nui { @@ -48,9 +49,17 @@ namespace Nui attachedOneshotEvents_.reserve(attachedOneshotEvents_.size() + other.attachedOneshotEvents_.size()); for (auto& event : other.attachedEvents_) + { + // Dont want to lose the move if event becomes non trivial + // NOLINTNEXTLINE(performance-move-const-arg, hicpp-move-const-arg) attachedEvents_.push_back(std::move(event)); + } for (auto& event : other.attachedOneshotEvents_) + { + // Dont want to lose the move if event becomes non trivial + // NOLINTNEXTLINE(performance-move-const-arg, hicpp-move-const-arg) attachedOneshotEvents_.push_back(std::move(event)); + } } catch (...) { @@ -67,9 +76,17 @@ namespace Nui attachedOneshotEvents_.reserve(attachedOneshotEvents_.size() + other.attachedOneshotEvents_.size()); for (auto& event : other.attachedEvents_) + { + // Dont want to lose the move if event becomes non trivial + // NOLINTNEXTLINE(performance-move-const-arg, hicpp-move-const-arg) attachedEvents_.push_back(std::move(event)); + } for (auto& event : other.attachedOneshotEvents_) + { + // Dont want to lose the move if event becomes non trivial + // NOLINTNEXTLINE(performance-move-const-arg, hicpp-move-const-arg) attachedOneshotEvents_.push_back(std::move(event)); + } } catch (...) { @@ -123,7 +140,7 @@ namespace Nui for (auto& event : attachedEvents_) { auto activationResult = eventContext_->activateEvent(event); - if (activationResult.found == false) + if (!activationResult.found) event = EventRegistry::invalidEventId; } for (auto& event : attachedOneshotEvents_) @@ -159,22 +176,44 @@ namespace Nui { public: explicit ModificationProxy(ModifiableObserved& observed) - : observed_{observed} + : observed_{&observed} , now_{false} {} explicit ModificationProxy(ModifiableObserved& observed, bool now) - : observed_{observed} + : observed_{&observed} , now_{now} {} + ModificationProxy(ModificationProxy const&) = delete; + ModificationProxy& operator=(ModificationProxy const&) = delete; + ModificationProxy(ModificationProxy&& other) noexcept + : observed_{other.observed_} + , now_{other.now_} + { + other.observed_ = nullptr; + } + ModificationProxy& operator=(ModificationProxy&& other) noexcept + { + if (this != &other) + { + observed_ = other.observed_; + now_ = other.now_; + other.observed_ = nullptr; + } + return *this; + } ~ModificationProxy() { try { + if (observed_ == nullptr) + return; + if (now_) - observed_.updateNow(true); + observed_->updateNow(true); else - observed_.update(true); + observed_->update(true); } + // NOLINTNEXTLINE(bugprone-empty-catch) catch (...) { // TODO: log? @@ -182,23 +221,23 @@ namespace Nui } auto& value() { - return observed_.contained_; + return observed_->contained_; } auto* operator->() { - return &observed_.contained_; + return &observed_->contained_; } auto& operator*() { - return observed_.contained_; + return observed_->contained_; } - operator ContainedT&() + explicit operator ContainedT&() { - return observed_.contained_; + return observed_->contained_; } private: - ModifiableObserved& observed_; + ModifiableObserved* observed_; bool now_; }; @@ -208,14 +247,14 @@ namespace Nui , contained_{} {} ModifiableObserved(const ModifiableObserved&) = delete; - ModifiableObserved(ModifiableObserved&& other) + ModifiableObserved(ModifiableObserved&& other) noexcept : ObservedBase{std::move(other)} , contained_{std::move(other.contained_)} { update(); }; ModifiableObserved& operator=(const ModifiableObserved&) = delete; - ModifiableObserved& operator=(ModifiableObserved&& other) + ModifiableObserved& operator=(ModifiableObserved&& other) noexcept { if (this != &other) { @@ -237,9 +276,10 @@ namespace Nui update(); return *this; } - ~ModifiableObserved() = default; + ~ModifiableObserved() override = default; template + requires std::is_constructible_v explicit ModifiableObserved(T&& t) : ObservedBase{CustomEventContextFlag, &globalEventContext} , contained_{std::forward(t)} @@ -251,7 +291,8 @@ namespace Nui {} template - explicit ModifiableObserved(CustomEventContextFlag_t, EventContext* ctx, T&& t) + requires std::is_constructible_v + ModifiableObserved(CustomEventContextFlag_t, EventContext* ctx, T&& t) : ObservedBase{CustomEventContextFlag, ctx} , contained_{std::forward(t)} {} @@ -289,7 +330,8 @@ namespace Nui requires std::equality_comparable_with && Fundamental && Fundamental ModifiableObserved& operator=(T&& t) { - return assignChecked(t); + assignChecked(std::forward(t)); + return *this; } template @@ -354,7 +396,9 @@ namespace Nui /** * @brief Sets the value without making an update. */ - void assignWithoutUpdate(ContainedT&& t) + template + requires std::constructible_from + void assignWithoutUpdate(T&& t) { contained_ = std::forward(t); } @@ -401,6 +445,8 @@ namespace Nui } return *this; } + ~ReferenceWrapper() = default; + // NOLINTNEXTLINE(hicpp-explicit-conversions) operator T&() { return *ref_; @@ -432,15 +478,25 @@ namespace Nui { return *ref_; } - void operator=(T&& val) + ReferenceWrapper& operator=(T&& val) { *ref_ = std::move(val); owner_->insertRangeChecked(pos_, pos_, RangeOperationType::Modify); + return *this; } - void operator=(T const& val) + ReferenceWrapper& operator=(T const& val) { *ref_ = val; owner_->insertRangeChecked(pos_, pos_, RangeOperationType::Modify); + return *this; + } + bool operator==(ReferenceWrapper const& other) const + { + return *ref_ == *other.ref_; + } + bool operator==(T const& other) const + { + return *ref_ == other; } protected: @@ -477,6 +533,7 @@ namespace Nui , pos_{pos} , ptr_{ptr} {} + // NOLINTNEXTLINE(hicpp-explicit-conversions) operator T&() { return *ptr_; @@ -508,10 +565,11 @@ namespace Nui { return *ptr_; } - void operator=(T* ptr) + PointerWrapper& operator=(T* ptr) { ptr_ = ptr; owner_->insertRangeChecked(pos_, pos_, RangeOperationType::Modify); + return *this; } protected: @@ -539,6 +597,7 @@ namespace Nui IteratorWrapper(IteratorWrapper&&) = default; IteratorWrapper& operator=(IteratorWrapper const&) = default; IteratorWrapper& operator=(IteratorWrapper&&) = default; + ~IteratorWrapper() = default; IteratorWrapper& operator+=(difference_type n) { it_ += n; @@ -688,6 +747,7 @@ namespace Nui , afterEffectId_{registerAfterEffect()} {} template + requires std::constructible_from explicit ObservedContainer(T&& t) : ModifiableObserved{std::forward(t)} , rangeContext_{std::make_shared()} @@ -1322,6 +1382,7 @@ namespace Nui : ObservedContainer>{RangeEventContext{true}} {} template > + requires std::constructible_from, T> explicit Observed(T&& t) : ObservedContainer>{std::forward(t), RangeEventContext{true}} {} @@ -1351,6 +1412,7 @@ namespace Nui : ObservedContainer>{RangeEventContext{true}} {} template > + requires std::constructible_from, T> explicit Observed(T&& t) : ObservedContainer>{std::forward(t), RangeEventContext{true}} {} @@ -1486,17 +1548,17 @@ namespace Nui : observed_{&observed} {} - inline T const& value() const + T const& value() const { return observed_->value(); } - inline void attachEvent(auto eventId) const + void attachEvent(auto eventId) const { observed_->attachEvent(eventId); } - inline void detachEvent(auto eventId) const + void detachEvent(auto eventId) const { observed_->detachEvent(eventId); } diff --git a/nui/src/nui/frontend/utility/fragment_listener.cpp b/nui/src/nui/frontend/utility/fragment_listener.cpp index 2dd869f..adfeb52 100644 --- a/nui/src/nui/frontend/utility/fragment_listener.cpp +++ b/nui/src/nui/frontend/utility/fragment_listener.cpp @@ -16,7 +16,8 @@ namespace Nui fragment = Nui::val::global("location")["hash"].as(); else fragment = ""; - if (fragment.front() == '#') + + if (fragment.value().front() == '#') fragment.erase(0, 1); Nui::val::global("window").call( From daab3b85a928bb0490c844f2cf660b6554fda530 Mon Sep 17 00:00:00 2001 From: Tim Ebbeke Date: Tue, 26 Nov 2024 22:58:56 +0100 Subject: [PATCH 10/19] Tidy range event context. --- .clang-tidy | 2 ++ .../nui/event_system/range_event_context.hpp | 19 ++++++++----------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 2a28f03..5e863d4 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -5,6 +5,7 @@ Checks: '-*, -cppcoreguidelines-pro-bounds-constant-array-index, -cppcoreguidelines-pro-type-vararg, -cppcoreguidelines-non-private-member-variables-in-classes, + -cppcoreguidelines-avoid-do-while, llvm-*, -llvm-header-guard, -llvm-include-order, @@ -18,6 +19,7 @@ Checks: '-*, -modernize-use-using, performance-*, -performance-noexcept-move-constructor, + -performance-enum-size, portability-*, readability-*, -readability-redundant-member-init, diff --git a/nui/include/nui/event_system/range_event_context.hpp b/nui/include/nui/event_system/range_event_context.hpp index 9568519..7861f38 100644 --- a/nui/include/nui/event_system/range_event_context.hpp +++ b/nui/include/nui/event_system/range_event_context.hpp @@ -7,7 +7,6 @@ #include #include -#include #include #include @@ -34,10 +33,12 @@ namespace Nui using interval_kind = IntervalKind; public: + // NOLINTNEXTLINE(bugprone-easily-swappable-parameters) RangeStateInterval(value_type low, value_type high) : low_{low} , high_{high} {} + // NOLINTNEXTLINE(bugprone-easily-swappable-parameters) void reset(value_type low, value_type high) { low_ = low; @@ -122,8 +123,7 @@ namespace Nui return 0; if (high_ < other.low_) return other.low_ - high_; - else - return low_ - other.high_; + return low_ - other.high_; } value_type size() const { @@ -189,7 +189,7 @@ namespace Nui explicit RangeEventContext() : RangeEventContext(false) {} - RangeEventContext(bool disableOptimizations) + explicit RangeEventContext(bool disableOptimizations) : trackedRanges_{} , operationType_{RangeOperationType::Keep} , nextEraseOverride_{std::nullopt} @@ -216,8 +216,7 @@ namespace Nui return false; if (operationType_ == RangeOperationType::Modify) return eraseModificationFixup(low, high); - else - return eraseInsertionFixup(low, high); + return eraseInsertionFixup(low, high); } bool eraseNotify(std::size_t low, std::size_t high) { @@ -452,10 +451,7 @@ namespace Nui // If the erase interval is left of the last modification interval, we must apply the changes and // retry. An overlap would have been found otherwise. - if (high < lastInterval.low()) - return true; - - return false; + return high < lastInterval.low(); } // find all overlapping modifications and cut them @@ -474,7 +470,8 @@ namespace Nui trackedRanges_.insert({range.high() + 1, modInterval.high()}); return true; // cannot overlap any further } - else if (modInterval.low() < range.low()) + + if (modInterval.low() < range.low()) { // 2. erase starts within modification interval: trackedRanges_.insert({modInterval.low(), range.low() - 1}); From c51462f30b21435122a0b123a465c46d601563d4 Mon Sep 17 00:00:00 2001 From: Tim Ebbeke Date: Tue, 26 Nov 2024 23:02:02 +0100 Subject: [PATCH 11/19] Tidy event system range --- nui/include/nui/event_system/range.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nui/include/nui/event_system/range.hpp b/nui/include/nui/event_system/range.hpp index 2e7a44c..8190efb 100644 --- a/nui/include/nui/event_system/range.hpp +++ b/nui/include/nui/event_system/range.hpp @@ -3,8 +3,8 @@ #include #include #include +#include -#include #include #ifdef NUI_HAS_STD_RANGES @@ -49,7 +49,7 @@ namespace Nui : observedValues_{std::move(observedValues)} , rangeLike_{std::move(rangeLike)} {} - UnoptimizedRange(CopyableRangeLike&& rangeLike) + explicit UnoptimizedRange(CopyableRangeLike&& rangeLike) requires(sizeof...(ObservedValues) == 0) : observedValues_{} , rangeLike_{std::move(rangeLike)} From 92e9fc4a8c07ee7ecdae518068a110281c6cb1be Mon Sep 17 00:00:00 2001 From: Tim Ebbeke Date: Tue, 26 Nov 2024 23:02:13 +0100 Subject: [PATCH 12/19] Tidy file dialog options. --- nui/include/nui/filesystem/file_dialog_options.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/nui/include/nui/filesystem/file_dialog_options.hpp b/nui/include/nui/filesystem/file_dialog_options.hpp index 942573e..1b78585 100644 --- a/nui/include/nui/filesystem/file_dialog_options.hpp +++ b/nui/include/nui/filesystem/file_dialog_options.hpp @@ -20,6 +20,7 @@ namespace Nui::FileDialog }; // This way aggregate initialization can be done without needing to add extra braces +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define COMMON_DIALOG_OPTIONS() \ std::optional title = std::nullopt; \ std::optional defaultPath = std::nullopt; \ From 4e86c6a9a168821138c64a4ef150ad27e68c721a Mon Sep 17 00:00:00 2001 From: Tim Ebbeke Date: Tue, 26 Nov 2024 23:17:29 +0100 Subject: [PATCH 13/19] Tidy throttle. --- nui/include/nui/frontend/api/throttle.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nui/include/nui/frontend/api/throttle.hpp b/nui/include/nui/frontend/api/throttle.hpp index 3a2647d..9109808 100644 --- a/nui/include/nui/frontend/api/throttle.hpp +++ b/nui/include/nui/frontend/api/throttle.hpp @@ -13,9 +13,9 @@ namespace Nui ThrottledFunction(int32_t id, bool calledWhenReady, std::function func); ~ThrottledFunction(); ThrottledFunction(ThrottledFunction const&) = delete; - ThrottledFunction(ThrottledFunction&& other); + ThrottledFunction(ThrottledFunction&& other) noexcept; ThrottledFunction& operator=(ThrottledFunction const&) = delete; - ThrottledFunction& operator=(ThrottledFunction&& other); + ThrottledFunction& operator=(ThrottledFunction&& other) noexcept; /// Calls the function if it is valid. void operator()(); @@ -24,7 +24,7 @@ namespace Nui bool valid() const; private: - int32_t id_{-1}; + int32_t id_; bool calledWhenReady_; std::function func_{}; }; From a66fcc61f62494e2427ef943a8ea5855edad7592 Mon Sep 17 00:00:00 2001 From: Tim Ebbeke Date: Tue, 26 Nov 2024 23:17:34 +0100 Subject: [PATCH 14/19] Tidy timer. --- nui/include/nui/frontend/api/timer.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nui/include/nui/frontend/api/timer.hpp b/nui/include/nui/frontend/api/timer.hpp index 8a71242..26b40a5 100644 --- a/nui/include/nui/frontend/api/timer.hpp +++ b/nui/include/nui/frontend/api/timer.hpp @@ -12,11 +12,11 @@ namespace Nui { public: TimerHandle(); - TimerHandle(int32_t id); + explicit TimerHandle(int32_t id); TimerHandle(const TimerHandle&) = delete; - TimerHandle(TimerHandle&& other); + TimerHandle(TimerHandle&& other) noexcept; TimerHandle& operator=(const TimerHandle&) = delete; - TimerHandle& operator=(TimerHandle&& other); + TimerHandle& operator=(TimerHandle&& other) noexcept; ~TimerHandle(); From 2455251676ab41c11ed98bb6a2fd9fd8aad3927f Mon Sep 17 00:00:00 2001 From: Tim Ebbeke Date: Tue, 26 Nov 2024 23:18:00 +0100 Subject: [PATCH 15/19] Tidy attribute factory. --- .../attributes/impl/attribute_factory.hpp | 73 ++++++++++++------- 1 file changed, 45 insertions(+), 28 deletions(-) diff --git a/nui/include/nui/frontend/attributes/impl/attribute_factory.hpp b/nui/include/nui/frontend/attributes/impl/attribute_factory.hpp index 472e3f5..6877293 100644 --- a/nui/include/nui/frontend/attributes/impl/attribute_factory.hpp +++ b/nui/include/nui/frontend/attributes/impl/attribute_factory.hpp @@ -70,14 +70,11 @@ namespace Nui::Attributes : name_{name} {} - explicit constexpr PropertyFactory(PropertyFactory const& other) - : name_{other.name_} - {} - explicit constexpr PropertyFactory(PropertyFactory&& other) - : name_{other.name_} - {} + constexpr PropertyFactory(PropertyFactory const& other) = default; + constexpr PropertyFactory(PropertyFactory&& other) noexcept = default; PropertyFactory& operator=(PropertyFactory const&) = delete; PropertyFactory& operator=(PropertyFactory&&) = delete; + ~PropertyFactory() = default; constexpr char const* name() const { @@ -88,6 +85,7 @@ namespace Nui::Attributes requires( !IsObservedLike> && !std::invocable && !std::invocable && !Nui::Detail::IsProperty>) + // NOLINTNEXTLINE(misc-unconventional-assign-operator, cppcoreguidelines-c-copy-assignment-signature) Attribute operator=(U val) const { return Attribute{ @@ -99,6 +97,7 @@ namespace Nui::Attributes template requires(IsSharedObserved>) + // NOLINTNEXTLINE(misc-unconventional-assign-operator, cppcoreguidelines-c-copy-assignment-signature) Attribute operator=(U const& shared) const { return Attribute{ @@ -106,7 +105,7 @@ namespace Nui::Attributes if (auto shared = weak.lock(); shared) element.setProperty(name, shared->value()); }, - [name = name(), weak = std::weak_ptr{shared}](std::weak_ptr&& element) { + [name = name(), weak = std::weak_ptr{shared}](std::weak_ptr const& element) { auto shared = weak.lock(); if (!shared) return EventContext::invalidEventId; @@ -142,6 +141,7 @@ namespace Nui::Attributes template requires(IsWeakObserved>) + // NOLINTNEXTLINE Attribute operator=(U&& val) const { auto shared = val.lock(); @@ -153,6 +153,7 @@ namespace Nui::Attributes template requires(IsObserved>) + // NOLINTNEXTLINE(misc-unconventional-assign-operator, cppcoreguidelines-c-copy-assignment-signature) Attribute operator=(U& val) const { return Attribute{ @@ -170,6 +171,7 @@ namespace Nui::Attributes } template + // NOLINTNEXTLINE(misc-unconventional-assign-operator, cppcoreguidelines-c-copy-assignment-signature) Attribute operator=(ObservedValueCombinatorWithPropertyGenerator const& combinator) const { @@ -187,6 +189,7 @@ namespace Nui::Attributes } template + // NOLINTNEXTLINE(misc-unconventional-assign-operator, cppcoreguidelines-c-copy-assignment-signature) Attribute operator=(ObservedValueCombinatorWithGenerator const& combinator) const { @@ -203,23 +206,25 @@ namespace Nui::Attributes }; } + // NOLINTNEXTLINE(misc-unconventional-assign-operator, cppcoreguidelines-c-copy-assignment-signature) Attribute operator=(std::function func) const { return Attribute{ [name = name(), func = std::move(func)](Dom::ChildlessElement& element) { element.setProperty(name, [func](Nui::val val) { - func(val); + func(std::move(val)); globalEventContext.executeActiveEventsImmediately(); }); }, }; } + // NOLINTNEXTLINE(misc-unconventional-assign-operator, cppcoreguidelines-c-copy-assignment-signature) Attribute operator=(std::function func) const { return Attribute{ [name = name(), func = std::move(func)](Dom::ChildlessElement& element) { - element.setProperty(name, [func](Nui::val) { + element.setProperty(name, [func](Nui::val const&) { func(); globalEventContext.executeActiveEventsImmediately(); }); @@ -238,14 +243,11 @@ namespace Nui::Attributes : name_{name} {} - explicit constexpr AttributeFactory(AttributeFactory const& other) - : name_{other.name_} - {} - explicit constexpr AttributeFactory(AttributeFactory&& other) - : name_{other.name_} - {} + constexpr AttributeFactory(AttributeFactory const& other) = default; + constexpr AttributeFactory(AttributeFactory&& other) = default; AttributeFactory& operator=(AttributeFactory const&) = delete; AttributeFactory& operator=(AttributeFactory&&) = delete; + ~AttributeFactory() = default; constexpr char const* name() const { @@ -256,6 +258,7 @@ namespace Nui::Attributes requires( !IsObservedLike> && !std::invocable && !std::invocable && !Nui::Detail::IsProperty>) + // NOLINTNEXTLINE(misc-unconventional-assign-operator, cppcoreguidelines-c-copy-assignment-signature) Attribute operator=(U val) const { return Attribute{ @@ -267,6 +270,7 @@ namespace Nui::Attributes template requires(IsSharedObserved>) + // NOLINTNEXTLINE(misc-unconventional-assign-operator, cppcoreguidelines-c-copy-assignment-signature) Attribute operator=(U const& shared) const { return Attribute{ @@ -274,7 +278,7 @@ namespace Nui::Attributes if (auto shared = weak.lock(); shared) element.setAttribute(name, shared->value()); }, - [name = name(), weak = std::weak_ptr{shared}](std::weak_ptr&& element) { + [name = name(), weak = std::weak_ptr{shared}](std::weak_ptr const& element) { auto shared = weak.lock(); if (!shared) return EventContext::invalidEventId; @@ -310,6 +314,7 @@ namespace Nui::Attributes template requires(IsWeakObserved>) + // NOLINTNEXTLINE Attribute operator=(U&& val) const { auto shared = val.lock(); @@ -321,6 +326,7 @@ namespace Nui::Attributes template requires(IsObserved>) + // NOLINTNEXTLINE(misc-unconventional-assign-operator, cppcoreguidelines-c-copy-assignment-signature) Attribute operator=(U& val) const { return Attribute{ @@ -339,6 +345,7 @@ namespace Nui::Attributes template requires(IsObserved>) + // NOLINTNEXTLINE(misc-unconventional-assign-operator, cppcoreguidelines-c-copy-assignment-signature) Attribute operator=(Nui::Detail::Property const& prop) const { return Attribute{ @@ -357,6 +364,7 @@ namespace Nui::Attributes template requires(IsWeakObserved>) + // NOLINTNEXTLINE(misc-unconventional-assign-operator, cppcoreguidelines-c-copy-assignment-signature) Attribute operator=(Nui::Detail::Property const& prop) const { auto shared = prop.prop.lock(); @@ -368,7 +376,7 @@ namespace Nui::Attributes if (auto shared = weak.lock(); shared) element.setProperty(name, shared->value()); }, - [name = name(), weak = std::weak_ptr{shared}](std::weak_ptr&& element) { + [name = name(), weak = std::weak_ptr{shared}](std::weak_ptr const& element) { auto shared = weak.lock(); if (!shared) return EventContext::invalidEventId; @@ -404,6 +412,7 @@ namespace Nui::Attributes template requires(!IsObservedLike> && !std::invocable && !std::invocable) + // NOLINTNEXTLINE(misc-unconventional-assign-operator, cppcoreguidelines-c-copy-assignment-signature) Attribute operator=(Nui::Detail::Property const& prop) const { return Attribute{[name = name(), p = std::move(prop.prop)](Dom::ChildlessElement& element) { @@ -412,6 +421,7 @@ namespace Nui::Attributes } template + // NOLINTNEXTLINE(misc-unconventional-assign-operator, cppcoreguidelines-c-copy-assignment-signature) Attribute operator=(ObservedValueCombinatorWithPropertyGenerator const& combinator) const { @@ -429,6 +439,7 @@ namespace Nui::Attributes } template + // NOLINTNEXTLINE(misc-unconventional-assign-operator, cppcoreguidelines-c-copy-assignment-signature) Attribute operator=(ObservedValueCombinatorWithGenerator const& combinator) const { @@ -445,23 +456,25 @@ namespace Nui::Attributes }; } + // NOLINTNEXTLINE(misc-unconventional-assign-operator, cppcoreguidelines-c-copy-assignment-signature) Attribute operator=(std::function func) const { return Attribute{ [name = name(), func = std::move(func)](Dom::ChildlessElement& element) { element.setAttribute(name, [func](Nui::val val) { - func(val); + func(std::move(val)); globalEventContext.executeActiveEventsImmediately(); }); }, }; } + // NOLINTNEXTLINE(misc-unconventional-assign-operator, cppcoreguidelines-c-copy-assignment-signature) Attribute operator=(std::function func) const { return Attribute{ [name = name(), func = std::move(func)](Dom::ChildlessElement& element) { - element.setAttribute(name, [func](Nui::val) { + element.setAttribute(name, [func](Nui::val const&) { func(); globalEventContext.executeActiveEventsImmediately(); }); @@ -469,23 +482,25 @@ namespace Nui::Attributes }; } + // NOLINTNEXTLINE(misc-unconventional-assign-operator, cppcoreguidelines-c-copy-assignment-signature) Attribute operator=(Nui::Detail::Property> func) const { return Attribute{ [name = name(), func = std::move(func.prop)](Dom::ChildlessElement& element) { element.setProperty(name, [func](Nui::val val) { - func(val); + func(std::move(val)); globalEventContext.executeActiveEventsImmediately(); }); }, }; } + // NOLINTNEXTLINE(misc-unconventional-assign-operator, cppcoreguidelines-c-copy-assignment-signature) Attribute operator=(Nui::Detail::Property> func) const { return Attribute{ [name = name(), func = std::move(func.prop)](Dom::ChildlessElement& element) { - element.setProperty(name, [func](Nui::val) { + element.setProperty(name, [func](Nui::val const&) { func(); globalEventContext.executeActiveEventsImmediately(); }); @@ -504,25 +519,23 @@ namespace Nui::Attributes : name_{name} {} - explicit constexpr EventFactory(EventFactory const& other) - : name_{other.name_} - {} - explicit constexpr EventFactory(EventFactory&& other) - : name_{other.name_} - {} + constexpr EventFactory(EventFactory const& other) = default; + constexpr EventFactory(EventFactory&& other) = default; EventFactory& operator=(EventFactory const&) = delete; EventFactory& operator=(EventFactory&&) = delete; + ~EventFactory() = default; constexpr char const* name() const { return name_; }; + // NOLINTNEXTLINE(misc-unconventional-assign-operator, cppcoreguidelines-c-copy-assignment-signature) Attribute operator=(std::function func) const { return Attribute{ [name = name(), func = std::move(func)](Dom::ChildlessElement& element) { - element.addEventListener(name, [func](Nui::val) { + element.addEventListener(name, [func](Nui::val const&) { func(); globalEventContext.executeActiveEventsImmediately(); }); @@ -530,6 +543,7 @@ namespace Nui::Attributes }; } + // NOLINTNEXTLINE(misc-unconventional-assign-operator, cppcoreguidelines-c-copy-assignment-signature) Attribute operator=(std::function func) const { return Attribute{ @@ -570,6 +584,7 @@ namespace Nui::Attributes T factory; template + // NOLINTNEXTLINE(misc-unconventional-assign-operator, cppcoreguidelines-c-copy-assignment-signature) Attribute operator=(Args&&... args) const { auto attr = factory.operator=(std::forward(args)...); @@ -588,6 +603,7 @@ namespace Nui::Attributes } } +// NOLINTBEGIN #define MAKE_HTML_VALUE_ATTRIBUTE_RENAME(NAME, HTML_NAME) \ namespace Nui::Attributes \ { \ @@ -605,5 +621,6 @@ namespace Nui::Attributes } \ static constexpr auto NAME = AttributeFactory{Names::Attr##NAME}; \ } +// NOLINTEND #define MAKE_HTML_EVENT_ATTRIBUTE(NAME) MAKE_HTML_EVENT_ATTRIBUTE_RENAME(NAME, #NAME) \ No newline at end of file From 60c0eea745c903f594bd93acb706a9e802f93451 Mon Sep 17 00:00:00 2001 From: Tim Ebbeke Date: Tue, 26 Nov 2024 23:18:50 +0100 Subject: [PATCH 16/19] Tidy throttle source. --- nui/src/nui/frontend/api/throttle.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/nui/src/nui/frontend/api/throttle.cpp b/nui/src/nui/frontend/api/throttle.cpp index db251e6..0e22c5c 100644 --- a/nui/src/nui/frontend/api/throttle.cpp +++ b/nui/src/nui/frontend/api/throttle.cpp @@ -27,14 +27,15 @@ namespace Nui } } //--------------------------------------------------------------------------------------------------------------------- - ThrottledFunction::ThrottledFunction(ThrottledFunction&& other) + ThrottledFunction::ThrottledFunction(ThrottledFunction&& other) noexcept : id_(other.id_) + , calledWhenReady_{other.calledWhenReady_} , func_(std::move(other.func_)) { other.id_ = -1; } //--------------------------------------------------------------------------------------------------------------------- - ThrottledFunction& ThrottledFunction::operator=(ThrottledFunction&& other) + ThrottledFunction& ThrottledFunction::operator=(ThrottledFunction&& other) noexcept { id_ = other.id_; func_ = std::move(other.func_); From 26f9217af6466abd08f3bb8172334f7ab89cc6a1 Mon Sep 17 00:00:00 2001 From: Tim Ebbeke Date: Tue, 26 Nov 2024 23:18:59 +0100 Subject: [PATCH 17/19] Tidy timer source. --- nui/src/nui/frontend/api/timer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nui/src/nui/frontend/api/timer.cpp b/nui/src/nui/frontend/api/timer.cpp index f176c9e..feab49e 100644 --- a/nui/src/nui/frontend/api/timer.cpp +++ b/nui/src/nui/frontend/api/timer.cpp @@ -18,13 +18,13 @@ namespace Nui stop(); } //--------------------------------------------------------------------------------------------------------------------- - TimerHandle::TimerHandle(TimerHandle&& other) + TimerHandle::TimerHandle(TimerHandle&& other) noexcept : id_{other.id_} { other.id_ = -1; } //--------------------------------------------------------------------------------------------------------------------- - TimerHandle& TimerHandle::operator=(TimerHandle&& other) + TimerHandle& TimerHandle::operator=(TimerHandle&& other) noexcept { id_ = other.id_; other.id_ = -1; From 6bb24c62ef31064f9e2e60eee23130ee6cb4251a Mon Sep 17 00:00:00 2001 From: Tim Ebbeke Date: Tue, 26 Nov 2024 23:21:17 +0100 Subject: [PATCH 18/19] Tidy attribute header. --- nui/include/nui/frontend/attributes/impl/attribute.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nui/include/nui/frontend/attributes/impl/attribute.hpp b/nui/include/nui/frontend/attributes/impl/attribute.hpp index 5721736..2fc3b5c 100644 --- a/nui/include/nui/frontend/attributes/impl/attribute.hpp +++ b/nui/include/nui/frontend/attributes/impl/attribute.hpp @@ -24,7 +24,7 @@ namespace Nui }; Attribute() = default; - Attribute( + explicit Attribute( std::function setter, std::function&& element)> createEvent = {}, std::function clearEvent = {}) @@ -57,6 +57,7 @@ namespace Nui Attribute(Attribute&&) = default; Attribute& operator=(Attribute const&) = default; Attribute& operator=(Attribute&&) = default; + ~Attribute() = default; void setOn(Dom::ChildlessElement& element) const; EventContext::EventIdType createEvent(std::weak_ptr&& element) const; From 68f72080ef10f1a7362a47cf3bb626bb738290f3 Mon Sep 17 00:00:00 2001 From: Tim Ebbeke Date: Tue, 26 Nov 2024 23:37:37 +0100 Subject: [PATCH 19/19] Applied more clang tidy fixes. --- .../nui/frontend/components/dialog.hpp | 9 ++-- nui/include/nui/frontend/components/table.hpp | 2 - .../nui/frontend/dom/basic_element.hpp | 7 +++ nui/include/nui/frontend/dom/dom.hpp | 2 +- nui/include/nui/frontend/dom/element.hpp | 5 +- nui/include/nui/frontend/dom/reference.hpp | 1 - .../elements/detail/fragment_context.hpp | 3 ++ .../frontend/elements/impl/html_element.tpp | 4 +- .../frontend/elements/impl/materialize.hpp | 5 ++ .../filesystem/file_dialog_options.cpp | 53 ++++++++++--------- 10 files changed, 53 insertions(+), 38 deletions(-) diff --git a/nui/include/nui/frontend/components/dialog.hpp b/nui/include/nui/frontend/components/dialog.hpp index fd47b1a..2bd48ef 100644 --- a/nui/include/nui/frontend/components/dialog.hpp +++ b/nui/include/nui/frontend/components/dialog.hpp @@ -2,7 +2,6 @@ #include #include -#include #include #include @@ -33,9 +32,9 @@ namespace Nui::Components struct ConstructionArgs { std::optional className{std::nullopt}; - std::string title{""}; - std::string body{""}; - std::string buttonClassName{""}; + std::string title{}; + std::string body{}; + std::string buttonClassName{}; ButtonConfiguration buttonConfiguration{ButtonConfiguration::Ok}; std::function onButtonClicked = [](Button) {}; }; @@ -45,7 +44,7 @@ namespace Nui::Components * * @param args The intial values for the dialog. */ - DialogController(ConstructionArgs&& args); + explicit DialogController(ConstructionArgs&& args); /** * @brief Shows the dialog as a modal dialog (blocks the UI). diff --git a/nui/include/nui/frontend/components/table.hpp b/nui/include/nui/frontend/components/table.hpp index 6e2c639..9b38a6b 100644 --- a/nui/include/nui/frontend/components/table.hpp +++ b/nui/include/nui/frontend/components/table.hpp @@ -10,9 +10,7 @@ #include #include -#include #include -#include #include namespace Nui::Components diff --git a/nui/include/nui/frontend/dom/basic_element.hpp b/nui/include/nui/frontend/dom/basic_element.hpp index 4a11aca..691068e 100644 --- a/nui/include/nui/frontend/dom/basic_element.hpp +++ b/nui/include/nui/frontend/dom/basic_element.hpp @@ -17,6 +17,10 @@ namespace Nui::Dom : element_{std::move(val)} {} virtual ~BasicElement() = default; + BasicElement(BasicElement const&) = default; + BasicElement(BasicElement&&) noexcept = default; + BasicElement& operator=(BasicElement const&) = default; + BasicElement& operator=(BasicElement&&) noexcept = default; Nui::val const& val() const { @@ -26,14 +30,17 @@ namespace Nui::Dom { return element_; } + // NOLINTNEXTLINE(hicpp-explicit-conversions) operator Nui::val const&() const { return element_; } + // NOLINTNEXTLINE(hicpp-explicit-conversions) operator Nui::val&() { return element_; } + // NOLINTNEXTLINE(hicpp-explicit-conversions) operator Nui::val&&() && { return std::move(element_); diff --git a/nui/include/nui/frontend/dom/dom.hpp b/nui/include/nui/frontend/dom/dom.hpp index 8e5bf4f..2824674 100644 --- a/nui/include/nui/frontend/dom/dom.hpp +++ b/nui/include/nui/frontend/dom/dom.hpp @@ -4,7 +4,7 @@ #include #include -#include +#include namespace Nui::Dom { diff --git a/nui/include/nui/frontend/dom/element.hpp b/nui/include/nui/frontend/dom/element.hpp index 15a572e..c105296 100644 --- a/nui/include/nui/frontend/dom/element.hpp +++ b/nui/include/nui/frontend/dom/element.hpp @@ -78,7 +78,7 @@ namespace Nui::Dom Element& operator=(Element const&) = delete; Element& operator=(Element&&) = delete; - ~Element() + ~Element() override { clearChildren(); destroy_(element_); @@ -277,8 +277,7 @@ namespace Nui::Dom { if (where >= children_.size()) return appendElement(element); - else - return insert(begin() + static_cast(where), element); + return insert(begin() + static_cast(where), element); } auto& operator[](std::size_t index) diff --git a/nui/include/nui/frontend/dom/reference.hpp b/nui/include/nui/frontend/dom/reference.hpp index a36eab5..e46f460 100644 --- a/nui/include/nui/frontend/dom/reference.hpp +++ b/nui/include/nui/frontend/dom/reference.hpp @@ -2,7 +2,6 @@ #include -#include #include #include #include diff --git a/nui/include/nui/frontend/elements/detail/fragment_context.hpp b/nui/include/nui/frontend/elements/detail/fragment_context.hpp index 3f210cd..5a21a46 100644 --- a/nui/include/nui/frontend/elements/detail/fragment_context.hpp +++ b/nui/include/nui/frontend/elements/detail/fragment_context.hpp @@ -1,5 +1,8 @@ #pragma once +#include +#include + namespace Nui::Detail { template diff --git a/nui/include/nui/frontend/elements/impl/html_element.tpp b/nui/include/nui/frontend/elements/impl/html_element.tpp index d072be9..3a949e6 100644 --- a/nui/include/nui/frontend/elements/impl/html_element.tpp +++ b/nui/include/nui/frontend/elements/impl/html_element.tpp @@ -36,6 +36,7 @@ namespace Nui } } +// NOLINTBEGIN #define NUI_MAKE_HTML_ELEMENT_RENAME(NAME, HTML_ACTUAL) \ struct NAME : ::Nui::HtmlElement \ { \ @@ -61,4 +62,5 @@ namespace Nui NUI_MAKE_HTML_ELEMENT_RENAME(NAME, HTML_ACTUAL) \ } -#define NUI_DECLARE_HTML_ELEMENT(NAME) NUI_DECLARE_HTML_ELEMENT_RENAME(NAME, #NAME) \ No newline at end of file +#define NUI_DECLARE_HTML_ELEMENT(NAME) NUI_DECLARE_HTML_ELEMENT_RENAME(NAME, #NAME) +// NOLINTEND \ No newline at end of file diff --git a/nui/include/nui/frontend/elements/impl/materialize.hpp b/nui/include/nui/frontend/elements/impl/materialize.hpp index 8fd19fc..89bea76 100644 --- a/nui/include/nui/frontend/elements/impl/materialize.hpp +++ b/nui/include/nui/frontend/elements/impl/materialize.hpp @@ -1,3 +1,8 @@ +#include + +#include +#include + namespace Nui { class HtmlElement; diff --git a/nui/src/nui/backend/filesystem/file_dialog_options.cpp b/nui/src/nui/backend/filesystem/file_dialog_options.cpp index 6b556a1..ae7a4dd 100644 --- a/nui/src/nui/backend/filesystem/file_dialog_options.cpp +++ b/nui/src/nui/backend/filesystem/file_dialog_options.cpp @@ -2,33 +2,36 @@ namespace Nui::FileDialog { - //##################################################################################################################### - template - void to_json_common(nlohmann::json& json, T const& options) + // ##################################################################################################################### + namespace { - if (options.title) - json["title"] = *options.title; - if (options.defaultPath) - json["defaultPath"] = options.defaultPath->string(); - json["filters"] = options.filters; - json["forcePath"] = options.forcePath; - } - //--------------------------------------------------------------------------------------------------------------------- - template - void from_json_common(nlohmann::json const& json, T& options) - { - if (json.contains("title")) - options.title = json["title"].get(); - else - options.title = std::nullopt; + template + void to_json_common(nlohmann::json& json, T const& options) + { + if (options.title) + json["title"] = *options.title; + if (options.defaultPath) + json["defaultPath"] = options.defaultPath->string(); + json["filters"] = options.filters; + json["forcePath"] = options.forcePath; + } + //--------------------------------------------------------------------------------------------------------------------- + template + void from_json_common(nlohmann::json const& json, T& options) + { + if (json.contains("title")) + options.title = json["title"].get(); + else + options.title = std::nullopt; - if (json.contains("defaultPath")) - options.defaultPath = json["defaultPath"].get(); - else - options.defaultPath = std::nullopt; + if (json.contains("defaultPath")) + options.defaultPath = json["defaultPath"].get(); + else + options.defaultPath = std::nullopt; - json.at("filters").get_to(options.filters); - json.at("forcePath").get_to(options.forcePath); + json.at("filters").get_to(options.filters); + json.at("forcePath").get_to(options.forcePath); + } } //--------------------------------------------------------------------------------------------------------------------- void to_json(nlohmann::json& json, OpenDialogOptions const& options) @@ -64,5 +67,5 @@ namespace Nui::FileDialog from_json_common(json, options); options.forceOverwrite = json["forceOverwrite"].get(); } - //##################################################################################################################### + // ##################################################################################################################### } \ No newline at end of file