|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r51148 - in sandbox/mirror: boost/mirror boost/mirror/factory boost/mirror/factory/wx_constructor_gui libs/mirror/build/msvc/mirror_examples libs/mirror/build/msvc/mirror_examples/fact_simple_gui libs/mirror/example/factories
From: chochlik_at_[hidden]
Date: 2009-02-09 13:14:49
Author: matus.chochlik
Date: 2009-02-09 13:14:48 EST (Mon, 09 Feb 2009)
New Revision: 51148
URL: http://svn.boost.org/trac/boost/changeset/51148
Log:
[mirror 0.3.x]
- added a wxWidgets based constructor param input dialog/factory
Added:
sandbox/mirror/boost/mirror/factory/
sandbox/mirror/boost/mirror/factory/wx_constructor_gui/
sandbox/mirror/boost/mirror/factory/wx_constructor_gui.hpp (contents, props changed)
sandbox/mirror/boost/mirror/factory/wx_constructor_gui/basic.hpp (contents, props changed)
sandbox/mirror/boost/mirror/factory/wx_constructor_gui/boolean.hpp (contents, props changed)
sandbox/mirror/boost/mirror/factory/wx_constructor_gui/data.hpp (contents, props changed)
sandbox/mirror/boost/mirror/factory/wx_constructor_gui/default.hpp (contents, props changed)
sandbox/mirror/boost/mirror/factory/wx_constructor_gui/manager.hpp (contents, props changed)
sandbox/mirror/boost/mirror/factory/wx_constructor_gui/utils.hpp (contents, props changed)
sandbox/mirror/libs/mirror/build/msvc/mirror_examples/fact_simple_gui/ (props changed)
sandbox/mirror/libs/mirror/build/msvc/mirror_examples/fact_simple_gui/fact_simple_gui.vcproj (contents, props changed)
sandbox/mirror/libs/mirror/example/factories/simple_gui.cpp (contents, props changed)
sandbox/mirror/libs/mirror/example/factories/tetrahedron.hpp (contents, props changed)
Text files modified:
sandbox/mirror/boost/mirror/factory.hpp | 2
sandbox/mirror/boost/mirror/meta_constructors.hpp | 88 ++++++++++++++++++++++++-
sandbox/mirror/boost/mirror/meta_data_fwd.hpp | 9 ++
sandbox/mirror/libs/mirror/build/msvc/mirror_examples/mirror_examples.sln | 6 +
sandbox/mirror/libs/mirror/example/factories/input_ui.hpp | 3
sandbox/mirror/libs/mirror/example/factories/tetrahedron.cpp | 135 ---------------------------------------
6 files changed, 105 insertions(+), 138 deletions(-)
Modified: sandbox/mirror/boost/mirror/factory.hpp
==============================================================================
--- sandbox/mirror/boost/mirror/factory.hpp (original)
+++ sandbox/mirror/boost/mirror/factory.hpp 2009-02-09 13:14:48 EST (Mon, 09 Feb 2009)
@@ -160,7 +160,7 @@
/** Factory constructor initalizer
*/
#define BOOST_MIRROR_INITIALIZE_FACTORY_CONSTRUCTOR(Z, INDEX, X)\
- , _##INDEX (manager.param())
+ , _##INDEX (manager.param((Product*)0, mpl::int_<INDEX>() ))
#define BOOST_MIRROR_CALL_FACTORY_FUNCTOR(Z, INDEX, X)\
case INDEX: return _##INDEX ();
Added: sandbox/mirror/boost/mirror/factory/wx_constructor_gui.hpp
==============================================================================
--- (empty file)
+++ sandbox/mirror/boost/mirror/factory/wx_constructor_gui.hpp 2009-02-09 13:14:48 EST (Mon, 09 Feb 2009)
@@ -0,0 +1,127 @@
+/**
+ * \file boost/mirror/factory/wx_constructor_gui.hpp
+ *
+ *
+ * Copyright 2008 Matus Chochlik. Distributed under the Boost
+ * Software License, Version 1.0. (See accompanying file
+ * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ */
+
+#ifndef BOOST_MIRROR_FACTORY_WX_CONSTRUCTOR_GUI_HPP
+#define BOOST_MIRROR_FACTORY_WX_CONSTRUCTOR_GUI_HPP
+
+#include <boost/mirror/factory.hpp>
+
+#include <boost/mirror/factory/wx_constructor_gui/data.hpp>
+#include <boost/mirror/factory/wx_constructor_gui/utils.hpp>
+#include <boost/mirror/factory/wx_constructor_gui/default.hpp>
+#include <boost/mirror/factory/wx_constructor_gui/basic.hpp>
+#include <boost/mirror/factory/wx_constructor_gui/boolean.hpp>
+#include <boost/mirror/factory/wx_constructor_gui/manager.hpp>
+
+#include <wx/statline.h>
+
+#include <assert.h>
+
+namespace boost {
+namespace mirror {
+namespace utils {
+
+template <class Product>
+class wx_factory_dialog
+{
+private:
+ // the dialog
+ wxDialog* dialog;
+
+ // the data passed to the factory
+ wx_constructor_gui_data data;
+ wx_constructor_gui_data make_data(wxWindow* parent)
+ {
+ assert(parent != 0);
+ //
+ // create the main panel od the dialog
+ wxPanel* panel = new wxPanel(parent, wxID_ANY);
+ // create the main sizer
+ wxBoxSizer* main_sizer = new wxBoxSizer(wxVERTICAL);
+ // top padding
+ main_sizer->AddSpacer(8);
+ // create the horizontal padding sizer
+ wxBoxSizer* hz_padding_sizer = new wxBoxSizer(wxHORIZONTAL);
+ // add left padding
+ hz_padding_sizer->AddSpacer(8);
+ // the main sizer
+ wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
+ panel->SetSizer(sizer);
+ hz_padding_sizer->Add(panel, 1, wxEXPAND);
+ // add the right padding
+ hz_padding_sizer->AddSpacer(16);
+ // add the padding sizer to the main sizer
+ main_sizer->Add(hz_padding_sizer, 1, wxEXPAND);
+ // add the padding above the buttons
+ main_sizer->AddSpacer(8);
+ main_sizer->Add(
+ new wxStaticLine(
+ parent,
+ wxID_ANY,
+ wxDefaultPosition,
+ wxDefaultSize,
+ wxLI_HORIZONTAL
+ ),
+ 0,
+ wxEXPAND
+ );
+ main_sizer->AddSpacer(8);
+ //
+ // now add the buttons
+ main_sizer->Add(
+ dialog->CreateStdDialogButtonSizer(wxOK | wxCANCEL),
+ 0,
+ wxEXPAND
+ );
+ // add bottom padding
+ main_sizer->AddSpacer(16);
+ // assign the main sizer
+ parent->SetSizer(main_sizer);
+ //
+ // 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)
+ : dialog(new wxDialog(parent, wxID_ANY, caption))
+ , data(make_data(dialog))
+ , fact(&data, 0)
+ {
+ // and resize the dialog
+ dialog->GetSizer()->SetSizeHints(dialog);
+ }
+
+ ~wx_factory_dialog(void)
+ {
+ dialog->Destroy();
+ }
+
+ inline Product* create(void)
+ {
+ assert(dialog != 0);
+ // center the dialog
+ dialog->Center();
+ // show it modally
+ if(dialog->ShowModal() == wxID_OK)
+ {
+ return fact.new_();
+ }
+ return 0;
+ }
+};
+
+} // namespace utils
+} // namespace mirror
+} // namespace boost
+
+#endif //include guard
+
Added: sandbox/mirror/boost/mirror/factory/wx_constructor_gui/basic.hpp
==============================================================================
--- (empty file)
+++ sandbox/mirror/boost/mirror/factory/wx_constructor_gui/basic.hpp 2009-02-09 13:14:48 EST (Mon, 09 Feb 2009)
@@ -0,0 +1,109 @@
+/**
+ * \file boost/mirror/factory/wx_constructor_gui/basic.hpp
+ *
+ *
+ * Copyright 2008 Matus Chochlik. Distributed under the Boost
+ * Software License, Version 1.0. (See accompanying file
+ * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ */
+
+#ifndef BOOST_MIRROR_FACTORY_WX_CONSTRUCTOR_GUI_BASIC_HPP
+#define BOOST_MIRROR_FACTORY_WX_CONSTRUCTOR_GUI_BASIC_HPP
+
+#include <wx/wx.h>
+#include <wx/sizer.h>
+
+namespace boost {
+namespace mirror {
+namespace utils {
+
+template <class Product>
+class wx_constructor_gui_basic : public wx_constructor_gui_utils
+{
+private:
+ wxTextCtrl* text_ctl;
+
+ struct text_ctl_maker
+ {
+ inline wxTextCtrl* operator()(wxWindow* parent) const
+ {
+ return new wxTextCtrl(parent, wxID_ANY);
+ }
+
+ typedef wxTextCtrl result_type;
+ };
+protected:
+ wxString get_text(void) const
+ {
+ return text_ctl->GetValue();
+ }
+public:
+ template <class Context, class ConstrIndex, class ParamIndex>
+ wx_constructor_gui_basic(
+ wx_constructor_gui_data* parent_data,
+ Context* pc,
+ ConstrIndex ci,
+ ParamIndex pi
+ ): text_ctl(make_ctl(text_ctl_maker(), parent_data, pc, ci, pi))
+ { }
+};
+
+#define BOOST_MIRROR_FACTORY_PLUGINS_SPECIALIZE_WX_CONSTR_GUI( \
+ PRODUCT, \
+ FUNCTOR_BODY \
+) \
+template <> \
+class wx_constructor_gui< PRODUCT > \
+ : public wx_constructor_gui_basic< PRODUCT > \
+{ \
+private: \
+ typedef wx_constructor_gui_basic< PRODUCT > \
+ base_class; \
+public: \
+ template <class Context, class ConstrIndex, class ParamIndex> \
+ wx_constructor_gui( \
+ wx_constructor_gui_data* parent_data, \
+ Context* pc, \
+ ConstrIndex ci, \
+ ParamIndex pi \
+ ): base_class(parent_data, pc, ci, pi) \
+ { } \
+ \
+ inline PRODUCT operator()(void) FUNCTOR_BODY \
+};
+
+BOOST_MIRROR_FACTORY_PLUGINS_SPECIALIZE_WX_CONSTR_GUI(
+ cts::bstring,
+ {return cts::bstring(get_text().c_str());}
+)
+
+#define BOOST_MIRROR_FACTORY_PLUGINS_SPECIALIZE_WX_CONSTR_GUI_WX_CONVERT( \
+ TYPE, \
+ TEMP_TYPE, \
+ CONVERSION \
+) BOOST_MIRROR_FACTORY_PLUGINS_SPECIALIZE_WX_CONSTR_GUI( \
+ TYPE, \
+ { \
+ TEMP_TYPE result; \
+ if(!get_text().CONVERSION(&result)) \
+ throw ::std::bad_cast(); \
+ return TYPE(result); \
+ } \
+)
+
+BOOST_MIRROR_FACTORY_PLUGINS_SPECIALIZE_WX_CONSTR_GUI_WX_CONVERT(unsigned char, unsigned long, ToULong)
+BOOST_MIRROR_FACTORY_PLUGINS_SPECIALIZE_WX_CONSTR_GUI_WX_CONVERT(short, long, ToLong)
+BOOST_MIRROR_FACTORY_PLUGINS_SPECIALIZE_WX_CONSTR_GUI_WX_CONVERT(unsigned short, unsigned long, ToULong)
+BOOST_MIRROR_FACTORY_PLUGINS_SPECIALIZE_WX_CONSTR_GUI_WX_CONVERT(int, long, ToLong)
+BOOST_MIRROR_FACTORY_PLUGINS_SPECIALIZE_WX_CONSTR_GUI_WX_CONVERT(unsigned int, unsigned long, ToULong)
+BOOST_MIRROR_FACTORY_PLUGINS_SPECIALIZE_WX_CONSTR_GUI_WX_CONVERT(long, long, ToLong)
+BOOST_MIRROR_FACTORY_PLUGINS_SPECIALIZE_WX_CONSTR_GUI_WX_CONVERT(unsigned long, unsigned long, ToULong)
+BOOST_MIRROR_FACTORY_PLUGINS_SPECIALIZE_WX_CONSTR_GUI_WX_CONVERT(float, double, ToDouble)
+BOOST_MIRROR_FACTORY_PLUGINS_SPECIALIZE_WX_CONSTR_GUI_WX_CONVERT(double, double, ToDouble)
+
+} // namespace utils
+} // namespace mirror
+} // namespace boost
+
+#endif //include guard
+
Added: sandbox/mirror/boost/mirror/factory/wx_constructor_gui/boolean.hpp
==============================================================================
--- (empty file)
+++ sandbox/mirror/boost/mirror/factory/wx_constructor_gui/boolean.hpp 2009-02-09 13:14:48 EST (Mon, 09 Feb 2009)
@@ -0,0 +1,61 @@
+/**
+ * \file boost/mirror/factory/wx_constructor_gui/boolean.hpp
+ *
+ *
+ * Copyright 2008 Matus Chochlik. Distributed under the Boost
+ * Software License, Version 1.0. (See accompanying file
+ * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ */
+
+#ifndef BOOST_MIRROR_FACTORY_WX_CONSTRUCTOR_GUI_BOOLEAN_HPP
+#define BOOST_MIRROR_FACTORY_WX_CONSTRUCTOR_GUI_BOOLEAN_HPP
+
+#include <wx/wx.h>
+#include <wx/sizer.h>
+#include <wx/checkbox.h>
+
+namespace boost {
+namespace mirror {
+namespace utils {
+
+template <>
+class wx_constructor_gui<bool> : public wx_constructor_gui_utils
+{
+private:
+ wxCheckBox* chb_ctl;
+ struct chbctl_maker
+ {
+ inline wxCheckBox* operator()(wxWindow* parent) const
+ {
+ return new wxCheckBox(
+ parent,
+ wxID_ANY,
+ wxEmptyString
+ );
+ }
+
+ typedef wxCheckBox result_type;
+ };
+
+public:
+ template <class Context, class ConstrIndex, class ParamIndex>
+ wx_constructor_gui(
+ wx_constructor_gui_data* parent_data,
+ Context* pc,
+ ConstrIndex ci,
+ ParamIndex pi
+ ): chb_ctl(make_ctl(chbctl_maker(), parent_data, pc, ci, pi))
+ { }
+
+ inline bool operator()(void) const
+ {
+ return chb_ctl->GetValue();
+ }
+};
+
+} // namespace utils
+} // namespace mirror
+} // namespace boost
+
+#endif //include guard
+
Added: sandbox/mirror/boost/mirror/factory/wx_constructor_gui/data.hpp
==============================================================================
--- (empty file)
+++ sandbox/mirror/boost/mirror/factory/wx_constructor_gui/data.hpp 2009-02-09 13:14:48 EST (Mon, 09 Feb 2009)
@@ -0,0 +1,57 @@
+/**
+ * \file boost/mirror/factory/wx_constructor_gui/data.hpp
+ *
+ *
+ * Copyright 2008 Matus Chochlik. Distributed under the Boost
+ * Software License, Version 1.0. (See accompanying file
+ * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ */
+
+#ifndef BOOST_MIRROR_FACTORY_WX_CONSTRUCTOR_GUI_DATA_HPP
+#define BOOST_MIRROR_FACTORY_WX_CONSTRUCTOR_GUI_DATA_HPP
+
+#include <wx/wx.h>
+#include <wx/sizer.h>
+
+namespace boost {
+namespace mirror {
+namespace utils {
+
+class wx_constructor_gui_data
+{
+private:
+ wx_constructor_gui_data* parent_data;
+ wxWindow* parent_window;
+ wxSizer* sizer;
+public:
+ wx_constructor_gui_data(
+ wxWindow* _window,
+ wxSizer* _sizer,
+ wx_constructor_gui_data* _data
+ ): parent_data(_data)
+ , parent_window(_window)
+ , sizer(_sizer)
+ { }
+
+ inline wx_constructor_gui_data* get_parent_data(void) const
+ {
+ return parent_data;
+ }
+
+ inline wxWindow* get_window(void) const
+ {
+ return parent_window;
+ }
+
+ inline wxSizer* get_sizer(void) const
+ {
+ return sizer;
+ }
+};
+
+} // namespace utils
+} // namespace mirror
+} // namespace boost
+
+#endif //include guard
+
Added: sandbox/mirror/boost/mirror/factory/wx_constructor_gui/default.hpp
==============================================================================
--- (empty file)
+++ sandbox/mirror/boost/mirror/factory/wx_constructor_gui/default.hpp 2009-02-09 13:14:48 EST (Mon, 09 Feb 2009)
@@ -0,0 +1,100 @@
+/**
+ * \file boost/mirror/factory/wx_constructor_gui/default.hpp
+ *
+ *
+ * Copyright 2008 Matus Chochlik. Distributed under the Boost
+ * Software License, Version 1.0. (See accompanying file
+ * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ */
+
+#ifndef BOOST_MIRROR_FACTORY_WX_CONSTRUCTOR_GUI_DEFAULT_HPP
+#define BOOST_MIRROR_FACTORY_WX_CONSTRUCTOR_GUI_DEFAULT_HPP
+
+#include <wx/wx.h>
+#include <wx/sizer.h>
+
+namespace boost {
+namespace mirror {
+namespace utils {
+
+template <class Product>
+class wx_constructor_gui
+{
+private:
+ // the data
+ wx_constructor_gui_data data;
+ //
+ // makes the data
+ template <class Context, class ConstrIndex, class ParamIndex>
+ static inline wx_constructor_gui_data make_data(
+ wx_constructor_gui_data* parent_data,
+ Context* pc,
+ ConstrIndex ci,
+ ParamIndex pi
+ )
+ {
+ // we need the parent data
+ assert(parent_data != 0);
+ // make a label for the static box sizer
+ wxString label(
+ BOOST_MIRRORED_CONSTRUCTORS(
+ Context
+ )::base_param_name(ci, pi)
+ );
+ // the panel which will be the parent of
+ // all child widgets
+ wxPanel* panel = new wxPanel(
+ parent_data->get_window(),
+ wxID_ANY
+ );
+ // the sizer
+ wxStaticBoxSizer* sizer = new wxStaticBoxSizer(
+ wxVERTICAL,
+ panel,
+ label
+ );
+ panel->SetSizer(sizer);
+ // add the panel to the parent sizer
+ parent_data->get_sizer()->Add(
+ panel,
+ 0, //proportion
+ wxEXPAND
+ );
+ // make and return the data
+ return wx_constructor_gui_data(
+ panel,
+ sizer,
+ parent_data
+ );
+ }
+
+ // the mirror factory that will create the instances
+ // of the Product
+ typename make_factory<
+ wx_constructor_gui,
+ Product
+ >::type fact;
+public:
+ template <class Context, class ConstrIndex, class ParamIndex>
+ wx_constructor_gui(
+ wx_constructor_gui_data* parent_data,
+ Context* pc,
+ ConstrIndex ci,
+ ParamIndex pi
+ ): data(make_data(parent_data, pc, ci, pi))
+ , fact(&data)
+ { }
+
+ inline Product operator()(void)
+ {
+ return fact();
+ }
+};
+
+
+} // namespace utils
+} // namespace mirror
+} // namespace boost
+
+#endif //include guard
+
Added: sandbox/mirror/boost/mirror/factory/wx_constructor_gui/manager.hpp
==============================================================================
--- (empty file)
+++ sandbox/mirror/boost/mirror/factory/wx_constructor_gui/manager.hpp 2009-02-09 13:14:48 EST (Mon, 09 Feb 2009)
@@ -0,0 +1,141 @@
+/**
+ * \file boost/mirror/factory/wx_constructor_gui/manager.hpp
+ *
+ *
+ * Copyright 2008 Matus Chochlik. Distributed under the Boost
+ * Software License, Version 1.0. (See accompanying file
+ * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ */
+
+#ifndef BOOST_MIRROR_FACTORY_WX_CONSTRUCTOR_GUI_MANAGER_HPP
+#define BOOST_MIRROR_FACTORY_WX_CONSTRUCTOR_GUI_MANAGER_HPP
+
+#include <wx/wx.h>
+#include <wx/sizer.h>
+#include <wx/choicebk.h>
+
+#include <list>
+
+
+namespace boost {
+namespace mirror {
+namespace utils {
+
+template <>
+class wx_constructor_gui<void>
+{
+private:
+ // pointer to the parent data
+ wx_constructor_gui_data* parent_data;
+ //
+ typedef wxChoicebook BookCtrl;
+ // the book ctrl
+ BookCtrl* book_ctl;
+ static inline BookCtrl* make_book_ctl(
+ wx_constructor_gui_data* parent_data,
+ int factory_index
+ )
+ {
+ assert(parent_data != 0);
+ // make the book ctrl
+ BookCtrl* book_ctl = new BookCtrl(
+ parent_data->get_window(),
+ wxID_ANY
+ );
+ // add the widget to the sizer
+ parent_data->get_sizer()->Add(book_ctl, 0, wxEXPAND);
+ // return the pointer
+ return book_ctl;
+ }
+ // list of parameters for the individual pages
+ ::std::list<wx_constructor_gui_data> params;
+
+ struct param_list_maker
+ {
+ wxString& str_ref;
+ bool first_param;
+
+ param_list_maker(wxString& _ref)
+ : str_ref(_ref)
+ , first_param(true)
+ { }
+
+ template <
+ typename Parameters,
+ typename ParamIndex
+ >
+ inline void operator()(
+ Parameters* ,
+ ParamIndex pi
+ )
+ {
+ // if it's not the first parameter
+ // prepend the comma
+ if(first_param) first_param = false;
+ else str_ref.append(wxT(", "));
+ // append the type name
+ str_ref.append(
+ Parameters::param<ParamIndex>::type::base_name()
+ );
+ // append the space
+ str_ref.append(wxT(" "));
+ str_ref.append(
+ Parameters::base_param_name(pi)
+ );
+ }
+ };
+
+public:
+ wx_constructor_gui(
+ wx_constructor_gui_data* data,
+ int factory_index
+ ): parent_data(data)
+ , book_ctl(make_book_ctl(parent_data, factory_index))
+ { }
+
+ template <class Product, class ConstructorIndex>
+ inline wx_constructor_gui_data* param(Product*, ConstructorIndex ci)
+ {
+ assert(parent_data);
+ // create a panel and a sizer for the page
+ wxPanel* panel = new wxPanel(book_ctl, wxID_ANY);
+ wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
+ panel->SetSizer(sizer);
+ //
+ wxString label(
+ BOOST_MIRRORED_TYPE(Product)::base_name()
+ );
+ label.append(wxT("("));
+ BOOST_MIRRORED_CONSTRUCTORS(
+ Product
+ )::constructor<
+ ConstructorIndex
+ >::params::for_each(param_list_maker(label));
+ label.append(wxT(")"));
+ // add a new page
+ book_ctl->AddPage(panel, label);
+ //
+ params.push_back(
+ wx_constructor_gui_data(
+ panel,
+ sizer,
+ parent_data
+ )
+ );
+ return ¶ms.back();
+ }
+
+ inline int index(void)
+ {
+ return book_ctl->GetSelection();
+ }
+
+};
+
+
+} // namespace utils
+} // namespace mirror
+} // namespace boost
+
+#endif //include guard
+
Added: sandbox/mirror/boost/mirror/factory/wx_constructor_gui/utils.hpp
==============================================================================
--- (empty file)
+++ sandbox/mirror/boost/mirror/factory/wx_constructor_gui/utils.hpp 2009-02-09 13:14:48 EST (Mon, 09 Feb 2009)
@@ -0,0 +1,85 @@
+/**
+ * \file boost/mirror/factory/wx_constructor_gui/utils.hpp
+ *
+ *
+ * Copyright 2008 Matus Chochlik. Distributed under the Boost
+ * Software License, Version 1.0. (See accompanying file
+ * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ */
+
+#ifndef BOOST_MIRROR_FACTORY_WX_CONSTRUCTOR_GUI_UTILS_HPP
+#define BOOST_MIRROR_FACTORY_WX_CONSTRUCTOR_GUI_UTILS_HPP
+
+#include <wx/wx.h>
+#include <wx/sizer.h>
+
+namespace boost {
+namespace mirror {
+namespace utils {
+
+class wx_constructor_gui_utils
+{
+protected:
+ // makes the data
+ template <class CtrlMaker, class Context, class ConstrIndex, class ParamIndex>
+ static inline typename CtrlMaker::result_type* make_ctl(
+ CtrlMaker make_ctl,
+ wx_constructor_gui_data* parent_data,
+ Context* pc,
+ ConstrIndex ci,
+ ParamIndex pi
+ )
+ {
+ // we need the parent data
+ assert(parent_data != 0);
+ // make a label for the static box sizer
+ wxString label(
+ BOOST_MIRRORED_CONSTRUCTORS(
+ Context
+ )::base_param_name(ci, pi)
+ );
+ // the panel which will be the parent of
+ // the child widgets
+ wxPanel* panel = new wxPanel(
+ parent_data->get_window(),
+ wxID_ANY
+ );
+ // the sizer
+ wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);
+ panel->SetSizer(sizer);
+ // add the panel to the parent sizer
+ parent_data->get_sizer()->Add(
+ panel,
+ 0, //proportion
+ wxEXPAND
+ );
+ //
+ // make the label
+ sizer->Add(
+ new wxStaticText(
+ panel,
+ wxID_ANY,
+ label,
+ wxDefaultPosition,
+ wxDefaultSize,
+ wxALIGN_RIGHT
+ ),
+ 1,
+ wxEXPAND
+ );
+ sizer->AddSpacer(8);
+ typedef typename CtrlMaker::result_type Ctrl;
+ Ctrl* ctl = make_ctl(panel);
+ sizer->Add(ctl, 1);
+ sizer->AddSpacer(8);
+ return ctl;
+ }
+};
+
+
+} // namespace utils
+} // namespace mirror
+} // namespace boost
+
+#endif //include guard
+
Modified: sandbox/mirror/boost/mirror/meta_constructors.hpp
==============================================================================
--- sandbox/mirror/boost/mirror/meta_constructors.hpp (original)
+++ sandbox/mirror/boost/mirror/meta_constructors.hpp 2009-02-09 13:14:48 EST (Mon, 09 Feb 2009)
@@ -30,17 +30,17 @@
#include <boost/preprocessor/wstringize.hpp>
#include <boost/char_type_switch/string.hpp>
+#include <boost/mirror/meta_data_fwd.hpp>
namespace boost {
namespace mirror {
template <class Class /*, class VariantTag*/ >
-struct meta_constructors;
-
+struct meta_constructors_base;
#define BOOST_MIRROR_REG_TEMPLATE_CONSTRUCTORS_BEGIN(TEMPLATE, TEMPL_ARG_COUNT) \
template < BOOST_PP_ENUM_PARAMS(TEMPL_ARG_COUNT, typename T) > \
-struct meta_constructors< \
+struct meta_constructors_base< \
TEMPLATE < BOOST_PP_ENUM_PARAMS(TEMPL_ARG_COUNT, T) > \
> \
{ \
@@ -49,7 +49,7 @@
#define BOOST_MIRROR_REG_CONSTRUCTORS_BEGIN(CLASS) \
template <> \
-struct meta_constructors< CLASS > \
+struct meta_constructors_base< CLASS > \
{ \
typedef mpl::vector0<>
@@ -153,6 +153,86 @@
#undef BOOST_MIRROR_REGISTER_NATIVE_TYPE_CONSTRUCTORS
+template <class Class /*, class VariantTag*/ >
+struct meta_constructors : public meta_constructors_base<Class>
+{
+ typedef meta_constructors_base<Class> base_class;
+ template <class ConstructorIndex>
+ struct constructor
+ {
+ struct params
+ {
+ private:
+ typedef typename mpl::at<
+ typename base_class::param_type_lists,
+ ConstructorIndex
+ >::type type_list;
+ public:
+ template <class ParamIndex>
+ struct param
+ {
+ private:
+ typedef typename mpl::at<
+ type_list,
+ ParamIndex
+ >::type param_type;
+ public:
+ typedef BOOST_MIRRORED_TYPE(param_type)
+ type;
+ };
+
+ typedef mpl::int_<
+ mpl::size< type_list>::value
+ > size;
+
+ template <class CharT, class ParamIndex>
+ inline static const ::std::basic_string<CharT>& get_param_name(
+ mpl::false_ full_or_base,
+ const ::std::char_traits<CharT>& traits,
+ ParamIndex
+ )
+ {
+ return meta_constructors::get_param_name(
+ full_or_base,
+ traits,
+ ConstructorIndex(),
+ ParamIndex()
+ );
+ }
+
+ template <class ParamIndex>
+ inline static const cts::bstring& base_param_name(
+ ParamIndex
+ )
+ {
+ return meta_constructors::base_param_name(
+ ConstructorIndex(),
+ ParamIndex()
+ );
+ }
+
+
+ template <class Functor>
+ static void for_each(Functor f)
+ {
+ call_for_each(f, mpl::int_<0>());
+ }
+ private:
+ template <class Functor, class ParamIndex>
+ static inline void call_for_each(Functor func, ParamIndex pi)
+ {
+ func((params*)0, pi);
+ call_for_each(func, mpl::next<ParamIndex>::type());
+ }
+
+ template <class Functor>
+ static inline void call_for_each(const Functor&, size)
+ {
+ }
+ };
+ };
+};
+
} // namespace mirror
} // namespace boost
Modified: sandbox/mirror/boost/mirror/meta_data_fwd.hpp
==============================================================================
--- sandbox/mirror/boost/mirror/meta_data_fwd.hpp (original)
+++ sandbox/mirror/boost/mirror/meta_data_fwd.hpp 2009-02-09 13:14:48 EST (Mon, 09 Feb 2009)
@@ -148,6 +148,15 @@
>::type
+/** This is a forward declaration of the meta_constructors template
+ */
+template <class Class /*, class VariantTag*/ >
+struct meta_constructors;
+
+#define BOOST_MIRRORED_CONSTRUCTORS(TYPE)\
+ meta_constructors< TYPE >
+
+
} // namespace mirror
} // namespace boost
Added: sandbox/mirror/libs/mirror/build/msvc/mirror_examples/fact_simple_gui/fact_simple_gui.vcproj
==============================================================================
--- (empty file)
+++ sandbox/mirror/libs/mirror/build/msvc/mirror_examples/fact_simple_gui/fact_simple_gui.vcproj 2009-02-09 13:14:48 EST (Mon, 09 Feb 2009)
@@ -0,0 +1,200 @@
+<?xml version="1.0" encoding="windows-1250"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="9,00"
+ Name="fact_simple_gui"
+ ProjectGUID="{41A930A9-ED86-4ABA-9FF7-997FBC0B88FA}"
+ RootNamespace="fact_simple_gui"
+ Keyword="Win32Proj"
+ TargetFrameworkVersion="196613"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="$(SolutionDir)/../../../../../../_build_$(SolutionName)/$(ConfigurationName)"
+ IntermediateDirectory="$(OutDir)/$(ProjectName)"
+ ConfigurationType="1"
+ CharacterSet="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories="$(BOOST_ROOT);$(MIRROR_ROOT);$(WXWIDGETS_ROOT)\include;$(WXWIDGETS_ROOT)\include\msvc"
+ PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
+ MinimalRebuild="true"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="3"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ DebugInformationFormat="4"
+ DisableSpecificWarnings="4996"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="wxbase$(WXWIDGETS_VERSION)ud.lib wxmsw$(WXWIDGETS_VERSION)ud_core.lib wxmsw$(WXWIDGETS_VERSION)ud_adv.lib comctl32.lib winmm.lib advapi32.lib rpcrt4.lib"
+ LinkIncremental="2"
+ AdditionalLibraryDirectories="$(WXWIDGETS_ROOT)\lib\vc_lib"
+ GenerateDebugInformation="true"
+ SubSystem="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="$(SolutionDir)/../../../../../../_build_$(SolutionName)/$(ConfigurationName)"
+ IntermediateDirectory="$(OutDir)/$(ProjectName)"
+ ConfigurationType="1"
+ CharacterSet="1"
+ WholeProgramOptimization="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="2"
+ EnableIntrinsicFunctions="true"
+ AdditionalIncludeDirectories="$(BOOST_ROOT);$(MIRROR_ROOT);$(WXWIDGETS_ROOT)\include;$(WXWIDGETS_ROOT)\include\msvc"
+ PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
+ RuntimeLibrary="2"
+ EnableFunctionLevelLinking="true"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="wxbase28ud.lib wxmsw28ud_core.lib wxmsw28ud_adv.lib comctl32.lib winmm.lib advapi32.lib rpcrt4.lib"
+ LinkIncremental="1"
+ AdditionalLibraryDirectories="$(WXWIDGETS_ROOT)\lib\vc_lib"
+ GenerateDebugInformation="true"
+ SubSystem="2"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+ >
+ <File
+ RelativePath="..\..\..\..\example\factories\simple_gui.cpp"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc;xsd"
+ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
+ >
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
+ UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
+ >
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
Modified: sandbox/mirror/libs/mirror/build/msvc/mirror_examples/mirror_examples.sln
==============================================================================
--- sandbox/mirror/libs/mirror/build/msvc/mirror_examples/mirror_examples.sln (original)
+++ sandbox/mirror/libs/mirror/build/msvc/mirror_examples/mirror_examples.sln 2009-02-09 13:14:48 EST (Mon, 09 Feb 2009)
@@ -23,6 +23,8 @@
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fact_tetrahedron", "fact_tetrahedron\fact_tetrahedron.vcproj", "{48B5F7B6-1E06-4495-90F9-AA33E43353C3}"
EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fact_simple_gui", "fact_simple_gui\fact_simple_gui.vcproj", "{41A930A9-ED86-4ABA-9FF7-997FBC0B88FA}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
@@ -73,6 +75,10 @@
{48B5F7B6-1E06-4495-90F9-AA33E43353C3}.Debug|Win32.Build.0 = Debug|Win32
{48B5F7B6-1E06-4495-90F9-AA33E43353C3}.Release|Win32.ActiveCfg = Release|Win32
{48B5F7B6-1E06-4495-90F9-AA33E43353C3}.Release|Win32.Build.0 = Release|Win32
+ {41A930A9-ED86-4ABA-9FF7-997FBC0B88FA}.Debug|Win32.ActiveCfg = Debug|Win32
+ {41A930A9-ED86-4ABA-9FF7-997FBC0B88FA}.Debug|Win32.Build.0 = Debug|Win32
+ {41A930A9-ED86-4ABA-9FF7-997FBC0B88FA}.Release|Win32.ActiveCfg = Release|Win32
+ {41A930A9-ED86-4ABA-9FF7-997FBC0B88FA}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Modified: sandbox/mirror/libs/mirror/example/factories/input_ui.hpp
==============================================================================
--- sandbox/mirror/libs/mirror/example/factories/input_ui.hpp (original)
+++ sandbox/mirror/libs/mirror/example/factories/input_ui.hpp 2009-02-09 13:14:48 EST (Mon, 09 Feb 2009)
@@ -124,7 +124,8 @@
names[factory_index] << ::std::endl;
}
- inline int param(void) const
+ template <class Product, class ConstructorIndex>
+ inline int param(Product* pp, ConstructorIndex ci) const
{
return tabs+1;
}
Added: sandbox/mirror/libs/mirror/example/factories/simple_gui.cpp
==============================================================================
--- (empty file)
+++ sandbox/mirror/libs/mirror/example/factories/simple_gui.cpp 2009-02-09 13:14:48 EST (Mon, 09 Feb 2009)
@@ -0,0 +1,85 @@
+/**
+ * \file examples/factories/simple_gui.cpp
+ *
+ * This example shows how to use the configurable factory
+ * with a input user interface implementation to generically
+ * construct an instance of classes with non default constructors.
+ *
+ * Copyright 2008 Matus Chochlik. Distributed under the Boost
+ * Software License, Version 1.0. (See accompanying file
+ * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ */
+
+#include <boost/mirror/factory/wx_constructor_gui.hpp>
+#include "./tetrahedron.hpp"
+
+
+namespace boost {
+namespace mirror {
+namespace utils {
+
+} // namespace utils
+} // namespace mirror
+} // namespace boost
+
+
+class simple_gui_test_app : public wxApp
+{
+ virtual bool OnInit();
+};
+
+IMPLEMENT_APP(simple_gui_test_app)
+
+
+bool simple_gui_test_app::OnInit()
+{
+ using namespace ::boost::mirror;
+ // we'll be constructing the tetrahedron
+ typedef ::test::tetrahedron T;
+ // we'll use the wxWidgets-based dialog
+ utils::wx_factory_dialog<T> fact(
+ 0,
+ wxT("GUI test")
+ );
+ try
+ {
+ // use the factory to create a tetrahedron
+ T* t = fact.create();
+ // if we were successful
+ if(t)
+ {
+ // show some info
+ wxString message;
+ message.Printf(
+ wxT("Area of the base: %f\nVolume: %f"),
+ t->base.area(),
+ t->volume()
+ );
+ wxMessageBox(
+ message,
+ wxT("Tetrahedron info")
+ );
+ // and delete the instance
+ delete t;
+ }
+ }
+ catch(::std::exception& e)
+ {
+ wxString message;
+ wxMessageBox(
+ wxString::FromAscii(e.what()),
+ wxT("Construction failed"),
+ wxOK | wxICON_ERROR
+ );
+ }
+ catch(...)
+ {
+ wxMessageBox(
+ wxT("Unknown error"),
+ wxT("Construction failed"),
+ wxOK | wxICON_ERROR
+ );
+ }
+ // finito
+ return true;
+}
\ No newline at end of file
Modified: sandbox/mirror/libs/mirror/example/factories/tetrahedron.cpp
==============================================================================
--- sandbox/mirror/libs/mirror/example/factories/tetrahedron.cpp (original)
+++ sandbox/mirror/libs/mirror/example/factories/tetrahedron.cpp 2009-02-09 13:14:48 EST (Mon, 09 Feb 2009)
@@ -10,141 +10,13 @@
* LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*/
-#include <math.h>
#include <boost/char_type_switch/iostream.hpp>
#include <boost/mirror/factory.hpp>
#include <boost/mirror/meta_type.hpp>
#include "./input_ui.hpp"
-
-namespace test {
-
-struct vector
-{
- double x,y,z;
-
- vector(double _x, double _y, double _z)
- : x(_x)
- , y(_y)
- , z(_z)
- { }
-
- vector(void)
- : x(0.0)
- , y(0.0)
- , z(0.0)
- { }
-
- friend vector operator + (const vector& a, const vector& b)
- {
- return vector(a.x + b.x, a.y + b.y, a.z + b.z);
- }
-
- friend vector operator - (const vector& a, const vector& b)
- {
- return vector(a.x - b.x, a.y - b.y, a.z - b.z);
- }
-
- // cross product
- friend vector operator % (const vector& a, const vector& b)
- {
- return vector(
- a.y * b.z - a.z * b.y,
- a.z * b.x - a.x * b.z,
- a.x * b.y - a.y * b.x
- );
- }
-
- // dot product
- friend double operator * (const vector& a, const vector& b)
- {
- return a.x*b.x + a.y*b.y + a.z*b.z;
- }
-
- double length(void) const
- {
- return sqrt(x*x + y*y + z*z);
- }
-};
-
-struct triangle
-{
- vector a, b, c;
-
- triangle(const vector& _a, const vector& _b, const vector& _c)
- : a(_a)
- , b(_b)
- , c(_c)
- { }
-
-
- double area(void) const
- {
- return ((b-a)%(c-a)).length()/2.0;
- }
-};
-
-struct tetrahedron
-{
- triangle base;
- vector apex;
-
- tetrahedron(const triangle& _base, const vector& _apex)
- : base(_base)
- , apex(_apex)
- { }
-
- const vector& a(void) const {return base.a;}
- const vector& b(void) const {return base.b;}
- const vector& c(void) const {return base.c;}
- const vector& d(void) const {return apex;}
-
- double volume(void) const
- {
- return fabs(((a()-d())*((b()-d())%(c()-d()))))/6.0;
- }
-};
-
-
-} // namespace test
-
-
-namespace boost {
-namespace mirror {
-
-// register the ::test namespace
-BOOST_MIRROR_REG_NAMESPACE( (test) )
-
-// register the vector, triangle and tetrahedron classes
-BOOST_MIRROR_REG_TYPE( ::test, vector)
-BOOST_MIRROR_REG_TYPE( ::test, triangle)
-BOOST_MIRROR_REG_TYPE( ::test, tetrahedron)
-
-// register the constructors of ::test::vector
-BOOST_MIRROR_REG_CONSTRUCTORS_BEGIN( ::test::vector )
- BOOST_MIRROR_REG_CONSTRUCTOR(0,
- ((double)(x))((double)(y))((double)(z))
- )
- BOOST_MIRROR_REG_DEFAULT_CONSTRUCTOR(1)
-BOOST_MIRROR_REG_CONSTRUCTORS_END
-
-// register the constructor of ::test::triangle
-BOOST_MIRROR_REG_CONSTRUCTORS_BEGIN( ::test::triangle )
- BOOST_MIRROR_REG_CONSTRUCTOR(0,
- ((::test::vector)(a))((::test::vector)(b))((::test::vector)(c))
- )
-BOOST_MIRROR_REG_CONSTRUCTORS_END
-
-// register the constructor of ::test::tetrahedron
-BOOST_MIRROR_REG_CONSTRUCTORS_BEGIN( ::test::tetrahedron )
- BOOST_MIRROR_REG_CONSTRUCTOR(0,
- ((::test::triangle)(base))((::test::vector)(apex))
- )
-BOOST_MIRROR_REG_CONSTRUCTORS_END
-
-} // namespace mirror
-} // namespace boost
+#include "./tetrahedron.hpp"
int main(void)
@@ -160,9 +32,8 @@
// it's volume and base area
::test::tetrahedron t(f());
// ... and print them out
- cout << BOOST_CTS_LIT("the volume is ") << t.volume() << endl;
- cout << BOOST_CTS_LIT("the area of the base is ") << t.base.area() << endl;
+ cts::bcout() << BOOST_CTS_LIT("the volume is ") << t.volume() << endl;
+ cts::bcout() << BOOST_CTS_LIT("the area of the base is ") << t.base.area() << endl;
//
return 0;
}
-
Added: sandbox/mirror/libs/mirror/example/factories/tetrahedron.hpp
==============================================================================
--- (empty file)
+++ sandbox/mirror/libs/mirror/example/factories/tetrahedron.hpp 2009-02-09 13:14:48 EST (Mon, 09 Feb 2009)
@@ -0,0 +1,159 @@
+/**
+ * \file examples/factories/tetrahedron.hpp
+ *
+ * Two classes used in some of the examples showing
+ * the use of meta-constructors and factories
+ *
+ * Copyright 2008 Matus Chochlik. Distributed under the Boost
+ * Software License, Version 1.0. (See accompanying file
+ * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ */
+
+#ifndef BOOST_MIRROR_EXAMPLES_FACTORIES_TETRAHEDRON_HPP
+#define BOOST_MIRROR_EXAMPLES_FACTORIES_TETRAHEDRON_HPP
+
+#include <math.h>
+#include <boost/mirror/meta_class.hpp>
+
+namespace test {
+
+struct vector
+{
+ double x,y,z;
+
+ vector(double _x, double _y, double _z)
+ : x(_x)
+ , y(_y)
+ , z(_z)
+ { }
+
+ vector(double _w)
+ : x(_w)
+ , y(_w)
+ , z(_w)
+ { }
+
+ vector(void)
+ : x(0.0)
+ , y(0.0)
+ , z(0.0)
+ { }
+
+ friend vector operator + (const vector& a, const vector& b)
+ {
+ return vector(a.x + b.x, a.y + b.y, a.z + b.z);
+ }
+
+ friend vector operator - (const vector& a, const vector& b)
+ {
+ return vector(a.x - b.x, a.y - b.y, a.z - b.z);
+ }
+
+ // cross product
+ friend vector operator % (const vector& a, const vector& b)
+ {
+ return vector(
+ a.y * b.z - a.z * b.y,
+ a.z * b.x - a.x * b.z,
+ a.x * b.y - a.y * b.x
+ );
+ }
+
+ // dot product
+ friend double operator * (const vector& a, const vector& b)
+ {
+ return a.x*b.x + a.y*b.y + a.z*b.z;
+ }
+
+ double length(void) const
+ {
+ return sqrt(x*x + y*y + z*z);
+ }
+};
+
+struct triangle
+{
+ vector a, b, c;
+
+ triangle(const vector& _a, const vector& _b, const vector& _c)
+ : a(_a)
+ , b(_b)
+ , c(_c)
+ { }
+
+ triangle(void){ }
+
+
+ double area(void) const
+ {
+ return ((b-a)%(c-a)).length()/2.0;
+ }
+};
+
+struct tetrahedron
+{
+ triangle base;
+ vector apex;
+
+ tetrahedron(const triangle& _base, const vector& _apex)
+ : base(_base)
+ , apex(_apex)
+ { }
+
+ const vector& a(void) const {return base.a;}
+ const vector& b(void) const {return base.b;}
+ const vector& c(void) const {return base.c;}
+ const vector& d(void) const {return apex;}
+
+ double volume(void) const
+ {
+ return fabs(((a()-d())*((b()-d())%(c()-d()))))/6.0;
+ }
+};
+
+
+} // namespace test
+
+
+namespace boost {
+namespace mirror {
+
+// register the ::test namespace
+BOOST_MIRROR_REG_NAMESPACE( (test) )
+
+// register the vector, triangle and tetrahedron classes
+BOOST_MIRROR_REG_TYPE( ::test, vector)
+BOOST_MIRROR_REG_TYPE( ::test, triangle)
+BOOST_MIRROR_REG_TYPE( ::test, tetrahedron)
+
+// register the constructors of ::test::vector
+BOOST_MIRROR_REG_CONSTRUCTORS_BEGIN( ::test::vector )
+ BOOST_MIRROR_REG_CONSTRUCTOR(0,
+ ((double)(x))((double)(y))((double)(z))
+ )
+ BOOST_MIRROR_REG_CONSTRUCTOR(1,
+ ((double)(w))
+ )
+ BOOST_MIRROR_REG_DEFAULT_CONSTRUCTOR(2)
+BOOST_MIRROR_REG_CONSTRUCTORS_END
+
+// register the constructor of ::test::triangle
+BOOST_MIRROR_REG_CONSTRUCTORS_BEGIN( ::test::triangle )
+ BOOST_MIRROR_REG_CONSTRUCTOR(0,
+ ((::test::vector)(a))((::test::vector)(b))((::test::vector)(c))
+ )
+ BOOST_MIRROR_REG_DEFAULT_CONSTRUCTOR(1)
+BOOST_MIRROR_REG_CONSTRUCTORS_END
+
+// register the constructor of ::test::tetrahedron
+BOOST_MIRROR_REG_CONSTRUCTORS_BEGIN( ::test::tetrahedron )
+ BOOST_MIRROR_REG_CONSTRUCTOR(0,
+ ((::test::triangle)(base))((::test::vector)(apex))
+ )
+BOOST_MIRROR_REG_CONSTRUCTORS_END
+
+} // namespace mirror
+} // namespace boost
+
+#endif
+
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