Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r52849 - in sandbox/mirror: boost/mirror boost/mirror/factory boost/mirror/factory/wx_constructor_gui libs/mirror/example/factories
From: chochlik_at_[hidden]
Date: 2009-05-08 07:25:00


Author: matus.chochlik
Date: 2009-05-08 07:24:59 EDT (Fri, 08 May 2009)
New Revision: 52849
URL: http://svn.boost.org/trac/boost/changeset/52849

Log:
[mirror 0.4.x]
- added function caller functionality to the wx_constructor_gui
- updated the simple_gui example to show the wx function caller
Text files modified:
   sandbox/mirror/boost/mirror/factory/wx_constructor_gui.hpp | 87 ++++++++++++++++++++++++++++++++-------
   sandbox/mirror/boost/mirror/factory/wx_constructor_gui/default.hpp | 2
   sandbox/mirror/boost/mirror/functor_call.hpp | 1
   sandbox/mirror/libs/mirror/example/factories/simple_gui.cpp | 5 ++
   sandbox/mirror/libs/mirror/example/factories/tetrahedron.hpp | 12 +++++
   5 files changed, 90 insertions(+), 17 deletions(-)

Modified: sandbox/mirror/boost/mirror/factory/wx_constructor_gui.hpp
==============================================================================
--- sandbox/mirror/boost/mirror/factory/wx_constructor_gui.hpp (original)
+++ sandbox/mirror/boost/mirror/factory/wx_constructor_gui.hpp 2009-05-08 07:24:59 EDT (Fri, 08 May 2009)
@@ -11,6 +11,7 @@
 #define BOOST_MIRROR_FACTORY_WX_CONSTRUCTOR_GUI_HPP
 
 #include <boost/mirror/factory.hpp>
+#include <boost/mirror/functor_call.hpp>
 
 #include <boost/mirror/factory/wx_constructor_gui/data.hpp>
 #include <boost/mirror/factory/wx_constructor_gui/utils.hpp>
@@ -26,16 +27,17 @@
 namespace boost {
 namespace mirror {
 namespace utils {
+namespace detail {
 
-template <class Product>
-class wx_factory_dialog
+class wx_constructor_gui_dialog
 {
 private:
         // the dialog
         wxDialog* dialog;
-
+protected:
         // the data passed to the factory
         wx_constructor_gui_data data;
+private:
         wx_constructor_gui_data make_data(wxWindow* parent)
         {
                 assert(parent != 0);
@@ -90,11 +92,8 @@
                 // make and return the data
                 return wx_constructor_gui_data(panel, sizer, 0);
         }
-
- // the factory
- factory< wx_constructor_gui, Product > fact;
-public:
- wx_factory_dialog(wxWindow* parent, wxString caption)
+protected:
+ wx_constructor_gui_dialog(wxWindow* parent, wxString caption)
          : dialog(
                 new wxDialog(
                         parent,
@@ -102,7 +101,14 @@
                         caption
                 )
         ), data(make_data(dialog))
- , fact(&data, 0)
+ { }
+
+ ~wx_constructor_gui_dialog(void)
+ {
+ dialog->Destroy();
+ }
+
+ void init(void)
         {
                 // and resize the dialog
                 dialog->GetSizer()->SetSizeHints(dialog);
@@ -112,18 +118,36 @@
                 );
         }
 
- ~wx_factory_dialog(void)
+ inline bool gather_input(void)
         {
- dialog->Destroy();
+ assert(dialog != 0);
+ // center the dialog
+ dialog->Center();
+ // show it modally and return result
+ return dialog->ShowModal() == wxID_OK;
+ }
+
+};
+
+} // namespace detail
+
+template <class Product>
+class wx_factory_dialog : public detail::wx_constructor_gui_dialog
+{
+private:
+ // the factory
+ factory< wx_constructor_gui, Product > fact;
+public:
+ wx_factory_dialog(wxWindow* parent, wxString caption)
+ : detail::wx_constructor_gui_dialog(parent, caption)
+ , fact(&data)
+ {
+ init();
         }
 
         inline Product* create(void)
         {
- assert(dialog != 0);
- // center the dialog
- dialog->Center();
- // show it modally
- if(dialog->ShowModal() == wxID_OK)
+ if(gather_input())
                 {
                         return fact.new_();
                 }
@@ -131,6 +155,37 @@
         }
 };
 
+template <class Class, int Index>
+class wx_fn_call_dialog : public detail::wx_constructor_gui_dialog
+{
+private:
+ typedef meta_member_functions<Class> meta_functions;
+ typedef mpl::int_<Index> function_index;
+ functor_caller<wx_constructor_gui, meta_functions, function_index>
+ caller;
+ typedef typename meta_functions::template function<function_index>
+ meta_function;
+ typedef typename meta_function::result_type::reflected_type
+ result_type;
+public:
+ wx_fn_call_dialog(wxWindow* parent, wxString caption)
+ : detail::wx_constructor_gui_dialog(parent, caption)
+ , caller(&data)
+ {
+ init();
+ }
+
+ template <class Class>
+ inline result_type call_on(Class& instance)
+ {
+ if(gather_input())
+ {
+ return caller(instance);
+ }
+ throw ::std::runtime_error("Operation cancelled by user");
+ }
+};
+
 } // namespace utils
 } // namespace mirror
 } // namespace boost

Modified: sandbox/mirror/boost/mirror/factory/wx_constructor_gui/default.hpp
==============================================================================
--- sandbox/mirror/boost/mirror/factory/wx_constructor_gui/default.hpp (original)
+++ sandbox/mirror/boost/mirror/factory/wx_constructor_gui/default.hpp 2009-05-08 07:24:59 EDT (Fri, 08 May 2009)
@@ -38,7 +38,7 @@
                 // make a label for the static box sizer
                 wxString label(
                         MetaFunctions::
- template constructor<FuncIndex>::params::
+ template function<FuncIndex>::params::
                         template param<ParamIndex>::base_name()
                 );
                 // the panel which will be the parent of

Modified: sandbox/mirror/boost/mirror/functor_call.hpp
==============================================================================
--- sandbox/mirror/boost/mirror/functor_call.hpp (original)
+++ sandbox/mirror/boost/mirror/functor_call.hpp 2009-05-08 07:24:59 EDT (Fri, 08 May 2009)
@@ -11,6 +11,7 @@
 #define BOOST_MIRROR_FUNCTOR_CALL_HPP
 
 #include <boost/mirror/factory.hpp>
+#include <boost/mirror/meta_mem_functions.hpp>
 
 namespace boost {
 namespace mirror {

Modified: sandbox/mirror/libs/mirror/example/factories/simple_gui.cpp
==============================================================================
--- sandbox/mirror/libs/mirror/example/factories/simple_gui.cpp (original)
+++ sandbox/mirror/libs/mirror/example/factories/simple_gui.cpp 2009-05-08 07:24:59 EDT (Fri, 08 May 2009)
@@ -49,6 +49,11 @@
                 // if we were successful
                 if(t)
                 {
+ utils::wx_fn_call_dialog<T, 0> reset_apex(
+ 0,
+ wxT("GUI test")
+ );
+ reset_apex.call_on(*t);
                         // show some info
                         wxString message;
                         message.Printf(

Modified: sandbox/mirror/libs/mirror/example/factories/tetrahedron.hpp
==============================================================================
--- sandbox/mirror/libs/mirror/example/factories/tetrahedron.hpp (original)
+++ sandbox/mirror/libs/mirror/example/factories/tetrahedron.hpp 2009-05-08 07:24:59 EDT (Fri, 08 May 2009)
@@ -14,6 +14,8 @@
 
 #include <math.h>
 #include <boost/mirror/meta_class.hpp>
+#include <boost/mirror/meta_constructors.hpp>
+#include <boost/mirror/meta_mem_functions.hpp>
         
 namespace test {
         
@@ -105,6 +107,11 @@
         const vector& c(void) const {return base.c;}
         const vector& d(void) const {return apex;}
 
+ void reset_apex(const vector& _apex)
+ {
+ apex = _apex;
+ }
+
         double volume(void) const
         {
                 return fabs(((a()-d())*((b()-d())%(c()-d()))))/6.0;
@@ -148,6 +155,11 @@
         ::test::tetrahedron,
         (((::test::triangle)(base))((::test::vector)(apex)))
 )
+BOOST_MIRROR_REG_MEM_FUNCTIONS_BEGIN(::test::tetrahedron)
+BOOST_MIRROR_REG_MEM_FUNCTION(
+ 0, void, reset_apex, ((const ::test::vector&)(apex))
+)
+BOOST_MIRROR_REG_MEM_FUNCTIONS_END
 
 } // namespace mirror
 } // namespace boost


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk