All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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>
21 #include <aerospike/as_integer.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
30 extern "C" {
31 #endif
32 
33 /******************************************************************************
34  * SETTER FUNCTIONS
35  *****************************************************************************/
36 
37 /**
38  * Set the specified key's value to an as_val.
39  */
40 static 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  */
48 static 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  */
56 static 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  */
64 static inline int as_stringmap_set_str(as_map * m, const char * k, const char * v)
65 {
66  return as_util_hook(set, 1, m, (as_val *) as_string_new_strdup(k), (as_val *) as_string_new_strdup(v));
67 }
68 
69 /**
70  * Set the specified key's value to an as_integer.
71  */
72 static 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  */
80 static 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  */
88 static 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  */
96 static 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  */
104 static 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  */
112 static 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  */
124 static 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  */
134 static 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  */
145 static 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  */
156 static 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));
160  as_string * s = as_string_fromval(v);
161  return s ? as_string_tostring(s) : NULL;
162 }
163 
164 /**
165  * Get the specified key's value as an as_integer.
166  */
167 static 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  */
177 static 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  */
187 static 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  */
197 static 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  */
207 static 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  */
217 static 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_integer * as_integer_fromval(const as_val *v)
Definition: as_integer.h:226
as_msg m
Definition: as_proto.h:36
Definition: as_map.h:61
static double as_stringmap_get_double(as_map *m, const char *k)
Definition: as_stringmap.h:145
AS_EXTERN as_string * as_string_new_strdup(const char *value)
static as_bytes * as_stringmap_get_bytes(as_map *m, const char *k)
Definition: as_stringmap.h:197
static as_double * as_double_fromval(const as_val *value)
Definition: as_double.h:225
static int64_t as_integer_toint(const as_integer *integer)
Definition: as_integer.h:204
static as_integer * as_stringmap_get_integer(as_map *m, const char *k)
Definition: as_stringmap.h:167
double value
Definition: as_double.h:110
#define as_util_hook(hook, default, object,...)
Definition: as_util.h:34
static as_val * as_stringmap_get(as_map *m, const char *k)
Definition: as_stringmap.h:124
static int as_stringmap_set_bytes(as_map *m, const char *k, as_bytes *v)
Definition: as_stringmap.h:96
static int as_stringmap_set_string(as_map *m, const char *k, as_string *v)
Definition: as_stringmap.h:88
Definition: as_val.h:61
static int as_stringmap_set(as_map *m, const char *k, as_val *v)
Definition: as_stringmap.h:40
static as_list * as_stringmap_get_list(as_map *m, const char *k)
Definition: as_stringmap.h:207
static int as_stringmap_set_as_double(as_map *m, const char *k, as_double *v)
Definition: as_stringmap.h:80
static int64_t as_stringmap_get_int64(as_map *m, const char *k)
Definition: as_stringmap.h:134
AS_EXTERN as_double * as_double_new(double value)
static int as_stringmap_set_double(as_map *m, const char *k, double v)
Definition: as_stringmap.h:56
static as_bytes * as_bytes_fromval(const as_val *v)
Definition: as_bytes.h:977
static char * as_string_tostring(const as_string *string)
Definition: as_string.h:255
static int as_stringmap_set_map(as_map *m, const char *k, as_map *v)
Definition: as_stringmap.h:112
static as_string * as_string_fromval(const as_val *v)
Definition: as_string.h:291
static char * as_stringmap_get_str(as_map *m, const char *k)
Definition: as_stringmap.h:156
static as_list * as_list_fromval(as_val *v)
Definition: as_list.h:1464
static as_map * as_stringmap_get_map(as_map *m, const char *k)
Definition: as_stringmap.h:217
static as_map * as_map_fromval(const as_val *val)
Definition: as_map.h:424
static int as_stringmap_set_str(as_map *m, const char *k, const char *v)
Definition: as_stringmap.h:64
static as_double * as_stringmap_get_as_double(as_map *m, const char *k)
Definition: as_stringmap.h:177
AS_EXTERN as_integer * as_integer_new(int64_t value)
static int as_stringmap_set_integer(as_map *m, const char *k, as_integer *v)
Definition: as_stringmap.h:72
static int as_stringmap_set_list(as_map *m, const char *k, as_list *v)
Definition: as_stringmap.h:104
AS_EXTERN as_string * as_string_init(as_string *string, char *value, bool free)
static as_string * as_stringmap_get_string(as_map *m, const char *k)
Definition: as_stringmap.h:187
static int as_stringmap_set_int64(as_map *m, const char *k, int64_t v)
Definition: as_stringmap.h:48