34 #ifndef _CYMEALG_READWRITE_H_ 35 #define _CYMEALG_READWRITE_H_ 38 #include "chomp/system/config.h" 39 #include "chomp/system/textfile.h" 46 template <
class inType,
class Graph>
47 inline inType &
read (inType &in, Graph &g)
49 chomp::homology::ignorecomments (in);
56 int_t curVertex (g. countVertices () - 1);
63 chomp::homology::ignorecomments (in);
66 if ((nVertices < 0) && (in. peek () !=
'-'))
69 chomp::homology::ignoreline (in);
70 chomp::homology::ignorecomments (in);
75 if (in. peek () ==
'-')
77 if (in. peek () ==
'>')
79 chomp::homology::ignorecomments (in);
84 chomp::homology::ignorecomments (in);
87 typename Graph::weight_type weight;
88 bool weightRead (
false);
89 if (in. peek () ==
'[')
94 if (in. peek () ==
']')
97 chomp::homology::ignorecomments (in);
100 if (vertex < curVertex)
101 throw "Wrong order of vertices in the input stream.";
102 while (vertex > curVertex)
114 g. setWeight (curVertex, curEdge, weight);
121 while (g. countVertices () < nVertices)
130 template <
class wType>
139 template <
class outType,
class Graph>
140 inline outType &
write (outType &out,
const Graph &g,
bool writeWeights)
142 int_t nVertices (g. countVertices ());
143 out <<
"; Directed graph.\n";
144 out << nVertices <<
" vertices.\n";
145 for (int_t i = 0; i < nVertices; ++ i)
147 int_t nEdges (g. countEdges (i));
148 for (int_t j = 0; j < nEdges; ++ j)
150 out << i <<
" -> " << g. getEdge (i, j);
152 out <<
" [" << g. getWeight (i, j) <<
"]\n";
157 out <<
"; This is the end of the graph.\n";
164 template <
class wType>
165 inline std::ostream &operator << (std::ostream &out, const diGraph<wType> &g)
167 return write (out, g,
true);
173 #endif // _CYMEALG_READWRITE_H_ This class defines a weighted directed graph with very limited number of operations.
inType & read(inType &in, Graph &g)
Reads a graph in the text mode from an input stream.
std::istream & operator>>(std::istream &in, diGraph< wType > &g)
Reads a graph in the text mode from an input stream.
outType & write(outType &out, const Graph &g, bool writeWeights)
Outputs the graph to a text stream in a human-readable format.