"Fossies" - the Fresh Open Source Software Archive

Member "qdiff-0.9.1/trotfile.h" (21 Oct 2008, 2321 Bytes) of package /linux/privat/old/qdiff-0.9.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /*GPL*START*
    2  * 
    3  * Copyright (C) 1998 by Johannes Overmann <overmann@iname.com>
    4  * Copyright (C) 2008 by Tong Sun <suntong001@users.sourceforge.net>
    5  * 
    6  * This program is free software; you can redistribute it and/or modify
    7  * it under the terms of the GNU General Public License as published by
    8  * the Free Software Foundation; either version 2 of the License, or
    9  * (at your option) any later version.
   10  * 
   11  * This program is distributed in the hope that it will be useful,
   12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14  * GNU General Public License for more details.
   15  * 
   16  * You should have received a copy of the GNU General Public License along
   17  * with this program; if not, write to the Free Software Foundation, Inc.,
   18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
   19  * *GPL*END*/  
   20 
   21 #ifndef _trotfile_h_
   22 #define _trotfile_h_
   23 
   24 #include "terror.h"
   25 #include "ttypes.h"
   26 #include "tstring.h"
   27 
   28 class TROTFile {
   29  public:
   30    // ctor & dtor
   31    TROTFile(const char *fname, int numbuf, int bufsize);
   32    ~TROTFile();
   33 
   34    // readonly access
   35    uchar operator[] (int i);
   36    int size() const {return _size;}
   37    const char *name() const {return fname.data();};
   38    
   39  private:
   40    // internal buffer
   41    int numbuf;   // number of buffer
   42    int bufsize;  // size of buffer
   43    int bufbits;  // bits of buffer size
   44    int bufmask;  // address mask for buffer (in)
   45    int nummask;  // address mask for buffer (which)
   46    int offmask;  // address mask for offset
   47    int *off;     // offset of buffer
   48    uchar **buf;  // buffer
   49    
   50    // real file
   51    int _size;    // size of file
   52    tstring fname; // filename
   53    FILE *file;   // open file
   54    
   55    // private methods
   56    void loadBuf(int offset, int buffer);
   57    int intLog2(int i) const;
   58    bool isPowerOf2(int i) const;
   59    
   60    // forbid copy
   61    TROTFile(const TROTFile& a);
   62    const TROTFile& operator=(const TROTFile& a);
   63 };
   64 
   65 inline uchar TROTFile::operator[] (int i) {
   66    if(((uint)i) < ((uint)_size)) {
   67       int offset = i&offmask;
   68       int buffer = (i >> bufbits) & nummask;
   69       if(offset!=off[buffer]) loadBuf(offset, buffer);
   70       return buf[buffer][i & bufmask];
   71    } else 
   72      fatalError("operator[]: index out of range! (%d not in [0..%d])\n", 
   73         i, _size-1);
   74 }
   75 
   76 #endif
   77 
   78 
   79 
   80 
   81