Rcpp Version 0.9.10
converter.h
Go to the documentation of this file.
00001 // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
00002 //
00003 // converter.h: Rcpp R/C++ interface class library -- converters
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 #ifndef Rcpp__vector__converters_h
00023 #define Rcpp__vector__converters_h
00024  
00025 namespace internal {
00026         template <int RTYPE>
00027         class element_converter{
00028         public:
00029                 typedef typename ::Rcpp::traits::storage_type<RTYPE>::type target ;
00030                 
00031                 template <typename T>
00032                 static target get( const T& input ){
00033                         return caster<T,target>(input) ;
00034                 }
00035                 
00036                 static target get( const target& input ){
00037                         return input ;
00038                 }
00039         } ;
00040         
00041         template <int RTYPE>
00042         class string_element_converter {
00043         public:
00044                 typedef SEXP target ;
00045                 
00046                 template <typename T>
00047                 static SEXP get( const T& input){
00048                         std::string out(input) ;
00049                         return Rf_mkChar( out.c_str() ) ;
00050                 }
00051                 
00052                 static SEXP get(const std::string& input){
00053                         return Rf_mkChar( input.c_str() ) ;
00054                 }
00055                 
00056                 static SEXP get(const char& input){
00057                         return Rf_mkChar( &input ) ;
00058                 }
00059         } ;
00060         
00061         template <int RTYPE>
00062         class generic_element_converter {
00063         public:
00064                 typedef SEXP target ;
00065                 
00066                 template <typename T>
00067                 static SEXP get( const T& input){
00068                         return ::Rcpp::wrap( input ) ;
00069                 }
00070                 
00071                 static SEXP get( const char* input){
00072                         return ::Rcpp::wrap( input );
00073                 }
00074                 
00075                 static SEXP get(SEXP input){
00076                         return input ;
00077                 }
00078         } ;
00079 }
00080 
00081 namespace traits{
00082         template <int RTYPE> struct r_vector_element_converter{
00083                 typedef typename ::Rcpp::internal::element_converter<RTYPE> type ;
00084         } ;
00085         template<> struct r_vector_element_converter<STRSXP>{
00086                 typedef ::Rcpp::internal::string_element_converter<STRSXP> type ;
00087         } ;
00088         template<> struct r_vector_element_converter<VECSXP>{
00089                 typedef ::Rcpp::internal::generic_element_converter<VECSXP> type ;
00090         } ;
00091         template<> struct r_vector_element_converter<EXPRSXP>{
00092                 typedef ::Rcpp::internal::generic_element_converter<EXPRSXP> type ;
00093         } ;
00094 }
00095 
00096 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Defines