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,30 +70,30 @@ class World {
7070 std::string msg;
7171};
7272
73- void clearWorld (World * w) {
73+ void clearWorld (ModuleWorld * w) {
7474 w->set (" " );
7575}
7676
7777class Num {
7878public:
79- Num () : x(0.0 ), y(0 ) {} ;
79+ Num () : 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
9191class Number {
9292public:
93- Number () : x(0.0 ), y(0 ) {} ;
93+ Number () : x(0.0 ), y(0 ) {};
9494
95- double x ;
96- int y ;
95+ double x;
96+ int y;
9797};
9898
9999class Randomizer {
@@ -103,40 +103,40 @@ class Randomizer {
103103 Randomizer (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
114114RCPP_EXPOSED_CLASS (Test)
115115class Test{
116116public:
117- double value ;
117+ double value;
118118 Test (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+ Test (const Test& other);
123+ Test& operator =(const Test&);
124+ };
125125
126126double Test_get_x_const_ref (const Test& x) {
127- return x.value ;
127+ return x.value ;
128128}
129129double Test_get_x_ref (Test& x) {
130130 return x.value ;
131131}
132132double Test_get_x_const_pointer (const Test* x) {
133- return x->value ;
133+ return x->value ;
134134}
135135double Test_get_x_pointer (Test* x) {
136- return x->value ;
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,23 +145,21 @@ 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
151151 class_<Test>(" Test" )
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
166164 class_<Num>(" Num" )
167165 .constructor ()
@@ -200,7 +198,7 @@ RCPP_MODULE(yada) {
200198
201199// [[Rcpp::export]]
202200double attr_Test_get_x_const_ref (const Test& x) {
203- return x.value ;
201+ return x.value ;
204202}
205203
206204// [[Rcpp::export]]
@@ -210,12 +208,12 @@ double attr_Test_get_x_ref(Test& x) {
210208
211209// [[Rcpp::export]]
212210double attr_Test_get_x_const_pointer (const Test* x) {
213- return x->value ;
211+ return x->value ;
214212}
215213
216214// [[Rcpp::export]]
217215double attr_Test_get_x_pointer (Test* x) {
218- return x->value ;
216+ return x->value ;
219217}
220218
221219
0 commit comments