diff --git a/libs/container/container.h b/libs/container/container.h index 9e8c03f5..ab04b609 100644 --- a/libs/container/container.h +++ b/libs/container/container.h @@ -74,20 +74,20 @@ private: struct Compare{ using is_transparent = void; - bool operator()( const iterator& one, const iterator& other ) const { + bool operator()( const const_iterator& one, const const_iterator& other ) const { return *one < *other; } - bool operator()( const Value& va, const iterator& it ) const { + bool operator()( const Value& va, const const_iterator& it ) const { return va < *it; } - bool operator()( const iterator& it, const Value& va ) const { + bool operator()( const const_iterator& it, const Value& va ) const { return *it < va; } }; -std::set m_set; // store sorted iterators for fast lookup +std::set m_set; // store sorted iterators for fast lookup void init_set(){ // only load set, when lookup is needed if( m_set.empty() ) - for( auto it = begin(); it != end(); ++it ) + for( const_iterator it = begin(); it != end(); ++it ) m_set.emplace( it ); } public: @@ -154,14 +154,14 @@ iterator insert( const Value& value ){ void erase( const Value& value ){ init_set(); const auto it = m_set.find( value ); - ASSERT_MESSAGE( it != m_set.end(), "UnsortedSet::erase: not found" ); + ASSERT_MESSAGE( it != m_set.cend(), "UnsortedSet::erase: not found" ); m_values.erase( *it ); m_set.erase( it ); } -iterator find( const Value& value ){ +const_iterator find( const Value& value ){ init_set(); const auto it = m_set.find( value ); - return it == m_set.end()? m_values.end() : *it; + return it == m_set.cend()? end() : *it; } }; diff --git a/libs/selectionlib.h b/libs/selectionlib.h index 022d62d7..2862bad7 100644 --- a/libs/selectionlib.h +++ b/libs/selectionlib.h @@ -121,6 +121,7 @@ typedef MemberCaller1 #include +/// It's illegal to modify inserted values directly! template class SelectionList { @@ -133,17 +134,17 @@ private: struct Compare{ using is_transparent = void; - bool operator()( const iterator& one, const iterator& other ) const { + bool operator()( const const_iterator& one, const const_iterator& other ) const { return *one < *other; } - bool operator()( const Selected* va, const iterator& it ) const { + bool operator()( const Selected* va, const const_iterator& it ) const { return va < *it; } - bool operator()( const iterator& it, const Selected* va ) const { + bool operator()( const const_iterator& it, const Selected* va ) const { return *it < va; } }; -std::multiset m_set; +std::multiset m_set; public: SelectionList() = default; @@ -181,8 +182,8 @@ void append( Selected& selected ){ m_set.emplace( --end() ); } void erase( Selected& selected ){ - auto it = m_set.find( &selected ); - ASSERT_MESSAGE( it != m_set.end(), "selection-tracking error" ); + const auto it = m_set.find( &selected ); + ASSERT_MESSAGE( it != m_set.cend(), "selection-tracking error" ); m_selection.erase( *it ); m_set.erase( it ); } diff --git a/radiant/treemodel.cpp b/radiant/treemodel.cpp index 4b1387f9..9d887db1 100644 --- a/radiant/treemodel.cpp +++ b/radiant/treemodel.cpp @@ -743,18 +743,27 @@ void graph_tree_model_row_changed( GraphTreeNode& node ); class GraphTreeNode { -typedef std::map, GraphTreeNode*> ChildNodes; +public: +typedef std::pair key_type; +private: +struct Compare{ + bool operator()( const key_type& one, const key_type& other ) const { + const int n = string_compare( one.first.c_str(), other.first.c_str() ); + return n != 0? n < 0 : one.second < other.second; + } +}; +typedef std::map ChildNodes; ChildNodes m_childnodes; -std::list m_list; // dummy list for child index identification -std::list::const_iterator m_parentListIterator; // iterator from parent's list +struct Dummy{}; +std::list m_list; // dummy list for child index identification +std::list::const_iterator m_parentListIterator; // iterator from parent's list bool m_searchFromEnd = false; //silly optimization public: Reference m_instance; GraphTreeNode* m_parent; typedef ChildNodes::iterator iterator; -typedef ChildNodes::key_type key_type; typedef ChildNodes::value_type value_type; typedef ChildNodes::size_type size_type; @@ -794,10 +803,11 @@ int getIndex() const { } iterator insert( const value_type& value ){ - iterator i = m_childnodes.insert( value ).first; + auto [ i, inserted ] = m_childnodes.insert( value ); + ASSERT_MESSAGE( inserted, "GraphTreeNode::insert: already added" ); ( *i ).second->m_parent = this; const auto pos = std::next( i ) == end()? m_list.end() : std::next( i )->second->m_parentListIterator; - i->second->m_parentListIterator = m_list.insert( pos, 'a' ); + i->second->m_parentListIterator = m_list.insert( pos, Dummy() ); return i; } void erase( iterator i ){