diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-05-31 20:51:09 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-05-31 20:51:09 +0200 |
commit | 9a9557b6431e8d27420603f4895e480d766f6ae2 (patch) | |
tree | 7a076e30c52c0a0d753b061ccf471d11cf5b3c79 | |
parent | 69a3900feb4a0277d4e70e44256c9b37be78a2d5 (diff) | |
download | sink-9a9557b6431e8d27420603f4895e480d766f6ae2.tar.gz sink-9a9557b6431e8d27420603f4895e480d766f6ae2.zip |
Use type implementation to define default buffer and buffer-builder
-rw-r--r-- | common/domain/event.cpp | 20 | ||||
-rw-r--r-- | common/domain/event.h | 9 | ||||
-rw-r--r-- | common/domainadaptor.h | 16 | ||||
-rw-r--r-- | examples/dummyresource/domainadaptor.h | 2 | ||||
-rw-r--r-- | tests/domainadaptortest.cpp | 2 |
5 files changed, 21 insertions, 28 deletions
diff --git a/common/domain/event.cpp b/common/domain/event.cpp index ea0931c..776fa50 100644 --- a/common/domain/event.cpp +++ b/common/domain/event.cpp | |||
@@ -56,28 +56,28 @@ void TypeImplementation<Event>::index(const Event &type) | |||
56 | } | 56 | } |
57 | } | 57 | } |
58 | 58 | ||
59 | QSharedPointer<ReadPropertyMapper<Buffer::Event> > TypeImplementation<Event>::initializeReadPropertyMapper() | 59 | QSharedPointer<ReadPropertyMapper<TypeImplementation<Event>::Buffer> > TypeImplementation<Event>::initializeReadPropertyMapper() |
60 | { | 60 | { |
61 | auto propertyMapper = QSharedPointer<ReadPropertyMapper<Buffer::Event> >::create(); | 61 | auto propertyMapper = QSharedPointer<ReadPropertyMapper<Buffer> >::create(); |
62 | propertyMapper->addMapping("summary", [](Buffer::Event const *buffer) -> QVariant { | 62 | propertyMapper->addMapping("summary", [](Buffer const *buffer) -> QVariant { |
63 | return propertyToVariant<QString>(buffer->summary()); | 63 | return propertyToVariant<QString>(buffer->summary()); |
64 | }); | 64 | }); |
65 | propertyMapper->addMapping("uid", [](Buffer::Event const *buffer) -> QVariant { | 65 | propertyMapper->addMapping("uid", [](Buffer const *buffer) -> QVariant { |
66 | return propertyToVariant<QString>(buffer->uid()); | 66 | return propertyToVariant<QString>(buffer->uid()); |
67 | }); | 67 | }); |
68 | return propertyMapper; | 68 | return propertyMapper; |
69 | } | 69 | } |
70 | 70 | ||
71 | QSharedPointer<WritePropertyMapper<Buffer::EventBuilder> > TypeImplementation<Event>::initializeWritePropertyMapper() | 71 | QSharedPointer<WritePropertyMapper<TypeImplementation<Event>::BufferBuilder> > TypeImplementation<Event>::initializeWritePropertyMapper() |
72 | { | 72 | { |
73 | auto propertyMapper = QSharedPointer<WritePropertyMapper<Buffer::EventBuilder> >::create(); | 73 | auto propertyMapper = QSharedPointer<WritePropertyMapper<BufferBuilder> >::create(); |
74 | propertyMapper->addMapping("summary", [](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function<void(Buffer::EventBuilder &)> { | 74 | propertyMapper->addMapping("summary", [](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function<void(BufferBuilder &)> { |
75 | auto offset = variantToProperty<QString>(value, fbb); | 75 | auto offset = variantToProperty<QString>(value, fbb); |
76 | return [offset](Buffer::EventBuilder &builder) { builder.add_summary(offset); }; | 76 | return [offset](BufferBuilder &builder) { builder.add_summary(offset); }; |
77 | }); | 77 | }); |
78 | propertyMapper->addMapping("uid", [](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function<void(Buffer::EventBuilder &)> { | 78 | propertyMapper->addMapping("uid", [](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function<void(BufferBuilder &)> { |
79 | auto offset = variantToProperty<QString>(value, fbb); | 79 | auto offset = variantToProperty<QString>(value, fbb); |
80 | return [offset](Buffer::EventBuilder &builder) { builder.add_uid(offset); }; | 80 | return [offset](BufferBuilder &builder) { builder.add_uid(offset); }; |
81 | }); | 81 | }); |
82 | return propertyMapper; | 82 | return propertyMapper; |
83 | } | 83 | } |
diff --git a/common/domain/event.h b/common/domain/event.h index d4ce20e..d40e55d 100644 --- a/common/domain/event.h +++ b/common/domain/event.h | |||
@@ -41,7 +41,10 @@ namespace ApplicationDomain { | |||
41 | * Implements all type-specific code such as updating and querying indexes. | 41 | * Implements all type-specific code such as updating and querying indexes. |
42 | */ | 42 | */ |
43 | template<> | 43 | template<> |
44 | struct TypeImplementation<Akonadi2::ApplicationDomain::Event> { | 44 | class TypeImplementation<Akonadi2::ApplicationDomain::Event> { |
45 | public: | ||
46 | typedef Akonadi2::ApplicationDomain::Buffer::Event Buffer; | ||
47 | typedef Akonadi2::ApplicationDomain::Buffer::EventBuilder BufferBuilder; | ||
45 | /** | 48 | /** |
46 | * Returns the potential result set based on the indexes. | 49 | * Returns the potential result set based on the indexes. |
47 | * | 50 | * |
@@ -49,8 +52,8 @@ struct TypeImplementation<Akonadi2::ApplicationDomain::Event> { | |||
49 | */ | 52 | */ |
50 | static ResultSet queryIndexes(const Akonadi2::Query &query, const QByteArray &resourceInstanceIdentifier); | 53 | static ResultSet queryIndexes(const Akonadi2::Query &query, const QByteArray &resourceInstanceIdentifier); |
51 | static void index(const Event &type); | 54 | static void index(const Event &type); |
52 | static QSharedPointer<ReadPropertyMapper<Akonadi2::ApplicationDomain::Buffer::Event> > initializeReadPropertyMapper(); | 55 | static QSharedPointer<ReadPropertyMapper<Buffer> > initializeReadPropertyMapper(); |
53 | static QSharedPointer<WritePropertyMapper<Akonadi2::ApplicationDomain::Buffer::EventBuilder> > initializeWritePropertyMapper(); | 56 | static QSharedPointer<WritePropertyMapper<BufferBuilder> > initializeWritePropertyMapper(); |
54 | }; | 57 | }; |
55 | 58 | ||
56 | } | 59 | } |
diff --git a/common/domainadaptor.h b/common/domainadaptor.h index 70c3a42..c9a3a01 100644 --- a/common/domainadaptor.h +++ b/common/domainadaptor.h | |||
@@ -25,7 +25,6 @@ | |||
25 | #include <functional> | 25 | #include <functional> |
26 | #include "clientapi.h" //for domain parts | 26 | #include "clientapi.h" //for domain parts |
27 | 27 | ||
28 | #include "event_generated.h" | ||
29 | #include "entity_generated.h" | 28 | #include "entity_generated.h" |
30 | #include "metadata_generated.h" | 29 | #include "metadata_generated.h" |
31 | #include "entitybuffer.h" | 30 | #include "entitybuffer.h" |
@@ -103,17 +102,6 @@ public: | |||
103 | QSharedPointer<ReadPropertyMapper<ResourceBuffer> > mResourceMapper; | 102 | QSharedPointer<ReadPropertyMapper<ResourceBuffer> > mResourceMapper; |
104 | }; | 103 | }; |
105 | 104 | ||
106 | /** | ||
107 | * Initializes the local property mapper. | ||
108 | * | ||
109 | * Provide an implementation for each application domain type. | ||
110 | */ | ||
111 | template <class T> | ||
112 | QSharedPointer<ReadPropertyMapper<T> > initializeReadPropertyMapper(); | ||
113 | |||
114 | template <class T> | ||
115 | QSharedPointer<WritePropertyMapper<T> > initializeWritePropertyMapper(); | ||
116 | |||
117 | template<typename DomainType> | 105 | template<typename DomainType> |
118 | class DomainTypeAdaptorFactoryInterface | 106 | class DomainTypeAdaptorFactoryInterface |
119 | { | 107 | { |
@@ -128,9 +116,11 @@ public: | |||
128 | * It defines how values are split accross local and resource buffer. | 116 | * It defines how values are split accross local and resource buffer. |
129 | * This is required by the facade the read the value, and by the pipeline preprocessors to access the domain values in a generic way. | 117 | * This is required by the facade the read the value, and by the pipeline preprocessors to access the domain values in a generic way. |
130 | */ | 118 | */ |
131 | template<typename DomainType, typename LocalBuffer, typename ResourceBuffer, typename LocalBuilder, typename ResourceBuilder> | 119 | template<typename DomainType, typename ResourceBuffer, typename ResourceBuilder> |
132 | class DomainTypeAdaptorFactory : public DomainTypeAdaptorFactoryInterface<DomainType> | 120 | class DomainTypeAdaptorFactory : public DomainTypeAdaptorFactoryInterface<DomainType> |
133 | { | 121 | { |
122 | typedef typename Akonadi2::ApplicationDomain::TypeImplementation<DomainType>::Buffer LocalBuffer; | ||
123 | typedef typename Akonadi2::ApplicationDomain::TypeImplementation<DomainType>::BufferBuilder LocalBuilder; | ||
134 | public: | 124 | public: |
135 | DomainTypeAdaptorFactory() : | 125 | DomainTypeAdaptorFactory() : |
136 | mLocalMapper(Akonadi2::ApplicationDomain::TypeImplementation<DomainType>::initializeReadPropertyMapper()), | 126 | mLocalMapper(Akonadi2::ApplicationDomain::TypeImplementation<DomainType>::initializeReadPropertyMapper()), |
diff --git a/examples/dummyresource/domainadaptor.h b/examples/dummyresource/domainadaptor.h index 9d351e7..0490387 100644 --- a/examples/dummyresource/domainadaptor.h +++ b/examples/dummyresource/domainadaptor.h | |||
@@ -5,7 +5,7 @@ | |||
5 | #include "dummycalendar_generated.h" | 5 | #include "dummycalendar_generated.h" |
6 | #include "entity_generated.h" | 6 | #include "entity_generated.h" |
7 | 7 | ||
8 | class DummyEventAdaptorFactory : public DomainTypeAdaptorFactory<Akonadi2::ApplicationDomain::Event, Akonadi2::ApplicationDomain::Buffer::Event, DummyCalendar::DummyEvent, Akonadi2::ApplicationDomain::Buffer::EventBuilder, DummyCalendar::DummyEventBuilder> | 8 | class DummyEventAdaptorFactory : public DomainTypeAdaptorFactory<Akonadi2::ApplicationDomain::Event, DummyCalendar::DummyEvent, DummyCalendar::DummyEventBuilder> |
9 | { | 9 | { |
10 | public: | 10 | public: |
11 | DummyEventAdaptorFactory(); | 11 | DummyEventAdaptorFactory(); |
diff --git a/tests/domainadaptortest.cpp b/tests/domainadaptortest.cpp index 97a78c2..ccf9a3c 100644 --- a/tests/domainadaptortest.cpp +++ b/tests/domainadaptortest.cpp | |||
@@ -13,7 +13,7 @@ | |||
13 | #include "metadata_generated.h" | 13 | #include "metadata_generated.h" |
14 | #include "entity_generated.h" | 14 | #include "entity_generated.h" |
15 | 15 | ||
16 | class TestFactory : public DomainTypeAdaptorFactory<Akonadi2::ApplicationDomain::Event, Akonadi2::ApplicationDomain::Buffer::Event, Akonadi2::ApplicationDomain::Buffer::Event, Akonadi2::ApplicationDomain::Buffer::EventBuilder, Akonadi2::ApplicationDomain::Buffer::EventBuilder> | 16 | class TestFactory : public DomainTypeAdaptorFactory<Akonadi2::ApplicationDomain::Event, Akonadi2::ApplicationDomain::Buffer::Event, Akonadi2::ApplicationDomain::Buffer::EventBuilder> |
17 | { | 17 | { |
18 | public: | 18 | public: |
19 | TestFactory() | 19 | TestFactory() |