[Rcpp-commits] r2082 - 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:34:42 CEST 2010
Author: romain
Date: 2010-09-08 10:34:42 +0200 (Wed, 08 Sep 2010)
New Revision: 2082
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:
tools to query if a property is read only
Modified: pkg/Rcpp/inst/ChangeLog
===================================================================
--- pkg/Rcpp/inst/ChangeLog 2010-09-08 07:43:44 UTC (rev 2081)
+++ pkg/Rcpp/inst/ChangeLog 2010-09-08 08:34:42 UTC (rev 2082)
@@ -1,10 +1,17 @@
2010-09-10 Romain Francois <romain at r-enthusiasts.com>
- * inst/include/Rcpp/Module.h : added class_Base::property_names method
+ * inst/include/Rcpp/Module.h : added class_Base::property_names method
to grab the names of all fields (properties)
- * src/Module.cpp : added R access (.Call) function CppClass__properties
+
+ * src/Module.cpp : added R access (.Call) function CppClass__properties
to grab the names of the fields (property) from the XP of a class
+ * inst/include/Rcpp/Module.h : added class_Base::property_is_readonly method
+ to query if a property is read only
+
+ * src/Module.cpp : added R access (.Call) function CppClass__property_is_readonly
+ to query if a class property is read only
+
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 07:43:44 UTC (rev 2081)
+++ pkg/Rcpp/inst/include/Rcpp/Module.h 2010-09-08 08:34:42 UTC (rev 2082)
@@ -67,6 +67,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 Rcpp::CharacterVector complete(){ return Rcpp::CharacterVector(0) ; }
virtual ~class_Base(){}
@@ -154,6 +155,7 @@
CppProperty(){} ;
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; }
} ;
#include <Rcpp/module/Module_Property.h>
@@ -221,6 +223,11 @@
bool has_property( const std::string& m){
return properties.find(m) != properties.end() ;
}
+ bool property_is_readonly( 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->is_readonly() ;
+ }
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 07:43:44 UTC (rev 2081)
+++ pkg/Rcpp/inst/include/Rcpp/module/Module_Field.h 2010-09-08 08:34:42 UTC (rev 2082)
@@ -32,7 +32,8 @@
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 ; }
+
private:
pointer ptr ;
} ;
@@ -48,7 +49,8 @@
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 ; }
+
private:
pointer ptr ;
} ;
Modified: pkg/Rcpp/inst/include/Rcpp/module/Module_Property.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/module/Module_Property.h 2010-09-08 07:43:44 UTC (rev 2081)
+++ pkg/Rcpp/inst/include/Rcpp/module/Module_Property.h 2010-09-08 08:34:42 UTC (rev 2082)
@@ -33,7 +33,8 @@
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") ; }
-
+ bool is_readonly(){ return true ; }
+
private:
GetMethod getter ;
@@ -50,6 +51,7 @@
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") ; }
+ bool is_readonly(){ return true ; }
private:
GetMethod getter ;
@@ -68,6 +70,7 @@
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") ; }
+ bool is_readonly(){ return true ; }
private:
GetMethod getter ;
@@ -93,6 +96,7 @@
Rcpp::as< typename Rcpp::traits::remove_const_and_reference< PROP >::type >( value )
) ;
}
+ bool is_readonly(){ return false ; }
private:
GetMethod getter ;
@@ -116,6 +120,7 @@
Rcpp::as< typename Rcpp::traits::remove_const_and_reference< PROP >::type >( value )
) ;
}
+ bool is_readonly(){ return false ; }
private:
GetMethod getter ;
@@ -144,6 +149,7 @@
Rcpp::as< typename Rcpp::traits::remove_const_and_reference< PROP >::type >( value )
) ;
}
+ bool is_readonly(){ return false ; }
private:
GetMethod getter ;
@@ -167,6 +173,7 @@
Rcpp::as< typename Rcpp::traits::remove_const_and_reference< PROP >::type >( value )
) ;
}
+ bool is_readonly(){ return false ; }
private:
GetMethod getter ;
@@ -192,6 +199,7 @@
Rcpp::as< typename Rcpp::traits::remove_const_and_reference< PROP >::type >( value )
) ;
}
+ bool is_readonly(){ return false ; }
private:
GetMethod getter ;
@@ -218,6 +226,7 @@
Rcpp::as< typename Rcpp::traits::remove_const_and_reference< PROP >::type >( value )
) ;
}
+ bool is_readonly(){ return false ; }
private:
GetMethod getter ;
Modified: pkg/Rcpp/src/Module.cpp
===================================================================
--- pkg/Rcpp/src/Module.cpp 2010-09-08 07:43:44 UTC (rev 2081)
+++ pkg/Rcpp/src/Module.cpp 2010-09-08 08:34:42 UTC (rev 2082)
@@ -56,6 +56,9 @@
RCPP_FUNCTION_1( Rcpp::CharacterVector, CppClass__properties, XP_Class cl){
return cl->property_names() ;
}
+RCPP_FUNCTION_2( bool, CppClass__property_is_readonly, XP_Class cl, std::string p){
+ return cl->property_is_readonly(p) ;
+}
RCPP_FUNCTION_1( Rcpp::IntegerVector, Module__funtions_arity, XP_Module module ){
return module-> functions_arity() ;
}
More information about the Rcpp-commits
mailing list