annotate DEPENDENCIES/generic/include/boost/multi_index/detail/copy_map.hpp @ 33:0f1df952e9e9

Looks like --retain-symbols-file=<file>.list is the PE equivalent of the ELF version script for our purposes
author Chris Cannam
date Wed, 06 Aug 2014 16:02:26 +0100
parents 2665513ce2d3
children c530137014c0
rev   line source
Chris@16 1 /* Copyright 2003-2008 Joaquin M Lopez Munoz.
Chris@16 2 * Distributed under the Boost Software License, Version 1.0.
Chris@16 3 * (See accompanying file LICENSE_1_0.txt or copy at
Chris@16 4 * http://www.boost.org/LICENSE_1_0.txt)
Chris@16 5 *
Chris@16 6 * See http://www.boost.org/libs/multi_index for library home page.
Chris@16 7 */
Chris@16 8
Chris@16 9 #ifndef BOOST_MULTI_INDEX_DETAIL_COPY_MAP_HPP
Chris@16 10 #define BOOST_MULTI_INDEX_DETAIL_COPY_MAP_HPP
Chris@16 11
Chris@16 12 #if defined(_MSC_VER)&&(_MSC_VER>=1200)
Chris@16 13 #pragma once
Chris@16 14 #endif
Chris@16 15
Chris@16 16 #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
Chris@16 17 #include <algorithm>
Chris@16 18 #include <boost/detail/no_exceptions_support.hpp>
Chris@16 19 #include <boost/multi_index/detail/auto_space.hpp>
Chris@16 20 #include <boost/multi_index/detail/prevent_eti.hpp>
Chris@16 21 #include <boost/noncopyable.hpp>
Chris@16 22 #include <cstddef>
Chris@16 23 #include <functional>
Chris@16 24
Chris@16 25 namespace boost{
Chris@16 26
Chris@16 27 namespace multi_index{
Chris@16 28
Chris@16 29 namespace detail{
Chris@16 30
Chris@16 31 /* copy_map is used as an auxiliary structure during copy_() operations.
Chris@16 32 * When a container with n nodes is replicated, node_map holds the pairings
Chris@16 33 * between original and copied nodes, and provides a fast way to find a
Chris@16 34 * copied node from an original one.
Chris@16 35 * The semantics of the class are not simple, and no attempt has been made
Chris@16 36 * to enforce it: multi_index_container handles it right. On the other hand,
Chris@16 37 * the const interface, which is the one provided to index implementations,
Chris@16 38 * only allows for:
Chris@16 39 * - Enumeration of pairs of (original,copied) nodes (excluding the headers),
Chris@16 40 * - fast retrieval of copied nodes (including the headers.)
Chris@16 41 */
Chris@16 42
Chris@16 43 template <typename Node>
Chris@16 44 struct copy_map_entry
Chris@16 45 {
Chris@16 46 copy_map_entry(Node* f,Node* s):first(f),second(s){}
Chris@16 47
Chris@16 48 Node* first;
Chris@16 49 Node* second;
Chris@16 50
Chris@16 51 bool operator<(const copy_map_entry<Node>& x)const
Chris@16 52 {
Chris@16 53 return std::less<Node*>()(first,x.first);
Chris@16 54 }
Chris@16 55 };
Chris@16 56
Chris@16 57 template <typename Node,typename Allocator>
Chris@16 58 class copy_map:private noncopyable
Chris@16 59 {
Chris@16 60 public:
Chris@16 61 typedef const copy_map_entry<Node>* const_iterator;
Chris@16 62
Chris@16 63 copy_map(
Chris@16 64 const Allocator& al,std::size_t size,Node* header_org,Node* header_cpy):
Chris@16 65 al_(al),size_(size),spc(al_,size_),n(0),
Chris@16 66 header_org_(header_org),header_cpy_(header_cpy),released(false)
Chris@16 67 {}
Chris@16 68
Chris@16 69 ~copy_map()
Chris@16 70 {
Chris@16 71 if(!released){
Chris@16 72 for(std::size_t i=0;i<n;++i){
Chris@16 73 boost::detail::allocator::destroy(&(spc.data()+i)->second->value());
Chris@16 74 deallocate((spc.data()+i)->second);
Chris@16 75 }
Chris@16 76 }
Chris@16 77 }
Chris@16 78
Chris@16 79 const_iterator begin()const{return &*spc.data();}
Chris@16 80 const_iterator end()const{return &*(spc.data()+n);}
Chris@16 81
Chris@16 82 void clone(Node* node)
Chris@16 83 {
Chris@16 84 (spc.data()+n)->first=node;
Chris@16 85 (spc.data()+n)->second=&*al_.allocate(1);
Chris@16 86 BOOST_TRY{
Chris@16 87 boost::detail::allocator::construct(
Chris@16 88 &(spc.data()+n)->second->value(),node->value());
Chris@16 89 }
Chris@16 90 BOOST_CATCH(...){
Chris@16 91 deallocate((spc.data()+n)->second);
Chris@16 92 BOOST_RETHROW;
Chris@16 93 }
Chris@16 94 BOOST_CATCH_END
Chris@16 95 ++n;
Chris@16 96
Chris@16 97 if(n==size_)std::sort(&*spc.data(),&*spc.data()+size_);
Chris@16 98 }
Chris@16 99
Chris@16 100 Node* find(Node* node)const
Chris@16 101 {
Chris@16 102 if(node==header_org_)return header_cpy_;
Chris@16 103 return std::lower_bound(
Chris@16 104 begin(),end(),copy_map_entry<Node>(node,0))->second;
Chris@16 105 }
Chris@16 106
Chris@16 107 void release()
Chris@16 108 {
Chris@16 109 released=true;
Chris@16 110 }
Chris@16 111
Chris@16 112 private:
Chris@16 113 typedef typename prevent_eti<
Chris@16 114 Allocator,
Chris@16 115 typename boost::detail::allocator::rebind_to<
Chris@16 116 Allocator,Node>::type
Chris@16 117 >::type allocator_type;
Chris@16 118 typedef typename allocator_type::pointer allocator_pointer;
Chris@16 119
Chris@16 120 allocator_type al_;
Chris@16 121 std::size_t size_;
Chris@16 122 auto_space<copy_map_entry<Node>,Allocator> spc;
Chris@16 123 std::size_t n;
Chris@16 124 Node* header_org_;
Chris@16 125 Node* header_cpy_;
Chris@16 126 bool released;
Chris@16 127
Chris@16 128 void deallocate(Node* node)
Chris@16 129 {
Chris@16 130 al_.deallocate(static_cast<allocator_pointer>(node),1);
Chris@16 131 }
Chris@16 132 };
Chris@16 133
Chris@16 134 } /* namespace multi_index::detail */
Chris@16 135
Chris@16 136 } /* namespace multi_index */
Chris@16 137
Chris@16 138 } /* namespace boost */
Chris@16 139
Chris@16 140 #endif