LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
RegistrableFactory.h
Go to the documentation of this file.
1// Copyright 2002-2019 CEA LIST
2// SPDX-FileCopyrightText: 2022 CEA LIST <gael.de-chalendar@cea.fr>
3//
4// SPDX-License-Identifier: MIT
5
6/***************************************************************************
7 * Copyright (C) 2004-2019 by CEA LIST *
8 * *
9 ***************************************************************************/
10
11#ifndef LIMA_COMMON_ABSTRACTFACTORYPATTERN_REGISTRABLEFACTORY_H
12#define LIMA_COMMON_ABSTRACTFACTORYPATTERN_REGISTRABLEFACTORY_H
13
14#include "MainFactory.h"
15#include <deque>
16#include <string>
17
18namespace Lima
19{
20
30template<typename Factory>
32{
33public:
34
35 virtual ~RegistrableFactory() = default;
36
42 static std::shared_ptr<Factory> getFactory(const std::string& id);
43
48 static std::deque<std::string> getRegisteredFactories();
49
50protected:
55 RegistrableFactory(const std::string& id);
56
57};
58
59template<typename Factory>
61{
62// std::cerr << "RegistrableFactory<Factory>::RegistrableFactory(" << id << ")" << std::endl;
64}
65
66template<typename Factory>
67std::shared_ptr<Factory> RegistrableFactory<Factory>::getFactory(const std::string& id)
68{
69// std::cerr << "RegistrableFactory<Factory>::getFactory(" << id << ")" << std::endl;
70//
71 if (id.empty())
72 {
73 std::cerr << "Trying to access to factory with empty name!" << std::endl;
75 }
76 return std::dynamic_pointer_cast<Factory>(MainFactory< RegistrableFactory<Factory> >::changeable().getFactory(id));
77}
78
79template<typename Factory>
84
85}
86
87#endif
Defines the MainFactory to create Object.
Use this exception to signal an error in one of the configuration files.
Definition LimaCommon.h:345
std::deque< std::string > getRegisteredFactories() const
show registered classId
void registerFactory(const std::string &classId, Factory *fact)
register a factory with an id
Defines a Factory that automatically register to a MainFactory singleton.
static std::shared_ptr< Factory > getFactory(const std::string &id)
get the factory corresponding to the given id
RegistrableFactory(const std::string &id)
Constructor is protected, and must be redefined by subclass.
virtual ~RegistrableFactory()=default
static std::deque< std::string > getRegisteredFactories()
get the list of factories registered
NAUTITIA.