2013-10-03 05:51:24 +04:00
|
|
|
// Copyright (c) 2012-2013 Konstantin Isakov <ikm@zbackup.org>
|
|
|
|
// Part of ZBackup. Licensed under GNU GPLv2 or later
|
|
|
|
|
|
|
|
#ifndef COMPRESSION_HH_INCLUDED__
|
|
|
|
#define COMPRESSION_HH_INCLUDED__
|
|
|
|
|
2013-10-08 03:17:15 +04:00
|
|
|
#include "sptr.hh"
|
2013-10-03 05:51:24 +04:00
|
|
|
|
|
|
|
|
|
|
|
// used for encoding or decoding
|
2013-10-08 03:17:15 +04:00
|
|
|
class EnDecoder
|
|
|
|
{
|
2013-10-03 05:51:24 +04:00
|
|
|
protected:
|
|
|
|
EnDecoder();
|
|
|
|
// cannot be copied
|
2013-10-08 03:17:15 +04:00
|
|
|
EnDecoder( const EnDecoder& );
|
2013-10-03 05:51:24 +04:00
|
|
|
public:
|
|
|
|
virtual ~EnDecoder();
|
|
|
|
|
|
|
|
// encoder can read up to size bytes from data
|
2013-10-08 03:17:15 +04:00
|
|
|
virtual void setInput ( const void* data, size_t size ) =0;
|
2013-10-03 05:51:24 +04:00
|
|
|
// how many bytes of the last input haven't been used, yet?
|
|
|
|
virtual size_t getAvailableInput() =0;
|
|
|
|
|
|
|
|
// encoder can write up to size bytes to output
|
2013-10-08 03:17:15 +04:00
|
|
|
virtual void setOutput( void* data, size_t size ) =0;
|
2013-10-03 05:51:24 +04:00
|
|
|
// how many bytes of free space are remaining in the output buffer
|
|
|
|
virtual size_t getAvailableOutput() =0;
|
|
|
|
|
|
|
|
// process some bytes
|
|
|
|
// finish: will you pass more data to the encoder via setOutput?
|
|
|
|
// NOTE You must eventually set finish to true.
|
|
|
|
// returns, whether all output bytes have been written
|
2013-10-08 03:17:15 +04:00
|
|
|
virtual bool process( bool finish ) =0;
|
2013-10-03 05:51:24 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
// compression method
|
2013-10-08 03:17:15 +04:00
|
|
|
class Compression
|
|
|
|
{
|
2013-10-03 05:51:24 +04:00
|
|
|
public:
|
|
|
|
virtual ~Compression();
|
|
|
|
|
|
|
|
// returns name of compression method
|
|
|
|
// This name is saved in the file header of the compressed file.
|
|
|
|
virtual std::string getName() const =0;
|
|
|
|
|
2013-10-08 03:17:15 +04:00
|
|
|
virtual sptr<EnDecoder> createEncoder() const =0;
|
|
|
|
virtual sptr<EnDecoder> createDecoder() const =0;
|
2013-10-03 05:51:24 +04:00
|
|
|
|
|
|
|
// find a compression by name
|
2013-10-08 03:17:15 +04:00
|
|
|
// If optional is false, it will either return a valid Compression
|
|
|
|
// object or abort the program. If optional is true, it will return
|
|
|
|
// NULL, if it cannot find the a compression with that name.
|
|
|
|
static const_sptr<Compression> findCompression(
|
|
|
|
const std::string& name, bool optional = false );
|
2013-10-03 05:51:24 +04:00
|
|
|
|
2013-10-08 03:17:15 +04:00
|
|
|
static const_sptr<Compression> default_compression;
|
2013-10-03 11:32:58 +04:00
|
|
|
|
2013-10-08 03:17:15 +04:00
|
|
|
class iterator
|
|
|
|
{
|
2013-10-03 11:32:58 +04:00
|
|
|
friend class Compression;
|
2013-10-03 12:24:47 +04:00
|
|
|
|
2013-10-08 03:17:15 +04:00
|
|
|
const const_sptr<Compression>* ptr;
|
|
|
|
iterator( const const_sptr<Compression>* ptr );
|
2013-10-03 11:32:58 +04:00
|
|
|
public:
|
2013-10-08 03:17:15 +04:00
|
|
|
iterator( const iterator& it );
|
|
|
|
iterator& operator =( const iterator& it );
|
2013-10-03 11:32:58 +04:00
|
|
|
|
2013-10-08 03:17:15 +04:00
|
|
|
bool operator ==( const iterator& other ) const;
|
|
|
|
bool operator !=( const iterator& other ) const;
|
2013-10-03 11:32:58 +04:00
|
|
|
|
|
|
|
bool at_end() const;
|
|
|
|
|
|
|
|
iterator& operator ++();
|
|
|
|
|
2013-10-08 03:17:15 +04:00
|
|
|
const_sptr<Compression> operator *();
|
2013-10-03 11:32:58 +04:00
|
|
|
};
|
|
|
|
static iterator begin();
|
|
|
|
static iterator end();
|
2013-10-03 05:51:24 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|