From e85967518b9041e9943ec5f1765c6694bb153840 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sun, 12 Apr 2015 16:02:10 +0200 Subject: More generic domainadpator code. This should cover read and write for entites that have a 1:1 mapping to the resource buffers. --- common/domainadaptor.h | 95 ++++++++++++++++++++++++-------------------------- 1 file changed, 45 insertions(+), 50 deletions(-) (limited to 'common/domainadaptor.h') diff --git a/common/domainadaptor.h b/common/domainadaptor.h index 5d9574b..e356692 100644 --- a/common/domainadaptor.h +++ b/common/domainadaptor.h @@ -77,6 +77,39 @@ private: QHash(const QVariant &, flatbuffers::FlatBufferBuilder &)> > mWriteAccessors; }; +/** + * Defines how to convert qt primitives to flatbuffer ones + * TODO: rename to createProperty or so? + */ +template +flatbuffers::uoffset_t extractProperty(const QVariant &, flatbuffers::FlatBufferBuilder &fbb); + +/** + * Create a buffer from a domain object using the provided mappings + */ +template +flatbuffers::Offset createBufferPart(const Akonadi2::ApplicationDomain::ApplicationDomainType &domainObject, flatbuffers::FlatBufferBuilder &fbb, const WritePropertyMapper &mapper) +{ + //First create a primitives such as strings using the mappings + QList > propertiesToAddToResource; + for (const auto &property : domainObject.changedProperties()) { + qWarning() << "copying property " << property; + const auto value = domainObject.getProperty(property); + if (mapper.hasMapping(property)) { + mapper.setProperty(property, domainObject.getProperty(property), propertiesToAddToResource, fbb); + } else { + qWarning() << "no mapping for property available " << property; + } + } + + //Then create all porperties using the above generated builderCalls + Builder builder(fbb); + for (auto propertyBuilder : propertiesToAddToResource) { + propertyBuilder(builder); + } + return builder.Finish(); +} + /** * A generic adaptor implementation that uses a property mapper to read/write values. * @@ -95,11 +128,6 @@ public: //TODO remove void setProperty(const QByteArray &key, const QVariant &value) { - // if (mResourceMapper && mResourceMapper->hasMapping(key)) { - // // mResourceMapper->setProperty(key, value, mResourceBuffer); - // } else { - // // mLocalMapper.; - // } } virtual QVariant getProperty(const QByteArray &key) const @@ -127,49 +155,6 @@ public: QSharedPointer > mResourceMapper; }; -/** - * A generic adaptor implementation that uses a property mapper to read/write values. - */ -template -class GenericWriteBufferAdaptor : public Akonadi2::ApplicationDomain::BufferAdaptor -{ -public: - GenericWriteBufferAdaptor(const BufferAdaptor &buffer) - : BufferAdaptor() - { - for(const auto &property : buffer.availableProperties()) { - setProperty(property, buffer.getProperty(property)); - } - } - - void setProperty(const QByteArray &key, const QVariant &value) - { - // if (mResourceMapper && mResourceMapper->hasMapping(key)) { - // // mResourceMapper->setProperty(key, value, mResourceBuffer); - // } else { - // // mLocalMapper.; - // } - } - - //TODO remove - virtual QVariant getProperty(const QByteArray &key) const - { - Q_ASSERT(false); - } - - virtual QList availableProperties() const - { - Q_ASSERT(false); - QList props; - return props; - } - - // LocalBuffer const *mLocalBuffer; - // ResourceBuffer const *mResourceBuffer; - QSharedPointer > mLocalMapper; - QSharedPointer > mResourceMapper; -}; - /** * Initializes the local property mapper. * @@ -178,16 +163,24 @@ public: template QSharedPointer > initializeReadPropertyMapper(); +template +QSharedPointer > initializeWritePropertyMapper(); + /** * The factory should define how to go from an entitybuffer (local + resource buffer), to a domain type adapter. * It defines how values are split accross local and resource buffer. * This is required by the facade the read the value, and by the pipeline preprocessors to access the domain values in a generic way. */ -template +template class DomainTypeAdaptorFactory { public: - DomainTypeAdaptorFactory() : mLocalMapper(initializeReadPropertyMapper()) {}; + DomainTypeAdaptorFactory() : + mLocalMapper(initializeReadPropertyMapper()), + mResourceMapper(QSharedPointer >::create()), + mLocalWriteMapper(initializeWritePropertyMapper()), + mResourceWriteMapper(QSharedPointer >::create()) + {}; virtual ~DomainTypeAdaptorFactory() {}; /** @@ -214,6 +207,8 @@ public: protected: QSharedPointer > mLocalMapper; QSharedPointer > mResourceMapper; + QSharedPointer > mLocalWriteMapper; + QSharedPointer > mResourceWriteMapper; }; -- cgit v1.2.3