List.C

Go to the documentation of this file.
00001 /*
00002  * See the dyninst/COPYRIGHT file for copyright information.
00003  * 
00004  * We provide the Paradyn Tools (below described as "Paradyn")
00005  * on an AS IS basis, and do not warrant its validity or performance.
00006  * We reserve the right to update, modify, or discontinue this
00007  * software at any time.  We shall have no obligation to supply such
00008  * updates or modifications or any other form of support to you.
00009  * 
00010  * By your use of Paradyn, you understand and agree that we (or any
00011  * other person or entity with proprietary rights in Paradyn) are
00012  * under no obligation to provide either maintenance services,
00013  * update services, notices of latent defects, or correction of
00014  * defects for Paradyn.
00015  * 
00016  * This library is free software; you can redistribute it and/or
00017  * modify it under the terms of the GNU Lesser General Public
00018  * License as published by the Free Software Foundation; either
00019  * version 2.1 of the License, or (at your option) any later version.
00020  * 
00021  * This library is distributed in the hope that it will be useful,
00022  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00023  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00024  * Lesser General Public License for more details.
00025  * 
00026  * You should have received a copy of the GNU Lesser General Public
00027  * License along with this library; if not, write to the Free Software
00028  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00029  */
00030 
00031 // $Id: list.C,v
00032 
00033 #include <ostream>
00034 #include "common/h/List.h"
00035 
00036 using namespace std;
00037 
00038 template <class DataType, class KeyType> DO_INLINE_F typename 
00039 ListBase<DataType, KeyType>::node *ListBase<DataType, KeyType>::getLastNode()
00040 {
00041   node *lag = NULL;
00042   node *curNode = head;
00043   while(1) {
00044     if(curNode == NULL) break;
00045     lag = curNode;
00046     curNode = curNode->next;
00047   }
00048   return lag;
00049 }
00050 
00051 template <class DataType, class KeyType> void 
00052 ListBase<DataType, KeyType>::__push_front(DataType &data, 
00053                       const KeyType &key)
00054 {
00055    typename ListBase<DataType, KeyType>::node *ni = new node(data, key, head);
00056    head = ni;
00057 }
00058 
00059 
00060 template <class DataType, class KeyType> 
00061 void ListBase<DataType, KeyType>::__push_back(DataType &data, 
00062                           const KeyType &key)
00063 {
00064    node *newNode = new node(data, key, NULL);
00065 
00066    if(! isEmpty()) {
00067      node *lastNode = getLastNode();
00068      lastNode->next = newNode;
00069    } else {
00070      head = newNode;
00071    }
00072 }
00073 
00074 template <class DataType, class KeyType>
00075 void ListBase<DataType, KeyType>::clear()
00076 {
00077   node *curr, *nx;
00078 
00079   curr = head;
00080   while (curr) {
00081     nx = curr->next;
00082     delete (curr);
00083     curr = nx;
00084   }
00085   head = NULL;
00086 }
00087 
00088 template <class DataType, class KeyType>
00089 bool ListBase<DataType, KeyType>::__remove_with_val(const DataType &dataVal)
00090 {
00091     node *lag;
00092     node *curr;
00093 
00094     for (curr=head, lag = NULL; curr; curr=curr->next) {
00095     if (curr->data == dataVal) {
00096         break;
00097     }
00098     lag = curr;
00099     }
00100 
00101     if (curr) {
00102     if (lag) {
00103         lag->next = curr->next;
00104     } else {
00105         head = curr->next;
00106     }
00107     delete(curr);
00108     return(true);
00109     } else {
00110     return(false);
00111     }
00112 }
00113 
00114 template <class DataType, class KeyType>
00115 bool ListBase<DataType, KeyType>::__remove_with_key(const KeyType &key)
00116 {
00117     node *lag;
00118     node *curr;
00119 
00120     for (curr=head, lag = NULL; curr; curr=curr->next) {
00121     if (curr->key == key) {
00122         break;
00123     }
00124     lag = curr;
00125     }
00126 
00127     if (curr) {
00128     if (lag) {
00129         lag->next = curr->next;
00130     } else {
00131         head = curr->next;
00132     }
00133     delete(curr);
00134     return(true);
00135     } else {
00136     return(false);
00137     }
00138 }
00139 
00140 template <class DataType, class KeyType>
00141 bool ListBase<DataType, KeyType>::__find_with_key(const KeyType &key, 
00142                           DataType *saveVal)
00143 {
00144    node *curr;
00145 
00146    for (curr=head; curr; curr=curr->next) {
00147       if (curr->key == key) {
00148      (*saveVal) = curr->data;
00149      return true;
00150       }
00151    }
00152    return false;
00153 }
00154 
00155 template <class DataType, class KeyType>
00156 bool ListBase<DataType, KeyType>::__find_with_val(const DataType &dataVal)
00157   const {
00158    node *curr;
00159 
00160    for (curr=head; curr; curr=curr->next) {
00161       if (curr->data == dataVal) {
00162      return true;
00163       }
00164    }
00165    return false;
00166 }
00167 
00168 
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 12 Jul 2013 for SymtabAPI by  doxygen 1.6.1