LTI-Lib latest version v1.9 - last update 10 Apr 2010

ltiDataCodec.h

00001 /*
00002  * Copyright (C) 2002, 2003, 2004, 2005, 2006
00003  * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany
00004  *
00005  * This file is part of the LTI-Computer Vision Library (LTI-Lib)
00006  *
00007  * The LTI-Lib is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public License (LGPL)
00009  * as published by the Free Software Foundation; either version 2.1 of
00010  * the License, or (at your option) any later version.
00011  *
00012  * The LTI-Lib is distributed in the hope that it will be
00013  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
00014  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with the LTI-Lib; see the file LICENSE.  If
00019  * not, write to the Free Software Foundation, Inc., 59 Temple Place -
00020  * Suite 330, Boston, MA 02111-1307, USA.
00021  */
00022 
00023 
00024 /*--------------------------------------------------------------------
00025  * project ....: LTI-Lib: Image Processing and Computer Vision Library
00026  * file .......: ltiDataTransformer.h
00027  * authors ....: Jochen Wickel
00028  * organization: LTI, RWTH Aachen
00029  * creation ...: 5.11.2002
00030  * revisions ..: $Id: ltiDataCodec.h,v 1.8 2006/02/08 12:02:39 ltilib Exp $
00031  */
00032 
00033 #ifndef _LTI_DATA_CODEC_H_
00034 #define _LTI_DATA_CODEC_H_
00035 
00036 #include "ltiDataTransformer.h"
00037 
00038 namespace lti {
00039   /**
00040    * This is the base class for data encoding and decoding.
00041    * This an abstract class.
00042    */
00043   class dataCodec : public dataTransformer {
00044   public:
00045     /**
00046      * The parameters for the class dataTransformer.
00047      */
00048     class parameters : public dataTransformer::parameters {
00049     public:
00050       /**
00051        * default constructor
00052        */
00053       parameters();
00054 
00055       /**
00056        * copy constructor
00057        * @param other the parameters object to be copied
00058        */
00059       parameters(const parameters& other);
00060 
00061       /**
00062        * destructor
00063        */
00064       ~parameters();
00065 
00066       /**
00067        * returns name of this type
00068        */
00069       const char* getTypeName() const;
00070 
00071       /**
00072        * copy the contents of a parameters object
00073        * @param other the parameters object to be copied
00074        * @return a reference to this parameters object
00075        */
00076       parameters& copy(const parameters& other);
00077 
00078       /**
00079        * copy the contents of a parameters object
00080        * @param other the parameters object to be copied
00081        * @return a reference to this parameters object
00082        */
00083       parameters& operator=(const parameters& other);
00084 
00085 
00086       /**
00087        * returns a pointer to a clone of the parameters
00088        */
00089       virtual functor::parameters* clone() const;
00090 
00091       /**
00092        * write the parameters in the given ioHandler
00093        * @param handler the ioHandler to be used
00094        * @param complete if true (the default) the enclosing begin/end will
00095        *        be also written, otherwise only the data block will be written.
00096        * @return true if write was successful
00097        */
00098       virtual bool write(ioHandler& handler,const bool complete=true) const;
00099 
00100       /**
00101        * read the parameters from the given ioHandler
00102        * @param handler the ioHandler to be used
00103        * @param complete if true (the default) the enclosing begin/end will
00104        *        be also written, otherwise only the data block will be written.
00105        * @return true if write was successful
00106        */
00107       virtual bool read(ioHandler& handler,const bool complete=true);
00108 
00109 #     ifdef _LTI_MSC_6
00110       /**
00111        * this function is required by MSVC only, as a workaround for a
00112        * very awful bug, which exists since MSVC V.4.0, and still by
00113        * V.6.0 with all bugfixes (so called "service packs") remains
00114        * there...  This method is also public due to another bug, so please
00115        * NEVER EVER call this method directly: use read() instead
00116        */
00117       bool readMS(ioHandler& handler,const bool complete=true);
00118 
00119       /**
00120        * this function is required by MSVC only, as a workaround for a
00121        * very awful bug, which exists since MSVC V.4.0, and still by
00122        * V.6.0 with all bugfixes (so called "service packs") remains
00123        * there...  This method is also public due to another bug, so please
00124        * NEVER EVER call this method directly: use write() instead
00125        */
00126       bool writeMS(ioHandler& handler,const bool complete=true) const;
00127 #     endif
00128 
00129       // ------------------------------------------------
00130       // the parameters
00131       // ------------------------------------------------
00132 
00133       //TODO: comment the parameters of your functor
00134       // If you add more parameters manually, do not forget to do following:
00135       // 1. indicate in the default constructor the default values
00136       // 2. make sure that the copy member also copy your new parameters
00137       // 3. make sure that the read and write members also read and
00138       //    write your parameters
00139 
00140       typedef enum {
00141         encode,
00142         decode
00143       } codingDirection;
00144 
00145       /**
00146        * The direction of the coding.
00147        */
00148       codingDirection direction;
00149 
00150       /**
00151        * If true, causes the encoding method to conclude the data block
00152        * with an end-of-data marker, whose value depends on the actual coding
00153        * method. This parameter is not implemented at present.
00154        */
00155       bool useEOD;
00156 
00157     };
00158 
00159     /**
00160      * default constructor
00161      */
00162     dataCodec();
00163 
00164     /**
00165      * Construct a functor using the given parameters
00166      */
00167     dataCodec(const parameters& par);
00168 
00169     /**
00170      * copy constructor
00171      * @param other the object to be copied
00172      */
00173     dataCodec(const dataCodec& other);
00174 
00175     /**
00176      * destructor
00177      */
00178     virtual ~dataCodec();
00179 
00180     /**
00181      * returns the name of this type ("dataCodec")
00182      */
00183     virtual const char* getTypeName() const;
00184 
00185     //TODO: comment the attributes of your functor
00186     // If you add more attributes manually, do not forget to do following:
00187     // 1. indicate in the default constructor the default values
00188     // 2. make sure that the copy member also copy your new attributes, or
00189     //    to ensure there, that these attributes are properly initialized.
00190 
00191 
00192     /**
00193      * Encodes data in place.
00194      */
00195     virtual bool encode(bufferElement* srcdest, int nsrc, int& ndest) const;
00196 
00197     /**
00198      * Encodes data in place.
00199      */
00200     virtual bool encode(buffer& srcdest) const;
00201 
00202     /**
00203      * Encodes data on copy.
00204      */
00205     virtual bool encode(const bufferElement* src, int nsrc, bufferElement* dest, int& ndest) const;
00206 
00207     /**
00208      * Encodes data on copy.
00209      */
00210     virtual bool encode(const buffer& src, buffer& dest) const;
00211 
00212 
00213     /**
00214      * Decodes data in place.
00215      */
00216     virtual bool decode(bufferElement* srcdest, int nsrc, int& ndest) const;
00217 
00218     /**
00219      * Decodes data in place.
00220      */
00221     virtual bool decode(buffer& srcdest) const;
00222 
00223     /**
00224      * Decodes data on copy.
00225      */
00226     virtual bool decode(const bufferElement* src, int nsrc, bufferElement* dest, int& ndest) const;
00227 
00228     /**
00229      * Decodes data on copy.
00230      */
00231     virtual bool decode(const buffer& src, buffer& dest) const;
00232 
00233 
00234     /**
00235      * Operates on the given arguments. If the data is encoded or
00236      * decoded depends on the coding direction parameter.
00237      * @param srcdest pointer to an array of bufferElement. The input
00238      *        array must be allocated and have enough space for
00239      *        input as well as output data.
00240      * @param nsrc the number of input bytes that should be transformed.
00241      * @param ndest the number of bytes of the transformed data. If the
00242      *        buffer was too small, it will contain -1 when the function
00243      *        returns.
00244      * @return true if apply successful or false otherwise.
00245      */
00246     virtual bool apply(bufferElement* srcdest, int nsrc, int& ndest) const;
00247 
00248     /**
00249      * Operates on the given argument. If the data is encoded or
00250      * decoded depends on the coding direction parameter.
00251      * @param srcdest vector with the input data which will
00252      *        also receive the transformed data.
00253      * @return true if apply successful or false otherwise.
00254      */
00255     virtual bool apply(buffer& srcdest) const;
00256 
00257     /**
00258      * Operates on a copy of the given arguments.
00259      * @param src pointer to an array of bufferElement which contains the
00260      *            source data
00261      * @param nsrc the number of input bytes that should be transformed.
00262      * @param dest pointer to an array of bufferElement which will receive
00263      *             the transformed data. The array must be allocated
00264      *             by the caller
00265      * @param ndest When called, must contain the size of the output
00266      *              buffer. When the function returns, it contains the
00267      *              number of bytes actually used, or -1 if the buffer
00268      *              was too small.
00269      *
00270      * @return true if apply successful or false otherwise.
00271      */
00272     virtual bool apply(const bufferElement* src, int nsrc, bufferElement* dest, int& ndest) const;
00273 
00274     /**
00275      * Operates on the given argument.
00276      * @param src vector with the input data
00277      * @param dest vector with the encoded or decoded data
00278      * @return true if apply successful or false otherwise.
00279      */
00280     virtual bool apply(const buffer& src, buffer& dest) const;
00281 
00282     /**
00283      * returns used parameters
00284      */
00285     const parameters& getParameters() const;
00286 
00287     /**
00288      * Copy another dataCodec
00289      */
00290     dataCodec& copy(const dataCodec& other);
00291 
00292     /**
00293      * Copy another dataCodec
00294      */
00295     dataCodec& operator=(const dataCodec& other);
00296 
00297   protected:
00298     /**
00299      * Implementation of on-copy data decoder. <b>This method
00300      * must not, under no circumstances, resize the destination vector.</b>
00301      * @return true if the decoding could be performed successfully.
00302      * @param src the source of the data.
00303      * @param dest the destination for the decoded data.
00304      * @param nsrc tells how many elements of the src vector
00305      *        must be decoded.
00306      * @param ndest tells how many elements of the destination vector
00307      *        can be used for the decoded data.
00308      *        When the method returns,
00309      *        this value tells how many elements were actually used,
00310      *        or notEnoughSpace if not enough elements were available.
00311      */
00312     virtual bool decodeImplementation(const buffer& src,
00313                                       buffer& dest,
00314                                       int nsrc, int& ndest) const=0;
00315 
00316     /**
00317      * Implementation of on-copy data encoder. <b>This method
00318      * must not, under no circumstances, resize the destination vector.</b>
00319      * @return true if the decoding could be performed successfully.
00320      * @param src the source of the data.
00321      * @param dest the destination for the encoded data.
00322      * @param nsrc tells how many elements of the src vector
00323      *        must be decoded.
00324      * @param ndest tells how many elements of the destination vector
00325      *        can be used for the decoded data.
00326      *        When the method returns,
00327      *        this value tells how many elements were actually used,
00328      *        or notEnoughSpace if not enough elements were available.
00329      */
00330     virtual bool encodeImplementation(const buffer& src,
00331                                       buffer& dest,
00332                                       int nsrc, int& ndest) const=0;
00333 
00334 
00335   public:
00336     /**
00337      * Computes the default buffer size for encoded data. The
00338      * source of the original data buffer is given as argument.
00339      * The default is to return the given value.
00340      * @param originalSize the size of the data buffer to be encoded
00341      * @return the estimated size of the encoded data.
00342      */
00343     virtual int estimateEncodedSize(int originalSize) const;
00344 
00345     /**
00346      * Computes the default buffer size for decoded data. The
00347      * source of the encoded data buffer is given as argument.
00348      * The default is to return the given value.
00349      * @param encodedSize the size of the data buffer to be decoded
00350      * @return the estimated size of the decoded data.
00351      */
00352     virtual int estimateDecodedSize(int encodedSize) const;
00353 
00354   protected:
00355     /**
00356      * Computes a new reasonable buffer size for encoded data
00357      * if the given buffer size is too small. The default is
00358      * 2*orginialSize;
00359      * @param originalSize the size of the data buffer
00360      * @return the recommended new size of the data buffer
00361      */
00362     virtual int getNewEncodingBufferSize(int originalSize) const;
00363 
00364     /**
00365      * Computes a new reasonable buffer size for encoded data
00366      * if the given buffer size is too small. The default is
00367      * 2*orginialSize;
00368      * @param originalSize the size of the data buffer
00369      * @return the recommended new size of the data buffer
00370      */
00371     virtual int getNewDecodingBufferSize(int originalSize) const;
00372 
00373   };
00374 }
00375 
00376 #endif

Generated on Sat Apr 10 15:25:20 2010 for LTI-Lib by Doxygen 1.6.1