summaryrefslogtreecommitdiffstats
path: root/common/bufferadaptor.h
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2015-05-25 23:54:36 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2015-05-25 23:54:36 +0200
commitb25c71e0a42b18b02764719d32714f07ca241b3f (patch)
treec780b3cdca0fd6495d2285a8876220de3b9a51f8 /common/bufferadaptor.h
parent3601ee575f833bf204540f4fac41d87a0d977a79 (diff)
downloadsink-b25c71e0a42b18b02764719d32714f07ca241b3f.tar.gz
sink-b25c71e0a42b18b02764719d32714f07ca241b3f.zip
Moved ApplicationDomainType and BufferAdaptor to separate files
Diffstat (limited to 'common/bufferadaptor.h')
-rw-r--r--common/bufferadaptor.h67
1 files changed, 67 insertions, 0 deletions
diff --git a/common/bufferadaptor.h b/common/bufferadaptor.h
new file mode 100644
index 0000000..121ef9d
--- /dev/null
+++ b/common/bufferadaptor.h
@@ -0,0 +1,67 @@
1/*
2 * Copyright (C) 2014 Christian Mollekopf <chrigi_1@fastmail.fm>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) version 3, or any
8 * later version accepted by the membership of KDE e.V. (or its
9 * successor approved by the membership of KDE e.V.), which shall
10 * act as a proxy defined in Section 6 of version 3 of the license.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
19 */
20#pragma once
21
22#include <QVariant>
23#include <QByteArray>
24#include <QHash>
25
26namespace Akonadi2 {
27
28namespace ApplicationDomain {
29
30/**
31 * This class has to be implemented by resources and can be used as generic interface to access the buffer properties
32 */
33class BufferAdaptor {
34public:
35 virtual ~BufferAdaptor() {}
36 virtual QVariant getProperty(const QByteArray &key) const { return QVariant(); }
37 virtual void setProperty(const QByteArray &key, const QVariant &value) {}
38 virtual QList<QByteArray> availableProperties() const { return QList<QByteArray>(); }
39};
40
41class MemoryBufferAdaptor : public BufferAdaptor {
42public:
43 MemoryBufferAdaptor()
44 : BufferAdaptor()
45 {
46 }
47
48 MemoryBufferAdaptor(const BufferAdaptor &buffer)
49 : BufferAdaptor()
50 {
51 for(const auto &property : buffer.availableProperties()) {
52 mValues.insert(property, buffer.getProperty(property));
53 }
54 }
55
56 virtual ~MemoryBufferAdaptor() {}
57
58 virtual QVariant getProperty(const QByteArray &key) const { return mValues.value(key); }
59 virtual void setProperty(const QByteArray &key, const QVariant &value) { mValues.insert(key, value); }
60 virtual QByteArrayList availableProperties() const { return mValues.keys(); }
61
62private:
63 QHash<QByteArray, QVariant> mValues;
64};
65
66}
67}