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 00024 class WriteBuffer { 00025 private: 00026 char* _buffer; 00027 size_t _bufferSize; 00028 File& _file; 00029 size_t _position; 00030 File::offset_type _filePos; 00031 00032 public: 00033 WriteBuffer( File& file, size_t bufferSize ); 00034 ~WriteBuffer(); 00035 00036 // gives a memory pointer to the next <length> 00037 // bytes in the file. 00038 char* write( size_t length ); 00039 00040 // tells the WriteBuffer that <length> bytes 00041 // of the last write(size_t) call were not used 00042 // and should be returned as a part of the 00043 // next write(size_t) call. This function cannot 00044 // be used in conjunction with the write(char*, size_t) 00045 // call. 00046 void unwrite( size_t length ); 00047 00048 // standard write semantics; will 00049 // perform an unbuffered write if 00050 // <length> is long enough to warrant it 00051 void write( const char* data, size_t length ); 00052 00053 // flushes the internal buffer out to 00054 // the ofstream. does not explicitly 00055 // flush the ofstream. 00056 void flush(); 00057 00058 // returns the current write pointer 00059 // position 00060 File::offset_type tellp() const; 00061 }; 00062 00063 #endif // LEMUR_WRITEBUFFER_HPP