Rcpp Version 1.0.14
Loading...
Searching...
No Matches
or.h
Go to the documentation of this file.
1// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
2//
3// or.h: Rcpp R/C++ interface class library --
4//
5// Copyright (C) 2010 - 2012 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__logical_or_h
23#define Rcpp__sugar__logical_or_h
24
25namespace Rcpp{
26namespace sugar{
27
28template <bool LHS_NA, typename LHS_T, bool RHS_NA, typename RHS_T>
31 (LHS_NA || RHS_NA) ,
32 Or_SingleLogicalResult_SingleLogicalResult<LHS_NA,LHS_T,RHS_NA,RHS_T>
33 >
34{
35public:
38 typedef SingleLogicalResult<
39 (LHS_NA || RHS_NA) ,
41 > BASE ;
42
45
46 inline void apply(){
47 int left = lhs.get() ;
49 BASE::set( left ) ;
50 } else if( left == TRUE ){
51 BASE::set( TRUE ) ;
52 } else {
53 BASE::set( rhs.get() ) ;
54 }
55 }
56
57private:
58 const LHS_TYPE& lhs ;
59 const RHS_TYPE& rhs ;
60
61} ;
62
63// special version when we know the rhs is not NA
64template <bool LHS_NA, typename LHS_T, typename RHS_T>
67 LHS_NA ,
68 Or_SingleLogicalResult_SingleLogicalResult<LHS_NA,LHS_T,false,RHS_T>
69 >
70{
71public:
74 typedef SingleLogicalResult<
75 LHS_NA,
77 > BASE ;
78
81
82 inline void apply(){
83 // here we know rhs does not have NA, so we start with the rhs
84 int right = rhs.get() ;
85 if( right == TRUE ){
86 BASE::set( TRUE ) ;
87 } else {
88 BASE::set( lhs.get() ) ;
89 }
90 }
91
92private:
93 const LHS_TYPE& lhs ;
94 const RHS_TYPE& rhs ;
95
96} ;
97
98
99// special version when we know the lhs is not NA
100template <typename LHS_T, bool RHS_NA, typename RHS_T>
103 RHS_NA ,
104 Or_SingleLogicalResult_SingleLogicalResult<false,LHS_T,RHS_NA,RHS_T>
105 >
106{
107public:
110 typedef SingleLogicalResult<
111 RHS_NA,
114
117
118 inline void apply(){
119 // here we know lhs does not have NA, so we start with the rhs
120 int left = lhs.get() ;
121 if( left == TRUE ){
122 BASE::set( TRUE ) ;
123 } else {
124 BASE::set( rhs.get() ) ;
125 }
126 }
127
128private:
129 const LHS_TYPE& lhs ;
130 const RHS_TYPE& rhs ;
131
132} ;
133
134// special version when we know both the lhs and the rhs are not NA
135template <typename LHS_T, typename RHS_T>
138 false ,
139 Or_SingleLogicalResult_SingleLogicalResult<false,LHS_T,false,RHS_T>
140 >
141{
142public:
145 typedef SingleLogicalResult<
146 false,
149
152
153 inline void apply(){
154 int left = lhs.get() ;
155 if( left == TRUE ){
156 BASE::set( TRUE ) ;
157 } else {
158 BASE::set( rhs.get() ) ;
159 }
160 }
161
162private:
163 const LHS_TYPE& lhs ;
164 const RHS_TYPE& rhs ;
165
166} ;
167
168
169template <bool LHS_NA, typename LHS_T>
172 LHS_NA ,
173 And_SingleLogicalResult_bool<LHS_NA,LHS_T>
174 >
175{
176public:
178 typedef SingleLogicalResult<
179 LHS_NA ,
182
185
186 inline void apply(){
187 if( rhs ){
188 BASE::set( TRUE ) ;
189 } else{
190 BASE::set( lhs.get() ) ;
191 }
192 }
193
194private:
195 const LHS_TYPE& lhs ;
196 bool rhs ;
197
198} ;
199
200// (LogicalExpression) | (LogicalExpression)
201template <bool LHS_NA, typename LHS_T, bool RHS_NA, typename RHS_T>
202class Or_LogicalExpression_LogicalExpression : public Rcpp::VectorBase< LGLSXP, true, Or_LogicalExpression_LogicalExpression<LHS_NA,LHS_T,RHS_NA,RHS_T> >{
203public:
206
208
209 inline int operator[]( R_xlen_t i ) const{
210 if( lhs[i] == TRUE || rhs[i] == TRUE ) return TRUE ;
211 if( lhs[i] == FALSE && rhs[i] == FALSE ) return FALSE ;
212 return NA_LOGICAL;
213 }
214 inline R_xlen_t size() const { return lhs.size(); }
215
216private:
217 const LHS_TYPE& lhs ;
218 const RHS_TYPE& rhs ;
219} ;
220template <typename LHS_T, bool RHS_NA, typename RHS_T>
222 : public Rcpp::VectorBase< LGLSXP, true, Or_LogicalExpression_LogicalExpression<false,LHS_T,RHS_NA,RHS_T> >{
223public:
226
228
229 inline int operator[]( R_xlen_t i ) const{
230 if( lhs[i] == TRUE || rhs[i] == TRUE ) return TRUE ;
231 if( rhs[i] == NA_LOGICAL ) return NA_LOGICAL ;
232 return FALSE ;
233 }
234 inline R_xlen_t size() const { return lhs.size(); }
235
236private:
237 const LHS_TYPE& lhs ;
238 const RHS_TYPE& rhs ;
239} ;
240template <bool LHS_NA, typename LHS_T, typename RHS_T>
242 : public Rcpp::VectorBase< LGLSXP, true, Or_LogicalExpression_LogicalExpression<LHS_NA,LHS_T,false,RHS_T> >{
243public:
246
248
249 inline int operator[]( R_xlen_t i ) const{
250 if( lhs[i] == TRUE || rhs[i] == TRUE ) return TRUE ;
251 if( lhs[i] == NA_LOGICAL ) return NA_LOGICAL ;
252 return FALSE;
253 }
254 inline R_xlen_t size() const { return lhs.size(); }
255
256private:
257 const LHS_TYPE& lhs ;
258 const RHS_TYPE& rhs ;
259} ;
260template <typename LHS_T, typename RHS_T>
262 : public Rcpp::VectorBase< LGLSXP, false, Or_LogicalExpression_LogicalExpression<false,LHS_T,false,RHS_T> >{
263public:
266
268
269 inline int operator[]( R_xlen_t i ) const{
270 if( lhs[i] == TRUE || rhs[i] == TRUE ) return TRUE ;
271 return FALSE;
272 }
273 inline R_xlen_t size() const { return lhs.size(); }
274
275private:
276 const LHS_TYPE& lhs ;
277 const RHS_TYPE& rhs ;
278} ;
279
280
281
282} // sugar
283} // Rcpp
284
285template <bool LHS_NA, typename LHS_T, bool RHS_NA, typename RHS_T>
293
294template <bool LHS_NA, typename LHS_T>
302
303template <bool LHS_NA, typename LHS_T>
311
312// (logical expression) | (logical expression)
313template <bool LHS_NA, typename LHS_T, bool RHS_NA, typename RHS_T>
321
322
323#endif
R_xlen_t size() const
Definition VectorBase.h:49
Or_LogicalExpression_LogicalExpression(const LHS_TYPE &lhs_, const RHS_TYPE &rhs_)
Definition or.h:247
Or_LogicalExpression_LogicalExpression(const LHS_TYPE &lhs_, const RHS_TYPE &rhs_)
Definition or.h:227
Or_LogicalExpression_LogicalExpression(const LHS_TYPE &lhs_, const RHS_TYPE &rhs_)
Definition or.h:267
Rcpp::VectorBase< LGLSXP, RHS_NA, RHS_T > RHS_TYPE
Definition or.h:205
Or_LogicalExpression_LogicalExpression(const LHS_TYPE &lhs_, const RHS_TYPE &rhs_)
Definition or.h:207
Rcpp::VectorBase< LGLSXP, LHS_NA, LHS_T > LHS_TYPE
Definition or.h:204
Or_SingleLogicalResult_SingleLogicalResult(const LHS_TYPE &lhs_, const RHS_TYPE &rhs_)
Definition or.h:79
SingleLogicalResult< LHS_NA, Or_SingleLogicalResult_SingleLogicalResult< LHS_NA, LHS_T, false, RHS_T > > BASE
Definition or.h:77
Or_SingleLogicalResult_SingleLogicalResult(const LHS_TYPE &lhs_, const RHS_TYPE &rhs_)
Definition or.h:115
SingleLogicalResult< RHS_NA, Or_SingleLogicalResult_SingleLogicalResult< false, LHS_T, RHS_NA, RHS_T > > BASE
Definition or.h:113
SingleLogicalResult< false, Or_SingleLogicalResult_SingleLogicalResult< false, LHS_T, false, RHS_T > > BASE
Definition or.h:148
Or_SingleLogicalResult_SingleLogicalResult(const LHS_TYPE &lhs_, const RHS_TYPE &rhs_)
Definition or.h:150
SingleLogicalResult< LHS_NA, LHS_T > LHS_TYPE
Definition or.h:36
SingleLogicalResult< RHS_NA, RHS_T > RHS_TYPE
Definition or.h:37
Or_SingleLogicalResult_SingleLogicalResult(const LHS_TYPE &lhs_, const RHS_TYPE &rhs_)
Definition or.h:43
Or_SingleLogicalResult_bool(const LHS_TYPE &lhs_, bool rhs_)
Definition or.h:183
SingleLogicalResult< LHS_NA, LHS_T > LHS_TYPE
Definition or.h:177
SingleLogicalResult< LHS_NA, Or_SingleLogicalResult_bool< LHS_NA, LHS_T > > BASE
Definition or.h:181
bool is_na< LGLSXP >(int x)
Definition is_na.h:57
Rcpp API.
Definition algo.h:28
T as(SEXP x)
Definition as.h:151
Rcpp::sugar::Or_LogicalExpression_LogicalExpression< LHS_NA, LHS_T, RHS_NA, RHS_T > operator|(const Rcpp::VectorBase< LGLSXP, LHS_NA, LHS_T > &lhs, const Rcpp::VectorBase< LGLSXP, RHS_NA, RHS_T > &rhs)
Definition or.h:315
Rcpp::sugar::Or_SingleLogicalResult_SingleLogicalResult< LHS_NA, LHS_T, RHS_NA, RHS_T > operator||(const Rcpp::sugar::SingleLogicalResult< LHS_NA, LHS_T > &lhs, const Rcpp::sugar::SingleLogicalResult< LHS_NA, LHS_T > &rhs)
Definition or.h:287