Added support for GraphML input format
[hypercube:hypercube.git] / IO / providers / graphml.h
1 #ifndef GRAPHML_H_
2 #define GRAPHML_H_
3
4 #include <string>
5 #include <fstream>
6 #include "IO/io.h"
7
8
9 class GraphmlGraphInput : public InputProvider
10 {
11 public:
12         virtual Error readGraph(Graph *graph, const char *fileName,
13           Encoding *encoding);
14
15 public:
16         enum Token {
17                 START,          /* Initial value */
18                 EOI,            /* End of File */
19                 ERROR,          /* Parse error */
20
21                 STRING,         /* Quoted string */
22                 IDENT,          /* Identificator (unknown) */
23
24                 LT,                     /* '<' */
25                 GT,                     /* '>' */
26                 EQ,                     /* '=' */
27                 AMP,            /* '&' */
28                 SLASH,          /* '/' */
29                 QM,                     /* '?' */
30         };
31
32         struct Relation {
33                 std::wstring node;
34                 std::wstring parent;
35         };
36
37         struct Attributes {
38                 std::wstring id;
39                 std::wstring source;
40                 std::wstring target;
41         };
42
43         Vertex *addVertex(const std::wstring &id);
44         Edge *addEdge(const std::wstring &source, const std::wstring &target);
45
46         void checkRelation(const std::wstring &node, const std::wstring &parent);
47
48         void error();
49         void nextToken();
50         void compare(Token token);
51         void data();
52         void attribute();
53         bool attributes();
54         void nextItem(const std::wstring &parent);
55         void elementType(const std::wstring &parent);
56         void element(const std::wstring &parent);
57         void xmlAttributes();
58         void xmlProlog();
59         void xml();
60         bool parse();
61
62         std::wifstream _fs;
63         std::wstring _string;
64         Token _token;
65         unsigned _line;
66         static const Relation relations[];
67
68         Attributes _attributes;
69         std::map<std::wstring, Vertex*> _vertexes;
70         Graph *_graph;
71 };
72
73 #endif // GRAPHML_H_