Projekt

Allgemein

Profil

Herunterladen als
Herunterladen (1,72 KB) Statistiken
| Zweig: | Revision:
01fe6db3 Christian Ehringfeld
/*
* Copyright (C) 2015 Christian Ehringfeld <c.ehringfeld@t-online.de>
*
* This program 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.
*
* 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 Lesser General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
e2ee17bf Christian Ehringfeld
#ifndef VALIDATORFACTORY_H
#define VALIDATORFACTORY_H
#include <QString>
#include <QHash>
fc14f551 Christian Ehringfeld
#include <QSharedPointer>
e2ee17bf Christian Ehringfeld
namespace CuteEntityManager {
class Validator;
class ValidatorFactory {
public:
static void registerClasses();
fc14f551 Christian Ehringfeld
static Validator *createValidator(const QString &shortname);
e2ee17bf Christian Ehringfeld
template<typename T>
static void registerClass() {
b7f1ce8e Christian Ehringfeld
if (!ValidatorFactory::instance.contains(T::staticMetaObject.className())) {
e2ee17bf Christian Ehringfeld
ValidatorFactory::instance.insert( T::staticMetaObject.className(),
&constructorHelper<T> );
}
}

fc14f551 Christian Ehringfeld
static Validator *createObject( const QByteArray &className);

static QSharedPointer<Validator> getValidatorObject(const QString &shortname);

e2ee17bf Christian Ehringfeld
typedef Validator *(*Constructor)();
template<typename T>
static Validator *constructorHelper() {
return new T();
}
static QHash<QByteArray, Constructor> instance;
fc14f551 Christian Ehringfeld
static QHash<QString, QSharedPointer<Validator>> validatorInstances;
e2ee17bf Christian Ehringfeld
protected:
ValidatorFactory();
};
}

#endif // VALIDATORFACTORY_H