libStatGen Software
1
|
00001 /* 00002 * Copyright (C) 2010 Regents of the University of Michigan 00003 * 00004 * This program is free software: you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation, either version 3 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00016 */ 00017 00018 #ifndef __BUFFER_H__ 00019 #define __BUFFER_H__ 00020 00021 #include <stdint.h> 00022 #include "InputFile.h" 00023 00024 class CharBuffer 00025 { 00026 public: 00027 CharBuffer(); 00028 CharBuffer(int32_t initialSize); 00029 ~CharBuffer(); 00030 00031 // Copy Constructor 00032 CharBuffer(const CharBuffer& buffer); 00033 00034 // Overload operator = to copy the passed in buffer into this buffer. 00035 CharBuffer& operator = (const CharBuffer& buffer); 00036 00037 // Overload operator = to copy the passed in buffer into this buffer. 00038 CharBuffer& operator = (const std::string& stringBuffer); 00039 00040 // Overload operator = to copy the passed in buffer into this buffer. 00041 bool copy(const CharBuffer& buffer); 00042 00043 void reset(); 00044 00045 // Read from a file into the buffer. length is the amount of data to read. 00046 // Returns the number of bytes read. 00047 int readFromFile(IFILE filePtr, int32_t length); 00048 00049 inline const char* c_str() const 00050 { 00051 return(myBuffer); 00052 } 00053 00054 inline int32_t length() const 00055 { 00056 return(myBufferLen); 00057 } 00058 00059 private: 00060 // newLen is the new length for the buffer. 00061 bool prepareNewLength(int32_t newLen); 00062 00063 int32_t myBufferLen; 00064 char* myBuffer; 00065 00066 int32_t myBufferAllocatedLen; 00067 00068 static const int32_t DEFAULT_BUFFER_SIZE = 100; 00069 }; 00070 00071 #endif 00072