39 #if !defined(TAWARA_SEGMENT_H_)
40 #define TAWARA_SEGMENT_H_
85 typedef boost::shared_ptr<Segment>
Ptr;
92 Segment(std::streamsize pad_size=4096);
99 template <
typename ClusterType>
101 :
public boost::iterator_facade<
102 ClusterIteratorBase<ClusterType>,
103 ClusterType, boost::forward_traversal_tag>
115 std::istream& stream)
116 : segment_(segment), stream_(stream)
120 std::streampos current_pos(stream_.tellg());
124 if (first_cluster != segment->
index.
end())
126 stream_.seekg(segment_->to_stream_offset(
127 first_cluster->second));
134 stream_.seekg(current_pos);
142 template <
typename OtherType>
145 : segment_(other.segment_), stream_(other.stream_),
146 cluster_(other.cluster_)
152 friend class boost::iterator_core_access;
168 err_pos(static_cast<std::streamsize>(
169 stream_.tellg()) -
id.second);
172 boost::shared_ptr<ClusterType> new_cluster(
new ClusterType);
173 new_cluster->read(stream_);
175 cluster_.swap(new_cluster);
182 std::streampos current_pos(stream_.tellg());
184 stream_.seekg(cluster_->offset());
186 stream_.seekg(cluster_->size(), std::ios::cur);
191 if (stream_.tellg() >=
192 segment_->size_ + segment_->offset_)
212 stream_.seekg(current_pos);
219 template <
typename OtherType>
235 else if (cluster_->offset() == other.
cluster_->offset())
270 template <
typename ClusterItrType,
typename BlockItrType>
272 :
public boost::iterator_facade<
273 BlockIteratorBase<ClusterItrType, BlockItrType>,
274 typename BlockItrType::value_type,
275 boost::forward_traversal_tag>
287 ClusterItrType
const& cluster)
288 : segment_(segment), cluster_(cluster)
290 if (cluster_.cluster_)
293 block_ = cluster_->begin();
296 while (block_ == cluster_->end() &&
300 block_ = cluster_->begin();
310 template <
typename OtherCIType,
typename OtherBIType>
313 : cluster_(other.cluster_), block_(other.block_)
323 friend class boost::iterator_core_access;
338 while (block_ == cluster_->end() &&
342 if (!cluster_.cluster_)
346 block_ = cluster_->begin();
354 template <
typename OtherCIType,
typename OtherBIType>
360 if (!cluster_.cluster_)
366 return block_ == other.
block_;
389 typedef BlockIteratorBase<MemClusterIterator,
476 std::streamsize
pad_size()
const {
return pad_size_; }
481 std::streamsize
size()
const;
498 std::streamsize finalise(std::iostream& stream);
525 std::streamsize to_segment_offset(std::streamsize stream_offset)
const;
533 std::streamsize to_stream_offset(std::streamsize seg_offset)
const;
553 std::streamsize write_size(std::ostream& output);
565 std::streamsize write_body(std::ostream& output);
596 std::streamsize read_body(std::istream& input,
597 std::streamsize
size);
603 #endif // TAWARA_SEGMENT_H_
SeekHead index
The segment index.
storage_type_::const_iterator const_iterator
The constant random access iterator type.
std::streamsize size_
The size of the segment, as read from the file.
ClusterIteratorBase< FileCluster > FileClusterIterator
File-based cluster iterator interface.
BlockItrType::value_type & dereference() const
Dereference the iterator to get a pointer to the block.
std::streamsize size(ID id)
Get the number of bytes required by an ID.
std::streamsize body_size() const
Get the size of the body of this element.
BlockIteratorBase< FileClusterIterator, FileCluster::Iterator > FileBlockIterator
File-based block iterator interface.
std::streamsize pad_size_
The size of the padding to place at the start of the file.
iterator end()
Get an iterator to the position past the last index entry.
iterator find(key_type const &id)
Search for the index entry with the given ID.
The MasterElement interface.
A child element was found where it doesn't belong.
The SegmentInfo element, containing the meta-data for a segment.
bool equal(ClusterIteratorBase< OtherType > const &other) const
Test for equality with another iterator.
ReadResult read(std::istream &input)
Read an ID from an input stream.
std::streamsize pad_size() const
Get the padding size.
ClusterIteratorBase< MemoryCluster > MemClusterIterator
Memory-based cluster iterator interface.
void increment()
Increment the iterator to the next block.
void increment()
Increment the iterator to the next cluster.
bool equal(BlockIteratorBase< OtherCIType, OtherBIType > const &other) const
Test for equality with another Iterator.
boost::error_info< struct tag_par_id, uint32_t > err_par_id
A parent element ID.
ClusterType & dereference() const
Dereference the iterator to get a pointer to the cluster.
BlockIteratorBase(BlockIteratorBase< OtherCIType, OtherBIType > const &other)
Templated base constructor.
boost::error_info< struct tag_id, ids::ID > err_id
An Element ID.
ClusterItrType cluster() const
Access to the cluster for the current block.
boost::error_info< struct tag_pos, std::streamsize > err_pos
Position in a Tawara file.
BlockIteratorBase(Segment *segment, ClusterItrType const &cluster)
Constructor.
SegmentInfo info
The segment information.
bool writing_
If the segment is currently being written.
boost::shared_ptr< Segment > Ptr
Pointer to a segment.
const ID Segment(0x18538067)
BlockIteratorBase< MemClusterIterator, MemoryCluster::Iterator > MemBlockIterator
Memory-based block iterator interface.
void pad_size(std::streamsize pad_size)
Set the padding size.
boost::shared_ptr< ClusterType > cluster_
ClusterIteratorBase(Segment const *segment, std::istream &stream)
Constructor.
const ID Cluster(0x1F43B675)
std::streamsize skip_read(std::istream &input, bool and_id)
Skip an element in an input stream.
ClusterIteratorBase(ClusterIteratorBase< OtherType > const &other)
Templated base constructor.
The SeekHead element, used as an index for a Tawara file.
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.