Hi Dirk,
I actually supplied a definition, right after the class implementation,
as I wrote before:
// DECLARATION
class SamData {
// CLASS IMPLEMENTATION
};
// WRAP / AS DEFINITION
namespace Rcpp {
template<> SEXP wrap(const SamData &s) {
return Rcpp::List::create( Rcpp::Named("Chr1") = s.getChr1(),
Rcpp::Named("Chr2") = s.getChr2(),
Rcpp::Named("Seq1") = s.getSeq(),
Rcpp::Named("HS1") = s.getHS1(),
Rcpp::Named("HS2") = s.getHS2(),
Rcpp::Named("Id") = s.getId(),
Rcpp::Named("Start1") = s.getStart1(),
Rcpp::Named("Start2") = s.getStart2() );
}
template <> SamData as( SEXP s ) {
Rcpp::List samL(s);
SamData sam;
sam.setChr1( Rcpp::as<std::string>(samL["Chr1"]) );
sam.setChr2( Rcpp::as<std::string>(samL["Chr2"]) );
sam.setSeq( Rcpp::as<std::string>(samL["Seq1"]) );
sam.setHS1( Rcpp::as<size_t>(samL["HS1"]) );
sam.setHS2( Rcpp::as<size_t>(samL["HS2"]) );
sam.setStart1( Rcpp::as<long>( samL["Start1"]) );
sam.setStart2( Rcpp::as<long>( samL["Start2"]) );
sam.setId( Rcpp::as<long>( samL["Id"]) );
return sam;
}
} // NAMESPACE RCPP
I thought this would be suffice to define a template specialisation for
'as' and 'wrap'. Also, this solution works as expected in a GSL-free
context.
Am I doing something wrong here?
Fabio
On 05/21/2015 05:41 PM, Dirk Eddelbuettel wrote:
On 21 May 2015 at 17:17, Fabio Tordini wrote:
| while extending Rcpp with my C++ classes, I received hundreds of "
| 'wrap' is not a template function" and " 'as' is not a template
| function" errors when compiling. Beside this, I get an impressive list
| of errors referring to RcppGSL files.
|
| The library from which my classes come from makes use GSL (on C++ side),
| thus I link RcppGSL to my package.
|
| Here is my extending for one class:
| #ifndef SAMDATA_HPP_
| #define SAMDATA_HPP_
|
| class SamData;
|
| #include <RcppCommon.h>
|
| namespace Rcpp {
| template<> SEXP wrap(const SamData &s);
| template<> SamData as( SEXP s ) ;
| }
That is a declaration. You also need to supply definitions.
Dirk
_______________________________________________
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