libsdr  0.1.0
A simple SDR library
Public Member Functions | Protected Attributes | List of all members
sdr::Buffer< T > Class Template Reference

A typed buffer. More...

#include <buffer.hh>

Inheritance diagram for sdr::Buffer< T >:
sdr::RawBuffer

Public Member Functions

 Buffer ()
 Empty constructor. More...
 
 Buffer (T *data, size_t size)
 Constructor from raw data. More...
 
 Buffer (size_t N, BufferOwner *owner=0)
 Creates a buffer with N samples. More...
 
 Buffer (const Buffer< T > &other)
 Create a new reference to the buffer. More...
 
virtual ~Buffer ()
 Destructor. More...
 
 Buffer (const RawBuffer &other)
 Explicit type cast. More...
 
const Buffer< T > & operator= (const Buffer< T > other)
 Assignment operator, turns this buffer into a reference to the other buffer. More...
 
bool operator< (const Buffer< T > &other) const
 This is used to store buffers in sets. More...
 
size_t size () const
 Returns the number of elements of type T in this buffer. More...
 
T & operator[] (int idx) const
 Element access. More...
 
double norm2 () const
 Returns the $l^2$ norm of the buffer. More...
 
double norm () const
 Returns the $l^1$ norm of the buffer. More...
 
double norm (double p) const
 Returns the $l^p$ norm of the buffer. More...
 
Buffer< T > & operator*= (const T &a)
 In-place, element wise product of the buffer with the scalar a. More...
 
Buffer< T > & operator/= (const T &a)
 In-place, element wise division of the buffer with the scalar a. More...
 
template<class oT >
Buffer< oT > as () const
 Explicit type cast. More...
 
Buffer< T > sub (size_t offset, size_t len) const
 Returns a new view on this buffer. More...
 
Buffer< T > head (size_t n) const
 Returns a new view on this buffer. More...
 
Buffer< T > tail (size_t n) const
 Returns a new view on this buffer. More...
 
- Public Member Functions inherited from sdr::RawBuffer
 RawBuffer ()
 Constructs an empty buffer. More...
 
 RawBuffer (char *data, size_t offset, size_t len)
 Constructor from unowned data. More...
 
 RawBuffer (size_t N, BufferOwner *owner=0)
 Constructs a buffer and allocates N bytes. More...
 
 RawBuffer (const RawBuffer &other)
 Copy constructor. More...
 
 RawBuffer (const RawBuffer &other, size_t offset, size_t len)
 Creates a new view on the buffer. More...
 
virtual ~RawBuffer ()
 Destructor. More...
 
const RawBufferoperator= (const RawBuffer &other)
 Assignment. More...
 
char * ptr () const
 Returns the pointer to the data (w/o view). More...
 
char * data () const
 Returns the pointer to the data of the buffer view. More...
 
size_t bytesOffset () const
 Returns the offset of the data by the view. More...
 
size_t bytesLen () const
 Returns the size of the buffer by the view. More...
 
size_t storageSize () const
 Returns the raw buffer size in bytes. More...
 
bool isEmpty () const
 Returns true if the buffer is invalid/empty. More...
 
void ref () const
 Increment reference counter. More...
 
void unref ()
 Dereferences the buffer. More...
 
int refCount () const
 Returns the reference counter. More...
 
bool isUnused () const
 We assume here that buffers are owned by one object: A buffer is therefore "unused" if the owner holds the only reference to the buffer. More...
 

Protected Attributes

size_t _size
 Holds the number of elements of type T in the buffer. More...
 
- Protected Attributes inherited from sdr::RawBuffer
char * _ptr
 Holds the pointer to the data or 0, if buffer is empty. More...
 
size_t _storage_size
 Holds the size of the buffer in bytes. More...
 
size_t _b_offset
 Holds the offset of the buffer in bytes. More...
 
size_t _b_length
 Holds the length of the buffer (view) in bytes. More...
 
int * _refcount
 The reference counter. More...
 
BufferOwner_owner
 Holds a weak reference the buffer owner. More...
 

Detailed Description

template<class T>
class sdr::Buffer< T >

A typed buffer.

Constructor & Destructor Documentation

template<class T>
sdr::Buffer< T >::Buffer ( )
inline

Empty constructor.

template<class T>
sdr::Buffer< T >::Buffer ( T *  data,
size_t  size 
)
inline

Constructor from raw data.

template<class T>
sdr::Buffer< T >::Buffer ( size_t  N,
BufferOwner owner = 0 
)
inline

Creates a buffer with N samples.

template<class T>
sdr::Buffer< T >::Buffer ( const Buffer< T > &  other)
inline

Create a new reference to the buffer.

template<class T>
virtual sdr::Buffer< T >::~Buffer ( )
inlinevirtual

Destructor.

template<class T>
sdr::Buffer< T >::Buffer ( const RawBuffer< T > &  other)
inlineexplicit

Explicit type cast.

Member Function Documentation

template<class T>
template<class oT >
Buffer<oT> sdr::Buffer< T >::as ( ) const
inline

Explicit type cast.

template<class T>
Buffer<T> sdr::Buffer< T >::head ( size_t  n) const
inline

Returns a new view on this buffer.

template<class T>
double sdr::Buffer< T >::norm ( ) const
inline

Returns the $l^1$ norm of the buffer.

template<class T>
double sdr::Buffer< T >::norm ( double  p) const
inline

Returns the $l^p$ norm of the buffer.

template<class T>
double sdr::Buffer< T >::norm2 ( ) const
inline

Returns the $l^2$ norm of the buffer.

template<class T>
Buffer<T>& sdr::Buffer< T >::operator*= ( const T &  a)
inline

In-place, element wise product of the buffer with the scalar a.

template<class T>
Buffer<T>& sdr::Buffer< T >::operator/= ( const T &  a)
inline

In-place, element wise division of the buffer with the scalar a.

template<class T>
bool sdr::Buffer< T >::operator< ( const Buffer< T > &  other) const
inline

This is used to store buffers in sets.

The comparison is performed on the pointer of the buffers and not on their content.

template<class T>
const Buffer<T>& sdr::Buffer< T >::operator= ( const Buffer< T >  other)
inline

Assignment operator, turns this buffer into a reference to the other buffer.

template<class T>
T& sdr::Buffer< T >::operator[] ( int  idx) const
inline

Element access.

If compiled in debug mode, this function will perform a check on the index and throws a RuntimeError exception if the index is out of bounds.

template<class T>
size_t sdr::Buffer< T >::size ( ) const
inline

Returns the number of elements of type T in this buffer.

template<class T>
Buffer<T> sdr::Buffer< T >::sub ( size_t  offset,
size_t  len 
) const
inline

Returns a new view on this buffer.

template<class T>
Buffer<T> sdr::Buffer< T >::tail ( size_t  n) const
inline

Returns a new view on this buffer.

Member Data Documentation

template<class T>
size_t sdr::Buffer< T >::_size
protected

Holds the number of elements of type T in the buffer.


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