From 4e83e0be3a3e8b029771e0040d703e0f59245749 Mon Sep 17 00:00:00 2001 From: Romain Francois Date: Fri, 4 May 2018 10:21:25 +0200 Subject: [PATCH 1/6] propagate StoragePolicy to internals of Rcpp::Vector. closes #849 --- inst/include/Rcpp/String.h | 10 +- inst/include/Rcpp/vector/00_forward_proxy.h | 26 +++--- inst/include/Rcpp/vector/Vector.h | 14 +-- .../include/Rcpp/vector/const_generic_proxy.h | 10 +- inst/include/Rcpp/vector/const_string_proxy.h | 43 +++++---- inst/include/Rcpp/vector/generic_proxy.h | 8 +- inst/include/Rcpp/vector/proxy.h | 92 +++++++++++-------- inst/include/Rcpp/vector/string_proxy.h | 12 ++- inst/include/Rcpp/vector/traits.h | 6 +- 9 files changed, 120 insertions(+), 101 deletions(-) diff --git a/inst/include/Rcpp/String.h b/inst/include/Rcpp/String.h index 8e4528d49..dd771d0ef 100644 --- a/inst/include/Rcpp/String.h +++ b/inst/include/Rcpp/String.h @@ -2,7 +2,7 @@ // // String.h: Rcpp R/C++ interface class library -- single string // -// Copyright (C) 2012 - 2015 Dirk Eddelbuettel and Romain Francois +// Copyright (C) 2012 - 2018 Dirk Eddelbuettel and Romain Francois // // This file is part of Rcpp. // @@ -483,8 +483,8 @@ namespace Rcpp { } namespace internal { - template - string_proxy& string_proxy::operator=(const String& s) { + template class StoragePolicy> + string_proxy& string_proxy::operator=(const String& s) { set(s.get_sexp()); return *this; } @@ -500,9 +500,9 @@ namespace Rcpp { return s.get_sexp(); } - template + template class StoragePolicy> template - string_proxy& string_proxy::operator+=(const T& rhs) { + string_proxy& string_proxy::operator+=(const T& rhs) { String tmp = get(); tmp += rhs; set(tmp); diff --git a/inst/include/Rcpp/vector/00_forward_proxy.h b/inst/include/Rcpp/vector/00_forward_proxy.h index df623ef34..9098b51fa 100644 --- a/inst/include/Rcpp/vector/00_forward_proxy.h +++ b/inst/include/Rcpp/vector/00_forward_proxy.h @@ -2,7 +2,7 @@ // // 00_forward_proxy.h: Rcpp R/C++ interface class library -- proxies // -// Copyright (C) 2010 - 2013 Dirk Eddelbuettel and Romain Francois +// Copyright (C) 2010 - 2018 Dirk Eddelbuettel and Romain Francois // // This file is part of Rcpp. // @@ -25,25 +25,25 @@ namespace Rcpp{ namespace internal{ - template class string_proxy ; - template class const_string_proxy ; - template class generic_proxy ; - template class const_generic_proxy ; - template class simple_name_proxy ; - template class string_name_proxy ; - template class generic_name_proxy ; + template class StoragePolicy = PreserveStorage> class string_proxy ; + template class StoragePolicy = PreserveStorage> class const_string_proxy ; + template class StoragePolicy = PreserveStorage> class generic_proxy ; + template class StoragePolicy = PreserveStorage> class const_generic_proxy ; + template class StoragePolicy = PreserveStorage> class simple_name_proxy ; + template class StoragePolicy = PreserveStorage> class string_name_proxy ; + template class StoragePolicy = PreserveStorage> class generic_name_proxy ; } namespace traits { template class StoragePolicy> struct r_vector_cache_type ; template class StoragePolicy> class r_vector_cache ; - template struct r_vector_name_proxy ; - template struct r_vector_proxy ; - template struct r_vector_const_proxy ; + template class StoragePolicy = PreserveStorage> struct r_vector_name_proxy ; + template class StoragePolicy = PreserveStorage> struct r_vector_proxy ; + template class StoragePolicy = PreserveStorage> struct r_vector_const_proxy ; - template struct r_vector_iterator ; - template struct r_vector_const_iterator ; + template class StoragePolicy = PreserveStorage> struct r_vector_iterator ; + template class StoragePolicy = PreserveStorage> struct r_vector_const_iterator ; } } diff --git a/inst/include/Rcpp/vector/Vector.h b/inst/include/Rcpp/vector/Vector.h index 141bce006..bc76bc238 100644 --- a/inst/include/Rcpp/vector/Vector.h +++ b/inst/include/Rcpp/vector/Vector.h @@ -2,7 +2,7 @@ // // Vector.h: Rcpp R/C++ interface class library -- vectors // -// Copyright (C) 2010 - 2017 Dirk Eddelbuettel and Romain Francois +// Copyright (C) 2010 - 2018 Dirk Eddelbuettel and Romain Francois // // This file is part of Rcpp. // @@ -40,12 +40,12 @@ class Vector : typedef StoragePolicy Storage ; typename traits::r_vector_cache_type::type cache ; - typedef typename traits::r_vector_proxy::type Proxy ; - typedef typename traits::r_vector_const_proxy::type const_Proxy ; - typedef typename traits::r_vector_name_proxy::type NameProxy ; - typedef typename traits::r_vector_proxy::type value_type ; - typedef typename traits::r_vector_iterator::type iterator ; - typedef typename traits::r_vector_const_iterator::type const_iterator ; + typedef typename traits::r_vector_proxy::type Proxy ; + typedef typename traits::r_vector_const_proxy::type const_Proxy ; + typedef typename traits::r_vector_name_proxy::type NameProxy ; + typedef typename traits::r_vector_proxy::type value_type ; + typedef typename traits::r_vector_iterator::type iterator ; + typedef typename traits::r_vector_const_iterator::type const_iterator ; typedef typename traits::init_type::type init_type ; typedef typename traits::r_vector_element_converter::type converter_type ; typedef typename traits::storage_type::type stored_type ; diff --git a/inst/include/Rcpp/vector/const_generic_proxy.h b/inst/include/Rcpp/vector/const_generic_proxy.h index 88e8d99c9..ac1f53e4e 100644 --- a/inst/include/Rcpp/vector/const_generic_proxy.h +++ b/inst/include/Rcpp/vector/const_generic_proxy.h @@ -1,6 +1,6 @@ // const_generic_proxy.h: Rcpp R/C++ interface class library -- // -// Copyright (C) 2013 Romain Francois +// Copyright (C) 2013 - 2018 Romain Francois // // This file is part of Rcpp. // @@ -23,10 +23,10 @@ namespace Rcpp{ namespace internal{ - template - class const_generic_proxy : public GenericProxy< const_generic_proxy > { + template class StoragePolicy> + class const_generic_proxy : public GenericProxy< const_generic_proxy > { public: - typedef typename ::Rcpp::Vector VECTOR ; + typedef typename ::Rcpp::Vector VECTOR ; const_generic_proxy(): parent(0), index(-1){} @@ -48,7 +48,7 @@ namespace internal{ operator int() const { return ::Rcpp::as(get()) ; } inline void move(R_xlen_t n) { index += n ; } - + const VECTOR* parent; R_xlen_t index ; diff --git a/inst/include/Rcpp/vector/const_string_proxy.h b/inst/include/Rcpp/vector/const_string_proxy.h index a890f2ac0..10c0b1bcd 100644 --- a/inst/include/Rcpp/vector/const_string_proxy.h +++ b/inst/include/Rcpp/vector/const_string_proxy.h @@ -2,7 +2,7 @@ // // const_string_proxy.h: Rcpp R/C++ interface class library -- // -// Copyright (C) 2013 Romain Francois +// Copyright (C) 2013 - 2018 Romain Francois // // This file is part of Rcpp. // @@ -25,10 +25,11 @@ namespace Rcpp{ namespace internal{ - template class const_string_proxy { + template class StoragePolicy> + class const_string_proxy { public: - typedef typename ::Rcpp::Vector VECTOR ; + typedef typename ::Rcpp::Vector VECTOR ; typedef const char* iterator ; typedef const char& reference ; @@ -43,7 +44,7 @@ namespace internal{ const_string_proxy( const VECTOR& v, R_xlen_t index_ ) : parent(&v), index(index_){} const_string_proxy(SEXP x): parent(0), index(0) { - Vector tmp(x); + VECTOR tmp(x); parent = &tmp; } @@ -76,11 +77,11 @@ namespace internal{ * Prints the element this proxy refers to to an * output stream */ - template - friend std::ostream& operator<<(std::ostream& os, const const_string_proxy& proxy); + template class StoragePolicy_> + friend std::ostream& operator<<(std::ostream& os, const const_string_proxy& proxy); - template - friend std::string operator+( const std::string& x, const const_string_proxy& proxy); + template class StoragePolicy_> + friend std::string operator+( const std::string& x, const const_string_proxy& proxy); const VECTOR* parent; R_xlen_t index ; @@ -110,13 +111,13 @@ namespace internal{ return strcmp( begin(), other.begin() ) != 0 ; } - bool operator==( SEXP other ) const { - return get() == other; - } + bool operator==( SEXP other ) const { + return get() == other; + } - bool operator!=( SEXP other ) const { - return get() != other; - } + bool operator!=( SEXP other ) const { + return get() != other; + } private: static std::string buffer ; @@ -155,20 +156,22 @@ namespace internal{ ) <= 0 ; } - template std::string const_string_proxy::buffer ; + template class StoragePolicy> std::string const_string_proxy::buffer ; - inline std::ostream& operator<<(std::ostream& os, const const_string_proxy& proxy) { + template