Main Page
Modules
Data Structures
Files
File List
Globals
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
modules
common
src
include
aerospike
modules/common/src/include/aerospike/as_val.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 <citrusleaf/cf_atomic.h>
26
27
#include <stdbool.h>
28
#include <stdint.h>
29
30
/******************************************************************************
31
* TYPES
32
*****************************************************************************/
33
34
/**
35
* as_val types
36
*/
37
typedef
enum
as_val_t
{
38
AS_UNDEF
= 0,
39
AS_UNKNOWN
= 0,
//<! @deprecated
40
AS_NIL
= 1,
41
AS_BOOLEAN
= 2,
42
AS_INTEGER
= 3,
43
AS_STRING
= 4,
44
AS_LIST
= 5,
45
AS_MAP
= 6,
46
AS_REC
= 7,
47
AS_PAIR
= 8,
48
AS_BYTES
= 9,
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