mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-07-18 13:14:47 +08:00
added class Header
This commit is contained in:
48
Common/cppcf/streamrw.cpp
Normal file
48
Common/cppcf/streamrw.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
#include "streamrw.h"
|
||||
#include <algorithm>
|
||||
|
||||
using namespace CFCPP;
|
||||
|
||||
StreamRW::StreamRW(std::fstream &stream)
|
||||
: stream(stream)
|
||||
{
|
||||
buffer.fill(0);
|
||||
}
|
||||
|
||||
T_LONG64 StreamRW::Seek(T_LONG64 offset)
|
||||
{
|
||||
stream.seekg(offset);
|
||||
return stream.tellg();
|
||||
}
|
||||
|
||||
|
||||
template<size_t N>
|
||||
std::array<BYTE, N> StreamRW::ReadArray()
|
||||
{
|
||||
std::array<BYTE,N> arr(0);
|
||||
stream.read(reinterpret_cast<char*>(arr.data()), N);
|
||||
return arr;
|
||||
}
|
||||
|
||||
void StreamRW::WriteArray(BYTE *arr, int lenght)
|
||||
{
|
||||
stream.write(reinterpret_cast<char*>(arr), lenght);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T StreamRW::Read()
|
||||
{
|
||||
T value;
|
||||
char* asByteArr = reinterpret_cast<char*>(&value);
|
||||
stream.read(asByteArr, sizeof (T));
|
||||
std::reverse(asByteArr, asByteArr + sizeof (T));
|
||||
return value;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void StreamRW::Write(T value)
|
||||
{
|
||||
char* asByteArr = reinterpret_cast<char*>(&value);
|
||||
std::reverse(asByteArr, asByteArr + sizeof (T));
|
||||
stream.write(asByteArr, sizeof (T));
|
||||
}
|
||||
Reference in New Issue
Block a user