bioprocessing  5.1.2
pointvertex.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_POINTVERTEX
12 #define BIOPROCESSING_GRAPH_POINTVERTEX
13 
14 //--- bioprocessing ----------------------------------------------------------
15 #include <bioprocessing/graph/basevertex.h> // bio::BaseVertex
16 //--- cartobase --------------------------------------------------------------
17 #include <cartobase/smart/rcptr.h> // carto::rc_ptr
18 //--- std --------------------------------------------------------------------
19 #include <typeinfo> // typeid
20 //----------------------------------------------------------------------------
21 namespace bio {
22 
23  template <typename P> class PointVertex;
24  template <typename P> class PointVertexRef;
25 
26 //============================================================================
27 // POINT VERTEX
28 //============================================================================
34  template <typename P>
35  class PointVertex: public BaseVertex
36  {
37  //--- typedef ------------------------------------------------------------
38  protected:
39  typedef PointVertex<P> This;
40  typedef BaseVertex Base;
41  public:
44  typedef P Point;
45 
46  //--- constructor --------------------------------------------------------
47  public:
49  PointVertex( const Point & p ): _point(p) {}
51  PointVertex( const This & other ): _point(other._point) {}
52  virtual ~PointVertex() {}
53 
54  //--- accessor -----------------------------------------------------------
55  public:
57  const Point & point() const { return _point; }
59  Point & point() { return _point; }
60 
61  //--- comparison ---------------------------------------------------------
62  public:
63  virtual bool operator==( const This & other ) const
64  {
65  if( typeid(other) != typeid(*this) )
66  return false;
67  return _point == ( (const This &)other )._point;
68  }
69  virtual bool operator!=( const This & other ) const
70  {
71  return !operator==( other );
72  }
73  virtual bool operator>( const This & other ) const
74  {
75  if( typeid(other) != typeid(*this) )
76  return this > &other;
77 
78  for( int i = _point.size()-1; i >= 0; --i )
79  {
80  if( _point[i] > ( (const This &)other )._point[i] )
81  return true;
82  else if( _point[i] < ( (const This &)other )._point[i] )
83  return false;
84  }
85  return false;
86  }
87  virtual bool operator<( const This & other ) const
88  {
89  if( operator>( other ) || operator==( other ) )
90  return false;
91  return true;
92  }
93  virtual bool operator<=( const This & other ) const
94  {
95  if( operator<( other ) || operator==( other ) )
96  return true;
97  return false;
98  }
99  virtual bool operator>=( const This & other ) const
100  {
101  if( operator>( other ) || operator==( other ) )
102  return true;
103  return false;
104  }
105 
106  //--- members ------------------------------------------------------------
107  protected:
109 
110  //--- friends ------------------------------------------------------------
111  friend class PointVertexRef<P>;
112  };
113 
114 } // namespace bio
115 
116 //============================================================================
117 // BASE EDGE: STREAM
118 //============================================================================
121 template <typename P>
122 std::ostream & operator<<( std::ostream & os, const bio::PointVertex<P> & v )
123 {
124  os << "V{ " << v.point() << " }";
125  return os;
126 }
127 
128 namespace bio {
129 
130 //============================================================================
131 // POINT VERTEX REF
132 //============================================================================
137  template <typename P>
139  {
140  //--- typedef ------------------------------------------------------------
141  protected:
143  typedef BaseVertexRef Base;
145  public:
146  typedef typename Pointed::Vertex Vertex;
147  typedef typename Pointed::Point Point;
148 
149  //--- constructor --------------------------------------------------------
150  public:
154  PointVertexRef( const Point & p ): Base( new Pointed( p ) ) {}
161  PointVertexRef( const Base & other ): Base( other ) {}
162  virtual ~PointVertexRef() {}
163 
164  //--- none factory -------------------------------------------------------
165  public:
168  static Vertex none() { return This( (Pointed*)0 ); }
169 
170  //--- virtual operators --------------------------------------------------
171  public:
174  virtual bool operator== ( const This & other ) const
175  {
176  if( !(*this) && !other )
177  return true;
178  else if( !(*this) || !other )
179  return false;
180  else
181  return *((Pointed*)this->get()) == *((Pointed*)other.get());
182  }
183  virtual bool operator!= ( const This & other ) const
184  {
185  return !( *this == other );
186  }
187  virtual bool operator> ( const This & other ) const
188  {
189  if( *this == other )
190  return false;
191  else if( !(*this) || !other )
192  return false;
193  else
194  return *((Pointed*)this->get()) > *((Pointed*)other.get());
195  }
196  virtual bool operator< ( const This & other ) const
197  {
198  if( *this == other )
199  return false;
200  else if( !(*this) || !other )
201  return false;
202  else
203  return *((Pointed*)this->get()) < *((Pointed*)other.get());
204  }
205  virtual bool operator>= ( const This & other ) const
206  {
207  return ( *this == other ) || ( *this > other );
208  }
209  virtual bool operator<= ( const This & other ) const
210  {
211  return ( *this == other ) || ( *this < other );
212  }
213 
214  //--- accessor -----------------------------------------------------------
215  public:
217  const Point & point() const { return ((Pointed*)(this->get()))->point(); }
219  Point & point() { return ((Pointed*)(this->get()))->point(); }
220  };
221 
222 } // namespace bio
223 
224 //============================================================================
225 // BASE EDGE REF: STREAM
226 //============================================================================
230 template <typename P>
231 std::ostream & operator<<( std::ostream & os, const bio::PointVertexRef<P> & v )
232 {
233  if( v.get() )
234  os << *( (bio::PointVertex<P> *)v.get() );
235  else
236  os << "V{ NULL }";
237  return os;
238 }
239 
240 #endif // BIOPROCESSING_GRAPH_POINTVERTEX
Reference counting pointer to a BaseVertex.
Definition: basevertex.h:105
carto::rc_ptr< BaseVertex > Base
Base class type.
Definition: basevertex.h:109
Base class for vertices.
Definition: basevertex.h:34
Reference counting pointer to a PointVertex.
Definition: pointvertex.h:139
virtual bool operator==(const This &other) const
There is equality if both pointers are none, or if both pointed objects are equal.
Definition: pointvertex.h:174
Point & point()
non constant accessor to the coordinates
Definition: pointvertex.h:219
virtual bool operator>(const This &other) const
Definition: pointvertex.h:187
PointVertexRef(const Point &p)
Constructor from coordinates.
Definition: pointvertex.h:154
BaseVertexRef Base
Base class (rc_ptr)
Definition: pointvertex.h:143
PointVertexRef(Pointed *v)
Constructor from a pointer (the pointer should either be created by new, or be already referenced by ...
Definition: pointvertex.h:158
virtual bool operator>=(const This &other) const
Definition: pointvertex.h:205
virtual bool operator!=(const This &other) const
Definition: pointvertex.h:183
PointVertexRef< P > This
Type of *this.
Definition: pointvertex.h:142
static Vertex none()
Empty pointer factory.
Definition: pointvertex.h:168
virtual bool operator<=(const This &other) const
Definition: pointvertex.h:209
Pointed::Point Point
Point.
Definition: pointvertex.h:147
virtual ~PointVertexRef()
Definition: pointvertex.h:162
Pointed::Vertex Vertex
Useable type (RC)
Definition: pointvertex.h:146
PointVertexRef(const Base &other)
Copy constructor (it copies the reference, it does not duplicate the pointed object)
Definition: pointvertex.h:161
virtual bool operator<(const This &other) const
Definition: pointvertex.h:196
const Point & point() const
constant accessor to the coordinates
Definition: pointvertex.h:217
PointVertex< P > Pointed
Pointed object type.
Definition: pointvertex.h:144
PointVertexRef()
Default constructor (creates an empty pointer)
Definition: pointvertex.h:152
Coordinates-defined vertices.
Definition: pointvertex.h:36
BaseVertex Base
Base class.
Definition: pointvertex.h:40
virtual bool operator!=(const This &other) const
Definition: pointvertex.h:69
virtual bool operator<(const This &other) const
Definition: pointvertex.h:87
virtual bool operator>=(const This &other) const
Definition: pointvertex.h:99
PointVertex(const Point &p)
Constructor from coordiantes.
Definition: pointvertex.h:49
const Point & point() const
constant accessor to the coordinates
Definition: pointvertex.h:57
P Point
Coordiantes type.
Definition: pointvertex.h:44
PointVertex< P > This
Type of *this.
Definition: pointvertex.h:39
PointVertex(const This &other)
Copy constructor.
Definition: pointvertex.h:51
virtual ~PointVertex()
Definition: pointvertex.h:52
PointVertexRef< P > Ref
Reference type.
Definition: pointvertex.h:43
Point & point()
non constant accessor to the coordinates
Definition: pointvertex.h:59
virtual bool operator==(const This &other) const
Definition: pointvertex.h:63
PointVertexRef< P > Vertex
Useable type (RC type)
Definition: pointvertex.h:42
virtual bool operator<=(const This &other) const
Definition: pointvertex.h:93
virtual bool operator>(const This &other) const
Definition: pointvertex.h:73
std::ostream & operator<<(std::ostream &os, const bio::PointVertex< P > &v)
Print of a PointVertex.
Definition: pointvertex.h:122