From e88ffd5209d58118fcc947a060c35504316da855 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 30 Nov 2016 16:08:09 +0100 Subject: TypeHelper so we can centrally define the type dispatch Not pretty, but that at least allows us to centrally define the string to type dispatch (It's somehow very hard to do in C++ without repeating all types over and over in various interfaces). --- common/storage/entitystore.cpp | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'common/storage') diff --git a/common/storage/entitystore.cpp b/common/storage/entitystore.cpp index f6b8f43..b6251b6 100644 --- a/common/storage/entitystore.cpp +++ b/common/storage/entitystore.cpp @@ -27,6 +27,7 @@ #include "index.h" #include "bufferutils.h" #include "entity_generated.h" +#include "applicationdomaintype_p.h" #include "mail.h" #include "folder.h" @@ -57,20 +58,12 @@ public: return transaction; } - template - void configure(const QByteArray &type, Args && ... args) - { - if (type == ApplicationDomain::getTypeName()) { - ApplicationDomain::TypeImplementation::configure(std::forward(args...)); - } else if (type == ApplicationDomain::getTypeName()) { - ApplicationDomain::TypeImplementation::configure(std::forward(args...)); - } else if (type == ApplicationDomain::getTypeName()) { - ApplicationDomain::TypeImplementation::configure(std::forward(args...)); - } else { - Q_ASSERT(false); - SinkError() << "Unkonwn type " << type; + template + struct ConfigureHelper { + void operator()(TypeIndex &arg) const { + ApplicationDomain::TypeImplementation::configure(arg); } - } + }; TypeIndex &cachedIndex(const QByteArray &type) { @@ -78,7 +71,7 @@ public: return *indexByType.value(type); } auto index = QSharedPointer::create(type); - configure(type, *index); + TypeHelper{type}.template operator()(*index); indexByType.insert(type, index); return *index; -- cgit v1.2.3