Added boost header
This commit is contained in:
78
test/external/boost/interprocess/indexes/flat_map_index.hpp
vendored
Normal file
78
test/external/boost/interprocess/indexes/flat_map_index.hpp
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2005-2009. Distributed under the Boost
|
||||
// Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// See http://www.boost.org/libs/interprocess for documentation.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
#ifndef BOOST_INTERPROCESS_FLAT_MAP_INDEX_HPP
|
||||
#define BOOST_INTERPROCESS_FLAT_MAP_INDEX_HPP
|
||||
|
||||
#include <boost/interprocess/detail/config_begin.hpp>
|
||||
#include <boost/interprocess/detail/workaround.hpp>
|
||||
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
#include <boost/interprocess/containers/flat_map.hpp>
|
||||
#include <boost/interprocess/allocators/allocator.hpp>
|
||||
|
||||
//!\file
|
||||
//!Describes index adaptor of boost::map container, to use it
|
||||
//!as name/shared memory index
|
||||
|
||||
//[flat_map_index
|
||||
namespace boost { namespace interprocess {
|
||||
|
||||
//!Helper class to define typedefs from IndexTraits
|
||||
template <class MapConfig>
|
||||
struct flat_map_index_aux
|
||||
{
|
||||
typedef typename MapConfig::key_type key_type;
|
||||
typedef typename MapConfig::mapped_type mapped_type;
|
||||
typedef typename MapConfig::
|
||||
segment_manager_base segment_manager_base;
|
||||
typedef std::less<key_type> key_less;
|
||||
typedef std::pair<key_type, mapped_type> value_type;
|
||||
typedef allocator<value_type
|
||||
,segment_manager_base> allocator_type;
|
||||
typedef flat_map<key_type, mapped_type,
|
||||
key_less, allocator_type> index_t;
|
||||
};
|
||||
|
||||
//!Index type based in flat_map. Just derives from flat_map and
|
||||
//!defines the interface needed by managed memory segments.
|
||||
template <class MapConfig>
|
||||
class flat_map_index
|
||||
//Derive class from flat_map specialization
|
||||
: public flat_map_index_aux<MapConfig>::index_t
|
||||
{
|
||||
/// @cond
|
||||
typedef flat_map_index_aux<MapConfig> index_aux;
|
||||
typedef typename index_aux::index_t base_type;
|
||||
typedef typename index_aux::
|
||||
segment_manager_base segment_manager_base;
|
||||
/// @endcond
|
||||
|
||||
public:
|
||||
//!Constructor. Takes a pointer to the segment manager. Can throw
|
||||
flat_map_index(segment_manager_base *segment_mngr)
|
||||
: base_type(typename index_aux::key_less(),
|
||||
typename index_aux::allocator_type(segment_mngr))
|
||||
{}
|
||||
|
||||
//!This reserves memory to optimize the insertion of n elements in the index
|
||||
void reserve(typename segment_manager_base::size_type n)
|
||||
{ base_type::reserve(n); }
|
||||
|
||||
//!This frees all unnecessary memory
|
||||
void shrink_to_fit()
|
||||
{ base_type::shrink_to_fit(); }
|
||||
};
|
||||
|
||||
}} //namespace boost { namespace interprocess
|
||||
//]
|
||||
#include <boost/interprocess/detail/config_end.hpp>
|
||||
|
||||
#endif //#ifndef BOOST_INTERPROCESS_FLAT_MAP_INDEX_HPP
|
||||
150
test/external/boost/interprocess/indexes/iset_index.hpp
vendored
Normal file
150
test/external/boost/interprocess/indexes/iset_index.hpp
vendored
Normal file
@@ -0,0 +1,150 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2005-2009. Distributed under the Boost
|
||||
// Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// See http://www.boost.org/libs/interprocess for documentation.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef BOOST_INTERPROCESS_ISET_INDEX_HPP
|
||||
#define BOOST_INTERPROCESS_ISET_INDEX_HPP
|
||||
|
||||
#include <boost/interprocess/detail/config_begin.hpp>
|
||||
#include <boost/interprocess/detail/workaround.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
#include <boost/interprocess/detail/utilities.hpp>
|
||||
#include <boost/intrusive/set.hpp>
|
||||
|
||||
|
||||
//!\file
|
||||
//!Describes index adaptor of boost::intrusive::set container, to use it
|
||||
//!as name/shared memory index
|
||||
|
||||
namespace boost {
|
||||
namespace interprocess {
|
||||
|
||||
/// @cond
|
||||
|
||||
//!Helper class to define typedefs from IndexTraits
|
||||
template <class MapConfig>
|
||||
struct iset_index_aux
|
||||
{
|
||||
typedef typename
|
||||
MapConfig::segment_manager_base segment_manager_base;
|
||||
|
||||
typedef typename
|
||||
segment_manager_base::void_pointer void_pointer;
|
||||
typedef typename bi::make_set_base_hook
|
||||
< bi::void_pointer<void_pointer>
|
||||
, bi::optimize_size<true>
|
||||
>::type derivation_hook;
|
||||
|
||||
typedef typename MapConfig::template
|
||||
intrusive_value_type<derivation_hook>::type value_type;
|
||||
typedef std::less<value_type> value_compare;
|
||||
typedef typename bi::make_set
|
||||
< value_type
|
||||
, bi::base_hook<derivation_hook>
|
||||
>::type index_t;
|
||||
};
|
||||
/// @endcond
|
||||
|
||||
//!Index type based in boost::intrusive::set.
|
||||
//!Just derives from boost::intrusive::set
|
||||
//!and defines the interface needed by managed memory segments*/
|
||||
template <class MapConfig>
|
||||
class iset_index
|
||||
//Derive class from map specialization
|
||||
: public iset_index_aux<MapConfig>::index_t
|
||||
{
|
||||
/// @cond
|
||||
typedef iset_index_aux<MapConfig> index_aux;
|
||||
typedef typename index_aux::index_t index_type;
|
||||
typedef typename MapConfig::
|
||||
intrusive_compare_key_type intrusive_compare_key_type;
|
||||
typedef typename MapConfig::char_type char_type;
|
||||
/// @endcond
|
||||
|
||||
public:
|
||||
typedef typename index_type::iterator iterator;
|
||||
typedef typename index_type::const_iterator const_iterator;
|
||||
typedef typename index_type::insert_commit_data insert_commit_data;
|
||||
typedef typename index_type::value_type value_type;
|
||||
|
||||
/// @cond
|
||||
private:
|
||||
|
||||
struct intrusive_key_value_less
|
||||
{
|
||||
bool operator()(const intrusive_compare_key_type &i, const value_type &b) const
|
||||
{
|
||||
std::size_t blen = b.name_length();
|
||||
return (i.m_len < blen) ||
|
||||
(i.m_len == blen &&
|
||||
std::char_traits<char_type>::compare
|
||||
(i.mp_str, b.name(), i.m_len) < 0);
|
||||
}
|
||||
|
||||
bool operator()(const value_type &b, const intrusive_compare_key_type &i) const
|
||||
{
|
||||
std::size_t blen = b.name_length();
|
||||
return (blen < i.m_len) ||
|
||||
(blen == i.m_len &&
|
||||
std::char_traits<char_type>::compare
|
||||
(b.name(), i.mp_str, i.m_len) < 0);
|
||||
}
|
||||
};
|
||||
|
||||
/// @endcond
|
||||
|
||||
public:
|
||||
|
||||
//!Constructor. Takes a pointer to the
|
||||
//!segment manager. Can throw
|
||||
iset_index(typename MapConfig::segment_manager_base *)
|
||||
: index_type(/*typename index_aux::value_compare()*/)
|
||||
{}
|
||||
|
||||
//!This reserves memory to optimize the insertion of n
|
||||
//!elements in the index
|
||||
void reserve(typename MapConfig::segment_manager_base::size_type)
|
||||
{ /*Does nothing, map has not reserve or rehash*/ }
|
||||
|
||||
//!This frees all unnecessary memory
|
||||
void shrink_to_fit()
|
||||
{ /*Does nothing, this intrusive index does not allocate memory;*/ }
|
||||
|
||||
iterator find(const intrusive_compare_key_type &key)
|
||||
{ return index_type::find(key, intrusive_key_value_less()); }
|
||||
|
||||
const_iterator find(const intrusive_compare_key_type &key) const
|
||||
{ return index_type::find(key, intrusive_key_value_less()); }
|
||||
|
||||
std::pair<iterator, bool>insert_check
|
||||
(const intrusive_compare_key_type &key, insert_commit_data &commit_data)
|
||||
{ return index_type::insert_check(key, intrusive_key_value_less(), commit_data); }
|
||||
};
|
||||
|
||||
/// @cond
|
||||
|
||||
//!Trait class to detect if an index is an intrusive
|
||||
//!index.
|
||||
template<class MapConfig>
|
||||
struct is_intrusive_index
|
||||
<boost::interprocess::iset_index<MapConfig> >
|
||||
{
|
||||
enum{ value = true };
|
||||
};
|
||||
/// @endcond
|
||||
|
||||
} //namespace interprocess {
|
||||
} //namespace boost
|
||||
|
||||
#include <boost/interprocess/detail/config_end.hpp>
|
||||
|
||||
#endif //#ifndef BOOST_INTERPROCESS_ISET_INDEX_HPP
|
||||
368
test/external/boost/interprocess/indexes/iunordered_set_index.hpp
vendored
Normal file
368
test/external/boost/interprocess/indexes/iunordered_set_index.hpp
vendored
Normal file
@@ -0,0 +1,368 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2005-2009. Distributed under the Boost
|
||||
// Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// See http://www.boost.org/libs/interprocess for documentation.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef BOOST_INTERPROCESS_IUNORDERED_SET_INDEX_HPP
|
||||
#define BOOST_INTERPROCESS_IUNORDERED_SET_INDEX_HPP
|
||||
|
||||
#include <boost/interprocess/detail/config_begin.hpp>
|
||||
#include <boost/interprocess/detail/workaround.hpp>
|
||||
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
#include <boost/get_pointer.hpp>
|
||||
#include <boost/interprocess/detail/utilities.hpp>
|
||||
#include <boost/interprocess/containers/vector.hpp>
|
||||
#include <boost/intrusive/unordered_set.hpp>
|
||||
#include <boost/interprocess/allocators/allocator.hpp>
|
||||
|
||||
//!\file
|
||||
//!Describes index adaptor of boost::intrusive::unordered_set container, to use it
|
||||
//!as name/shared memory index
|
||||
|
||||
namespace boost { namespace interprocess {
|
||||
|
||||
/// @cond
|
||||
|
||||
//!Helper class to define typedefs
|
||||
//!from IndexTraits
|
||||
template <class MapConfig>
|
||||
struct iunordered_set_index_aux
|
||||
{
|
||||
typedef typename
|
||||
MapConfig::segment_manager_base segment_manager_base;
|
||||
|
||||
typedef typename
|
||||
segment_manager_base::void_pointer void_pointer;
|
||||
|
||||
typedef typename bi::make_unordered_set_base_hook
|
||||
< bi::void_pointer<void_pointer>
|
||||
>::type derivation_hook;
|
||||
|
||||
typedef typename MapConfig::template
|
||||
intrusive_value_type<derivation_hook>::type value_type;
|
||||
|
||||
typedef typename MapConfig::
|
||||
intrusive_compare_key_type intrusive_compare_key_type;
|
||||
|
||||
typedef std::equal_to<value_type> value_equal;
|
||||
|
||||
typedef typename MapConfig::char_type char_type;
|
||||
|
||||
struct equal_function
|
||||
{
|
||||
bool operator()(const intrusive_compare_key_type &i, const value_type &b) const
|
||||
{
|
||||
return (i.m_len == b.name_length()) &&
|
||||
(std::char_traits<char_type>::compare
|
||||
(i.mp_str, b.name(), i.m_len) == 0);
|
||||
}
|
||||
|
||||
bool operator()(const value_type &b, const intrusive_compare_key_type &i) const
|
||||
{
|
||||
return (i.m_len == b.name_length()) &&
|
||||
(std::char_traits<char_type>::compare
|
||||
(i.mp_str, b.name(), i.m_len) == 0);
|
||||
}
|
||||
|
||||
bool operator()(const value_type &b1, const value_type &b2) const
|
||||
{
|
||||
return (b1.name_length() == b2.name_length()) &&
|
||||
(std::char_traits<char_type>::compare
|
||||
(b1.name(), b2.name(), b1.name_length()) == 0);
|
||||
}
|
||||
};
|
||||
|
||||
struct hash_function
|
||||
: std::unary_function<value_type, std::size_t>
|
||||
{
|
||||
std::size_t operator()(const value_type &val) const
|
||||
{
|
||||
const char_type *beg = ipcdetail::get_pointer(val.name()),
|
||||
*end = beg + val.name_length();
|
||||
return boost::hash_range(beg, end);
|
||||
}
|
||||
|
||||
std::size_t operator()(const intrusive_compare_key_type &i) const
|
||||
{
|
||||
const char_type *beg = i.mp_str,
|
||||
*end = beg + i.m_len;
|
||||
return boost::hash_range(beg, end);
|
||||
}
|
||||
};
|
||||
|
||||
typedef typename bi::make_unordered_set
|
||||
< value_type
|
||||
, bi::hash<hash_function>
|
||||
, bi::equal<equal_function>
|
||||
, bi::size_type<typename segment_manager_base::size_type>
|
||||
>::type index_t;
|
||||
typedef typename index_t::bucket_type bucket_type;
|
||||
typedef allocator
|
||||
<bucket_type, segment_manager_base> allocator_type;
|
||||
|
||||
struct allocator_holder
|
||||
{
|
||||
allocator_holder(segment_manager_base *mngr)
|
||||
: alloc(mngr)
|
||||
{}
|
||||
allocator_type alloc;
|
||||
bucket_type init_bucket;
|
||||
};
|
||||
};
|
||||
/// @endcond
|
||||
|
||||
//!Index type based in boost::intrusive::set.
|
||||
//!Just derives from boost::intrusive::set
|
||||
//!and defines the interface needed by managed memory segments
|
||||
template <class MapConfig>
|
||||
class iunordered_set_index
|
||||
//Derive class from map specialization
|
||||
: private iunordered_set_index_aux<MapConfig>::allocator_holder
|
||||
, public iunordered_set_index_aux<MapConfig>::index_t
|
||||
{
|
||||
/// @cond
|
||||
typedef iunordered_set_index_aux<MapConfig> index_aux;
|
||||
typedef typename index_aux::index_t index_type;
|
||||
typedef typename MapConfig::
|
||||
intrusive_compare_key_type intrusive_compare_key_type;
|
||||
typedef typename index_aux::equal_function equal_function;
|
||||
typedef typename index_aux::hash_function hash_function;
|
||||
typedef typename MapConfig::char_type char_type;
|
||||
typedef typename
|
||||
iunordered_set_index_aux<MapConfig>::allocator_type allocator_type;
|
||||
typedef typename
|
||||
iunordered_set_index_aux<MapConfig>::allocator_holder allocator_holder;
|
||||
/// @endcond
|
||||
|
||||
public:
|
||||
typedef typename index_type::iterator iterator;
|
||||
typedef typename index_type::const_iterator const_iterator;
|
||||
typedef typename index_type::insert_commit_data insert_commit_data;
|
||||
typedef typename index_type::value_type value_type;
|
||||
typedef typename index_type::bucket_ptr bucket_ptr;
|
||||
typedef typename index_type::bucket_type bucket_type;
|
||||
typedef typename index_type::bucket_traits bucket_traits;
|
||||
typedef typename index_type::size_type size_type;
|
||||
|
||||
/// @cond
|
||||
private:
|
||||
typedef typename index_aux::
|
||||
segment_manager_base segment_manager_base;
|
||||
|
||||
enum { InitBufferSize = 64};
|
||||
|
||||
static bucket_ptr create_buckets(allocator_type &alloc, size_type num)
|
||||
{
|
||||
num = index_type::suggested_upper_bucket_count(num);
|
||||
bucket_ptr buckets = alloc.allocate(num);
|
||||
bucket_ptr buckets_init = buckets;
|
||||
for(size_type i = 0; i < num; ++i){
|
||||
new(get_pointer(buckets_init++))bucket_type();
|
||||
}
|
||||
return buckets;
|
||||
}
|
||||
|
||||
static size_type shrink_buckets
|
||||
( bucket_ptr buckets, size_type old_size
|
||||
, allocator_type &alloc, size_type new_size)
|
||||
{
|
||||
if(old_size <= new_size )
|
||||
return old_size;
|
||||
size_type received_size;
|
||||
if(!alloc.allocation_command
|
||||
(boost::interprocess::try_shrink_in_place | boost::interprocess::nothrow_allocation, old_size, new_size, received_size, buckets).first){
|
||||
return old_size;
|
||||
}
|
||||
|
||||
for( bucket_type *p = ipcdetail::get_pointer(buckets) + received_size
|
||||
, *pend = ipcdetail::get_pointer(buckets) + old_size
|
||||
; p != pend
|
||||
; ++p){
|
||||
p->~bucket_type();
|
||||
}
|
||||
|
||||
bucket_ptr shunk_p = alloc.allocation_command
|
||||
(boost::interprocess::shrink_in_place | boost::interprocess::nothrow_allocation, received_size, received_size, received_size, buckets).first;
|
||||
BOOST_ASSERT(buckets == shunk_p);
|
||||
|
||||
bucket_ptr buckets_init = buckets + received_size;
|
||||
for(size_type i = 0; i < (old_size - received_size); ++i){
|
||||
get_pointer(buckets_init++)->~bucket_type();
|
||||
}
|
||||
return received_size;
|
||||
}
|
||||
|
||||
static bucket_ptr expand_or_create_buckets
|
||||
( bucket_ptr old_buckets, const size_type old_num
|
||||
, allocator_type &alloc, const size_type new_num)
|
||||
{
|
||||
size_type received_size;
|
||||
std::pair<bucket_ptr, bool> ret =
|
||||
alloc.allocation_command
|
||||
(boost::interprocess::expand_fwd | boost::interprocess::allocate_new, new_num, new_num, received_size, old_buckets);
|
||||
if(ret.first == old_buckets){
|
||||
bucket_ptr buckets_init = old_buckets + old_num;
|
||||
for(size_type i = 0; i < (new_num - old_num); ++i){
|
||||
new(get_pointer(buckets_init++))bucket_type();
|
||||
}
|
||||
}
|
||||
else{
|
||||
bucket_ptr buckets_init = ret.first;
|
||||
for(size_type i = 0; i < new_num; ++i){
|
||||
new(get_pointer(buckets_init++))bucket_type();
|
||||
}
|
||||
}
|
||||
|
||||
return ret.first;
|
||||
}
|
||||
|
||||
static void destroy_buckets
|
||||
(allocator_type &alloc, bucket_ptr buckets, size_type num)
|
||||
{
|
||||
bucket_ptr buckets_destroy = buckets;
|
||||
for(size_type i = 0; i < num; ++i){
|
||||
get_pointer(buckets_destroy++)->~bucket_type();
|
||||
}
|
||||
alloc.deallocate(buckets, num);
|
||||
}
|
||||
|
||||
iunordered_set_index<MapConfig>* get_this_pointer()
|
||||
{ return this; }
|
||||
|
||||
/// @endcond
|
||||
|
||||
public:
|
||||
//!Constructor. Takes a pointer to the
|
||||
//!segment manager. Can throw
|
||||
iunordered_set_index(segment_manager_base *mngr)
|
||||
: allocator_holder(mngr)
|
||||
, index_type(bucket_traits(&get_this_pointer()->init_bucket, 1))
|
||||
{}
|
||||
|
||||
~iunordered_set_index()
|
||||
{
|
||||
index_type::clear();
|
||||
if(index_type::bucket_pointer() != bucket_ptr(&this->init_bucket)){
|
||||
destroy_buckets(this->alloc, index_type::bucket_pointer(), index_type::bucket_count());
|
||||
}
|
||||
}
|
||||
|
||||
//!This reserves memory to optimize the insertion of n
|
||||
//!elements in the index
|
||||
void reserve(size_type new_n)
|
||||
{
|
||||
//Let's maintain a 1.0f load factor
|
||||
size_type old_n = this->bucket_count();
|
||||
if(new_n <= old_n)
|
||||
return;
|
||||
bucket_ptr old_p = this->bucket_pointer();
|
||||
new_n = index_type::suggested_upper_bucket_count(new_n);
|
||||
bucket_ptr new_p;
|
||||
//This can throw
|
||||
try{
|
||||
if(old_p != bucket_ptr(&this->init_bucket))
|
||||
new_p = expand_or_create_buckets(old_p, old_n, this->alloc, new_n);
|
||||
else
|
||||
new_p = create_buckets(this->alloc, new_n);
|
||||
}
|
||||
catch(...){
|
||||
return;
|
||||
}
|
||||
//Rehashing does not throw, since neither the hash nor the
|
||||
//comparison function can throw
|
||||
this->rehash(bucket_traits(new_p, new_n));
|
||||
if(new_p != old_p && old_p != bucket_ptr(&this->init_bucket)){
|
||||
destroy_buckets(this->alloc, old_p, old_n);
|
||||
}
|
||||
}
|
||||
|
||||
//!This tries to free unused memory
|
||||
//!previously allocated.
|
||||
void shrink_to_fit()
|
||||
{
|
||||
size_type cur_size = this->size();
|
||||
size_type cur_count = this->bucket_count();
|
||||
bucket_ptr old_p = this->bucket_pointer();
|
||||
|
||||
if(!this->size() && old_p != bucket_ptr(&this->init_bucket)){
|
||||
this->rehash(bucket_traits(bucket_ptr(&this->init_bucket), 1));
|
||||
destroy_buckets(this->alloc, old_p, cur_count);
|
||||
}
|
||||
else{
|
||||
size_type sug_count = 0; //gcc warning
|
||||
sug_count = index_type::suggested_upper_bucket_count(cur_size);
|
||||
|
||||
if(sug_count >= cur_count)
|
||||
return;
|
||||
|
||||
try{
|
||||
shrink_buckets(old_p, cur_count, this->alloc, sug_count);
|
||||
}
|
||||
catch(...){
|
||||
return;
|
||||
}
|
||||
|
||||
//Rehashing does not throw, since neither the hash nor the
|
||||
//comparison function can throw
|
||||
this->rehash(bucket_traits(old_p, sug_count));
|
||||
}
|
||||
}
|
||||
|
||||
iterator find(const intrusive_compare_key_type &key)
|
||||
{ return index_type::find(key, hash_function(), equal_function()); }
|
||||
|
||||
const_iterator find(const intrusive_compare_key_type &key) const
|
||||
{ return index_type::find(key, hash_function(), equal_function()); }
|
||||
|
||||
std::pair<iterator, bool>insert_check
|
||||
(const intrusive_compare_key_type &key, insert_commit_data &commit_data)
|
||||
{ return index_type::insert_check(key, hash_function(), equal_function(), commit_data); }
|
||||
|
||||
iterator insert_commit(value_type &val, insert_commit_data &commit_data)
|
||||
{
|
||||
iterator it = index_type::insert_commit(val, commit_data);
|
||||
size_type cur_size = this->size();
|
||||
if(cur_size > this->bucket_count()){
|
||||
try{
|
||||
this->reserve(cur_size);
|
||||
}
|
||||
catch(...){
|
||||
//Strong guarantee: if something goes wrong
|
||||
//we should remove the insertion.
|
||||
//
|
||||
//We can use the iterator because the hash function
|
||||
//can't throw and this means that "reserve" will
|
||||
//throw only because of the memory allocation:
|
||||
//the iterator has not been invalidated.
|
||||
index_type::erase(it);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
return it;
|
||||
}
|
||||
};
|
||||
|
||||
/// @cond
|
||||
|
||||
//!Trait class to detect if an index is an intrusive
|
||||
//!index
|
||||
template<class MapConfig>
|
||||
struct is_intrusive_index
|
||||
<boost::interprocess::iunordered_set_index<MapConfig> >
|
||||
{
|
||||
enum{ value = true };
|
||||
};
|
||||
/// @endcond
|
||||
|
||||
}} //namespace boost { namespace interprocess {
|
||||
|
||||
#include <boost/interprocess/detail/config_end.hpp>
|
||||
|
||||
#endif //#ifndef BOOST_INTERPROCESS_IUNORDERED_SET_INDEX_HPP
|
||||
100
test/external/boost/interprocess/indexes/map_index.hpp
vendored
Normal file
100
test/external/boost/interprocess/indexes/map_index.hpp
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2005-2009. Distributed under the Boost
|
||||
// Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// See http://www.boost.org/libs/interprocess for documentation.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef BOOST_INTERPROCESS_MAP_INDEX_HPP
|
||||
#define BOOST_INTERPROCESS_MAP_INDEX_HPP
|
||||
|
||||
#include <boost/interprocess/detail/config_begin.hpp>
|
||||
#include <boost/interprocess/detail/workaround.hpp>
|
||||
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
#include <boost/interprocess/containers/map.hpp>
|
||||
#include <boost/interprocess/allocators/private_adaptive_pool.hpp>
|
||||
|
||||
//!\file
|
||||
//!Describes index adaptor of boost::map container, to use it
|
||||
//!as name/shared memory index
|
||||
|
||||
namespace boost {
|
||||
namespace interprocess {
|
||||
namespace ipcdetail{
|
||||
|
||||
//!Helper class to define typedefs from IndexTraits
|
||||
template <class MapConfig>
|
||||
struct map_index_aux
|
||||
{
|
||||
typedef typename MapConfig::key_type key_type;
|
||||
typedef typename MapConfig::mapped_type mapped_type;
|
||||
typedef std::less<key_type> key_less;
|
||||
typedef std::pair<const key_type, mapped_type> value_type;
|
||||
|
||||
typedef private_adaptive_pool
|
||||
<value_type,
|
||||
typename MapConfig::
|
||||
segment_manager_base> allocator_type;
|
||||
|
||||
typedef boost::interprocess::map
|
||||
<key_type, mapped_type,
|
||||
key_less, allocator_type> index_t;
|
||||
};
|
||||
|
||||
} //namespace ipcdetail {
|
||||
|
||||
//!Index type based in boost::interprocess::map. Just derives from boost::interprocess::map
|
||||
//!and defines the interface needed by managed memory segments
|
||||
template <class MapConfig>
|
||||
class map_index
|
||||
//Derive class from map specialization
|
||||
: public ipcdetail::map_index_aux<MapConfig>::index_t
|
||||
{
|
||||
/// @cond
|
||||
typedef ipcdetail::map_index_aux<MapConfig> index_aux;
|
||||
typedef typename index_aux::index_t base_type;
|
||||
typedef typename MapConfig::
|
||||
segment_manager_base segment_manager_base;
|
||||
/// @endcond
|
||||
|
||||
public:
|
||||
//!Constructor. Takes a pointer to the
|
||||
//!segment manager. Can throw
|
||||
map_index(segment_manager_base *segment_mngr)
|
||||
: base_type(typename index_aux::key_less(),
|
||||
segment_mngr){}
|
||||
|
||||
//!This reserves memory to optimize the insertion of n
|
||||
//!elements in the index
|
||||
void reserve(typename segment_manager_base::size_type)
|
||||
{ /*Does nothing, map has not reserve or rehash*/ }
|
||||
|
||||
//!This tries to free previously allocate
|
||||
//!unused memory.
|
||||
void shrink_to_fit()
|
||||
{ base_type::get_stored_allocator().deallocate_free_blocks(); }
|
||||
};
|
||||
|
||||
/// @cond
|
||||
|
||||
//!Trait class to detect if an index is a node
|
||||
//!index. This allows more efficient operations
|
||||
//!when deallocating named objects.
|
||||
template<class MapConfig>
|
||||
struct is_node_index
|
||||
<boost::interprocess::map_index<MapConfig> >
|
||||
{
|
||||
enum { value = true };
|
||||
};
|
||||
/// @endcond
|
||||
|
||||
}} //namespace boost { namespace interprocess {
|
||||
|
||||
#include <boost/interprocess/detail/config_end.hpp>
|
||||
|
||||
#endif //#ifndef BOOST_INTERPROCESS_MAP_INDEX_HPP
|
||||
68
test/external/boost/interprocess/indexes/null_index.hpp
vendored
Normal file
68
test/external/boost/interprocess/indexes/null_index.hpp
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2005-2009. Distributed under the Boost
|
||||
// Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// See http://www.boost.org/libs/interprocess for documentation.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
#ifndef BOOST_INTERPROCESS_NULL_INDEX_HPP
|
||||
#define BOOST_INTERPROCESS_NULL_INDEX_HPP
|
||||
|
||||
#include <boost/interprocess/detail/config_begin.hpp>
|
||||
#include <boost/interprocess/detail/workaround.hpp>
|
||||
|
||||
#include <boost/interprocess/offset_ptr.hpp>
|
||||
|
||||
//!\file
|
||||
//!Describes a null index adaptor, so that if we don't want to construct
|
||||
//!named objects, we can use this null index type to save resources.
|
||||
|
||||
namespace boost {
|
||||
namespace interprocess {
|
||||
|
||||
//!Null index type
|
||||
//!used to save compilation time when
|
||||
//!named indexes are not needed.
|
||||
template <class MapConfig>
|
||||
class null_index
|
||||
{
|
||||
/// @cond
|
||||
typedef typename MapConfig::
|
||||
segment_manager_base segment_manager_base;
|
||||
/// @endcond
|
||||
|
||||
public:
|
||||
typedef void * iterator;
|
||||
typedef const void * const_iterator;
|
||||
|
||||
//!begin() is equal
|
||||
//!to end()
|
||||
const_iterator begin() const
|
||||
{ return const_iterator(0); }
|
||||
|
||||
//!begin() is equal
|
||||
//!to end()
|
||||
iterator begin()
|
||||
{ return iterator(0); }
|
||||
|
||||
//!begin() is equal
|
||||
//!to end()
|
||||
const_iterator end() const
|
||||
{ return const_iterator(0); }
|
||||
|
||||
//!begin() is equal
|
||||
//!to end()
|
||||
iterator end()
|
||||
{ return iterator(0); }
|
||||
|
||||
//!Empty constructor
|
||||
null_index(segment_manager_base *){}
|
||||
};
|
||||
|
||||
}} //namespace boost { namespace interprocess {
|
||||
|
||||
#include <boost/interprocess/detail/config_end.hpp>
|
||||
|
||||
#endif //#ifndef BOOST_INTERPROCESS_NULL_INDEX_HPP
|
||||
113
test/external/boost/interprocess/indexes/unordered_map_index.hpp
vendored
Normal file
113
test/external/boost/interprocess/indexes/unordered_map_index.hpp
vendored
Normal file
@@ -0,0 +1,113 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2005-2009. Distributed under the Boost
|
||||
// Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// See http://www.boost.org/libs/interprocess for documentation.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef BOOST_INTERPROCESS_UNORDERED_MAP_INDEX_HPP
|
||||
#define BOOST_INTERPROCESS_UNORDERED_MAP_INDEX_HPP
|
||||
|
||||
#include <boost/interprocess/detail/config_begin.hpp>
|
||||
#include <boost/interprocess/detail/workaround.hpp>
|
||||
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
#include <boost/unordered_map.hpp>
|
||||
#include <boost/interprocess/detail/utilities.hpp>
|
||||
#include <boost/interprocess/allocators/private_adaptive_pool.hpp>
|
||||
|
||||
//!\file
|
||||
//!Describes index adaptor of boost::unordered_map container, to use it
|
||||
//!as name/shared memory index
|
||||
|
||||
namespace boost {
|
||||
namespace interprocess {
|
||||
|
||||
///@cond
|
||||
|
||||
//!Helper class to define typedefs from
|
||||
//!IndexTraits
|
||||
template <class MapConfig>
|
||||
struct unordered_map_index_aux
|
||||
{
|
||||
typedef typename MapConfig::key_type key_type;
|
||||
typedef typename MapConfig::mapped_type mapped_type;
|
||||
typedef std::equal_to<key_type> key_equal;
|
||||
typedef std::pair<const key_type, mapped_type> value_type;
|
||||
typedef private_adaptive_pool
|
||||
<value_type,
|
||||
typename MapConfig::
|
||||
segment_manager_base> allocator_type;
|
||||
struct hasher
|
||||
: std::unary_function<key_type, std::size_t>
|
||||
{
|
||||
std::size_t operator()(const key_type &val) const
|
||||
{
|
||||
typedef typename key_type::char_type char_type;
|
||||
const char_type *beg = ipcdetail::get_pointer(val.mp_str),
|
||||
*end = beg + val.m_len;
|
||||
return boost::hash_range(beg, end);
|
||||
}
|
||||
};
|
||||
typedef unordered_map<key_type, mapped_type, hasher,
|
||||
key_equal, allocator_type> index_t;
|
||||
};
|
||||
|
||||
///@endcond
|
||||
|
||||
//!Index type based in unordered_map. Just derives from unordered_map and
|
||||
//!defines the interface needed by managed memory segments
|
||||
template <class MapConfig>
|
||||
class unordered_map_index
|
||||
//Derive class from unordered_map specialization
|
||||
: public unordered_map_index_aux<MapConfig>::index_t
|
||||
{
|
||||
/// @cond
|
||||
typedef unordered_map_index_aux<MapConfig> index_aux;
|
||||
typedef typename index_aux::index_t base_type;
|
||||
typedef typename
|
||||
MapConfig::segment_manager_base segment_manager_base;
|
||||
/// @endcond
|
||||
|
||||
public:
|
||||
//!Constructor. Takes a pointer to the
|
||||
//!segment manager. Can throw
|
||||
unordered_map_index(segment_manager_base *segment_mngr)
|
||||
: base_type(0,
|
||||
typename index_aux::hasher(),
|
||||
typename index_aux::key_equal(),
|
||||
segment_mngr){}
|
||||
|
||||
//!This reserves memory to optimize the insertion of n
|
||||
//!elements in the index
|
||||
void reserve(typename segment_manager_base::size_type n)
|
||||
{ base_type::rehash(n); }
|
||||
|
||||
//!This tries to free previously allocate
|
||||
//!unused memory.
|
||||
void shrink_to_fit()
|
||||
{ base_type::rehash(base_type::size()); }
|
||||
};
|
||||
|
||||
/// @cond
|
||||
|
||||
//!Trait class to detect if an index is a node
|
||||
//!index. This allows more efficient operations
|
||||
//!when deallocating named objects.
|
||||
template<class MapConfig>
|
||||
struct is_node_index
|
||||
<boost::interprocess::unordered_map_index<MapConfig> >
|
||||
{
|
||||
enum { value = true };
|
||||
};
|
||||
/// @endcond
|
||||
|
||||
}} //namespace boost { namespace interprocess {
|
||||
|
||||
#include <boost/interprocess/detail/config_end.hpp>
|
||||
|
||||
#endif //#ifndef BOOST_INTERPROCESS_UNORDERED_MAP_INDEX_HPP
|
||||
Reference in New Issue
Block a user