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


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