libStatGen Software 1
CharBuffer Class Reference

Public Member Functions

 CharBuffer (int32_t initialSize)
 
 CharBuffer (const CharBuffer &buffer)
 
CharBufferoperator= (const CharBuffer &buffer)
 
CharBufferoperator= (const std::string &stringBuffer)
 
bool copy (const CharBuffer &buffer)
 
void reset ()
 
int readFromFile (IFILE filePtr, int32_t length)
 
const char * c_str () const
 
int32_t length () const
 

Detailed Description

Definition at line 24 of file CharBuffer.h.

Constructor & Destructor Documentation

◆ CharBuffer() [1/3]

CharBuffer::CharBuffer ( )

Definition at line 21 of file CharBuffer.cpp.

22 : myBuffer(NULL)
23{
24 myBuffer = (char *) malloc(DEFAULT_BUFFER_SIZE);
25 myBufferAllocatedLen = DEFAULT_BUFFER_SIZE;
26 reset();
27}

◆ CharBuffer() [2/3]

CharBuffer::CharBuffer ( int32_t  initialSize)

Definition at line 30 of file CharBuffer.cpp.

31 : myBuffer(NULL)
32{
33 myBuffer = (char *) malloc(initialSize);
34 myBufferAllocatedLen = DEFAULT_BUFFER_SIZE;
35
36 reset();
37}

◆ ~CharBuffer()

CharBuffer::~CharBuffer ( )

Definition at line 40 of file CharBuffer.cpp.

41{
42 reset();
43 if(myBuffer != NULL)
44 {
45 free(myBuffer);
46 myBuffer = NULL;
47 }
48}

◆ CharBuffer() [3/3]

CharBuffer::CharBuffer ( const CharBuffer buffer)

Definition at line 52 of file CharBuffer.cpp.

53 : myBuffer(NULL)
54{
55 myBuffer =
56 (char *) malloc(DEFAULT_BUFFER_SIZE);
57 myBufferAllocatedLen = DEFAULT_BUFFER_SIZE;
58
59 reset();
60
61 copy(buffer);
62}

Member Function Documentation

◆ c_str()

const char * CharBuffer::c_str ( ) const
inline

Definition at line 49 of file CharBuffer.h.

50 {
51 return(myBuffer);
52 }

◆ copy()

bool CharBuffer::copy ( const CharBuffer buffer)

Definition at line 87 of file CharBuffer.cpp.

88{
89 // Check to see if the passed in value is the same as this.
90 if(this == &buffer)
91 {
92 return(true);
93 }
94
95 // Copy the buffer.
96 // First check lengh
97 prepareNewLength(buffer.myBufferLen);
98
99 memcpy(myBuffer, buffer.myBuffer, buffer.myBufferLen);
100 myBufferLen = buffer.myBufferLen;
101
102 return(true);
103}

◆ length()

int32_t CharBuffer::length ( ) const
inline

Definition at line 54 of file CharBuffer.h.

55 {
56 return(myBufferLen);
57 }

◆ operator=() [1/2]

CharBuffer & CharBuffer::operator= ( const CharBuffer buffer)

Definition at line 66 of file CharBuffer.cpp.

67{
68 copy(buffer);
69 return(*this);
70}

◆ operator=() [2/2]

CharBuffer & CharBuffer::operator= ( const std::string &  stringBuffer)

Definition at line 74 of file CharBuffer.cpp.

75{
76 // First check lengh
77 if(prepareNewLength(stringBuffer.length()))
78 {
79 memcpy(myBuffer, stringBuffer.c_str(), stringBuffer.length());
80 }
81 // TODO: on failure of prepareNewLength, should it throw an exception?
82
83 return(*this);
84}

◆ readFromFile()

int CharBuffer::readFromFile ( IFILE  filePtr,
int32_t  length 
)

Definition at line 119 of file CharBuffer.cpp.

120{
121 if(filePtr == NULL)
122 {
123 return(0);
124 }
125
126 if(prepareNewLength(length))
127 {
128 return(ifread(filePtr, myBuffer, length));
129 }
130 // failed to setup the buffer, return false.
131 return(false);
132}
unsigned int ifread(IFILE file, void *buffer, unsigned int size)
Read up to size bytes from the file into the buffer.
Definition: InputFile.h:600

◆ reset()

void CharBuffer::reset ( )

Definition at line 107 of file CharBuffer.cpp.

108{
109 myBufferLen = 0;
110 if(myBuffer != NULL)
111 {
112 myBuffer[0] = 0;
113 }
114}

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