ROSE  0.11.145.0
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
Sawyer::Container::MappedBuffer< A, T > Class Template Reference

Description

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

Memory mapped file.

This buffer points to a file that is mapped into memory by the operating system. The API supports a common divisor for POSIX and Microsoft Windows and is therefore not all that powerful, but it does allow simple maps to be created that have a file as backing store. See http://www.boost.org/doc/libs for more information.

Access modes are the following enumerated constants:

When a file is mapped with private access changes written to the buffer are not reflected in the underlying file.

Definition at line 43 of file MappedBuffer.h.

#include <util/Sawyer/MappedBuffer.h>

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

Public Types

typedef A Address
 Type of addresses. More...
 
typedef T Value
 Type of values. More...
 
typedef Buffer< A, T > Super
 Type of base class. More...
 
- Public Types inherited from Sawyer::Container::Buffer< A, T >
typedef SharedPointer< BufferPtr
 Reference counting smart pointer. More...
 
typedef A Address
 Key type for addressing data. More...
 
typedef T Value
 Type of values stored in the buffer. More...
 

Public Member Functions

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

Static Public Member Functions

static Buffer< A, T >::Ptr instance (const boost::iostreams::mapped_file_params &params)
 Map a file according to boost parameters. More...
 
static Buffer< A, T >::Ptr instance (const boost::filesystem::path &path, boost::iostreams::mapped_file::mapmode mode=boost::iostreams::mapped_file::readonly, boost::intmax_t offset=0, boost::iostreams::mapped_file::size_type length=boost::iostreams::mapped_file::max_length)
 Map a file by name. More...
 

Protected Member Functions

 MappedBuffer (const boost::iostreams::mapped_file_params &params)
 
- Protected Member Functions inherited from Sawyer::Container::Buffer< A, T >
 Buffer (const std::string &name="")
 

Member Typedef Documentation

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

Type of addresses.

Definition at line 48 of file MappedBuffer.h.

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

Type of values.

Definition at line 49 of file MappedBuffer.h.

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

Type of base class.

Definition at line 50 of file MappedBuffer.h.

Member Function Documentation

template<class A , class T >
static Buffer<A, T>::Ptr Sawyer::Container::MappedBuffer< A, T >::instance ( const boost::iostreams::mapped_file_params &  params)
inlinestatic

Map a file according to boost parameters.

The parameters describe which file (by name) and part thereof should be mapped into memory.

Definition at line 105 of file MappedBuffer.h.

References Sawyer::Container::StaticBuffer< A, T >::instance().

Referenced by Sawyer::Container::MappedBuffer< A, T >::instance().

template<class A , class T >
static Buffer<A, T>::Ptr Sawyer::Container::MappedBuffer< A, T >::instance ( const boost::filesystem::path &  path,
boost::iostreams::mapped_file::mapmode  mode = boost::iostreams::mapped_file::readonly,
boost::intmax_t  offset = 0,
boost::iostreams::mapped_file::size_type  length = boost::iostreams::mapped_file::max_length 
)
inlinestatic

Map a file by name.

The specified file, which must already exist, is mapped into memory and pointed to by this new buffer.

Definition at line 123 of file MappedBuffer.h.

References Sawyer::Container::MappedBuffer< A, T >::instance().

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

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.

Implements Sawyer::Container::Buffer< A, T >.

Definition at line 138 of file MappedBuffer.h.

References Sawyer::Container::AllocatingBuffer< A, T >::instance(), and Sawyer::Container::Buffer< A, T >::size().

template<class A , class T >
Address Sawyer::Container::MappedBuffer< A, T >::available ( Address  address) const
inlinevirtual

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.

Implements Sawyer::Container::Buffer< A, T >.

Definition at line 150 of file MappedBuffer.h.

Referenced by Sawyer::Container::MappedBuffer< A, T >::read(), and Sawyer::Container::MappedBuffer< A, T >::write().

template<class A , class T >
void Sawyer::Container::MappedBuffer< A, T >::resize ( Address  n)
inlinevirtual

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.

Implements Sawyer::Container::Buffer< A, T >.

Definition at line 154 of file MappedBuffer.h.

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

template<class A , class T >
Address Sawyer::Container::MappedBuffer< A, T >::read ( Value buf,
Address  address,
Address  n 
) const
inlinevirtual

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.

Implements Sawyer::Container::Buffer< A, T >.

Definition at line 159 of file MappedBuffer.h.

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

template<class A , class T >
Address Sawyer::Container::MappedBuffer< A, T >::write ( const Value buf,
Address  address,
Address  n 
)
inlinevirtual

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.

Implements Sawyer::Container::Buffer< A, T >.

Definition at line 165 of file MappedBuffer.h.

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

template<class A , class T >
const Value* Sawyer::Container::MappedBuffer< A, T >::data ( ) const
inlinevirtual

Data for the buffer.

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

Implements Sawyer::Container::Buffer< A, T >.

Definition at line 171 of file MappedBuffer.h.


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