X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2Fstlplus%2Fpersistence%2Fpersistent_map.tpp;fp=src%2Fstlplus%2Fpersistence%2Fpersistent_map.tpp;h=b1af42c268f4322c57079f00efb8898d7ad17bc0;hb=6b0a0d0efafe34d48ab344fca3b479553bd4e62c;hp=0000000000000000000000000000000000000000;hpb=85783316365181491a3e3c0c63659972477cebba;p=chaz%2Fyoink diff --git a/src/stlplus/persistence/persistent_map.tpp b/src/stlplus/persistence/persistent_map.tpp new file mode 100644 index 0000000..b1af42c --- /dev/null +++ b/src/stlplus/persistence/persistent_map.tpp @@ -0,0 +1,45 @@ +//////////////////////////////////////////////////////////////////////////////// + +// Author: Andy Rushton +// Copyright: (c) Southampton University 1999-2004 +// (c) Andy Rushton 2004-2009 +// License: BSD License, see ../docs/license.html + +//////////////////////////////////////////////////////////////////////////////// +#include "persistent_int.hpp" + +namespace stlplus +{ + + //////////////////////////////////////////////////////////////////////////////// + + template + void dump_map(dump_context& context, const std::map& data, DK key_fn, DT val_fn) + throw(persistent_dump_failed) + { + dump_unsigned(context,data.size()); + for (typename std::map::const_iterator i = data.begin(); i != data.end(); i++) + { + key_fn(context,i->first); + val_fn(context,i->second); + } + } + + template + void restore_map(restore_context& context, std::map& data, RK key_fn, RT val_fn) + throw(persistent_restore_failed) + { + data.clear(); + unsigned size = 0; + restore_unsigned(context,size); + for (unsigned j = 0; j < size; j++) + { + K key; + key_fn(context,key); + val_fn(context,data[key]); + } + } + + //////////////////////////////////////////////////////////////////////////////// + +} // end namespace stlplus