Rcpp Version 1.0.14
Loading...
Searching...
No Matches
Comparator.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_h
23#define Rcpp__sugar__Comparator_h
24
25namespace Rcpp{
26namespace sugar{
27
28template <int RTYPE, typename Operator, bool LHS_NA, typename LHS_T, bool RHS_NA, typename RHS_T>
30 public ::Rcpp::VectorBase< LGLSXP, true, Comparator<RTYPE,Operator,LHS_NA,LHS_T,RHS_NA,RHS_T> > {
31
32public:
36
38 lhs(lhs_), rhs(rhs_), op() {}
39
40 inline int operator[]( R_xlen_t i ) const {
41 STORAGE x = lhs[i] ;
42 if( Rcpp::traits::is_na<RTYPE>( x ) ) return NA_LOGICAL ;
43 STORAGE y = rhs[i] ;
44 if( Rcpp::traits::is_na<RTYPE>( y ) ) return NA_LOGICAL ;
45 return op( x, y ) ;
46 }
47
48 inline R_xlen_t size() const { return lhs.size() ; }
49
50private:
51 const LHS_TYPE& lhs ;
52 const RHS_TYPE& rhs ;
54
55} ;
56
57
58
59template <int RTYPE, typename Operator, typename LHS_T, bool RHS_NA, typename RHS_T>
61 public ::Rcpp::VectorBase< LGLSXP, true, Comparator<RTYPE,Operator,false,LHS_T,RHS_NA,RHS_T> > {
62
63public:
67
69 lhs(lhs_), rhs(rhs_), op() {}
70
71 inline int operator[]( R_xlen_t i ) const {
72 STORAGE y = rhs[i] ;
73 if( Rcpp::traits::is_na<RTYPE>( y ) ) return NA_LOGICAL ;
74 return op( lhs[i], y ) ;
75 }
76
77 inline R_xlen_t size() const { return lhs.size() ; }
78
79private:
80 const LHS_TYPE& lhs ;
81 const RHS_TYPE& rhs ;
83
84} ;
85
86
87template <int RTYPE, typename Operator, typename LHS_T, typename RHS_T>
89 public ::Rcpp::VectorBase< LGLSXP, true, Comparator<RTYPE,Operator,false,LHS_T,false,RHS_T> > {
90
91public:
95
97 lhs(lhs_), rhs(rhs_), op() {}
98
99 inline int operator[]( R_xlen_t i ) const {
100 return op( lhs[i], rhs[i] ) ;
101 }
102
103 inline R_xlen_t size() const { return lhs.size() ; }
104
105private:
106 const LHS_TYPE& lhs ;
107 const RHS_TYPE& rhs ;
109
110} ;
111
112
113}
114}
115
116
117#endif
R_xlen_t size() const
Definition VectorBase.h:49
Comparator(const LHS_TYPE &lhs_, const RHS_TYPE &rhs_)
Definition Comparator.h:96
traits::storage_type< RTYPE >::type STORAGE
Definition Comparator.h:35
Rcpp::VectorBase< RTYPE, LHS_NA, LHS_T > LHS_TYPE
Definition Comparator.h:33
R_xlen_t size() const
Definition Comparator.h:48
Comparator(const LHS_TYPE &lhs_, const RHS_TYPE &rhs_)
Definition Comparator.h:37
const RHS_TYPE & rhs
Definition Comparator.h:52
const LHS_TYPE & lhs
Definition Comparator.h:51
int operator[](R_xlen_t i) const
Definition Comparator.h:40
Rcpp::VectorBase< RTYPE, RHS_NA, RHS_T > RHS_TYPE
Definition Comparator.h:34
Rcpp API.
Definition algo.h:28
T as(SEXP x)
Definition as.h:151