28 XmlResLoader::XmlResLoader(
const char* szPath,
const char* szName)
35 if((strPath.rfind(directorySeparator)==string::npos) ||
36 (strPath.rfind(directorySeparator)!=strPath.size()-1))
37 strPath = strPath + string(directorySeparator);
47 XmlResLoader::XmlResLoader(
const char* szFileName)
51 strFileName = szFileName;
56 XmlResLoader::~XmlResLoader()
65 bool XmlResLoader::init()
73 if(!strFileName.empty())
75 fileNames.push_back(strFileName);
81 logger->
addError(
"No module path is introduced.");
87 if ((dir = opendir(strPath.c_str())) ==
nullptr)
90 err<<
"Cannot access "<<strPath;
96 while((entry = readdir(dir)))
98 string name = entry->d_name;
101 string ext = name.substr(name.size()-3,3);
103 fileNames.push_back(strPath+name);
121 void XmlResLoader::reset()
128 void XmlResLoader::fini()
140 dummyComputer = computers.back();
141 computers.pop_back();
142 return &dummyComputer;
149 if(fileNames.empty())
152 string fname = fileNames.back();
153 fileNames.pop_back();
154 ret = parsXml(fname.c_str());
157 dummyComputer = computers.back();
158 computers.pop_back();
159 return &dummyComputer;
167 vector<string>::iterator itr;
168 for(itr=fileNames.begin(); itr<fileNames.end(); itr++)
170 if(parsXml((*itr).c_str()))
172 for(
auto& computer : computers)
173 if(
string(computer.getName()) == strName)
183 bool XmlResLoader::parsXml(
const char* szFile)
189 TiXmlDocument doc(szFile);
193 err<<
"Syntax error while loading "<<szFile<<
" at line "\
194 <<doc.ErrorRow()<<
": ";
195 err<<doc.ErrorDesc();
200 TiXmlElement *root = doc.RootElement();
204 err<<
"Syntax error while loading "<<szFile<<
" . ";
205 err<<
"No root element.";
222 for(TiXmlElement* var = root->FirstChildElement(
"var"); var; var = var->NextSiblingElement())
224 if(var->Attribute(
"name") && var->GetText())
226 parser->addVariable(var->Attribute(
"name"), var->GetText());
231 for(TiXmlElement* restag = root->FirstChildElement();
232 restag; restag = restag->NextSiblingElement())
240 for(TiXmlElement* comptag = restag->FirstChildElement();
241 comptag; comptag = comptag->NextSiblingElement())
245 computer.
setName(parser->parseText(comptag->GetText()).c_str());
249 computer.
setDescription(parser->parseText(comptag->GetText()).c_str());
254 if(
compareString(parser->parseText(comptag->GetText()).c_str(),
"yes"))
262 TiXmlElement* element;
263 if((element = (TiXmlElement*) comptag->FirstChild(
"name")))
264 os.
setName(parser->parseText(element->GetText()).c_str());
268 war<<
"Platform from "<<szFile<<
" at line "\
269 <<comptag->Row()<<
" has no name.";
273 if((element = (TiXmlElement*) comptag->FirstChild(
"distribution")))
276 if((element = (TiXmlElement*) comptag->FirstChild(
"release")))
277 os.
setRelease(parser->parseText(element->GetText()).c_str());
286 TiXmlElement* element;
287 if((element = (TiXmlElement*) comptag->FirstChild(
"total_space")))
296 TiXmlElement* element;
297 if((element = (TiXmlElement*) comptag->FirstChild(
"total_space")))
306 TiXmlElement* element;
307 if((element = (TiXmlElement*) comptag->FirstChild(
"architecture")))
309 if((element = (TiXmlElement*) comptag->FirstChild(
"model")))
310 proc.
setModel(parser->parseText(element->GetText()).c_str());
311 if((element = (TiXmlElement*) comptag->FirstChild(
"cores")))
312 proc.
setCores((
size_t)atoi(parser->parseText(element->GetText()).c_str()));
313 if((element = (TiXmlElement*) comptag->FirstChild(
"frequency")))
314 proc.
setFrequency(atof(parser->parseText(element->GetText()).c_str()));
322 TiXmlElement* element;
323 if((element = (TiXmlElement*) comptag->FirstChild(
"ip4")))
324 net.
setIP4(parser->parseText(element->GetText()).c_str());
325 if((element = (TiXmlElement*) comptag->FirstChild(
"ip6")))
326 net.
setIP6(parser->parseText(element->GetText()).c_str());
327 if((element = (TiXmlElement*) comptag->FirstChild(
"mac")))
328 net.
setMAC(parser->parseText(element->GetText()).c_str());
337 TiXmlElement* element;
338 if((element = (TiXmlElement*) comptag->FirstChild(
"name")))
339 gpu.
setName(parser->parseText(element->GetText()).c_str());
340 if((element = (TiXmlElement*) comptag->FirstChild(
"capability")))
342 if((element = (TiXmlElement*) comptag->FirstChild(
"cores")))
343 gpu.
setCores((
size_t)atoi(parser->parseText(element->GetText()).c_str()));
344 if((element = (TiXmlElement*) comptag->FirstChild(
"frequency")))
345 gpu.
setFrequency(atof(parser->parseText(element->GetText()).c_str()));
346 if((element = (TiXmlElement*) comptag->FirstChild(
"register_block")))
348 if((element = (TiXmlElement*) comptag->FirstChild(
"thread_block")))
349 gpu.
setThreadPerBlock((
size_t)atoi(parser->parseText(element->GetText()).c_str()));
350 if((element = (TiXmlElement*) comptag->FirstChild(
"overlap")))
352 if(
compareString(parser->parseText(element->GetText()).c_str(),
"yes"))
359 if(comptag->FirstChild(
"global_memory"))
361 TiXmlElement* element;
362 element = (TiXmlElement*) comptag->FirstChild(
"global_memory");
363 if((element = (TiXmlElement*) element->FirstChild(
"total_space")))
368 if(comptag->FirstChild(
"shared_memory"))
370 TiXmlElement* element;
371 element = (TiXmlElement*) comptag->FirstChild(
"shared_memory");
372 if((element = (TiXmlElement*) element->FirstChild(
"total_space")))
377 if(comptag->FirstChild(
"constant_memory"))
379 TiXmlElement* element;
380 element = (TiXmlElement*) comptag->FirstChild(
"constant_memory");
381 if((element = (TiXmlElement*) element->FirstChild(
"total_space")))
389 computers.push_back(computer);