|
1 | 1 | // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*- |
2 | | -/* :tabSize=4:indentSize=4:noTabs=false:folding=explicit:collapseFolds=1: */ |
3 | 2 | // |
4 | 3 | // exporter.h: Rcpp R/C++ interface class library -- identify if a class has a nested iterator typedef |
5 | 4 | // |
6 | | -// Copyright (C) 2010 - 2011 Dirk Eddelbuettel and Romain Francois |
| 5 | +// Copyright (C) 2010 - 2013 Dirk Eddelbuettel and Romain Francois |
7 | 6 | // |
8 | 7 | // This file is part of Rcpp. |
9 | 8 | // |
|
26 | 25 | namespace Rcpp{ |
27 | 26 | namespace traits{ |
28 | 27 |
|
29 | | - template <typename T> class Exporter{ |
30 | | - public: |
31 | | - Exporter( SEXP x ) : t(x){} |
32 | | - inline T get(){ return t ; } |
33 | | - |
34 | | - private: |
35 | | - T t ; |
36 | | - } ; |
37 | | - |
38 | | - template <typename T> class RangeExporter { |
39 | | - public: |
40 | | - typedef typename T::value_type r_export_type ; |
41 | | - |
42 | | - RangeExporter( SEXP x ) : object(x){} |
43 | | - ~RangeExporter(){} |
44 | | - |
45 | | - T get(){ |
46 | | - T vec( ::Rf_length(object) ); |
47 | | - ::Rcpp::internal::export_range( object, vec.begin() ) ; |
48 | | - return vec ; |
49 | | - } |
| 28 | + template <typename T> class Exporter{ |
| 29 | + public: |
| 30 | + Exporter( SEXP x ) : t(x){} |
| 31 | + inline T get(){ return t ; } |
| 32 | + |
| 33 | + private: |
| 34 | + T t ; |
| 35 | + } ; |
| 36 | + |
| 37 | + template <typename T> class RangeExporter { |
| 38 | + public: |
| 39 | + typedef typename T::value_type r_export_type ; |
| 40 | + |
| 41 | + RangeExporter( SEXP x ) : object(x){} |
| 42 | + ~RangeExporter(){} |
| 43 | + |
| 44 | + T get(){ |
| 45 | + T vec( ::Rf_length(object) ); |
| 46 | + ::Rcpp::internal::export_range( object, vec.begin() ) ; |
| 47 | + return vec ; |
| 48 | + } |
| 49 | + |
| 50 | + private: |
| 51 | + SEXP object ; |
| 52 | + } ; |
50 | 53 |
|
51 | | - private: |
52 | | - SEXP object ; |
53 | | - } ; |
54 | | - |
55 | | - template <typename T, typename value_type> class IndexingExporter { |
| 54 | + template <typename T, typename value_type> class IndexingExporter { |
56 | 55 | public: |
57 | 56 | typedef value_type r_export_type ; |
58 | 57 |
|
@@ -92,20 +91,26 @@ namespace Rcpp{ |
92 | 91 | SEXP object ; |
93 | 92 | } ; |
94 | 93 |
|
95 | | - |
96 | | - template <typename T> class Exporter< std::vector<T> > : public RangeExporter< std::vector<T> > { |
| 94 | + template < template<class,class> class Container, typename T> |
| 95 | + struct container_exporter{ |
| 96 | + typedef RangeExporter< Container<T, std::allocator<T> > > type ; |
| 97 | + } ; |
| 98 | + template < template<class,class> class Container > struct container_exporter< Container, int > ; |
| 99 | + template < template<class,class> class Container > struct container_exporter< Container, double > ; |
| 100 | + |
| 101 | + template <typename T> class Exporter< std::vector<T> > : public container_exporter< std::vector, T>::type { |
97 | 102 | public: |
98 | | - Exporter(SEXP x) : RangeExporter< std::vector<T> >(x){} |
| 103 | + Exporter(SEXP x) : container_exporter< std::vector, T>::type(x){} |
99 | 104 | }; |
100 | | - template <typename T> class Exporter< std::deque<T> > : public RangeExporter< std::deque<T> > { |
| 105 | + template <typename T> class Exporter< std::deque<T> > : public container_exporter< std::deque, T>::type { |
101 | 106 | public: |
102 | | - Exporter(SEXP x) : RangeExporter< std::deque<T> >(x){} |
| 107 | + Exporter(SEXP x) : container_exporter< std::deque, T>::type(x){} |
103 | 108 | }; |
104 | | - template <typename T> class Exporter< std::list<T> > : public RangeExporter< std::list<T> > { |
| 109 | + template <typename T> class Exporter< std::list<T> > : public container_exporter< std::list, T>::type { |
105 | 110 | public: |
106 | | - Exporter(SEXP x) : RangeExporter< std::list<T> >(x){} |
| 111 | + Exporter(SEXP x) : container_exporter< std::list, T>::type(x){} |
107 | 112 | }; |
108 | | - |
| 113 | + |
109 | 114 | } // namespace traits |
110 | 115 | } // namespace Rcpp |
111 | 116 | #endif |
0 commit comments