On Sun, May 13, 2012 at 5:42 PM, Dirk Eddelbuettel <e...@debian.org> wrote:
> > Hi Alexey, > > On 13 May 2012 at 16:45, Alexey Stukalov wrote: > | thanks for the quick response, there are some clarifications below. > | > | I'm trying to use Rcpp::Rostream from my C++ library, not from the > inline code, > | so I have to deal with the headers inclusion on my own :) > > Oh, now I see more clearly where you come from but I don't yet understand > where you want to go. > > | Basically, I want to use Rostream as a log sink for boost::log (this > library > | not in the mainline boost yet). > | Because of boost-log API I have to create new Rostream object, using > | Rcpp::Rcout is not an option. > | > | The minimal code that directs log to R console once the library is > loaded looks > | like this: > | > | #include <Rcpp/iostream/Rostream.h> > | #include <boost/log/trivial.hpp> > | #include <boost/log/sinks.hpp> > | #include <boost/log/core.hpp> > | > | // Called when the library is loaded and before dlopen() returns > | void __attribute__ ((constructor)) test_load() > | { > | // initialize boost-log > | // Construct the R sink > | typedef boost::log::sinks::synchronous_sink > | <boost::log::sinks::text_ostream_backend> text_sink; > | boost::shared_ptr< text_sink > pRSink = boost::make_shared< > text_sink > > | (); > | > | // Add a stream to write log to > | pRSink->locked_backend()->add_stream( > boost::make_shared<Rcpp::Rostream> > | () ); > | > | // Register the sink in the logging core > | boost::log::core::get()->add_sink(pRSink); > | > | BOOST_LOG_TRIVIAL(info) << "R test library loaded"; > | } > | > | // Called when the library is unloaded and before dlclose() returns > | void __attribute__ ((destructor)) test_unload() > | { > | } > | > | To make this code work I had to add #include "Rstreambuf.h" into > <Rostream.h> > | for the reasons described above. > | I hope now it's more clear. > > And this is code that you call from R? > > This is basically outside of our current scope. Rcpp doesn't use Boost > itself, so we can't promise that it works with boost::log etc -- this is > essentially something you need to work out. > > That said, it could be made to work. If you can suggest patches for our > header files that will help you without affecting prior behaviour, we could > possibly include. Rcpp::Rostream is a good example as Jelmer added this > without affecting anything else. > > Does that make sense? > Actually, the example above works just fine, since Rostream conforms to ostream concept. I just had to make the following change to Rostream.h to make it compile: --- /usr/lib64/R/library/Rcpp/include/Rcpp/iostream/Rostream.h 2012-05-13 17:50:58.090987364 +0200 +++ /fast/opt/lib64/R/library/Rcpp/include/Rcpp/iostream/Rostream.h 2012-05-10 13:52:45.542940000 +0200 @@ -24,6 +24,8 @@ #include <iomanip> // USES setw +#include "Rstreambuf.h" + // modified from // http://stackoverflow.com/questions/243696/correctly-over-loading-a-stringbuf-to-replace-cout-in-a-matlab-mex-file It would be nice if you can apply this tiny patch. Thanks, Alexey > > Dirk > > -- > Dirk Eddelbuettel | e...@debian.org | http://dirk.eddelbuettel.com >
_______________________________________________ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel