Visualization Library 2.1.0

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
vl::GZipCodec Class Reference

The GZipCodec class is a VirtualFile that transparently encodes and decodes a stream of data using the GZip compression algorithm. More...

#include <GZipCodec.hpp>

+ Inheritance diagram for vl::GZipCodec:

Public Member Functions

 GZipCodec (VirtualFile *stream=NULL)
 Constructor. More...
 
 GZipCodec (const String &gz_path)
 Constructor. More...
 
 ~GZipCodec ()
 Destructor. More...
 
virtual bool open (EOpenMode mode)
 Opens a compressed stream. More...
 
virtual bool isOpen () const
 Returns true if the file is open for read or writing. More...
 
virtual bool exists () const
 Returns true if the input or output stream file exists. More...
 
virtual void close ()
 Closes the GZipStream. More...
 
virtual long long size () const
 Returns the uncompressed size of the stream. This is not a thread safe function. More...
 
virtual ref< VirtualFileclone () const
 Returns an equivalent GZipCodec. More...
 
GZipCodecoperator= (const GZipCodec &other)
 
void setCompressionLevel (int level)
 Sets the compression level used during write operations. More...
 
int compressionLevel () const
 
void setStream (VirtualFile *stream)
 Installs the VirtualFile representing the GZip file to be read or to be written. More...
 
const VirtualFilestream () const
 Returns the VirtualFile representing the GZip file to be read or to be written. More...
 
VirtualFilestream ()
 Returns the VirtualFile representing the GZip file to be read or to be written. More...
 
long long uncompressedSize ()
 Returns the uncompressed size of the stream. More...
 
long long compressedSize () const
 Returns the size of the compressed stream as returned by stream()->size(). More...
 
float compressionRatio () const
 Returns the compression ratio computed as compressedsize/uncompressedsize. More...
 
bool warnOnSeek () const
 
void setWarnOnSeek (bool warn_on)
 
- Public Member Functions inherited from vl::VirtualFile
 VirtualFile ()
 Constructor. More...
 
unsigned int crc32 ()
 Computes the crc32 of the entire file. More...
 
MD5CheckSum md5 ()
 Computes the md5 of the entire file. More...
 
VirtualFileoperator= (const VirtualFile &other)
 
const Stringpath () const
 Returns the path of the file. More...
 
void setPath (const String &name)
 Changes the path bound to a VirtualFile. Use carefully this function, you shouldn't rename a VirtualFile managed by a VirtualDirectory. More...
 
long long peek (void *buffer, long long byte_count)
 Reads byte_count bytes and returns to the original position. More...
 
long long read (void *buffer, long long byte_count)
 Reads byte_count bytes from a file. Returns the number of bytes actually read. More...
 
long long write (const void *buffer, long long byte_count)
 Writes byte_count bytes to a file. Returns the number of bytes actually written. More...
 
long long position () const
 Returns the current position in the file. More...
 
bool seekSet (long long offset)
 Changes the current read/write position of a file. More...
 
bool seekCur (long long offset)
 Changes the current read/write position of a file. More...
 
bool seekEnd (long long offset)
 Changes the current read/write position of a file. More...
 
bool endOfFile () const
 Returns true if position() >= size() More...
 
long long load (std::vector< char > &data)
 Loads the entire file in the specified vector. More...
 
long long load (void *buffer, long long max=-1)
 Loads the entire file in the specified buffer. More...
 
double readDouble (bool little_endian_data=true)
 Reads single entry. More...
 
float readFloat (bool little_endian_data=true)
 Reads single entry. More...
 
unsigned long long readUInt64 (bool little_endian_data=true)
 Reads single entry. More...
 
long long readSInt64 (bool little_endian_data=true)
 Reads single entry. More...
 
unsigned int readUInt32 (bool little_endian_data=true)
 Reads single entry. More...
 
int readSInt32 (bool little_endian_data=true)
 Reads single entry. More...
 
unsigned short readUInt16 (bool little_endian_data=true)
 Reads single entry. More...
 
short readSInt16 (bool little_endian_data=true)
 Reads single entry. More...
 
unsigned char readUInt8 ()
 Reads single entry. More...
 
char readSInt8 ()
 Reads single entry. More...
 
long long readDouble (double *buffer, long long count, bool little_endian_data=true)
 Reads multiple entries. Returns the number of bytes read. More...
 
long long readFloat (float *buffer, long long count, bool little_endian_data=true)
 Reads multiple entries. Returns the number of bytes read. More...
 
long long readUInt64 (unsigned long long *buffer, long long count, bool little_endian_data=true)
 Reads multiple entries. Returns the number of bytes read. More...
 
long long readSInt64 (long long *buffer, long long count, bool little_endian_data=true)
 Reads multiple entries. Returns the number of bytes read. More...
 
long long readUInt32 (unsigned int *buffer, long long count, bool little_endian_data=true)
 Reads multiple entries. Returns the number of bytes read. More...
 
long long readSInt32 (int *buffer, long long count, bool little_endian_data=true)
 Reads multiple entries. Returns the number of bytes read. More...
 
long long readUInt16 (unsigned short *buffer, long long count, bool little_endian_data=true)
 Reads multiple entries. Returns the number of bytes read. More...
 
long long readSInt16 (short *buffer, long long count, bool little_endian_data=true)
 Reads multiple entries. Returns the number of bytes read. More...
 
long long readUInt8 (unsigned char *buffer, long long count)
 Reads multiple entries. Returns the number of bytes read. More...
 
long long readSInt8 (char *buffer, long long count)
 Reads multiple entries. Returns the number of bytes read. More...
 
long long writeDouble (double data, bool little_endian_data=true)
 Writes a single entry. Returns the number of bytes written. More...
 
long long writeFloat (float data, bool little_endian_data=true)
 Writes a single entry. Returns the number of bytes written. More...
 
long long writeUInt64 (unsigned long long data, bool little_endian_data=true)
 Writes a single entry. Returns the number of bytes written. More...
 
long long writeSInt64 (long long data, bool little_endian_data=true)
 Writes a single entry. Returns the number of bytes written. More...
 
long long writeUInt32 (unsigned int data, bool little_endian_data=true)
 Writes a single entry. Returns the number of bytes written. More...
 
long long writeSInt32 (int data, bool little_endian_data=true)
 Writes a single entry. Returns the number of bytes written. More...
 
long long writeUInt16 (unsigned short data, bool little_endian_data=true)
 Writes a single entry. Returns the number of bytes written. More...
 
long long writeSInt16 (short data, bool little_endian_data=true)
 Writes a single entry. Returns the number of bytes written. More...
 
long long writeUInt8 (unsigned char data)
 Writes a single entry. Returns the number of bytes written. More...
 
long long writeSInt8 (char data)
 Writes a single entry. Returns the number of bytes written. More...
 
long long writeDouble (const double *buffer, long long count, bool little_endian_data=true)
 Writes multiple entries. Returns the number of bytes written. More...
 
long long writeFloat (const float *buffer, long long count, bool little_endian_data=true)
 Writes multiple entries. Returns the number of bytes written. More...
 
long long writeUInt64 (const unsigned long long *buffer, long long count, bool little_endian_data=true)
 Writes multiple entries. Returns the number of bytes written. More...
 
long long writeSInt64 (const long long *buffer, long long count, bool little_endian_data=true)
 Writes multiple entries. Returns the number of bytes written. More...
 
long long writeUInt32 (const unsigned int *buffer, long long count, bool little_endian_data=true)
 Writes multiple entries. Returns the number of bytes written. More...
 
long long writeSInt32 (const int *buffer, long long count, bool little_endian_data=true)
 Writes multiple entries. Returns the number of bytes written. More...
 
long long writeUInt16 (const unsigned short *buffer, long long count, bool little_endian_data=true)
 Writes multiple entries. Returns the number of bytes written. More...
 
long long writeSInt16 (const short *buffer, long long count, bool little_endian_data=true)
 Writes multiple entries. Returns the number of bytes written. More...
 
long long writeUInt8 (const unsigned char *buffer, long long count)
 Writes multiple entries. Returns the number of bytes written. More...
 
long long writeSInt8 (const char *buffer, long long count)
 Writes multiple entries. Returns the number of bytes written. More...
 
- Public Member Functions inherited from vl::Object
 Object ()
 Constructor. More...
 
 Object (const Object &other)
 Copy constructor: copies the name, ref count mutex and user data. More...
 
Objectoperator= (const Object &other)
 Copy operator: copies the object's name, ref count mutex and user data. More...
 
const std::string & objectName () const
 The name of the object, by default set to the object's class name. More...
 
void setObjectName (const char *name)
 The name of the object, by default set to the object's class name in debug builds. More...
 
void setObjectName (const std::string &name)
 The name of the object, by default set to the object's class name in debug builds. More...
 
void setRefCountMutex (IMutex *mutex)
 The mutex used to protect the reference counting of an Object across multiple threads. More...
 
IMutexrefCountMutex ()
 The mutex used to protect the reference counting of an Object across multiple threads. More...
 
const IMutexrefCountMutex () const
 The mutex used to protect the reference counting of an Object across multiple threads. More...
 
int referenceCount () const
 Returns the number of references of an object. More...
 
void incReference () const
 Increments the reference count of an object. More...
 
void decReference ()
 Decrements the reference count of an object and deletes it if both automaticDelete() is true the count reaches 0. More...
 
void setAutomaticDelete (bool autodel_on)
 If set to true the Object is deleted when its reference count reaches 0. More...
 
bool automaticDelete () const
 If set to true the Object is deleted when its reference count reaches 0. More...
 
template<class T >
T * as ()
 Casts an Object to the specified class. More...
 
template<class T >
const T * as () const
 Casts an Object to the specified class. More...
 

Protected Types

enum  { ZNone, ZCompress, ZDecompress }
 

Protected Member Functions

virtual long long read_Implementation (void *buffer, long long bytes_to_read)
 
virtual long long write_Implementation (const void *buffer, long long byte_count)
 
virtual long long position_Implementation () const
 
void resetStream ()
 
bool seekSet_Implementation (long long pos)
 
bool fillUncompressedBuffer ()
 
- Protected Member Functions inherited from vl::VirtualFile
 VirtualFile (const VirtualFile &other)
 
long long write64 (const void *buffer, long long count, bool little_endian_data=true)
 
long long write32 (const void *buffer, long long count, bool little_endian_data=true)
 
long long write16 (const void *buffer, long long count, bool little_endian_data=true)
 
long long read64 (void *buffer, long long count, bool little_endian_data=true)
 
long long read32 (void *buffer, long long count, bool little_endian_data=true)
 
long long read16 (void *buffer, long long count, bool little_endian_data=true)
 
long long write64 (const void *buffer, bool little_endian_data=true)
 
long long write32 (const void *buffer, bool little_endian_data=true)
 
long long write16 (const void *buffer, bool little_endian_data=true)
 
long long read64 (void *buffer, bool little_endian_data=true)
 
long long read32 (void *buffer, bool little_endian_data=true)
 
long long read16 (void *buffer, bool little_endian_data=true)
 
- Protected Member Functions inherited from vl::Object
virtual ~Object ()
 

Protected Attributes

int mCompressionLevel
 
ref< VirtualFilemStream
 
long long mReadBytes
 
long long mWrittenBytes
 
bool mWarnOnSeek
 
z_stream_s * mZStream
 
unsigned char mZipBufferIn [CHUNK_SIZE]
 
unsigned char mZipBufferOut [CHUNK_SIZE]
 
std::vector< char > mUncompressedBuffer
 
int mUncompressedBufferPtr
 
long long mStreamSize
 
long long mUncompressedSize
 
enum vl::GZipCodec:: { ... }  mMode
 
- Protected Attributes inherited from vl::VirtualFile
String mPath
 
- Protected Attributes inherited from vl::Object
std::string mObjectName
 
IMutexmRefCountMutex
 
int mReferenceCount
 
bool mAutomaticDelete
 

Detailed Description

The GZipCodec class is a VirtualFile that transparently encodes and decodes a stream of data using the GZip compression algorithm.

Definition at line 43 of file GZipCodec.hpp.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
protected
Enumerator
ZNone 
ZCompress 
ZDecompress 

Definition at line 135 of file GZipCodec.hpp.

Constructor & Destructor Documentation

◆ GZipCodec() [1/2]

GZipCodec::GZipCodec ( VirtualFile stream = NULL)

Constructor.

Definition at line 43 of file GZipCodec.cpp.

References mCompressionLevel, mReadBytes, mUncompressedSize, mWarnOnSeek, mWrittenBytes, and mZStream.

Referenced by clone().

◆ GZipCodec() [2/2]

GZipCodec::GZipCodec ( const String gz_path)

◆ ~GZipCodec()

GZipCodec::~GZipCodec ( )

Destructor.

Definition at line 66 of file GZipCodec.cpp.

References close(), mUncompressedSize, mWrittenBytes, mZStream, and NULL.

Member Function Documentation

◆ clone()

ref< VirtualFile > GZipCodec::clone ( ) const
virtual

Returns an equivalent GZipCodec.

Implements vl::VirtualFile.

Definition at line 178 of file GZipCodec.cpp.

References GZipCodec().

◆ close()

void GZipCodec::close ( )
virtual

◆ compressedSize()

long long vl::GZipCodec::compressedSize ( ) const
inline

Returns the size of the compressed stream as returned by stream()->size().

Definition at line 104 of file GZipCodec.hpp.

References vl::VirtualFile::size().

Referenced by compressionRatio().

◆ compressionLevel()

int vl::GZipCodec::compressionLevel ( ) const
inline

Definition at line 86 of file GZipCodec.hpp.

Referenced by open().

◆ compressionRatio()

float GZipCodec::compressionRatio ( ) const

Returns the compression ratio computed as compressedsize/uncompressedsize.

Definition at line 385 of file GZipCodec.cpp.

References compressedSize(), and size().

◆ exists()

virtual bool vl::GZipCodec::exists ( ) const
inlinevirtual

Returns true if the input or output stream file exists.

Implements vl::VirtualFile.

Definition at line 69 of file GZipCodec.hpp.

◆ fillUncompressedBuffer()

bool GZipCodec::fillUncompressedBuffer ( )
protected

◆ isOpen()

virtual bool vl::GZipCodec::isOpen ( ) const
inlinevirtual

Returns true if the file is open for read or writing.

Implements vl::VirtualFile.

Definition at line 66 of file GZipCodec.hpp.

Referenced by fillUncompressedBuffer(), open(), read_Implementation(), setStream(), and uncompressedSize().

◆ open()

bool GZipCodec::open ( EOpenMode  mode)
virtual

Opens a compressed stream.

  • If mode == OM_ReadOnly the stream will be decompressed during read operations.
  • If mode == OM_WriteOnly the stream will be compressed during write operations.

Implements vl::VirtualFile.

Definition at line 74 of file GZipCodec.cpp.

References compressionLevel(), vl::Log::error(), vl::ref< T >::get(), isOpen(), vl::locateFile(), mMode, mReadBytes, mStreamSize, mUncompressedBuffer, mUncompressedBufferPtr, mWrittenBytes, mZStream, vl::OM_ReadOnly, vl::OM_WriteOnly, vl::VirtualFile::path(), setStream(), vl::VirtualFile::size(), stream(), ZCompress, ZDecompress, and ZNone.

Referenced by resetStream().

◆ operator=()

GZipCodec & GZipCodec::operator= ( const GZipCodec other)

Definition at line 185 of file GZipCodec.cpp.

References close(), mCompressionLevel, and mStream.

◆ position_Implementation()

long long GZipCodec::position_Implementation ( ) const
protectedvirtual

Implements vl::VirtualFile.

Definition at line 260 of file GZipCodec.cpp.

References mReadBytes.

◆ read_Implementation()

long long GZipCodec::read_Implementation ( void *  buffer,
long long  bytes_to_read 
)
protectedvirtual

◆ resetStream()

void GZipCodec::resetStream ( )
protected

Definition at line 265 of file GZipCodec.cpp.

References close(), vl::OM_ReadOnly, and open().

Referenced by seekSet_Implementation().

◆ seekSet_Implementation()

bool GZipCodec::seekSet_Implementation ( long long  pos)
protectedvirtual

◆ setCompressionLevel()

void vl::GZipCodec::setCompressionLevel ( int  level)
inline

Sets the compression level used during write operations.

Parameters
levelValues can be between 0 (faster compression) to 9 (slower but better compression).

Definition at line 84 of file GZipCodec.hpp.

◆ setStream()

void GZipCodec::setStream ( VirtualFile stream)

Installs the VirtualFile representing the GZip file to be read or to be written.

Definition at line 375 of file GZipCodec.cpp.

References vl::VirtualFile::close(), isOpen(), mStream, mUncompressedSize, mWrittenBytes, vl::VirtualFile::path(), vl::VirtualFile::setPath(), and stream().

Referenced by vl::LoadWriterManager::loadResource(), and open().

◆ setWarnOnSeek()

void vl::GZipCodec::setWarnOnSeek ( bool  warn_on)
inline

Definition at line 111 of file GZipCodec.hpp.

◆ size()

long long GZipCodec::size ( ) const
virtual

Returns the uncompressed size of the stream. This is not a thread safe function.

Implements vl::VirtualFile.

Definition at line 367 of file GZipCodec.cpp.

References mMode, mWrittenBytes, uncompressedSize(), and ZCompress.

Referenced by compressionRatio().

◆ stream() [1/2]

const VirtualFile* vl::GZipCodec::stream ( ) const
inline

Returns the VirtualFile representing the GZip file to be read or to be written.

Definition at line 92 of file GZipCodec.hpp.

Referenced by close(), fillUncompressedBuffer(), open(), setStream(), uncompressedSize(), and write_Implementation().

◆ stream() [2/2]

VirtualFile* vl::GZipCodec::stream ( )
inline

Returns the VirtualFile representing the GZip file to be read or to be written.

Definition at line 95 of file GZipCodec.hpp.

◆ uncompressedSize()

long long GZipCodec::uncompressedSize ( )

Returns the uncompressed size of the stream.

Note
This function needs to seek to the end of the GZip stream in order to read the uncompressed file size.

Definition at line 340 of file GZipCodec.cpp.

References vl::VirtualFile::close(), isOpen(), mMode, mUncompressedSize, vl::OM_ReadOnly, vl::VirtualFile::open(), vl::VirtualFile::position(), vl::VirtualFile::readUInt32(), vl::VirtualFile::seekEnd(), vl::VirtualFile::seekSet(), stream(), ZDecompress, and ZNone.

Referenced by size().

◆ warnOnSeek()

bool vl::GZipCodec::warnOnSeek ( ) const
inline

Definition at line 109 of file GZipCodec.hpp.

Referenced by seekSet_Implementation().

◆ write_Implementation()

long long GZipCodec::write_Implementation ( const void *  buffer,
long long  byte_count 
)
protectedvirtual

Implements vl::VirtualFile.

Definition at line 233 of file GZipCodec.cpp.

References vl::Log::error(), mWrittenBytes, mZStream, stream(), and vl::VirtualFile::write().

Member Data Documentation

◆ mCompressionLevel

int vl::GZipCodec::mCompressionLevel
protected

Definition at line 122 of file GZipCodec.hpp.

Referenced by GZipCodec(), and operator=().

◆ mMode

enum { ... } vl::GZipCodec::mMode

◆ mReadBytes

long long vl::GZipCodec::mReadBytes
protected

Definition at line 124 of file GZipCodec.hpp.

Referenced by close(), GZipCodec(), open(), position_Implementation(), and read_Implementation().

◆ mStream

ref<VirtualFile> vl::GZipCodec::mStream
protected

Definition at line 123 of file GZipCodec.hpp.

Referenced by operator=(), and setStream().

◆ mStreamSize

long long vl::GZipCodec::mStreamSize
protected

Definition at line 133 of file GZipCodec.hpp.

Referenced by fillUncompressedBuffer(), and open().

◆ mUncompressedBuffer

std::vector<char> vl::GZipCodec::mUncompressedBuffer
protected

Definition at line 131 of file GZipCodec.hpp.

Referenced by close(), fillUncompressedBuffer(), open(), and read_Implementation().

◆ mUncompressedBufferPtr

int vl::GZipCodec::mUncompressedBufferPtr
protected

Definition at line 132 of file GZipCodec.hpp.

Referenced by close(), fillUncompressedBuffer(), open(), and read_Implementation().

◆ mUncompressedSize

long long vl::GZipCodec::mUncompressedSize
protected

Definition at line 134 of file GZipCodec.hpp.

Referenced by GZipCodec(), setStream(), uncompressedSize(), and ~GZipCodec().

◆ mWarnOnSeek

bool vl::GZipCodec::mWarnOnSeek
protected

Definition at line 126 of file GZipCodec.hpp.

Referenced by GZipCodec().

◆ mWrittenBytes

long long vl::GZipCodec::mWrittenBytes
protected

Definition at line 125 of file GZipCodec.hpp.

Referenced by close(), GZipCodec(), open(), setStream(), size(), write_Implementation(), and ~GZipCodec().

◆ mZipBufferIn

unsigned char vl::GZipCodec::mZipBufferIn[CHUNK_SIZE]
protected

Definition at line 129 of file GZipCodec.hpp.

Referenced by fillUncompressedBuffer().

◆ mZipBufferOut

unsigned char vl::GZipCodec::mZipBufferOut[CHUNK_SIZE]
protected

Definition at line 130 of file GZipCodec.hpp.

Referenced by fillUncompressedBuffer().

◆ mZStream

z_stream_s* vl::GZipCodec::mZStream
protected

The documentation for this class was generated from the following files: