Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r48736 - in sandbox/mirror: boost/mirror boost/mirror/detail boost/mirror/meta_classes boost/mirror/meta_namespaces boost/mirror/meta_types libs/mirror/example/special libs/mirror/test
From: chochlik_at_[hidden]
Date: 2008-09-11 13:19:17


Author: matus.chochlik
Date: 2008-09-11 13:19:16 EDT (Thu, 11 Sep 2008)
New Revision: 48736
URL: http://svn.boost.org/trac/boost/changeset/48736

Log:
[mirror 0.2.x]
- added support for fusion::vector
- added several new tests into the testsuite
Added:
   sandbox/mirror/boost/mirror/detail/unnamed_attribs.hpp (contents, props changed)
   sandbox/mirror/boost/mirror/meta_classes/boost_fusion_vector.hpp (contents, props changed)
   sandbox/mirror/boost/mirror/meta_namespaces/boost_fusion.hpp (contents, props changed)
   sandbox/mirror/boost/mirror/meta_types/boost_fusion_vector.hpp (contents, props changed)
   sandbox/mirror/libs/mirror/test/classes_rt_02.cpp (contents, props changed)
   sandbox/mirror/libs/mirror/test/classes_rt_03.cpp (contents, props changed)
   sandbox/mirror/libs/mirror/test/classes_rt_04.cpp (contents, props changed)
   sandbox/mirror/libs/mirror/test/classes_rt_05.cpp (contents, props changed)
   sandbox/mirror/libs/mirror/test/classes_rt_06.cpp (contents, props changed)
   sandbox/mirror/libs/mirror/test/classes_rt_07.cpp (contents, props changed)
Text files modified:
   sandbox/mirror/boost/mirror/detail/meta_attribs_base.hpp | 3 ++-
   sandbox/mirror/boost/mirror/meta_attributes.hpp | 10 ++++++++++
   sandbox/mirror/boost/mirror/meta_classes/boost_tuple.hpp | 22 ++--------------------
   sandbox/mirror/boost/mirror/meta_inheritance.hpp | 4 +++-
   sandbox/mirror/libs/mirror/example/special/boost_tuple.cpp | 3 ++-
   sandbox/mirror/libs/mirror/test/Jamfile.v2 | 6 ++++++
   sandbox/mirror/libs/mirror/test/classes.hpp | 10 +++++-----
   sandbox/mirror/libs/mirror/test/classes_rt_01.cpp | 2 +-
   8 files changed, 31 insertions(+), 29 deletions(-)

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 2008-09-11 13:19:16 EDT (Thu, 11 Sep 2008)
@@ -18,6 +18,7 @@
 #include <boost/mirror/detail/meta_attribs_outline.hpp>
 //
 #include <boost/preprocessor/repetition/enum_params.hpp>
+#include <boost/mpl/vector.hpp>
 //
 // necessary type traits
 #include <boost/call_traits.hpp>
@@ -35,7 +36,7 @@
 template <class Class, class VariantTag>
 struct meta_class_attributes
 {
- typedef mpl::vector<> type_list;
+ typedef mpl::vector0<> type_list;
 };
 
 /** Possible class attribute storage specifiers

Added: sandbox/mirror/boost/mirror/detail/unnamed_attribs.hpp
==============================================================================
--- (empty file)
+++ sandbox/mirror/boost/mirror/detail/unnamed_attribs.hpp 2008-09-11 13:19:16 EDT (Thu, 11 Sep 2008)
@@ -0,0 +1,40 @@
+/**
+ * \file boost/mirror/detail/unnamed_attribs.hpp
+ * Basic class for getting names of attributes of tuple-like 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_DETAIL_UNNAMED_ATTRIBS_HPP
+#define BOOST_MIRROR_DETAIL_UNNAMED_ATTRIBS_HPP
+
+#include <boost/mirror/detail/static_int_to_str.hpp>
+
+namespace boost {
+namespace mirror {
+namespace detail {
+ //
+ // specializations of this meta-function return a vector
+ // containing the proper 'static string' that is used as
+ // prefix for tuple member attribute names
+ template <typename CharT>
+ struct meta_class_tuple_attrib_name_prefix;
+
+ template <>
+ struct meta_class_tuple_attrib_name_prefix<char>
+ {
+ typedef mpl::vector_c<char, '_' > type;
+ };
+ template <>
+ struct meta_class_tuple_attrib_name_prefix<wchar_t>
+ {
+ typedef mpl::vector_c<wchar_t, L'_' > type;
+ };
+} // namespace detail
+} // namespace mirror
+} // namespace boost
+
+#endif //include guard
+

Modified: sandbox/mirror/boost/mirror/meta_attributes.hpp
==============================================================================
--- sandbox/mirror/boost/mirror/meta_attributes.hpp (original)
+++ sandbox/mirror/boost/mirror/meta_attributes.hpp 2008-09-11 13:19:16 EDT (Thu, 11 Sep 2008)
@@ -10,11 +10,21 @@
 #ifndef BOOST_MIRROR_META_ATTRIBUTES_HPP
 #define BOOST_MIRROR_META_ATTRIBUTES_HPP
 
+#include <boost/mirror/traits/reflects_virtual_inheritance.hpp>
 // macros for declaration of simple meta attributes
 #include <boost/mirror/detail/meta_attribs_base.hpp>
 //
+#include <boost/char_type_switch/string.hpp>
+//
 #include <boost/typeof/typeof.hpp>
 #include <boost/mpl/eval_if.hpp>
+#include <boost/mpl/remove_if.hpp>
+#include <boost/mpl/push_back.hpp>
+#include <boost/mpl/insert_range.hpp>
+#include <boost/mpl/accumulate.hpp>
+#include <boost/mpl/contains.hpp>
+#include <boost/mpl/less.hpp>
+#include <boost/mpl/lambda.hpp>
 
 namespace boost {
 namespace mirror {

Added: sandbox/mirror/boost/mirror/meta_classes/boost_fusion_vector.hpp
==============================================================================
--- (empty file)
+++ sandbox/mirror/boost/mirror/meta_classes/boost_fusion_vector.hpp 2008-09-11 13:19:16 EDT (Thu, 11 Sep 2008)
@@ -0,0 +1,119 @@
+/**
+ * \file boost/mirror/meta_classes/boost_fusion_vector.hpp
+ * Meta-class for boost::fusion::vector<T0, T1, ..., Tn>
+ *
+ * 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_CLASSES_BOOST_FUSION_VECTOR_HPP
+#define BOOST_MIRROR_META_CLASSES_BOOST_FUSION_VECTOR_HPP
+
+#include <boost/mirror/meta_class.hpp>
+#include <boost/mirror/meta_types/boost_fusion_vector.hpp>
+#include <boost/mirror/detail/static_int_to_str.hpp>
+#include <boost/mirror/detail/unnamed_attribs.hpp>
+#include <boost/fusion/sequence/intrinsic/at.hpp>
+
+
+namespace boost {
+namespace mirror {
+
+
+BOOST_MIRROR_REG_TEMPLATE_ATTRIBS_BEGIN(
+ ::boost::fusion::vector,
+ FUSION_MAX_VECTOR_SIZE
+)
+ __dummy_list;
+ //
+ //
+ // the full list vectors template arguments
+ typedef typename mpl::vector<
+ BOOST_PP_ENUM_PARAMS(FUSION_MAX_VECTOR_SIZE, T)
+ > all_template_params;
+ //
+ // the list of member attributes without the null types
+ typedef typename detail::template_args_type_list_wo_nulls<
+ all_template_params
+ >::type template_params;
+ //
+ template <int I>
+ struct att_val_pass
+ {
+ typedef typename call_traits<
+ typename mpl::at<template_params, mpl::int_<I> >::type
+ >::param_type type;
+ };
+ //
+ // member attribute base name getter
+ template <int I, typename CharT>
+ inline static const ::std::basic_string<CharT>& get_name(
+ mpl::int_<I> pos,
+ mpl::false_ full_name,
+ ::std::char_traits<CharT> cht
+ )
+ {
+ // get the prefix 'static string'
+ typedef typename detail::meta_class_tuple_attrib_name_prefix<
+ CharT
+ >::type prefix;
+ // get a prefixed name builder
+ typedef typename boost::mirror::detail::static_int_to_str_w_prefix<
+ prefix,
+ CharT,
+ I
+ >::holder name_builder;
+ // build the name and assing it to the static name
+ static ::std::basic_string<CharT> name(name_builder::get());
+ // return the built name
+ return name;
+ }
+
+ // traits getter
+ template <int I>
+ static meta_class_attribute_traits<
+ ::boost::mirror::attrib_storage_specifiers::__,
+ typename att_val_pass<I>::type
+ > get_traits(mpl::int_<I>);
+
+
+ // member attrib value get
+ template <int I>
+ static typename att_val_pass<I>::type
+ get(const Class& an_inst, mpl::int_<I>)
+ {
+ return ::boost::fusion::at_c<I>(an_inst);
+ }
+
+ // member attrib value query
+ template <typename dest_type, int I>
+ static dest_type& query(const Class& an_inst, mpl::int_<I>, dest_type& dest)
+ {
+ dest = dest_type(::boost::fusion::at_c<I>(an_inst));
+ return dest;
+ }
+
+ // member attrib value set
+ template <int I>
+ static void set(Class& an_inst, mpl::int_<I>, typename att_val_pass<I>::type val)
+ {
+ ::boost::fusion::at_c<I>(an_inst) = val;
+ }
+
+ // const member attrib value set
+ template <int I>
+ static void set(const Class& an_inst, mpl::int_<I>, typename att_val_pass<I>::type val)
+ {
+ }
+
+ //
+ typedef template_params
+BOOST_MIRROR_REG_TEMPLATE_ATTRIBS_END
+
+
+} // namespace mirror
+} // namespace boost
+
+#endif //include guard
+

Modified: sandbox/mirror/boost/mirror/meta_classes/boost_tuple.hpp
==============================================================================
--- sandbox/mirror/boost/mirror/meta_classes/boost_tuple.hpp (original)
+++ sandbox/mirror/boost/mirror/meta_classes/boost_tuple.hpp 2008-09-11 13:19:16 EDT (Thu, 11 Sep 2008)
@@ -13,28 +13,10 @@
 #include <boost/mirror/meta_class.hpp>
 #include <boost/mirror/meta_types/boost_tuple.hpp>
 #include <boost/mirror/detail/static_int_to_str.hpp>
+#include <boost/mirror/detail/unnamed_attribs.hpp>
 
 namespace boost {
 namespace mirror {
-namespace detail {
- //
- // specializations of this meta-function return a vector
- // containing the proper 'static string' that is used as
- // prefix for tuple member attribute names
- template <typename CharT>
- struct meta_class_boost_tuple_attrib_name_prefix;
-
- template <>
- struct meta_class_boost_tuple_attrib_name_prefix<char>
- {
- typedef mpl::vector_c<char, '_' > type;
- };
- template <>
- struct meta_class_boost_tuple_attrib_name_prefix<wchar_t>
- {
- typedef mpl::vector_c<wchar_t, L'_' > type;
- };
-} // namespace detail
 
 BOOST_MIRROR_REG_TEMPLATE_ATTRIBS_BEGIN(::boost::tuples::tuple, 10)
         __dummy_list;
@@ -58,7 +40,7 @@
         )
         {
                 // get the prefix 'static string'
- typedef typename detail::meta_class_boost_tuple_attrib_name_prefix<
+ typedef typename detail::meta_class_tuple_attrib_name_prefix<
                         CharT
>::type prefix;
                 // get a prefixed name builder

Modified: sandbox/mirror/boost/mirror/meta_inheritance.hpp
==============================================================================
--- sandbox/mirror/boost/mirror/meta_inheritance.hpp (original)
+++ sandbox/mirror/boost/mirror/meta_inheritance.hpp 2008-09-11 13:19:16 EDT (Thu, 11 Sep 2008)
@@ -18,6 +18,8 @@
 #include <boost/mirror/inherit_spec.hpp>
 // class 'kind' specifiers
 #include <boost/mirror/class_kind_spec.hpp>
+//
+#include <boost/mpl/vector.hpp>
 
 namespace boost {
 namespace mirror {
@@ -140,7 +142,7 @@
>
 struct meta_base_classes
 {
- typedef mpl::vector<> list;
+ typedef mpl::vector0<> list;
 };
 
 

Added: sandbox/mirror/boost/mirror/meta_namespaces/boost_fusion.hpp
==============================================================================
--- (empty file)
+++ sandbox/mirror/boost/mirror/meta_namespaces/boost_fusion.hpp 2008-09-11 13:19:16 EDT (Thu, 11 Sep 2008)
@@ -0,0 +1,24 @@
+/**
+ * \file boost/mirror/meta_namespaces/boost_fusion.hpp
+ * Meta-namespace for the boost::fusion namespace
+ *
+ * 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_NAMESPACES_BOOST_FUSION_HPP
+#define BOOST_MIRROR_META_NAMESPACES_BOOST_FUSION_HPP
+
+#include <boost/mirror/meta_namespace.hpp>
+
+namespace boost {
+namespace mirror {
+
+BOOST_MIRROR_REG_NAMESPACE((boost)(fusion))
+
+} // namespace mirror
+} // namespace boost
+
+#endif //include guard
+

Added: sandbox/mirror/boost/mirror/meta_types/boost_fusion_vector.hpp
==============================================================================
--- (empty file)
+++ sandbox/mirror/boost/mirror/meta_types/boost_fusion_vector.hpp 2008-09-11 13:19:16 EDT (Thu, 11 Sep 2008)
@@ -0,0 +1,76 @@
+/**
+ * \file boost/mirror/meta_types/boost_fusion_vector.hpp
+ * Meta-type for boost::fusion::vector<>
+ *
+ * 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_TYPES_BOOST_FUSION_VECTOR_HPP
+#define BOOST_MIRROR_META_TYPES_BOOST_FUSION_VECTOR_HPP
+
+#include <boost/mirror/meta_type.hpp>
+#include <boost/mirror/detail/template_name.hpp>
+#include <boost/mirror/meta_namespaces/boost_fusion.hpp>
+//
+#include <boost/fusion/container/vector.hpp>
+#include <boost/preprocessor/repetition/enum_params.hpp>
+
+namespace boost {
+namespace mirror {
+
+#define BOOST_MIRROR_TMP_BOOST_FUSION_VECTOR_TEMPL_DECL() \
+template < \
+ BOOST_PP_ENUM_PARAMS(FUSION_MAX_VECTOR_SIZE, class T) \
+>
+
+#define BOOST_MIRROR_TMP_BOOST_FUSION_VECTOR_TEMPL_ARG_NAMES() \
+ BOOST_PP_ENUM_PARAMS(FUSION_MAX_VECTOR_SIZE, T)
+
+namespace detail {
+
+BOOST_MIRROR_TMP_BOOST_FUSION_VECTOR_TEMPL_DECL()
+struct meta_type_boost_fusion_vector
+{
+ BOOST_MIRROR_REG_TYPE_DECLARE_BASE_NAME("vector")
+};
+
+
+// designate fusion::void_ type as a typelist null type
+template <>
+struct is_typelist_null_type< ::boost::fusion::void_ >
+ : ::boost::true_type { };
+
+
+} // namespace detail
+
+BOOST_MIRROR_TMP_BOOST_FUSION_VECTOR_TEMPL_DECL()
+struct meta_type<
+ ::boost::fusion::vector< BOOST_MIRROR_TMP_BOOST_FUSION_VECTOR_TEMPL_ARG_NAMES() >
+>
+: detail::static_template_name<
+ BOOST_MIRRORED_NAMESPACE(::boost::fusion),
+ detail::meta_type_boost_fusion_vector<
+ BOOST_MIRROR_TMP_BOOST_FUSION_VECTOR_TEMPL_ARG_NAMES()
+ >,
+ mpl::vector<
+ BOOST_MIRROR_TMP_BOOST_FUSION_VECTOR_TEMPL_ARG_NAMES()
+ >
+>
+{
+ typedef ::boost::fusion::vector<
+ BOOST_MIRROR_TMP_BOOST_FUSION_VECTOR_TEMPL_ARG_NAMES()
+ > reflected_type;
+};
+
+// undefine the helper macros
+#undef BOOST_MIRROR_TMP_BOOST_FUSION_VECTOR_TEMPL_DECL
+#undef BOOST_MIRROR_TMP_BOOST_FUSION_VECTOR_TEMPL_ARG_NAMES
+
+
+} // namespace mirror
+} // namespace boost
+
+#endif //include guard
+

Modified: sandbox/mirror/libs/mirror/example/special/boost_tuple.cpp
==============================================================================
--- sandbox/mirror/libs/mirror/example/special/boost_tuple.cpp (original)
+++ sandbox/mirror/libs/mirror/example/special/boost_tuple.cpp 2008-09-11 13:19:16 EDT (Thu, 11 Sep 2008)
@@ -27,6 +27,7 @@
 #include <boost/mirror/meta_types/std_set.hpp>
 
 #include <boost/mirror/meta_classes/boost_tuple.hpp>
+#include <boost/mirror/meta_classes/boost_fusion_vector.hpp>
 
 template <class Class>
 class attrib_value_printer
@@ -117,7 +118,7 @@
         assert(meta_T1::all_attributes::get(t1, mpl::int_<1>()) == tuples::get<1>(t1));
         //
         //
- tuple<int, int, int, int, int, int, int, int, int, int> x(0,1,2,3,4,5,6,7,8,9);
+ fusion::vector<int, int, int, int, int, int, int, int, int, int> x(0,1,2,3,4,5,6,7,8,9);
         typedef BOOST_MIRRORED_CLASS(BOOST_TYPEOF(x)) meta_X;
         attrib_value_printer<meta_X::reflected_type> p(x);
         //

Modified: sandbox/mirror/libs/mirror/test/Jamfile.v2
==============================================================================
--- sandbox/mirror/libs/mirror/test/Jamfile.v2 (original)
+++ sandbox/mirror/libs/mirror/test/Jamfile.v2 2008-09-11 13:19:16 EDT (Thu, 11 Sep 2008)
@@ -35,5 +35,11 @@
          [ compile classes_ct_06.cpp ]
          [ compile classes_ct_07.cpp ]
          [ run classes_rt_01.cpp ]
+ [ run classes_rt_02.cpp ]
+ [ run classes_rt_03.cpp ]
+ [ run classes_rt_04.cpp ]
+ [ run classes_rt_05.cpp ]
+ [ run classes_rt_06.cpp ]
+ [ run classes_rt_07.cpp ]
     ;
 

Modified: sandbox/mirror/libs/mirror/test/classes.hpp
==============================================================================
--- sandbox/mirror/libs/mirror/test/classes.hpp (original)
+++ sandbox/mirror/libs/mirror/test/classes.hpp 2008-09-11 13:19:16 EDT (Thu, 11 Sep 2008)
@@ -28,29 +28,29 @@
         {
                 static int b1;
                 int b2;
- B(void):b2(4){ }
+ B(void):b2(5){ }
         };
- int B::b1 = 0;
+ int B::b1 = 4;
 
         struct C : virtual A
         {
                 mutable double c1;
                 double c2;
- C(void):c1(5.0),c2(6.0){ }
+ C(void):c1(6.0),c2(7.0){ }
         };
 
         struct D : virtual A
         {
                 const short d1;
                 volatile short d2;
- D(void):d1(7), d2(8){ }
+ D(void):d1(8), d2(9){ }
         };
 
         struct E : B, C, D
         {
                 static const float e;
         };
- const float E::e = 1.0f;
+ const float E::e = 10.0f;
 
         struct F : virtual E
         {

Modified: sandbox/mirror/libs/mirror/test/classes_rt_01.cpp
==============================================================================
--- sandbox/mirror/libs/mirror/test/classes_rt_01.cpp (original)
+++ sandbox/mirror/libs/mirror/test/classes_rt_01.cpp 2008-09-11 13:19:16 EDT (Thu, 11 Sep 2008)
@@ -1,5 +1,5 @@
 /**
- * \file test/classes_ct_04.cpp
+ * \file test/classes_rt_01.cpp
  *
  * This file is part of the Mirror library testsuite.
  *

Added: sandbox/mirror/libs/mirror/test/classes_rt_02.cpp
==============================================================================
--- (empty file)
+++ sandbox/mirror/libs/mirror/test/classes_rt_02.cpp 2008-09-11 13:19:16 EDT (Thu, 11 Sep 2008)
@@ -0,0 +1,77 @@
+/**
+ * \file test/classes_rt_02.cpp
+ *
+ * This file is part of the Mirror library testsuite.
+ *
+ * Testing class registration and reflection.
+ *
+ * Tests attribute name getter on reflected boost::tuple and
+ * the for_each run-time algorithm
+ *
+ * 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/lexical_cast.hpp>
+#include <boost/tuple/tuple.hpp>
+//
+#include <boost/mirror/meta_class.hpp>
+#include <boost/mirror/meta_classes/boost_tuple.hpp>
+#include <boost/mirror/algorithm/for_each.hpp>
+//
+#include "./test.hpp"
+
+class cmp_att_base_names
+{
+public:
+ template <class MetaAttribute>
+ void operator()(MetaAttribute ma)
+ {
+ using namespace ::boost;
+ const int i = MetaAttribute::position::value;
+ all_match &= (
+ ma.base_name() ==
+ cts::bstring(BOOST_CTS_LIT("_")) +
+ lexical_cast<cts::bstring>(i)
+ );
+ }
+
+ cmp_att_base_names(void)
+ : all_match(true)
+ { }
+
+ bool result(void) const {return all_match;}
+private:
+ bool all_match;
+};
+
+void test_main()
+{
+ using namespace ::boost;
+ using namespace ::boost::mirror;
+ //
+ typedef tuples::tuple< int, int, int, int, int, int, int, int, int > T;
+ typedef BOOST_MIRRORED_CLASS(T) meta_T;
+
+ try
+ {
+ // create the comparating functor
+ cmp_att_base_names test_op;
+ // and call it for every reflected attribute
+ // of the T tuple class
+ for_each<meta_T::all_attributes>(ref(test_op));
+ // check the result of the operation
+ BOOST_CHECK(( test_op.result() ));
+ }
+ catch(...){BOOST_CHECK(false);}
+}
+
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("Mirror: classes run-time test 02");
+ test->add(BOOST_TEST_CASE(&test_main));
+ return test;
+}
+
+

Added: sandbox/mirror/libs/mirror/test/classes_rt_03.cpp
==============================================================================
--- (empty file)
+++ sandbox/mirror/libs/mirror/test/classes_rt_03.cpp 2008-09-11 13:19:16 EDT (Thu, 11 Sep 2008)
@@ -0,0 +1,51 @@
+/**
+ * \file test/classes_rt_03.cpp
+ *
+ * This file is part of the Mirror library testsuite.
+ *
+ * Testing class registration and reflection.
+ *
+ * Test the attribute name getters with reflected ::std::pair
+ *
+ *
+ *
+ * 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/lexical_cast.hpp>
+#include <utility>
+//
+#include <boost/mirror/algorithm/at.hpp>
+#include <boost/mirror/meta_class.hpp>
+#include <boost/mirror/meta_classes/std_pair.hpp>
+//
+#include "./test.hpp"
+
+void test_main()
+{
+ using namespace ::boost;
+ using namespace ::boost::mirror;
+ //
+ typedef ::std::pair<int, double> T;
+ typedef BOOST_MIRRORED_CLASS(T) meta_T;
+
+ BOOST_CHECK((
+ at< meta_T::attributes, mpl::int_<0> >::type::base_name() ==
+ BOOST_CTS_LIT("first")
+ ));
+ BOOST_CHECK((
+ at< meta_T::attributes, mpl::int_<1> >::type::base_name() ==
+ BOOST_CTS_LIT("second")
+ ));
+}
+
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("Mirror: classes run-time test 02");
+ test->add(BOOST_TEST_CASE(&test_main));
+ return test;
+}
+
+

Added: sandbox/mirror/libs/mirror/test/classes_rt_04.cpp
==============================================================================
--- (empty file)
+++ sandbox/mirror/libs/mirror/test/classes_rt_04.cpp 2008-09-11 13:19:16 EDT (Thu, 11 Sep 2008)
@@ -0,0 +1,124 @@
+/**
+ * \file test/classes_rt_04.cpp
+ *
+ * This file is part of the Mirror library testsuite.
+ *
+ * Testing class registration and reflection.
+ *
+ * Tests the for_each algorithm and the attribute value
+ * getters/setters on reflected homogeneous boost::tuple
+ *
+ * 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/tuple/tuple.hpp>
+//
+#include <boost/mirror/meta_class.hpp>
+#include <boost/mirror/meta_classes/boost_tuple.hpp>
+#include <boost/mirror/algorithm/for_each.hpp>
+//
+#include "./test.hpp"
+
+template <typename T>
+class setter_tester
+{
+public:
+ setter_tester(T& _t):t(_t){ }
+ template <class MetaAttribute>
+ inline void operator()(MetaAttribute ma)
+ {
+ // use the meta-attribute's setter
+ // to set the position of the attribute as its
+ // value
+ ma.set(t, MetaAttribute::position::value);
+ }
+private:
+ T& t;
+};
+
+template <typename T>
+class getter_tester
+{
+public:
+ getter_tester(T& _t):t(_t){ }
+
+ template <class MetaAttribute>
+ inline void operator()(MetaAttribute ma)
+ {
+ // use the meta-attribute's setter
+ // to check if the position of the attribute
+ // is its value
+ if(ma.get(t) != MetaAttribute::position::value)
+ throw (int)MetaAttribute::position::value;
+
+ }
+private:
+ T& t;
+};
+
+template <typename T>
+class query_tester
+{
+public:
+ query_tester(T& _t, T& _s):t(_t),s(_s){ }
+
+ template <class MetaAttribute>
+ inline void operator()(MetaAttribute ma)
+ {
+ // use the meta-attribute's value query
+ // to copy the value of the t's attrib
+ // to s's attrib
+ ma.query(t, ::boost::get<MetaAttribute::position::value>(s));
+ }
+private:
+ T& t;
+ T& s;
+};
+
+void test_main()
+{
+ using namespace ::boost;
+ using namespace ::boost::mirror;
+ //
+ // define the tuple
+ typedef tuples::tuple<
+ int, int, int, int, int, int, int, int, int, int
+ > T;
+ // reflect it
+ typedef BOOST_MIRRORED_CLASS(T) meta_T;
+ // create an instance and initialize the attrib. values
+ T t(9, 8, 7, 6, 5, 4, 3, 2, 1, 0);
+ T s(t);
+ //
+ try
+ {
+ // execute the setter-tester functor on every attribute
+ // - sets new values to t's attributes
+ for_each<meta_T::attributes>(setter_tester<T>(t));
+ // execute the query-tester
+ // - copies t to s attribute-wise
+ for_each<meta_T::attributes>(query_tester<T>(t, s));
+ // execute a getter-tester on every attribute
+ // - gets and checks the s's attribute values
+ // throws an (int) position of the attribute
+ // where the check failed
+ for_each<meta_T::attributes>(getter_tester<T>(s));
+ }
+ catch(int& i)
+ {
+ // this is always false
+ BOOST_CHECK(i == -1);
+ }
+
+}
+
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("Mirror: classes run-time test 04");
+ test->add(BOOST_TEST_CASE(&test_main));
+ return test;
+}
+
+

Added: sandbox/mirror/libs/mirror/test/classes_rt_05.cpp
==============================================================================
--- (empty file)
+++ sandbox/mirror/libs/mirror/test/classes_rt_05.cpp 2008-09-11 13:19:16 EDT (Thu, 11 Sep 2008)
@@ -0,0 +1,90 @@
+/**
+ * \file test/classes_rt_05.cpp
+ *
+ * This file is part of the Mirror library testsuite.
+ *
+ * Testing class registration and reflection.
+ *
+ * Tests the for_each algorithm and the attribute value
+ * getters/setters on all attributes of a reflected test class
+ * and a heterogeneous boost::tuple
+ *
+ * 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/tuple/tuple.hpp>
+//
+#include <boost/mirror/meta_class.hpp>
+#include <boost/mirror/meta_classes/boost_tuple.hpp>
+#include <boost/mirror/algorithm/for_each.hpp>
+#include <boost/mirror/algorithm/size.hpp>
+//
+#include "./test.hpp"
+#include "./classes.hpp"
+
+template <typename T, typename S>
+class tester
+{
+public:
+ tester(T& _t, S& _s):t(_t),s(_s){ }
+
+ template <class MetaAttribute>
+ inline void operator()(MetaAttribute)
+ {
+ BOOST_CHECK(
+ MetaAttribute::get(t) ==
+ ::boost::get<
+ MetaAttribute::position::value
+ >(s)
+ );
+ }
+private:
+ T& t;
+ S& s;
+};
+
+
+void test_main()
+{
+ using namespace ::boost;
+ using namespace ::boost::mirror;
+ using namespace ::test;
+ //
+ // reflect the test::E class
+ typedef BOOST_MIRRORED_CLASS(E) meta_E;
+ // define a tuple that corresponds to the E class
+ typedef tuple<
+ long, long, long, int, int, double, double, short, short, float
+ > T;
+ // reflect the tuple
+ typedef BOOST_MIRRORED_CLASS(T) meta_T;
+ //
+ BOOST_MPL_ASSERT_RELATION(
+ size<meta_E::all_attributes>::value,
+ ==,
+ size<meta_T::attributes>::value
+ );
+ //
+ // create an instance of the E class
+ // the attributes are initialized by the constructors
+ E e;
+ // create an instace of the T tuple
+ // and initialize the attribute values to correspond
+ // to those of the E class instance
+ T t(1L, 2L, 3L, 4, 5, 6.0, 7.0, 8, 9, 10.0f);
+ //
+ // call the test functor for each attribute
+ for_each<meta_E::all_attributes>(tester<E, T>(e, t));
+}
+
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("Mirror: classes run-time test 05");
+ test->add(BOOST_TEST_CASE(&test_main));
+ return test;
+}
+
+

Added: sandbox/mirror/libs/mirror/test/classes_rt_06.cpp
==============================================================================
--- (empty file)
+++ sandbox/mirror/libs/mirror/test/classes_rt_06.cpp 2008-09-11 13:19:16 EDT (Thu, 11 Sep 2008)
@@ -0,0 +1,132 @@
+/**
+ * \file test/classes_rt_06.cpp
+ *
+ * This file is part of the Mirror library testsuite.
+ *
+ * Testing class registration and reflection.
+ *
+ * Tests the getter/setter functions of the meta-attribute sequences
+ * on custom 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)
+ */
+#include <boost/mpl/vector.hpp>
+#include <boost/mpl/for_each.hpp>
+#include <boost/mpl/at.hpp>
+//
+#include <boost/mirror/meta_class.hpp>
+#include <boost/mirror/algorithm/get_type_list.hpp>
+//
+#include "./test.hpp"
+#include "./classes.hpp"
+
+template <typename T>
+class increment_value
+{
+public:
+ increment_value(T& _t) : t(_t) { }
+
+ template <class Position>
+ inline void operator()(Position position)
+ {
+ using namespace ::boost;
+ using namespace ::boost::mirror;
+ // reflect the class
+ typedef BOOST_MIRRORED_CLASS(T) meta_T;
+ // get the meta-attributes
+ typedef typename meta_T::all_attributes meta_attribs;
+ // get the type of this attribute
+ typedef typename mpl::at<
+ typename get_type_list<meta_attribs>::type,
+ Position
+ >::type attrib_type;
+ // get the value of this attribute
+ attrib_type value(meta_attribs::get(
+ t, position
+ ));
+ // increment by one and set the value of this
+ // attribute
+ meta_attribs::set(
+ t, position,
+ attrib_type(value + 1)
+ );
+ }
+private:
+ T& t;
+};
+
+template <typename T, bool Equal>
+class check_equality
+{
+public:
+ check_equality(T& _t, T& _s) : t(_t), s(_s) { }
+
+ template <class Position>
+ inline void operator()(Position position)
+ {
+ using namespace ::boost;
+ using namespace ::boost::mirror;
+ // reflect the class
+ typedef BOOST_MIRRORED_CLASS(T) meta_T;
+ // get the meta-attributes
+ typedef typename meta_T::all_attributes meta_attribs;
+ // get the type of this attribute
+ typedef typename mpl::at<
+ typename get_type_list<meta_attribs>::type,
+ Position
+ >::type attrib_type;
+ //
+ // get the equality of values
+ BOOST_CHECK((
+ meta_attribs::get(
+ t, position
+ ) == meta_attribs::get(
+ s, position
+ )) == Equal
+ );
+ }
+private:
+ T& t;
+ T& s;
+};
+
+void test_main()
+{
+ using namespace ::boost;
+ using namespace ::boost::mirror;
+ using namespace ::test;
+ //
+ H g, h;
+ // create a list of several of H's attribute positions
+ typedef mpl::vector<
+ mpl::int_< 0>, // A::a1
+ mpl::int_< 1>, // A::a2
+ mpl::int_< 2>, // A::a3
+ mpl::int_< 4>, // B::b2
+ mpl::int_< 5>, // C::c1
+ mpl::int_< 6>, // C::c2
+ mpl::int_<12>, // G::g1
+ mpl::int_<13>, // G::g2
+ mpl::int_<14>, // G::g3
+ mpl::int_<15>, // H::h1
+ mpl::int_<16>, // H::h2
+ mpl::int_<17> // H::h3
+ > mutable_attr_positions;
+
+ mpl::for_each<mutable_attr_positions>(check_equality<H, true>(g, h));
+ mpl::for_each<mutable_attr_positions>(increment_value<H>(g));
+ mpl::for_each<mutable_attr_positions>(check_equality<H, false>(g, h));
+ mpl::for_each<mutable_attr_positions>(increment_value<H>(h));
+ mpl::for_each<mutable_attr_positions>(check_equality<H, true>(g, h));
+}
+
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("Mirror: classes run-time test 05");
+ test->add(BOOST_TEST_CASE(&test_main));
+ return test;
+}
+
+

Added: sandbox/mirror/libs/mirror/test/classes_rt_07.cpp
==============================================================================
--- (empty file)
+++ sandbox/mirror/libs/mirror/test/classes_rt_07.cpp 2008-09-11 13:19:16 EDT (Thu, 11 Sep 2008)
@@ -0,0 +1,123 @@
+/**
+ * \file test/classes_rt_07.cpp
+ *
+ * This file is part of the Mirror library testsuite.
+ *
+ * Testing class registration and reflection.
+ *
+ * Tests the for_each algorithm and the attribute value
+ * getters/setters on reflected homogeneous boost::fusion::vector
+ *
+ * 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/boost_fusion_vector.hpp>
+#include <boost/mirror/algorithm/for_each.hpp>
+//
+#include "./test.hpp"
+
+template <typename T>
+class setter_tester
+{
+public:
+ setter_tester(T& _t):t(_t){ }
+ template <class MetaAttribute>
+ inline void operator()(MetaAttribute ma)
+ {
+ // use the meta-attribute's setter
+ // to set the position of the attribute as its
+ // value
+ ma.set(t, MetaAttribute::position::value);
+ }
+private:
+ T& t;
+};
+
+template <typename T>
+class getter_tester
+{
+public:
+ getter_tester(T& _t):t(_t){ }
+
+ template <class MetaAttribute>
+ inline void operator()(MetaAttribute ma)
+ {
+ // use the meta-attribute's setter
+ // to check if the position of the attribute
+ // is its value
+ if(ma.get(t) != MetaAttribute::position::value)
+ throw (int)MetaAttribute::position::value;
+
+ }
+private:
+ T& t;
+};
+
+template <typename T>
+class query_tester
+{
+public:
+ query_tester(T& _t, T& _s):t(_t),s(_s){ }
+
+ template <class MetaAttribute>
+ inline void operator()(MetaAttribute ma)
+ {
+ // use the meta-attribute's value query
+ // to copy the value of the t's attrib
+ // to s's attrib
+ ma.query(t, ::boost::fusion::at_c<MetaAttribute::position::value>(s));
+ }
+private:
+ T& t;
+ T& s;
+};
+
+void test_main()
+{
+ using namespace ::boost;
+ using namespace ::boost::mirror;
+ //
+ // define the fusion::vector type
+ typedef fusion::vector<
+ int, int, int, int, int, int, int, int, int, int
+ > T;
+ // reflect it
+ typedef BOOST_MIRRORED_CLASS(T) meta_T;
+ // create an instance and initialize the attrib. values
+ T t(9, 8, 7, 6, 5, 4, 3, 2, 1, 0);
+ T s(t);
+ //
+ try
+ {
+ // execute the setter-tester functor on every attribute
+ // - sets new values to t's attributes
+ for_each<meta_T::attributes>(setter_tester<T>(t));
+ // execute the query-tester
+ // - copies t to s attribute-wise
+ for_each<meta_T::attributes>(query_tester<T>(t, s));
+ // execute a getter-tester on every attribute
+ // - gets and checks the s's attribute values
+ // throws an (int) position of the attribute
+ // where the check failed
+ for_each<meta_T::attributes>(getter_tester<T>(s));
+ }
+ catch(int& i)
+ {
+ // this is always false
+ BOOST_CHECK(i == -1);
+ }
+
+}
+
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("Mirror: classes run-time test 07");
+ 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