Rcpp Version 0.12.12
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  return Rf_allocVector(RTYPE, size) ;
41  }
42 
43 private:
44  R_xlen_t size ;
45 } ;
46 
48 public:
49  no_init_matrix(int nr_, int nc_): nr(nr_), nc(nc_) {}
50 
51  inline int nrow() const {
52  return nr;
53  }
54 
55  inline int ncol() const {
56  return nc;
57  }
58 
59  template <int RTYPE, template <class> class StoragePolicy >
60  operator Matrix<RTYPE, StoragePolicy>() const {
61  return Rf_allocMatrix(RTYPE, nr, nc);
62  }
63 
64 private:
65  int nr;
66  int nc;
67 } ;
68 
69 inline no_init_vector no_init(R_xlen_t size) {
70  return no_init_vector(size);
71 }
72 
73 inline no_init_matrix no_init(int nr, int nc) {
74  return no_init_matrix(nr, nc);
75 }
76 
77 
78 }
79 #endif
no_init_matrix(int nr_, int nc_)
Definition: no_init.h:49
int nrow() const
Definition: no_init.h:51
no_init_vector no_init(R_xlen_t size)
Definition: no_init.h:69
no_init_vector(R_xlen_t size_)
Definition: no_init.h:32
Rcpp API.
Definition: algo.h:28
int ncol() const
Definition: no_init.h:55