Rcpp Version 1.0.9
export.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 // export.h: Rcpp R/C++ interface class library -- export implementations
4 //
5 // Copyright (C) 2013 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_api_meat_export_h
23 #define Rcpp_api_meat_export_h
24 
25 namespace Rcpp{
26 namespace internal{
27 
28  template <typename InputIterator, typename value_type>
29  void export_range__dispatch( SEXP x, InputIterator first, ::Rcpp::traits::r_type_generic_tag ) {
30  R_xlen_t n = ::Rf_xlength(x) ;
31  for( R_xlen_t i=0; i<n; i++, ++first ){
32  *first = ::Rcpp::as<value_type>( VECTOR_ELT(x, i) ) ;
33  }
34  }
35 
36 
37 } // namespace internal
38 
39  namespace traits{
40 
41  template < template <class, class> class ContainerTemplate, typename T > class ContainerExporter {
42  public:
43  typedef ContainerTemplate<T, std::allocator<T> > Container ;
45 
46  ContainerExporter( SEXP x ) : object(x){}
48 
50  if( TYPEOF(object) == RTYPE ){
51  T* start = Rcpp::internal::r_vector_start<RTYPE>(object) ;
52  return Container( start, start + Rf_xlength(object) ) ;
53  }
54  Container vec( ::Rf_xlength(object) );
55  ::Rcpp::internal::export_range( object, vec.begin() ) ;
56  return vec ;
57  }
58 
59  private:
60  SEXP object ;
61  } ;
62  template < template<class,class> class Container > struct container_exporter< Container, int >{
64  } ;
65  template < template<class,class> class Container > struct container_exporter< Container, double >{
67  } ;
68 
69  }
70 } // namespace Rcpp
71 
72 #endif
static const int RTYPE
Definition: export.h:44
ContainerTemplate< T, std::allocator< T > > Container
Definition: export.h:43
void export_range__dispatch(SEXP x, InputIterator first, ::Rcpp::traits::r_type_generic_tag)
Definition: export.h:29
Rcpp API.
Definition: algo.h:28
ContainerExporter< Container, double > type
Definition: export.h:66
ContainerExporter< Container, int > type
Definition: export.h:63