summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Moreira Magalhaes (andrunko) <andre.magalhaes@collabora.co.uk>2010-11-16 12:16:53 -0200
committerAndre Moreira Magalhaes (andrunko) <andre.magalhaes@collabora.co.uk>2010-12-09 11:09:35 -0200
commited2de858b363caa5ef5e646ec200e480bdbfc52f (patch)
tree825abf9e2501d1e73def805eddf59f1265344efa
parent38874e096210aa313ada3908f6bfd21849d5b77f (diff)
Added OrFilter class.
-rw-r--r--TelepathyQt4/CMakeLists.txt2
-rw-r--r--TelepathyQt4/OrFilter13
-rw-r--r--TelepathyQt4/or-filter.h82
3 files changed, 97 insertions, 0 deletions
diff --git a/TelepathyQt4/CMakeLists.txt b/TelepathyQt4/CMakeLists.txt
index 8189afd1..8ff4679c 100644
--- a/TelepathyQt4/CMakeLists.txt
+++ b/TelepathyQt4/CMakeLists.txt
@@ -258,6 +258,8 @@ set(telepathy_qt4_HEADERS
object.h
OptionalInterfaceFactory
optional-interface-factory.h
+ OrFilter
+ or-filter.h
OutgoingFileTransferChannel
outgoing-file-transfer-channel.h
PeerInterface
diff --git a/TelepathyQt4/OrFilter b/TelepathyQt4/OrFilter
new file mode 100644
index 00000000..3ef0a2f5
--- /dev/null
+++ b/TelepathyQt4/OrFilter
@@ -0,0 +1,13 @@
+#ifndef _TelepathyQt4_OrFilter_HEADER_GUARD_
+#define _TelepathyQt4_OrFilter_HEADER_GUARD_
+
+#ifndef IN_TELEPATHY_QT4_HEADER
+#define IN_TELEPATHY_QT4_HEADER
+#endif
+
+#include <TelepathyQt4/or-filter.h>
+
+#undef IN_TELEPATHY_QT4_HEADER
+
+#endif
+// vim:set ft=cpp:
diff --git a/TelepathyQt4/or-filter.h b/TelepathyQt4/or-filter.h
new file mode 100644
index 00000000..87a62482
--- /dev/null
+++ b/TelepathyQt4/or-filter.h
@@ -0,0 +1,82 @@
+/*
+ * This file is part of TelepathyQt4
+ *
+ * Copyright (C) 2010 Collabora Ltd. <http://www.collabora.co.uk/>
+ * Copyright (C) 2010 Nokia Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef _TelepathyQt4_or_filter_h_HEADER_GUARD_
+#define _TelepathyQt4_or_filter_h_HEADER_GUARD_
+
+#ifndef IN_TELEPATHY_QT4_HEADER
+#error IN_TELEPATHY_QT4_HEADER
+#endif
+
+#include <TelepathyQt4/Filter>
+#include <TelepathyQt4/Types>
+
+namespace Tp
+{
+
+template <class T>
+class OrFilter : public Filter<T>
+{
+public:
+ static SharedPtr<OrFilter<T> > create(
+ const QList<SharedPtr<const Filter<T> > > &filters = QList<SharedPtr<const Filter<T> > >())
+ {
+ return SharedPtr<OrFilter<T> >(new OrFilter<T>(filters));
+ }
+
+ inline virtual ~OrFilter() { }
+
+ inline virtual bool isValid() const
+ {
+ Q_FOREACH (const SharedPtr<const Filter<T> > &filter, mFilters) {
+ if (!filter || !filter->isValid()) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ inline virtual bool matches(const SharedPtr<T> &t) const
+ {
+ if (!isValid()) {
+ return false;
+ }
+
+ Q_FOREACH (const SharedPtr<const Filter<T> > &filter, mFilters) {
+ if (filter->matches(t)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ inline QList<SharedPtr<const Filter<T> > > filters() const { return mFilters; }
+
+private:
+ OrFilter(const QList<SharedPtr<const Filter<T> > > &filters)
+ : Filter<T>(), mFilters(filters) { }
+
+ QList<SharedPtr<const Filter<T> > > mFilters;
+};
+
+} // Tp
+
+#endif