RInside Version 0.2.6
src/MemBuf.cpp
Go to the documentation of this file.
00001 // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
00002 //
00003 // MemBuf.cpp: R/C++ interface class library -- Easier R embedding into C++
00004 //
00005 // Copyright (C) 2009         Dirk Eddelbuettel
00006 // Copyright (C) 2010 - 2012  Dirk Eddelbuettel and Romain Francois
00007 //
00008 // This file is part of RInside.
00009 //
00010 // RInside is free software: you can redistribute it and/or modify it
00011 // under the terms of the GNU General Public License as published by
00012 // the Free Software Foundation, either version 2 of the License, or
00013 // (at your option) any later version.
00014 //
00015 // RInside is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 // GNU General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU General Public License
00021 // along with RInside.  If not, see <http://www.gnu.org/licenses/>.
00022 
00023 #include <iostream>
00024 #include <cstdlib>
00025 #include <string>
00026 
00027 #include <MemBuf.h>
00028 
00029 extern bool verbose;
00030 extern const char *programName;
00031 
00032 MemBuf::~MemBuf() {}
00033 
00034 MemBuf::MemBuf(int sizebytes) : buffer() {
00035     buffer.reserve(sizebytes) ;
00036 }
00037 
00038 void MemBuf::resize() {         // Use power of 2 resizing 
00039     buffer.reserve( 2*buffer.capacity() ) ;
00040 }
00041 
00042 void MemBuf::rewind(){
00043     buffer.clear() ;
00044 }
00045 
00046 void MemBuf::add(const std::string& buf){
00047     int buflen = buf.size() ;
00048     while ( ( buflen + buffer.size() ) >= buffer.capacity() ) {
00049         resize();
00050     }
00051     buffer += buf ;
00052 }
00053 
 All Classes Files Functions Variables Enumerations Enumerator Defines