ParameterCreatorFromExpression.cc
3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* ParameterCreatorFromExpression.cc
*
* Created on: Dec 14, 2012
* Author: f.casimir
*/
#include <boost/functional/hash.hpp>
#include <boost/algorithm/string.hpp>
#include "DicError.hh"
#include "Process.hh"
#include "ParameterManager.hh"
#include "ServicesServer.hh"
#include "InternLib_Config.hh"
#include "ParameterCreatorFromExpression.hh"
using namespace std;
using namespace boost;
using namespace log4cxx;
namespace AMDA {
namespace Parameters {
ParameterCreatorFromExpression::ParameterCreatorFromExpression(ParameterManager& pParameterManager) :
_parameterManager(pParameterManager) {
}
ParameterCreatorFromExpression::~ParameterCreatorFromExpression() {
}
ParameterSPtr ParameterCreatorFromExpression::getOneParameterFromExpression(Parameter& pParameter, const std::string& pExpression) {
ParameterSPtr lParameter;
_parser.process(pExpression);
///Case of one parameter return this parameter
if (_parser.getListParameterName().size() == 1
&& _parser.getListProcessName().size() == 0
&& _parser.getListFctName().size() == 0) {
lParameter = _parameterManager.getParameter(*_parser.getListParameterName().begin());
// Here we have a broken link in parameter chaining so create link.
// Child is already creating before linking it to its parent parameter.
pParameter.addParameter(lParameter);
} else {
///Case of one process return a Parameter with this Process
if (_parser.getListParameterName().size() == 0
&& _parser.getListProcessName().size() == 1
&& _parser.getListFctName().size() == 0) {
const Parser::ListProcessName& processNameList = _parser.getListProcessName();
auto lProcessIt = processNameList.begin();
if ( _parameterManager.addParameter(&pParameter,lProcessIt->first,lParameter)) {
Process* lProcess = ServicesServer::getInstance()->getProcess(lProcessIt->second.name,*lParameter.get());
if ( lProcess) {
lProcess->setExpression(lProcessIt->second.expression);
lProcess->setAttributList(lProcessIt->second.attribut);
DataWriterSPtr dataWriter(lProcess);
lParameter->setDataWriter(dataWriter);
} else {
stringstream lError; lError << "Process: '" << lProcessIt->second.name << "' not found";
LOG4CXX_ERROR(AMDA::InternLib::gLogger, lError.str());
BOOST_THROW_EXCEPTION(AMDA::InternLib::exception() << AMDA::errno_code(AMDA_PROCESS_ERR) << AMDA::ex_msg(lError.str()));
}
}
} else {
boost::hash<std::string> string_hash;
std::stringstream key;
key << string_hash(pExpression);
///Else return a Parameter with a Standard Process
if ( _parameterManager.addParameter(&pParameter,key.str(),lParameter)) {
Process *lProcess = ServicesServer::getInstance()->getProcess("standard", *lParameter.get());
if ( lProcess) {
lProcess->setExpression(pExpression);
DataWriterSPtr dataWriter(lProcess);
lParameter->setDataWriter(dataWriter);
} else {
stringstream lError; lError << "Process: 'standard' not found";
LOG4CXX_ERROR(AMDA::InternLib::gLogger, lError.str());
BOOST_THROW_EXCEPTION(AMDA::InternLib::exception() << AMDA::errno_code(AMDA_PROCESS_ERR) << AMDA::ex_msg(lError.str()));
}
}
}
}
return lParameter;
}
} /* namespace Parameters */
} /* namespace AMDA */