Tawara  0.1.0
cluster.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_CLUSTER_H_)
40 #define TAWARA_CLUSTER_H_
41 
42 #include <tawara/block_element.h>
43 #include <tawara/master_element.h>
44 #include <tawara/uint_element.h>
45 #include <tawara/win_dll.h>
46 
49 
50 namespace tawara
51 {
58  {
59  public:
60  SilentTrackNumber(uint64_t track_number)
61  : UIntElement(ids::SilentTrackNumber, track_number)
62  {
63  }
64  };
65 
149  //template <typename Impl>
151  {
152  public:
154  typedef boost::shared_ptr<Cluster> Ptr;
158  typedef size_t size_type;
160  typedef value_type& reference;
162  typedef value_type const& const_reference;
163 
169  Cluster(uint64_t timecode=0);
170 
172  virtual ~Cluster() {};
173 
175  // Cluster interface
177 
179  virtual bool empty() const = 0;
181  virtual size_type count() const = 0;
183  virtual void clear() = 0;
184 
185  /* \brief Erase the block at the specified iterator.
186  *
187  * \param[in] position The position to erase at.
188  */
189  //virtual void erase(typename Impl::Iterator position) = 0;
190  /* \brief Erase a range of blocks.
191  *
192  * \param[in] first The start of the range.
193  * \param[in] last The end of the range.
194  */
195  //virtual void erase(typename Impl::Iterator first,
196  //typename Impl::Iterator last) = 0;
197 
206  virtual void push_back(value_type const& value) = 0;
207 
214  uint64_t timecode() const { return timecode_; }
216  void timecode(uint64_t timecode) { timecode_ = timecode; }
217 
228  std::vector<SilentTrackNumber>& silent_tracks()
229  { return silent_tracks_; }
230 
239  uint64_t position() const;
240 
249  uint64_t previous_size() const { return prev_size_; }
251  void previous_size(uint64_t size) { prev_size_ = size; }
252 
254  std::streamsize size() const;
255 
263  std::streamsize read(std::istream& input)
264  { return Element::read(input); }
265 
276  virtual std::streamsize finalise(std::ostream& output) = 0;
277 
278  protected:
280  std::vector<SilentTrackNumber> silent_tracks_;
283  bool writing_;
284 
286  //this element.
287  std::streamsize meta_size() const;
288 
290  std::streamsize body_size() const
291  { return meta_size() + blocks_size(); }
292 
294  std::streamsize write_size(std::ostream& output);
295 
297  std::streamsize write_body(std::ostream& output);
298 
300  std::streamsize read_body(std::istream& input,
301  std::streamsize size);
302 
304  virtual std::streamsize blocks_size() const = 0;
305 
327  virtual std::streamsize read_blocks(std::istream& input,
328  std::streamsize size) = 0;
329 
334  std::streamsize read_silent_tracks(std::istream& input);
335 
337  virtual void reset();
338  }; // class Cluster
339 }; // namespace tawara
340 
342 // group interfaces
343 
344 #endif // TAWARA_CLUSTER_H_
345 
value_type & reference
The reference type.
Definition: cluster.h:160
boost::shared_ptr< BlockElement > Ptr
Definition: block_element.h:57
virtual std::streamsize read(std::istream &input)
Element reading.
std::streamsize read(std::istream &input)
Element reading.
Definition: cluster.h:263
void timecode(uint64_t timecode)
Set the cluster's timecode.
Definition: cluster.h:216
std::streamsize size(ID id)
Get the number of bytes required by an ID.
#define TAWARA_EXPORT
Definition: win_dll.h:51
BlockElement::Ptr value_type
The value type of this container.
Definition: cluster.h:156
The MasterElement interface.
UIntElement prev_size_
Definition: cluster.h:282
boost::shared_ptr< Cluster > Ptr
Pointer to a cluster.
Definition: cluster.h:154
The track number of a silent track.
Definition: cluster.h:57
std::streamsize body_size() const
Get the size of the body of this element.
Definition: cluster.h:290
Unsigned integer primitive element.
Definition: uint_element.h:57
UIntElement timecode_
Definition: cluster.h:279
SilentTrackNumber(uint64_t track_number)
Definition: cluster.h:60
The base Cluster, defining the common interface for Cluster element implementations.
Definition: cluster.h:150
value_type const & const_reference
The constant reference type.
Definition: cluster.h:162
virtual ~Cluster()
Destructor.
Definition: cluster.h:172
void previous_size(uint64_t size)
Set the size of the previous cluster in the segment.
Definition: cluster.h:251
UIntElement position_
Definition: cluster.h:281
size_t size_type
The size type of this container.
Definition: cluster.h:158
uint64_t timecode() const
Get the cluster's timecode.
Definition: cluster.h:214
std::vector< SilentTrackNumber > & silent_tracks()
Get the list of silent tracks.
Definition: cluster.h:228
const ID Cluster(0x1F43B675)
uint64_t previous_size() const
Get the size of the previous cluster in the segment.
Definition: cluster.h:249
std::vector< SilentTrackNumber > silent_tracks_
Definition: cluster.h:280