$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r64455 - in sandbox/intro/boost/fusion: . adapted adapted/struct
From: strasser_at_[hidden]
Date: 2010-07-29 15:15:35
Author: stefans
Date: 2010-07-29 15:15:34 EDT (Thu, 29 Jul 2010)
New Revision: 64455
URL: http://svn.boost.org/trac/boost/changeset/64455
Log:
initial
Added:
   sandbox/intro/boost/fusion/
   sandbox/intro/boost/fusion/adapted/
   sandbox/intro/boost/fusion/adapted/struct/
   sandbox/intro/boost/fusion/adapted/struct/access.hpp   (contents, props changed)
   sandbox/intro/boost/fusion/adapted/struct/adapt_derived.hpp   (contents, props changed)
   sandbox/intro/boost/fusion/adapted/struct/adapt_struct.hpp   (contents, props changed)
Added: sandbox/intro/boost/fusion/adapted/struct/access.hpp
==============================================================================
--- (empty file)
+++ sandbox/intro/boost/fusion/adapted/struct/access.hpp	2010-07-29 15:15:34 EDT (Thu, 29 Jul 2010)
@@ -0,0 +1,34 @@
+/*=============================================================================
+    Copyright (c) 2010 Stefan Strasser
+
+    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)
+==============================================================================*/
+
+#if !defined(BOOST_FUSION_ADAPTED_STRUCT_ACCESS)
+#define BOOST_FUSION_ADAPTED_STRUCT_ACCESS
+
+#include <boost/fusion/adapted/struct/extension.hpp>
+
+namespace boost{
+namespace fusion{
+
+class access{
+private:
+    template<typename Struct,int N>
+    friend struct fusion::extension::struct_member;
+    template<typename Struct,int N>
+    struct result;
+    template<typename Struct,int N>
+    static typename result<Struct,N>::type &call(Struct &);
+    template<typename To,typename From>
+    static To &upcast(From &from){ //for private inheritance
+        return from;
+    }
+};
+
+}
+}
+
+
+#endif
Added: sandbox/intro/boost/fusion/adapted/struct/adapt_derived.hpp
==============================================================================
--- (empty file)
+++ sandbox/intro/boost/fusion/adapted/struct/adapt_derived.hpp	2010-07-29 15:15:34 EDT (Thu, 29 Jul 2010)
@@ -0,0 +1,91 @@
+/*=============================================================================
+    Copyright (c) 2010 Stefan Strasser
+
+    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_ADAPTED_STRUCT_ADAPT_DERIVED_HPP
+#define BOOST_ADAPTED_STRUCT_ADAPT_DERIVED_HPP
+
+#include <boost/fusion/adapted/struct/adapt_struct.hpp>
+#include <boost/preprocessor/seq/for_each.hpp>
+#include <boost/preprocessor/seq/enum.hpp>
+#include <boost/mpl/eval_if.hpp>
+#include <boost/mpl/pair.hpp>
+#include <boost/mpl/int.hpp>
+
+namespace boost{
+namespace fusion{
+namespace extension{
+namespace detail{
+
+//this is done while compiling, instead of preprocessing, because struct_size<Base>::value
+//is not known to the preprocessor
+template<int I,typename B0=void,typename B1=void,typename B2=void,typename B3=void,typename B4=void>
+struct struct_base_member{
+    typedef typename mpl::eval_if_c<
+        I < struct_size<B0>::value,
+        mpl::pair<B0,mpl::int_<I> >,
+        struct_base_member<
+            I - struct_size<B0>::value,
+            B1,B2,B3,B4
+        >
+    >::type type;
+};
+
+}
+}
+}
+}
+
+
+#define BOOST_FUSION_ADAPT_DERIVED(name, dseq, bseq)                            \
+    BOOST_FUSION_ADAPT_DERIVED_I(                                               \
+        name, dseq, BOOST_PP_CAT(BOOST_FUSION_ADAPT_STRUCT_X bseq, 0))          \
+    /***/
+
+
+#define BOOST_FUSION_ADAPT_DERIVED_I(name, dseq, seq)                           \
+    namespace boost { namespace fusion {                                        \
+        BOOST_FUSION_ADAPT_STRUCT_H(                                            \
+            name,                                                               \
+            BOOST_FUSION_ADAPT_BASE_SIZE_PLUS(dseq) BOOST_PP_SEQ_SIZE(seq))     \
+        namespace extension{                                                    \
+            template <int I>                                                    \
+            struct struct_member<name, I>                                       \
+            {                                                                   \
+                typedef typename detail::struct_base_member<                    \
+                    I,BOOST_PP_SEQ_ENUM(dseq)                                   \
+                >::type pair;                                                   \
+                typedef typename pair::first Base;                              \
+                typedef struct_member<Base,pair::second::value> base_member;    \
+                typedef typename base_member::type type;                        \
+                static type& call(name& struct_)                                \
+                {                                                               \
+                    Base &b=fusion::access::upcast<Base>(struct_);              \
+                    return base_member::call(b);                                \
+                };                                                              \
+            };                                                                  \
+        }                                                                       \
+        BOOST_PP_SEQ_FOR_EACH_I(                                                \
+            BOOST_FUSION_ADAPT_DERIVED_M,                                       \
+            (name,BOOST_FUSION_ADAPT_BASE_SIZE_PLUS(dseq) 0), seq)              \
+    }}                                                                          \
+    /***/
+
+#define BOOST_FUSION_ADAPT_BASE_SIZE_PLUS(seq)                                  \
+    BOOST_PP_SEQ_FOR_EACH(BOOST_FUSION_ADAPT_BASE_SIZE_E,0,seq)                 \
+    /***/
+
+#define BOOST_FUSION_ADAPT_BASE_SIZE_E(r,data,elem)                             \
+    extension::struct_size<elem>::value +                                       \
+    /***/
+
+#define BOOST_FUSION_ADAPT_DERIVED_M(r, tuple, i, xy)                           \
+    BOOST_FUSION_ADAPT_STRUCT_C(r,BOOST_PP_TUPLE_ELEM(2,0,tuple),                      \
+        i + BOOST_PP_TUPLE_ELEM(2,1,tuple),xy)                                  \
+    /***/
+
+
+#endif
+
Added: sandbox/intro/boost/fusion/adapted/struct/adapt_struct.hpp
==============================================================================
--- (empty file)
+++ sandbox/intro/boost/fusion/adapted/struct/adapt_struct.hpp	2010-07-29 15:15:34 EDT (Thu, 29 Jul 2010)
@@ -0,0 +1,93 @@
+/*=============================================================================
+    Copyright (c) 2001-2007 Joel de Guzman
+
+    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)
+==============================================================================*/
+#if !defined(BOOST_FUSION_ADAPT_STRUCT_APRIL_2_2007_1158AM)
+#define BOOST_FUSION_ADAPT_STRUCT_APRIL_2_2007_1158AM
+
+#include <boost/fusion/support/tag_of_fwd.hpp>
+#include <boost/fusion/adapted/struct/extension.hpp>
+#include <boost/fusion/adapted/struct/access.hpp>
+#include <boost/fusion/adapted/struct/struct_iterator.hpp>
+#include <boost/fusion/adapted/struct/detail/is_view_impl.hpp>
+#include <boost/fusion/adapted/struct/detail/is_sequence_impl.hpp>
+#include <boost/fusion/adapted/struct/detail/category_of_impl.hpp>
+#include <boost/fusion/adapted/struct/detail/begin_impl.hpp>
+#include <boost/fusion/adapted/struct/detail/end_impl.hpp>
+#include <boost/fusion/adapted/struct/detail/size_impl.hpp>
+#include <boost/fusion/adapted/struct/detail/at_impl.hpp>
+#include <boost/fusion/adapted/struct/detail/value_at_impl.hpp>
+
+#include <boost/preprocessor/cat.hpp>
+#include <boost/preprocessor/punctuation/comma_if.hpp>
+#include <boost/preprocessor/seq/for_each_i.hpp>
+#include <boost/preprocessor/tuple/elem.hpp>
+#include <boost/preprocessor/repetition/enum_params_with_a_default.hpp>
+#include <boost/preprocessor/repetition/enum_params.hpp>
+#include <boost/preprocessor/cat.hpp>
+#include <boost/mpl/int.hpp>
+#include <boost/config/no_tr1/utility.hpp>
+
+#define BOOST_FUSION_ADAPT_STRUCT(name, bseq)                                   \
+    BOOST_FUSION_ADAPT_STRUCT_I(                                                \
+        name, BOOST_PP_CAT(BOOST_FUSION_ADAPT_STRUCT_X bseq, 0))                \
+    /***/
+
+#define BOOST_FUSION_ADAPT_STRUCT_X(x, y) ((x, y)) BOOST_FUSION_ADAPT_STRUCT_Y
+#define BOOST_FUSION_ADAPT_STRUCT_Y(x, y) ((x, y)) BOOST_FUSION_ADAPT_STRUCT_X
+#define BOOST_FUSION_ADAPT_STRUCT_X0
+#define BOOST_FUSION_ADAPT_STRUCT_Y0
+
+// BOOST_FUSION_ADAPT_STRUCT_I generates the overarching structure and uses
+// SEQ_FOR_EACH_I to generate the "linear" substructures.
+// Thanks to Paul Mensonides for the PP macro help
+
+#define BOOST_FUSION_ADAPT_STRUCT_I(name, seq)                                  \
+    namespace boost { namespace fusion {                                        \
+        BOOST_FUSION_ADAPT_STRUCT_H(name, BOOST_PP_SEQ_SIZE(seq))               \
+        BOOST_PP_SEQ_FOR_EACH_I(BOOST_FUSION_ADAPT_STRUCT_C, name, seq)         \
+    }}                                                                          \
+    /***/
+
+#define BOOST_FUSION_ADAPT_STRUCT_H(name, size)                                 \
+    namespace traits                                                            \
+    {                                                                           \
+        template <>                                                             \
+        struct tag_of<name>                                                     \
+        {                                                                       \
+            typedef struct_tag type;                                            \
+        };                                                                      \
+    }                                                                           \
+    namespace extension                                                         \
+    {                                                                           \
+        template <>                                                             \
+        struct struct_size<name> : mpl::int_<size> {};                          \
+    }                                                                           \
+    /***/
+
+
+#define BOOST_FUSION_ADAPT_STRUCT_C(r, name, i, xy)                             \
+    template <>                                                                 \
+    struct access::result<name, i>{                                             \
+        typedef BOOST_PP_TUPLE_ELEM(2, 0, xy) type;                             \
+    };                                                                          \
+    template <>                                                                 \
+    access::result<name, i>::type &access::call<name,i>(name& struct_){         \
+        return struct_.BOOST_PP_TUPLE_ELEM(2, 1, xy);                           \
+    }                                                                           \
+    namespace extension{                                                        \
+        template <>                                                             \
+        struct struct_member<name, i>                                           \
+        {                                                                       \
+            typedef fusion::access::result<name,i>::type type;                  \
+            static type& call(name& struct_)                                    \
+            {                                                                   \
+                return fusion::access::call<name,i>(struct_);                   \
+            };                                                                  \
+        };                                                                      \
+    }                                                                           \
+    /***/
+
+#endif