Skip to content

Commit

Permalink
Merge pull request #182 from SylvainCorlay/drop-generator
Browse files Browse the repository at this point in the history
Drop generator class and precompilation
  • Loading branch information
JohanMabille committed Jan 10, 2020
2 parents 2771063 + f9a05e0 commit 3ef1443
Show file tree
Hide file tree
Showing 68 changed files with 88 additions and 551 deletions.
6 changes: 3 additions & 3 deletions docs/source/embed_widgets/xleaflet_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@
"#include \"xleaflet/xmap.hpp\"\n",
"#include \"xleaflet/xmarker.hpp\"\n",
"\n",
"auto html = xw::html_generator()\n",
"auto html = xw::html::initialize()\n",
" .value(\"Hello from an <b>xwidget</b> in an <b>xmarker</b>!\")\n",
" .finalize();\n",
"\n",
"std::array<double, 2> center = {52.204793, 360.121558};\n",
"\n",
"auto map = xlf::map_generator()\n",
"auto map = xlf::map::initialize()\n",
" .center(center)\n",
" .zoom(15)\n",
" .finalize();\n",
"\n",
"auto marker = xlf::marker_generator()\n",
"auto marker = xlf::marker::initialize()\n",
" .location(center)\n",
" .draggable(false)\n",
" .popup(html)\n",
Expand Down
2 changes: 1 addition & 1 deletion docs/source/embed_widgets/xplot_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"xpl::linear_scale scale_x, scale_y;\n",
"xpl::linear_scale scale_size;\n",
"\n",
"auto scatter = xpl::scatter_generator(scale_x, scale_y, scale_size)\n",
"auto scatter = xpl::scatter::initialize(scale_x, scale_y, scale_size)\n",
" .x(data_x)\n",
" .y(data_y)\n",
" .size(data_c)\n",
Expand Down
10 changes: 5 additions & 5 deletions docs/source/related_projects.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ xplot_ if the C++ backend for the bqplot_ 2-D plotting library
xpl::linear_scale scale_x, scale_y;
xpl::linear_scale scale_size;
auto scatter = xpl::scatter_generator(scale_x, scale_y, scale_size)
auto scatter = xpl::scatter::initialize(scale_x, scale_y, scale_size)
.x(data_x)
.y(data_y)
.size(data_c)
Expand All @@ -78,7 +78,7 @@ xplot_ if the C++ backend for the bqplot_ 2-D plotting library
xpl::toolbar tb(fig);
xw::vbox b = xw::vbox_generator()
xw::vbox b = xw::vbox::initialize()
.children({fig, tb})
.finalize();
b
Expand Down Expand Up @@ -110,18 +110,18 @@ xleaflet_ is the C++ backend for the leaflet maps visualization library. The Pyt
#include "xleaflet/xmap.hpp"
#include "xleaflet/xmarker.hpp"
auto html = xw::html_generator()
auto html = xw::html::initialize()
.value("Hello from an <b>xwidget</b> in an <b>xmarker</b>!")
.finalize();
std::array<double, 2> center = {52.204793, 360.121558};
auto map = xlf::map_generator()
auto map = xlf::map::initialize()
.center(center)
.zoom(15)
.finalize();
auto marker = xlf::marker_generator()
auto marker = xlf::marker::initialize()
.location(center)
.draggable(false)
.popup(html)
Expand Down
19 changes: 2 additions & 17 deletions docs/source/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -100,29 +100,14 @@ Providing a constructor for ``slider`` with a large number of such attributes wo

.. code:: cpp
auto button = xw::slider_generator<double>()
auto button = xw::slider<double>::initialize()
.min(1.0)
.max(9.0)
.value(4.0)
.orientation("vertical")
.finalize();
This is a classical approach: calls to ``min``, ``max``, ``value`` and ``orientation`` all return the ``slider_generator`` instance (by value, which is optimized with C++ move semantics and copy ellision). The ``finalize()`` method transforms the generator class into the corresponding ``xmaterialize`` instance, resulting in the communication of the appropriate message for the creation of the front-end counterpart, with the proper data.

For each widget type, the generator type is the name of the widget, suffixed with ``_generator``. For example, we have:

.. code:: cpp
using button_generator = xgenerator<xbutton>;
Similarly, for template widget types, we have

.. code:: cpp
template <class T>
using slider_generator = xgenerator<xslider, T>;
Just like ``xmaterialize``, ``xgenerator`` closes the CRTP in a *final* way, but does not implement the RAII logic. Instead, it provides the ``finalize`` method which can convert it into an actual widget.
This is a classical approach: calls to ``min``, ``max``, ``value`` and ``orientation`` all return the ``slider`` instance (by rvalue reference, which is optimized with C++ move semantics and copy ellision). The ``finalize()`` triggers the creation of the front-end object with the data.

Widget Events
-------------
Expand Down
5 changes: 0 additions & 5 deletions include/xwidgets/xaccordion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ namespace xw

using accordion = xmaterialize<xaccordion>;

using accordion_generator = xgenerator<xaccordion>;

/*****************************
* xaccordion implementation *
*****************************/
Expand Down Expand Up @@ -81,9 +79,6 @@ namespace xw
extern template class xmaterialize<xaccordion>;
extern template xmaterialize<xaccordion>::xmaterialize();
extern template class xtransport<xmaterialize<xaccordion>>;
extern template class xgenerator<xaccordion>;
extern template xgenerator<xaccordion>::xgenerator();
extern template class xtransport<xgenerator<xaccordion>>;
#endif
}

Expand Down
13 changes: 4 additions & 9 deletions include/xwidgets/xaudio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ namespace xw

using audio = xmaterialize<xaudio>;

using audio_generator = xgenerator<xaudio>;

/*************************
* xaudio implementation *
*************************/
Expand Down Expand Up @@ -111,15 +109,15 @@ namespace xw
}
}

inline audio_generator audio_from_file(const std::string& filename)
inline auto audio_from_file(const std::string& filename)
{
return audio_generator().value(read_file(filename));
return audio::initialize().value(read_file(filename));
}

inline audio_generator audio_from_url(const std::string& url)
inline auto audio_from_url(const std::string& url)
{
std::vector<char> value(url.cbegin(), url.cend());
return audio_generator().value(value).format("url");
return audio::initialize().value(value).format("url");
}

/*********************
Expand All @@ -130,9 +128,6 @@ namespace xw
extern template class xmaterialize<xaudio>;
extern template xmaterialize<xaudio>::xmaterialize();
extern template class xtransport<xmaterialize<xaudio>>;
extern template class xgenerator<xaudio>;
extern template xgenerator<xaudio>::xgenerator();
extern template class xtransport<xgenerator<xaudio>>;
#endif
}
#endif
20 changes: 5 additions & 15 deletions include/xwidgets/xbox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ namespace xw

using hbox = xmaterialize<xhbox>;

using hbox_generator = xgenerator<xhbox>;

/********************
* vbox declaration *
********************/
Expand All @@ -118,8 +116,6 @@ namespace xw

using vbox = xmaterialize<xvbox>;

using vbox_generator = xgenerator<xvbox>;

/***********************
* xbox implementation *
***********************/
Expand Down Expand Up @@ -153,7 +149,7 @@ namespace xw
#endif
nl::json state;
xeus::buffer_sequence buffers;
xwidgets_serialize(children(), state["box_style"], buffers);
xwidgets_serialize(children(), state["children"], buffers);
this->send_patch(std::move(state), std::move(buffers));
}

Expand All @@ -164,7 +160,7 @@ namespace xw
this->children().emplace_back(make_owning_holder(std::move(w)));
nl::json state;
xeus::buffer_sequence buffers;
xwidgets_serialize(children(), state["box_style"], buffers);
xwidgets_serialize(children(), state["children"], buffers);
this->send_patch(std::move(state), std::move(buffers));
}

Expand All @@ -179,7 +175,7 @@ namespace xw
#endif
nl::json state;
xeus::buffer_sequence buffers;
xwidgets_serialize(children(), state["box_style"], buffers);
xwidgets_serialize(children(), state["children"], buffers);
this->send_patch(std::move(state), std::move(buffers));
}

Expand Down Expand Up @@ -210,7 +206,7 @@ namespace xw
#endif
nl::json state;
xeus::buffer_sequence buffers;
xwidgets_serialize(children(), state["box_style"], buffers);
xwidgets_serialize(children(), state["children"], buffers);
this->send_patch(std::move(state), std::move(buffers));
}

Expand All @@ -220,7 +216,7 @@ namespace xw
this->children() = {};
nl::json state;
xeus::buffer_sequence buffers;
xwidgets_serialize(children(), state["box_style"], buffers);
xwidgets_serialize(children(), state["children"], buffers);
this->send_patch(std::move(state), std::move(buffers));
}

Expand Down Expand Up @@ -286,16 +282,10 @@ namespace xw
extern template class xmaterialize<xhbox>;
extern template xmaterialize<xhbox>::xmaterialize();
extern template class xtransport<xmaterialize<xhbox>>;
extern template class xgenerator<xhbox>;
extern template xgenerator<xhbox>::xgenerator();
extern template class xtransport<xgenerator<xhbox>>;

extern template class xmaterialize<xvbox>;
extern template xmaterialize<xvbox>::xmaterialize();
extern template class xtransport<xmaterialize<xvbox>>;
extern template class xgenerator<xvbox>;
extern template xgenerator<xvbox>::xgenerator();
extern template class xtransport<xgenerator<xvbox>>;
#endif
}
#endif
10 changes: 0 additions & 10 deletions include/xwidgets/xbutton.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ namespace xw

using button_style = xmaterialize<xbutton_style>;

using button_style_generator = xgenerator<xbutton_style>;

/**********************
* button declaration *
**********************/
Expand Down Expand Up @@ -100,8 +98,6 @@ namespace xw

using button = xmaterialize<xbutton>;

using button_generator = xgenerator<xbutton>;

/********************************
* xbutton_style implementation *
********************************/
Expand Down Expand Up @@ -213,16 +209,10 @@ namespace xw
extern template class xmaterialize<xbutton_style>;
extern template xmaterialize<xbutton_style>::xmaterialize();
extern template class xtransport<xmaterialize<xbutton_style>>;
extern template class xgenerator<xbutton_style>;
extern template xgenerator<xbutton_style>::xgenerator();
extern template class xtransport<xgenerator<xbutton_style>>;

extern template class xmaterialize<xbutton>;
extern template xmaterialize<xbutton>::xmaterialize();
extern template class xtransport<xmaterialize<xbutton>>;
extern template class xgenerator<xbutton>;
extern template xgenerator<xbutton>::xgenerator();
extern template class xtransport<xgenerator<xbutton>>;
#endif
}
#endif
4 changes: 0 additions & 4 deletions include/xwidgets/xcheckbox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ namespace xw

using checkbox = xmaterialize<xcheckbox>;

using checkbox_generator = xgenerator<xcheckbox>;

/****************************
* xcheckbox implementation *
****************************/
Expand Down Expand Up @@ -88,8 +86,6 @@ namespace xw
extern template class xmaterialize<xcheckbox>;
extern template xmaterialize<xcheckbox>::xmaterialize();
extern template class xtransport<xmaterialize<xcheckbox>>;
extern template class xgenerator<xcheckbox>;
extern template xgenerator<xcheckbox>::xgenerator();
#endif
}

Expand Down
5 changes: 0 additions & 5 deletions include/xwidgets/xcolor_picker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ namespace xw

using color_picker = xmaterialize<xcolor_picker>;

using color_picker_generator = xgenerator<xcolor_picker>;

/********************************
* xcolor_picker implementation *
********************************/
Expand Down Expand Up @@ -100,9 +98,6 @@ namespace xw
extern template class xmaterialize<xcolor_picker>;
extern template xmaterialize<xcolor_picker>::xmaterialize();
extern template class xtransport<xmaterialize<xcolor_picker>>;
extern template class xgenerator<xcolor_picker>;
extern template xgenerator<xcolor_picker>::xgenerator();
extern template class xtransport<xgenerator<xcolor_picker>>;
#endif
}

Expand Down
15 changes: 0 additions & 15 deletions include/xwidgets/xcontroller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ namespace xw

using controller_button = xmaterialize<xcontroller_button>;

using controller_button_generator = xgenerator<xcontroller_button>;

/********************************
* xcontroller_axis declaration *
********************************/
Expand Down Expand Up @@ -83,8 +81,6 @@ namespace xw

using controller_axis = xmaterialize<xcontroller_axis>;

using controller_axis_generator = xgenerator<xcontroller_axis>;

/***************************
* xcontroller declaration *
***************************/
Expand Down Expand Up @@ -133,8 +129,6 @@ namespace xw

using controller = xmaterialize<xcontroller>;

using controller_generator = xmaterialize<xcontroller>;

/*************************************
* xcontroller_button implementation *
*************************************/
Expand Down Expand Up @@ -289,23 +283,14 @@ namespace xw
extern template class xmaterialize<xcontroller_button>;
extern template xmaterialize<xcontroller_button>::xmaterialize();
extern template class xtransport<xmaterialize<xcontroller_button>>;
extern template class xgenerator<xcontroller_button>;
extern template xgenerator<xcontroller_button>::xgenerator();
extern template class xtransport<xgenerator<xcontroller_button>>;

extern template class xmaterialize<xcontroller_axis>;
extern template xmaterialize<xcontroller_axis>::xmaterialize();
extern template class xtransport<xmaterialize<xcontroller_axis>>;
extern template class xgenerator<xcontroller_axis>;
extern template xgenerator<xcontroller_axis>::xgenerator();
extern template class xtransport<xgenerator<xcontroller_axis>>;

extern template class xmaterialize<xcontroller>;
extern template xmaterialize<xcontroller>::xmaterialize();
extern template class xtransport<xmaterialize<xcontroller>>;
extern template class xgenerator<xcontroller>;
extern template xgenerator<xcontroller>::xgenerator();
extern template class xtransport<xgenerator<xcontroller>>;
#endif
}

Expand Down
5 changes: 0 additions & 5 deletions include/xwidgets/xdropdown.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ namespace xw

using dropdown = xmaterialize<xdropdown>;

using dropdown_generator = xgenerator<xdropdown>;

/****************************
* xdropdown implementation *
****************************/
Expand Down Expand Up @@ -100,9 +98,6 @@ namespace xw
extern template class xmaterialize<xdropdown>;
extern template xmaterialize<xdropdown>::xmaterialize();
extern template class xtransport<xmaterialize<xdropdown>>;
extern template class xgenerator<xdropdown>;
extern template xgenerator<xdropdown>::xgenerator();
extern template class xtransport<xgenerator<xdropdown>>;
#endif
}
#endif

0 comments on commit 3ef1443

Please sign in to comment.