[Rcpp-commits] r302 - in pkg/src: . Rcpp
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Jan 7 16:27:22 CET 2010
Author: romain
Date: 2010-01-07 16:27:21 +0100 (Thu, 07 Jan 2010)
New Revision: 302
Modified:
pkg/src/Promise.cpp
pkg/src/Rcpp/Promise.h
Log:
minor update of Promise
Modified: pkg/src/Promise.cpp
===================================================================
--- pkg/src/Promise.cpp 2010-01-07 15:16:32 UTC (rev 301)
+++ pkg/src/Promise.cpp 2010-01-07 15:27:21 UTC (rev 302)
@@ -27,6 +27,10 @@
namespace Rcpp {
+ const char* Promise::unevaluated_promise::what() throw() {
+ return "promise not yet evaluated" ;
+ }
+
Promise::Promise(SEXP x) throw(not_compatible) : RObject(){
if( TYPEOF(x) == PROMSXP ){
setSEXP( x ) ;
@@ -35,13 +39,19 @@
}
}
- int Promise::seen(){
+ int Promise::seen() const {
return PRSEEN(m_sexp);
}
- RObject Promise::value() const{
- return wrap( PRVALUE(m_sexp) ) ;
+ RObject Promise::value() const throw(unevaluated_promise) {
+ SEXP val = PRVALUE(m_sexp) ;
+ if( val == R_UnboundValue ) throw unevaluated_promise() ;
+ return wrap( val ) ;
}
+
+ bool Promise::was_evaluated() const {
+ return PRVALUE(m_sexp) != R_UnboundValue ;
+ }
Environment Promise::environment() const {
return Environment(PRENV(m_sexp)) ;
Modified: pkg/src/Rcpp/Promise.h
===================================================================
--- pkg/src/Rcpp/Promise.h 2010-01-07 15:16:32 UTC (rev 301)
+++ pkg/src/Rcpp/Promise.h 2010-01-07 15:27:21 UTC (rev 302)
@@ -32,18 +32,28 @@
class Promise : public RObject {
public:
+
+ class unevaluated_promise : public std::exception{
+ public:
+ unevaluated_promise() throw(){};
+ ~unevaluated_promise() throw(){} ;
+ const char* what() throw() ;
+ } ;
+
Promise( SEXP x) throw(not_compatible) ;
/**
* Return the result of the PRSEEN macro
*/
- int seen() ;
+ int seen() const ;
/**
* Return the result of the PRVALUE macro on the promise
*/
- RObject value() const ;
+ RObject value() const throw(unevaluated_promise) ;
+ bool was_evaluated() const ;
+
/**
* The promise expression: PRCODE
*/
More information about the Rcpp-commits
mailing list