]>
Commit | Line | Data |
---|---|---|
e135a038 BK |
1 | // std::list utilities implementation -*- C++ -*- |
2 | ||
12ffa228 | 3 | // Copyright (C) 2003, 2005, 2009, 2010, 2011 Free Software Foundation, Inc. |
e135a038 BK |
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 | |
748086b7 | 8 | // Free Software Foundation; either version 3, or (at your option) |
e135a038 BK |
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 | ||
748086b7 JJ |
16 | // Under Section 7 of GPL version 3, you are granted additional |
17 | // permissions described in the GCC Runtime Library Exception, version | |
18 | // 3.1, as published by the Free Software Foundation. | |
e135a038 | 19 | |
748086b7 JJ |
20 | // You should have received a copy of the GNU General Public License and |
21 | // a copy of the GCC Runtime Library Exception along with this program; | |
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | |
23 | // <http://www.gnu.org/licenses/>. | |
e135a038 BK |
24 | |
25 | /* | |
26 | * | |
27 | * Copyright (c) 1994 | |
28 | * Hewlett-Packard Company | |
29 | * | |
30 | * Permission to use, copy, modify, distribute and sell this software | |
31 | * and its documentation for any purpose is hereby granted without fee, | |
32 | * provided that the above copyright notice appear in all copies and | |
33 | * that both that copyright notice and this permission notice appear | |
34 | * in supporting documentation. Hewlett-Packard Company makes no | |
35 | * representations about the suitability of this software for any | |
36 | * purpose. It is provided "as is" without express or implied warranty. | |
37 | * | |
38 | * | |
39 | * Copyright (c) 1996,1997 | |
40 | * Silicon Graphics Computer Systems, Inc. | |
41 | * | |
42 | * Permission to use, copy, modify, distribute and sell this software | |
43 | * and its documentation for any purpose is hereby granted without fee, | |
44 | * provided that the above copyright notice appear in all copies and | |
45 | * that both that copyright notice and this permission notice appear | |
46 | * in supporting documentation. Silicon Graphics makes no | |
47 | * representations about the suitability of this software for any | |
48 | * purpose. It is provided "as is" without express or implied warranty. | |
49 | */ | |
50 | ||
51 | #include <list> | |
52 | ||
12ffa228 BK |
53 | namespace std _GLIBCXX_VISIBILITY(default) |
54 | { | |
55 | namespace __detail | |
e135a038 | 56 | { |
12ffa228 BK |
57 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
58 | ||
59 | void | |
60 | _List_node_base::swap(_List_node_base& __x, _List_node_base& __y) throw() | |
e135a038 | 61 | { |
12ffa228 BK |
62 | if ( __x._M_next != &__x ) |
63 | { | |
64 | if ( __y._M_next != &__y ) | |
65 | { | |
66 | // Both __x and __y are not empty. | |
67 | std::swap(__x._M_next,__y._M_next); | |
68 | std::swap(__x._M_prev,__y._M_prev); | |
69 | __x._M_next->_M_prev = __x._M_prev->_M_next = &__x; | |
70 | __y._M_next->_M_prev = __y._M_prev->_M_next = &__y; | |
71 | } | |
72 | else | |
73 | { | |
74 | // __x is not empty, __y is empty. | |
75 | __y._M_next = __x._M_next; | |
76 | __y._M_prev = __x._M_prev; | |
77 | __y._M_next->_M_prev = __y._M_prev->_M_next = &__y; | |
78 | __x._M_next = __x._M_prev = &__x; | |
79 | } | |
80 | } | |
81 | else if ( __y._M_next != &__y ) | |
82 | { | |
83 | // __x is empty, __y is not empty. | |
84 | __x._M_next = __y._M_next; | |
85 | __x._M_prev = __y._M_prev; | |
86 | __x._M_next->_M_prev = __x._M_prev->_M_next = &__x; | |
87 | __y._M_next = __y._M_prev = &__y; | |
88 | } | |
e135a038 | 89 | } |
e135a038 | 90 | |
12ffa228 BK |
91 | void |
92 | _List_node_base::_M_transfer(_List_node_base * const __first, | |
93 | _List_node_base * const __last) throw() | |
e135a038 | 94 | { |
12ffa228 BK |
95 | if (this != __last) |
96 | { | |
97 | // Remove [first, last) from its old position. | |
98 | __last->_M_prev->_M_next = this; | |
99 | __first->_M_prev->_M_next = __last; | |
100 | this->_M_prev->_M_next = __first; | |
101 | ||
102 | // Splice [first, last) into its new position. | |
103 | _List_node_base* const __tmp = this->_M_prev; | |
104 | this->_M_prev = __last->_M_prev; | |
105 | __last->_M_prev = __first->_M_prev; | |
106 | __first->_M_prev = __tmp; | |
107 | } | |
e135a038 | 108 | } |
e135a038 | 109 | |
12ffa228 BK |
110 | void |
111 | _List_node_base::_M_reverse() throw() | |
e135a038 | 112 | { |
12ffa228 BK |
113 | _List_node_base* __tmp = this; |
114 | do | |
115 | { | |
116 | std::swap(__tmp->_M_next, __tmp->_M_prev); | |
bd1a56a0 | 117 | |
12ffa228 BK |
118 | // Old next node is now prev. |
119 | __tmp = __tmp->_M_prev; | |
120 | } | |
121 | while (__tmp != this); | |
122 | } | |
e135a038 | 123 | |
12ffa228 BK |
124 | void |
125 | _List_node_base::_M_hook(_List_node_base* const __position) throw() | |
126 | { | |
127 | this->_M_next = __position; | |
128 | this->_M_prev = __position->_M_prev; | |
129 | __position->_M_prev->_M_next = this; | |
130 | __position->_M_prev = this; | |
131 | } | |
e135a038 | 132 | |
12ffa228 BK |
133 | void |
134 | _List_node_base::_M_unhook() throw() | |
135 | { | |
136 | _List_node_base* const __next_node = this->_M_next; | |
137 | _List_node_base* const __prev_node = this->_M_prev; | |
138 | __prev_node->_M_next = __next_node; | |
139 | __next_node->_M_prev = __prev_node; | |
140 | } | |
e135a038 | 141 | |
12ffa228 BK |
142 | _GLIBCXX_END_NAMESPACE_VERSION |
143 | } // namespace __detail | |
144 | } // namespace std |