Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

WriteBuffer.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 // WriteBuffer
00015 //
00016 // tds - 13 November 2003
00017 //
00018 
00019 #ifndef LEMUR_WRITEBUFFER_HPP
00020 #define LEMUR_WRITEBUFFER_HPP
00021 
00022 #include "File.hpp"
00023 namespace lemur 
00024 {
00025   namespace file 
00026   {
00027     
00028     class WriteBuffer {
00029     private:
00030       char* _buffer;
00031       size_t _bufferSize;
00032       File& _file;
00033       size_t _position;
00034       File::offset_type _filePos;
00035       bool _exclusiveAccess;
00036 
00037     public:
00038       // <exclusiveAccess> = true if the WriteBuffer is 
00039       // the only user of the underlying file, false otherwise.
00040       WriteBuffer( File& file, size_t bufferSize, bool exclusiveAccess = true  );
00041       ~WriteBuffer();
00042 
00043       // gives a memory pointer to the next <length>
00044       // bytes in the file.
00045       char* write( size_t length );
00046 
00047       // tells the WriteBuffer that <length> bytes
00048       // of the last write(size_t) call were not used
00049       // and should be returned as a part of the
00050       // next write(size_t) call.  This function cannot
00051       // be used in conjunction with the write(char*, size_t)
00052       // call.
00053       void unwrite( size_t length );
00054   
00055       // standard write semantics; will
00056       // perform an unbuffered write if
00057       // <length> is long enough to warrant it
00058       void write( const char* data, size_t length );
00059 
00060       // flushes the internal buffer out to 
00061       // the ofstream. does not explicitly
00062       // flush the ofstream.
00063       void flush();
00064 
00065       // returns the current write pointer
00066       // position
00067       File::offset_type tellp() ;
00068     };
00069   }
00070 }
00071 
00072 #endif // LEMUR_WRITEBUFFER_HPP

Generated on Tue Jun 15 11:02:56 2010 for Lemur by doxygen 1.3.4