FunctionsArgsListParser.cc
3.81 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
* FunctionsArgsListParser.cc
*
* Created on: Dec 03, 2020
* Author: AKKA
*/
#include "NodeCfg.hh"
#include "AMDA_exception.hh"
#include "FunctionsArgsListParser.hh"
#include "ParserLogger.hh"
#include <boost/lexical_cast.hpp>
using namespace AMDA::XMLConfigurator;
namespace AMDA {
namespace parser {
///////////////////////////////////////////////////////////////////////////////
/*
* @brief value node
*/
class ArgListValueNode : public NodeCfg
{
public:
void proceed(xmlNodePtr pNode,const AMDA::Parameters::CfgContext& pContext) {
ArgListInfo *pArgListInfo = pContext.get<ArgListInfo *>();
//Get key
xmlChar* value = xmlGetProp(pNode, (const xmlChar *) "key");
std::string argKey;
if (value != NULL)
{
argKey = (char *)value;
xmlFree(value);
}
//Get value
value = xmlGetProp(pNode, (const xmlChar *) "value");
std::string argValue;
if (value != NULL)
{
argValue = (char *)value;
xmlFree(value);
}
if (!argKey.empty()) {
pArgListInfo->addValue(argKey, argValue);
}
}
};
///////////////////////////////////////////////////////////////////////////////
/*
* @brief values node
*/
class ArgListValuesNode : public NodeGrpCfg {
public:
ArgListValuesNode () : NodeGrpCfg() {
getChildList()["value"] = NodeCfgSPtr(new ArgListValueNode);
}
void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pContext) {
LOG4CXX_INFO(gLogger, "ArgListValuesNode::proceed");
// Proceed nodes
NodeGrpCfg::proceed(pNode, pContext);
}
};
///////////////////////////////////////////////////////////////////////////////
/*
* @brief arglist node
*/
class ArgListNode : public NodeGrpCfg
{
public:
ArgListNode () : NodeGrpCfg() {
getChildList()["values"] = RootNodeCfgSPtr(new ArgListValuesNode);
}
void proceed(xmlNodePtr pNode,const AMDA::Parameters::CfgContext& pContext) {
//Get id
xmlChar* value = xmlGetProp(pNode, (const xmlChar *) "id");
std::string id;
if (value != NULL)
{
id = (char *)value;
xmlFree(value);
}
if (!id.empty()) {
AMDA::Parameters::CfgContext ctx;
ArgListInfo argListInfo;
ctx.push<ArgListInfo *>(&argListInfo);
argListInfo.setID(id);
// Proceed nodes
NodeGrpCfg::proceed(pNode, ctx);
//Add functions argument list in map
ArgListInfoMap *pArgListInfoMap = pContext.get<ArgListInfoMap *>();
(*pArgListInfoMap)[id] = argListInfo;
}
}
};
///////////////////////////////////////////////////////////////////////////////
/*
* @brief argslist node
*/
class ArgsListNode : public NodeGrpCfg {
public:
ArgsListNode () : NodeGrpCfg() {
getChildList()["arglist"] = NodeCfgSPtr(new ArgListNode);
}
void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pContext) {
LOG4CXX_INFO(gLogger, "ArgsListNode::proceed");
// Proceed nodes
NodeGrpCfg::proceed(pNode, pContext);
}
};
///////////////////////////////////////////////////////////////////////////////
/*
* @brief argslist node parser
*/
FunctionsArgsListParser::FunctionsArgsListParser (const char* pXSDFile) : XMLConfigurator(pXSDFile,true)
{
// argslist root node
getXmlConfiguratorMap()["argslist"] = RootNodeCfgSPtr(new ArgsListNode ());
}
ArgListInfoMap FunctionsArgsListParser::parse (const std::string& functionsArgsListFile) {
LOG4CXX_INFO(gLogger, "FunctionsArgsListParser::parse parsing " << functionsArgsListFile);
AMDA::Parameters::CfgContext ctx;
ArgListInfoMap argListInfoMap;
ctx.push<ArgListInfoMap *>(&argListInfoMap);
// Check schema validity and parse xml file
try {
if (!XMLConfigurator::proceed(functionsArgsListFile.c_str(), ctx, true)) {
return argListInfoMap;
}
}
catch (...) {
LOG4CXX_INFO(gLogger, "FunctionsArgsListParser::parse error while parsing file " << functionsArgsListFile);
return argListInfoMap;
}
return argListInfoMap;
}
} /* namespace parser */
} /* namespace AMDA */