[Rcpp-commits] r1171 - in pkg/Rcpp: inst/include/Rcpp inst/unitTests src
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed May 5 13:03:32 CEST 2010
Author: romain
Date: 2010-05-05 13:03:32 +0200 (Wed, 05 May 2010)
New Revision: 1171
Modified:
pkg/Rcpp/inst/include/Rcpp/S4.h
pkg/Rcpp/inst/unitTests/runit.S4.R
pkg/Rcpp/src/S4.cpp
Log:
S4( SlotProxy ) and S4( AttributeProxy )
Modified: pkg/Rcpp/inst/include/Rcpp/S4.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/S4.h 2010-05-05 10:29:07 UTC (rev 1170)
+++ pkg/Rcpp/inst/include/Rcpp/S4.h 2010-05-05 11:03:32 UTC (rev 1171)
@@ -39,7 +39,7 @@
*
* @param x must be an S4 object
*/
- S4(SEXP x);
+ S4(SEXP x) throw(not_s4) ;
/**
* copy constructor
@@ -48,11 +48,16 @@
*/
S4(const S4& other) ;
+ S4(const RObject::SlotProxy& proxy ) throw(not_s4) ;
+ S4(const RObject::AttributeProxy& proxy ) throw(not_s4);
+
/**
* assignment operator.
*/
S4& operator=( const S4& other);
+ S4& operator=( SEXP other ) throw(not_s4) ;
+
/**
* Creates an S4 object of the requested class.
*
@@ -66,6 +71,8 @@
*/
bool is( const std::string& clazz) ;
+private:
+ void set( SEXP x) throw(not_s4) ;
} ;
} // namespace Rcpp
Modified: pkg/Rcpp/inst/unitTests/runit.S4.R
===================================================================
--- pkg/Rcpp/inst/unitTests/runit.S4.R 2010-05-05 10:29:07 UTC (rev 1170)
+++ pkg/Rcpp/inst/unitTests/runit.S4.R 2010-05-05 11:03:32 UTC (rev 1171)
@@ -129,7 +129,7 @@
fx <- cppfunction( signature(tr="ANY"),
' S4 o(tr); return CharacterVector(o.slot("foo")); '
)
- checkEquals( fx(tr1), "bar", "Vector( AttributeProxy ) ambiguity" )
+ checkEquals( fx(x), "bar", "Vector( AttributeProxy ) ambiguity" )
}
Modified: pkg/Rcpp/src/S4.cpp
===================================================================
--- pkg/Rcpp/src/S4.cpp 2010-05-05 10:29:07 UTC (rev 1170)
+++ pkg/Rcpp/src/S4.cpp 2010-05-05 11:03:32 UTC (rev 1171)
@@ -27,23 +27,31 @@
S4::S4() : RObject(){}
- S4::S4(SEXP x) : RObject(){
- if( ! ::Rf_isS4(x) ){
- throw not_s4() ;
- } else{
- setSEXP( x) ;
- }
+ S4::S4(SEXP x) throw(not_s4) : RObject(){
+ set( x) ;
}
S4::S4( const S4& other) : RObject(){
setSEXP( other.asSexp() ) ;
}
+ S4::S4( const RObject::SlotProxy& proxy ) throw(not_s4) : RObject() {
+ set( proxy ) ;
+ }
+ S4::S4( const RObject::AttributeProxy& proxy ) throw(not_s4) : RObject() {
+ set( proxy ) ;
+ }
+
S4& S4::operator=( const S4& other){
setSEXP( other.asSexp() ) ;
return *this ;
}
+ S4& S4::operator=( SEXP other ) throw(not_s4) {
+ set( other ) ;
+ return *this ;
+ }
+
S4::S4( const std::string& klass ) throw(S4_creation_error) {
SEXP oo = PROTECT( R_do_new_object(R_do_MAKE_CLASS(klass.c_str())) ) ;
if (!Rf_inherits(oo, klass.c_str())) {
@@ -84,4 +92,12 @@
}
+ void S4::set( SEXP x) throw(not_s4) {
+ if( ! ::Rf_isS4(x) ){
+ throw not_s4() ;
+ } else{
+ setSEXP( x) ;
+ }
+ }
+
} // namespace Rcpp
More information about the Rcpp-commits
mailing list