Added workaround for broken ifstream::putback() on MSVC
[hypercube:hypercube.git] / IO / providers / gml.h
1 #ifndef GML_H_
2 #define GML_H_
3
4 #include <string>
5 #include <fstream>
6 #include "IO/io.h"
7
8
9 class GmlGraphInput : public InputProvider
10 {
11 public:
12         virtual Error readGraph(Graph *graph, const char *fileName,
13           Encoding *encoding);
14
15 private:
16         enum Token {
17                 START,          /* Initial value */
18                 EOI,            /* End of File */
19                 ERROR,          /* Parse error */
20
21                 INT,            /* Integer */
22                 REAL,           /* Real */
23                 STRING,         /* String */
24                 KEY,            /* Key (identificator) */
25
26                 LBRK,           /* '[' */
27                 RBRK            /* ']' */
28         };
29
30         enum ValueType {
31                 UNKNOWN,
32                 GRAPH,
33                 NODE,
34                 EDGE,
35                 ID,
36                 LABEL,
37                 SOURCE,
38                 TARGET
39         };
40
41         struct NodeAttributes {
42                 int id;
43                 std::wstring label;
44         };
45
46         struct EdgeAttributes {
47                 int source;
48                 int target;
49                 std::wstring label;
50         };
51
52         void error();
53         void nextToken();
54         void compare(Token token);
55         void value(ValueType parent, ValueType key);
56         void list(ValueType parent);
57         bool parse();
58
59         ValueType valueType();
60
61         void clearAttributes();
62         void setVertexAttributes(Vertex *vertex);
63         void setEdgeAttributes(Edge *edge);
64
65         Vertex *addVertex(int id);
66         Edge *addEdge();
67
68         std::wstring _string;
69         lexstream _fs;
70         int _int;
71         float _float;
72         Token _token;
73         unsigned _line;
74
75         NodeAttributes _nodeAttributes;
76         EdgeAttributes _edgeAttributes;
77
78         std::map<int, Vertex*> _vertexes;
79
80         Graph *_graph;
81 };
82
83 #endif // GML_H_