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 # Release Libs
LIBS += -L$$BUILD_DIR/FileIO/ -lFileIO \ 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/lzo-2.09/lib -llzo2 \
-L$$EXTERNALS_DIR/tinyxml2/lib -ltinyxml2 \ -L$$EXTERNALS_DIR/tinyxml2/lib -ltinyxml2 \
-L$$EXTERNALS_DIR/zlib/lib -lzlib -L$$EXTERNALS_DIR/zlib/lib -lzlib

View File

@ -60,6 +60,14 @@ double IInputStream::ReadDouble()
return Val; 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 IInputStream::ReadString()
{ {
std::string Str; std::string Str;
@ -166,6 +174,23 @@ double IInputStream::PeekDouble()
return Val; 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) void IInputStream::SeekToBoundary(unsigned long Boundary)
{ {
long Num = Boundary - (Tell() % Boundary); long Num = Boundary - (Tell() % Boundary);

View File

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

View File

@ -45,6 +45,12 @@ void IOutputStream::WriteDouble(double Val)
WriteBytes(&Val, 8); 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) void IOutputStream::WriteString(const std::string& rkVal)
{ {
for (unsigned int i = 0; i < rkVal.size(); i++) 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); 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) void IOutputStream::WriteToBoundary(unsigned long Boundary, unsigned char Fill)
{ {
long Num = Boundary - (Tell() % Boundary); long Num = Boundary - (Tell() % Boundary);

View File

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

View File

@ -22,6 +22,14 @@ float DegreesToRadians(float Deg);
float RadiansToDegrees(float Rad); 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> template<typename Type>
Type Max(const Type& rkA, const Type& rkB) Type Max(const Type& rkA, const Type& rkB)
{ {