-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtask.cpp
58 lines (52 loc) · 1.5 KB
/
task.cpp
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
#include "task.h"
Task::Task()
{
agents.clear();
}
bool Task::get_task(const char *FileName)
{
tinyxml2::XMLElement *root = 0, *agent = 0;
tinyxml2::XMLDocument doc;
std::string value;
std::stringstream stream;
// Load XML File
if (doc.LoadFile(FileName) != tinyxml2::XMLError::XML_SUCCESS)
{
std::cout << "Error opening XML file!" << std::endl;
return false;
}
// Get ROOT element
root = doc.FirstChildElement(CNS_TAG_ROOT);
if (!root)
{
std::cout << "Error! No '" << CNS_TAG_ROOT << "' tag found in XML file!" << std::endl;
return false;
}
for (agent = root->FirstChildElement(); agent; agent = agent->NextSiblingElement())
{
value = agent->Value();
std::transform(value.begin(), value.end(), value.begin(), ::tolower);
Agent a;
stream.clear();
stream << agent->Attribute(CNS_TAG_START_I);
stream >> a.start_i;
stream.clear();
stream << agent->Attribute(CNS_TAG_START_J);
stream >> a.start_j;
stream.clear();
stream << agent->Attribute(CNS_TAG_GOAL_I);
stream >> a.goal_i;
stream.clear();
stream << agent->Attribute(CNS_TAG_GOAL_J);
stream >> a.goal_j;
a.id = agents.size();
agents.push_back(a);
}
}
Agent Task::get_agent(int id) const
{
if(id >= 0 && id < agents.size())
return agents[id];
else
return Agent();
}