LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
ConfigurationHelper.cpp
Go to the documentation of this file.
1// Copyright 2002-2021 CEA LIST
2// SPDX-FileCopyrightText: 2022 CEA LIST <gael.de-chalendar@cea.fr>
3//
4// SPDX-License-Identifier: MIT
5
7
11
12#include <string>
13
14using namespace std;
15using namespace Lima::Common;
17using namespace Lima::Common::MediaticData;
18
19namespace Lima
20{
21namespace LinguisticProcessing
22{
23
26 const string& name,
27 string& value,
28 int flags,
29 string default_value)
30{
31 string tmp;
32 try
33 {
34 tmp = unitConfiguration.getParamsValueAtKey(name);
35 }
36 catch (NoSuchParam& )
37 {
38 if (flags & Flags::REQUIRED)
39 {
40 LOGINIT(m_loggingCategory.c_str());
41 LERROR << "no param \"" << name << "\" in " << m_processUnitName << " group configuration";
43 }
44
45 tmp = default_value;
46 }
47
48 if (flags & Flags::NOT_EMPTY && tmp.size() == 0)
49 {
50 LOGINIT(m_loggingCategory.c_str());
51 LERROR << "param \"" << name << "\" in " << m_processUnitName << " group configuration has zero length";
53 }
54
55 value = tmp;
56}
57
60 const string& name,
61 int flags,
62 string default_value)
63{
64 std::string value;
65 getStringParameter(unitConfiguration, name, value, flags, default_value);
66 return value;
67}
68
71 const string& name,
72 int& value,
73 int flags,
74 int default_value)
75{
76 int tmp;
77 try
78 {
79 tmp = QString::fromStdString(unitConfiguration.getParamsValueAtKey(name)).toInt();
80 }
81 catch (NoSuchParam& )
82 {
83 if (flags & Flags::REQUIRED)
84 {
85 LOGINIT(m_loggingCategory.c_str());
86 LERROR << "no param \"" << name << "\" in " << m_processUnitName << " group configuration";
88 }
89
90 tmp = default_value;
91 }
92
93 if (flags & Flags::NOT_ZERO && tmp == 0)
94 {
95 LOGINIT(m_loggingCategory.c_str());
96 LERROR << "param \"" << name << "\" in " << m_processUnitName << " group configuration is zero";
98 }
99
100 value = tmp;
101}
102
105 const string& name,
106 int flags,
107 int default_value)
108{
109 int value;
110 getIntParameter(unitConfiguration, name, value, flags, default_value);
111 return value;
112}
113
115{
116 string lazy_init;
118 if (lazy_init == "true")
119 {
120 return true;
121 }
122 return false;
123}
124
125
126}
127}
#define LOGINIT(X)
Definition LimaCommon.h:187
#define LERROR
Definition LimaCommon.h:161
bool getOptionValue(const std::string &name, std::string &value) const
return a message when a 'param' was not found
Use this exception to signal an error in one of the configuration files.
Definition LimaCommon.h:345
void getIntParameter(Common::XMLConfigurationFiles::GroupConfigurationStructure &unitConfiguration, const std::string &name, int &value, int flags=Flags::REQUIRED, int default_value=0)
void getStringParameter(Common::XMLConfigurationFiles::GroupConfigurationStructure &unitConfiguration, const std::string &name, std::string &value, int flags=Flags::REQUIRED, std::string default_value="")
static const MediaticData & single()
const singleton accessor
Definition Singleton.h:51
NAUTITIA.
STL namespace.
launch exception related to the configuration file parsing