ROSE  0.9.6a
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MemoryMap::Buffer Class Referenceabstract

Base class for data associated with a memory segment. More...

#include <MemoryMap.h>

Inheritance diagram for MemoryMap::Buffer:
Collaboration diagram for MemoryMap::Buffer:

Public Member Functions

virtual ~Buffer ()
 
virtual BufferPtr clone () const =0
 Create a new buffer from an existing buffer. More...
 
virtual size_t read (void *buf, size_t offset, size_t nbytes) const =0
 Reads data from a buffer. More...
 
virtual size_t write (const void *buf, size_t offset, size_t nbytes)=0
 Writes data into a buffer. More...
 
virtual void save (const std::string &filename) const
 Saves data to a file. More...
 
virtual const void * get_data_ptr () const =0
 Return pointer to low-level data. More...
 
virtual bool is_zero () const
 Returns true if the buffer's data is all zero. More...
 
virtual bool is_read_only () const
 Property indicating whether buffer is read-only. More...
 
virtual void set_read_only (bool b=true)
 Property indicating whether buffer is read-only. More...
 
void clear_read_only ()
 Property indicating whether buffer is read-only. More...
 
virtual std::string get_name () const
 Debug name for buffer. More...
 
virtual void set_name (const std::string &s)
 Debug name for buffer. More...
 
virtual size_t size () const
 Size of buffer in bytes. More...
 
virtual void resize (size_t n)
 Size of buffer in bytes. More...
 

Protected Member Functions

 Buffer (size_t size)
 
std::string new_name ()
 

Protected Attributes

bool read_only
 If true, buffer data cannot be modified. More...
 
std::string name
 Name for debugging. More...
 
size_t p_size
 Size of buffer in bytes. More...
 

Detailed Description

Base class for data associated with a memory segment.

Memory map buffers are reference counted and managed by boost::shared_ptr. Use the class' create methods to allocate new Buffer objects. A Buffer object usually (but not necessarily) points to an array of bytes, and it is up to the Buffer subclass as to how to manage that array. The Buffer desctructor is only called when its reference count reaches zero.

Definition at line 113 of file MemoryMap.h.

Constructor & Destructor Documentation

virtual MemoryMap::Buffer::~Buffer ( )
inlinevirtual

Definition at line 115 of file MemoryMap.h.

MemoryMap::Buffer::Buffer ( size_t  size)
inlineprotected

Definition at line 172 of file MemoryMap.h.

References name, and new_name().

Member Function Documentation

virtual BufferPtr MemoryMap::Buffer::clone ( ) const
pure virtual

Create a new buffer from an existing buffer.

The new buffer will point to a different copy of the data so that writing data into one buffer will not cause it to appear when reading from the other buffer. The type of the new buffer might not be the same as this buffer because not all buffers are able to copy their data. For instance, cloning an ExternBuffer or a MmapBuffer will create a ByteBuffer.

Implemented in MemoryMap::AnonymousBuffer, MemoryMap::ExternBuffer, and MemoryMap::NullBuffer.

virtual bool MemoryMap::Buffer::is_read_only ( ) const
inlinevirtual

Property indicating whether buffer is read-only.

The "modifiability" of a buffer is orthogonal to whether segments pointing to this buffer have the MemoryMap::MM_PROT_WRITE bit set. For instance, the storage for the buffer can be a const buffer (is_read_only() returning true) even though a MemoryMap::Segment could be marked as writable.

Definition at line 127 of file MemoryMap.h.

References read_only.

virtual void MemoryMap::Buffer::set_read_only ( bool  b = true)
inlinevirtual

Property indicating whether buffer is read-only.

The "modifiability" of a buffer is orthogonal to whether segments pointing to this buffer have the MemoryMap::MM_PROT_WRITE bit set. For instance, the storage for the buffer can be a const buffer (is_read_only() returning true) even though a MemoryMap::Segment could be marked as writable.

Definition at line 128 of file MemoryMap.h.

References read_only.

Referenced by clear_read_only(), MemoryMap::ExternBuffer::ExternBuffer(), and MemoryMap::MmapBuffer::MmapBuffer().

void MemoryMap::Buffer::clear_read_only ( )
inline

Property indicating whether buffer is read-only.

The "modifiability" of a buffer is orthogonal to whether segments pointing to this buffer have the MemoryMap::MM_PROT_WRITE bit set. For instance, the storage for the buffer can be a const buffer (is_read_only() returning true) even though a MemoryMap::Segment could be marked as writable.

Definition at line 129 of file MemoryMap.h.

References set_read_only().

virtual std::string MemoryMap::Buffer::get_name ( ) const
inlinevirtual

Debug name for buffer.

Rather than print buffer pointers to distinguish one buffer from another, we use a three character name composed of the 26 lower-case letters. The user can set this name to something else if they like.

Definition at line 135 of file MemoryMap.h.

References name.

Referenced by MemoryMap::AnonymousBuffer::create().

virtual void MemoryMap::Buffer::set_name ( const std::string &  s)
inlinevirtual

Debug name for buffer.

Rather than print buffer pointers to distinguish one buffer from another, we use a three character name composed of the 26 lower-case letters. The user can set this name to something else if they like.

Definition at line 136 of file MemoryMap.h.

References name.

Referenced by MemoryMap::AnonymousBuffer::create().

virtual size_t MemoryMap::Buffer::size ( void  ) const
inlinevirtual

Size of buffer in bytes.

Definition at line 141 of file MemoryMap.h.

References p_size.

Referenced by MemoryMap::NullBuffer::clone().

virtual void MemoryMap::Buffer::resize ( size_t  n)
inlinevirtual

Size of buffer in bytes.

Reimplemented in MemoryMap::MmapBuffer, and MemoryMap::ExternBuffer.

Definition at line 142 of file MemoryMap.h.

References p_size.

virtual size_t MemoryMap::Buffer::read ( void *  buf,
size_t  offset,
size_t  nbytes 
) const
pure virtual

Reads data from a buffer.

Reads up to nbytes of data from this buffer and copies it to the caller-supplied address, the buf argument. Reading starts at the specified byte offset from the beginning of this buffer. Returns the number of bytes copied. The output buffer is not zero-padded for short reads.

If buf is the null pointer, then no data is copied and the return value is the number of bytes that would have been copied if buf had not been null.

Implemented in MemoryMap::AnonymousBuffer, MemoryMap::ExternBuffer, and MemoryMap::NullBuffer.

virtual size_t MemoryMap::Buffer::write ( const void *  buf,
size_t  offset,
size_t  nbytes 
)
pure virtual

Writes data into a buffer.

Writes up to nbytes of data from buf into this buffer starting at the specified byte offset within this buffer. Returns the number of bytes written. The return value will be less than nbytes if an error occurs.

Implemented in MemoryMap::AnonymousBuffer, MemoryMap::ExternBuffer, and MemoryMap::NullBuffer.

void MemoryMap::Buffer::save ( const std::string &  filename) const
virtual

Saves data to a file.

Writes the entire buffer contents to the specified file, creating or truncating the file if necessary.

Definition at line 116 of file MemoryMap.C.

References offset, and MemoryMap::read().

virtual const void* MemoryMap::Buffer::get_data_ptr ( ) const
pure virtual

Return pointer to low-level data.

This probably shouldn't be used to access the data because it makes assumptions about the implementation (use read() and write() methods instead). But it is sometimes useful when trying to determine if a buffer was initialized with data known to the caller.

Implemented in MemoryMap::AnonymousBuffer, MemoryMap::ExternBuffer, and MemoryMap::NullBuffer.

bool MemoryMap::Buffer::is_zero ( ) const
virtual

Returns true if the buffer's data is all zero.

Some subclasses will be able to do something more efficient than reading all the data.

Reimplemented in MemoryMap::AnonymousBuffer.

Definition at line 132 of file MemoryMap.C.

References MemoryMap::at(), MemoryMap::read(), and MemoryMap::size().

Referenced by MemoryMap::AnonymousBuffer::is_zero().

std::string MemoryMap::Buffer::new_name ( )
protected

Definition at line 103 of file MemoryMap.C.

Referenced by Buffer().

Member Data Documentation

bool MemoryMap::Buffer::read_only
protected

If true, buffer data cannot be modified.

Definition at line 175 of file MemoryMap.h.

Referenced by is_read_only(), and set_read_only().

std::string MemoryMap::Buffer::name
protected

Name for debugging.

Definition at line 176 of file MemoryMap.h.

Referenced by Buffer(), get_name(), and set_name().

size_t MemoryMap::Buffer::p_size
protected

Size of buffer in bytes.

Definition at line 177 of file MemoryMap.h.

Referenced by resize(), and size().


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