Falcon::MemBuf Class Reference

#include <membuf.h>

Inheritance diagram for Falcon::MemBuf:

Inheritance graph
[legend]

List of all members.

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 MemBufclone () const
void compact ()
 Compacts the buffer and prepares it for a new read.
bytedata () const
 Returns the raw buffer data.
void dependant (CoreObject *g)
 Links this data to a CoreObject.
CoreObjectdependant () 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 MemBufcreate (int nWordSize, uint32 length)
 Creates a membuf with defined wordsize.
static MemBufdeserialize (VMachine *vm, Stream *stream)

Public Attributes

enum Falcon::MemBuf:: { ... }  t_enum_mark

Protected Attributes

uint16 m_byteOrder
tf_deletor m_deletor
CoreObjectm_dependant
uint32 m_length
uint32 m_limit
uint32 m_mark
bytem_memory
uint32 m_position
uint16 m_wordSize


Member Typedef Documentation

typedef void(* Falcon::MemBuf::tf_deletor)(void *memory)


Member Enumeration Documentation

anonymous enum

Enumerator:
INVALID_MARK 
MAX_LEN 


Constructor & Destructor Documentation

Falcon::MemBuf::MemBuf ( uint32  ws,
uint32  length 
)

Creates a pure memory based memory buffer.

This constructor creates a memory buffer containing a memory data that will be freed at buffer destruction.

Falcon::MemBuf::MemBuf ( uint32  ws,
byte data,
uint32  length 
)

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.

Parameters:
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.

Parameters:
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.


Member Function Documentation

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.

static MemBuf* Falcon::MemBuf::create ( int  nWordSize,
uint32  length 
) [static]

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]

Returns the raw buffer data.

Referenced by Falcon::Item::asMemBuf().

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.

See also:
void dependant( CoreObject *g )

static MemBuf* Falcon::MemBuf::deserialize ( VMachine vm,
Stream stream 
) [static]

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.

virtual uint32 Falcon::MemBuf::get ( uint32  pos  )  const [pure virtual]

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.

virtual void Falcon::MemBuf::readIndex ( const Item pos,
Item target 
) [virtual]

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.

virtual void Falcon::MemBuf::readProperty ( const String ,
Item item 
) [virtual]

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.

Note:
This method uses memRealloc, so it can be used only if the memory buffer has been created through memAlloc and should be released with memFree. The method doesn't perform any check, so be sure that you're knowing what you're doing when you use it.
Parameters:
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]

virtual void Falcon::MemBuf::set ( uint32  pos,
uint32  value 
) [pure virtual]

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]

virtual void Falcon::MemBuf::writeIndex ( const Item pos,
const Item target 
) [virtual]

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.

virtual void Falcon::MemBuf::writeProperty ( const String ,
const Item item 
) [virtual]

Implements the deep item interface.

May throw AccessError * if the property cannot be set.

Implements Falcon::DeepItem.


Member Data Documentation


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

Generated on Mon Oct 19 10:11:38 2009 for Falcon_Core by  doxygen 1.5.8