Skip to content

Commit 3b628fa

Browse files
committed
Adds patch by Jelmer Ypma which implements a new device Rcout which acts like
std::cout but is implemented using Rprintf to cooperate more cleanly with the output buffering by R
1 parent 654ffbf commit 3b628fa

9 files changed

Lines changed: 176 additions & 2 deletions

File tree

ChangeLog

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
2011-10-25 Dirk Eddelbuettel <edd@debian.org>
2+
3+
* src/Rostream.cpp: Patch by Jelmer Ypma which adds a new device
4+
'Rcout' not unlike std::cout but uses Rprintf internally
5+
* src/Rstreambuf.cpp: Idem
6+
* include/include/Rcpp/iostream/Rostream.h: Idem
7+
* include/include/Rcpp/iostream/Rstreambuf.h: Idem
8+
* include/include/Rcpp.h: Include new headers
9+
110
2011-09-29 Dirk Eddelbuettel <edd@debian.org>
211

312
* DESCRIPTION: Release 0.9.7

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: Rcpp
22
Title: Seamless R and C++ Integration
3-
Version: 0.9.7
3+
Version: 0.9.7.1
44
Date: $Date$
55
Author: Dirk Eddelbuettel and Romain Francois,
66
with contributions by Douglas Bates and John Chambers

inst/NEWS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
0.9.8 201x-yy-zz
2+
3+
o Applied patch by Jelmer Ypma which adds an output stream class
4+
'Rcout' not unlike std::cout, but implemented via Rprintf to
5+
cooperate with R and its output buffering.
6+
17
0.9.7 2011-09-29
28

39
o Applied two patches kindly provided by Martyn Plummer which provide

inst/THANKS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Rainer Hurling for help debugging builds issues on FreeBSD
1010
Uwe Ligges for help with Windows (32 and 64 bit) build issues
1111
Tama Ma for a patch that extends Module constructors
1212
Karl Millar for a patch helping with a non-g++ compiler
13-
Martyn Plummer for help with Solaris build issues
13+
Martyn Plummer for help and patches regarding Solaris build issues
1414
David Reiss for the first-ever contributed patch (Rcpp*View)
1515
Brian Ripley for help with Win64 + Solaris build issues
1616
Dominick Samperi for starting what is now in the RcppClassic package
@@ -19,3 +19,4 @@ Alexey Stukalov for a support enabling Intel Compiler 12.0 support
1919
Luke Tierney for helpful discussions on R internals
2020
Simon Urbanek for help on OS X build issues and with R internals
2121
Ken Williams for additional OS X testing
22+
Jelmer Ypma for contributing the Rcout iostreams class patch

inst/include/Rcpp.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,8 @@
6868
#include <Rcpp/sugar/sugar.h>
6969
#include <Rcpp/stats/stats.h>
7070

71+
// "Rcout" iostream class contributed by Jelmer Ypma
72+
#include <Rcpp/iostream/Rstreambuf.h>
73+
#include <Rcpp/iostream/Rostream.h>
74+
7175
#endif
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2+
//
3+
// Rostream.h: Rcpp R/C++ interface class library -- output stream
4+
//
5+
// Copyright (C) 2011 Dirk Eddelbuettel, Romain Francois and Jelmer Ypma
6+
//
7+
// This file is part of Rcpp.
8+
//
9+
// Rcpp is free software: you can redistribute it and/or modify it
10+
// under the terms of the GNU General Public License as published by
11+
// the Free Software Foundation, either version 2 of the License, or
12+
// (at your option) any later version.
13+
//
14+
// Rcpp is distributed in the hope that it will be useful, but
15+
// WITHOUT ANY WARRANTY; without even the implied warranty of
16+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
// GNU General Public License for more details.
18+
//
19+
// You should have received a copy of the GNU General Public License
20+
// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
21+
22+
#ifndef __ROSTREAM_H__
23+
#define __ROSTREAM_H__
24+
25+
#include <RcppCommon.h>
26+
#include <Rcpp/iostream/Rstreambuf.h>
27+
28+
// modified from
29+
// http://stackoverflow.com/questions/243696/correctly-over-loading-a-stringbuf-to-replace-cout-in-a-matlab-mex-file
30+
31+
namespace Rcpp {
32+
33+
class Rostream : public std::ostream {
34+
35+
protected:
36+
Rstreambuf buf;
37+
38+
public:
39+
Rostream();
40+
};
41+
42+
// declare global variable
43+
extern Rostream Rcout;
44+
45+
}
46+
47+
#endif
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2+
//
3+
// Rostream.h: Rcpp R/C++ interface class library -- stream buffer
4+
//
5+
// Copyright (C) 2011 Dirk Eddelbuettel, Romain Francois and Jelmer Ypma
6+
//
7+
// This file is part of Rcpp.
8+
//
9+
// Rcpp is free software: you can redistribute it and/or modify it
10+
// under the terms of the GNU General Public License as published by
11+
// the Free Software Foundation, either version 2 of the License, or
12+
// (at your option) any later version.
13+
//
14+
// Rcpp is distributed in the hope that it will be useful, but
15+
// WITHOUT ANY WARRANTY; without even the implied warranty of
16+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
// GNU General Public License for more details.
18+
//
19+
// You should have received a copy of the GNU General Public License
20+
// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
21+
22+
#ifndef __RSTREAMBUF_H__
23+
#define __RSTREAMBUF_H__
24+
25+
#include <streambuf>
26+
#include <RcppCommon.h>
27+
28+
// modified from
29+
// http://stackoverflow.com/questions/243696/correctly-over-loading-a-stringbuf-to-replace-cout-in-a-matlab-mex-file
30+
31+
namespace Rcpp {
32+
33+
class Rstreambuf : public std::streambuf {
34+
public:
35+
36+
protected:
37+
virtual std::streamsize xsputn(const char *s, std::streamsize n );
38+
39+
virtual int overflow(int c = EOF );
40+
};
41+
42+
}
43+
44+
#endif

src/Rostream.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2+
//
3+
// Rostream.cpp: Rcpp R/C++ interface class library -- output stream
4+
//
5+
// Copyright (C) 2011 Dirk Eddelbuettel, Romain Francois and Jelmer Ypma
6+
//
7+
// This file is part of Rcpp.
8+
//
9+
// Rcpp is free software: you can redistribute it and/or modify it
10+
// under the terms of the GNU General Public License as published by
11+
// the Free Software Foundation, either version 2 of the License, or
12+
// (at your option) any later version.
13+
//
14+
// Rcpp is distributed in the hope that it will be useful, but
15+
// WITHOUT ANY WARRANTY; without even the implied warranty of
16+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
// GNU General Public License for more details.
18+
//
19+
// You should have received a copy of the GNU General Public License
20+
// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
21+
22+
#include <RcppCommon.h>
23+
#include <Rcpp/iostream/Rostream.h>
24+
25+
Rcpp::Rostream::Rostream() : std::ostream( &buf ) {}
26+
27+
// define global variable Rcout
28+
Rcpp::Rostream Rcpp::Rcout;

src/Rstreambuf.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2+
//
3+
// Rostream.h: Rcpp R/C++ interface class library -- stream buffer
4+
//
5+
// Copyright (C) 2011 Dirk Eddelbuettel, Romain Francois and Jelmer Ypma
6+
//
7+
// This file is part of Rcpp.
8+
//
9+
// Rcpp is free software: you can redistribute it and/or modify it
10+
// under the terms of the GNU General Public License as published by
11+
// the Free Software Foundation, either version 2 of the License, or
12+
// (at your option) any later version.
13+
//
14+
// Rcpp is distributed in the hope that it will be useful, but
15+
// WITHOUT ANY WARRANTY; without even the implied warranty of
16+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
// GNU General Public License for more details.
18+
//
19+
// You should have received a copy of the GNU General Public License
20+
// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
21+
22+
#include <RcppCommon.h>
23+
#include <Rcpp/iostream/Rstreambuf.h>
24+
25+
std::streamsize Rcpp::Rstreambuf::xsputn(const char *s, std::streamsize num ) {
26+
Rprintf( "%.*s", num, s );
27+
return num;
28+
}
29+
30+
int Rcpp::Rstreambuf::overflow(int c ) {
31+
if (c != EOF) {
32+
Rprintf( "%.1s", &c );
33+
}
34+
return c;
35+
}

0 commit comments

Comments
 (0)