1 |
18 |
jlechner |
// std::list utilities implementation -*- C++ -*-
|
2 |
|
|
|
3 |
|
|
// Copyright (C) 2003 Free Software Foundation, Inc.
|
4 |
|
|
//
|
5 |
|
|
// This file is part of the GNU ISO C++ Library. This library is free
|
6 |
|
|
// software; you can redistribute it and/or modify it under the
|
7 |
|
|
// terms of the GNU General Public License as published by the
|
8 |
|
|
// Free Software Foundation; either version 2, or (at your option)
|
9 |
|
|
// any later version.
|
10 |
|
|
|
11 |
|
|
// This library is distributed in the hope that it will be useful,
|
12 |
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
|
|
// GNU General Public License for more details.
|
15 |
|
|
|
16 |
|
|
// You should have received a copy of the GNU General Public License along
|
17 |
|
|
// with this library; see the file COPYING. If not, write to the Free
|
18 |
|
|
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
19 |
|
|
// USA.
|
20 |
|
|
|
21 |
|
|
// As a special exception, you may use this file as part of a free software
|
22 |
|
|
// library without restriction. Specifically, if other files instantiate
|
23 |
|
|
// templates or use macros or inline functions from this file, or you compile
|
24 |
|
|
// this file and link it with other files to produce an executable, this
|
25 |
|
|
// file does not by itself cause the resulting executable to be covered by
|
26 |
|
|
// the GNU General Public License. This exception does not however
|
27 |
|
|
// invalidate any other reasons why the executable file might be covered by
|
28 |
|
|
// the GNU General Public License.
|
29 |
|
|
|
30 |
|
|
/*
|
31 |
|
|
*
|
32 |
|
|
* Copyright (c) 1994
|
33 |
|
|
* Hewlett-Packard Company
|
34 |
|
|
*
|
35 |
|
|
* Permission to use, copy, modify, distribute and sell this software
|
36 |
|
|
* and its documentation for any purpose is hereby granted without fee,
|
37 |
|
|
* provided that the above copyright notice appear in all copies and
|
38 |
|
|
* that both that copyright notice and this permission notice appear
|
39 |
|
|
* in supporting documentation. Hewlett-Packard Company makes no
|
40 |
|
|
* representations about the suitability of this software for any
|
41 |
|
|
* purpose. It is provided "as is" without express or implied warranty.
|
42 |
|
|
*
|
43 |
|
|
*
|
44 |
|
|
* Copyright (c) 1996,1997
|
45 |
|
|
* Silicon Graphics Computer Systems, Inc.
|
46 |
|
|
*
|
47 |
|
|
* Permission to use, copy, modify, distribute and sell this software
|
48 |
|
|
* and its documentation for any purpose is hereby granted without fee,
|
49 |
|
|
* provided that the above copyright notice appear in all copies and
|
50 |
|
|
* that both that copyright notice and this permission notice appear
|
51 |
|
|
* in supporting documentation. Silicon Graphics makes no
|
52 |
|
|
* representations about the suitability of this software for any
|
53 |
|
|
* purpose. It is provided "as is" without express or implied warranty.
|
54 |
|
|
*/
|
55 |
|
|
|
56 |
|
|
#include <list>
|
57 |
|
|
|
58 |
|
|
namespace _GLIBCXX_STD
|
59 |
|
|
{
|
60 |
|
|
void
|
61 |
|
|
_List_node_base::swap(_List_node_base& __x, _List_node_base& __y)
|
62 |
|
|
{
|
63 |
|
|
if ( __x._M_next != &__x )
|
64 |
|
|
{
|
65 |
|
|
if ( __y._M_next != &__y )
|
66 |
|
|
{
|
67 |
|
|
// Both __x and __y are not empty.
|
68 |
|
|
std::swap(__x._M_next,__y._M_next);
|
69 |
|
|
std::swap(__x._M_prev,__y._M_prev);
|
70 |
|
|
__x._M_next->_M_prev = __x._M_prev->_M_next = &__x;
|
71 |
|
|
__y._M_next->_M_prev = __y._M_prev->_M_next = &__y;
|
72 |
|
|
}
|
73 |
|
|
else
|
74 |
|
|
{
|
75 |
|
|
// __x is not empty, __y is empty.
|
76 |
|
|
__y._M_next = __x._M_next;
|
77 |
|
|
__y._M_prev = __x._M_prev;
|
78 |
|
|
__y._M_next->_M_prev = __y._M_prev->_M_next = &__y;
|
79 |
|
|
__x._M_next = __x._M_prev = &__x;
|
80 |
|
|
}
|
81 |
|
|
}
|
82 |
|
|
else if ( __y._M_next != &__y )
|
83 |
|
|
{
|
84 |
|
|
// __x is empty, __y is not empty.
|
85 |
|
|
__x._M_next = __y._M_next;
|
86 |
|
|
__x._M_prev = __y._M_prev;
|
87 |
|
|
__x._M_next->_M_prev = __x._M_prev->_M_next = &__x;
|
88 |
|
|
__y._M_next = __y._M_prev = &__y;
|
89 |
|
|
}
|
90 |
|
|
}
|
91 |
|
|
|
92 |
|
|
void
|
93 |
|
|
_List_node_base::transfer(_List_node_base * const __first,
|
94 |
|
|
_List_node_base * const __last)
|
95 |
|
|
{
|
96 |
|
|
if (this != __last)
|
97 |
|
|
{
|
98 |
|
|
// Remove [first, last) from its old position.
|
99 |
|
|
__last->_M_prev->_M_next = this;
|
100 |
|
|
__first->_M_prev->_M_next = __last;
|
101 |
|
|
this->_M_prev->_M_next = __first;
|
102 |
|
|
|
103 |
|
|
// Splice [first, last) into its new position.
|
104 |
|
|
_List_node_base* const __tmp = this->_M_prev;
|
105 |
|
|
this->_M_prev = __last->_M_prev;
|
106 |
|
|
__last->_M_prev = __first->_M_prev;
|
107 |
|
|
__first->_M_prev = __tmp;
|
108 |
|
|
}
|
109 |
|
|
}
|
110 |
|
|
|
111 |
|
|
void
|
112 |
|
|
_List_node_base::reverse()
|
113 |
|
|
{
|
114 |
|
|
_List_node_base* __tmp = this;
|
115 |
|
|
do
|
116 |
|
|
{
|
117 |
|
|
std::swap(__tmp->_M_next, __tmp->_M_prev);
|
118 |
|
|
__tmp = __tmp->_M_prev; // Old next node is now prev.
|
119 |
|
|
}
|
120 |
|
|
while (__tmp != this);
|
121 |
|
|
}
|
122 |
|
|
|
123 |
|
|
void
|
124 |
|
|
_List_node_base::hook(_List_node_base* const __position)
|
125 |
|
|
{
|
126 |
|
|
this->_M_next = __position;
|
127 |
|
|
this->_M_prev = __position->_M_prev;
|
128 |
|
|
__position->_M_prev->_M_next = this;
|
129 |
|
|
__position->_M_prev = this;
|
130 |
|
|
}
|
131 |
|
|
|
132 |
|
|
void
|
133 |
|
|
_List_node_base::unhook()
|
134 |
|
|
{
|
135 |
|
|
_List_node_base* const __next_node = this->_M_next;
|
136 |
|
|
_List_node_base* const __prev_node = this->_M_prev;
|
137 |
|
|
__prev_node->_M_next = __next_node;
|
138 |
|
|
__next_node->_M_prev = __prev_node;
|
139 |
|
|
}
|
140 |
|
|
} // namespace std
|
141 |
|
|
|