-
-
Notifications
You must be signed in to change notification settings - Fork 219
Expand file tree
/
Copy pathExporter.h
More file actions
116 lines (97 loc) · 3.79 KB
/
Copy pathExporter.h
File metadata and controls
116 lines (97 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
//
// exporter.h: Rcpp R/C++ interface class library -- identify if a class has a nested iterator typedef
//
// Copyright (C) 2010 - 2013 Dirk Eddelbuettel and Romain Francois
//
// This file is part of Rcpp.
//
// Rcpp is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// Rcpp is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
#ifndef Rcpp__internal__exporter__h
#define Rcpp__internal__exporter__h
namespace Rcpp{
namespace traits{
template <typename T>
class Exporter{
public:
Exporter( SEXP x ) : t(x){}
inline T get(){ return t ; }
private:
T t ;
} ;
template <typename T> class RangeExporter {
public:
typedef typename T::value_type r_export_type ;
RangeExporter( SEXP x ) : object(x){}
~RangeExporter(){}
T get(){
T vec( ::Rf_length(object) );
::Rcpp::internal::export_range( object, vec.begin() ) ;
return vec ;
}
private:
SEXP object ;
} ;
template <typename T, typename value_type> class IndexingExporter {
public:
typedef value_type r_export_type ;
IndexingExporter( SEXP x) : object(x){}
~IndexingExporter(){}
T get(){
T result( ::Rf_length(object) ) ;
::Rcpp::internal::export_indexing<T,value_type>( object, result ) ;
return result ;
}
private:
SEXP object ;
} ;
template <typename T, typename value_type> class MatrixExporter {
public:
typedef value_type r_export_type ;
MatrixExporter( SEXP x) : object(x){}
~MatrixExporter(){}
T get() {
Shield<SEXP> dims( ::Rf_getAttrib( object, R_DimSymbol ) ) ;
if( Rf_isNull(dims) || ::Rf_length(dims) != 2 ){
throw ::Rcpp::not_a_matrix() ;
}
int* dims_ = INTEGER(dims) ;
T result( dims_[0], dims_[1] ) ;
::Rcpp::internal::export_indexing<T,value_type>( object, result ) ;
return result ;
}
private:
SEXP object ;
} ;
template < template<class,class> class Container, typename T>
struct container_exporter{
typedef RangeExporter< Container<T, std::allocator<T> > > type ;
} ;
template < template<class,class> class Container > struct container_exporter< Container, int > ;
template < template<class,class> class Container > struct container_exporter< Container, double > ;
template <typename T> class Exporter< std::vector<T> > : public container_exporter< std::vector, T>::type {
public:
Exporter(SEXP x) : container_exporter< std::vector, T>::type(x){}
};
template <typename T> class Exporter< std::deque<T> > : public container_exporter< std::deque, T>::type {
public:
Exporter(SEXP x) : container_exporter< std::deque, T>::type(x){}
};
template <typename T> class Exporter< std::list<T> > : public container_exporter< std::list, T>::type {
public:
Exporter(SEXP x) : container_exporter< std::list, T>::type(x){}
};
} // namespace traits
} // namespace Rcpp
#endif