Tawara  0.1.0
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
tawara::BlockImpl Class Reference

Common block functionality implementation. More...

#include <tawara/block_impl.h>

Inheritance diagram for tawara::BlockImpl:
Inheritance graph
[legend]
Collaboration diagram for tawara::BlockImpl:
Collaboration graph
[legend]

Public Types

typedef std::pair
< std::streamsize, uint8_t > 
ReadResult
 The return result of a read. More...
 
typedef boost::shared_ptr
< std::vector< char > > 
value_type
 The stored type. More...
 
- Public Types inherited from tawara::Block
enum  LacingType { LACING_NONE, LACING_EBML, LACING_FIXED }
 Lacing types. More...
 
typedef boost::shared_ptr< BlockPtr
 Pointer to a block. More...
 
typedef boost::shared_ptr
< Block const > 
ConstPtr
 Constant pointer to a block. More...
 
typedef std::vector< char > Frame
 The type of a single frame of data. More...
 
typedef boost::shared_ptr< FrameFramePtr
 A pointer to a frame of data. More...
 
typedef std::vector< FramePtr >
::value_type 
value_type
 The value type of this container. More...
 
typedef std::vector< FramePtr >
::size_type 
size_type
 The size type of this container. More...
 
typedef std::vector< FramePtr >
::reference 
reference
 The reference type. More...
 
typedef std::vector< FramePtr >
::const_reference 
const_reference
 The constant reference type. More...
 
typedef std::vector< FramePtr >
::iterator 
iterator
 The random access iterator type. More...
 
typedef std::vector< FramePtr >
::const_iterator 
const_iterator
 The constant random access iterator type. More...
 
typedef std::vector< FramePtr >
::reverse_iterator 
reverse_iterator
 The reversed random access iterator type. More...
 
typedef std::vector< FramePtr >
::const_reverse_iterator 
const_reverse_iterator
 The constant reversed random access iterator type. More...
 

Public Member Functions

 BlockImpl (uint64_t track_number, int16_t timecode, LacingType lacing=LACING_NONE)
 Constructor. More...
 
uint64_t track_number () const
 The block's track number. More...
 
void track_number (uint64_t track_number)
 Set the block's track number. More...
 
int16_t timecode () const
 The timecode of this block. More...
 
void timecode (int16_t timecode)
 Set the block's timecode. More...
 
bool invisible () const
 If this block is invisible. More...
 
void invisible (bool invisible)
 Set if this block is invisible. More...
 
LacingType lacing () const
 Get the lacing type in use. More...
 
void lacing (LacingType lacing)
 Set the lacing type in use. More...
 
BlockImploperator= (BlockImpl const &other)
 Replace the content of this block with another block. More...
 
value_typeat (size_type pos)
 Get the frame at the given position, with bounds checking. More...
 
value_type const & at (size_type pos) const
 Get the frame at the given position, with bounds checking. More...
 
value_typeoperator[] (size_type pos)
 Get a reference to a frame. More...
 
value_type const & operator[] (size_type pos) const
 Get a reference to a frame. More...
 
iterator begin ()
 Get an iterator to the first frame. More...
 
const_iterator begin () const
 Get an iterator to the first frame. More...
 
iterator end ()
 Get an iterator to the position past the last frame. More...
 
const_iterator end () const
 Get an iterator to the position past the last frame. More...
 
reverse_iterator rbegin ()
 Get a reverse iterator to the last frame. More...
 
const_reverse_iterator rbegin () const
 Get a reverse iterator to the last frame. More...
 
reverse_iterator rend ()
 Get a reverse iterator to the position before the first frame. More...
 
const_reverse_iterator rend () const
 Get a reverse iterator to the position before the first frame. More...
 
bool empty () const
 Check if there are no frames. More...
 
size_type count () const
 Get the number of frames. More...
 
size_type max_count () const
 Get the maximum number of frames. More...
 
void clear ()
 Remove all frames. More...
 
void erase (iterator position)
 Erase the frame at the specified iterator. More...
 
void erase (iterator first, iterator last)
 Erase a range of frames. More...
 
void push_back (value_type const &value)
 Add a frame to this block. More...
 
void resize (size_type count)
 Resizes the frames storage. More...
 
void swap (BlockImpl &other)
 Swaps the contents of this block with another. More...
 
std::streamsize size () const
 Gets the size of the block data. More...
 
std::streamsize write (std::ostream &output, uint8_t extra_flags)
 Write the block data to an output stream. More...
 
ReadResult read (std::istream &input, std::streamsize size)
 Read the block data from an input stream. More...
 
- Public Member Functions inherited from tawara::Block
 Block (uint64_t track_number, int16_t timecode, LacingType lacing=LACING_NONE)
 Constructor. More...
 
virtual ~Block ()=0
 Desctructor. More...
 
virtual void push_back (value_type const &value)=0
 Add a frame to this block. More...
 
virtual void swap (Block &other)
 Swaps the contents of this block with another. More...
 

Protected Member Functions

void validate () const
 Checks that the block is in a good condition to write. More...
 
void reset ()
 Resets this block to an empty state. More...
 
std::streamsize read_ebml_laced_frames (std::istream &input, std::streamsize size)
 Reads frames laced using EBML lacing, including the lace header. More...
 
std::streamsize read_fixed_frames (std::istream &input, std::streamsize size, unsigned int count)
 Reads frames laced using fixed lacing. More...
 

Protected Attributes

uint64_t track_num_
 
int16_t timecode_
 
bool invisible_
 
LacingType lacing_
 
std::vector< value_typeframes_
 

Friends

bool operator== (BlockImpl const &lhs, BlockImpl const &rhs)
 Equality operator. More...
 

Detailed Description

Common block functionality implementation.

This class provides an implementation of the Block interface functionality.

Definition at line 57 of file block_impl.h.

Member Typedef Documentation

typedef std::pair<std::streamsize, uint8_t> tawara::BlockImpl::ReadResult

The return result of a read.

The first contains the number of bytes read. The second contains any extra flags that were stored in the block.

Definition at line 191 of file block_impl.h.

typedef boost::shared_ptr<std::vector<char> > tawara::BlockImpl::value_type

The stored type.

Definition at line 210 of file block_impl.h.

Constructor & Destructor Documentation

tawara::BlockImpl::BlockImpl ( uint64_t  track_number,
int16_t  timecode,
LacingType  lacing = LACING_NONE 
)

Constructor.

Member Function Documentation

value_type& tawara::BlockImpl::at ( size_type  pos)
inlinevirtual

Get the frame at the given position, with bounds checking.

Implements tawara::Block.

Definition at line 92 of file block_impl.h.

value_type const& tawara::BlockImpl::at ( size_type  pos) const
inlinevirtual

Get the frame at the given position, with bounds checking.

Implements tawara::Block.

Definition at line 97 of file block_impl.h.

iterator tawara::BlockImpl::begin ( )
inlinevirtual

Get an iterator to the first frame.

Implements tawara::Block.

Definition at line 112 of file block_impl.h.

const_iterator tawara::BlockImpl::begin ( ) const
inlinevirtual

Get an iterator to the first frame.

Implements tawara::Block.

Definition at line 114 of file block_impl.h.

void tawara::BlockImpl::clear ( )
inlinevirtual

Remove all frames.

Implements tawara::Block.

Definition at line 140 of file block_impl.h.

size_type tawara::BlockImpl::count ( ) const
inlinevirtual

Get the number of frames.

Implements tawara::Block.

Definition at line 135 of file block_impl.h.

bool tawara::BlockImpl::empty ( ) const
inlinevirtual

Check if there are no frames.

Implements tawara::Block.

Definition at line 133 of file block_impl.h.

iterator tawara::BlockImpl::end ( )
inlinevirtual

Get an iterator to the position past the last frame.

Implements tawara::Block.

Definition at line 116 of file block_impl.h.

const_iterator tawara::BlockImpl::end ( ) const
inlinevirtual

Get an iterator to the position past the last frame.

Implements tawara::Block.

Definition at line 118 of file block_impl.h.

void tawara::BlockImpl::erase ( iterator  position)
inlinevirtual

Erase the frame at the specified iterator.

Implements tawara::Block.

Definition at line 143 of file block_impl.h.

void tawara::BlockImpl::erase ( iterator  first,
iterator  last 
)
inlinevirtual

Erase a range of frames.

Implements tawara::Block.

Definition at line 146 of file block_impl.h.

bool tawara::BlockImpl::invisible ( ) const
inlinevirtual

If this block is invisible.

Implements tawara::Block.

Definition at line 77 of file block_impl.h.

void tawara::BlockImpl::invisible ( bool  invisible)
inlinevirtual

Set if this block is invisible.

Implements tawara::Block.

Definition at line 79 of file block_impl.h.

LacingType tawara::BlockImpl::lacing ( ) const
inlinevirtual

Get the lacing type in use.

Implements tawara::Block.

Definition at line 82 of file block_impl.h.

void tawara::BlockImpl::lacing ( LacingType  lacing)
inlinevirtual

Set the lacing type in use.

Implements tawara::Block.

Definition at line 84 of file block_impl.h.

size_type tawara::BlockImpl::max_count ( ) const
virtual

Get the maximum number of frames.

Implements tawara::Block.

BlockImpl& tawara::BlockImpl::operator= ( BlockImpl const &  other)

Replace the content of this block with another block.

value_type& tawara::BlockImpl::operator[] ( size_type  pos)
inlinevirtual

Get a reference to a frame.

No bounds checking is performed.

Implements tawara::Block.

Definition at line 103 of file block_impl.h.

value_type const& tawara::BlockImpl::operator[] ( size_type  pos) const
inlinevirtual

Get a reference to a frame.

No bounds checking is performed.

Implements tawara::Block.

Definition at line 108 of file block_impl.h.

void tawara::BlockImpl::push_back ( value_type const &  value)

Add a frame to this block.

reverse_iterator tawara::BlockImpl::rbegin ( )
inlinevirtual

Get a reverse iterator to the last frame.

Implements tawara::Block.

Definition at line 120 of file block_impl.h.

const_reverse_iterator tawara::BlockImpl::rbegin ( ) const
inlinevirtual

Get a reverse iterator to the last frame.

Implements tawara::Block.

Definition at line 122 of file block_impl.h.

ReadResult tawara::BlockImpl::read ( std::istream &  input,
std::streamsize  size 
)

Read the block data from an input stream.

This function reads a block header and all stored frames.

Parameters
[in]inputThe input byte stream to read from.
[in]sizeThe number of bytes used by the block.
Returns
The number of bytes read and any extra flags that were present in the block.
Exceptions
ReadErrorif an error occurs reading data.
BadBlockSizeif the block size is too small or too big.
std::streamsize tawara::BlockImpl::read_ebml_laced_frames ( std::istream &  input,
std::streamsize  size 
)
protected

Reads frames laced using EBML lacing, including the lace header.

Parameters
[in]inputThe input byte stream to read from.
[in]sizeThe number of bytes available.
Returns
The number of bytes read.
Exceptions
ReadErrorif an error occurs reading data.
BadElementSizeif the block size is too small or too big.
std::streamsize tawara::BlockImpl::read_fixed_frames ( std::istream &  input,
std::streamsize  size,
unsigned int  count 
)
protected

Reads frames laced using fixed lacing.

The number of frames to read is specified. The value of size must be evenly dividable by this count with no remainder (i.e. every frame must be the same size).

Parameters
[in]inputThe input byte stream to read from.
[in]sizeThe number of bytes available.
[in]countThe number of frames to read.
Returns
The number of bytes read.
Exceptions
ReadErrorif an error occurs reading data.
BadLacedFrameSizeif the block size is too small or too big.
reverse_iterator tawara::BlockImpl::rend ( )
inlinevirtual

Get a reverse iterator to the position before the first frame.

Implements tawara::Block.

Definition at line 126 of file block_impl.h.

const_reverse_iterator tawara::BlockImpl::rend ( ) const
inlinevirtual

Get a reverse iterator to the position before the first frame.

Implements tawara::Block.

Definition at line 130 of file block_impl.h.

void tawara::BlockImpl::reset ( )
protected

Resets this block to an empty state.

void tawara::BlockImpl::resize ( size_type  count)
virtual

Resizes the frames storage.

Implements tawara::Block.

std::streamsize tawara::BlockImpl::size ( ) const

Gets the size of the block data.

This includes the block header bytes, the frame data, and the lacing header (if present).

void tawara::BlockImpl::swap ( BlockImpl other)

Swaps the contents of this block with another.

int16_t tawara::BlockImpl::timecode ( ) const
inlinevirtual

The timecode of this block.

Implements tawara::Block.

Definition at line 72 of file block_impl.h.

void tawara::BlockImpl::timecode ( int16_t  timecode)
inlinevirtual

Set the block's timecode.

Implements tawara::Block.

Definition at line 74 of file block_impl.h.

uint64_t tawara::BlockImpl::track_number ( ) const
inlinevirtual

The block's track number.

Implements tawara::Block.

Definition at line 66 of file block_impl.h.

void tawara::BlockImpl::track_number ( uint64_t  track_number)
inlinevirtual

Set the block's track number.

Implements tawara::Block.

Definition at line 68 of file block_impl.h.

void tawara::BlockImpl::validate ( ) const
protected

Checks that the block is in a good condition to write.

std::streamsize tawara::BlockImpl::write ( std::ostream &  output,
uint8_t  extra_flags 
)

Write the block data to an output stream.

This function performs the write of the block header and all stored frames.

Before performing the write, the block is validated. This may cause exceptions to be raised if the block is in an invalid state.

Parameters
[in]outputThe output byte stream to write data to.
[in]extra_flagsExtra flags to add to the flags contained in this block.
Returns
The number of bytes written.
Exceptions
EmptyFrameif an empty frame is found.
BadLacedFrameSizeif fixed lacing is used and all frames are not the same size.
WriteErrorif an error occurs writing data.

Friends And Related Function Documentation

bool operator== ( BlockImpl const &  lhs,
BlockImpl const &  rhs 
)
friend

Equality operator.

Member Data Documentation

std::vector<value_type> tawara::BlockImpl::frames_
protected

Definition at line 217 of file block_impl.h.

bool tawara::BlockImpl::invisible_
protected

Definition at line 215 of file block_impl.h.

LacingType tawara::BlockImpl::lacing_
protected

Definition at line 216 of file block_impl.h.

int16_t tawara::BlockImpl::timecode_
protected

Definition at line 214 of file block_impl.h.

uint64_t tawara::BlockImpl::track_num_
protected

Definition at line 213 of file block_impl.h.


The documentation for this class was generated from the following file: