Rcpp Version 1.0.7
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 namespace Rcpp{
26 class Argument ;
27 
28 namespace traits{
29 
30 template <typename T> struct needs_protection : false_type{} ;
31 template <> struct needs_protection<SEXP> : true_type{} ;
32 
33 template <typename T> class named_object {
34 public:
35  named_object( const std::string& name_, const T& o_) :
36  name(name_), object(o_){}
37  const std::string& name;
38  const T& object;
39 };
40 template <> class named_object<SEXP> {
41 public: // #nocov start
42  named_object( const std::string& name_, const SEXP& o_):
43  name(name_), object(o_), token(R_NilValue) {
44  token = Rcpp_PreciousPreserve(object);
45  }
46 
47  named_object( const named_object<SEXP>& other ) :
48  name(other.name), object(other.object), token(other.token) {
49  token = Rcpp_PreciousPreserve(object);
50  }
52  Rcpp_PreciousRelease(token);
53 
54  } // #nocov end
55  const std::string& name;
56  SEXP object;
57 private:
58  SEXP token;
59 };
60 
61 
62 template <typename T> struct is_named : public false_type{};
63 template <typename T> struct is_named< named_object<T> > : public true_type {};
64 template <> struct is_named< Rcpp::Argument > : public true_type {};
65 
66 } // namespace traits
67 } // namespace Rcpp
68 
69 #endif
Rcpp::traits::is_named
Definition: named_object.h:62
Rcpp::traits::integral_constant
Definition: integral_constant.h:29
Rcpp::traits::named_object< SEXP >::~named_object
~named_object()
Definition: named_object.h:51
Rcpp::traits::named_object< SEXP >::named_object
named_object(const named_object< SEXP > &other)
Definition: named_object.h:47
Rcpp::traits::named_object< SEXP >::token
SEXP token
Definition: named_object.h:58
Rcpp::traits::named_object::named_object
named_object(const std::string &name_, const T &o_)
Definition: named_object.h:35
Rcpp::traits::named_object::name
const std::string & name
Definition: named_object.h:37
Rcpp
Rcpp API.
Definition: algo.h:28
Rcpp::object
Definition: Module.h:65
Rcpp::Rcpp_PreciousPreserve
SEXP Rcpp_PreciousPreserve(SEXP object)
Definition: RcppCommon.h:115
Rcpp::traits::named_object< SEXP >
Definition: named_object.h:40
Rcpp::Argument
Definition: Named.h:27
Rcpp::traits::named_object
Definition: named_object.h:33
Rcpp::Rcpp_PreciousRelease
void Rcpp_PreciousRelease(SEXP token)
Definition: RcppCommon.h:119
Rcpp::traits::named_object::object
const T & object
Definition: named_object.h:38
Rcpp::traits::needs_protection
Definition: named_object.h:30
Rcpp::traits::named_object< SEXP >::name
const std::string & name
Definition: named_object.h:55
Rcpp::traits::named_object< SEXP >::named_object
named_object(const std::string &name_, const SEXP &o_)
Definition: named_object.h:42
Rcpp::traits::named_object< SEXP >::object
SEXP object
Definition: named_object.h:56