Rcpp Version 0.9.10
r_sexptype_traits.h
Go to the documentation of this file.
00001 // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
00002 /* :tabSize=4:indentSize=4:noTabs=false:folding=explicit:collapseFolds=1: */
00003 //
00004 // r_sexptype_traits.h: Rcpp R/C++ interface class library -- traits to help wrap
00005 //
00006 // Copyright (C) 2010 - 2011 Dirk Eddelbuettel and Romain Francois
00007 //
00008 // This file is part of Rcpp.
00009 //
00010 // Rcpp is free software: you can redistribute it and/or modify it
00011 // under the terms of the GNU General Public License as published by
00012 // the Free Software Foundation, either version 2 of the License, or
00013 // (at your option) any later version.
00014 //
00015 // Rcpp is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 // GNU General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU General Public License
00021 // along with Rcpp.  If not, see <http://www.gnu.org/licenses/>.
00022 
00023 #ifndef Rcpp__traits__r_sexptype_traits__h
00024 #define Rcpp__traits__r_sexptype_traits__h
00025 
00026 namespace Rcpp{
00027 namespace traits{
00028 
00033 template <typename T> struct r_sexptype_traits{ enum{ rtype = VECSXP }; } ;
00034 template<> struct r_sexptype_traits<int>{ enum{ rtype = INTSXP } ; } ;
00035 template<> struct r_sexptype_traits<const int>{ enum{ rtype = INTSXP } ; } ;
00036 template<> struct r_sexptype_traits<double>{ enum{ rtype = REALSXP } ; } ;
00037 template<> struct r_sexptype_traits<bool>{ enum{ rtype = LGLSXP } ; } ;
00038 template<> struct r_sexptype_traits<std::string>{ enum{ rtype = STRSXP } ; } ;
00039 template<> struct r_sexptype_traits<Rcomplex>{ enum{ rtype = CPLXSXP } ; } ;
00040 template<> struct r_sexptype_traits<Rbyte>{ enum{ rtype = RAWSXP } ; } ;
00041 
00042 template<> struct r_sexptype_traits<unsigned int>{ enum{ rtype = INTSXP } ; } ;
00043 template<> struct r_sexptype_traits<float>{ enum{ rtype = REALSXP } ; } ;
00044 
00045 /* long are represented as numeric vectors which allows more precision 
00046    to be preserved than int */
00047 template<> struct r_sexptype_traits<long>{ enum{ rtype = REALSXP } ; } ;
00048 template<> struct r_sexptype_traits<unsigned long>{ enum{ rtype = REALSXP } ; } ;
00049 
00050 /* long double are represented as numeric vectors because we cannot do better in R
00051    some precision will be lost though
00052 */
00053 template<> struct r_sexptype_traits<long double>{ enum{ rtype = REALSXP } ; } ;
00054 
00055 /* short are represented as integer vector in R
00056 */
00057 template<> struct r_sexptype_traits<short>{ enum{ rtype = INTSXP } ; } ;
00058 template<> struct r_sexptype_traits<unsigned short>{ enum{ rtype = INTSXP } ; } ;
00059 
00060 /* long long int */
00061 #ifdef RCPP_HAS_LONG_LONG_TYPES
00062 template<> struct r_sexptype_traits<rcpp_long_long_type>{ enum{ rtype = REALSXP } ; } ;
00063 template<> struct r_sexptype_traits<rcpp_ulong_long_type>{ enum{ rtype = REALSXP } ; } ;
00064 #endif
00065 
00066 /* std::complex */
00067 template<> struct r_sexptype_traits< std::complex<double> >{ enum{ rtype = CPLXSXP } ; } ;
00068 template<> struct r_sexptype_traits< std::complex<float> >{ enum{ rtype = CPLXSXP } ; } ;
00069 
00070 
00074 template <typename T> struct r_sexptype_needscast : public true_type{}; 
00075 template<> struct r_sexptype_needscast<int>          : public false_type{} ;
00076 template<> struct r_sexptype_needscast<double>       : public false_type{} ;
00077 template<> struct r_sexptype_needscast<Rcomplex>     : public false_type{} ;
00078 template<> struct r_sexptype_needscast<Rbyte>        : public false_type{} ;
00079 
00080 
00081 } // traits
00082 } // Rcpp
00083 
00084 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Defines