datacompression.cpp

来自「自适应算术编码的实现」· C++ 代码 · 共 67 行

CPP
67
字号
//  DataCompression.cpp :   Define virtual class for Coder and Decoder 
// 
//  Author:    Shen Hongwei
//  Date:      Sep.28, 2005
//  Location:  Beijing, China
// 

#include "StdAfx.h"
#include "./DataCompression.h"

CompressionHeader::CompressionHeader(void)
{
}

CompressionHeader::~CompressionHeader(void)
{
}

void CompressionHeader::Init(fstream * p_fs)
{
	this->fs = p_fs;
}

bool CompressionHeader::ReadHeader(void)
{
	union u {
		unsigned long   l;
	    char   str[4];   // NT_REVISISTED
	} un;

	this->fs->read(un.str, 4);

	if (this->fs->eof()) {
		this->length = 0;
		return false;
	} else {
		this->length = un.l;
	}

	this->fs->read(un.str, 4);

	if (this->fs->eof()) {
		this->origin_len = 0;
		return false;
	} else {
		this->origin_len = un.l;
	    return true;
	}
}

bool CompressionHeader::WriteHeader(void)
{
	this->fs->seekp(0);
	union u {
		unsigned long   l;
	    char   str[4];   // NT_REVISISTED
	} un;

	un.l = this->length;
	this->fs->write(un.str, 4);

	un.l = this->origin_len;
	this->fs->write(un.str, 4);

	return true;
}

⌨️ 快捷键说明

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