Main Page
Modules
Data Structures
Files
File List
Globals
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
target
Linux-x86_64
include
aerospike
target/Linux-x86_64/include/aerospike/as_boolean.h
Go to the documentation of this file.
1
/******************************************************************************
2
* Copyright 2008-2013 by Aerospike.
3
*
4
* Permission is hereby granted, free of charge, to any person obtaining a copy
5
* of this software and associated documentation files (the "Software"), to
6
* deal in the Software without restriction, including without limitation the
7
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8
* sell copies of the Software, and to permit persons to whom the Software is
9
* furnished to do so, subject to the following conditions:
10
*
11
* The above copyright notice and this permission notice shall be included in
12
* all copies or substantial portions of the Software.
13
*
14
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20
* IN THE SOFTWARE.
21
*****************************************************************************/
22
23
#pragma once
24
25
#include <aerospike/as_util.h>
26
#include <aerospike/as_val.h>
27
28
#include <stdbool.h>
29
30
/******************************************************************************
31
* TYPES
32
******************************************************************************/
33
34
/**
35
* Boolean value.
36
*
37
* To use the boolean value, you should use one of the two constants:
38
*
39
* as_boolean as_true;
40
* as_boolean as_false;
41
*
42
* Both `as_boolean_init()` and `as_boolean_new()` should be used sparingly.
43
*
44
* @extends as_val
45
* @ingroup aerospike_t
46
*/
47
typedef
struct
as_boolean_s {
48
49
/**
50
* @private
51
* as_boolean is a subtype of as_val.
52
* You can cast as_boolean to as_val.
53
*/
54
as_val
_;
55
56
/**
57
* The boolean value.
58
*/
59
bool
value;
60
61
}
as_boolean
;
62
63
/******************************************************************************
64
* CONSTANTS
65
*****************************************************************************/
66
67
/**
68
* True value.
69
*
70
* Use this when you need to use an `as_boolean` containing `true`,
71
* rather than allocating a new `as_boolean`.
72
*/
73
extern
const
as_boolean
as_true
;
74
75
/**
76
* False value.
77
*
78
* Use this when you need to use an `as_boolean` containing `true`,
79
* rather than allocating a new `as_boolean`.
80
*/
81
extern
const
as_boolean
as_false
;
82
83
/******************************************************************************
84
* INSTANCE FUNCTIONS
85
******************************************************************************/
86
87
/**
88
* Initialize a stack allocated `as_boolean` with the given boolean value.
89
*
90
* @param boolean The `as_boolean` to initialize.
91
* @param value The bool value.
92
*
93
* @return On success, the initialized value. Otherwise NULL.
94
*
95
* @relatesalso as_boolean
96
*/
97
as_boolean
*
as_boolean_init
(
as_boolean
*
boolean
,
bool
value);
98
99
/**
100
* Creates a new heap allocated `as_boolean` and initializes with
101
* the given boolean value.
102
*
103
* @param value The bool value.
104
*
105
* @return On success, the newly allocated value. Otherwise NULL.
106
*
107
* @relatesalso as_boolean
108
*/
109
as_boolean
*
as_boolean_new
(
bool
value);
110
111
/**
112
* Destroy the `as_boolean` and release associated resources.
113
*
114
* @param boolean The `as_boolean` to destroy.
115
*
116
* @relatesalso as_boolean
117
*/
118
static
inline
void
as_boolean_destroy
(
as_boolean
*
boolean
) {
119
as_val_destroy
((
as_val
*)
boolean
);
120
}
121
122
/******************************************************************************
123
* VALUE FUNCTIONS
124
******************************************************************************/
125
126
/**
127
* Get the bool value. If boolean is NULL, then return the fallback value.
128
*
129
* @relatesalso as_boolean
130
*/
131
static
inline
bool
as_boolean_getorelse
(
const
as_boolean
*
boolean
,
bool
fallback) {
132
return
boolean
?
boolean
->value : fallback;
133
}
134
135
/**
136
* Get the bool value.
137
*
138
* @relatesalso as_boolean
139
*/
140
static
inline
bool
as_boolean_get
(
const
as_boolean
*
boolean
) {
141
return
as_boolean_getorelse
(
boolean
,
false
);
142
}
143
144
/**
145
* Get the bool value.
146
* @deprecated Use as_boolean_get() instead.
147
*
148
* @relatesalso as_boolean
149
*/
150
static
inline
bool
as_boolean_tobool
(
const
as_boolean
*
boolean
) {
151
return
as_boolean_getorelse
(
boolean
,
false
);
152
}
153
154
/******************************************************************************
155
* CONVERSION FUNCTIONS
156
*****************************************************************************/
157
158
/**
159
* Convert to an as_val.
160
*
161
* @relatesalso as_boolean
162
*/
163
static
inline
as_val
*
as_boolean_toval
(
const
as_boolean
*
boolean
) {
164
return
(
as_val
*) boolean;
165
}
166
167
/**
168
* Convert from an as_val.
169
*
170
* @relatesalso as_boolean
171
*/
172
static
inline
as_boolean
*
as_boolean_fromval
(
const
as_val
* v) {
173
return
as_util_fromval
(v,
AS_BOOLEAN
,
as_boolean
);
174
}
175
176
/******************************************************************************
177
* as_val FUNCTIONS
178
*****************************************************************************/
179
180
/**
181
* @private
182
* Internal helper function for destroying an as_val.
183
*/
184
void
as_boolean_val_destroy
(
as_val
* v);
185
186
/**
187
* @private
188
* Internal helper function for getting the hashcode of an as_val.
189
*/
190
uint32_t
as_boolean_val_hashcode
(
const
as_val
* v);
191
192
/**
193
* @private
194
* Internal helper function for getting the string representation of an as_val.
195
*/
196
char
*
as_boolean_val_tostring
(
const
as_val
* v);