[Rcpp-commits] r1373 - in pkg/Rcpp: . R inst inst/include/Rcpp src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun May 30 09:26:34 CEST 2010


Author: romain
Date: 2010-05-30 09:26:34 +0200 (Sun, 30 May 2010)
New Revision: 1373

Modified:
   pkg/Rcpp/NAMESPACE
   pkg/Rcpp/R/Module.R
   pkg/Rcpp/inst/ChangeLog
   pkg/Rcpp/inst/include/Rcpp/Module.h
   pkg/Rcpp/src/Module.cpp
Log:
completion for Modules

Modified: pkg/Rcpp/NAMESPACE
===================================================================
--- pkg/Rcpp/NAMESPACE	2010-05-30 06:57:46 UTC (rev 1372)
+++ pkg/Rcpp/NAMESPACE	2010-05-30 07:26:34 UTC (rev 1373)
@@ -11,4 +11,5 @@
 
 importFrom( utils, .DollarNames )
 S3method( .DollarNames, "C++ObjectS3" )
+S3method( .DollarNames, "Module" )
 

Modified: pkg/Rcpp/R/Module.R
===================================================================
--- pkg/Rcpp/R/Module.R	2010-05-30 06:57:46 UTC (rev 1372)
+++ pkg/Rcpp/R/Module.R	2010-05-30 07:26:34 UTC (rev 1373)
@@ -56,6 +56,10 @@
 	writeLines( txt )
 } )
 
+.DollarNames.Module <- function(x, pattern){
+	grep( pattern , .Call( "Module__complete", x at pointer, PACKAGE = "Rcpp"), value = TRUE )	
+}
+
 new_CppObject_xp <- function(Class, ...){
 	xp <- .External( "class__newInstance", Class at module, Class at pointer, ..., PACKAGE = "Rcpp" )
 	cl <- .Call( "Class__name", Class at pointer, PACKAGE = "Rcpp" )

Modified: pkg/Rcpp/inst/ChangeLog
===================================================================
--- pkg/Rcpp/inst/ChangeLog	2010-05-30 06:57:46 UTC (rev 1372)
+++ pkg/Rcpp/inst/ChangeLog	2010-05-30 07:26:34 UTC (rev 1373)
@@ -1,3 +1,7 @@
+2010-05-30  Romain Francois <romain at r-enthusiasts.com>
+
+	* R/Module.R: completion for C++ modules. 
+
 2010-05-29  Romain Francois <romain at r-enthusiasts.com>
 
 	* R/Module.R: when a Module is loaded, it creates extensions of the 

Modified: pkg/Rcpp/inst/include/Rcpp/Module.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/Module.h	2010-05-30 06:57:46 UTC (rev 1372)
+++ pkg/Rcpp/inst/include/Rcpp/Module.h	2010-05-30 07:26:34 UTC (rev 1373)
@@ -78,6 +78,7 @@
 		Rcpp::IntegerVector functions_arity() ;
 		Rcpp::CharacterVector class_names() ;
 		Rcpp::List classes_info() ;
+		Rcpp::CharacterVector complete() ;
 		
 		inline void Add( const char* name, CppFunction* ptr){
 			functions.insert( FUNCTION_PAIR( name, ptr ) ) ;

Modified: pkg/Rcpp/src/Module.cpp
===================================================================
--- pkg/Rcpp/src/Module.cpp	2010-05-30 06:57:46 UTC (rev 1372)
+++ pkg/Rcpp/src/Module.cpp	2010-05-30 07:26:34 UTC (rev 1373)
@@ -49,25 +49,19 @@
 RCPP_FUNCTION_1( Rcpp::CharacterVector, CppClass__methods, XP_Class cl){
 	return cl->method_names() ;
 }
-
-
-extern "C" SEXP Module__funtions_arity( SEXP mod_xp ){
-	Rcpp::XPtr<Rcpp::Module> module(mod_xp) ;
+RCPP_FUNCTION_1( Rcpp::IntegerVector, Module__funtions_arity, XP_Module module ){
 	return module->	functions_arity() ;
 }
-
-extern "C" SEXP Module__name( SEXP mod_xp ){
-	Rcpp::XPtr<Rcpp::Module> module(mod_xp) ;
-	return Rcpp::wrap( module->name );
+RCPP_FUNCTION_1( std::string, Module__name, XP_Module module ){
+	return module->name;
 }
-
-extern "C" SEXP Module__classes_info( SEXP mod_xp ){
-	Rcpp::XPtr<Rcpp::Module> mod(mod_xp) ;
-	return mod->classes_info() ;
+RCPP_FUNCTION_1( Rcpp::List, Module__classes_info, XP_Module module ){
+	return module->classes_info() ;
 }
+RCPP_FUNCTION_1( Rcpp::CharacterVector, Module__complete, XP_Module module ){
+	return module->complete() ;
+}
 
-
-
 // .External functions
 extern "C" SEXP Module__invoke( SEXP args){
 	SEXP p = CDR(args) ;
@@ -117,7 +111,6 @@
    	return clazz->invoke( met, obj, cargs, nargs ) ;
 }
 
-
 namespace Rcpp{
 	static Module* current_scope  ;
 }
@@ -187,6 +180,30 @@
 		return x ;
 	}
 	
+	Rcpp::CharacterVector Module::complete(){
+		int nf = functions.size() ;
+		int nc = classes.size() ;
+		int n = nf + nc ;
+		Rcpp::CharacterVector res( n ) ;
+		int i=0;
+		MAP::iterator it = functions.begin();
+		std::string buffer ;
+		for( ; i<nf; i++, ++it) {
+			buffer = it->first ;
+			if( (it->second)->nargs() == 0 ) {
+				buffer += "()" ;
+			} else {
+				buffer += "( " ;
+			}
+			res[i] = buffer ;
+		}
+		CLASS_MAP::iterator cit = classes.begin() ;
+		for( int j=0; j<nc; j++, i++, ++cit){
+			res[i] = cit->first ;
+		}
+		return res ;
+	}
+	
 	CppClass::CppClass( SEXP x) : S4(x){}
 	
 	CppClass::CppClass( Module* p, class_Base* cl ) : S4("C++Class") {



More information about the Rcpp-commits mailing list