gravatar
deba@inf.elte.hu
deba@inf.elte.hu
Revert 356930927a71 and add TEMPLATE_GRAPH_TYPEDEFS instead (ticket #89)
0 3 0
default
3 files changed with 65 insertions and 118 deletions:
↑ Collapse diff ↑
Ignore white space 192 line context
1 1
/* -*- C++ -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library
4 4
 *
5 5
 * Copyright (C) 2003-2008
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
14 14
 * express or implied, and with no claim as to its suitability for any
15 15
 * purpose.
16 16
 *
17 17
 */
18 18

	
19 19
#ifndef LEMON_GRAPH_UTILS_H
20 20
#define LEMON_GRAPH_UTILS_H
21 21

	
22 22
#include <iterator>
23 23
#include <vector>
24 24
#include <map>
25 25
#include <cmath>
26 26
#include <algorithm>
27 27

	
28 28
#include <lemon/bits/invalid.h>
29 29
#include <lemon/bits/utility.h>
30 30
#include <lemon/maps.h>
31 31
#include <lemon/bits/traits.h>
32 32

	
33 33
#include <lemon/bits/alteration_notifier.h>
34 34
#include <lemon/bits/default_map.h>
35 35

	
36 36
///\ingroup gutils
37 37
///\file
38 38
///\brief Graph utilities.
39 39

	
40 40
namespace lemon {
41 41

	
42 42
  /// \addtogroup gutils
43 43
  /// @{
44 44

	
45
  namespace _graph_utils_bits {
46
    template <typename Graph>
47
    struct Node { typedef typename Graph::Node type; };
48

	
49
    template <typename Graph>
50
    struct NodeIt { typedef typename Graph::NodeIt type; };
51

	
52
    template <typename Graph>
53
    struct Arc { typedef typename Graph::Arc type; };
54

	
55
    template <typename Graph>
56
    struct ArcIt { typedef typename Graph::ArcIt type; };
57

	
58
    template <typename Graph>
59
    struct Edge { typedef typename Graph::Edge type; };
60

	
61
    template <typename Graph>
62
    struct EdgeIt { typedef typename Graph::EdgeIt type; };
63

	
64
    template <typename Graph>
65
    struct OutArcIt { typedef typename Graph::OutArcIt type; };
66

	
67
    template <typename Graph>
68
    struct InArcIt { typedef typename Graph::InArcIt type; };
69

	
70
    template <typename Graph>
71
    struct IncEdgeIt { typedef typename Graph::IncEdgeIt type; };
72

	
73
    template <typename Graph>
74
    struct BoolNodeMap { 
75
      typedef typename Graph::template NodeMap<bool> type; 
76
    };
77

	
78
    template <typename Graph>
79
    struct IntNodeMap { 
80
      typedef typename Graph::template NodeMap<int> type; 
81
    };
82

	
83
    template <typename Graph>
84
    struct DoubleNodeMap { 
85
      typedef typename Graph::template NodeMap<double> type; 
86
    };
87

	
88
    template <typename Graph>
89
    struct BoolArcMap { 
90
      typedef typename Graph::template ArcMap<bool> type; 
91
    };
92

	
93
    template <typename Graph>
94
    struct IntArcMap { 
95
      typedef typename Graph::template ArcMap<int> type; 
96
    };
97

	
98
    template <typename Graph>
99
    struct DoubleArcMap { 
100
      typedef typename Graph::template ArcMap<double> type; 
101
    };
102

	
103
    template <typename Graph>
104
    struct BoolEdgeMap { 
105
      typedef typename Graph::template EdgeMap<bool> type; 
106
    };
107

	
108
    template <typename Graph>
109
    struct IntEdgeMap { 
110
      typedef typename Graph::template EdgeMap<int> type; 
111
    };
112

	
113
    template <typename Graph>
114
    struct DoubleEdgeMap { 
115
      typedef typename Graph::template EdgeMap<double> type; 
116
    };
117

	
118
    
119
  }
120

	
121 45
  ///Creates convenience typedefs for the digraph types and iterators
122 46

	
123 47
  ///This \c \#define creates convenience typedefs for the following types
124 48
  ///of \c Digraph: \c Node,  \c NodeIt, \c Arc, \c ArcIt, \c InArcIt,
125 49
  ///\c OutArcIt, \c BoolNodeMap, \c IntNodeMap, \c DoubleNodeMap, 
126
  ///\c BoolArcMap, \c IntArcMap, \c DoubleArcMap. 
50
  ///\c BoolArcMap, \c IntArcMap, \c DoubleArcMap.
51
  ///
52
  ///\note If the graph type is a dependent type, ie. the graph type depend
53
  ///on a template parameter, then use \c TEMPLATE_DIGRAPH_TYPEDEFS()
54
  ///macro.
127 55
#define DIGRAPH_TYPEDEFS(Digraph)					\
128
  typedef typename ::lemon::_graph_utils_bits::				\
129
  Node<Digraph>::type Node;						\
130
  typedef typename ::lemon::_graph_utils_bits::				\
131
  NodeIt<Digraph>::type	NodeIt;						\
132
  typedef typename ::lemon::_graph_utils_bits::				\
133
  Arc<Digraph>::type Arc;						\
134
  typedef typename ::lemon::_graph_utils_bits::				\
135
  ArcIt<Digraph>::type ArcIt;						\
136
  typedef typename ::lemon::_graph_utils_bits::				\
137
  OutArcIt<Digraph>::type OutArcIt;					\
138
  typedef typename ::lemon::_graph_utils_bits::				\
139
  InArcIt<Digraph>::type InArcIt;					\
140
  typedef typename ::lemon::_graph_utils_bits::				\
141
  BoolNodeMap<Digraph>::type BoolNodeMap;				\
142
  typedef typename ::lemon::_graph_utils_bits::				\
143
  IntNodeMap<Digraph>::type IntNodeMap;					\
144
  typedef typename ::lemon::_graph_utils_bits::				\
145
  DoubleNodeMap<Digraph>::type DoubleNodeMap;				\
146
  typedef typename ::lemon::_graph_utils_bits::				\
147
  BoolArcMap<Digraph>::type BoolArcMap;					\
148
  typedef typename ::lemon::_graph_utils_bits::				\
149
  IntArcMap<Digraph>::type IntArcMap;					\
150
  typedef typename ::lemon::_graph_utils_bits::				\
151
  DoubleArcMap<Digraph>::type DoubleArcMap
56
  typedef Digraph::Node Node;						\
57
  typedef Digraph::NodeIt NodeIt;					\
58
  typedef Digraph::Arc Arc;						\
59
  typedef Digraph::ArcIt ArcIt;						\
60
  typedef Digraph::InArcIt InArcIt;					\
61
  typedef Digraph::OutArcIt OutArcIt;					\
62
  typedef Digraph::NodeMap<bool> BoolNodeMap;				\
63
  typedef Digraph::NodeMap<int> IntNodeMap;				\
64
  typedef Digraph::NodeMap<double> DoubleNodeMap;			\
65
  typedef Digraph::ArcMap<bool> BoolArcMap;				\
66
  typedef Digraph::ArcMap<int> IntArcMap;				\
67
  typedef Digraph::ArcMap<double> DoubleArcMap
152 68

	
69
  ///Creates convenience typedefs for the digraph types and iterators
153 70

	
71
  ///\see DIGRAPH_TYPEDEFS
72
  ///
73
  ///\note Use this macro, if the graph type is a dependent type,
74
  ///ie. the graph type depend on a template parameter.
75
#define TEMPLATE_DIGRAPH_TYPEDEFS(Digraph)				\
76
  typedef typename Digraph::Node Node;					\
77
  typedef typename Digraph::NodeIt NodeIt;				\
78
  typedef typename Digraph::Arc Arc;					\
79
  typedef typename Digraph::ArcIt ArcIt;				\
80
  typedef typename Digraph::InArcIt InArcIt;				\
81
  typedef typename Digraph::OutArcIt OutArcIt;				\
82
  typedef typename Digraph::template NodeMap<bool> BoolNodeMap;		\
83
  typedef typename Digraph::template NodeMap<int> IntNodeMap;		\
84
  typedef typename Digraph::template NodeMap<double> DoubleNodeMap;	\
85
  typedef typename Digraph::template ArcMap<bool> BoolArcMap;		\
86
  typedef typename Digraph::template ArcMap<int> IntArcMap;		\
87
  typedef typename Digraph::template ArcMap<double> DoubleArcMap
88
  
154 89
  ///Creates convenience typedefs for the graph types and iterators
155 90

	
156 91
  ///This \c \#define creates the same convenience typedefs as defined
157 92
  ///by \ref DIGRAPH_TYPEDEFS(Graph) and six more, namely it creates
158 93
  ///\c Edge, \c EdgeIt, \c IncEdgeIt, \c BoolEdgeMap, \c IntEdgeMap,
159 94
  ///\c DoubleEdgeMap.
95
  ///
96
  ///\note If the graph type is a dependent type, ie. the graph type depend
97
  ///on a template parameter, then use \c TEMPLATE_DIGRAPH_TYPEDEFS()
98
  ///macro.
160 99
#define GRAPH_TYPEDEFS(Graph)						\
161 100
  DIGRAPH_TYPEDEFS(Graph);						\
162
  typedef typename ::lemon::_graph_utils_bits::				\
163
  Edge<Graph>::type Edge;						\
164
  typedef typename ::lemon::_graph_utils_bits::				\
165
  EdgeIt<Graph>::type EdgeIt;						\
166
  typedef typename ::lemon::_graph_utils_bits::				\
167
  IncEdgeIt<Graph>::type IncEdgeIt;					\
168
  typedef typename ::lemon::_graph_utils_bits::				\
169
  BoolEdgeMap<Graph>::type BoolEdgeMap;					\
170
  typedef typename ::lemon::_graph_utils_bits::				\
171
  IntEdgeMap<Graph>::type IntEdgeMap;					\
172
  typedef typename ::lemon::_graph_utils_bits::				\
173
  DoubleEdgeMap<Graph>::type DoubleEdgeMap
101
  typedef Graph::Edge Edge;						\
102
  typedef Graph::EdgeIt EdgeIt;						\
103
  typedef Graph::IncEdgeIt IncEdgeIt;					\
104
  typedef Graph::EdgeMap<bool> BoolEdgeMap;				\
105
  typedef Graph::EdgeMap<int> IntEdgeMap;				\
106
  typedef Graph::EdgeMap<double> DoubleEdgeMap
174 107

	
108
  ///Creates convenience typedefs for the graph types and iterators
109

	
110
  ///\see GRAPH_TYPEDEFS
111
  ///
112
  ///\note Use this macro, if the graph type is a dependent type,
113
  ///ie. the graph type depend on a template parameter.
114
#define TEMPLATE_GRAPH_TYPEDEFS(Graph)					\
115
  TEMPLATE_DIGRAPH_TYPEDEFS(Graph);					\
116
  typedef typename Graph::Edge Edge;					\
117
  typedef typename Graph::EdgeIt EdgeIt;				\
118
  typedef typename Graph::IncEdgeIt IncEdgeIt;				\
119
  typedef typename Graph::template EdgeMap<bool> BoolEdgeMap;		\
120
  typedef typename Graph::template EdgeMap<int> IntEdgeMap;		\
121
  typedef typename Graph::template EdgeMap<double> DoubleEdgeMap
175 122

	
176 123
  /// \brief Function to count the items in the graph.
177 124
  ///
178 125
  /// This function counts the items (nodes, arcs etc) in the graph.
179 126
  /// The complexity of the function is O(n) because
180 127
  /// it iterates on all of the items.
181 128
  template <typename Graph, typename Item>
182 129
  inline int countItems(const Graph& g) {
183 130
    typedef typename ItemSetTraits<Graph, Item>::ItemIt ItemIt;
184 131
    int num = 0;
185 132
    for (ItemIt it(g); it != INVALID; ++it) {
186 133
      ++num;
187 134
    }
188 135
    return num;
189 136
  }
190 137

	
191 138
  // Node counting:
192 139

	
193 140
  namespace _graph_utils_bits {
194 141
    
195 142
    template <typename Graph, typename Enable = void>
196 143
    struct CountNodesSelector {
197 144
      static int count(const Graph &g) {
198 145
        return countItems<Graph, typename Graph::Node>(g);
199 146
      }
200 147
    };
201 148

	
202 149
    template <typename Graph>
203 150
    struct CountNodesSelector<
204 151
      Graph, typename 
205 152
      enable_if<typename Graph::NodeNumTag, void>::type> 
206 153
    {
207 154
      static int count(const Graph &g) {
208 155
        return g.nodeNum();
209 156
      }
210 157
    };    
211 158
  }
212 159

	
213 160
  /// \brief Function to count the nodes in the graph.
214 161
  ///
215 162
  /// This function counts the nodes in the graph.
216 163
  /// The complexity of the function is O(n) but for some
217 164
  /// graph structures it is specialized to run in O(1).
218 165
  ///
219 166
  /// If the graph contains a \e nodeNum() member function and a 
220 167
  /// \e NodeNumTag tag then this function calls directly the member
221 168
  /// function to query the cardinality of the node set.
222 169
  template <typename Graph>
223 170
  inline int countNodes(const Graph& g) {
224 171
    return _graph_utils_bits::CountNodesSelector<Graph>::count(g);
225 172
  }
226 173

	
227 174
  // Arc counting:
228 175

	
229 176
  namespace _graph_utils_bits {
230 177
    
231 178
    template <typename Graph, typename Enable = void>
232 179
    struct CountArcsSelector {
233 180
      static int count(const Graph &g) {
234 181
        return countItems<Graph, typename Graph::Arc>(g);
235 182
      }
236 183
    };
237 184

	
238 185
    template <typename Graph>
239 186
    struct CountArcsSelector<
240 187
      Graph, 
241 188
      typename enable_if<typename Graph::ArcNumTag, void>::type> 
242 189
    {
243 190
      static int count(const Graph &g) {
244 191
        return g.arcNum();
245 192
      }
246 193
    };    
247 194
  }
248 195

	
249 196
  /// \brief Function to count the arcs in the graph.
250 197
  ///
251 198
  /// This function counts the arcs in the graph.
252 199
  /// The complexity of the function is O(e) but for some
253 200
  /// graph structures it is specialized to run in O(1).
254 201
  ///
255 202
  /// If the graph contains a \e arcNum() member function and a 
256 203
  /// \e EdgeNumTag tag then this function calls directly the member
257 204
  /// function to query the cardinality of the arc set.
258 205
  template <typename Graph>
259 206
  inline int countArcs(const Graph& g) {
260 207
    return _graph_utils_bits::CountArcsSelector<Graph>::count(g);
261 208
  }
262 209

	
263 210
  // Edge counting:
264 211
  namespace _graph_utils_bits {
265 212
    
266 213
    template <typename Graph, typename Enable = void>
267 214
    struct CountEdgesSelector {
268 215
      static int count(const Graph &g) {
269 216
        return countItems<Graph, typename Graph::Edge>(g);
270 217
      }
... ...
@@ -2068,193 +2015,193 @@
2068 2015
	}
2069 2016
      }
2070 2017
    };
2071 2018

	
2072 2019
  public:
2073 2020

	
2074 2021
    /// \brief Constructor.
2075 2022
    ///
2076 2023
    /// Constructor for creating out-degree map.
2077 2024
    explicit OutDegMap(const Digraph& digraph) 
2078 2025
      : _digraph(digraph), _deg(digraph) {
2079 2026
      Parent::attach(_digraph.notifier(typename Digraph::Arc()));
2080 2027
      
2081 2028
      for(typename Digraph::NodeIt it(_digraph); it != INVALID; ++it) {
2082 2029
	_deg[it] = countOutArcs(_digraph, it);
2083 2030
      }
2084 2031
    }
2085 2032

	
2086 2033
    /// Gives back the out-degree of a Node.
2087 2034
    int operator[](const Key& key) const {
2088 2035
      return _deg[key];
2089 2036
    }
2090 2037

	
2091 2038
  protected:
2092 2039
    
2093 2040
    typedef typename Digraph::Arc Arc;
2094 2041

	
2095 2042
    virtual void add(const Arc& arc) {
2096 2043
      ++_deg[_digraph.source(arc)];
2097 2044
    }
2098 2045

	
2099 2046
    virtual void add(const std::vector<Arc>& arcs) {
2100 2047
      for (int i = 0; i < int(arcs.size()); ++i) {
2101 2048
        ++_deg[_digraph.source(arcs[i])];
2102 2049
      }
2103 2050
    }
2104 2051

	
2105 2052
    virtual void erase(const Arc& arc) {
2106 2053
      --_deg[_digraph.source(arc)];
2107 2054
    }
2108 2055

	
2109 2056
    virtual void erase(const std::vector<Arc>& arcs) {
2110 2057
      for (int i = 0; i < int(arcs.size()); ++i) {
2111 2058
        --_deg[_digraph.source(arcs[i])];
2112 2059
      }
2113 2060
    }
2114 2061

	
2115 2062
    virtual void build() {
2116 2063
      for(typename Digraph::NodeIt it(_digraph); it != INVALID; ++it) {
2117 2064
	_deg[it] = countOutArcs(_digraph, it);
2118 2065
      }      
2119 2066
    }
2120 2067

	
2121 2068
    virtual void clear() {
2122 2069
      for(typename Digraph::NodeIt it(_digraph); it != INVALID; ++it) {
2123 2070
	_deg[it] = 0;
2124 2071
      }
2125 2072
    }
2126 2073
  private:
2127 2074
    
2128 2075
    const Digraph& _digraph;
2129 2076
    AutoNodeMap _deg;
2130 2077
  };
2131 2078

	
2132 2079

	
2133 2080
  ///Dynamic arc look up between given endpoints.
2134 2081
  
2135 2082
  ///\ingroup gutils
2136 2083
  ///Using this class, you can find an arc in a digraph from a given
2137 2084
  ///source to a given target in amortized time <em>O(log d)</em>,
2138 2085
  ///where <em>d</em> is the out-degree of the source node.
2139 2086
  ///
2140 2087
  ///It is possible to find \e all parallel arcs between two nodes with
2141 2088
  ///the \c findFirst() and \c findNext() members.
2142 2089
  ///
2143 2090
  ///See the \ref ArcLookUp and \ref AllArcLookUp classes if your
2144 2091
  ///digraph is not changed so frequently.
2145 2092
  ///
2146 2093
  ///This class uses a self-adjusting binary search tree, Sleator's
2147 2094
  ///and Tarjan's Splay tree for guarantee the logarithmic amortized
2148 2095
  ///time bound for arc lookups. This class also guarantees the
2149 2096
  ///optimal time bound in a constant factor for any distribution of
2150 2097
  ///queries.
2151 2098
  ///
2152 2099
  ///\param G The type of the underlying digraph.  
2153 2100
  ///
2154 2101
  ///\sa ArcLookUp  
2155 2102
  ///\sa AllArcLookUp  
2156 2103
  template<class G>
2157 2104
  class DynArcLookUp 
2158 2105
    : protected ItemSetTraits<G, typename G::Arc>::ItemNotifier::ObserverBase
2159 2106
  {
2160 2107
  public:
2161 2108
    typedef typename ItemSetTraits<G, typename G::Arc>
2162 2109
    ::ItemNotifier::ObserverBase Parent;
2163 2110

	
2164
    DIGRAPH_TYPEDEFS(G);
2111
    TEMPLATE_DIGRAPH_TYPEDEFS(G);
2165 2112
    typedef G Digraph;
2166 2113

	
2167 2114
  protected:
2168 2115

	
2169 2116
    class AutoNodeMap : public DefaultMap<G, Node, Arc> {
2170 2117
    public:
2171 2118

	
2172 2119
      typedef DefaultMap<G, Node, Arc> Parent;
2173 2120

	
2174 2121
      AutoNodeMap(const G& digraph) : Parent(digraph, INVALID) {}
2175 2122
      
2176 2123
      virtual void add(const Node& node) {
2177 2124
	Parent::add(node);
2178 2125
	Parent::set(node, INVALID);
2179 2126
      }
2180 2127

	
2181 2128
      virtual void add(const std::vector<Node>& nodes) {
2182 2129
	Parent::add(nodes);
2183 2130
	for (int i = 0; i < int(nodes.size()); ++i) {
2184 2131
	  Parent::set(nodes[i], INVALID);
2185 2132
	}
2186 2133
      }
2187 2134

	
2188 2135
      virtual void build() {
2189 2136
	Parent::build();
2190 2137
	Node it;
2191 2138
	typename Parent::Notifier* nf = Parent::notifier();
2192 2139
	for (nf->first(it); it != INVALID; nf->next(it)) {
2193 2140
	  Parent::set(it, INVALID);
2194 2141
	}
2195 2142
      }
2196 2143
    };
2197 2144

	
2198 2145
    const Digraph &_g;
2199 2146
    AutoNodeMap _head;
2200 2147
    typename Digraph::template ArcMap<Arc> _parent;
2201 2148
    typename Digraph::template ArcMap<Arc> _left;
2202 2149
    typename Digraph::template ArcMap<Arc> _right;
2203 2150
    
2204 2151
    class ArcLess {
2205 2152
      const Digraph &g;
2206 2153
    public:
2207 2154
      ArcLess(const Digraph &_g) : g(_g) {}
2208 2155
      bool operator()(Arc a,Arc b) const 
2209 2156
      {
2210 2157
	return g.target(a)<g.target(b);
2211 2158
      }
2212 2159
    };
2213 2160
    
2214 2161
  public:
2215 2162
    
2216 2163
    ///Constructor
2217 2164

	
2218 2165
    ///Constructor.
2219 2166
    ///
2220 2167
    ///It builds up the search database.
2221 2168
    DynArcLookUp(const Digraph &g) 
2222 2169
      : _g(g),_head(g),_parent(g),_left(g),_right(g) 
2223 2170
    { 
2224 2171
      Parent::attach(_g.notifier(typename Digraph::Arc()));
2225 2172
      refresh(); 
2226 2173
    }
2227 2174
    
2228 2175
  protected:
2229 2176

	
2230 2177
    virtual void add(const Arc& arc) {
2231 2178
      insert(arc);
2232 2179
    }
2233 2180

	
2234 2181
    virtual void add(const std::vector<Arc>& arcs) {
2235 2182
      for (int i = 0; i < int(arcs.size()); ++i) {
2236 2183
	insert(arcs[i]);
2237 2184
      }
2238 2185
    }
2239 2186

	
2240 2187
    virtual void erase(const Arc& arc) {
2241 2188
      remove(arc);
2242 2189
    }
2243 2190

	
2244 2191
    virtual void erase(const std::vector<Arc>& arcs) {
2245 2192
      for (int i = 0; i < int(arcs.size()); ++i) {
2246 2193
	remove(arcs[i]);
2247 2194
      }     
2248 2195
    }
2249 2196

	
2250 2197
    virtual void build() {
2251 2198
      refresh();
2252 2199
    }
2253 2200

	
2254 2201
    virtual void clear() {
2255 2202
      for(NodeIt n(_g);n!=INVALID;++n) {
2256 2203
	_head.set(n, INVALID);
2257 2204
      }
2258 2205
    }
2259 2206

	
2260 2207
    void insert(Arc arc) {
... ...
@@ -2505,310 +2452,310 @@
2505 2452
    /// <em>O(</em>log<em>d)</em>, where <em>d</em> is the number of
2506 2453
    /// outgoing arcs of \c s.  
2507 2454
    ///\param s The source node 
2508 2455
    ///\param t The target node
2509 2456
    ///\return An arc from \c s to \c t if there exists, \ref INVALID
2510 2457
    /// otherwise.
2511 2458
    Arc findFirst(Node s, Node t) const
2512 2459
    {
2513 2460
      Arc a = _head[s];
2514 2461
      Arc r = INVALID;
2515 2462
      while (true) {
2516 2463
	if (_g.target(a) < t) {
2517 2464
	  if (_right[a] == INVALID) {
2518 2465
	    const_cast<DynArcLookUp&>(*this).splay(a);
2519 2466
	    return r;
2520 2467
	  } else {
2521 2468
	    a = _right[a];
2522 2469
	  }
2523 2470
	} else {
2524 2471
	  if (_g.target(a) == t) {
2525 2472
	    r = a;
2526 2473
	  }
2527 2474
	  if (_left[a] == INVALID) {
2528 2475
	    const_cast<DynArcLookUp&>(*this).splay(a);
2529 2476
	    return r;
2530 2477
	  } else {
2531 2478
	    a = _left[a];
2532 2479
	  }
2533 2480
	}
2534 2481
      }
2535 2482
    }
2536 2483

	
2537 2484
    ///Find the next arc between two nodes.
2538 2485
    
2539 2486
    ///Find the next arc between two nodes in time
2540 2487
    /// <em>O(</em>log<em>d)</em>, where <em>d</em> is the number of
2541 2488
    /// outgoing arcs of \c s.  
2542 2489
    ///\param s The source node 
2543 2490
    ///\param t The target node
2544 2491
    ///\return An arc from \c s to \c t if there exists, \ref INVALID
2545 2492
    /// otherwise.
2546 2493

	
2547 2494
    ///\note If \c e is not the result of the previous \c findFirst()
2548 2495
    ///operation then the amorized time bound can not be guaranteed.
2549 2496
#ifdef DOXYGEN
2550 2497
    Arc findNext(Node s, Node t, Arc a) const
2551 2498
#else
2552 2499
    Arc findNext(Node, Node t, Arc a) const
2553 2500
#endif
2554 2501
    {
2555 2502
      if (_right[a] != INVALID) {
2556 2503
	a = _right[a];
2557 2504
	while (_left[a] != INVALID) {
2558 2505
	  a = _left[a];
2559 2506
	}
2560 2507
	const_cast<DynArcLookUp&>(*this).splay(a);
2561 2508
      } else {
2562 2509
	while (_parent[a] != INVALID && _right[_parent[a]] ==  a) {
2563 2510
	  a = _parent[a];
2564 2511
	}
2565 2512
	if (_parent[a] == INVALID) {
2566 2513
	  return INVALID;
2567 2514
	} else {
2568 2515
	  a = _parent[a];
2569 2516
	  const_cast<DynArcLookUp&>(*this).splay(a);
2570 2517
	}
2571 2518
      }
2572 2519
      if (_g.target(a) == t) return a;
2573 2520
      else return INVALID;    
2574 2521
    }
2575 2522

	
2576 2523
  };
2577 2524

	
2578 2525
  ///Fast arc look up between given endpoints.
2579 2526
  
2580 2527
  ///\ingroup gutils
2581 2528
  ///Using this class, you can find an arc in a digraph from a given
2582 2529
  ///source to a given target in time <em>O(log d)</em>,
2583 2530
  ///where <em>d</em> is the out-degree of the source node.
2584 2531
  ///
2585 2532
  ///It is not possible to find \e all parallel arcs between two nodes.
2586 2533
  ///Use \ref AllArcLookUp for this purpose.
2587 2534
  ///
2588 2535
  ///\warning This class is static, so you should refresh() (or at least
2589 2536
  ///refresh(Node)) this data structure
2590 2537
  ///whenever the digraph changes. This is a time consuming (superlinearly
2591 2538
  ///proportional (<em>O(m</em>log<em>m)</em>) to the number of arcs).
2592 2539
  ///
2593 2540
  ///\param G The type of the underlying digraph.
2594 2541
  ///
2595 2542
  ///\sa DynArcLookUp
2596 2543
  ///\sa AllArcLookUp  
2597 2544
  template<class G>
2598 2545
  class ArcLookUp 
2599 2546
  {
2600 2547
  public:
2601
    DIGRAPH_TYPEDEFS(G);
2548
    TEMPLATE_DIGRAPH_TYPEDEFS(G);
2602 2549
    typedef G Digraph;
2603 2550

	
2604 2551
  protected:
2605 2552
    const Digraph &_g;
2606 2553
    typename Digraph::template NodeMap<Arc> _head;
2607 2554
    typename Digraph::template ArcMap<Arc> _left;
2608 2555
    typename Digraph::template ArcMap<Arc> _right;
2609 2556
    
2610 2557
    class ArcLess {
2611 2558
      const Digraph &g;
2612 2559
    public:
2613 2560
      ArcLess(const Digraph &_g) : g(_g) {}
2614 2561
      bool operator()(Arc a,Arc b) const 
2615 2562
      {
2616 2563
	return g.target(a)<g.target(b);
2617 2564
      }
2618 2565
    };
2619 2566
    
2620 2567
  public:
2621 2568
    
2622 2569
    ///Constructor
2623 2570

	
2624 2571
    ///Constructor.
2625 2572
    ///
2626 2573
    ///It builds up the search database, which remains valid until the digraph
2627 2574
    ///changes.
2628 2575
    ArcLookUp(const Digraph &g) :_g(g),_head(g),_left(g),_right(g) {refresh();}
2629 2576
    
2630 2577
  private:
2631 2578
    Arc refreshRec(std::vector<Arc> &v,int a,int b) 
2632 2579
    {
2633 2580
      int m=(a+b)/2;
2634 2581
      Arc me=v[m];
2635 2582
      _left[me] = a<m?refreshRec(v,a,m-1):INVALID;
2636 2583
      _right[me] = m<b?refreshRec(v,m+1,b):INVALID;
2637 2584
      return me;
2638 2585
    }
2639 2586
  public:
2640 2587
    ///Refresh the data structure at a node.
2641 2588

	
2642 2589
    ///Build up the search database of node \c n.
2643 2590
    ///
2644 2591
    ///It runs in time <em>O(d</em>log<em>d)</em>, where <em>d</em> is
2645 2592
    ///the number of the outgoing arcs of \c n.
2646 2593
    void refresh(Node n) 
2647 2594
    {
2648 2595
      std::vector<Arc> v;
2649 2596
      for(OutArcIt e(_g,n);e!=INVALID;++e) v.push_back(e);
2650 2597
      if(v.size()) {
2651 2598
	std::sort(v.begin(),v.end(),ArcLess(_g));
2652 2599
	_head[n]=refreshRec(v,0,v.size()-1);
2653 2600
      }
2654 2601
      else _head[n]=INVALID;
2655 2602
    }
2656 2603
    ///Refresh the full data structure.
2657 2604

	
2658 2605
    ///Build up the full search database. In fact, it simply calls
2659 2606
    ///\ref refresh(Node) "refresh(n)" for each node \c n.
2660 2607
    ///
2661 2608
    ///It runs in time <em>O(m</em>log<em>D)</em>, where <em>m</em> is
2662 2609
    ///the number of the arcs of \c n and <em>D</em> is the maximum
2663 2610
    ///out-degree of the digraph.
2664 2611

	
2665 2612
    void refresh() 
2666 2613
    {
2667 2614
      for(NodeIt n(_g);n!=INVALID;++n) refresh(n);
2668 2615
    }
2669 2616
    
2670 2617
    ///Find an arc between two nodes.
2671 2618
    
2672 2619
    ///Find an arc between two nodes in time <em>O(</em>log<em>d)</em>, where
2673 2620
    /// <em>d</em> is the number of outgoing arcs of \c s.
2674 2621
    ///\param s The source node
2675 2622
    ///\param t The target node
2676 2623
    ///\return An arc from \c s to \c t if there exists,
2677 2624
    ///\ref INVALID otherwise.
2678 2625
    ///
2679 2626
    ///\warning If you change the digraph, refresh() must be called before using
2680 2627
    ///this operator. If you change the outgoing arcs of
2681 2628
    ///a single node \c n, then
2682 2629
    ///\ref refresh(Node) "refresh(n)" is enough.
2683 2630
    ///
2684 2631
    Arc operator()(Node s, Node t) const
2685 2632
    {
2686 2633
      Arc e;
2687 2634
      for(e=_head[s];
2688 2635
	  e!=INVALID&&_g.target(e)!=t;
2689 2636
	  e = t < _g.target(e)?_left[e]:_right[e]) ;
2690 2637
      return e;
2691 2638
    }
2692 2639

	
2693 2640
  };
2694 2641

	
2695 2642
  ///Fast look up of all arcs between given endpoints.
2696 2643
  
2697 2644
  ///\ingroup gutils
2698 2645
  ///This class is the same as \ref ArcLookUp, with the addition
2699 2646
  ///that it makes it possible to find all arcs between given endpoints.
2700 2647
  ///
2701 2648
  ///\warning This class is static, so you should refresh() (or at least
2702 2649
  ///refresh(Node)) this data structure
2703 2650
  ///whenever the digraph changes. This is a time consuming (superlinearly
2704 2651
  ///proportional (<em>O(m</em>log<em>m)</em>) to the number of arcs).
2705 2652
  ///
2706 2653
  ///\param G The type of the underlying digraph.
2707 2654
  ///
2708 2655
  ///\sa DynArcLookUp
2709 2656
  ///\sa ArcLookUp  
2710 2657
  template<class G>
2711 2658
  class AllArcLookUp : public ArcLookUp<G>
2712 2659
  {
2713 2660
    using ArcLookUp<G>::_g;
2714 2661
    using ArcLookUp<G>::_right;
2715 2662
    using ArcLookUp<G>::_left;
2716 2663
    using ArcLookUp<G>::_head;
2717 2664

	
2718
    DIGRAPH_TYPEDEFS(G);
2665
    TEMPLATE_DIGRAPH_TYPEDEFS(G);
2719 2666
    typedef G Digraph;
2720 2667
    
2721 2668
    typename Digraph::template ArcMap<Arc> _next;
2722 2669
    
2723 2670
    Arc refreshNext(Arc head,Arc next=INVALID)
2724 2671
    {
2725 2672
      if(head==INVALID) return next;
2726 2673
      else {
2727 2674
	next=refreshNext(_right[head],next);
2728 2675
// 	_next[head]=next;
2729 2676
	_next[head]=( next!=INVALID && _g.target(next)==_g.target(head))
2730 2677
	  ? next : INVALID;
2731 2678
	return refreshNext(_left[head],head);
2732 2679
      }
2733 2680
    }
2734 2681
    
2735 2682
    void refreshNext()
2736 2683
    {
2737 2684
      for(NodeIt n(_g);n!=INVALID;++n) refreshNext(_head[n]);
2738 2685
    }
2739 2686
    
2740 2687
  public:
2741 2688
    ///Constructor
2742 2689

	
2743 2690
    ///Constructor.
2744 2691
    ///
2745 2692
    ///It builds up the search database, which remains valid until the digraph
2746 2693
    ///changes.
2747 2694
    AllArcLookUp(const Digraph &g) : ArcLookUp<G>(g), _next(g) {refreshNext();}
2748 2695

	
2749 2696
    ///Refresh the data structure at a node.
2750 2697

	
2751 2698
    ///Build up the search database of node \c n.
2752 2699
    ///
2753 2700
    ///It runs in time <em>O(d</em>log<em>d)</em>, where <em>d</em> is
2754 2701
    ///the number of the outgoing arcs of \c n.
2755 2702
    
2756 2703
    void refresh(Node n) 
2757 2704
    {
2758 2705
      ArcLookUp<G>::refresh(n);
2759 2706
      refreshNext(_head[n]);
2760 2707
    }
2761 2708
    
2762 2709
    ///Refresh the full data structure.
2763 2710

	
2764 2711
    ///Build up the full search database. In fact, it simply calls
2765 2712
    ///\ref refresh(Node) "refresh(n)" for each node \c n.
2766 2713
    ///
2767 2714
    ///It runs in time <em>O(m</em>log<em>D)</em>, where <em>m</em> is
2768 2715
    ///the number of the arcs of \c n and <em>D</em> is the maximum
2769 2716
    ///out-degree of the digraph.
2770 2717

	
2771 2718
    void refresh() 
2772 2719
    {
2773 2720
      for(NodeIt n(_g);n!=INVALID;++n) refresh(_head[n]);
2774 2721
    }
2775 2722
    
2776 2723
    ///Find an arc between two nodes.
2777 2724
    
2778 2725
    ///Find an arc between two nodes.
2779 2726
    ///\param s The source node
2780 2727
    ///\param t The target node
2781 2728
    ///\param prev The previous arc between \c s and \c t. It it is INVALID or
2782 2729
    ///not given, the operator finds the first appropriate arc.
2783 2730
    ///\return An arc from \c s to \c t after \c prev or
2784 2731
    ///\ref INVALID if there is no more.
2785 2732
    ///
2786 2733
    ///For example, you can count the number of arcs from \c u to \c v in the
2787 2734
    ///following way.
2788 2735
    ///\code
2789 2736
    ///AllArcLookUp<ListDigraph> ae(g);
2790 2737
    ///...
2791 2738
    ///int n=0;
2792 2739
    ///for(Arc e=ae(u,v);e!=INVALID;e=ae(u,v,e)) n++;
2793 2740
    ///\endcode
2794 2741
    ///
2795 2742
    ///Finding the first arc take <em>O(</em>log<em>d)</em> time, where
2796 2743
    /// <em>d</em> is the number of outgoing arcs of \c s. Then, the
2797 2744
    ///consecutive arcs are found in constant time.
2798 2745
    ///
2799 2746
    ///\warning If you change the digraph, refresh() must be called before using
2800 2747
    ///this operator. If you change the outgoing arcs of
2801 2748
    ///a single node \c n, then
2802 2749
    ///\ref refresh(Node) "refresh(n)" is enough.
2803 2750
    ///
2804 2751
#ifdef DOXYGEN
2805 2752
    Arc operator()(Node s, Node t, Arc prev=INVALID) const {}
2806 2753
#else
2807 2754
    using ArcLookUp<G>::operator() ;
2808 2755
    Arc operator()(Node s, Node t, Arc prev) const
2809 2756
    {
2810 2757
      return prev==INVALID?(*this)(s,t):_next[prev];
2811 2758
    }
2812 2759
#endif
2813 2760
      
2814 2761
  };
Ignore white space 192 line context
... ...
@@ -209,193 +209,193 @@
209 209
	return '\r';
210 210
      case 't':
211 211
	return '\t';
212 212
      case 'v':
213 213
	return '\v';
214 214
      case 'x':
215 215
	{
216 216
	  int code;
217 217
	  if (!is.get(c) || !isHex(c)) 
218 218
	    throw DataFormatError("Escape format error");
219 219
	  else if (code = valueHex(c), !is.get(c) || !isHex(c)) is.putback(c);
220 220
	  else code = code * 16 + valueHex(c);
221 221
	  return code;
222 222
	}
223 223
      default:
224 224
	{
225 225
	  int code;
226 226
	  if (!isOct(c)) 
227 227
	    throw DataFormatError("Escape format error");
228 228
	  else if (code = valueOct(c), !is.get(c) || !isOct(c)) 
229 229
	    is.putback(c);
230 230
	  else if (code = code * 8 + valueOct(c), !is.get(c) || !isOct(c)) 
231 231
	    is.putback(c);
232 232
	  else code = code * 8 + valueOct(c);
233 233
	  return code;
234 234
	}	      
235 235
      } 
236 236
    }
237 237
    
238 238
    std::istream& readToken(std::istream& is, std::string& str) {
239 239
      std::ostringstream os;
240 240

	
241 241
      char c;
242 242
      is >> std::ws;
243 243
      
244 244
      if (!is.get(c)) 
245 245
	return is;
246 246

	
247 247
      if (c == '\"') {
248 248
	while (is.get(c) && c != '\"') {
249 249
	  if (c == '\\') 
250 250
	    c = readEscape(is);
251 251
	  os << c;
252 252
	}
253 253
	if (!is) 
254 254
	  throw DataFormatError("Quoted format error");
255 255
      } else {
256 256
	is.putback(c);
257 257
	while (is.get(c) && !isWhiteSpace(c)) {
258 258
	  if (c == '\\') 
259 259
	    c = readEscape(is);
260 260
	  os << c;
261 261
	}
262 262
	if (!is) {
263 263
	  is.clear();
264 264
	} else {
265 265
	  is.putback(c);
266 266
	}
267 267
      }
268 268
      str = os.str();
269 269
      return is;
270 270
    }
271 271

	
272 272
    std::istream& readIdentifier(std::istream& is, std::string& str) {
273 273
      std::ostringstream os;
274 274

	
275 275
      char c;
276 276
      is >> std::ws;
277 277
      
278 278
      if (!is.get(c))
279 279
	return is;
280 280

	
281 281
      if (!isIdentifierFirstChar(c))
282 282
	throw DataFormatError("Wrong char in identifier");
283 283
      
284 284
      os << c;
285 285
      
286 286
      while (is.get(c) && !isWhiteSpace(c)) {
287 287
	if (!isIdentifierChar(c)) 
288 288
	  throw DataFormatError("Wrong char in identifier");	  
289 289
	os << c;
290 290
      }
291 291
      if (!is) is.clear();
292 292
     
293 293
      str = os.str();
294 294
      return is;
295 295
    }
296 296
    
297 297
  }
298 298
  
299 299
  /// \e
300 300
  template <typename _Digraph>
301 301
  class DigraphReader {
302 302
  public:
303 303

	
304 304
    typedef _Digraph Digraph;
305
    DIGRAPH_TYPEDEFS(Digraph);
305
    TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
306 306
    
307 307
  private:
308 308

	
309 309

	
310 310
    std::istream* _is;
311 311
    bool local_is;
312 312

	
313 313
    Digraph& _digraph;
314 314

	
315 315
    std::string _nodes_caption;
316 316
    std::string _arcs_caption;
317 317
    std::string _attributes_caption;
318 318

	
319 319
    typedef std::map<std::string, Node> NodeIndex;
320 320
    NodeIndex _node_index;
321 321
    typedef std::map<std::string, Arc> ArcIndex;
322 322
    ArcIndex _arc_index;
323 323
    
324 324
    typedef std::vector<std::pair<std::string, 
325 325
      _reader_bits::MapStorageBase<Node>*> > NodeMaps;    
326 326
    NodeMaps _node_maps; 
327 327

	
328 328
    typedef std::vector<std::pair<std::string,
329 329
      _reader_bits::MapStorageBase<Arc>*> >ArcMaps;
330 330
    ArcMaps _arc_maps;
331 331

	
332 332
    typedef std::multimap<std::string, _reader_bits::ValueStorageBase*> 
333 333
      Attributes;
334 334
    Attributes _attributes;
335 335

	
336 336
    bool _use_nodes;
337 337
    bool _use_arcs;
338 338

	
339 339
    int line_num;
340 340
    std::istringstream line;
341 341

	
342 342
  public:
343 343

	
344 344
    /// \e
345 345
    DigraphReader(std::istream& is, Digraph& digraph) 
346 346
      : _is(&is), local_is(false), _digraph(digraph),
347 347
	_use_nodes(false), _use_arcs(false) {}
348 348

	
349 349
    /// \e
350 350
    DigraphReader(const std::string& fn, Digraph& digraph) 
351 351
      : _is(new std::ifstream(fn.c_str())), local_is(true), _digraph(digraph),
352 352
    	_use_nodes(false), _use_arcs(false) {}
353 353

	
354 354

	
355 355
    /// \e
356 356
    DigraphReader(const char* fn, Digraph& digraph) 
357 357
      : _is(new std::ifstream(fn)), local_is(true), _digraph(digraph),
358 358
    	_use_nodes(false), _use_arcs(false) {}
359 359

	
360 360
    /// \e
361 361
    DigraphReader(DigraphReader& other) 
362 362
      : _is(other._is), local_is(other.local_is), _digraph(other._digraph),
363 363
	_use_nodes(other._use_nodes), _use_arcs(other._use_arcs) {
364 364

	
365 365
      other.is = 0;
366 366
      other.local_is = false;
367 367
      
368 368
      _node_index.swap(other._node_index);
369 369
      _arc_index.swap(other._arc_index);
370 370

	
371 371
      _node_maps.swap(other._node_maps);
372 372
      _arc_maps.swap(other._arc_maps);
373 373
      _attributes.swap(other._attributes);
374 374

	
375 375
      _nodes_caption = other._nodes_caption;
376 376
      _arcs_caption = other._arcs_caption;
377 377
      _attributes_caption = other._attributes_caption;
378 378
    }
379 379

	
380 380
    /// \e
381 381
    ~DigraphReader() {
382 382
      for (typename NodeMaps::iterator it = _node_maps.begin(); 
383 383
	   it != _node_maps.end(); ++it) {
384 384
	delete it->second;
385 385
      }
386 386

	
387 387
      for (typename ArcMaps::iterator it = _arc_maps.begin(); 
388 388
	   it != _arc_maps.end(); ++it) {
389 389
	delete it->second;
390 390
      }
391 391

	
392 392
      for (typename Attributes::iterator it = _attributes.begin(); 
393 393
	   it != _attributes.end(); ++it) {
394 394
	delete it->second;
395 395
      }
396 396

	
397 397
      if (local_is) {
398 398
	delete _is;
399 399
      }
400 400

	
401 401
    }
Ignore white space 192 line context
... ...
@@ -144,193 +144,193 @@
144 144
      MapLookUpConverter(const std::map<Value, std::string>& map) 
145 145
	: _map(map) {}
146 146
      
147 147
      std::string operator()(const Value& str) {
148 148
	typename std::map<Value, std::string>::const_iterator it = 
149 149
	  _map.find(str);
150 150
	if (it == _map.end()) {
151 151
	  throw DataFormatError("Item not found");
152 152
	}
153 153
	return it->second;
154 154
      }
155 155
    };
156 156

	
157 157
    bool isWhiteSpace(char c) {
158 158
      return c == ' ' || c == '\t' || c == '\v' || 
159 159
        c == '\n' || c == '\r' || c == '\f'; 
160 160
    }
161 161

	
162 162
    bool isEscaped(char c) {
163 163
      return c == '\\' || c == '\"' || c == '\'' || 
164 164
	c == '\a' || c == '\b';
165 165
    }
166 166

	
167 167
    static void writeEscape(std::ostream& os, char c) {
168 168
      switch (c) {
169 169
      case '\\':
170 170
	os << "\\\\";
171 171
	return;
172 172
      case '\"':
173 173
	os << "\\\"";
174 174
	return;
175 175
      case '\a':
176 176
	os << "\\a";
177 177
	return;
178 178
      case '\b':
179 179
	os << "\\b";
180 180
	return;
181 181
      case '\f':
182 182
	os << "\\f";
183 183
	return;
184 184
      case '\r':
185 185
	os << "\\r";
186 186
	return;
187 187
      case '\n':
188 188
	os << "\\n";
189 189
	return;
190 190
      case '\t':
191 191
	os << "\\t";
192 192
	return;
193 193
      case '\v':
194 194
	os << "\\v";
195 195
	return;
196 196
      default:
197 197
	if (c < 0x20) {
198 198
	  os << '\\' << std::oct << static_cast<int>(c);
199 199
	} else {
200 200
	  os << c;
201 201
	}
202 202
	return;
203 203
      }     
204 204
    }
205 205

	
206 206
    bool requireEscape(const std::string& str) {
207 207
      std::istringstream is(str);
208 208
      char c;
209 209
      while (is.get(c)) {
210 210
	if (isWhiteSpace(c) || isEscaped(c)) {
211 211
	  return true;
212 212
	}
213 213
      }
214 214
      return false;
215 215
    }
216 216
    
217 217
    std::ostream& writeToken(std::ostream& os, const std::string& str) {
218 218

	
219 219
      if (requireEscape(str)) {
220 220
	os << '\"';
221 221
	for (std::string::const_iterator it = str.begin(); 
222 222
	     it != str.end(); ++it) {
223 223
	  writeEscape(os, *it);
224 224
	}	
225 225
	os << '\"';
226 226
      } else {
227 227
	os << str;
228 228
      }
229 229
      return os;
230 230
    }
231 231

	
232 232
  }
233 233
  
234 234
  /// \e
235 235
  template <typename _Digraph>
236 236
  class DigraphWriter {
237 237
  public:
238 238

	
239 239
    typedef _Digraph Digraph;
240
    DIGRAPH_TYPEDEFS(Digraph);
240
    TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
241 241
    
242 242
  private:
243 243

	
244 244

	
245 245
    std::ostream* _os;
246 246
    bool local_os;
247 247

	
248 248
    Digraph& _digraph;
249 249

	
250 250
    std::string _nodes_caption;
251 251
    std::string _arcs_caption;
252 252
    std::string _attributes_caption;
253 253
    
254 254
    typedef std::map<Node, std::string> NodeIndex;
255 255
    NodeIndex _node_index;
256 256
    typedef std::map<Arc, std::string> ArcIndex;
257 257
    ArcIndex _arc_index;
258 258

	
259 259
    typedef std::vector<std::pair<std::string, 
260 260
      _writer_bits::MapStorageBase<Node>* > > NodeMaps;    
261 261
    NodeMaps _node_maps; 
262 262

	
263 263
    typedef std::vector<std::pair<std::string, 
264 264
      _writer_bits::MapStorageBase<Arc>* > >ArcMaps;
265 265
    ArcMaps _arc_maps;
266 266

	
267 267
    typedef std::vector<std::pair<std::string, 
268 268
      _writer_bits::ValueStorageBase*> > Attributes;
269 269
    Attributes _attributes;
270 270

	
271 271
    bool _skip_nodes;
272 272
    bool _skip_arcs;
273 273

	
274 274
  public:
275 275

	
276 276
    /// \e
277 277
    DigraphWriter(std::ostream& is, Digraph& digraph) 
278 278
      : _os(&is), local_os(false), _digraph(digraph),
279 279
	_skip_nodes(false), _skip_arcs(false) {}
280 280

	
281 281
    /// \e
282 282
    DigraphWriter(const std::string& fn, Digraph& digraph) 
283 283
      : _os(new std::ofstream(fn.c_str())), local_os(true), _digraph(digraph),
284 284
	_skip_nodes(false), _skip_arcs(false) {}
285 285

	
286 286
    /// \e
287 287
    DigraphWriter(const char* fn, Digraph& digraph) 
288 288
      : _os(new std::ofstream(fn)), local_os(true), _digraph(digraph),
289 289
	_skip_nodes(false), _skip_arcs(false) {}
290 290

	
291 291
    DigraphWriter(DigraphWriter& other) 
292 292
      : _os(other._os), local_os(other.local_os), _digraph(other._digraph),
293 293
	_skip_nodes(other._skip_nodes), _skip_arcs(other._skip_arcs) {
294 294

	
295 295
      other.is = 0;
296 296
      other.local_os = false;
297 297

	
298 298
      _node_index.swap(other._node_index);
299 299
      _arc_index.swap(other._arc_index);
300 300

	
301 301
      _node_maps.swap(other._node_maps);
302 302
      _arc_maps.swap(other._arc_maps);
303 303
      _attributes.swap(other._attributes);
304 304

	
305 305
      _nodes_caption = other._nodes_caption;
306 306
      _arcs_caption = other._arcs_caption;
307 307
      _attributes_caption = other._attributes_caption;
308 308
    }
309 309

	
310 310
    /// \e
311 311
    ~DigraphWriter() {
312 312
      for (typename NodeMaps::iterator it = _node_maps.begin(); 
313 313
	   it != _node_maps.end(); ++it) {
314 314
	delete it->second;
315 315
      }
316 316

	
317 317
      for (typename ArcMaps::iterator it = _arc_maps.begin(); 
318 318
	   it != _arc_maps.end(); ++it) {
319 319
	delete it->second;
320 320
      }
321 321

	
322 322
      for (typename Attributes::iterator it = _attributes.begin(); 
323 323
	   it != _attributes.end(); ++it) {
324 324
	delete it->second;
325 325
      }
326 326

	
327 327
      if (local_os) {
328 328
	delete _os;
329 329
      }
330 330
    }
331 331

	
332 332
  private:
333 333
    
334 334
    DigraphWriter& operator=(const DigraphWriter&);
335 335

	
336 336
  public:
0 comments (0 inline)