ROSE 0.11.145.147
Public Types | Public Member Functions | Protected Member Functions | List of all members
Sawyer::Container::Buffer< A, T > Class Template Referenceabstract

Description

template<class A, class T>
class Sawyer::Container::Buffer< A, T >

Base class for all buffers.

A buffer stores a sequence of elements somewhat like a vector, but imparts a read/write paradigm for accessing those elements.

Definition at line 23 of file Buffer.h.

#include <Sawyer/Buffer.h>

Inheritance diagram for Sawyer::Container::Buffer< A, T >:
Inheritance graph
[legend]
Collaboration diagram for Sawyer::Container::Buffer< A, T >:
Collaboration graph
[legend]

Public Types

typedef SharedPointer< BufferPtr
 Reference counting smart pointer.
 
typedef A Address
 Key type for addressing data.
 
typedef T Value
 Type of values stored in the buffer.
 

Public Member Functions

virtual Ptr copy () const =0
 Create a new copy of buffer data.
 
virtual Address available (Address address) const =0
 Distance to end of buffer.
 
virtual Address size () const
 Size of buffer.
 
virtual void resize (Address n)=0
 Change the size of the buffer.
 
virtual void sync ()
 Synchronize buffer with persistent storage.
 
virtual Address read (Value *buf, Address address, Address n) const =0
 Reads data from a buffer.
 
virtual Address write (const Value *buf, Address address, Address n)=0
 Writes data to a buffer.
 
virtual const Valuedata () const =0
 Data for the buffer.
 
const std::string & name () const
 Property: Name.
 
void name (const std::string &s)
 Property: Name.
 
bool copyOnWrite () const
 Property: Copy on write.
 
void copyOnWrite (bool b)
 Property: Copy on write.
 
- Public Member Functions inherited from Sawyer::SharedObject
 SharedObject ()
 Default constructor.
 
 SharedObject (const SharedObject &)
 Copy constructor.
 
virtual ~SharedObject ()
 Virtual destructor.
 
SharedObjectoperator= (const SharedObject &)
 Assignment.
 

Protected Member Functions

 Buffer (const std::string &name="")
 

Member Typedef Documentation

◆ Ptr

template<class A , class T >
typedef SharedPointer<Buffer> Sawyer::Container::Buffer< A, T >::Ptr

Reference counting smart pointer.

See also
smart_pointers

Definition at line 62 of file Buffer.h.

◆ Address

template<class A , class T >
typedef A Sawyer::Container::Buffer< A, T >::Address

Key type for addressing data.

The key type should be an unsigned integral type and is the type used to index the data.

Definition at line 67 of file Buffer.h.

◆ Value

template<class A , class T >
typedef T Sawyer::Container::Buffer< A, T >::Value

Type of values stored in the buffer.

Definition at line 70 of file Buffer.h.

Constructor & Destructor Documentation

◆ Buffer()

template<class A , class T >
Sawyer::Container::Buffer< A, T >::Buffer ( const std::string &  name = "")
inlineexplicitprotected

Definition at line 28 of file Buffer.h.

◆ ~Buffer()

template<class A , class T >
virtual Sawyer::Container::Buffer< A, T >::~Buffer ( )
inlinevirtual

Definition at line 73 of file Buffer.h.

Member Function Documentation

◆ copy()

template<class A , class T >
virtual Ptr Sawyer::Container::Buffer< A, T >::copy ( ) const
pure virtual

Create a new copy of buffer data.

Returns a new buffer containing the same data as the old buffer. Some buffer types cannot make an exact copy, in which case they should return an AllocatingBuffer that holds a snapshot of the source buffer's data as it existed at the time of this operation.

Implemented in Sawyer::Container::AllocatingBuffer< A, T >, Sawyer::Container::MappedBuffer< A, T >, Sawyer::Container::NullBuffer< A, T >, and Sawyer::Container::StaticBuffer< A, T >.

◆ available()

template<class A , class T >
virtual Address Sawyer::Container::Buffer< A, T >::available ( Address  address) const
pure virtual

Distance to end of buffer.

The distance in units of the Value type from the specified address (inclusive) to the last element of the buffer (inclusive). If the address is beyond the end of the buffer then a distance of zero is returned rather than a negative distance. Note that the return value will overflow to zero if the buffer spans the entire address space.

Implemented in Sawyer::Container::MappedBuffer< A, T >, Sawyer::Container::AllocatingBuffer< A, T >, Sawyer::Container::NullBuffer< A, T >, and Sawyer::Container::StaticBuffer< A, T >.

Referenced by Sawyer::Container::Buffer< A, T >::size().

◆ size()

template<class A , class T >
virtual Address Sawyer::Container::Buffer< A, T >::size ( ) const
inlinevirtual

Size of buffer.

Returns the number of Value elements stored in the buffer. In other words, this is the first address beyond the end of the buffer. Note that the return value may overflow to zero if the buffer spans the entire address space.

Definition at line 93 of file Buffer.h.

References Sawyer::Container::Buffer< A, T >::available().

Referenced by Sawyer::Container::AllocatingBuffer< A, T >::copy(), Sawyer::Container::MappedBuffer< A, T >::copy(), Sawyer::Container::AllocatingBuffer< A, T >::instance(), Sawyer::Container::NullBuffer< A, T >::instance(), Sawyer::Container::StaticBuffer< A, T >::instance(), Sawyer::Container::StaticBuffer< A, T >::instance(), and Sawyer::Container::MappedBuffer< A, T >::resize().

◆ resize()

template<class A , class T >
virtual void Sawyer::Container::Buffer< A, T >::resize ( Address  n)
pure virtual

Change the size of the buffer.

Truncates the buffer to a smaller size, or extends the buffer as necessary to make its size n values.

Implemented in Sawyer::Container::MappedBuffer< A, T >, Sawyer::Container::AllocatingBuffer< A, T >, Sawyer::Container::NullBuffer< A, T >, and Sawyer::Container::StaticBuffer< A, T >.

◆ sync()

template<class A , class T >
virtual void Sawyer::Container::Buffer< A, T >::sync ( )
inlinevirtual

Synchronize buffer with persistent storage.

If the buffer is backed by a file of some sort, then synchronize the buffer contents with the file by writing to the file any buffer values that have changed.

Definition at line 104 of file Buffer.h.

◆ name() [1/2]

template<class A , class T >
const std::string & Sawyer::Container::Buffer< A, T >::name ( ) const
inline

Property: Name.

An arbitrary string stored as part of the buffer, usually used for debugging.

Definition at line 111 of file Buffer.h.

◆ name() [2/2]

template<class A , class T >
void Sawyer::Container::Buffer< A, T >::name ( const std::string &  s)
inline

Property: Name.

An arbitrary string stored as part of the buffer, usually used for debugging.

Definition at line 112 of file Buffer.h.

◆ read()

template<class A , class T >
virtual Address Sawyer::Container::Buffer< A, T >::read ( Value buf,
Address  address,
Address  n 
) const
pure virtual

Reads data from a buffer.

Reads up to n values from this buffer beginning at the specified address and copies them to the caller-supplied argument. Returns the number of values actually copied, which may be smaller than the number requested. The output buffer is not zero-padded for short reads. Also note that the return value may overflow to zero if the entire address space is read.

As a special case, if buf is a null pointer, then no data is copied and the return value indicates the number of values that would have been copied had buf been non-null.

Implemented in Sawyer::Container::AllocatingBuffer< A, T >, Sawyer::Container::MappedBuffer< A, T >, Sawyer::Container::NullBuffer< A, T >, and Sawyer::Container::StaticBuffer< A, T >.

◆ write()

template<class A , class T >
virtual Address Sawyer::Container::Buffer< A, T >::write ( const Value buf,
Address  address,
Address  n 
)
pure virtual

Writes data to a buffer.

Writes up to n values from buf into this buffer starting at the specified address. Returns the number of values actually written, which might be smaller than n. The return value will be less than n if an error occurs, but note that the return value may overflow to zero if the entire address space is written.

Implemented in Sawyer::Container::NullBuffer< A, T >, Sawyer::Container::AllocatingBuffer< A, T >, Sawyer::Container::MappedBuffer< A, T >, and Sawyer::Container::StaticBuffer< A, T >.

◆ data()

template<class A , class T >
virtual const Value * Sawyer::Container::Buffer< A, T >::data ( ) const
pure virtual

Data for the buffer.

Returns a pointer for the buffer data. Those subclasses that don't support this method will return the null pointer.

Implemented in Sawyer::Container::AllocatingBuffer< A, T >, Sawyer::Container::MappedBuffer< A, T >, Sawyer::Container::NullBuffer< A, T >, and Sawyer::Container::StaticBuffer< A, T >.

◆ copyOnWrite() [1/2]

template<class A , class T >
bool Sawyer::Container::Buffer< A, T >::copyOnWrite ( ) const
inline

Property: Copy on write.

This is a bit stored in the buffer and is used by higher layers to implement copy-on-write. The buffer itself does nothing with this bit.

Definition at line 144 of file Buffer.h.

◆ copyOnWrite() [2/2]

template<class A , class T >
void Sawyer::Container::Buffer< A, T >::copyOnWrite ( bool  b)
inline

Property: Copy on write.

This is a bit stored in the buffer and is used by higher layers to implement copy-on-write. The buffer itself does nothing with this bit.

Definition at line 145 of file Buffer.h.


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