Tawara  0.1.0
block_impl.h
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2011, 2012, Geoffrey Biggs, geoffrey.biggs@aist.go.jp
5  * RT-Synthesis Research Group
6  * Intelligent Systems Research Institute,
7  * National Institute of Advanced Industrial Science and Technology (AIST),
8  * Japan
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  *
15  * * Redistributions of source code must retain the above copyright
16  * notice, this list of conditions and the following disclaimer.
17  * * Redistributions in binary form must reproduce the above
18  * copyright notice, this list of conditions and the following
19  * disclaimer in the documentation and/or other materials provided
20  * with the distribution.
21  * * Neither the name of Geoffrey Biggs nor AIST, nor the names of its
22  * contributors may be used to endorse or promote products derived
23  * from this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
28  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
29  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 #if !defined(TAWARA_BLOCK_IMPL_H_)
40 #define TAWARA_BLOCK_IMPL_H_
41 
42 #include <stdint.h>
43 #include <tawara/block.h>
44 #include <tawara/win_dll.h>
45 #include <utility>
46 
49 
50 namespace tawara
51 {
57  class TAWARA_EXPORT BlockImpl : public Block,
58  public boost::equality_comparable<BlockImpl>
59  {
60  public:
62  BlockImpl(uint64_t track_number, int16_t timecode,
63  LacingType lacing=LACING_NONE);
64 
66  uint64_t track_number() const { return track_num_; }
68  void track_number(uint64_t track_number)
69  { track_num_ = track_number; }
70 
72  int16_t timecode() const { return timecode_; }
74  void timecode(int16_t timecode) { timecode_ = timecode; }
75 
77  bool invisible() const { return invisible_; }
79  void invisible(bool invisible) { invisible_ = invisible; }
80 
82  LacingType lacing() const { return lacing_; }
84  void lacing(LacingType lacing) { lacing_ = lacing; }
85 
87  BlockImpl& operator=(BlockImpl const& other);
88 
93  { return frames_.at(pos); }
97  value_type const& at(size_type pos) const
98  { return frames_.at(pos); }
99 
104  { return frames_[pos]; }
108  value_type const& operator[](size_type pos) const
109  { return frames_[pos]; }
110 
112  iterator begin() { return frames_.begin(); }
114  const_iterator begin() const { return frames_.begin(); }
116  iterator end() { return frames_.end(); }
118  const_iterator end() const { return frames_.end(); }
120  reverse_iterator rbegin() { return frames_.rbegin(); }
122  const_reverse_iterator rbegin() const { return frames_.rbegin(); }
126  reverse_iterator rend() { return frames_.rend(); }
130  const_reverse_iterator rend() const { return frames_.rend(); }
131 
133  bool empty() const { return frames_.empty(); }
135  size_type count() const { return frames_.size(); }
137  size_type max_count() const;
138 
140  void clear() { frames_.clear(); }
141 
143  void erase(iterator position)
144  { frames_.erase(position); }
146  void erase(iterator first, iterator last)
147  { frames_.erase(first, last); }
148 
150  void push_back(value_type const& value);
151 
153  void resize(size_type count);
154 
156  void swap(BlockImpl& other);
157 
163  std::streamsize size() const;
164 
183  std::streamsize write(std::ostream& output, uint8_t extra_flags);
184 
191  typedef std::pair<std::streamsize, uint8_t> ReadResult;
204  ReadResult read(std::istream& input, std::streamsize size);
205 
207  friend bool operator==(BlockImpl const& lhs, BlockImpl const& rhs);
208 
210  typedef boost::shared_ptr<std::vector<char> > value_type;
211 
212  protected:
213  uint64_t track_num_;
214  int16_t timecode_;
217  std::vector<value_type> frames_;
218 
220  void validate() const;
221 
223  void reset();
224 
235  std::streamsize read_ebml_laced_frames(std::istream& input,
236  std::streamsize size);
237 
252  std::streamsize read_fixed_frames(std::istream& input,
253  std::streamsize size, unsigned int count);
254  }; // class BlockImpl
255 
257  bool operator==(BlockImpl const& lhs, BlockImpl const& rhs);
258 }; // namespace tawara
259 
261 // group implementations
262 
263 #endif // TAWARA_BLOCK_IMPL_H_
264 
Block interface.
Definition: block.h:59
std::streamsize write(ID id, std::ostream &output)
Write an ID to an output stream.
size_type count() const
Get the number of frames.
Definition: block_impl.h:135
LacingType
Lacing types.
Definition: block.h:69
const_iterator end() const
Get an iterator to the position past the last frame.
Definition: block_impl.h:118
std::vector< value_type > frames_
Definition: block_impl.h:217
std::streamsize size(ID id)
Get the number of bytes required by an ID.
#define TAWARA_EXPORT
Definition: win_dll.h:51
value_type const & operator[](size_type pos) const
Get a reference to a frame.
Definition: block_impl.h:108
std::vector< FramePtr >::const_iterator const_iterator
The constant random access iterator type.
Definition: block.h:93
void track_number(uint64_t track_number)
Set the block's track number.
Definition: block_impl.h:68
value_type & operator[](size_type pos)
Get a reference to a frame.
Definition: block_impl.h:103
Common block functionality implementation.
Definition: block_impl.h:57
boost::shared_ptr< std::vector< char > > value_type
The stored type.
Definition: block_impl.h:210
iterator begin()
Get an iterator to the first frame.
Definition: block_impl.h:112
bool invisible() const
If this block is invisible.
Definition: block_impl.h:77
reverse_iterator rbegin()
Get a reverse iterator to the last frame.
Definition: block_impl.h:120
void clear()
Remove all frames.
Definition: block_impl.h:140
ReadResult read(std::istream &input)
Read an ID from an input stream.
uint64_t track_num_
Definition: block_impl.h:213
bool operator==(AttachedFile const &lhs, AttachedFile const &rhs)
Equality operator for the AttachedFile object.
void timecode(int16_t timecode)
Set the block's timecode.
Definition: block_impl.h:74
std::vector< FramePtr >::size_type size_type
The size type of this container.
Definition: block.h:85
bool empty() const
Check if there are no frames.
Definition: block_impl.h:133
const_reverse_iterator rend() const
Get a reverse iterator to the position before the first frame.
Definition: block_impl.h:130
reverse_iterator rend()
Get a reverse iterator to the position before the first frame.
Definition: block_impl.h:126
std::vector< FramePtr >::reverse_iterator reverse_iterator
The reversed random access iterator type.
Definition: block.h:95
LacingType lacing() const
Get the lacing type in use.
Definition: block_impl.h:82
const_reverse_iterator rbegin() const
Get a reverse iterator to the last frame.
Definition: block_impl.h:122
void erase(iterator first, iterator last)
Erase a range of frames.
Definition: block_impl.h:146
value_type const & at(size_type pos) const
Get the frame at the given position, with bounds checking.
Definition: block_impl.h:97
const_iterator begin() const
Get an iterator to the first frame.
Definition: block_impl.h:114
void erase(iterator position)
Erase the frame at the specified iterator.
Definition: block_impl.h:143
value_type & at(size_type pos)
Get the frame at the given position, with bounds checking.
Definition: block_impl.h:92
std::pair< std::streamsize, uint8_t > ReadResult
The return result of a read.
Definition: block_impl.h:191
LacingType lacing_
Definition: block_impl.h:216
std::vector< FramePtr >::const_reverse_iterator const_reverse_iterator
The constant reversed random access iterator type.
Definition: block.h:98
void lacing(LacingType lacing)
Set the lacing type in use.
Definition: block_impl.h:84
uint64_t track_number() const
The block's track number.
Definition: block_impl.h:66
int16_t timecode() const
The timecode of this block.
Definition: block_impl.h:72
void invisible(bool invisible)
Set if this block is invisible.
Definition: block_impl.h:79
iterator end()
Get an iterator to the position past the last frame.
Definition: block_impl.h:116
std::vector< FramePtr >::iterator iterator
The random access iterator type.
Definition: block.h:91