Loading...
Searching...
No Matches
as_stringmap.h
Go to the documentation of this file.
1/*
2 * Copyright 2008-2023 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_bytes.h>
22#include <aerospike/as_list.h>
23#include <aerospike/as_map.h>
24#include <aerospike/as_std.h>
25#include <aerospike/as_string.h>
26#include <aerospike/as_util.h>
27#include <aerospike/as_val.h>
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33/******************************************************************************
34 * SETTER FUNCTIONS
35 *****************************************************************************/
36
37/**
38 * Set the specified key's value to an as_val.
39 */
40static inline int as_stringmap_set(as_map * m, const char * k, as_val * v)
41{
42 return as_util_hook(set, 1, m, (as_val *) as_string_new_strdup(k), v);
43}
44
45/**
46 * Set the specified key's value to an int64_t.
47 */
48static inline int as_stringmap_set_int64(as_map * m, const char * k, int64_t v)
49{
50 return as_util_hook(set, 1, m, (as_val *) as_string_new_strdup(k), (as_val *) as_integer_new(v));
51}
52
53/**
54 * Set the specified key's value to a double.
55 */
56static inline int as_stringmap_set_double(as_map * m, const char * k, double v)
57{
58 return as_util_hook(set, 1, m, (as_val *) as_string_new_strdup(k), (as_val *) as_double_new(v));
59}
60
61/**
62 * Set the specified key's value to a NULL terminated string.
63 */
64static inline int as_stringmap_set_str(as_map * m, const char * k, const char * v)
65{
67}
68
69/**
70 * Set the specified key's value to an as_integer.
71 */
72static inline int as_stringmap_set_integer(as_map * m, const char * k, as_integer * v)
73{
74 return as_util_hook(set, 1, m, (as_val *) as_string_new_strdup(k), (as_val *) v);
75}
76
77/**
78 * Set the specified key's value to an as_integer.
79 */
80static inline int as_stringmap_set_as_double(as_map * m, const char * k, as_double * v)
81{
82 return as_util_hook(set, 1, m, (as_val *) as_string_new_strdup(k), (as_val *) v);
83}
84
85/**
86 * Set the specified key's value to an as_string.
87 */
88static inline int as_stringmap_set_string(as_map * m, const char * k, as_string * v)
89{
90 return as_util_hook(set, 1, m, (as_val *) as_string_new_strdup(k), (as_val *) v);
91}
92
93/**
94 * Set the specified key's value to an as_bytes.
95 */
96static inline int as_stringmap_set_bytes(as_map * m, const char * k, as_bytes * v)
97{
98 return as_util_hook(set, 1, m, (as_val *) as_string_new_strdup(k), (as_val *) v);
99}
100
101/**
102 * Set the specified key's value to an as_list.
103 */
104static inline int as_stringmap_set_list(as_map * m, const char * k, as_list * v)
105{
106 return as_util_hook(set, 1, m, (as_val *) as_string_new_strdup(k), (as_val *) v);
107}
108
109/**
110 * Set the specified key's value to an as_map.
111 */
112static inline int as_stringmap_set_map(as_map * m, const char * k, as_map * v)
113{
114 return as_util_hook(set, 1, m, (as_val *) as_string_new_strdup(k), (as_val *) v);
115}
116
117/******************************************************************************
118 * GETTER FUNCTIONS
119 *****************************************************************************/
120
121/**
122 * Get the specified key's value as an as_val.
123 */
124static inline as_val * as_stringmap_get(as_map * m, const char * k)
125{
126 as_string key;
127 as_val * v = as_util_hook(get, NULL, m, (as_val *) as_string_init(&key, (char *) k, false));
128 return v;
129}
130
131/**
132 * Get the specified key's value as an int64_t.
133 */
134static inline int64_t as_stringmap_get_int64(as_map * m, const char * k)
135{
136 as_string key;
137 as_val * v = as_util_hook(get, NULL, m, (as_val *) as_string_init(&key, (char *) k, false));
139 return i ? as_integer_toint(i) : 0;
140}
141
142/**
143 * Get the specified key's value as a double.
144 */
145static inline double as_stringmap_get_double(as_map * m, const char * k)
146{
147 as_string key;
148 as_val * v = as_util_hook(get, NULL, m, (as_val *) as_string_init(&key, (char *) k, false));
149 as_double * ptr = as_double_fromval(v);
150 return ptr ? ptr->value : 0.0;
151}
152
153/**
154 * Get the specified key's value as a NULL terminated string.
155 */
156static inline char * as_stringmap_get_str(as_map * m, const char * k)
157{
158 as_string key;
159 as_val * v = as_util_hook(get, NULL, m, (as_val *) as_string_init(&key, (char *) k, false));
161 return s ? as_string_tostring(s) : NULL;
162}
163
164/**
165 * Get the specified key's value as an as_integer.
166 */
167static inline as_integer * as_stringmap_get_integer(as_map * m, const char * k)
168{
169 as_string key;
170 as_val * v = as_util_hook(get, NULL, m, (as_val *) as_string_init(&key, (char *) k, false));
171 return as_integer_fromval(v);
172}
173
174/**
175 * Get the specified key's value as an as_double.
176 */
177static inline as_double * as_stringmap_get_as_double(as_map * m, const char * k)
178{
179 as_string key;
180 as_val * v = as_util_hook(get, NULL, m, (as_val *) as_string_init(&key, (char *) k, false));
181 return as_double_fromval(v);
182}
183
184/**
185 * Get the specified key's value as an as_string.
186 */
187static inline as_string * as_stringmap_get_string(as_map * m, const char * k)
188{
189 as_string key;
190 as_val * v = as_util_hook(get, NULL, m, (as_val *) as_string_init(&key, (char *) k, false));
191 return as_string_fromval(v);
192}
193
194/**
195 * Get the specified key's value as an as_bytes.
196 */
197static inline as_bytes * as_stringmap_get_bytes(as_map * m, const char * k)
198{
199 as_string key;
200 as_val * v = as_util_hook(get, NULL, m, (as_val *) as_string_init(&key, (char *) k, false));
201 return as_bytes_fromval(v);
202}
203
204/**
205 * Get the specified key's value as an as_list.
206 */
207static inline as_list * as_stringmap_get_list(as_map * m, const char * k)
208{
209 as_string key;
210 as_val * v = as_util_hook(get, NULL, m, (as_val *) as_string_init(&key, (char *) k, false));
211 return as_list_fromval(v);
212}
213
214/**
215 * Get the specified key's value as an as_map.
216 */
217static inline as_map * as_stringmap_get_map(as_map * m, const char * k)
218{
219 as_string key;
220 as_val * v = as_util_hook(get, NULL, m, (as_val *) as_string_init(&key, (char *) k, false));
221 return as_map_fromval(v);
222}
223
224#ifdef __cplusplus
225} // end extern "C"
226#endif
static as_bytes * as_bytes_fromval(const as_val *v)
Definition as_bytes.h:977
AS_EXTERN as_double * as_double_new(double value)
static as_double * as_double_fromval(const as_val *value)
Definition as_double.h:225
static as_integer * as_integer_fromval(const as_val *v)
Definition as_integer.h:226
AS_EXTERN as_integer * as_integer_new(int64_t value)
static int64_t as_integer_toint(const as_integer *integer)
Definition as_integer.h:204
static as_list * as_list_fromval(as_val *v)
Definition as_list.h:1464
static as_map * as_map_fromval(const as_val *val)
Definition as_map.h:424
as_msg m
Definition as_proto.h:1
static char * as_string_tostring(const as_string *string)
Definition as_string.h:255
AS_EXTERN as_string * as_string_init(as_string *string, char *value, bool free)
static as_string * as_string_fromval(const as_val *v)
Definition as_string.h:291
AS_EXTERN as_string * as_string_new_strdup(const char *value)
static as_map * as_stringmap_get_map(as_map *m, const char *k)
static int64_t as_stringmap_get_int64(as_map *m, const char *k)
static as_double * as_stringmap_get_as_double(as_map *m, const char *k)
static int as_stringmap_set_bytes(as_map *m, const char *k, as_bytes *v)
static int as_stringmap_set_list(as_map *m, const char *k, as_list *v)
static int as_stringmap_set_int64(as_map *m, const char *k, int64_t v)
static int as_stringmap_set_as_double(as_map *m, const char *k, as_double *v)
static int as_stringmap_set_string(as_map *m, const char *k, as_string *v)
static char * as_stringmap_get_str(as_map *m, const char *k)
static int as_stringmap_set_integer(as_map *m, const char *k, as_integer *v)
static as_val * as_stringmap_get(as_map *m, const char *k)
static int as_stringmap_set_map(as_map *m, const char *k, as_map *v)
static as_bytes * as_stringmap_get_bytes(as_map *m, const char *k)
static int as_stringmap_set_double(as_map *m, const char *k, double v)
static as_string * as_stringmap_get_string(as_map *m, const char *k)
static as_integer * as_stringmap_get_integer(as_map *m, const char *k)
static int as_stringmap_set_str(as_map *m, const char *k, const char *v)
static int as_stringmap_set(as_map *m, const char *k, as_val *v)
static double as_stringmap_get_double(as_map *m, const char *k)
static as_list * as_stringmap_get_list(as_map *m, const char *k)
#define as_util_hook(hook, default, object,...)
Definition as_util.h:34
double value
Definition as_double.h:110