~ubuntu-branches/ubuntu/wily/davix/wily

« back to all changes in this revision

Viewing changes to deps/boost_intern/boost/container/detail/allocator_version_traits.hpp

  • Committer: Package Import Robot
  • Author(s): Mattias Ellert
  • Date: 2015-07-31 13:17:55 UTC
  • mfrom: (5.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20150731131755-mizprbmn7ogv33te
Tags: 0.4.1-1
* Update to version 0.4.1
* Implement Multi-Arch support

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//////////////////////////////////////////////////////////////////////////////
2
 
//
3
 
// (C) Copyright Ion Gaztanaga 2012-2012. Distributed under the Boost
4
 
// Software License, Version 1.0. (See accompanying file
5
 
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6
 
//
7
 
// See http://www.boost.org/libs/container for documentation.
8
 
//
9
 
//////////////////////////////////////////////////////////////////////////////
10
 
 
11
 
#ifndef BOOST_CONTAINER_DETAIL_ALLOCATOR_VERSION_TRAITS_HPP
12
 
#define BOOST_CONTAINER_DETAIL_ALLOCATOR_VERSION_TRAITS_HPP
13
 
 
14
 
#if defined(_MSC_VER)
15
 
#  pragma once
16
 
#endif
17
 
 
18
 
#include <boost/container/detail/config_begin.hpp>
19
 
#include <boost/container/detail/workaround.hpp>
20
 
#include <boost/container/allocator_traits.hpp>             //allocator_traits
21
 
#include <boost/container/throw_exception.hpp>
22
 
#include <boost/container/detail/multiallocation_chain.hpp> //multiallocation_chain
23
 
#include <boost/container/detail/version_type.hpp>          //version_type
24
 
#include <boost/container/detail/allocation_type.hpp>       //allocation_type
25
 
#include <boost/container/detail/mpl.hpp>                   //integral_constant
26
 
#include <boost/intrusive/pointer_traits.hpp>               //pointer_traits
27
 
#include <utility>                                          //pair
28
 
#include <boost/detail/no_exceptions_support.hpp>           //BOOST_TRY
29
 
 
30
 
namespace boost {
31
 
namespace container {
32
 
namespace container_detail {
33
 
 
34
 
template<class Allocator, unsigned Version = boost::container::container_detail::version<Allocator>::value>
35
 
struct allocator_version_traits
36
 
{
37
 
   typedef ::boost::container::container_detail::integral_constant
38
 
      <unsigned, Version> alloc_version;
39
 
 
40
 
   typedef typename Allocator::multiallocation_chain multiallocation_chain;
41
 
 
42
 
   typedef typename boost::container::allocator_traits<Allocator>::pointer    pointer;
43
 
   typedef typename boost::container::allocator_traits<Allocator>::size_type  size_type;
44
 
 
45
 
   //Node allocation interface
46
 
   static pointer allocate_one(Allocator &a)
47
 
   {  return a.allocate_one();   }
48
 
 
49
 
   static void deallocate_one(Allocator &a, const pointer &p)
50
 
   {  a.deallocate_one(p);   }
51
 
 
52
 
   static void allocate_individual(Allocator &a, size_type n, multiallocation_chain &m)
53
 
   {  return a.allocate_individual(n, m);   }
54
 
 
55
 
   static void deallocate_individual(Allocator &a, multiallocation_chain &holder)
56
 
   {  a.deallocate_individual(holder);   }
57
 
 
58
 
   static std::pair<pointer, bool>
59
 
      allocation_command(Allocator &a, allocation_type command,
60
 
                         size_type limit_size, size_type preferred_size,
61
 
                         size_type &received_size, const pointer &reuse)
62
 
   {
63
 
      return a.allocation_command
64
 
         (command, limit_size, preferred_size, received_size, reuse);
65
 
   }
66
 
};
67
 
 
68
 
template<class Allocator>
69
 
struct allocator_version_traits<Allocator, 1>
70
 
{
71
 
   typedef ::boost::container::container_detail::integral_constant
72
 
      <unsigned, 1> alloc_version;
73
 
 
74
 
   typedef typename boost::container::allocator_traits<Allocator>::pointer    pointer;
75
 
   typedef typename boost::container::allocator_traits<Allocator>::size_type  size_type;
76
 
   typedef typename boost::container::allocator_traits<Allocator>::value_type value_type;
77
 
 
78
 
   typedef typename boost::intrusive::pointer_traits<pointer>::
79
 
         template rebind_pointer<void>::type                void_ptr;
80
 
   typedef container_detail::basic_multiallocation_chain
81
 
      <void_ptr>                                            multialloc_cached_counted;
82
 
   typedef boost::container::container_detail::
83
 
      transform_multiallocation_chain
84
 
         < multialloc_cached_counted, value_type>           multiallocation_chain;
85
 
 
86
 
   //Node allocation interface
87
 
   static pointer allocate_one(Allocator &a)
88
 
   {  return a.allocate(1);   }
89
 
 
90
 
   static void deallocate_one(Allocator &a, const pointer &p)
91
 
   {  a.deallocate(p, 1);   }
92
 
 
93
 
   static void deallocate_individual(Allocator &a, multiallocation_chain &holder)
94
 
   {
95
 
      size_type n = holder.size();
96
 
      typename multiallocation_chain::iterator it = holder.begin();
97
 
      while(n--){
98
 
         pointer p = boost::intrusive::pointer_traits<pointer>::pointer_to(*it);
99
 
         ++it;
100
 
         a.deallocate(p, 1);
101
 
      }
102
 
   }
103
 
 
104
 
   struct allocate_individual_rollback
105
 
   {
106
 
      allocate_individual_rollback(Allocator &a, multiallocation_chain &chain)
107
 
         : mr_a(a), mp_chain(&chain)
108
 
      {}
109
 
 
110
 
      ~allocate_individual_rollback()
111
 
      {
112
 
         if(mp_chain)
113
 
            allocator_version_traits::deallocate_individual(mr_a, *mp_chain);
114
 
      }
115
 
 
116
 
      void release()
117
 
      {
118
 
         mp_chain = 0;
119
 
      }
120
 
 
121
 
      Allocator &mr_a;
122
 
      multiallocation_chain * mp_chain;
123
 
   };
124
 
 
125
 
   static void allocate_individual(Allocator &a, size_type n, multiallocation_chain &m)
126
 
   {
127
 
      allocate_individual_rollback rollback(a, m);
128
 
      while(n--){
129
 
         m.push_front(a.allocate(1));
130
 
      }
131
 
      rollback.release();
132
 
   }
133
 
 
134
 
   static std::pair<pointer, bool>
135
 
      allocation_command(Allocator &a, allocation_type command,
136
 
                         size_type, size_type preferred_size,
137
 
                         size_type &received_size, const pointer &)
138
 
   {
139
 
      std::pair<pointer, bool> ret(pointer(), false);
140
 
      if(!(command & allocate_new)){
141
 
         if(!(command & nothrow_allocation)){
142
 
            throw_logic_error("version 1 allocator without allocate_new flag");
143
 
         }
144
 
      }
145
 
      else{
146
 
         received_size = preferred_size;
147
 
         BOOST_TRY{
148
 
            ret.first = a.allocate(received_size);
149
 
         }
150
 
         BOOST_CATCH(...){
151
 
            if(!(command & nothrow_allocation)){
152
 
               BOOST_RETHROW
153
 
            }
154
 
         }
155
 
         BOOST_CATCH_END
156
 
      }
157
 
      return ret;
158
 
   }
159
 
};
160
 
 
161
 
}  //namespace container_detail {
162
 
}  //namespace container {
163
 
}  //namespace boost {
164
 
 
165
 
#include <boost/container/detail/config_end.hpp>
166
 
 
167
 
#endif // ! defined(BOOST_CONTAINER_DETAIL_ALLOCATOR_VERSION_TRAITS_HPP)