Skip to content

Commit ff3b8ef

Browse files
committed
Merge pull request #292 from romainfrancois/master
Better support for Vector with alternative storage policy. closes #291
2 parents c67c899 + a3e27fe commit ff3b8ef

File tree

9 files changed

+60
-17
lines changed

9 files changed

+60
-17
lines changed

ChangeLog

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
2014-04-25 Romain Francois <[email protected]>
2+
3+
* inst/include/Rcpp/vector/Vector.h: update the parameterization of Vector cache
4+
* inst/include/Rcpp/vector/traits.h: ...
5+
* inst/include/Rcpp/vector/00_forward_proxy.h: ...
6+
* inst/unitTests/runit.Vector.R: test for above changes
7+
* inst/unitTests/cpp/Vector.cpp: ...
8+
19
2015-04-22 Kevin Ushey <[email protected]>
210

311
* inst/include/Rcpp/utils/tinyformat.h: don't use C++11 features

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: Rcpp
22
Title: Seamless R and C++ Integration
3-
Version: 0.11.5.3
4-
Date: 2015-04-11
3+
Version: 0.11.5.4
4+
Date: 2015-04-25
55
Author: Dirk Eddelbuettel, Romain Francois, JJ Allaire, Kevin Ushey,
66
Douglas Bates, and John Chambers
77
Maintainer: Dirk Eddelbuettel <[email protected]>

inst/NEWS.Rd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
\item Matrices now have a default constructor for zero-by-zero dimension
1313
matrices (via pull request by Dmitrii Meleshko).
1414
\item A new \code{empty()} string constructor was added.
15+
\item Better support for vector with storage policy different from the
16+
default, i.e. \code{NoProtectStorage}.
1517
}
1618
\item Changes in Rcpp Attributes:
1719
\itemize{

inst/include/Rcpp/config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#define RCPP_VERSION Rcpp_Version(0,11,5)
3131

3232
// the current source snapshot
33-
#define RCPP_DEV_VERSION RcppDevVersion(0,11,5,3)
33+
#define RCPP_DEV_VERSION RcppDevVersion(0,11,5,4)
3434

3535
#endif
3636

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ namespace internal{
3535
}
3636

3737
namespace traits {
38-
template <int RTYPE> struct r_vector_cache_type ;
39-
template <int RTYPE> class r_vector_cache ;
38+
template <int RTYPE, template <class> class StoragePolicy> struct r_vector_cache_type ;
39+
template <int RTYPE, template <class> class StoragePolicy> class r_vector_cache ;
4040

4141
template <int RTYPE> struct r_vector_name_proxy ;
4242
template <int RTYPE> struct r_vector_proxy ;

inst/include/Rcpp/vector/Vector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Vector :
3939

4040
typedef StoragePolicy<Vector> Storage ;
4141

42-
typename traits::r_vector_cache_type<RTYPE>::type cache ;
42+
typename traits::r_vector_cache_type<RTYPE, StoragePolicy>::type cache ;
4343
typedef typename traits::r_vector_proxy<RTYPE>::type Proxy ;
4444
typedef typename traits::r_vector_const_proxy<RTYPE>::type const_Proxy ;
4545
typedef typename traits::r_vector_name_proxy<RTYPE>::type NameProxy ;

inst/include/Rcpp/vector/traits.h

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// traits.h: Rcpp R/C++ interface class library -- support traits for vector
44
//
5-
// Copyright (C) 2010 - 2012 Dirk Eddelbuettel and Romain Francois
5+
// Copyright (C) 2010 - 2015 Dirk Eddelbuettel and Romain Francois
66
//
77
// This file is part of Rcpp.
88
//
@@ -25,10 +25,10 @@
2525
namespace Rcpp{
2626
namespace traits{
2727

28-
template <int RTYPE>
28+
template <int RTYPE, template <class> class StoragePolicy = PreserveStorage >
2929
class r_vector_cache{
3030
public:
31-
typedef typename ::Rcpp::Vector<RTYPE> VECTOR ;
31+
typedef typename ::Rcpp::Vector<RTYPE, StoragePolicy> VECTOR ;
3232
typedef typename r_vector_iterator<RTYPE>::type iterator ;
3333
typedef typename r_vector_const_iterator<RTYPE>::type const_iterator ;
3434
typedef typename r_vector_proxy<RTYPE>::type proxy ;
@@ -51,9 +51,10 @@ namespace traits{
5151
private:
5252
iterator start ;
5353
} ;
54-
template <int RTYPE> class proxy_cache{
54+
template <int RTYPE, template <class> class StoragePolicy = PreserveStorage>
55+
class proxy_cache{
5556
public:
56-
typedef typename ::Rcpp::Vector<RTYPE> VECTOR ;
57+
typedef typename ::Rcpp::Vector<RTYPE, StoragePolicy> VECTOR ;
5758
typedef typename r_vector_iterator<RTYPE>::type iterator ;
5859
typedef typename r_vector_const_iterator<RTYPE>::type const_iterator ;
5960
typedef typename r_vector_proxy<RTYPE>::type proxy ;
@@ -79,12 +80,24 @@ namespace traits{
7980
} ;
8081

8182
// regular types for INTSXP, REALSXP, ...
82-
template <int RTYPE> struct r_vector_cache_type { typedef r_vector_cache<RTYPE> type ; } ;
83+
template <int RTYPE, template <class> class StoragePolicy = PreserveStorage>
84+
struct r_vector_cache_type {
85+
typedef r_vector_cache<RTYPE, StoragePolicy> type ;
86+
} ;
8387

8488
// proxy types for VECSXP, STRSXP and EXPRSXP
85-
template <> struct r_vector_cache_type<VECSXP> { typedef proxy_cache<VECSXP> type ; } ;
86-
template <> struct r_vector_cache_type<EXPRSXP> { typedef proxy_cache<EXPRSXP> type ; } ;
87-
template <> struct r_vector_cache_type<STRSXP> { typedef proxy_cache<STRSXP> type ; } ;
89+
template <template <class> class StoragePolicy>
90+
struct r_vector_cache_type<VECSXP, StoragePolicy> {
91+
typedef proxy_cache<VECSXP, StoragePolicy> type ;
92+
} ;
93+
template <template <class> class StoragePolicy>
94+
struct r_vector_cache_type<EXPRSXP, StoragePolicy> {
95+
typedef proxy_cache<EXPRSXP, StoragePolicy> type ;
96+
} ;
97+
template <template <class> class StoragePolicy>
98+
struct r_vector_cache_type<STRSXP, StoragePolicy> {
99+
typedef proxy_cache<STRSXP, StoragePolicy> type ;
100+
} ;
88101

89102
} // traits
90103
}

inst/unitTests/cpp/Vector.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// Vector.cpp: Rcpp R/C++ interface class library -- Vector unit tests
44
//
5-
// Copyright (C) 2012 - 2013 Dirk Eddelbuettel and Romain Francois
5+
// Copyright (C) 2012 - 2015 Dirk Eddelbuettel and Romain Francois
66
//
77
// This file is part of Rcpp.
88
//
@@ -766,3 +766,13 @@ LogicalVector logical_vector_from_bool_assign() {
766766
void no_op(int major) {
767767
int minor = 1;
768768
}
769+
770+
// [[Rcpp::export]]
771+
int noprotect_vector( Vector<REALSXP, NoProtectStorage> x){
772+
return x.size() ;
773+
}
774+
775+
// [[Rcpp::export]]
776+
int noprotect_matrix( Matrix<REALSXP, NoProtectStorage> x){
777+
return x.nrow() ;
778+
}

inst/unitTests/runit.Vector.R

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/r -t
22
# hey emacs, please make this use -*- tab-width: 4 -*-
33
#
4-
# Copyright (C) 2010 - 2014 Dirk Eddelbuettel and Romain Francois
4+
# Copyright (C) 2010 - 2015 Dirk Eddelbuettel and Romain Francois
55
#
66
# This file is part of Rcpp.
77
#
@@ -674,5 +674,15 @@ if (.runThisTest) {
674674
checkIdentical(logical_vector_from_bool_assign(), TRUE)
675675
}
676676

677+
test.noprotect_vector <- function(){
678+
x <- rnorm(10)
679+
checkIdentical( noprotect_vector(x), 10L )
680+
}
681+
682+
test.noprotect_matrix <- function(){
683+
x <- matrix(rnorm(10), nrow=2)
684+
checkIdentical( noprotect_matrix(x), 2L )
685+
}
686+
677687
}
678688

0 commit comments

Comments
 (0)