MeeGo 1.2 Harmattan Developer Documentation Develop for the Nokia N9
   Home · All Classes · All Namespaces · Modules · Functions · Files

or-filter.h

00001 
00023 #ifndef _TelepathyQt4_or_filter_h_HEADER_GUARD_
00024 #define _TelepathyQt4_or_filter_h_HEADER_GUARD_
00025 
00026 #ifndef IN_TELEPATHY_QT4_HEADER
00027 #error IN_TELEPATHY_QT4_HEADER
00028 #endif
00029 
00030 #include <TelepathyQt4/Filter>
00031 #include <TelepathyQt4/Types>
00032 
00033 namespace Tp
00034 {
00035 
00036 template <class T>
00037 class OrFilter : public Filter<T>
00038 {
00039 public:
00040     static SharedPtr<OrFilter<T> > create(
00041             const QList<SharedPtr<const Filter<T> > > &filters = QList<SharedPtr<const Filter<T> > >())
00042     {
00043         return SharedPtr<OrFilter<T> >(new OrFilter<T>(filters));
00044     }
00045 
00046     inline virtual ~OrFilter() { }
00047 
00048     inline virtual bool isValid() const
00049     {
00050         Q_FOREACH (const SharedPtr<const Filter<T> > &filter, mFilters) {
00051             if (!filter || !filter->isValid()) {
00052                 return false;
00053             }
00054         }
00055         return true;
00056     }
00057 
00058     inline virtual bool matches(const SharedPtr<T> &t) const
00059     {
00060         if (!isValid()) {
00061             return false;
00062         }
00063 
00064         Q_FOREACH (const SharedPtr<const Filter<T> > &filter, mFilters) {
00065             if (filter->matches(t)) {
00066                 return true;
00067             }
00068         }
00069         return false;
00070     }
00071 
00072     inline QList<SharedPtr<const Filter<T> > > filters() const { return mFilters; }
00073 
00074 private:
00075     OrFilter(const QList<SharedPtr<const Filter<T> > > &filters)
00076         : Filter<T>(), mFilters(filters) { }
00077 
00078     QList<SharedPtr<const Filter<T> > > mFilters;
00079 };
00080 
00081 } // Tp
00082 
00083 #endif

Copyright © 2008-2011 Collabora Ltd. and Nokia Corporation
Telepathy-Qt4 0.6.5