Skip to content

Commit b8c88bf

Browse files
authored
Merge pull request #262 from JohanMabille/xtl
Xtl
2 parents 3547b9d + d7cf044 commit b8c88bf

26 files changed

+178
-194
lines changed

CMakeLists.txt

+3-9
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,13 @@ message(STATUS "xwidgets binary version: v${XWIDGETS_BINARY_VERSION}")
6767

6868
option(XWIDGETS_BUILD_SHARED_LIBS "Build xwidgets shared library." ON)
6969
option(XWIDGETS_BUILD_STATIC_LIBS "Build xwidgets static library (default if BUILD_SHARED_LIBS is OFF)." ON)
70+
option(XWIDGETS_BUILD_TESTS "xwidgets test suite" OFF)
7071

7172
# Dependencies
7273
# ============
7374

74-
set(xtl_REQUIRED_VERSION 0.7.0)
7575
set(xeus_REQUIRED_VERSION 5.0.0)
76-
set(xproperty_REQUIRED_VERSION 0.11.0)
77-
78-
if(NOT TARGET xtl)
79-
find_package(xtl ${xtl_REQUIRED_VERSION} REQUIRED)
80-
endif()
76+
set(xproperty_REQUIRED_VERSION 0.12.0)
8177

8278
if(NOT TARGET xeus)
8379
find_package(xeus ${xeus_REQUIRED_VERSION} REQUIRED)
@@ -160,7 +156,7 @@ macro(xwidgets_create_target target_name linkage output_name)
160156
${target_name} PUBLIC $<BUILD_INTERFACE:${XWIDGETS_INCLUDE_DIR}> $<INSTALL_INTERFACE:include>
161157
)
162158

163-
target_link_libraries(${target_name} PUBLIC xtl ${XEUS_TARGET_NAME} xproperty)
159+
target_link_libraries(${target_name} PUBLIC ${XEUS_TARGET_NAME} xproperty)
164160

165161
set_target_properties(
166162
${target_name}
@@ -228,8 +224,6 @@ endif()
228224

229225
# Tests =====
230226

231-
option(XWIDGETS_BUILD_TESTS "xwidgets test suite" OFF)
232-
233227
include(CTest)
234228

235229
if(XWIDGETS_BUILD_TESTS)

environment-dev.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ dependencies:
88
- ninja
99
# Host dependencies
1010
- xeus>=5.0.0,<6
11-
- xproperty=0.11.0
11+
- xproperty=0.12.0
1212
- nlohmann_json=3.11.3
1313
# Test dependencies
1414
- doctest >= 2.4.6

include/xwidgets/xbutton.hpp

+9-11
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@
1111

1212
#include <functional>
1313
#include <list>
14+
#include <optional>
1415
#include <stdexcept>
1516
#include <string>
16-
#include <utility>
17-
18-
#include <xtl/xoptional.hpp>
1917

2018
#include "xcolor.hpp"
2119
#include "xeither.hpp"
@@ -40,14 +38,14 @@ namespace xw
4038
void serialize_state(nl::json&, xeus::buffer_sequence&) const;
4139
void apply_patch(const nl::json&, const xeus::buffer_sequence&);
4240

43-
XPROPERTY(xtl::xoptional<html_color>, derived_type, button_color);
44-
XPROPERTY(xtl::xoptional<std::string>, derived_type, font_family);
45-
XPROPERTY(xtl::xoptional<std::string>, derived_type, font_size);
46-
XPROPERTY(xtl::xoptional<std::string>, derived_type, font_style);
47-
XPROPERTY(xtl::xoptional<std::string>, derived_type, font_variant);
48-
XPROPERTY(xtl::xoptional<std::string>, derived_type, font_weight);
49-
XPROPERTY(xtl::xoptional<std::string>, derived_type, text_color);
50-
XPROPERTY(xtl::xoptional<std::string>, derived_type, text_decoration);
41+
XPROPERTY(std::optional<html_color>, derived_type, button_color);
42+
XPROPERTY(std::optional<std::string>, derived_type, font_family);
43+
XPROPERTY(std::optional<std::string>, derived_type, font_size);
44+
XPROPERTY(std::optional<std::string>, derived_type, font_style);
45+
XPROPERTY(std::optional<std::string>, derived_type, font_variant);
46+
XPROPERTY(std::optional<std::string>, derived_type, font_weight);
47+
XPROPERTY(std::optional<std::string>, derived_type, text_color);
48+
XPROPERTY(std::optional<std::string>, derived_type, text_decoration);
5149

5250
protected:
5351

include/xwidgets/xcheckbox.hpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99
#ifndef XWIDGETS_CHECKBOX_HPP
1010
#define XWIDGETS_CHECKBOX_HPP
1111

12+
#include <optional>
1213
#include <string>
1314

14-
#include <xtl/xoptional.hpp>
15-
1615
#include "xboolean.hpp"
1716
#include "xmaterialize.hpp"
1817
#include "xstyle.hpp"
@@ -34,7 +33,7 @@ namespace xw
3433
void serialize_state(nl::json&, xeus::buffer_sequence&) const;
3534
void apply_patch(const nl::json&, const xeus::buffer_sequence&);
3635

37-
XPROPERTY(xtl::xoptional<std::string>, derived_type, background);
36+
XPROPERTY(std::optional<std::string>, derived_type, background);
3837
XPROPERTY(std::string, derived_type, description_width);
3938

4039
protected:

include/xwidgets/xcommon.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
#ifndef XWIDGETS_COMMON_HPP
1010
#define XWIDGETS_COMMON_HPP
1111

12+
#include <optional>
1213
#include <string>
1314
#include <utility>
1415
#include <vector>
1516

1617
#include <xeus/xcomm.hpp>
17-
#include <xtl/xoptional.hpp>
1818

1919
#include "xbinary.hpp"
2020
#include "xwidgets_config.hpp"
@@ -92,7 +92,7 @@ namespace xw
9292
*
9393
* If the optional is empty, then no setting is set explicitly.
9494
*/
95-
static xtl::xoptional<bool> global_echo_update();
95+
static std::optional<bool> global_echo_update();
9696

9797
bool
9898
same_patch(const std::string&, const nl::json&, const xeus::buffer_sequence&, const nl::json&, const xeus::buffer_sequence&)

include/xwidgets/xeither.hpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@
99
#ifndef XWIDGETS_EITHER_HPP
1010
#define XWIDGETS_EITHER_HPP
1111

12+
#include <optional>
1213
#include <stdexcept>
1314
#include <string>
1415
#include <unordered_set>
1516

16-
#include "xtl/xoptional.hpp"
17-
1817
template <typename... T>
1918
auto XEITHER(T... vals)
2019
{
@@ -35,9 +34,9 @@ auto XEITHER_OPTIONAL(T... vals)
3534
const std::unordered_set<std::string> options({vals...});
3635
return [options](const auto& proposal)
3736
{
38-
if (xtl::has_value(proposal))
37+
if (proposal.has_value())
3938
{
40-
auto position = options.find(xtl::value(proposal));
39+
auto position = options.find(proposal.value());
4140
if (position == options.end())
4241
{
4342
throw std::runtime_error("Invalid proposal for optional string enum");

include/xwidgets/xholder.hpp

+19-20
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#ifndef XWIDGETS_HOLDER_HPP
1010
#define XWIDGETS_HOLDER_HPP
1111

12+
#include <any>
1213
#include <memory>
1314
#include <stdexcept>
1415
#include <string>
@@ -17,8 +18,6 @@
1718
#include <nlohmann/json.hpp>
1819
#include <xeus/xguid.hpp>
1920
#include <xeus/xmessage.hpp>
20-
#include <xtl/xany.hpp>
21-
#include <xtl/xclosure.hpp>
2221

2322
#include "xbinary.hpp"
2423
#include "xwidgets_config.hpp"
@@ -74,8 +73,8 @@ namespace xw
7473
void serialize_state(nl::json& state, xeus::buffer_sequence& buffers) const;
7574
const std::vector<xjson_path_type>& buffer_paths() const;
7675

77-
xtl::any value() &;
78-
const xtl::any value() const&;
76+
std::any value() &;
77+
const std::any value() const&;
7978

8079
template <class D>
8180
D& get() &;
@@ -139,8 +138,8 @@ namespace xw
139138
virtual void serialize_state(nl::json& state, xeus::buffer_sequence& buffers) const = 0;
140139
virtual const std::vector<xjson_path_type>& buffer_paths() const = 0;
141140

142-
virtual xtl::any value() & = 0;
143-
virtual const xtl::any value() const& = 0;
141+
virtual std::any value() & = 0;
142+
virtual const std::any value() const& = 0;
144143

145144
protected:
146145

@@ -196,14 +195,14 @@ namespace xw
196195
return m_value.buffer_paths();
197196
}
198197

199-
xtl::any value() & override
198+
std::any value() & override
200199
{
201-
return xtl::closure(m_value);
200+
return std::ref(m_value);
202201
}
203202

204-
const xtl::any value() const& override
203+
const std::any value() const& override
205204
{
206-
return xtl::closure(m_value);
205+
return std::cref(m_value);
207206
}
208207

209208
private:
@@ -259,14 +258,14 @@ namespace xw
259258
return p_value->buffer_paths();
260259
}
261260

262-
xtl::any value() & override
261+
std::any value() & override
263262
{
264-
return xtl::closure(*p_value);
263+
return std::ref(*p_value);
265264
}
266265

267-
const xtl::any value() const& override
266+
const std::any value() const& override
268267
{
269-
return xtl::closure(*p_value);
268+
return std::cref(*p_value);
270269
}
271270

272271
private:
@@ -326,14 +325,14 @@ namespace xw
326325
return p_value->buffer_paths();
327326
}
328327

329-
xtl::any value() & override
328+
std::any value() & override
330329
{
331-
return xtl::closure(*p_value);
330+
return std::ref(*p_value);
332331
}
333332

334-
const xtl::any value() const& override
333+
const std::any value() const& override
335334
{
336-
return xtl::closure(*p_value);
335+
return std::cref(*p_value);
337336
}
338337

339338
private:
@@ -413,13 +412,13 @@ namespace xw
413412
template <class D>
414413
D& xholder::get() &
415414
{
416-
return xtl::any_cast<xtl::closure_wrapper<D&>>(this->value()).get();
415+
return std::any_cast<std::reference_wrapper<D>>(this->value()).get();
417416
}
418417

419418
template <class D>
420419
const D& xholder::get() const&
421420
{
422-
return xtl::any_cast<xtl::closure_wrapper<const D&>>(this->value()).get();
421+
return std::any_cast<std::reference_wrapper<const D>>(this->value()).get();
423422
}
424423
}
425424

include/xwidgets/xhtml.hpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99
#ifndef XWIDGETS_HTML_HPP
1010
#define XWIDGETS_HTML_HPP
1111

12+
#include <optional>
1213
#include <string>
1314

14-
#include <xtl/xoptional.hpp>
15-
1615
#include "xmaterialize.hpp"
1716
#include "xstring.hpp"
1817
#include "xstyle.hpp"
@@ -34,10 +33,10 @@ namespace xw
3433
void serialize_state(nl::json&, xeus::buffer_sequence&) const;
3534
void apply_patch(const nl::json&, const xeus::buffer_sequence&);
3635

37-
XPROPERTY(xtl::xoptional<std::string>, derived_type, background);
36+
XPROPERTY(std::optional<std::string>, derived_type, background);
3837
XPROPERTY(std::string, derived_type, description_width);
39-
XPROPERTY(xtl::xoptional<std::string>, derived_type, font_size);
40-
XPROPERTY(xtl::xoptional<std::string>, derived_type, text_color);
38+
XPROPERTY(std::optional<std::string>, derived_type, font_size);
39+
XPROPERTY(std::optional<std::string>, derived_type, text_color);
4140

4241
protected:
4342

include/xwidgets/xjson.hpp

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/***************************************************************************
2+
* Copyright (c) 2024, QuantStack *
3+
* *
4+
* Distributed under the terms of the BSD 3-Clause License. *
5+
* *
6+
* The full license is in the file LICENSE, distributed with this software. *
7+
****************************************************************************/
8+
9+
#ifndef XWIDGETS_JSON_HPP
10+
#define XWIDGETS_JSON_HPP
11+
12+
#include <optional>
13+
14+
#include <nlohmann/json.hpp>
15+
16+
namespace nlohmann
17+
{
18+
template <class T>
19+
struct adl_serializer<std::optional<T>>
20+
{
21+
static void to_json(nlohmann::json& j, const std::optional<T>& o)
22+
{
23+
if (!o.has_value())
24+
{
25+
j = nullptr;
26+
}
27+
else
28+
{
29+
j = o.value();
30+
}
31+
}
32+
33+
static void from_json(const nlohmann::json& j, std::optional<T>& o)
34+
{
35+
if (j.is_null())
36+
{
37+
o = std::nullopt;
38+
}
39+
else
40+
{
41+
o = j.get<T>();
42+
}
43+
}
44+
};
45+
}
46+
47+
#endif

include/xwidgets/xlabel.hpp

+9-10
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99
#ifndef XWIDGETS_LABEL_HPP
1010
#define XWIDGETS_LABEL_HPP
1111

12+
#include <optional>
1213
#include <string>
1314

14-
#include <xtl/xoptional.hpp>
15-
1615
#include "xmaterialize.hpp"
1716
#include "xstring.hpp"
1817
#include "xstyle.hpp"
@@ -35,15 +34,15 @@ namespace xw
3534
void serialize_state(nl::json&, xeus::buffer_sequence&) const;
3635
void apply_patch(const nl::json&, const xeus::buffer_sequence&);
3736

38-
XPROPERTY(xtl::xoptional<std::string>, derived_type, background);
37+
XPROPERTY(std::optional<std::string>, derived_type, background);
3938
XPROPERTY(std::string, derived_type, description_width);
40-
XPROPERTY(xtl::xoptional<std::string>, derived_type, font_family);
41-
XPROPERTY(xtl::xoptional<std::string>, derived_type, font_size);
42-
XPROPERTY(xtl::xoptional<std::string>, derived_type, font_style);
43-
XPROPERTY(xtl::xoptional<std::string>, derived_type, font_variant);
44-
XPROPERTY(xtl::xoptional<std::string>, derived_type, font_weight);
45-
XPROPERTY(xtl::xoptional<std::string>, derived_type, text_color);
46-
XPROPERTY(xtl::xoptional<std::string>, derived_type, text_decoration);
39+
XPROPERTY(std::optional<std::string>, derived_type, font_family);
40+
XPROPERTY(std::optional<std::string>, derived_type, font_size);
41+
XPROPERTY(std::optional<std::string>, derived_type, font_style);
42+
XPROPERTY(std::optional<std::string>, derived_type, font_variant);
43+
XPROPERTY(std::optional<std::string>, derived_type, font_weight);
44+
XPROPERTY(std::optional<std::string>, derived_type, text_color);
45+
XPROPERTY(std::optional<std::string>, derived_type, text_decoration);
4746

4847
protected:
4948

0 commit comments

Comments
 (0)