MCPcopy Create free account
hub / github.com/RcppCore/Rcpp / SingleLogicalResult

Class SingleLogicalResult

inst/include/Rcpp/sugar/logical/SingleLogicalResult.h:42–99  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40
41template <bool NA,typename T>
42class SingleLogicalResult {
43public:
44 const static int UNRESOLVED = -5 ;
45
46 SingleLogicalResult() : result(UNRESOLVED) {} ;
47
48 void apply(){
49 if( result == UNRESOLVED ){
50 static_cast<T&>(*this).apply() ;
51 }
52 }
53
54 inline bool is_true(){
55 apply() ;
56 return result == TRUE ;
57 }
58
59 inline bool is_false(){
60 apply() ;
61 return result == FALSE ;
62 }
63
64 inline bool is_na(){
65 apply() ;
66 return Rcpp::traits::is_na<LGLSXP>( result ) ;
67 }
68
69 inline operator SEXP(){
70 return get_sexp() ;
71 }
72
73 inline operator bool(){
74 conversion_to_bool_is_forbidden<!NA> x ;
75 x.touch() ;
76 return is_true() ;
77 }
78
79 inline int size(){ return 1 ; }
80
81 inline int get(){
82 apply();
83 return result;
84 }
85
86 inline SEXP get_sexp(){
87 apply() ;
88 return Rf_ScalarLogical( result ) ;
89 }
90
91protected:
92 int result ;
93 inline void set(int x){ result = x ;}
94 inline void reset(){ set(UNRESOLVED) ; }
95 inline void set_true(){ set(TRUE); }
96 inline void set_false(){ set(FALSE); }
97 inline void set_na(){ set(NA_LOGICAL); }
98 inline bool is_unresolved(){ return result == UNRESOLVED ; }
99} ;

Callers

nothing calls this directly

Calls 2

is_trueFunction · 0.85
touchMethod · 0.80

Tested by

no test coverage detected