From 206dc4a974ff4a75d2b2b42c9942dd407b9d9745 Mon Sep 17 00:00:00 2001 From: Johan Mabille Date: Wed, 29 May 2024 15:15:53 +0200 Subject: [PATCH 1/6] Replaced xtl::any with std::any --- include/xwidgets/xholder.hpp | 26 +++++++++++++------------- src/xholder.cpp | 4 ++-- src/xholder_id.cpp | 4 ++-- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/include/xwidgets/xholder.hpp b/include/xwidgets/xholder.hpp index 7c996b6..f7b503d 100644 --- a/include/xwidgets/xholder.hpp +++ b/include/xwidgets/xholder.hpp @@ -9,6 +9,7 @@ #ifndef XWIDGETS_HOLDER_HPP #define XWIDGETS_HOLDER_HPP +#include #include #include #include @@ -17,7 +18,6 @@ #include #include #include -#include #include #include "xbinary.hpp" @@ -74,8 +74,8 @@ namespace xw void serialize_state(nl::json& state, xeus::buffer_sequence& buffers) const; const std::vector& buffer_paths() const; - xtl::any value() &; - const xtl::any value() const&; + std::any value() &; + const std::any value() const&; template D& get() &; @@ -139,8 +139,8 @@ namespace xw virtual void serialize_state(nl::json& state, xeus::buffer_sequence& buffers) const = 0; virtual const std::vector& buffer_paths() const = 0; - virtual xtl::any value() & = 0; - virtual const xtl::any value() const& = 0; + virtual std::any value() & = 0; + virtual const std::any value() const& = 0; protected: @@ -196,12 +196,12 @@ namespace xw return m_value.buffer_paths(); } - xtl::any value() & override + std::any value() & override { return xtl::closure(m_value); } - const xtl::any value() const& override + const std::any value() const& override { return xtl::closure(m_value); } @@ -259,12 +259,12 @@ namespace xw return p_value->buffer_paths(); } - xtl::any value() & override + std::any value() & override { return xtl::closure(*p_value); } - const xtl::any value() const& override + const std::any value() const& override { return xtl::closure(*p_value); } @@ -326,12 +326,12 @@ namespace xw return p_value->buffer_paths(); } - xtl::any value() & override + std::any value() & override { return xtl::closure(*p_value); } - const xtl::any value() const& override + const std::any value() const& override { return xtl::closure(*p_value); } @@ -413,13 +413,13 @@ namespace xw template D& xholder::get() & { - return xtl::any_cast>(this->value()).get(); + return std::any_cast>(this->value()).get(); } template const D& xholder::get() const& { - return xtl::any_cast>(this->value()).get(); + return std::any_cast>(this->value()).get(); } } diff --git a/src/xholder.cpp b/src/xholder.cpp index db7335a..bc6cba3 100644 --- a/src/xholder.cpp +++ b/src/xholder.cpp @@ -76,13 +76,13 @@ namespace xw return p_holder->buffer_paths(); } - xtl::any xholder::value() & + std::any xholder::value() & { check_holder(); return p_holder->value(); } - const xtl::any xholder::value() const& + const std::any xholder::value() const& { check_holder(); return p_holder->value(); diff --git a/src/xholder_id.cpp b/src/xholder_id.cpp index 83a4728..ec13765 100644 --- a/src/xholder_id.cpp +++ b/src/xholder_id.cpp @@ -59,12 +59,12 @@ namespace xw return get_transport_registry().find(m_id).buffer_paths(); } - xtl::any value() & override + std::any value() & override { return get_transport_registry().find(m_id).value(); } - const xtl::any value() const& override + const std::any value() const& override { return get_transport_registry().find(m_id).value(); } From 3479ba0b9b0bf1762acd05c6aa4fcb168b0a3e87 Mon Sep 17 00:00:00 2001 From: Johan Mabille Date: Wed, 29 May 2024 18:00:09 +0200 Subject: [PATCH 2/6] Replaced xoptional with std::optional --- include/xwidgets/xbutton.hpp | 20 +++--- include/xwidgets/xcheckbox.hpp | 5 +- include/xwidgets/xcommon.hpp | 5 +- include/xwidgets/xeither.hpp | 7 +- include/xwidgets/xhtml.hpp | 9 ++- include/xwidgets/xjson.hpp | 48 ++++++++++++++ include/xwidgets/xlabel.hpp | 19 +++--- include/xwidgets/xlayout.hpp | 79 ++++++++++++----------- include/xwidgets/xobject.hpp | 14 ++-- include/xwidgets/xprogress.hpp | 5 +- include/xwidgets/xselection_container.hpp | 4 +- include/xwidgets/xslider.hpp | 5 +- include/xwidgets/xtext.hpp | 6 +- include/xwidgets/xtextarea.hpp | 4 +- include/xwidgets/xtogglebutton.hpp | 17 +++-- include/xwidgets/xwidget.hpp | 7 +- src/xcommon.cpp | 7 +- 17 files changed, 151 insertions(+), 110 deletions(-) create mode 100644 include/xwidgets/xjson.hpp diff --git a/include/xwidgets/xbutton.hpp b/include/xwidgets/xbutton.hpp index 5faba5f..ccfcf9f 100644 --- a/include/xwidgets/xbutton.hpp +++ b/include/xwidgets/xbutton.hpp @@ -11,11 +11,9 @@ #include #include +#include #include #include -#include - -#include #include "xcolor.hpp" #include "xeither.hpp" @@ -40,14 +38,14 @@ namespace xw void serialize_state(nl::json&, xeus::buffer_sequence&) const; void apply_patch(const nl::json&, const xeus::buffer_sequence&); - XPROPERTY(xtl::xoptional, derived_type, button_color); - XPROPERTY(xtl::xoptional, derived_type, font_family); - XPROPERTY(xtl::xoptional, derived_type, font_size); - XPROPERTY(xtl::xoptional, derived_type, font_style); - XPROPERTY(xtl::xoptional, derived_type, font_variant); - XPROPERTY(xtl::xoptional, derived_type, font_weight); - XPROPERTY(xtl::xoptional, derived_type, text_color); - XPROPERTY(xtl::xoptional, derived_type, text_decoration); + XPROPERTY(std::optional, derived_type, button_color); + XPROPERTY(std::optional, derived_type, font_family); + XPROPERTY(std::optional, derived_type, font_size); + XPROPERTY(std::optional, derived_type, font_style); + XPROPERTY(std::optional, derived_type, font_variant); + XPROPERTY(std::optional, derived_type, font_weight); + XPROPERTY(std::optional, derived_type, text_color); + XPROPERTY(std::optional, derived_type, text_decoration); protected: diff --git a/include/xwidgets/xcheckbox.hpp b/include/xwidgets/xcheckbox.hpp index 58c2690..95bfe3b 100644 --- a/include/xwidgets/xcheckbox.hpp +++ b/include/xwidgets/xcheckbox.hpp @@ -9,10 +9,9 @@ #ifndef XWIDGETS_CHECKBOX_HPP #define XWIDGETS_CHECKBOX_HPP +#include #include -#include - #include "xboolean.hpp" #include "xmaterialize.hpp" #include "xstyle.hpp" @@ -34,7 +33,7 @@ namespace xw void serialize_state(nl::json&, xeus::buffer_sequence&) const; void apply_patch(const nl::json&, const xeus::buffer_sequence&); - XPROPERTY(xtl::xoptional, derived_type, background); + XPROPERTY(std::optional, derived_type, background); XPROPERTY(std::string, derived_type, description_width); protected: diff --git a/include/xwidgets/xcommon.hpp b/include/xwidgets/xcommon.hpp index 5b89ebd..b4d2cee 100644 --- a/include/xwidgets/xcommon.hpp +++ b/include/xwidgets/xcommon.hpp @@ -9,14 +9,15 @@ #ifndef XWIDGETS_COMMON_HPP #define XWIDGETS_COMMON_HPP +#include #include #include #include #include -#include #include "xbinary.hpp" +#include "xjson.hpp" #include "xwidgets_config.hpp" namespace xw @@ -92,7 +93,7 @@ namespace xw * * If the optional is empty, then no setting is set explicitly. */ - static xtl::xoptional global_echo_update(); + static std::optional global_echo_update(); bool same_patch(const std::string&, const nl::json&, const xeus::buffer_sequence&, const nl::json&, const xeus::buffer_sequence&) diff --git a/include/xwidgets/xeither.hpp b/include/xwidgets/xeither.hpp index 42da7e1..3c5ad86 100644 --- a/include/xwidgets/xeither.hpp +++ b/include/xwidgets/xeither.hpp @@ -9,12 +9,11 @@ #ifndef XWIDGETS_EITHER_HPP #define XWIDGETS_EITHER_HPP +#include #include #include #include -#include "xtl/xoptional.hpp" - template auto XEITHER(T... vals) { @@ -35,9 +34,9 @@ auto XEITHER_OPTIONAL(T... vals) const std::unordered_set options({vals...}); return [options](const auto& proposal) { - if (xtl::has_value(proposal)) + if (proposal.has_value()) { - auto position = options.find(xtl::value(proposal)); + auto position = options.find(proposal.value()); if (position == options.end()) { throw std::runtime_error("Invalid proposal for optional string enum"); diff --git a/include/xwidgets/xhtml.hpp b/include/xwidgets/xhtml.hpp index 94ba84b..9785857 100644 --- a/include/xwidgets/xhtml.hpp +++ b/include/xwidgets/xhtml.hpp @@ -9,10 +9,9 @@ #ifndef XWIDGETS_HTML_HPP #define XWIDGETS_HTML_HPP +#include #include -#include - #include "xmaterialize.hpp" #include "xstring.hpp" #include "xstyle.hpp" @@ -34,10 +33,10 @@ namespace xw void serialize_state(nl::json&, xeus::buffer_sequence&) const; void apply_patch(const nl::json&, const xeus::buffer_sequence&); - XPROPERTY(xtl::xoptional, derived_type, background); + XPROPERTY(std::optional, derived_type, background); XPROPERTY(std::string, derived_type, description_width); - XPROPERTY(xtl::xoptional, derived_type, font_size); - XPROPERTY(xtl::xoptional, derived_type, text_color); + XPROPERTY(std::optional, derived_type, font_size); + XPROPERTY(std::optional, derived_type, text_color); protected: diff --git a/include/xwidgets/xjson.hpp b/include/xwidgets/xjson.hpp new file mode 100644 index 0000000..f5de796 --- /dev/null +++ b/include/xwidgets/xjson.hpp @@ -0,0 +1,48 @@ +/*************************************************************************** + * Copyright (c) 2024, QuantStack * + * * + * Distributed under the terms of the BSD 3-Clause License. * + * * + * The full license is in the file LICENSE, distributed with this software. * + ****************************************************************************/ + +#ifndef XWIDGETS_JSON_HPP +#define XWIDGETS_JSON_HPP + +#include + +#include + +namespace nlohmann +{ + template + struct adl_serializer> + { + static void to_json(nlohmann::json& j, const std::optional& o) + { + if (!o.has_value()) + { + j = nullptr; + } + else + { + j = o.value(); + } + } + + static void from_json(const nlohmann::json& j, std::optional& o) + { + if (j.is_null()) + { + o = std::nullopt; + } + else + { + o = j.get(); + } + } + }; +} + +#endif + diff --git a/include/xwidgets/xlabel.hpp b/include/xwidgets/xlabel.hpp index a05b8af..34b6147 100644 --- a/include/xwidgets/xlabel.hpp +++ b/include/xwidgets/xlabel.hpp @@ -9,10 +9,9 @@ #ifndef XWIDGETS_LABEL_HPP #define XWIDGETS_LABEL_HPP +#include #include -#include - #include "xmaterialize.hpp" #include "xstring.hpp" #include "xstyle.hpp" @@ -35,15 +34,15 @@ namespace xw void serialize_state(nl::json&, xeus::buffer_sequence&) const; void apply_patch(const nl::json&, const xeus::buffer_sequence&); - XPROPERTY(xtl::xoptional, derived_type, background); + XPROPERTY(std::optional, derived_type, background); XPROPERTY(std::string, derived_type, description_width); - XPROPERTY(xtl::xoptional, derived_type, font_family); - XPROPERTY(xtl::xoptional, derived_type, font_size); - XPROPERTY(xtl::xoptional, derived_type, font_style); - XPROPERTY(xtl::xoptional, derived_type, font_variant); - XPROPERTY(xtl::xoptional, derived_type, font_weight); - XPROPERTY(xtl::xoptional, derived_type, text_color); - XPROPERTY(xtl::xoptional, derived_type, text_decoration); + XPROPERTY(std::optional, derived_type, font_family); + XPROPERTY(std::optional, derived_type, font_size); + XPROPERTY(std::optional, derived_type, font_style); + XPROPERTY(std::optional, derived_type, font_variant); + XPROPERTY(std::optional, derived_type, font_weight); + XPROPERTY(std::optional, derived_type, text_color); + XPROPERTY(std::optional, derived_type, text_decoration); protected: diff --git a/include/xwidgets/xlayout.hpp b/include/xwidgets/xlayout.hpp index 2336729..3d0ef7d 100644 --- a/include/xwidgets/xlayout.hpp +++ b/include/xwidgets/xlayout.hpp @@ -9,6 +9,7 @@ #ifndef XWIDGETS_LAYOUT_HPP #define XWIDGETS_LAYOUT_HPP +#include #include #include "xeither.hpp" @@ -33,7 +34,7 @@ namespace xw void apply_patch(const nl::json&, const xeus::buffer_sequence&); XPROPERTY( - xtl::xoptional, + std::optional, derived_type, align_content, {}, @@ -51,91 +52,91 @@ namespace xw ) ); XPROPERTY( - xtl::xoptional, + std::optional, derived_type, align_items, {}, XEITHER_OPTIONAL("flex-start", "flex-end", "center", "baseline", "stretch", "inherit", "inital", "unset") ); XPROPERTY( - xtl::xoptional, + std::optional, derived_type, align_self, {}, XEITHER_OPTIONAL("auto", "flex-start", "flex-end", "center", "baseline", "stretch", "inherit", "inital", "unset") ); - XPROPERTY(xtl::xoptional, derived_type, border_bottom); - XPROPERTY(xtl::xoptional, derived_type, border_left); - XPROPERTY(xtl::xoptional, derived_type, border_right); - XPROPERTY(xtl::xoptional, derived_type, border_top); - XPROPERTY(xtl::xoptional, derived_type, bottom); - XPROPERTY(xtl::xoptional, derived_type, display); - XPROPERTY(xtl::xoptional, derived_type, flex); - XPROPERTY(xtl::xoptional, derived_type, flex_flow); - XPROPERTY(xtl::xoptional, derived_type, grid_area); - XPROPERTY(xtl::xoptional, derived_type, grid_auto_columns); + XPROPERTY(std::optional, derived_type, border_bottom); + XPROPERTY(std::optional, derived_type, border_left); + XPROPERTY(std::optional, derived_type, border_right); + XPROPERTY(std::optional, derived_type, border_top); + XPROPERTY(std::optional, derived_type, bottom); + XPROPERTY(std::optional, derived_type, display); + XPROPERTY(std::optional, derived_type, flex); + XPROPERTY(std::optional, derived_type, flex_flow); + XPROPERTY(std::optional, derived_type, grid_area); + XPROPERTY(std::optional, derived_type, grid_auto_columns); XPROPERTY( - xtl::xoptional, + std::optional, derived_type, grid_auto_flow, {}, XEITHER_OPTIONAL("column", "row", "row dense", "column dense", "inherit", "initial", "unset") ); - XPROPERTY(xtl::xoptional, derived_type, grid_auto_rows); - XPROPERTY(xtl::xoptional, derived_type, grid_column); - XPROPERTY(xtl::xoptional, derived_type, grid_gap); - XPROPERTY(xtl::xoptional, derived_type, grid_row); - XPROPERTY(xtl::xoptional, derived_type, grid_template_areas); - XPROPERTY(xtl::xoptional, derived_type, grid_template_columns); - XPROPERTY(xtl::xoptional, derived_type, grid_template_rows); - XPROPERTY(xtl::xoptional, derived_type, height); + XPROPERTY(std::optional, derived_type, grid_auto_rows); + XPROPERTY(std::optional, derived_type, grid_column); + XPROPERTY(std::optional, derived_type, grid_gap); + XPROPERTY(std::optional, derived_type, grid_row); + XPROPERTY(std::optional, derived_type, grid_template_areas); + XPROPERTY(std::optional, derived_type, grid_template_columns); + XPROPERTY(std::optional, derived_type, grid_template_rows); + XPROPERTY(std::optional, derived_type, height); XPROPERTY( - xtl::xoptional, + std::optional, derived_type, justify_content, {}, XEITHER_OPTIONAL("flex-start", "flex-end", "center", "space-between", "space-around", "inherit", "inital", "unset") ); XPROPERTY( - xtl::xoptional, + std::optional, derived_type, justify_items, {}, XEITHER_OPTIONAL("flex-start", "flex-end", "center", "inherit", "initial", "unset") ); - XPROPERTY(xtl::xoptional, derived_type, left); - XPROPERTY(xtl::xoptional, derived_type, margin); - XPROPERTY(xtl::xoptional, derived_type, max_height); - XPROPERTY(xtl::xoptional, derived_type, max_width); - XPROPERTY(xtl::xoptional, derived_type, min_height); - XPROPERTY(xtl::xoptional, derived_type, min_width); + XPROPERTY(std::optional, derived_type, left); + XPROPERTY(std::optional, derived_type, margin); + XPROPERTY(std::optional, derived_type, max_height); + XPROPERTY(std::optional, derived_type, max_width); + XPROPERTY(std::optional, derived_type, min_height); + XPROPERTY(std::optional, derived_type, min_width); XPROPERTY( - xtl::xoptional, + std::optional, derived_type, object_fit, {}, XEITHER_OPTIONAL("contain", "cover", "fill", "scale-down", "none") ); - XPROPERTY(xtl::xoptional, derived_type, object_position); - XPROPERTY(xtl::xoptional, derived_type, order); + XPROPERTY(std::optional, derived_type, object_position); + XPROPERTY(std::optional, derived_type, order); XPROPERTY( - xtl::xoptional, + std::optional, derived_type, overflow, {}, XEITHER_OPTIONAL("visible", "hidden", "scroll", "auto", "inherit", "inital", "unset") ); - XPROPERTY(xtl::xoptional, derived_type, padding); - XPROPERTY(xtl::xoptional, derived_type, right); - XPROPERTY(xtl::xoptional, derived_type, top); + XPROPERTY(std::optional, derived_type, padding); + XPROPERTY(std::optional, derived_type, right); + XPROPERTY(std::optional, derived_type, top); XPROPERTY( - xtl::xoptional, + std::optional, derived_type, visibility, {}, XEITHER_OPTIONAL("visible", "hidden", "inherit", "initial", "unset") ); - XPROPERTY(xtl::xoptional, derived_type, width); + XPROPERTY(std::optional, derived_type, width); protected: diff --git a/include/xwidgets/xobject.hpp b/include/xwidgets/xobject.hpp index 0950eab..98a2c05 100644 --- a/include/xwidgets/xobject.hpp +++ b/include/xwidgets/xobject.hpp @@ -9,10 +9,10 @@ #ifndef XOBJECT_HPP #define XOBJECT_HPP +#include #include #include -#include #include "xmaterialize.hpp" #include "xtransport.hpp" @@ -36,12 +36,12 @@ namespace xw void serialize_state(nl::json&, xeus::buffer_sequence&) const; void apply_patch(const nl::json&, const xeus::buffer_sequence&); - XPROPERTY(xtl::xoptional, derived_type, _model_module, "@jupyter-widgets/base"); - XPROPERTY(xtl::xoptional, derived_type, _model_module_version, XWIDGETS_BASE_VERSION); - XPROPERTY(xtl::xoptional, derived_type, _model_name, "WidgetModel"); - XPROPERTY(xtl::xoptional, derived_type, _view_module, "@jupyter-widgets/base"); - XPROPERTY(xtl::xoptional, derived_type, _view_module_version, XWIDGETS_BASE_VERSION); - XPROPERTY(xtl::xoptional, derived_type, _view_name, "WidgetView"); + XPROPERTY(std::optional, derived_type, _model_module, "@jupyter-widgets/base"); + XPROPERTY(std::optional, derived_type, _model_module_version, XWIDGETS_BASE_VERSION); + XPROPERTY(std::optional, derived_type, _model_name, "WidgetModel"); + XPROPERTY(std::optional, derived_type, _view_module, "@jupyter-widgets/base"); + XPROPERTY(std::optional, derived_type, _view_module_version, XWIDGETS_BASE_VERSION); + XPROPERTY(std::optional, derived_type, _view_name, "WidgetView"); protected: diff --git a/include/xwidgets/xprogress.hpp b/include/xwidgets/xprogress.hpp index a78e314..a9228d6 100644 --- a/include/xwidgets/xprogress.hpp +++ b/include/xwidgets/xprogress.hpp @@ -9,11 +9,10 @@ #ifndef XWIDGETS_PROGRESS_HPP #define XWIDGETS_PROGRESS_HPP +#include #include #include -#include - #include "xcolor.hpp" #include "xeither.hpp" #include "xmaterialize.hpp" @@ -39,7 +38,7 @@ namespace xw void apply_patch(const nl::json&, const xeus::buffer_sequence&); XPROPERTY(std::string, derived_type, description_width); - XPROPERTY(xtl::xoptional, derived_type, bar_color); + XPROPERTY(std::optional, derived_type, bar_color); protected: diff --git a/include/xwidgets/xselection_container.hpp b/include/xwidgets/xselection_container.hpp index 7ca0989..07547fa 100644 --- a/include/xwidgets/xselection_container.hpp +++ b/include/xwidgets/xselection_container.hpp @@ -9,12 +9,12 @@ #ifndef XWIDGETS_SELECTION_CONTAINER_HPP #define XWIDGETS_SELECTION_CONTAINER_HPP +#include #include #include #include "xbox.hpp" #include "xmaterialize.hpp" -#include "xtl/xoptional.hpp" namespace xw { @@ -36,7 +36,7 @@ namespace xw void apply_patch(const nl::json&, const xeus::buffer_sequence&); XPROPERTY(titles_type, derived_type, titles); - XPROPERTY(xtl::xoptional, derived_type, selected_index, 0); + XPROPERTY(std::optional, derived_type, selected_index, 0); void set_title(typename titles_type::size_type i, std::string title); diff --git a/include/xwidgets/xslider.hpp b/include/xwidgets/xslider.hpp index 10a75f1..5e503d7 100644 --- a/include/xwidgets/xslider.hpp +++ b/include/xwidgets/xslider.hpp @@ -9,11 +9,10 @@ #ifndef XWIDGETS_SLIDER_HPP #define XWIDGETS_SLIDER_HPP +#include #include #include -#include - #include "xcolor.hpp" #include "xeither.hpp" #include "xmaterialize.hpp" @@ -38,7 +37,7 @@ namespace xw void apply_patch(const nl::json&, const xeus::buffer_sequence&); XPROPERTY(std::string, derived_type, description_width); - XPROPERTY(xtl::xoptional, derived_type, handle_color); + XPROPERTY(std::optional, derived_type, handle_color); protected: diff --git a/include/xwidgets/xtext.hpp b/include/xwidgets/xtext.hpp index a6b8c42..bf4eebe 100644 --- a/include/xwidgets/xtext.hpp +++ b/include/xwidgets/xtext.hpp @@ -30,10 +30,10 @@ namespace xw void serialize_state(nl::json&, xeus::buffer_sequence&) const; void apply_patch(const nl::json&, const xeus::buffer_sequence&); - XPROPERTY(xtl::xoptional, derived_type, background); + XPROPERTY(std::optional, derived_type, background); XPROPERTY(std::string, derived_type, description_width); - XPROPERTY(xtl::xoptional, derived_type, font_size); - XPROPERTY(xtl::xoptional, derived_type, text_color); + XPROPERTY(std::optional, derived_type, font_size); + XPROPERTY(std::optional, derived_type, text_color); protected: diff --git a/include/xwidgets/xtextarea.hpp b/include/xwidgets/xtextarea.hpp index 14e16d2..f4c9b85 100644 --- a/include/xwidgets/xtextarea.hpp +++ b/include/xwidgets/xtextarea.hpp @@ -9,6 +9,8 @@ #ifndef XWIDGETS_TEXTAREA_HPP #define XWIDGETS_TEXTAREA_HPP +#include + #include "xmaterialize.hpp" #include "xstring.hpp" #include "xtext.hpp" @@ -30,7 +32,7 @@ namespace xw void serialize_state(nl::json&, xeus::buffer_sequence&) const; void apply_patch(const nl::json&, const xeus::buffer_sequence&); - XPROPERTY(xtl::xoptional, derived_type, rows); + XPROPERTY(std::optional, derived_type, rows); XPROPERTY(bool, derived_type, disabled); XPROPERTY(bool, derived_type, continuous_update, true); XPROPERTY(::xw::text_style, derived_type, style); diff --git a/include/xwidgets/xtogglebutton.hpp b/include/xwidgets/xtogglebutton.hpp index e65aa1f..77d4b48 100644 --- a/include/xwidgets/xtogglebutton.hpp +++ b/include/xwidgets/xtogglebutton.hpp @@ -9,10 +9,9 @@ #ifndef XWIDGETS_TOGGLE_HPP #define XWIDGETS_TOGGLE_HPP +#include #include -#include - #include "xboolean.hpp" #include "xeither.hpp" #include "xmaterialize.hpp" @@ -36,13 +35,13 @@ namespace xw void apply_patch(const nl::json&, const xeus::buffer_sequence&); XPROPERTY(std::string, derived_type, description_width); - XPROPERTY(xtl::xoptional, derived_type, font_family); - XPROPERTY(xtl::xoptional, derived_type, font_size); - XPROPERTY(xtl::xoptional, derived_type, font_style); - XPROPERTY(xtl::xoptional, derived_type, font_variant); - XPROPERTY(xtl::xoptional, derived_type, font_weight); - XPROPERTY(xtl::xoptional, derived_type, text_color); - XPROPERTY(xtl::xoptional, derived_type, text_decoration); + XPROPERTY(std::optional, derived_type, font_family); + XPROPERTY(std::optional, derived_type, font_size); + XPROPERTY(std::optional, derived_type, font_style); + XPROPERTY(std::optional, derived_type, font_variant); + XPROPERTY(std::optional, derived_type, font_weight); + XPROPERTY(std::optional, derived_type, text_color); + XPROPERTY(std::optional, derived_type, text_decoration); protected: diff --git a/include/xwidgets/xwidget.hpp b/include/xwidgets/xwidget.hpp index d9dba80..0f20bef 100644 --- a/include/xwidgets/xwidget.hpp +++ b/include/xwidgets/xwidget.hpp @@ -9,11 +9,10 @@ #ifndef XWIDGETS_WIDGET_HPP #define XWIDGETS_WIDGET_HPP +#include #include #include -#include - #include "xlayout.hpp" #include "xobject.hpp" @@ -36,8 +35,8 @@ namespace xw XPROPERTY(std::vector, derived_type, _dom_classes); XPROPERTY(::xw::layout, derived_type, layout); - XPROPERTY(xtl::xoptional, derived_type, tabbable); - XPROPERTY(xtl::xoptional, derived_type, tooltip); + XPROPERTY(std::optional, derived_type, tabbable); + XPROPERTY(std::optional, derived_type, tooltip); protected: diff --git a/src/xcommon.cpp b/src/xcommon.cpp index 7cc5e1e..caf43c1 100644 --- a/src/xcommon.cpp +++ b/src/xcommon.cpp @@ -10,12 +10,11 @@ #include #include +#include #include #include #include -#include - #include "xeus/xinterpreter.hpp" #include "xtarget.hpp" @@ -271,7 +270,7 @@ namespace xw return std::find(falses.begin(), falses.end(), s) == falses.end(); } - xtl::xoptional get_tristate_env(const char* name) + std::optional get_tristate_env(const char* name) { const char* const val = std::getenv(name); if (val == nullptr) @@ -282,7 +281,7 @@ namespace xw } } - xtl::xoptional xcommon::global_echo_update() + std::optional xcommon::global_echo_update() { static const auto out = get_tristate_env("JUPYTER_WIDGETS_ECHO"); return out; From cb2d4e41a9a197f9efdba0ae5e860b272357b83f Mon Sep 17 00:00:00 2001 From: Johan Mabille Date: Thu, 30 May 2024 09:37:06 +0200 Subject: [PATCH 3/6] Replaced xtl::closure with std::reference_wrapper --- include/xwidgets/xcommon.hpp | 1 - include/xwidgets/xholder.hpp | 17 ++++++++--------- include/xwidgets/xobject.hpp | 3 +-- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/include/xwidgets/xcommon.hpp b/include/xwidgets/xcommon.hpp index b4d2cee..3538a52 100644 --- a/include/xwidgets/xcommon.hpp +++ b/include/xwidgets/xcommon.hpp @@ -17,7 +17,6 @@ #include #include "xbinary.hpp" -#include "xjson.hpp" #include "xwidgets_config.hpp" namespace xw diff --git a/include/xwidgets/xholder.hpp b/include/xwidgets/xholder.hpp index f7b503d..b913e3e 100644 --- a/include/xwidgets/xholder.hpp +++ b/include/xwidgets/xholder.hpp @@ -18,7 +18,6 @@ #include #include #include -#include #include "xbinary.hpp" #include "xwidgets_config.hpp" @@ -198,12 +197,12 @@ namespace xw std::any value() & override { - return xtl::closure(m_value); + return std::ref(m_value); } const std::any value() const& override { - return xtl::closure(m_value); + return std::cref(m_value); } private: @@ -261,12 +260,12 @@ namespace xw std::any value() & override { - return xtl::closure(*p_value); + return std::ref(*p_value); } const std::any value() const& override { - return xtl::closure(*p_value); + return std::cref(*p_value); } private: @@ -328,12 +327,12 @@ namespace xw std::any value() & override { - return xtl::closure(*p_value); + return std::ref(*p_value); } const std::any value() const& override { - return xtl::closure(*p_value); + return std::cref(*p_value); } private: @@ -413,13 +412,13 @@ namespace xw template D& xholder::get() & { - return std::any_cast>(this->value()).get(); + return std::any_cast>(this->value()).get(); } template const D& xholder::get() const& { - return std::any_cast>(this->value()).get(); + return std::any_cast>(this->value()).get(); } } diff --git a/include/xwidgets/xobject.hpp b/include/xwidgets/xobject.hpp index 98a2c05..baedac9 100644 --- a/include/xwidgets/xobject.hpp +++ b/include/xwidgets/xobject.hpp @@ -12,8 +12,7 @@ #include #include -#include - +#include "xjson.hpp" #include "xmaterialize.hpp" #include "xtransport.hpp" From 992b5f77d861ae12eacdc39225764164f5db3fd9 Mon Sep 17 00:00:00 2001 From: Johan Mabille Date: Thu, 30 May 2024 09:45:16 +0200 Subject: [PATCH 4/6] Removed dependency on xtl --- CMakeLists.txt | 10 ++-------- test/CMakeLists.txt | 3 +-- xwidgetsConfig.cmake.in | 1 - 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3261d2e..a40a3c2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,18 +67,14 @@ message(STATUS "xwidgets binary version: v${XWIDGETS_BINARY_VERSION}") option(XWIDGETS_BUILD_SHARED_LIBS "Build xwidgets shared library." ON) option(XWIDGETS_BUILD_STATIC_LIBS "Build xwidgets static library (default if BUILD_SHARED_LIBS is OFF)." ON) +option(XWIDGETS_BUILD_TESTS "xwidgets test suite" OFF) # Dependencies # ============ -set(xtl_REQUIRED_VERSION 0.7.0) set(xeus_REQUIRED_VERSION 5.0.0) set(xproperty_REQUIRED_VERSION 0.11.0) -if(NOT TARGET xtl) - find_package(xtl ${xtl_REQUIRED_VERSION} REQUIRED) -endif() - if(NOT TARGET xeus) find_package(xeus ${xeus_REQUIRED_VERSION} REQUIRED) endif() @@ -160,7 +156,7 @@ macro(xwidgets_create_target target_name linkage output_name) ${target_name} PUBLIC $ $ ) - target_link_libraries(${target_name} PUBLIC xtl ${XEUS_TARGET_NAME} xproperty) + target_link_libraries(${target_name} PUBLIC ${XEUS_TARGET_NAME} xproperty) set_target_properties( ${target_name} @@ -228,8 +224,6 @@ endif() # Tests ===== -option(XWIDGETS_BUILD_TESTS "xwidgets test suite" OFF) - include(CTest) if(XWIDGETS_BUILD_TESTS) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 484fc83..d090488 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -12,7 +12,6 @@ if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) project(xwidgets-test) find_package(xwidgets REQUIRED CONFIG) - find_package(xtl REQUIRED CONFIG) set(XWIDGETS_INCLUDE_DIR ${xwidgets_INCLUDE_DIRS}) endif() @@ -41,7 +40,7 @@ target_compile_definitions( target_link_libraries( test_xwidgets - PRIVATE xwidgets xtl xeus doctest::doctest nlohmann_json_schema_validator ${CMAKE_THREAD_LIBS_INIT} + PRIVATE xwidgets xeus doctest::doctest nlohmann_json_schema_validator ${CMAKE_THREAD_LIBS_INIT} ) target_include_directories(test_xwidgets PRIVATE XWIDGETS_INCLUDE_DIR) diff --git a/xwidgetsConfig.cmake.in b/xwidgetsConfig.cmake.in index 9399a1f..2e4e9fa 100644 --- a/xwidgetsConfig.cmake.in +++ b/xwidgetsConfig.cmake.in @@ -18,7 +18,6 @@ @XWIDGETS_CONFIG_CODE@ include(CMakeFindDependencyMacro) -find_dependency(xtl @xtl_REQUIRED_VERSION@) find_dependency(xeus @xeus_REQUIRED_VERSION@) find_dependency(xproperty @xproperty_REQUIRED_VERSION@) From e2bb717ef898b404d3939598b8422b21da531a9b Mon Sep 17 00:00:00 2001 From: Johan Mabille Date: Thu, 30 May 2024 09:50:29 +0200 Subject: [PATCH 5/6] Removed gtest files --- test/copyGTest.cmake.in | 22 ---------------------- test/downloadGTest.cmake.in | 23 ----------------------- 2 files changed, 45 deletions(-) delete mode 100644 test/copyGTest.cmake.in delete mode 100644 test/downloadGTest.cmake.in diff --git a/test/copyGTest.cmake.in b/test/copyGTest.cmake.in deleted file mode 100644 index aa6785a..0000000 --- a/test/copyGTest.cmake.in +++ /dev/null @@ -1,22 +0,0 @@ -############################################################################ -# Copyright (c) 2017, Sylvain Corlay, Johan Mabille, and Loic Gouarin # -# # -# Distributed under the terms of the BSD 3-Clause License. # -# # -# The full license is in the file LICENSE, distributed with this software. # -############################################################################ - -cmake_minimum_required(VERSION 2.8.2) - -project(googletest-download NONE) - -include(ExternalProject) -ExternalProject_Add(googletest - URL "${GTEST_SRC_DIR}" - SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-src" - BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-build" - CONFIGURE_COMMAND "" - BUILD_COMMAND "" - INSTALL_COMMAND "" - TEST_COMMAND "" -) diff --git a/test/downloadGTest.cmake.in b/test/downloadGTest.cmake.in deleted file mode 100644 index a03a08f..0000000 --- a/test/downloadGTest.cmake.in +++ /dev/null @@ -1,23 +0,0 @@ -############################################################################ -# Copyright (c) 2017, Sylvain Corlay, Johan Mabille, and Loic Gouarin # -# # -# Distributed under the terms of the BSD 3-Clause License. # -# # -# The full license is in the file LICENSE, distributed with this software. # -############################################################################ - -cmake_minimum_required(VERSION 2.8.2) - -project(googletest-download NONE) - -include(ExternalProject) -ExternalProject_Add(googletest - GIT_REPOSITORY https://github.com/google/googletest.git - GIT_TAG release-1.10.0 - SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-src" - BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-build" - CONFIGURE_COMMAND "" - BUILD_COMMAND "" - INSTALL_COMMAND "" - TEST_COMMAND "" -) From d7cf0446c5ab7820ee2bbd2a4bb79dce713d234c Mon Sep 17 00:00:00 2001 From: Johan Mabille Date: Fri, 31 May 2024 09:31:19 +0200 Subject: [PATCH 6/6] Upgraded to xproperty 0.12.0 --- CMakeLists.txt | 2 +- environment-dev.yml | 2 +- include/xwidgets/xjson.hpp | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a40a3c2..f9124dc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,7 +73,7 @@ option(XWIDGETS_BUILD_TESTS "xwidgets test suite" OFF) # ============ set(xeus_REQUIRED_VERSION 5.0.0) -set(xproperty_REQUIRED_VERSION 0.11.0) +set(xproperty_REQUIRED_VERSION 0.12.0) if(NOT TARGET xeus) find_package(xeus ${xeus_REQUIRED_VERSION} REQUIRED) diff --git a/environment-dev.yml b/environment-dev.yml index 1a89e1c..ef632a5 100644 --- a/environment-dev.yml +++ b/environment-dev.yml @@ -8,7 +8,7 @@ dependencies: - ninja # Host dependencies - xeus>=5.0.0,<6 -- xproperty=0.11.0 +- xproperty=0.12.0 - nlohmann_json=3.11.3 # Test dependencies - doctest >= 2.4.6 diff --git a/include/xwidgets/xjson.hpp b/include/xwidgets/xjson.hpp index f5de796..4f01902 100644 --- a/include/xwidgets/xjson.hpp +++ b/include/xwidgets/xjson.hpp @@ -45,4 +45,3 @@ namespace nlohmann } #endif -