Rcpp Version 1.0.7
no_init.h
Go to the documentation of this file.
1 // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2 //
3 // Vector.h: Rcpp R/C++ interface class library -- vectors
4 //
5 // Copyright (C) 2010 - 2017 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__vector__no_init_h
23 #define Rcpp__vector__no_init_h
24 
25 namespace Rcpp{
26 
27 template <int RTYPE, template <class> class StoragePolicy>
28 class Matrix;
29 
31 public:
32  no_init_vector(R_xlen_t size_): size(size_){}
33 
34  inline R_xlen_t get() const {
35  return size;
36  }
37 
38  template <int RTYPE, template <class> class StoragePolicy >
39  operator Vector<RTYPE, StoragePolicy>() const {
40  // Explicitly protect temporary vector to avoid false positive
41  // with rchk (#892)
42  Shield<SEXP> x(Rf_allocVector(RTYPE, size));
44  return ret;
45  }
46 
47 private:
48  R_xlen_t size ;
49 } ;
50 
52 public:
53  no_init_matrix(int nr_, int nc_): nr(nr_), nc(nc_) {}
54 
55  inline int nrow() const {
56  return nr;
57  }
58 
59  inline int ncol() const {
60  return nc;
61  }
62 
63  template <int RTYPE, template <class> class StoragePolicy >
64  operator Matrix<RTYPE, StoragePolicy>() const {
65  // Explicitly protect temporary matrix to avoid false positive
66  // with rchk (#892)
67  Shield<SEXP> x(Rf_allocMatrix(RTYPE, nr, nc));
69  return ret;
70  }
71 
72 private:
73  int nr;
74  int nc;
75 } ;
76 
77 inline no_init_vector no_init(R_xlen_t size) {
78  return no_init_vector(size);
79 }
80 
81 inline no_init_matrix no_init(int nr, int nc) {
82  return no_init_matrix(nr, nc);
83 }
84 
85 
86 }
87 #endif
Rcpp::Matrix
Definition: Matrix.h:28
Rcpp::no_init
no_init_vector no_init(R_xlen_t size)
Definition: no_init.h:77
Rcpp::no_init_vector::get
R_xlen_t get() const
Definition: no_init.h:34
Rcpp::no_init_vector::no_init_vector
no_init_vector(R_xlen_t size_)
Definition: no_init.h:32
Rcpp::no_init_matrix::nr
int nr
Definition: no_init.h:73
Rcpp::Shield
Definition: Shield.h:35
Rcpp
Rcpp API.
Definition: algo.h:28
Rcpp::Vector
Definition: 00_forward_Vector.h:26
Rcpp::no_init_matrix::no_init_matrix
no_init_matrix(int nr_, int nc_)
Definition: no_init.h:53
Rcpp::no_init_matrix::nc
int nc
Definition: no_init.h:74
Rcpp::no_init_matrix
Definition: no_init.h:51
Rcpp::no_init_vector::size
R_xlen_t size
Definition: no_init.h:48
Rcpp::no_init_vector
Definition: no_init.h:30
Rcpp::no_init_matrix::ncol
int ncol() const
Definition: no_init.h:59
Rcpp::no_init_matrix::nrow
int nrow() const
Definition: no_init.h:55