summaryrefslogtreecommitdiffstats
path: root/common/storage/entitystore.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-11-30 16:08:09 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-11-30 16:08:09 +0100
commite88ffd5209d58118fcc947a060c35504316da855 (patch)
tree8a75b909f8cb84479e41ac55025ba3e1adc75705 /common/storage/entitystore.cpp
parente13e8dd740a7d3b36915bba272cb5a8ea965eff2 (diff)
downloadsink-e88ffd5209d58118fcc947a060c35504316da855.tar.gz
sink-e88ffd5209d58118fcc947a060c35504316da855.zip
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).
Diffstat (limited to 'common/storage/entitystore.cpp')
-rw-r--r--common/storage/entitystore.cpp21
1 files changed, 7 insertions, 14 deletions
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 @@
27#include "index.h" 27#include "index.h"
28#include "bufferutils.h" 28#include "bufferutils.h"
29#include "entity_generated.h" 29#include "entity_generated.h"
30#include "applicationdomaintype_p.h"
30 31
31#include "mail.h" 32#include "mail.h"
32#include "folder.h" 33#include "folder.h"
@@ -57,20 +58,12 @@ public:
57 return transaction; 58 return transaction;
58 } 59 }
59 60
60 template<typename ...Args> 61 template <class T>
61 void configure(const QByteArray &type, Args && ... args) 62 struct ConfigureHelper {
62 { 63 void operator()(TypeIndex &arg) const {
63 if (type == ApplicationDomain::getTypeName<ApplicationDomain::Folder>()) { 64 ApplicationDomain::TypeImplementation<T>::configure(arg);
64 ApplicationDomain::TypeImplementation<ApplicationDomain::Folder>::configure(std::forward<Args...>(args...));
65 } else if (type == ApplicationDomain::getTypeName<ApplicationDomain::Mail>()) {
66 ApplicationDomain::TypeImplementation<ApplicationDomain::Mail>::configure(std::forward<Args...>(args...));
67 } else if (type == ApplicationDomain::getTypeName<ApplicationDomain::Event>()) {
68 ApplicationDomain::TypeImplementation<ApplicationDomain::Event>::configure(std::forward<Args...>(args...));
69 } else {
70 Q_ASSERT(false);
71 SinkError() << "Unkonwn type " << type;
72 } 65 }
73 } 66 };
74 67
75 TypeIndex &cachedIndex(const QByteArray &type) 68 TypeIndex &cachedIndex(const QByteArray &type)
76 { 69 {
@@ -78,7 +71,7 @@ public:
78 return *indexByType.value(type); 71 return *indexByType.value(type);
79 } 72 }
80 auto index = QSharedPointer<TypeIndex>::create(type); 73 auto index = QSharedPointer<TypeIndex>::create(type);
81 configure(type, *index); 74 TypeHelper<ConfigureHelper>{type}.template operator()<void>(*index);
82 indexByType.insert(type, index); 75 indexByType.insert(type, index);
83 return *index; 76 return *index;
84 77