Initial
This commit is contained in:
121
sample/holdii/ChunkID.hpp
Normal file
121
sample/holdii/ChunkID.hpp
Normal file
@@ -0,0 +1,121 @@
|
||||
#ifndef _SAMPLE_CHUNKID_HPP_
|
||||
#define _SAMPLE_CHUNKID_HPP_
|
||||
#ifndef _COMMON_WINDOWS_HPP_
|
||||
#include <common/windows.hpp>
|
||||
#endif
|
||||
#ifndef _COMMON_STRING_HPP_
|
||||
#include <common/string.hpp>
|
||||
#endif
|
||||
#ifndef _COMMON_MEMFILE_HPP_
|
||||
#include <common/memfile.hpp>
|
||||
#endif
|
||||
#ifndef _COMMON_OPENFILE_HPP_
|
||||
#include <common/openfile.hpp>
|
||||
#endif
|
||||
|
||||
class ChunkID
|
||||
{
|
||||
public:
|
||||
ChunkID(void);
|
||||
ChunkID(const ChunkID &someChunkID);
|
||||
virtual ~ChunkID();
|
||||
ChunkID &operator=(const ChunkID &someChunkID);
|
||||
ChunkID &operator=(String chunkIDString);
|
||||
WORD operator==(const ChunkID &someChunkID)const;
|
||||
WORD operator==(const String &chunkIDString)const;
|
||||
MemFile &ChunkID::operator>>(MemFile &someMemFile)const;
|
||||
FileHandle &ChunkID::operator<<(FileHandle &someFileHandle);
|
||||
String chunkID(void)const;
|
||||
WORD size(void)const;
|
||||
String toString(void)const;
|
||||
private:
|
||||
enum {MaxLength=4};
|
||||
void initChunk(void);
|
||||
|
||||
char mChunkID[MaxLength];
|
||||
};
|
||||
|
||||
inline
|
||||
ChunkID::ChunkID(void)
|
||||
{
|
||||
initChunk();
|
||||
}
|
||||
|
||||
inline
|
||||
ChunkID::ChunkID(const ChunkID &someChunkID)
|
||||
{
|
||||
initChunk();
|
||||
*this=someChunkID;
|
||||
}
|
||||
|
||||
inline
|
||||
ChunkID::~ChunkID()
|
||||
{
|
||||
}
|
||||
|
||||
inline
|
||||
ChunkID &ChunkID::operator=(const ChunkID &someChunkID)
|
||||
{
|
||||
::memcpy(mChunkID,someChunkID.mChunkID,sizeof(mChunkID));
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline
|
||||
ChunkID &ChunkID::operator=(String chunkIDString)
|
||||
{
|
||||
if(chunkIDString.length()>sizeof(mChunkID))chunkIDString.length(sizeof(mChunkID));
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline
|
||||
WORD ChunkID::operator==(const ChunkID &someChunkID)const
|
||||
{
|
||||
return (!::memcmp(mChunkID,someChunkID.mChunkID,sizeof(mChunkID))?TRUE:FALSE);
|
||||
}
|
||||
|
||||
inline
|
||||
WORD ChunkID::operator==(const String &chunkIDString)const
|
||||
{
|
||||
return chunkID()==chunkIDString;
|
||||
}
|
||||
|
||||
inline
|
||||
MemFile &ChunkID::operator>>(MemFile &someMemFile)const
|
||||
{
|
||||
someMemFile.write((char*)mChunkID,sizeof(mChunkID));
|
||||
return someMemFile;
|
||||
}
|
||||
|
||||
inline
|
||||
FileHandle &ChunkID::operator<<(FileHandle &someFileHandle)
|
||||
{
|
||||
someFileHandle.read((BYTE*)mChunkID,sizeof(mChunkID));
|
||||
return someFileHandle;
|
||||
}
|
||||
|
||||
inline
|
||||
String ChunkID::chunkID(void)const
|
||||
{
|
||||
String chunkString;
|
||||
::memcpy(chunkString,mChunkID,sizeof(mChunkID));
|
||||
return chunkString;
|
||||
}
|
||||
|
||||
inline
|
||||
WORD ChunkID::size(void)const
|
||||
{
|
||||
return sizeof(mChunkID);
|
||||
}
|
||||
|
||||
inline
|
||||
void ChunkID::initChunk(void)
|
||||
{
|
||||
::memset(mChunkID,0,sizeof(mChunkID));
|
||||
}
|
||||
|
||||
inline
|
||||
String ChunkID::toString(void)const
|
||||
{
|
||||
return String("<CHUNKID> ChunkID=")+String(mChunkID).quotes()+String("</CHUNKID>");
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user