[Rcpp-commits] r2083 - in pkg/Rcpp: inst inst/include/Rcpp inst/include/Rcpp/module src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Sep 8 10:51:53 CEST 2010


Author: romain
Date: 2010-09-08 10:51:53 +0200 (Wed, 08 Sep 2010)
New Revision: 2083

Modified:
   pkg/Rcpp/inst/ChangeLog
   pkg/Rcpp/inst/include/Rcpp/Module.h
   pkg/Rcpp/inst/include/Rcpp/module/Module_Field.h
   pkg/Rcpp/inst/include/Rcpp/module/Module_Property.h
   pkg/Rcpp/src/Module.cpp
Log:
acces to the demangled C++ class name of a property

Modified: pkg/Rcpp/inst/ChangeLog
===================================================================
--- pkg/Rcpp/inst/ChangeLog	2010-09-08 08:34:42 UTC (rev 2082)
+++ pkg/Rcpp/inst/ChangeLog	2010-09-08 08:51:53 UTC (rev 2083)
@@ -12,6 +12,12 @@
     * src/Module.cpp : added R access (.Call) function CppClass__property_is_readonly 
 	to query if a class property is read only
 
+    * inst/include/Rcpp/Module.h : added class_Base::property_class method
+	to grab the C++ class of a property
+
+    * src/Module.cpp : added R access (.Call) function CppClass__property_class 
+	to grab the C++ class of a property
+
 2010-09-06  Dirk Eddelbuettel  <edd at debian.org>
 
 	* inst/examples/ConvolveBenchmarks/exampleRCode.r: Rewritten /

Modified: pkg/Rcpp/inst/include/Rcpp/Module.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/Module.h	2010-09-08 08:34:42 UTC (rev 2082)
+++ pkg/Rcpp/inst/include/Rcpp/Module.h	2010-09-08 08:51:53 UTC (rev 2083)
@@ -68,6 +68,7 @@
 	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 ; }
+	virtual std::string property_class(const std::string& ) throw(std::range_error){ return "" ; }
 	
 	virtual Rcpp::CharacterVector complete(){ return Rcpp::CharacterVector(0) ; }
 	virtual ~class_Base(){}
@@ -156,6 +157,7 @@
 		virtual SEXP get(Class* ) throw(std::range_error){ throw std::range_error("cannot retrieve property"); }
 		virtual void set(Class*, SEXP) throw(std::range_error){ throw std::range_error("cannot set property"); }
 		virtual bool is_readonly(){ return false; }
+		virtual std::string get_class(){ return ""; }
 } ;
 
 #include <Rcpp/module/Module_Property.h>
@@ -228,6 +230,11 @@
 		if( it == properties.end() ) throw std::range_error( "no such property" ) ;
 		return it->second->is_readonly() ;
 	}
+	std::string property_class(const std::string& p) throw(std::range_error) {
+		typename PROPERTY_MAP::iterator it = properties.find( p ) ;
+		if( it == properties.end() ) throw std::range_error( "no such property" ) ;
+		return it->second->get_class() ;
+	}
 	
 	Rcpp::CharacterVector method_names(){
 		int n = methods.size() ;

Modified: pkg/Rcpp/inst/include/Rcpp/module/Module_Field.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/module/Module_Field.h	2010-09-08 08:34:42 UTC (rev 2082)
+++ pkg/Rcpp/inst/include/Rcpp/module/Module_Field.h	2010-09-08 08:51:53 UTC (rev 2083)
@@ -28,14 +28,16 @@
 		public: 	
 			typedef PROP Class::*pointer ;
 			
-			CppProperty_Getter_Setter( pointer ptr_ ) : ptr(ptr_) {}
+			CppProperty_Getter_Setter( pointer ptr_ ) : ptr(ptr_), class_name(DEMANGLE(PROP)) {}
 			
 			SEXP get(Class* object) throw(std::range_error){ return Rcpp::wrap( object->*ptr ) ; }
 			void set(Class* object, SEXP value) throw(std::range_error){ object->*ptr = Rcpp::as<PROP>( value ) ; }		
 			bool is_readonly(){ return false ; }
+			std::string get_class(){ return class_name; }
 			
 		private:
 			pointer ptr ;
+			std::string class_name ;
 	} ;
 	
 	
@@ -45,14 +47,16 @@
 		public: 	
 			typedef PROP Class::*pointer ;
 			
-			CppProperty_Getter( pointer ptr_ ) : ptr(ptr_) {}
+			CppProperty_Getter( pointer ptr_ ) : ptr(ptr_), class_name(DEMANGLE(PROP)) {}
 			
 			SEXP get(Class* object) throw(std::range_error){ return Rcpp::wrap( object->*ptr ) ; }
 			void set(Class* object, SEXP value) throw(std::range_error){ throw std::range_error("read only data member") ; }		
 			bool is_readonly(){ return true ; }
-
+			std::string get_class(){ return class_name; }
+			
 		private:
 			pointer ptr ;
+			std::string class_name ;
 	} ;
 
 	

Modified: pkg/Rcpp/inst/include/Rcpp/module/Module_Property.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/module/Module_Property.h	2010-09-08 08:34:42 UTC (rev 2082)
+++ pkg/Rcpp/inst/include/Rcpp/module/Module_Property.h	2010-09-08 08:51:53 UTC (rev 2083)
@@ -29,7 +29,7 @@
 		typedef PROP (Class::*GetMethod)(void) ;
 		typedef CppProperty<Class> prop_class ;
 
-		CppProperty_GetMethod( GetMethod getter_ ) : getter(getter_){}
+		CppProperty_GetMethod( GetMethod getter_ ) : getter(getter_), class_name(DEMANGLE(PROP)){}
 		
 		SEXP get(Class* object) throw(std::range_error){ return Rcpp::wrap( (object->*getter)() ) ; }
 		void set(Class*, SEXP) throw(std::range_error){ throw std::range_error("property is read only") ; }		
@@ -37,6 +37,7 @@
 		
 	private:
 		GetMethod getter ;
+		std::string class_name ;
 				
 } ;
 
@@ -47,7 +48,7 @@
 		typedef PROP (Class::*GetMethod)(void) const ;
 		typedef CppProperty<Class> prop_class ;
 
-		CppProperty_GetConstMethod( GetMethod getter_ ) : getter(getter_){}
+		CppProperty_GetConstMethod( GetMethod getter_ ) : getter(getter_), class_name(DEMANGLE(PROP)){}
 		
 		SEXP get(Class* object) throw(std::range_error){ return Rcpp::wrap( (object->*getter)() ) ; }
 		void set(Class*, SEXP) throw(std::range_error){ throw std::range_error("property is read only") ; }		
@@ -55,6 +56,7 @@
 
 	private:
 		GetMethod getter ;
+		std::string class_name ;
 				
 } ;
 
@@ -66,7 +68,7 @@
 		typedef PROP (*GetMethod)(Class*) ;
 		typedef CppProperty<Class> prop_class ;
 
-		CppProperty_GetPointerMethod( GetMethod getter_ ) : getter(getter_){}
+		CppProperty_GetPointerMethod( GetMethod getter_ ) : getter(getter_), class_name(DEMANGLE(PROP)){}
 		
 		SEXP get(Class* object) throw(std::range_error){ return Rcpp::wrap( getter(object) ) ; }
 		void set(Class*, SEXP) throw(std::range_error){ throw std::range_error("property is read only") ; }		
@@ -74,7 +76,7 @@
 
 	private:
 		GetMethod getter ;
-				
+		std::string class_name ;				
 } ;
 
 
@@ -86,7 +88,7 @@
 		typedef void (Class::*SetMethod)(PROP) ;
 		typedef CppProperty<Class> prop_class ;
 
-		CppProperty_GetMethod_SetMethod( GetMethod getter_, SetMethod setter_) : getter(getter_), setter(setter_){}
+		CppProperty_GetMethod_SetMethod( GetMethod getter_, SetMethod setter_) : getter(getter_), setter(setter_), class_name(DEMANGLE(PROP)){}
 		
 		SEXP get(Class* object) throw(std::range_error){ 
 			return Rcpp::wrap( (object->*getter)() ) ; 
@@ -101,7 +103,7 @@
 	private:
 		GetMethod getter ;
 		SetMethod setter ;
-				
+		std::string class_name ;				
 } ;
 template <typename Class, typename PROP>
 class CppProperty_GetConstMethod_SetMethod : public CppProperty<Class> {
@@ -110,7 +112,7 @@
 		typedef void (Class::*SetMethod)(PROP) ;
 		typedef CppProperty<Class> prop_class ;
 
-		CppProperty_GetConstMethod_SetMethod( GetMethod getter_, SetMethod setter_) : getter(getter_), setter(setter_){}
+		CppProperty_GetConstMethod_SetMethod( GetMethod getter_, SetMethod setter_) : getter(getter_), setter(setter_), class_name(DEMANGLE(PROP)){}
 		
 		SEXP get(Class* object) throw(std::range_error){ 
 			return Rcpp::wrap( (object->*getter)() ) ; 
@@ -125,6 +127,7 @@
 	private:
 		GetMethod getter ;
 		SetMethod setter ;
+		std::string class_name ;
 				
 } ;
 
@@ -139,7 +142,7 @@
 		typedef void (*SetMethod)(Class*,PROP) ;
 		typedef CppProperty<Class> prop_class ;
 
-		CppProperty_GetMethod_SetPointer( GetMethod getter_, SetMethod setter_) : getter(getter_), setter(setter_){}
+		CppProperty_GetMethod_SetPointer( GetMethod getter_, SetMethod setter_) : getter(getter_), setter(setter_), class_name(DEMANGLE(PROP)){}
 		
 		SEXP get(Class* object) throw(std::range_error){ 
 			return Rcpp::wrap( (object->*getter)() ) ;
@@ -154,6 +157,7 @@
 	private:
 		GetMethod getter ;
 		SetMethod setter ;
+		std::string class_name ;
 				
 } ;
 template <typename Class, typename PROP>
@@ -163,7 +167,7 @@
 		typedef void (*SetMethod)(Class*,PROP) ;
 		typedef CppProperty<Class> prop_class ;
 
-		CppProperty_GetConstMethod_SetPointer( GetMethod getter_, SetMethod setter_) : getter(getter_), setter(setter_){}
+		CppProperty_GetConstMethod_SetPointer( GetMethod getter_, SetMethod setter_) : getter(getter_), setter(setter_), class_name(DEMANGLE(PROP)){}
 		
 		SEXP get(Class* object) throw(std::range_error){ 
 			return Rcpp::wrap( (object->*getter)() ) ;
@@ -178,6 +182,7 @@
 	private:
 		GetMethod getter ;
 		SetMethod setter ;
+		std::string class_name ;
 				
 } ;
 
@@ -189,7 +194,7 @@
 		typedef void (Class::*SetMethod)(PROP) ;
 		typedef CppProperty<Class> prop_class ;
 
-		CppProperty_GetPointer_SetMethod( GetMethod getter_, SetMethod setter_) : getter(getter_), setter(setter_){}
+		CppProperty_GetPointer_SetMethod( GetMethod getter_, SetMethod setter_) : getter(getter_), setter(setter_), class_name(DEMANGLE(PROP)){}
 		
 		SEXP get(Class* object) throw(std::range_error){ 
 			return Rcpp::wrap( getter(object) ) ;
@@ -204,6 +209,7 @@
 	private:
 		GetMethod getter ;
 		SetMethod setter ;
+		std::string class_name ;
 				
 } ;
 
@@ -216,7 +222,7 @@
 		typedef void (*SetMethod)(Class*,PROP) ;
 		typedef CppProperty<Class> prop_class ;
 
-		CppProperty_GetPointer_SetPointer( GetMethod getter_, SetMethod setter_) : getter(getter_), setter(setter_){}
+		CppProperty_GetPointer_SetPointer( GetMethod getter_, SetMethod setter_) : getter(getter_), setter(setter_), class_name(DEMANGLE(PROP)){}
 		
 		SEXP get(Class* object) throw(std::range_error){ 
 			return Rcpp::wrap( getter(object) ) ;
@@ -231,7 +237,8 @@
 	private:
 		GetMethod getter ;
 		SetMethod setter ;
-				
+		std::string class_name ;
+		
 } ;
 
 

Modified: pkg/Rcpp/src/Module.cpp
===================================================================
--- pkg/Rcpp/src/Module.cpp	2010-09-08 08:34:42 UTC (rev 2082)
+++ pkg/Rcpp/src/Module.cpp	2010-09-08 08:51:53 UTC (rev 2083)
@@ -59,6 +59,10 @@
 RCPP_FUNCTION_2( bool, CppClass__property_is_readonly, XP_Class cl, std::string p){
 	return cl->property_is_readonly(p) ;
 }
+RCPP_FUNCTION_2( std::string, CppClass__property_class, XP_Class cl, std::string p){
+	return cl->property_class(p) ;
+}
+
 RCPP_FUNCTION_1( Rcpp::IntegerVector, Module__funtions_arity, XP_Module module ){
 	return module->	functions_arity() ;
 }



More information about the Rcpp-commits mailing list