Compare operators for CFourCC + reorganization

This commit is contained in:
parax0 2015-07-26 20:54:55 -04:00
parent 66e8c2ebcb
commit e5048ca8d2
2 changed files with 83 additions and 79 deletions

View File

@ -1,11 +1,9 @@
#include "CFourCC.h" #include "CFourCC.h"
// ************ CONSTRUCTORS ************
CFourCC::CFourCC() CFourCC::CFourCC()
{ {
FourCC[0] = 0; memset(mFourCC, 0, 4);
FourCC[1] = 0;
FourCC[2] = 0;
FourCC[3] = 0;
} }
CFourCC::CFourCC(const char *src) CFourCC::CFourCC(const char *src)
@ -18,81 +16,30 @@ CFourCC::CFourCC(const std::string& src)
*this = src; *this = src;
} }
CFourCC::CFourCC(long src) CFourCC::CFourCC(u32 src)
{ {
*this = src; *this = src;
} }
CFourCC::CFourCC(CInputStream& src) CFourCC::CFourCC(CInputStream& src)
{ {
src.ReadBytes(&FourCC[0], 4); src.ReadBytes(&mFourCC[0], 4);
} }
// ************ FUNCTIONALITY ************
void CFourCC::Write(COutputStream &Output) void CFourCC::Write(COutputStream &Output)
{ {
Output.WriteBytes(FourCC, 4); Output.WriteBytes(mFourCC, 4);
} }
CFourCC& CFourCC::operator=(const char *src) u32 CFourCC::ToLong() const
{ {
return mFourCC[0] << 24 | mFourCC[1] << 16 | mFourCC[2] << 8 | mFourCC[3];
memcpy(&FourCC[0], src, 4);
return *this;
}
CFourCC& CFourCC::operator=(const std::string& src)
{
memcpy(&FourCC[0], src.c_str(), 4);
return *this;
}
CFourCC& CFourCC::operator=(long src)
{
FourCC[0] = (src >> 24) & 0xFF;
FourCC[1] = (src >> 16) & 0xFF;
FourCC[2] = (src >> 8) & 0xFF;
FourCC[3] = (src >> 0) & 0xFF;
return *this;
}
bool CFourCC::operator==(const CFourCC& other) const
{
return ((FourCC[0] == other.FourCC[0]) && (FourCC[1] == other.FourCC[1]) && (FourCC[2] == other.FourCC[2]) && (FourCC[3] == other.FourCC[3]));
}
bool CFourCC::operator!=(const CFourCC& other) const
{
return (!(*this == other));
}
bool CFourCC::operator==(const char *other) const
{
return (*this == CFourCC(other));
}
bool CFourCC::operator!=(const char *other) const
{
return (!(*this == other));
}
bool CFourCC::operator==(const long other) const
{
return (*this == CFourCC(other));
}
bool CFourCC::operator!=(const long other) const
{
return (!(*this == other));
}
long CFourCC::ToLong() const
{
return FourCC[0] << 24 | FourCC[1] << 16 | FourCC[2] << 8 | FourCC[3];
} }
std::string CFourCC::ToString() const std::string CFourCC::ToString() const
{ {
return std::string(FourCC, 4); return std::string(mFourCC, 4);
} }
CFourCC CFourCC::ToUpper() const CFourCC CFourCC::ToUpper() const
@ -101,11 +48,63 @@ CFourCC CFourCC::ToUpper() const
for (int c = 0; c < 4; c++) for (int c = 0; c < 4; c++)
{ {
if ((FourCC[c] >= 0x61) && (FourCC[c] <= 0x7A)) if ((mFourCC[c] >= 0x61) && (mFourCC[c] <= 0x7A))
Out.FourCC[c] = FourCC[c] - 0x20; Out.mFourCC[c] = mFourCC[c] - 0x20;
else else
Out.FourCC[c] = FourCC[c]; Out.mFourCC[c] = mFourCC[c];
} }
return Out; return Out;
} }
// ************ OPERATORS ************
CFourCC& CFourCC::operator=(const char *src)
{
memcpy(&mFourCC[0], src, 4);
return *this;
}
CFourCC& CFourCC::operator=(const std::string& src)
{
memcpy(&mFourCC[0], src.c_str(), 4);
return *this;
}
CFourCC& CFourCC::operator=(u32 src)
{
mFourCC[0] = (src >> 24) & 0xFF;
mFourCC[1] = (src >> 16) & 0xFF;
mFourCC[2] = (src >> 8) & 0xFF;
mFourCC[3] = (src >> 0) & 0xFF;
return *this;
}
bool CFourCC::operator==(const CFourCC& other) const
{
return ((mFourCC[0] == other.mFourCC[0]) && (mFourCC[1] == other.mFourCC[1]) && (mFourCC[2] == other.mFourCC[2]) && (mFourCC[3] == other.mFourCC[3]));
}
bool CFourCC::operator!=(const CFourCC& other) const
{
return (!(*this == other));
}
bool CFourCC::operator>(const CFourCC& other) const
{
return (ToLong() > other.ToLong());
}
bool CFourCC::operator>=(const CFourCC& other) const
{
return (ToLong() >= other.ToLong());
}
bool CFourCC::operator<(const CFourCC& other) const
{
return (ToLong() < other.ToLong());
}
bool CFourCC::operator<=(const CFourCC& other) const
{
return (ToLong() <= other.ToLong());
}

View File

@ -1,34 +1,39 @@
#ifndef CFOURCC_H #ifndef CFOURCC_H
#define CFOURCC_H #define CFOURCC_H
#include "types.h"
#include <FileIO/CInputStream.h> #include <FileIO/CInputStream.h>
#include <FileIO/COutputStream.h> #include <FileIO/COutputStream.h>
#include <string> #include <string>
class CFourCC class CFourCC
{ {
char FourCC[4]; char mFourCC[4];
public: public:
// Constructors
CFourCC(); CFourCC();
CFourCC(const char *src); CFourCC(const char *src);
CFourCC(const std::string& src); CFourCC(const std::string& src);
CFourCC(long src); CFourCC(u32 src);
CFourCC(CInputStream& src); CFourCC(CInputStream& src);
// Functionality
void Write(COutputStream& Output); void Write(COutputStream& Output);
u32 ToLong() const;
CFourCC& operator=(const char *src);
CFourCC& operator=(const std::string& src);
CFourCC& operator=(long src);
bool operator==(const CFourCC& other) const;
bool operator!=(const CFourCC& other) const;
bool operator==(const char *other) const;
bool operator!=(const char *other) const;
bool operator==(const long other) const;
bool operator!=(const long other) const;
long ToLong() const;
std::string ToString() const; std::string ToString() const;
CFourCC ToUpper() const; CFourCC ToUpper() const;
// Operators
CFourCC& operator=(const char *src);
CFourCC& operator=(const std::string& src);
CFourCC& operator=(u32 src);
bool operator==(const CFourCC& other) const;
bool operator!=(const CFourCC& other) const;
bool operator>(const CFourCC& other) const;
bool operator>=(const CFourCC& other) const;
bool operator<(const CFourCC& other) const;
bool operator<=(const CFourCC& other) const;
}; };
#endif // CFOURCC_H #endif // CFOURCC_H