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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon May 31 20:11:26 CEST 2010


Author: romain
Date: 2010-05-31 20:11:26 +0200 (Mon, 31 May 2010)
New Revision: 1383

Modified:
   pkg/Rcpp/NAMESPACE
   pkg/Rcpp/R/Module.R
   pkg/Rcpp/inst/include/Rcpp/Module.h
   pkg/Rcpp/src/Module.cpp
Log:
arity tip in completion

Modified: pkg/Rcpp/NAMESPACE
===================================================================
--- pkg/Rcpp/NAMESPACE	2010-05-31 15:38:41 UTC (rev 1382)
+++ pkg/Rcpp/NAMESPACE	2010-05-31 18:11:26 UTC (rev 1383)
@@ -12,4 +12,5 @@
 importFrom( utils, .DollarNames )
 S3method( .DollarNames, "C++ObjectS3" )
 S3method( .DollarNames, "Module" )
+exportMethods( complete )
 

Modified: pkg/Rcpp/R/Module.R
===================================================================
--- pkg/Rcpp/R/Module.R	2010-05-31 15:38:41 UTC (rev 1382)
+++ pkg/Rcpp/R/Module.R	2010-05-31 18:11:26 UTC (rev 1383)
@@ -138,10 +138,11 @@
 
 setGeneric( "complete", function(x) standardGeneric("complete") )
 setMethod( "complete", "C++Object", function(x){
-	.Call( "CppClass__methods" , x at cppclass, PACKAGE = "Rcpp" )
+	xp <- x at cppclass
+	.Call( "CppClass__complete" , xp , PACKAGE = "Rcpp" )
 } )
 
 ".DollarNames.C++ObjectS3" <- function( x, pattern ){
-	grep( pattern, complete(x) , value = TRUE )
+	grep( pattern, complete(x), value = TRUE )
 }
 

Modified: pkg/Rcpp/inst/include/Rcpp/Module.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/Module.h	2010-05-31 15:38:41 UTC (rev 1382)
+++ pkg/Rcpp/inst/include/Rcpp/Module.h	2010-05-31 18:11:26 UTC (rev 1383)
@@ -57,6 +57,7 @@
 		return R_NilValue ;
 	}
 	virtual Rcpp::CharacterVector method_names(){ return Rcpp::CharacterVector(0) ; }
+	virtual Rcpp::CharacterVector complete(){ return Rcpp::CharacterVector(0) ; }
 	virtual ~class_Base(){}
 	
 	std::string name ;
@@ -137,7 +138,7 @@
 	typedef std::pair<const std::string,method_class*> PAIR ;
 	typedef Rcpp::XPtr<Class> XP ;   
 	
-	class_( const char* name_ ) : class_Base(name_), methods() {
+	class_( const char* name_ ) : class_Base(name_), methods(), specials(0) {
 		if( !singleton ){
 			singleton = new self ;
 			singleton->name = name_ ;
@@ -169,6 +170,7 @@
 	
 	self& AddMethod( const char* name, method_class* m){
 		singleton->methods.insert( PAIR( name,m ) ) ;  
+		if( *name == '[' ) singleton->specials++ ;
 		return *this ;
 	}
 
@@ -189,11 +191,31 @@
 		return out ;
 	}
 	
+	Rcpp::CharacterVector complete(){
+		int n = methods.size() - specials ;
+		Rcpp::CharacterVector out(n) ;
+		typename METHOD_MAP::iterator it = methods.begin( ) ;
+		std::string buffer ;
+		for( int i=0; i<n; ++it){  
+			buffer = it->first ;
+			if( buffer[0] == '[' ) continue ;
+			if( (it->second)->nargs() == 0){
+				buffer += "() " ;
+			} else {
+				buffer += "( " ;
+			}
+			out[i] = buffer ;
+			i++ ;
+		} 
+		return out ;
+	}
+	
 private:
 	METHOD_MAP methods ;
 	static self* singleton ;
+	int specials ;
 	
-	class_( ) : class_Base(), methods(){}; 
+	class_( ) : class_Base(), methods(), specials(0) {}; 
 	
 } ;   
 

Modified: pkg/Rcpp/src/Module.cpp
===================================================================
--- pkg/Rcpp/src/Module.cpp	2010-05-31 15:38:41 UTC (rev 1382)
+++ pkg/Rcpp/src/Module.cpp	2010-05-31 18:11:26 UTC (rev 1383)
@@ -61,6 +61,10 @@
 RCPP_FUNCTION_1( Rcpp::CharacterVector, Module__complete, XP_Module module ){
 	return module->complete() ;
 }
+extern "C" SEXP CppClass__complete( SEXP xp){
+	XP_Class cl(xp) ;
+	return cl->complete(); 
+}
 
 // .External functions
 extern "C" SEXP Module__invoke( SEXP args){
@@ -191,7 +195,7 @@
 		for( ; i<nf; i++, ++it) {
 			buffer = it->first ;
 			if( (it->second)->nargs() == 0 ) {
-				buffer += "()" ;
+				buffer += "() " ;
 			} else {
 				buffer += "( " ;
 			}



More information about the Rcpp-commits mailing list