<div>Hi Dirk,</div><div><br></div><div>thanks for the quick response, there are some clarifications below.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Hi Alexey,<br>
On 12 May 2012 at 19:03, Alexey Stukalov wrote:<br>|<i> Dear Rcpp developers,<br>
</i>|<br><i>
</i>|<i> ATM to define the Rcpp::Rostream I have to fix the iostream/Rostream.h header<br>
</i>|<i> directly and add<br>
</i>|<br><i>
</i>|<i> #include "Rstreambuf.h"<br>
</i>|<br><i>
</i>|<i> before its declarations.<br>
</i>|<br><i>
</i>|<i> Including "Rstreambuf.h" in my source file before "Rstreambuf.h" doesn't help,<br>
</i>|<i> it seems the headers are processed in a way that Rostream declaration comes<br>
</i>|<i> before Rstreambuf<br>
</i>|<i> (due to RcppCommon.h that is included by Rstreambuf.h and not by Rostream.h).<br>
</i>|<br><i>
</i>|<i> Is it possible to fix Rostream.h in the mainline or there's another proper way<br>
</i>|<i> to include it?<br>
</i>
Can you restate your problem a little differently? I don't quite understand<br>what you are trying to do, and what is not working.<br>
What do you mean by "define the Rcpp::Rostream" ? You would not have to<br>include that explicitly as our header structure already does it. See the<br>example blog post from a few months ago:<br>
<a href="http://dirk.eddelbuettel.com/blog/2012/02/18#rcout_armadillo_example">http://dirk.eddelbuettel.com/blog/2012/02/18#rcout_armadillo_example<br></a>
That works the same way with Rcpp alone:<br>
R> library(inline)<br>R><br> R> fun <- cxxfunction(signature(), plugin="Rcpp", body='<br>+ Rcpp::Rcout << "Hello, world" << std::endl;<br>+ ')<br>R><br> R> cat("Before Rcpp-created function\n")<br>
Before Rcpp-created function<br>R> fun()<br>Hello, world<br>NULL<br>R> cat("After Rcpp-created function\n")<br>After Rcpp-created function<br>R><br> R><br>
That doesn't work so impressively with inline etc as we come back to the<br>prompt anyway, but by using Rcpp::Rcout all your stdout access from C++ is<br>passed through the output stream controlled by R thanks to the work Jelmer did.<br>
Or did I misunderstand and you wanted to do something different ?<br></blockquote><div><br></div><div>I'm trying to use Rcpp::Rostream from my C++ library, not from the inline code,</div><div>so I have to deal with the headers inclusion on my own :)</div>
<div>Basically, I want to use Rostream as a log sink for boost::log (this library not in the mainline boost yet).</div><div>Because of boost-log API I have to create new Rostream object, using Rcpp::Rcout is not an option.</div>
<div><br></div><div>The minimal code that directs log to R console once the library is loaded looks like this:</div><div><br></div><div><div>#include <Rcpp/iostream/Rostream.h></div><div>#include <boost/log/trivial.hpp></div>
<div>#include <boost/log/sinks.hpp></div><div>#include <boost/log/core.hpp></div><div><br></div><div>// Called when the library is loaded and before dlopen() returns</div><div>void __attribute__ ((constructor)) test_load()</div>
<div>{</div><div> // initialize boost-log</div><div> // Construct the R sink</div><div> typedef boost::log::sinks::synchronous_sink<boost::log::sinks::text_ostream_backend> text_sink;</div><div> boost::shared_ptr< text_sink > pRSink = boost::make_shared< text_sink >();</div>
<div><br></div><div> // Add a stream to write log to</div><div> pRSink->locked_backend()->add_stream( boost::make_shared<Rcpp::Rostream>() );</div><div><br></div><div> // Register the sink in the logging core</div>
<div> boost::log::core::get()->add_sink(pRSink);</div><div><br></div><div> BOOST_LOG_TRIVIAL(info) << "R test library loaded";</div><div>}</div><div><br></div><div>// Called when the library is unloaded and before dlclose() returns</div>
<div>void __attribute__ ((destructor)) test_unload()</div><div>{</div><div>}</div></div><div><br></div><div>To make this code work I had to add #include "Rstreambuf.h" into <Rostream.h> for the reasons described above.</div>
<div>I hope now it's more clear.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Dirk</blockquote><div><br></div><div>WBR,</div><div> Alexey</div>