00001 /* 00002 * This file is part of TelepathyQt4 00003 * 00004 * Copyright (C) 2008 Collabora Ltd. <http://www.collabora.co.uk/> 00005 * Copyright (C) 2008 Nokia Corporation 00006 * 00007 * This library is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with this library; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00020 */ 00021 00022 #ifndef _TelepathyQt4_cli_referenced_handles_h_HEADER_GUARD_ 00023 #define _TelepathyQt4_cli_referenced_handles_h_HEADER_GUARD_ 00024 00025 #ifndef IN_TELEPATHY_QT4_HEADER 00026 #error IN_TELEPATHY_QT4_HEADER 00027 #endif 00028 00048 namespace Telepathy 00049 { 00050 namespace Client 00051 { 00052 class ReferencedHandles; 00053 } 00054 } 00055 00056 #include <TelepathyQt4/Types> 00057 00058 #include <list> 00059 00060 #include <QList> 00061 #include <QSet> 00062 #include <QSharedDataPointer> 00063 #include <QVector> 00064 00065 namespace Telepathy 00066 { 00067 namespace Client 00068 { 00069 class Connection; 00070 00089 class ReferencedHandles 00090 { 00091 public: 00092 typedef UIntList::const_iterator const_iterator; 00093 typedef UIntList::ConstIterator ConstIterator; 00094 typedef UIntList::const_pointer const_pointer; 00095 typedef UIntList::const_reference const_reference; 00096 typedef UIntList::difference_type difference_type; 00097 typedef UIntList::pointer pointer; 00098 typedef UIntList::reference reference; 00099 typedef UIntList::size_type size_type; 00100 typedef UIntList::value_type value_type; 00101 00102 ReferencedHandles(); 00103 ReferencedHandles(const ReferencedHandles& other); 00104 ~ReferencedHandles(); 00105 00106 Connection* connection() const; 00107 uint handleType() const; 00108 00109 uint at(int i) const; 00110 00111 inline uint back() const 00112 { 00113 return last(); 00114 } 00115 00116 inline uint first() const 00117 { 00118 return at(0); 00119 } 00120 00121 inline uint front() const 00122 { 00123 return first(); 00124 } 00125 00126 inline uint last() const 00127 { 00128 return at(size() - 1); 00129 } 00130 00131 uint value(int i, uint defaultValue = 0) const; 00132 00133 const_iterator begin() const; 00134 00135 inline const_iterator constBegin() const 00136 { 00137 return begin(); 00138 } 00139 00140 inline const_iterator constEnd() const 00141 { 00142 return end(); 00143 } 00144 00145 const_iterator end() const; 00146 00147 bool contains(uint handle) const; 00148 00149 int count(uint handle) const; 00150 00151 inline int count() const 00152 { 00153 return size(); 00154 } 00155 00156 inline bool empty() const 00157 { 00158 return isEmpty(); 00159 } 00160 00161 inline bool endsWith(uint handle) const 00162 { 00163 return !isEmpty() && last() == handle; 00164 } 00165 00166 int indexOf(uint handle, int from = 0) const; 00167 00168 bool isEmpty() const; 00169 00170 int lastIndexOf(uint handle, int from = -1) const; 00171 00172 inline int length() const 00173 { 00174 return count(); 00175 } 00176 00177 ReferencedHandles mid(int pos, int length = -1) const; 00178 00179 int size() const; 00180 00181 inline bool startsWith(uint handle) const 00182 { 00183 return !isEmpty() && first() == handle; 00184 } 00185 00186 inline void append(const ReferencedHandles& another) 00187 { 00188 *this = *this + another; 00189 } 00190 00191 void clear(); 00192 void move(int from, int to); 00193 00194 inline void pop_back() 00195 { 00196 return removeLast(); 00197 } 00198 00199 inline void pop_front() 00200 { 00201 return removeFirst(); 00202 } 00203 00204 int removeAll(uint handle); 00205 00206 void removeAt(int i); 00207 00208 inline void removeFirst() 00209 { 00210 return removeAt(0); 00211 } 00212 00213 inline void removeLast() 00214 { 00215 return removeAt(size() - 1); 00216 } 00217 00218 bool removeOne(uint handle); 00219 00220 void swap(int i, int j); 00221 00222 uint takeAt(int i); 00223 00224 inline uint takeFirst() 00225 { 00226 return takeAt(0); 00227 } 00228 00229 inline uint takeLast() 00230 { 00231 return takeAt(size() - 1); 00232 } 00233 00234 bool operator!=(const ReferencedHandles& another) const 00235 { 00236 return !(*this == another); 00237 } 00238 00239 bool operator!=(const UIntList& another) const 00240 { 00241 return !(*this == another); 00242 } 00243 00244 ReferencedHandles operator+(const ReferencedHandles& another) const; 00245 00246 inline ReferencedHandles& operator+=(const ReferencedHandles& another) 00247 { 00248 return *this = (*this + another); 00249 } 00250 00251 ReferencedHandles& operator<<(const ReferencedHandles& another) 00252 { 00253 return *this += another; 00254 } 00255 00256 ReferencedHandles& operator=(const ReferencedHandles& another); 00257 00258 bool operator==(const ReferencedHandles& another) const; 00259 bool operator==(const UIntList& list) const; 00260 00261 inline uint operator[](int i) const 00262 { 00263 return at(i); 00264 } 00265 00266 UIntList toList() const; 00267 00268 inline QSet<uint> toSet() const 00269 { 00270 return toList().toSet(); 00271 } 00272 00273 inline std::list<uint> toStdList() const 00274 { 00275 return toList().toStdList(); 00276 } 00277 00278 inline QVector<uint> toVector() const 00279 { 00280 return toList().toVector(); 00281 } 00282 00283 private: 00284 // For access to the "prime" constructor 00285 friend class PendingContactAttributes; 00286 friend class PendingHandles; 00287 00288 ReferencedHandles(Connection* connection, uint handleType, const UIntList& handles); 00289 00290 struct Private; 00291 QSharedDataPointer<Private> mPriv; 00292 }; 00293 00294 typedef QListIterator<uint> ReferencedHandlesIterator; 00295 00296 } 00297 } 00298 00299 #endif