Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

AbstractPbmPlusFile.H

Go to the documentation of this file.
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 __ABSTRACTPBMPLUS_H_INCLUDED__
00029 #define __ABSTRACTPBMPLUS_H_INCLUDED__
00030 
00031 
00032 /**
00033  * @file   AbstractPbmPlusFile.H
00034  * @brief  Header file of class qgar::AbstractPbmPlusFile.
00035  *
00036  * @author <a href="mailto:qgar-develop@loria.fr?subject=Qgar fwd Karl Tombre">Karl Tombre</a>
00037  * @date   Jul, 3  2001  16:25
00038  * @since  Qgar 1.0
00039  */
00040 
00041 // For RCS/CVS use: Do not delete
00042 /* $Id: AbstractPbmPlusFile.H,v 1.12 2005/07/13 16:29:00 masini Exp $ */
00043 
00044 
00045 
00046 // QGAR
00047 #include <qgarlib/AbstractFile.H>
00048 #include <qgarlib/QgarErrorInvalidArg.H>
00049 #include <qgarlib/QgarErrorIO.H>
00050 
00051 
00052 
00053 namespace qgar
00054 {
00055 
00056 
00057 // TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
00058 // TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
00059 // T Y P E S   R E L A T E D   T O   P B M   F I L E S
00060 // TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
00061 // TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
00062 
00063 
00064 /**
00065  * @name Types related to PBM files
00066  * @ingroup IO_FILE
00067  */
00068 //@{
00069 
00070 /**
00071  * @brief PBM+ file formats.
00072  */
00073 enum QGEpbmFormat
00074 {
00075 QGE_PBM_PLAIN,
00076 QGE_PBM_RAW
00077 };
00078 
00079 //@}
00080 
00081 
00082 // TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
00083 // TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
00084 
00085 
00086 
00087 
00088 
00089 /**
00090  * @class AbstractPbmPlusFile AbstractPbmPlusFile.H "qgarlib/AbstractPbmPlusFile.H"
00091  * @ingroup IO_FILE
00092  *
00093  * @brief File containing an image in some PBM+ format.
00094  * 
00095  * Most of the code documented here is an adaptation of code from the PBM
00096  * software package. Here is the copyright notice of this package:
00097 @verbatim
00098  +------------------------------------------------------------------------+
00099  | Copyright (C) 1988 by Jef Poskanzer                                    |
00100  |                                                                        |
00101  | Permission to use, copy, modify, and distribute this software and its  |
00102  | documentation for any purpose and without fee is hereby granted,       |
00103  | provided that the above copyright notice appear in all copies and that |
00104  | both that copyright notice and this permission notice appear in        |
00105  | supporting documentation.  This software is provided "as is" without   |
00106  | express or implied warranty.                                           |
00107  +------------------------------------------------------------------------+
00108 @endverbatim
00109  *  For more information about PBM, see the
00110  *  <a href="http://www.bath.ac.uk/BUCS/Software/graphics/pbm/pbm.html">PBMPLUS home page</a>.
00111  *
00112  * @warning This is an abstract class.
00113  * Pure virtual functions:
00114  * - qgar::AbstractPbmPlusFile::readRow
00115  * - qgar::AbstractPbmPlusFile::writeRow
00116  *
00117  * @author <a href="mailto:qgar-develop@loria.fr?subject=Qgar fwd Karl Tombre">Karl Tombre</a>
00118  * @date   Jul, 3  2001  16:25
00119  * @since  Qgar 1.0
00120  */
00121 class AbstractPbmPlusFile
00122 
00123   : public AbstractFile
00124 
00125 {
00126 // -------------------------------------------------------------------
00127 // P U B L I C    M E M B E R S
00128 // -------------------------------------------------------------------
00129 public:
00130 
00131   /** @name Destructor */
00132   //        ==========
00133   //@{
00134 
00135   /**
00136    * @brief Free the current row.
00137    */
00138   virtual ~AbstractPbmPlusFile();
00139 
00140   //@}
00141 
00142 
00143   /** @name Access */
00144   //        ======
00145   //@{
00146 
00147   /**
00148    * @brief Get number of columns.
00149    */
00150   inline int colCnt() const;
00151 
00152   /**
00153    * @brief Get number of rows.
00154    */
00155   inline int rowCnt() const;
00156 
00157   /**
00158    * @brief Get current row.
00159    */
00160   inline unsigned char* pRow();
00161 
00162   //@}
00163 
00164 
00165   /** @name Assignment */
00166   //        ==========
00167   //@{
00168 
00169   /**
00170    * @brief Set number of columns.
00171    *
00172    * @param aCnt  number to set
00173    */
00174   inline void setColCnt(int aCnt);
00175 
00176   /**
00177    * @brief Set number of rows.
00178    *
00179    * @param aCnt  number to set
00180    */
00181   inline void setRowCnt(int aCnt);
00182 
00183   //@}
00184 
00185 
00186   /** @name Input */
00187   //        =====
00188   //@{
00189 
00190   /**
00191    * @brief Read a row from the file.
00192    */
00193   virtual void readRow() = 0;
00194 
00195   //@}
00196 
00197 
00198   /** @name Output */
00199   //        ======
00200   //@{
00201 
00202   /**
00203    * @brief Write a row into the file.
00204    */
00205   virtual void writeRow() = 0;
00206 
00207   //@}
00208 
00209 // -------------------------------------------------------------------
00210 // P R O T E C T E D    M E M B E R S
00211 // -------------------------------------------------------------------
00212 protected:
00213 
00214   //  ============================================
00215   /** @name Constructors
00216       Constructors belong to the protected section
00217       so that the class cannot be instantiated.
00218    */
00219   //  ============================================
00220   //@{
00221 
00222   /**
00223    * @brief Initialize with full data.
00224    *
00225    * @param aFileName name of the new file
00226    * @param aRowCnt    number of rows of the corresponding image
00227    * @param aColCnt    number of columns of the corresponding image
00228    * @param aFormat   format of the image contained in the file (default raw)
00229    *
00230    * @exception qgar::QgarErrorInvalidArg (bad image size)
00231    */
00232   AbstractPbmPlusFile(const char*  aFileName,
00233                       int          aRowCnt,
00234                       int          aColCnt,
00235                       QGEpbmFormat aFormat = QGE_PBM_RAW)
00236     throw(QgarErrorInvalidArg);
00237 
00238   //@}
00239 
00240 
00241   /** @name Representation of a file */
00242   //        ========================
00243   //@{
00244 
00245   /**
00246    * @brief Format of the file.
00247    */
00248   QGEpbmFormat _format;
00249 
00250   /**
00251    * @brief Number of rows of the image.
00252    */
00253   int _rowCnt;
00254 
00255   /**
00256    * @brief Number of columns of the image.
00257    */
00258   int _colCnt;
00259 
00260   /**
00261    * @brief Pointer to current image row.
00262    */
00263   unsigned char* _pRow;
00264 
00265   //@}
00266 
00267 
00268   /** @name Input auxiliaries */
00269   //        =================
00270   //@{
00271 
00272   /**
00273    * @brief Read a character from the file. 
00274    *
00275    * @exception qgar::QgarErrorIO (EOF while reading in file)
00276   */
00277   virtual char getChar() throw(QgarErrorIO);
00278 
00279   /**
00280    * @brief Read an integer from the file. 
00281    *
00282    * @exception qgar::QgarErrorIO
00283    * (error while reading in file: integer in [0,9] expected)
00284    */
00285   virtual int getInt() throw(QgarErrorIO);
00286 
00287   /**
00288    * @brief Read a raw byte from the file. 
00289    *
00290    *  @exception qgar::QgarErrorIO (EOF while reading in file)
00291    */
00292   virtual unsigned char getRawByte() throw(QgarErrorIO);
00293 
00294   //@}
00295 
00296 
00297   /** @name Memory space allocation */
00298   //        =======================
00299   //@{
00300 
00301   /**
00302    * @brief Allocate a new row.
00303    */
00304   void newRow();
00305 
00306   //@}
00307 
00308 // -------------------------------------------------------------------
00309 }; // class AbstractPbmPlusFile
00310 
00311 
00312 
00313 
00314 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00315 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00316 // I N L I N E   F U N C T I O N S   I M P L E M E N T A T I O N 
00317 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00318 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00319 
00320 
00321 // ======
00322 // ACCESS
00323 // ======
00324 
00325 // GET NUMBER OF COLUMNS
00326 
00327 inline int
00328 AbstractPbmPlusFile::colCnt() const
00329 {
00330   return _colCnt;
00331 }
00332 
00333 
00334 // GET NUMBER OF ROWS
00335 
00336 inline int
00337 AbstractPbmPlusFile::rowCnt() const
00338 {
00339   return _rowCnt;
00340 }
00341 
00342 
00343 // GET CURRENT ROW
00344 
00345 inline unsigned char*
00346 AbstractPbmPlusFile::pRow()
00347 {
00348   return _pRow;
00349 }
00350 
00351 
00352 // ==========
00353 // ASSIGNMENT
00354 // ==========
00355 
00356 
00357 // SET NUMBER OF COLUMNS
00358 
00359 inline void
00360 AbstractPbmPlusFile::setColCnt(int aCnt)
00361 {
00362   _colCnt = aCnt;
00363 }
00364 
00365 
00366 // SET NUMBER OF ROWS
00367 
00368 inline void
00369 AbstractPbmPlusFile::setRowCnt(int aCnt)
00370 {
00371   _rowCnt = aCnt;
00372 }
00373 
00374 
00375 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00376 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00377 
00378 
00379 } // namespace qgar
00380 
00381 
00382 #endif /* __ABSTRACTPBMPLUS_H_INCLUDED__ */