#include <membuf.h>
Public Types | |
enum | { INVALID_MARK = 0xFFFFFFFF, MAX_LEN = 0xFFFFFFFF } |
Public Member Functions | |
void | clear () |
Rewinds the membuf The position is set to 0 and the mark is invalidated. | |
virtual MemBuf * | clone () const |
void | compact () |
Compacts the buffer and prepares it for a new read. | |
byte * | data () const |
Returns the raw buffer data. | |
void | dependant (CoreObject *g) |
Links this data to a CoreObject. | |
CoreObject * | dependant () const |
Return the CoreObject that stores vital data for this mempool. | |
void | flip () |
After a write, prepares for a read. | |
virtual void | gcMark (uint32 gen) |
Applies mark to subclasses. | |
uint32 | get () |
Gets a value at current position and advance. | |
virtual uint32 | get (uint32 pos) const =0 |
uint32 | getMark () const |
void | length (uint32 s) |
Sets the amount of items in this buffer. | |
uint32 | length () const |
void | limit (uint32 l) |
Sets the limit of read operations. | |
uint32 | limit () const |
MemBuf (uint32 ws, byte *data, uint32 length, tf_deletor deletor) | |
Creates an owned memory buffer. | |
MemBuf (uint32 ws, byte *data, uint32 length) | |
Creates an unowned memory buffer. | |
MemBuf (uint32 ws, uint32 length) | |
Creates a pure memory based memory buffer. | |
void | placeMark () |
Mark current position. | |
void | placeMark (uint32 m) |
Mark a position for a subquesent reset. | |
void | position (uint32 p) |
Set current read-write position. | |
uint32 | position () const |
void | put (uint32 data) |
Puts a value at current position and advance. | |
virtual void | readIndex (const Item &pos, Item &target) |
Implements the deep item interface. | |
virtual void | readProperty (const String &, Item &item) |
Implements the deep item interface. | |
uint32 | remaining () const |
Return the amount of items that can be taken before causing an exception. | |
void | reset () |
Returns the pointer at previous mark. | |
void | resize (uint32 newSize) |
Resizes the Memory Buffer Invariants are maintained. | |
void | rewind () |
Rewinds the membuf The position is set to 0 and the mark is invalidated. | |
virtual bool | serialize (Stream *stream, bool bLive=false) const |
virtual void | set (uint32 pos, uint32 value)=0 |
void | setData (byte *data, uint32 length, tf_deletor deletor=0) |
uint32 | size () const |
Returns the size of the buffer in bytes. | |
uint16 | wordSize () const |
virtual void | writeIndex (const Item &pos, const Item &target) |
Implements the deep item interface. | |
virtual void | writeProperty (const String &, const Item &item) |
Implements the deep item interface. | |
virtual | ~MemBuf () |
Destructor. | |
Static Public Member Functions | |
static MemBuf * | create (int nWordSize, uint32 length) |
Creates a membuf with defined wordsize. | |
static MemBuf * | deserialize (VMachine *vm, Stream *stream) |
Public Attributes | |
enum Falcon::MemBuf:: { ... } | t_enum_mark |
Protected Attributes | |
uint16 | m_byteOrder |
tf_deletor | m_deletor |
CoreObject * | m_dependant |
uint32 | m_length |
uint32 | m_limit |
uint32 | m_mark |
byte * | m_memory |
uint32 | m_position |
uint16 | m_wordSize |
typedef void(* Falcon::MemBuf::tf_deletor)(void *memory) |
Creates a pure memory based memory buffer.
This constructor creates a memory buffer containing a memory data that will be freed at buffer destruction.
Creates an unowned memory buffer.
This simply stores the data in this memory buffer; the ownership of the data stays on the creator, which must dispose it separately.
ws | Size of each element in bytes (1-4) | |
data | The memory buffer | |
length | Maximum length of the buffer; pass MAX_LEN if unknown, or 0 if unknown and unavailable to the calling program. |
Falcon::MemBuf::MemBuf | ( | uint32 | ws, | |
byte * | data, | |||
uint32 | length, | |||
tf_deletor | deletor | |||
) |
Creates an owned memory buffer.
This stores the memory in the memory buffer and associates it with a deletor function which will be called when this MemBuf is disposed of. the ownership of the data stays on the creator, which must dispose it separately.
ws | Size of each element in bytes (1-4) | |
data | The memory buffer | |
length | Maximum length of the buffer; pass MAX_LEN if unknown, or 0 if unknown and unavailable to the calling program. | |
deletor | The deletor for the given data. Pass memFree for data created with memAlloc, or 0 to make data unowned. |
virtual Falcon::MemBuf::~MemBuf | ( | ) | [virtual] |
Destructor.
The destructor will also destroy the associated data if a deletor function has been specified in the constructor.
void Falcon::MemBuf::clear | ( | ) | [inline] |
Rewinds the membuf The position is set to 0 and the mark is invalidated.
Limit is set to size.
virtual MemBuf* Falcon::MemBuf::clone | ( | ) | const [virtual] |
void Falcon::MemBuf::compact | ( | ) |
Compacts the buffer and prepares it for a new read.
Remaining data, if any, is moved to the beginning of the buffer. Position is set to the previous limit, and limit is set to length. The mark is discarded.
Creates a membuf with defined wordsize.
The length parameter is the final element count; it gets multiplied by nWordSize.
byte* Falcon::MemBuf::data | ( | ) | const [inline] |
void Falcon::MemBuf::dependant | ( | CoreObject * | g | ) | [inline] |
Links this data to a CoreObject.
Some object may provide MemBuf properties to access data or data portion stored in some part of the user_data they reflect.
To make this possible and easy, the MemBuf can be given a back reference to the object that created it. In this way, the object will be granted to stay alive as long as the MemBuf is alive.
CoreObject* Falcon::MemBuf::dependant | ( | ) | const [inline] |
Return the CoreObject that stores vital data for this mempool.
void Falcon::MemBuf::flip | ( | ) | [inline] |
After a write, prepares for a read.
Useful to parse an incoming buffer or to drop the incoming buffer in another place.
virtual void Falcon::MemBuf::gcMark | ( | uint32 | mk | ) | [virtual] |
Applies mark to subclasses.
By default, this method just changes the mark() value.
Subclasses having deep data may overload this to take care of marking it.
Reimplemented from Falcon::Garbageable.
uint32 Falcon::MemBuf::get | ( | ) | [inline] |
Gets a value at current position and advance.
Will throw AccessError on error. This is meant to be called from scripts.
Implemented in Falcon::MemBuf_1, Falcon::MemBuf_2, Falcon::MemBuf_3, and Falcon::MemBuf_4.
uint32 Falcon::MemBuf::getMark | ( | ) | const [inline] |
void Falcon::MemBuf::length | ( | uint32 | s | ) | [inline] |
Sets the amount of items in this buffer.
The actual size in bytes is obtained multiplying this length by the word size.
uint32 Falcon::MemBuf::length | ( | ) | const [inline] |
void Falcon::MemBuf::limit | ( | uint32 | l | ) | [inline] |
Sets the limit of read operations.
uint32 Falcon::MemBuf::limit | ( | ) | const [inline] |
void Falcon::MemBuf::placeMark | ( | ) | [inline] |
Mark current position.
Records the position() as it is now. A subquesent reset() will bring the position() pointer here.
void Falcon::MemBuf::placeMark | ( | uint32 | m | ) | [inline] |
Mark a position for a subquesent reset.
A subquesent reset() will bring the position() pointer here.
void Falcon::MemBuf::position | ( | uint32 | p | ) | [inline] |
Set current read-write position.
Will throw if the limit is less than the current length().
uint32 Falcon::MemBuf::position | ( | ) | const [inline] |
void Falcon::MemBuf::put | ( | uint32 | data | ) | [inline] |
Puts a value at current position and advance.
Will throw AccessError on error. This is meant to be called from scripts.
Implements the deep item interface.
May throw AccessError * if the pos doesn't represents a valid item index for the current type.
Implements Falcon::DeepItem.
Implements the deep item interface.
May throw AccessError * if the property cannot be read.
Implements Falcon::DeepItem.
uint32 Falcon::MemBuf::remaining | ( | ) | const [inline] |
Return the amount of items that can be taken before causing an exception.
void Falcon::MemBuf::reset | ( | ) | [inline] |
Returns the pointer at previous mark.
Raises an access error if the mark is not set.
void Falcon::MemBuf::resize | ( | uint32 | newSize | ) |
Resizes the Memory Buffer Invariants are maintained.
newSize | number of items stored. |
void Falcon::MemBuf::rewind | ( | ) | [inline] |
Rewinds the membuf The position is set to 0 and the mark is invalidated.
virtual bool Falcon::MemBuf::serialize | ( | Stream * | stream, | |
bool | bLive = false | |||
) | const [virtual] |
Implemented in Falcon::MemBuf_1, Falcon::MemBuf_2, Falcon::MemBuf_3, and Falcon::MemBuf_4.
void Falcon::MemBuf::setData | ( | byte * | data, | |
uint32 | length, | |||
tf_deletor | deletor = 0 | |||
) |
uint32 Falcon::MemBuf::size | ( | ) | const [inline] |
Returns the size of the buffer in bytes.
It's the length of the buffer * the word size.
uint16 Falcon::MemBuf::wordSize | ( | ) | const [inline] |
Implements the deep item interface.
May throw AccessError * if the pos doesn't represents a valid item index for the current type or if the target item can't be set into this item at the given index.
Implements Falcon::DeepItem.
Implements the deep item interface.
May throw AccessError * if the property cannot be set.
Implements Falcon::DeepItem.
uint16 Falcon::MemBuf::m_byteOrder [protected] |
tf_deletor Falcon::MemBuf::m_deletor [protected] |
CoreObject* Falcon::MemBuf::m_dependant [protected] |
uint32 Falcon::MemBuf::m_length [protected] |
uint32 Falcon::MemBuf::m_limit [protected] |
uint32 Falcon::MemBuf::m_mark [protected] |
byte* Falcon::MemBuf::m_memory [protected] |
uint32 Falcon::MemBuf::m_position [protected] |
uint16 Falcon::MemBuf::m_wordSize [protected] |
enum { ... } Falcon::MemBuf::t_enum_mark |