22//
33// rcast.h: Rcpp R/C++ interface class library -- cast from one SEXP type to another
44//
5- // Copyright (C) 2010 - 2013 Dirk Eddelbuettel and Romain Francois
5+ // Copyright (C) 2010 - 2017 Dirk Eddelbuettel and Romain Francois
66//
77// This file is part of Rcpp.
88//
2424
2525#include < Rcpp/exceptions.h>
2626
27- namespace Rcpp {
27+ namespace Rcpp {
2828 namespace internal {
2929
30- inline SEXP convert_using_rfunction (SEXP x, const char * const fun){
31- Armor<SEXP> res ;
30+ inline SEXP convert_using_rfunction (SEXP x, const char * const fun) { // #nocov start
31+ Armor<SEXP> res;
3232 try {
3333 SEXP funSym = Rf_install (fun);
34- res = Rcpp_eval ( Rf_lang2 ( funSym, x ) ) ;
34+ res = Rcpp_eval (Rf_lang2 (funSym, x)) ;
3535 } catch ( eval_error& e){
36- throw not_compatible ( std::string (" could not convert using R function : " ) + fun ) ;
36+ throw not_compatible (std::string (" could not convert using R function : " ) + fun) ;
3737 }
38- return res;
38+ return res; // #nocov end
3939 }
4040
4141 // r_true_cast is only meant to be used when the target SEXP type
4242 // is different from the SEXP type of x
4343 template <int TARGET>
4444 SEXP r_true_cast ( SEXP x) {
45- throw not_compatible ( " not compatible" ) ;
46- return x ; // makes solaris happy
45+ throw not_compatible ( " not compatible" );
46+ return x; // makes solaris happy
4747 }
4848
4949 template <int RTYPE>
50- SEXP basic_cast ( SEXP x){
51- if ( TYPEOF (x) == RTYPE ) return x ;
50+ SEXP basic_cast ( SEXP x) { // #nocov start
51+ if ( TYPEOF (x) == RTYPE ) return x;
5252 switch ( TYPEOF (x) ){
5353 case REALSXP:
5454 case RAWSXP:
5555 case LGLSXP:
5656 case CPLXSXP:
5757 case INTSXP:
58- return Rf_coerceVector ( x, RTYPE) ;
58+ return Rf_coerceVector (x, RTYPE);
5959 default :
60- throw ::Rcpp::not_compatible ( " not compatible with requested type" ) ;
61- }
62- return R_NilValue ; /* -Wall */
60+ throw ::Rcpp::not_compatible (" not compatible with requested type" ) ;
61+ } // #nocov end
62+ return R_NilValue; /* -Wall */
6363 }
6464
6565 template <>
6666 inline SEXP r_true_cast<INTSXP>(SEXP x){
67- return basic_cast<INTSXP>(x) ;
67+ return basic_cast<INTSXP>(x);
6868 }
6969 template <>
70- inline SEXP r_true_cast<REALSXP>(SEXP x){
71- return basic_cast<REALSXP>(x) ;
70+ inline SEXP r_true_cast<REALSXP>(SEXP x){ // #nocov
71+ return basic_cast<REALSXP>(x); // #nocov
7272 }
7373 template <>
7474 inline SEXP r_true_cast<RAWSXP>(SEXP x){
75- return basic_cast<RAWSXP>(x) ;
75+ return basic_cast<RAWSXP>(x);
7676 }
7777 template <>
7878 inline SEXP r_true_cast<CPLXSXP>(SEXP x){
79- return basic_cast<CPLXSXP>(x) ;
79+ return basic_cast<CPLXSXP>(x);
8080 }
8181 template <>
82- inline SEXP r_true_cast<LGLSXP>(SEXP x){
83- return basic_cast<LGLSXP>(x) ;
82+ inline SEXP r_true_cast<LGLSXP>(SEXP x){ // #nocov
83+ return basic_cast<LGLSXP>(x); // #nocov
8484 }
8585
8686 template <>
87- inline SEXP r_true_cast<STRSXP>(SEXP x){
88- switch ( TYPEOF ( x ) ) {
87+ inline SEXP r_true_cast<STRSXP>(SEXP x){ // #nocov start
88+ switch ( TYPEOF (x)) {
8989 case CPLXSXP:
9090 case RAWSXP:
9191 case LGLSXP:
@@ -94,43 +94,43 @@ namespace Rcpp{
9494 {
9595 // return Rf_coerceVector( x, STRSXP );
9696 // coerceVector does not work for some reason
97- Shield<SEXP> call ( Rf_lang2 ( Rf_install ( " as.character" ), x ) ) ;
98- Shield<SEXP> res ( Rcpp_eval ( call, R_GlobalEnv ) ) ;
99- return res ;
97+ Shield<SEXP> call ( Rf_lang2 ( Rf_install ( " as.character" ), x ) );
98+ Shield<SEXP> res ( Rcpp_eval ( call, R_GlobalEnv ) );
99+ return res;
100100 }
101101 case CHARSXP:
102- return Rf_ScalarString ( x ) ;
102+ return Rf_ScalarString ( x );
103103 case SYMSXP:
104- return Rf_ScalarString ( PRINTNAME ( x ) ) ;
104+ return Rf_ScalarString ( PRINTNAME ( x ) );
105105 default :
106- throw ::Rcpp::not_compatible ( " not compatible with STRSXP" ) ;
106+ throw ::Rcpp::not_compatible (" not compatible with STRSXP" ) ;
107107 }
108- return R_NilValue ; /* -Wall */
108+ return R_NilValue; /* -Wall */
109109 }
110110 template <>
111111 inline SEXP r_true_cast<VECSXP>(SEXP x) {
112- return convert_using_rfunction (x, " as.list" ) ;
112+ return convert_using_rfunction (x, " as.list" ); // #nocov end
113113 }
114114 template <>
115115 inline SEXP r_true_cast<EXPRSXP>(SEXP x) {
116- return convert_using_rfunction (x, " as.expression" ) ;
116+ return convert_using_rfunction (x, " as.expression" );
117117 }
118118 template <>
119119 inline SEXP r_true_cast<LISTSXP>(SEXP x) {
120120 switch ( TYPEOF (x) ){
121121 case LANGSXP:
122122 {
123123 Shield<SEXP> y ( Rf_duplicate ( x ));
124- SET_TYPEOF (y,LISTSXP) ;
125- return y ;
124+ SET_TYPEOF (y,LISTSXP);
125+ return y;
126126 }
127127 default :
128- return convert_using_rfunction (x, " as.pairlist" ) ;
128+ return convert_using_rfunction (x, " as.pairlist" );
129129 }
130130 }
131131 template <>
132132 inline SEXP r_true_cast<LANGSXP>(SEXP x) {
133- return convert_using_rfunction (x, " as.call" ) ;
133+ return convert_using_rfunction (x, " as.call" );
134134 }
135135
136136 } // namespace internal
@@ -147,7 +147,7 @@ namespace Rcpp{
147147 );
148148 return result;
149149 #else
150- return internal::r_true_cast<TARGET>(x);
150+ return internal::r_true_cast<TARGET>(x); // #nocov
151151 #endif
152152 }
153153 }
0 commit comments