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