Skip to content

Commit

Permalink
Merge pull request #173 from SylvainCorlay/nl-json
Browse files Browse the repository at this point in the history
Drop xeus::xjson
  • Loading branch information
SylvainCorlay committed Jan 8, 2020
2 parents 7d1f9b4 + 10dcca9 commit a1d7c6e
Show file tree
Hide file tree
Showing 45 changed files with 313 additions and 296 deletions.
8 changes: 4 additions & 4 deletions docs/source/custom.rst
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ property of the image widget reads:
.. code::
inline void set_patch_from_property(const decltype(image::value)& property,
xeus::xjson& patch,
nl::json& patch,
xeus::buffer_sequence& buffers)
{
patch[property.name()] = xbuffer_reference_prefix() + std::to_string(buffers.size());
Expand All @@ -199,7 +199,7 @@ The default implementation of ``set_patch_from_property`` reads:
template <class P>
inline void set_patch_from_property(const P& property,
xeus::xjson& patch,
nl::json& patch,
xeus::buffer_sequence& buffers)
{
xwidgets_serialize(property(), patch[property.name()], buffers);
Expand Down Expand Up @@ -246,7 +246,7 @@ property of the image widget reads:
.. code::
inline void set_property_from_patch(decltype(image::value)& property,
const xeus::xjson& patch,
const nl::json& patch,
const xeus::buffer_sequence& buffers)
{
auto it = patch.find(property.name());
Expand Down Expand Up @@ -279,7 +279,7 @@ The default implementation of ``set_property_from_patch`` reads:
template <class P>
inline void set_property_from_patch(P& property,
const xeus::xjson& patch,
const nl::json& patch,
const xeus::buffer_sequence& buffers)
{
auto it = patch.find(property.name());
Expand Down
8 changes: 4 additions & 4 deletions include/xwidgets/xaccordion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ namespace xw
using base_type = xselection_container<D>;
using derived_type = D;

void serialize_state(xeus::xjson&, xeus::buffer_sequence&) const;
void apply_patch(const xeus::xjson&, const xeus::buffer_sequence&);
void serialize_state(nl::json&, xeus::buffer_sequence&) const;
void apply_patch(const nl::json&, const xeus::buffer_sequence&);

protected:

Expand All @@ -48,13 +48,13 @@ namespace xw
*****************************/

template <class D>
inline void xaccordion<D>::serialize_state(xeus::xjson& state, xeus::buffer_sequence& buffers) const
inline void xaccordion<D>::serialize_state(nl::json& state, xeus::buffer_sequence& buffers) const
{
base_type::serialize_state(state, buffers);
}

template <class D>
inline void xaccordion<D>::apply_patch(const xeus::xjson& patch, const xeus::buffer_sequence& buffers)
inline void xaccordion<D>::apply_patch(const nl::json& patch, const xeus::buffer_sequence& buffers)
{
base_type::apply_patch(patch, buffers);
}
Expand Down
12 changes: 6 additions & 6 deletions include/xwidgets/xaudio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ namespace xw
using base_type = xmedia<D>;
using derived_type = D;

void serialize_state(xeus::xjson& state, xeus::buffer_sequence&) const;
void apply_patch(const xeus::xjson&, const xeus::buffer_sequence&);
void serialize_state(nl::json& state, xeus::buffer_sequence&) const;
void apply_patch(const nl::json&, const xeus::buffer_sequence&);

XPROPERTY(std::string, derived_type, format, "mp4");
XPROPERTY(bool, derived_type, autoplay, true);
Expand All @@ -57,7 +57,7 @@ namespace xw
*************************/

template <class D>
inline void xaudio<D>::serialize_state(xeus::xjson& state, xeus::buffer_sequence& buffers) const
inline void xaudio<D>::serialize_state(nl::json& state, xeus::buffer_sequence& buffers) const
{
base_type::serialize_state(state, buffers);

Expand All @@ -68,7 +68,7 @@ namespace xw
}

template <class D>
inline void xaudio<D>::apply_patch(const xeus::xjson& patch, const xeus::buffer_sequence& buffers)
inline void xaudio<D>::apply_patch(const nl::json& patch, const xeus::buffer_sequence& buffers)
{
base_type::apply_patch(patch, buffers);

Expand Down Expand Up @@ -97,15 +97,15 @@ namespace xw
**********************/

inline void set_patch_from_property(const decltype(audio::value)& property,
xeus::xjson& patch,
nl::json& patch,
xeus::buffer_sequence& buffers)
{
patch[property.name()] = xbuffer_reference_prefix() + std::to_string(buffers.size());
buffers.emplace_back(property().data(), property().size());
}

inline void set_property_from_patch(decltype(audio::value)& property,
const xeus::xjson& patch,
const nl::json& patch,
const xeus::buffer_sequence& buffers)
{
auto it = patch.find(property.name());
Expand Down
43 changes: 23 additions & 20 deletions include/xwidgets/xbinary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
#include <string>
#include <vector>

#include "xeus/xjson.hpp"
#include "nlohmann/json.hpp"

#include "xeus/xmessage.hpp"

namespace nl = nlohmann;

namespace xw
{
/****************
Expand All @@ -26,12 +29,12 @@ namespace xw
using xjson_path_type = std::vector<std::string>;

void extract_buffer_paths(const std::vector<xjson_path_type>& to_check,
const xeus::xjson& patch,
const nl::json& patch,
const xeus::buffer_sequence& buffers,
xeus::xjson& buffer_paths);
nl::json& buffer_paths);

void insert_buffer_paths(xeus::xjson& patch,
const xeus::xjson& buffer_paths);
void insert_buffer_paths(nl::json& patch,
const nl::json& buffer_paths);

const std::string& xbuffer_reference_prefix();

Expand Down Expand Up @@ -67,10 +70,10 @@ namespace xw

namespace detail
{
inline const xeus::xjson* get_buffers(const xeus::xjson& patch,
const xjson_path_type& path)
inline const nl::json* get_buffers(const nl::json& patch,
const xjson_path_type& path)
{
const xeus::xjson* current = &patch;
const nl::json* current = &patch;
for (const auto& item : path)
{
if (current->is_array())
Expand All @@ -93,9 +96,9 @@ namespace xw
return current;
}

inline xeus::xjson* get_json(xeus::xjson& patch, const xjson_path_type& path)
inline nl::json* get_json(nl::json& patch, const xjson_path_type& path)
{
xeus::xjson* current = &patch;
nl::json* current = &patch;
for (const auto& item : path)
{
if (current->is_array())
Expand All @@ -111,19 +114,19 @@ namespace xw
}

template <class T>
inline void set_json(xeus::xjson& patch,
inline void set_json(nl::json& patch,
const xjson_path_type& path,
const T& value)
{
xeus::xjson* json = get_json(patch, path);
nl::json* json = get_json(patch, path);
if (json != nullptr)
{
(*json) = value;
}
}

inline void insert_buffer_path(xeus::xjson& patch,
const xeus::xjson& path,
inline void insert_buffer_path(nl::json& patch,
const nl::json& path,
std::size_t buffer_index)
{
xjson_path_type p = path;
Expand All @@ -133,14 +136,14 @@ namespace xw
}

inline void extract_buffer_paths(const std::vector<xjson_path_type>& to_check,
const xeus::xjson& patch,
const nl::json& patch,
const xeus::buffer_sequence& buffers,
xeus::xjson& buffer_paths)
nl::json& buffer_paths)
{
buffer_paths = xeus::xjson(buffers.size(), nullptr);
buffer_paths = nl::json(buffers.size(), nullptr);
for (const auto& path : to_check)
{
const xeus::xjson* item = detail::get_buffers(patch, path);
const nl::json* item = detail::get_buffers(patch, path);
if (item != nullptr && item->is_string())
{
const std::string leaf = item->get<std::string>();
Expand All @@ -152,8 +155,8 @@ namespace xw
}
}

inline void insert_buffer_paths(xeus::xjson& patch,
const xeus::xjson& buffer_paths)
inline void insert_buffer_paths(nl::json& patch,
const nl::json& buffer_paths)
{
for (std::size_t i = 0; i != buffer_paths.size(); ++i)
{
Expand Down
8 changes: 4 additions & 4 deletions include/xwidgets/xboolean.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ namespace xw
using base_type = xwidget<D>;
using derived_type = D;

void serialize_state(xeus::xjson&, xeus::buffer_sequence&) const;
void apply_patch(const xeus::xjson&, const xeus::buffer_sequence&);
void serialize_state(nl::json&, xeus::buffer_sequence&) const;
void apply_patch(const nl::json&, const xeus::buffer_sequence&);

XPROPERTY(std::string, derived_type, description);

Expand All @@ -51,7 +51,7 @@ namespace xw
***************************/

template <class D>
inline void xboolean<D>::serialize_state(xeus::xjson& state, xeus::buffer_sequence& buffers) const
inline void xboolean<D>::serialize_state(nl::json& state, xeus::buffer_sequence& buffers) const
{
base_type::serialize_state(state, buffers);

Expand All @@ -60,7 +60,7 @@ namespace xw
}

template <class D>
inline void xboolean<D>::apply_patch(const xeus::xjson& patch, const xeus::buffer_sequence& buffers)
inline void xboolean<D>::apply_patch(const nl::json& patch, const xeus::buffer_sequence& buffers)
{
base_type::apply_patch(patch, buffers);

Expand Down
18 changes: 9 additions & 9 deletions include/xwidgets/xbox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ namespace xw
using children_list_type = std::vector<xholder<xtransport>>;
#endif

void serialize_state(xeus::xjson&, xeus::buffer_sequence&) const;
void apply_patch(const xeus::xjson&, const xeus::buffer_sequence&);
void serialize_state(nl::json&, xeus::buffer_sequence&) const;
void apply_patch(const nl::json&, const xeus::buffer_sequence&);

XPROPERTY(std::string, derived_type, box_style, "", XEITHER("success", "info", "warning", "danger", ""));

Expand Down Expand Up @@ -125,7 +125,7 @@ namespace xw
***********************/

template <class D>
inline void xbox<D>::serialize_state(xeus::xjson& state, xeus::buffer_sequence& buffers) const
inline void xbox<D>::serialize_state(nl::json& state, xeus::buffer_sequence& buffers) const
{
base_type::serialize_state(state, buffers);

Expand All @@ -134,7 +134,7 @@ namespace xw
}

template <class D>
inline void xbox<D>::apply_patch(const xeus::xjson& patch, const xeus::buffer_sequence& buffers)
inline void xbox<D>::apply_patch(const nl::json& patch, const xeus::buffer_sequence& buffers)
{
base_type::apply_patch(patch, buffers);

Expand All @@ -151,7 +151,7 @@ namespace xw
#else
this->children().emplace_back(make_id_holder<xtransport>(w.id()));
#endif
xeus::xjson state;
nl::json state;
xeus::buffer_sequence buffers;
set_patch_from_property(children, state, buffers);
this->send_patch(std::move(state), std::move(buffers));
Expand All @@ -162,7 +162,7 @@ namespace xw
inline void xbox<D>::add(xtransport<T>&& w)
{
this->children().emplace_back(make_owning_holder(std::move(w)));
xeus::xjson state;
nl::json state;
xeus::buffer_sequence buffers;
set_patch_from_property(children, state, buffers);
this->send_patch(std::move(state), std::move(buffers));
Expand All @@ -177,7 +177,7 @@ namespace xw
#else
this->children().emplace_back(make_shared_holder<xtransport, T>(w));
#endif
xeus::xjson state;
nl::json state;
xeus::buffer_sequence buffers;
set_patch_from_property(children, state, buffers);
this->send_patch(std::move(state), std::move(buffers));
Expand Down Expand Up @@ -208,7 +208,7 @@ namespace xw
this->children().end()
);
#endif
xeus::xjson state;
nl::json state;
xeus::buffer_sequence buffers;
set_patch_from_property(children, state, buffers);
this->send_patch(std::move(state), std::move(buffers));
Expand All @@ -218,7 +218,7 @@ namespace xw
inline void xbox<D>::clear()
{
this->children() = {};
xeus::xjson state;
nl::json state;
xeus::buffer_sequence buffers;
set_patch_from_property(children, state, buffers);
this->send_patch(std::move(state), std::move(buffers));
Expand Down
20 changes: 10 additions & 10 deletions include/xwidgets/xbutton.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ namespace xw
using base_type = xstyle<D>;
using derived_type = D;

void serialize_state(xeus::xjson&, xeus::buffer_sequence&) const;
void apply_patch(const xeus::xjson&, const xeus::buffer_sequence&);
void serialize_state(nl::json&, xeus::buffer_sequence&) const;
void apply_patch(const nl::json&, const xeus::buffer_sequence&);

XPROPERTY(xtl::xoptional<html_color>, derived_type, button_color);
XPROPERTY(std::string, derived_type, font_weight);
Expand Down Expand Up @@ -71,8 +71,8 @@ namespace xw
using base_type = xwidget<D>;
using derived_type = D;

void serialize_state(xeus::xjson&, xeus::buffer_sequence&) const;
void apply_patch(const xeus::xjson&, const xeus::buffer_sequence&);
void serialize_state(nl::json&, xeus::buffer_sequence&) const;
void apply_patch(const nl::json&, const xeus::buffer_sequence&);

void on_click(click_callback_type);

Expand All @@ -84,7 +84,7 @@ namespace xw
XPROPERTY(std::string, derived_type, button_style, "", XEITHER("primary", "success", "info", "warning", "danger", ""));
XPROPERTY(::xw::button_style, derived_type, style);

void handle_custom_message(const xeus::xjson&);
void handle_custom_message(const nl::json&);

protected:

Expand All @@ -107,7 +107,7 @@ namespace xw
********************************/

template <class D>
inline void xbutton_style<D>::serialize_state(xeus::xjson& state, xeus::buffer_sequence& buffers) const
inline void xbutton_style<D>::serialize_state(nl::json& state, xeus::buffer_sequence& buffers) const
{
base_type::serialize_state(state, buffers);

Expand All @@ -116,7 +116,7 @@ namespace xw
}

template <class D>
inline void xbutton_style<D>::apply_patch(const xeus::xjson& patch, const xeus::buffer_sequence& buffers)
inline void xbutton_style<D>::apply_patch(const nl::json& patch, const xeus::buffer_sequence& buffers)
{
base_type::apply_patch(patch, buffers);

Expand All @@ -143,7 +143,7 @@ namespace xw
**************************/

template <class D>
inline void xbutton<D>::serialize_state(xeus::xjson& state, xeus::buffer_sequence& buffers) const
inline void xbutton<D>::serialize_state(nl::json& state, xeus::buffer_sequence& buffers) const
{
base_type::serialize_state(state, buffers);

Expand All @@ -156,7 +156,7 @@ namespace xw
}

template <class D>
inline void xbutton<D>::apply_patch(const xeus::xjson& patch, const xeus::buffer_sequence& buffers)
inline void xbutton<D>::apply_patch(const nl::json& patch, const xeus::buffer_sequence& buffers)
{
base_type::apply_patch(patch, buffers);

Expand Down Expand Up @@ -193,7 +193,7 @@ namespace xw
}

template <class D>
inline void xbutton<D>::handle_custom_message(const xeus::xjson& content)
inline void xbutton<D>::handle_custom_message(const nl::json& content)
{
auto it = content.find("event");
if (it != content.end() && it.value() == "click")
Expand Down

0 comments on commit a1d7c6e

Please sign in to comment.