minor tweaks
This commit is contained in:
parent
95f4b3e504
commit
9feec41e31
|
|
@ -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<iterator, Compare> m_set; // store sorted iterators for fast lookup
|
||||
std::set<const_iterator, Compare> 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;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -121,6 +121,7 @@ typedef MemberCaller1<SelectableInstance, const Selectable&, &SelectableInstance
|
|||
#include <list>
|
||||
#include <set>
|
||||
|
||||
/// It's illegal to modify inserted values directly!
|
||||
template<typename Selected>
|
||||
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<iterator, Compare> m_set;
|
||||
std::multiset<const_iterator, Compare> 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 );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -743,18 +743,27 @@ void graph_tree_model_row_changed( GraphTreeNode& node );
|
|||
|
||||
class GraphTreeNode
|
||||
{
|
||||
typedef std::map<std::pair<CopiedString, scene::Node*>, GraphTreeNode*> ChildNodes;
|
||||
public:
|
||||
typedef std::pair<CopiedString, scene::Node*> 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<key_type, GraphTreeNode*, Compare> ChildNodes;
|
||||
ChildNodes m_childnodes;
|
||||
|
||||
std::list<char> m_list; // dummy list for child index identification
|
||||
std::list<char>::const_iterator m_parentListIterator; // iterator from parent's list
|
||||
struct Dummy{};
|
||||
std::list<Dummy> m_list; // dummy list for child index identification
|
||||
std::list<Dummy>::const_iterator m_parentListIterator; // iterator from parent's list
|
||||
bool m_searchFromEnd = false; //silly optimization
|
||||
public:
|
||||
Reference<scene::Instance> 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 ){
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user