[Rcpp-commits] r2509 - in pkg/Rcpp: . R inst/doc/Rcpp-modules inst/include/Rcpp man src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Nov 23 19:18:52 CET 2010


Author: romain
Date: 2010-11-23 19:18:51 +0100 (Tue, 23 Nov 2010)
New Revision: 2509

Modified:
   pkg/Rcpp/ChangeLog
   pkg/Rcpp/R/00_classes.R
   pkg/Rcpp/R/01_show.R
   pkg/Rcpp/inst/doc/Rcpp-modules/Rcpp-modules.Rnw
   pkg/Rcpp/inst/include/Rcpp/Module.h
   pkg/Rcpp/man/CppClass-class.Rd
   pkg/Rcpp/src/Module.cpp
Log:
C++Class gains a docstring slot

Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog	2010-11-23 17:47:39 UTC (rev 2508)
+++ pkg/Rcpp/ChangeLog	2010-11-23 18:18:51 UTC (rev 2509)
@@ -1,5 +1,7 @@
 2010-11-23  Romain Francois <romain at r-enthusiasts.com>
 
+    * R/00_classes.R: C++Class gains a docstring slot to host self documentation
+    
     * R/Module.R: calling an exposed C++ more efficiently by using the xp directly 
     rather than traversing the map internally
     
@@ -8,7 +10,7 @@
     the function
     
     * R/01_show.R: updated show( C++Function ) to display the docstring and
-    the signature
+    the signature. updated show( C++Class ) to display the docstring.
     
     * inst/include/Rcpp/module/Module_generated_CppFunction.h: self documentation
     for exposed C++ functions and extraction of the signature

Modified: pkg/Rcpp/R/00_classes.R
===================================================================
--- pkg/Rcpp/R/00_classes.R	2010-11-23 17:47:39 UTC (rev 2508)
+++ pkg/Rcpp/R/00_classes.R	2010-11-23 18:18:51 UTC (rev 2509)
@@ -67,8 +67,9 @@
 	    module       = "externalptr", 
 	    fields       = "list",
 	    methods      = "list",
-	    constructors = "list", 
-	    generator    = "refObjectGenerator"
+	    constructors = "list",
+	    generator    = "refObjectGenerator", 
+	    docstring    = "character"
 	), 
 	contains = "character"
 	)

Modified: pkg/Rcpp/R/01_show.R
===================================================================
--- pkg/Rcpp/R/01_show.R	2010-11-23 17:47:39 UTC (rev 2508)
+++ pkg/Rcpp/R/01_show.R	2010-11-23 18:18:51 UTC (rev 2509)
@@ -34,9 +34,12 @@
 } )
 
 setMethod( "show", "C++Class", function(object){
-	txt <- sprintf( "C++ class '%s' <%s>", 
+	doc <- object at docstring
+    txt <- sprintf( "C++ class '%s' <%s>%s", 
 		.Call( Class__name, object at pointer ), 
-		externalptr_address(object at pointer) )
+		externalptr_address(object at pointer), 
+		if( length(doc) && nchar(doc) ) sprintf( "\n    docstring : %s", doc ) else ""
+	)
 	writeLines( txt )
 	
 	ctors <- object at constructors

Modified: pkg/Rcpp/inst/doc/Rcpp-modules/Rcpp-modules.Rnw
===================================================================
--- pkg/Rcpp/inst/doc/Rcpp-modules/Rcpp-modules.Rnw	2010-11-23 17:47:39 UTC (rev 2508)
+++ pkg/Rcpp/inst/doc/Rcpp-modules/Rcpp-modules.Rnw	2010-11-23 18:18:51 UTC (rev 2509)
@@ -709,10 +709,9 @@
 b$stats()
 @
 
-
 \subsubsection{Exposing methods}
+\subsubsection{Object finalizers}
 
-
 The construction of the object is then followed by two calls to the
 \texttt{method} member function of \texttt{class\_<World>}. The
 \texttt{method} methods can expose :

Modified: pkg/Rcpp/inst/include/Rcpp/Module.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/Module.h	2010-11-23 17:47:39 UTC (rev 2508)
+++ pkg/Rcpp/inst/include/Rcpp/Module.h	2010-11-23 18:18:51 UTC (rev 2509)
@@ -55,8 +55,9 @@
 
 class class_Base {
 public:
-	class_Base() :name(){} ;
-	class_Base(const char* name_) : name(name_){} ;
+	class_Base() : name(), docstring() {} ;
+	class_Base(const char* name_, const char* doc) : 
+	    name(name_), docstring( doc == 0 ? "" : doc ){} ;
 	
 	virtual Rcpp::List fields(SEXP){ return Rcpp::List(0); }
 	virtual Rcpp::List getMethods(SEXP){ return Rcpp::List(0); }
@@ -84,8 +85,6 @@
 		return R_NilValue ;
 	}
 	
-	
-	
 	virtual Rcpp::CharacterVector method_names(){ return Rcpp::CharacterVector(0) ; }
 	virtual Rcpp::CharacterVector property_names(){ return Rcpp::CharacterVector(0) ; }
 	virtual bool property_is_readonly(const std::string& ) throw(std::range_error) { return false ; }
@@ -105,6 +104,7 @@
 	}
 	
 	std::string name ;
+	std::string docstring ;
 } ;
 
 class Module {
@@ -336,12 +336,18 @@
 	typedef std::map<std::string,prop_class*> PROPERTY_MAP ;
 	typedef std::pair<const std::string,prop_class*> PROP_PAIR ;
 	
-	class_( const char* name_ ) : 
-	    class_Base(name_), vec_methods(), properties(), finalizer_pointer(0), specials(0), constructors()
+	class_( const char* name_, const char* doc = 0) : 
+	    class_Base(name_, 0), 
+	    vec_methods(), 
+	    properties(), 
+	    finalizer_pointer(0), 
+	    specials(0), 
+	    constructors()
 	{
 		if( !singleton ){
 			singleton = new self ;
 			singleton->name = name_ ;
+			singleton->docstring = std::string( doc == 0 ? "" : doc );
 			singleton->finalizer_pointer = new finalizer_class ;
 			getCurrentScope()->AddClass( name_, singleton ) ;
 		}

Modified: pkg/Rcpp/man/CppClass-class.Rd
===================================================================
--- pkg/Rcpp/man/CppClass-class.Rd	2010-11-23 17:47:39 UTC (rev 2508)
+++ pkg/Rcpp/man/CppClass-class.Rd	2010-11-23 18:18:51 UTC (rev 2509)
@@ -22,6 +22,7 @@
     \item{\code{constructors}:}{list of \linkS4class{C++Constructor} objects}
     \item{\code{methods}:}{list of \linkS4class{C++OverloadedMethods} objects}
     \item{generator}{the generator object for the class}
+    \item{docstring}{description of the class}
   }
 }
 \section{Methods}{

Modified: pkg/Rcpp/src/Module.cpp
===================================================================
--- pkg/Rcpp/src/Module.cpp	2010-11-23 17:47:39 UTC (rev 2508)
+++ pkg/Rcpp/src/Module.cpp	2010-11-23 18:18:51 UTC (rev 2509)
@@ -361,6 +361,7 @@
 		slot( "fields" )      = cl->fields( clxp.asSexp() ) ;
 		slot( "methods" )     = cl->getMethods( clxp.asSexp() ) ;
 		slot( "constructors") = cl->getConstructors( clxp.asSexp() ) ;
+		slot( "docstring"   ) = cl->docstring ;
 	}
 
 	CppObject::CppObject( Module* p, class_Base* clazz, SEXP xp ) : S4("C++Object") {



More information about the Rcpp-commits mailing list