Rcpp Version 0.12.12
any.h
Go to the documentation of this file.
1 // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
2 //
3 // any.h: Rcpp R/C++ interface class library -- any
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__any_h
23 #define Rcpp__sugar__any_h
24 
25 namespace Rcpp{
26 namespace sugar{
27 
28 template <bool NA, typename T>
29 class Any : public SingleLogicalResult< true, Any<NA,T> >{
30 public:
33  Any( const VEC_TYPE& t ) : PARENT() , object(t) {}
34 
35  void apply(){
36  R_xlen_t n = object.size() ;
37  int current = 0 ;
38  PARENT::reset() ;
39  for( R_xlen_t i=0 ; i<n ; i++){
40  current = object[i] ;
41  if( current == TRUE ) {
43  return ;
44  }
45  if( Rcpp::traits::is_na<LGLSXP>(current) ) {
47  }
48  }
49  if( PARENT::is_unresolved() ){
51  }
52  }
53 private:
54  const VEC_TYPE& object ;
55 } ;
56 
57 template <typename T>
58 class Any<false,T> : public SingleLogicalResult< false, Any<false,T> >{
59 public:
62  Any( const VEC_TYPE& t ) : PARENT() , object(t) {}
63 
64  void apply(){
65  R_xlen_t n = object.size() ;
67  for( R_xlen_t i=0 ; i<n ; i++){
68  if( object[i] == TRUE ) {
70  return ;
71  }
72  }
73  }
74 private:
75  const VEC_TYPE& object ;
76 } ;
77 
78 } // sugar
79 
80 template <bool NA, typename T>
82  return sugar::Any<NA,T>( t ) ;
83 }
84 
85 } // Rcpp
86 #endif
87 
Any(const VEC_TYPE &t)
Definition: any.h:33
const VEC_TYPE & object
Definition: any.h:75
SingleLogicalResult< true, Any< NA, T > > PARENT
Definition: any.h:32
void apply()
Definition: any.h:35
bool is_na< LGLSXP >(int x)
Definition: is_na.h:57
bool any(InputIterator first, InputIterator last, const T &value)
Definition: algo.h:89
Rcpp::VectorBase< LGLSXP, NA, T > VEC_TYPE
Definition: any.h:31
Any(const VEC_TYPE &t)
Definition: any.h:62
Rcpp::VectorBase< LGLSXP, false, T > VEC_TYPE
Definition: any.h:60
Rcpp API.
Definition: algo.h:28
const VEC_TYPE & object
Definition: any.h:54
SingleLogicalResult< false, Any< false, T > > PARENT
Definition: any.h:61