00001 /*---------------------------------------------------------------------+ 00002 | Library QgarLib, graphics analysis and recognition | 00003 | Copyright (C) 2002 Qgar Project, LORIA | 00004 | | 00005 | This library is free software; you can redistribute it and/or | 00006 | modify it under the terms of the GNU Lesser General Public | 00007 | License version 2.1, as published by the Free Software Foundation. | 00008 | | 00009 | This library is distributed in the hope that it will be useful, | 00010 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 00011 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 00012 | See the GNU Lesser General Public License for more details. | 00013 | | 00014 | The GNU Lesser General Public License is included in the file | 00015 | LICENSE.LGPL, in the root directory of the Qgar packaging. See | 00016 | http://www.gnu.org/licenses/lgpl.html for the terms of the licence. | 00017 | To receive a paper copy, write to the Free Software Foundation, | 00018 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. | 00019 | | 00020 | Contact Project Qgar for any information: | 00021 | LORIA - équipe Qgar | 00022 | B.P. 239, 54506 Vandoeuvre-lès-Nancy Cedex, France | 00023 | email: qgar-contact@loria.fr | 00024 | http://www.qgar.org/ | 00025 *---------------------------------------------------------------------*/ 00026 00027 00028 #ifndef __GENPOINTCHAIN_H_INCLUDED__ 00029 #define __GENPOINTCHAIN_H_INCLUDED__ 00030 00031 00032 /** 00033 * @file GenPointChain.H 00034 * @brief Header file of class qgar::GenPointChain. 00035 * 00036 * @author <a href="mailto:qgar-develop@loria.fr?subject=Qgar fwd Gérald Masini">Gérald Masini</a>, 00037 * from previous work by Karl Tombre 00038 * @date December 15, 2003 16:16 00039 * @since Qgar 2.1.1 00040 */ 00041 00042 00043 // For RCS/CVS use: Do not delete 00044 /* $Id: GenPointChain.H,v 1.13 2005/07/13 16:29:01 masini Exp $ */ 00045 00046 00047 00048 // STD 00049 #include <list> 00050 // QGAR 00051 #include <qgarlib/AbstractGenPointChain.H> 00052 #include <qgarlib/primitives.H> 00053 00054 00055 00056 namespace qgar 00057 { 00058 00059 /** 00060 * @class GenPointChain GenPointChain.H "qgarlib/GenPointChain.H" 00061 * @ingroup DS_POINT 00062 * @brief Chain of points having coordinates of type <b>T</b>. 00063 * 00064 * A point is an instance of class qgar::GenPoint<T>. 00065 * New points can only be inserted to the beginning or to the end of the chain. 00066 * 00067 * Such a chain is implemented by a STL list of points with an iterator that 00068 * allows bidirectional traversal of the chain. The validity of the iterator 00069 * is preserved by any legal operation on the chain, unless the chain is empty. 00070 * 00071 * <b>Warning: Such a chain cannot be used in the STL way. The beginning 00072 * (resp. end) of the chain is the first (resp. last) point of the chain, 00073 * that is returned by functions qgar::GenPointChain::accessFront 00074 * and qgar::GenPointChain::front (resp. GenPointChain::back and 00075 * qgar::GenPointChain::back). In other words, the iterator <i>always</i> 00076 * points to a point in the chain (unless empty).</b> 00077 * 00078 * To use the chain in the Qgar way: 00079 * - To set the iterator to the beginning (resp. end) of the chain, 00080 * function qgar::GenPointChain::setToBegin 00081 * (resp. qgar::GenPointChain::setToEnd) 00082 * - To test if the iterator points to the beginning (resp. end) 00083 * of the chain, function qgar::GenPointChain::isAtBegin 00084 * (resp. qgar::GenPointChain::isAtEnd) 00085 * - To test if the chain includes at least one point after (resp. before) 00086 * the current point, function qgar::GenPointChain::hasNext 00087 * (resp. qgar::GenPointChain::hasPrevious) 00088 * - To move to the next (resp. previous) point, function 00089 * qgar::GenPointChain::moveNext (resp. qgar::GenPointChain::movePrevious) 00090 * - To get the current point, functions qgar::GenPointChain::current 00091 * or qgar::GenPointChain::accessCurrent 00092 * - To get the next (resp. previous) point, functions 00093 * qgar::GenPointChain::next or qgar::GenPointChain::accessNext 00094 * (resp. qgar::GenPointChain::previous or qgar::GenPointChain::accessPrevious) 00095 * - To insert a new point at the beginning (resp. end) of the chain, 00096 * function qgar::GenPointChain::push_front 00097 * (resp. qgar::GenPointChain::push_back) 00098 00099 * To use the chain in the STL way: 00100 * - Functions qgar::GenPointChain::pointList and 00101 * qgar::GenPointChain::accessPointList return the STL list of the points 00102 * representing the chain, 00103 * - STL iterators and functions may then be used to directly manage this list. 00104 * 00105 * Predefined types: 00106 * - qgar::Chain 00107 * - qgar::IChain 00108 * - qgar::FChain 00109 * - qgar::DChain 00110 * 00111 * @author <a href="mailto:qgar-develop@loria.fr?subject=Qgar fwd Gérald Masini">Gérald Masini</a>, 00112 * from previous work by Karl Tombre 00113 * @date December 15, 2003 16:16 00114 * @since Qgar 2.1.1 00115 */ 00116 template <class T> class GenPointChain 00117 00118 : public AbstractGenPointChain<T> 00119 00120 { 00121 // ------------------------------------------------------------------- 00122 // T Y P E D E F I N I T I O N S 00123 // ------------------------------------------------------------------- 00124 public: 00125 00126 /** @name Types */ 00127 // ===== 00128 //@{ 00129 00130 /** 00131 * @brief Type of the coordinates of the points. 00132 */ 00133 typedef T value_type; 00134 00135 /** 00136 * @brief Reference to qgar::GenPointChain::value_type. 00137 */ 00138 typedef value_type& reference; 00139 00140 /** 00141 * @brief Constant reference to qgar::GenPointChain::value_type. 00142 */ 00143 typedef const value_type& const_reference; 00144 00145 /** 00146 * @brief Pointer to qgar::GenPointChain::value_type. 00147 */ 00148 typedef value_type* pointer; 00149 00150 /** 00151 * @brief Constant pointer to qgar::GenPointChain::value_type. 00152 */ 00153 typedef const value_type* const_pointer; 00154 00155 //@} 00156 00157 00158 // ------------------------------------------------------------------- 00159 // P U B L I C M E M B E R S 00160 // ------------------------------------------------------------------- 00161 public: 00162 00163 00164 /** @name Constructors */ 00165 // ============ 00166 //@{ 00167 00168 /** 00169 * @brief Default constructor. 00170 * 00171 * The STL list of points is empty and the value of the iterator 00172 * is undefined. 00173 */ 00174 GenPointChain<value_type>(); 00175 00176 /** 00177 * @brief Copy constructor. 00178 * 00179 * @param aPtChain a chain of points 00180 * 00181 * @warning The internal iterator points to the beginning of the chain. 00182 */ 00183 GenPointChain<value_type>(const GenPointChain<value_type>& aPtChain); 00184 00185 /** 00186 * @brief Construct from a given point, that becomes the current point. 00187 * 00188 * The internal iterator points to the beginning of the chain. 00189 * 00190 * @param aPoint a point 00191 */ 00192 GenPointChain<value_type>(const GenPoint<value_type>& aPoint); 00193 00194 //@} 00195 00196 00197 /** @name Destructor */ 00198 // ========== 00199 //@{ 00200 00201 /** 00202 * @brief Virtual destructor. 00203 */ 00204 virtual ~GenPointChain<T>(); 00205 00206 //@} 00207 00208 00209 /** @name Access to chain characteristics */ 00210 // =============================== 00211 //@{ 00212 00213 /** 00214 * @brief Is current chain empty? 00215 */ 00216 virtual bool empty() const; 00217 00218 /** 00219 * @brief Get chain size (number of points). 00220 */ 00221 virtual int size() const; 00222 00223 //@} 00224 00225 00226 /** @name Iterator */ 00227 // ======== 00228 //@{ 00229 00230 /** 00231 * @brief Make the internal iterator point to the beginning 00232 * (first point) of the chain. 00233 * 00234 * @warning The chain is supposed not to be empty. 00235 */ 00236 virtual void setToBegin(); 00237 00238 /** 00239 * @brief Make the internal iterator point to the end 00240 * (last point) of the chain. 00241 * 00242 * @warning The chain is supposed not to be empty. 00243 */ 00244 virtual void setToEnd(); 00245 00246 /** 00247 * @brief Does internal iterator points to the beginning of the chain? 00248 */ 00249 virtual bool isAtBegin() const; 00250 00251 /** 00252 * @brief Does internal iterator points to the end of the chain? 00253 */ 00254 virtual bool isAtEnd() const; 00255 00256 /** 00257 * @brief Is there a point after the current point? 00258 * 00259 * @warning The chain is supposed not to be empty. 00260 */ 00261 virtual bool hasNext() const; 00262 00263 /** 00264 * @brief Is there a point before the current point? 00265 * 00266 * @warning The chain is supposed not to be empty. 00267 */ 00268 virtual bool hasPrevious() const; 00269 00270 /** 00271 * @brief Move to next point, that becomes the current point. 00272 * 00273 * @warning The chain is supposed not to be empty. 00274 */ 00275 virtual void moveNext(); 00276 00277 /** 00278 * @brief Move to previous point, that becomes the current point. 00279 * 00280 * @warning The chain is supposed not to be empty. 00281 */ 00282 virtual void movePrevious(); 00283 00284 //@} 00285 00286 00287 /** @name Access to points */ 00288 // ================ 00289 //@{ 00290 00291 /** 00292 * @brief Get first point. 00293 * 00294 * @warning The chain is supposed not to be empty. 00295 */ 00296 virtual const GenPoint<value_type>& accessFront() const; 00297 00298 /** 00299 * @brief Get a copy of first point. 00300 * 00301 * @warning The chain is supposed not to be empty. 00302 */ 00303 virtual GenPoint<value_type> front() const; 00304 00305 /** 00306 * @brief Get last point. 00307 * 00308 * @warning The chain is supposed not to be empty. 00309 */ 00310 virtual const GenPoint<value_type>& accessBack() const; 00311 00312 /** 00313 * @brief Get a copy of last point. 00314 * 00315 * @warning The chain is supposed not to be empty. 00316 */ 00317 virtual GenPoint<value_type> back() const; 00318 00319 /** 00320 * @brief Get the current point. 00321 * 00322 * @warning The chain is supposed not to be empty. 00323 */ 00324 virtual const GenPoint<value_type>& accessCurrent() const; 00325 00326 /** 00327 * @brief Get a copy of the current point. 00328 * 00329 * @warning The chain is supposed not to be empty. 00330 */ 00331 virtual GenPoint<value_type> current() const; 00332 00333 /** 00334 * @brief Get the successor of the current point. 00335 * 00336 * @warning The chain is supposed not to be empty, 00337 * and the iterator is supposed not to point to the last point. 00338 */ 00339 const GenPoint<value_type>& accessNext(); 00340 00341 /** 00342 * @brief Get a copy of the successor of the current point. 00343 * 00344 * @warning The chain is supposed not to be empty, 00345 * and the iterator is supposed not to point to the last point. 00346 */ 00347 virtual GenPoint<value_type> next(); 00348 00349 /** 00350 * @brief Get the predecessor of the current point. 00351 * 00352 * @warning The chain is supposed not to be empty, 00353 * and the iterator is supposed not to point to the first point. 00354 */ 00355 const GenPoint<value_type>& accessPrevious(); 00356 00357 /** 00358 * @brief Get a copy of the predecessor of the current point. 00359 * 00360 * @warning The chain is supposed not to be empty, 00361 * and the iterator is supposed not to point to the first point. 00362 */ 00363 virtual GenPoint<value_type> previous(); 00364 00365 //@} 00366 00367 00368 /** @name Access to the list of points */ 00369 // ============================ 00370 //@{ 00371 00372 /** 00373 * @brief Get the STL list implementing the chain of points. 00374 * 00375 * The function returns a <b>const</b> result, so that the user 00376 * cannot directly transform the list. 00377 */ 00378 inline const std::list< GenPoint<value_type> >& accessPointList() const; 00379 00380 /** 00381 * @brief Get the STL list implementing the chain of points. 00382 * 00383 * @warning The function does not return a <b>const</b> result, 00384 * allowing the client to directly transform the internal structure 00385 * of the chain, without using functions of the interface. 00386 * 00387 * @todo Maybe this kind of function should not be provided! 00388 */ 00389 inline std::list< GenPoint<value_type> >& pointList(); 00390 00391 //@} 00392 00393 00394 /** @name Insertion */ 00395 // ========= 00396 //@{ 00397 00398 /** 00399 * @brief Insert a point at the beginning of the chain. 00400 * 00401 * The internal iterator remains valid after the operation. 00402 * 00403 * @param aPt a point 00404 */ 00405 virtual void push_front(const GenPoint<value_type>& aPt); 00406 00407 /** 00408 * @brief Insert a point at the end of the chain. 00409 * 00410 * The internal iterator remains valid after the operation. 00411 * 00412 * @param aPt a point 00413 */ 00414 virtual void push_back(const GenPoint<value_type>& aPt); 00415 00416 //@} 00417 00418 00419 /** @name Transformations */ 00420 // =============== 00421 //@{ 00422 00423 /** 00424 * @brief Reverse the order of elements in the list. 00425 * 00426 * @warning The validity of the internal iterator to the chain 00427 * is preserved. 00428 */ 00429 virtual void reverse(); 00430 00431 //@} 00432 00433 00434 /** @name Conversions */ 00435 // =========== 00436 //@{ 00437 00438 /** 00439 * @brief Convert into a (STL) list of points. 00440 */ 00441 virtual std::list< GenPoint<value_type> > toPointList() const; 00442 00443 //@} 00444 00445 00446 /** @name Operators */ 00447 // ========= 00448 //@{ 00449 00450 /** 00451 * @brief Assignment. 00452 * 00453 * @param aPtChain a chain of points 00454 * 00455 * @warning The internal iterator points to the beginning of the chain. 00456 */ 00457 GenPointChain<value_type>& 00458 operator=(const GenPointChain<value_type>& aPtChain); 00459 00460 //@} 00461 00462 00463 // ------------------------------------------------------------------- 00464 // P R O T E C T E D M E M B E R S 00465 // ------------------------------------------------------------------- 00466 protected: 00467 00468 00469 /** @name Implementation of a chain of points */ 00470 // =================================== 00471 //@{ 00472 00473 /** 00474 * @brief List of the points. 00475 */ 00476 std::list< GenPoint<value_type> > _chain; 00477 00478 /** 00479 * @brief Iterator on the list of points. 00480 */ 00481 typename std::list< GenPoint<value_type> >::iterator _iter; 00482 00483 //@} 00484 00485 // ------------------------------------------------------------------- 00486 00487 }; // Class GenPointChain 00488 00489 00490 } // namespace qgar 00491 00492 00493 00494 00495 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII 00496 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII 00497 // I M P L E M E N T A T I O N 00498 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII 00499 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII 00500 00501 #include <qgarlib/GenPointChain.TCC> 00502 00503 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII 00504 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII 00505 00506 00507 00508 00509 // TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT 00510 // TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT 00511 // P R E D E F I N E D P O I N T C H A I N T Y P E S 00512 // TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT 00513 // TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT 00514 00515 00516 namespace qgar 00517 { 00518 00519 00520 /** 00521 * @name Predefined point chain types 00522 * @ingroup DS_POINT 00523 */ 00524 //@{ 00525 00526 /** 00527 * @brief Chain of points with <b>integer</b> coordinates. 00528 * 00529 * @see IPointChain 00530 */ 00531 typedef GenPointChain<int> PointChain; 00532 00533 /** 00534 * @brief Chain of points with <b>integer</b> coordinates. 00535 * 00536 * @see PointChain 00537 */ 00538 typedef GenPointChain<int> IPointChain; 00539 00540 /** 00541 * @brief Chain of points with <b>float</b> coordinates. 00542 */ 00543 typedef GenPointChain<float> FPointChain; 00544 00545 /** 00546 * @brief Chain of points with <b>double</b> coordinates. 00547 */ 00548 typedef GenPointChain<double> DPointChain; 00549 00550 //@} 00551 00552 00553 } // namespace qgar 00554 00555 00556 // TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT 00557 // TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT 00558 00559 00560 #endif /* __GENPOINTCHAIN_H_INCLUDED__ */