File indexing completed on 2025-01-18 09:30:52
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef BOOST_FLYWEIGHT_DETAIL_SERIALIZATION_HELPER_HPP
0010 #define BOOST_FLYWEIGHT_DETAIL_SERIALIZATION_HELPER_HPP
0011
0012 #if defined(_MSC_VER)&&(_MSC_VER>=1200)
0013 #pragma once
0014 #endif
0015
0016 #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
0017 #include <boost/multi_index_container.hpp>
0018 #include <boost/multi_index/hashed_index.hpp>
0019 #include <boost/multi_index/random_access_index.hpp>
0020 #include <boost/noncopyable.hpp>
0021 #include <vector>
0022
0023 namespace boost{
0024
0025 namespace flyweights{
0026
0027 namespace detail{
0028
0029
0030
0031
0032
0033
0034
0035
0036 template<typename Flyweight>
0037 struct flyweight_value_address
0038 {
0039 typedef const typename Flyweight::value_type* result_type;
0040
0041 result_type operator()(const Flyweight& x)const{return &x.get();}
0042 };
0043
0044 template<typename Flyweight>
0045 class save_helper:private noncopyable
0046 {
0047 typedef multi_index::multi_index_container<
0048 Flyweight,
0049 multi_index::indexed_by<
0050 multi_index::random_access<>,
0051 multi_index::hashed_unique<flyweight_value_address<Flyweight> >
0052 >
0053 > table;
0054
0055 public:
0056
0057 typedef typename table::size_type size_type;
0058
0059 size_type size()const{return t.size();}
0060
0061 size_type find(const Flyweight& x)const
0062 {
0063 return multi_index::project<0>(t,multi_index::get<1>(t).find(&x.get()))
0064 -t.begin();
0065 }
0066
0067 void push_back(const Flyweight& x){t.push_back(x);}
0068
0069 private:
0070 table t;
0071 };
0072
0073 template<typename Flyweight>
0074 class load_helper:private noncopyable
0075 {
0076 typedef std::vector<Flyweight> table;
0077
0078 public:
0079
0080 typedef typename table::size_type size_type;
0081
0082 size_type size()const{return t.size();}
0083
0084 Flyweight operator[](size_type n)const{return t[n];}
0085
0086 void push_back(const Flyweight& x){t.push_back(x);}
0087
0088 private:
0089 table t;
0090 };
0091
0092 }
0093
0094 }
0095
0096 }
0097
0098 #endif