Rcpp Version 1.0.9
SingleLogicalResult.h
Go to the documentation of this file.
1
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
2
//
3
// SingleLogicalResult.h: Rcpp R/C++ interface class library --
4
//
5
// Copyright (C) 2010 - 2012 Dirk Eddelbuettel and Romain Francois
6
//
7
// This file is part of Rcpp.
8
//
9
// Rcpp is free software: you can redistribute it and/or modify it
10
// under the terms of the GNU General Public License as published by
11
// the Free Software Foundation, either version 2 of the License, or
12
// (at your option) any later version.
13
//
14
// Rcpp is distributed in the hope that it will be useful, but
15
// WITHOUT ANY WARRANTY; without even the implied warranty of
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
// GNU General Public License for more details.
18
//
19
// You should have received a copy of the GNU General Public License
20
// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
21
22
#ifndef Rcpp__sugar__SingleLogicalResult_h
23
#define Rcpp__sugar__SingleLogicalResult_h
24
25
namespace
Rcpp
{
26
namespace
sugar{
27
28
template
<
bool
>
29
class
forbidden_conversion
;
30
31
template
<>
32
class
forbidden_conversion
<true>{} ;
33
34
template
<
bool
x>
35
class
conversion_to_bool_is_forbidden
:
36
forbidden_conversion
<x>{
37
public
:
38
void
touch
(){}
39
};
40
41
template
<
bool
NA,
typename
T>
42
class
SingleLogicalResult
{
43
public
:
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
91
protected
:
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
} ;
100
101
}
102
}
103
104
105
106
#endif
Rcpp::result
Definition:
Module.h:56
Rcpp::sugar::SingleLogicalResult
Definition:
SingleLogicalResult.h:42
Rcpp::sugar::SingleLogicalResult::SingleLogicalResult
SingleLogicalResult()
Definition:
SingleLogicalResult.h:46
Rcpp::sugar::SingleLogicalResult::is_unresolved
bool is_unresolved()
Definition:
SingleLogicalResult.h:98
Rcpp::sugar::SingleLogicalResult::set_false
void set_false()
Definition:
SingleLogicalResult.h:96
Rcpp::sugar::SingleLogicalResult::set_na
void set_na()
Definition:
SingleLogicalResult.h:97
Rcpp::sugar::SingleLogicalResult::set_true
void set_true()
Definition:
SingleLogicalResult.h:95
Rcpp::sugar::SingleLogicalResult::size
int size()
Definition:
SingleLogicalResult.h:79
Rcpp::sugar::SingleLogicalResult::result
int result
Definition:
SingleLogicalResult.h:92
Rcpp::sugar::SingleLogicalResult::set
void set(int x)
Definition:
SingleLogicalResult.h:93
Rcpp::sugar::SingleLogicalResult::is_na
bool is_na()
Definition:
SingleLogicalResult.h:64
Rcpp::sugar::SingleLogicalResult::apply
void apply()
Definition:
SingleLogicalResult.h:48
Rcpp::sugar::SingleLogicalResult::get_sexp
SEXP get_sexp()
Definition:
SingleLogicalResult.h:86
Rcpp::sugar::SingleLogicalResult::get
int get()
Definition:
SingleLogicalResult.h:81
Rcpp::sugar::SingleLogicalResult::UNRESOLVED
static const int UNRESOLVED
Definition:
SingleLogicalResult.h:44
Rcpp::sugar::SingleLogicalResult::is_false
bool is_false()
Definition:
SingleLogicalResult.h:59
Rcpp::sugar::SingleLogicalResult::reset
void reset()
Definition:
SingleLogicalResult.h:94
Rcpp::sugar::SingleLogicalResult::is_true
bool is_true()
Definition:
SingleLogicalResult.h:54
Rcpp::sugar::conversion_to_bool_is_forbidden
Definition:
SingleLogicalResult.h:36
Rcpp::sugar::conversion_to_bool_is_forbidden::touch
void touch()
Definition:
SingleLogicalResult.h:38
Rcpp::sugar::forbidden_conversion
Definition:
SingleLogicalResult.h:29
Rcpp::traits::is_na< LGLSXP >
bool is_na< LGLSXP >(int x)
Definition:
is_na.h:57
Rcpp
Rcpp API.
Definition:
algo.h:28
inst
include
Rcpp
sugar
logical
SingleLogicalResult.h
Generated on Sat Jul 9 2022 09:14:52 for Rcpp Version 1.0.9 by
1.9.1