Main Page
Modules
Data Structures
Files
File List
Globals
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
aerospike
as_boolean.h
Go to the documentation of this file.
1
/*
2
* Copyright 2008-2016 Aerospike, Inc.
3
*
4
* Portions may be licensed to Aerospike, Inc. under one or more contributor
5
* license agreements.
6
*
7
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
8
* use this file except in compliance with the License. You may obtain a copy of
9
* the License at http://www.apache.org/licenses/LICENSE-2.0
10
*
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
* License for the specific language governing permissions and limitations under
15
* the License.
16
*/
17
18
#pragma once
19
20
#include <
aerospike/as_util.h
>
21
#include <
aerospike/as_val.h
>
22
23
#include <stdbool.h>
24
25
#ifdef __cplusplus
26
extern
"C"
{
27
#endif
28
29
/******************************************************************************
30
* TYPES
31
******************************************************************************/
32
33
/**
34
* Boolean value.
35
*
36
* To use the boolean value, you should use one of the two constants:
37
*
38
* as_boolean as_true;
39
* as_boolean as_false;
40
*
41
* Both `as_boolean_init()` and `as_boolean_new()` should be used sparingly.
42
*
43
* @extends as_val
44
* @ingroup aerospike_t
45
*/
46
typedef
struct
as_boolean_s {
47
48
/**
49
* @private
50
* as_boolean is a subtype of as_val.
51
* You can cast as_boolean to as_val.
52
*/
53
as_val
_
;
54
55
/**
56
* The boolean value.
57
*/
58
bool
value
;
59
60
}
as_boolean
;
61
62
/******************************************************************************
63
* CONSTANTS
64
*****************************************************************************/
65
66
/**
67
* True value.
68
*
69
* Use this when you need to use an `as_boolean` containing `true`,
70
* rather than allocating a new `as_boolean`.
71
*/
72
extern
const
as_boolean
as_true
;
73
74
/**
75
* False value.
76
*
77
* Use this when you need to use an `as_boolean` containing `true`,
78
* rather than allocating a new `as_boolean`.
79
*/
80
extern
const
as_boolean
as_false
;
81
82
/******************************************************************************
83
* INSTANCE FUNCTIONS
84
******************************************************************************/
85
86
/**
87
* Initialize a stack allocated `as_boolean` with the given boolean value.
88
*
89
* @param boolean The `as_boolean` to initialize.
90
* @param value The bool value.
91
*
92
* @return On success, the initialized value. Otherwise NULL.
93
*
94
* @relatesalso as_boolean
95
*/
96
as_boolean
*
as_boolean_init
(
as_boolean
*
boolean
,
bool
value);
97
98
/**
99
* Creates a new heap allocated `as_boolean` and initializes with
100
* the given boolean value.
101
*
102
* @param value The bool value.
103
*
104
* @return On success, the newly allocated value. Otherwise NULL.
105
*
106
* @relatesalso as_boolean
107
*/
108
as_boolean
*
as_boolean_new
(
bool
value);
109
110
/**
111
* Destroy the `as_boolean` and release associated resources.
112
*
113
* @param boolean The `as_boolean` to destroy.
114
*
115
* @relatesalso as_boolean
116
*/
117
static
inline
void
as_boolean_destroy
(
as_boolean
*
boolean
) {
118
as_val_destroy
((
as_val
*)
boolean
);
119
}
120
121
/******************************************************************************
122
* VALUE FUNCTIONS
123
******************************************************************************/
124
125
/**
126
* Get the bool value. If boolean is NULL, then return the fallback value.
127
*
128
* @relatesalso as_boolean
129
*/
130
static
inline
bool
as_boolean_getorelse
(
const
as_boolean
*
boolean
,
bool
fallback) {
131
return
boolean
?
boolean
->value : fallback;
132
}
133
134
/**
135
* Get the bool value.
136
*
137
* @relatesalso as_boolean
138
*/
139
static
inline
bool
as_boolean_get
(
const
as_boolean
*
boolean
) {
140
return
as_boolean_getorelse
(
boolean
,
false
);
141
}
142
143
/**
144
* Get the bool value.
145
* @deprecated Use as_boolean_get() instead.
146
*
147
* @relatesalso as_boolean
148
*/
149
static
inline
bool
as_boolean_tobool
(
const
as_boolean
*
boolean
) {
150
return
as_boolean_getorelse
(
boolean
,
false
);
151
}
152
153
/******************************************************************************
154
* CONVERSION FUNCTIONS
155
*****************************************************************************/
156
157
/**
158
* Convert to an as_val.
159
*
160
* @relatesalso as_boolean
161
*/
162
static
inline
as_val
*
as_boolean_toval
(
const
as_boolean
*
boolean
) {
163
return
(
as_val
*) boolean;
164
}
165
166
/**
167
* Convert from an as_val.
168
*
169
* @relatesalso as_boolean
170
*/
171
static
inline
as_boolean
*
as_boolean_fromval
(
const
as_val
* v) {
172
return
as_util_fromval
(v,
AS_BOOLEAN
,
as_boolean
);
173
}
174
175
/******************************************************************************
176
* as_val FUNCTIONS
177
*****************************************************************************/
178
179
/**
180
* @private
181
* Internal helper function for destroying an as_val.
182
*/
183
void
as_boolean_val_destroy
(
as_val
* v);
184
185
/**
186
* @private
187
* Internal helper function for getting the hashcode of an as_val.
188
*/
189
uint32_t
as_boolean_val_hashcode
(
const
as_val
* v);
190
191
/**
192
* @private
193
* Internal helper function for getting the string representation of an as_val.
194
*/
195
char
*
as_boolean_val_tostring
(
const
as_val
* v);
196
197
#ifdef __cplusplus
198
}
// end extern "C"
199
#endif