1 | /* |
2 | Copyright (c) 1999-2001 the KMime authors. |
3 | See file AUTHORS for details |
4 | |
5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. |
9 | |
10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. |
14 | |
15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
18 | Boston, MA 02110-1301, USA. |
19 | */ |
20 | /** |
21 | @file |
22 | This file is part of the API for handling @ref MIME data and |
23 | defines the BoolFlags class. |
24 | |
25 | @brief |
26 | Defines the BoolFlags class. |
27 | */ |
28 | |
29 | #ifndef __KMIME_BOOLFLAGS_H__ |
30 | #define __KMIME_BOOLFLAGS_H__ |
31 | |
32 | #include "kmime_export.h" |
33 | |
34 | namespace KMime { |
35 | |
36 | /** |
37 | @brief |
38 | Provides a class for storing boolean values in single bytes. |
39 | |
40 | This class provides functionality similar to QBitArray but requires |
41 | much less memory. Only 16-bits (or 2-bytes) can be stored. |
42 | */ |
43 | // TODO: KDE5: BIC: Remove this class, it is unused. |
44 | class KMIME_EXPORT BoolFlags { |
45 | |
46 | public: |
47 | /** |
48 | Constructs an empty 2-byte flag storage. |
49 | */ |
50 | BoolFlags() { clear(); } |
51 | |
52 | /** |
53 | Destroys the flag storage. |
54 | */ |
55 | ~BoolFlags() {} |
56 | |
57 | /** |
58 | Sets bit number @p i to the value @p b. |
59 | |
60 | @param i is the bit number. Valid values are 0 through 15. |
61 | Higher values will be silently ignored. |
62 | @param b is the value to set for bit @p i. |
63 | */ |
64 | void set( unsigned int i, bool b=true ); |
65 | |
66 | /** |
67 | Get bit number @p i. |
68 | |
69 | @param i is the bit number. Valid values are 0 through 15. |
70 | Higher values all return @c false. |
71 | @return Value of the single bit @p i. |
72 | Invalid bit numbers return @c false. |
73 | */ |
74 | bool get( unsigned int i ); |
75 | |
76 | /** |
77 | Sets all bits to false. |
78 | */ |
79 | void clear() { mBits[0]=0; mBits[1]=0; } |
80 | |
81 | /** |
82 | Returns a pointer to the data structure used to store the bits. |
83 | */ |
84 | unsigned char *data() { return mBits; } |
85 | |
86 | private: |
87 | /** |
88 | Two bytes (at least) of storage for the bits. |
89 | */ |
90 | unsigned char mBits[2]; //space for 16 flags |
91 | }; |
92 | |
93 | } //namespace KMime |
94 | |
95 | #endif // __KMIME_BOOLFLAGS_H__ |
96 | |