|
Boost-Commit : |
From: chochlik_at_[hidden]
Date: 2008-06-20 08:31:53
Author: matus.chochlik
Date: 2008-06-20 08:31:52 EDT (Fri, 20 Jun 2008)
New Revision: 46552
URL: http://svn.boost.org/trac/boost/changeset/46552
Log:
Added example/traversal/sample_meta_path.cpp showing how meta-path expressions can be used in visitors
Added:
sandbox/mirror/libs/mirror/example/traversal/sample_meta_path.cpp (contents, props changed)
Text files modified:
sandbox/mirror/boost/mirror/visitors/sample.hpp | 4 ++--
sandbox/mirror/libs/mirror/example/Jamfile.v2 | 3 ++-
sandbox/mirror/libs/mirror/example/traversal/sample_visitor.cpp | 5 -----
3 files changed, 4 insertions(+), 8 deletions(-)
Modified: sandbox/mirror/boost/mirror/visitors/sample.hpp
==============================================================================
--- sandbox/mirror/boost/mirror/visitors/sample.hpp (original)
+++ sandbox/mirror/boost/mirror/visitors/sample.hpp 2008-06-20 08:31:52 EDT (Fri, 20 Jun 2008)
@@ -73,7 +73,7 @@
{
using namespace ::std;
using namespace ::boost;
- if(mirror::size<MetaClass::base_classes>::value > 0)
+ if(mirror::size<BaseClasses>::value > 0)
{
print_indentation();
++indent;
@@ -88,7 +88,7 @@
{
using namespace ::std;
using namespace ::boost;
- if(mirror::size<MetaClass::base_classes>::value > 0)
+ if(mirror::size<BaseClasses>::value > 0)
{
--indent;
print_indentation();
Modified: sandbox/mirror/libs/mirror/example/Jamfile.v2
==============================================================================
--- sandbox/mirror/libs/mirror/example/Jamfile.v2 (original)
+++ sandbox/mirror/libs/mirror/example/Jamfile.v2 2008-06-20 08:31:52 EDT (Fri, 20 Jun 2008)
@@ -32,7 +32,8 @@
#
# traversal by visitors
#
-exe tvrsl_sample_visitor : traversal/sample_visitor.cpp ;
+exe tvrsl_sample_visitor : traversal/sample_visitor.cpp ;
+exe tvrsl_meta_path_visitor : traversal/sample_meta_path.cpp ;
#
# cooperation with Boost.Serialization
#
Added: sandbox/mirror/libs/mirror/example/traversal/sample_meta_path.cpp
==============================================================================
--- (empty file)
+++ sandbox/mirror/libs/mirror/example/traversal/sample_meta_path.cpp 2008-06-20 08:31:52 EDT (Fri, 20 Jun 2008)
@@ -0,0 +1,186 @@
+/**
+ * \file examples/traversal/sample_meta_path.cpp
+ *
+ * Example of class structure deep and flat traversal
+ *
+ * NOTE: if You are not familiar with registration
+ * and reflection, You should probably
+ * see examples in examples/registering/ 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 <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/meta_types/std_pair.hpp>
+#include <boost/mirror/meta_types/boost_tuple.hpp>
+#include <boost/mirror/meta_classes/boost_tuple.hpp>
+
+#include <boost/mirror/meta_path/ancestors.hpp>
+#include <boost/mirror/meta_path/size.hpp>
+
+#include <boost/mirror/visitors/meta_path_sample.hpp>
+#include <boost/mirror/traversal.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;
+ };
+
+ struct F : virtual E
+ {
+ bool b;
+ };
+
+ struct G : virtual E
+ {
+ char c;
+ };
+
+ struct H : F, G
+ {
+ wchar_t w;
+ };
+
+
+} // namespace Test
+
+namespace boost {
+namespace mirror {
+
+/** Register the Test namespace
+ */
+BOOST_MIRROR_REG_NAMESPACE_TOP_LEVEL(Test)
+
+/** Register the types and classes
+ */
+BOOST_MIRROR_REG_TYPE(_Test, ::Test, A)
+BOOST_MIRROR_REG_TYPE(_Test, ::Test, B)
+BOOST_MIRROR_REG_TYPE(_Test, ::Test, C)
+BOOST_MIRROR_REG_TYPE(_Test, ::Test, D)
+BOOST_MIRROR_REG_TYPE(_Test, ::Test, E)
+BOOST_MIRROR_REG_TYPE(_Test, ::Test, F)
+BOOST_MIRROR_REG_TYPE(_Test, ::Test, G)
+BOOST_MIRROR_REG_TYPE(_Test, ::Test, H)
+
+
+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
+
+BOOST_MIRROR_REG_BASE_CLASSES_BEGIN(::Test::F)
+BOOST_MIRROR_REG_BASE_CLASS_VIRTUAL(0, public, ::Test::E)
+BOOST_MIRROR_REG_BASE_CLASSES_END
+
+BOOST_MIRROR_REG_BASE_CLASSES_BEGIN(::Test::G)
+BOOST_MIRROR_REG_BASE_CLASS_VIRTUAL(0, public, ::Test::E)
+BOOST_MIRROR_REG_BASE_CLASSES_END
+
+BOOST_MIRROR_REG_BASE_CLASSES_BEGIN(::Test::H)
+BOOST_MIRROR_REG_BASE_CLASS_SIMPLE(0, ::Test::F)
+BOOST_MIRROR_REG_BASE_CLASS_SIMPLE(1, ::Test::G)
+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
+
+BOOST_MIRROR_REG_CLASS_ATTRIBS_BEGIN(::Test::F)
+ BOOST_MIRROR_REG_CLASS_ATTRIB(0, bool, b)
+BOOST_MIRROR_REG_CLASS_ATTRIBS_END
+
+BOOST_MIRROR_REG_CLASS_ATTRIBS_BEGIN(::Test::G)
+ BOOST_MIRROR_REG_CLASS_ATTRIB(0, char, c)
+BOOST_MIRROR_REG_CLASS_ATTRIBS_END
+
+BOOST_MIRROR_REG_CLASS_ATTRIBS_BEGIN(::Test::H)
+ BOOST_MIRROR_REG_CLASS_ATTRIB(0, wchar_t, w)
+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(H) meta_H;
+ //
+ bcout << "--------------------------------------------" << endl;
+ deep_traversal_of<meta_H>::accept(meta_path_sample_visitor());
+ bcout << "--------------------------------------------" << endl;
+ flat_traversal_of<meta_H>::accept(meta_path_sample_visitor());
+ bcout << "--------------------------------------------" << endl;
+ //
+ //
+ return 0;
+}
Modified: sandbox/mirror/libs/mirror/example/traversal/sample_visitor.cpp
==============================================================================
--- sandbox/mirror/libs/mirror/example/traversal/sample_visitor.cpp (original)
+++ sandbox/mirror/libs/mirror/example/traversal/sample_visitor.cpp 2008-06-20 08:31:52 EDT (Fri, 20 Jun 2008)
@@ -26,7 +26,6 @@
#include <boost/mirror/meta_path/size.hpp>
#include <boost/mirror/visitors/sample.hpp>
-#include <boost/mirror/visitors/meta_path_sample.hpp>
#include <boost/mirror/traversal.hpp>
/** First declare some namespaces and classes
@@ -190,10 +189,6 @@
bcout << "--------------------------------------------" << endl;
flat_traversal_of<meta_H>::accept(sample_visitor<true>(), &h);
bcout << "--------------------------------------------" << endl;
- deep_traversal_of<meta_H>::accept(meta_path_sample_visitor());
- bcout << "--------------------------------------------" << endl;
- flat_traversal_of<meta_H>::accept(meta_path_sample_visitor());
- bcout << "--------------------------------------------" << endl;
//
//
typedef pair<int volatile, long const> T1;
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