|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r52018 - in sandbox/mirror: boost/mirror boost/mirror/detail boost/mirror/intrinsic libs/mirror/example libs/mirror/example/generators libs/mirror/test
From: chochlik_at_[hidden]
Date: 2009-03-27 12:02:40
Author: matus.chochlik
Date: 2009-03-27 12:02:37 EDT (Fri, 27 Mar 2009)
New Revision: 52018
URL: http://svn.boost.org/trac/boost/changeset/52018
Log:
[mirror 0.3.x]
- update of the class generators
- update of the traversals
- minor modifications of meta-attribute implementation
- added several new examples
- added several test cases into the testsuite
Added:
sandbox/mirror/boost/mirror/class_generators.hpp (contents, props changed)
sandbox/mirror/libs/mirror/example/generators/
sandbox/mirror/libs/mirror/example/generators/gen_01.cpp (contents, props changed)
sandbox/mirror/libs/mirror/example/generators/gen_02.cpp (contents, props changed)
sandbox/mirror/libs/mirror/test/classes_ct_10.cpp (contents, props changed)
sandbox/mirror/libs/mirror/test/classes_rt_11.cpp (contents, props changed)
sandbox/mirror/libs/mirror/test/simple_classes.hpp (contents, props changed)
sandbox/mirror/libs/mirror/test/visitors_01.cpp (contents, props changed)
sandbox/mirror/libs/mirror/test/visitors_02.cpp (contents, props changed)
Text files modified:
sandbox/mirror/boost/mirror/detail/class_generators.hpp | 92 +++++++++++++++++++++++++++++++--------
sandbox/mirror/boost/mirror/detail/meta_all_attribs_base.hpp | 13 +++--
sandbox/mirror/boost/mirror/detail/meta_attribs_base.hpp | 43 ++++++++++++++++--
sandbox/mirror/boost/mirror/detail/traversal.hpp | 92 ++++++++++++++++++++-------------------
sandbox/mirror/boost/mirror/intrinsic/by_name.hpp | 26 +---------
sandbox/mirror/boost/mirror/traversal.hpp | 52 ++++++++++++++++++++--
sandbox/mirror/libs/mirror/example/Jamfile.v2 | 5 ++
sandbox/mirror/libs/mirror/test/Jamfile.v2 | 4 +
8 files changed, 224 insertions(+), 103 deletions(-)
Added: sandbox/mirror/boost/mirror/class_generators.hpp
==============================================================================
--- (empty file)
+++ sandbox/mirror/boost/mirror/class_generators.hpp 2009-03-27 12:02:37 EDT (Fri, 27 Mar 2009)
@@ -0,0 +1,92 @@
+/**
+ * \file boost/mirror/class_generators.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_INTRINSIC_BY_NAME_HPP
+#define BOOST_MIRROR_INTRINSIC_BY_NAME_HPP
+
+#include <boost/mirror/meta_attributes.hpp>
+#include <boost/mirror/detail/class_generators.hpp>
+
+namespace boost {
+namespace mirror {
+namespace detail {
+
+template <template <class> class Model>
+struct apply_meta_function_generator_plugin_wrapper
+{
+ template <
+ class Class,
+ class VariantTag,
+ class MetaClassAttributes,
+ class Position
+ >
+ struct generator_plugin
+ {
+ typedef typename Model<
+ meta_class_attribute<
+ Class,
+ VariantTag,
+ MetaClassAttributes,
+ Position
+ >
+ >::type type;
+ };
+};
+
+
+} // namespace detail
+
+template <
+ class MetaClassAttributes,
+ template <class> class Model,
+ class UnitKindSelector
+> struct class_generator
+ : detail::class_generator<
+ MetaClassAttributes,
+ detail::
+ apply_meta_function_generator_plugin_wrapper<Model>::
+ template generator_plugin,
+ UnitKindSelector
+>
+{
+private:
+ typedef detail::class_generator<
+ MetaClassAttributes,
+ detail::
+ apply_meta_function_generator_plugin_wrapper<Model>::
+ template generator_plugin,
+ UnitKindSelector
+ > base_class;
+public:
+ inline class_generator(void){ }
+
+ inline class_generator(const class_generator& other)
+ : base_class(static_cast<const base_class&>(other))
+ { }
+
+ inline class_generator(class_generator& other)
+ : base_class(static_cast<const base_class&>(other))
+ { }
+
+ template <class Param>
+ inline class_generator(Param& param)
+ : base_class(param)
+ { }
+
+ template <class Param>
+ inline class_generator(const Param& param)
+ : base_class(param)
+ { }
+};
+
+} // namespace mirror
+} // namespace boost
+
+#endif //include guard
+
Modified: sandbox/mirror/boost/mirror/detail/class_generators.hpp
==============================================================================
--- sandbox/mirror/boost/mirror/detail/class_generators.hpp (original)
+++ sandbox/mirror/boost/mirror/detail/class_generators.hpp 2009-03-27 12:02:37 EDT (Fri, 27 Mar 2009)
@@ -21,7 +21,8 @@
template <
class MetaClassAttributes,
template <class, class, class, class> class MetaFunction,
- class Position
+ class Position,
+ class UnitKindSelector
>
struct class_generator_unit
{
@@ -30,7 +31,7 @@
(MetaClassAttributes::template get_generator_plugin<
MetaClassAttributes,
MetaFunction
- >(Position()))
+ >(Position(), UnitKindSelector()))
);
typedef typename generator_plugin::type type;
};
@@ -40,38 +41,54 @@
class MetaClassAttributes,
template <class, class, class, class> class MetaFunction,
class Position,
- class Size
+ class Size,
+ class UnitKindSelector
> struct class_generator_base
: public class_generator_unit<
MetaClassAttributes,
MetaFunction,
- Position
+ Position,
+ UnitKindSelector
>::type
, public class_generator_base<
MetaClassAttributes,
MetaFunction,
mpl::int_<Position::value + 1>,
- Size
+ Size,
+ UnitKindSelector
>
{
typedef typename class_generator_unit<
MetaClassAttributes,
MetaFunction,
- Position
+ Position,
+ UnitKindSelector
>::type head;
typedef class_generator_base<
MetaClassAttributes,
MetaFunction,
mpl::int_<Position::value + 1>,
- Size
+ Size,
+ UnitKindSelector
> tail;
- class_generator_base(void)
+ inline class_generator_base(void)
+ { }
+
+ inline class_generator_base(const class_generator_base& other)
+ : head(static_cast<const head&>(other))
+ , tail(static_cast<const tail&>(other))
+ { }
+
+ template <class Param>
+ inline class_generator_base(Param& init)
+ : head(init)
+ , tail(init)
{ }
template <class Param>
- class_generator_base(Param& init)
+ inline class_generator_base(const Param& init)
: head(init)
, tail(init)
{ }
@@ -80,22 +97,25 @@
template <
class MetaClassAttributes,
template <class, class, class, class> class MetaFunction,
- class Size
+ class Size,
+ class UnitKindSelector
>
struct class_generator_base<
MetaClassAttributes,
MetaFunction,
Size,
- Size
+ Size,
+ UnitKindSelector
>
{
- class_generator_base(void){ }
+ inline class_generator_base(void){ }
template <class Param>
- class_generator_base(Param&){ }
-};
+ inline class_generator_base(Param&){ }
-} // namespace detail
+ template <class Param>
+ inline class_generator_base(const Param&){ }
+};
/** Creates a class hierarchy based on the results
* of the GeneratorUnit meta-function, with the
@@ -104,13 +124,15 @@
*/
template <
class MetaClassAttributes,
- template <class, class, class, class> class MetaFunction
+ template <class, class, class, class> class MetaFunction,
+ class UnitKindSelector
> struct class_generator
: detail::class_generator_base<
MetaClassAttributes,
MetaFunction,
mpl::int_<0>,
- mpl::int_<mirror::size<MetaClassAttributes>::value>
+ mpl::int_<mirror::size<MetaClassAttributes>::value>,
+ UnitKindSelector
>
{
private:
@@ -118,18 +140,48 @@
MetaClassAttributes,
MetaFunction,
mpl::int_<0>,
- mpl::int_<mirror::size<MetaClassAttributes>::value>
+ mpl::int_<mirror::size<MetaClassAttributes>::value>,
+ UnitKindSelector
> base_generator;
public:
- class_generator(void) { }
+ inline class_generator(void) { }
+
+ inline class_generator(const class_generator& other)
+ : base_generator(static_cast<const base_generator&>(other))
+ { }
template <class Param>
- class_generator(Param& init)
+ inline class_generator(Param& init)
: base_generator(init)
{ }
+
+ template <class Param>
+ inline class_generator(const Param& init)
+ : base_generator(init)
+ { }
+};
+
+/** A class generator unit which "returns" the result type of the
+ * get_meta_attrib_holder function on the MetaClassAttributes.
+ */
+template <
+ class Class,
+ class VariantTag,
+ class MetaClassAttributes,
+ class Position
+>
+struct get_meta_attrib_generator_plugin
+{
+ typedef meta_class_attribute<
+ Class,
+ VariantTag,
+ MetaClassAttributes,
+ Position
+ > type;
};
+} // namespace detail
} // namespace mirror
} // namespace boost
Modified: sandbox/mirror/boost/mirror/detail/meta_all_attribs_base.hpp
==============================================================================
--- sandbox/mirror/boost/mirror/detail/meta_all_attribs_base.hpp (original)
+++ sandbox/mirror/boost/mirror/detail/meta_all_attribs_base.hpp 2009-03-27 12:02:37 EDT (Fri, 27 Mar 2009)
@@ -578,7 +578,8 @@
int I,
class Inherited,
class MetaClassAttributes,
- template <class, class, class, class> class MetaFunction
+ template <class, class, class, class> class MetaFunction,
+ class UnitKindSelector
> struct result_of_get_generator_plugin
{
// get the right meta-class
@@ -602,7 +603,7 @@
(ancestor::attributes::template get_generator_plugin<
MetaClassAttributes,
MetaFunction
- >(position()))
+ >(position(), UnitKindSelector()))
)
// the traits of the i-th attribute
@@ -743,13 +744,15 @@
template <
class MetaClassAttributes,
template <class, class, class, class> class MetaFunction,
- int I
+ int I,
+ bool B
> static typename helpers:: template result_of_get_generator_plugin<
I,
typename result_of_is_inherited<I>::type,
MetaClassAttributes,
- MetaFunction
- >::type get_generator_plugin(mpl::int_<I>);
+ MetaFunction,
+ mpl::bool_<B>
+ >::type get_generator_plugin(mpl::int_<I>, mpl::bool_<B>);
}; // all_attributes_base
Modified: sandbox/mirror/boost/mirror/detail/meta_attribs_base.hpp
==============================================================================
--- sandbox/mirror/boost/mirror/detail/meta_attribs_base.hpp (original)
+++ sandbox/mirror/boost/mirror/detail/meta_attribs_base.hpp 2009-03-27 12:02:37 EDT (Fri, 27 Mar 2009)
@@ -144,13 +144,13 @@
/**
*/
-#define BOOST_MIRROR_REG_META_CLASS_ATTRIB_HOLDER(NAME) \
+#define BOOST_MIRROR_REG_META_CLASS_GENERATOR_PLUGIN(NAME) \
template < \
class MetaClassAttributes, \
template <class, class, class, class> \
class MetaFunction \
> \
- struct NAME##_generator_plugin \
+ struct NAME##_generator_plugin_mem_typedef \
{ \
typedef typename MetaFunction< \
Class, \
@@ -164,10 +164,43 @@
template <class, class, class, class> \
class MetaFunction \
> \
- static NAME##_generator_plugin< \
+ static NAME##_generator_plugin_mem_typedef< \
MetaClassAttributes, \
MetaFunction \
- > get_generator_plugin(position_of_##NAME);
+ > get_generator_plugin(position_of_##NAME, mpl::true_); \
+ template < \
+ class MetaClassAttributes, \
+ template <class, class, class, class> \
+ class MetaFunction \
+ > \
+ struct NAME##_generator_plugin_mem_attrib \
+ { \
+ typedef typename MetaFunction< \
+ Class, \
+ variant_tag, \
+ MetaClassAttributes, \
+ position_of_##NAME \
+ >::type type; \
+ type NAME; \
+ inline NAME##_generator_plugin_mem_attrib(void){ } \
+ template <class Param> \
+ inline NAME##_generator_plugin_mem_attrib(Param& param) \
+ : NAME(param) \
+ { } \
+ template <class Param> \
+ inline NAME##_generator_plugin_mem_attrib(const Param& param) \
+ : NAME(param) \
+ { } \
+ }; \
+ template < \
+ class MetaClassAttributes, \
+ template <class, class, class, class> \
+ class MetaFunction \
+ > \
+ static NAME##_generator_plugin_mem_attrib< \
+ MetaClassAttributes, \
+ MetaFunction \
+ > get_generator_plugin(position_of_##NAME, mpl::false_);
/** Helper macro expanding into an epilogue of a meta-attribute
@@ -178,7 +211,7 @@
NAME, \
TYPENAME_KW \
) \
- BOOST_MIRROR_REG_META_CLASS_ATTRIB_HOLDER(NAME) \
+ BOOST_MIRROR_REG_META_CLASS_GENERATOR_PLUGIN(NAME) \
typedef TYPENAME_KW mpl::push_back< \
partial_list_##NAME, \
type_of_##NAME \
Modified: sandbox/mirror/boost/mirror/detail/traversal.hpp
==============================================================================
--- sandbox/mirror/boost/mirror/detail/traversal.hpp (original)
+++ sandbox/mirror/boost/mirror/detail/traversal.hpp 2009-03-27 12:02:37 EDT (Fri, 27 Mar 2009)
@@ -48,12 +48,8 @@
typedef typename mpl::push_back<NodePath, MetaClass>::type
ClassNodePath;
- typedef typename remove_reference<
- typename MetaClass::reflected_type
- >::type* InstancePtr;
-
- template <class VisitorType>
+ template <class VisitorType, class InstancePtr>
class attribute_traversal
{
public:
@@ -120,7 +116,7 @@
template <class MetaAttribute, class AttribsNodePath>
inline void traverse_attribute_if(
- mpl::bool_<true>,
+ mpl::true_,
MetaAttribute ma,
AttribsNodePath path
) const
@@ -144,7 +140,7 @@
template <class MetaAttribute, class AttribsNodePath>
inline void traverse_attribute_if(
- mpl::bool_<false>,
+ mpl::false_,
MetaAttribute ma,
AttribsNodePath path
) const
@@ -156,7 +152,7 @@
AttribsNodePath,
MetaAttribute
>::type
- >::accept(visitor, 0);
+ >::accept(visitor);
}
template < class MetaAttribute, class AttribsNodePath>
@@ -180,7 +176,7 @@
template < class MetaAttribute, class AttribsNodePath>
static inline void lead_into_attribute_if(
- mpl::bool_<true>,
+ mpl::true_,
reference_wrapper<VisitorType> visitor,
MetaAttribute ma,
AttribsNodePath path
@@ -197,7 +193,7 @@
template <class MetaAttribute, class AttribsNodePath>
static inline void lead_into_attribute_if(
- mpl::bool_<false>,
+ mpl::false_,
reference_wrapper<VisitorType> visitor,
MetaAttribute ma,
AttribsNodePath path
@@ -224,7 +220,7 @@
template <class MetaAttribute, class AttribsNodePath>
static inline void lead_out_of_attribute_if(
- mpl::bool_<true>,
+ mpl::true_,
reference_wrapper<VisitorType> visitor,
MetaAttribute ma,
AttribsNodePath path
@@ -241,7 +237,7 @@
template <class MetaAttribute, class AttribsNodePath>
static inline void lead_out_of_attribute_if(
- mpl::bool_<false>,
+ mpl::false_,
reference_wrapper<VisitorType> visitor,
MetaAttribute ma,
AttribsNodePath path
@@ -263,7 +259,7 @@
}
static inline void lead_into_attribute_list_if(
- mpl::bool_<true>,
+ mpl::true_,
reference_wrapper<VisitorType> visitor
)
{
@@ -278,7 +274,7 @@
}
static inline void lead_into_attribute_list_if(
- mpl::bool_<false>,
+ mpl::false_,
reference_wrapper<VisitorType> visitor
){ }
@@ -298,7 +294,7 @@
}
static inline void lead_out_of_attribute_list_if(
- mpl::bool_<true>,
+ mpl::true_,
reference_wrapper<VisitorType> visitor
)
{
@@ -313,25 +309,28 @@
}
static inline void lead_out_of_attribute_list_if(
- mpl::bool_<false>,
+ mpl::false_,
reference_wrapper<VisitorType> visitor
){ }
};
// attribute_traversal factory function
- template <class VisitorType>
- static inline attribute_traversal<VisitorType>
+ template <class VisitorType, class InstancePtr>
+ static inline attribute_traversal<VisitorType, InstancePtr>
show_attribs_to(
reference_wrapper<VisitorType> visitor,
InstancePtr ptr_to_inst
)
{
- return attribute_traversal<VisitorType>(visitor, ptr_to_inst);
+ return attribute_traversal<VisitorType, InstancePtr>(
+ visitor,
+ ptr_to_inst
+ );
}
- template <class VisitorType>
+ template <class VisitorType, class InstancePtr>
class base_class_traversal
{
public:
@@ -402,7 +401,7 @@
template <class MetaInheritance>
static inline void lead_into_base_class_if(
- mpl::bool_<true>,
+ mpl::true_,
reference_wrapper<VisitorType> visitor,
MetaInheritance mbc,
BaseClassesNodePath path
@@ -419,7 +418,7 @@
template <class MetaInheritance>
static inline void lead_into_base_class_if(
- mpl::bool_<false>,
+ mpl::false_,
reference_wrapper<VisitorType> visitor,
MetaInheritance mbc,
BaseClassesNodePath path
@@ -446,7 +445,7 @@
template <class MetaInheritance>
static inline void lead_out_of_base_class_if(
- mpl::bool_<true>,
+ mpl::true_,
reference_wrapper<VisitorType> visitor,
MetaInheritance mbc,
BaseClassesNodePath path
@@ -463,7 +462,7 @@
template <class MetaInheritance>
static inline void lead_out_of_base_class_if(
- mpl::bool_<false>,
+ mpl::false_,
reference_wrapper<VisitorType> visitor,
MetaInheritance mbc,
BaseClassesNodePath path
@@ -488,7 +487,7 @@
}
static inline void lead_into_base_class_list_if(
- mpl::bool_<true>,
+ mpl::true_,
reference_wrapper<VisitorType> visitor
)
{
@@ -503,7 +502,7 @@
}
static inline void lead_into_base_class_list_if(
- mpl::bool_<false>,
+ mpl::false_,
reference_wrapper<VisitorType> visitor
){ }
@@ -526,7 +525,7 @@
}
static inline void lead_out_of_base_class_list_if(
- mpl::bool_<true>,
+ mpl::true_,
reference_wrapper<VisitorType> visitor
)
{
@@ -541,7 +540,7 @@
}
static inline void lead_out_of_base_class_list_if(
- mpl::bool_<false>,
+ mpl::false_,
reference_wrapper<VisitorType> visitor
){ }
@@ -549,14 +548,17 @@
};
// base class traversal factory function
- template <class VisitorType>
- static inline base_class_traversal<VisitorType>
+ template <class VisitorType, class InstancePtr>
+ static inline base_class_traversal<VisitorType, InstancePtr>
show_bases_to(
reference_wrapper<VisitorType> visitor,
InstancePtr ptr_to_inst
)
{
- return base_class_traversal<VisitorType>(visitor, ptr_to_inst);
+ return base_class_traversal<VisitorType, InstancePtr>(
+ visitor,
+ ptr_to_inst
+ );
}
template <
@@ -584,7 +586,7 @@
class InstanceType
>
inline static void lead_to_instance_if(
- mpl::bool_<true>,
+ mpl::true_,
reference_wrapper<VisitorType> visitor,
MetaClass mc,
NodePath path,
@@ -606,7 +608,7 @@
class InstanceType
>
inline static void lead_to_instance_if(
- mpl::bool_<false>,
+ mpl::false_,
reference_wrapper<VisitorType> visitor,
MetaClass mc,
NodePath path,
@@ -634,7 +636,7 @@
template < class VisitorType>
static inline void lead_into_type_if(
- mpl::bool_<true>,
+ mpl::true_,
reference_wrapper<VisitorType> visitor,
MetaClass mc,
NodePath path
@@ -651,7 +653,7 @@
template < class VisitorType>
static inline void lead_into_type_if(
- mpl::bool_<false>,
+ mpl::false_,
reference_wrapper<VisitorType> visitor,
MetaClass mc,
NodePath path
@@ -678,7 +680,7 @@
template < class VisitorType>
static inline void lead_out_of_type_if(
- mpl::bool_<true>,
+ mpl::true_,
reference_wrapper<VisitorType> visitor,
MetaClass mc,
NodePath path
@@ -695,7 +697,7 @@
template < class VisitorType>
static inline void lead_out_of_type_if(
- mpl::bool_<false>,
+ mpl::false_,
reference_wrapper<VisitorType> visitor,
MetaClass mc,
NodePath path
@@ -775,7 +777,7 @@
}
static inline void lead_into_namespace_member_list_if(
- mpl::bool_<true>,
+ mpl::true_,
reference_wrapper<VisitorType> visitor,
Members m,
NamespaceNodePath path
@@ -791,7 +793,7 @@
}
static inline void lead_into_namespace_member_list_if(
- mpl::bool_<false>,
+ mpl::false_,
reference_wrapper<VisitorType> visitor,
Members m,
NamespaceNodePath path
@@ -816,7 +818,7 @@
}
static inline void lead_out_of_namespace_member_list_if(
- mpl::bool_<true>,
+ mpl::true_,
reference_wrapper<VisitorType> visitor,
Members m,
NamespaceNodePath path
@@ -832,7 +834,7 @@
}
static inline void lead_out_of_namespace_member_list_if(
- mpl::bool_<false>,
+ mpl::false_,
reference_wrapper<VisitorType> visitor,
Members m,
NamespaceNodePath path
@@ -868,7 +870,7 @@
template <class VisitorType>
static inline void lead_into_namespace_if(
- mpl::bool_<true>,
+ mpl::true_,
reference_wrapper<VisitorType> visitor,
MetaNamespace mn,
NodePath path
@@ -885,7 +887,7 @@
template < class VisitorType>
static inline void lead_into_namespace_if(
- mpl::bool_<false>,
+ mpl::false_,
reference_wrapper<VisitorType> visitor,
MetaNamespace mn,
NodePath path
@@ -912,7 +914,7 @@
template < class VisitorType>
static inline void lead_out_of_namespace_if(
- mpl::bool_<true>,
+ mpl::true_,
reference_wrapper<VisitorType> visitor,
MetaNamespace mn,
NodePath path
@@ -929,7 +931,7 @@
template < class VisitorType>
static inline void lead_out_of_namespace_if(
- mpl::bool_<false>,
+ mpl::false_,
reference_wrapper<VisitorType> visitor,
MetaNamespace mn,
NodePath path
Modified: sandbox/mirror/boost/mirror/intrinsic/by_name.hpp
==============================================================================
--- sandbox/mirror/boost/mirror/intrinsic/by_name.hpp (original)
+++ sandbox/mirror/boost/mirror/intrinsic/by_name.hpp 2009-03-27 12:02:37 EDT (Fri, 27 Mar 2009)
@@ -1,6 +1,6 @@
/**
- * \file boost/mirror/intrinsic/empty.hpp
- * Gets count of meta-attributes/meta-inheritences/etc.
+ * \file boost/mirror/intrinsic/by_name.hpp
+ *
*
* Copyright 2008 Matus Chochlik. Distributed under the Boost
* Software License, Version 1.0. (See accompanying file
@@ -17,30 +17,12 @@
namespace mirror {
namespace detail {
-/** A class generator unit which "returns" the result type of the
- * get_meta_attrib_holder function on the MetaClassAttributes.
- */
-template <
- class Class,
- class VariantTag,
- class MetaClassAttributes,
- class Position
->
-struct get_meta_attrib_generator_plugin
-{
- typedef meta_class_attribute<
- Class,
- VariantTag,
- MetaClassAttributes,
- Position
- > type;
-};
-
template <class MetaClassAttributes>
struct attrib_by_name : public class_generator<
MetaClassAttributes,
- get_meta_attrib_generator_plugin
+ get_meta_attrib_generator_plugin,
+ mpl::true_
> { };
Modified: sandbox/mirror/boost/mirror/traversal.hpp
==============================================================================
--- sandbox/mirror/boost/mirror/traversal.hpp (original)
+++ sandbox/mirror/boost/mirror/traversal.hpp 2009-03-27 12:02:37 EDT (Fri, 27 Mar 2009)
@@ -31,7 +31,9 @@
private:
typedef typename remove_reference<
typename MetaClass::reflected_type
- >::type* InstancePtr;
+ >::type InstType;
+ typedef InstType* InstancePtr;
+ typedef const InstType* ConstInstancePtr;
public:
template <class VisitorType>
static inline void accept(
@@ -50,11 +52,29 @@
{
do_accept(visitor, ptr_to_inst);
}
-private:
+
template <class VisitorType>
+ static inline void accept(
+ VisitorType visitor,
+ ConstInstancePtr ptr_to_inst
+ )
+ {
+ do_accept(ref<VisitorType>(visitor), ptr_to_inst);
+ }
+
+ template <class VisitorType>
+ static inline void accept(
+ reference_wrapper<VisitorType> visitor,
+ ConstInstancePtr ptr_to_inst
+ )
+ {
+ do_accept(visitor, ptr_to_inst);
+ }
+private:
+ template <class VisitorType, class InstanceType>
static inline void do_accept(
reference_wrapper<VisitorType> visitor,
- InstancePtr ptr_to_inst
+ InstanceType* ptr_to_inst
)
{
MetaClass mc;
@@ -91,7 +111,9 @@
private:
typedef typename remove_reference<
typename MetaClass::reflected_type
- >::type* InstancePtr;
+ >::type InstType;
+ typedef InstType* InstancePtr;
+ typedef const InstType* ConstInstancePtr;
public:
template <class VisitorType>
static inline void accept(
@@ -110,11 +132,29 @@
{
do_accept(visitor, ptr_to_inst);
}
-private:
+
template <class VisitorType>
+ static inline void accept(
+ VisitorType visitor,
+ ConstInstancePtr ptr_to_inst
+ )
+ {
+ do_accept(ref<VisitorType>(visitor), ptr_to_inst);
+ }
+
+ template <class VisitorType>
+ static inline void accept(
+ reference_wrapper<VisitorType> visitor,
+ ConstInstancePtr ptr_to_inst
+ )
+ {
+ do_accept(visitor, ptr_to_inst);
+ }
+private:
+ template <class VisitorType, class InstanceType>
static inline void do_accept(
reference_wrapper<VisitorType> visitor,
- InstancePtr ptr_to_inst
+ InstanceType* ptr_to_inst
)
{
MetaClass mc;
Modified: sandbox/mirror/libs/mirror/example/Jamfile.v2
==============================================================================
--- sandbox/mirror/libs/mirror/example/Jamfile.v2 (original)
+++ sandbox/mirror/libs/mirror/example/Jamfile.v2 2009-03-27 12:02:37 EDT (Fri, 27 Mar 2009)
@@ -13,6 +13,8 @@
: requirements
<include>../../../ #the mirror library root
;
+exe gen_01 : generators/gen_01.cpp ;
+exe gen_02 : generators/gen_02.cpp ;
#
# basics
#
@@ -49,6 +51,9 @@
exe fctry_tetrahedron : factories/tetrahedron.cpp ;
exe fn_call_inserter : factories/inserter.cpp ;
#
+# class generators
+#
+#
# cooperation with Boost.Serialization
#
#exe serial_cube : serialization/cube.cpp ;
Added: sandbox/mirror/libs/mirror/example/generators/gen_01.cpp
==============================================================================
--- (empty file)
+++ sandbox/mirror/libs/mirror/example/generators/gen_01.cpp 2009-03-27 12:02:37 EDT (Fri, 27 Mar 2009)
@@ -0,0 +1,142 @@
+/**
+ * \file examples/generators/gen_01.cpp
+ *
+ * This example shows the usage of class generators.
+ *
+ * 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/char_type_switch/iostream.hpp>
+#include <boost/char_type_switch/string.hpp>
+
+#include <boost/mirror/meta_class.hpp>
+#include <boost/mirror/class_generators.hpp>
+
+#include <boost/call_traits.hpp>
+
+#include <vector>
+
+namespace test {
+
+typedef ::boost::cts::bstring string;
+
+struct person
+{
+ string name;
+ string surname;
+ double height;
+ double weight;
+};
+
+} // namespace test
+
+namespace boost {
+namespace mirror {
+
+/** Register everything
+ */
+BOOST_MIRROR_REG_NAMESPACE((test))
+BOOST_MIRROR_REG_TYPE(::test, person)
+BOOST_MIRROR_REG_CLASS_ATTRIBS_BEGIN(::test::person)
+ BOOST_MIRROR_REG_AUTO_CLASS_ATTRIB(_, name)
+ BOOST_MIRROR_REG_AUTO_CLASS_ATTRIB(_, surname)
+ BOOST_MIRROR_REG_AUTO_CLASS_ATTRIB(_, height)
+ BOOST_MIRROR_REG_AUTO_CLASS_ATTRIB(_, weight)
+BOOST_MIRROR_REG_CLASS_ATTRIBS_END
+
+} // namespace mirror
+} // namespace boost
+
+namespace test {
+
+template <class MetaAttribute>
+class building_block
+{
+private:
+ typedef typename MetaAttribute::type::reflected_type type;
+ type value;
+
+ typedef typename ::boost::call_traits<type>::param_type param_type;
+public:
+ building_block(void)
+ {
+ ::boost::cts::bcerr() <<
+ BOOST_CTS_LIT("Enter ") <<
+ MetaAttribute::base_name() <<
+ BOOST_CTS_LIT(" (") <<
+ MetaAttribute::type::base_name() <<
+ BOOST_CTS_LIT("): ") <<
+ ::std::flush;
+ ::boost::cts::bcin() >> value;
+ }
+
+ inline param_type get(void) const
+ {
+ ::boost::cts::bcerr() <<
+ BOOST_CTS_LIT("Getting the value of ") <<
+ MetaAttribute::base_name() <<
+ ::std::endl;
+ return value;
+ }
+};
+
+template <class MetaAttribute>
+struct get_building_block
+{
+ typedef building_block<MetaAttribute> type;
+};
+
+} // namespace test
+
+int main(void)
+{
+ using namespace ::std;
+ using namespace ::boost;
+ //
+ cts::bostream& bcout = cts::bcout();
+ typedef BOOST_MIRRORED_CLASS(::test::person) meta_person;
+ //
+ // use the class generator and the meta-data about the
+ // ::test::person class to create a new class with
+ // the same set of attributes which are made of
+ // the ::test::building_block instantiations.
+ typedef mirror::class_generator<
+ meta_person::attributes,
+ ::test::get_building_block,
+ mpl::false_
+ > person;
+ // a list of persons
+ vector<person> persons;
+ //
+ // construct and insert a few persons into the list
+ int n = 3;
+ while(n--)
+ {
+ persons.push_back(person());
+ }
+ //
+ // print out info about the persons stored in the list
+ for(
+ vector<person>::iterator
+ i = persons.begin(),
+ e = persons.end();
+ i != e;
+ ++i
+ ) bcout <<
+ meta_person::base_name() <<
+ BOOST_CTS_LIT("(") <<
+ i->name.get() <<
+ BOOST_CTS_LIT(", ") <<
+ i->surname.get() <<
+ BOOST_CTS_LIT(", ") <<
+ i->height.get() <<
+ BOOST_CTS_LIT(", ") <<
+ i->weight.get() <<
+ BOOST_CTS_LIT(")") <<
+ ::std::endl;
+ //
+ return 0;
+}
+
Added: sandbox/mirror/libs/mirror/example/generators/gen_02.cpp
==============================================================================
--- (empty file)
+++ sandbox/mirror/libs/mirror/example/generators/gen_02.cpp 2009-03-27 12:02:37 EDT (Fri, 27 Mar 2009)
@@ -0,0 +1,249 @@
+/**
+ * \file examples/generators/gen_02.cpp
+ *
+ * This example shows the usage of class generators.
+ *
+ * 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/char_type_switch/iostream.hpp>
+#include <boost/char_type_switch/string.hpp>
+
+#include <boost/mirror/meta_class.hpp>
+#include <boost/mirror/class_generators.hpp>
+
+#include <boost/call_traits.hpp>
+#include <boost/type_traits/is_fundamental.hpp>
+
+#include <list>
+#include <cmath>
+
+namespace test {
+
+struct vector
+{
+ double x;
+ double y;
+ double z;
+};
+
+struct tetrahedron
+{
+ vector a;
+ vector b;
+ vector c;
+ vector d;
+};
+
+} // namespace test
+
+namespace boost {
+namespace mirror {
+
+/** Register everything
+ */
+BOOST_MIRROR_REG_NAMESPACE((test))
+BOOST_MIRROR_REG_TYPE(::test, vector)
+BOOST_MIRROR_REG_CLASS_ATTRIBS_BEGIN(::test::vector)
+ BOOST_MIRROR_REG_AUTO_CLASS_ATTRIB(_, x)
+ BOOST_MIRROR_REG_AUTO_CLASS_ATTRIB(_, y)
+ BOOST_MIRROR_REG_AUTO_CLASS_ATTRIB(_, z)
+BOOST_MIRROR_REG_CLASS_ATTRIBS_END
+
+BOOST_MIRROR_REG_TYPE(::test, tetrahedron)
+BOOST_MIRROR_REG_CLASS_ATTRIBS_BEGIN(::test::tetrahedron)
+ BOOST_MIRROR_REG_AUTO_CLASS_ATTRIB(_, a)
+ BOOST_MIRROR_REG_AUTO_CLASS_ATTRIB(_, b)
+ BOOST_MIRROR_REG_AUTO_CLASS_ATTRIB(_, c)
+ BOOST_MIRROR_REG_AUTO_CLASS_ATTRIB(_, d)
+BOOST_MIRROR_REG_CLASS_ATTRIBS_END
+
+} // namespace mirror
+} // namespace boost
+
+namespace test {
+
+typedef ::boost::cts::bstring string;
+
+/** A building block template for the individual attributes
+ * (that had fundamental types) in the generated class.
+ * The other attributes (with non-fundamental types) are
+ * recursivelly generated using the same generator and
+ * building_block template.
+ */
+template <class MetaAttribute>
+class building_block
+{
+private:
+ // the type of the attribute
+ typedef typename MetaAttribute::type::reflected_type type;
+ // parameter type
+ typedef typename ::boost::call_traits<type>::param_type param_type;
+
+ // the path to this building block inside of the generated class
+ string path;
+public:
+ building_block(const string& _path)
+ : path(_path)
+ { }
+
+ inline type get(void) const
+ {
+ // in a real-life application, instead of this
+ // console I/O the building block could
+ // access a configuration file, Windows registry
+ // or a database to get the value
+ ::boost::cts::bcout() <<
+ BOOST_CTS_LIT("Get value of ") <<
+ path <<
+ BOOST_CTS_LIT("/") <<
+ MetaAttribute::base_name() <<
+ BOOST_CTS_LIT(": ") <<
+ ::std::flush;
+ type value;
+ ::boost::cts::bcin() >> value;
+ return value;
+ }
+
+ inline void set(param_type value)
+ {
+ // again a real-life implementation could
+ // be writing the value to a config, registry
+ // or a database
+ ::boost::cts::bcout() <<
+ BOOST_CTS_LIT("New value of ") <<
+ path <<
+ BOOST_CTS_LIT("/") <<
+ MetaAttribute::base_name() <<
+ BOOST_CTS_LIT(" = ") <<
+ value <<
+ ::std::endl;
+ }
+
+ inline void operator = (param_type value)
+ {
+ set(value);
+ }
+};
+
+/** Forward declaration of the building_block getter
+ */
+template <class MetaAttribute>
+struct get_building_block;
+
+/** Specialization of building block getter for
+ * fundamental types
+ */
+template <class MetaAttribute, class IsFundamental>
+struct do_get_building_block
+{
+ typedef building_block<MetaAttribute> type;
+};
+
+/** Specialization of building block getter for
+ * non-fundamental types
+ */
+template <class MetaAttribute>
+struct do_get_building_block<MetaAttribute, ::boost::mpl::false_>
+{
+ typedef ::boost::mirror::class_generator<
+ typename MetaAttribute::type::all_attributes,
+ get_building_block,
+ ::boost::mpl::false_
+ > base_generator;
+
+ /** This is the building block type for attributes
+ * with non-fundamental types
+ */
+ struct type : public base_generator
+ {
+ static inline const string& separator(void)
+ {
+ static string sep(BOOST_CTS_LIT("/"));
+ return sep;
+ }
+
+ /** The constructor composes the path to this
+ * part of the geenrated class and passes along
+ * to the base generator
+ */
+ type(const string& path)
+ : base_generator(
+ path +
+ separator() +
+ MetaAttribute::base_name()
+ ) { }
+ };
+};
+
+
+/** Implementation of building block getter meta-function
+ */
+template <class MetaAttribute>
+struct get_building_block
+{
+ typedef typename MetaAttribute::type::reflected_type
+ attrib_type;
+
+ typedef typename do_get_building_block<
+ MetaAttribute,
+ ::boost::mpl::bool_<
+ ::boost::is_fundamental<attrib_type>::value
+ >
+ >::type type;
+};
+
+/** A test function which uses the generated vectors and calculates
+ * the difference between them.
+ */
+template <class GeneratedVector1, class GeneratedVector2>
+double difference(const GeneratedVector1& v1, const GeneratedVector2& v2)
+{
+ return ::std::sqrt(
+ v1.x.get()*v2.x.get() +
+ v1.y.get()*v2.y.get() +
+ v1.z.get()*v2.z.get()
+ );
+}
+
+} // namespace test
+
+int main(void)
+{
+ using namespace ::std;
+ using namespace ::boost;
+ //
+ cts::bostream& bcout = cts::bcout();
+ typedef BOOST_MIRRORED_CLASS(::test::tetrahedron) meta_T;
+ //
+ // uses the class generator and the meta-data about the
+ // ::test::person class to create a new class with
+ // the same set of attributes which are made of
+ // the ::test::building_block instantiations.
+ typedef mirror::class_generator<
+ meta_T::all_attributes,
+ ::test::get_building_block,
+ mpl::false_
+ > tetrahedron;
+ ::test::string name(BOOST_CTS_LIT("t"));
+ tetrahedron t(name);
+ //
+ // use compare the differences between the individual
+ // vectors in the tetrahedron
+ if(::test::difference(t.a, t.b) > ::test::difference(t.c, t.d))
+ bcout << "|ab| > |cd|" << ::std::endl;
+ else bcout << "|ab| <= |cd|" << ::std::endl;
+ //
+ // set the value of the t.a's and t.b's coordinates
+ t.a.x = 1.0;
+ t.a.y = 2.0;
+ t.a.z = 3.0;
+ t.b.x = 4.0;
+ t.b.y = 5.0;
+ t.b.z = 6.0;
+ //
+ return 0;
+}
+
Modified: sandbox/mirror/libs/mirror/test/Jamfile.v2
==============================================================================
--- sandbox/mirror/libs/mirror/test/Jamfile.v2 (original)
+++ sandbox/mirror/libs/mirror/test/Jamfile.v2 2009-03-27 12:02:37 EDT (Fri, 27 Mar 2009)
@@ -37,6 +37,7 @@
[ compile classes_ct_07.cpp ]
[ compile classes_ct_08.cpp ]
[ compile classes_ct_09.cpp ]
+ [ compile classes_ct_10.cpp ]
[ run classes_rt_01.cpp ]
[ run classes_rt_02.cpp ]
[ run classes_rt_03.cpp ]
@@ -47,11 +48,14 @@
[ run classes_rt_08.cpp ]
[ run classes_rt_09.cpp ]
[ run classes_rt_10.cpp ]
+ [ run classes_rt_11.cpp ]
[ compile concepts_ct_01.cpp ]
[ compile concepts_ct_02.cpp ]
[ compile concepts_ct_03.cpp ]
[ compile other_ct_01.cpp ]
[ run other_rt_01.cpp ]
[ run other_rt_02.cpp ]
+ [ run visitors_01.cpp ]
+ [ run visitors_02.cpp ]
;
Added: sandbox/mirror/libs/mirror/test/classes_ct_10.cpp
==============================================================================
--- (empty file)
+++ sandbox/mirror/libs/mirror/test/classes_ct_10.cpp 2009-03-27 12:02:37 EDT (Fri, 27 Mar 2009)
@@ -0,0 +1,135 @@
+/**
+ * \file test/classes_ct_10.cpp
+ *
+ * This file is part of the Mirror library testsuite.
+ *
+ * Testing the by_name metafunction
+ *
+ * This test focuses on the testing of the by_name intrinsic
+ * meta-function with meta-class-attributes
+ *
+ * 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)
+ */
+
+// MPL
+#include <boost/mpl/assert.hpp>
+//
+#include <boost/type_traits/is_same.hpp>
+//
+#include <boost/mirror/meta_class.hpp>
+#include <boost/mirror/intrinsic/by_name.hpp>
+#include <boost/mirror/intrinsic/at.hpp>
+//
+#include "./simple_classes.hpp"
+#include "./test.hpp"
+
+template <class MetaAttribute1, class MetaAttribute2>
+void test_attribs(void)
+{
+ BOOST_MPL_ASSERT((
+ is_same<
+ MetaAttribute1::type::reflected_type,
+ MetaAttribute2::type::reflected_type
+ >
+ ));
+ BOOST_MPL_ASSERT((
+ is_same<
+ MetaAttribute1::scope::type::reflected_type,
+ MetaAttribute2::scope::type::reflected_type
+ >
+ ));
+}
+
+void test_main()
+{
+ using namespace ::std;
+ using namespace ::boost;
+ using namespace ::boost::mirror;
+ //
+ typedef BOOST_MIRRORED_CLASS(::test::A) meta_A;
+ typedef BOOST_MIRRORED_CLASS(::test::B) meta_B;
+ typedef BOOST_MIRRORED_CLASS(::test::C) meta_C;
+ typedef BOOST_MIRRORED_CLASS(::test::D) meta_D;
+ typedef BOOST_MIRRORED_CLASS(::test::E) meta_E;
+ typedef BOOST_MIRRORED_CLASS(::test::F) meta_F;
+ typedef BOOST_MIRRORED_CLASS(::test::G) meta_G;
+ typedef BOOST_MIRRORED_CLASS(::test::H) meta_H;
+ //
+ test_attribs<
+ by_name<meta_A::attributes>::a,
+ at<meta_A::attributes, mpl::int_<0> >::type
+ >();
+ test_attribs<
+ by_name<meta_B::attributes>::b,
+ at<meta_B::attributes, mpl::int_<0> >::type
+ >();
+ test_attribs<
+ by_name<meta_C::attributes>::c,
+ at<meta_C::attributes, mpl::int_<0> >::type
+ >();
+ test_attribs<
+ by_name<meta_D::attributes>::d,
+ at<meta_D::attributes, mpl::int_<0> >::type
+ >();
+ test_attribs<
+ by_name<meta_E::attributes>::e,
+ at<meta_E::attributes, mpl::int_<0> >::type
+ >();
+ test_attribs<
+ by_name<meta_F::attributes>::f,
+ at<meta_F::attributes, mpl::int_<0> >::type
+ >();
+ test_attribs<
+ by_name<meta_G::attributes>::g,
+ at<meta_G::attributes, mpl::int_<0> >::type
+ >();
+ test_attribs<
+ by_name<meta_H::attributes>::h,
+ at<meta_H::attributes, mpl::int_<0> >::type
+ >();
+ //
+ test_attribs<
+ by_name<meta_H::all_attributes>::a,
+ at<meta_H::all_attributes, mpl::int_<0> >::type
+ >();
+ test_attribs<
+ by_name<meta_H::all_attributes>::b,
+ at<meta_H::all_attributes, mpl::int_<1> >::type
+ >();
+ test_attribs<
+ by_name<meta_H::all_attributes>::c,
+ at<meta_H::all_attributes, mpl::int_<2> >::type
+ >();
+ test_attribs<
+ by_name<meta_H::all_attributes>::d,
+ at<meta_H::all_attributes, mpl::int_<3> >::type
+ >();
+ test_attribs<
+ by_name<meta_H::all_attributes>::e,
+ at<meta_H::all_attributes, mpl::int_<4> >::type
+ >();
+ test_attribs<
+ by_name<meta_H::all_attributes>::f,
+ at<meta_H::all_attributes, mpl::int_<5> >::type
+ >();
+ test_attribs<
+ by_name<meta_H::all_attributes>::g,
+ at<meta_H::all_attributes, mpl::int_<6> >::type
+ >();
+ test_attribs<
+ by_name<meta_H::all_attributes>::h,
+ at<meta_H::all_attributes, mpl::int_<7> >::type
+ >();
+
+}
+
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("Mirror: classes compile test 10");
+ test->add(BOOST_TEST_CASE(&test_main));
+ return test;
+}
+
+
Added: sandbox/mirror/libs/mirror/test/classes_rt_11.cpp
==============================================================================
--- (empty file)
+++ sandbox/mirror/libs/mirror/test/classes_rt_11.cpp 2009-03-27 12:02:37 EDT (Fri, 27 Mar 2009)
@@ -0,0 +1,129 @@
+/**
+ * \file test/classes_rt_11.cpp
+ *
+ * This file is part of the Mirror library testsuite.
+ *
+ * Testing the by_name metafunction
+ *
+ * This test focuses on the testing of the by_name intrinsic
+ * meta-function with meta-class-attributes
+ *
+ * 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)
+ */
+
+// MPL
+#include <boost/mpl/assert.hpp>
+//
+#include <boost/mirror/meta_class.hpp>
+#include <boost/mirror/intrinsic/by_name.hpp>
+#include <boost/mirror/intrinsic/at.hpp>
+//
+#include "./simple_classes.hpp"
+#include "./test.hpp"
+
+template <class MetaAttribute1, class MetaAttribute2>
+void test_attribs(void)
+{
+ BOOST_CHECK(
+ MetaAttribute1::scope::full_name() ==
+ MetaAttribute1::scope::full_name()
+ );
+ BOOST_CHECK(
+ MetaAttribute1::base_name() ==
+ MetaAttribute1::base_name()
+ );
+}
+
+void test_main()
+{
+ using namespace ::std;
+ using namespace ::boost;
+ using namespace ::boost::mirror;
+ //
+ typedef BOOST_MIRRORED_CLASS(::test::A) meta_A;
+ typedef BOOST_MIRRORED_CLASS(::test::B) meta_B;
+ typedef BOOST_MIRRORED_CLASS(::test::C) meta_C;
+ typedef BOOST_MIRRORED_CLASS(::test::D) meta_D;
+ typedef BOOST_MIRRORED_CLASS(::test::E) meta_E;
+ typedef BOOST_MIRRORED_CLASS(::test::F) meta_F;
+ typedef BOOST_MIRRORED_CLASS(::test::G) meta_G;
+ typedef BOOST_MIRRORED_CLASS(::test::H) meta_H;
+ //
+ test_attribs<
+ by_name<meta_A::attributes>::a,
+ at<meta_A::attributes, mpl::int_<0> >::type
+ >();
+ test_attribs<
+ by_name<meta_B::attributes>::b,
+ at<meta_B::attributes, mpl::int_<0> >::type
+ >();
+ test_attribs<
+ by_name<meta_C::attributes>::c,
+ at<meta_C::attributes, mpl::int_<0> >::type
+ >();
+ test_attribs<
+ by_name<meta_D::attributes>::d,
+ at<meta_D::attributes, mpl::int_<0> >::type
+ >();
+ test_attribs<
+ by_name<meta_E::attributes>::e,
+ at<meta_E::attributes, mpl::int_<0> >::type
+ >();
+ test_attribs<
+ by_name<meta_F::attributes>::f,
+ at<meta_F::attributes, mpl::int_<0> >::type
+ >();
+ test_attribs<
+ by_name<meta_G::attributes>::g,
+ at<meta_G::attributes, mpl::int_<0> >::type
+ >();
+ test_attribs<
+ by_name<meta_H::attributes>::h,
+ at<meta_H::attributes, mpl::int_<0> >::type
+ >();
+ //
+ test_attribs<
+ by_name<meta_H::all_attributes>::a,
+ at<meta_H::all_attributes, mpl::int_<0> >::type
+ >();
+ test_attribs<
+ by_name<meta_H::all_attributes>::b,
+ at<meta_H::all_attributes, mpl::int_<1> >::type
+ >();
+ test_attribs<
+ by_name<meta_H::all_attributes>::c,
+ at<meta_H::all_attributes, mpl::int_<2> >::type
+ >();
+ test_attribs<
+ by_name<meta_H::all_attributes>::d,
+ at<meta_H::all_attributes, mpl::int_<3> >::type
+ >();
+ test_attribs<
+ by_name<meta_H::all_attributes>::e,
+ at<meta_H::all_attributes, mpl::int_<4> >::type
+ >();
+ test_attribs<
+ by_name<meta_H::all_attributes>::f,
+ at<meta_H::all_attributes, mpl::int_<5> >::type
+ >();
+ test_attribs<
+ by_name<meta_H::all_attributes>::g,
+ at<meta_H::all_attributes, mpl::int_<6> >::type
+ >();
+ test_attribs<
+ by_name<meta_H::all_attributes>::h,
+ at<meta_H::all_attributes, mpl::int_<7> >::type
+ >();
+
+}
+
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("Mirror: classes compile test 10");
+ test->add(BOOST_TEST_CASE(&test_main));
+ return test;
+}
+
+
Added: sandbox/mirror/libs/mirror/test/simple_classes.hpp
==============================================================================
--- (empty file)
+++ sandbox/mirror/libs/mirror/test/simple_classes.hpp 2009-03-27 12:02:37 EDT (Fri, 27 Mar 2009)
@@ -0,0 +1,128 @@
+/**
+ * \file test/classes.hpp
+ *
+ * This file is part of the Mirror library testsuite.
+ *
+ * Several test classes
+ *
+ * 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_LIBS_MIRROR_TEST_CLASSES_HPP
+#define BOOST_MIRROR_LIBS_MIRROR_TEST_CLASSES_HPP
+
+#include "./namespaces.hpp"
+
+namespace test {
+
+struct A
+{
+ ::std::string a;
+};
+
+struct B : A
+{
+ bool b;
+};
+
+struct C : B
+{
+ char c;
+};
+
+struct D : C
+{
+ double d;
+};
+
+struct E : D
+{
+ wchar_t e;
+};
+
+struct F : E
+{
+ float f;
+};
+
+struct G : F
+{
+ unsigned g;
+};
+
+struct H : G
+{
+ short h;
+};
+
+} // namespace test
+
+namespace boost {
+namespace mirror {
+
+BOOST_MIRROR_REG_TYPE(::test, A)
+BOOST_MIRROR_REG_CLASS_ATTRIBS_BEGIN(::test::A)
+ BOOST_MIRROR_REG_AUTO_CLASS_ATTRIB(_, a)
+BOOST_MIRROR_REG_CLASS_ATTRIBS_END
+
+BOOST_MIRROR_REG_TYPE(::test, B)
+BOOST_MIRROR_REG_BASE_CLASSES_BEGIN(::test::B)
+ BOOST_MIRROR_REG_BASE_CLASS(0, public, ::test::A)
+BOOST_MIRROR_REG_BASE_CLASSES_END
+BOOST_MIRROR_REG_CLASS_ATTRIBS_BEGIN(::test::B)
+ BOOST_MIRROR_REG_AUTO_CLASS_ATTRIB(_, b)
+BOOST_MIRROR_REG_CLASS_ATTRIBS_END
+
+BOOST_MIRROR_REG_TYPE(::test, C)
+BOOST_MIRROR_REG_BASE_CLASSES_BEGIN(::test::C)
+ BOOST_MIRROR_REG_BASE_CLASS(0, public, ::test::B)
+BOOST_MIRROR_REG_BASE_CLASSES_END
+BOOST_MIRROR_REG_CLASS_ATTRIBS_BEGIN(::test::C)
+ BOOST_MIRROR_REG_AUTO_CLASS_ATTRIB(_, c)
+BOOST_MIRROR_REG_CLASS_ATTRIBS_END
+
+BOOST_MIRROR_REG_TYPE(::test, D)
+BOOST_MIRROR_REG_BASE_CLASSES_BEGIN(::test::D)
+ BOOST_MIRROR_REG_BASE_CLASS(0, public, ::test::C)
+BOOST_MIRROR_REG_BASE_CLASSES_END
+BOOST_MIRROR_REG_CLASS_ATTRIBS_BEGIN(::test::D)
+ BOOST_MIRROR_REG_AUTO_CLASS_ATTRIB(_, d)
+BOOST_MIRROR_REG_CLASS_ATTRIBS_END
+
+BOOST_MIRROR_REG_TYPE(::test, E)
+BOOST_MIRROR_REG_BASE_CLASSES_BEGIN(::test::E)
+ BOOST_MIRROR_REG_BASE_CLASS(0, public, ::test::D)
+BOOST_MIRROR_REG_BASE_CLASSES_END
+BOOST_MIRROR_REG_CLASS_ATTRIBS_BEGIN(::test::E)
+ BOOST_MIRROR_REG_AUTO_CLASS_ATTRIB(_, e)
+BOOST_MIRROR_REG_CLASS_ATTRIBS_END
+
+BOOST_MIRROR_REG_TYPE(::test, F)
+BOOST_MIRROR_REG_BASE_CLASSES_BEGIN(::test::F)
+ BOOST_MIRROR_REG_BASE_CLASS(0, public, ::test::E)
+BOOST_MIRROR_REG_BASE_CLASSES_END
+BOOST_MIRROR_REG_CLASS_ATTRIBS_BEGIN(::test::F)
+ BOOST_MIRROR_REG_AUTO_CLASS_ATTRIB(_, f)
+BOOST_MIRROR_REG_CLASS_ATTRIBS_END
+
+BOOST_MIRROR_REG_TYPE(::test, G)
+BOOST_MIRROR_REG_BASE_CLASSES_BEGIN(::test::G)
+ BOOST_MIRROR_REG_BASE_CLASS(0, public, ::test::F)
+BOOST_MIRROR_REG_BASE_CLASSES_END
+BOOST_MIRROR_REG_CLASS_ATTRIBS_BEGIN(::test::G)
+ BOOST_MIRROR_REG_AUTO_CLASS_ATTRIB(_, g)
+BOOST_MIRROR_REG_CLASS_ATTRIBS_END
+
+BOOST_MIRROR_REG_TYPE(::test, H)
+BOOST_MIRROR_REG_BASE_CLASSES_BEGIN(::test::H)
+ BOOST_MIRROR_REG_BASE_CLASS(0, public, ::test::G)
+BOOST_MIRROR_REG_BASE_CLASSES_END
+BOOST_MIRROR_REG_CLASS_ATTRIBS_BEGIN(::test::H)
+ BOOST_MIRROR_REG_AUTO_CLASS_ATTRIB(_, h)
+BOOST_MIRROR_REG_CLASS_ATTRIBS_END
+
+} // namespace miror
+} // namespace boost
+
+#endif
Added: sandbox/mirror/libs/mirror/test/visitors_01.cpp
==============================================================================
--- (empty file)
+++ sandbox/mirror/libs/mirror/test/visitors_01.cpp 2009-03-27 12:02:37 EDT (Fri, 27 Mar 2009)
@@ -0,0 +1,196 @@
+/**
+ * \file test/visitors_01.cpp
+ *
+ * This file is part of the Mirror library testsuite.
+ *
+ * Testing traversals
+ *
+ * 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 <map>
+
+#include <boost/mirror/meta_class.hpp>
+#include <boost/mirror/meta_classes/std/pair.hpp>
+#include <boost/mirror/meta_classes/boost/tuples/tuple.hpp>
+#include <boost/mirror/meta_classes/boost/fusion/vector.hpp>
+#include <boost/mirror/traversal.hpp>
+
+#include "./namespaces.hpp"
+#include "./simple_classes.hpp"
+#include "./test.hpp"
+
+typedef ::std::map< ::std::string, int > visitors_log;
+
+struct visitor_1
+{
+ typedef ::boost::mpl::false_ works_on_instances;
+
+ visitors_log& log;
+
+ visitor_1(visitors_log& _log)
+ : log(_log)
+ { }
+
+ template <class MetaNamespace, class Context>
+ void enter_namespace(MetaNamespace, Context)
+ {
+ ++log["item"];
+ ++log["namespace"];
+ }
+
+ template <class MetaObjectSequence, class Context>
+ void enter_namespace_members(MetaObjectSequence, Context)
+ {
+ ++log["item"];
+ ++log["namespace_members"];
+ }
+
+ template <class MetaClass, class Context>
+ void enter_type(MetaClass, Context)
+ {
+ ++log["item"];
+ ++log["type"];
+ }
+
+ template <class MetaClass, class BaseClasses, class Context>
+ void enter_base_classes(MetaClass, BaseClasses, Context)
+ {
+ ++log["item"];
+ ++log["base_classes"];
+ }
+
+ template <class MetaInheritance, class Context>
+ void enter_base_class(MetaInheritance, Context)
+ {
+ ++log["item"];
+ ++log["base_class"];
+ }
+
+ template <class MetaClass, class MetaAttributes, class Context>
+ void enter_attributes(MetaClass, MetaAttributes, Context)
+ {
+ ++log["item"];
+ ++log["attributes"];
+ }
+
+ template <class MetaAttribute, class Context>
+ void enter_attribute(MetaAttribute, Context)
+ {
+ ++log["item"];
+ ++log["attribute"];
+ }
+};
+
+
+struct visitor_2
+{
+ typedef ::boost::mpl::false_ works_on_instances;
+
+ visitors_log& log;
+
+ visitor_2(visitors_log& _log)
+ : log(_log)
+ { }
+
+ template <class MetaNamespace, class Context>
+ void leave_namespace(MetaNamespace, Context)
+ {
+ ++log["item"];
+ ++log["namespace"];
+ }
+
+ template <class MetaObjectSequence, class Context>
+ void leave_namespace_members(MetaObjectSequence, Context)
+ {
+ ++log["item"];
+ ++log["namespace_members"];
+ }
+
+ template <class MetaClass, class Context>
+ void leave_type(MetaClass, Context)
+ {
+ ++log["item"];
+ ++log["type"];
+ }
+
+ template <class MetaClass, class BaseClasses, class Context>
+ void leave_base_classes(MetaClass, BaseClasses, Context)
+ {
+ ++log["item"];
+ ++log["base_classes"];
+ }
+
+ template <class MetaInheritance, class Context>
+ void leave_base_class(MetaInheritance, Context)
+ {
+ ++log["item"];
+ ++log["base_class"];
+ }
+
+ template <class MetaClass, class MetaAttributes, class Context>
+ void leave_attributes(MetaClass, MetaAttributes, Context)
+ {
+ ++log["item"];
+ ++log["attributes"];
+ }
+
+ template <class MetaAttribute, class Context>
+ void leave_attribute(MetaAttribute, Context)
+ {
+ ++log["item"];
+ ++log["attribute"];
+ }
+};
+
+template <class MetaClass>
+void test_traversals(void)
+{
+ using namespace ::boost::mirror;
+ //
+ visitors_log log1, log2;
+ //
+ deep_traversal_of<MetaClass>::accept(visitor_1(log1));
+ deep_traversal_of<MetaClass>::accept(visitor_2(log2));
+ //
+ BOOST_CHECK(!log1.empty());
+ BOOST_CHECK(!log2.empty());
+ BOOST_CHECK(log1["item"] > 0);
+ BOOST_CHECK(log2["item"] > 0);
+ BOOST_CHECK(log1 == log2);
+ //
+ log1.clear();
+ log2.clear();
+ //
+ flat_traversal_of<MetaClass>::accept(visitor_1(log1));
+ flat_traversal_of<MetaClass>::accept(visitor_2(log2));
+ //
+ BOOST_CHECK(!log1.empty());
+ BOOST_CHECK(!log2.empty());
+ BOOST_CHECK(log1["item"] > 0);
+ BOOST_CHECK(log2["item"] > 0);
+ BOOST_CHECK(log1 == log2);
+}
+
+
+void test_main()
+{
+ typedef ::std::pair< ::std::string, ::std::wstring> P;
+ typedef ::boost::tuple<bool, char, short, int, long, float, double> T;
+ typedef ::boost::fusion::vector<bool, char, short, int, long, float> V;
+
+ test_traversals<BOOST_MIRRORED_CLASS(::test::H)>();
+ test_traversals<BOOST_MIRRORED_CLASS(P)>();
+ test_traversals<BOOST_MIRRORED_CLASS(T)>();
+ test_traversals<BOOST_MIRRORED_CLASS(V)>();
+}
+
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("Mirror: traversals/visitors run-time test 01");
+ test->add(BOOST_TEST_CASE(&test_main));
+ return test;
+}
+
+
Added: sandbox/mirror/libs/mirror/test/visitors_02.cpp
==============================================================================
--- (empty file)
+++ sandbox/mirror/libs/mirror/test/visitors_02.cpp 2009-03-27 12:02:37 EDT (Fri, 27 Mar 2009)
@@ -0,0 +1,94 @@
+/**
+ * \file test/visitors_02.cpp
+ *
+ * This file is part of the Mirror library testsuite.
+ *
+ * Testing traversals
+ *
+ *
+ * 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/meta_class.hpp>
+#include <boost/mirror/meta_classes/std/pair.hpp>
+#include <boost/mirror/meta_classes/boost/tuples/tuple.hpp>
+#include <boost/mirror/traversal.hpp>
+
+#include "./namespaces.hpp"
+#include "./simple_classes.hpp"
+#include "./test.hpp"
+
+
+struct visitor_1
+{
+ typedef ::boost::mpl::true_ works_on_instances;
+
+ size_t& size;
+
+ visitor_1(size_t& _size)
+ : size(_size)
+ { }
+
+ template <class MetaClass, class Context, typename InstanceType>
+ void visit_instance(MetaClass, Context ctx, InstanceType* ptr_to_inst)
+ {
+ size += sizeof(*ptr_to_inst);
+ }
+};
+
+struct visitor_2
+{
+ typedef ::boost::mpl::true_ works_on_instances;
+
+ size_t& size;
+
+ visitor_2(size_t& _size)
+ : size(_size)
+ { }
+
+ template <class MetaClass, class Context, typename InstanceType>
+ void visit_instance(MetaClass, Context ctx, InstanceType* ptr_to_inst)
+ {
+ size -= sizeof(*ptr_to_inst);
+ }
+};
+
+template <class Class>
+void test_traversals(const Class& instance)
+{
+ using namespace ::boost::mirror;
+ typedef BOOST_MIRRORED_CLASS(Class) meta_Class;
+
+ size_t size = 0;
+
+ deep_traversal_of<meta_Class>::accept(visitor_1(size), &instance);
+ BOOST_CHECK(size > 0);
+ deep_traversal_of<meta_Class>::accept(visitor_2(size), &instance);
+ BOOST_CHECK(size == 0);
+
+ flat_traversal_of<meta_Class>::accept(visitor_1(size), &instance);
+ BOOST_CHECK(size > 0);
+ flat_traversal_of<meta_Class>::accept(visitor_2(size), &instance);
+ BOOST_CHECK(size == 0);
+
+}
+
+
+void test_main()
+{
+ using namespace ::std;
+ using namespace ::boost;
+
+ test_traversals(make_tuple(0,1,2,3,4,5,6,7,8,9));
+ test_traversals(pair<string, wstring>("ABC",L"DEF"));
+}
+
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("Mirror: traversals/visitors run-time test 02");
+ test->add(BOOST_TEST_CASE(&test_main));
+ return test;
+}
+
+
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