Rcpp Version 0.12.12
all.h
Go to the documentation of this file.
1 // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
2 //
3 // all.h: Rcpp R/C++ interface class library -- all
4 //
5 // Copyright (C) 2010 - 2013 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__all_h
23 #define Rcpp__sugar__all_h
24 
25 namespace Rcpp{
26 namespace sugar{
27 
28 template <bool NA, typename T>
29 class All : public SingleLogicalResult< true, All<NA,T> >{
30 public:
33  All( 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 == FALSE ) {
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 
58 
59 template <typename T>
60 class All<false,T> : public SingleLogicalResult< false, All<false,T> >{
61 public:
64  All( const VEC_TYPE& t ) : PARENT() , object(t) {}
65 
66  void apply(){
67  R_xlen_t n = object.size() ;
69  for( R_xlen_t i=0 ; i<n ; i++){
70  if( object[i] == FALSE ) {
72  return ;
73  }
74  }
75  }
76 private:
77  const VEC_TYPE& object ;
78 } ;
79 
80 
81 } // sugar
82 
83 template <bool NA, typename T>
85  return sugar::All<NA,T>( t ) ;
86 }
87 
88 } // Rcpp
89 #endif
90 
Rcpp::VectorBase< LGLSXP, NA, T > VEC_TYPE
Definition: all.h:31
All(const VEC_TYPE &t)
Definition: all.h:64
const VEC_TYPE & object
Definition: all.h:54
All(const VEC_TYPE &t)
Definition: all.h:33
bool is_na< LGLSXP >(int x)
Definition: is_na.h:57
SingleLogicalResult< false, All< false, T > > PARENT
Definition: all.h:63
sugar::All< NA, T > all(const Rcpp::VectorBase< LGLSXP, NA, T > &t)
Definition: all.h:84
const VEC_TYPE & object
Definition: all.h:77
SingleLogicalResult< true, All< NA, T > > PARENT
Definition: all.h:32
Rcpp::VectorBase< LGLSXP, false, T > VEC_TYPE
Definition: all.h:62
void apply()
Definition: all.h:35
Rcpp API.
Definition: algo.h:28