Skip to content

Commit 6d57868

Browse files
added const_generic_proxy
1 parent de32263 commit 6d57868

File tree

4 files changed

+73
-0
lines changed

4 files changed

+73
-0
lines changed

inst/include/Rcpp/Vector.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ template <int RTYPE> class SubMatrix ;
6363
#include <Rcpp/vector/string_proxy.h>
6464
#include <Rcpp/vector/const_string_proxy.h>
6565
}
66+
#include <Rcpp/vector/const_generic_proxy.h>
67+
6668

6769
#include <Rcpp/String.h>
6870
#include <Rcpp/vector/LazyVector.h>

inst/include/Rcpp/vector/00_forward_proxy.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ namespace internal{
2626
template <int RTYPE> class string_proxy ;
2727
template <int RTYPE> class const_string_proxy ;
2828
template <int RTYPE> class generic_proxy ;
29+
template <int RTYPE> class const_generic_proxy ;
2930
template <int RTYPE> class simple_name_proxy ;
3031
template <int RTYPE> class string_name_proxy ;
3132
template <int RTYPE> class generic_name_proxy ;
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// const_generic_proxy.h: Rcpp R/C++ interface class library --
2+
//
3+
// Copyright (C) 2013 Romain Francois
4+
//
5+
// This file is part of Rcpp.
6+
//
7+
// Rcpp is free software: you can redistribute it and/or modify it
8+
// under the terms of the GNU General Public License as published by
9+
// the Free Software Foundation, either version 2 of the License, or
10+
// (at your option) any later version.
11+
//
12+
// Rcpp is distributed in the hope that it will be useful, but
13+
// WITHOUT ANY WARRANTY; without even the implied warranty of
14+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
// GNU General Public License for more details.
16+
//
17+
// You should have received a copy of the GNU General Public License
18+
// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
19+
20+
#ifndef Rcpp__vector__const_generic_proxy_h
21+
#define Rcpp__vector__const_generic_proxy_h
22+
23+
namespace Rcpp{
24+
namespace internal{
25+
26+
template <int RTYPE>
27+
class const_generic_proxy{
28+
public:
29+
typedef typename ::Rcpp::Vector<RTYPE> VECTOR ;
30+
31+
const_generic_proxy(): parent(0), index(-1){}
32+
33+
const_generic_proxy( const const_generic_proxy& other ) :
34+
parent(other.parent), index(other.index){} ;
35+
36+
const_generic_proxy( const VECTOR& v, int i ) : parent(&v), index(i){} ;
37+
38+
operator SEXP() const {
39+
return get() ;
40+
}
41+
42+
template <typename U> operator U() const {
43+
return ::Rcpp::as<U>(get()) ;
44+
}
45+
46+
// helping the compiler (not sure why it can't help itself)
47+
operator bool() const { return ::Rcpp::as<bool>(get()) ; }
48+
operator int() const { return ::Rcpp::as<int>(get()) ; }
49+
50+
const VECTOR* parent;
51+
int index ;
52+
53+
private:
54+
55+
inline SEXP get() const {
56+
return VECTOR_ELT(*parent, index );
57+
}
58+
59+
} ;
60+
61+
}
62+
}
63+
64+
#endif

inst/include/Rcpp/vector/proxy.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,12 @@ namespace traits {
230230
template<> struct r_vector_const_proxy<STRSXP> {
231231
typedef ::Rcpp::internal::const_string_proxy<STRSXP> type ;
232232
} ;
233+
template<> struct r_vector_const_proxy<VECSXP> {
234+
typedef ::Rcpp::internal::const_generic_proxy<VECSXP> type ;
235+
} ;
236+
template<> struct r_vector_const_proxy<EXPRSXP> {
237+
typedef ::Rcpp::internal::const_generic_proxy<EXPRSXP> type ;
238+
} ;
233239

234240
template <int RTYPE>
235241
struct r_vector_iterator {

0 commit comments

Comments
 (0)