ParamMgr.cc
2 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
/*
* ParamMgr.cc
*
* Created on: Oct 6, 2014
* Author: m.mazel
*/
#include "Helper.hh"
#include "Properties.hh"
#include "ParamMgr.hh"
#include "ParamParser.hh"
#include "InfoLogger.hh"
namespace AMDA {
namespace Info {
const ParamInfoSPtr ParamMgr::getParamInfoFromId (const std::string &id, bool forceCreateIfNoExist) {
if (id.empty())
return ParamInfoSPtr();
// If Param id already loaded, return it
if (_paramInfoMap.find (id) != _paramInfoMap.end()) {
return _paramInfoMap [id];
}
// Otherwise, build Param path & filename using the id
AMDA::helpers::Properties lProperties("app.properties");
std::string xmlFileName = lProperties["app.param.path"] + "/" + id + ".xml";
_paramInfoMap [id] = getParamInfoFromFile (id, xmlFileName);
if (forceCreateIfNoExist && (_paramInfoMap [id] == nullptr))
{
_paramInfoMap [id] = ParamInfoSPtr(new ParamInfo);
_paramInfoMap [id]->setId(id);
}
return _paramInfoMap [id];
}
const ParamInfoSPtr ParamMgr::cloneParamInfoFromId(const std::string &originId, const std::string &dstId)
{
if (originId.empty() || dstId.empty()) {
return ParamInfoSPtr();
}
//if param dst id exist, return it
if (_paramInfoMap.find (dstId) != _paramInfoMap.end()) {
return _paramInfoMap [dstId];
}
//if Param origin id no exist, return nullptr
if (_paramInfoMap.find (originId) == _paramInfoMap.end()) {
return ParamInfoSPtr();
}
if (_paramInfoMap[originId] == nullptr) {
return ParamInfoSPtr();
}
//copy param info
_paramInfoMap [dstId] = ParamInfoSPtr(new ParamInfo(*_paramInfoMap[originId].get()));
_paramInfoMap [dstId]->setId(dstId);
return _paramInfoMap [dstId];
}
ParamInfoSPtr ParamMgr::getParamInfoFromFile (const std::string ¶mId,
const std::string &xmlFilename) {
AMDA::helpers::Properties lProperties("app.properties");
// Retrieve XSD file for Param and build a parser
ParamParser parser(lProperties["app.paramInfo.xsd"].c_str());
// Parse XML file
return parser.parse (paramId, xmlFilename);
}
} /* namespace Info */
} /* namespace AMDA */