[Rcpp-commits] r2490 - in pkg/Rcpp: R inst/include/Rcpp inst/include/Rcpp/module

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Nov 22 19:12:57 CET 2010


Author: romain
Date: 2010-11-22 19:12:54 +0100 (Mon, 22 Nov 2010)
New Revision: 2490

Added:
   pkg/Rcpp/inst/include/Rcpp/module/Module_generated_ctor_signature.h
   pkg/Rcpp/inst/include/Rcpp/module/Module_generated_get_return_type.h
Modified:
   pkg/Rcpp/R/00_classes.R
   pkg/Rcpp/R/01_show.R
   pkg/Rcpp/inst/include/Rcpp/Module.h
   pkg/Rcpp/inst/include/Rcpp/module/Module_generated_Constructor.h
   pkg/Rcpp/inst/include/Rcpp/module/Module_generated_get_signature.h
Log:
pulling reflection info about constructors

Modified: pkg/Rcpp/R/00_classes.R
===================================================================
--- pkg/Rcpp/R/00_classes.R	2010-11-22 14:59:44 UTC (rev 2489)
+++ pkg/Rcpp/R/00_classes.R	2010-11-22 18:12:54 UTC (rev 2490)
@@ -53,7 +53,8 @@
     fields = list( 
         pointer       = "externalptr", 
         class_pointer = "externalptr", 
-        nargs         = "integer"
+        nargs         = "integer", 
+        signature     = "character"
     )
 )
 

Modified: pkg/Rcpp/R/01_show.R
===================================================================
--- pkg/Rcpp/R/01_show.R	2010-11-22 14:59:44 UTC (rev 2489)
+++ pkg/Rcpp/R/01_show.R	2010-11-22 18:12:54 UTC (rev 2490)
@@ -39,6 +39,16 @@
 		externalptr_address(object at pointer) )
 	writeLines( txt )
 	
+	ctors <- object at constructors
+	nctors <- length( ctors )
+	txt <- character( nctors )
+	for( i in seq_len(nctors) ){
+	    txt[i] <- sprintf( "    %s", ctors[[i]]$signature )
+	}
+	writeLines( "Constructors:" )
+	writeLines( paste( txt, collapse = "\n" ) )
+	
+	writeLines( "\nFields: " )
 	fields <- object at fields
 	nfields <- length(fields)
 	names <- names(fields)
@@ -51,8 +61,6 @@
 	        if( f$read_only ) " [readonly]" else "" 
 	    )    
 	}
-	# TODO: pull out reflection info about constructors
-	writeLines( "Fields: " )
 	writeLines( paste( txt, collapse = "\n" ) )
 	
 	writeLines( "\nMethods: " )

Modified: pkg/Rcpp/inst/include/Rcpp/Module.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/Module.h	2010-11-22 14:59:44 UTC (rev 2489)
+++ pkg/Rcpp/inst/include/Rcpp/Module.h	2010-11-22 18:12:54 UTC (rev 2490)
@@ -165,6 +165,8 @@
 		virtual const char* signature(const char* name ){ return name ; }
 } ;
 
+#include <Rcpp/module/Module_generated_get_return_type.h>
+#include <Rcpp/module/Module_generated_ctor_signature.h>
 #include <Rcpp/module/Module_generated_Constructor.h>
 #include <Rcpp/module/Module_generated_class_signature.h>
 
@@ -184,6 +186,9 @@
     ValidConstructor valid ;
     
     inline int nargs(){ return ctor->nargs() ; }
+    inline const char* signature(const std::string& class_name){ 
+        return ctor->signature(class_name) ;
+    }
 } ;
 
 template <typename Class>
@@ -205,10 +210,12 @@
 template <typename Class>
 class S4_CppConstructor : public Rcpp::Reference {
 public:             
-    S4_CppConstructor( SignedConstructor<Class>* m, SEXP class_xp ) : Reference( "C++Constructor" ){
+    S4_CppConstructor( SignedConstructor<Class>* m, SEXP class_xp, const std::string& class_name ) : Reference( "C++Constructor" ){
         field( "pointer" )       = Rcpp::XPtr< SignedConstructor<Class> >( m, false ) ;
         field( "class_pointer" ) = class_xp ;
         field( "nargs" )         = m->nargs() ;
+        std::string sign(  m->signature(class_name) ) ;
+        field( "signature" )     = sign ;
     }
 } ;
 
@@ -636,12 +643,12 @@
 	    return res ;
 	}
 	
-	Rcpp::List getConstructors( SEXP class_xp ){
+	Rcpp::List getConstructors( SEXP class_xp){
 	    int n = constructors.size() ;
 		Rcpp::List out(n) ;
 		typename vec_signed_constructor::iterator it = constructors.begin( ) ;
 		for( int i=0; i<n; i++, ++it){
-			out[i] = S4_CppConstructor<Class>( *it , class_xp ) ; 
+			out[i] = S4_CppConstructor<Class>( *it , class_xp, name ) ; 
 		} 
 		return out ;
 	}

Modified: pkg/Rcpp/inst/include/Rcpp/module/Module_generated_Constructor.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/module/Module_generated_Constructor.h	2010-11-22 14:59:44 UTC (rev 2489)
+++ pkg/Rcpp/inst/include/Rcpp/module/Module_generated_Constructor.h	2010-11-22 18:12:54 UTC (rev 2490)
@@ -27,6 +27,7 @@
 public:
     virtual Class* get_new( SEXP* args, int nargs ) = 0 ;
     virtual int nargs() = 0 ;
+    virtual const char* signature(const std::string& class_name) = 0 ;
 } ;
 
 template <typename Class>
@@ -36,6 +37,9 @@
 	return new Class ;
     }
     virtual int nargs(){ return 0 ; }
+    virtual const char* signature(const std::string& class_name ){
+        return ctor_signature(class_name) ;
+    }
 } ;
 template <typename Class, typename U0>
 class Constructor_1 : public Constructor_Base<Class>{
@@ -43,6 +47,9 @@
         return new Class( as<U0>(args[0]) ) ;
     }
     virtual int nargs(){ return 1 ; }
+    virtual const char* signature(const std::string& class_name ){
+        return ctor_signature<U0>(class_name) ;
+    }
 } ;
 template <typename Class, typename U0, typename U1>
 class Constructor_2 : public Constructor_Base<Class>{
@@ -53,6 +60,9 @@
             ) ;
     }
     virtual int nargs(){ return 2 ; }
+    virtual const char* signature(const std::string& class_name ){
+        return ctor_signature<U0,U1>(class_name) ;
+    }
 } ;
 template <typename Class, typename U0, typename U1, typename U2>
 class Constructor_3 : public Constructor_Base<Class>{
@@ -64,6 +74,9 @@
             ) ;
     }
     virtual int nargs(){ return 3 ; }
+    virtual const char* signature(const std::string& class_name ){
+        return ctor_signature<U0,U1,U2>(class_name) ;
+    }
 } ;
 template <typename Class, typename U0, typename U1, typename U2, typename U3>
 class Constructor_4 : public Constructor_Base<Class>{
@@ -76,6 +89,9 @@
             ) ;
     }
     virtual int nargs(){ return 4 ; }
+    virtual const char* signature(const std::string& class_name ){
+        return ctor_signature<U0,U1,U2,U3>(class_name) ;
+    }
 } ;
 template <typename Class, typename U0, typename U1, typename U2, typename U3, typename U4>
 class Constructor_5 : public Constructor_Base<Class>{
@@ -89,6 +105,9 @@
             ) ;
     }
     virtual int nargs(){ return 5 ; }
+    virtual const char* signature(const std::string& class_name ){
+        return ctor_signature<U0,U1,U2,U3,U4>(class_name) ;
+    }
 } ;
 template <typename Class, typename U0, typename U1, typename U2, typename U3, typename U4, typename U5>
 class Constructor_6 : public Constructor_Base<Class>{
@@ -103,6 +122,9 @@
             ) ;
     }
     virtual int nargs(){ return 6 ; }
+    virtual const char* signature(const std::string& class_name ){
+        return ctor_signature<U0,U1,U2,U3,U4,U5>(class_name) ;
+    }
 } ;
 
 #endif

Added: pkg/Rcpp/inst/include/Rcpp/module/Module_generated_ctor_signature.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/module/Module_generated_ctor_signature.h	                        (rev 0)
+++ pkg/Rcpp/inst/include/Rcpp/module/Module_generated_ctor_signature.h	2010-11-22 18:12:54 UTC (rev 2490)
@@ -0,0 +1,100 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 4 -*-
+//
+// Module_generated_ctor_signature.h: Rcpp R/C++ interface class library --
+//
+// 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_ctor_signature_h
+#define Rcpp_Module_generated_ctor_signature_h
+
+inline const char* ctor_signature( const std::string& classname ){
+    std::string s( classname ) ;
+    s+= "()" ; 
+    return s.c_str() ;
+}
+
+template <typename U0>
+inline const char* ctor_signature( const std::string& classname ){
+    std::string s( classname ) ;
+    s += "(" ; 
+    s += get_return_type<U0>() ;
+    s += ")" ;
+    return s.c_str() ;
+}
+
+template <typename U0, typename U1>
+inline const char* ctor_signature( const std::string& classname ){
+    std::string s( classname ) ;
+    s += "(" ; 
+    s += get_return_type<U0>() ;
+    s += ", " ; s+= get_return_type<U1>() ;
+    s += ")" ;
+    return s.c_str() ;
+}
+
+template <typename U0, typename U1, typename U2>
+inline const char* ctor_signature( const std::string& classname ){
+    std::string s( classname ) ;
+    s += "(" ; 
+    s += get_return_type<U0>() ;
+    s += ", " ; s+= get_return_type<U1>() ;
+    s += ", " ; s+= get_return_type<U2>() ;
+    s += ")" ;
+    return s.c_str() ;
+}
+
+template <typename U0, typename U1, typename U2, typename U3>
+inline const char* ctor_signature( const std::string& classname ){
+    std::string s( classname ) ;
+    s += "(" ; 
+    s += get_return_type<U0>() ;
+    s += ", " ; s+= get_return_type<U1>() ;
+    s += ", " ; s+= get_return_type<U2>() ;
+    s += ", " ; s+= get_return_type<U3>() ;
+    s += ")" ;
+    return s.c_str() ;
+}
+
+template <typename U0, typename U1, typename U2, typename U3, typename U4>
+inline const char* ctor_signature( const std::string& classname ){
+    std::string s( classname ) ;
+    s += "(" ; 
+    s += get_return_type<U0>() ;
+    s += ", " ; s+= get_return_type<U1>() ;
+    s += ", " ; s+= get_return_type<U2>() ;
+    s += ", " ; s+= get_return_type<U3>() ;
+    s += ", " ; s+= get_return_type<U4>() ;
+    s += ")" ;
+    return s.c_str() ;
+}
+
+template <typename U0, typename U1, typename U2, typename U3, typename U4, typename U5>
+inline const char* ctor_signature( const std::string& classname ){
+    std::string s( classname ) ;
+    s += "(" ; 
+    s += get_return_type<U0>() ;
+    s += ", " ; s+= get_return_type<U1>() ;
+    s += ", " ; s+= get_return_type<U2>() ;
+    s += ", " ; s+= get_return_type<U3>() ;
+    s += ", " ; s+= get_return_type<U4>() ;
+    s += ", " ; s+= get_return_type<U5>() ;
+    s += ")" ;
+    return s.c_str() ;
+}
+
+#endif

Added: pkg/Rcpp/inst/include/Rcpp/module/Module_generated_get_return_type.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/module/Module_generated_get_return_type.h	                        (rev 0)
+++ pkg/Rcpp/inst/include/Rcpp/module/Module_generated_get_return_type.h	2010-11-22 18:12:54 UTC (rev 2490)
@@ -0,0 +1,60 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 4 -*-
+//
+// Module_generated_get_return_type.h: Rcpp R/C++ interface class library --
+//
+// 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_get_return_type_h
+#define Rcpp_Module_generated_get_return_type_h
+
+struct void_type{} ;
+
+template <typename OUT>
+inline std::string get_return_type(){
+    return demangle( typeid(OUT).name() ).data() ;
+}
+template <>
+inline std::string get_return_type<void_type>(){
+    return "void" ;
+}
+template <>
+inline std::string get_return_type<Rcpp::IntegerVector>(){
+    return "Rcpp::IntegerVector" ;
+}
+template <>
+inline std::string get_return_type<Rcpp::NumericVector>(){
+    return "Rcpp::NumericVector" ;
+}
+template <>
+inline std::string get_return_type<Rcpp::RawVector>(){
+    return "Rcpp::RawVector" ;
+}
+template <>
+inline std::string get_return_type<Rcpp::ExpressionVector>(){
+    return "Rcpp::ExpressionVector" ;
+}
+template <>
+inline std::string get_return_type<Rcpp::List>(){
+    return "Rcpp::List" ;
+}
+template <>
+inline std::string get_return_type<Rcpp::CharacterVector>(){
+    return "Rcpp::CharacterVector" ;
+}
+
+#endif

Modified: pkg/Rcpp/inst/include/Rcpp/module/Module_generated_get_signature.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/module/Module_generated_get_signature.h	2010-11-22 14:59:44 UTC (rev 2489)
+++ pkg/Rcpp/inst/include/Rcpp/module/Module_generated_get_signature.h	2010-11-22 18:12:54 UTC (rev 2490)
@@ -22,43 +22,7 @@
 #ifndef Rcpp_Module_generated_get_signature_h
 #define Rcpp_Module_generated_get_signature_h
 
-struct void_type{} ;
-
 template <typename OUT>
-inline std::string get_return_type(){
-    return demangle( typeid(OUT).name() ).data() ;
-}
-template <>
-inline std::string get_return_type<void_type>(){
-    return "void" ;
-}
-template <>
-inline std::string get_return_type<Rcpp::IntegerVector>(){
-    return "Rcpp::IntegerVector" ;
-}
-template <>
-inline std::string get_return_type<Rcpp::NumericVector>(){
-    return "Rcpp::NumericVector" ;
-}
-template <>
-inline std::string get_return_type<Rcpp::RawVector>(){
-    return "Rcpp::RawVector" ;
-}
-template <>
-inline std::string get_return_type<Rcpp::ExpressionVector>(){
-    return "Rcpp::ExpressionVector" ;
-}
-template <>
-inline std::string get_return_type<Rcpp::List>(){
-    return "Rcpp::List" ;
-}
-template <>
-inline std::string get_return_type<Rcpp::CharacterVector>(){
-    return "Rcpp::CharacterVector" ;
-}
-
-
-template <typename OUT>
 inline const char* signature(const std::string& name){
     std::string s ;
     s += get_return_type<OUT>() ;



More information about the Rcpp-commits mailing list