Skip to content

Commit

Permalink
Merge pull request #143 from SylvainCorlay/custom-serialization
Browse files Browse the repository at this point in the history
Enable custom serialization
  • Loading branch information
SylvainCorlay committed Apr 25, 2018
2 parents e6a4a67 + a313aa9 commit 8b971c4
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 14 deletions.
4 changes: 3 additions & 1 deletion docs/source/compilers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ case for widget types that are used as properties for other widgets such as
``xlayout``` and style widgets.

The upstream `MSVC issue`_ issue appears to have been solved with VS2017 15.7
(Preview 3).
(Preview 3). The impacted build numbers for Visual Studio are
``_MSC_VER==1910``, ``_MSC_VER==1911```, ``_MSC_VER==1912```,
``_MSC_VER==1913```.

Visual Studio and CRTP bases
----------------------------
Expand Down
12 changes: 10 additions & 2 deletions docs/source/related_projects.rst
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,15 @@ xleaflet_ is the C++ backend for the leaflet maps visualization library. The Pyt
}
</script>

.. _xplot: https://github.com/quantstack/xplot.git
.. image:: xproperty.svg
:alt: xproperty

xproperty_ is the C++ implementation of the observer pattern underlying
``xwidgets``. It is to ``xwidgets`` what the traitlets project is to
``ipywidgets``.

.. _xplot: https://github.com/QuantStack/xplot.git
.. _bqplot: https://github.com/bloomberg/bqplot.git
.. _xleaflet: https://github.com/quantstack/xleaflet.git
.. _xleaflet: https://github.com/QuantStack/xleaflet.git
.. _ipyleaflet: https://github.com/jupyter-widgets/ipyleaflet.git
.. _xproperty: https://github.com/QuantStack/xproperty.git
40 changes: 29 additions & 11 deletions include/xwidgets/xtransport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,24 +79,42 @@ namespace xw
.target(get_widget_target_name());
}

/*****************
* Serialization *
*****************/
/**********************************************
* property serialization and deserialization *
**********************************************/

// Values

template <class T>
inline void xwidgets_serialize(const T& value, xeus::xjson& j, xeus::buffer_sequence&)
{
j = value;
}

template <class T>
inline void xwidgets_deserialize(T& value, const xeus::xjson& j, const xeus::buffer_sequence&)
{
value = j.template get<T>();
}

// Properties

template <class P>
inline void set_property_from_patch(P& property, const xeus::xjson& patch, const xeus::buffer_sequence&)
inline void set_patch_from_property(const P& property, xeus::xjson& patch, xeus::buffer_sequence& buffers)
{
auto it = patch.find(property.name());
if (it != patch.end())
{
property = it->template get<typename P::value_type>();
}
xwidgets_serialize(property(), patch[property.name()], buffers);
}

template <class P>
inline void set_patch_from_property(const P& property, xeus::xjson& patch, xeus::buffer_sequence&)
inline void set_property_from_patch(P& property, const xeus::xjson& patch, const xeus::buffer_sequence& buffers)
{
patch[property.name()] = property();
auto it = patch.find(property.name());
if (it != patch.end())
{
typename P::value_type value;
xwidgets_deserialize(value, *it, buffers);
property = value;
}
}

/*******************************
Expand Down

0 comments on commit 8b971c4

Please sign in to comment.