Rcpp Version 1.0.9
traits.h
Go to the documentation of this file.
1 // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
2 //
3 // traits.h: Rcpp R/C++ interface class library -- support traits for vector
4 //
5 // Copyright (C) 2010 - 2018 Dirk Eddelbuettel and Romain Francois
6 //
7 // This file is part of Rcpp.
8 //
9 // Rcpp is free software: you can redistribute it and/or modify it
10 // under the terms of the GNU General Public License as published by
11 // the Free Software Foundation, either version 2 of the License, or
12 // (at your option) any later version.
13 //
14 // Rcpp is distributed in the hope that it will be useful, but
15 // WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
21 
22 #ifndef Rcpp__vector__traits_h
23 #define Rcpp__vector__traits_h
24 
25 namespace Rcpp{
26 namespace traits{
27 
28  template <int RTYPE, template <class> class StoragePolicy = PreserveStorage >
30  public:
31  typedef typename ::Rcpp::Vector<RTYPE, StoragePolicy> VECTOR ;
37 
38  r_vector_cache() : start(0){} ;
39  inline void update( const VECTOR& v ) {
40  start = ::Rcpp::internal::r_vector_start<RTYPE>(v) ;
41  }
42  inline iterator get() const { return start; }
43  inline const_iterator get_const() const { return start; }
44 
45  inline proxy ref() { return *start ;}
46  inline proxy ref(R_xlen_t i) { return start[i] ; }
47 
48  inline proxy ref() const { return *start ;}
49  inline proxy ref(R_xlen_t i) const { return start[i] ; }
50 
51  private:
53  } ;
54  template <int RTYPE, template <class> class StoragePolicy = PreserveStorage>
55  class proxy_cache{
56  public:
57  typedef typename ::Rcpp::Vector<RTYPE, StoragePolicy> VECTOR ;
62 
63  proxy_cache(): p(0){}
65  void update( const VECTOR& v ){
66  p = const_cast<VECTOR*>(&v) ;
67  }
68  inline iterator get() const { return iterator( proxy(*p, 0 ) ) ;}
69  // inline const_iterator get_const() const { return const_iterator( *p ) ;}
70  inline const_iterator get_const() const { return const_iterator( const_proxy(*p, 0) ) ; }
71 
72  inline proxy ref() { return proxy(*p,0) ; }
73  inline proxy ref(R_xlen_t i) { return proxy(*p,i);}
74 
75  inline const_proxy ref() const { return const_proxy(*p,0) ; }
76  inline const_proxy ref(R_xlen_t i) const { return const_proxy(*p,i);}
77 
78  private:
79  VECTOR* p ;
80  } ;
81 
82  // regular types for INTSXP, REALSXP, ...
83  template <int RTYPE, template <class> class StoragePolicy = PreserveStorage>
86  } ;
87 
88  // proxy types for VECSXP, STRSXP and EXPRSXP
89  template <template <class> class StoragePolicy>
90  struct r_vector_cache_type<VECSXP, StoragePolicy> {
92  } ;
93  template <template <class> class StoragePolicy>
94  struct r_vector_cache_type<EXPRSXP, StoragePolicy> {
96  } ;
97  template <template <class> class StoragePolicy>
98  struct r_vector_cache_type<STRSXP, StoragePolicy> {
100  } ;
101 
102 } // traits
103 }
104 
105 #endif
r_vector_const_iterator< RTYPE, StoragePolicy >::type const_iterator
Definition: traits.h:59
iterator get() const
Definition: traits.h:68
r_vector_proxy< RTYPE, StoragePolicy >::type proxy
Definition: traits.h:60
::Rcpp::Vector< RTYPE, StoragePolicy > VECTOR
Definition: traits.h:57
const_proxy ref(R_xlen_t i) const
Definition: traits.h:76
r_vector_iterator< RTYPE, StoragePolicy >::type iterator
Definition: traits.h:58
const_proxy ref() const
Definition: traits.h:75
const_iterator get_const() const
Definition: traits.h:70
proxy ref(R_xlen_t i)
Definition: traits.h:73
r_vector_const_proxy< RTYPE, StoragePolicy >::type const_proxy
Definition: traits.h:61
void update(const VECTOR &v)
Definition: traits.h:65
void update(const VECTOR &v)
Definition: traits.h:39
const_iterator get_const() const
Definition: traits.h:43
proxy ref(R_xlen_t i) const
Definition: traits.h:49
r_vector_const_iterator< RTYPE >::type const_iterator
Definition: traits.h:33
r_vector_const_proxy< RTYPE >::type const_proxy
Definition: traits.h:35
iterator get() const
Definition: traits.h:42
storage_type< RTYPE >::type storage_type
Definition: traits.h:36
r_vector_iterator< RTYPE >::type iterator
Definition: traits.h:32
proxy ref(R_xlen_t i)
Definition: traits.h:46
::Rcpp::Vector< RTYPE, StoragePolicy > VECTOR
Definition: traits.h:31
r_vector_proxy< RTYPE >::type proxy
Definition: traits.h:34
Rcpp API.
Definition: algo.h:28
proxy_cache< EXPRSXP, StoragePolicy > type
Definition: traits.h:95
proxy_cache< STRSXP, StoragePolicy > type
Definition: traits.h:99
proxy_cache< VECSXP, StoragePolicy > type
Definition: traits.h:91
r_vector_cache< RTYPE, StoragePolicy > type
Definition: traits.h:85
const storage_type< RTYPE >::type * type
Definition: proxy.h:255
const storage_type< RTYPE >::type & type
Definition: proxy.h:234
storage_type< RTYPE >::type * type
Definition: proxy.h:251
storage_type< RTYPE >::type & type
Definition: proxy.h:217