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