mcio.cpp

来自「非常好用的五子棋游戏源码」· C++ 代码 · 共 65 行

CPP
65
字号
// Created:10-04-98
// By Jeff Connelly

// Memory I/O for ComprLib

#include "stdafx.h"
#include <string.h>
#include <stdlib.h>

//#include "mcio.h"
#define EXPORTING
#include "comprlib.h"

// Static members initalization
char* ComprLibMemIO::source_ptr = NULL;
char* ComprLibMemIO::dest_ptr = NULL;
long ComprLibMemIO::source_len = 0;
long ComprLibMemIO::dest_len = 0;
long ComprLibMemIO::source_pos = 0;
long ComprLibMemIO::dest_pos = 0;
long ComprLibMemIO::grow_by = 1024;   // Increment in 1K

// End of input data?
bool ComprLibMemIO::end_of_data()
{
    if (source_pos >= source_len)
        return true;
    return false;
}

// Size of input stream
long ComprLibMemIO::stream_size()
{
    return source_len;
}

// Read a byte from input memory
unsigned char ComprLibMemIO::read_byte()
{
    unsigned char c;
    if (end_of_data())
        return 0;
    c = *(source_ptr + source_pos);
    ++source_pos;
    return c;
}

// Write a byte to memory
void ComprLibMemIO::write_byte(unsigned char byte)
{
    // Reallocate the memory until we have enough
    while (dest_pos >= dest_len)
        dest_ptr = (char*)
		realloc(dest_ptr, dest_len += grow_by);

    *(dest_ptr + dest_pos) = byte;
    ++dest_pos;
}

// Reset the input position to the beginning
void ComprLibMemIO::beginning_of_data()
{
    source_pos = 0;
}

⌨️ 快捷键说明

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