RInside Version 0.2.12
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
MemBuf.cpp
Go to the documentation of this file.
1 // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2 //
3 // MemBuf.cpp: R/C++ interface class library -- Easier R embedding into C++
4 //
5 // Copyright (C) 2009 Dirk Eddelbuettel
6 // Copyright (C) 2010 - 2012 Dirk Eddelbuettel and Romain Francois
7 //
8 // This file is part of RInside.
9 //
10 // RInside is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 2 of the License, or
13 // (at your option) any later version.
14 //
15 // RInside is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with RInside. If not, see <http://www.gnu.org/licenses/>.
22 
23 #include <iostream>
24 #include <cstdlib>
25 #include <string>
26 
27 #include <MemBuf.h>
28 
29 extern bool verbose;
30 extern const char *programName;
31 
33 
34 MemBuf::MemBuf(int sizebytes) : buffer() {
35  buffer.reserve(sizebytes) ;
36 }
37 
38 void MemBuf::resize() { // Use power of 2 resizing
39  buffer.reserve( 2*buffer.capacity() ) ;
40 }
41 
43  buffer.clear() ;
44 }
45 
46 void MemBuf::add(const std::string& buf){
47  int buflen = buf.size() ;
48  while ( ( buflen + buffer.size() ) >= buffer.capacity() ) {
49  resize();
50  }
51  buffer += buf ;
52 }
53 
~MemBuf()
Definition: MemBuf.cpp:32
void rewind()
Definition: MemBuf.cpp:42
std::string buffer
Definition: MemBuf.h:25
MemBuf(int sizebytes=1024)
Definition: MemBuf.cpp:34
void add(const std::string &)
Definition: MemBuf.cpp:46
bool verbose
void resize()
Definition: MemBuf.cpp:38
const char * programName
Definition: RInside.cpp:28