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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Sep 16 11:35:13 CEST 2010


Author: romain
Date: 2010-09-16 11:35:12 +0200 (Thu, 16 Sep 2010)
New Revision: 2114

Added:
   pkg/Rcpp/R/00_classes.R
   pkg/Rcpp/man/CppField-class.Rd
Modified:
   pkg/Rcpp/NAMESPACE
   pkg/Rcpp/R/Module.R
   pkg/Rcpp/inst/ChangeLog
   pkg/Rcpp/inst/include/Rcpp/Module.h
   pkg/Rcpp/man/CppClass-class.Rd
   pkg/Rcpp/src/Module.cpp
Log:
introducing C++Field

Modified: pkg/Rcpp/NAMESPACE
===================================================================
--- pkg/Rcpp/NAMESPACE	2010-09-15 19:51:25 UTC (rev 2113)
+++ pkg/Rcpp/NAMESPACE	2010-09-16 09:35:12 UTC (rev 2114)
@@ -5,7 +5,7 @@
 
 importFrom( utils, capture.output, assignInNamespace )
 
-exportClasses( Module, "C++Class", "C++Object", "C++Function", 
+exportClasses( Module, "C++Field", "C++Class", "C++Object", "C++Function", 
     "C++Property", "C++ClassRepresentation" )
 export( Module )
 

Added: pkg/Rcpp/R/00_classes.R
===================================================================
--- pkg/Rcpp/R/00_classes.R	                        (rev 0)
+++ pkg/Rcpp/R/00_classes.R	2010-09-16 09:35:12 UTC (rev 2114)
@@ -0,0 +1,58 @@
+# Copyright (C)        2010 John Chambers, 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/>.
+
+
+## "Module" class as an environment with "pointer", "moduleName", and "packageName"
+## Stands in for a reference class with those fields.
+setClass( "Module",  contains = "environment" )
+
+setClass( "C++Field", 
+    representation( 
+        pointer = "externalptr", 
+        cpp_class = "character", 
+        read_only = "logical"
+    )
+)
+
+setClass( "C++Class", 
+	representation( 
+	    pointer = "externalptr", 
+	    module  = "externalptr", 
+	    fields  = "list" 
+	), 
+	contains = "character"
+	)
+setClass( "C++ClassRepresentation", 
+    representation( pointer = "externalptr" ), 
+    contains = "classRepresentation" )
+
+# might not actually use this
+setClass( "C++Property" )	
+
+setClass( "C++Object", 
+	representation( 
+		module = "externalptr", 
+		cppclass = "externalptr", 
+		pointer = "externalptr"
+		)
+	)
+setClass( "C++Function", 
+	representation( pointer = "externalptr" ), 
+	contains = "function"
+)
+
+

Modified: pkg/Rcpp/R/Module.R
===================================================================
--- pkg/Rcpp/R/Module.R	2010-09-15 19:51:25 UTC (rev 2113)
+++ pkg/Rcpp/R/Module.R	2010-09-16 09:35:12 UTC (rev 2114)
@@ -17,29 +17,6 @@
 
 setGeneric( "new" )
 
-## "Module" class as an environment with "pointer", "moduleName", and "packageName"
-## Stands in for a reference class with those fields.
-setClass( "Module",  contains = "environment" )
-setClass( "C++Class", 
-	representation( pointer = "externalptr", module = "externalptr" ), 
-	contains = "character"
-	)
-setClass( "C++ClassRepresentation", 
-    representation( pointer = "externalptr" ), 
-    contains = "classRepresentation" )
-setClass( "C++Property" )	
-setClass( "C++Object", 
-	representation( 
-		module = "externalptr", 
-		cppclass = "externalptr", 
-		pointer = "externalptr"
-		)
-	)
-setClass( "C++Function", 
-	representation( pointer = "externalptr" ), 
-	contains = "function"
-)
-     
 internal_function <- function(pointer){
 	f <- function(xp){
 		force(xp)

Modified: pkg/Rcpp/inst/ChangeLog
===================================================================
--- pkg/Rcpp/inst/ChangeLog	2010-09-15 19:51:25 UTC (rev 2113)
+++ pkg/Rcpp/inst/ChangeLog	2010-09-16 09:35:12 UTC (rev 2114)
@@ -1,3 +1,11 @@
+2010-09-16  Romain Francois <romain at r-enthusiasts.com>
+
+    * R/00_classes.R: moving classes definition here
+    
+    * inst/Rcpp/Module.h: added C++ class S4_field that builds S4 objects of 
+    class C++Field. Build the list of fields as part of the creation of the 
+    C++Class objects
+
 2010-09-15  Romain Francois <romain at r-enthusiasts.com>
 
     * DESCRIPTION: added the declaration MinimumSvnRev to control which version

Modified: pkg/Rcpp/inst/include/Rcpp/Module.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/Module.h	2010-09-15 19:51:25 UTC (rev 2113)
+++ pkg/Rcpp/inst/include/Rcpp/Module.h	2010-09-16 09:35:12 UTC (rev 2114)
@@ -164,15 +164,15 @@
 		virtual std::string get_class(){ return ""; }
 } ;
 
-//// template <typename Class>
-//// class S4_field : public Rcpp::S4 {
-//// public:
-////     S4_field( CppProperty<Class>* p ) : S4( "C++Field" ){
-////         slot( "read_only" ) = p->is_readonly() ;
-////         slot( "cpp_class" ) = p->get_class();
-////         slot( "pointer" )   = Rcpp::XPtr< CppProperty<Class> >( p, false ) ;
-////     }
-//// } ;
+template <typename Class>
+class S4_field : public Rcpp::S4 {
+public:
+    S4_field( CppProperty<Class>* p ) : S4( "C++Field" ){
+        slot( "read_only" ) = p->is_readonly() ;
+        slot( "cpp_class" ) = p->get_class();
+        slot( "pointer" )   = Rcpp::XPtr< CppProperty<Class> >( p, false ) ;
+    }
+} ;
 
 
 #include <Rcpp/module/Module_Property.h>
@@ -357,18 +357,18 @@
 	VOID_END_RCPP
 	}
 	
-	//// Rcpp::List fields( ){
-	////     int n = properties.size() ;
-	//// 	Rcpp::CharacterVector pnames(n) ;
-	//// 	Rcpp::List out(n) ;
-	//// 	typename PROPERTY_MAP::iterator it = properties.begin( ) ;
-	//// 	for( int i=0; i<n; i++, ++it){
-	//// 		pnames[i] = it->first ;
-	//// 		out[i] = S4_field<Class>( it->second ) ; 
-	//// 	} 
-	//// 	out.names() = pnames ;
-	//// 	return out ;
-	//// }
+	Rcpp::List fields( ){
+	    int n = properties.size() ;
+		Rcpp::CharacterVector pnames(n) ;
+		Rcpp::List out(n) ;
+		typename PROPERTY_MAP::iterator it = properties.begin( ) ;
+		for( int i=0; i<n; i++, ++it){
+			pnames[i] = it->first ;
+			out[i] = S4_field<Class>( it->second ) ; 
+		} 
+		out.names() = pnames ;
+		return out ;
+	}
 
 #include <Rcpp/module/Module_Field.h>
 

Modified: pkg/Rcpp/man/CppClass-class.Rd
===================================================================
--- pkg/Rcpp/man/CppClass-class.Rd	2010-09-15 19:51:25 UTC (rev 2113)
+++ pkg/Rcpp/man/CppClass-class.Rd	2010-09-16 09:35:12 UTC (rev 2114)
@@ -18,6 +18,7 @@
   	\item{\code{.Data}:}{mangled name of the class}
     \item{\code{pointer}:}{external pointer to the internal infomation}
     \item{\code{module}:}{external pointer to the module}
+    \item{\code{fields}:}{list of \linkS4class{C++Field} objects}
   }
 }
 \section{Methods}{

Added: pkg/Rcpp/man/CppField-class.Rd
===================================================================
--- pkg/Rcpp/man/CppField-class.Rd	                        (rev 0)
+++ pkg/Rcpp/man/CppField-class.Rd	2010-09-16 09:35:12 UTC (rev 2114)
@@ -0,0 +1,27 @@
+\name{C++Field-class}
+\Rdversion{1.1}
+\docType{class}
+\alias{C++Field-class}
+
+\title{Class "C++Field"}
+\description{
+Metadata associated with a field of a class exposed through Rcpp modules
+}
+\section{Slots}{
+  \describe{
+    \item{\code{pointer}:}{external pointer to the internal (C++) object that represents fields}
+    \item{\code{cpp_class}:}{(demangled) name of the C++ class of the field}
+    \item{\code{read_only}:}{Is this field read only}
+  }
+}
+\section{Methods}{
+No methods defined with class "C++Field" in the signature.
+}
+\seealso{
+    The \code{fields} slot of the \code{\linkS4class{C++Class}} class is a 
+    list of \code{C++Field} objects
+}
+\examples{
+showClass("C++Field")
+}
+\keyword{classes}

Modified: pkg/Rcpp/src/Module.cpp
===================================================================
--- pkg/Rcpp/src/Module.cpp	2010-09-15 19:51:25 UTC (rev 2113)
+++ pkg/Rcpp/src/Module.cpp	2010-09-16 09:35:12 UTC (rev 2114)
@@ -273,7 +273,7 @@
 		mangled_name += cl->name ;
 		slot( ".Data" ) = mangled_name ;
 		
-		//// slot( "fields" ) = cl->fields() ;
+		slot( "fields" ) = cl->fields() ;
 		
 	}
 



More information about the Rcpp-commits mailing list