summaryrefslogtreecommitdiffstats
path: root/common/typeindex.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'common/typeindex.cpp')
-rw-r--r--common/typeindex.cpp40
1 files changed, 34 insertions, 6 deletions
diff --git a/common/typeindex.cpp b/common/typeindex.cpp
index 153aa43..5a19839 100644
--- a/common/typeindex.cpp
+++ b/common/typeindex.cpp
@@ -21,18 +21,20 @@
21#include "log.h" 21#include "log.h"
22#include "index.h" 22#include "index.h"
23#include <QDateTime> 23#include <QDateTime>
24 24#include <QDataStream>
25SINK_DEBUG_AREA("typeindex")
26 25
27using namespace Sink; 26using namespace Sink;
28 27
29static QByteArray getByteArray(const QVariant &value) 28static QByteArray getByteArray(const QVariant &value)
30{ 29{
31 if (value.type() == QVariant::DateTime) { 30 if (value.type() == QVariant::DateTime) {
32 const auto result = value.toDateTime().toString().toLatin1(); 31 QByteArray result;
33 if (result.isEmpty()) { 32 QDataStream ds(&result, QIODevice::WriteOnly);
34 return "nodate"; 33 ds << value.toDateTime();
35 } 34 return result;
35 }
36 if (value.type() == QVariant::Bool) {
37 return value.toBool() ? "t" : "f";
36 } 38 }
37 if (value.canConvert<Sink::ApplicationDomain::Reference>()) { 39 if (value.canConvert<Sink::ApplicationDomain::Reference>()) {
38 const auto ba = value.value<Sink::ApplicationDomain::Reference>().value; 40 const auto ba = value.value<Sink::ApplicationDomain::Reference>().value;
@@ -85,6 +87,20 @@ void TypeIndex::addProperty<QByteArray>(const QByteArray &property)
85} 87}
86 88
87template <> 89template <>
90void TypeIndex::addProperty<bool>(const QByteArray &property)
91{
92 auto indexer = [this, property](bool add, const QByteArray &identifier, const QVariant &value, Sink::Storage::DataStore::Transaction &transaction) {
93 if (add) {
94 Index(indexName(property), transaction).add(getByteArray(value), identifier);
95 } else {
96 Index(indexName(property), transaction).remove(getByteArray(value), identifier);
97 }
98 };
99 mIndexer.insert(property, indexer);
100 mProperties << property;
101}
102
103template <>
88void TypeIndex::addProperty<QString>(const QByteArray &property) 104void TypeIndex::addProperty<QString>(const QByteArray &property)
89{ 105{
90 auto indexer = [this, property](bool add, const QByteArray &identifier, const QVariant &value, Sink::Storage::DataStore::Transaction &transaction) { 106 auto indexer = [this, property](bool add, const QByteArray &identifier, const QVariant &value, Sink::Storage::DataStore::Transaction &transaction) {
@@ -266,6 +282,18 @@ void TypeIndex::index<QString, QByteArray>(const QByteArray &leftName, const QBy
266} 282}
267 283
268template <> 284template <>
285void TypeIndex::unindex<QByteArray, QByteArray>(const QByteArray &leftName, const QByteArray &rightName, const QVariant &leftValue, const QVariant &rightValue, Sink::Storage::DataStore::Transaction &transaction)
286{
287 Index(indexName(leftName + rightName), transaction).remove(getByteArray(leftValue), getByteArray(rightValue));
288}
289
290template <>
291void TypeIndex::unindex<QString, QByteArray>(const QByteArray &leftName, const QByteArray &rightName, const QVariant &leftValue, const QVariant &rightValue, Sink::Storage::DataStore::Transaction &transaction)
292{
293 Index(indexName(leftName + rightName), transaction).remove(getByteArray(leftValue), getByteArray(rightValue));
294}
295
296template <>
269QVector<QByteArray> TypeIndex::secondaryLookup<QByteArray>(const QByteArray &leftName, const QByteArray &rightName, const QVariant &value) 297QVector<QByteArray> TypeIndex::secondaryLookup<QByteArray>(const QByteArray &leftName, const QByteArray &rightName, const QVariant &value)
270{ 298{
271 QVector<QByteArray> keys; 299 QVector<QByteArray> keys;