From 4067462b0a27984df84b0379c19122d574253dfb Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sat, 3 Jan 2015 00:08:44 +0100 Subject: Shared domain adaptors between resource and facade. --- common/domainadaptor.h | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 common/domainadaptor.h (limited to 'common/domainadaptor.h') 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 @@ +/* + * Copyright (C) 2014 Christian Mollekopf + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#pragma once + +#include "entity_generated.h" +#include +#include +#include +#include "clientapi.h" //for domain parts + +/** + * The property mapper holds accessor functions for all properties. + * + * It is by default initialized with accessors that access the local-only buffer, + * and resource simply have to overwrite those accessors. + */ +template +class PropertyMapper +{ +public: + void setProperty(const QString &key, const QVariant &value, BufferType *buffer) + { + if (mWriteAccessors.contains(key)) { + auto accessor = mWriteAccessors.value(key); + return accessor(value, buffer); + } + } + + virtual QVariant getProperty(const QString &key, BufferType const *buffer) const + { + if (mReadAccessors.contains(key)) { + auto accessor = mReadAccessors.value(key); + return accessor(buffer); + } + return QVariant(); + } + QHash > mReadAccessors; + QHash > mWriteAccessors; +}; + +//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 +// class DomainTypeAdaptorFactory +// { +// }; + +template +class DomainTypeAdaptorFactory/* */ +{ +public: + virtual QSharedPointer createAdaptor(const Akonadi2::Entity &entity) = 0; + +protected: + QSharedPointer > mLocalMapper; + QSharedPointer > mResourceMapper; +}; + + -- cgit v1.2.3