[Lemon-commits] Balazs Dezso: Fix skip*() functions is GraphWrit...
Lemon HG
hg at lemon.cs.elte.hu
Tue Jul 1 22:40:35 CEST 2008
details: http://lemon.cs.elte.hu/hg/lemon/rev/33e45a9b868c
changeset: 185:33e45a9b868c
user: Balazs Dezso <deba [at] inf.elte.hu>
date: Tue Jul 01 21:21:49 2008 +0200
description:
Fix skip*() functions is GraphWriters (Ticket #107)
diffstat:
1 file changed, 108 insertions(+)
lemon/lgf_writer.h | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++++
diffs (187 lines):
diff -r 716b220697a0 -r 33e45a9b868c lemon/lgf_writer.h
--- a/lemon/lgf_writer.h Thu Mar 27 16:27:23 2008 +0100
+++ b/lemon/lgf_writer.h Tue Jul 01 21:21:49 2008 +0200
@@ -603,6 +603,7 @@
/// The \c \@nodes section will be not written to the stream.
DigraphWriter& skipNodes() {
LEMON_ASSERT(!_skip_nodes, "Multiple usage of skipNodes() member");
+ _skip_nodes = true;
return *this;
}
@@ -611,6 +612,7 @@
/// The \c \@arcs section will be not written to the stream.
DigraphWriter& skipArcs() {
LEMON_ASSERT(!_skip_arcs, "Multiple usage of skipArcs() member");
+ _skip_arcs = true;
return *this;
}
@@ -675,6 +677,30 @@
*_os << '\t';
}
*_os << std::endl;
+ }
+ }
+
+ void createNodeIndex() {
+ _writer_bits::MapStorageBase<Node>* label = 0;
+ for (typename NodeMaps::iterator it = _node_maps.begin();
+ it != _node_maps.end(); ++it) {
+ if (it->first == "label") {
+ label = it->second;
+ break;
+ }
+ }
+
+ if (label == 0) {
+ for (NodeIt n(_digraph); n != INVALID; ++n) {
+ std::ostringstream os;
+ os << _digraph.id(n);
+ _node_index.insert(std::make_pair(n, os.str()));
+ }
+ } else {
+ for (NodeIt n(_digraph); n != INVALID; ++n) {
+ std::string value = label->get(n);
+ _node_index.insert(std::make_pair(n, value));
+ }
}
}
@@ -745,6 +771,30 @@
}
}
+ void createArcIndex() {
+ _writer_bits::MapStorageBase<Arc>* label = 0;
+ for (typename ArcMaps::iterator it = _arc_maps.begin();
+ it != _arc_maps.end(); ++it) {
+ if (it->first == "label") {
+ label = it->second;
+ break;
+ }
+ }
+
+ if (label == 0) {
+ for (ArcIt a(_digraph); a != INVALID; ++a) {
+ std::ostringstream os;
+ os << _digraph.id(a);
+ _arc_index.insert(std::make_pair(a, os.str()));
+ }
+ } else {
+ for (ArcIt a(_digraph); a != INVALID; ++a) {
+ std::string value = label->get(a);
+ _arc_index.insert(std::make_pair(a, value));
+ }
+ }
+ }
+
void writeAttributes() {
if (_attributes.empty()) return;
*_os << "@attributes";
@@ -771,9 +821,13 @@
void run() {
if (!_skip_nodes) {
writeNodes();
+ } else {
+ createNodeIndex();
}
if (!_skip_arcs) {
writeArcs();
+ } else {
+ createArcIndex();
}
writeAttributes();
}
@@ -1115,6 +1169,7 @@
/// The \c \@nodes section will be not written to the stream.
GraphWriter& skipNodes() {
LEMON_ASSERT(!_skip_nodes, "Multiple usage of skipNodes() member");
+ _skip_nodes = true;
return *this;
}
@@ -1123,6 +1178,7 @@
/// The \c \@edges section will be not written to the stream.
GraphWriter& skipEdges() {
LEMON_ASSERT(!_skip_edges, "Multiple usage of skipEdges() member");
+ _skip_edges = true;
return *this;
}
@@ -1187,6 +1243,30 @@
*_os << '\t';
}
*_os << std::endl;
+ }
+ }
+
+ void createNodeIndex() {
+ _writer_bits::MapStorageBase<Node>* label = 0;
+ for (typename NodeMaps::iterator it = _node_maps.begin();
+ it != _node_maps.end(); ++it) {
+ if (it->first == "label") {
+ label = it->second;
+ break;
+ }
+ }
+
+ if (label == 0) {
+ for (NodeIt n(_graph); n != INVALID; ++n) {
+ std::ostringstream os;
+ os << _graph.id(n);
+ _node_index.insert(std::make_pair(n, os.str()));
+ }
+ } else {
+ for (NodeIt n(_graph); n != INVALID; ++n) {
+ std::string value = label->get(n);
+ _node_index.insert(std::make_pair(n, value));
+ }
}
}
@@ -1257,6 +1337,30 @@
}
}
+ void createEdgeIndex() {
+ _writer_bits::MapStorageBase<Edge>* label = 0;
+ for (typename EdgeMaps::iterator it = _edge_maps.begin();
+ it != _edge_maps.end(); ++it) {
+ if (it->first == "label") {
+ label = it->second;
+ break;
+ }
+ }
+
+ if (label == 0) {
+ for (EdgeIt e(_graph); e != INVALID; ++e) {
+ std::ostringstream os;
+ os << _graph.id(e);
+ _edge_index.insert(std::make_pair(e, os.str()));
+ }
+ } else {
+ for (EdgeIt e(_graph); e != INVALID; ++e) {
+ std::string value = label->get(e);
+ _edge_index.insert(std::make_pair(e, value));
+ }
+ }
+ }
+
void writeAttributes() {
if (_attributes.empty()) return;
*_os << "@attributes";
@@ -1283,9 +1387,13 @@
void run() {
if (!_skip_nodes) {
writeNodes();
+ } else {
+ createNodeIndex();
}
if (!_skip_edges) {
writeEdges();
+ } else {
+ createEdgeIndex();
}
writeAttributes();
}
More information about the Lemon-commits
mailing list