[Rcpp-commits] r2390 - in pkg/Rcpp/inst/include/Rcpp: . module

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Nov 4 13:05:34 CET 2010


Author: romain
Date: 2010-11-04 13:05:34 +0100 (Thu, 04 Nov 2010)
New Revision: 2390

Added:
   pkg/Rcpp/inst/include/Rcpp/module/Module_generated_Constructor.h
   pkg/Rcpp/inst/include/Rcpp/module/Module_generated_class_get_constructor.h
Modified:
   pkg/Rcpp/inst/include/Rcpp/Module.h
Log:
separate the constructor stuff from the rest, to facilitate future code generation

Modified: pkg/Rcpp/inst/include/Rcpp/Module.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/Module.h	2010-11-04 11:56:55 UTC (rev 2389)
+++ pkg/Rcpp/inst/include/Rcpp/Module.h	2010-11-04 12:05:34 UTC (rev 2390)
@@ -215,39 +215,8 @@
 
 #include <Rcpp/module/Module_Property.h>
 
-template <typename Class>
-class Constructor_Base {
-public:
-    virtual Class* get_new( SEXP* args, int nargs ) = 0 ;
-} ;
+#include <Rcpp/module/Module_generated_Constructor.h>
 
-template <typename Class>
-class Constructor_0 : public Constructor_Base<Class>{
-public:
-    Class* newInstance(){ return new Class ; }
-    virtual Class* get_new( SEXP* args, int nargs ){
-        return newInstance() ;
-    }
-} ;
-template <typename Class, typename U0>
-class Constructor_1 : public Constructor_Base<Class>{
-    Class* newInstance(U0 u0){ return new Class( u0) ; }
-    virtual Class* get_new( SEXP* args, int nargs ){
-        return newInstance( as<U0>(args[0]) ) ;
-    }
-} ;
-template <typename Class, typename U0, typename U1>
-class Constructor_2 : public Constructor_Base<Class>{
-    Class* newInstance(U0 u0, U1 u1){ return new Class( u0, u1 ) ; }
-    virtual Class* get_new( SEXP* args, int nargs ){
-        return newInstance( as<U0>(args[0]), as<U1>(args[1]) ) ;
-    }
-} ;
-
-struct init_0 {};
-template <typename U0> struct init_1{} ;
-template <typename U0, typename U1> struct init_2{} ;
-
 template <typename Class, typename INIT = init_0>
 class class_ : public class_Base {
 public:
@@ -274,20 +243,9 @@
 			getCurrentScope()->AddClass( name_, singleton ) ;
 		}
 	}
-	
-private:
-    constructor_class* get_constructor( init_0 ){
-        return new Constructor_0<Class> ;
-    }
-    template <typename U0>
-    constructor_class* get_constructor( init_1<U0> ){
-        return new Constructor_1<Class,U0>() ;
-    }
-    template <typename U0, typename U1>
-    constructor_class* get_constructor( init_2<U0,U1> ){
-        return new Constructor_2<Class,U0,U1>() ;
-    }
-    
+
+#include <Rcpp/module/Module_generated_class_get_constructor.h>
+
 public:
 	
 	SEXP newInstance( SEXP* args, int nargs ){

Added: pkg/Rcpp/inst/include/Rcpp/module/Module_generated_Constructor.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/module/Module_generated_Constructor.h	                        (rev 0)
+++ pkg/Rcpp/inst/include/Rcpp/module/Module_generated_Constructor.h	2010-11-04 12:05:34 UTC (rev 2390)
@@ -0,0 +1,58 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+//
+// Module_generated_Constructor.h: Rcpp R/C++ interface class library -- Rcpp modules
+//
+// Copyright (C) 2010	Dirk Eddelbuettel and Romain Francois
+//
+// This file is part of Rcpp.
+//
+// Rcpp is free software: you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// (at your option) any later version.
+//
+// Rcpp is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Rcpp.  If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef Rcpp_Module_generated_Constructor_h
+#define Rcpp_Module_generated_Constructor_h
+
+template <typename Class>
+class Constructor_Base {
+public:
+    virtual Class* get_new( SEXP* args, int nargs ) = 0 ;
+} ;
+
+template <typename Class>
+class Constructor_0 : public Constructor_Base<Class>{
+public:
+    virtual Class* get_new( SEXP* args, int nargs ){
+        return return new Class ;
+    }
+} ;
+template <typename Class, typename U0>
+class Constructor_1 : public Constructor_Base<Class>{
+    virtual Class* get_new( SEXP* args, int nargs ){
+        return return new Class( as<U0>(args[0]) ) ;
+    }
+} ;
+template <typename Class, typename U0, typename U1>
+class Constructor_2 : public Constructor_Base<Class>{
+    virtual Class* get_new( SEXP* args, int nargs ){
+        return new Class( 
+            as<U0>(args[0]), 
+            as<U1>(args[1]) 
+            ) ;
+    }
+} ;
+
+struct init_0 {};
+template <typename U0> struct init_1{} ;
+template <typename U0, typename U1> struct init_2{} ;
+
+#endif

Added: pkg/Rcpp/inst/include/Rcpp/module/Module_generated_class_get_constructor.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/module/Module_generated_class_get_constructor.h	                        (rev 0)
+++ pkg/Rcpp/inst/include/Rcpp/module/Module_generated_class_get_constructor.h	2010-11-04 12:05:34 UTC (rev 2390)
@@ -0,0 +1,38 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+//
+// Module_generated_class_get_constructor.h: Rcpp R/C++ interface class library -- Rcpp modules
+//
+// Copyright (C) 2010	Dirk Eddelbuettel and Romain Francois
+//
+// This file is part of Rcpp.
+//
+// Rcpp is free software: you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// (at your option) any later version.
+//
+// Rcpp is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Rcpp.  If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef Rcpp_Module_generated_class_get_Constructor_h
+#define Rcpp_Module_generated_class_get_Constructor_h
+
+private:
+    constructor_class* get_constructor( init_0 ){
+        return new Constructor_0<Class> ;
+    }
+    template <typename U0>
+    constructor_class* get_constructor( init_1<U0> ){
+        return new Constructor_1<Class,U0>() ;
+    }
+    template <typename U0, typename U1>
+    constructor_class* get_constructor( init_2<U0,U1> ){
+        return new Constructor_2<Class,U0,U1>() ;
+    }
+    
+#endif



More information about the Rcpp-commits mailing list