Rcpp Version 1.1.2
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
27 RCPP_API_CLASS(Symbol_Impl) {
28 public:
29
30 RCPP_GENERATE_CTOR_ASSIGN(Symbol_Impl)
31
32
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
78} // namespace Rcpp
79
80#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)
Symbol_Impl< NoProtectStorage > Symbol
Definition Symbol.h:76
bool operator==(const Date &d1, const Date &d2)
Definition Date.h:167