/search.css" rel="stylesheet" type="text/css"/> /search.js">
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes
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.

ByteBuffer::~ByteBuffer ( ) [virtual]

Destroys this objects.

Definition at line 28 of file ByteBuffer.cc.

                        {
        if (0 != m_buffer) {
                delete m_buffer;
        }
}
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.

                                   {
        ++m_count;
        return m_buffer + m_position;
}
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.

                               {
        --m_count;
        if (0 == m_count) {
                delete this;
        }
}
const unsigned int ByteBuffer::capacity ( ) const

Returns the size of the block wrapped by this object.

Definition at line 46 of file ByteBuffer.cc.

                                              {
        return m_capacity;
}
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.

                                               {
        return m_limit - m_position;
}
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.

                                          {
        return 0 != remaining();
}
const unsigned int ByteBuffer::limit ( ) const

Returns the limit in the buffer.

Definition at line 62 of file ByteBuffer.cc.

                                           {
        return m_limit;
}
const ByteBuffer * ByteBuffer::limit ( unsigned int  newLimit) const

Sets the limit in the buffer.

Definition at line 66 of file ByteBuffer.cc.

                                                               {
        m_limit = newLimit;
        return this;
}
const unsigned int ByteBuffer::position ( ) const

Returns the position in the buffer.

Definition at line 71 of file ByteBuffer.cc.

                                              {
        return m_position;
}
const ByteBuffer * ByteBuffer::position ( unsigned int  newPosition) const

Sets the position in the buffer.

Definition at line 75 of file ByteBuffer.cc.

                                                                     {
        m_position = newPosition;
        return this;
}
const char * ByteBuffer::cursor ( ) const

Returns the memory location at the current position.

Definition at line 50 of file ByteBuffer.cc.

                                     {
    return m_buffer + m_position;
}
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.

                                                        {
        return (m_buffer + index)[0];
}
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.

                                                                       {
        return *((unsigned int*)(m_buffer + index));
}
char * ByteBuffer::cursor ( )

Returns the memory location at the current position.

Definition at line 88 of file ByteBuffer.cc.

                         {
    return m_buffer + m_position;
}
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.

                                                              {
    const unsigned int spaceLeft = remaining();
    if (length > spaceLeft) {
        memcpy(m_buffer + m_position,
               source,
               spaceLeft);
        m_position += spaceLeft;
        return length - spaceLeft;
    }
    memcpy(m_buffer + m_position,
           source,
           length);
    return 0;
}
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.

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 Fri May 16 2014 09:52:49 for DaqReadoutFormat by doxygen 1.7.4