Rcpp Version 1.1.2
Loading...
Searching...
No Matches
NamesProxy.h
Go to the documentation of this file.
1// Copyright (C) 2013 - 2025 Romain François
2// Copyright (C) 2026 Romain François, Iñaki Ucar and Dirk Eddelbuettel
3//
4// This file is part of Rcpp.
5//
6// Rcpp is free software: you can redistribute it and/or modify it
7// under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 2 of the License, or
9// (at your option) any later version.
10//
11// Rcpp is distributed in the hope that it will be useful, but
12// WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
18
19#ifndef Rcpp_proxy_NamesProxy_h
20#define Rcpp_proxy_NamesProxy_h
21
22namespace Rcpp{
23
24template <typename CLASS>
26public:
27
28 class NamesProxy : public GenericProxy<NamesProxy> {
29 public:
30 NamesProxy( CLASS& v) : parent(v){} ;
31
32 /* lvalue uses */
34 if( this != &rhs) set( rhs.get() ) ;
35 return *this ;
36 }
37
38 template <typename T>
39 NamesProxy& operator=(const T& rhs);
40
41 template <typename T> operator T() const;
42
43 private:
44 CLASS& parent;
45
46 SEXP get() const {
47 return RCPP_GET_NAMES(parent) ;
48 }
49
50 void set(SEXP x) {
51 if (!Rf_isNull(x))
52 Rf_namesgets(parent, x);
53 else Rf_setAttrib(parent, R_NamesSymbol, x);
54 }
55
56 } ;
57
58 class const_NamesProxy : public GenericProxy<const_NamesProxy>{
59 public:
60 const_NamesProxy( const CLASS& v) : parent(v){} ;
61
62 template <typename T> operator T() const;
63
64 private:
65 const CLASS& parent;
66
67 SEXP get() const {
68 return RCPP_GET_NAMES(parent) ;
69 }
70
71 } ;
72
74 return NamesProxy( static_cast<CLASS&>(*this) ) ;
75 }
76
78 return const_NamesProxy(static_cast<const CLASS&>(*this) ) ;
79 }
80
81
82} ;
83
84}
85
86#endif
NamesProxy & operator=(const NamesProxy &rhs)
Definition NamesProxy.h:33
NamesProxy & operator=(const T &rhs)
const_NamesProxy names() const
Definition NamesProxy.h:77
#define RCPP_GET_NAMES(x)
Definition macros.h:45
Rcpp API.
Definition algo.h:28