Changeset 1133:9fd485470fee in lemon-0.x for src/work/deba/graph_writer.h
- Timestamp:
- 02/07/05 11:48:14 (19 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1532
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/work/deba/graph_writer.h
r1115 r1133 34 34 namespace lemon { 35 35 36 /// \brief Standard WriterTraits for the GraphWriter class. 37 /// 38 /// Standard WriterTraits for the GraphWriter class. 39 /// It defines standard writing method for all type of value. 36 40 struct DefaultWriterTraits { 37 41 42 /// \brief Template class for writing an value. 43 /// 44 /// Template class for writing an value. 38 45 template <typename _Value> 39 46 struct Writer { 47 /// The value type. 40 48 typedef _Value Value; 41 49 50 /// \brief Writes a value from the given stream. 51 /// 52 /// Writes a value from the given stream. 42 53 void write(std::ostream& os, const Value& value) { 43 54 os << value << '\t'; … … 48 59 49 60 61 /// \brief Writer class for quoted strings. 62 /// 63 /// Writer class for quoted strings. It can process the escape 64 /// sequences in the string. 50 65 class QuotedStringWriter { 51 66 public: 52 67 typedef std::string Value; 53 68 69 /// \brief Constructor for the writer. 70 /// 71 /// Constructor for the writer. If the given parameter is true 72 /// the writer creates escape sequences from special characters. 54 73 QuotedStringWriter(bool _escaped = true) : escaped(_escaped) {} 55 74 75 /// \brief Writes a quoted string from the given stream. 76 /// 77 /// Writes a quoted string from the given stream. 56 78 void write(std::ostream& os, const std::string& value) { 57 79 os << "\""; … … 118 140 }; 119 141 120 // Graph writer121 142 143 /// \brief The graph writer class. 144 /// 145 /// The writer class for the graph output. 146 /// \see graph-io-page 122 147 template <typename _Graph, typename _WriterTraits = DefaultWriterTraits> 123 148 class GraphWriter { … … 131 156 132 157 typedef _WriterTraits WriterTraits; 133 158 159 /// \brief Construct a new GraphWriter. 160 /// 161 /// Construct a new GraphWriter. It writes from the given map, 162 /// it constructs the given map and it use the given writer as the 163 /// default skipper. 134 164 GraphWriter(std::ostream& _os, Graph& _graph) : os(_os), graph(_graph) {} 135 165 136 166 167 /// \brief Destruct the graph writer. 168 /// 169 /// Destruct the graph writer. 137 170 ~GraphWriter() { 138 171 for (typename NodeMapWriters::iterator it = node_map_writers.begin(); … … 150 183 // Node map rules 151 184 185 /// \brief Add a new node map writer command for the writer. 186 /// 187 /// Add a new node map writer command for the writer. 152 188 template <typename Map> 153 189 GraphWriter& addNodeMap(std::string name, const Map& map) { … … 156 192 } 157 193 194 /// \brief Add a new node map writer command for the writer. 195 /// 196 /// Add a new node map writer command for the writer. 158 197 template <typename Writer, typename Map> 159 198 GraphWriter& addNodeMap(std::string name, const Map& map, 160 199 const Writer& writer = Writer()) { 161 // if (node_map_writers.find(name) != node_map_writers.end()) {162 // throw Exception() << "Multiple write rule for node map: "163 // << name;164 // }165 200 node_map_writers.push_back( 166 201 make_pair(name, new MapWriter<Node, Map, Writer>(map, writer))); … … 170 205 // Edge map rules 171 206 207 /// \brief Add a new edge map writer command for the writer. 208 /// 209 /// Add a new edge map writer command for the writer. 172 210 template <typename Map> 173 211 GraphWriter& addEdgeMap(std::string name, const Map& map) { 174 return addEdgeMap<typename WriterTraits::template Writer<typename Map::Value>, Map>(name, map); 175 } 176 177 212 return addEdgeMap<typename WriterTraits::template Writer< 213 typename Map::Value>, Map>(name, map); 214 } 215 216 217 /// \brief Add a new edge map writer command for the writer. 218 /// 219 /// Add a new edge map writer command for the writer. 178 220 template <typename Writer, typename Map> 179 GraphWriter& addEdgeMap(std::string name, const Map& map, const Writer& writer = Writer()) { 180 // if (edge_map_writers.find(name) != edge_map_writers.end()) { 181 // throw Exception() << "Multiple write rule for edge map: " << name; 182 // } 183 edge_map_writers.push_back(make_pair(name, new MapWriter<Edge, Map, Writer>(map, writer))); 221 GraphWriter& addEdgeMap(std::string name, 222 const Map& map, const Writer& writer = Writer()) { 223 edge_map_writers.push_back(make_pair(name, 224 new MapWriter<Edge, Map, Writer>(map, writer))); 184 225 return *this; 185 226 } 186 227 187 // Node rules 228 /// \brief Add a new labeled node writer for the writer. 229 /// 230 /// Add a new labeled node writer for the writer. 188 231 GraphWriter& addNode(std::string name, const Node& node) { 189 // if (node_writers.find(name) != node_writers.end()) {190 // throw Exception() << "Multiple write rule for node";191 // }192 232 node_writers.push_back(make_pair(name, node)); 193 233 return *this; 194 234 } 195 235 196 // Edge rules 197 236 /// \brief Add a new labeled edge writer for the writer. 237 /// 238 /// Add a new labeled edge writer for the writer. 198 239 GraphWriter& addEdge(std::string name, const Edge& edge) { 199 // if (edge_writers.find(name) != edge_writers.end()) {200 // throw Exception() << "Multiple write rule for edge";201 // }202 240 edge_writers.push_back(make_pair(name, edge)); 203 241 return *this; 204 242 } 205 243 206 void write() { 244 /// \brief Executes the writer commands. 245 /// 246 /// Executes the writer commands. 247 void run() { 207 248 writeNodeSet(); 208 249 writeEdgeSet();
Note: See TracChangeset
for help on using the changeset viewer.