Rcpp Version 1.0.14
Loading...
Searching...
No Matches
Symbol.h
Go to the documentation of this file.
1// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2//
3// Symbol.h: Rcpp R/C++ interface class library -- access R environments
4//
5// Copyright (C) 2013 - 2015 Dirk Eddelbuettel and Romain Francois
6//
7// This file is part of Rcpp.
8//
9// Rcpp is free software: you can redistribute it and/or modify it
10// under the terms of the GNU General Public License as published by
11// the Free Software Foundation, either version 2 of the License, or
12// (at your option) any later version.
13//
14// Rcpp is distributed in the hope that it will be useful, but
15// WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17// GNU General Public License for more details.
18//
19// You should have received a copy of the GNU General Public License
20// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
21
22#ifndef Rcpp_Symbol_h
23#define Rcpp_Symbol_h
24
25namespace Rcpp{
26
28 public:
29
31
32
40 int type = TYPEOF(x) ;
41 switch( type ){
42 case SYMSXP:
43 Storage::set__( x ) ;
44 break; /* nothing to do */
45 case CHARSXP: {
46 #if R_VERSION >= R_Version(3,2,0)
47 SEXP charSym = Rf_installChar(x); // R 3.2.0 or later have Rf_installChar
48 #else
49 SEXP charSym = Rf_install(CHAR(x)); // cannot be gc()'ed once in symbol table
50 #endif
51 Storage::set__( charSym ) ;
52 break ;
53 }
54 case STRSXP: {
55 /* FIXME: check that there is at least one element */
56 #if R_VERSION >= R_Version(3,2,0)
57 SEXP charSym = Rf_installChar(STRING_ELT(x, 0 )); // R 3.2.0 or later have Rf_installChar
58 #else
59 SEXP charSym = Rf_install( CHAR(STRING_ELT(x, 0 )) ); // cannot be gc()'ed once in symbol table
60 #endif
61 Storage::set__( charSym );
62 break ;
63 }
64 default:
65 const char* fmt = "Cannot convert object to a symbol: "
66 "[type=%s; target=SYMSXP].";
68 }
69 }
70
71 Symbol_Impl(const std::string& symbol){
72 Storage::set__( Rf_install(symbol.c_str()) );
73 }
74 inline const char* c_str() const {
75 return CHAR(PRINTNAME(Storage::get__())) ;
76 }
77 inline bool operator==(const char* other) const {
78 return ! strcmp(other, c_str() );
79 }
80
81 void update(SEXP){}
82 };
83
85
86} // namespace Rcpp
87
88#endif
#define RCPP_GENERATE_CTOR_ASSIGN(__CLASS__)
Definition interface.h:21
#define RCPP_API_CLASS(__CLASS__)
Definition interface.h:49
Rcpp API.
Definition algo.h:28
void update(SEXP)
T as(SEXP x)
Definition as.h:151
Symbol_Impl< NoProtectStorage > Symbol
Definition Symbol.h:84
bool operator==(const Date &d1, const Date &d2)
Definition Date.h:167