bioprocessing 6.0.4
setedge.h
Go to the documentation of this file.
1/* Copyright (C) 2000-2013 CEA
2 *
3 * This software and supporting documentation were developed by
4 * bioPICSEL
5 * CEA/DSV/I²BM/MIRCen/LMN, Batiment 61,
6 * 18, route du Panorama
7 * 92265 Fontenay-aux-Roses
8 * France
9 */
10
11#ifndef BIOPROCESSING_GRAPH_SETEDGE
12#define BIOPROCESSING_GRAPH_SETEDGE
13
14//--- bioprocessing ----------------------------------------------------------
15#include <bioprocessing/graph/baseedge.h> // bio::BaseEdge
16//--- cartobase --------------------------------------------------------------
17#include <cartobase/smart/rcptr.h> // carto::rc_ptr
18//--- std --------------------------------------------------------------------
19#include <set> // std::set
20//----------------------------------------------------------------------------
21
22namespace bio {
23
24 template <typename V> class SetEdge;
25 template <typename V> class SetEdgeRef;
26
27//============================================================================
28// Set EDGE: DECLARATION
29//============================================================================
36 template <typename V>
37 class SetEdge: public BaseEdge<V>
38 {
39 //--- typedef ------------------------------------------------------------
40 protected:
41 typedef SetEdge<V> This;
42 typedef BaseEdge<V> Base;
43 typedef std::set<V> VertexSet;
44 public:
45 typedef V Vertex;
48
49 //--- constructor --------------------------------------------------------
50 public:
52 SetEdge( const Vertex & x, const Vertex & y ): _set()
53 {
54 _set.insert(x);
55 _set.insert(y);
56 }
57
58 SetEdge( const This & other ): _set(other._set) {}
60 SetEdge( const Base & other ): _set()
61 {
62 _set.insert( other.x() );
63 _set.insert( other.y() );
64 }
65 virtual ~SetEdge() {}
66
67 //--- iterators ----------------------------------------------------------
68 public:
69 typedef typename VertexSet::const_iterator const_iterator;
70 typedef typename VertexSet::iterator iterator;
71 const_iterator begin() const { return _set.begin(); }
72 const_iterator end() const { return _set.end(); }
73 iterator begin() { return _set.begin(); }
74 iterator end() { return _set.end(); }
75
76 //--- accessor -----------------------------------------------------------
77 public:
79 Vertex x() { return *( begin() ); }
81 const Vertex x() const { return *( begin() ); }
83 Vertex y() { return *( ++( begin() ) ); }
85 const Vertex y() const { return *( ++( begin() ) ); }
87 Vertex other( const Vertex & v )
88 {
89 iterator i = begin();
90 return( v == *i ? *(++i) : *i );
91 }
92
93 const Vertex other( const Vertex & v ) const
94 {
96 return( v == *i ? *(++i) : *i );
97 }
98
99 //--- virtual operators ----------------------------------------------------
100 public:
102 virtual bool operator== ( const This & other ) const
103 {
104 return x() == other.x() && y() == other.y();
105 }
106
107 virtual bool operator!= ( const This & other ) const
108 {
109 return x() != other.x() || y() != other.y();
110 }
111
113 virtual bool operator> ( const This & other ) const
114 {
115 const_iterator i, j;
116 for( i = begin(), j = other.begin(); i != end(); ++i, ++j )
117 {
118 if( *i > *j )
119 return true;
120 else if( *i < *j )
121 return false;
122 }
123 return false;
124 }
125
127 virtual bool operator< ( const This & other ) const
128 {
129 const_iterator i, j;
130 for( i = begin(), j = other.begin(); i != end(); ++i, ++j )
131 {
132 if( *i < *j )
133 return true;
134 else if( *i > *j )
135 return false;
136 }
137 return false;
138 }
139
141 virtual bool operator>= ( const This & other ) const
142 {
143 return ( *this == other ) || ( *this > other );
144 }
145
147 virtual bool operator<= ( const This & other ) const
148 {
149 return ( *this == other ) || ( *this < other );
150 }
151
152 //--- members ------------------------------------------------------------
154
155 //--- friends ------------------------------------------------------------
156 friend class SetEdgeRef<V>;
157 };
158
159//============================================================================
160// SET EDGE REF
161//============================================================================
166 template <typename V>
167 class SetEdgeRef: public BaseEdgeRef<V>
168 {
169 //--- typedef ------------------------------------------------------------
170 protected:
174 public:
175 typedef typename Pointed::Vertex Vertex;
176 typedef typename Pointed::Edge Edge;
177
178 //--- constructor --------------------------------------------------------
179 protected:
182 public:
184 SetEdgeRef( const Vertex & x, const Vertex & y ): Base( new Pointed(x,y) ) {}
188 SetEdgeRef( Pointed * e ): Base(e) {}
192 virtual ~SetEdgeRef() {}
193
194 //--- none factory -------------------------------------------------------
195 public:
198 static Edge none() { return This( (Pointed*)0 ); }
199
200 //--- iterators ----------------------------------------------------------
201 public:
202 typedef typename Pointed::iterator iterator;
204 virtual const_iterator begin() const { return ((Pointed*)(this->get()))->begin(); }
205 virtual const_iterator end() const { return ((Pointed*)(this->get()))->end(); }
206 virtual iterator begin() { return ((Pointed*)(this->get()))->begin(); }
207 virtual iterator end() { return ((Pointed*)(this->get()))->end(); }
208
209 //--- virtual operators --------------------------------------------------
210 public:
213 virtual bool operator== ( const This & other ) const
214 {
215 if( !(*this) && !other )
216 return true;
217 else if( !(*this) || !other )
218 return false;
219 else
220 return *((Pointed*)this->get()) == *((Pointed*)other.get());
221 }
222 virtual bool operator!= ( const This & other ) const
223 {
224 return !( *this == other );
225 }
226 virtual bool operator> ( const This & other ) const
227 {
228 if( *this == other )
229 return false;
230 else if( !(*this) || !other )
231 return false;
232 else
233 return *((Pointed*)this->get()) > *((Pointed*)other.get());
234 }
235 virtual bool operator< ( const This & other ) const
236 {
237 if( *this == other )
238 return false;
239 else if( !(*this) || !other )
240 return false;
241 else
242 return *((Pointed*)this->get()) < *((Pointed*)other.get());
243 }
244 virtual bool operator>= ( const This & other ) const
245 {
246 return ( *this == other ) || ( *this > other );
247 }
248 virtual bool operator<= ( const This & other ) const
249 {
250 return ( *this == other ) || ( *this < other );
251 }
252
253 //--- friends ------------------------------------------------------------
254 friend class SetEdge<V>;
255 };
256
257} // namespace bio
258
259#endif // BIOPROCESSING_GRAPH_BASEEDGE
BaseEdgeRef()
Default constructor (creates an empty pointer)
Definition baseedge.h:116
virtual Vertex other(const Vertex &v)
access the vertex that is not v
Definition baseedge.h:144
virtual Vertex x()
access the first vertex (arbitrary choice for non oriented edges)
Definition baseedge.h:136
virtual Vertex y()
access the second vertex (arbitrary choice for non oriented edges)
Definition baseedge.h:140
Base class for edges.
Definition baseedge.h:36
Reference counting pointer to a SetEdge.
Definition setedge.h:168
Pointed::iterator iterator
Definition setedge.h:202
static Edge none()
Empty pointer factory.
Definition setedge.h:198
virtual const_iterator end() const
Definition setedge.h:205
Pointed::Edge Edge
USable Edge type.
Definition setedge.h:176
virtual ~SetEdgeRef()
Definition setedge.h:192
SetEdge< V > Pointed
Pointed object type.
Definition setedge.h:173
Pointed::Vertex Vertex
Usable Vertex type.
Definition setedge.h:175
virtual const_iterator begin() const
Definition setedge.h:204
virtual bool operator>(const This &other) const
Definition setedge.h:226
SetEdgeRef(const Vertex &x, const Vertex &y)
Constructor from a pair of vertices.
Definition setedge.h:184
virtual bool operator!=(const This &other) const
Definition setedge.h:222
virtual bool operator>=(const This &other) const
Definition setedge.h:244
virtual iterator end()
Definition setedge.h:207
virtual iterator begin()
Definition setedge.h:206
Pointed::const_iterator const_iterator
Definition setedge.h:203
SetEdgeRef< V > This
Type of *this.
Definition setedge.h:171
virtual bool operator<=(const This &other) const
Definition setedge.h:248
SetEdgeRef()
Default constructor (builds a none pointer)
Definition setedge.h:181
SetEdgeRef(const Base &other)
Copy constructor (it copies the reference, it does not duplicate the pointed object)
Definition setedge.h:191
SetEdgeRef(Pointed *e)
Constructor from a pointer (the pointer should either be created by new, or be already referenced by ...
Definition setedge.h:188
BaseEdgeRef< V > Base
Base class type.
Definition setedge.h:172
virtual bool operator<(const This &other) const
Definition setedge.h:235
virtual bool operator==(const This &other) const
There is equality if both pointers are none, or if both pointed objects are equal.
Definition setedge.h:213
Edges: set implementation of non-oriented edges.
Definition setedge.h:38
const_iterator end() const
Definition setedge.h:72
std::set< V > VertexSet
Vertex set type.
Definition setedge.h:43
virtual bool operator!=(const This &other) const
there is equality if both vertices are equal
Definition setedge.h:107
virtual bool operator>(const This &other) const
For inequality we first look at x, and if they are equal, we look at y.
Definition setedge.h:113
Vertex y()
access the second vertex (y is the bigger vertex)
Definition setedge.h:83
SetEdgeRef< V > Ref
Reference type.
Definition setedge.h:47
SetEdge< V > This
Type of *this.
Definition setedge.h:41
SetEdge(const Vertex &x, const Vertex &y)
Constructor from a pair of vertices.
Definition setedge.h:52
const Vertex other(const Vertex &v) const
access the vertex that is not v
Definition setedge.h:93
Vertex other(const Vertex &v)
access the vertex that is not v
Definition setedge.h:87
virtual bool operator<=(const This &other) const
For inequality we first look at x, and if they are equal, we look at y.
Definition setedge.h:147
iterator begin()
Definition setedge.h:73
SetEdgeRef< V > Edge
Usable edge type.
Definition setedge.h:46
virtual bool operator==(const This &other) const
there is equality if both vertices are equal
Definition setedge.h:102
BaseEdge< V > Base
Base class type.
Definition setedge.h:42
SetEdge(const Base &other)
Copy constructor from base class.
Definition setedge.h:60
Vertex x()
access the first vertex (x is the smaller vertex)
Definition setedge.h:79
VertexSet _set
Definition setedge.h:153
virtual bool operator>=(const This &other) const
For inequality we first look at x, and if they are equal, we look at y.
Definition setedge.h:141
const Vertex x() const
access the first vertex (x is the smaller vertex)
Definition setedge.h:81
VertexSet::const_iterator const_iterator
Definition setedge.h:69
virtual bool operator<(const This &other) const
For inequality we first look at x, and if they are equal, we look at y.
Definition setedge.h:127
V Vertex
Usable vertex type.
Definition setedge.h:45
SetEdge(const This &other)
Copy constructor.
Definition setedge.h:58
iterator end()
Definition setedge.h:74
VertexSet::iterator iterator
Definition setedge.h:70
const_iterator begin() const
Definition setedge.h:71
virtual ~SetEdge()
Definition setedge.h:65
const Vertex y() const
access the second vertex (y is the bigger vertex)
Definition setedge.h:85