libamxc  1.10.3
C Generic Data Containers
amxc_set.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** SPDX-License-Identifier: BSD-2-Clause-Patent
4 **
5 ** SPDX-FileCopyrightText: Copyright (c) 2023 SoftAtHome
6 **
7 ** Redistribution and use in source and binary forms, with or without modification,
8 ** are permitted provided that the following conditions are met:
9 **
10 ** 1. Redistributions of source code must retain the above copyright notice,
11 ** this list of conditions and the following disclaimer.
12 **
13 ** 2. Redistributions in binary form must reproduce the above copyright notice,
14 ** this list of conditions and the following disclaimer in the documentation
15 ** and/or other materials provided with the distribution.
16 **
17 ** Subject to the terms and conditions of this license, each copyright holder
18 ** and contributor hereby grants to those receiving rights under this license
19 ** a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable
20 ** (except for failure to satisfy the conditions of this license) patent license
21 ** to make, have made, use, offer to sell, sell, import, and otherwise transfer
22 ** this software, where such license applies only to those patent claims, already
23 ** acquired or hereafter acquired, licensable by such copyright holder or contributor
24 ** that are necessarily infringed by:
25 **
26 ** (a) their Contribution(s) (the licensed copyrights of copyright holders and
27 ** non-copyrightable additions of contributors, in source or binary form) alone;
28 ** or
29 **
30 ** (b) combination of their Contribution(s) with the work of authorship to which
31 ** such Contribution(s) was added by such copyright holder or contributor, if,
32 ** at the time the Contribution is added, such addition causes such combination
33 ** to be necessarily infringed. The patent license shall not apply to any other
34 ** combinations which include the Contribution.
35 **
36 ** Except as expressly stated above, no rights or licenses from any copyright
37 ** holder or contributor is granted under this license, whether expressly, by
38 ** implication, estoppel or otherwise.
39 **
40 ** DISCLAIMER
41 **
42 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
43 ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44 ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45 ** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
46 ** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
47 ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
48 ** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
49 ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
50 ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
51 ** USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
52 **
53 ****************************************************************************/
54 
55 #if !defined(__AMXC_SET_H__)
56 #define __AMXC_SET_H__
57 
58 #ifdef __cplusplus
59 extern "C"
60 {
61 #endif
62 
63 #include <amxc/amxc_common.h>
64 #include <amxc/amxc_llist.h>
65 
66 typedef struct _set amxc_set_t;
67 
107 typedef void (* amxc_set_alert_t)(amxc_set_t* set,
108  const char* flag,
109  bool value,
110  void* priv);
118 typedef struct _flag {
120  char* flag;
121  uint32_t count;
123 
129 struct _set {
133  void* priv;
134  bool counted;
135  int count;
137 };
138 
165 int amxc_set_new(amxc_set_t** set, bool counted);
166 
176 void amxc_set_delete(amxc_set_t** set);
177 
198 int amxc_set_init(amxc_set_t* const set, bool counted);
199 
209 void amxc_set_clean(amxc_set_t* const set);
210 
226 amxc_set_t* amxc_set_copy(const amxc_set_t* const set);
227 
235 void amxc_set_reset(amxc_set_t* set);
236 
258 int amxc_set_parse(amxc_set_t* set, const char* str);
259 
272 char* amxc_set_to_string(const amxc_set_t* const set);
273 
287 char* amxc_set_to_string_sep(const amxc_set_t* const set, const char* sep);
288 
301 void amxc_set_add_flag(amxc_set_t* set, const char* flag);
302 
315 void amxc_set_remove_flag(amxc_set_t* set, const char* flag);
316 
329 bool amxc_set_has_flag(const amxc_set_t* const set, const char* flag);
330 
348 uint32_t amxc_set_get_count(const amxc_set_t* const set, const char* flag);
349 
363 void amxc_set_union(amxc_set_t* const set, const amxc_set_t* const operand);
364 
378 void amxc_set_intersect(amxc_set_t* const set, const amxc_set_t* const operand);
379 
395 void amxc_set_subtract(amxc_set_t* const set, const amxc_set_t* const operand);
396 
411 bool amxc_set_is_equal(const amxc_set_t* const set1,
412  const amxc_set_t* const set2);
413 
430 void amxc_set_alert_cb(amxc_set_t* set, amxc_set_alert_t handler, void* priv);
431 
443 void amxc_set_symmetric_difference(amxc_set_t* const set, const amxc_set_t* const operand);
444 
445 #ifdef __cplusplus
446 }
447 #endif
448 
449 #endif // __AMXC_SET_H__
Ambiorix linked list API header file.
void(* amxc_set_alert_t)(amxc_set_t *set, const char *flag, bool value, void *priv)
Flag set alert handler type.
Definition: amxc_set.h:107
void amxc_set_remove_flag(amxc_set_t *set, const char *flag)
Removes a flag from a set or decreases the flag counter.
Definition: amxc_set.c:315
char * amxc_set_to_string_sep(const amxc_set_t *const set, const char *sep)
Converts a set to a separated string of flags.
Definition: amxc_set.c:264
int amxc_set_new(amxc_set_t **set, bool counted)
Allocates a set.
Definition: amxc_set.c:138
void amxc_set_reset(amxc_set_t *set)
Reset or empty a set, i.e. clear all flags.
Definition: amxc_set.c:199
amxc_set_t * amxc_set_copy(const amxc_set_t *const set)
Copies a set.
Definition: amxc_set.c:187
void amxc_set_intersect(amxc_set_t *const set, const amxc_set_t *const operand)
Intersect a set with another set.
Definition: amxc_set.c:384
bool amxc_set_is_equal(const amxc_set_t *const set1, const amxc_set_t *const set2)
Compare two sets.
Definition: amxc_set.c:430
void amxc_set_add_flag(amxc_set_t *set, const char *flag)
Adds a flag to a set, or increases the flag counter.
Definition: amxc_set.c:305
void amxc_set_delete(amxc_set_t **set)
Frees a set.
Definition: amxc_set.c:151
void amxc_set_symmetric_difference(amxc_set_t *const set, const amxc_set_t *const operand)
Calculates the symmetric difference of two sets.
Definition: amxc_set.c:463
int amxc_set_init(amxc_set_t *const set, bool counted)
Initializes a set.
Definition: amxc_set.c:162
char * amxc_set_to_string(const amxc_set_t *const set)
Converts a set to a space-separated string of flags.
Definition: amxc_set.c:301
uint32_t amxc_set_get_count(const amxc_set_t *const set, const char *flag)
Get a flag counter.
Definition: amxc_set.c:349
struct _flag amxc_flag_t
The flag structure.
int amxc_set_parse(amxc_set_t *set, const char *str)
Parses a space-separated string of flags and adds them to the set.
Definition: amxc_set.c:210
void amxc_set_clean(amxc_set_t *const set)
Cleans a set.
Definition: amxc_set.c:177
void amxc_set_union(amxc_set_t *const set, const amxc_set_t *const operand)
Joins two sets.
Definition: amxc_set.c:365
bool amxc_set_has_flag(const amxc_set_t *const set, const char *flag)
Check if a set contains a flag.
Definition: amxc_set.c:337
void amxc_set_alert_cb(amxc_set_t *set, amxc_set_alert_t handler, void *priv)
Install a set alert callback function.
Definition: amxc_set.c:453
void amxc_set_subtract(amxc_set_t *const set, const amxc_set_t *const operand)
Subtract a set from another set.
Definition: amxc_set.c:408
The linked list iterator structure.
Definition: amxc_llist.h:215
The linked list structure.
Definition: amxc_llist.h:228
The flag structure.
Definition: amxc_set.h:118
uint32_t count
Definition: amxc_set.h:121
char * flag
Definition: amxc_set.h:120
amxc_llist_it_t it
Definition: amxc_set.h:119
The set structure.
Definition: amxc_set.h:129
bool counted
Definition: amxc_set.h:134
amxc_set_alert_t alert_handler
Definition: amxc_set.h:131
int count
Definition: amxc_set.h:135
amxc_llist_t list
Definition: amxc_set.h:130
void * priv
Definition: amxc_set.h:133