41 # define CHUNK_ID_RIFF 0x52494646 42 # define CHUNK_ID_RIFX 0x52494658 43 # define CHUNK_ID_LIST 0x4C495354 45 # define LIST_TYPE_INFO 0x494E464F 46 # define CHUNK_ID_ICMT 0x49434D54 47 # define CHUNK_ID_ICOP 0x49434F50 48 # define CHUNK_ID_ICRD 0x49435244 49 # define CHUNK_ID_IENG 0x49454E47 50 # define CHUNK_ID_INAM 0x494E414D 51 # define CHUNK_ID_IPRD 0x49505244 52 # define CHUNK_ID_ISFT 0x49534654 54 # define CHUNK_ID_SMPL 0x736D706C 56 #else // little endian 57 # define CHUNK_ID_RIFF 0x46464952 58 # define CHUNK_ID_RIFX 0x58464952 59 # define CHUNK_ID_LIST 0x5453494C 61 # define LIST_TYPE_INFO 0x4F464E49 62 # define CHUNK_ID_ICMT 0x544D4349 63 # define CHUNK_ID_ICOP 0x504F4349 64 # define CHUNK_ID_ICRD 0x44524349 65 # define CHUNK_ID_IENG 0x474E4549 66 # define CHUNK_ID_INAM 0x4D414E49 67 # define CHUNK_ID_IPRD 0x44525049 68 # define CHUNK_ID_ISFT 0x54465349 70 # define CHUNK_ID_SMPL 0x6C706D73 72 #endif // WORDS_BIGENDIAN 74 #define CHUNK_HEADER_SIZE(fileOffsetSize) (4 + fileOffsetSize) 75 #define LIST_HEADER_SIZE(fileOffsetSize) (8 + fileOffsetSize) 76 #define RIFF_HEADER_SIZE(fileOffsetSize) (8 + fileOffsetSize) 104 typedef std::string String;
111 stream_mode_read = 0,
112 stream_mode_read_write = 1,
113 stream_mode_closed = 2
119 stream_end_reached = 1,
170 std::vector<progress_t>
subdivide(
int iSubtasks);
171 std::vector<progress_t>
subdivide(std::vector<float> vSubTaskPortions);
182 String GetChunkIDString()
const;
186 file_offset_t
GetSize()
const {
return ullCurrentChunkSize; }
188 file_offset_t GetPos()
const;
189 file_offset_t GetFilePos()
const;
190 file_offset_t SetPos(file_offset_t Where,
stream_whence_t Whence = stream_start);
191 file_offset_t RemainingBytes()
const;
193 file_offset_t Read(
void* pData, file_offset_t WordCount, file_offset_t WordSize);
194 file_offset_t ReadInt8(int8_t* pData, file_offset_t WordCount = 1);
195 file_offset_t ReadUint8(uint8_t* pData, file_offset_t WordCount = 1);
196 file_offset_t ReadInt16(int16_t* pData, file_offset_t WordCount = 1);
197 file_offset_t ReadUint16(uint16_t* pData, file_offset_t WordCount = 1);
198 file_offset_t ReadInt32(int32_t* pData, file_offset_t WordCount = 1);
199 file_offset_t ReadUint32(uint32_t* pData, file_offset_t WordCount = 1);
203 uint16_t ReadUint16();
205 uint32_t ReadUint32();
206 void ReadString(String& s,
int size);
207 file_offset_t Write(
void* pData, file_offset_t WordCount, file_offset_t WordSize);
208 file_offset_t WriteInt8(int8_t* pData, file_offset_t WordCount = 1);
209 file_offset_t WriteUint8(uint8_t* pData, file_offset_t WordCount = 1);
210 file_offset_t WriteInt16(int16_t* pData, file_offset_t WordCount = 1);
211 file_offset_t WriteUint16(uint16_t* pData, file_offset_t WordCount = 1);
212 file_offset_t WriteInt32(int32_t* pData, file_offset_t WordCount = 1);
213 file_offset_t WriteUint32(uint32_t* pData, file_offset_t WordCount = 1);
214 void* LoadChunkData();
215 void ReleaseChunkData();
216 void Resize(file_offset_t NewSize);
220 file_offset_t ullCurrentChunkSize;
221 file_offset_t ullNewChunkSize;
224 file_offset_t ullStartPos;
226 file_offset_t ullChunkDataSize;
228 file_offset_t ullPos;
229 mutable std::map<std::thread::id,file_offset_t> byThread;
230 mutable std::mutex mutex;
234 Chunk(
File* pFile,
List* pParent, uint32_t uiChunkID, file_offset_t ullBodySize);
235 void ReadHeader(file_offset_t filePos);
236 void WriteHeader(file_offset_t filePos);
237 file_offset_t ReadSceptical(
void* pData, file_offset_t WordCount, file_offset_t WordSize);
238 inline static String convertToString(uint32_t word) {
240 for (
int i = 0; i < 4; i++) {
241 uint8_t byte = *((uint8_t*)(&word) + i);
247 virtual file_offset_t RequiredPhysicalSize(
int fileOffsetSize);
248 virtual file_offset_t WriteChunk(file_offset_t ullWritePos, file_offset_t ullCurrentDataOffset,
progress_t* pProgress = NULL);
249 virtual void __resetPos();
253 file_offset_t& GetPosUnsafeRef();
263 List(
File* pFile, file_offset_t StartPos,
List* Parent);
264 String GetListTypeString()
const;
266 Chunk* GetSubChunkAt(
size_t pos);
267 Chunk* GetSubChunk(uint32_t ChunkID);
268 List* GetSubListAt(
size_t pos);
269 List* GetSubList(uint32_t ListType);
270 Chunk* GetFirstSubChunk() LIBGIG_DEPRECATED_API(
"Use GetSubChunkAt() instead.");
271 Chunk* GetNextSubChunk() LIBGIG_DEPRECATED_API(
"Use GetSubChunkAt() instead.");
272 List* GetFirstSubList() LIBGIG_DEPRECATED_API(
"Use GetSubListAt() instead.");
273 List* GetNextSubList() LIBGIG_DEPRECATED_API(
"Use GetSubListAt() instead.");
274 size_t CountSubChunks();
275 size_t CountSubChunks(uint32_t ChunkID);
276 size_t CountSubLists();
277 size_t CountSubLists(uint32_t ListType);
278 Chunk* AddSubChunk(uint32_t uiChunkID, file_offset_t ullBodySize);
279 List* AddSubList(uint32_t uiListType);
280 void DeleteSubChunk(
Chunk* pSubChunk);
282 void MoveSubChunk(
Chunk* pSrc,
List* pNewParent);
285 typedef std::map<uint32_t, RIFF::Chunk*> ChunkMap;
286 typedef std::vector<Chunk*> ChunkList;
287 typedef std::set<Chunk*> ChunkSet;
290 ChunkList* pSubChunks;
291 ChunkMap* pSubChunksMap;
292 ChunkList::iterator ChunksIterator;
293 ChunkList::iterator ListIterator;
297 void ReadHeader(file_offset_t filePos);
298 void WriteHeader(file_offset_t filePos);
299 void LoadSubChunks(
progress_t* pProgress = NULL);
300 void LoadSubChunksRecursively(
progress_t* pProgress = NULL);
301 virtual file_offset_t RequiredPhysicalSize(
int fileOffsetSize);
302 virtual file_offset_t WriteChunk(file_offset_t ullWritePos, file_offset_t ullCurrentDataOffset,
progress_t* pProgress = NULL);
303 virtual void __resetPos();
304 void DeleteChunkList();
322 typedef HANDLE Handle;
324 typedef FILE* Handle;
327 File(uint32_t FileType);
328 File(
const String& path);
333 String GetFileName()
const;
334 void SetFileName(
const String& path);
335 Handle FileHandle()
const;
338 file_offset_t GetCurrentFileSize()
const;
339 file_offset_t GetRequiredFileSize();
340 file_offset_t GetRequiredFileSize(
offset_size_t fileOffsetSize);
341 int GetFileOffsetSize()
const;
342 int GetRequiredFileOffsetSize();
343 bool IsIOPerThread()
const;
344 void SetIOPerThread(
bool enable);
346 virtual void Save(
progress_t* pProgress = NULL);
347 virtual void Save(
const String& path,
progress_t* pProgress = NULL);
355 struct IO : HandlePair {
357 mutable std::map<std::thread::id,HandlePair> byThread;
358 mutable std::mutex mutex;
367 Handle FileWriteHandle()
const;
368 HandlePair FileHandlePair()
const;
373 void __openExistingFile(
const String& path, uint32_t* FileType = NULL);
374 void ResizeFile(file_offset_t ullNewSize);
376 file_offset_t __GetFileSize(
int hFile)
const;
378 file_offset_t __GetFileSize(HANDLE hFile)
const;
380 file_offset_t __GetFileSize(FILE* hFile)
const;
382 int FileOffsetSizeFor(file_offset_t fileSize)
const;
384 HandlePair& FileHandlePairUnsafeRef();
385 bool SetModeInternal(
stream_mode_t NewMode,
bool* pResetPos);
402 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...
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.
int Handle
OS dependent type serving as file handle / descriptor for OS dependent file I/O operations.
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.
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.
Always use 64 bit offsets (even for files smaller than 4 GB).