Files
core/Common/cppcf/streamrw.h
2022-07-27 22:36:56 +03:00

46 lines
850 B
C++

#pragma once
#include <fstream>
#include <array>
#include <vector>
#include "stream.h"
namespace CFCPP
{
class StreamRW
{
public:
StreamRW(const Stream &stream);
T_LONG64 Seek(T_LONG64 offset);
template <class T>
T Read()
{
T value;
char* asByteArr = reinterpret_cast<char*>(&value);
stream->read(asByteArr, sizeof (T));
return value;
}
template<class T>
void Write(T value)
{
char* asByteArr = reinterpret_cast<char*>(&value);
stream->write(asByteArr, sizeof (T));
}
void ReadArray(char* data, int lenght);
void ReadArray(BYTE* data, int lenght);
void WriteArray(const BYTE *arr, int lenght);
void WriteArray(const char *arr, int lenght);
inline void Close(){return;}
private:
std::array<char,8> buffer;
Stream stream;
};
}