Main Page
Modules
Data Structures
Files
File List
Globals
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
aerospike
as_val.h
Go to the documentation of this file.
1
/*
2
* Copyright 2008-2015 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 <citrusleaf/cf_atomic.h>
21
22
#include <stdbool.h>
23
#include <stdint.h>
24
25
#ifdef __cplusplus
26
extern
"C"
{
27
#endif
28
29
/******************************************************************************
30
* TYPES
31
*****************************************************************************/
32
33
/**
34
* as_val types
35
*/
36
typedef
enum
as_val_t
{
37
AS_UNDEF
= 0,
38
AS_UNKNOWN
= 0,
//<! @deprecated
39
AS_NIL
= 1,
40
AS_BOOLEAN
= 2,
41
AS_INTEGER
= 3,
42
AS_STRING
= 4,
43
AS_LIST
= 5,
44
AS_MAP
= 6,
45
AS_REC
= 7,
46
AS_PAIR
= 8,
47
AS_BYTES
= 9,
48
AS_DOUBLE
= 10,
49
AS_VAL_T_MAX
50
}
__attribute__
((packed))
as_val_t
;
51
52
/**
53
* Represents a value
54
* @ingroup aerospike_t
55
*/
56
typedef struct as_val_s {
57
58
/**
59
* Value type
60
*/
61
enum
as_val_t
type
;
62
63
/**
64
* Value can be freed.
65
* Should be false for stack allocated values.
66
*/
67
bool
free
;
68
69
/**
70
* Reference count
71
* Values are ref counted.
72
* To increment the count, use `as_val_reserve()`
73
*/
74
cf_atomic32
count
;
75
76
}
as_val
;
77
78
/******************************************************************************
79
* MACROS
80
*****************************************************************************/
81
82
/**
83
* Returns the `as_val.type` of a value.
84
*
85
* @param __v The `as_val` to get the type of
86
*
87
* @return An as_val_t value. If the type is unknown, then it will
88
* be AS_UNKNOWN.
89
*/
90
#define as_val_type(__v) (__v ? ((as_val *)__v)->type : AS_UNDEF)
91
92
/**
93
* Increment the `as_val.count` of a value.
94
*
95
* @param __v The `as_val` to be incremented.
96
*
97
* @return The value, with it's refcount incremented.
98
*/
99
#define as_val_reserve(__v) ( as_val_val_reserve((as_val *)__v) )
100
101
/**
102
* Decrement the `as_val.count` of a value. If `as_val.count` reaches 0 (zero) and
103
* `as_val.free` is true, then free the `as_val` instance.
104
*
105
* @param __v The `as_val` to be decremented.
106
*
107
* @return The value, if its `as_val.count` > 0. Otherwise NULL.
108
*/
109
#define as_val_destroy(__v) ( as_val_val_destroy((as_val *)__v) )
110
111
/**
112
* Get the hashcode value for the value.
113
*
114
* @param __v The `as_val` to get the hashcode value for.
115
*
116
* @return The hashcode value.
117
*/
118
#define as_val_hashcode(__v) ( as_val_val_hashcode((as_val *)__v) )
119
120
/**
121
* Get the string representation of the value.
122
*
123
* @param __v The `as_val` to get the string value for.
124
*
125
* @return The string representation on success. Otherwise NULL.
126
*/
127
#define as_val_tostring(__v) ( as_val_val_tostring((as_val *)__v) )
128
129
/******************************************************************************
130
* FUNCTIONS
131
*****************************************************************************/
132
133
/**
134
* @private
135
* Helper function for incrementing the count of a value.
136
*/
137
as_val
*
as_val_val_reserve
(
as_val
*);
138
139
/**
140
* @private
141
* Helper function for decrementing the count of a value,
142
* and if count==0 and free==true, then free the value.
143
*/
144
as_val
*
as_val_val_destroy
(
as_val
*);
145
146
/**
147
* @private
148
* Helper function for calculating the hash value.
149
*/
150
uint32_t
as_val_val_hashcode
(
const
as_val
*);
151
152
/**
153
* @private
154
* Helper function for generating the string representation.
155
*/
156
char
*
as_val_val_tostring
(
const
as_val
*);
157
158
/******************************************************************************
159
* INSTANCE FUNCTIONS
160
*****************************************************************************/
161
162
/**
163
* @private
164
* Initialize an as_val.
165
* Should only be used by subtypes.
166
* @deprecated Use as_val_cons() instead.
167
*/
168
static
inline
void
as_val_init
(
as_val
* v,
as_val_t
type
,
bool
free)
169
{
170
v->
type
=
type
;
171
v->
free
= free;
172
v->
count
= 1;
173
}
174
175
176
/**
177
* @private
178
* Initialize an as_val.
179
* Should only be used by subtypes.
180
*/
181
static
inline
as_val
*
as_val_cons
(
as_val
* val,
as_val_t
type
,
bool
free)
182
{
183
if
( !val )
return
val;
184
185
val->
type
=
type
;
186
val->
free
= free;
187
val->
count
= 1;
188
return
val;
189
}
190
191
#ifdef __cplusplus
192
}
// end extern "C"
193
#endif