39 #if !defined(TAWARA_FILE_CLUSTER_H_)
40 #define TAWARA_FILE_CLUSTER_H_
42 #include <boost/iterator/iterator_facade.hpp>
67 typedef boost::shared_ptr<FileCluster>
Ptr;
80 template <
typename BlockType>
82 :
public boost::iterator_facade<
83 IteratorBase<BlockType>, BlockType,
84 boost::forward_traversal_tag>
107 std::istream& stream, std::streampos pos)
108 : cluster_(cluster), stream_(&stream)
119 template <
typename OtherType>
121 : cluster_(other.cluster_), stream_(other.stream_),
128 friend class boost::iterator_core_access;
147 std::streampos cur_read(stream_->tellg());
155 new_block->read(*stream_);
157 boost::shared_ptr<BlockType> new_const_block(new_block);
158 block_.swap(new_const_block);
163 new_block->read(*stream_);
165 boost::shared_ptr<BlockType> new_const_block(new_block);
166 block_.swap(new_const_block);
173 err_pos(static_cast<std::streamsize>(stream_->tellg()) -
177 stream_->seekg(cur_read);
188 load_block(block_->offset() + block_->size());
196 template <
typename OtherType>
205 return block_->offset() ==
258 virtual bool empty()
const;
266 virtual void clear();
275 virtual void erase(Iterator position);
284 virtual void erase(Iterator first, Iterator last);
291 virtual void push_back(
value_type const& value);
294 std::streamsize
write(std::ostream& output);
297 std::streamsize finalise(std::ostream& output);
306 std::streamsize blocks_size()
const;
309 std::streamsize read_blocks(std::istream& input,
310 std::streamsize
size);
317 #endif // TAWARA_FILE_CLUSTER_H_
std::streampos blocks_end_pos_
std::streampos blocks_start_pos_
void load_block(std::streampos pos)
BlockType & dereference() const
Dereference the iterator to get a pointer to the block.
std::streamsize write(ID id, std::ostream &output)
Write an ID to an output stream.
boost::shared_ptr< BlockElement > Ptr
FileCluster const * cluster_
std::streamsize size(ID id)
Get the number of bytes required by an ID.
The in-file Cluster implementation.
BlockElement::Ptr value_type
The value type of this container.
bool equal(IteratorBase< OtherType > const &other) const
Test for equality with another iterator.
A child element was found where it doesn't belong.
void increment()
Increment the iterator to the next block.
boost::shared_ptr< BlockType > block_
ReadResult read(std::istream &input)
Read an ID from an input stream.
const ID BlockGroup(0xA0)
IteratorBase(FileCluster const *cluster, std::istream &stream, std::streampos pos)
Base constructor.
boost::shared_ptr< FileCluster > Ptr
Pointer to a file-based cluster.
const ID SimpleBlock(0xA3)
IteratorBase()
Base constructor.
boost::error_info< struct tag_par_id, uint32_t > err_par_id
A parent element ID.
The base Cluster, defining the common interface for Cluster element implementations.
IteratorBase< BlockElement > Iterator
File-based cluster iterator interface.
IteratorBase(IteratorBase< OtherType > const &other)
Templated base constructor.
boost::error_info< struct tag_id, ids::ID > err_id
An Element ID.
boost::error_info< struct tag_pos, std::streamsize > err_pos
Position in a Tawara file.
size_t size_type
The size type of this container.
std::pair< ID, std::streamsize > ReadResult
The result of a read operation is a pair of the ID read and the number of bytes read.