Debian Codegraph @

lib/packagekit-glib2/pk-bitfield.h

raw
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
2 *
3 * Copyright (C) 2007-2008 Richard Hughes <[email protected]>
4 *
5 * Licensed under the GNU Lesser General Public License Version 2.1
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #if !defined (__PACKAGEKIT_H_INSIDE__) && !defined (PK_COMPILATION)
23 #error "Only <packagekit.h> can be included directly."
24 #endif
25
26 #ifndef __PK_BITFIELD_H
27 #define __PK_BITFIELD_H
28
29 #include <glib.h>
30
31 G_BEGIN_DECLS
32
33 /**
34 * PkBitfield:
35 *
36 * A bitfield capable of storing enumerations with up to 64 values.
37 */
38 typedef guint64 PkBitfield;
39
40 /**
41 * PK_BITFIELD_FORMAT:
42 *
43 * printf format string suitable for printing #PkBitfield values.
44 */
45 #define PK_BITFIELD_FORMAT G_GUINT64_FORMAT
46
47 /* convenience functions as it's easy to forget the bitwise operators */
48
49 /**
50 * pk_bitfield_add:
51 * @bitfield: a #PkBitfield
52 * @enum: value to add
53 *
54 * Set a value in a bitfield
55 */
56 #define pk_bitfield_add(bitfield,enum) do { ((bitfield) |= (pk_bitfield_value(enum))); } while (0)
57
58 /**
59 * pk_bitfield_remove:
60 * @bitfield: a #PkBitfield
61 * @enum: value to remove
62 *
63 * Remove a value from a bitfield
64 */
65 #define pk_bitfield_remove(bitfield,enum) do { ((bitfield) &= ~(pk_bitfield_value(enum))); } while (0)
66
67 /**
68 * pk_bitfield_invert:
69 * @bitfield: a #PkBitfield
70 * @enum: value to invert
71 *
72 * Invert a value in a bitfield
73 */
74 #define pk_bitfield_invert(bitfield,enum) do { ((bitfield) ^= (pk_bitfield_value(enum))); } while (0)
75
76 /**
77 * pk_bitfield_contain:
78 * @bitfield: a #PkBitfield
79 * @enum: value to check
80 *
81 * Check if a bitfield contains a value
82 *
83 * Return value: %TRUE if the bitfield contains this value
84 */
85 #define pk_bitfield_contain(bitfield,enum) (((bitfield) & (pk_bitfield_value(enum))) > 0)
86
87 /**
88 * pk_bitfield_value:
89 * @enum: enumerated valued to convert
90 *
91 * Convert an enumerated value to a bitfield value
92 *
93 * Return value: a bitfield value
94 */
95 #define pk_bitfield_value(enum) ((PkBitfield) 1 << (enum))
96
97 gint pk_bitfield_contain_priority (PkBitfield values,
98 gint value, ...);
99 PkBitfield pk_bitfield_from_enums (gint value, ...);
100 PkBitfield pk_role_bitfield_from_string (const gchar *roles);
101 gchar *pk_role_bitfield_to_string (PkBitfield roles);
102 PkBitfield pk_group_bitfield_from_string (const gchar *groups);
103 gchar *pk_group_bitfield_to_string (PkBitfield groups);
104 PkBitfield pk_filter_bitfield_from_string (const gchar *filters);
105 gchar *pk_filter_bitfield_to_string (PkBitfield filters);
106 PkBitfield pk_transaction_flag_bitfield_from_string (const gchar *transaction_flags);
107 gchar *pk_transaction_flag_bitfield_to_string (PkBitfield transaction_flags);
108
109 G_END_DECLS
110
111 #endif /* __PK_BITFIELD_H */
112