50 # include <sys/types.h> 51 # include <sys/stat.h> 58 typedef __int8 int8_t;
59 typedef __int16 int16_t;
60 typedef __int32 int32_t;
61 typedef __int64 int64_t;
62 typedef unsigned __int8 uint8_t;
63 typedef unsigned __int16 uint16_t;
64 typedef unsigned __int32 uint32_t;
65 typedef unsigned __int64 uint64_t;
71 # if (_WIN32 && !_WIN64) || (__GNUC__ && !(__x86_64__ || __ppc64__)) 72 # define _WIN32_WINNT 0x0501 75 typedef unsigned int uint;
81 # define CHUNK_ID_RIFF 0x52494646 82 # define CHUNK_ID_RIFX 0x52494658 83 # define CHUNK_ID_LIST 0x4C495354 85 # define LIST_TYPE_INFO 0x494E464F 86 # define CHUNK_ID_ICMT 0x49434D54 87 # define CHUNK_ID_ICOP 0x49434F50 88 # define CHUNK_ID_ICRD 0x49435244 89 # define CHUNK_ID_IENG 0x49454E47 90 # define CHUNK_ID_INAM 0x494E414D 91 # define CHUNK_ID_IPRD 0x49505244 92 # define CHUNK_ID_ISFT 0x49534654 94 # define CHUNK_ID_SMPL 0x736D706C 96 #else // little endian 97 # define CHUNK_ID_RIFF 0x46464952 98 # define CHUNK_ID_RIFX 0x58464952 99 # define CHUNK_ID_LIST 0x5453494C 101 # define LIST_TYPE_INFO 0x4F464E49 102 # define CHUNK_ID_ICMT 0x544D4349 103 # define CHUNK_ID_ICOP 0x504F4349 104 # define CHUNK_ID_ICRD 0x44524349 105 # define CHUNK_ID_IENG 0x474E4549 106 # define CHUNK_ID_INAM 0x4D414E49 107 # define CHUNK_ID_IPRD 0x44525049 108 # define CHUNK_ID_ISFT 0x54465349 110 # define CHUNK_ID_SMPL 0x6C706D73 112 #endif // WORDS_BIGENDIAN 114 #define CHUNK_HEADER_SIZE(fileOffsetSize) (4 + fileOffsetSize) 115 #define LIST_HEADER_SIZE(fileOffsetSize) (8 + fileOffsetSize) 116 #define RIFF_HEADER_SIZE(fileOffsetSize) (8 + fileOffsetSize) 144 typedef std::string
String;
220 String GetChunkIDString()
const;
224 file_offset_t
GetSize()
const {
return ullCurrentChunkSize; }
226 file_offset_t
GetPos()
const {
return ullPos; }
227 file_offset_t
GetFilePos()
const {
return ullStartPos + ullPos; }
229 file_offset_t RemainingBytes()
const;
231 file_offset_t Read(
void* pData, file_offset_t WordCount, file_offset_t WordSize);
232 file_offset_t ReadInt8(int8_t* pData, file_offset_t WordCount = 1);
233 file_offset_t ReadUint8(uint8_t* pData, file_offset_t WordCount = 1);
234 file_offset_t ReadInt16(int16_t* pData, file_offset_t WordCount = 1);
235 file_offset_t ReadUint16(uint16_t* pData, file_offset_t WordCount = 1);
236 file_offset_t ReadInt32(int32_t* pData, file_offset_t WordCount = 1);
237 file_offset_t ReadUint32(uint32_t* pData, file_offset_t WordCount = 1);
241 uint16_t ReadUint16();
243 uint32_t ReadUint32();
244 void ReadString(String& s,
int size);
245 file_offset_t Write(
void* pData, file_offset_t WordCount, file_offset_t WordSize);
246 file_offset_t WriteInt8(int8_t* pData, file_offset_t WordCount = 1);
247 file_offset_t WriteUint8(uint8_t* pData, file_offset_t WordCount = 1);
248 file_offset_t WriteInt16(int16_t* pData, file_offset_t WordCount = 1);
249 file_offset_t WriteUint16(uint16_t* pData, file_offset_t WordCount = 1);
250 file_offset_t WriteInt32(int32_t* pData, file_offset_t WordCount = 1);
251 file_offset_t WriteUint32(uint32_t* pData, file_offset_t WordCount = 1);
252 void* LoadChunkData();
253 void ReleaseChunkData();
254 void Resize(file_offset_t NewSize);
268 Chunk(
File* pFile,
List* pParent, uint32_t uiChunkID, file_offset_t ullBodySize);
269 void ReadHeader(file_offset_t filePos);
270 void WriteHeader(file_offset_t filePos);
271 file_offset_t ReadSceptical(
void* pData, file_offset_t WordCount, file_offset_t WordSize);
274 for (
int i = 0; i < 4; i++) {
275 uint8_t byte = *((uint8_t*)(&word) + i);
281 virtual file_offset_t RequiredPhysicalSize(
int fileOffsetSize);
282 virtual file_offset_t WriteChunk(file_offset_t ullWritePos, file_offset_t ullCurrentDataOffset,
progress_t* pProgress = NULL);
283 virtual void __resetPos();
295 List(
File* pFile, file_offset_t StartPos,
List* Parent);
296 String GetListTypeString()
const;
298 Chunk* GetSubChunk(uint32_t ChunkID);
299 List* GetSubList(uint32_t ListType);
300 Chunk* GetFirstSubChunk();
301 Chunk* GetNextSubChunk();
302 List* GetFirstSubList();
303 List* GetNextSubList();
304 size_t CountSubChunks();
305 size_t CountSubChunks(uint32_t ChunkID);
306 size_t CountSubLists();
307 size_t CountSubLists(uint32_t ListType);
308 Chunk* AddSubChunk(uint32_t uiChunkID, file_offset_t ullBodySize);
309 List* AddSubList(uint32_t uiListType);
310 void DeleteSubChunk(
Chunk* pSubChunk);
312 void MoveSubChunk(
Chunk* pSrc,
List* pNewParent);
327 void ReadHeader(file_offset_t filePos);
328 void WriteHeader(file_offset_t filePos);
329 void LoadSubChunks(
progress_t* pProgress = NULL);
330 void LoadSubChunksRecursively(
progress_t* pProgress = NULL);
331 virtual file_offset_t RequiredPhysicalSize(
int fileOffsetSize);
332 virtual file_offset_t WriteChunk(file_offset_t ullWritePos, file_offset_t ullCurrentDataOffset,
progress_t* pProgress = NULL);
333 virtual void __resetPos();
334 void DeleteChunkList();
345 File(uint32_t FileType);
346 File(
const String& path);
351 String GetFileName()
const;
352 void SetFileName(
const String& path);
355 file_offset_t GetCurrentFileSize()
const;
356 file_offset_t GetRequiredFileSize();
357 file_offset_t GetRequiredFileSize(
offset_size_t fileOffsetSize);
358 int GetFileOffsetSize()
const;
359 int GetRequiredFileOffsetSize();
361 virtual void Save(
progress_t* pProgress = NULL);
362 virtual void Save(
const String& path,
progress_t* pProgress = NULL);
387 void __openExistingFile(
const String& path, uint32_t* FileType = NULL);
388 void ResizeFile(file_offset_t ullNewSize);
390 file_offset_t __GetFileSize(
int hFile)
const;
392 file_offset_t __GetFileSize(HANDLE hFile)
const;
394 file_offset_t __GetFileSize(FILE* hFile)
const;
396 int FileOffsetSizeFor(file_offset_t fileSize)
const;
file_offset_t GetFilePos() const
Current, actual offset of chunk data body start in file.
file_offset_t GetNewSize() const
New chunk size if it was modified with Resize(), otherwise value returned will be equal to GetSize()...
int FileOffsetSize
Size of file offsets (in bytes) when this file was opened (or saved the last time).
File * GetFile() const
Returns pointer to the chunk's File object.
stream_whence_t
File stream position dependent to these relations.
String libraryName()
Returns the name of this C++ library.
file_offset_t ullCurrentChunkSize
static String convertToString(uint32_t word)
layout_t Layout
An ordinary RIFF file is always set to layout_standard.
void(* callback)(progress_t *)
Callback function pointer which has to be assigned to a function for progress notification.
stream_state_t
Current state of the file stream.
List * GetParent() const
Returns pointer to the chunk's parent list chunk.
String libraryVersion()
Returns version of this C++ library.
Use 32 bit offsets for files smaller than 4 GB, use 64 bit offsets for files equal or larger than 4 G...
int hFileWrite
handle / descriptor for writing to (some) file
file_offset_t GetPos() const
Position within the chunk data body (starting with 0).
Exception(String Message)
stream_mode_t
Whether file stream is open in read or in read/write mode.
std::list< Chunk * > ChunkList
file_offset_t ullChunkDataSize
std::set< Chunk * > ChunkSet
file_offset_t GetSize() const
Chunk size in bytes (without header, thus the chunk data body)
offset_size_t
Size of RIFF file offsets used in all RIFF chunks' headers.
ChunkList::iterator ListIterator
uint64_t file_offset_t
Type used by libgig for handling file positioning during file I/O tasks.
float __range_min
Only for internal usage, do not modify!
offset_size_t FileOffsetPreference
file_offset_t ullStartPos
layout_t
General RIFF chunk structure of a RIFF file.
uint32_t GetChunkID() const
Chunk ID in unsigned integer representation.
ChunkList::iterator ChunksIterator
void * custom
This pointer can be used for arbitrary data.
Used for indicating the progress of a certain task.
file_offset_t ullNewChunkSize
int hFileRead
handle / descriptor for reading from file
Not a "real" RIFF file: First chunk in file is an ordinary data chunk, not a List chunk...
endian_t
Alignment of data bytes in memory (system dependant).
Standard RIFF file layout: First chunk in file is a List chunk which contains all other chunks and th...
RIFF specific classes and definitions.
float factor
Reflects current progress as value between 0.0 and 1.0.
Always use 32 bit offsets (even for files larger than 4 GB).
float __range_max
Only for internal usage, do not modify!
Will be thrown whenever an error occurs while handling a RIFF file.
Always use 64 bit offsets (even for files smaller than 4 GB).
uint32_t GetListType() const
Returns unsigned integer representation of the list's ID.
std::map< uint32_t, RIFF::Chunk * > ChunkMap