2 * \file storage_chunks.h
3 * \brief CStorageChunks
4 * \date 2012-08-18 09:20GMT
5 * \author Jan Boon (Kaetemi)
10 * Copyright (C) 2012 by authors
12 * This file is part of RYZOM CORE PIPELINE.
13 * RYZOM CORE PIPELINE is free software: you can redistribute it
14 * and/or modify it under the terms of the GNU Affero General Public
15 * License as published by the Free Software Foundation, either
16 * version 3 of the License, or (at your option) any later version.
18 * RYZOM CORE PIPELINE is distributed in the hope that it will be
19 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
20 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Affero General Public License for more details.
23 * You should have received a copy of the GNU Affero General Public
24 * License along with RYZOM CORE PIPELINE. If not, see
25 * <http://www.gnu.org/licenses/>.
28 #ifndef PIPELINE_STORAGE_CHUNKS_H
29 #define PIPELINE_STORAGE_CHUNKS_H
30 #include <nel/misc/types_nl.h>
35 #include <nel/misc/stream.h>
43 * \brief CStorageChunks
44 * \date 2012-08-18 09:20GMT
45 * \author Jan Boon (Kaetemi)
53 // Size of the chunk header, 6 for 32 bit, 14 for 64 bit
55 // Where the header starts
60 // Size including header size
63 inline sint32
getSizeWithHeader() const { return (sint32
)(Size
& 0x7FFFFFFF); }
64 inline sint32
getSize() const { return getSizeWithHeader() - (sint32
)HeaderSize
; }
65 inline bool isContainer() const { return (Size
& 0x80000000) == 0x80000000; }
66 inline sint32
endOfChunk() const { return OffsetBegin
+ getSizeWithHeader(); }
67 inline sint32
getDataBegin() const { return OffsetBegin
+ (sint32
)HeaderSize
; }
71 CStorageChunks(NLMISC::IStream
&stream
, sint64 size
= 0);
72 virtual ~CStorageChunks();
74 // Returns true if there's another chunk, false if no more chunks in this container or if the current chunk is not a container
76 // Reads and skips chunks until the one with given id is found, or writes a chunk with this id
77 bool enterChunk(uint16 id
, bool container
);
78 // Returns the number of skipped bytes in read more, returns chunk size including header in write mode
81 inline bool is64Bit() const { return m_Is64Bit
; }
82 inline void set64Bit(bool enabled
= true) { m_Is64Bit
= enabled
; }
84 inline uint16
getChunkId() const { return currentChunk()->Id
; }
85 inline sint32
getChunkSize() const { return currentChunk()->getSize(); }
86 inline bool isChunkContainer() const { return currentChunk()->isContainer(); }
87 inline bool endOfChunk() const { return /*m_Chunks.size() == 1 ? eof() :*/ m_Stream
.getPos() >= currentChunk()->endOfChunk(); }
89 inline NLMISC::IStream
&stream() { return m_Stream
; }
92 inline const CChunk
*currentChunk() const { return &m_Chunks
[m_Chunks
.size() - 1]; }
93 inline CChunk
*currentChunk() { return &m_Chunks
[m_Chunks
.size() - 1]; }
96 NLMISC::IStream
&m_Stream
;
97 std::vector
<CChunk
> m_Chunks
;
100 }; /* class CStorageChunks */
102 } /* namespace MAX */
103 } /* namespace PIPELINE */
105 #endif /* #ifndef PIPELINE_STORAGE_CHUNKS_H */