Rcpp Version 1.0.14
Loading...
Searching...
No Matches
ListOf.h
Go to the documentation of this file.
1// ListOf.h: Rcpp R/C++ interface class library -- templated List container
2//
3// Copyright (C) 2014 Dirk Eddelbuettel, Romain Francois and Kevin Ushey
4//
5// This file is part of Rcpp.
6//
7// Rcpp is free software: you can redistribute it and/or modify it
8// under the terms of the GNU General Public License as published by
9// the Free Software Foundation, either version 2 of the License, or
10// (at your option) any later version.
11//
12// Rcpp is distributed in the hope that it will be useful, but
13// WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
19
20#ifndef Rcpp_vector_ListOf_h_
21#define Rcpp_vector_ListOf_h_
22
23namespace Rcpp {
24
25template <typename T>
26class ListOf
27 : public NamesProxyPolicy<T>
28 , public AttributeProxyPolicy<T>
29 , public RObjectMethods<T>
30{
31
32public:
35
37
38 ListOf(SEXP data_): list(data_) {
39 std::transform(list.begin(), list.end(), list.begin(), as<T>);
40 }
41
42 template <typename U>
43 ListOf(const U& data_): list(data_) {
44 std::transform(list.begin(), list.end(), list.begin(), as<T>);
45 }
46
48
50 if (this != &other) {
51 list = other.list;
52 }
53 return *this;
54 }
55
56 template <typename U>
59 return *this;
60 }
61
62 // subsetting operators
63
67
69 return ChildVector<T>(list[i], list, i);
70 }
71
72 ChildVector<T> operator[](const std::string& str) {
74 }
75
76 const ChildVector<T> operator[](const std::string& str) const {
78 }
79
80 // iteration operators pass down to list
81
82 inline iterator begin() {
83 return list.begin();
84 }
85
86 inline iterator end() {
87 return list.end();
88 }
89
90 inline const_iterator begin() const {
91 return list.begin();
92 }
93
94 inline const_iterator end() const {
95 return list.end();
96 }
97
98 inline R_xlen_t size() const {
99 return list.size() ;
100 }
101
102 inline List get() const {
103 return list;
104 }
105
106 // conversion operators
107 operator SEXP() const { return wrap(list); }
108 operator List() const { return list; }
109
110private:
111
113
114}; // ListOf<T>
115
116// sapply, lapply wrappers
117
118namespace sugar {
119
120template <int RTYPE, bool NA, typename T, typename Function>
121class Lapply;
122
123template <int RTYPE, bool NA, typename T, typename Function, bool NO_CONVERSION>
124class Sapply;
125
126}
127
128template <typename T, typename Function>
130 return lapply(t.get(), fun);
131}
132
133template <typename T, typename Function>
134T sapply(const ListOf<T>& t, Function fun) {
135 return sapply(t.get(), fun);
136}
137
138} // Rcpp
139
140#endif
traits::r_vector_const_iterator< VECSXP >::type const_iterator
Definition ListOf.h:34
R_xlen_t size() const
Definition ListOf.h:98
ChildVector< T > operator[](const std::string &str)
Definition ListOf.h:72
ListOf & operator=(const U &other)
Definition ListOf.h:57
ListOf(const ListOf &other)
Definition ListOf.h:47
ChildVector< T > operator[](R_xlen_t i)
Definition ListOf.h:64
List list
Definition ListOf.h:112
List get() const
Definition ListOf.h:102
const ChildVector< T > operator[](R_xlen_t i) const
Definition ListOf.h:68
iterator begin()
Definition ListOf.h:82
const_iterator begin() const
Definition ListOf.h:90
ListOf(SEXP data_)
Definition ListOf.h:38
const_iterator end() const
Definition ListOf.h:94
const ChildVector< T > operator[](const std::string &str) const
Definition ListOf.h:76
ListOf & operator=(const ListOf &other)
Definition ListOf.h:49
ListOf(const U &data_)
Definition ListOf.h:43
traits::r_vector_iterator< VECSXP >::type iterator
Definition ListOf.h:33
iterator end()
Definition ListOf.h:86
R_xlen_t findName(const std::string &name) const
Definition Vector.h:596
R_xlen_t size() const
Definition Vector.h:275
iterator end()
Definition Vector.h:334
iterator begin()
Definition Vector.h:333
Rcpp API.
Definition algo.h:28
Function_Impl< PreserveStorage > Function
Definition Function.h:131
sugar::Sapply< RTYPE, NA, T, Function, traits::same_type< typename ::Rcpp::sugar::sapply_application_result_of< Function, T >::type, typename Rcpp::traits::storage_type< traits::r_sexptype_traits< typename ::Rcpp::sugar::sapply_application_result_of< Function, T >::type >::rtype >::type >::value > sapply(const Rcpp::VectorBase< RTYPE, NA, T > &t, Function fun)
Definition sapply.h:131
Vector< VECSXP > List
T as(SEXP x)
Definition as.h:151
sugar::Lapply< RTYPE, NA, T, Function > lapply(const Rcpp::VectorBase< RTYPE, NA, T > &t, Function fun)
Definition lapply.h:55
SEXP wrap(const Date &date)
Definition Date.h:38
const storage_type< RTYPE >::type * type
Definition proxy.h:255
storage_type< RTYPE >::type * type
Definition proxy.h:251