Initial
This commit is contained in:
121
sample/ChunkID.hpp
Normal file
121
sample/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);
|
||||
bool operator==(const ChunkID &someChunkID)const;
|
||||
bool operator==(const String &chunkIDString)const;
|
||||
bool ChunkID::write(MemFile &memFile)const;
|
||||
bool ChunkID::read(FileHandle &handle);
|
||||
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
|
||||
bool ChunkID::operator==(const ChunkID &someChunkID)const
|
||||
{
|
||||
return (!::memcmp(mChunkID,someChunkID.mChunkID,sizeof(mChunkID))?true:false);
|
||||
}
|
||||
|
||||
inline
|
||||
bool ChunkID::operator==(const String &chunkIDString)const
|
||||
{
|
||||
return chunkID()==chunkIDString;
|
||||
}
|
||||
|
||||
inline
|
||||
bool ChunkID::write(MemFile &memFile)const
|
||||
{
|
||||
if(!memFile.write((char*)mChunkID,sizeof(mChunkID)))return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
inline
|
||||
bool ChunkID::read(FileHandle &handle)
|
||||
{
|
||||
if(!handle.read((BYTE*)mChunkID,sizeof(mChunkID)))return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
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