From 73ef798bf849a01418895c2e88300e1c6730b665 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 15 Feb 2017 16:17:26 +0100 Subject: PropertyRegistry for runtime information about properties. A first usecase is parsing different property types. --- common/domain/propertyregistry.h | 87 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 common/domain/propertyregistry.h (limited to 'common/domain/propertyregistry.h') diff --git a/common/domain/propertyregistry.h b/common/domain/propertyregistry.h new file mode 100644 index 0000000..16df23b --- /dev/null +++ b/common/domain/propertyregistry.h @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2017 Christian Mollekopf + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) version 3, or any + * later version accepted by the membership of KDE e.V. (or its + * successor approved by the membership of KDE e.V.), which shall + * act as a proxy defined in Section 6 of version 3 of the license. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#pragma once + +#include +#include +#include +#include + +#include "applicationdomaintype.h" + +namespace Sink { +namespace Private { + +template +QVariant parseString(const QString &); + +template <> +QVariant parseString(const QString &s); + +template <> +QVariant parseString(const QString &s); + +template <> +QVariant parseString(const QString &s); + +template <> +QVariant parseString(const QString &s); + +template <> +QVariant parseString(const QString &s); + +template <> +QVariant parseString>(const QString &s); + +template <> +QVariant parseString(const QString &s); + +template <> +QVariant parseString(const QString &s); + +template <> +QVariant parseString>(const QString &s); + +class PropertyRegistry +{ +public: + struct Type { + struct Property { + std::function parser; + }; + QHash properties; + }; + + QHash registry; + + static PropertyRegistry &instance(); + + template + void registerProperty(const QByteArray &entityType) { + registry[entityType].properties[PropertyType::name].parser = Sink::Private::parseString; + } + + QVariant parse(const QByteArray &type, const QByteArray &property, const QString &value); +}; + + } +} + -- cgit v1.2.3