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

RVLDecompressStream.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 #ifndef INDRI_RVLDECOMPRESSSTREAM_HPP
00013 #define INDRI_RVLDECOMPRESSSTREAM_HPP
00014 namespace indri
00015 {
00016   namespace utility
00017   {
00018     
00021     class RVLDecompressStream {
00022     private:
00023       const char* _buffer;
00024       int _bufferSize;
00025       const char* _current;
00026 
00027     public:
00031       RVLDecompressStream( const char* buffer, int size ) {
00032         _buffer = buffer;
00033         _bufferSize = size;
00034         _current = buffer;
00035       }
00036 
00040       void setBuffer( const char* buffer, int size ) {
00041         _buffer = buffer;
00042         _bufferSize = size;
00043         _current = buffer;
00044       }
00045 
00048       RVLDecompressStream& operator>> ( INT64& value ) {
00049         _current = lemur::utility::RVLCompress::decompress_longlong( _current, value );
00050         assert( _current - _buffer <= _bufferSize );
00051         return *this;
00052       }
00053 
00056       RVLDecompressStream& operator>> ( UINT64& value ) {
00057         _current = lemur::utility::RVLCompress::decompress_longlong( _current, value );
00058         assert( _current - _buffer <= _bufferSize );
00059         return *this;
00060       }
00061 
00064       RVLDecompressStream& operator>> ( int& value ) {
00065         _current = lemur::utility::RVLCompress::decompress_int( _current, value );
00066         assert( _current - _buffer <= _bufferSize );    
00067         return *this;
00068       }
00069 
00072       RVLDecompressStream& operator>> ( unsigned int& value ) {
00073         int v;
00074         _current = lemur::utility::RVLCompress::decompress_int( _current, v );
00075         value = (unsigned int) v;
00076         assert( _current - _buffer <= _bufferSize );    
00077         return *this;
00078       }
00079 
00082       RVLDecompressStream& operator>> ( float& value ) {
00083         // doubles aren't compressed
00084         memcpy( &value, _current, sizeof value );
00085         _current += sizeof value;
00086         return *this;
00087       }
00088 
00091       RVLDecompressStream& operator>> ( char* value ) {
00092         int length;
00093         _current = lemur::utility::RVLCompress::decompress_int( _current, length );
00094         ::memcpy( value, _current, length );
00095         value[length] = 0;
00096         _current += length;
00097         return *this;
00098       }
00099 
00100 
00102       bool done() const {
00103         return (_current - _buffer) >= _bufferSize;
00104       }
00105     };
00106   }
00107 }
00108 
00109 #endif // INDRI_RVLDECOMPRESSSTREAM_HPP

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