00001 /*========================================================================= 00002 00003 Module: $RCSfile: vtkLinkedList.h,v $ 00004 00005 Copyright (c) Kitware, Inc. 00006 All rights reserved. 00007 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00008 00009 This software is distributed WITHOUT ANY WARRANTY; without even 00010 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00011 PURPOSE. See the above copyright notice for more information. 00012 00013 =========================================================================*/ 00014 // .NAME vtkLinkedList - a templated linked list 00015 00016 #ifndef __vtkLinkedList_h 00017 #define __vtkLinkedList_h 00018 00019 #include "vtkAbstractList.h" 00020 #include "vtkMimxCommonWin32Header.h" 00021 00022 template <class DType> class vtkLinkedListNode; 00023 template <class DType> class vtkLinkedListIterator; 00024 00025 template <class DType> 00026 class vtkLinkedList : public vtkAbstractList<DType> 00027 { 00028 friend class vtkLinkedListIterator<DType>; 00029 virtual const char* GetClassNameInternal() const { return "vtkLinkedList"; } 00030 00031 public: 00032 typedef vtkAbstractList<DType> Superclass; 00033 typedef vtkLinkedListIterator<DType> IteratorType; 00034 00035 static vtkLinkedList<DType> *New(); 00036 00037 // Description: 00038 // Return an iterator to the list. This iterator is allocated using 00039 // New, so the developer is responsible for deleating it. 00040 vtkLinkedListIterator<DType> *NewIterator(); 00041 00042 // Description: 00043 // Append an Item to the end of the linked list. 00044 int AppendItem(DType a); 00045 00046 // Description: 00047 // Insert an Item to the front of the linked list. 00048 int PrependItem(DType a); 00049 00050 // Description: 00051 // Insert an Item to the specific location in the linked list. 00052 int InsertItem(vtkIdType loc, DType a); 00053 00054 // Description: 00055 // Sets the Item at the specific location in the list to a new value. 00056 // It also checks if the item can be set. 00057 // It returns VTK_OK if successfull. 00058 int SetItem(vtkIdType loc, DType a); 00059 00060 // Description: 00061 // Sets the Item at the specific location in the list to a new value. 00062 // This method does not perform any error checking. 00063 void SetItemNoCheck(vtkIdType loc, DType a); 00064 00065 // Description: 00066 // Remove an Item from the linked list 00067 int RemoveItem(vtkIdType id); 00068 00069 // Description: 00070 // Return an item that was previously added to this linked list. 00071 DType GetItem(vtkIdType id); 00072 00073 // Description: 00074 // Find an item in the linked list. Return VTK_OK if it was found 00075 // od VTK_ERROR if not found. The location of the item is returned in res. 00076 int FindItem(DType a, vtkIdType &res); 00077 00078 // Description: 00079 // Find an item in the linked list using a comparison routine. 00080 // Return VTK_OK if it was found 00081 // od VTK_ERROR if not found. The location of the item is returned in res. 00082 int FindItem(DType a, 00083 vtkAbstractListCompareFunction(DType, compare), 00084 vtkIdType &res); 00085 00086 // Description: 00087 // Return the number of items currently held in this container. This 00088 // different from GetSize which is provided for some containers. GetSize 00089 // will return how many items the container can currently hold. 00090 vtkIdType GetNumberOfItems() const { return this->NumberOfItems; } 00091 00092 // Description: 00093 // Returns the number of items the container can currently hold. 00094 // Since capacity is arbitrary for the linked list, this will 00095 // always return the current number of elements. 00096 vtkIdType GetSize() const { return this->NumberOfItems; } 00097 00098 // Description: 00099 // Removes all items from the container. 00100 void RemoveAllItems(); 00101 00102 // Description: 00103 // Since linked list does not have the notion of capacity, 00104 // this method always return VTK_ERROR. 00105 int SetSize(vtkIdType ) { return VTK_ERROR; } 00106 00107 // Description: 00108 // This method dumps debug of the linked list. 00109 void DebugList(); 00110 00111 00112 protected: 00113 vtkLinkedList() { 00114 this->Head = 0; this->Tail = 0; 00115 this->NumberOfItems = 0; 00116 } 00117 virtual ~vtkLinkedList(); 00118 00119 // Description: 00120 // Find a node with given index. 00121 00122 vtkIdType NumberOfItems; 00123 vtkLinkedListNode<DType> *Head; 00124 vtkLinkedListNode<DType> *Tail; 00125 vtkLinkedListNode<DType>* FindNode(vtkIdType i); 00126 00127 private: 00128 vtkLinkedList(const vtkLinkedList<DType>&); // Not implemented 00129 void operator=(const vtkLinkedList<DType>&); // Not implemented 00130 }; 00131 00132 #ifdef VTK_NO_EXPLICIT_TEMPLATE_INSTANTIATION 00133 #include "vtkLinkedList.txx" 00134 #endif 00135 00136 #endif 00137 00138 00139
1.6.1