Rcpp Version 1.0.14
Loading...
Searching...
No Matches
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
25namespace Rcpp{
26namespace 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), size(0) {} ;
39
40 inline void update( const VECTOR& v ) {
42 size = v.size();
43 }
44
45 inline iterator get() const { return start; }
46 inline const_iterator get_const() const { return start; }
47
48 inline proxy ref() { check_index(0); return start[0] ;}
49 inline proxy ref(R_xlen_t i) { check_index(i); return start[i] ; }
50
51 inline proxy ref() const { check_index(0); return start[0] ;}
52 inline proxy ref(R_xlen_t i) const { check_index(i); return start[i] ; }
53
54 private:
55
56 void check_index(R_xlen_t i) const {
57#ifndef RCPP_NO_BOUNDS_CHECK
58 if (i >= size) {
59 warning("subscript out of bounds (index %s >= vector size %s)", i, size);
60 }
61#endif
62 }
63
66 } ;
67
68 template <int RTYPE, template <class> class StoragePolicy = PreserveStorage>
70 public:
71 typedef typename ::Rcpp::Vector<RTYPE, StoragePolicy> VECTOR ;
76
77 proxy_cache(): p(0){}
79 void update( const VECTOR& v ){
80 p = const_cast<VECTOR*>(&v) ;
81 }
82 inline iterator get() const { return iterator( proxy(*p, 0 ) ) ;}
83 inline const_iterator get_const() const { return const_iterator( const_proxy(*p, 0) ) ; }
84
85 inline proxy ref() { check_index(0); return proxy(*p,0) ; }
86 inline proxy ref(R_xlen_t i) { check_index(i); return proxy(*p,i);}
87
88 inline const_proxy ref() const { check_index(0); return const_proxy(*p,0) ; }
89 inline const_proxy ref(R_xlen_t i) const { check_index(i); return const_proxy(*p,i);}
90
91 private:
93
94 void check_index(R_xlen_t i) const {
95#ifndef RCPP_NO_BOUNDS_CHECK
96 if (i >= p->size()) {
97 warning("subscript out of bounds (index %s >= vector size %s)", i, p->size());
98 }
99#endif
100 }
101 } ;
102
103 // regular types for INTSXP, REALSXP, ...
104 template <int RTYPE, template <class> class StoragePolicy = PreserveStorage>
108
109 // proxy types for VECSXP, STRSXP and EXPRSXP
110 template <template <class> class StoragePolicy>
111 struct r_vector_cache_type<VECSXP, StoragePolicy> {
113 } ;
114 template <template <class> class StoragePolicy>
118 template <template <class> class StoragePolicy>
119 struct r_vector_cache_type<STRSXP, StoragePolicy> {
121 } ;
122
123} // traits
124}
125
126#endif
R_xlen_t size() const
Definition Vector.h:275
r_vector_proxy< RTYPE, StoragePolicy >::type proxy
Definition traits.h:74
iterator get() const
Definition traits.h:82
r_vector_const_proxy< RTYPE, StoragePolicy >::type const_proxy
Definition traits.h:75
::Rcpp::Vector< RTYPE, StoragePolicy > VECTOR
Definition traits.h:71
r_vector_iterator< RTYPE, StoragePolicy >::type iterator
Definition traits.h:72
const_proxy ref(R_xlen_t i) const
Definition traits.h:89
void check_index(R_xlen_t i) const
Definition traits.h:94
r_vector_const_iterator< RTYPE, StoragePolicy >::type const_iterator
Definition traits.h:73
const_proxy ref() const
Definition traits.h:88
const_iterator get_const() const
Definition traits.h:83
proxy ref(R_xlen_t i)
Definition traits.h:86
void update(const VECTOR &v)
Definition traits.h:79
void update(const VECTOR &v)
Definition traits.h:40
const_iterator get_const() const
Definition traits.h:46
proxy ref(R_xlen_t i) const
Definition traits.h:52
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:45
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:49
void check_index(R_xlen_t i) const
Definition traits.h:56
::Rcpp::Vector< RTYPE, StoragePolicy > VECTOR
Definition traits.h:31
r_vector_proxy< RTYPE >::type proxy
Definition traits.h:34
T as(SEXP x, ::Rcpp::traits::r_type_primitive_tag)
Definition as.h:43
Rcpp API.
Definition algo.h:28
T as(SEXP x)
Definition as.h:151
void warning(const std::string &message)
Definition exceptions.h:113
proxy_cache< EXPRSXP, StoragePolicy > type
Definition traits.h:116
proxy_cache< STRSXP, StoragePolicy > type
Definition traits.h:120
proxy_cache< VECSXP, StoragePolicy > type
Definition traits.h:112
r_vector_cache< RTYPE, StoragePolicy > type
Definition traits.h:106
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