Added a couple new utility/convenience functions in FileIO and Math

This commit is contained in:
Aruki 2017-03-30 01:25:50 -06:00
parent 98cd617b3e
commit cd8f4147c2
6 changed files with 60 additions and 1 deletions

View File

@ -42,7 +42,7 @@ CONFIG (release, debug|release) {
# Release Libs
LIBS += -L$$BUILD_DIR/FileIO/ -lFileIO \
-L$$EXTERNALS_DIR/boost_1_63_0/lib64-msvc-140 -llibboost_filesystem-vc140-mt-1_63 \
-L$$EXTERNALS_DIR/boost_1_63_0/lib64-msvc-14.0 -llibboost_filesystem-vc140-mt-1_63 \
-L$$EXTERNALS_DIR/lzo-2.09/lib -llzo2 \
-L$$EXTERNALS_DIR/tinyxml2/lib -ltinyxml2 \
-L$$EXTERNALS_DIR/zlib/lib -lzlib

View File

@ -60,6 +60,14 @@ double IInputStream::ReadDouble()
return Val;
}
long IInputStream::ReadFourCC()
{
long Val;
ReadBytes(&Val, 4);
if (IOUtil::kSystemEndianness == IOUtil::eLittleEndian) IOUtil::SwapBytes(Val);
return Val;
}
std::string IInputStream::ReadString()
{
std::string Str;
@ -166,6 +174,23 @@ double IInputStream::PeekDouble()
return Val;
}
long IInputStream::PeekFourCC()
{
long Val = ReadFourCC();
Seek(-4, SEEK_CUR);
return Val;
}
bool IInputStream::GoTo(long Address)
{
return Seek(Address, SEEK_SET);
}
bool IInputStream::Skip(long SkipAmount)
{
return Seek(SkipAmount, SEEK_CUR);
}
void IInputStream::SeekToBoundary(unsigned long Boundary)
{
long Num = Boundary - (Tell() % Boundary);

View File

@ -19,6 +19,7 @@ public:
long long ReadLongLong();
float ReadFloat();
double ReadDouble();
long ReadFourCC();
std::string ReadString();
std::string ReadString(unsigned long Count);
std::string ReadSizedString();
@ -32,6 +33,10 @@ public:
long long PeekLongLong();
float PeekFloat();
double PeekDouble();
long PeekFourCC();
bool GoTo(long Address);
bool Skip(long SkipAmount);
void SeekToBoundary(unsigned long Boundary);
void SetEndianness(IOUtil::EEndianness Endianness);

View File

@ -45,6 +45,12 @@ void IOutputStream::WriteDouble(double Val)
WriteBytes(&Val, 8);
}
void IOutputStream::WriteFourCC(long Val)
{
if (IOUtil::kSystemEndianness == IOUtil::eLittleEndian) IOUtil::SwapBytes(Val);
WriteBytes(&Val, 4);
}
void IOutputStream::WriteString(const std::string& rkVal)
{
for (unsigned int i = 0; i < rkVal.size(); i++)
@ -93,6 +99,17 @@ void IOutputStream::WriteSizedWideString(const std::wstring& rkVal)
WriteBytes(rkVal.data(), rkVal.size() * 2);
}
bool IOutputStream::GoTo(long Address)
{
return Seek(Address, SEEK_SET);
}
bool IOutputStream::Skip(long SkipAmount)
{
return Seek(SkipAmount, SEEK_CUR);
}
void IOutputStream::WriteToBoundary(unsigned long Boundary, unsigned char Fill)
{
long Num = Boundary - (Tell() % Boundary);

View File

@ -18,6 +18,7 @@ public:
void WriteLongLong(long long Val);
void WriteFloat(float Val);
void WriteDouble(double Val);
void WriteFourCC(long Val);
void WriteString(const std::string& rkVal);
void WriteString(const std::string& rkVal, unsigned long Count, bool Terminate = false);
void WriteSizedString(const std::string& rkVal);
@ -25,6 +26,9 @@ public:
void WriteWideString(const std::wstring& rkVal, unsigned long Count, bool Terminate = false);
void WriteSizedWideString(const std::wstring& rkVal);
bool GoTo(long Address);
bool Skip(long SkipAmount);
void WriteToBoundary(unsigned long Boundary, unsigned char Fill);
void SetEndianness(IOUtil::EEndianness Endianness);
void SetDestString(const std::string& rkDest);

View File

@ -22,6 +22,14 @@ float DegreesToRadians(float Deg);
float RadiansToDegrees(float Rad);
template<typename Type>
Type Clamp(const Type& rkMin, const Type& rkMax, const Type& rkVal)
{
return (rkVal < rkMin) ? rkMin :
(rkVal > rkMax) ? rkMax :
rkVal;
}
template<typename Type>
Type Max(const Type& rkA, const Type& rkB)
{