diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-01-03 00:08:44 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-01-03 00:08:44 +0100 |
commit | 4067462b0a27984df84b0379c19122d574253dfb (patch) | |
tree | e6a413a575b7fd4062da6474907bffd68155706f /common/domainadaptor.h | |
parent | 91d915a09b7d52c10edb1d4c1298fc2885b8a257 (diff) | |
download | sink-4067462b0a27984df84b0379c19122d574253dfb.tar.gz sink-4067462b0a27984df84b0379c19122d574253dfb.zip |
Shared domain adaptors between resource and facade.
Diffstat (limited to 'common/domainadaptor.h')
-rw-r--r-- | common/domainadaptor.h | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/common/domainadaptor.h b/common/domainadaptor.h new file mode 100644 index 0000000..e8f586b --- /dev/null +++ b/common/domainadaptor.h | |||
@@ -0,0 +1,77 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2014 Christian Mollekopf <chrigi_1@fastmail.fm> | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | ||
6 | * the Free Software Foundation; either version 2 of the License, or | ||
7 | * (at your option) any later version. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, write to the | ||
16 | * Free Software Foundation, Inc., | ||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
18 | */ | ||
19 | |||
20 | #pragma once | ||
21 | |||
22 | #include "entity_generated.h" | ||
23 | #include <QVariant> | ||
24 | #include <QString> | ||
25 | #include <functional> | ||
26 | #include "clientapi.h" //for domain parts | ||
27 | |||
28 | /** | ||
29 | * The property mapper holds accessor functions for all properties. | ||
30 | * | ||
31 | * It is by default initialized with accessors that access the local-only buffer, | ||
32 | * and resource simply have to overwrite those accessors. | ||
33 | */ | ||
34 | template<typename BufferType> | ||
35 | class PropertyMapper | ||
36 | { | ||
37 | public: | ||
38 | void setProperty(const QString &key, const QVariant &value, BufferType *buffer) | ||
39 | { | ||
40 | if (mWriteAccessors.contains(key)) { | ||
41 | auto accessor = mWriteAccessors.value(key); | ||
42 | return accessor(value, buffer); | ||
43 | } | ||
44 | } | ||
45 | |||
46 | virtual QVariant getProperty(const QString &key, BufferType const *buffer) const | ||
47 | { | ||
48 | if (mReadAccessors.contains(key)) { | ||
49 | auto accessor = mReadAccessors.value(key); | ||
50 | return accessor(buffer); | ||
51 | } | ||
52 | return QVariant(); | ||
53 | } | ||
54 | QHash<QString, std::function<QVariant(BufferType const *)> > mReadAccessors; | ||
55 | QHash<QString, std::function<void(const QVariant &, BufferType*)> > mWriteAccessors; | ||
56 | }; | ||
57 | |||
58 | //The factory should define how to go from an entitybuffer (local + resource buffer), to a domain type adapter. | ||
59 | //It defines how values are split accross local and resource buffer. | ||
60 | //This is required by the facade the read the value, and by the pipeline preprocessors to access the domain values in a generic way. | ||
61 | // template<typename DomainType, typename LocalBuffer, typename ResourceBuffer> | ||
62 | // class DomainTypeAdaptorFactory | ||
63 | // { | ||
64 | // }; | ||
65 | |||
66 | template<typename DomainType, typename LocalBuffer, typename ResourceBuffer> | ||
67 | class DomainTypeAdaptorFactory/* <typename DomainType, LocalBuffer, ResourceBuffer> */ | ||
68 | { | ||
69 | public: | ||
70 | virtual QSharedPointer<Akonadi2::Domain::BufferAdaptor> createAdaptor(const Akonadi2::Entity &entity) = 0; | ||
71 | |||
72 | protected: | ||
73 | QSharedPointer<PropertyMapper<LocalBuffer> > mLocalMapper; | ||
74 | QSharedPointer<PropertyMapper<ResourceBuffer> > mResourceMapper; | ||
75 | }; | ||
76 | |||
77 | |||