Added support for GraphML input format
[hypercube:hypercube.git] / IO / io.h
1 #ifndef IO_H_
2 #define IO_H_
3
4 #include <string>
5 #include <sstream>
6 #include "CORE/graph.h"
7 #include "CORE/line.h"
8 #include "encoding.h"
9
10
11 class IO
12 {
13 public:
14         enum Error {Ok, OpenError, ReadError, WriteError, FormatError};
15         static std::ostringstream ioerr;
16 };
17
18
19 class InputProvider : public IO
20 {
21 public:
22         virtual Error readGraph(Graph *graph, const char *fileName,
23           Encoding *encoding) = 0;
24
25 protected:
26         static bool stringCaseCmp(const std::wstring &s1, const std::wstring &s2);
27 };
28
29 class OutputProvider : public IO
30 {
31 public:
32         virtual Error writeGraph(Graph *graph, const char *fileName) = 0;
33         virtual const char* type() = 0;
34         virtual const char* description() = 0;
35
36 protected:
37         struct Arrow {
38                 CoordinatesF p[3];
39         };
40
41         static CoordinatesF edgeTextPosition(const LineF &line, float size,
42           const CoordinatesF &textBox);
43         static CoordinatesF vertexTextPosition(const CoordinatesF &point,
44           float size);
45         static Arrow arrow(LineF &line, float size);
46
47         static void stringReplace(std::wstring &source, const std::wstring &find,
48           const std::wstring &replace);
49 };
50
51 #endif /* IO_H_ */