|
Boost-Commit : |
From: fmhess_at_[hidden]
Date: 2008-03-11 11:12:20
Author: fmhess
Date: 2008-03-11 11:12:20 EDT (Tue, 11 Mar 2008)
New Revision: 43563
URL: http://svn.boost.org/trac/boost/changeset/43563
Log:
Added proper copy constructor for grouped_list, to prevent invalid
list iterators in map.
Text files modified:
sandbox/thread_safe_signals/boost/thread_safe_signals/detail/slot_groups.hpp | 40 +++++++++++++++++++++++++++++++++++++++-
1 files changed, 39 insertions(+), 1 deletions(-)
Modified: sandbox/thread_safe_signals/boost/thread_safe_signals/detail/slot_groups.hpp
==============================================================================
--- sandbox/thread_safe_signals/boost/thread_safe_signals/detail/slot_groups.hpp (original)
+++ sandbox/thread_safe_signals/boost/thread_safe_signals/detail/slot_groups.hpp 2008-03-11 11:12:20 EDT (Tue, 11 Mar 2008)
@@ -53,14 +53,37 @@
typedef std::list<ValueType> list_type;
typedef std::map<typename group_key<Group>::type, typename list_type::iterator> map_type;
typedef typename map_type::iterator map_iterator;
+ typedef typename map_type::const_iterator const_map_iterator;
public:
typedef typename list_type::iterator iterator;
+ typedef typename list_type::const_iterator const_iterator;
typedef typename group_key<Group>::type group_key_type;
typedef group_key_less<Group, GroupCompare> group_key_compare_type;
grouped_list(const group_key_compare_type &group_key_compare):
_group_key_compare(group_key_compare)
{}
+ grouped_list(const grouped_list &other): _list(other._list),
+ _group_key_compare(other._group_key_compare)
+ {
+ typename map_type::const_iterator other_map_it;
+ typename list_type::iterator this_list_it = _list.begin();
+ for(other_map_it = other._group_map.begin();
+ other_map_it != other._group_map.end();
+ ++other_map_it)
+ {
+ typename list_type::const_iterator other_list_it = other.get_list_iterator(other_map_it);
+ _group_map.insert(typename map_type::value_type(other_map_it->first, this_list_it));
+ typename map_type::const_iterator other_next_map_it = other_map_it;
+ ++other_next_map_it;
+ typename list_type::const_iterator other_next_list_it = other.get_list_iterator(other_next_map_it);
+ while(other_list_it != other_next_list_it)
+ {
+ ++other_list_it;
+ ++this_list_it;
+ }
+ }
+ }
iterator begin()
{
return _list.begin();
@@ -141,6 +164,9 @@
_group_map.clear();
}
private:
+ /* Suppress default assignment operator, since it has the wrong semantics. */
+ grouped_list& operator=(const grouped_list &other);
+
bool weakly_equivalent(const group_key_type &arg1, const group_key_type &arg2)
{
if(_group_key_compare(arg1, arg2)) return false;
@@ -165,7 +191,7 @@
_group_map.insert(typename map_type::value_type(key, new_it));
}
}
- iterator get_list_iterator(const map_iterator &map_it)
+ iterator get_list_iterator(const const_map_iterator &map_it)
{
iterator list_it;
if(map_it == _group_map.end())
@@ -177,6 +203,18 @@
}
return list_it;
}
+ const_iterator get_list_iterator(const const_map_iterator &map_it) const
+ {
+ const_iterator list_it;
+ if(map_it == _group_map.end())
+ {
+ list_it = _list.end();
+ }else
+ {
+ list_it = map_it->second;
+ }
+ return list_it;
+ }
list_type _list;
// holds iterators to first list item in each group
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk