From 6b8432a5c0647d8fbe3cda549574ae13e07bb2f4 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 28 Apr 2017 11:48:06 +0200 Subject: Simplified propertymapper --- common/domain/typeimplementations.cpp | 10 ++-- common/domain/typeimplementations.h | 11 ++-- common/domainadaptor.h | 12 ++-- common/propertymapper.h | 109 ++++------------------------------ 4 files changed, 29 insertions(+), 113 deletions(-) diff --git a/common/domain/typeimplementations.cpp b/common/domain/typeimplementations.cpp index eb3851e..5db35b7 100644 --- a/common/domain/typeimplementations.cpp +++ b/common/domain/typeimplementations.cpp @@ -61,7 +61,7 @@ void TypeImplementation::configure(IndexPropertyMapper &indexPropertyMappe }); } -void TypeImplementation::configure(ReadPropertyMapper &propertyMapper) +void TypeImplementation::configure(ReadPropertyMapper &propertyMapper) { propertyMapper.addMapping(&Buffer::sender); propertyMapper.addMapping(&Buffer::to); @@ -108,7 +108,7 @@ void TypeImplementation::configure(TypeIndex &index) index.addProperty(Folder::Name::name); } -void TypeImplementation::configure(ReadPropertyMapper &propertyMapper) +void TypeImplementation::configure(ReadPropertyMapper &propertyMapper) { propertyMapper.addMapping(&Buffer::parent); propertyMapper.addMapping(&Buffer::name); @@ -137,7 +137,7 @@ void TypeImplementation::configure(TypeIndex &index) index.addProperty(Contact::Uid::name); } -void TypeImplementation::configure(ReadPropertyMapper &propertyMapper) +void TypeImplementation::configure(ReadPropertyMapper &propertyMapper) { propertyMapper.addMapping(&Buffer::uid); propertyMapper.addMapping(&Buffer::fn); @@ -171,7 +171,7 @@ void TypeImplementation::configure(TypeIndex &index) index.addProperty(Addressbook::Name::name); } -void TypeImplementation::configure(ReadPropertyMapper &propertyMapper) +void TypeImplementation::configure(ReadPropertyMapper &propertyMapper) { propertyMapper.addMapping(&Buffer::parent); propertyMapper.addMapping(&Buffer::name); @@ -194,7 +194,7 @@ void TypeImplementation::configure(TypeIndex &index) index.addProperty(Event::Uid::name); } -void TypeImplementation::configure(ReadPropertyMapper &propertyMapper) +void TypeImplementation::configure(ReadPropertyMapper &propertyMapper) { propertyMapper.addMapping(&Buffer::summary); propertyMapper.addMapping(&Buffer::description); diff --git a/common/domain/typeimplementations.h b/common/domain/typeimplementations.h index 37d6ca9..705b059 100644 --- a/common/domain/typeimplementations.h +++ b/common/domain/typeimplementations.h @@ -26,7 +26,6 @@ #include "contact_generated.h" #include "addressbook_generated.h" -template class ReadPropertyMapper; template class WritePropertyMapper; @@ -48,7 +47,7 @@ public: typedef Sink::ApplicationDomain::Buffer::Mail Buffer; typedef Sink::ApplicationDomain::Buffer::MailBuilder BufferBuilder; static void configure(TypeIndex &index); - static void configure(ReadPropertyMapper &propertyMapper); + static void configure(ReadPropertyMapper &propertyMapper); static void configure(WritePropertyMapper &propertyMapper); static void configure(IndexPropertyMapper &indexPropertyMapper); }; @@ -59,7 +58,7 @@ public: typedef Sink::ApplicationDomain::Buffer::Folder Buffer; typedef Sink::ApplicationDomain::Buffer::FolderBuilder BufferBuilder; static void configure(TypeIndex &); - static void configure(ReadPropertyMapper &); + static void configure(ReadPropertyMapper &); static void configure(WritePropertyMapper &); static void configure(IndexPropertyMapper &indexPropertyMapper); }; @@ -70,7 +69,7 @@ public: typedef Sink::ApplicationDomain::Buffer::Contact Buffer; typedef Sink::ApplicationDomain::Buffer::ContactBuilder BufferBuilder; static void configure(TypeIndex &); - static void configure(ReadPropertyMapper &); + static void configure(ReadPropertyMapper &); static void configure(WritePropertyMapper &); static void configure(IndexPropertyMapper &indexPropertyMapper); }; @@ -81,7 +80,7 @@ public: typedef Sink::ApplicationDomain::Buffer::Addressbook Buffer; typedef Sink::ApplicationDomain::Buffer::AddressbookBuilder BufferBuilder; static void configure(TypeIndex &); - static void configure(ReadPropertyMapper &); + static void configure(ReadPropertyMapper &); static void configure(WritePropertyMapper &); static void configure(IndexPropertyMapper &indexPropertyMapper); }; @@ -92,7 +91,7 @@ public: typedef Sink::ApplicationDomain::Buffer::Event Buffer; typedef Sink::ApplicationDomain::Buffer::EventBuilder BufferBuilder; static void configure(TypeIndex &); - static void configure(ReadPropertyMapper &); + static void configure(ReadPropertyMapper &); static void configure(WritePropertyMapper &); static void configure(IndexPropertyMapper &indexPropertyMapper); }; diff --git a/common/domainadaptor.h b/common/domainadaptor.h index af5d5fc..9182001 100644 --- a/common/domainadaptor.h +++ b/common/domainadaptor.h @@ -157,8 +157,8 @@ public: LocalBuffer const *mLocalBuffer; ResourceBuffer const *mResourceBuffer; - QSharedPointer> mLocalMapper; - QSharedPointer> mResourceMapper; + QSharedPointer mLocalMapper; + QSharedPointer mResourceMapper; QSharedPointer mIndexMapper; TypeIndex *mIndex; }; @@ -176,8 +176,8 @@ class SINK_EXPORT DomainTypeAdaptorFactory : public DomainTypeAdaptorFactoryInte public: DomainTypeAdaptorFactory() - : mLocalMapper(QSharedPointer>::create()), - mResourceMapper(QSharedPointer>::create()), + : mLocalMapper(QSharedPointer::create()), + mResourceMapper(QSharedPointer::create()), mLocalWriteMapper(QSharedPointer>::create()), mResourceWriteMapper(QSharedPointer>::create()), mIndexMapper(QSharedPointer::create()) @@ -236,8 +236,8 @@ public: protected: - QSharedPointer> mLocalMapper; - QSharedPointer> mResourceMapper; + QSharedPointer mLocalMapper; + QSharedPointer mResourceMapper; QSharedPointer> mLocalWriteMapper; QSharedPointer> mResourceWriteMapper; QSharedPointer mIndexMapper; diff --git a/common/propertymapper.h b/common/propertymapper.h index 9ea0b73..bca45aa 100644 --- a/common/propertymapper.h +++ b/common/propertymapper.h @@ -65,13 +65,12 @@ QVariant SINK_EXPORT propertyToVariant(const flatbuffers::Vector class ReadPropertyMapper { public: virtual ~ReadPropertyMapper(){}; - virtual QVariant getProperty(const QByteArray &key, BufferType const *buffer) const + virtual QVariant getProperty(const QByteArray &key, void const *buffer) const { if (mReadAccessors.contains(key)) { auto accessor = mReadAccessors.value(key); @@ -79,69 +78,30 @@ public: } return QVariant(); } + bool hasMapping(const QByteArray &key) const { return mReadAccessors.contains(key); } + QList availableProperties() const { return mReadAccessors.keys(); } - void addMapping(const QByteArray &property, const std::function &mapping) - { - mReadAccessors.insert(property, mapping); - } - - template - void addMapping(const flatbuffers::String *(Buffer::*f)() const) - { - addMapping(T::name, [f](Buffer const *buffer) -> QVariant { return propertyToVariant((buffer->*f)()); }); - } - - template - void addMapping(uint8_t (Buffer::*f)() const) - { - addMapping(T::name, [f](Buffer const *buffer) -> QVariant { return propertyToVariant((buffer->*f)()); }); - } - - template - void addMapping(bool (Buffer::*f)() const) - { - addMapping(T::name, [f](Buffer const *buffer) -> QVariant { return propertyToVariant((buffer->*f)()); }); - } - - template - void addMapping(const flatbuffers::Vector *(Buffer::*f)() const) - { - addMapping(T::name, [f](Buffer const *buffer) -> QVariant { return propertyToVariant((buffer->*f)()); }); - } - template - void addMapping(const flatbuffers::Vector> *(Buffer::*f)() const) + void addMapping(const QByteArray &property, const std::function &mapping) { - addMapping(T::name, [f](Buffer const *buffer) -> QVariant { return propertyToVariant((buffer->*f)()); }); - } - - template - void addMapping(const Sink::ApplicationDomain::Buffer::MailContact *(Buffer::*f)() const) - { - addMapping(T::name, [f](Buffer const *buffer) -> QVariant { return propertyToVariant((buffer->*f)()); }); - } - - template - void addMapping(const flatbuffers::Vector> *(Buffer::*f)() const) - { - addMapping(T::name, [f](Buffer const *buffer) -> QVariant { return propertyToVariant((buffer->*f)()); }); + mReadAccessors.insert(property, mapping); } - template - void addMapping(const flatbuffers::Vector> *(Buffer::*f)() const) + template + void addMapping(FunctionReturnValue (Buffer::*f)() const) { - addMapping(T::name, [f](Buffer const *buffer) -> QVariant { return propertyToVariant((buffer->*f)()); }); + addMapping(T::name, [f](void const *buffer) -> QVariant { return propertyToVariant((static_cast(buffer)->*f)()); }); } private: - QHash> mReadAccessors; + QHash> mReadAccessors; }; template @@ -157,10 +117,12 @@ public: builderCalls << accessor(value, fbb); } } + bool hasMapping(const QByteArray &key) const { return mWriteAccessors.contains(key); } + void addMapping(const QByteArray &property, const std::function(const QVariant &, flatbuffers::FlatBufferBuilder &)> &mapping) { mWriteAccessors.insert(property, mapping); @@ -182,53 +144,8 @@ public: }); } - template - void addMapping(void (BufferBuilder::*f)(flatbuffers::Offset)) - { - addMapping(T::name, [f](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function { - auto offset = variantToProperty(value, fbb); - return [offset, f](BufferBuilder &builder) { (builder.*f)(offset); }; - }); - } - - template - void addMapping(void (BufferBuilder::*f)(flatbuffers::Offset>)) - { - addMapping(T::name, [f](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function { - auto offset = variantToProperty(value, fbb); - return [offset, f](BufferBuilder &builder) { (builder.*f)(offset); }; - }); - } - - template - void addMapping(void (BufferBuilder::*f)(flatbuffers::Offset>>)) - { - addMapping(T::name, [f](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function { - auto offset = variantToProperty(value, fbb); - return [offset, f](BufferBuilder &builder) { (builder.*f)(offset); }; - }); - } - - template - void addMapping(void (BufferBuilder::*f)(flatbuffers::Offset)) - { - addMapping(T::name, [f](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function { - auto offset = variantToProperty(value, fbb); - return [offset, f](BufferBuilder &builder) { (builder.*f)(offset); }; - }); - } - - template - void addMapping(void (BufferBuilder::*f)(flatbuffers::Offset>>)) - { - addMapping(T::name, [f](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function { - auto offset = variantToProperty(value, fbb); - return [offset, f](BufferBuilder &builder) { (builder.*f)(offset); }; - }); - } - - template - void addMapping(void (BufferBuilder::*f)(flatbuffers::Offset>>)) + template + void addMapping(void (BufferBuilder::*f)(flatbuffers::Offset)) { addMapping(T::name, [f](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function { auto offset = variantToProperty(value, fbb); -- cgit v1.2.3