libStatGen Software 1
CharBuffer.h
1/*
2 * Copyright (C) 2010 Regents of the University of Michigan
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef __BUFFER_H__
19#define __BUFFER_H__
20
21#include <stdint.h>
22#include "InputFile.h"
23
25{
26public:
27 CharBuffer();
28 CharBuffer(int32_t initialSize);
30
31 // Copy Constructor
32 CharBuffer(const CharBuffer& buffer);
33
34 // Overload operator = to copy the passed in buffer into this buffer.
35 CharBuffer& operator = (const CharBuffer& buffer);
36
37 // Overload operator = to copy the passed in buffer into this buffer.
38 CharBuffer& operator = (const std::string& stringBuffer);
39
40 // Overload operator = to copy the passed in buffer into this buffer.
41 bool copy(const CharBuffer& buffer);
42
43 void reset();
44
45 // Read from a file into the buffer. length is the amount of data to read.
46 // Returns the number of bytes read.
47 int readFromFile(IFILE filePtr, int32_t length);
48
49 inline const char* c_str() const
50 {
51 return(myBuffer);
52 }
53
54 inline int32_t length() const
55 {
56 return(myBufferLen);
57 }
58
59private:
60 // newLen is the new length for the buffer.
61 bool prepareNewLength(int32_t newLen);
62
63 int32_t myBufferLen;
64 char* myBuffer;
65
66 int32_t myBufferAllocatedLen;
67
68 static const int32_t DEFAULT_BUFFER_SIZE = 100;
69};
70
71#endif
72
Class for easily reading/writing files without having to worry about file type (uncompressed,...
Definition: InputFile.h:37