00001
00002
00003 #ifndef VGS_GraphLoaderKFile_H
00004 #define VGS_GraphLoaderKFile_H
00005
00006 #include "GraphLoader.h"
00007
00008 #include <fstream>
00009 #include <iostream>
00010
00011 namespace VGServer {
00012
00016 class GraphLoaderKFile : public GraphLoader
00017 {
00018 public:
00019 explicit GraphLoaderKFile(const class GraphProperties &gp)
00020 : GraphLoader(gp)
00021 {
00022 }
00023
00024 bool load(std::istream &in, bool silent=false)
00025 {
00026 unsigned int vertexnum;
00027 in >> vertexnum;
00028
00029 if (!silent)
00030 std::cerr << "Vertices: " << vertexnum << "\n";
00031
00032 for (unsigned int vnum = 0; vnum < vertexnum; vnum++)
00033 {
00034 int vid, vx, vy;
00035
00036
00037 in >> vid >> vx >> vy;
00038
00039 if (not in.good()) return false;
00040
00041 addVertex(vid);
00042 setVertexAttr(vid, 0, vx);
00043 setVertexAttr(vid, 1, vy);
00044 }
00045
00046 unsigned int edgenum;
00047 in >> edgenum;
00048
00049 if (!silent)
00050 std::cerr << "Edges: " << edgenum << "\n";
00051
00052 for (unsigned int en = 0; en < edgenum and in.good(); en++)
00053 {
00054 int src, tgt, attr_distance, attr_direction, attr_speed;
00055
00056 in >> src >> tgt >> attr_distance >> attr_direction >> attr_speed;
00057
00058 if (not in.good()) return false;
00059
00060 addEdge(src, tgt);
00061
00062 setEdgeAttr(src, tgt, 0, attr_distance);
00063 setEdgeAttr(src, tgt, 1, attr_direction);
00064 setEdgeAttr(src, tgt, 2, attr_speed);
00065 }
00066
00067 return true;
00068 }
00069
00070 bool loadfile(const char *path, bool silent=false)
00071 {
00072 std::ifstream in(path);
00073 if (!in.is_open()) {
00074 if (!silent)
00075 std::cerr << "Could not open map file " << path << std::endl;
00076 return false;
00077 }
00078
00079 return load(in, silent);
00080 }
00081 };
00082
00083 }
00084
00085 #endif // VGS_GraphLoaderKFile_H