Rcpp Version 1.0.7
nona.h
Go to the documentation of this file.
1 // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 4 -*-
2 //
3 // nona.h: Rcpp R/C++ interface class library -- noNA handling
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_NONA_NONA_H
23 #define RCPP_SUGAR_NONA_NONA_H
24 
25 namespace Rcpp{
26 namespace sugar {
27 
28  template <int RTYPE, bool NA, typename VECTOR>
29  class Nona : public Rcpp::VectorBase<RTYPE,false, Nona<RTYPE,NA,VECTOR> > {
30  public:
33 
34  Nona( const SUGAR_TYPE& expr) : data(expr.get_ref()){}
35 
36  inline R_xlen_t size() const { return data.size() ; }
37  inline STORAGE operator[](R_xlen_t i) const { return data[i] ; }
38 
39  private:
40  const VECTOR& data ;
41  } ;
42 
43  // specialization when the expression is actually a vector expression
44  template <int RTYPE, bool NA>
45  class Nona< RTYPE,NA,Rcpp::Vector<RTYPE> > : public Rcpp::VectorBase<RTYPE,false, Nona<RTYPE,NA,Rcpp::Vector<RTYPE> > > {
46  public:
50 
51  Nona( const SUGAR_TYPE& expr) : data(expr.get_ref().begin()), n(expr.size()){}
52 
53  inline R_xlen_t size() const { return n ; }
54  inline STORAGE operator[](R_xlen_t i) const { return data[i] ; }
55 
56  private:
58  R_xlen_t n ;
59  } ;
60 
61  template <typename T>
62  class NonaPrimitive {
63  public:
64  NonaPrimitive( T t) : x(t){}
65  inline operator T(){ return x ; }
66 
67  private:
68  T x ;
69  } ;
70 
71 }
72 
73 template <int RTYPE, bool NA, typename VECTOR>
75  return sugar::Nona<RTYPE,NA,VECTOR>( vec ) ;
76 }
77 
79  return sugar::NonaPrimitive<double>( x ) ;
80 }
82  return sugar::NonaPrimitive<int>( x ) ;
83 }
84 
85 
86 }
87 
88 #endif
Rcpp::sugar::Nona
Definition: nona.h:29
Rcpp::sugar::Nona::SUGAR_TYPE
Rcpp::VectorBase< RTYPE, NA, VECTOR > SUGAR_TYPE
Definition: nona.h:31
Rcpp::sugar::Nona< RTYPE, NA, Rcpp::Vector< RTYPE > >::STORAGE
Rcpp::traits::storage_type< RTYPE >::type STORAGE
Definition: nona.h:48
Rcpp::sugar::Nona< RTYPE, NA, Rcpp::Vector< RTYPE > >::SUGAR_TYPE
Rcpp::VectorBase< RTYPE, NA, Rcpp::Vector< RTYPE > > SUGAR_TYPE
Definition: nona.h:47
Rcpp::sugar::Nona::data
const VECTOR & data
Definition: nona.h:40
Rcpp::sugar::NonaPrimitive::NonaPrimitive
NonaPrimitive(T t)
Definition: nona.h:64
Rcpp::noNA
sugar::Nona< RTYPE, NA, VECTOR > noNA(const Rcpp::VectorBase< RTYPE, NA, VECTOR > &vec)
Definition: nona.h:74
Rcpp::sugar::Nona< RTYPE, NA, Rcpp::Vector< RTYPE > >::n
R_xlen_t n
Definition: nona.h:58
Rcpp::VectorBase< RTYPE, false, Nona< RTYPE, NA, VECTOR > >::get_ref
Nona< RTYPE, NA, VECTOR > & get_ref()
Definition: VectorBase.h:37
Rcpp::Vector::const_iterator
traits::r_vector_const_iterator< RTYPE, StoragePolicy >::type const_iterator
Definition: Vector.h:47
Rcpp::sugar::Nona< RTYPE, NA, Rcpp::Vector< RTYPE > >::iterator
Rcpp::Vector< RTYPE >::const_iterator iterator
Definition: nona.h:49
Rcpp
Rcpp API.
Definition: algo.h:28
Rcpp::sugar::Nona< RTYPE, NA, Rcpp::Vector< RTYPE > >::size
R_xlen_t size() const
Definition: nona.h:53
Rcpp::NA
static Na_Proxy NA
Definition: Na_Proxy.h:52
Rcpp::Vector
Definition: 00_forward_Vector.h:26
Rcpp::sugar::NonaPrimitive::x
T x
Definition: nona.h:68
Rcpp::sugar::Nona< RTYPE, NA, Rcpp::Vector< RTYPE > >::data
iterator data
Definition: nona.h:57
Rcpp::sugar::Nona::operator[]
STORAGE operator[](R_xlen_t i) const
Definition: nona.h:37
Rcpp::sugar::NonaPrimitive
Definition: nona.h:62
Rcpp::VectorBase< RTYPE, false, Nona< RTYPE, NA, VECTOR > >::begin
const_iterator begin() const
Definition: VectorBase.h:164
Rcpp::sugar::Nona< RTYPE, NA, Rcpp::Vector< RTYPE > >::Nona
Nona(const SUGAR_TYPE &expr)
Definition: nona.h:51
Rcpp::sugar::Nona::size
R_xlen_t size() const
Definition: nona.h:36
Rcpp::sugar::Nona::STORAGE
Rcpp::traits::storage_type< RTYPE >::type STORAGE
Definition: nona.h:32
Rcpp::traits::storage_type::type
SEXP type
Definition: storage_type.h:36
Rcpp::sugar::Nona< RTYPE, NA, Rcpp::Vector< RTYPE > >::operator[]
STORAGE operator[](R_xlen_t i) const
Definition: nona.h:54
Rcpp::sugar::Nona::Nona
Nona(const SUGAR_TYPE &expr)
Definition: nona.h:34
Rcpp::VectorBase
Definition: VectorBase.h:29