|
Boost-Commit : |
From: chochlik_at_[hidden]
Date: 2008-04-18 13:31:40
Author: matus.chochlik
Date: 2008-04-18 13:31:39 EDT (Fri, 18 Apr 2008)
New Revision: 44548
URL: http://svn.boost.org/trac/boost/changeset/44548
Log:
WARNING: this revision might not work as expected
- Added two new examples, both are still incomplete
- Added support for introspection of inherited member attributes (incomplete and buggy)
Added:
sandbox/mirror/boost/mirror/reflects_virtual_inheritance.hpp (contents, props changed)
sandbox/mirror/libs/examples/registering/virtual_bases.cpp (contents, props changed)
sandbox/mirror/libs/examples/serialization/
sandbox/mirror/libs/examples/serialization/cube.cpp (contents, props changed)
Text files modified:
sandbox/mirror/boost/mirror/meta_attribs_base.hpp | 1
sandbox/mirror/boost/mirror/meta_class.hpp | 153 ++++++++++++++++++++++++++++++++++++---
sandbox/mirror/boost/mirror/meta_data_fwd.hpp | 21 ++++
sandbox/mirror/boost/mirror/meta_inheritance.hpp | 134 +++++++++++++++++++++++++---------
sandbox/mirror/libs/examples/registering/classes.cpp | 1
5 files changed, 258 insertions(+), 52 deletions(-)
Modified: sandbox/mirror/boost/mirror/meta_attribs_base.hpp
==============================================================================
--- sandbox/mirror/boost/mirror/meta_attribs_base.hpp (original)
+++ sandbox/mirror/boost/mirror/meta_attribs_base.hpp 2008-04-18 13:31:39 EDT (Fri, 18 Apr 2008)
@@ -211,6 +211,7 @@
*/
#define BOOST_MIRROR_REG_CLASS_ATTRIBS_END \
type_list; \
+struct size : public mpl::size<type_list>{ };\
};
} // namespace mirror
} // namespace boost
Modified: sandbox/mirror/boost/mirror/meta_class.hpp
==============================================================================
--- sandbox/mirror/boost/mirror/meta_class.hpp (original)
+++ sandbox/mirror/boost/mirror/meta_class.hpp 2008-04-18 13:31:39 EDT (Fri, 18 Apr 2008)
@@ -10,36 +10,159 @@
#ifndef BOOST_MIRROR_META_CLASS_HPP
#define BOOST_MIRROR_META_CLASS_HPP
+#include <boost/mpl/if.hpp>
+#include <boost/mpl/accumulate.hpp>
+#include <boost/mpl/remove_if.hpp>
+#include <boost/mpl/insert_range.hpp>
+#include <boost/mpl/joint_view.hpp>
+//
// basic meta types
#include <boost/mirror/meta_type.hpp>
// reflection of class inheritance
#include <boost/mirror/meta_inheritance.hpp>
+// inheritance trait
+#include <boost/mirror/reflects_virtual_inheritance.hpp>
// reflection of class member attributes
#include <boost/mirror/meta_attributes.hpp>
namespace boost {
namespace mirror {
-namespace detail {
-
- /** Because one class can have several different meta_classes
- * we require some means to distinguish between them when
- * selecting the proper meta_class<> template instantiation.
- * This type is used to mark the default meta-class variant.
- */
- struct default_meta_class_variant;
-} //namespace detail
-
/** Meta class - specializes the meta_type for classes
*/
template <
- class a_class,
- class variant_tag = detail::default_meta_class_variant
+ class reflected_class,
+ class variant_tag
>
-struct meta_class : public meta_type<a_class>
+struct meta_class : public meta_type<reflected_class>
{
- typedef typename meta_base_classes<a_class, variant_tag> base_classes;
- typedef typename meta_class_attributes<a_class, variant_tag> attributes;
+ /** The base classes of a class.
+ * The member base_classes::list is a mpl::vector of
+ * meta_inheritance<> specializations, one for every
+ * base class.
+ */
+ typedef meta_base_classes<reflected_class, variant_tag> base_classes;
+
+ /** The member attributes of the class (not includeing the inherited
+ * member attribs.
+ * The attributes::type_list is a mpl::vector of types
+ * of the attributes.
+ *
+ * The attributes::get(mpl::int_<I>) functions allow to get the value
+ * of the I-th attribute, if the attribute is not write-only, where:
+ * 0 <= I < N; N = $mpl::size<attributes::type_list>::value
+ *
+ * The attributes::set(mpl::int_<I>), T val) functions allow to set
+ * the value of the I-th attribute, if it's not read-only, where
+ * 0 <= I < N; N = $mpl::size<attributes::type_list>::value
+ *
+ */
+ typedef meta_class_attributes<reflected_class, variant_tag> attributes;
+
+ /** This is basically the same as the "attributes" structure
+ * but allows to work with all member attributes including
+ * the inherited ones.
+ */
+ struct all_attributes
+ {
+ /** This struct "hides" the internal helpers
+ */
+ struct detail
+ {
+ /** The list of non-virtual base classes in the same
+ * order as registered.
+ */
+ typedef typename mpl::remove_if<
+ typename base_classes::list,
+ mpl::lambda<
+ mpl::not_<reflects_virtual_inheritance<mpl::_1> >
+ >::type
+ >::type list_of_regular_base_classes;
+
+ /** The list of all virtual base classes with duplicates.
+ */
+ typedef typename mpl::remove_if<
+ typename base_classes::list,
+ mpl::lambda<
+ reflects_virtual_inheritance<mpl::_1>
+ >::type
+ >::type list_of_all_virtual_base_classes;
+
+ /** The list of virtual base classes with duplicates
+ * removed.
+ * TODO:
+ */
+ typedef typename list_of_all_virtual_base_classes
+ list_of_virtual_base_classes;
+
+ /** This tells whether the virtual base classes
+ * go first or last into the list of base classes.
+ */
+ typedef true_type virtual_first;
+
+ /** The list of base classes of the reflected_class.
+ */
+ typedef typename mpl::joint_view<
+ typename mpl::if_<
+ virtual_first,
+ list_of_virtual_base_classes,
+ list_of_regular_base_classes
+ >::type,
+ typename mpl::if_<
+ virtual_first,
+ list_of_regular_base_classes,
+ list_of_virtual_base_classes
+ >::type
+ >::type list_of_base_classes;
+
+ /** This template gets the list of attributes types
+ * when given a meta_inheritance specialization.
+ */
+ template <class meta_inheritance>
+ struct get_bc_all_attrib_tl
+ {
+ typedef typename meta_inheritance::meta_class::all_attributes::type_list type;
+ };
+
+ /** Definition of a list containing the lists
+ * of all_attributes from the base classes.
+ */
+ typedef typename mpl::accumulate<
+ typename list_of_base_classes,
+ mpl::vector<>,
+ mpl::push_back<
+ mpl::_1,
+ mpl::lambda<get_bc_all_attrib_tl<mpl::_2> >
+ >
+ >::type att_type_lists_of_base_classes;
+
+ /** Defintion of a mpl::vector containing the member
+ * attributes inherited from the base classes.
+ */
+ typedef typename mpl::accumulate<
+ att_type_lists_of_base_classes,
+ mpl::vector<>,
+ mpl::insert_range<
+ mpl::_1,
+ mpl::end<mpl::_1>,
+ mpl::_2
+ >
+ >::type inherited_attrib_type_list;
+ }; // struct detail
+
+ /** The list of types of all attributes including
+ * the inherited ones.
+ */
+ typedef typename mpl::joint_view<
+ typename detail::inherited_attrib_type_list,
+ typename meta_class<reflected_class, variant_tag>::attributes::type_list
+ >::type type_list;
+
+ /** The size of the type_list, i.e. the count of all attributes
+ */
+ struct size : public mpl::size<type_list> { };
+ };
+
};
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 2008-04-18 13:31:39 EDT (Fri, 18 Apr 2008)
@@ -57,9 +57,23 @@
+namespace detail {
+
+ /** Because one class can have several different meta_classes
+ * we require some means to distinguish between them when
+ * selecting the proper meta_class<> template instantiation.
+ * This type is used to mark the default meta-class variant.
+ */
+ struct default_meta_class_variant{ };
+} //namespace detail
+
+
/** Meta-class template forward declaration
*/
-template <class a_class, class variant_tag>
+template <
+ class a_class,
+ class variant_tag = detail::default_meta_class_variant
+>
struct meta_class;
/** Macro that expands into the meta_class for the
@@ -72,7 +86,10 @@
* given type or class.
*/
#define BOOST_MIRROR_REFLECT_CLASS_VT(CLASS, VARIANT_TAG) \
- ::boost::mirror::meta_class<CLASS, VARIANT_TAG>
+ ::boost::mirror::meta_class<\
+ CLASS, \
+ VARIANT_TAG\
+>
Modified: sandbox/mirror/boost/mirror/meta_inheritance.hpp
==============================================================================
--- sandbox/mirror/boost/mirror/meta_inheritance.hpp (original)
+++ sandbox/mirror/boost/mirror/meta_inheritance.hpp 2008-04-18 13:31:39 EDT (Fri, 18 Apr 2008)
@@ -10,6 +10,8 @@
#ifndef BOOST_MIRROR_META_INHERITANCE_HPP
#define BOOST_MIRROR_META_INHERITANCE_HPP
+// forward declarations
+#include <boost/mirror/meta_data_fwd.hpp>
// access specifiers
#include <boost/mirror/access_spec.hpp>
// inheritance specifiers
@@ -24,57 +26,116 @@
/** helper template instances of which define the inheritance type,
* access specifiers and base class of a meta_class
*/
-template <class a_class, typename access_spec, typename inheritance_spec>
-struct meta_inheritance_defs
+template <
+ class the_base_class,
+ typename access_spec,
+ typename inheritance_spec
+> struct meta_inheritance_defs
{
typedef inheritance_spec inheritance_specifier;
typedef access_spec access_specifier;
- typedef a_class base_class;
+ typedef the_base_class base_class;
+ typedef BOOST_MIRROR_REFLECT_CLASS(the_base_class) meta_class;
};
/** This template stores the inheritance type and access specifier
* of a base class for a derived class
*/
-template <class a_class, typename access_spec, typename inheritance_spec>
-struct meta_inheritance_spec;
-
-template <class a_class>
-struct meta_inheritance_spec<a_class, private_, virtual_base_>
-: meta_inheritance_defs<a_class, private_, virtual_base_> { };
-
-template <class a_class>
-struct meta_inheritance_spec<a_class, protected_, virtual_base_>
-: meta_inheritance_defs<a_class, protected_, virtual_base_> { };
-
-template <class a_class>
-struct meta_inheritance_spec<a_class, public_, virtual_base_>
-: meta_inheritance_defs<a_class, public_, virtual_base_> { };
-
-template <class a_class>
-struct meta_inheritance_spec<a_class, private_, nonvirtual_base_>
-: meta_inheritance_defs<a_class, private_, nonvirtual_base_> { };
-
-template <class a_class>
-struct meta_inheritance_spec<a_class, protected_, nonvirtual_base_>
-: meta_inheritance_defs<a_class, protected_, nonvirtual_base_> { };
-
-template <class a_class>
-struct meta_inheritance_spec<a_class, public_, nonvirtual_base_>
-: meta_inheritance_defs<a_class, public_, nonvirtual_base_> { };
+template <
+ class the_base_class,
+ typename access_spec,
+ typename inheritance_spec
+> struct meta_inheritance_spec;
+
+template <class the_base_class>
+struct meta_inheritance_spec<
+ the_base_class,
+ private_,
+ virtual_base_
+> : meta_inheritance_defs<
+ the_base_class,
+ private_,
+ virtual_base_
+> { };
+
+template <class the_base_class>
+struct meta_inheritance_spec<
+ the_base_class,
+ protected_,
+ virtual_base_
+> : meta_inheritance_defs<
+ the_base_class,
+ protected_,
+ virtual_base_
+> { };
+
+template <class the_base_class>
+struct meta_inheritance_spec<
+ the_base_class,
+ public_,
+ virtual_base_
+> : meta_inheritance_defs<
+ the_base_class,
+ public_,
+ virtual_base_
+> { };
+
+template <class the_base_class>
+struct meta_inheritance_spec<
+ the_base_class,
+ private_,
+ nonvirtual_base_
+> : meta_inheritance_defs<
+ the_base_class,
+ private_,
+ nonvirtual_base_
+> { };
+
+template <class the_base_class>
+struct meta_inheritance_spec<
+ the_base_class,
+ protected_,
+ nonvirtual_base_
+> : meta_inheritance_defs<
+ the_base_class,
+ protected_,
+ nonvirtual_base_
+> { };
+
+template <class the_base_class>
+struct meta_inheritance_spec<
+ the_base_class,
+ public_,
+ nonvirtual_base_
+> : meta_inheritance_defs<
+ the_base_class,
+ public_,
+ nonvirtual_base_
+> { };
/** This template stores the inheritance type and access specifier
* of a base class for a derived class
*/
template <
- class a_class,
- typename access_spec = class_kind_default_access<meta_class_kind<a_class>::result>::specifier,
+ class the_base_class,
+ typename access_spec = class_kind_default_access<
+ meta_class_kind<the_base_class>::result
+ >::specifier,
typename inheritance_spec = nonvirtual_base_
>
-struct meta_inheritance : meta_inheritance_spec<a_class, access_spec, inheritance_spec>{ };
+struct meta_inheritance
+: meta_inheritance_spec<
+ the_base_class,
+ access_spec,
+ inheritance_spec
+>{ };
/** Default (empty) list of base classes of a meta_class
*/
-template <class a_class, class variant_tag = detail::default_meta_class_variant>
+template <
+ class reflected_class,
+ class variant_tag = detail::default_meta_class_variant
+>
struct meta_base_classes
{
typedef mpl::vector<> list;
@@ -85,8 +146,10 @@
* of the given class
*/
#define BOOST_MIRROR_REG_BASE_CLASSES_BEGIN(A_CLASS) \
- template <> struct meta_base_classes<A_CLASS, detail::default_meta_class_variant> \
- { \
+ template <> struct meta_base_classes<\
+ A_CLASS, \
+ detail::default_meta_class_variant \
+ > { \
typedef mpl::vector<
/** This macro declares that the A_BASE_CLASS class is the i-th
@@ -118,6 +181,7 @@
*/
#define BOOST_MIRROR_REG_BASE_CLASSES_END \
> list; \
+ struct size : public mpl::size<list>{ };\
};
/** This macro registers a the A_BASE_CLASS class
Added: sandbox/mirror/boost/mirror/reflects_virtual_inheritance.hpp
==============================================================================
--- (empty file)
+++ sandbox/mirror/boost/mirror/reflects_virtual_inheritance.hpp 2008-04-18 13:31:39 EDT (Fri, 18 Apr 2008)
@@ -0,0 +1,53 @@
+/**
+ * \file boost/mirror/reflects_virtual_inheritance.hpp
+ * Meta function that returns true if the given meta-inheritance
+ * reflects virtual inheritance.
+ *
+ * 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_META_REFLECTS_VIRTUAL_INHERITANCE_HPP
+#define BOOST_MIRROR_META_REFLECTS_VIRTUAL_INHERITANCE_HPP
+
+// true type/false type for trait templates
+#include <boost/type_traits/integral_constant.hpp>
+#include <boost/mirror/meta_inheritance.hpp>
+
+namespace boost {
+namespace mirror {
+
+template <class meta_object>
+struct reflects_virtual_inheritance;
+
+template <
+ class base_class,
+ typename access_spec
+>
+struct reflects_virtual_inheritance<
+ meta_inheritance<
+ base_class,
+ access_spec,
+ virtual_base_
+ >
+> : public true_type{ };
+
+template <
+ class base_class,
+ typename access_spec
+>
+struct reflects_virtual_inheritance<
+ meta_inheritance<
+ base_class,
+ access_spec,
+ nonvirtual_base_
+ >
+> : public false_type{ };
+
+
+} // namespace mirror
+} // namespace boost
+
+#endif //include guard
+
Modified: sandbox/mirror/libs/examples/registering/classes.cpp
==============================================================================
--- sandbox/mirror/libs/examples/registering/classes.cpp (original)
+++ sandbox/mirror/libs/examples/registering/classes.cpp 2008-04-18 13:31:39 EDT (Fri, 18 Apr 2008)
@@ -365,6 +365,7 @@
using ::test::stuff::detail::bar_base;
//
// use the pretty printer to print out into about the given types
+ //
// pointer to native type
bcout << "|01| " << endl << pretty_printer<BOOST_MIRROR_REFLECT_TYPE(double*)>() << endl;
// a class defined in a namespace
Added: sandbox/mirror/libs/examples/registering/virtual_bases.cpp
==============================================================================
--- (empty file)
+++ sandbox/mirror/libs/examples/registering/virtual_bases.cpp 2008-04-18 13:31:39 EDT (Fri, 18 Apr 2008)
@@ -0,0 +1,153 @@
+/**
+ * \file examples/registering/virtual_bases.cpp
+ * Example of registering virtual base classes
+ * and using the meta_class<>::all_attributes
+ *
+ * NOTE: if You are not familiar with namespace and type
+ * registration and reflection, You should probably
+ * see examples/registering/namespaces.cpp,
+ * examples/registering/classes.cpp and
+ * examples/registering/types.cpp first.
+ *
+ * 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 <assert.h>
+#include <math.h>
+
+#include <boost/mpl/list.hpp>
+#include <boost/mpl/for_each.hpp>
+#include <boost/mpl/size.hpp>
+#include <boost/mpl/at.hpp>
+
+#include <boost/char_type_switch/iostream.hpp>
+
+#include <boost/mirror/meta_namespace.hpp>
+#include <boost/mirror/meta_type.hpp>
+#include <boost/mirror/meta_class.hpp>
+
+#include <boost/mirror/utils/name_to_stream.hpp>
+
+
+/** First declare some namespaces and classes
+ */
+
+namespace Test {
+
+ struct A
+ {
+ long l;
+ };
+
+ struct B : virtual A
+ {
+ int i;
+ };
+
+ struct C : virtual A
+ {
+ double d;
+ };
+
+ struct D : virtual A
+ {
+ short s;
+ };
+
+ struct E : B, C, D
+ {
+ float f;
+ };
+
+} // namespace Test
+
+
+
+namespace boost {
+namespace mirror {
+
+/** Register the 3D namespace
+ */
+BOOST_MIRROR_REG_META_NAMESPACE_TOP_LEVEL(Test)
+
+/** Register the types and classes
+ */
+BOOST_MIRROR_REG_META_TYPE(_Test, ::Test, A)
+BOOST_MIRROR_REG_META_TYPE(_Test, ::Test, B)
+BOOST_MIRROR_REG_META_TYPE(_Test, ::Test, C)
+BOOST_MIRROR_REG_META_TYPE(_Test, ::Test, D)
+BOOST_MIRROR_REG_META_TYPE(_Test, ::Test, E)
+
+
+BOOST_MIRROR_REG_BASE_CLASSES_BEGIN(::Test::B)
+BOOST_MIRROR_REG_BASE_CLASS_VIRTUAL(0, public, ::Test::A)
+BOOST_MIRROR_REG_BASE_CLASSES_END
+
+BOOST_MIRROR_REG_BASE_CLASSES_BEGIN(::Test::C)
+BOOST_MIRROR_REG_BASE_CLASS_VIRTUAL(0, public, ::Test::A)
+BOOST_MIRROR_REG_BASE_CLASSES_END
+
+BOOST_MIRROR_REG_BASE_CLASSES_BEGIN(::Test::D)
+BOOST_MIRROR_REG_BASE_CLASS_VIRTUAL(0, public, ::Test::A)
+BOOST_MIRROR_REG_BASE_CLASSES_END
+
+BOOST_MIRROR_REG_BASE_CLASSES_BEGIN(::Test::E)
+BOOST_MIRROR_REG_BASE_CLASS_SIMPLE(0, ::Test::B)
+BOOST_MIRROR_REG_BASE_CLASS_SIMPLE(1, ::Test::C)
+BOOST_MIRROR_REG_BASE_CLASS_SIMPLE(2, ::Test::D)
+BOOST_MIRROR_REG_BASE_CLASSES_END
+
+
+/** Class attributes
+ */
+BOOST_MIRROR_REG_CLASS_ATTRIBS_BEGIN(::Test::A)
+ BOOST_MIRROR_REG_CLASS_ATTRIB(0, long, l)
+BOOST_MIRROR_REG_CLASS_ATTRIBS_END
+
+BOOST_MIRROR_REG_CLASS_ATTRIBS_BEGIN(::Test::B)
+ BOOST_MIRROR_REG_CLASS_ATTRIB(0, int, i)
+BOOST_MIRROR_REG_CLASS_ATTRIBS_END
+
+BOOST_MIRROR_REG_CLASS_ATTRIBS_BEGIN(::Test::C)
+ BOOST_MIRROR_REG_CLASS_ATTRIB(0, double, d)
+BOOST_MIRROR_REG_CLASS_ATTRIBS_END
+
+BOOST_MIRROR_REG_CLASS_ATTRIBS_BEGIN(::Test::D)
+ BOOST_MIRROR_REG_CLASS_ATTRIB(0, short, s)
+BOOST_MIRROR_REG_CLASS_ATTRIBS_END
+
+BOOST_MIRROR_REG_CLASS_ATTRIBS_BEGIN(::Test::E)
+ BOOST_MIRROR_REG_CLASS_ATTRIB(0, float, f)
+BOOST_MIRROR_REG_CLASS_ATTRIBS_END
+
+
+
+} // namespace mirror
+} // namespace boost
+
+int main(void)
+{
+ using namespace ::std;
+ using namespace ::boost;
+ using namespace ::boost::mirror;
+ //
+ using namespace ::Test;
+ //
+ typedef BOOST_MIRROR_REFLECT_CLASS(::Test::E) meta_E;
+ //
+ bcout << sizeof(E().l) << endl;
+ //
+ bcout << "The class ::Test::E has " << endl;
+ //
+ bcout << meta_E::base_classes::size::value << " base classes" << endl;
+ bcout << meta_E::attributes::size::value << " own member attribs" << endl;
+ // NOTE: this isn't working as expected yet
+ bcout << meta_E::all_attributes::size::value << " member attribs" << endl;
+ //
+ //
+ bcout << "Finished" << endl;
+ //
+ return 0;
+}
+
Added: sandbox/mirror/libs/examples/serialization/cube.cpp
==============================================================================
--- (empty file)
+++ sandbox/mirror/libs/examples/serialization/cube.cpp 2008-04-18 13:31:39 EDT (Fri, 18 Apr 2008)
@@ -0,0 +1,165 @@
+/**
+ * \file examples/serialization/cube.cpp
+ * Example of registering namespaces, types and classes
+ * and cooperation with the Boost.Serialization library
+ *
+ * NOTE: if You are not familiar with namespace and type
+ * registration and reflection, You should probably
+ * see examples/registering/namespaces.cpp and
+ * examples/registering/types.cpp first.
+ *
+ * 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 <assert.h>
+#include <math.h>
+
+#include <boost/mpl/list.hpp>
+#include <boost/mpl/for_each.hpp>
+#include <boost/mpl/size.hpp>
+#include <boost/mpl/at.hpp>
+
+#include <boost/char_type_switch/iostream.hpp>
+
+#include <boost/mirror/meta_namespace.hpp>
+#include <boost/mirror/meta_type.hpp>
+#include <boost/mirror/meta_class.hpp>
+
+#include <boost/mirror/utils/name_to_stream.hpp>
+
+
+/** First declare some namespaces and classes
+ */
+
+namespace Graphics {
+
+ // coordinates
+ template <typename float_type>
+ class CoordsTempl
+ {
+ public:
+ typedef float_type float_type;
+ CoordsTempl(
+ float_type _x = 0.0,
+ float_type _y = 0.0,
+ float_type _z = 0.0,
+ float_type _w = 1.0
+ )
+ : x(_x)
+ , y(_y)
+ , z(_z)
+ , w(_w)
+ { }
+ // getters (space coordinates)
+ float_type get_x(void) const {return x;}
+ float_type get_y(void) const {return y;}
+ float_type get_z(void) const {return z;}
+ float_type get_w(void) const {return w;}
+ // setters
+ void set_x(float_type _x){x = _x;}
+ void set_y(float_type _y){y = _y;}
+ void set_z(float_type _z){z = _z;}
+ void set_w(float_type _w){w = _w;}
+ protected:
+ float_type x, y, z, w;
+ };
+
+ typedef CoordsTempl<float> Coords;
+
+ // a 3D vector
+ class Vector : public Coords
+ {
+ public:
+ Vector(
+ float_type _x = 0.0,
+ float_type _y = 0.0,
+ float_type _z = 0.0
+ )
+ : Coords(_x, _y, _z){ }
+ float_type length_squared(void){return x*x + y*y + z*z;}
+ float_type length(void){return sqrt(length_squared());}
+ private:
+ };
+
+} // namespace Graphics
+
+
+
+namespace boost {
+namespace mirror {
+
+/** Register the 3D namespace
+ */
+BOOST_MIRROR_REG_META_NAMESPACE_TOP_LEVEL(Graphics)
+
+/** Register the types and classes
+ */
+BOOST_MIRROR_REG_META_TYPE(_Graphics, ::Graphics, Coords)
+BOOST_MIRROR_REG_META_TYPE(_Graphics, ::Graphics, Vector)
+
+
+BOOST_MIRROR_REG_SINGLE_BASE_CLASS(
+ ::Graphics::Vector,
+ public, ::Graphics::Coords
+)
+
+/** Class attributes
+ */
+// register the attributes of Coords
+BOOST_MIRROR_REG_CLASS_ATTRIBS_BEGIN(::Graphics::Coords)
+ BOOST_MIRROR_REG_CLASS_ATTRIB_GETTER_SETTER(
+ 0, ::Graphics::Coords::float_type,
+ x, get_x, set_x
+ )
+ BOOST_MIRROR_REG_CLASS_ATTRIB_GETTER_SETTER(
+ 1, ::Graphics::Coords::float_type,
+ y, get_y, set_y
+ )
+ BOOST_MIRROR_REG_CLASS_ATTRIB_GETTER_SETTER(
+ 2, ::Graphics::Coords::float_type,
+ z, get_z, set_z
+ )
+ BOOST_MIRROR_REG_CLASS_ATTRIB_GETTER_SETTER(
+ 3, ::Graphics::Coords::float_type,
+ w, get_w, set_w
+ )
+BOOST_MIRROR_REG_CLASS_ATTRIBS_END
+
+// register the attributes of Vector
+BOOST_MIRROR_REG_CLASS_ATTRIBS_BEGIN(::Graphics::Vector)
+ BOOST_MIRROR_REG_CLASS_ATTRIB_GETTER_ONLY(
+ 0, ::Graphics::Vector::float_type,
+ length_squared, length_squared
+ )
+ BOOST_MIRROR_REG_CLASS_ATTRIB_GETTER_ONLY(
+ 1, ::Graphics::Vector::float_type,
+ length, length
+ )
+BOOST_MIRROR_REG_CLASS_ATTRIBS_END
+
+
+} // namespace mirror
+} // namespace boost
+
+int main(void)
+{
+ using namespace ::std;
+ using namespace ::boost;
+ using namespace ::boost::mirror;
+ //
+ using ::Graphics::Coords;
+ using ::Graphics::Vector;
+ //
+ typedef BOOST_MIRROR_REFLECT_CLASS(Vector) meta_Vector;
+ //
+ bcout << meta_Vector::base_classes::size::value << endl;
+ bcout << meta_Vector::attributes::size::value << endl;
+ bcout << meta_Vector::all_attributes::size::value << endl;
+ //
+ //
+ bcout << "Finished" << endl;
+ //
+ return 0;
+}
+
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