epoc32/include/stdapis/boost/multi_index/detail/index_node_base.hpp
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:27:01 +0100 (2010-03-31)
branchSymbian2
changeset 3 e1b950c65cb4
permissions -rw-r--r--
Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
     1 /* Copyright 2003-2006 Joaquín M López Muñoz.
     2  * Distributed under the Boost Software License, Version 1.0.
     3  * (See accompanying file LICENSE_1_0.txt or copy at
     4  * http://www.boost.org/LICENSE_1_0.txt)
     5  *
     6  * See http://www.boost.org/libs/multi_index for library home page.
     7  */
     8 
     9 #ifndef BOOST_MULTI_INDEX_DETAIL_INDEX_NODE_BASE_HPP
    10 #define BOOST_MULTI_INDEX_DETAIL_INDEX_NODE_BASE_HPP
    11 
    12 #if defined(_MSC_VER)&&(_MSC_VER>=1200)
    13 #pragma once
    14 #endif
    15 
    16 #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
    17 #include <boost/type_traits/aligned_storage.hpp>
    18 #include <boost/type_traits/alignment_of.hpp> 
    19 
    20 #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
    21 #include <boost/archive/archive_exception.hpp>
    22 #include <boost/serialization/access.hpp>
    23 #include <boost/throw_exception.hpp> 
    24 #endif
    25 
    26 namespace boost{
    27 
    28 namespace multi_index{
    29 
    30 namespace detail{
    31 
    32 /* index_node_base tops the node hierarchy of multi_index_container. It holds
    33  * the value of the element contained.
    34  */
    35 
    36 template<typename Value>
    37 struct pod_value_holder
    38 {
    39   typename aligned_storage<
    40     sizeof(Value),
    41     alignment_of<Value>::value
    42   >::type                      space;
    43 };
    44 
    45 template<typename Value>
    46 struct index_node_base:private pod_value_holder<Value>
    47 {
    48   typedef index_node_base base_type; /* used for serialization purposes */
    49   typedef Value           value_type;
    50 
    51   value_type& value()
    52   {
    53     return *static_cast<value_type*>(
    54       static_cast<void*>(&this->space));
    55   }
    56 
    57   const value_type& value()const
    58   {
    59     return *static_cast<const value_type*>(
    60       static_cast<const void*>(&this->space));
    61   }
    62 
    63   static index_node_base* from_value(const value_type* p)
    64   {
    65     return static_cast<index_node_base *>(
    66       reinterpret_cast<pod_value_holder<Value>*>( /* std 9.2.17 */
    67         const_cast<value_type*>(p))); 
    68   }
    69 
    70 private:
    71 #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
    72   friend class boost::serialization::access;
    73   
    74   /* nodes do not emit any kind of serialization info. They are
    75    * fed to Boost.Serialization so that pointers to nodes are
    76    * tracked correctly.
    77    */
    78 
    79   template<class Archive>
    80   void serialize(Archive&,const unsigned int)
    81   {
    82   }
    83 #endif
    84 };
    85 
    86 template<typename Node,typename Value>
    87 Node* node_from_value(
    88   const Value* p
    89   BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(Node))
    90 {
    91   return static_cast<Node*>(index_node_base<Value>::from_value(p));
    92 }
    93 
    94 } /* namespace multi_index::detail */
    95 
    96 } /* namespace multi_index */
    97 
    98 #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
    99 /* Index nodes never get constructed directly by Boost.Serialization,
   100  * as archives are always fed pointers to previously existent
   101  * nodes. So, if this is called it means we are dealing with a
   102  * somehow invalid archive.
   103  */
   104 
   105 #if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
   106 namespace serialization{
   107 #else
   108 namespace multi_index{
   109 namespace detail{
   110 #endif
   111 
   112 template<class Archive,typename Value>
   113 inline void load_construct_data(
   114   Archive&,boost::multi_index::detail::index_node_base<Value>*,
   115   const unsigned int)
   116 {
   117   throw_exception(
   118     archive::archive_exception(archive::archive_exception::other_exception));
   119 }
   120 
   121 #if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
   122 } /* namespace serialization */
   123 #else
   124 } /* namespace multi_index::detail */
   125 } /* namespace multi_index */
   126 #endif
   127 
   128 #endif
   129 
   130 } /* namespace boost */
   131 
   132 #endif