Soletta™ Framework
Framework for making IoT devices

Full online documentation | C API Index
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
sol-str-table.h
Go to the documentation of this file.
1 /*
2  * This file is part of the Soletta (TM) Project
3  *
4  * Copyright (C) 2015 Intel Corporation. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #pragma once
20 
21 #include <inttypes.h>
22 
23 #include <sol-str-slice.h>
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
51 typedef struct sol_str_table {
52  const char *key;
53  uint16_t len;
54  int16_t val;
56 
68 #define SOL_STR_TABLE_ITEM(_key, _val) \
69  { .key = SOL_STR_STATIC_ASSERT_LITERAL(_key), .len = sizeof(_key) - 1, .val = _val }
70 
88 const struct sol_str_table *sol_str_table_entry_lookup(const struct sol_str_table *table, const struct sol_str_slice key);
89 
104 int16_t sol_str_table_lookup_fallback(const struct sol_str_table *table,
105  const struct sol_str_slice key,
106  int16_t fallback);
107 
111 #define SOL_STR_TABLE_NOT_FOUND INT16_MAX
112 
131 #define sol_str_table_lookup(_table, _key, _pval) ({ \
132  int16_t _v = sol_str_table_lookup_fallback(_table, _key, INT16_MAX); \
133  if (_v != INT16_MAX) \
134  *_pval = _v; \
135  _v != INT16_MAX; \
136  })
137 
141 typedef struct sol_str_table_ptr {
142  const char *key;
143  const void *val;
144  size_t len;
146 
155 #define SOL_STR_TABLE_PTR_ITEM(_key, _val) \
156  { .key = SOL_STR_STATIC_ASSERT_LITERAL(_key), \
157  .val = _val, \
158  .len = sizeof(_key) - 1 }
159 
175 const void *sol_str_table_ptr_lookup_fallback(const struct sol_str_table_ptr *table_ptr,
176  const struct sol_str_slice key,
177  const void *fallback)
178 #ifndef DOXYGEN_RUN
180 #endif
181  ;
182 
200 const struct sol_str_table_ptr *sol_str_table_ptr_entry_lookup(const struct sol_str_table_ptr *table, const struct sol_str_slice key);
201 
217 #define sol_str_table_ptr_lookup(_table_ptr, _key, _pval) ({ \
218  const void *_v = sol_str_table_ptr_lookup_fallback(_table_ptr, \
219  _key, NULL); \
220  if (_v != NULL) \
221  *_pval = _v; \
222  _v != NULL; \
223  })
224 
228 typedef struct sol_str_table_int64 {
229  const char *key;
230  size_t len;
231  int64_t val;
233 
242 #define SOL_STR_TABLE_INT64_ITEM(_key, _val) \
243  { .key = SOL_STR_STATIC_ASSERT_LITERAL(_key), \
244  .len = sizeof(_key) - 1, \
245  .val = _val }
246 
264 const struct sol_str_table_int64 *sol_str_table_int64_entry_lookup(const struct sol_str_table_int64 *table, const struct sol_str_slice key);
265 
280 int64_t sol_str_table_int64_lookup_fallback(const struct sol_str_table_int64 *table_int64,
281  const struct sol_str_slice key,
282  int64_t fallback)
283 #ifndef DOXYGEN_RUN
285 #endif
286  ;
287 
291 #define SOL_STR_TABLE_INT64_NOT_FOUND INT64_MAX
292 
308 #define sol_str_table_int64_lookup(_table_int64, _key, _pval) ({ \
309  int64_t _v = sol_str_table_int64_lookup_fallback(_table_int64, \
310  _key, SOL_STR_TABLE_INT64_NOT_FOUND); \
311  if (_v != SOL_STR_TABLE_INT64_NOT_FOUND) \
312  *_pval = _v; \
313  _v != SOL_STR_TABLE_INT64_NOT_FOUND; \
314  })
315 
320 #ifdef __cplusplus
321 }
322 #endif
int64_t sol_str_table_int64_lookup_fallback(const struct sol_str_table_int64 *table_int64, const struct sol_str_slice key, int64_t fallback)
Retrieves the value associated with a given key from the string/int64_t table.
struct sol_str_table_ptr sol_str_table_ptr
String/Pointer table type.
int16_t val
Value (16 bits integer)
Definition: sol-str-table.h:54
size_t len
Key string length.
Definition: sol-str-table.h:230
String/int64_t table type.
Definition: sol-str-table.h:228
String table element type.
Definition: sol-str-table.h:51
String slice type.
Definition: sol-str-slice.h:84
static struct sol_cert * key
Definition: server-https.c:51
struct sol_str_table sol_str_table
String table element type.
int64_t val
Value (int64_t)
Definition: sol-str-table.h:231
int16_t sol_str_table_lookup_fallback(const struct sol_str_table *table, const struct sol_str_slice key, int16_t fallback)
Retrieves the value associated with a given key from the string table.
const struct sol_str_table * sol_str_table_entry_lookup(const struct sol_str_table *table, const struct sol_str_slice key)
Retrieves the table entry associated with a given key from the string/integer table.
#define SOL_ATTR_NON_NULL(...)
Specifies that some function parameters should be non-null pointers.
Definition: sol-macros.h:193
String/Pointer table type.
Definition: sol-str-table.h:141
const void * val
Value (pointer)
Definition: sol-str-table.h:143
const char * key
Key string.
Definition: sol-str-table.h:142
These are routines that Soletta provides for its string slice implementation.
const struct sol_str_table_ptr * sol_str_table_ptr_entry_lookup(const struct sol_str_table_ptr *table, const struct sol_str_slice key)
Retrieves the table entry associated with a given key from the string/pointer table.
const char * key
Key string.
Definition: sol-str-table.h:52
const void * sol_str_table_ptr_lookup_fallback(const struct sol_str_table_ptr *table_ptr, const struct sol_str_slice key, const void *fallback)
Retrieves the value associated with a given key from the string/pointer table.
const struct sol_str_table_int64 * sol_str_table_int64_entry_lookup(const struct sol_str_table_int64 *table, const struct sol_str_slice key)
Retrieves the table entry associated with a given key from the string/pointer table.
const char * key
Key string.
Definition: sol-str-table.h:229
size_t len
Key string length.
Definition: sol-str-table.h:144
struct sol_str_table_int64 sol_str_table_int64
String/int64_t table type.
uint16_t len
Key string length.
Definition: sol-str-table.h:53