Rcpp Version 1.0.14
Loading...
Searching...
No Matches
named_object.h
Go to the documentation of this file.
1
2// named_object.h: Rcpp R/C++ interface class library -- named SEXP
3//
4// Copyright (C) 2010 - 2020 Dirk Eddelbuettel and Romain Francois
5// Copyright (C) 2021 Dirk Eddelbuettel, Romain Francois and IƱaki Ucar
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__traits__named_object__h
23#define Rcpp__traits__named_object__h
24
25#include <type_traits>
26
27namespace Rcpp{
28class Argument ;
29
30namespace traits{
31
32template <typename T> struct needs_protection : false_type{} ;
33template <> struct needs_protection<SEXP> : true_type{} ;
34
35template <typename T> class named_object {
36public:
37 named_object( const std::string& name_, const T& o_) :
38 name(name_), object(o_){}
39 const std::string& name;
40 const T& object;
41};
42template <> class named_object<SEXP> {
43public: // #nocov start
44 named_object( const std::string& name_, const SEXP& o_):
45 name(name_), object(o_), token(R_NilValue) {
46 token = Rcpp_PreciousPreserve(object);
47 }
48
50 name(other.name), object(other.object), token(other.token) {
51 token = Rcpp_PreciousPreserve(object);
52 }
55
56 } // #nocov end
57 const std::string& name;
59private:
61};
62
63
64template <typename T> struct is_named : public false_type{};
65template <typename T> struct is_named< named_object<T> > : public true_type {};
66template <> struct is_named< Rcpp::Argument > : public true_type {};
67
68
69#if defined(HAS_VARIADIC_TEMPLATES)
70 template <typename... T> struct is_any_named : public false_type {};
71 template <typename T> struct is_any_named<T> : public is_named<T>::type {};
72
73 template <typename T, typename... TArgs>
74 struct is_any_named<T, TArgs...>
75 : public std::conditional<
76 is_any_named<T>::value,
77 std::true_type,
78 is_any_named<TArgs...>>::type {};
79#endif
80
81} // namespace traits
82} // namespace Rcpp
83
84#endif
named_object(const named_object< SEXP > &other)
named_object(const std::string &name_, const SEXP &o_)
named_object(const std::string &name_, const T &o_)
const std::string & name
Rcpp API.
Definition algo.h:28
SEXP Rcpp_PreciousPreserve(SEXP object)
Definition RcppCommon.h:117
void Rcpp_PreciousRelease(SEXP token)
Definition RcppCommon.h:121
T as(SEXP x)
Definition as.h:151