bioprocessing 6.0.4
baseedge.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_BASEEDGE
12#define BIOPROCESSING_GRAPH_BASEEDGE
13
14//--- cartobase --------------------------------------------------------------
15#include <cartobase/smart/rcptr.h> // carto::rc_ptr
16//----------------------------------------------------------------------------
17
18namespace bio {
19
20 template <typename V> class BaseEdge;
21 template <typename V> class BaseEdgeRef;
22
23//============================================================================
24// BASE EDGE: DECLARATION
25//============================================================================
34 template <typename V>
35 class BaseEdge: public carto::RCObject
36 {
37 //--- typedef ------------------------------------------------------------
38 protected:
39 typedef BaseEdge<V> This;
40 public:
41 typedef V Vertex;
44
45 //--- constructor --------------------------------------------------------
46 public:
47 virtual ~BaseEdge() {}
48
49 //--- accessor -----------------------------------------------------------
50 public:
52 virtual Vertex x() { throw; } //< not defined
54 virtual const Vertex x() const { throw; } //< not defined
56 virtual Vertex y() { throw; } //< not defined
58 virtual const Vertex y() const { throw; } //< not defined
60 virtual Vertex other( const Vertex & v ) { throw; } //< not defined
62 virtual const Vertex other( const Vertex & v ) const { throw; } //< not defined
63
64 //--- virtual operators ----------------------------------------------------
65 public:
66 virtual bool operator== ( const This & other ) const { throw; } //< not defined
67 virtual bool operator!= ( const This & other ) const { throw; } //< not defined
68 virtual bool operator> ( const This & other ) const { throw; } //< not defined
69 virtual bool operator< ( const This & other ) const { throw; } //< not defined
70 virtual bool operator>= ( const This & other ) const { throw; } //< not defined
71 virtual bool operator<= ( const This & other ) const { throw; } //< not defined
72
73 //--- friends ------------------------------------------------------------
74 friend class BaseEdgeRef<V>;
75 };
76
77} // namespace bio
78
79//============================================================================
80// BASE EDGE: STREAM
81//============================================================================
84template <typename V>
85std::ostream & operator<<( std::ostream & os, const bio::BaseEdge<V> & e )
86{
87 os << "E{ " << e.x() << " -- " << e.y() << " }";
88 return os;
89}
90
91namespace bio {
92
93//============================================================================
94// EDGE REF
95//============================================================================
100 template <typename V>
101 class BaseEdgeRef: public carto::rc_ptr<BaseEdge<V> >
102 {
103 //--- typedef ------------------------------------------------------------
104 protected:
106 typedef carto::rc_ptr<BaseEdge<V> > Base;
108 public:
109 typedef typename Pointed::Vertex Vertex;
110 typedef typename Pointed::Edge Edge;
111 typedef typename Pointed::Edge Ref;
112
113 //--- constructor --------------------------------------------------------
114 protected:
117 public:
125 virtual ~BaseEdgeRef() {}
126
127 //--- none factory -------------------------------------------------------
128 public:
131 static Edge none() { return This( (Pointed*)0 ); }
132
133 //--- accessor -----------------------------------------------------------
134 public:
136 virtual Vertex x() { return (*this)->x(); }
138 virtual const Vertex x() const { return (*this)->x(); }
140 virtual Vertex y() { return (*this)->y(); }
142 virtual const Vertex y() const { return (*this)->y(); }
144 virtual Vertex other( const Vertex & v ) { return (*this)->other(v); }
146 virtual const Vertex other( const Vertex & v ) const { return (*this)->other(v); }
147
148 //--- virtual operators --------------------------------------------------
149 public:
152 virtual bool operator== ( const This & other ) const
153 {
154 if( !(*this) && !other )
155 return true;
156 else if( !(*this) || !other )
157 return false;
158 else
159 return *(this->get()) == *(other.get());
160 }
161 virtual bool operator!= ( const This & other ) const
162 {
163 return !( *this == other );
164 }
165 virtual bool operator> ( const This & other ) const
166 {
167 if( *this == other )
168 return false;
169 else
170 return this > &other;
171 }
172 virtual bool operator< ( const This & other ) const
173 {
174 if( *this == other )
175 return false;
176 else
177 return this < &other;
178 }
179 virtual bool operator>= ( const This & other ) const
180 {
181 return ( *this == other ) || ( *this > other );
182 }
183 virtual bool operator<= ( const This & other ) const
184 {
185 return ( *this == other ) || ( *this < other );
186 }
187
188 //--- friends ------------------------------------------------------------
189 friend class BaseEdge<V>;
190 };
191
192} // namespace bio
193
194//============================================================================
195// BASE EDGE REF: STREAM
196//============================================================================
200template <typename V>
201std::ostream & operator<<( std::ostream & os, const bio::BaseEdgeRef<V> & e )
202{
203 if( e.get() )
204 os << *e;
205 else
206 os << "E{ NULL }";
207 return os;
208}
209
210
211#endif // BIOPROCESSING_GRAPH_BASEEDGE
std::ostream & operator<<(std::ostream &os, const bio::BaseEdge< V > &e)
Print of a BaseEdge.
Definition baseedge.h:85
Reference counting pointer to a BaseEdge.
Definition baseedge.h:102
virtual bool operator>(const This &other) const
Definition baseedge.h:165
virtual bool operator>=(const This &other) const
Definition baseedge.h:179
carto::rc_ptr< BaseEdge< V > > Base
Base class.
Definition baseedge.h:106
Pointed::Vertex Vertex
Usable vertex type.
Definition baseedge.h:109
BaseEdgeRef(const Base &other)
Copy constructor (it copies the reference, it does not duplicate the pointed object)
Definition baseedge.h:124
Pointed::Edge Edge
Usable edge type.
Definition baseedge.h:110
virtual bool operator!=(const This &other) const
Definition baseedge.h:161
virtual const Vertex other(const Vertex &v) const
access the vertex that is not v
Definition baseedge.h:146
BaseEdgeRef(Pointed *e)
Constructor from a pointer (the pointer should either be created by new, or be already referenced by ...
Definition baseedge.h:121
Pointed::Edge Ref
Reference type.
Definition baseedge.h:111
BaseEdgeRef()
Default constructor (creates an empty pointer)
Definition baseedge.h:116
BaseEdgeRef< V > This
Type of *this.
Definition baseedge.h:105
virtual bool operator==(const This &other) const
There is equality if both pointers are none, or if both pointed objects are equal.
Definition baseedge.h:152
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 bool operator<(const This &other) const
Definition baseedge.h:172
virtual ~BaseEdgeRef()
Definition baseedge.h:125
virtual Vertex y()
access the second vertex (arbitrary choice for non oriented edges)
Definition baseedge.h:140
static Edge none()
Empty pointer factory.
Definition baseedge.h:131
virtual const Vertex y() const
access the second vertex (arbitrary choice for non oriented edges)
Definition baseedge.h:142
virtual bool operator<=(const This &other) const
Definition baseedge.h:183
virtual const Vertex x() const
access the first vertex (arbitrary choice for non oriented edges)
Definition baseedge.h:138
BaseEdge< V > Pointed
Pointed object type.
Definition baseedge.h:107
Base class for edges.
Definition baseedge.h:36
virtual bool operator!=(const This &other) const
Definition baseedge.h:67
virtual bool operator>=(const This &other) const
Definition baseedge.h:70
virtual const Vertex y() const
access the second vertex (arbitrary choice for non oriented edges)
Definition baseedge.h:58
virtual Vertex x()
access the first vertex (arbitrary choice for non oriented edges)
Definition baseedge.h:52
virtual bool operator<(const This &other) const
Definition baseedge.h:69
BaseEdgeRef< V > Ref
Reference type.
Definition baseedge.h:43
BaseEdgeRef< V > Edge
Usable Edge type (RC)
Definition baseedge.h:42
virtual bool operator<=(const This &other) const
Definition baseedge.h:71
V Vertex
Vertex type.
Definition baseedge.h:41
virtual const Vertex x() const
access the first vertex (arbitrary choice for non oriented edges)
Definition baseedge.h:54
virtual bool operator>(const This &other) const
Definition baseedge.h:68
virtual bool operator==(const This &other) const
Definition baseedge.h:66
BaseEdge< V > This
Type of *this.
Definition baseedge.h:39
virtual Vertex y()
access the second vertex (arbitrary choice for non oriented edges)
Definition baseedge.h:56
virtual const Vertex other(const Vertex &v) const
access the vertex that is not v
Definition baseedge.h:62
virtual Vertex other(const Vertex &v)
access the vertex that is not v
Definition baseedge.h:60
virtual ~BaseEdge()
Definition baseedge.h:47