Rcpp Version 1.0.14
Loading...
Searching...
No Matches
MatrixColumn.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// MatrixColumn.h: Rcpp R/C++ interface class library -- matrices column
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__vector__MatrixColumn_h
23#define Rcpp__vector__MatrixColumn_h
24
25namespace Rcpp{
26
27template <int RTYPE>
28class MatrixColumn : public VectorBase<RTYPE,true,MatrixColumn<RTYPE> > {
29public:
31 typedef typename MATRIX::Proxy Proxy ;
33 typedef typename MATRIX::value_type value_type ;
34 typedef typename MATRIX::iterator iterator ;
36
38 n(parent.nrow()),
41 {
42 if( i < 0 || i >= parent.ncol() ) {
43 const char* fmt = "Column index is out of bounds: "
44 "[index=%i; column extent=%i].";
45 throw index_out_of_bounds(fmt, i, parent.ncol()) ;
46 }
47 }
48
49 MatrixColumn( const MATRIX& parent, int i ) :
50 n(parent.nrow()),
53 {
54 if( i < 0 || i >= parent.ncol() ) {
55 const char* fmt = "Column index is out of bounds: "
56 "[index=%i; column extent=%i].";
57 throw index_out_of_bounds(fmt, i, parent.ncol()) ;
58 }
59 }
60
65
66 template <int RT, bool NA, typename T>
68 const T& ref = rhs.get_ref() ;
70 return *this ;
71 }
72
78
79 inline Proxy operator[]( int i ){
80 return start[i] ;
81 }
82
83 inline const_Proxy operator[]( int i ) const {
84 return const_start[i] ;
85 }
86
87 inline const_iterator begin() const {
88 return const_start ;
89 }
90
91 inline const_iterator end() const {
92 return const_start + n ;
93 }
94
95 inline const_iterator cbegin() const {
96 return const_start ;
97 }
98
99 inline const_iterator cend() const {
100 return const_start + n ;
101 }
102
103 inline iterator begin(){
104 return start ;
105 }
106
107 inline iterator end(){
108 return start + n ;
109 }
110
111 inline int size() const {
112 return n ;
113 }
114
115private:
116 const int n ;
119
120} ;
121
122template <int RTYPE>
123class ConstMatrixColumn : public VectorBase<RTYPE,true,ConstMatrixColumn<RTYPE> > {
124public:
129
130 ConstMatrixColumn( const MATRIX& parent, int i ) :
131 n(parent.nrow()),
133 {
134 if( i < 0 || i >= parent.ncol() ) {
135 const char* fmt = "Column index is out of bounds: "
136 "[index=%i; column extent=%i].";
137 throw index_out_of_bounds(fmt, i, parent.ncol()) ;
138 }
139 }
140
144
145 inline const_Proxy operator[]( int i ) const {
146 return const_start[i] ;
147 }
148
149 inline const_iterator begin() const {
150 return const_start ;
151 }
152
153 inline const_iterator end() const {
154 return const_start + n ;
155 }
156
157 inline const_iterator cbegin() const {
158 return const_start ;
159 }
160
161 inline const_iterator cend() const {
162 return const_start + n ;
163 }
164
165 inline int size() const {
166 return n ;
167 }
168
169private:
170 const int n ;
172
173} ;
174
175}
176#endif
MATRIX::const_iterator const_iterator
const_Proxy operator[](int i) const
const_iterator const_start
const_iterator cend() const
MATRIX::value_type value_type
const_iterator begin() const
const_iterator end() const
const_iterator cbegin() const
ConstMatrixColumn(const MATRIX &parent, int i)
ConstMatrixColumn(const ConstMatrixColumn &other)
Matrix< RTYPE > MATRIX
MATRIX::const_Proxy const_Proxy
const_iterator const_start
Matrix< RTYPE > MATRIX
const_iterator end() const
MatrixColumn(const MATRIX &parent, int i)
const_iterator cend() const
const_Proxy operator[](int i) const
MatrixColumn & operator=(const Rcpp::VectorBase< RT, NA, T > &rhs)
MatrixColumn(MATRIX &parent, int i)
const_iterator cbegin() const
MATRIX::value_type value_type
MATRIX::const_Proxy const_Proxy
MatrixColumn & operator=(const MatrixColumn &rhs)
MATRIX::iterator iterator
MATRIX::Proxy Proxy
const_iterator begin() const
MATRIX::const_iterator const_iterator
MatrixColumn(const MatrixColumn &other)
Proxy operator[](int i)
VECTOR::const_iterator const_iterator
Definition Matrix.h:45
VECTOR::Proxy Proxy
Definition Matrix.h:48
VECTOR::const_Proxy const_Proxy
Definition Matrix.h:49
VECTOR::iterator iterator
Definition Matrix.h:44
VECTOR & get_ref()
Definition VectorBase.h:37
traits::r_vector_proxy< RTYPE, StoragePolicy >::type value_type
Definition Vector.h:44
Rcpp API.
Definition algo.h:28
Environment_Impl parent() const
T as(SEXP x)
Definition as.h:151
#define RCPP_LOOP_UNROLL(TARGET, SOURCE)
Definition unroll.h:47