Rcpp Version 1.0.14
Loading...
Searching...
No Matches
Module_Property.h
Go to the documentation of this file.
1// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2//
3// Module_Property.h: Rcpp R/C++ interface class library -- Rcpp modules
4//
5// Copyright (C) 2010 - 2017 Dirk Eddelbuettel and Romain Francois
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_Module_Property_h
23#define Rcpp_Module_Property_h
24
25// getter through a member function
26template <typename Class, typename PROP>
27class CppProperty_GetMethod : public CppProperty<Class> {
28public:
29 typedef PROP (Class::*GetMethod)(void);
30 typedef CppProperty<Class> prop_class;
31
32 CppProperty_GetMethod(GetMethod getter_, const char* doc = 0) :
33 prop_class(doc), getter(getter_), class_name(DEMANGLE(PROP)){}
34
35 SEXP get(Class* object) { return Rcpp::wrap((object->*getter)()); }
36 void set(Class*, SEXP) { throw std::range_error("property is read only"); }
37 bool is_readonly(){ return true; }
38 std::string get_class(){ return class_name; }
39
40private:
42 std::string class_name;
43
44};
45
46// getter through a const member function
47template <typename Class, typename PROP>
48class CppProperty_GetConstMethod : public CppProperty<Class> {
49public:
50 typedef PROP (Class::*GetMethod)(void) const;
51 typedef CppProperty<Class> prop_class;
52
53 CppProperty_GetConstMethod(GetMethod getter_ , const char* doc = 0) :
54 prop_class(doc), getter(getter_), class_name(DEMANGLE(PROP)){}
55
56 SEXP get(Class* object) { return Rcpp::wrap((object->*getter)()); }
57 void set(Class*, SEXP) { throw std::range_error("property is read only"); }
58 bool is_readonly(){ return true; }
59 std::string get_class(){ return class_name; }
60
61private:
63 std::string class_name;
64
65};
66
67
68// getter through a free function taking a pointer to Class
69template <typename Class, typename PROP>
70class CppProperty_GetPointerMethod : public CppProperty<Class> {
71public:
72 typedef PROP (*GetMethod)(Class*);
73 typedef CppProperty<Class> prop_class;
74
75 CppProperty_GetPointerMethod(GetMethod getter_ , const char* doc = 0) :
76 prop_class(doc), getter(getter_), class_name(DEMANGLE(PROP)){}
77
78 SEXP get(Class* object) { return Rcpp::wrap(getter(object)); }
79 void set(Class*, SEXP) { throw std::range_error("property is read only"); }
80 bool is_readonly(){ return true; }
81 std::string get_class(){ return class_name; }
82
83private:
85 std::string class_name;
86};
87
88
89// getter and setter through member functions
90template <typename Class, typename PROP>
91class CppProperty_GetMethod_SetMethod : public CppProperty<Class> {
92public:
93 typedef PROP (Class::*GetMethod)(void);
94 typedef void (Class::*SetMethod)(PROP);
95 typedef CppProperty<Class> prop_class;
96
97 CppProperty_GetMethod_SetMethod(GetMethod getter_, SetMethod setter_, const char* doc = 0) :
98 prop_class(doc), getter(getter_), setter(setter_), class_name(DEMANGLE(PROP)){}
99
100 SEXP get(Class* object) {
101 return Rcpp::wrap((object->*getter)());
102 }
103 void set(Class* object, SEXP value) {
105 }
106 bool is_readonly(){ return false; }
107 std::string get_class(){ return class_name; }
108
109private:
112 std::string class_name;
113};
114template <typename Class, typename PROP>
115class CppProperty_GetConstMethod_SetMethod : public CppProperty<Class> {
116public:
117 typedef PROP (Class::*GetMethod)(void) const;
118 typedef void (Class::*SetMethod)(PROP);
119 typedef CppProperty<Class> prop_class;
120
121 CppProperty_GetConstMethod_SetMethod(GetMethod getter_, SetMethod setter_, const char* doc = 0) :
122 prop_class(doc), getter(getter_), setter(setter_), class_name(DEMANGLE(PROP)){}
123
124 SEXP get(Class* object) {
125 return Rcpp::wrap((object->*getter)());
126 }
127 void set(Class* object, SEXP value) {
129 }
130 bool is_readonly(){ return false; }
131 std::string get_class(){ return class_name; }
132
133private:
136 std::string class_name;
137
138};
139
140
141
142
143// getter though a member function, setter through a pointer function
144template <typename Class, typename PROP>
145class CppProperty_GetMethod_SetPointer : public CppProperty<Class> {
146public:
147 typedef PROP (Class::*GetMethod)(void);
148 typedef void (*SetMethod)(Class*,PROP);
149 typedef CppProperty<Class> prop_class;
150
151 CppProperty_GetMethod_SetPointer(GetMethod getter_, SetMethod setter_, const char* doc = 0) :
152 prop_class(doc), getter(getter_), setter(setter_), class_name(DEMANGLE(PROP)){}
153
154 SEXP get(Class* object) {
155 return Rcpp::wrap((object->*getter)());
156 }
157 void set(Class* object, SEXP value) {
159 }
160 bool is_readonly(){ return false; }
161 std::string get_class(){ return class_name; }
162
163private:
166 std::string class_name;
167
168};
169template <typename Class, typename PROP>
170class CppProperty_GetConstMethod_SetPointer : public CppProperty<Class> {
171public:
172 typedef PROP (Class::*GetMethod)(void) const;
173 typedef void (*SetMethod)(Class*,PROP);
174 typedef CppProperty<Class> prop_class;
175
176 CppProperty_GetConstMethod_SetPointer(GetMethod getter_, SetMethod setter_, const char* doc = 0) :
177 prop_class(doc), getter(getter_), setter(setter_), class_name(DEMANGLE(PROP)){}
178
179 SEXP get(Class* object) {
180 return Rcpp::wrap((object->*getter)());
181 }
182 void set(Class* object, SEXP value) {
184 }
185 bool is_readonly(){ return false; }
186 std::string get_class(){ return class_name; }
187
188private:
191 std::string class_name;
192
193};
194
195// getter through pointer function, setter through member function
196template <typename Class, typename PROP>
197class CppProperty_GetPointer_SetMethod : public CppProperty<Class> {
198public:
199 typedef PROP (*GetMethod)(Class*);
200 typedef void (Class::*SetMethod)(PROP);
201 typedef CppProperty<Class> prop_class;
202
203 CppProperty_GetPointer_SetMethod(GetMethod getter_, SetMethod setter_, const char* doc = 0) :
204 prop_class(doc), getter(getter_), setter(setter_), class_name(DEMANGLE(PROP)){}
205
206 SEXP get(Class* object) {
207 return Rcpp::wrap(getter(object));
208 }
209 void set(Class* object, SEXP value) {
211 }
212 bool is_readonly(){ return false; }
213 std::string get_class(){ return class_name; }
214
215private:
218 std::string class_name;
219
220};
221
222// getter and setter through pointer functions
223// getter through pointer function, setter through member function
224template <typename Class, typename PROP>
225class CppProperty_GetPointer_SetPointer : public CppProperty<Class> {
226public:
227 typedef PROP (*GetMethod)(Class*);
228 typedef void (*SetMethod)(Class*,PROP);
229 typedef CppProperty<Class> prop_class;
230
231 CppProperty_GetPointer_SetPointer(GetMethod getter_, SetMethod setter_, const char* doc = 0) :
232 prop_class(doc), getter(getter_), setter(setter_), class_name(DEMANGLE(PROP)){}
233
234 SEXP get(Class* object) {
235 return Rcpp::wrap(getter(object));
236 }
237 void set(Class* object, SEXP value) {
239 }
240 bool is_readonly(){ return false; }
241 std::string get_class(){ return class_name; }
242
243private:
246 std::string class_name;
247
248};
249
250
251#endif
PROP(Class::* GetMethod)(void) const
CppProperty_GetConstMethod_SetMethod(GetMethod getter_, SetMethod setter_, const char *doc=0)
void set(Class *object, SEXP value)
CppProperty_GetConstMethod_SetPointer(GetMethod getter_, SetMethod setter_, const char *doc=0)
PROP(Class::* GetMethod)(void) const
void set(Class *object, SEXP value)
void set(Class *, SEXP)
PROP(Class::* GetMethod)(void) const
SEXP get(Class *object)
CppProperty< Class > prop_class
CppProperty_GetConstMethod(GetMethod getter_, const char *doc=0)
CppProperty< Class > prop_class
CppProperty_GetMethod_SetMethod(GetMethod getter_, SetMethod setter_, const char *doc=0)
void set(Class *object, SEXP value)
CppProperty_GetMethod_SetPointer(GetMethod getter_, SetMethod setter_, const char *doc=0)
void(* SetMethod)(Class *, PROP)
void set(Class *object, SEXP value)
CppProperty_GetMethod(GetMethod getter_, const char *doc=0)
CppProperty< Class > prop_class
PROP(Class::* GetMethod)(void)
void set(Class *, SEXP)
SEXP get(Class *object)
CppProperty_GetPointerMethod(GetMethod getter_, const char *doc=0)
CppProperty< Class > prop_class
void set(Class *object, SEXP value)
CppProperty_GetPointer_SetMethod(GetMethod getter_, SetMethod setter_, const char *doc=0)
void set(Class *object, SEXP value)
CppProperty_GetPointer_SetPointer(GetMethod getter_, SetMethod setter_, const char *doc=0)
#define DEMANGLE(__TYPE__)
Definition exceptions.h:382
T as(SEXP x)
Definition as.h:151
SEXP wrap(const Date &date)
Definition Date.h:38
remove_const< typenameremove_reference< T >::type >::type type