Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r63317 - sandbox/variadic_templates/boost/composite_storage/layout
From: cppljevans_at_[hidden]
Date: 2010-06-25 14:20:07


Author: cppljevans
Date: 2010-06-25 14:20:06 EDT (Fri, 25 Jun 2010)
New Revision: 63317
URL: http://svn.boost.org/trac/boost/changeset/63317

Log:
Directory and files for calculating layout of composite,
all except the all_of_pacckec composite.

Added:
   sandbox/variadic_templates/boost/composite_storage/layout/
   sandbox/variadic_templates/boost/composite_storage/layout/layout_of.hpp (contents, props changed)
   sandbox/variadic_templates/boost/composite_storage/layout/operators_all_of_aligned.hpp (contents, props changed)
   sandbox/variadic_templates/boost/composite_storage/layout/operators_fwd.hpp (contents, props changed)
   sandbox/variadic_templates/boost/composite_storage/layout/operators_one_of_maybe.hpp (contents, props changed)

Added: sandbox/variadic_templates/boost/composite_storage/layout/layout_of.hpp
==============================================================================
--- (empty file)
+++ sandbox/variadic_templates/boost/composite_storage/layout/layout_of.hpp 2010-06-25 14:20:06 EDT (Fri, 25 Jun 2010)
@@ -0,0 +1,118 @@
+//layout data for individual components of a composite.
+#ifndef BOOST_COMPOSITE_STORAGE_LAYOUT_OF_HPP_INCLUDED
+#define BOOST_COMPOSITE_STORAGE_LAYOUT_OF_HPP_INCLUDED
+#include <boost/composite_storage/buffers/char_buf.hpp>
+
+namespace boost
+{
+namespace composite_storage
+{
+namespace layout
+{
+ template
+ < typename T
+ >
+ struct
+alignment_of
+ /**@brief
+ * Allow specialization of alignment calculation.
+ * This is useful when the alignment for some
+ * composite is partially calculated
+ * (see ../detail/layout_operators*.hpp)
+ * but the complete object type has not been
+ * defined yet. For example, the one_of_maybe
+ * composite needs to calculate the alignment
+ * of all it's components, then calculate the
+ * alignment of those components following by
+ * the alignment of the discriminant.
+ */
+: public ::boost::alignment_of<T>
+{
+};
+ template
+ < std::size_t Size
+ , std::size_t Align
+ , buffers::is_aligned IsAligned
+ >
+struct alignment_of
+ < buffers::char_buf<Size,Align,IsAligned>
+ >
+{
+ static
+ std::size_t const
+ value
+ =Align
+ ;
+};
+
+ template
+ < typename T
+ >
+ struct
+size_of
+{
+ static
+ std::size_t const
+ value
+ =sizeof(T)
+ ;
+};
+
+struct components_aligned_yes
+{
+ template
+ < std::size_t Size=0
+ , std::size_t Align=1
+ >
+ struct layout_data
+ {
+ static
+ std::size_t const
+ size
+ =Size
+ ;
+ static
+ std::size_t const
+ align
+ =Align
+ ;
+ };
+ template
+ < typename Component
+ >
+ struct layout_of
+ : layout_data
+ < size_of<Component>::value
+ , alignment_of<Component>::value
+ >
+ {
+ };
+};
+struct components_aligned_not
+{
+ template
+ < std::size_t Size=0
+ >
+ struct layout_data
+ {
+ static
+ std::size_t const
+ size
+ =Size
+ ;
+ };
+ template
+ < typename Component
+ >
+ struct layout_of
+ : layout_data
+ < size_of<Component>::value
+ >
+ {
+ };
+};
+}//exit layout namespace
+}//exit composite_storage namespace
+}//exit boost namespace
+#endif
+

Added: sandbox/variadic_templates/boost/composite_storage/layout/operators_all_of_aligned.hpp
==============================================================================
--- (empty file)
+++ sandbox/variadic_templates/boost/composite_storage/layout/operators_all_of_aligned.hpp 2010-06-25 14:20:06 EDT (Fri, 25 Jun 2010)
@@ -0,0 +1,251 @@
+//operators for calculating the layout of all_of_aligned composite.
+#ifndef BOOST_COMPOSITE_STORAGE_LAYOUT_OPERATORS_ALL_OF_ALIGNED_HPP_INCLUDED
+#define BOOST_COMPOSITE_STORAGE_LAYOUT_OPERATORS_ALL_OF_ALIGNED_HPP_INCLUDED
+#include <boost/composite_storage/layout/operators_fwd.hpp>
+#include <boost/composite_storage/tags.hpp>
+#include <boost/composite_storage/layout/layout_of.hpp>
+#include <boost/composite_storage/buffers/rval_ref_buf.hpp>
+#include <boost/composite_storage/alignment/compose.hpp>
+#include <boost/composite_storage/alignment/aligned_offset.hpp>
+#include <boost/composite_storage/special_components.hpp>
+
+namespace boost
+{
+namespace composite_storage
+{
+namespace layout
+{
+
+ template
+ <// class CompositeTag
+ >
+struct operators< tags::all_of_aligned>
+: components_aligned_yes
+{
+
+ template
+ < typename HeadComposed
+ , typename TailLayout
+ >
+ struct compose_layout
+ {
+ static
+ std::size_t const
+ offset
+ =alignment::aligned_offset
+ < HeadComposed::size
+ , TailLayout::align
+ >::value
+ ;
+ static
+ std::size_t const
+ size
+ =offset
+ +TailLayout::size
+ ;
+ static
+ std::size_t const
+ align
+ =alignment::compose
+ < HeadComposed::align
+ , TailLayout::align
+ >::value
+ ;
+ };
+
+ template
+ < typename IndexUndefined
+ >
+ struct layout0
+ {
+ typedef
+ IndexUndefined
+ index_part
+ ;
+ typedef
+ layout_data<>
+ comp_part
+ ;
+ static
+ void
+ inject(void)
+ {
+ }
+ static
+ void
+ inject_default(void)
+ {
+ }
+ static
+ void
+ project(void)
+ {
+ }
+ static
+ void
+ destroy(char*buffer_composite)
+ {
+ }
+ };
+
+ template
+ < typename HeadLayout
+ , typename TailComponent
+ >
+ struct push_back
+ {
+ struct
+ type
+ : private HeadLayout
+ {
+ typedef
+ HeadLayout
+ head_layout
+ ;
+ typedef
+ typename mpl::next<typename HeadLayout::index_part>::type
+ index_part
+ ;
+ typedef
+ compose_layout
+ < typename HeadLayout::comp_part
+ , layout_of<TailComponent>
+ >
+ comp_part
+ ;
+ using HeadLayout::
+ inject
+ ;
+ static
+ void
+ inject
+ ( index_part index_arg
+ , char*buffer_composite
+ , TailComponent&& tail_component
+ )
+ {
+ void*tail_buffer=buffer_composite+comp_part::offset;
+ new(tail_buffer) TailComponent(std::forward<TailComponent>(tail_component));
+ }
+ static
+ void
+ inject
+ ( index_part index_arg
+ , char*buffer_composite
+ , TailComponent const& tail_component
+ )
+ {
+ void*tail_buffer=buffer_composite+comp_part::offset;
+ new(tail_buffer) TailComponent(tail_component);
+ }
+ using HeadLayout::
+ inject_default
+ ;
+ static
+ void
+ inject_default
+ ( index_part index_arg
+ , char*buffer_composite
+ )
+
+ {
+ TailComponent tail_component;
+ inject(index_arg,buffer_composite,std::move(tail_component));
+ }
+ using HeadLayout::
+ project
+ ;
+ static
+ TailComponent const&
+ project(index_part index_arg, char const*buffer_composite)
+ {
+ void const*tail_buffer=buffer_composite+comp_part::offset;
+ TailComponent const*tail_ptr=static_cast<TailComponent const*>(tail_buffer);
+ return *tail_ptr;
+ }
+ static
+ TailComponent&
+ project(index_part index_arg, char*buffer_composite)
+ {
+ void*tail_buffer=buffer_composite+comp_part::offset;
+ TailComponent*tail_ptr=static_cast<TailComponent*>(tail_buffer);
+ return *tail_ptr;
+ }
+ static
+ TailComponent&&
+ project(index_part index_arg, buffers::rval_ref_buf buffer_composite)
+ {
+ void*tail_buffer=buffer_composite.my_buf+comp_part::offset;
+ TailComponent*tail_ptr=static_cast<TailComponent*>(tail_buffer);
+ return std::move(*tail_ptr);
+ }
+ static
+ void
+ destroy( char*buffer_composite)
+ {
+ TailComponent&tail_ref=project( index_part(), buffer_composite);
+ tail_ref.~TailComponent();
+ HeadLayout::destroy(buffer_composite);
+ }
+
+ };//end type struct
+ };//end push_back struct
+
+ template
+ < typename HeadLayout
+ >
+ struct push_back< HeadLayout, void>
+ {
+ typedef
+ void
+ TailComponent
+ ;
+ struct
+ type
+ : private HeadLayout
+ {
+ typedef
+ HeadLayout
+ head_layout
+ ;
+ typedef
+ typename mpl::next<typename HeadLayout::index_part>::type
+ index_part
+ ;
+ using HeadLayout::
+ comp_part
+ ;
+ using HeadLayout::
+ inject
+ ;
+ using HeadLayout::
+ inject_default
+ ;
+ static
+ void
+ inject_default
+ ( index_part index_arg
+ , char*buffer_composite
+ )
+
+ {
+ }
+ using HeadLayout::
+ project
+ ;
+ static
+ void
+ destroy( char*buffer_composite)
+ {
+ HeadLayout::destroy(buffer_composite);
+ }
+
+ };//end type struct
+ };//end push_back<.,void> struct
+};//end operators struct
+
+}//exit layout namespace
+}//exit composite_storage namespace
+}//exit boost namespace
+#endif
+

Added: sandbox/variadic_templates/boost/composite_storage/layout/operators_fwd.hpp
==============================================================================
--- (empty file)
+++ sandbox/variadic_templates/boost/composite_storage/layout/operators_fwd.hpp 2010-06-25 14:20:06 EDT (Fri, 25 Jun 2010)
@@ -0,0 +1,62 @@
+//forward declaration of operators for calculating the layout of a composite.
+#ifndef BOOST_COMPOSITE_STORAGE_LAYOUT_OPERATORS_FWD_HPP_INCLUDED
+#define BOOST_COMPOSITE_STORAGE_LAYOUT_OPERATORS_FWD_HPP_INCLUDED
+#include <boost/composite_storage/tags.hpp>
+
+namespace boost
+{
+namespace composite_storage
+{
+namespace layout
+{
+ template
+ < class CompositeTag
+ >
+ struct
+operators
+/**@brief
+ * Member templates:
+ * push_back
+ * layout0
+ * are used to calculate various "layout" traits of a composite.
+ * These traits include at least:
+ * the size
+ * and possibly:
+ * the offsets and alignments
+ * of the composite's components.
+ * Also a layout contains member functions:
+ * inject:
+ * for creating or modifying a component.
+ * project:
+ * for retrieving a component.
+ */
+{
+ template
+ < typename IndexUndefined //index for accessing this layout.
+ >
+ struct
+ layout0
+ /**@brief
+ * Nullary operator:
+ * The layout of a composite with 0 components.
+ */
+ ;
+ template
+ < typename HeadLayout //layout of some Composite
+ , typename TailComponent//Type to be appended to some Composite
+ >
+ struct
+ push_back
+ /**@brief
+ * Binary operator:
+ * Calculates the layout of composite with component, TailComponent,
+ * appended to a Composite with layout, HeadLayout, and return
+ * layout result in push_back<HeadLayout,TailComponent>::type.
+ */
+ ;
+};
+
+}//exit detail namespace
+}//exit composite_storage namespace
+}//exit boost namespace
+#endif

Added: sandbox/variadic_templates/boost/composite_storage/layout/operators_one_of_maybe.hpp
==============================================================================
--- (empty file)
+++ sandbox/variadic_templates/boost/composite_storage/layout/operators_one_of_maybe.hpp 2010-06-25 14:20:06 EDT (Fri, 25 Jun 2010)
@@ -0,0 +1,306 @@
+//operators for calculating the layout of one_of_maybe composite.
+#ifndef BOOST_COMPOSITE_STORAGE_DETAIL_LAYOUT_OPERATORS_ONE_OF_MAYBE_HPP_INCLUDED
+#define BOOST_COMPOSITE_STORAGE_DETAIL_LAYOUT_OPERATORS_ONE_OF_MAYBE_HPP_INCLUDED
+#include <boost/composite_storage/layout/operators_fwd.hpp>
+#include <boost/composite_storage/tags.hpp>
+#include <boost/composite_storage/layout/layout_of.hpp>
+#include <boost/composite_storage/buffers/rval_ref_buf.hpp>
+#include <boost/composite_storage/alignment/compose.hpp>
+#include <boost/composite_storage/special_components.hpp>
+
+namespace boost
+{
+namespace composite_storage
+{
+namespace layout
+{
+ template
+ <// class CompositeTag
+ >
+struct operators< tags::one_of_maybe>
+: components_aligned_yes
+{
+ template
+ < typename HeadComposed
+ , typename TailLayout
+ >
+ struct compose_layout
+ {
+ static
+ std::size_t const
+ size
+ = HeadComposed::size
+ > TailLayout::size
+ ? HeadComposed::size
+ : TailLayout::size
+ ;
+ static
+ std::size_t const
+ align
+ =alignment::compose
+ < HeadComposed::align
+ , TailLayout::align
+ >::value
+ ;
+ };
+
+ template
+ < typename IndexUndefined
+ >
+ struct layout0
+ {
+ typedef
+ special_components::nothing
+ tail_type
+ ;
+ typedef
+ IndexUndefined
+ index_part
+ ;
+ typedef
+ layout_data<>
+ comp_part
+ ;
+ static
+ void
+ inject_default( index_part index_arg, char*buffer_composite)
+ {
+ }
+ static
+ void
+ inject( index_part index_arg, char*buffer_composite, tail_type const&)
+ {
+ }
+ static
+ special_components::nothing const*
+ project(index_part index_arg, char const*buffer_composite)
+ {
+ return tail_type::_();
+ }
+ static
+ special_components::nothing*
+ project(index_part index_arg, char*buffer_composite)
+ {
+ return tail_type::_();
+ }
+ static
+ special_components::nothing*
+ project(index_part index_arg, buffers::rval_ref_buf buffer_composite)
+ {
+ return tail_type::_();
+ }
+ static
+ void
+ destroyer( index_part index_arg, char*buffer_composite)
+ {
+ }
+ };
+
+ template
+ < typename HeadLayout
+ , typename TailComponent
+ >
+ struct push_back
+ {
+ struct type
+ : private HeadLayout
+ {
+ typedef
+ HeadLayout
+ head_layout
+ ;
+ typedef
+ typename mpl::next<typename HeadLayout::index_part>::type
+ index_part
+ ;
+ typedef
+ compose_layout
+ < typename HeadLayout::comp_part
+ , layout_of<TailComponent>
+ >
+ comp_part
+ ;
+ template
+ < typename TailConvertible
+ , int Dummy=0
+ >
+ struct
+ inject_non_empty
+ {
+ static
+ void
+ _
+ ( char*buffer_composite
+ )
+ {
+ new(buffer_composite) TailComponent;
+ }
+ static
+ void
+ _
+ ( char*buffer_composite
+ , TailConvertible const& tail_component
+ )
+ {
+ new(buffer_composite) TailComponent(tail_component);
+ }
+ static
+ void
+ _
+ ( char*buffer_composite
+ , TailConvertible&& tail_component
+ )
+ {
+ new(buffer_composite) TailComponent(std::forward<TailConvertible>(tail_component));
+ }
+ };
+
+ template
+ < int Dummy
+ >
+ struct
+ inject_non_empty
+ < special_components::empty
+ , Dummy
+ >
+ {
+ static
+ void
+ _
+ ( char*buffer_composite
+ )
+ {
+ }
+ static
+ void
+ _
+ ( char*buffer_composite
+ , special_components::empty
+ )
+ {
+ }
+ };
+ using HeadLayout::
+ inject_default
+ ;
+ static
+ void
+ inject_default
+ ( index_part index_arg
+ , char*buffer_composite
+ )
+ {
+ inject_non_empty<TailComponent>::_(buffer_composite);
+ }
+
+ using HeadLayout::
+ inject
+ ;
+ static
+ void
+ inject
+ ( index_part index_arg
+ , char*buffer_composite
+ , TailComponent const& tail_component
+ )
+ {
+ inject_non_empty<TailComponent>::_
+ ( buffer_composite
+ , tail_component
+ );
+ }
+ static
+ void
+ inject
+ ( index_part index_arg
+ , char*buffer_composite
+ , TailComponent&& tail_component
+ )
+ {
+ inject_non_empty<TailComponent>::_
+ ( buffer_composite
+ , std::forward<TailComponent>(tail_component)
+ );
+ }
+
+ using HeadLayout::
+ project
+ ;
+ static
+ TailComponent const*
+ project(index_part index_arg, char const*buffer_composite)
+ {
+ void const*tail_buffer=buffer_composite;
+ TailComponent const*tail_ptr=static_cast<TailComponent const*>(tail_buffer);
+ return tail_ptr;
+ }
+ static
+ TailComponent*
+ project(index_part index_arg, char*buffer_composite)
+ {
+ void*tail_buffer=buffer_composite;
+ TailComponent*tail_ptr=static_cast<TailComponent*>(tail_buffer);
+ return tail_ptr;
+ }
+ static
+ TailComponent*
+ project(index_part index_arg, buffers::rval_ref_buf buffer_composite)
+ {
+ void*tail_buffer=buffer_composite.my_buf;
+ TailComponent*tail_ptr=static_cast<TailComponent*>(tail_buffer);
+ return tail_ptr;
+ }
+ using HeadLayout::
+ destroyer
+ ;
+ template
+ < typename TailConvertible
+ , int Dummy=0
+ >
+ struct
+ destroy_non_empty
+ {
+ static
+ void
+ _
+ ( void*buffer_composite
+ )
+ {
+ TailComponent*tail_ptr=static_cast<TailComponent*>(buffer_composite);
+ tail_ptr->~TailComponent();
+ }
+ };
+
+ template
+ < int Dummy
+ >
+ struct
+ destroy_non_empty
+ < special_components::empty
+ , Dummy
+ >
+ {
+ static
+ void
+ _
+ ( void*buffer_composite
+ )
+ {
+ }
+ };
+ static
+ void
+ destroyer( index_part index_arg, char*buffer_composite)
+ {
+ destroy_non_empty<TailComponent>::_( buffer_composite);
+ }
+ };
+ };
+
+};
+
+}//exit layout namespace
+}//exit composite_storage namespace
+}//exit boost namespace
+#endif
+


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