3 template<
typename t_item>
25 template<
typename _t_item>
43 template<
typename t_in>
void _set(
const t_in & in) {
44 remove_all(); _add(in);
46 template<
typename t_in>
void _add(
const t_in & in) {
47 for(
typename t_in::const_iterator iter = in.first(); iter.is_valid(); ++in) add_item(*iter);
49 template<
typename t_in> t_self &
operator=(
const t_in & in) {_set(in);
return *
this;}
54 add_item(
walk->m_content);
63 iterator
first() {
return iterator(m_first);}
64 iterator
last() {
return iterator(m_last);}
65 const_iterator
first()
const {
return const_iterator(m_first);}
66 const_iterator
last()
const {
return const_iterator(m_last);}
70 __unlink(_elem(p_iter));
73 void remove(const_iterator
const & p_iter) {
74 PFC_ASSERT(p_iter.is_valid());
75 __unlink(_elem(p_iter));
79 while(m_first != NULL) __unlink(m_first);
80 PFC_ASSERT(m_count == 0);
82 void remove_range(const_iterator
const & p_from,const_iterator
const & p_to) {
83 for(t_elem *
walk = _elem(p_from);;) {
84 if (
walk == NULL) {PFC_ASSERT(!
"Should not get here");
break;}
87 if (
walk == _elem(p_to))
break;
92 template<
typename t_callback>
void enumerate(t_callback & p_callback)
const {__enumerate_chain<const t_elem>(m_first,p_callback);}
93 template<
typename t_callback>
void enumerate(t_callback & p_callback) {__enumerate_chain<t_elem>(m_first,p_callback);}
95 template<
typename t_source>
bool remove_item(
const t_source & p_item) {
97 if (__find(elem,p_item)) {
107 template<
typename t_source>
109 __link_last(
new t_elem(p_source));
111 template<
typename t_source>
113 add_item(p_source);
return *
this;
117 iterator
insert_after(const_iterator
const & p_iter) {
return __link_next(_elem(p_iter),
new t_elem);}
118 iterator
insert_before(const_iterator
const & p_iter) {
return __link_prev(_elem(p_iter),
new t_elem);}
119 template<
typename t_source> iterator
insert_last(
const t_source & p_source) {
return __link_last(
new t_elem(p_source));}
120 template<
typename t_source> iterator
insert_first(
const t_source & p_source) {
return __link_first(
new t_elem(p_source));}
121 template<
typename t_source> iterator
insert_after(const_iterator
const & p_iter,
const t_source & p_source) {
return __link_next(_elem(p_iter),
new t_elem(p_source));}
122 template<
typename t_source> iterator
insert_before(const_iterator
const & p_iter,
const t_source & p_source) {
return __link_prev(_elem(p_iter),
new t_elem(p_source));}
124 template<
typename t_source> const_iterator
find_item(
const t_source & p_item)
const {
126 if (!__find(elem,p_item))
return const_iterator();
127 return const_iterator(elem);
130 template<
typename t_source> iterator
find_item(
const t_source & p_item) {
132 if (!__find(elem,p_item))
return iterator();
133 return iterator(elem);
136 template<
typename t_source>
bool have_item(
const t_source & p_item)
const {
138 return __find(dummy,p_item);
140 template<
typename t_source>
void set_single(
const t_source & p_item) {
141 remove_all(); add_item(p_item);
150 while(p_other.
m_first != NULL) {
156 while(m_last != NULL) {
164 PFC_ASSERT( _elem(iter)->
m_prev == NULL && _elem(iter)->
m_next == NULL );
165 __link_last(_elem(iter));
170 PFC_ASSERT( _elem(iter)->
m_prev == NULL && _elem(iter)->
m_next == NULL );
171 __link_first(_elem(iter));
174 static t_elem *
_elem(const_iterator
const & iter) {
175 return static_cast<t_elem*
>(iter.
_node());
178 t_elem *
walk = m_first;
179 while(p_index > 0 && walk != NULL) {
185 template<
typename t_elemwalk,
typename t_callback>
187 t_elemwalk *
walk = p_elem;
188 while(walk != NULL) {
189 p_callback(walk->m_content);
194 template<
typename t_source>
bool __find(t_elem * & p_elem,
const t_source & p_item)
const {
196 if (
walk->m_content == p_item) {
197 p_elem =
walk;
return true;
204 (p_elem->m_prev == NULL ? m_first : p_elem->m_prev->m_next) = p_elem->m_next;
205 (p_elem->m_next == NULL ? m_last : p_elem->m_next->m_prev) = p_elem->m_prev;
206 p_elem->m_next = p_elem->m_prev = NULL;
211 __unlink_helper(p_elem);
212 --m_count; p_elem->__release_temporary();
217 __unlink_helper(p_elem);
218 --m_count; p_elem->release();
222 p_elem->add_ref(); ++m_count;
226 p_elem->m_next = m_first;
227 p_elem->m_prev = NULL;
228 (m_first == NULL ? m_last : m_first->m_prev) = p_elem;
234 p_elem->m_prev = m_last;
235 p_elem->m_next = NULL;
236 (m_last == NULL ? m_first : m_last->m_next) = p_elem;
242 p_elem->m_prev = p_prev;
243 p_elem->m_next = p_prev->m_next;
244 (p_prev->m_next != NULL ? p_prev->m_next->m_prev : m_last) = p_elem;
245 p_prev->m_next = p_elem;
250 p_elem->m_next = p_next;
251 p_elem->m_prev = p_next->m_prev;
252 (p_next->m_prev != NULL ? p_next->m_prev->m_next : m_first) = p_elem;
253 p_next->m_prev = p_elem;
266 constructor_may_fail =
false 270 template<
typename t_item>
class traits_t<const_iterator<t_item> > :
public traits_t<refcounted_object_ptr_t<_list_node<t_item> > > {};
272 template<
typename t_item>
class traits_t<iterator<t_item> > :
public traits_t<const_iterator<t_item> > {};
chain_list_v2_t(const t_self &p_source)
Base class for list nodes. Implemented by list implementers.
static void __enumerate_chain(t_elemwalk *p_elem, t_callback &p_callback)
::pfc::const_iterator< t_item > const_iterator
void add_item(const t_source &p_source)
t_elem * __link_prev(t_elem *p_next, t_elem *p_elem)
void set_single(const t_source &p_item)
::pfc::iterator< t_item > iterator
iterator insert_before(const_iterator const &p_iter)
t_elem * __unlink(t_elem *p_elem)
const_iterator first() const
t_elem * __link_last(t_elem *p_elem)
t_elem * __link_next(t_elem *p_prev, t_elem *p_elem)
t_elem * __unlink_temporary(t_elem *p_elem)
Differences between chain_list_v2_t<> and old chain_list_t<>: Iterators pointing to removed items as...
iterator by_index(t_size p_index)
Slow!
iterator insert_after(const_iterator const &p_iter, const t_source &p_source)
iterator insert_before(const_iterator const &p_iter, const t_source &p_source)
iterator find_item(const t_source &p_item)
t_self & operator=(const t_self &p_other)
t_self * walk(bool forward)
iterator insert_first(const t_source &p_source)
const_iterator find_item(const t_source &p_item) const
t_self & operator>>(t_self &p_other)
bool remove_item(const t_source &p_item)
void remove_single(const_iterator const &p_iter)
t_node * _node() const
For internal use / list implementations only! Do not call!
__chain_list_elem< t_item > t_elem
iterator insert_last(const t_source &p_source)
void _link_first(const_iterator const &iter)
Links an object that has been unlinked from another list. Unsafe.
__chain_list_elem< t_item > t_self
void _set(const t_in &in)
void enumerate(t_callback &p_callback) const
const_iterator last() const
t_self & operator+=(const t_source &p_source)
bool have_item(const t_source &p_item) const
void enumerate(t_callback &p_callback)
void __on_link(t_elem *p_elem)
void __release_temporary()
_list_node< t_item > t_node
t_self & operator=(const t_in &in)
void _link_last(const_iterator const &iter)
Links an object that has been unlinked from another list. Unsafe.
const_iterator by_index(t_size p_index) const
Slow!
static t_elem * _elem(const_iterator const &iter)
t_elem * __link_first(t_elem *p_elem)
bool __find(t_elem *&p_elem, const t_source &p_item) const
void remove_range(const_iterator const &p_from, const_iterator const &p_to)
t_elem * __by_index(t_size p_index) const
t_self & operator<<(t_self &p_other)
chain_list_v2_t< t_item > t_self
iterator insert_after(const_iterator const &p_iter)
TEMPLATE_CONSTRUCTOR_FORWARD_FLOOD_WITH_INITIALIZER(__chain_list_elem, t_node,{m_prev=m_next=NULL;})
void _add(const t_in &in)
void _refcount_release_temporary()
void __unlink_helper(t_elem *p_elem)