1 /* Copyright 2006-2009 Joaquin M Lopez Munoz.
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)
6 * See http://www.boost.org/libs/flyweight for library home page.
9 #ifndef BOOST_FLYWEIGHT_HASHED_FACTORY_HPP
10 #define BOOST_FLYWEIGHT_HASHED_FACTORY_HPP
12 #if defined(_MSC_VER)&&(_MSC_VER>=1200)
16 #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
17 #include <boost/flyweight/factory_tag.hpp>
18 #include <boost/flyweight/hashed_factory_fwd.hpp>
19 #include <boost/multi_index_container.hpp>
20 #include <boost/multi_index/identity.hpp>
21 #include <boost/multi_index/hashed_index.hpp>
22 #include <boost/mpl/aux_/lambda_support.hpp>
23 #include <boost/mpl/if.hpp>
25 /* Flyweight factory based on a hashed container implemented
26 * with Boost.MultiIndex.
34 typename Entry
,typename Key
,
35 typename Hash
,typename Pred
,typename Allocator
37 class hashed_factory_class
:public factory_marker
41 multi_index::hashed_unique
<
42 multi_index::identity
<Entry
>,
43 typename
boost::mpl::if_
<
48 typename
boost::mpl::if_
<
57 typedef multi_index::multi_index_container
<
60 typename
boost::mpl::if_
<
61 mpl::is_na
<Allocator
>,
62 std::allocator
<Entry
>,
68 typedef const Entry
* handle_type
;
70 handle_type
insert(const Entry
& x
)
72 return &*cont
.insert(x
).first
;
75 void erase(handle_type h
)
77 cont
.erase(cont
.iterator_to(*h
));
80 static const Entry
& entry(handle_type h
){return *h
;}
86 typedef hashed_factory_class type
;
87 BOOST_MPL_AUX_LAMBDA_SUPPORT(
88 5,hashed_factory_class
,(Entry
,Key
,Hash
,Pred
,Allocator
))
91 /* hashed_factory_class specifier */
94 typename Hash
,typename Pred
,typename Allocator
95 BOOST_FLYWEIGHT_NOT_A_PLACEHOLDER_EXPRESSION_DEF
97 struct hashed_factory
:factory_marker
99 template<typename Entry
,typename Key
>
102 hashed_factory_class
<
103 boost::mpl::_1
,boost::mpl::_2
,Hash
,Pred
,Allocator
110 } /* namespace flyweights */
112 } /* namespace boost */