33//
44// Module.cpp: Rcpp R/C++ interface class library -- module unit tests
55//
6- // Copyright (C) 2013 - 2014 Dirk Eddelbuettel and Romain Francois
6+ // Copyright (C) 2013 - 2015 Dirk Eddelbuettel and Romain Francois
77//
88// This file is part of Rcpp.
99//
2222
2323#include < Rcpp.h>
2424
25- using namespace Rcpp ;
25+ using namespace Rcpp ;
2626
2727std::string hello () {
28- return " hello" ;
28+ return " hello" ;
2929}
3030
3131int bar (int x) {
32- return x*2 ;
32+ return x*2 ;
3333}
3434
3535double foo (int x, double y) {
36- return x * y ;
36+ return x * y;
3737}
3838
3939void bla () {
40- Rprintf (" hello\\ n" ) ;
40+ Rprintf (" hello\\ n" );
4141}
4242
4343void bla1 (int x) {
44- Rprintf (" hello (x = %d)\\ n" , x) ;
44+ Rprintf (" hello (x = %d)\\ n" , x);
4545}
4646
4747void bla2 (int x, double y) {
48- Rprintf (" hello (x = %d, y = %5.2f)\\ n" , x, y) ;
48+ Rprintf (" hello (x = %d, y = %5.2f)\\ n" , x, y);
4949}
5050
5151int test_reference (std::vector<double >& ref) {
52- return ref.size () ;
52+ return ref.size ();
5353}
5454int test_const_reference (const std::vector<double >& ref) {
55- return ref.size () ;
55+ return ref.size ();
5656}
5757int test_const (const std::vector<double > ref) {
58- return ref.size () ;
58+ return ref.size ();
5959}
6060
61- class World {
61+ class ModuleWorld {
6262public:
63- World () : msg(" hello" ) {}
63+ ModuleWorld () : msg(" hello" ) {}
6464 void set (std::string msg_) { this ->msg = msg_; }
6565 void set_ref (std::string& msg_) { this ->msg = msg_; }
6666 void set_const_ref (const std::string& msg_) { this ->msg = msg_; }
@@ -70,73 +70,73 @@ class World {
7070 std::string msg;
7171};
7272
73- void clearWorld (World * w) {
73+ void clearWorld (ModuleWorld * w) {
7474 w->set (" " );
7575}
7676
77- class Num {
77+ class ModuleNum {
7878public:
79- Num () : x(0.0 ), y(0 ) {} ;
79+ ModuleNum () : x(0.0 ), y(0 ) {};
8080
81- double getX () const { return x ; }
82- void setX (double value) { x = value ; }
81+ double getX () const { return x; }
82+ void setX (double value) { x = value; }
8383
84- int getY () { return y ; }
84+ int getY () { return y; }
8585
8686private:
87- double x ;
88- int y ;
87+ double x;
88+ int y;
8989};
9090
91- class Number {
91+ class ModuleNumber {
9292public:
93- Number () : x(0.0 ), y(0 ) {} ;
93+ ModuleNumber () : x(0.0 ), y(0 ) {};
9494
95- double x ;
96- int y ;
95+ double x;
96+ int y;
9797};
9898
99- class Randomizer {
99+ class ModuleRandomizer {
100100public:
101101
102102 // Randomizer() : min(0), max(1) {}
103- Randomizer (double min_, double max_) : min(min_), max(max_) {}
103+ ModuleRandomizer (double min_, double max_) : min(min_), max(max_) {}
104104
105105 NumericVector get (int n) {
106- RNGScope scope ;
106+ RNGScope scope;
107107 return runif (n, min, max);
108108 }
109109
110110private:
111- double min, max ;
112- } ;
111+ double min, max;
112+ };
113113
114- RCPP_EXPOSED_CLASS (Test )
115- class Test {
114+ RCPP_EXPOSED_CLASS (ModuleTest )
115+ class ModuleTest {
116116public:
117- double value ;
118- Test (double v) : value (v) {}
117+ double value;
118+ ModuleTest (double v) : value (v) {}
119119private:
120120 // hiding those on purpose
121121 // we work by reference or pointers here. Not by copy.
122- Test (const Test & other) ;
123- Test & operator =(const Test&) ;
124- } ;
122+ ModuleTest (const ModuleTest & other);
123+ ModuleTest & operator =(const ModuleTest&) ;
124+ };
125125
126- double Test_get_x_const_ref (const Test & x) {
127- return x.value ;
126+ double Test_get_x_const_ref (const ModuleTest & x) {
127+ return x.value ;
128128}
129- double Test_get_x_ref (Test & x) {
129+ double Test_get_x_ref (ModuleTest & x) {
130130 return x.value ;
131131}
132- double Test_get_x_const_pointer (const Test * x) {
133- return x->value ;
132+ double Test_get_x_const_pointer (const ModuleTest * x) {
133+ return x->value ;
134134}
135- double Test_get_x_pointer (Test * x) {
136- return x->value ;
135+ double Test_get_x_pointer (ModuleTest * x) {
136+ return x->value ;
137137}
138138
139- RCPP_MODULE (yada ) {
139+ RCPP_MODULE (demoModule ) {
140140 function (" hello" , &hello);
141141 function (" bar" , &bar );
142142 function (" foo" , &foo );
@@ -145,43 +145,41 @@ RCPP_MODULE(yada) {
145145 function (" bla2" , &bla2 );
146146
147147 function (" test_reference" , test_reference);
148- function (" test_const_reference" , test_const_reference) ;
149- function (" test_const" , test_const) ;
148+ function (" test_const_reference" , test_const_reference);
149+ function (" test_const" , test_const);
150150
151- class_<Test >(" Test " )
151+ class_<ModuleTest >(" ModuleTest " )
152152 .constructor <double >()
153153 ;
154154
155- class_<World>(" World" )
156-
155+ class_<ModuleWorld>(" ModuleWorld" )
157156 .constructor ()
158-
159- .method (" greet" , &World::greet)
160- .method (" set" , &World::set)
161- .method (" set_ref" , &World::set_ref)
162- .method (" set_const_ref" , &World::set_const_ref)
157+ .method (" greet" , &ModuleWorld::greet)
158+ .method (" set" , &ModuleWorld::set)
159+ .method (" set_ref" , &ModuleWorld::set_ref)
160+ .method (" set_const_ref" , &ModuleWorld::set_const_ref)
163161 .method (" clear" , &clearWorld)
164- ;
162+ ;
165163
166- class_<Num >(" Num " )
164+ class_<ModuleNum >(" ModuleNum " )
167165 .constructor ()
168166
169167 // read and write property
170- .property (" x" , &Num ::getX, &Num ::setX)
168+ .property (" x" , &ModuleNum ::getX, &ModuleNum ::setX)
171169
172170 // read-only property
173- .property (" y" , &Num ::getY)
171+ .property (" y" , &ModuleNum ::getY)
174172 ;
175173
176- class_<Number >(" Number " )
174+ class_<ModuleNumber >(" ModuleNumber " )
177175
178176 .constructor ()
179177
180178 // read and write data member
181- .field (" x" , &Number ::x)
179+ .field (" x" , &ModuleNumber ::x)
182180
183181 // read only data member
184- .field_readonly (" y" , &Number ::y)
182+ .field_readonly (" y" , &ModuleNumber ::y)
185183 ;
186184
187185 function (" Test_get_x_const_ref" , Test_get_x_const_ref);
@@ -190,32 +188,31 @@ RCPP_MODULE(yada) {
190188 function (" Test_get_x_pointer" , Test_get_x_pointer);
191189
192190
193- class_<Randomizer >(" Randomizer " )
191+ class_<ModuleRandomizer >(" ModuleRandomizer " )
194192 // No default: .default_constructor()
195193 .constructor <double ,double >()
196194
197- .method (" get" , &Randomizer ::get)
195+ .method (" get" , &ModuleRandomizer ::get)
198196 ;
199197}
200198
201199// [[Rcpp::export]]
202- double attr_Test_get_x_const_ref (const Test & x) {
203- return x.value ;
200+ double attr_Test_get_x_const_ref (const ModuleTest & x) {
201+ return x.value ;
204202}
205203
206204// [[Rcpp::export]]
207- double attr_Test_get_x_ref (Test & x) {
205+ double attr_Test_get_x_ref (ModuleTest & x) {
208206 return x.value ;
209207}
210208
211209// [[Rcpp::export]]
212- double attr_Test_get_x_const_pointer (const Test * x) {
213- return x->value ;
210+ double attr_Test_get_x_const_pointer (const ModuleTest * x) {
211+ return x->value ;
214212}
215213
216214// [[Rcpp::export]]
217- double attr_Test_get_x_pointer (Test * x) {
218- return x->value ;
215+ double attr_Test_get_x_pointer (ModuleTest * x) {
216+ return x->value ;
219217}
220218
221-
0 commit comments