Rcpp Version 0.9.10
Rostream.h
Go to the documentation of this file.
00001 // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
00002 //
00003 // Rostream.h: Rcpp R/C++ interface class library -- output stream
00004 //
00005 // Copyright (C) 2012           Dirk Eddelbuettel, Romain Francois and Jelmer Ypma
00006 //
00007 // This file is part of Rcpp.
00008 //
00009 // Rcpp is free software: you can redistribute it and/or modify it
00010 // under the terms of the GNU General Public License as published by
00011 // the Free Software Foundation, either version 2 of the License, or
00012 // (at your option) any later version.
00013 //
00014 // Rcpp is distributed in the hope that it will be useful, but
00015 // WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU General Public License
00020 // along with Rcpp.  If not, see <http://www.gnu.org/licenses/>.
00021 
00022 #ifndef __ROSTREAM_H__
00023 #define __ROSTREAM_H__
00024 
00025 #include <iomanip>                              // USES setw
00026 
00027 // modified from 
00028 // http://stackoverflow.com/questions/243696/correctly-over-loading-a-stringbuf-to-replace-cout-in-a-matlab-mex-file
00029 
00030 namespace Rcpp {
00031 
00032     class Rostream : public std::ostream {
00033         
00034     protected:
00035         Rstreambuf buf;
00036         
00037     public:
00038         Rostream();
00039     };
00040     
00041     // declare global variable
00042     extern Rostream Rcout;
00043 
00044     // template <int RTYPE> std::ostream& operator<<(std::ostream& out, const Rcpp::Vector< RTYPE >& v) {
00045     //     out << "[1] " << v[0];
00046     //     for (int i=1;i<v.size();i++) {
00047     //         out << " " << v[i];
00048     //     }
00049     //     return out;  // for multiple << operators.
00050     // }
00051 
00052     // template <int RTYPE> std::ostream& operator<<(std::ostream& out, const Rcpp::Matrix< RTYPE >& m) {
00053     //     // width of columns showing values
00054     //     int val_col_width = 12;
00055         
00056     //     // width of first column, showing row index
00057     //     int max_row_idx = m.rows() + 1;
00058     //     int idx_col_width = 0;
00059     //     while(max_row_idx > 0) {
00060     //         max_row_idx /= 10;
00061     //         idx_col_width++;
00062     //     }
00063         
00064     //     // print column headers (add 1 to have R indexing)
00065     //     out << std::setw( val_col_width + idx_col_width + 3 ) << "[,1]";
00066     //     for (int jcol=1;jcol<m.ncol();jcol++) {
00067     //         out << std::setw( val_col_width-2 ) << "[," << jcol+1 << "]";
00068     //     }
00069     //     out << std::endl;
00070     //     for (int irow=0;irow<m.nrow();irow++) {
00071     //         // print row header (add 1 to have R indexing)
00072     //         out << "[" << std::setw( idx_col_width ) << irow+1 << ",]";
00073         
00074     //         // print values in current row
00075     //         for (int jcol=0;jcol<m.ncol();jcol++) {
00076     //             out << std::setw( val_col_width ) << m( irow, jcol );
00077     //         }
00078     //         out << std::endl;
00079     //     }
00080     //     return out;  // for multiple << operators.
00081     // }
00082 
00083 }
00084 
00085 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Defines