Files
envi-code/SourceCode/Code2026/tg_shs/shs_subgeLib/TWArchive.cpp
T
2026-09-28 15:28:50 +08:00

287 lines
4.1 KiB
C++

//-----------------------------------------------------------------------------+
// Copyright (C), 1998-2007, Beijing Tangent Software Co. Ltd.
// = FileName : TWArchive.cpp
// = Version : ver2.0
// = Author : xlc
// = CreateDate : 2002-09-09
// = Description: 类的定义
// = Maintainers:
//
//-----------------------------------------------------------------------------+
#include "StdAfx.h"
#include "TWArchive.h"
TWArchive::TWArchive()
: m_iCur(0),m_iLength(0)
{
}
TWArchive::~TWArchive()
{
}
//清空并初始化为初始状态
void TWArchive::Clear()
{
m_iLength = 0;
m_iCur = 0;
}
//移动游标
void TWArchive::MoveTo(long i)
{
if (i < 0)
{
i = 0;
}
m_iCur = i;
}
long TWArchive::GetLength()const
{
return m_iLength;
}
long TWArchive::GetCur()const
{
return m_iCur;
}
bool TWArchive::IsOut()const
{
return m_iCur >= GetLength();
}
//移动游标
void TWArchive::MoveToFirst()
{
MoveTo(0);
}
void TWArchive::MoveToLast()
{
MoveTo(GetLength() - 1);
}
void TWArchive::MoveOut()
{
MoveTo(GetLength());
}
void TWArchive::MoveToNext(long step)
{
MoveTo(GetCur() + step);
}
void TWArchive::MoveToPre(long step)
{
MoveTo(GetCur() - step);
}
//当前游标位置读取,不移动游标
void TWArchive::Read(char &val)
{
Read(&val, sizeof(val));
}
void TWArchive::Read(bool &val)
{
Read(&val, sizeof(val));
}
void TWArchive::Read(short &val)
{
Read(&val, sizeof(val));
}
void TWArchive::Read(int &val)
{
Read(&val, sizeof(val));
}
void TWArchive::Read(long &val)
{
Read(&val, sizeof(val));
}
void TWArchive::Read(float &val)
{
Read(&val, sizeof(val));
}
void TWArchive::Read(double &val)
{
Read(&val, sizeof(val));
}
void TWArchive::Read(long double &val)
{
Read(&val, sizeof(val));
}
//当前游标位置写,不移动游标
void TWArchive::Write(char val)
{
Write(&val, sizeof(val));
}
void TWArchive::Write(bool val)
{
Write(&val, sizeof(val));
}
void TWArchive::Write(short val)
{
Write(&val, sizeof(val));
}
void TWArchive::Write(int val)
{
Write(&val, sizeof(val));
}
void TWArchive::Write(long val)
{
Write(&val, sizeof(val));
}
void TWArchive::Write(float val)
{
Write(&val, sizeof(val));
}
void TWArchive::Write(double val)
{
Write(&val, sizeof(val));
}
void TWArchive::Write(long double val)
{
Write(&val, sizeof(val));
}
//末尾添加并后移游标
void TWArchive::Append(void *p, long size)
{
MoveOut();
Write(p,size);
MoveOut();
}
TWArchive& TWArchive::operator<<(char val)
{
Append(&val, sizeof(val));
return *this;
}
TWArchive& TWArchive::operator<<(bool val)
{
Append(&val, sizeof(val));
return *this;
}
TWArchive& TWArchive::operator<<(short val)
{
Append(&val, sizeof(val));
return *this;
}
TWArchive& TWArchive::operator<<(int val)
{
Append(&val, sizeof(val));
return *this;
}
TWArchive& TWArchive::operator<<(long val)
{
Append(&val, sizeof(val));
return *this;
}
TWArchive& TWArchive::operator<<(float val)
{
Append(&val, sizeof(val));
return *this;
}
TWArchive& TWArchive::operator<<(double val)
{
Append(&val, sizeof(val));
return *this;
}
TWArchive& TWArchive::operator<<(long double val)
{
Append(&val, sizeof(val));
return *this;
}
//当前游标位置读数据并后移游标
TWArchive& TWArchive::operator>>(char &val)
{
Read(&val, sizeof(val));
MoveToNext(sizeof(val));
return *this;
}
TWArchive& TWArchive::operator>>(bool &val)
{
Read(&val, sizeof(val));
MoveToNext(sizeof(val));
return *this;
}
TWArchive& TWArchive::operator>>(short &val)
{
Read(&val, sizeof(val));
MoveToNext(sizeof(val));
return *this;
}
TWArchive& TWArchive::operator>>(int &val)
{
Read(&val, sizeof(val));
MoveToNext(sizeof(val));
return *this;
}
TWArchive& TWArchive::operator>>(long &val)
{
Read(&val, sizeof(val));
MoveToNext(sizeof(val));
return *this;
}
TWArchive& TWArchive::operator>>(float &val)
{
Read(&val, sizeof(val));
MoveToNext(sizeof(val));
return *this;
}
TWArchive& TWArchive::operator>>(double &val)
{
Read(&val, sizeof(val));
MoveToNext(sizeof(val));
return *this;
}
TWArchive& TWArchive::operator>>(long double &val)
{
Read(&val, sizeof(val));
MoveToNext(sizeof(val));
return *this;
}
bool TWArchive::operator> (const TWArchive &ar)const
{
return false;
}
bool TWArchive::operator< (const TWArchive &ar)const
{
return false;
}