00001 00002 /* 00003 | Author: Michael Schmidt; 00004 | Gunnar Jehl 00005 | 00006 | ************************* SOFTWARE LICENSE AGREEMENT *********************** 00007 | This source code is published under the BSD License. 00008 | 00009 | See file 'LICENSE.txt' that comes with this distribution or 00010 | http://dbis.informatik.uni-freiburg.de/index.php?project=GCX/license.php 00011 | for the full license agreement. 00012 | 00013 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00014 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00015 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00016 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00017 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00018 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00019 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00020 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00021 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00022 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00023 | POSSIBILITY OF SUCH DAMAGE. 00024 | **************************************************************************** 00025 */ 00026 00035 #include "buffernodelist.h" 00036 #include "outputstream.h" 00037 #include "buffernode.h" 00038 00039 BufferNodeList::BufferNodeList(): 00040 front(NULL), back(NULL) { 00041 } 00042 00043 BufferNodeList::~BufferNodeList() { 00044 while (front) { 00045 BufferNode *next = front->r_sibling; 00046 delete front; 00047 00048 front = next; 00049 } 00050 } 00051 00052 void BufferNodeList::push_back(BufferNode * node) { 00053 if (!front) { 00054 front = node; 00055 back = node; 00056 } else { 00057 back->r_sibling = node; 00058 back = node; 00059 } 00060 back->r_sibling = NULL; 00061 } 00062 00063 BufferNode *BufferNodeList::operator[] (unsigned index) { 00064 unsigned _index = 0; 00065 BufferNode *it = NULL; 00066 00067 for (it = front; _index != index; it = it->r_sibling) { 00068 _index++; 00069 } 00070 return it; 00071 } 00072 00073 void BufferNodeList::print(OutputStream & dos) { 00074 for (BufferNode * it = front; it != NULL; it = it->r_sibling) { 00075 it->debugPrint(dos); 00076 } 00077 } 00078 00079 void BufferNodeList::removeElem(BufferNode * to_remove, BufferNode * prev) { 00080 // case 1: deleting first element 00081 if (prev == NULL) { 00082 if (back == front) { // list contains 1 element 00083 front = NULL; 00084 back = NULL; 00085 } else { // list contains more than 1 element 00086 front = front->r_sibling; 00087 } 00088 00089 // case 2: deleting other than first element 00090 } else { 00091 prev->r_sibling = to_remove->r_sibling; // adjust list pointer 00092 // front remains unchanges 00093 if (to_remove == back) 00094 back = prev; // is we remove the last element, back is changed 00095 } 00096 00097 delete to_remove; 00098 }