mirror of
https://github.com/jorio/Pomme.git
synced 2024-12-27 06:29:18 +00:00
BigEndianOStream
This commit is contained in:
parent
935674437f
commit
b4516298a3
@ -40,7 +40,8 @@ set(POMME_SOURCES
|
||||
${POMME_SRCDIR}/Sound/xlaw.cpp
|
||||
${POMME_SRCDIR}/Text/TextUtilities.cpp
|
||||
${POMME_SRCDIR}/Time/TimeManager.cpp
|
||||
${POMME_SRCDIR}/Utilities/BigEndianIStream.cpp
|
||||
${POMME_SRCDIR}/Utilities/bigendianstreams.cpp
|
||||
${POMME_SRCDIR}/Utilities/bigendianstreams.h
|
||||
${POMME_SRCDIR}/Utilities/FixedPool.h
|
||||
${POMME_SRCDIR}/Utilities/GrowablePool.h
|
||||
${POMME_SRCDIR}/Utilities/IEEEExtended.cpp
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include "Pomme.h"
|
||||
#include "Utilities/BigEndianIStream.h"
|
||||
#include "Utilities/bigendianstreams.h"
|
||||
#include "Utilities/GrowablePool.h"
|
||||
#include "Utilities/memstream.h"
|
||||
#include "PommeFiles.h"
|
||||
|
@ -2,7 +2,7 @@
|
||||
#include "PommeDebug.h"
|
||||
#include "PommeFiles.h"
|
||||
#include "Files/HostVolume.h"
|
||||
#include "Utilities/BigEndianIStream.h"
|
||||
#include "Utilities/bigendianstreams.h"
|
||||
#include "Utilities/StringUtils.h"
|
||||
|
||||
#include <fstream>
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "Pomme.h"
|
||||
#include "PommeFiles.h"
|
||||
#include "Utilities/BigEndianIStream.h"
|
||||
#include "Utilities/bigendianstreams.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "Pomme.h"
|
||||
#include "PommeGraphics.h"
|
||||
#include "Utilities/BigEndianIStream.h"
|
||||
#include "Utilities/bigendianstreams.h"
|
||||
|
||||
#include <list>
|
||||
#include <fstream>
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include <map>
|
||||
#include <cstring>
|
||||
#include <QD3D/QD3D.h>
|
||||
#include "Utilities/BigEndianIStream.h"
|
||||
#include "Utilities/bigendianstreams.h"
|
||||
|
||||
struct Q3MetaFileTOCEntry
|
||||
{
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include "PommeSound.h"
|
||||
#include "Utilities/BigEndianIStream.h"
|
||||
#include "Utilities/bigendianstreams.h"
|
||||
#include <cstdint>
|
||||
|
||||
static void AIFFAssert(bool condition, const char* message)
|
||||
|
@ -2,7 +2,7 @@
|
||||
#include "PommeFiles.h"
|
||||
#include "Sound/cmixer.h"
|
||||
#include "PommeSound.h"
|
||||
#include "Utilities/BigEndianIStream.h"
|
||||
#include "Utilities/bigendianstreams.h"
|
||||
#include "Utilities/memstream.h"
|
||||
|
||||
#include <thread>
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
#include <cstring>
|
||||
#include <Utilities/memstream.h>
|
||||
#include <Utilities/BigEndianIStream.h>
|
||||
#include <Utilities/bigendianstreams.h>
|
||||
|
||||
void NumToString(long theNum, Str255 theString)
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "Utilities/BigEndianIStream.h"
|
||||
#include "Utilities/bigendianstreams.h"
|
||||
#include "Utilities/IEEEExtended.h"
|
||||
|
||||
Pomme::StreamPosGuard::StreamPosGuard(std::istream& theStream) :
|
||||
@ -21,6 +21,8 @@ void Pomme::StreamPosGuard::Cancel()
|
||||
active = false;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
Pomme::BigEndianIStream::BigEndianIStream(std::istream& theStream) :
|
||||
stream(theStream)
|
||||
{
|
||||
@ -83,3 +85,46 @@ Pomme::StreamPosGuard Pomme::BigEndianIStream::GuardPos()
|
||||
{
|
||||
return Pomme::StreamPosGuard(stream);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
Pomme::BigEndianOStream::BigEndianOStream(std::ostream& theStream) :
|
||||
stream(theStream)
|
||||
{
|
||||
}
|
||||
|
||||
void Pomme::BigEndianOStream::Write(const char* src, size_t n)
|
||||
{
|
||||
stream.write(src, n);
|
||||
}
|
||||
|
||||
void Pomme::BigEndianOStream::WritePascalString(const std::string& text, int padToAlignment)
|
||||
{
|
||||
int length = text.length();
|
||||
if (length > 255)
|
||||
{
|
||||
throw std::out_of_range("WritePascalString: must be <255 characters!");
|
||||
}
|
||||
Write<uint8_t>(length);
|
||||
Write(text.data(), length);
|
||||
|
||||
int padding = (length + 1) % padToAlignment;
|
||||
for (int i = 0; i < padding; i++)
|
||||
Write<uint8_t>(0);
|
||||
}
|
||||
|
||||
void Pomme::BigEndianOStream::WriteRawString(const std::string& text)
|
||||
{
|
||||
Write(text.data(), text.length());
|
||||
}
|
||||
|
||||
void Pomme::BigEndianOStream::Goto(std::streamoff absoluteOffset)
|
||||
{
|
||||
stream.seekp(absoluteOffset, std::ios_base::beg);
|
||||
}
|
||||
|
||||
std::streampos Pomme::BigEndianOStream::Tell() const
|
||||
{
|
||||
return stream.tellp();
|
||||
}
|
||||
|
@ -22,8 +22,6 @@ namespace Pomme
|
||||
|
||||
class BigEndianIStream
|
||||
{
|
||||
std::istream& stream;
|
||||
|
||||
public:
|
||||
BigEndianIStream(std::istream& theStream);
|
||||
|
||||
@ -58,5 +56,40 @@ namespace Pomme
|
||||
#endif
|
||||
return *(T*) b;
|
||||
}
|
||||
|
||||
private:
|
||||
std::istream& stream;
|
||||
};
|
||||
|
||||
class BigEndianOStream
|
||||
{
|
||||
public:
|
||||
BigEndianOStream(std::ostream& theStream);
|
||||
|
||||
void Write(const char* src, size_t n);
|
||||
|
||||
void Goto(std::streamoff absoluteOffset);
|
||||
|
||||
std::streampos Tell() const;
|
||||
|
||||
void WritePascalString(const std::string& text, int padToAlignment = 1);
|
||||
|
||||
void WriteRawString(const std::string& text);
|
||||
|
||||
template<typename T>
|
||||
void Write(T value)
|
||||
{
|
||||
char* b = (char*) &value;
|
||||
#if !(TARGET_RT_BIGENDIAN)
|
||||
if constexpr (sizeof(T) > 1)
|
||||
{
|
||||
std::reverse(b, b + sizeof(T));
|
||||
}
|
||||
#endif
|
||||
Write(b, sizeof(T));
|
||||
}
|
||||
|
||||
private:
|
||||
std::ostream& stream;
|
||||
};
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
#include "Video/Cinepak.h"
|
||||
#include "PommeVideo.h"
|
||||
#include "PommeSound.h"
|
||||
#include "Utilities/BigEndianIStream.h"
|
||||
#include "Utilities/bigendianstreams.h"
|
||||
#include "PommeDebug.h"
|
||||
|
||||
#include <iostream>
|
||||
|
Loading…
Reference in New Issue
Block a user