00001 // +-------------------------------------------------------------------------+ 00002 // | I__n__t__e__L__i__b 0.6.10 development | 00003 // | Copyright (c) Andrey Vikt. Stolyarov <crocodil_AT_croco.net> 2000-2007. | 00004 // | | 00005 // | This is free software. The library part is available under | 00006 // | GNU LESSER GENERAL PUBLIC LICENSE v.2.1. | 00007 // | GNU LGPL v2.1 is found in docs/gnu_gpl2.txt, or at http://www.gnu.org | 00008 // | Please see also docs/readme.txt and visit http://www.intelib.org | 00009 // | | 00010 // | !!! THERE IS NO WARRANTY OF ANY KIND, NEITHER EXPRESSED NOR IMPLIED !!! | 00011 // +-------------------------------------------------------------------------+ 00012 00013 00014 00015 00016 #include "srawbuf.hpp" 00017 #if INTELIB_TEXT_REPRESENTATIONS == 1 00018 #include "sstring.hpp" 00019 #endif 00020 00021 IntelibTypeId SExpressionRawBuffer::TypeId(&SExpression::TypeId, true); 00022 00023 SExpressionRawBuffer::SExpressionRawBuffer(int size) 00024 : SExpression(TypeId) 00025 { 00026 if(size > 0) { 00027 buf = new char[size]; 00028 len = size; 00029 } else { 00030 buf = 0; 00031 len = 0; 00032 } 00033 } 00034 00035 SExpressionRawBuffer::~SExpressionRawBuffer() 00036 { 00037 if(buf) delete[] buf; 00038 } 00039 00040 00041 #if INTELIB_TEXT_REPRESENTATIONS == 1 00042 SString SExpressionRawBuffer::TextRepresentation() const 00043 { 00044 return "#<RAW-MEMORY-BUFFER>"; 00045 } 00046 #endif 00047 00048 SExpression* SExpressionRawBuffer::Clone() const 00049 { 00050 SExpressionRawBuffer *res = new SExpressionRawBuffer(len); 00051 for(int i=0; i<len; i++) 00052 res->buf[i] = buf[i]; 00053 return res; 00054 } 00055 00056 void SExpressionRawBuffer::Resize(int newsize) 00057 { 00058 int cplen = (len > newsize) ? newsize : len; 00059 char *newbuf = new char[newsize]; 00060 for(int i=0; i<cplen; i++) 00061 newbuf[i] = buf[i]; 00062 delete[] buf; 00063 buf = newbuf; 00064 len = newsize; 00065 } 00066 00067 int SExpressionRawBuffer::Append(void* nbuf, int buflen) 00068 { 00069 int oldlen = len; 00070 Resize(len+buflen); 00071 for(int i=0; i<buflen; i++) 00072 buf[i+oldlen] = ((char*)nbuf)[i]; 00073 return len; 00074 }