40 # if defined(__cplusplus) && __cplusplus >= 201103L 41 # define OVERRIDE override 60 # include <sys/types.h> 61 # include <sys/stat.h> 66 #if defined _MSC_VER && _MSC_VER < 1600 68 typedef __int8 int8_t;
69 typedef __int16 int16_t;
70 typedef __int32 int32_t;
71 typedef __int64 int64_t;
72 typedef unsigned __int8 uint8_t;
73 typedef unsigned __int16 uint16_t;
74 typedef unsigned __int32 uint32_t;
75 typedef unsigned __int64 uint64_t;
81 # if (_WIN32 && !_WIN64) || (__GNUC__ && !(__x86_64__ || __ppc64__)) 82 # if _WIN32_WINNT < 0x0501 84 # define _WIN32_WINNT 0x0501 88 typedef unsigned int uint;
94 # define CHUNK_ID_RIFF 0x52494646 95 # define CHUNK_ID_RIFX 0x52494658 96 # define CHUNK_ID_LIST 0x4C495354 98 # define LIST_TYPE_INFO 0x494E464F 99 # define CHUNK_ID_ICMT 0x49434D54 100 # define CHUNK_ID_ICOP 0x49434F50 101 # define CHUNK_ID_ICRD 0x49435244 102 # define CHUNK_ID_IENG 0x49454E47 103 # define CHUNK_ID_INAM 0x494E414D 104 # define CHUNK_ID_IPRD 0x49505244 105 # define CHUNK_ID_ISFT 0x49534654 107 # define CHUNK_ID_SMPL 0x736D706C 109 #else // little endian 110 # define CHUNK_ID_RIFF 0x46464952 111 # define CHUNK_ID_RIFX 0x58464952 112 # define CHUNK_ID_LIST 0x5453494C 114 # define LIST_TYPE_INFO 0x4F464E49 115 # define CHUNK_ID_ICMT 0x544D4349 116 # define CHUNK_ID_ICOP 0x504F4349 117 # define CHUNK_ID_ICRD 0x44524349 118 # define CHUNK_ID_IENG 0x474E4549 119 # define CHUNK_ID_INAM 0x4D414E49 120 # define CHUNK_ID_IPRD 0x44525049 121 # define CHUNK_ID_ISFT 0x54465349 123 # define CHUNK_ID_SMPL 0x6C706D73 125 #endif // WORDS_BIGENDIAN 127 #define CHUNK_HEADER_SIZE(fileOffsetSize) (4 + fileOffsetSize) 128 #define LIST_HEADER_SIZE(fileOffsetSize) (8 + fileOffsetSize) 129 #define RIFF_HEADER_SIZE(fileOffsetSize) (8 + fileOffsetSize) 157 typedef std::string String;
164 stream_mode_read = 0,
165 stream_mode_read_write = 1,
166 stream_mode_closed = 2
172 stream_end_reached = 1,
223 std::vector<progress_t>
subdivide(
int iSubtasks);
224 std::vector<progress_t>
subdivide(std::vector<float> vSubTaskPortions);
235 String GetChunkIDString()
const;
239 file_offset_t
GetSize()
const {
return ullCurrentChunkSize; }
241 file_offset_t
GetPos()
const {
return ullPos; }
242 file_offset_t
GetFilePos()
const {
return ullStartPos + ullPos; }
243 file_offset_t SetPos(file_offset_t Where,
stream_whence_t Whence = stream_start);
244 file_offset_t RemainingBytes()
const;
246 file_offset_t Read(
void* pData, file_offset_t WordCount, file_offset_t WordSize);
247 file_offset_t ReadInt8(int8_t* pData, file_offset_t WordCount = 1);
248 file_offset_t ReadUint8(uint8_t* pData, file_offset_t WordCount = 1);
249 file_offset_t ReadInt16(int16_t* pData, file_offset_t WordCount = 1);
250 file_offset_t ReadUint16(uint16_t* pData, file_offset_t WordCount = 1);
251 file_offset_t ReadInt32(int32_t* pData, file_offset_t WordCount = 1);
252 file_offset_t ReadUint32(uint32_t* pData, file_offset_t WordCount = 1);
256 uint16_t ReadUint16();
258 uint32_t ReadUint32();
259 void ReadString(String& s,
int size);
260 file_offset_t Write(
void* pData, file_offset_t WordCount, file_offset_t WordSize);
261 file_offset_t WriteInt8(int8_t* pData, file_offset_t WordCount = 1);
262 file_offset_t WriteUint8(uint8_t* pData, file_offset_t WordCount = 1);
263 file_offset_t WriteInt16(int16_t* pData, file_offset_t WordCount = 1);
264 file_offset_t WriteUint16(uint16_t* pData, file_offset_t WordCount = 1);
265 file_offset_t WriteInt32(int32_t* pData, file_offset_t WordCount = 1);
266 file_offset_t WriteUint32(uint32_t* pData, file_offset_t WordCount = 1);
267 void* LoadChunkData();
268 void ReleaseChunkData();
269 void Resize(file_offset_t NewSize);
273 file_offset_t ullCurrentChunkSize;
274 file_offset_t ullNewChunkSize;
277 file_offset_t ullStartPos;
278 file_offset_t ullPos;
280 file_offset_t ullChunkDataSize;
283 Chunk(
File* pFile,
List* pParent, uint32_t uiChunkID, file_offset_t ullBodySize);
284 void ReadHeader(file_offset_t filePos);
285 void WriteHeader(file_offset_t filePos);
286 file_offset_t ReadSceptical(
void* pData, file_offset_t WordCount, file_offset_t WordSize);
287 inline static String convertToString(uint32_t word) {
289 for (
int i = 0; i < 4; i++) {
290 uint8_t byte = *((uint8_t*)(&word) + i);
296 virtual file_offset_t RequiredPhysicalSize(
int fileOffsetSize);
297 virtual file_offset_t WriteChunk(file_offset_t ullWritePos, file_offset_t ullCurrentDataOffset,
progress_t* pProgress = NULL);
298 virtual void __resetPos();
310 List(
File* pFile, file_offset_t StartPos,
List* Parent);
311 String GetListTypeString()
const;
313 Chunk* GetSubChunk(uint32_t ChunkID);
314 List* GetSubList(uint32_t ListType);
315 Chunk* GetFirstSubChunk();
316 Chunk* GetNextSubChunk();
317 List* GetFirstSubList();
318 List* GetNextSubList();
319 size_t CountSubChunks();
320 size_t CountSubChunks(uint32_t ChunkID);
321 size_t CountSubLists();
322 size_t CountSubLists(uint32_t ListType);
323 Chunk* AddSubChunk(uint32_t uiChunkID, file_offset_t ullBodySize);
324 List* AddSubList(uint32_t uiListType);
325 void DeleteSubChunk(
Chunk* pSubChunk);
327 void MoveSubChunk(
Chunk* pSrc,
List* pNewParent);
330 typedef std::map<uint32_t, RIFF::Chunk*> ChunkMap;
331 typedef std::list<Chunk*> ChunkList;
332 typedef std::set<Chunk*> ChunkSet;
335 ChunkList* pSubChunks;
336 ChunkMap* pSubChunksMap;
337 ChunkList::iterator ChunksIterator;
338 ChunkList::iterator ListIterator;
342 void ReadHeader(file_offset_t filePos);
343 void WriteHeader(file_offset_t filePos);
344 void LoadSubChunks(
progress_t* pProgress = NULL);
345 void LoadSubChunksRecursively(
progress_t* pProgress = NULL);
346 virtual file_offset_t RequiredPhysicalSize(
int fileOffsetSize);
347 virtual file_offset_t WriteChunk(file_offset_t ullWritePos, file_offset_t ullCurrentDataOffset,
progress_t* pProgress = NULL);
348 virtual void __resetPos();
349 void DeleteChunkList();
360 File(uint32_t FileType);
361 File(
const String& path);
366 String GetFileName()
const;
367 void SetFileName(
const String& path);
370 file_offset_t GetCurrentFileSize()
const;
371 file_offset_t GetRequiredFileSize();
372 file_offset_t GetRequiredFileSize(
offset_size_t fileOffsetSize);
373 int GetFileOffsetSize()
const;
374 int GetRequiredFileOffsetSize();
376 virtual void Save(
progress_t* pProgress = NULL);
377 virtual void Save(
const String& path,
progress_t* pProgress = NULL);
402 void __openExistingFile(
const String& path, uint32_t* FileType = NULL);
403 void ResizeFile(file_offset_t ullNewSize);
405 file_offset_t __GetFileSize(
int hFile)
const;
407 file_offset_t __GetFileSize(HANDLE hFile)
const;
409 file_offset_t __GetFileSize(FILE* hFile)
const;
411 int FileOffsetSizeFor(file_offset_t fileSize)
const;
429 static String assemble(String format, va_list arg);
int FileOffsetSize
Size of file offsets (in bytes) when this file was opened (or saved the last time).
stream_whence_t
File stream position dependent to these relations.
String libraryName()
Returns the name of this C++ library.
file_offset_t GetSize() const
Chunk size in bytes (without header, thus the chunk data body)
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.
String libraryVersion()
Returns version of this C++ library.
std::vector< progress_t > subdivide(int iSubtasks)
Divides this progress task into the requested amount of equal weighted sub-progress tasks and returns...
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
stream_mode_t
Whether file stream is open in read or in read/write mode.
List * GetParent() const
Returns pointer to the chunk's parent list chunk.
offset_size_t
Size of RIFF file offsets used in all RIFF chunks' headers.
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!
layout_t
General RIFF chunk structure of a RIFF file.
uint32_t GetChunkID() const
Chunk ID in unsigned integer representation.
void * custom
This pointer can be used for arbitrary data.
Used for indicating the progress of a certain task.
int hFileRead
handle / descriptor for reading from file
uint32_t GetListType() const
Returns unsigned integer representation of the list's ID.
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.
file_offset_t GetNewSize() const
New chunk size if it was modified with Resize(), otherwise value returned will be equal to GetSize()...
Always use 32 bit offsets (even for files larger than 4 GB).
File * GetFile() const
Returns pointer to the chunk's File object.
float __range_max
Only for internal usage, do not modify!
Will be thrown whenever an error occurs while handling a RIFF file.
file_offset_t GetFilePos() const
Current, actual offset in file of current chunk data body read/write position.
Always use 64 bit offsets (even for files smaller than 4 GB).
file_offset_t GetPos() const
Position within the chunk data body (starting with 0).