and-filter.h Source File

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

and-filter.h
1
23 #ifndef _TelepathyQt_and_filter_h_HEADER_GUARD_
24 #define _TelepathyQt_and_filter_h_HEADER_GUARD_
25
26 #ifndef IN_TP_QT_HEADER
27 #error IN_TP_QT_HEADER
28 #endif
29
30 #include <TelepathyQt/Filter>
31 #include <TelepathyQt/Types>
32
33 namespace Tp
34 {
35
36 template <class T>
37 class AndFilter : public Filter<T>
38 {
39 public:
40 static SharedPtr<AndFilter<T> > create(
41 const QList<SharedPtr<const Filter<T> > > &filters = QList<SharedPtr<const Filter<T> > >())
42 {
43 return SharedPtr<AndFilter<T> >(new AndFilter<T>(filters));
44 }
45
46 inline virtual ~AndFilter() { }
47
48 inline virtual bool isValid() const
49 {
50 Q_FOREACH (const SharedPtr<const Filter<T> > &filter, mFilters) {
51 if (!filter || !filter->isValid()) {
52 return false;
53 }
54 }
55 return true;
56 }
57
58 inline virtual bool matches(const SharedPtr<T> &t) const
59 {
60 if (!isValid()) {
61 return false;
62 }
63
64 Q_FOREACH (const SharedPtr<const Filter<T> > &filter, mFilters) {
65 if (!filter->matches(t)) {
66 return false;
67 }
68 }
69 return true;
70 }
71
72 inline QList<SharedPtr<const Filter<T> > > filters() const { return mFilters; }
73
74 private:
75 AndFilter(const QList<SharedPtr<const Filter<T> > > &filters)
76 : Filter<T>(), mFilters(filters) { }
77
78 QList<SharedPtr<const Filter<T> > > mFilters;
79 };
80
81 } // Tp
82
83 #endif
Tp::AndFilter::matches
virtual bool matches(const SharedPtr< T > &t) const
Definition: and-filter.h:58
Tp::AndFilter::filters
QList< SharedPtr< const Filter< T > > > filters() const
Definition: and-filter.h:72
Tp::Filter
The Filter class provides a base class to be used by specialized filters such as GenericCapabilityFil...
Definition: filter.h:37
Tp::SharedPtr
The SharedPtr class is a pointer to an explicitly shared object.
Definition: shared-ptr.h:39
Tp::AndFilter
The AndFilter class provides a generic filter object to be used in conjunction of other filters...
Definition: and-filter.h:37
Tp::AndFilter::isValid
virtual bool isValid() const
Definition: and-filter.h:48
Tp::AndFilter::~AndFilter
virtual ~AndFilter()
Definition: and-filter.h:46
Tp::AndFilter::create
static SharedPtr< AndFilter< T > > create(const QList< SharedPtr< const Filter< T > > > &filters=QList< SharedPtr< const Filter< T > > >())
Definition: and-filter.h:40