Skip to content

Commit 89e6d83

Browse files
authored
Merge pull request #850 from romainfrancois/NoProtectStorage_string_proxies
More thorough use of storage policy in Vector internals
2 parents c50f941 + 01deea0 commit 89e6d83

13 files changed

+215
-141
lines changed

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.12.16.2
4-
Date: 2018-04-25
3+
Version: 0.12.16.3
4+
Date: 2018-05-04
55
Author: Dirk Eddelbuettel, Romain Francois, JJ Allaire, Kevin Ushey, Qiang Kou,
66
Nathan Russell, Douglas Bates and John Chambers
77
Maintainer: Dirk Eddelbuettel <[email protected]>

inst/include/Rcpp/String.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// String.h: Rcpp R/C++ interface class library -- single string
44
//
5-
// Copyright (C) 2012 - 2015 Dirk Eddelbuettel and Romain Francois
5+
// Copyright (C) 2012 - 2018 Dirk Eddelbuettel and Romain Francois
66
//
77
// This file is part of Rcpp.
88
//
@@ -483,8 +483,8 @@ namespace Rcpp {
483483
}
484484

485485
namespace internal {
486-
template <int RTYPE>
487-
string_proxy<RTYPE>& string_proxy<RTYPE>::operator=(const String& s) {
486+
template <int RTYPE, template <class> class StoragePolicy>
487+
string_proxy<RTYPE, StoragePolicy>& string_proxy<RTYPE, StoragePolicy>::operator=(const String& s) {
488488
set(s.get_sexp());
489489
return *this;
490490
}
@@ -500,9 +500,9 @@ namespace Rcpp {
500500
return s.get_sexp();
501501
}
502502

503-
template <int RTYPE>
503+
template <int RTYPE, template <class> class StoragePolicy>
504504
template <typename T>
505-
string_proxy<RTYPE>& string_proxy<RTYPE>::operator+=(const T& rhs) {
505+
string_proxy<RTYPE, StoragePolicy>& string_proxy<RTYPE, StoragePolicy>::operator+=(const T& rhs) {
506506
String tmp = get();
507507
tmp += rhs;
508508
set(tmp);

inst/include/Rcpp/internal/Proxy_Iterator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class Proxy_Iterator {
8181
}
8282

8383
inline reference operator*() {
84-
return proxy ;
84+
return proxy ;
8585
}
8686
inline pointer operator->(){
8787
return &proxy ;

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// 00_forward_proxy.h: Rcpp R/C++ interface class library -- proxies
44
//
5-
// Copyright (C) 2010 - 2013 Dirk Eddelbuettel and Romain Francois
5+
// Copyright (C) 2010 - 2018 Dirk Eddelbuettel and Romain Francois
66
//
77
// This file is part of Rcpp.
88
//
@@ -25,25 +25,25 @@
2525
namespace Rcpp{
2626

2727
namespace internal{
28-
template <int RTYPE> class string_proxy ;
29-
template <int RTYPE> class const_string_proxy ;
30-
template <int RTYPE> class generic_proxy ;
31-
template <int RTYPE> class const_generic_proxy ;
32-
template <int RTYPE> class simple_name_proxy ;
33-
template <int RTYPE> class string_name_proxy ;
34-
template <int RTYPE> class generic_name_proxy ;
28+
template <int RTYPE, template <class> class StoragePolicy = PreserveStorage> class string_proxy ;
29+
template <int RTYPE, template <class> class StoragePolicy = PreserveStorage> class const_string_proxy ;
30+
template <int RTYPE, template <class> class StoragePolicy = PreserveStorage> class generic_proxy ;
31+
template <int RTYPE, template <class> class StoragePolicy = PreserveStorage> class const_generic_proxy ;
32+
template <int RTYPE, template <class> class StoragePolicy = PreserveStorage> class simple_name_proxy ;
33+
template <int RTYPE, template <class> class StoragePolicy = PreserveStorage> class string_name_proxy ;
34+
template <int RTYPE, template <class> class StoragePolicy = PreserveStorage> class generic_name_proxy ;
3535
}
3636

3737
namespace traits {
3838
template <int RTYPE, template <class> class StoragePolicy> struct r_vector_cache_type ;
3939
template <int RTYPE, template <class> class StoragePolicy> class r_vector_cache ;
4040

41-
template <int RTYPE> struct r_vector_name_proxy ;
42-
template <int RTYPE> struct r_vector_proxy ;
43-
template <int RTYPE> struct r_vector_const_proxy ;
41+
template <int RTYPE, template <class> class StoragePolicy = PreserveStorage> struct r_vector_name_proxy ;
42+
template <int RTYPE, template <class> class StoragePolicy = PreserveStorage> struct r_vector_proxy ;
43+
template <int RTYPE, template <class> class StoragePolicy = PreserveStorage> struct r_vector_const_proxy ;
4444

45-
template <int RTYPE> struct r_vector_iterator ;
46-
template <int RTYPE> struct r_vector_const_iterator ;
45+
template <int RTYPE, template <class> class StoragePolicy = PreserveStorage> struct r_vector_iterator ;
46+
template <int RTYPE, template <class> class StoragePolicy = PreserveStorage> struct r_vector_const_iterator ;
4747

4848
}
4949
}

inst/include/Rcpp/vector/Vector.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// Vector.h: Rcpp R/C++ interface class library -- vectors
44
//
5-
// Copyright (C) 2010 - 2017 Dirk Eddelbuettel and Romain Francois
5+
// Copyright (C) 2010 - 2018 Dirk Eddelbuettel and Romain Francois
66
//
77
// This file is part of Rcpp.
88
//
@@ -40,12 +40,12 @@ class Vector :
4040
typedef StoragePolicy<Vector> Storage ;
4141

4242
typename traits::r_vector_cache_type<RTYPE, StoragePolicy>::type cache ;
43-
typedef typename traits::r_vector_proxy<RTYPE>::type Proxy ;
44-
typedef typename traits::r_vector_const_proxy<RTYPE>::type const_Proxy ;
45-
typedef typename traits::r_vector_name_proxy<RTYPE>::type NameProxy ;
46-
typedef typename traits::r_vector_proxy<RTYPE>::type value_type ;
47-
typedef typename traits::r_vector_iterator<RTYPE>::type iterator ;
48-
typedef typename traits::r_vector_const_iterator<RTYPE>::type const_iterator ;
43+
typedef typename traits::r_vector_proxy<RTYPE, StoragePolicy>::type Proxy ;
44+
typedef typename traits::r_vector_const_proxy<RTYPE, StoragePolicy>::type const_Proxy ;
45+
typedef typename traits::r_vector_name_proxy<RTYPE, StoragePolicy>::type NameProxy ;
46+
typedef typename traits::r_vector_proxy<RTYPE, StoragePolicy>::type value_type ;
47+
typedef typename traits::r_vector_iterator<RTYPE, StoragePolicy>::type iterator ;
48+
typedef typename traits::r_vector_const_iterator<RTYPE, StoragePolicy>::type const_iterator ;
4949
typedef typename traits::init_type<RTYPE>::type init_type ;
5050
typedef typename traits::r_vector_element_converter<RTYPE>::type converter_type ;
5151
typedef typename traits::storage_type<RTYPE>::type stored_type ;
@@ -936,6 +936,7 @@ class Vector :
936936
}
937937

938938
R_xlen_t n = size() ;
939+
939940
Vector target( n - 1 ) ;
940941
iterator target_it(target.begin()) ;
941942
iterator it(begin()) ;

inst/include/Rcpp/vector/const_generic_proxy.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// const_generic_proxy.h: Rcpp R/C++ interface class library --
22
//
3-
// Copyright (C) 2013 Romain Francois
3+
// Copyright (C) 2013 - 2018 Romain Francois
44
//
55
// This file is part of Rcpp.
66
//
@@ -23,10 +23,10 @@
2323
namespace Rcpp{
2424
namespace internal{
2525

26-
template <int RTYPE>
27-
class const_generic_proxy : public GenericProxy< const_generic_proxy<RTYPE> > {
26+
template <int RTYPE, template <class> class StoragePolicy>
27+
class const_generic_proxy : public GenericProxy< const_generic_proxy<RTYPE, StoragePolicy> > {
2828
public:
29-
typedef typename ::Rcpp::Vector<RTYPE> VECTOR ;
29+
typedef typename ::Rcpp::Vector<RTYPE, StoragePolicy> VECTOR ;
3030

3131
const_generic_proxy(): parent(0), index(-1){}
3232

@@ -48,7 +48,7 @@ namespace internal{
4848
operator int() const { return ::Rcpp::as<int>(get()) ; }
4949

5050
inline void move(R_xlen_t n) { index += n ; }
51-
51+
5252
const VECTOR* parent;
5353
R_xlen_t index ;
5454

inst/include/Rcpp/vector/const_string_proxy.h

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// const_string_proxy.h: Rcpp R/C++ interface class library --
44
//
5-
// Copyright (C) 2013 Romain Francois
5+
// Copyright (C) 2013 - 2018 Romain Francois
66
//
77
// This file is part of Rcpp.
88
//
@@ -25,10 +25,11 @@
2525
namespace Rcpp{
2626
namespace internal{
2727

28-
template<int RTYPE> class const_string_proxy {
28+
template<int RTYPE, template <class> class StoragePolicy>
29+
class const_string_proxy {
2930
public:
3031

31-
typedef typename ::Rcpp::Vector<RTYPE> VECTOR ;
32+
typedef typename ::Rcpp::Vector<RTYPE, StoragePolicy> VECTOR ;
3233
typedef const char* iterator ;
3334
typedef const char& reference ;
3435

@@ -43,7 +44,7 @@ namespace internal{
4344
const_string_proxy( const VECTOR& v, R_xlen_t index_ ) : parent(&v), index(index_){}
4445

4546
const_string_proxy(SEXP x): parent(0), index(0) {
46-
Vector<RTYPE> tmp(x);
47+
VECTOR tmp(x);
4748
parent = &tmp;
4849
}
4950

@@ -76,11 +77,11 @@ namespace internal{
7677
* Prints the element this proxy refers to to an
7778
* output stream
7879
*/
79-
template <int RT>
80-
friend std::ostream& operator<<(std::ostream& os, const const_string_proxy<RT>& proxy);
80+
template <int RT, template <class> class StoragePolicy_>
81+
friend std::ostream& operator<<(std::ostream& os, const const_string_proxy<RT, StoragePolicy_>& proxy);
8182

82-
template <int RT>
83-
friend std::string operator+( const std::string& x, const const_string_proxy<RT>& proxy);
83+
template <int RT, template <class> class StoragePolicy_>
84+
friend std::string operator+( const std::string& x, const const_string_proxy<RT, StoragePolicy_>& proxy);
8485

8586
const VECTOR* parent;
8687
R_xlen_t index ;
@@ -110,13 +111,13 @@ namespace internal{
110111
return strcmp( begin(), other.begin() ) != 0 ;
111112
}
112113

113-
bool operator==( SEXP other ) const {
114-
return get() == other;
115-
}
114+
bool operator==( SEXP other ) const {
115+
return get() == other;
116+
}
116117

117-
bool operator!=( SEXP other ) const {
118-
return get() != other;
119-
}
118+
bool operator!=( SEXP other ) const {
119+
return get() != other;
120+
}
120121

121122
private:
122123
static std::string buffer ;
@@ -155,20 +156,22 @@ namespace internal{
155156
) <= 0 ;
156157
}
157158

158-
template<int RTYPE> std::string const_string_proxy<RTYPE>::buffer ;
159+
template<int RTYPE, template <class> class StoragePolicy> std::string const_string_proxy<RTYPE, StoragePolicy>::buffer ;
159160

160-
inline std::ostream& operator<<(std::ostream& os, const const_string_proxy<STRSXP>& proxy) {
161+
template <template <class> class StoragePolicy>
162+
inline std::ostream& operator<<(std::ostream& os, const const_string_proxy<STRSXP, StoragePolicy>& proxy) {
161163
os << static_cast<const char*>(proxy) ;
162164
return os;
163165
}
164166

165-
inline std::string operator+( const std::string& x, const const_string_proxy<STRSXP>& y ){
167+
template <template <class> class StoragePolicy>
168+
inline std::string operator+( const std::string& x, const const_string_proxy<STRSXP, StoragePolicy>& y ){
166169
return x + static_cast<const char*>(y) ;
167170
}
168171

169-
170-
template <int RTYPE>
171-
string_proxy<RTYPE>& string_proxy<RTYPE>::operator=(const const_string_proxy<RTYPE>& other){
172+
template <int RTYPE, template <class> class StoragePolicy1>
173+
template <template <class> class StoragePolicy2>
174+
string_proxy<RTYPE, StoragePolicy1>& string_proxy<RTYPE, StoragePolicy1>::operator=(const const_string_proxy<RTYPE, StoragePolicy2>& other){
172175
set( other.get() ) ;
173176
return *this ;
174177
}

inst/include/Rcpp/vector/generic_proxy.h

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// generic_proxy.h: Rcpp R/C++ interface class library --
22
//
3-
// Copyright (C) 2010 - 2013 Dirk Eddelbuettel and Romain Francois
3+
// Copyright (C) 2010 - 2018 Dirk Eddelbuettel and Romain Francois
44
//
55
// This file is part of Rcpp.
66
//
@@ -23,25 +23,34 @@
2323
namespace Rcpp{
2424
namespace internal{
2525

26-
template <int RTYPE>
27-
class generic_proxy : public GenericProxy< generic_proxy<RTYPE> > {
26+
template <int RTYPE, template <class> class StoragePolicy>
27+
class generic_proxy : public GenericProxy< generic_proxy<RTYPE, StoragePolicy> > {
2828
public:
29-
typedef typename ::Rcpp::Vector<RTYPE> VECTOR ;
29+
typedef typename ::Rcpp::Vector<RTYPE, StoragePolicy> VECTOR ;
3030

3131
generic_proxy(): parent(0), index(-1){}
3232

3333
generic_proxy( const generic_proxy& other ) :
34-
parent(other.parent), index(other.index){} ;
34+
parent(other.parent), index(other.index)
35+
{}
3536

36-
generic_proxy( VECTOR& v, R_xlen_t i ) : parent(&v), index(i){} ;
37+
generic_proxy( VECTOR& v, R_xlen_t i ) :
38+
parent(&v), index(i)
39+
{}
3740

3841
generic_proxy& operator=(SEXP rhs) {
3942
set(rhs) ;
4043
return *this ;
4144
}
4245

43-
generic_proxy& operator=(const generic_proxy& rhs) {
44-
set(rhs.get());
46+
generic_proxy& operator=(const generic_proxy& rhs){
47+
set(rhs.get());
48+
return *this ;
49+
}
50+
51+
template <template <class> class StoragePolicy2>
52+
generic_proxy& operator=(const generic_proxy<RTYPE,StoragePolicy2>& rhs) {
53+
set(rhs.get());
4554
return *this ;
4655
}
4756

@@ -78,13 +87,15 @@ namespace internal{
7887
index = other.index ;
7988
}
8089

90+
inline SEXP get() const {
91+
return VECTOR_ELT(*parent, index );
92+
}
93+
8194
private:
8295
inline void set(SEXP x) {
8396
SET_VECTOR_ELT( *parent, index, x ) ;
8497
}
85-
inline SEXP get() const {
86-
return VECTOR_ELT(*parent, index );
87-
}
98+
8899

89100
} ;
90101

0 commit comments

Comments
 (0)