# # add_file "safe_map.hh" # # patch "Makefile.am" # from [d57b2f802841e105a2b45bb847aa17dc696b07aa] # to [76d958030020f74a8337d2da80762316cdac363e] # # patch "cset.cc" # from [479497215b8ba2394a8487a71a2544a583d6cc40] # to [ba9337419d0cc5649c35b28310a926411205a764] # # patch "cset.hh" # from [c76626e6e18c4b9651821cb9f636c1e36c05622b] # to [37e25c0a3768be89b4a6208db27ebdfc5cf1968f] # # patch "revision.cc" # from [6ccee6812be509e8b56f84a7db4b66d7296fa129] # to [e0469a524455b86a3867af582fd4e7149553374c] # # patch "roster.cc" # from [7be377698e6a799056bc4b03eef616bd941b0538] # to [a253a4d916c62272b592bfd0d008abd30dd28f7b] # # patch "roster_merge.cc" # from [ba7fc8b18d1a445624cade8edb1ddf98f5228e1e] # to [053900b693576f72fa3b6f08697a4fcdae13399b] # # patch "safe_map.hh" # from [] # to [26030e4c94caf4c3d6672dca244991823c2b4ff9] # ======================================================================== --- Makefile.am d57b2f802841e105a2b45bb847aa17dc696b07aa +++ Makefile.am 76d958030020f74a8337d2da80762316cdac363e @@ -53,7 +53,7 @@ netio.hh smap.hh gettext.h \ package_revision.c package_revision.h \ package_full_revision.c package_full_revision.h options.hh \ - i18n.h hash_map.hh parallel_iter.hh + i18n.h hash_map.hh parallel_iter.hh safe_map.hh NETXX_SOURCES = \ netxx/accept.cxx netxx/accept.h netxx/address.cxx \ ======================================================================== --- cset.cc 479497215b8ba2394a8487a71a2544a583d6cc40 +++ cset.cc ba9337419d0cc5649c35b28310a926411205a764 @@ -1,17 +1,18 @@ // copyright (C) 2005 nathaniel smith // copyright (C) 2005 graydon hoare // all rights reserved. // licensed to the public under the terms of the GNU GPL (>= 2) // see the file COPYING for details +#include +#include +#include + #include "basic_io.hh" #include "cset.hh" #include "sanity.hh" +#include "safe_map.hh" -#include -#include -#include - using std::set; using std::map; using std::pair; ======================================================================== --- cset.hh c76626e6e18c4b9651821cb9f636c1e36c05622b +++ cset.hh 37e25c0a3768be89b4a6208db27ebdfc5cf1968f @@ -131,31 +131,6 @@ // Some helpers. -template -void -safe_erase(T & container, typename T::key_type const & key) -{ - I(container.erase(key)); -} - -template -typename T::iterator -safe_insert(T & container, typename T::value_type const & val) -{ - std::pair r = container.insert(val); - I(r.second); - return r.first; -} - -template -typename T::mapped_type const & -safe_get(T & container, typename T::key_type const & key) -{ - typename T::const_iterator i = container.find(key); - I(i != container.end()); - return i->second; -} - inline split_path internal_string_to_split_path(std::string const & str) { ======================================================================== --- revision.cc 6ccee6812be509e8b56f84a7db4b66d7296fa129 +++ revision.cc e0469a524455b86a3867af582fd4e7149553374c @@ -35,6 +35,7 @@ #include "transforms.hh" #include "ui.hh" #include "vocab.hh" +#include "safe_map.hh" void revision_set::check_sane() const @@ -711,9 +712,9 @@ void select_nodes_modified_by_rev(revision_id const & rid, revision_set const & rev, - std::set & nodes_changed, - std::set & nodes_born, - app_state & app) + std::set & nodes_changed, + std::set & nodes_born, + app_state & app) { roster_t new_roster; marking_map mm; ======================================================================== --- roster.cc 7be377698e6a799056bc4b03eef616bd941b0538 +++ roster.cc a253a4d916c62272b592bfd0d008abd30dd28f7b @@ -20,6 +20,7 @@ #include "vocab.hh" #include "transforms.hh" #include "parallel_iter.hh" +#include "safe_map.hh" #include @@ -1653,10 +1654,10 @@ void select_nodes_modified_by_cset(cset const & cs, - roster_t const & old_roster, - roster_t const & new_roster, - std::set & nodes_changed, - std::set & nodes_born) + roster_t const & old_roster, + roster_t const & new_roster, + std::set & nodes_changed, + std::set & nodes_born) { nodes_changed.clear(); nodes_born.clear(); ======================================================================== --- roster_merge.cc ba7fc8b18d1a445624cade8edb1ddf98f5228e1e +++ roster_merge.cc 053900b693576f72fa3b6f08697a4fcdae13399b @@ -8,6 +8,7 @@ #include "vocab.hh" #include "roster_merge.hh" #include "parallel_iter.hh" +#include "safe_map.hh" bool roster_merge_result::is_clean() ======================================================================== --- safe_map.hh +++ safe_map.hh 26030e4c94caf4c3d6672dca244991823c2b4ff9 @@ -0,0 +1,39 @@ +#ifndef __SAFE_MAP_HH__ +#define __SAFE_MAP_HH__ + +// copyright (C) 2005 nathaniel smith +// all rights reserved. +// licensed to the public under the terms of the GNU GPL (>= 2) +// see the file COPYING for details + +// some helpers to safely use maps + +// errors out if the key does not exist +template +void +safe_erase(T & container, typename T::key_type const & key) +{ + I(container.erase(key)); +} + +// errors out if the key already exists +template +typename T::iterator +safe_insert(T & container, typename T::value_type const & val) +{ + std::pair r = container.insert(val); + I(r.second); + return r.first; +} + +// errors out if the key does not exist +template +typename T::mapped_type const & +safe_get(T & container, typename T::key_type const & key) +{ + typename T::const_iterator i = container.find(key); + I(i != container.end()); + return i->second; +} + +#endif