00001 /***************************************************************************** 00002 * Copyright (C) 2011 by Benjamin Hadorn (b_hadorn@bluewin.ch) 00003 ***************************************************************************** 00004 * Project : Zeus Base Library 00005 * Module : StringList 00006 * Package : Zeus.ZeusBase.System 00007 * Author : Benjamin Hadorn 00008 * Date : 27.12.2011 00009 * System : Zeus-Framework 00010 ***************************************************************************** 00011 * Licence: * 00012 * This library is free software; you can redistribute it and/or modify * 00013 * it under the terms of the GNU Lesser General Public License as * 00014 * published by the Free Software Foundation; either version * 00015 * 2.1 of the License, or (at your option) any later version. * 00016 * * 00017 * This library is distributed in the hope that it will be useful, * 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00020 * GNU Lesser General Public License for more details. * 00021 * * 00022 * You should have received a copy of the GNU Lesser General Public * 00023 * License along with this library; if not, write to the Free Software * 00024 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA * 00025 *****************************************************************************/ 00026 00027 /***************************************************************************** 00028 * Changes: 00029 * 27.12.2011 bha: created zeus 2.0 00030 *****************************************************************************/ 00031 00032 #ifndef StringListH 00033 #define StringListH 00034 00035 #include <zeusbase/System/ZObject.h> 00036 #include <zeusbase/System/SingleLinkedList.hpp> 00037 #include <zeusbase/System/Interfaces/IStringList.hpp> 00038 00039 00040 BEGIN_NAMESPACE_Zeus 00041 00042 /***************************************************************************/ 00045 /***************************************************************************/ 00046 zeusbase_class TStringList : public IStringList 00047 { 00048 public: 00049 TStringList(); 00050 virtual ~TStringList(); 00051 00052 //Methods of IStringList 00053 virtual Int MQUALIFIER add(const IString& rItem); 00054 virtual Int MQUALIFIER addAll(const IStringList& rlstItems); 00055 virtual Int MQUALIFIER addEmptyItem(); 00056 virtual void MQUALIFIER copyToList(IStringList& rList) const; 00057 virtual void MQUALIFIER clear(); 00058 virtual Retval MQUALIFIER deleteItem(Int iIndex); 00059 virtual Retval MQUALIFIER remove(const IString& rItem); 00060 virtual Retval MQUALIFIER removeAll(const IStringList& rlstItems); 00061 virtual Int MQUALIFIER getCount()const; 00062 virtual IString& MQUALIFIER getItem(Int iIndex); 00063 virtual const IString& MQUALIFIER getItemConst(Int iIndex) const; 00064 virtual bool MQUALIFIER equalsItem(Int iIndex, const IString& rItem) const; 00065 virtual bool MQUALIFIER equals(const IStringList& rList) const; 00066 virtual Int MQUALIFIER indexOf(const IString& rItem) const; 00067 virtual Int MQUALIFIER insert(Int iIndex, const IString& rItem); 00068 virtual IStringListIterator* MQUALIFIER getIterator() const; 00069 virtual const IStringListIterator* MQUALIFIER getConstIterator() const; 00070 virtual void MQUALIFIER releaseIterator(const IStringListIterator* pIterator) const; 00071 virtual bool MQUALIFIER isEmpty() const; 00072 virtual IString& MQUALIFIER getFirstItem(); 00073 virtual const IString& MQUALIFIER getFirstItemConst() const; 00074 virtual IString& MQUALIFIER getLastItem(); 00075 virtual const IString& MQUALIFIER getLastItemConst() const; 00076 virtual bool MQUALIFIER hasItem(const IString& rItem) const; 00077 virtual bool MQUALIFIER hasAllItems(const IStringList& rlstItems) const; 00078 00079 //Additional methods for easy accessing the list 00080 Int add(TString strItem); 00081 Retval remove(TString strItem); 00082 bool equalsItem(Int iIndex, TString strItem) const; 00083 Int indexOf(TString strItem) const; 00084 00085 //Operators 00086 IString& operator[] (Int iIndex); 00087 TStringList& operator = (const TStringList& rList); 00088 bool operator == (const TStringList& rList); 00089 00090 private: 00092 TSingleLinkedList<TString> m_lstStrings; 00093 00094 }; 00095 00096 00097 //Inline methods 00098 /***************************************************************************/ 00101 /***************************************************************************/ 00102 inline Int MQUALIFIER TStringList::add(const IString& rItem) 00103 { 00104 return m_lstStrings.add(TString(rItem)); 00105 } 00106 00107 /******************************************************************************/ 00110 /******************************************************************************/ 00111 inline Int TStringList::add(TString strItem) 00112 { 00113 return m_lstStrings.add(strItem); 00114 } 00115 00116 /******************************************************************************/ 00119 /******************************************************************************/ 00120 inline Int MQUALIFIER TStringList::addEmptyItem() 00121 { 00122 return m_lstStrings.addEmptyItem(); 00123 } 00124 00125 /***************************************************************************/ 00128 /***************************************************************************/ 00129 inline void MQUALIFIER TStringList::clear() 00130 { 00131 m_lstStrings.clear(); 00132 } 00133 00134 /***************************************************************************/ 00137 /***************************************************************************/ 00138 inline Retval MQUALIFIER TStringList::deleteItem(Int iIndex) 00139 { 00140 return m_lstStrings.deleteItem(iIndex); 00141 } 00142 00143 /***************************************************************************/ 00146 /***************************************************************************/ 00147 inline Retval MQUALIFIER TStringList::remove(const IString& rItem) 00148 { 00149 return deleteItem(indexOf(rItem)); 00150 } 00151 00152 /******************************************************************************/ 00155 /******************************************************************************/ 00156 inline Retval TStringList::remove(TString strItem) 00157 { 00158 return deleteItem(indexOf(strItem)); 00159 } 00160 00161 /***************************************************************************/ 00164 /***************************************************************************/ 00165 inline Int MQUALIFIER TStringList::getCount() const 00166 { 00167 return m_lstStrings.getCount(); 00168 } 00169 00170 /***************************************************************************/ 00173 /***************************************************************************/ 00174 inline IString& MQUALIFIER TStringList::getItem(Int iIndex) 00175 { 00176 return m_lstStrings.getItem(iIndex); 00177 } 00178 00179 /***************************************************************************/ 00182 /***************************************************************************/ 00183 inline const IString& MQUALIFIER TStringList::getItemConst(Int iIndex) const 00184 { 00185 return m_lstStrings.getItemConst(iIndex); 00186 } 00187 00188 /***************************************************************************/ 00191 /***************************************************************************/ 00192 inline bool MQUALIFIER TStringList::equalsItem(Int iIndex, const IString& rItem) const 00193 { 00194 return getItemConst(iIndex).equalsStr(rItem); 00195 } 00196 00197 /******************************************************************************/ 00200 /******************************************************************************/ 00201 inline bool TStringList::equalsItem(Int iIndex, TString strItem) const 00202 { 00203 return getItemConst(iIndex).equalsStr(strItem); 00204 } 00205 00206 /***************************************************************************/ 00209 /***************************************************************************/ 00210 inline Int MQUALIFIER TStringList::insert(Int iIndex, const IString& rItem) 00211 { 00212 return m_lstStrings.insert(iIndex, rItem); 00213 } 00214 00215 /******************************************************************************/ 00218 /******************************************************************************/ 00219 inline Int TStringList::indexOf(TString strItem) const 00220 { 00221 return indexOf((IString&)strItem); 00222 } 00223 00224 /******************************************************************************/ 00227 /******************************************************************************/ 00228 inline bool MQUALIFIER TStringList::isEmpty() const 00229 { 00230 return m_lstStrings.isEmpty(); 00231 } 00232 00233 /******************************************************************************/ 00236 /******************************************************************************/ 00237 inline IString& MQUALIFIER TStringList::getFirstItem() 00238 { 00239 return this->getItem(0); 00240 } 00241 00242 /******************************************************************************/ 00245 /******************************************************************************/ 00246 inline const IString& MQUALIFIER TStringList::getFirstItemConst() const 00247 { 00248 return this->getItemConst(0); 00249 } 00250 00251 /******************************************************************************/ 00254 /******************************************************************************/ 00255 inline IString& MQUALIFIER TStringList::getLastItem() 00256 { 00257 return this->getItem(m_lstStrings.getCount()-1); 00258 } 00259 00260 /******************************************************************************/ 00263 /******************************************************************************/ 00264 inline const IString& MQUALIFIER TStringList::getLastItemConst() const 00265 { 00266 return this->getItemConst(m_lstStrings.getCount()-1); 00267 } 00268 00269 /******************************************************************************/ 00272 /******************************************************************************/ 00273 inline bool MQUALIFIER TStringList::hasItem(const IString& rItem) const 00274 { 00275 return m_lstStrings.hasItem(TString(rItem)); 00276 } 00277 00278 00279 /******************************************************************************/ 00284 /******************************************************************************/ 00285 inline IString& TStringList::operator[](Int iIndex) 00286 { 00287 return getItem(iIndex); 00288 } 00289 00290 END_NAMESPACE_Zeus 00291 00292 #endif