Rcpp Version 1.0.14
Loading...
Searching...
No Matches
DimNameProxy.h
Go to the documentation of this file.
1// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
2//
3// DimNameProxy.h: Rcpp R/C++ interface class library -- dimension name proxy
4//
5// Copyright (C) 2010 - 2014 Dirk Eddelbuettel, Romain Francois and Kevin Ushey
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_DimNameProxy_h
23#define Rcpp_vector_DimNameProxy_h
24
25namespace Rcpp{
26namespace internal{
27
29
30 public:
31
32 DimNameProxy(SEXP data, int dim): data_(data), dim_(dim) {}
35
37 if (Rf_length(other) == 0)
38 {
40 } else {
42 if (INTEGER(dims)[dim_] != Rf_length(other)) {
43 stop("dimension extent is '%d' while length of names is '%d'", INTEGER(dims)[dim_], Rf_length(other));
44 }
45
47 if (Rf_isNull(dimnames)) {
51 } else {
53 }
54 }
55 return *this;
56 }
57
59 return assign(other);
60 }
61
63 return assign(SEXP(other));
64 }
65
66 inline operator SEXP() const {
69 }
70
71 template <typename T>
72 inline operator T() const {
74 if (Rf_isNull(dimnames)) {
75 return T();
76 } else {
77 return T(VECTOR_ELT(dimnames, dim_));
78 }
79 }
80
81 private:
82
84 int dim_;
85 };
86
87}
88
89}
90
91#endif
DimNameProxy(SEXP data, int dim)
DimNameProxy(DimNameProxy const &other)
DimNameProxy & assign(SEXP other)
DimNameProxy & operator=(SEXP other)
DimNameProxy & operator=(const DimNameProxy &other)
T as(SEXP x, ::Rcpp::traits::r_type_primitive_tag)
Definition as.h:43
Rcpp API.
Definition algo.h:28
void NORET stop(const std::string &message)
Definition exceptions.h:117