DirPath fejlodes.
authorklao
Fri, 30 Apr 2004 01:59:15 +0000
changeset 493bbd1db03f0fe
parent 492 d649b43e2dc0
child 494 e42f56e7ad93
DirPath fejlodes.
Kiserleti struktura a forditasi idoben kapcsolhato konzisztencia es range
ellenorzesekre.
src/work/klao/debug.h
src/work/klao/path.h
src/work/klao/path_test.cc
src/work/makefile
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/work/klao/debug.h	Fri Apr 30 01:59:15 2004 +0000
     1.3 @@ -0,0 +1,36 @@
     1.4 +// -*- C++ -*- //
     1.5 +
     1.6 +#ifndef HUGO_DEBUG_H
     1.7 +#define HUGO_DEBUG_H
     1.8 +
     1.9 +//! \file
    1.10 +//! \brief Basic definitions for debug control.
    1.11 +
    1.12 +namespace hugo {
    1.13 +
    1.14 +  struct DebugOn {
    1.15 +    //! Example: check whether the edges added to a path are adjacent
    1.16 +    static const bool consistensy_check = true;
    1.17 +
    1.18 +    static const bool range_check = true;
    1.19 +
    1.20 +    //! Examples: initialize maps with some value;
    1.21 +    //! after deleting an item from UnionFindEnum set its value in the
    1.22 +    //! corresponding map to NULL...
    1.23 +    static const bool ensure_safe_state = true;
    1.24 +  };
    1.25 +
    1.26 +  struct DebugOff {
    1.27 +    static const bool consistensy_check = false;
    1.28 +    static const bool range_check = false;
    1.29 +    static const bool ensure_safe_state = false;
    1.30 +  };
    1.31 +
    1.32 +#ifdef DEBUG
    1.33 +  typedef DebugOn DefaultDebugMode;
    1.34 +#else
    1.35 +  typedef DebugOff DefaultDebugMode;
    1.36 +#endif
    1.37 +
    1.38 +}
    1.39 +#endif // HUGO_DEBUG_H
     2.1 --- a/src/work/klao/path.h	Fri Apr 30 01:10:13 2004 +0000
     2.2 +++ b/src/work/klao/path.h	Fri Apr 30 01:59:15 2004 +0000
     2.3 @@ -1,8 +1,8 @@
     2.4  // -*- c++ -*- //
     2.5  
     2.6 -///ingroup datas
     2.7 +///\ingroup datas
     2.8  ///\file
     2.9 -///\brief Class for representing paths in graphs.
    2.10 +///\brief Classes for representing paths in graphs.
    2.11  
    2.12  #ifndef HUGO_PATH_H
    2.13  #define HUGO_PATH_H
    2.14 @@ -12,22 +12,26 @@
    2.15  #include <algorithm>
    2.16  
    2.17  #include <invalid.h>
    2.18 +#include <error.h>
    2.19 +#include <debug.h>
    2.20  
    2.21  namespace hugo {
    2.22  
    2.23    /// \addtogroup datas
    2.24    /// @{
    2.25  
    2.26 -  ///A container for directed paths
    2.27  
    2.28 -  ///\param Graph The graph type in which the path is.
    2.29 -  ///
    2.30 -  ///In a sense, the path can be treated as a graph, for is has \c NodeIt
    2.31 -  ///and \c EdgeIt with the same usage. These types converts to the \c Node
    2.32 -  ///and \c Edge of the original graph.
    2.33 -  ///\todo How to clear a path?
    2.34 -  ///\todo Clarify the consistency checks to do.
    2.35 -  template<typename Graph>
    2.36 +  //! \brief A structure for representing directed path in a graph.
    2.37 +  //!
    2.38 +  //! \param Graph The graph type in which the path is.
    2.39 +  //! \param DM DebugMode, defaults to DefaultDebugMode.
    2.40 +  //! 
    2.41 +  //! In a sense, the path can be treated as a graph, for is has \c NodeIt
    2.42 +  //! and \c EdgeIt with the same usage. These types converts to the \c Node
    2.43 +  //! and \c Edge of the original graph.
    2.44 +  //!
    2.45 +  //! \todo Thoroughfully check all the range and consistency tests.
    2.46 +  template<typename Graph, typename DM = DefaultDebugMode>
    2.47    class DirPath {
    2.48    public:
    2.49      typedef typename Graph::Edge GraphEdge;
    2.50 @@ -42,43 +46,86 @@
    2.51  
    2.52    public:
    2.53  
    2.54 -    /// Constructor
    2.55 -    
    2.56      /// \param _G The graph in which the path is.
    2.57      ///
    2.58      DirPath(const Graph &_G) : gr(&_G) {}
    2.59  
    2.60 +    /// \brief Subpath constructor.
    2.61 +    ///
    2.62      /// Subpath defined by two nodes.
    2.63      /// \warning It is an error if the two edges are not in order!
    2.64 +    /// \todo Implement!
    2.65      DirPath(const DirPath &P, const NodeIt &a, const NodeIt &b);
    2.66 +    /// \brief Subpath constructor.
    2.67 +    ///
    2.68      /// Subpath defined by two edges. Contains edges in [a,b)
    2.69      /// \warning It is an error if the two edges are not in order!
    2.70 +    /// \todo Implement!
    2.71      DirPath(const DirPath &P, const EdgeIt &a, const EdgeIt &b);
    2.72  
    2.73 +    /// Length of the path.
    2.74      size_t length() const { return edges.size(); }
    2.75 +    /// Returns whether the path is empty.
    2.76      bool empty() const { return edges.empty(); }
    2.77 +
    2.78 +    /// Resets the path to an empty path.
    2.79 +    void clear() { edges.clear(); }
    2.80 +
    2.81 +    /// \brief Starting point of the path.
    2.82 +    ///
    2.83 +    /// Starting point of the path.
    2.84 +    /// Returns INVALID if the path is empty.
    2.85      GraphNode from() const {
    2.86        return empty() ? INVALID : gr->tail(edges[0]);
    2.87      }
    2.88 +    /// \brief End point of the path.
    2.89 +    ///
    2.90 +    /// End point of the path.
    2.91 +    /// Returns INVALID if the path is empty.
    2.92      GraphNode to() const {
    2.93        return empty() ? INVALID : gr->head(edges[length()-1]);
    2.94      }
    2.95  
    2.96 +    /// \brief Initializes node or edge iterator to point to the first
    2.97 +    /// node or edge.
    2.98 +    ///
    2.99 +    /// \sa nth
   2.100      template<typename It>
   2.101      It& first(It &i) const { return i=It(*this); }
   2.102  
   2.103 +    /// \brief Initializes node or edge iterator to point to the node or edge
   2.104 +    /// of a given index.
   2.105      template<typename It>
   2.106 -    It& nth(It &i, int n) const { return i=It(*this, n); }
   2.107 +    It& nth(It &i, int n) const {
   2.108 +      // FIXME: this test should be different for NodeIt and EdgeIt:
   2.109 +      if( DM::range_check && (n<0 || n>int(length())) )
   2.110 +	fault("DirPath::nth: index out of range");
   2.111 +      return i=It(*this, n);
   2.112 +    }
   2.113  
   2.114 +    /// Checks validity of a node or edge iterator.
   2.115      template<typename It>
   2.116      bool valid(const It &i) const { return i.valid(); }
   2.117  
   2.118 +    /// Steps the given node or edge iterator.
   2.119      template<typename It>
   2.120 -    It& next(It &e) const { return ++e; }
   2.121 +    It& next(It &e) const {
   2.122 +      if( DM::range_check && !e.valid() )
   2.123 +	fault("DirPath::next() on invalid iterator");
   2.124 +      return ++e;
   2.125 +    }
   2.126  
   2.127 -    /// \todo !
   2.128 -    NodeIt head(const EdgeIt& e) const;
   2.129 -    NodeIt tail(const EdgeIt& e) const;
   2.130 +    /// \brief Returns node iterator pointing to the head node of the
   2.131 +    /// given edge iterator.
   2.132 +    NodeIt head(const EdgeIt& e) const {
   2.133 +      return NodeIt(*this, e.idx+1);
   2.134 +    }
   2.135 +
   2.136 +    /// \brief Returns node iterator pointing to the tail node of the
   2.137 +    /// given edge iterator.
   2.138 +    NodeIt tail(const EdgeIt& e) const {
   2.139 +      return NodeIt(*this, e.idx);
   2.140 +    }
   2.141  
   2.142  
   2.143      /*** Iterator classes ***/
   2.144 @@ -143,92 +190,118 @@
   2.145  
   2.146      friend class Builder;    
   2.147  
   2.148 -    ///Class to build paths
   2.149 -
   2.150 -    ///\ingroup datas
   2.151 -    ///This class is used to build new paths.
   2.152 -    ///You can push new edges to the front and to the back of the path in
   2.153 -    ///arbitrary order the you can commit these changes to the graph.
   2.154 -    ///\todo We must clarify when the path will be in "transitional" state.
   2.155 +    /**
   2.156 +     * \brief Class to build paths
   2.157 +     * 
   2.158 +     * \ingroup datas
   2.159 +     * This class is used to fill a path with edges.
   2.160 +     *
   2.161 +     * You can push new edges to the front and to the back of the path in
   2.162 +     * arbitrary order the you can commit these changes to the graph.
   2.163 +     *
   2.164 +     * Fundamentally, for most "Paths" (classes fulfilling the
   2.165 +     * PathConcept) while the builder is active (after the first modifying
   2.166 +     * operation and until the commit()) the original Path is in a
   2.167 +     * "transitional" state (operations ot it have undefined result). But
   2.168 +     * in the case of DirPath the original path is unchanged until the
   2.169 +     * commit. However we don't recomend that you use this feature.
   2.170 +     */
   2.171      class Builder {
   2.172        DirPath &P;
   2.173 -      Container d;
   2.174 +      Container front, back;
   2.175  
   2.176      public:
   2.177 -      ///Constructor
   2.178 -
   2.179 -      ///\param _P the path you want to build.
   2.180 +      ///\param _P the path you want to fill in.
   2.181        ///
   2.182        Builder(DirPath &_P) : P(_P) {}
   2.183  
   2.184 -      ///Set the first node of the path.
   2.185 +      ///Sets the first node of the path.
   2.186        
   2.187 -      ///Set the first node of the path.
   2.188 -      ///If the path is empty, this must be call before any call of
   2.189 -      ///\ref pushFront() or \ref pushBack()
   2.190 -      void setFirst(const GraphNode &) { }
   2.191 +      ///Sets the first node of the path. If the path is empty, this
   2.192 +      ///function or setTo() have to be called before any call to \ref
   2.193 +      ///pushFront() or \ref pushBack()
   2.194 +      void setFrom(const GraphNode &) {}
   2.195 +      
   2.196 +      ///Sets the last node of the path.
   2.197 +      
   2.198 +      ///Sets the last node of the path. If the path is empty, this
   2.199 +      ///function or setFrom() have to be called before any call of \ref
   2.200 +      ///pushFront() or \ref pushBack()
   2.201 +      void setTo(const GraphNode &) {}
   2.202        
   2.203        ///Push a new edge to the front of the path
   2.204  
   2.205        ///Push a new edge to the front of the path.
   2.206 -      ///\sa setFirst()
   2.207 -      bool pushFront(const GraphEdge& e) {
   2.208 -	if( empty() || P.gr->head(e)==from() ) {
   2.209 -	  d.push_back(e);
   2.210 -	  return true;
   2.211 +      ///\sa setTo
   2.212 +      void pushFront(const GraphEdge& e) {
   2.213 +	if( DM::consistensy_check && !empty() && P.gr->head(e)!=from() ) {
   2.214 +	  fault("DirPath::Builder::pushFront: nonincident edge");
   2.215  	}
   2.216 -	return false;
   2.217 +	front.push_back(e);
   2.218        }
   2.219 +
   2.220        ///Push a new edge to the back of the path
   2.221  
   2.222        ///Push a new edge to the back of the path.
   2.223 -      ///\sa setFirst()
   2.224 -      bool pushBack(const GraphEdge& e) {
   2.225 -	if( empty() || P.gr->tail(e)==to() ) {
   2.226 -	  P.edges.push_back(e);
   2.227 -	  return true;
   2.228 +      ///\sa setFrom
   2.229 +      void pushBack(const GraphEdge& e) {
   2.230 +	if( DM::consistensy_check && !empty() && P.gr->tail(e)!=to() ) {
   2.231 +	  fault("DirPath::Builder::pushBack: nonincident edge");
   2.232  	}
   2.233 -	return false;
   2.234 +	back.push_back(e);
   2.235        }
   2.236  
   2.237        ///Commit the changes to the path.
   2.238        void commit() {
   2.239 -	if( !d.empty() ) {
   2.240 -	  P.edges.insert(P.edges.begin(), d.rbegin(), d.rend());
   2.241 -	  d.clear();
   2.242 +	if( !(front.empty() && back.empty()) ) {
   2.243 +	  Container tmp;
   2.244 +	  tmp.reserve(front.size()+back.size()+P.length());
   2.245 +	  tmp.insert(tmp.end(), front.rbegin(), front.rend());
   2.246 +	  tmp.insert(tmp.end(), P.edges.begin(), P.edges.end());
   2.247 +	  tmp.insert(tmp.end(), back.begin(), back.end());
   2.248 +	  P.edges.swap(tmp);
   2.249 +	  front.clear();
   2.250 +	  back.clear();
   2.251  	}
   2.252        }
   2.253  
   2.254 -      ///Desctuctor
   2.255 +//       ///Desctuctor
   2.256  
   2.257 -      ///The desctuctor.
   2.258 -      ///It commit also commit the changes.
   2.259 -      ///\todo Is this what we want?
   2.260 -      ~Builder() { commit(); }
   2.261 +//       ///The desctuctor.
   2.262 +//       ///It commit also commit the changes.
   2.263 +//       ///\todo Is this what we want?
   2.264 +//  Nope. Let's use commit() explicitly.
   2.265 +//       ~Builder() { commit(); }
   2.266  
   2.267        // FIXME: Hmm, pontosan hogy is kene ezt csinalni?
   2.268        // Hogy kenyelmes egy ilyet hasznalni?
   2.269        void reserve(size_t r) {
   2.270 -	d.reserve(r);
   2.271 -	P.edges.reserve(P.length()+r);
   2.272 +	front.reserve(r);
   2.273 +	back.reserve(r);
   2.274        }
   2.275  
   2.276      private:
   2.277 -      bool empty() { return d.empty() && P.empty(); }
   2.278 +      bool empty() {
   2.279 +	return front.empty() && back.empty() && P.empty();
   2.280 +      }
   2.281  
   2.282        GraphNode from() const {
   2.283 -	if( ! d.empty() )
   2.284 -	  return P.gr->tail(d[d.size()-1]);
   2.285 +	if( ! front.empty() )
   2.286 +	  return P.gr->tail(front[front.size()-1]);
   2.287  	else if( ! P.empty() )
   2.288  	  return P.gr->tail(P.edges[0]);
   2.289 +	else if( ! back.empty() )
   2.290 +	  return P.gr->tail(back[0]);
   2.291  	else
   2.292  	  return INVALID;
   2.293        }
   2.294        GraphNode to() const {
   2.295 -	if( ! P.empty() )
   2.296 +	if( ! back.empty() )
   2.297 +	  return P.gr->head(back[back.size()-1]);
   2.298 +	else if( ! P.empty() )
   2.299  	  return P.gr->head(P.edges[P.length()-1]);
   2.300 -	else if( ! d.empty() )
   2.301 -	  return P.gr->head(d[0]);
   2.302 +	else if( ! front.empty() )
   2.303 +	  return P.gr->head(front[0]);
   2.304  	else
   2.305  	  return INVALID;
   2.306        }
     3.1 --- a/src/work/klao/path_test.cc	Fri Apr 30 01:10:13 2004 +0000
     3.2 +++ b/src/work/klao/path_test.cc	Fri Apr 30 01:59:15 2004 +0000
     3.3 @@ -16,233 +16,142 @@
     3.4    }
     3.5  }
     3.6  
     3.7 +#ifdef DEBUG
     3.8 +const bool debug = true;
     3.9 +#else
    3.10 +const bool debug = false;
    3.11 +#endif
    3.12 +
    3.13 +
    3.14  int main() {
    3.15  
    3.16 -  typedef ListGraph::Node Node;
    3.17 -  typedef ListGraph::Edge Edge;
    3.18 +  try {
    3.19  
    3.20 -  ListGraph G;
    3.21 +    typedef ListGraph::Node Node;
    3.22 +    typedef ListGraph::Edge Edge;
    3.23  
    3.24 -  Node s=G.addNode();
    3.25 -  Node v1=G.addNode();
    3.26 -  Node v2=G.addNode();
    3.27 -  Node v3=G.addNode();
    3.28 -  Node v4=G.addNode();
    3.29 -  Node t=G.addNode();
    3.30 +    ListGraph G;
    3.31 +
    3.32 +    Node s=G.addNode();
    3.33 +    Node v1=G.addNode();
    3.34 +    Node v2=G.addNode();
    3.35 +    Node v3=G.addNode();
    3.36 +    Node v4=G.addNode();
    3.37 +    Node t=G.addNode();
    3.38    
    3.39 -  Edge e1 = G.addEdge(s, v1);
    3.40 -  Edge e2 = G.addEdge(s, v2);
    3.41 -  Edge e3 = G.addEdge(v1, v2);
    3.42 -  Edge e4 = G.addEdge(v2, v1);
    3.43 -  Edge e5 = G.addEdge(v1, v3);
    3.44 -  Edge e6 = G.addEdge(v3, v2);
    3.45 -  Edge e7 = G.addEdge(v2, v4);
    3.46 -  Edge e8 = G.addEdge(v4, v3);
    3.47 -  Edge e9 = G.addEdge(v3, t);
    3.48 -  Edge e10 = G.addEdge(v4, t);
    3.49 +    Edge e1 = G.addEdge(s, v1);
    3.50 +    Edge e2 = G.addEdge(s, v2);
    3.51 +    Edge e3 = G.addEdge(v1, v2);
    3.52 +    Edge e4 = G.addEdge(v2, v1);
    3.53 +    Edge e5 = G.addEdge(v1, v3);
    3.54 +    Edge e6 = G.addEdge(v3, v2);
    3.55 +    Edge e7 = G.addEdge(v2, v4);
    3.56 +    Edge e8 = G.addEdge(v4, v3);
    3.57 +    Edge e9 = G.addEdge(v3, t);
    3.58 +    Edge e10 = G.addEdge(v4, t);
    3.59  
    3.60 -  bool rc;
    3.61 +    bool rc;
    3.62  
    3.63 -  {
    3.64 -    cout << "DynamicPath tesztelese...\n";
    3.65 +    {
    3.66 +      cout << "\n\n\nDirPath tesztelese...\n";
    3.67  
    3.68 -    cout << "Ures path letrehozasa" << endl;
    3.69 -    typedef DynamicPath<ListGraph> LPath;
    3.70 -    LPath P(G);
    3.71  
    3.72 -    cout << "P.length() == " << P.length() << endl;
    3.73 -    check(P.length() == 0);
    3.74 +      cout << "Ures path letrehozasa" << endl;
    3.75 +      typedef DirPath<ListGraph> DPath;
    3.76 +      DPath P(G);
    3.77  
    3.78 -    cout << "P.from() valid? " << G.valid(P.from()) << endl;
    3.79 -    check(! G.valid(P.from()));
    3.80 +      cout << "P.length() == " << P.length() << endl;
    3.81 +      check(P.length() == 0);
    3.82  
    3.83 -    cout << "Hozzaadunk ket elet..." << endl;
    3.84 -    check(P.pushBack(e1));
    3.85 -    check(P.pushBack(e3));
    3.86 -    cout << "P.length() == " << P.length() << endl;
    3.87 -    check(P.length() == 2);
    3.88 +      cout << "P.from() valid? " << G.valid(P.from()) << endl;
    3.89 +      check(! G.valid(P.from()));
    3.90  
    3.91 -    cout << "P.from() valid? " << G.valid(P.from()) << endl;
    3.92 -    check(G.valid(P.from()));
    3.93 -  
    3.94 -    cout << "P.from()==s ? " << (P.from()==s) << endl;
    3.95 -    check(P.from() == s);
    3.96 +      {
    3.97 +	cout << "Builder objektum letrehozasa" << endl;
    3.98 +	DPath::Builder B(P);
    3.99  
   3.100 -    cout << "Hozzaadunk egy nem illeszkedo elt." << endl;
   3.101 -    rc = P.pushBack(e8);
   3.102 -    cout << "Sukerult: " << rc << endl;
   3.103 -    check(!rc);
   3.104 +	cout << "Hozzaadunk az elejehez ket elet..." << endl;
   3.105 +	B.pushFront(e6);
   3.106 +	B.pushFront(e5);
   3.107 +	cout << "P.length() == " << P.length() << endl;
   3.108 +	check(P.length() == 0);
   3.109 +      
   3.110 +	cout << "Commitolunk..." << endl;
   3.111 +	B.commit();
   3.112  
   3.113 -    cout << "Meg 3 el hozzaadasa, nem mind elore iranyu..." << endl;
   3.114 -    check(P.pushBack(e6));
   3.115 -    check(P.pushBack(e8));
   3.116 -    check(P.pushBack(e10));
   3.117 +	cout << "P.length() == " << P.length() << endl;
   3.118 +	check(P.length() == 2);
   3.119 +	cout << "P.from() valid? " << G.valid(P.from()) << endl;
   3.120 +	check(G.valid(P.from()));
   3.121 +	cout << "P.from()==v1 ? " << (P.from()==v1) << endl;
   3.122 +	check(P.from() == v1);
   3.123  
   3.124 -    cout << "P.length() == " << P.length() << endl;
   3.125 -    check(P.length() == 5);
   3.126 +	// Na ja, ez igy nem igazi, mindket esetet le kene tesztelni,
   3.127 +	// de legalabb valami:
   3.128 +#ifdef DEBUG
   3.129 +	cout << "Hozzaadunk az elejehez egy nem illeszkedo elet..." << endl;
   3.130 +	rc = false;
   3.131 +	try {
   3.132 +	  B.pushFront(e3);
   3.133 +	}
   3.134 +	catch(const Exception &e) {
   3.135 +	  cout << "E: " << e.what() << endl;
   3.136 +	  rc = true;
   3.137 +	}
   3.138 +	check(rc);
   3.139 +#endif
   3.140  
   3.141 -    cout << "P.from()==s ? " << (P.from()==s) << endl;
   3.142 -    check(P.from() == s);
   3.143 -    cout << "P.to()==t ? " << (P.to()==t) << endl;
   3.144 -    check(P.to() == t);
   3.145 +	cout << "Hozzaadunk a vegehez ket elet..." << endl;
   3.146 +	B.pushBack(e7);
   3.147 +	B.pushBack(e8);
   3.148 +	cout << "P.length() == " << P.length() << endl;
   3.149 +	check(P.length() == 2);
   3.150 +      
   3.151 +	cout << "Es commitolunk...\n";
   3.152 +	B.commit();
   3.153 +      }
   3.154 +      cout << "P.length() == " << P.length() << endl;
   3.155 +      check(P.length() == 4);
   3.156 +      cout << "P.to()==v3 ? " << (P.to()==v3) << endl;
   3.157 +      check(P.to() == v3);
   3.158  
   3.159 -    cout << "Vegpont bellitasa: " << endl;
   3.160 -    rc = P.setTo(v2);
   3.161 -    cout << "Hibasra: " << rc << endl;
   3.162 -    check(!rc);
   3.163 -    rc = P.setTo(t);
   3.164 -    cout << "Helyesre: " << rc << endl;
   3.165 -    check(rc);
   3.166 +      cout << "Vegigiteralunk az eleken." << endl;
   3.167 +      typedef DPath::NodeIt NodeIt;
   3.168 +      typedef DPath::EdgeIt EdgeIt;
   3.169 +      EdgeIt e;
   3.170 +      int i=1;
   3.171 +      for(P.first(e); P.valid(e); P.next(e), ++i) {
   3.172 +	cout << i << ". el: " << e << endl;
   3.173 +      }
   3.174  
   3.175 -    cout << "Elek iranyitasanak ellenorzese." << endl;
   3.176 -    cout << "El: " << e1 << ", G.tail(el): " << G.head(e1) << endl;
   3.177 -    check(G.tail(e1)==s);
   3.178  
   3.179 -    cout << "Vegigiteralunk az eleken." << endl;
   3.180 -    typedef LPath::NodeIt NodeIt;
   3.181 -    typedef LPath::EdgeIt EdgeIt;
   3.182 -    EdgeIt e = P.first<EdgeIt>();
   3.183 -    int i=1;
   3.184 -    for(; P.valid(e); P.next(e), ++i) {
   3.185 -      cout << i << ". el: " << P.graphEdge(e)
   3.186 -	   << ", elore el? " << P.isForward(e) << endl;
   3.187 -      if(i>=3 && i<5) 
   3.188 -	check(!P.isForward(e));
   3.189 -      else
   3.190 -	check(P.isForward(e));
   3.191 +      // Na ja, ez igy nem igazi, mindket esetet le kene tesztelni,
   3.192 +      // de legalabb valami:
   3.193 +      rc = false;
   3.194 +      try {
   3.195 +	cout << "Setting an edgeiter to a nonexistant edge." << endl;
   3.196 +	P.nth(e,134);
   3.197 +	rc = !debug;
   3.198 +      }
   3.199 +      catch(const Exception &e) {
   3.200 +	cout << "E: " << e.what() << endl;
   3.201 +	rc = debug;
   3.202 +      }
   3.203 +      check(rc);
   3.204      }
   3.205  
   3.206 -    {
   3.207 -      cout << "Reszut letrehozasa: [2. el, 4. el)..." << endl;
   3.208 -      LPath P2(P, P.nth<EdgeIt>(1), P.nth<EdgeIt>(3));
   3.209 -
   3.210 -      cout << "P2.length() == " << P2.length() << endl;
   3.211 -      check(P2.length() == 2);
   3.212 -    
   3.213 -      cout << "P2.from()==v1 ? " << (P2.from()==v1) << endl;
   3.214 -      check(P2.from() == v1);
   3.215 -      cout << "P2.to()==v3 ? " << (P2.to()==v3) << endl;
   3.216 -      check(P2.to() == v3);
   3.217 -    }
   3.218 -    {
   3.219 -      cout << "Reszut letrehozasa: [1. el, 6. el)..." << endl;
   3.220 -      LPath P2(P, P.nth<EdgeIt>(0), P.nth<EdgeIt>(5));
   3.221 -
   3.222 -      cout << "P2.length() == " << P2.length() << endl;
   3.223 -      check(P2.length() == 5);
   3.224 -    
   3.225 -      cout << "P2.from()==s ? " << (P2.from()==s) << endl;
   3.226 -      check(P2.from() == s);
   3.227 -      cout << "P2.to()==t ? " << (P2.to()==t) << endl;
   3.228 -      check(P2.to() == t);
   3.229 -    }
   3.230 -
   3.231 -    {
   3.232 -      cout << "Ket pont altal megadott reszut letrehozasa: [2. pont, 4. pont]..."
   3.233 -	   << endl;
   3.234 -      LPath P2(P, P.nth<NodeIt>(1), P.nth<NodeIt>(3));
   3.235 -
   3.236 -      cout << "P2.length() == " << P2.length() << endl;
   3.237 -      check(P2.length() == 2);
   3.238 -    
   3.239 -      cout << "P2.from()==v1 ? " << (P2.from()==v1) << endl;
   3.240 -      check(P2.from() == v1);
   3.241 -      cout << "P2.to()==v3 ? " << (P2.to()==v3) << endl;
   3.242 -      check(P2.to() == v3);
   3.243 -    }
   3.244 -    {
   3.245 -      cout << "Egy pontu reszut letrehozasa: [4. pont, 4. pont]..."
   3.246 -	   << endl;
   3.247 -      LPath P2(P, P.nth<NodeIt>(3), P.nth<NodeIt>(3));
   3.248 -
   3.249 -      cout << "P2.length() == " << P2.length() << endl;
   3.250 -      check(P2.length() == 0);
   3.251 -    
   3.252 -      cout << "P2.from()==v3 ? " << (P2.from()==v3) << endl;
   3.253 -      check(P2.from() == v3);
   3.254 -      cout << "P2.to()==v3 ? " << (P2.to()==v3) << endl;
   3.255 -      check(P2.to() == v3);
   3.256 -    }
   3.257 -    {
   3.258 -      cout << "Forditott ut letrehozasa: [6. pont, 1. pont]..."
   3.259 -	   << endl;
   3.260 -      LPath P2(P, P.nth<NodeIt>(5), P.nth<NodeIt>(0));
   3.261 -
   3.262 -      cout << "P2.length() == " << P2.length() << endl;
   3.263 -      check(P2.length() == 5);
   3.264 -    
   3.265 -      cout << "P2.from()==t ? " << (P2.from()==t) << endl;
   3.266 -      check(P2.from() == t);
   3.267 -      cout << "P2.to()==s ? " << (P2.to()==s) << endl;
   3.268 -      check(P2.to() == s);
   3.269 -    }
   3.270  
   3.271    }
   3.272 +  catch(const std::exception &e) {
   3.273 +    cout << "Uncaught exception: " << e.what() << endl;
   3.274 +    return 1;
   3.275 +  }
   3.276 +  catch(...) {
   3.277 +    cout << "Something horrible happened: an exception which isn't "
   3.278 +	 << "std::exception" << endl;
   3.279 +    return 2;
   3.280 +  }
   3.281  
   3.282 -  {
   3.283 -    cout << "\n\n\nDirPath tesztelese...\n";
   3.284 -
   3.285 -
   3.286 -    cout << "Ures path letrehozasa" << endl;
   3.287 -    typedef DirPath<ListGraph> DPath;
   3.288 -    DPath P(G);
   3.289 -
   3.290 -    cout << "P.length() == " << P.length() << endl;
   3.291 -    check(P.length() == 0);
   3.292 -
   3.293 -    cout << "P.from() valid? " << G.valid(P.from()) << endl;
   3.294 -    check(! G.valid(P.from()));
   3.295 -
   3.296 -    {
   3.297 -      cout << "Builder objektum letrehozasa" << endl;
   3.298 -      DPath::Builder B(P);
   3.299 -
   3.300 -      cout << "Hozzaadunk az elejehez ket elet..." << endl;
   3.301 -      check(B.pushFront(e6));
   3.302 -      check(B.pushFront(e5));
   3.303 -      cout << "P.length() == " << P.length() << endl;
   3.304 -      check(P.length() == 0);
   3.305 -      
   3.306 -      cout << "Commitolunk..." << endl;
   3.307 -      B.commit();
   3.308 -
   3.309 -      cout << "P.length() == " << P.length() << endl;
   3.310 -      check(P.length() == 2);
   3.311 -      cout << "P.from() valid? " << G.valid(P.from()) << endl;
   3.312 -      check(G.valid(P.from()));
   3.313 -      cout << "P.from()==v1 ? " << (P.from()==v1) << endl;
   3.314 -      check(P.from() == v1);
   3.315 -
   3.316 -      cout << "Hozzaadunk az elejehez egy nem illeszkedo elet..." << endl;
   3.317 -      check(!B.pushFront(e3));
   3.318 -    
   3.319 -      cout << "Hozzaadunk a vegehez ket elet..." << endl;
   3.320 -      check(B.pushBack(e7));
   3.321 -      check(B.pushBack(e8));
   3.322 -      cout << "P.length() == " << P.length() << endl;
   3.323 -      check(P.length() == 4);
   3.324 -
   3.325 -      cout << "Hozzaadunk az elejehez meg egy elet..." << endl;
   3.326 -      check(B.pushFront(e4));
   3.327 -      cout << "P.length() == " << P.length() << endl;
   3.328 -      check(P.length() == 4);
   3.329 -      
   3.330 -      cout << "Es megvarjuk, amig megszunik a Builder...\n";
   3.331 -    }
   3.332 -    cout << "P.length() == " << P.length() << endl;
   3.333 -    check(P.length() == 5);
   3.334 -    cout << "P.from()==v2 ? " << (P.from()==v2) << endl;
   3.335 -    check(P.from() == v2);
   3.336 -
   3.337 -    cout << "Vegigiteralunk az eleken." << endl;
   3.338 -    typedef DPath::NodeIt NodeIt;
   3.339 -    typedef DPath::EdgeIt EdgeIt;
   3.340 -    EdgeIt e;
   3.341 -    int i=1;
   3.342 -    for(P.first(e); P.valid(e); P.next(e), ++i) {
   3.343 -      cout << i << ". el: " << e << endl;
   3.344 -    }
   3.345 -  }
   3.346  
   3.347    cout << (passed ? "All tests passed." : "Some of the tests failed!!!")
   3.348         << endl;
     4.1 --- a/src/work/makefile	Fri Apr 30 01:10:13 2004 +0000
     4.2 +++ b/src/work/makefile	Fri Apr 30 01:59:15 2004 +0000
     4.3 @@ -11,6 +11,10 @@
     4.4  CXX := $(shell type -p g++-3.3 || type -p g++-3.2 || type -p g++-3.0 || type -p g++-3 || echo g++)
     4.5  endif
     4.6  
     4.7 +ifdef DEBUG
     4.8 +CXXFLAGS += -DDEBUG
     4.9 +endif
    4.10 +
    4.11  CC := $(CXX)
    4.12  
    4.13