Function names are corrected according to naming conventions.
5 \page graph-io-page Graph Input-Output
7 The standard graph IO enables to store graphs and additional maps
8 in a flexible and efficient way.
10 \section format The general file format
12 The file contains at most four sections in the following order:
19 The nodeset section starts with the following line:
23 The next line contains the names of the nodemaps, separated by whitespaces. Each
24 following line describes a node in the graph: it contains the values of the
25 maps in the right order. The map named "id" should contain unique values
26 because it is regarded as an ID-map. For example:
30 id x-coord y-coord color
36 The edgeset section is very similar to the nodeset section, it has
37 the same coloumn oriented structure. It starts with the line
41 The next line contains the whitespace separated list of names of the maps.
42 Each of the next lines describes one edge. The first two elements in the line
43 are the IDs of the source and target (or tail and head) node of the edge as they occur in the ID node
44 map. You can also have an optional ID map on the edges for later reference.
54 The next section contains <em>labeled nodes</em> (i.e. nodes having a special
55 label on them). The section starts with
59 Each of the next lines contains a label for a node in the graph
60 and then the ID described in the nodeset section.
68 The last section describes the <em>labeled edges</em>
69 (i.e. edges having a special label on them). It starts with \c \@edges
70 and then each line contains the name of the edge and the ID.
78 The file may contain empty lines and comment lines. The comment lines
79 start with an \c # character.
81 The file ends with the
88 \section use Using graph input-output
89 The graph input and output is based on reading and writing commands. The user
90 adds reading and writing commands to the reader or writer class, then he
91 calls the \c run() method that executes all the given commands.
93 \subsection write Writing a graph
95 The \c GraphWriter class provides the graph output. To write a graph
96 you should first give writing commands for the writer. You can declare
97 write command as \c NodeMap or \c EdgeMap writing and labeled Node and
101 GraphWriter<ListGraph> writer(std::cout, graph);
104 The \c writeNodeMap() function declares a \c NodeMap writing command in the
105 \c GraphWriter. You should give a name of the map and the map
106 object as parameters. The NodeMap writing command with name "id" should write a
107 unique map because it is regarded as ID map.
109 \see IdMap, DescriptorMap
112 IdMap<ListGraph, Node> nodeIdMap;
113 writer.writeNodeMap("id", nodeIdMap);
115 writer.writeNodeMap("x-coord", xCoordMap);
116 writer.writeNodeMap("y-coord", yCoordMap);
117 writer.writeNodeMap("color", colorMap);
120 With the \c writeEdgeMap() member function you can give an edge map
121 writing command similar to the NodeMaps.
123 \see IdMap, DescriptorMap
126 DescriptorMap<ListGraph, Edge, ListGraph::EdgeMap<int> > edgeDescMap(graph);
127 writer.writeEdgeMap("descriptor", edgeDescMap);
129 writer.writeEdgeMap("weight", weightMap);
130 writer.writeEdgeMap("label", labelMap);
133 With \c writeNode() and \c writeEdge() functions you can designate Nodes and
134 Edges in the graph. For example, you can write out the source and target node
135 of a maximum flow instance.
138 writer.writeNode("source", sourceNode);
139 writer.writeNode("target", targetNode);
141 writer.writeEdge("observed", edge);
144 After you give all write commands you must call the \c run() member
145 function, which executes all the writing commands.
151 \subsection reading Reading a graph
153 The given file format may contain several maps and labeled nodes or edges.
154 If you read a graph you need not read all the maps and items just those
155 that you need. The interface of the \c GraphReader is very similar to
156 the GraphWriter but the reading method does not depend on the order of the
159 The reader object assumes that each not readed value does not contain
160 whitespaces, therefore it has some extra possibilities to control how
161 it should skip the values when the string representation contains spaces.
164 GraphReader<ListGraph> reader(std::cin, graph);
167 The \c readNodeMap() function reads a map from the \c \@nodeset section.
168 If there is a map that you do not want to read from the file and there are
169 whitespaces in the string represenation of the values then you should
170 call the \c skipNodeMap() template member function with proper parameters.
172 \see QuotedStringReader
175 reader.readNodeMap("x-coord", xCoordMap);
176 reader.readNodeMap("y-coord", yCoordMap);
178 reader.readNodeMap<QuotedStringReader>("label", labelMap);
179 reader.skipNodeMap<QuotedStringReader>("description");
181 reader.readNodeMap("color", colorMap);
184 With the \c readEdgeMap() member function you can give an edge map
185 reading command similar to the NodeMaps.
188 reader.readEdgeMap("weight", weightMap);
189 reader.readEdgeMap("label", labelMap);
192 With \c readNode() and \c readEdge() functions you can read labeled Nodes and
196 reader.readNode("source", sourceNode);
197 reader.readNode("target", targetNode);
199 reader.readEdge("observed", edge);
202 After you give all read commands you must call the \c run() member
203 function, which executes all the commands.
209 \section types The background of Reading and Writing
210 The \c GraphReader should know how to read a Value from the given map.
211 By the default implementation the input operator reads a value from
212 the stream and the type of the readed value is the value type of the given map.
213 When the reader should skip a value in the stream, because you do not
214 want to store it in map, the reader skips a character sequence without
217 If you want to change the functionality of the reader, you can use
218 template parameters to specialize it. When you give a reading
219 command for a map you can give a Reader type as template parameter.
220 With this template parameter you can control how the Reader reads
221 a value from the stream.
223 The reader has the next structure:
226 typedef TypeName Value;
228 void read(std::istream& is, Value& value);
232 By example, the \c "strings" nodemap contains strings and you do not need
233 the value of the string just the length. Then you can implement own Reader
237 struct LengthReader {
240 void read(std::istream& is, Value& value) {
243 value = tmp.length();
247 reader.readNodeMap<LengthReader>("strings", lengthMap);
250 The global functionality of the reader class can be changed by giving a
251 special template parameter for the GraphReader class. By default, the
252 template parameter is \c DefaultReaderTraits. A reader traits class
253 should provide an inner template class Reader for each type, and an
254 DefaultReader for skipping a value.
256 The specialization of the writing should be very similar to the reading.