- FileStream cleanup

This commit is contained in:
Christoph Oelckers 2020-06-28 14:42:06 +02:00
parent 2ddec37098
commit 7b7c64fc17
2 changed files with 16 additions and 81 deletions

View File

@ -1,65 +0,0 @@
//-------------------------------------------------------------------------
/*
Copyright (C) 2010-2020 EDuke32 developers and contributors
Copyright (C) 2020 sirlemonhead
This file is part of Rednukem.
Rednukem is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License version 2
as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
//-------------------------------------------------------------------------
#ifndef _RedNukemFileStream_h_
#define _RedNukemFileStream_h_
#include "vfs.h"
#include "compat.h"
#include <stdint.h>
namespace RedNukem {
class FileStream
{
public:
bool Open(const char *fileName);
bool Is_Open();
void Close();
int32_t ReadBytes(uint8_t *data, uint32_t nBytes);
uint64_t ReadUint64LE();
uint64_t ReadUint64BE();
uint32_t ReadUint32LE();
uint32_t ReadUint32BE();
uint16_t ReadUint16LE();
uint16_t ReadUint16BE();
uint8_t ReadByte();
enum SeekDirection {
kSeekCurrent = 0,
kSeekStart = 1,
kSeekEnd = 2
};
int32_t Seek(int32_t offset, SeekDirection = kSeekStart);
int32_t Skip(int32_t offset);
int32_t GetPosition();
private:
buildvfs_kfd file;
};
} // close namespace RedNukem
#endif

View File

@ -30,29 +30,29 @@ class FileStream
public:
bool Open(const char *fileName);
bool Is_Open();
void Close();
bool Is_Open() { return file.isOpen(); }
void Close() { file.Close(); }
int32_t ReadBytes(uint8_t *data, uint32_t nBytes);
int32_t ReadBytes(uint8_t *data, uint32_t nBytes)
{
return (uint32_t)file.Read(data, static_cast<int32_t>(nBytes));
}
uint32_t ReadUint32LE();
uint32_t ReadUint32BE();
uint64_t ReadUint64LE() { return file.ReadUInt64(); }
uint32_t ReadUint32LE() { return file.ReadUInt32(); }
uint16_t ReadUint16LE() { return file.ReadUInt16(); }
uint8_t ReadByte() { return file.ReadInt8(); }
uint16_t ReadUint16LE();
uint16_t ReadUint16BE();
uint8_t ReadByte();
enum SeekDirection{
kSeekCurrent = 0,
kSeekStart = 1,
kSeekEnd = 2
kSeekCurrent = SEEK_CUR,
kSeekStart = SEEK_SET,
kSeekEnd = SEEK_END
};
int32_t Seek(int32_t offset, SeekDirection = kSeekStart);
int32_t Skip(int32_t offset);
int32_t GetPosition();
int32_t Seek(int32_t offset, SeekDirection dir = kSeekStart) { return file.Seek(offset, (FileReader::ESeek) dir); }
int32_t Skip(int32_t offset) { return Seek(offset, kSeekCurrent); }
int32_t GetPosition() { return file.Tell(); }
private:
FileReader file;