MCPcopy Create free account
hub / github.com/RcppCore/Rcpp / RCPP_API_CLASS

Function RCPP_API_CLASS

inst/include/Rcpp/Symbol.h:27–74  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25namespace Rcpp{
26
27 RCPP_API_CLASS(Symbol_Impl) {
28 public:
29
30 RCPP_GENERATE_CTOR_ASSIGN(Symbol_Impl)
31
32 /**
33 * wraps the SEXP into a Symbol object.
34 *
35 * @param x Accepted SEXP types are SYMSXP, CHARSXP and STRSXP
36 * in the last case, the first element of the character vector
37 * is silently used
38 */
39 Symbol_Impl(SEXP x){
40 int type = TYPEOF(x) ;
41 switch( type ){
42 case SYMSXP:
43 Storage::set__( x ) ;
44 break; /* nothing to do */
45 case CHARSXP: {
46 SEXP charSym = Rf_installChar(x); // R 3.2.0 or later have Rf_installChar
47 Storage::set__( charSym ) ;
48 break ;
49 }
50 case STRSXP: {
51 /* FIXME: check that there is at least one element */
52 SEXP charSym = Rf_installChar(STRING_ELT(x, 0 )); // R 3.2.0 or later have Rf_installChar
53 Storage::set__( charSym );
54 break ;
55 }
56 default:
57 const char* fmt = "Cannot convert object to a symbol: "
58 "[type=%s; target=SYMSXP].";
59 throw not_compatible(fmt, Rf_type2char(TYPEOF(x)));
60 }
61 }
62
63 Symbol_Impl(const std::string& symbol){
64 Storage::set__( Rf_install(symbol.c_str()) );
65 }
66 inline const char* c_str() const {
67 return CHAR(PRINTNAME(Storage::get__())) ;
68 }
69 inline bool operator==(const char* other) const {
70 return ! strcmp(other, c_str() );
71 }
72
73 void update(SEXP){}
74 };
75
76 typedef Symbol_Impl<NoProtectStorage> Symbol;
77

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected