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
18
namespace
Lima
19
{
20
30
template
<
typename
Factory>
31
class
RegistrableFactory
32
{
33
public
:
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
50
protected
:
55
RegistrableFactory
(
const
std::string&
id
);
56
57
};
58
59
template
<
typename
Factory>
60
RegistrableFactory<Factory>::RegistrableFactory
(
const
std::string&
id
)
61
{
62
// std::cerr << "RegistrableFactory<Factory>::RegistrableFactory(" << id << ")" << std::endl;
63
MainFactory< RegistrableFactory<Factory>
>::changeable().
registerFactory
(
id
,
this
);
64
}
65
66
template
<
typename
Factory>
67
std::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;
74
throw
InvalidConfiguration
();
75
}
76
return
std::dynamic_pointer_cast<Factory>(
MainFactory
<
RegistrableFactory<Factory>
>::changeable().getFactory(
id
));
77
}
78
79
template
<
typename
Factory>
80
std::deque<std::string>
RegistrableFactory<Factory>::getRegisteredFactories
()
81
{
82
return
MainFactory< RegistrableFactory<Factory>
>::single().
getRegisteredFactories
();
83
}
84
85
}
86
87
#endif
MainFactory.h
Defines the MainFactory to create Object.
Lima::InvalidConfiguration
Use this exception to signal an error in one of the configuration files.
Definition
LimaCommon.h:345
Lima::MainFactory
Definition
MainFactory.h:37
Lima::MainFactory::getRegisteredFactories
std::deque< std::string > getRegisteredFactories() const
show registered classId
Definition
MainFactory.h:216
Lima::MainFactory::registerFactory
void registerFactory(const std::string &classId, Factory *fact)
register a factory with an id
Definition
MainFactory.h:199
Lima::RegistrableFactory
Defines a Factory that automatically register to a MainFactory singleton.
Definition
RegistrableFactory.h:32
Lima::RegistrableFactory::getFactory
static std::shared_ptr< Factory > getFactory(const std::string &id)
get the factory corresponding to the given id
Definition
RegistrableFactory.h:67
Lima::RegistrableFactory::RegistrableFactory
RegistrableFactory(const std::string &id)
Constructor is protected, and must be redefined by subclass.
Definition
RegistrableFactory.h:60
Lima::RegistrableFactory::~RegistrableFactory
virtual ~RegistrableFactory()=default
Lima::RegistrableFactory::getRegisteredFactories
static std::deque< std::string > getRegisteredFactories()
get the list of factories registered
Definition
RegistrableFactory.h:80
Lima
NAUTITIA.
Definition
AmosePluginsManager.h:15
lima_common
src
common
AbstractFactoryPattern
RegistrableFactory.h
Generated by
1.9.8