From: Dejan L. <de...@us...> - 2004-06-11 17:09:55
|
Update of /cvsroot/rtk/rtk/src/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32322/src/core Modified Files: Buffer.cpp Log Message: Few new methods in Buffer.cpp . Index: Buffer.cpp =================================================================== RCS file: /cvsroot/rtk/rtk/src/core/Buffer.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Buffer.cpp 11 Jun 2004 15:37:46 -0000 1.4 --- Buffer.cpp 11 Jun 2004 17:09:45 -0000 1.5 *************** *** 42,45 **** --- 42,48 ---- #include <rtk/Buffer.h> + #if _DEBUG + #include <rtk/debug.h> + #endif namespace Rtk { *************** *** 52,62 **** if (_allocated < newsize) _allocated = newsize; ! uchar *newdata = new unsigned char[_allocated]; memcpy(newdata, _data, _size); ! delete[] _data; _data = newdata; } // if return _data + _size; ! } void Buffer::Write(const uchar* arg_byte_array, uint arg_num) --- 55,65 ---- if (_allocated < newsize) _allocated = newsize; ! uchar* newdata = (uchar*) malloc(_allocated); memcpy(newdata, _data, _size); ! free(_data); _data = newdata; } // if return _data + _size; ! } // Allocate() void Buffer::Write(const uchar* arg_byte_array, uint arg_num) *************** *** 65,68 **** --- 68,108 ---- _size += arg_num; } // Write() + + int Buffer::SetSize(uchar arg_size) + { + if (arg_size) + { + uchar* newdata = (uchar*) realloc(_data, arg_size + 1); + if (!newdata) + return -1; + _data = newdata; + _allocated = arg_size; + } // if + _size = 0; + } + + void Buffer::Fill(uchar arg_char) + { + memset(_data, arg_char, _allocated); + _size = _allocated; + } // Fill() + + #if _DEBUG + // Code taken from eFLTK ... + + void Buffer::FromFile(const String& arg_fname) + { + FILE *f = fopen(fileName,"rb"); + if (!f) + return; // Some error checks should be here... + fseek(f,0,SEEK_END); + int size = ftell(f); + fseek(f,0,SEEK_SET); + Allocate(size+1); + _data[size] = '\0'; + _size = fread(_data, 1 , size, f); + fclose(f); + } + #endif }; // Rtk |