Rcpp Version 0.9.10
Symbol.cpp
Go to the documentation of this file.
00001 // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
00002 //
00003 // Symbol.cpp: Rcpp R/C++ interface class library -- Symbols
00004 //
00005 // Copyright (C) 2010 - 2011 Dirk Eddelbuettel and Romain Francois
00006 //
00007 // This file is part of Rcpp.
00008 //
00009 // Rcpp is free software: you can redistribute it and/or modify it
00010 // under the terms of the GNU General Public License as published by
00011 // the Free Software Foundation, either version 2 of the License, or
00012 // (at your option) any later version.
00013 //
00014 // Rcpp is distributed in the hope that it will be useful, but
00015 // WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU General Public License
00020 // along with Rcpp.  If not, see <http://www.gnu.org/licenses/>.
00021 
00022 #include <Rcpp/Symbol.h>
00023 
00024 namespace Rcpp {
00025 
00026     Symbol::Symbol( SEXP x ) : RObject() {
00027         if( x != R_NilValue ){
00028             int type = TYPEOF(x) ;
00029             switch( type ){
00030             case SYMSXP:
00031                 setSEXP( x ) ;
00032                 break; /* nothing to do */
00033             case CHARSXP: {
00034                 SEXP charSym = Rf_install(CHAR(x));     // cannot be gc()'ed  once in symbol table
00035                 setSEXP( charSym ) ;
00036                 break ;
00037             }
00038             case STRSXP: {
00039                 /* FIXME: check that there is at least one element */
00040                 SEXP charSym = Rf_install( CHAR(STRING_ELT(x, 0 )) ); // cannot be gc()'ed  once in symbol table
00041                 setSEXP( charSym );
00042                 break ;
00043             }
00044             default:
00045                 throw not_compatible("cannot convert to symbol (SYMSXP)") ;
00046             }
00047         } 
00048     }
00049         
00050     Symbol::Symbol(const std::string& symbol): RObject(){
00051         SEXP charSym = Rf_install(symbol.c_str());      // cannot be gc()'ed  once in symbol table
00052         setSEXP( charSym );
00053     }
00054         
00055     Symbol::Symbol( const Symbol& other) : RObject() {
00056         setSEXP( other.asSexp() );
00057     }
00058         
00059     Symbol& Symbol::operator=(const Symbol& other){
00060         setSEXP( other.asSexp() );
00061         return *this;
00062     }
00063         
00064     Symbol::~Symbol(){}
00065         
00066 } // namespace Rcpp
00067 
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Defines