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