Home · All Classes · All Namespaces · Modules · Functions · Files

referenced-handles.h

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 #include <TelepathyQt4/Types>
00049 #include <TelepathyQt4/Types>
00050 
00051 #ifndef QT_NO_STL
00052 # include <list>
00053 #endif
00054 
00055 #include <QList>
00056 #include <QSet>
00057 #include <QSharedDataPointer>
00058 #include <QVector>
00059 
00060 namespace Tp
00061 {
00062 
00063 class Connection;
00064 
00083 class ReferencedHandles
00084 {
00085     public:
00086         typedef UIntList::const_iterator const_iterator;
00087         typedef UIntList::ConstIterator ConstIterator;
00088         typedef UIntList::const_pointer const_pointer;
00089         typedef UIntList::const_reference const_reference;
00090         typedef UIntList::difference_type difference_type;
00091         typedef UIntList::pointer pointer;
00092         typedef UIntList::reference reference;
00093         typedef UIntList::size_type size_type;
00094         typedef UIntList::value_type value_type;
00095 
00096         ReferencedHandles();
00097         ReferencedHandles(const ReferencedHandles& other);
00098         ~ReferencedHandles();
00099 
00100         ConnectionPtr connection() const;
00101         uint handleType() const;
00102 
00103         uint at(int i) const;
00104 
00105         inline uint back() const
00106         {
00107             return last();
00108         }
00109 
00110         inline uint first() const
00111         {
00112             return at(0);
00113         }
00114 
00115         inline uint front() const
00116         {
00117             return first();
00118         }
00119 
00120         inline uint last() const
00121         {
00122             return at(size() - 1);
00123         }
00124 
00125         uint value(int i, uint defaultValue = 0) const;
00126 
00127         const_iterator begin() const;
00128 
00129         inline const_iterator constBegin() const
00130         {
00131             return begin();
00132         }
00133 
00134         inline const_iterator constEnd() const
00135         {
00136             return end();
00137         }
00138 
00139         const_iterator end() const;
00140 
00141         bool contains(uint handle) const;
00142 
00143         int count(uint handle) const;
00144 
00145         inline int count() const
00146         {
00147             return size();
00148         }
00149 
00150         inline bool empty() const
00151         {
00152             return isEmpty();
00153         }
00154 
00155         inline bool endsWith(uint handle) const
00156         {
00157             return !isEmpty() && last() == handle;
00158         }
00159 
00160         int indexOf(uint handle, int from = 0) const;
00161 
00162         bool isEmpty() const;
00163 
00164         int lastIndexOf(uint handle, int from = -1) const;
00165 
00166         inline int length() const
00167         {
00168             return count();
00169         }
00170 
00171         ReferencedHandles mid(int pos, int length = -1) const;
00172 
00173         int size() const;
00174 
00175         inline bool startsWith(uint handle) const
00176         {
00177             return !isEmpty() && first() == handle;
00178         }
00179 
00180         inline void append(const ReferencedHandles& another)
00181         {
00182             *this = *this + another;
00183         }
00184 
00185         void clear();
00186         void move(int from, int to);
00187 
00188         inline void pop_back()
00189         {
00190             return removeLast();
00191         }
00192 
00193         inline void pop_front()
00194         {
00195             return removeFirst();
00196         }
00197 
00198         int removeAll(uint handle);
00199 
00200         void removeAt(int i);
00201 
00202         inline void removeFirst()
00203         {
00204             return removeAt(0);
00205         }
00206 
00207         inline void removeLast()
00208         {
00209             return removeAt(size() - 1);
00210         }
00211 
00212         bool removeOne(uint handle);
00213 
00214         void swap(int i, int j);
00215 
00216         uint takeAt(int i);
00217 
00218         inline uint takeFirst()
00219         {
00220             return takeAt(0);
00221         }
00222 
00223         inline uint takeLast()
00224         {
00225             return takeAt(size() - 1);
00226         }
00227 
00228         bool operator!=(const ReferencedHandles& another) const
00229         {
00230             return !(*this == another);
00231         }
00232 
00233         bool operator!=(const UIntList& another) const
00234         {
00235             return !(*this == another);
00236         }
00237 
00238         ReferencedHandles operator+(const ReferencedHandles& another) const;
00239 
00240         inline ReferencedHandles& operator+=(const ReferencedHandles& another)
00241         {
00242             return *this = (*this + another);
00243         }
00244 
00245         ReferencedHandles& operator<<(const ReferencedHandles& another)
00246         {
00247             return *this += another;
00248         }
00249 
00250         ReferencedHandles& operator=(const ReferencedHandles& another);
00251 
00252         bool operator==(const ReferencedHandles& another) const;
00253         bool operator==(const UIntList& list) const;
00254 
00255         inline uint operator[](int i) const
00256         {
00257             return at(i);
00258         }
00259 
00260         UIntList toList() const;
00261 
00262         inline QSet<uint> toSet() const
00263         {
00264             return toList().toSet();
00265         }
00266 
00267 #ifndef QT_NO_STL
00268         inline std::list<uint> toStdList() const
00269         {
00270             return toList().toStdList();
00271         }
00272 #endif
00273 
00274         inline QVector<uint> toVector() const
00275         {
00276             return toList().toVector();
00277         }
00278 
00279     private:
00280         // For access to the "prime" constructor
00281         friend class PendingContactAttributes;
00282         friend class PendingContacts;
00283         friend class PendingHandles;
00284 
00285         ReferencedHandles(const ConnectionPtr &connection,
00286                 uint handleType, const UIntList& handles);
00287 
00288         struct Private;
00289         QSharedDataPointer<Private> mPriv;
00290 };
00291 
00292 typedef QListIterator<uint> ReferencedHandlesIterator;
00293 
00294 } // Tp
00295 
00296 #endif


Copyright © 2009 Collabora Ltd. and Nokia Corporation
Telepathy-Qt4 0.1.8