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

referenced-handles.h

00001 /*
00002  * This file is part of TelepathyQt4
00003  *
00004  * Copyright (C) 2008-2009 Collabora Ltd. <http://www.collabora.co.uk/>
00005  * Copyright (C) 2008-2009 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_referenced_handles_h_HEADER_GUARD_
00023 #define _TelepathyQt4_referenced_handles_h_HEADER_GUARD_
00024 
00025 #ifndef IN_TELEPATHY_QT4_HEADER
00026 #error IN_TELEPATHY_QT4_HEADER
00027 #endif
00028 
00029 #include <TelepathyQt4/Types>
00030 #include <TelepathyQt4/Types>
00031 
00032 #ifndef QT_NO_STL
00033 # include <list>
00034 #endif
00035 
00036 #include <QList>
00037 #include <QSet>
00038 #include <QSharedDataPointer>
00039 #include <QVector>
00040 
00041 namespace Tp
00042 {
00043 
00044 class Connection;
00045 
00046 class TELEPATHY_QT4_EXPORT ReferencedHandles
00047 {
00048 public:
00049     typedef UIntList::const_iterator const_iterator;
00050     typedef UIntList::ConstIterator ConstIterator;
00051     typedef UIntList::const_pointer const_pointer;
00052     typedef UIntList::const_reference const_reference;
00053     typedef UIntList::difference_type difference_type;
00054     typedef UIntList::pointer pointer;
00055     typedef UIntList::reference reference;
00056     typedef UIntList::size_type size_type;
00057     typedef UIntList::value_type value_type;
00058 
00059     ReferencedHandles();
00060     ReferencedHandles(const ReferencedHandles &other);
00061     ~ReferencedHandles();
00062 
00063     ConnectionPtr connection() const;
00064     uint handleType() const;
00065 
00066     uint at(int i) const;
00067 
00068     inline uint back() const
00069     {
00070         return last();
00071     }
00072 
00073     inline uint first() const
00074     {
00075         return at(0);
00076     }
00077 
00078     inline uint front() const
00079     {
00080         return first();
00081     }
00082 
00083     inline uint last() const
00084     {
00085         return at(size() - 1);
00086     }
00087 
00088     uint value(int i, uint defaultValue = 0) const;
00089 
00090     const_iterator begin() const;
00091 
00092     inline const_iterator constBegin() const
00093     {
00094         return begin();
00095     }
00096 
00097     inline const_iterator constEnd() const
00098     {
00099         return end();
00100     }
00101 
00102     const_iterator end() const;
00103 
00104     bool contains(uint handle) const;
00105 
00106     int count(uint handle) const;
00107 
00108     inline int count() const
00109     {
00110         return size();
00111     }
00112 
00113     inline bool empty() const
00114     {
00115         return isEmpty();
00116     }
00117 
00118     inline bool endsWith(uint handle) const
00119     {
00120         return !isEmpty() && last() == handle;
00121     }
00122 
00123     int indexOf(uint handle, int from = 0) const;
00124 
00125     bool isEmpty() const;
00126 
00127     int lastIndexOf(uint handle, int from = -1) const;
00128 
00129     inline int length() const
00130     {
00131         return count();
00132     }
00133 
00134     ReferencedHandles mid(int pos, int length = -1) const;
00135 
00136     int size() const;
00137 
00138     inline bool startsWith(uint handle) const
00139     {
00140         return !isEmpty() && first() == handle;
00141     }
00142 
00143     inline void append(const ReferencedHandles& another)
00144     {
00145         *this = *this + another;
00146     }
00147 
00148     void clear();
00149     void move(int from, int to);
00150 
00151     inline void pop_back()
00152     {
00153         return removeLast();
00154     }
00155 
00156     inline void pop_front()
00157     {
00158         return removeFirst();
00159     }
00160 
00161     int removeAll(uint handle);
00162 
00163     void removeAt(int i);
00164 
00165     inline void removeFirst()
00166     {
00167         return removeAt(0);
00168     }
00169 
00170     inline void removeLast()
00171     {
00172         return removeAt(size() - 1);
00173     }
00174 
00175     bool removeOne(uint handle);
00176 
00177     void swap(int i, int j);
00178 
00179     uint takeAt(int i);
00180 
00181     inline uint takeFirst()
00182     {
00183         return takeAt(0);
00184     }
00185 
00186     inline uint takeLast()
00187     {
00188         return takeAt(size() - 1);
00189     }
00190 
00191     bool operator!=(const ReferencedHandles& another) const
00192     {
00193         return !(*this == another);
00194     }
00195 
00196     bool operator!=(const UIntList& another) const
00197     {
00198         return !(*this == another);
00199     }
00200 
00201     ReferencedHandles operator+(const ReferencedHandles& another) const;
00202 
00203     inline ReferencedHandles& operator+=(const ReferencedHandles& another)
00204     {
00205         return *this = (*this + another);
00206     }
00207 
00208     ReferencedHandles& operator<<(const ReferencedHandles& another)
00209     {
00210         return *this += another;
00211     }
00212 
00213     ReferencedHandles& operator=(const ReferencedHandles& another);
00214 
00215     bool operator==(const ReferencedHandles& another) const;
00216     bool operator==(const UIntList& list) const;
00217 
00218     inline uint operator[](int i) const
00219     {
00220         return at(i);
00221     }
00222 
00223     UIntList toList() const;
00224 
00225     inline QSet<uint> toSet() const
00226     {
00227         return toList().toSet();
00228     }
00229 
00230 #ifndef QT_NO_STL
00231     inline std::list<uint> toStdList() const
00232     {
00233         return toList().toStdList();
00234     }
00235 #endif
00236 
00237     inline QVector<uint> toVector() const
00238     {
00239         return toList().toVector();
00240     }
00241 
00242 private:
00243     // For access to the "prime" constructor
00244     friend class PendingContactAttributes;
00245     friend class PendingContacts;
00246     friend class PendingHandles;
00247 
00248     ReferencedHandles(const ConnectionPtr &connection,
00249             uint handleType, const UIntList& handles);
00250 
00251     struct Private;
00252     friend struct Private;
00253     QSharedDataPointer<Private> mPriv;
00254 };
00255 
00256 typedef QListIterator<uint> ReferencedHandlesIterator;
00257 
00258 } // Tp
00259 
00260 Q_DECLARE_METATYPE(Tp::ReferencedHandles);
00261 
00262 #endif


Copyright © 2008-2010 Collabora Ltd. and Nokia Corporation
Telepathy-Qt4 0.4.4