summaryrefslogtreecommitdiffstats
path: root/common/domain
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2015-05-31 20:16:23 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2015-05-31 20:16:23 +0200
commite297fb92c2c0e344d36e0aef57921f6b9b921a61 (patch)
treeab36c3a121f3f132235ed3eafb5eb5d767c77b3b /common/domain
parent0815156ef93cb9f48073a777b888ed47b579d695 (diff)
downloadsink-e297fb92c2c0e344d36e0aef57921f6b9b921a61.tar.gz
sink-e297fb92c2c0e344d36e0aef57921f6b9b921a61.zip
Moved default read/write property mapper to TypeImplementation
There is always exactly one default buffer that we can centralize in TypeImplementation.
Diffstat (limited to 'common/domain')
-rw-r--r--common/domain/applicationdomaintype.h9
-rw-r--r--common/domain/event.cpp34
-rw-r--r--common/domain/event.h19
3 files changed, 56 insertions, 6 deletions
diff --git a/common/domain/applicationdomaintype.h b/common/domain/applicationdomaintype.h
index 2de1460..f2a4ad6 100644
--- a/common/domain/applicationdomaintype.h
+++ b/common/domain/applicationdomaintype.h
@@ -130,5 +130,14 @@ QByteArray getTypeName<Todo>();
130template<> 130template<>
131QByteArray getTypeName<AkonadiResource>(); 131QByteArray getTypeName<AkonadiResource>();
132 132
133/**
134 * Type implementation.
135 *
136 * Needs to be implemented for every application domain type.
137 * Contains all non-resource specific, but type-specific code.
138 */
139template<typename DomainType>
140class TypeImplementation;
141
133} 142}
134} 143}
diff --git a/common/domain/event.cpp b/common/domain/event.cpp
index 86100b7..ea0931c 100644
--- a/common/domain/event.cpp
+++ b/common/domain/event.cpp
@@ -20,15 +20,19 @@
20 20
21#include <QVector> 21#include <QVector>
22#include <QByteArray> 22#include <QByteArray>
23#include <QString>
23 24
24#include "../resultset.h" 25#include "../resultset.h"
25#include "../index.h" 26#include "../index.h"
26#include "../storage.h" 27#include "../storage.h"
27#include "../log.h" 28#include "../log.h"
29#include "../propertymapper.h"
30
31#include "event_generated.h"
28 32
29using namespace Akonadi2::ApplicationDomain; 33using namespace Akonadi2::ApplicationDomain;
30 34
31ResultSet EventImplementation::queryIndexes(const Akonadi2::Query &query, const QByteArray &resourceInstanceIdentifier) 35ResultSet TypeImplementation<Event>::queryIndexes(const Akonadi2::Query &query, const QByteArray &resourceInstanceIdentifier)
32{ 36{
33 QVector<QByteArray> keys; 37 QVector<QByteArray> keys;
34 if (query.propertyFilter.contains("uid")) { 38 if (query.propertyFilter.contains("uid")) {
@@ -43,7 +47,7 @@ ResultSet EventImplementation::queryIndexes(const Akonadi2::Query &query, const
43 return ResultSet(keys); 47 return ResultSet(keys);
44} 48}
45 49
46void EventImplementation::index(const Event &type) 50void TypeImplementation<Event>::index(const Event &type)
47{ 51{
48 Index uidIndex(Akonadi2::Store::storageLocation(), type.resourceInstanceIdentifier() + "index.uid", Akonadi2::Storage::ReadWrite); 52 Index uidIndex(Akonadi2::Store::storageLocation(), type.resourceInstanceIdentifier() + "index.uid", Akonadi2::Storage::ReadWrite);
49 const auto uid = type.getProperty("uid"); 53 const auto uid = type.getProperty("uid");
@@ -51,3 +55,29 @@ void EventImplementation::index(const Event &type)
51 uidIndex.add(uid.toByteArray(), type.identifier()); 55 uidIndex.add(uid.toByteArray(), type.identifier());
52 } 56 }
53} 57}
58
59QSharedPointer<ReadPropertyMapper<Buffer::Event> > TypeImplementation<Event>::initializeReadPropertyMapper()
60{
61 auto propertyMapper = QSharedPointer<ReadPropertyMapper<Buffer::Event> >::create();
62 propertyMapper->addMapping("summary", [](Buffer::Event const *buffer) -> QVariant {
63 return propertyToVariant<QString>(buffer->summary());
64 });
65 propertyMapper->addMapping("uid", [](Buffer::Event const *buffer) -> QVariant {
66 return propertyToVariant<QString>(buffer->uid());
67 });
68 return propertyMapper;
69}
70
71QSharedPointer<WritePropertyMapper<Buffer::EventBuilder> > TypeImplementation<Event>::initializeWritePropertyMapper()
72{
73 auto propertyMapper = QSharedPointer<WritePropertyMapper<Buffer::EventBuilder> >::create();
74 propertyMapper->addMapping("summary", [](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function<void(Buffer::EventBuilder &)> {
75 auto offset = variantToProperty<QString>(value, fbb);
76 return [offset](Buffer::EventBuilder &builder) { builder.add_summary(offset); };
77 });
78 propertyMapper->addMapping("uid", [](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function<void(Buffer::EventBuilder &)> {
79 auto offset = variantToProperty<QString>(value, fbb);
80 return [offset](Buffer::EventBuilder &builder) { builder.add_uid(offset); };
81 });
82 return propertyMapper;
83}
diff --git a/common/domain/event.h b/common/domain/event.h
index 4cb0d34..d4ce20e 100644
--- a/common/domain/event.h
+++ b/common/domain/event.h
@@ -23,23 +23,34 @@
23class ResultSet; 23class ResultSet;
24class QByteArray; 24class QByteArray;
25 25
26template<typename T>
27class ReadPropertyMapper;
28template<typename T>
29class WritePropertyMapper;
30
26namespace Akonadi2 { 31namespace Akonadi2 {
27 class Query; 32 class Query;
28 33
29namespace ApplicationDomain { 34namespace ApplicationDomain {
35 namespace Buffer {
36 class Event;
37 class EventBuilder;
38 }
30 39
31/** 40/**
32 * Implements all type-specific code such as updating and querying indexes. 41 * Implements all type-specific code such as updating and querying indexes.
33 */ 42 */
34namespace EventImplementation { 43template<>
35 typedef Event DomainType; 44struct TypeImplementation<Akonadi2::ApplicationDomain::Event> {
36 /** 45 /**
37 * Returns the potential result set based on the indexes. 46 * Returns the potential result set based on the indexes.
38 * 47 *
39 * An empty result set indicates that a full scan is required. 48 * An empty result set indicates that a full scan is required.
40 */ 49 */
41 ResultSet queryIndexes(const Akonadi2::Query &query, const QByteArray &resourceInstanceIdentifier); 50 static ResultSet queryIndexes(const Akonadi2::Query &query, const QByteArray &resourceInstanceIdentifier);
42 void index(const Event &type); 51 static void index(const Event &type);
52 static QSharedPointer<ReadPropertyMapper<Akonadi2::ApplicationDomain::Buffer::Event> > initializeReadPropertyMapper();
53 static QSharedPointer<WritePropertyMapper<Akonadi2::ApplicationDomain::Buffer::EventBuilder> > initializeWritePropertyMapper();
43}; 54};
44 55
45} 56}