9 #include "pol_global_config.h" 12 #pragma warning( disable : 4503 ) // decorated name length exceeded 15 #ifdef DEBUG_FLYWEIGHT 16 #include <boost/flyweight/factory_tag.hpp> 17 #include <boost/flyweight/hashed_factory_fwd.hpp> 18 #include <boost/foreach.hpp> 19 #include <boost/mpl/aux_/lambda_support.hpp> 20 #include <boost/mpl/if.hpp> 21 #include <boost/multi_index/hashed_index.hpp> 22 #include <boost/multi_index/identity.hpp> 23 #include <boost/multi_index_container.hpp> 29 #include <boost/flyweight.hpp> 35 #ifdef DEBUG_FLYWEIGHT 39 typedef std::size_t size_type;
40 virtual ~bucket_query(){};
41 virtual size_type bucket_count()
const = 0;
42 virtual size_type max_bucket_count()
const = 0;
43 virtual size_type bucket_size( size_type n )
const = 0;
44 virtual size_type estimateSize()
const = 0;
47 extern std::vector<bucket_query*> debug_flyweight_queries;
49 template <
typename Entry,
typename Key,
typename Hash = boost::mpl::na,
50 typename Pred = boost::mpl::na,
typename Allocator = boost::mpl::na>
51 class accessible_hashed_factory_class :
public boost::flyweights::factory_marker,
55 : boost::mpl::vector1<boost::multi_index::hashed_unique<
56 boost::multi_index::identity<Entry>,
57 typename boost::mpl::if_<boost::mpl::is_na<Hash>, boost::hash<Key>, Hash>::type,
58 typename boost::mpl::if_<boost::mpl::is_na<Pred>, std::equal_to<Key>, Pred>::type>>
62 typedef boost::multi_index::multi_index_container<
64 typename boost::mpl::if_<boost::mpl::is_na<Allocator>, std::allocator<Entry>,
69 typedef const Entry* handle_type;
71 accessible_hashed_factory_class() { debug_flyweight_queries.push_back(
this ); }
72 handle_type insert(
const Entry& x ) {
return &*cont.insert( x ).first; }
73 void erase( handle_type h ) { cont.erase( cont.iterator_to( *h ) ); }
74 static const Entry& entry( handle_type h ) {
return *h; }
75 typedef std::size_t size_type;
77 virtual size_type bucket_count() const
POL_OVERRIDE {
return cont.bucket_count(); }
78 virtual size_type max_bucket_count() const
POL_OVERRIDE {
return cont.max_bucket_count(); }
79 virtual size_type bucket_size( size_type n )
const POL_OVERRIDE {
return cont.bucket_size( n ); }
83 BOOST_FOREACH (
const Entry& e, cont )
85 size += (int)( 4.5 *
sizeof(
long ) );
86 size += ( (std::string)e ).capacity();
95 typedef accessible_hashed_factory_class type;
96 BOOST_MPL_AUX_LAMBDA_SUPPORT( 5, accessible_hashed_factory_class,
97 ( Entry, Key, Hash, Pred, Allocator ) )
100 template <
typename Hash = boost::mpl::na,
typename Pred = boost::mpl::na,
101 typename Allocator = boost::mpl::na BOOST_FLYWEIGHT_NOT_A_PLACEHOLDER_EXPRESSION>
102 struct accessible_hashed_factory : boost::flyweights::factory_marker
104 template <
typename Entry,
typename Key>
106 : boost::mpl::apply2<
107 accessible_hashed_factory_class<boost::mpl::_1, boost::mpl::_2, Hash, Pred, Allocator>,
113 #define FLYWEIGHT_HASH_FACTORY boost_utils::accessible_hashed_factory<> 115 #define FLYWEIGHT_HASH_FACTORY boost::flyweights::hashed_factory<> 123 typedef boost::flyweight<std::string, boost::flyweights::tag<cprop_name_tag>,
129 typedef boost::flyweight<std::string, boost::flyweights::tag<cprop_value_tag>,
140 typedef boost::flyweight<std::string, boost::flyweights::tag<object_name_tag>,
146 typedef boost::flyweight<std::string, boost::flyweights::tag<script_name_tag>,
152 typedef boost::flyweight<std::string, boost::flyweights::tag<npctemplate_name_tag>,
158 typedef boost::flyweight<std::string, boost::flyweights::tag<function_name_tag>,
boost::flyweight< std::string, boost::flyweights::tag< cfg_key_tag >, FLYWEIGHT_HASH_FACTORY > cfg_key_flystring
cprop_value_flystring::initializer fwInit_cprop_value
script_name_flystring::initializer fwInit_script_name
npctemplate_name_flystring::initializer fwInit_npctemplate_name
boost::flyweight< std::string, boost::flyweights::tag< cprop_name_tag >, FLYWEIGHT_HASH_FACTORY > cprop_name_flystring
cfg_key_flystring::initializer fwInit_cfg_key
function_name_flystring::initializer fwInit_func_name
cprop_name_flystring::initializer fwInit_cprop_name
boost::flyweight< std::string, boost::flyweights::tag< script_name_tag >, FLYWEIGHT_HASH_FACTORY > script_name_flystring
object_name_flystring::initializer fwInit_obj_name
#define FLYWEIGHT_HASH_FACTORY
boost::flyweight< std::string, boost::flyweights::tag< cprop_value_tag >, FLYWEIGHT_HASH_FACTORY > cprop_value_flystring
boost::flyweight< std::string, boost::flyweights::tag< object_name_tag >, FLYWEIGHT_HASH_FACTORY > object_name_flystring
boost::flyweight< std::string, boost::flyweights::tag< npctemplate_name_tag >, FLYWEIGHT_HASH_FACTORY > npctemplate_name_flystring
boost::flyweight< std::string, boost::flyweights::tag< function_name_tag >, FLYWEIGHT_HASH_FACTORY > function_name_flystring