Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

ReadBuffer.hpp

Go to the documentation of this file.
00001 /*==========================================================================
00002  * Copyright (c) 2003 University of Massachusetts.  All Rights Reserved.
00003  *
00004  * Use of the Lemur Toolkit for Language Modeling and Information Retrieval
00005  * is subject to the terms of the software license set forth in the LICENSE
00006  * file included with this software, and also available at
00007  * http://www.lemurproject.org/license.html
00008  *
00009  *==========================================================================
00010 */
00011 
00012 
00013 //
00014 // ReadBuffer
00015 //
00016 // tds - 13 November 2003
00017 //
00018 
00019 #ifndef LEMUR_READBUFFER_HPP
00020 #define LEMUR_READBUFFER_HPP
00021 
00022 #include "File.hpp"
00023 
00024 class ReadBuffer {
00025 private:
00026   File::offset_type _filePosition;
00027   char* _buffer;
00028   File& _file;
00029   size_t _bufferSize;
00030   size_t _bufferPosition;
00031   size_t _bufferDataLength;
00032   bool _gValid;
00033   bool _exclusiveAccess;
00034 
00035 public:
00036   // wrap <file> in a ReadBuffer with initial
00037   // buffer size <bufferSize>.  The buffer
00038   // may grow if necessary to support large
00039   // peek() and read() requests.
00040   // <exclusiveAccess> = true if the ReadBuffer is 
00041   // the only user of the underlying file, false otherwise.
00042   ReadBuffer( File& file, size_t bufferSize, bool exclusiveAccess = true );
00043   ~ReadBuffer();
00044 
00045   // standard read() semantics; will perform
00046   // an unbuffered read if the read size is
00047   // large enough
00048   void read( char* data, size_t length );
00049 
00050   // return a pointer to a buffer containing 
00051   // the next <length> bytes, but do not advance
00052   // the read pointer
00053   const char* peek( size_t length );
00054 
00055   // return a pointer to a buffer containing 
00056   // the next <length> bytes, and advance
00057   // the read pointer
00058   const char* read( size_t length );
00059 
00060   // move the internal read pointer
00061   // to <position>, which may be relative to the
00062   // beginning, end or current position of the file
00063   // as specified by <direction>.
00064   void seekg( File::offset_type position, std::fstream::seekdir direction );
00065 
00066   // return the read pointer location with
00067   // reference to the beginning of the file
00068   File::offset_type tellg();
00069 
00070   // return the current read state bits,
00071   // eofbit, badbit, etc. (same
00072   // semantics as std::ifstream::rdstate())
00073   int rdstate();
00074 
00075   // marks the underlying stream pointer
00076   // as invalid--call this if you seek
00077   // the underlying file to a new location
00078   void invalidateg();
00079 };
00080 
00081 #endif // LEMUR_READBUFFER_HPP

Generated on Wed Nov 3 12:59:03 2004 for Lemur Toolkit by doxygen1.2.18