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

RVLCompressStream.hpp

Go to the documentation of this file.
00001 /*==========================================================================
00002  * Copyright (c) 2004 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 // RVLCompressStream
00015 //
00016 // 9 February 2004 -- tds
00017 //
00018 
00019 #ifndef INDRI_RVLCOMPRESSSTREAM_HPP
00020 #define INDRI_RVLCOMPRESSSTREAM_HPP
00021 
00022 #include "RVLCompress.hpp"
00023 #include "indri/Buffer.hpp"
00024 namespace indri
00025 {
00026   namespace utility
00027   {
00028     
00031     class RVLCompressStream {
00032     private:
00033       indri::utility::Buffer& _buffer;
00034 
00035     public:
00038       RVLCompressStream( indri::utility::Buffer& buffer ) :
00039         _buffer(buffer)
00040       {
00041       }
00042 
00044       const char* data() const {
00045         return _buffer.front();
00046       }
00048       size_t dataSize() const {
00049         return _buffer.position();
00050       }
00051 
00054       RVLCompressStream& operator<< ( int value ) {
00055         char* writePosition = _buffer.write(5);
00056         char* endPosition = lemur::utility::RVLCompress::compress_int( writePosition, value );
00057         _buffer.unwrite( 5 - (endPosition - writePosition) );
00058         return *this;
00059       }
00060 
00063       RVLCompressStream& operator<< ( unsigned int value ) {
00064         char* writePosition = _buffer.write(5);
00065         char* endPosition = lemur::utility::RVLCompress::compress_int( writePosition, value );
00066         _buffer.unwrite( 5 - (endPosition - writePosition) );
00067         return *this;
00068       }
00069 
00072       RVLCompressStream& operator<< ( INT64 value ) {
00073         char* writePosition = _buffer.write(10);
00074         char* endPosition = lemur::utility::RVLCompress::compress_longlong( writePosition, value );
00075         _buffer.unwrite( 10 - (endPosition - writePosition) );
00076         return *this;
00077       }
00078 
00081       RVLCompressStream& operator<< ( UINT64 value ) {
00082         char* writePosition = _buffer.write(10);
00083         char* endPosition = lemur::utility::RVLCompress::compress_longlong( writePosition, value );
00084         _buffer.unwrite( 10 - (endPosition - writePosition) );
00085         return *this;
00086       }
00087 
00090       RVLCompressStream& operator << ( float value ) {
00091         // can't compress a float, unfortunately
00092         memcpy( _buffer.write(sizeof(float)), &value, sizeof value );
00093         return *this;
00094       }
00095 
00097       RVLCompressStream& operator << ( const char* value ) {
00098         unsigned int length = (unsigned int) strlen( value );
00099         (*this) << length;
00100         memcpy( _buffer.write(length), value, length );
00101         return *this;
00102       }
00103     };
00104   }
00105 }
00106 
00107 #endif // INDRI_RVLCOMPRESSSTREAM_HPP
00108 

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