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-2014 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
/******************************************************************************
26
* TYPES
27
******************************************************************************/
28
29
/**
30
* Boolean value.
31
*
32
* To use the boolean value, you should use one of the two constants:
33
*
34
* as_boolean as_true;
35
* as_boolean as_false;
36
*
37
* Both `as_boolean_init()` and `as_boolean_new()` should be used sparingly.
38
*
39
* @extends as_val
40
* @ingroup aerospike_t
41
*/
42
typedef
struct
as_boolean_s {
43
44
/**
45
* @private
46
* as_boolean is a subtype of as_val.
47
* You can cast as_boolean to as_val.
48
*/
49
as_val
_
;
50
51
/**
52
* The boolean value.
53
*/
54
bool
value
;
55
56
}
as_boolean
;
57
58
/******************************************************************************
59
* CONSTANTS
60
*****************************************************************************/
61
62
/**
63
* True value.
64
*
65
* Use this when you need to use an `as_boolean` containing `true`,
66
* rather than allocating a new `as_boolean`.
67
*/
68
extern
const
as_boolean
as_true
;
69
70
/**
71
* False value.
72
*
73
* Use this when you need to use an `as_boolean` containing `true`,
74
* rather than allocating a new `as_boolean`.
75
*/
76
extern
const
as_boolean
as_false
;
77
78
/******************************************************************************
79
* INSTANCE FUNCTIONS
80
******************************************************************************/
81
82
/**
83
* Initialize a stack allocated `as_boolean` with the given boolean value.
84
*
85
* @param boolean The `as_boolean` to initialize.
86
* @param value The bool value.
87
*
88
* @return On success, the initialized value. Otherwise NULL.
89
*
90
* @relatesalso as_boolean
91
*/
92
as_boolean
*
as_boolean_init
(
as_boolean
*
boolean
,
bool
value);
93
94
/**
95
* Creates a new heap allocated `as_boolean` and initializes with
96
* the given boolean value.
97
*
98
* @param value The bool value.
99
*
100
* @return On success, the newly allocated value. Otherwise NULL.
101
*
102
* @relatesalso as_boolean
103
*/
104
as_boolean
*
as_boolean_new
(
bool
value);
105
106
/**
107
* Destroy the `as_boolean` and release associated resources.
108
*
109
* @param boolean The `as_boolean` to destroy.
110
*
111
* @relatesalso as_boolean
112
*/
113
static
inline
void
as_boolean_destroy
(
as_boolean
*
boolean
) {
114
as_val_destroy
((
as_val
*)
boolean
);
115
}
116
117
/******************************************************************************
118
* VALUE FUNCTIONS
119
******************************************************************************/
120
121
/**
122
* Get the bool value. If boolean is NULL, then return the fallback value.
123
*
124
* @relatesalso as_boolean
125
*/
126
static
inline
bool
as_boolean_getorelse
(
const
as_boolean
*
boolean
,
bool
fallback) {
127
return
boolean
?
boolean
->value : fallback;
128
}
129
130
/**
131
* Get the bool value.
132
*
133
* @relatesalso as_boolean
134
*/
135
static
inline
bool
as_boolean_get
(
const
as_boolean
*
boolean
) {
136
return
as_boolean_getorelse
(
boolean
,
false
);
137
}
138
139
/**
140
* Get the bool value.
141
* @deprecated Use as_boolean_get() instead.
142
*
143
* @relatesalso as_boolean
144
*/
145
static
inline
bool
as_boolean_tobool
(
const
as_boolean
*
boolean
) {
146
return
as_boolean_getorelse
(
boolean
,
false
);
147
}
148
149
/******************************************************************************
150
* CONVERSION FUNCTIONS
151
*****************************************************************************/
152
153
/**
154
* Convert to an as_val.
155
*
156
* @relatesalso as_boolean
157
*/
158
static
inline
as_val
*
as_boolean_toval
(
const
as_boolean
*
boolean
) {
159
return
(
as_val
*) boolean;
160
}
161
162
/**
163
* Convert from an as_val.
164
*
165
* @relatesalso as_boolean
166
*/
167
static
inline
as_boolean
*
as_boolean_fromval
(
const
as_val
* v) {
168
return
as_util_fromval
(v,
AS_BOOLEAN
,
as_boolean
);
169
}
170
171
/******************************************************************************
172
* as_val FUNCTIONS
173
*****************************************************************************/
174
175
/**
176
* @private
177
* Internal helper function for destroying an as_val.
178
*/
179
void
as_boolean_val_destroy
(
as_val
* v);
180
181
/**
182
* @private
183
* Internal helper function for getting the hashcode of an as_val.
184
*/
185
uint32_t
as_boolean_val_hashcode
(
const
as_val
* v);
186
187
/**
188
* @private
189
* Internal helper function for getting the string representation of an as_val.
190
*/
191
char
*
as_boolean_val_tostring
(
const
as_val
* v);