ROSE
0.9.6a
|
Base class for data associated with a memory segment. More...
#include <MemoryMap.h>
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... | |
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.
|
inlinevirtual |
Definition at line 115 of file MemoryMap.h.
|
inlineprotected |
Definition at line 172 of file MemoryMap.h.
References name, and new_name().
|
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.
|
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.
|
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().
|
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().
|
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().
|
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().
|
inlinevirtual |
Size of buffer in bytes.
Definition at line 141 of file MemoryMap.h.
References p_size.
Referenced by MemoryMap::NullBuffer::clone().
|
inlinevirtual |
Size of buffer in bytes.
Reimplemented in MemoryMap::MmapBuffer, and MemoryMap::ExternBuffer.
Definition at line 142 of file MemoryMap.h.
References p_size.
|
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.
|
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.
|
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().
|
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.
|
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().
|
protected |
Definition at line 103 of file MemoryMap.C.
Referenced by Buffer().
|
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().
|
protected |
Name for debugging.
Definition at line 176 of file MemoryMap.h.
Referenced by Buffer(), get_name(), and set_name().
|
protected |
Size of buffer in bytes.
Definition at line 177 of file MemoryMap.h.