| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

DybDaq::ByteBuffer Class Reference

#include <ByteBuffer.h>

List of all members.


Public Member Functions

 ByteBuffer (char *contents, unsigned int capacity)
 Create an instance of this class, wrapping the supplied memory block.
virtual ~ByteBuffer ()
 Destroys this objects.
const char * grab () const
 Tells this object that something is holding on to its buffer.
void release () const
 Tells this object that something is no longer holding on to its buffer.
const unsigned int capacity () const
 Returns the size of the block wrapped by this object.
const unsigned int remaining () const
 Returns the number of bytes between the position and the limit.
const bool hasRemaining () const
 Returns true when there are still elements between the position and limit.
const unsigned int limit () const
 Returns the limit in the buffer.
const ByteBufferlimit (unsigned int newLimit) const
 Sets the limit in the buffer.
const unsigned int position () const
 Returns the position in the buffer.
const ByteBufferposition (unsigned int newPosition) const
 Sets the position in the buffer.
const char * cursor () const
 Returns the memory location at the current position.
const char readChar (unsigned int index) const
 Returns the element in the buffer at the specified position as an unsigned int.
const unsigned int readUnsignedInt (unsigned int index) const
 Returns the element in the buffer at the specified position as an unsigned int.
char * cursor ()
 Returns the memory location at the current position.
const unsigned int put (const char *source, const unsigned int length)
 Copies 'length' bytes of the source into this buffer.

Static Public Attributes

static const unsigned int BYTES_IN_INT = 4
 The number of bytes in an integer.

Private Member Functions

 ByteBuffer (ByteBuffer &rhs)
 Suppress default.
ByteBufferoperator= (ByteBuffer &rhs)
 Suppress default.

Private Attributes

char * m_buffer
 The memory block wrapped by this object.
unsigned int m_capacity
 The size of the block being wrapped.
unsigned int m_limit
 The index to the 'end-past-end' element in this objects range.
unsigned int m_position
 The index to the 'first' element in this objects range.
unsigned int m_count
 The number of objects that have grabbed this buffer.

Detailed Description

Definition at line 15 of file ByteBuffer.h.


Constructor & Destructor Documentation

ByteBuffer::ByteBuffer ( char *  contents,
unsigned int  capacity 
)

Create an instance of this class, wrapping the supplied memory block.

Definition at line 19 of file ByteBuffer.cc.

00020                                                                   :
00021 m_buffer(contents),
00022 m_capacity(capacity),
00023 m_limit(capacity),
00024 m_position(0),
00025 m_count(1) {
00026 }

ByteBuffer::~ByteBuffer (  )  [virtual]

Destroys this objects.

Definition at line 28 of file ByteBuffer.cc.

00028                         {
00029         if (0 != m_buffer) {
00030                 delete m_buffer;
00031         }
00032 }

DybDaq::ByteBuffer::ByteBuffer ( ByteBuffer rhs  )  [private]

Suppress default.


Member Function Documentation

const char * ByteBuffer::grab (  )  const

Tells this object that something is holding on to its buffer.

Definition at line 34 of file ByteBuffer.cc.

00034                                    {
00035         ++m_count;
00036         return m_buffer + m_position;
00037 }

void ByteBuffer::release (  )  const

Tells this object that something is no longer holding on to its buffer.

Definition at line 39 of file ByteBuffer.cc.

00039                                {
00040         --m_count;
00041         if (0 == m_count) {
00042                 delete this;
00043         }
00044 }

const unsigned int ByteBuffer::capacity (  )  const

Returns the size of the block wrapped by this object.

Definition at line 46 of file ByteBuffer.cc.

00046                                               {
00047         return m_capacity;
00048 }

const unsigned int ByteBuffer::remaining (  )  const

Returns the number of bytes between the position and the limit.

Definition at line 54 of file ByteBuffer.cc.

00054                                                {
00055         return m_limit - m_position;
00056 }

const bool ByteBuffer::hasRemaining (  )  const

Returns true when there are still elements between the position and limit.

Definition at line 58 of file ByteBuffer.cc.

00058                                           {
00059         return 0 != remaining();
00060 }

const unsigned int ByteBuffer::limit (  )  const

Returns the limit in the buffer.

Definition at line 62 of file ByteBuffer.cc.

00062                                            {
00063         return m_limit;
00064 }

const ByteBuffer * ByteBuffer::limit ( unsigned int  newLimit  )  const

Sets the limit in the buffer.

Definition at line 66 of file ByteBuffer.cc.

00066                                                                {
00067         m_limit = newLimit;
00068         return this;
00069 }

const unsigned int ByteBuffer::position (  )  const

Returns the position in the buffer.

Definition at line 71 of file ByteBuffer.cc.

00071                                               {
00072         return m_position;
00073 }

const ByteBuffer * ByteBuffer::position ( unsigned int  newPosition  )  const

Sets the position in the buffer.

Definition at line 75 of file ByteBuffer.cc.

00075                                                                      {
00076         m_position = newPosition;
00077         return this;
00078 }

const char * ByteBuffer::cursor (  )  const

Returns the memory location at the current position.

Definition at line 50 of file ByteBuffer.cc.

00050                                      {
00051     return m_buffer + m_position;
00052 }

const char ByteBuffer::readChar ( unsigned int  index  )  const

Returns the element in the buffer at the specified position as an unsigned int.

Definition at line 80 of file ByteBuffer.cc.

00080                                                         {
00081         return (m_buffer + index)[0];
00082 }

const unsigned int ByteBuffer::readUnsignedInt ( unsigned int  index  )  const

Returns the element in the buffer at the specified position as an unsigned int.

Definition at line 84 of file ByteBuffer.cc.

00084                                                                        {
00085         return *((unsigned int*)(m_buffer + index));
00086 }

char * ByteBuffer::cursor (  ) 

Returns the memory location at the current position.

Definition at line 88 of file ByteBuffer.cc.

00088                          {
00089     return m_buffer + m_position;
00090 }

const unsigned int ByteBuffer::put ( const char *  source,
const unsigned int  length 
)

Copies 'length' bytes of the source into this buffer.

If the length exceeds the number of remaining byte those that can fit will be copied and the number that failed to be copied with be returned. If all of the bytes are copied, 0 is returned.

Definition at line 92 of file ByteBuffer.cc.

00093                                                               {
00094     const unsigned int spaceLeft = remaining();
00095     if (length > spaceLeft) {
00096         memcpy(m_buffer + m_position,
00097                source,
00098                spaceLeft);
00099         m_position += spaceLeft;
00100         return length - spaceLeft;
00101     }
00102     memcpy(m_buffer + m_position,
00103            source,
00104            length);
00105     return 0;
00106 }

ByteBuffer& DybDaq::ByteBuffer::operator= ( ByteBuffer rhs  )  [private]

Suppress default.


Member Data Documentation

const unsigned int ByteBuffer::BYTES_IN_INT = 4 [static]

The number of bytes in an integer.

Definition at line 22 of file ByteBuffer.h.

char* DybDaq::ByteBuffer::m_buffer [private]

The memory block wrapped by this object.

Definition at line 125 of file ByteBuffer.h.

unsigned int DybDaq::ByteBuffer::m_capacity [private]

The size of the block being wrapped.

Definition at line 130 of file ByteBuffer.h.

unsigned int DybDaq::ByteBuffer::m_limit [mutable, private]

The index to the 'end-past-end' element in this objects range.

Definition at line 135 of file ByteBuffer.h.

unsigned int DybDaq::ByteBuffer::m_position [mutable, private]

The index to the 'first' element in this objects range.

Definition at line 140 of file ByteBuffer.h.

unsigned int DybDaq::ByteBuffer::m_count [mutable, private]

The number of objects that have grabbed this buffer.

Definition at line 145 of file ByteBuffer.h.


The documentation for this class was generated from the following files:
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:07:43 2011 for DaqReadoutFormat by doxygen 1.4.7