File indexing completed on 2025-01-18 09:42:07
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef BOOST_MULTI_INDEX_DETAIL_INDEX_SAVER_HPP
0010 #define BOOST_MULTI_INDEX_DETAIL_INDEX_SAVER_HPP
0011
0012 #if defined(_MSC_VER)
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/detail/index_matcher.hpp>
0018 #include <boost/core/noncopyable.hpp>
0019 #include <boost/core/serialization.hpp>
0020 #include <cstddef>
0021
0022 namespace boost{
0023
0024 namespace multi_index{
0025
0026 namespace detail{
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037 template<typename Node,typename Allocator>
0038 class index_saver:private noncopyable
0039 {
0040 public:
0041 index_saver(const Allocator& al,std::size_t size):alg(al,size){}
0042
0043 template<class Archive>
0044 void add(Node* node,Archive& ar,const unsigned int)
0045 {
0046 ar<<core::make_nvp("position",*node);
0047 alg.add(node);
0048 }
0049
0050 template<class Archive>
0051 void add_track(Node* node,Archive& ar,const unsigned int)
0052 {
0053 ar<<core::make_nvp("position",*node);
0054 }
0055
0056 template<typename IndexIterator,class Archive>
0057 void save(
0058 IndexIterator first,IndexIterator last,Archive& ar,
0059 const unsigned int)const
0060 {
0061
0062
0063 alg.execute(first,last);
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095 std::size_t last_saved=3;
0096 for(IndexIterator it=first,prev=first;it!=last;prev=it++,++last_saved){
0097 if(!alg.is_ordered(get_node(it))){
0098 if(last_saved>1)save_node(get_node(prev),ar);
0099 save_node(get_node(it),ar);
0100 last_saved=0;
0101 }
0102 else if(last_saved==2)save_node(null_node(),ar);
0103 }
0104 if(last_saved<=2)save_node(null_node(),ar);
0105
0106
0107
0108 save_node(null_node(),ar);
0109 }
0110
0111 private:
0112 template<typename IndexIterator>
0113 static Node* get_node(IndexIterator it)
0114 {
0115 return it.get_node();
0116 }
0117
0118 static Node* null_node(){return 0;}
0119
0120 template<typename Archive>
0121 static void save_node(Node* node,Archive& ar)
0122 {
0123 ar<<core::make_nvp("pointer",node);
0124 }
0125
0126 index_matcher::algorithm<Node,Allocator> alg;
0127 };
0128
0129 }
0130
0131 }
0132
0133 }
0134
0135 #endif