/* * Copyright (C) 2015 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. */ #include "typeindex.h" #include template void mergeImpl(T &map, First f) { for (auto it = f.constBegin(); it != f.constEnd(); it++) { map.insert(it.key(), it.value()); } } template void mergeImpl(T &map, First f, Tail ...maps) { for (auto it = f.constBegin(); it != f.constEnd(); it++) { map.insert(it.key(), it.value()); } mergeImpl(map, maps...); } template First merge(First f, Tail ...maps) { First map; mergeImpl(map, f, maps...); return map; } template class ValueIndex { public: static void configure(TypeIndex &index) { index.addProperty(); } template static QMap databases() { return {{QByteArray{EntityType::name} +".index." + Property::name, 1}}; } }; template class SortedIndex { public: static void configure(TypeIndex &index) { index.addPropertyWithSorting(); } template static QMap databases() { return {{QByteArray{EntityType::name} +".index." + Property::name + ".sort." + SortProperty::name, 1}}; } }; template class SecondaryIndex { public: static void configure(TypeIndex &index) { index.addSecondaryProperty(); } template static QMap databases() { return {{QByteArray{EntityType::name} +".index." + Property::name + SecondaryProperty::name, 1}}; } }; template class CustomSecondaryIndex { public: static void configure(TypeIndex &index) { index.addSecondaryPropertyIndexer(); } template static QMap databases() { return Indexer::databases(); } }; template class IndexConfig { template static void applyIndex(TypeIndex &index) { T::configure(index); } ///Apply recursively for parameter pack template static void applyIndex(TypeIndex &index) { applyIndex(index); applyIndex(index); } template static QMap getDbs() { return T::template databases(); } template static QMap getDbs() { return merge(getDbs(), getDbs()); } public: static void configure(TypeIndex &index) { applyIndex(index); } static QMap databases() { return getDbs(); } };