Rcpp Version 1.1.2
Loading...
Searching...
No Matches
traits.h
Go to the documentation of this file.
1
2// traits.h: Rcpp R/C++ interface class library -- support traits for vector
3//
4// Copyright (C) 2010 - 2026 Dirk Eddelbuettel and Romain Francois
5//
6// This file is part of Rcpp.
7//
8// Rcpp is free software: you can redistribute it and/or modify it
9// under the terms of the GNU General Public License as published by
10// the Free Software Foundation, either version 2 of the License, or
11// (at your option) any later version.
12//
13// Rcpp is distributed in the hope that it will be useful, but
14// WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU General Public License for more details.
17//
18// You should have received a copy of the GNU General Public License
19// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
20
21#ifndef Rcpp__vector__traits_h
22#define Rcpp__vector__traits_h
23
24namespace Rcpp{
25namespace traits{
26
27 template <int RTYPE, template <class> class StoragePolicy = PreserveStorage >
29 public:
30 typedef typename ::Rcpp::Vector<RTYPE, StoragePolicy> VECTOR ;
36
37 r_vector_cache() : start(0), size(0) {} ;
38
39 inline void update( const VECTOR& v ) {
40 start = ::Rcpp::internal::r_vector_start<RTYPE>(v) ;
41 size = v.size();
42 }
43
44 inline iterator get() const { return start; }
45 inline const_iterator get_const() const { return start; }
46
47 inline proxy ref() { check_index(0); return start[0] ;}
48 inline proxy ref(R_xlen_t i) { check_index(i); return start[i] ; }
49
50 inline proxy ref() const { check_index(0); return start[0] ;}
51 inline proxy ref(R_xlen_t i) const { check_index(i); return start[i] ; }
52
53 private:
54
55 void check_index(R_xlen_t i) const {
56#ifndef RCPP_NO_BOUNDS_CHECK
57 if (i >= size) {
58 warning("subscript out of bounds (index %s >= vector size %s)", i, size); // #nocov
59 }
60#endif
61 }
62
64 R_xlen_t size ;
65 } ;
66
67 template <int RTYPE, template <class> class StoragePolicy = PreserveStorage>
69 public:
70 typedef typename ::Rcpp::Vector<RTYPE, StoragePolicy> VECTOR ;
75
76 proxy_cache(): p(0){}
78 void update( const VECTOR& v ){
79 p = const_cast<VECTOR*>(&v) ;
80 }
81 inline iterator get() const { return iterator( proxy(*p, 0 ) ) ;}
82 inline const_iterator get_const() const { return const_iterator( const_proxy(*p, 0) ) ; }
83
84 inline proxy ref() { check_index(0); return proxy(*p,0) ; }
85 inline proxy ref(R_xlen_t i) { check_index(i); return proxy(*p,i);}
86
87 inline const_proxy ref() const { check_index(0); return const_proxy(*p,0) ; }
88 inline const_proxy ref(R_xlen_t i) const { check_index(i); return const_proxy(*p,i);}
89
90 private:
92
93 void check_index(R_xlen_t i) const {
94#ifndef RCPP_NO_BOUNDS_CHECK
95 if (i >= p->size()) {
96 warning("subscript out of bounds (index %s >= vector size %s)", i, p->size()); // #nocov
97 }
98#endif
99 }
100 } ;
101
102 // regular types for INTSXP, REALSXP, ...
103 template <int RTYPE, template <class> class StoragePolicy = PreserveStorage>
107
108 // proxy types for VECSXP, STRSXP and EXPRSXP
109 template <template <class> class StoragePolicy>
110 struct r_vector_cache_type<VECSXP, StoragePolicy> {
112 } ;
113 template <template <class> class StoragePolicy>
114 struct r_vector_cache_type<EXPRSXP, StoragePolicy> {
116 } ;
117 template <template <class> class StoragePolicy>
118 struct r_vector_cache_type<STRSXP, StoragePolicy> {
120 } ;
121
122} // traits
123}
124
125#endif
R_xlen_t size() const
Definition Vector.h:274
r_vector_proxy< RTYPE, StoragePolicy >::type proxy
Definition traits.h:73
iterator get() const
Definition traits.h:81
r_vector_const_proxy< RTYPE, StoragePolicy >::type const_proxy
Definition traits.h:74
::Rcpp::Vector< RTYPE, StoragePolicy > VECTOR
Definition traits.h:70
r_vector_iterator< RTYPE, StoragePolicy >::type iterator
Definition traits.h:71
const_proxy ref(R_xlen_t i) const
Definition traits.h:88
void check_index(R_xlen_t i) const
Definition traits.h:93
r_vector_const_iterator< RTYPE, StoragePolicy >::type const_iterator
Definition traits.h:72
const_proxy ref() const
Definition traits.h:87
const_iterator get_const() const
Definition traits.h:82
proxy ref(R_xlen_t i)
Definition traits.h:85
void update(const VECTOR &v)
Definition traits.h:78
void update(const VECTOR &v)
Definition traits.h:39
const_iterator get_const() const
Definition traits.h:45
proxy ref(R_xlen_t i) const
Definition traits.h:51
r_vector_const_iterator< RTYPE >::type const_iterator
Definition traits.h:32
r_vector_const_proxy< RTYPE >::type const_proxy
Definition traits.h:34
iterator get() const
Definition traits.h:44
storage_type< RTYPE >::type storage_type
Definition traits.h:35
r_vector_iterator< RTYPE >::type iterator
Definition traits.h:31
proxy ref(R_xlen_t i)
Definition traits.h:48
void check_index(R_xlen_t i) const
Definition traits.h:55
::Rcpp::Vector< RTYPE, StoragePolicy > VECTOR
Definition traits.h:30
r_vector_proxy< RTYPE >::type proxy
Definition traits.h:33
traits used to dispatch wrap
Definition Date.h:27
Rcpp API.
Definition algo.h:28
void warning(const std::string &message)
Definition exceptions.h:115
proxy_cache< EXPRSXP, StoragePolicy > type
Definition traits.h:115
proxy_cache< STRSXP, StoragePolicy > type
Definition traits.h:119
proxy_cache< VECSXP, StoragePolicy > type
Definition traits.h:111
r_vector_cache< RTYPE, StoragePolicy > type
Definition traits.h:105
const storage_type< RTYPE >::type * type
Definition proxy.h:254
const storage_type< RTYPE >::type & type
Definition proxy.h:233
storage_type< RTYPE >::type * type
Definition proxy.h:250
storage_type< RTYPE >::type & type
Definition proxy.h:216