31 if ((strPath.rfind(directorySeparator) == std::string::npos) || (strPath.rfind(directorySeparator) != strPath.size() - 1)) {
32 strPath = strPath + std::string(directorySeparator);
48 strFileName = szFileName;
71 if(!strFileName.empty())
73 fileNames.push_back(strFileName);
79 logger->
addError(
"No module path is introduced.");
85 if ((dir = opendir(strPath.c_str())) ==
nullptr)
88 err<<
"Cannot access "<<strPath;
94 while((entry = readdir(dir)))
96 std::string name = entry->d_name;
99 std::string ext = name.substr(name.size()-3,3);
101 fileNames.push_back(strPath + name);
139 dummyComputer = computers.back();
140 computers.pop_back();
141 return &dummyComputer;
148 if (fileNames.empty()) {
152 std::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 std::vector<std::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 (std::string(computer.getName()) == strName) {
185bool XmlResLoader::parsXml(
const char* szFile)
191 TiXmlDocument doc(szFile);
195 err<<
"Syntax error while loading "<<szFile<<
" at line "\
196 <<doc.ErrorRow()<<
": ";
197 err<<doc.ErrorDesc();
202 TiXmlElement *root = doc.RootElement();
206 err<<
"Syntax error while loading "<<szFile<<
" . ";
207 err<<
"No root element.";
224 for(TiXmlElement* var = root->FirstChildElement(
"var"); var; var = var->NextSiblingElement())
226 if(var->Attribute(
"name") && var->GetText())
228 parser->
addVariable(var->Attribute(
"name"), var->GetText());
233 for(TiXmlElement* restag = root->FirstChildElement();
234 restag; restag = restag->NextSiblingElement())
242 for(TiXmlElement* comptag = restag->FirstChildElement();
243 comptag; comptag = comptag->NextSiblingElement())
267 TiXmlElement* element;
268 if ((element = (TiXmlElement*)comptag->FirstChild(
"name"))) {
272 war<<
"Platform from "<<szFile<<
" at line "\
273 <<comptag->Row()<<
" has no name.";
277 if ((element = (TiXmlElement*)comptag->FirstChild(
"distribution"))) {
281 if ((element = (TiXmlElement*)comptag->FirstChild(
"release"))) {
292 TiXmlElement* element;
293 if ((element = (TiXmlElement*)comptag->FirstChild(
"total_space"))) {
303 TiXmlElement* element;
304 if ((element = (TiXmlElement*)comptag->FirstChild(
"total_space"))) {
314 TiXmlElement* element;
315 if ((element = (TiXmlElement*)comptag->FirstChild(
"architecture"))) {
318 if ((element = (TiXmlElement*)comptag->FirstChild(
"model"))) {
321 if ((element = (TiXmlElement*)comptag->FirstChild(
"cores"))) {
324 if ((element = (TiXmlElement*)comptag->FirstChild(
"frequency"))) {
334 TiXmlElement* element;
335 if ((element = (TiXmlElement*)comptag->FirstChild(
"ip4"))) {
338 if ((element = (TiXmlElement*)comptag->FirstChild(
"ip6"))) {
341 if ((element = (TiXmlElement*)comptag->FirstChild(
"mac"))) {
352 TiXmlElement* element;
353 if ((element = (TiXmlElement*)comptag->FirstChild(
"name"))) {
356 if ((element = (TiXmlElement*)comptag->FirstChild(
"capability"))) {
359 if ((element = (TiXmlElement*)comptag->FirstChild(
"cores"))) {
362 if ((element = (TiXmlElement*)comptag->FirstChild(
"frequency"))) {
365 if ((element = (TiXmlElement*)comptag->FirstChild(
"register_block"))) {
368 if ((element = (TiXmlElement*)comptag->FirstChild(
"thread_block"))) {
371 if((element = (TiXmlElement*) comptag->FirstChild(
"overlap")))
381 if(comptag->FirstChild(
"global_memory"))
383 TiXmlElement* element;
384 element = (TiXmlElement*) comptag->FirstChild(
"global_memory");
385 if ((element = (TiXmlElement*)element->FirstChild(
"total_space"))) {
391 if(comptag->FirstChild(
"shared_memory"))
393 TiXmlElement* element;
394 element = (TiXmlElement*) comptag->FirstChild(
"shared_memory");
395 if ((element = (TiXmlElement*)element->FirstChild(
"total_space"))) {
401 if(comptag->FirstChild(
"constant_memory"))
403 TiXmlElement* element;
404 element = (TiXmlElement*) comptag->FirstChild(
"constant_memory");
405 if ((element = (TiXmlElement*)element->FirstChild(
"total_space"))) {
414 computers.push_back(computer);
void setProcessor(Processor &proc)
void setNetwork(Network &net)
bool addPeripheral(GenericResource &res)
void setPlatform(Platform &os)
void setStorage(Storage &stg)
void setMemory(Memory &mem)
Singleton class ErrorLogger.
void addError(const char *szError)
void addWarning(const char *szWarning)
static ErrorLogger * Instance()
Singleton class ErrorLogger.
void setFrequency(double f)
void setThreadPerBlock(size_t val)
void setOverlap(bool flag)
void setCompCompatibility(const char *cap)
void setConstantMemory(Capacity c)
void setSharedMemory(Capacity c)
void setResgisterPerBlock(size_t val)
void setGlobalMemory(Capacity c)
void setName(const char *szName)
void setXmlFile(const char *szFilename)
void setDescription(const char *szDesc)
void setDisable(bool flag)
void setTotalSpace(Capacity c)
void setIP4(const char *ip)
void setIP6(const char *ip)
void setMAC(const char *mac)
void setArchitecture(const char *arch)
void setModel(const char *model)
void setFrequency(double f)
void setTotalSpace(Capacity c)
bool addVariable(const std::string &key, const std::string &value)
std::string parseText(const char *element)
GenericResource * getNextResource() override
XmlResLoader(const char *szFileName)
load only one module indicated by its xml file name
static constexpr value_type preferred_separator
bool compareString(const char *szFirst, const char *szSecond)
std::stringstream OSTRINGSTREAM