Proszę oto trochę więcej kodu:
//klasa parser pliku (czesc metody)
//......
if(line.substr(0, 5) == "<node")
{
Graph_node * ONodes;
ONodes = new Graph_node;
ONodes->lat = to_float((this->get_value("lat", line))[0]);
ONodes->lon = to_float((this->get_value("lon", line))[0]);
ONodes->id = node_id;
this->nodes[to_lint((this->get_value("id", line))[0])] = ONodes;
//wyluskuje tutaj z tagow w pliku <node id="liczba"...> ta liczbe jako id i tworze na jej podstawie mape obiektow
node_id++;
}
if(line.size() >= 6)
{
if(line.substr(0, 4) == "<way" || start_way == true) //w drugiej czesci pliku sa <way> <nd ref="liczba"><tag k="nazwa_ulicy">, liczba to id node'a,
{
new_line = new_line + line;
start_way = true;
}
if(line.substr(0, 6) == "</way>")
{
string street_name;
vector <string> keys = get_value("k", new_line);
nds = this->get_value("ref", new_line);
for(int i=0; i<keys.size(); i++)
{
if(keys[i] == "name")
{
street_name = (this->get_value("v", new_line))[i];
break;
}
}
//do tej pory mam elegancko wszystkie street name
for(int i=0; i<nds.size(); i++)
{
if(this->nodes[to_lint(nds[i])]) //jesli node z way'a istnieje (bo nie wszystkie ref="liczba" istnieją w nodach bo to tylko fragment pliku)
{
exist_nds.push_back(to_lint(nds[i])); //to te co istnieja do vectora
}
}
// jak tu dam cout<<street_name to wyswietla poprawnie
for(int i=0; i<exist_nds.size(); i++)
{
if(i < exist_nds.size()-1)
{
if(street_name == "") street_name = "<no named>";
this->nodes[exist_nds[i]]->street_name = street_name; //i do tych istniejacych przypisuje street name
double ab_dist = gdistance(this->nodes[exist_nds[i]]->lat, this->nodes[exist_nds[i]]->lon, this->nodes[exist_nds[i+1]]->lat, this->nodes[exist_nds[i+1]]->lon);
this->graph_matrix[exist_nds[i]][exist_nds[i+1]] = ab_dist;
this->graph_matrix[exist_nds[i+1]][exist_nds[i]] = ab_dist;
}
}
nds.clear();
exist_nds.clear();
street_name.clear();
new_line.clear();
start_way = false;
}
//......
//zwracanie tych graph_matrix i nodes
Tmatrix * Parser::get_graph_matrix()
{
return &(this->graph_matrix);
}
Tnodes * Parser::get_nodes()
{
return &(this->nodes);
}
//main.cpp
OGraph = new Graph(OParser->get_graph_matrix(), OParser->get_nodes());
//klasa graph
class Graph
{
public:
Tmatrix graph_matrix;
Tnodes graph_nodes;
Graph(Tmatrix * graph_matrix, Tnodes * graph_nodes);
void get_shortest_way(string street_name1, string street_name2);
long int get_node_id(string street_name);
private:
void Dijkstra(long int A, long int B);
};
Graph::Graph(Tmatrix * graph_matrix, Tnodes * graph_nodes)
{
this->graph_matrix = *graph_matrix;
this->graph_nodes = *graph_nodes;
}
long int Graph::get_node_id(string street_name)
{
Tnodes::iterator it;
for(it = this->graph_nodes.begin(); it != this->graph_nodes.end(); it++)
{
if(it->second->street_name == street_name)
return it->first;
}
}
Kompiluje sie, ale nie wyswietla wszystkich ulic i na koniec dostaje NAruszenie ochrony pamieci. WLasciwie w tej pierwszej metodzie do ostatniej linijki jest wszystko wporzadku, problem jest w tym iteratorze przy wysiwetlaniu