Rcpp Version 1.0.14
Loading...
Searching...
No Matches
Comparator_With_One_Value.h
Go to the documentation of this file.
1// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
2//
3// LessThan.h: Rcpp R/C++ interface class library -- vector operators
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__sugar__Comparator_With_One_Value_h
23#define Rcpp__sugar__Comparator_With_One_Value_h
24
25namespace Rcpp{
26namespace sugar{
27
28template <int RTYPE, typename Operator, bool NA, typename T>
29class Comparator_With_One_Value : public ::Rcpp::VectorBase< LGLSXP, true, Comparator_With_One_Value<RTYPE,Operator,NA,T> > {
30public:
34
36 lhs(lhs_), rhs(rhs_), m(), op() {
37
38 m = Rcpp::traits::is_na<RTYPE>(rhs) ?
41
42 }
43
44 inline int operator[]( R_xlen_t i ) const {
45 return (this->*m)(i) ;
46 }
47
48 inline R_xlen_t size() const { return lhs.size() ; }
49
50private:
51 const VEC_TYPE& lhs ;
55
56 inline int rhs_is_na(int i) const { return rhs ; }
57 inline int rhs_is_not_na(int i) const {
58 STORAGE x = lhs[i] ;
59 return Rcpp::traits::is_na<RTYPE>(x) ? x : op( x, rhs ) ;
60 }
61
62} ;
63
64
65template <int RTYPE, typename Operator, typename T>
67 public ::Rcpp::VectorBase< RTYPE, true, Comparator_With_One_Value<LGLSXP,Operator,false,T> > {
68
69public:
73
75 lhs(lhs_), rhs(rhs_), m(), op() {
76
77 m = Rcpp::traits::is_na<RTYPE>(rhs) ?
80
81 }
82
83 inline int operator[]( R_xlen_t i ) const {
84 return (this->*m)(i) ;
85 }
86
87 inline R_xlen_t size() const { return lhs.size() ; }
88
89private:
90 const VEC_TYPE& lhs ;
94
95 inline int rhs_is_na(int i) const { return rhs ; }
96 inline int rhs_is_not_na(int i) const {
97 return op( lhs[i], rhs ) ;
98 }
99
100} ;
101
102
103} // sugar
104} // Rcpp
105
106
107
108
109
110#endif
R_xlen_t size() const
Definition VectorBase.h:49
Rcpp::VectorBase< RTYPE, NA, T > VEC_TYPE
traits::storage_type< RTYPE >::type STORAGE
Comparator_With_One_Value(const VEC_TYPE &lhs_, STORAGE rhs_)
int(Comparator_With_One_Value::* METHOD)(int) const
Rcpp API.
Definition algo.h:28
T as(SEXP x)
Definition as.h:151