⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bitio.h

📁 自适应huffman编码
💻 H
字号:
#pragma once

#ifndef _BitIO_H_
#define _BitIO_H_

// #include "stdio.h"
#include <iostream>
#include <fstream>
using namespace std;

#include <assert.h>


class BitOp 
{
public: 
	void static AddPrefix(char * bits, int & bits_len, char * pre, int pre_len);
};

virtual class BitIO
{
public:
	BitIO(void);
	~BitIO(void);
	bool Init();
	bool Init(int buf_size, int mode);
	virtual bool Write(const char * bits, int bits_len);
	virtual void Flush();
	virtual void FlushEnd() = 0;
	virtual void Close();
	virtual int  ReadABit() = 0;
	virtual int  ReadABit(char * c, int start);
	virtual bool ReadAByte(char & c);
//	bool Read(char * bits, int &bits_len);
	int  GetMode();  // return the working mode of current object
	inline unsigned long GetBitsNum(void) { return bits_num;};
protected:
	unsigned long bits_num;
	unsigned long max_bits_num;

	int    mode;  // 0 for read only; 1 for write only; 2 for read & write
	char * buf;
	unsigned long  used;  // used buffer (by number of bits)
	unsigned long  buf_size;  // size of buf by bytes.
	unsigned long  unhandled; // the number of unhandled bits in buffer, set for reading funtion
	unsigned long  handled;   // the number of handled bits in buffer, set for reading funtion
};

class FileBitIO : public BitIO
{
public:
	FileBitIO(void);
	~FileBitIO(void);
	bool Init(fstream * p_fs);
	bool Init(fstream * p_fs, int bufsize, int work_mode, unsigned long leng);
	bool Init(fstream * p_fs, int bufsize, int work_mode);
	bool Write(const char * bits, int bits_len);
	void Flush();
	void FlushEnd();
	void Close();
    int  ReadABit();
	int  ReadABit(char * c, int start);
	bool ReadAByte(char & c);
	unsigned long GetBitsNum(void);
protected:
	int RenewReadBuf();
	fstream * fs;  
};

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -