00001 // 00002 // Copyright (c) 2007-2009 Google Inc. 00003 // Copyright (c) 2006-2007 Jaiku Ltd. 00004 // Copyright (c) 2002-2006 Mika Raento and Renaud Petit 00005 // 00006 // This software is licensed at your choice under either 1 or 2 below. 00007 // 00008 // 1. MIT License 00009 // 00010 // Permission is hereby granted, free of charge, to any person obtaining a copy 00011 // of this software and associated documentation files (the "Software"), to deal 00012 // in the Software without restriction, including without limitation the rights 00013 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00014 // copies of the Software, and to permit persons to whom the Software is 00015 // furnished to do so, subject to the following conditions: 00016 // 00017 // The above copyright notice and this permission notice shall be included in 00018 // all copies or substantial portions of the Software. 00019 // 00020 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00021 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00022 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00023 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00024 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00025 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00026 // THE SOFTWARE. 00027 // 00028 // 2. Gnu General Public license 2.0 00029 // 00030 // This program is free software; you can redistribute it and/or 00031 // modify it under the terms of the GNU General Public License 00032 // as published by the Free Software Foundation; either version 2 00033 // of the License, or (at your option) any later version. 00034 // 00035 // This program is distributed in the hope that it will be useful, 00036 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00037 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00038 // GNU General Public License for more details. 00039 // 00040 // You should have received a copy of the GNU General Public License 00041 // along with this program; if not, write to the Free Software 00042 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00043 // 00044 00045 #ifndef LIST_H_INCLUDED 00046 #define LIST_H_INCLUDED 1 00047 00048 #include <e32std.h> 00049 00050 #include "symbian_auto_ptr.hpp" 00051 00052 template<typename Data> 00053 struct PlainNode { 00054 Data Item; 00055 PlainNode<Data>* Next; 00056 PlainNode(): Next(0) { } 00057 void Release() { } 00058 }; 00059 00060 template<typename Data> 00061 struct PtrNode { 00062 Data* Item; 00063 PtrNode<Data>* Next; 00064 PtrNode(): Next(0), Item(0) { } 00065 ~PtrNode() { delete Item; } 00066 void Release() { Item=0; } 00067 }; 00068 00069 template<typename Data, typename NodeType=PlainNode<Data> > class CList : public CBase { 00070 public: 00071 typedef NodeType Node; 00072 00073 Node *iFirst, *iCurrent; 00074 TInt iCount; 00075 Node* AppendL(Data Item) { 00076 Node* n=new (ELeave) Node; 00077 n->Item=Item; 00078 if (iCurrent) { 00079 iCurrent->Next=n; 00080 iCurrent=iCurrent->Next; 00081 } else { 00082 iCurrent=iFirst=n; 00083 } 00084 iCount++; 00085 return iCurrent; 00086 00087 } 00088 void DeleteNode(Node* ListNode, bool Destroy) 00089 { 00090 if (!ListNode) return; 00091 Node* n=iFirst, *prev=0; 00092 while (n!=ListNode) { 00093 prev=n; 00094 n=n->Next; 00095 } 00096 if (n) { 00097 if (prev) { 00098 prev->Next=n->Next; 00099 if (n==iCurrent) iCurrent=prev; 00100 } else { 00101 if (iCurrent==iFirst) iCurrent=0; 00102 iFirst=iFirst->Next; 00103 } 00104 } 00105 if (Destroy) delete n; 00106 iCount--; 00107 } 00108 00109 void MoveToTop(Node* ListNode) 00110 { 00111 if (ListNode==iFirst) return; 00112 DeleteNode(ListNode, false); 00113 ListNode->Next=iFirst; 00114 iFirst=ListNode; 00115 iCount++; 00116 } 00117 00118 static CList<Data, NodeType>* NewL() { 00119 e_auto_ptr<CList <Data, NodeType> > self(new (ELeave) CList); 00120 self->ConstructL(); 00121 return self.release(); 00122 } 00123 00124 ~CList() { 00125 reset(); 00126 } 00127 void reset() { 00128 while (iFirst!=0) { 00129 Node* tmp=iFirst->Next; 00130 delete iFirst; 00131 iFirst=tmp; 00132 } 00133 iCurrent=0; 00134 iCount=0; 00135 } 00136 void DeleteFirst() { 00137 if (!iFirst) return; 00138 Node* tmp=iFirst; 00139 if (iCurrent==iFirst) { 00140 iCurrent=tmp->Next; 00141 } 00142 iFirst=tmp->Next; 00143 delete tmp; 00144 iCount--; 00145 } 00146 void DeleteLast() 00147 { 00148 if (!iCurrent) { 00149 User::Leave(-1005); 00150 } 00151 DeleteNode(iCurrent, true); 00152 } 00153 Data Top() { 00154 if (!iFirst) return Data(); 00155 return iFirst->Item; 00156 } 00157 00158 Data Pop() { 00159 if (!iFirst) { 00160 return Data(); 00161 } 00162 00163 Data ret=iFirst->Item; 00164 iFirst->Release(); 00165 DeleteFirst(); 00166 return ret; 00167 } 00168 void Push(Data Item) { 00169 Node* n=new (ELeave) Node; 00170 n->Item=Item; // may not leave 00171 n->Next=iFirst; 00172 iFirst=n; 00173 if (!iCurrent) iCurrent=iFirst; 00174 iCount++; 00175 } 00176 protected: 00177 CList() : iFirst(0), iCurrent(0), iCount(0) { } 00178 void ConstructL() { } 00179 }; 00180 00181 template<typename Data> class CPtrList : public CList< Data*, PtrNode<Data> > 00182 { 00183 public: 00184 static CPtrList<Data>* NewL() { 00185 e_auto_ptr<CPtrList <Data> > self(new (ELeave) CPtrList); 00186 self->ConstructL(); 00187 return self.release(); 00188 } 00189 private: 00190 CPtrList() : CList<Data*, PtrNode<Data> >() { } 00191 }; 00192 00193 #endif // LIST_H_INCLUDED
ContextLogger2—ContextLogger2 Logger Daemon Internals—Generated on Mon May 2 13:49:57 2011 by Doxygen 1.6.1