Rcpp Version 1.0.14
Loading...
Searching...
No Matches
RangeIndexer.h
Go to the documentation of this file.
1// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
2//
3// RangeIndexer.h: Rcpp R/C++ interface class library --
4//
5// Copyright (C) 2010 - 2011 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__RangeIndexer_h
23#define Rcpp__vector__RangeIndexer_h
24
25#define UNROLL_LOOP(OP) \
26 typedef typename ::Rcpp::traits::Extractor<RTYPE,NA,T>::type EXT ; \
27 const EXT& input( x.get_ref() ) ; \
28 int __trip_count = (size_) >> 2; \
29 int i=0 ; \
30 for ( ; __trip_count > 0 ; --__trip_count) { \
31 start[i] OP input[i] ; i++ ; \
32 start[i] OP input[i] ; i++ ; \
33 start[i] OP input[i] ; i++ ; \
34 start[i] OP input[i] ; i++ ; \
35 } \
36 switch (size_ - i){ \
37 case 3: \
38 start[i] OP input[i] ; i++ ; \
39 case 2: \
40 start[i] OP input[i] ; i++ ; \
41 case 1: \
42 start[i] OP input[i] ; i++ ; \
43 case 0: \
44 default: \
45 return *this ; \
46 }
47
48
49namespace Rcpp{
50namespace internal{
51
52template <int RTYPE, bool NA, typename VECTOR>
53class RangeIndexer : public VectorBase<RTYPE, NA, RangeIndexer<RTYPE,NA,VECTOR> > {
54public:
55 typedef typename VECTOR::Proxy Proxy ;
56 typedef typename VECTOR::iterator iterator ;
57
58 RangeIndexer( VECTOR& vec_, const Rcpp::Range& range_) :
59 start(vec_.begin() + range_.get_start() ), size_( range_.size() ) {}
60
61 template <bool NA_, typename T>
65
66 template <bool NA_, typename T>
70
71 template <bool NA_, typename T>
75
76 template <bool NA_, typename T>
80
81 template <bool NA_, typename T>
85
86 inline Proxy operator[]( R_xlen_t i ) const {
87 return start[i] ;
88 }
89
90 inline R_xlen_t size() const {
91 return size_ ;
92 }
93
94private:
97} ;
98
99}
100}
101
102#undef UNROLL_LOOP
103
104#endif
#define UNROLL_LOOP(OP)
RangeIndexer & operator-=(const Rcpp::VectorBase< RTYPE, NA_, T > &x)
RangeIndexer & operator=(const Rcpp::VectorBase< RTYPE, NA_, T > &x)
RangeIndexer & operator*=(const Rcpp::VectorBase< RTYPE, NA_, T > &x)
RangeIndexer & operator/=(const Rcpp::VectorBase< RTYPE, NA_, T > &x)
RangeIndexer & operator+=(const Rcpp::VectorBase< RTYPE, NA_, T > &x)
RangeIndexer(VECTOR &vec_, const Rcpp::Range &range_)
Proxy operator[](R_xlen_t i) const
T as(SEXP x, ::Rcpp::traits::r_type_primitive_tag)
Definition as.h:43
Rcpp API.
Definition algo.h:28