Belle II Software development
Buffer Class Reference

Public Member Functions

 Buffer (unsigned int size, unsigned char *memory=NULL)
 
 Buffer (const Buffer &w)
 
unsigned char * ptr ()
 
const unsigned char * ptr () const
 
unsigned int size () const
 
virtual bool available ()
 
const Bufferoperator= (const Buffer &)
 

Protected Attributes

unsigned char * m_memory
 
unsigned int m_size
 
bool m_allocated
 

Detailed Description

Definition at line 19 of file Buffer.h.

Constructor & Destructor Documentation

◆ Buffer() [1/3]

Buffer ( )

Definition at line 14 of file Buffer.cc.

14: m_memory(NULL), m_size(0), m_allocated(false) {}

◆ Buffer() [2/3]

Buffer ( unsigned int  size,
unsigned char *  memory = NULL 
)

Definition at line 16 of file Buffer.cc.

17 : m_memory(memory), m_size(size), m_allocated(false)
18{
19 if (memory == NULL && size > 0) {
20 m_memory = new unsigned char[size];
21 ::memset(m_memory, 0, size);
22 m_allocated = true;
23 }
24}

◆ Buffer() [3/3]

Buffer ( const Buffer w)

Definition at line 26 of file Buffer.cc.

27 : m_memory(NULL), m_size(buf.m_size),
28 m_allocated(buf.m_allocated)
29{
30 if (m_allocated) {
31 m_memory = new unsigned char [buf.m_size];
32 ::memset(m_memory, 0, buf.m_size);
33 ::memcpy(m_memory, buf.m_memory, buf.m_size);
34 } else {
35 m_memory = buf.m_memory;
36 }
37 m_size = buf.m_size;
38}

◆ ~Buffer()

~Buffer ( )
virtual

Definition at line 40 of file Buffer.cc.

41{
42 if (m_allocated && m_memory != NULL) {
43 delete [] m_memory;
44 m_allocated = false;
45 m_memory = NULL;
46 }
47}

Member Function Documentation

◆ available()

virtual bool available ( )
inlinevirtual

Definition at line 33 of file Buffer.h.

33{ return m_memory != NULL; }

◆ operator=()

const Buffer & operator= ( const Buffer buf)

Definition at line 49 of file Buffer.cc.

50{
51 if (m_allocated) {
52 delete [] m_memory;
53 }
54 m_allocated = buf.m_allocated;
55 if (m_allocated) {
56 m_memory = new unsigned char [buf.m_size];
57 ::memset(m_memory, 0, buf.m_size);
58 ::memcpy(m_memory, buf.m_memory, buf.m_size);
59 } else {
60 m_memory = buf.m_memory;
61 }
62 m_size = buf.m_size;
63 return *this;
64}

◆ ptr() [1/2]

unsigned char * ptr ( )
inline

Definition at line 30 of file Buffer.h.

30{ return m_memory; }

◆ ptr() [2/2]

const unsigned char * ptr ( ) const
inline

Definition at line 31 of file Buffer.h.

31{ return m_memory; }

◆ size()

unsigned int size ( ) const
inline

Definition at line 32 of file Buffer.h.

32{ return m_size; }

Member Data Documentation

◆ m_allocated

bool m_allocated
protected

Definition at line 43 of file Buffer.h.

◆ m_memory

unsigned char* m_memory
protected

Definition at line 41 of file Buffer.h.

◆ m_size

unsigned int m_size
protected

Definition at line 42 of file Buffer.h.


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