| 25 | namespace Rcpp{ |
| 26 | |
| 27 | RCPP_API_CLASS(Promise_Impl) { |
| 28 | public: |
| 29 | RCPP_GENERATE_CTOR_ASSIGN(Promise_Impl) |
| 30 | |
| 31 | Promise_Impl( SEXP x){ |
| 32 | if( TYPEOF(x) != PROMSXP) { |
| 33 | const char* fmt = "Not a promise: [type = %s]."; |
| 34 | throw not_compatible(fmt, Rf_type2char(TYPEOF(x))); |
| 35 | } |
| 36 | |
| 37 | Storage::set__(x) ; |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Return the result of the PRSEEN macro |
| 42 | */ |
| 43 | int seen() const { |
| 44 | return PRSEEN(Storage::get__()); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Return the result of the PRVALUE macro on the promise |
| 49 | */ |
| 50 | SEXP value() const{ |
| 51 | if (!was_evaluated()) throw unevaluated_promise(); |
| 52 | return PRVALUE(Storage::get__()); |
| 53 | } |
| 54 | |
| 55 | bool was_evaluated() const { |
| 56 | #if R_VERSION < R_Version(4,6,0) |
| 57 | return PRVALUE(Storage::get__()) != R_UnboundValue ; |
| 58 | #else |
| 59 | SEXP env = environment(); |
| 60 | R_BindingType_t bt = R_GetBindingType(Storage::get__(), env); |
| 61 | return bt != R_BindingTypeUnbound; |
| 62 | #endif |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * The promise expression: PRCODE |
| 67 | */ |
| 68 | ExpressionVector expression() const { |
| 69 | return ExpressionVector(PRCODE( Storage::get__() )) ; |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * The promise environment : PRENV |
| 74 | */ |
| 75 | Environment environment() const { |
| 76 | return Environment( PRENV(Storage::get__() ) ) ; |
| 77 | } |
| 78 | |
| 79 | inline void update(SEXP data){} |
| 80 | |
| 81 | } ; |
| 82 | |
| 83 | typedef Promise_Impl<PreserveStorage> Promise ; |
| 84 |
nothing calls this directly
no outgoing calls
no test coverage detected