Simple request about core::map

Discuss about anything related to the Irrlicht Engine, or read announcements about any significant features or usage changes.
Post Reply
teto
Posts: 159
Joined: Thu Dec 03, 2009 9:37 pm
Location: /home
Contact:

Simple request about core::map

Post by teto »

Hi,

When iterating through a core::map, there are some items I need to check before deleting them and I can't find any simple way to delete a Node* or an Iterator from map. remove only accepts a key which means I will look twice for the same item as I already have the correct Node*.

Code: Select all

 
    TJoystickMap::Iterator itr = Joysticks.getIterator();
 
    for( ;!itr.atEnd(); ++itr)
    {
        TJoystickMap::Node* n = itr.getNode();
        CJoystickDirectInput* joystick = n->getValue();
 
        // Copy Save state
        const SJoystickState savedState = joystick->getState();
        if( joystick->update() )
        {
 
            // generate events
            IInputManager::compareStates(savedState, joystick);
        }
        else
        {
            sendJoystickEvent(EJE_UNPLUGGED, joystick );
            Joysticks.remove ( n->getKey() );         //!< Here is the "problem", I don't need to search the node again. I wish I could do: Joysticks.remove(n);
        }
 
    }
This is very simple to do and effective.

Matt
Using trunk with mingw/gcc 4.6, Windows 7 64 bits driver opengl
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Simple request about core::map

Post by hendu »

Either way, I don't think you should remove nodes while iterating. Removal triggers rebalancing, how's the iterator supposed to keep track of things?
teto
Posts: 159
Joined: Thu Dec 03, 2009 9:37 pm
Location: /home
Contact:

Re: Simple request about core::map

Post by teto »

In the std, you retrieve a valid iterator upon deletion. Also std::map doesn't move values.
Using trunk with mingw/gcc 4.6, Windows 7 64 bits driver opengl
aanderse
Posts: 155
Joined: Sun Aug 10, 2008 2:02 pm
Location: Canada

Re: Simple request about core::map

Post by aanderse »

teto wrote:In the std
it sounds like you've already found a suitable alternative then!
excellent
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: Simple request about core::map

Post by hybrid »

Added in SVN/trunk.
teto
Posts: 159
Joined: Thu Dec 03, 2009 9:37 pm
Location: /home
Contact:

Re: Simple request about core::map

Post by teto »

aanderse wrote:
teto wrote:In the std
it sounds like you've already found a suitable alternative then!
excellent
A bit low, don't you think ?
Added in SVN/trunk.
Thank you !
Using trunk with mingw/gcc 4.6, Windows 7 64 bits driver opengl
Brkopac
Posts: 88
Joined: Fri Sep 19, 2008 2:36 am

Re: Simple request about core::map

Post by Brkopac »

teto wrote:
aanderse wrote:
teto wrote:In the std
it sounds like you've already found a suitable alternative then!
excellent
QFT * OVER 9000
Image - The glory days.
Post Reply