2015-07-26 21:39:49 +00:00
|
|
|
#include "CFourCC.h"
|
|
|
|
|
2015-07-27 00:54:55 +00:00
|
|
|
// ************ CONSTRUCTORS ************
|
2015-07-26 21:39:49 +00:00
|
|
|
CFourCC::CFourCC()
|
|
|
|
{
|
2015-07-27 00:54:55 +00:00
|
|
|
memset(mFourCC, 0, 4);
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CFourCC::CFourCC(const char *src)
|
|
|
|
{
|
|
|
|
*this = src;
|
|
|
|
}
|
|
|
|
|
|
|
|
CFourCC::CFourCC(const std::string& src)
|
|
|
|
{
|
|
|
|
*this = src;
|
|
|
|
}
|
|
|
|
|
2015-07-27 00:54:55 +00:00
|
|
|
CFourCC::CFourCC(u32 src)
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
|
|
|
*this = src;
|
|
|
|
}
|
|
|
|
|
|
|
|
CFourCC::CFourCC(CInputStream& src)
|
|
|
|
{
|
2015-07-27 00:54:55 +00:00
|
|
|
src.ReadBytes(&mFourCC[0], 4);
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
|
2015-07-27 00:54:55 +00:00
|
|
|
// ************ FUNCTIONALITY ************
|
2015-07-26 21:39:49 +00:00
|
|
|
void CFourCC::Write(COutputStream &Output)
|
|
|
|
{
|
2015-07-27 00:54:55 +00:00
|
|
|
Output.WriteBytes(mFourCC, 4);
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
|
2015-07-27 00:54:55 +00:00
|
|
|
u32 CFourCC::ToLong() const
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
2015-07-27 00:54:55 +00:00
|
|
|
return mFourCC[0] << 24 | mFourCC[1] << 16 | mFourCC[2] << 8 | mFourCC[3];
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
|
2015-07-27 00:54:55 +00:00
|
|
|
std::string CFourCC::ToString() const
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
2015-07-27 00:54:55 +00:00
|
|
|
return std::string(mFourCC, 4);
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
|
2015-07-27 00:54:55 +00:00
|
|
|
CFourCC CFourCC::ToUpper() const
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
2015-07-27 00:54:55 +00:00
|
|
|
CFourCC Out;
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-07-27 00:54:55 +00:00
|
|
|
for (int c = 0; c < 4; c++)
|
|
|
|
{
|
|
|
|
if ((mFourCC[c] >= 0x61) && (mFourCC[c] <= 0x7A))
|
|
|
|
Out.mFourCC[c] = mFourCC[c] - 0x20;
|
|
|
|
else
|
|
|
|
Out.mFourCC[c] = mFourCC[c];
|
|
|
|
}
|
|
|
|
|
|
|
|
return Out;
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
|
2015-07-27 00:54:55 +00:00
|
|
|
// ************ OPERATORS ************
|
|
|
|
CFourCC& CFourCC::operator=(const char *src)
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
2015-07-27 00:54:55 +00:00
|
|
|
memcpy(&mFourCC[0], src, 4);
|
|
|
|
return *this;
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
|
2015-07-27 00:54:55 +00:00
|
|
|
CFourCC& CFourCC::operator=(const std::string& src)
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
2015-07-27 00:54:55 +00:00
|
|
|
memcpy(&mFourCC[0], src.c_str(), 4);
|
|
|
|
return *this;
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
|
2015-07-27 00:54:55 +00:00
|
|
|
CFourCC& CFourCC::operator=(u32 src)
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
2015-07-27 00:54:55 +00:00
|
|
|
mFourCC[0] = (src >> 24) & 0xFF;
|
|
|
|
mFourCC[1] = (src >> 16) & 0xFF;
|
|
|
|
mFourCC[2] = (src >> 8) & 0xFF;
|
|
|
|
mFourCC[3] = (src >> 0) & 0xFF;
|
|
|
|
return *this;
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
|
2015-07-27 00:54:55 +00:00
|
|
|
bool CFourCC::operator==(const CFourCC& other) const
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
2015-07-27 00:54:55 +00:00
|
|
|
return ((mFourCC[0] == other.mFourCC[0]) && (mFourCC[1] == other.mFourCC[1]) && (mFourCC[2] == other.mFourCC[2]) && (mFourCC[3] == other.mFourCC[3]));
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
|
2015-07-27 00:54:55 +00:00
|
|
|
bool CFourCC::operator!=(const CFourCC& other) const
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
|
|
|
return (!(*this == other));
|
|
|
|
}
|
|
|
|
|
2015-07-27 00:54:55 +00:00
|
|
|
bool CFourCC::operator>(const CFourCC& other) const
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
2015-07-27 00:54:55 +00:00
|
|
|
return (ToLong() > other.ToLong());
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
|
2015-07-27 00:54:55 +00:00
|
|
|
bool CFourCC::operator>=(const CFourCC& other) const
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
2015-07-27 00:54:55 +00:00
|
|
|
return (ToLong() >= other.ToLong());
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
|
2015-07-27 00:54:55 +00:00
|
|
|
bool CFourCC::operator<(const CFourCC& other) const
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
2015-07-27 00:54:55 +00:00
|
|
|
return (ToLong() < other.ToLong());
|
|
|
|
}
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-07-27 00:54:55 +00:00
|
|
|
bool CFourCC::operator<=(const CFourCC& other) const
|
|
|
|
{
|
|
|
|
return (ToLong() <= other.ToLong());
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
2015-07-27 20:17:22 +00:00
|
|
|
|
|
|
|
char CFourCC::operator[](int index)
|
|
|
|
{
|
|
|
|
return mFourCC[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
const char CFourCC::operator[](int index) const
|
|
|
|
{
|
|
|
|
return mFourCC[index];
|
|
|
|
}
|