/[ff3d]/ff3d/solver/Edge.hpp
ViewVC logotype

Diff of /ff3d/solver/Edge.hpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by delpinux, Sun Jun 15 18:36:26 2003 UTC revision 1.4 by delpinux, Fri Aug 8 08:39:56 2003 UTC
# Line 24  Line 24 
24  #include <Vertex.hpp>  #include <Vertex.hpp>
25  #include <utility>  #include <utility>
26    
 /*!  
   \class Edge  
 */  
   
27  /**  /**
28   * @file   Edge.hpp   * @file   Edge.hpp
29   * @author Stephane Del Pino   * @author Stephane Del Pino
# Line 35  Line 31 
31   *   *
32   * @brief  This class provides a Edge description.   * @brief  This class provides a Edge description.
33   *   *
34   * This class provides a Edge description.  A Edge is defined by 2   * This class provides edge description.  An edge is defined by two
35   * vertices and a reference.   * vertices and a reference.
36   *   *
37   * @todo This class is really hugly should rework it a lot!   * @todo This class is really hugly should rework it a lot!
# Line 50  public: Line 46  public:
46    
47    typedef std::pair<Vertex*, Vertex*> Pair;    typedef std::pair<Vertex*, Vertex*> Pair;
48  private:  private:
49    //! An edge is defined by two vertices.    Edge::Pair __verticesPair;    /**< the two vertices defining the edge */
   Edge::Pair vp;  
50    
51    //! reference of the Edge.    size_t __reference;           /**< the reference of the edge */
   int ref;  
52    
53  public:  public:
54    //! Returns the reference of the edge.    /**
55    const int& Ref() const     * Read-only access to the reference of the edge
56       *
57       *
58       * @return the reference
59       */
60      const size_t& reference() const
61      {
62        return __reference;
63      }
64    
65      /**
66       * Access to the reference of the edge
67       *
68       *
69       * @return the reference
70       */
71      size_t& reference()
72      {
73        return __reference;
74      }
75    
76      /**
77       * Access to the ith vertex of the edge
78       *
79       *
80       * @return the ith vertex
81       */
82      inline const Vertex& operator() (const size_t& i) const
83      {
84        assert (i<2);
85        switch(i) {
86        case 0:
87          return *(__verticesPair.first);
88        case 1:
89          return *(__verticesPair.second);
90        }
91        return *(__verticesPair.first); // Never reached
92      }
93    
94      /**
95       * Returns true if edges have \b only same \b vertices
96       *
97       * @param e another edge
98       *
99       * @return true if vertices are the same
100       */
101      inline bool operator==(const Edge& e) const
102      {
103        return (__verticesPair==e.__verticesPair);
104      }
105    
106      /**
107       * Sets an order for edges
108       *
109       * @param e a given edge
110       *
111       * @return true is the edge is sort before the given one
112       */
113      inline bool operator<(const Edge& e) const
114      {
115        return (__verticesPair<e.__verticesPair);
116      }
117    
118      /**
119       * Sets the current edge to a given one
120       *
121       * @param e a given edge
122       *
123       * @return \f$ e := e' \f$
124       */
125      inline const Edge& operator=(const Edge& e)
126    {    {
127      return ref;      __verticesPair = e.__verticesPair;
128    }      __reference = e.__reference;
129    
130    //! Returns the reference of the edge.      return *this;
   int& Ref()  
   {  
     return ref;  
131    }    }
132    
   //! Returns a Edge Vertex  
   inline const Vertex& operator() (int i) const;  
   
   //! Returns true if edges have *only* same *vertices*  
   inline const bool operator==(const Edge& e) const;  
   
   //! Tries to implement a sort of order for edges (using the address of vertices)  
   inline const bool operator< (const Edge& e) const;  
   
   //! Copies the Edge \a e.  
   inline const Edge& operator= (const Edge& e);  
   
133    //! Cast to a Edge::Pair    //! Cast to a Edge::Pair
134    inline operator Pair()    inline operator Pair&()
135    {    {
136      return vp;      return __verticesPair;
137    }    }
138    
139    //!  Cast to a const Edge::Pair    /**
140    inline operator Pair() const     * Automatic cast to a Edge::Pair
141       *
142       *
143       * @return the vertices pair
144       */
145      inline operator const Pair&() const
146    {    {
147      return vp;      return __verticesPair;
148    }    }
149    
150    //! Default constructor.    /**
151       * Default constructor
152       *
153       * @note do no initialization
154       */
155    Edge()    Edge()
156    {    {
157      ;      ;
158    }    }
159    
160    //! Copy constructor.    /**
161       * Copy constructor
162       *
163       * @param E a given edge
164       */
165    Edge(const Edge& E)    Edge(const Edge& E)
166      : vp(E.vp),      : __verticesPair(E.__verticesPair),
167        ref(E.ref)        __reference(E.__reference)
168    {    {
169      ;      ;
170    }    }
171    
172    /*!  Constructs an Edge using the vertices \a v1 and \a v2 and a given    /**
173      reference \a ref. If this last argument is not given ref is 0.     * Constructs an edge using two vertices
174    */     *
175    Edge(const Vertex& v1, const Vertex& v2, int r=0)     * @param v1 the first vertex
176      : ref(r)     * @param v2 the second vertex
177       * @param ref a given reference
178       *
179       * @note if reference is not provided, it is set to 0
180       * @note vertices are sorted to optimization purpose
181       * @warning const_cast usage is not good for design
182       */
183      Edge(const Vertex& v1, const Vertex& v2,
184           const size_t& ref=0)
185        : __reference(ref)
186    {    {
187      Vertex* V1 = const_cast<Vertex*>((&v1<&v2) ? &v1 : &v2);      Vertex* V1 = const_cast<Vertex*>((&v1<&v2) ? &v1 : &v2);
188      Vertex* V2 = const_cast<Vertex*>((&v1>&v2) ? &v1 : &v2);      Vertex* V2 = const_cast<Vertex*>((&v1>&v2) ? &v1 : &v2);
189      vp = Pair(V1, V2);      __verticesPair = Pair(V1, V2);
190    }    }
191    
192    /*!  Constructs an Edge using the Edge::Pair \a VP and a given    /**
193      reference \a ref. If this last argument is not given ref is 0.     * Constructs an edge using a pair of vertices and a given reference
194      \warning the Edge::Pair ordering is not test assuming that it is correct.     *
195    */     * @param vp the pair of vertices
196    Edge(const Edge::Pair& VP, int r=0)     * @param ref the givene reference
197      : vp(VP),     */
198        ref(r)    Edge(const Edge::Pair& VP,
199           const size_t& ref=0)
200        : __verticesPair(VP),
201          __reference(ref)
202    {    {
203      ;      ;
204    }    }
205    
206    //! Destructor.    /**
207       * The destructor
208       *
209       */
210    ~Edge()    ~Edge()
211    {    {
212      ;      ;
213    }    }
214    
215    //! Outputs the Edge \a e using the stream \a os.    /**
216       * Prints the edge to a given stream
217       *
218       * @param os the given stream
219       * @param e the edge to print
220       *
221       * @return the modified stream
222       */
223    friend std::ostream& operator << (std::ostream& os,    friend std::ostream& operator << (std::ostream& os,
224                                      const Edge& e);                                      const Edge& e);
225  };  };
226    
 //! Returns a Edge Vertex  
 inline const Vertex& Edge::operator () (int i) const  
 {  
   assert ((i>=0)&&(i<2));  
   switch(i) {  
   case 0:  
     return *(vp.first);  
   case 1:  
     return *(vp.second);  
   }  
   return *(vp.first); // Never reached  
 }  
   
 /*! Just use vertices pointers for comparison because same edge can be isued  
  from 2 different cells.  
 */  
 inline const bool Edge::operator==(const Edge& e) const  
 {  
   return (vp==e.vp);  
 }  
   
 /*! use the address of Vertices to define an order in edges ... The purpose of  
   this method is to be able to remove same edges from a list.  
 */  
 inline const bool Edge::operator< (const Edge& e) const  
 {  
   return (vp<e.vp);  
 }  
   
 //! Copies the Edge \a e.  
 inline const Edge& Edge::operator=(const Edge& e)  
 {  
   vp = e.vp;  
   ref = e.ref;  
   
   return *this;  
 }  
   
227  #endif // LINE_HPP  #endif // LINE_HPP
228    

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26