Tawara  0.1.0
cues.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_CUES_H_)
40 #define TAWARA_CUES_H_
41 
42 #include <boost/operators.hpp>
43 #include <boost/shared_ptr.hpp>
44 #include <tawara/master_element.h>
45 #include <tawara/uint_element.h>
46 #include <tawara/win_dll.h>
47 #include <vector>
48 
51 
52 namespace tawara
53 {
61  public boost::equality_comparable<CueTrackPosition>
62  {
63  public:
66 
72  CueTrackPosition(uint64_t track, uint64_t cluster_pos);
73 
75  uint64_t track() const { return track_; }
77  void track(uint64_t track);
78 
84  uint64_t cluster_pos() const { return cluster_pos_; }
86  void cluster_pos(uint64_t cluster_pos)
87  { cluster_pos_ = cluster_pos; }
88 
94  uint64_t block_num() const { return block_num_; }
96  void block_num(uint64_t block_num);
97 
103  uint64_t codec_state() const { return codec_state_; }
105  void codec_state(uint64_t codec_state)
106  { codec_state_ = codec_state; }
107 
114  std::vector<uint64_t>& reference_times()
115  { return ref_blocks_; }
116 
118  friend bool operator==(CueTrackPosition const& lhs,
119  CueTrackPosition const& rhs);
120 
121  protected:
126  std::vector<uint64_t> ref_blocks_;
127 
129  // Element interface
131 
133  virtual std::streamsize body_size() const;
134 
136  virtual std::streamsize write_body(std::ostream& output);
137 
139  virtual std::streamsize read_body(std::istream& input,
140  std::streamsize size);
141 
143  std::streamsize read_cue_reference(std::istream& input,
144  std::streamsize size);
145 
147  void reset();
148  }; // class CueTrackPosition
149 
151  bool operator==(CueTrackPosition const& lhs,
152  CueTrackPosition const& rhs);
153 
154 
167  public boost::equality_comparable<CuePoint>
168  {
169  protected:
171  typedef std::vector<CueTrackPosition> storage_type_;
172  public:
174  typedef storage_type_::value_type value_type;
176  typedef storage_type_::size_type size_type;
178  typedef storage_type_::reference reference;
180  typedef storage_type_::const_reference const_reference;
182  typedef storage_type_::iterator iterator;
184  typedef storage_type_::const_iterator const_iterator;
186  typedef storage_type_::reverse_iterator reverse_iterator;
188  typedef storage_type_::const_reverse_iterator
191  typedef boost::shared_ptr<CuePoint> Ptr;
192 
194  CuePoint();
195 
200  CuePoint(uint64_t timecode);
201 
207  uint64_t timecode() const { return timecode_; }
209  void timecode(uint64_t timecode) { timecode_ = timecode; }
210 
217  virtual value_type& at(size_type pos)
218  { return positions_.at(pos); }
225  virtual value_type const& at(size_type pos) const
226  { return positions_.at(pos); }
227 
231  virtual value_type& operator[](size_type pos)
232  { return positions_[pos]; }
236  virtual value_type const& operator[](size_type pos) const
237  { return positions_[pos]; }
238 
240  virtual iterator begin() { return positions_.begin(); }
242  virtual const_iterator begin() const { return positions_.begin(); }
244  virtual iterator end() { return positions_.end(); }
246  virtual const_iterator end() const { return positions_.end(); }
248  virtual reverse_iterator rbegin() { return positions_.rbegin(); }
251  { return positions_.rbegin(); }
255  virtual reverse_iterator rend() { return positions_.rend(); }
259  virtual const_reverse_iterator rend() const
260  { return positions_.rend(); }
261 
267  virtual bool empty() const { return positions_.empty(); }
269  virtual size_type count() const { return positions_.size(); }
271  virtual size_type max_count() const
272  { return positions_.max_size(); }
273 
275  virtual void clear() { positions_.clear(); }
276 
281  virtual void erase(iterator position)
282  { positions_.erase(position); }
288  virtual void erase(iterator first, iterator last)
289  { positions_.erase(first, last); }
290 
292  virtual void push_back(value_type const& value)
293  { positions_.push_back(value); }
294 
296  virtual void resize(size_type count) { positions_.resize(count); }
297 
303  virtual void swap(CuePoint& other)
304  { positions_.swap(other.positions_); }
305 
307  friend bool operator==(CuePoint const& lhs, CuePoint const& rhs);
308 
309  protected:
311  storage_type_ positions_;
312 
314  // Element interface
316 
318  virtual std::streamsize body_size() const;
319 
321  virtual std::streamsize write_body(std::ostream& output);
322 
328  virtual std::streamsize read_body(std::istream& input,
329  std::streamsize size);
330  }; // class CuePoint
331 
333  bool operator==(CuePoint const& lhs, CuePoint const& rhs);
334 
335 
354  public boost::equality_comparable<Cues>
355  {
356  public:
358  typedef uint64_t key_type;
361 
362  protected:
364  typedef std::map<key_type, mapped_type> storage_type_;
365 
366  public:
368  Cues();
369 
371  typedef storage_type_::value_type value_type;
373  typedef storage_type_::size_type size_type;
375  typedef storage_type_::reference reference;
377  typedef storage_type_::const_reference const_reference;
379  typedef storage_type_::iterator iterator;
381  typedef storage_type_::const_iterator const_iterator;
383  typedef storage_type_::reverse_iterator reverse_iterator;
385  typedef storage_type_::const_reverse_iterator
387 
393  mapped_type& at(key_type const& pos)
394  { return cues_.at(pos); }
400  mapped_type const& at(key_type const& pos) const
401  { return cues_.at(pos); }
402 
408  mapped_type& operator[](key_type const& key)
409  { return cues_[key]; }
415  mapped_type const& operator[](key_type const& key) const
416  { return cues_.find(key)->second; }
417 
419  iterator begin() { return cues_.begin(); }
421  const_iterator begin() const { return cues_.begin(); }
423  iterator end() { return cues_.end(); }
425  const_iterator end() const { return cues_.end(); }
427  reverse_iterator rbegin() { return cues_.rbegin(); }
429  const_reverse_iterator rbegin() const { return cues_.rbegin(); }
433  reverse_iterator rend() { return cues_.rend(); }
437  const_reverse_iterator rend() const { return cues_.rend(); }
438 
440  bool empty() const { return cues_.empty(); }
442  size_type count() const { return cues_.size(); }
444  size_type max_count() const { return cues_.max_size(); }
445 
447  void clear() { cues_.clear(); }
461  std::pair<iterator, bool> insert(mapped_type const& value)
462  { return cues_.insert(std::make_pair(value.timecode(), value)); }
468  void insert(const_iterator first, const_iterator last)
469  { cues_.insert(first, last); }
474  void erase(iterator position)
475  { cues_.erase(position); }
481  void erase(iterator first, iterator last)
482  { cues_.erase(first, last); }
488  size_type erase(key_type const& number)
489  { return cues_.erase(number); }
494  void swap(Cues& other) { cues_.swap(other.cues_); }
495 
502  iterator find(key_type const& number)
503  { return cues_.find(number); }
510  const_iterator find(key_type const& number) const
511  { return cues_.find(number); }
512 
514  friend bool operator==(Cues const& lhs, Cues const& rhs);
515 
516  protected:
517  storage_type_ cues_;
518 
520  // Element interface
522 
524  virtual std::streamsize body_size() const;
525 
527  virtual std::streamsize write_body(std::ostream& output);
528 
530  virtual std::streamsize read_body(std::istream& input,
531  std::streamsize size);
532  }; // class Cues
533 
535  bool operator==(Cues const& lhs, Cues const& rhs);
536 }; // namespace tawara;
537 
539 // group elements
540 
541 #endif // TAWARA_CUES_H_
542 
void erase(iterator first, iterator last)
Erase a range of CuePoints.
Definition: cues.h:481
virtual iterator end()
Get an iterator to the position past the last cue.
Definition: cues.h:244
storage_type_::const_reverse_iterator const_reverse_iterator
The constant reversed random access iterator type.
Definition: cues.h:386
virtual void erase(iterator position)
Erase the CueTrackPosition at the specified iterator.
Definition: cues.h:281
uint64_t timecode() const
Get the timecode of this cue point.
Definition: cues.h:207
uint64_t track() const
The track number this element contains positions for.
Definition: cues.h:75
void timecode(uint64_t timecode)
Set the timecode.
Definition: cues.h:209
storage_type_::const_reverse_iterator const_reverse_iterator
The constant reversed random access iterator type.
Definition: cues.h:189
uint64_t key_type
The key type (Key) of this container.
Definition: cues.h:358
const_reverse_iterator rend() const
Get a reverse iterator to the position before the first CuePoint.
Definition: cues.h:437
virtual iterator begin()
Get an iterator to the first cue.
Definition: cues.h:240
virtual const_reverse_iterator rbegin() const
Get a reverse iterator to the last cue.
Definition: cues.h:250
storage_type_::reverse_iterator reverse_iterator
The reversed random access iterator type.
Definition: cues.h:186
mapped_type & at(key_type const &pos)
Get the CuePoint with the given timecode.
Definition: cues.h:393
storage_type_::value_type value_type
The value type of this container.
Definition: cues.h:174
std::streamsize size(ID id)
Get the number of bytes required by an ID.
#define TAWARA_EXPORT
Definition: win_dll.h:51
virtual reverse_iterator rbegin()
Get a reverse iterator to the last cue.
Definition: cues.h:248
iterator end()
Get an iterator to the position past the last CuePoint.
Definition: cues.h:423
storage_type_::iterator iterator
The random access iterator type.
Definition: cues.h:182
virtual value_type & operator[](size_type pos)
Get a reference to a CueTracksPosition.
Definition: cues.h:231
storage_type_::const_reference const_reference
The constant reference type.
Definition: cues.h:377
virtual size_type count() const
Get the number of cue positions.
Definition: cues.h:269
size_type erase(key_type const &number)
Erase the CuePoint with the given timecode.
Definition: cues.h:488
storage_type_::const_iterator const_iterator
The constant random access iterator type.
Definition: cues.h:381
storage_type_::size_type size_type
The size type of this container.
Definition: cues.h:373
storage_type_::const_reference const_reference
The constant reference type.
Definition: cues.h:180
storage_type_ positions_
Definition: cues.h:311
UIntElement codec_state_
Definition: cues.h:125
virtual size_type max_count() const
Get the maximum number of cue positions.
Definition: cues.h:271
virtual void resize(size_type count)
Resizes the vector.
Definition: cues.h:296
void erase(iterator position)
Erase the CuePoint at the specified iterator.
Definition: cues.h:474
The MasterElement interface.
UIntElement cluster_pos_
Definition: cues.h:123
virtual void swap(CuePoint &other)
Swaps the contents of this CuePoint element with another.
Definition: cues.h:303
storage_type_::iterator iterator
The random access iterator type.
Definition: cues.h:379
The Cues element provides a list of indexes into the blocks for specific timecodes.
Definition: cues.h:353
virtual const_iterator end() const
Get an iterator to the position past the last cue.
Definition: cues.h:246
storage_type_::const_iterator const_iterator
The constant random access iterator type.
Definition: cues.h:184
size_type count() const
Get the number of CuePoints.
Definition: cues.h:442
virtual const_reverse_iterator rend() const
Get a reverse iterator to the position before the first cue.
Definition: cues.h:259
std::vector< uint64_t > & reference_times()
Get the vector of reference block timecodes.
Definition: cues.h:114
const ID CueTrackPosition(0xB7)
iterator begin()
Get an iterator to the first CuePoint.
Definition: cues.h:419
bool operator==(AttachedFile const &lhs, AttachedFile const &rhs)
Equality operator for the AttachedFile object.
UIntElement track_
Definition: cues.h:122
const ID CuePoint(0xBB)
const_iterator end() const
Get an iterator to the position past the last CuePoint.
Definition: cues.h:425
UIntElement block_num_
Definition: cues.h:124
size_type max_count() const
Get the maximum number of CuePoints.
Definition: cues.h:444
std::vector< CueTrackPosition > storage_type_
The storage type.
Definition: cues.h:171
Unsigned integer primitive element.
Definition: uint_element.h:57
const_iterator find(key_type const &number) const
Search for the CuePoint with the given timecode.
Definition: cues.h:510
reverse_iterator rbegin()
Get a reverse iterator to the last CuePoint.
Definition: cues.h:427
virtual const_iterator begin() const
Get an iterator to the first cue.
Definition: cues.h:242
mapped_type const & operator[](key_type const &key) const
Gets a reference to the CuePoint with the given timecode, without range checking. ...
Definition: cues.h:415
CuePoint mapped_type
The mapped type (T) of this container.
Definition: cues.h:360
std::vector< uint64_t > ref_blocks_
Definition: cues.h:126
virtual void clear()
Remove all cue positions.
Definition: cues.h:275
iterator find(key_type const &number)
Search for the CuePoint with the given timecode.
Definition: cues.h:502
virtual void push_back(value_type const &value)
Add a CueTrackPosition.
Definition: cues.h:292
mapped_type & operator[](key_type const &key)
Gets a reference to the CuePoint with the given timecode, without range checking. ...
Definition: cues.h:408
uint64_t block_num() const
Get the number of the relevant block.
Definition: cues.h:94
void cluster_pos(uint64_t cluster_pos)
Set the cluster position.
Definition: cues.h:86
The position in the segment of the data for a single track.
Definition: cues.h:60
storage_type_::size_type size_type
The size type of this container.
Definition: cues.h:176
const ID Cues(0x1C53BB6B)
virtual reverse_iterator rend()
Get a reverse iterator to the position before the first cue.
Definition: cues.h:255
storage_type_::value_type value_type
The value type of this container.
Definition: cues.h:371
A CuePoint is an index from a timecode to one or more cluster/block positions.
Definition: cues.h:166
bool empty() const
Check if there are no CuePoints.
Definition: cues.h:440
boost::shared_ptr< CuePoint > Ptr
The pointer to this type.
Definition: cues.h:191
void insert(const_iterator first, const_iterator last)
Insert a range of CuePoints.
Definition: cues.h:468
storage_type_ cues_
Definition: cues.h:517
void clear()
Remove all CuePoints.
Definition: cues.h:447
storage_type_::reference reference
The reference type.
Definition: cues.h:178
uint64_t codec_state() const
Get the index of the relevant codec state.
Definition: cues.h:103
reverse_iterator rend()
Get a reverse iterator to the position before the first CuePoint.
Definition: cues.h:433
virtual void erase(iterator first, iterator last)
Erase a range of CueTrackPosition.
Definition: cues.h:288
std::pair< iterator, bool > insert(mapped_type const &value)
Insert a new CuePoint.
Definition: cues.h:461
std::map< key_type, mapped_type > storage_type_
The type of the internal storage.
Definition: cues.h:364
virtual value_type const & at(size_type pos) const
Get the CueTracksPosition at the given position, with bounds checking.
Definition: cues.h:225
const_reverse_iterator rbegin() const
Get a reverse iterator to the last CuePoint.
Definition: cues.h:429
uint64_t cluster_pos() const
Get the cluster position.
Definition: cues.h:84
void codec_state(uint64_t codec_state)
Set the index of the codec state.
Definition: cues.h:105
void swap(Cues &other)
Swaps the contents of this Cues element with another.
Definition: cues.h:494
UIntElement timecode_
Definition: cues.h:310
storage_type_::reverse_iterator reverse_iterator
The reversed random access iterator type.
Definition: cues.h:383
virtual value_type const & operator[](size_type pos) const
Get a reference to a CueTracksPosition.
Definition: cues.h:236
virtual bool empty() const
Check if there are no cue positions.
Definition: cues.h:267
mapped_type const & at(key_type const &pos) const
Get the CuePoint with the given timecode.
Definition: cues.h:400
const_iterator begin() const
Get an iterator to the first CuePoint.
Definition: cues.h:421
storage_type_::reference reference
The reference type.
Definition: cues.h:375
virtual value_type & at(size_type pos)
Get the CueTracksPosition at the given position, with bounds checking.
Definition: cues.h:217