24 strFileName = szFileName;
30 if (!strFileName.size()) {
31 return serialXml(application, application->
getXmlFile());
34 return serialXml(application, strFileName.c_str());
39bool XmlAppSaver::serialXml(
Application* app,
const char* szFile)
48 auto* root =
new TiXmlElement(
"application");
49 doc.LinkEndChild( root );
50 auto* appName =
new TiXmlElement(
"name");
51 appName->LinkEndChild(
new TiXmlText(app->
getName()));
52 root->LinkEndChild(appName);
57 auto* desc=
new TiXmlElement(
"description");
59 root->LinkEndChild(desc);
64 auto* vers=
new TiXmlElement(
"version");
65 vers->LinkEndChild(
new TiXmlText( app->
getVersion()));
66 root->LinkEndChild(vers);
86 auto* auths=
new TiXmlElement(
"authors");
90 auto* auth=
new TiXmlElement(
"author");
93 auths->LinkEndChild(auth);
95 root->LinkEndChild(auths);
101 for (
int modCt=0; modCt<nModules; ++modCt)
103 auto* newMod =
new TiXmlElement(
"module");
104 root->LinkEndChild(newMod);
107 auto* name =
new TiXmlElement(
"name");
108 name->LinkEndChild(
new TiXmlText(curMod.
getName()));
109 newMod->LinkEndChild(name);
111 auto* parameters=
new TiXmlElement(
"parameters");
112 parameters->LinkEndChild(
new TiXmlText(curMod.
getParam()));
113 newMod->LinkEndChild(parameters);
115 auto* node =
new TiXmlElement(
"node");
116 node->LinkEndChild(
new TiXmlText(curMod.
getHost()));
117 newMod->LinkEndChild(node);
119 auto* prefix=
new TiXmlElement(
"prefix");
120 prefix->LinkEndChild(
new TiXmlText(curMod.
getPrefix()));
121 newMod->LinkEndChild(prefix);
123 if(strcmp(curMod.
getStdio(),
"") != 0)
125 auto* stdio=
new TiXmlElement(
"stdio");
126 stdio->LinkEndChild(
new TiXmlText(curMod.
getStdio()));
127 newMod->LinkEndChild(stdio);
132 auto* workdir=
new TiXmlElement(
"workdir");
133 workdir->LinkEndChild(
new TiXmlText(curMod.
getWorkDir()));
134 newMod->LinkEndChild(workdir);
139 auto* broker=
new TiXmlElement(
"deployer");
140 broker->LinkEndChild(
new TiXmlText(curMod.
getBroker()));
141 newMod->LinkEndChild(broker);
158 txt<<
"(Pos (x "<<model.
points[0].x<<
") "<<
"(y "<<model.
points[0].y<<
"))";
159 auto* geometry=
new TiXmlElement(
"geometry");
160 geometry->LinkEndChild(
new TiXmlText(txt.str().c_str()));
161 newMod->LinkEndChild(geometry);
170 for (
int appCt=0; appCt<nApps; ++appCt)
172 auto* newApp =
new TiXmlElement(
"application");
173 root->LinkEndChild(newApp);
176 auto* name =
new TiXmlElement(
"name");
177 name->LinkEndChild(
new TiXmlText(curApp.
getName()));
178 newApp->LinkEndChild(name);
181 auto* prefix=
new TiXmlElement(
"prefix");
182 prefix->LinkEndChild(
new TiXmlText(curApp.
getPrefix()));
183 newApp->LinkEndChild(prefix);
189 txt<<
"(Pos (x "<<model.
points[0].x<<
") "<<
"(y "<<model.
points[0].y<<
"))";
190 auto* geometry=
new TiXmlElement(
"geometry");
191 geometry->LinkEndChild(
new TiXmlText(txt.str().c_str()));
192 newApp->LinkEndChild(geometry);
201 for (
int connCt=0; connCt<nConns; ++connCt)
203 auto* newConn=
new TiXmlElement(
"connection");
206 if (strlen(curConn.
getId())) {
207 newConn->SetAttribute(
"id", curConn.
getId());
211 newConn->SetAttribute(
"persist",
"true");
214 auto* from =
new TiXmlElement(
"from");
216 from->SetAttribute(
"external",
"true");
218 from->LinkEndChild(
new TiXmlText(curConn.
from()));
219 newConn->LinkEndChild(from);
221 auto* to =
new TiXmlElement(
"to");
223 to->SetAttribute(
"external",
"true");
225 to->LinkEndChild(
new TiXmlText(curConn.
to()));
226 newConn->LinkEndChild(to);
228 auto* protocol =
new TiXmlElement(
"protocol");
229 protocol->LinkEndChild(
new TiXmlText(curConn.
carrier()));
230 newConn->LinkEndChild(protocol);
237 for (
auto& point : model.points) {
238 txt <<
"((x " << point.x <<
") "
239 <<
"(y " << point.y <<
")) ";
242 auto* geometry=
new TiXmlElement(
"geometry");
243 geometry->LinkEndChild(
new TiXmlText(txt.str().c_str()));
244 newConn->LinkEndChild(geometry);
247 root->LinkEndChild(newConn);
256 auto* newArb =
new TiXmlElement(
"arbitrator");
258 auto* port =
new TiXmlElement(
"port");
259 port->LinkEndChild(
new TiXmlText(arb.
getPort()));
260 newArb->LinkEndChild(port);
262 std::map<std::string, std::string> &rules = arb.
getRuleMap();
263 for(
auto& it : rules)
265 auto* rule =
new TiXmlElement(
"rule");
266 rule->SetAttribute(
"connection", it.first.c_str());
267 rule->LinkEndChild(
new TiXmlText(it.second.c_str()));
268 newArb->LinkEndChild(rule);
276 for (
auto& point : model.points) {
277 txt <<
"((x " << point.x <<
") "
278 <<
"(y " << point.y <<
")) ";
281 auto* geometry=
new TiXmlElement(
"geometry");
282 geometry->LinkEndChild(
new TiXmlText(txt.str().c_str()));
283 newArb->LinkEndChild(geometry);
285 root->LinkEndChild(newArb);
294 err<<
"tinyXml error for file " << app->
getXmlFile();
296 err <<
" at line " << doc.ErrorRow() <<
", column " << doc.ErrorCol() <<
": " << doc.ErrorDesc();
Class ApplicationInterface.
GraphicModel & getModelBase()
const char * getXmlFile()
Arbitrator & getArbitratorAt(int index)
const char * getVersion()
ModuleInterface & getImoduleAt(int index)
void setXmlFile(const char *szFilename)
const char * getDescription()
Author & getAuthorAt(int index)
Connection & getConnectionAt(int index)
ApplicationInterface & getIapplicationAt(int index)
GraphicModel & getModelBase()
std::map< std::string, std::string > & getRuleMap()
GraphicModel & getModelBase()
Singleton class ErrorLogger.
void addError(const char *szError)
static ErrorLogger * Instance()
Singleton class ErrorLogger.
std::vector< GyPoint > points
GraphicModel & getModelBase()
const char * getWorkDir()
bool save(Application *application) override
XmlAppSaver(const char *szFileName=NULL)
std::stringstream OSTRINGSTREAM