[Rcpp-devel] Rcpp packages that use Boost.Geometry?
    Dirk Eddelbuettel 
    edd at debian.org
       
    Sat Feb 22 02:47:17 CET 2014
    
    
  
Robi,
Again, your best bet is to use the 
 - existing vignette, and/or the corresponding chapter in my Rcpp book
 - existing Rcpp Gallery pieces
 - existing packages with as<> amnd wrap() you can study.
Here is an example from the to-be-updated-on-CRAN-current-on-GitHub RcppBDT
package.  In the header file RcppBDT.h we have
    // First the 'date' class boost::gregorian::date
    //
    // non-intrusive extension via template specialisation
    template <> boost::gregorian::date as(SEXP dt);
    //
    // non-intrusive extension via template specialisation
    template <> SEXP wrap(const boost::gregorian::date &d);
and in the corresponding source file we have
// define template specialisations for as and wrap
namespace Rcpp {
    template <> boost::gregorian::date as( SEXP dtsexp ) {
        Rcpp::Date dt(dtsexp);
        return boost::gregorian::date(dt.getYear(), dt.getMonth(), dt.getDay());
    }
    template <> SEXP wrap(const boost::gregorian::date &d) {
        boost::gregorian::date::ymd_type ymd = d.year_month_day();     // convert to y/m/d struct
        return Rcpp::wrap(Rcpp::Date( ymd.year, ymd.month, ymd.day ));
    }
}
It can be that simple: just pick components of a structure from one
representation, move it to the other. RcppBDT is a good use case because the
data structures are simple.  Work on a toy example, learn the ropes and then
carry over to the real use case.
Dirk
-- 
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
    
    
More information about the Rcpp-devel
mailing list