|
2 | 2 | // |
3 | 3 | // Module.cpp: Rcpp R/C++ interface class library -- Rcpp modules |
4 | 4 | // |
5 | | -// Copyright (C) 2010 - 2013 Dirk Eddelbuettel and Romain Francois |
| 5 | +// Copyright (C) 2010 - 2015 Dirk Eddelbuettel and Romain Francois |
6 | 6 | // |
7 | 7 | // This file is part of Rcpp. |
8 | 8 | // |
|
24 | 24 | #include <Rcpp.h> |
25 | 25 | #include "internal.h" |
26 | 26 |
|
27 | | -typedef Rcpp::XPtr<Rcpp::Module> XP_Module ; |
28 | | -typedef Rcpp::XPtr<Rcpp::class_Base> XP_Class ; |
29 | | -typedef Rcpp::XPtr<Rcpp::CppFunctionBase> XP_Function ; |
| 27 | +typedef Rcpp::XPtr<Rcpp::Module> XP_Module; |
| 28 | +typedef Rcpp::XPtr<Rcpp::class_Base> XP_Class; |
| 29 | +typedef Rcpp::XPtr<Rcpp::CppFunctionBase> XP_Function; |
30 | 30 |
|
31 | | -RCPP_FUN_1( bool, Class__has_default_constructor, XP_Class cl ){ |
32 | | - return cl->has_default_constructor() ; |
| 31 | +RCPP_FUN_1(bool, Class__has_default_constructor, XP_Class cl) { |
| 32 | + return cl->has_default_constructor(); |
33 | 33 | } |
34 | | -RCPP_FUN_2( SEXP, Module__get_function, XP_Module module, std::string fun ){ |
35 | | - return module->get_function( fun ) ; |
| 34 | +RCPP_FUN_2(SEXP, Module__get_function, XP_Module module, std::string fun) { |
| 35 | + return module->get_function(fun); |
36 | 36 | } |
37 | | -RCPP_FUN_2( bool, Class__has_method, XP_Class cl, std::string m){ |
38 | | - return cl->has_method(m) ; |
| 37 | +RCPP_FUN_2(bool, Class__has_method, XP_Class cl, std::string m) { |
| 38 | + return cl->has_method(m); |
39 | 39 | } |
40 | | -RCPP_FUN_2( bool, Class__has_property, XP_Class cl, std::string m){ |
41 | | - return cl->has_property(m) ; |
| 40 | +RCPP_FUN_2(bool, Class__has_property, XP_Class cl, std::string m) { |
| 41 | + return cl->has_property(m); |
42 | 42 | } |
43 | | -RCPP_FUN_1( std::string, Class__name, XP_Class cl){ |
44 | | - return cl->name ; |
| 43 | +RCPP_FUN_1(std::string, Class__name, XP_Class cl) { |
| 44 | + return cl->name; |
45 | 45 | } |
46 | | -RCPP_FUN_2( bool, Module__has_function, XP_Module module, std::string met ){ |
47 | | - return module->has_function( met ) ; |
| 46 | +RCPP_FUN_2(bool, Module__has_function, XP_Module module, std::string met) { |
| 47 | + return module->has_function(met); |
48 | 48 | } |
49 | | -RCPP_FUN_2( bool, Module__has_class, XP_Module module, std::string cl ){ |
50 | | - return module->has_class( cl ) ; |
| 49 | +RCPP_FUN_2(bool, Module__has_class, XP_Module module, std::string cl) { |
| 50 | + return module->has_class(cl); |
51 | 51 | } |
52 | | -RCPP_FUN_2( Rcpp::CppClass, Module__get_class, XP_Module module, std::string cl ){ |
53 | | - return module->get_class( cl ) ; |
| 52 | +RCPP_FUN_2(Rcpp::CppClass, Module__get_class, XP_Module module, std::string cl) { |
| 53 | + return module->get_class(cl); |
54 | 54 | } |
55 | | -RCPP_FUN_1( bool, CppObject__needs_init, SEXP xp ){ |
56 | | - return EXTPTR_PTR(xp) == 0 ; |
| 55 | +RCPP_FUN_1(bool, CppObject__needs_init, SEXP xp) { |
| 56 | + return EXTPTR_PTR(xp) == 0; |
57 | 57 | } |
58 | | -RCPP_FUN_1( Rcpp::CharacterVector, CppClass__methods, XP_Class cl){ |
59 | | - return cl->method_names() ; |
| 58 | +RCPP_FUN_1(Rcpp::CharacterVector, CppClass__methods, XP_Class cl) { |
| 59 | + return cl->method_names(); |
60 | 60 | } |
61 | | -RCPP_FUN_1( Rcpp::CharacterVector, CppClass__properties, XP_Class cl){ |
62 | | - return cl->property_names() ; |
| 61 | +RCPP_FUN_1(Rcpp::CharacterVector, CppClass__properties, XP_Class cl) { |
| 62 | + return cl->property_names(); |
63 | 63 | } |
64 | | -RCPP_FUN_1( Rcpp::List, CppClass__property_classes, XP_Class cl){ |
65 | | - return cl->property_classes() ; |
| 64 | +RCPP_FUN_1(Rcpp::List, CppClass__property_classes, XP_Class cl) { |
| 65 | + return cl->property_classes(); |
66 | 66 | } |
67 | 67 |
|
68 | | -RCPP_FUN_1( Rcpp::IntegerVector, CppClass__methods_arity, XP_Class cl){ |
69 | | - return cl->methods_arity() ; |
| 68 | +RCPP_FUN_1(Rcpp::IntegerVector, CppClass__methods_arity, XP_Class cl) { |
| 69 | + return cl->methods_arity(); |
70 | 70 | } |
71 | | -RCPP_FUN_1( Rcpp::LogicalVector, CppClass__methods_voidness, XP_Class cl){ |
72 | | - return cl->methods_voidness() ; |
| 71 | +RCPP_FUN_1(Rcpp::LogicalVector, CppClass__methods_voidness, XP_Class cl) { |
| 72 | + return cl->methods_voidness(); |
73 | 73 | } |
74 | 74 |
|
75 | 75 |
|
76 | | -RCPP_FUN_2( bool, CppClass__property_is_readonly, XP_Class cl, std::string p){ |
77 | | - return cl->property_is_readonly(p) ; |
| 76 | +RCPP_FUN_2(bool, CppClass__property_is_readonly, XP_Class cl, std::string p) { |
| 77 | + return cl->property_is_readonly(p); |
78 | 78 | } |
79 | | -RCPP_FUN_2( std::string, CppClass__property_class, XP_Class cl, std::string p){ |
80 | | - return cl->property_class(p) ; |
| 79 | +RCPP_FUN_2(std::string, CppClass__property_class, XP_Class cl, std::string p) { |
| 80 | + return cl->property_class(p); |
81 | 81 | } |
82 | 82 |
|
83 | | -RCPP_FUN_1( Rcpp::IntegerVector, Module__functions_arity, XP_Module module ){ |
84 | | - return module-> functions_arity() ; |
| 83 | +RCPP_FUN_1(Rcpp::IntegerVector, Module__functions_arity, XP_Module module) { |
| 84 | + return module-> functions_arity(); |
85 | 85 | } |
86 | | -RCPP_FUN_1( Rcpp::CharacterVector, Module__functions_names, XP_Module module ){ |
87 | | - return module-> functions_names() ; |
| 86 | +RCPP_FUN_1(Rcpp::CharacterVector, Module__functions_names, XP_Module module) { |
| 87 | + return module-> functions_names(); |
88 | 88 | } |
89 | | -RCPP_FUN_1( std::string, Module__name, XP_Module module ){ |
| 89 | +RCPP_FUN_1(std::string, Module__name, XP_Module module) { |
90 | 90 | return module->name; |
91 | 91 | } |
92 | | -RCPP_FUN_1( Rcpp::List, Module__classes_info, XP_Module module ){ |
93 | | - return module->classes_info() ; |
| 92 | +RCPP_FUN_1(Rcpp::List, Module__classes_info, XP_Module module) { |
| 93 | + return module->classes_info(); |
94 | 94 | } |
95 | | -RCPP_FUN_1( Rcpp::CharacterVector, Module__complete, XP_Module module ){ |
96 | | - return module->complete() ; |
| 95 | +RCPP_FUN_1(Rcpp::CharacterVector, Module__complete, XP_Module module) { |
| 96 | + return module->complete(); |
97 | 97 | } |
98 | | -RCPP_FUN_1( Rcpp::CharacterVector, CppClass__complete, XP_Class cl){ |
| 98 | +RCPP_FUN_1(Rcpp::CharacterVector, CppClass__complete, XP_Class cl) { |
99 | 99 | return cl->complete(); |
100 | 100 | } |
101 | 101 |
|
102 | 102 | // these operate directly on the external pointers, rather than |
103 | 103 | // looking up the property in the map |
104 | | -RCPP_FUN_3(SEXP, CppField__get, XP_Class cl, SEXP field_xp, SEXP obj){ |
105 | | - return cl->getProperty( field_xp, obj ) ; |
| 104 | +RCPP_FUN_3(SEXP, CppField__get, XP_Class cl, SEXP field_xp, SEXP obj) { |
| 105 | + return cl->getProperty(field_xp, obj); |
106 | 106 | } |
107 | | -RCPP_FUN_4(SEXP, CppField__set, XP_Class cl, SEXP field_xp, SEXP obj, SEXP value){ |
108 | | - cl->setProperty( field_xp, obj, value ) ; |
109 | | - return R_NilValue ; |
| 107 | +RCPP_FUN_4(SEXP, CppField__set, XP_Class cl, SEXP field_xp, SEXP obj, SEXP value) { |
| 108 | + cl->setProperty(field_xp, obj, value); |
| 109 | + return R_NilValue; |
110 | 110 | } |
111 | | -RCPP_FUN_2(SEXP, CppObject__finalize, XP_Class cl, SEXP obj){ |
112 | | - cl->run_finalizer( obj ) ; |
113 | | - return R_NilValue ; |
| 111 | +RCPP_FUN_2(SEXP, CppObject__finalize, XP_Class cl, SEXP obj) { |
| 112 | + cl->run_finalizer(obj); |
| 113 | + return R_NilValue; |
114 | 114 | } |
115 | 115 |
|
116 | 116 | // .External functions |
117 | | -SEXP InternalFunction_invoke( SEXP args ){ |
| 117 | +SEXP InternalFunction_invoke(SEXP args) { |
118 | 118 | BEGIN_RCPP |
119 | | - SEXP p = CDR(args) ; |
120 | | - XP_Function fun( CAR(p) ) ; p = CDR(p) ; |
| 119 | + SEXP p = CDR(args); |
| 120 | + XP_Function fun(CAR(p)); p = CDR(p); |
121 | 121 | UNPACK_EXTERNAL_ARGS(cargs,p) |
122 | | - return fun->operator()( cargs ) ; |
| 122 | + return fun->operator()(cargs); |
123 | 123 | END_RCPP |
124 | 124 | } |
125 | 125 |
|
126 | | -SEXP Module__invoke( SEXP args){ |
| 126 | +SEXP Module__invoke(SEXP args) { |
127 | 127 | BEGIN_RCPP |
128 | | - SEXP p = CDR(args) ; |
129 | | - XP_Module module( CAR(p) ) ; p = CDR(p) ; |
130 | | - std::string fun = Rcpp::as<std::string>( CAR(p) ) ; p = CDR(p) ; |
| 128 | + SEXP p = CDR(args); |
| 129 | + XP_Module module(CAR(p)); p = CDR(p); |
| 130 | + std::string fun = Rcpp::as<std::string>(CAR(p)); p = CDR(p); |
131 | 131 |
|
132 | 132 | UNPACK_EXTERNAL_ARGS(cargs,p) |
133 | | - return module->invoke( fun, cargs, nargs ) ; |
| 133 | + return module->invoke(fun, cargs, nargs); |
134 | 134 | END_RCPP |
135 | 135 | } |
136 | 136 |
|
137 | | -SEXP class__newInstance(SEXP args){ |
138 | | - SEXP p = CDR(args) ; |
| 137 | +SEXP class__newInstance(SEXP args) { |
| 138 | + SEXP p = CDR(args); |
139 | 139 |
|
140 | | - XP_Module module( CAR(p) ) ; p = CDR(p) ; |
141 | | - XP_Class clazz( CAR(p) ) ; p = CDR(p); |
| 140 | + XP_Module module(CAR(p)); p = CDR(p); |
| 141 | + XP_Class clazz(CAR(p)); p = CDR(p); |
142 | 142 | UNPACK_EXTERNAL_ARGS(cargs,p) |
143 | | - return clazz->newInstance(cargs, nargs ) ; |
| 143 | + return clazz->newInstance(cargs, nargs); |
144 | 144 | } |
145 | 145 |
|
146 | 146 | // relies on being set in .onLoad() |
147 | 147 | SEXP rcpp_dummy_pointer = R_NilValue; |
148 | 148 |
|
149 | | -#define CHECK_DUMMY_OBJ(p) if(p == rcpp_dummy_pointer) forward_exception_to_r( Rcpp::not_initialized()) |
| 149 | +#define CHECK_DUMMY_OBJ(p) if (p == rcpp_dummy_pointer) forward_exception_to_r(Rcpp::not_initialized()) |
150 | 150 |
|
151 | 151 |
|
152 | 152 | SEXP class__dummyInstance(SEXP args) { |
153 | 153 | SEXP p; |
154 | 154 |
|
155 | | - if(args == R_NilValue) |
| 155 | + if (args == R_NilValue) { |
156 | 156 | return rcpp_dummy_pointer; |
| 157 | + } |
157 | 158 | p = CDR(args); |
158 | 159 |
|
159 | | - if(p != R_NilValue) |
| 160 | + if (p != R_NilValue) { |
160 | 161 | rcpp_dummy_pointer = CAR(p); |
| 162 | + } |
161 | 163 | return rcpp_dummy_pointer; |
162 | 164 | } |
163 | 165 |
|
164 | | -SEXP CppMethod__invoke(SEXP args){ |
165 | | - SEXP p = CDR(args) ; |
| 166 | +SEXP CppMethod__invoke(SEXP args) { |
| 167 | + SEXP p = CDR(args); |
166 | 168 |
|
167 | 169 | // the external pointer to the class |
168 | | - XP_Class clazz( CAR(p) ) ; p = CDR(p); |
| 170 | + XP_Class clazz(CAR(p)); p = CDR(p); |
169 | 171 |
|
170 | 172 | // the external pointer to the method |
171 | | - SEXP met = CAR(p) ; p = CDR(p) ; |
| 173 | + SEXP met = CAR(p); p = CDR(p); |
172 | 174 |
|
173 | 175 | // the external pointer to the object |
174 | | - SEXP obj = CAR(p); p = CDR(p) ; |
| 176 | + SEXP obj = CAR(p); p = CDR(p); |
175 | 177 | CHECK_DUMMY_OBJ(obj); |
176 | 178 |
|
177 | 179 | // additional arguments, processed the same way as .Call does |
178 | 180 | UNPACK_EXTERNAL_ARGS(cargs,p) |
179 | 181 |
|
180 | | - return clazz->invoke( met, obj, cargs, nargs ) ; |
| 182 | + return clazz->invoke(met, obj, cargs, nargs); |
181 | 183 | } |
182 | 184 |
|
183 | | -SEXP CppMethod__invoke_void(SEXP args){ |
184 | | - SEXP p = CDR(args) ; |
| 185 | +SEXP CppMethod__invoke_void(SEXP args) { |
| 186 | + SEXP p = CDR(args); |
185 | 187 |
|
186 | 188 | // the external pointer to the class |
187 | | - XP_Class clazz( CAR(p) ) ; p = CDR(p); |
| 189 | + XP_Class clazz(CAR(p)); p = CDR(p); |
188 | 190 |
|
189 | 191 | // the external pointer to the method |
190 | | - SEXP met = CAR(p) ; p = CDR(p) ; |
| 192 | + SEXP met = CAR(p); p = CDR(p); |
191 | 193 |
|
192 | 194 | // the external pointer to the object |
193 | | - SEXP obj = CAR(p); p = CDR(p) ; |
| 195 | + SEXP obj = CAR(p); p = CDR(p); |
194 | 196 | CHECK_DUMMY_OBJ(obj); |
195 | 197 |
|
196 | 198 | // additional arguments, processed the same way as .Call does |
197 | 199 | UNPACK_EXTERNAL_ARGS(cargs,p) |
198 | | - clazz->invoke_void( met, obj, cargs, nargs ) ; |
199 | | - return R_NilValue ; |
| 200 | + clazz->invoke_void(met, obj, cargs, nargs); |
| 201 | + return R_NilValue; |
200 | 202 | } |
201 | 203 |
|
202 | | -SEXP CppMethod__invoke_notvoid(SEXP args){ |
203 | | - SEXP p = CDR(args) ; |
| 204 | +SEXP CppMethod__invoke_notvoid(SEXP args) { |
| 205 | + SEXP p = CDR(args); |
204 | 206 |
|
205 | 207 | // the external pointer to the class |
206 | | - XP_Class clazz( CAR(p) ) ; p = CDR(p); |
| 208 | + XP_Class clazz(CAR(p)); p = CDR(p); |
207 | 209 |
|
208 | 210 | // the external pointer to the method |
209 | | - SEXP met = CAR(p) ; p = CDR(p) ; |
| 211 | + SEXP met = CAR(p); p = CDR(p); |
210 | 212 |
|
211 | 213 | // the external pointer to the object |
212 | | - SEXP obj = CAR(p); p = CDR(p) ; |
| 214 | + SEXP obj = CAR(p); p = CDR(p); |
213 | 215 | CHECK_DUMMY_OBJ(obj); |
214 | 216 |
|
215 | 217 | // additional arguments, processed the same way as .Call does |
216 | 218 | UNPACK_EXTERNAL_ARGS(cargs,p) |
217 | 219 |
|
218 | | - return clazz->invoke_notvoid( met, obj, cargs, nargs ) ; |
| 220 | + return clazz->invoke_notvoid(met, obj, cargs, nargs); |
219 | 221 | } |
220 | 222 |
|
221 | 223 | namespace Rcpp{ |
222 | | - static Module* current_scope ; |
| 224 | + static Module* current_scope ; |
223 | 225 | } |
224 | 226 |
|
225 | | -Rcpp::Module* getCurrentScope(){ |
226 | | - return Rcpp::current_scope ; |
| 227 | +Rcpp::Module* getCurrentScope() { |
| 228 | + return Rcpp::current_scope; |
227 | 229 | } |
228 | | -void setCurrentScope( Rcpp::Module* scope ){ |
229 | | - Rcpp::current_scope = scope ; |
| 230 | +void setCurrentScope(Rcpp::Module* scope) { |
| 231 | + Rcpp::current_scope = scope; |
230 | 232 | } |
231 | 233 |
|
0 commit comments