1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include "nel/3d/fast_ptr_list.h"
31 // ***************************************************************************
32 void CFastPtrListNode::unlink()
34 // If linked to a list, remove me.
38 nlassert(_Owner
==NULL
);
43 // ***************************************************************************
44 CFastPtrListBase::~CFastPtrListBase()
50 // ***************************************************************************
51 void CFastPtrListBase::clear()
55 CFastPtrListNode
*node
= _Nodes
[0];
61 // ***************************************************************************
62 void CFastPtrListBase::insert(void *element
, CFastPtrListNode
*node
)
67 // if this node is already linked to me, no-op!
68 if(node
->_Owner
==this)
71 // first unlink the node from its older list if any.
74 // then add the elements to the list, and update node info
75 _Elements
.push_back(element
);
76 _Nodes
.push_back(node
);
78 node
->_IndexInOwner
= (uint32
)_Nodes
.size()-1;
81 // ***************************************************************************
82 void CFastPtrListBase::erase(CFastPtrListNode
*node
)
85 if(node
->_Owner
!=this)
89 uint nodeIndex
= node
->_IndexInOwner
;
90 uint lastIndex
= (uint
)_Nodes
.size()-1;
92 // swap the last element and the erased one.
93 swap(_Elements
[nodeIndex
], _Elements
[lastIndex
]);
94 swap(_Nodes
[nodeIndex
], _Nodes
[lastIndex
]);
95 // change the swapped node index. NB: work also in the particular case nodeIndex==lastIndex
96 _Nodes
[nodeIndex
]->_IndexInOwner
= nodeIndex
;
97 // erase the last elements
101 // reset erased node.