]> Dogcows Code - chaz/yoink/blob - src/stlplus/persistence/persistent_multiset.tpp
archiving support for releases
[chaz/yoink] / src / stlplus / persistence / persistent_multiset.tpp
1 ////////////////////////////////////////////////////////////////////////////////
2
3 // Author: Andy Rushton
4 // Copyright: (c) Southampton University 1999-2004
5 // (c) Andy Rushton 2004-2009
6 // License: BSD License, see ../docs/license.html
7
8 ////////////////////////////////////////////////////////////////////////////////
9 #include "persistent_int.hpp"
10
11 namespace stlplus
12 {
13
14 ////////////////////////////////////////////////////////////////////////////////
15
16 template<typename K, typename P, typename D>
17 void dump_multiset(dump_context& context, const std::multiset<K,P>& data, D dump_fn)
18 throw(persistent_dump_failed)
19 {
20 dump_unsigned(context,data.size());
21 for (typename std::multiset<K,P>::const_iterator i = data.begin(); i != data.end(); i++)
22 dump_fn(context,*i);
23 }
24
25 template<typename K, typename P, typename R>
26 void restore_multiset(restore_context& context, std::multiset<K,P>& data, R restore_fn)
27 throw(persistent_restore_failed)
28 {
29 data.clear();
30 unsigned size = 0;
31 restore_unsigned(context,size);
32 typename std::multiset<K,P>::iterator i = data.begin();
33 for (unsigned j = 0; j < size; j++)
34 {
35 K key;
36 restore_fn(context,key);
37 // inserting using an iterator is O(n) rather than O(n*log(n))
38 i = data.insert(i, key);
39 }
40 }
41
42 ////////////////////////////////////////////////////////////////////////////////
43
44 } // end namespace stlplus
This page took 0.031977 seconds and 4 git commands to generate.