30 lines
748 B
C++
30 lines
748 B
C++
#ifndef FORMATFACTORYREGISTRY_H
|
|
#define FORMATFACTORYREGISTRY_H
|
|
|
|
#include <QHash>
|
|
#include <memory>
|
|
#include "IFormatFactory.h"
|
|
|
|
class FormatFactoryRegistry {
|
|
static FormatFactoryRegistry * instance;
|
|
public:
|
|
void registerFactory(const QString& suffix, std::shared_ptr<IFormatFactory> factory) {
|
|
factories[suffix.toLower()] = std::move(factory);
|
|
}
|
|
|
|
static FormatFactoryRegistry& Get();
|
|
|
|
std::shared_ptr<IFormatFactory> getFactory(const QString& suffix) const {
|
|
auto it = factories.find(suffix.toLower());
|
|
if (it != factories.end())
|
|
return it.value();
|
|
return nullptr;
|
|
}
|
|
|
|
private:
|
|
QHash<QString, std::shared_ptr<IFormatFactory>> factories;
|
|
};
|
|
|
|
|
|
#endif // FORMATFACTORYREGISTRY_H
|