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 MIME data and
23 defines the BoolFlags class.
24
25 @brief
26 Defines the BoolFlags class.
27
28 @author see AUTHORS file.
29*/
30
31#include "boolflags.h"
32
33using namespace KMime;
34
35void BoolFlags::set( unsigned int i, bool b )
36{
37 if ( i > 15 ) {
38 return;
39 }
40
41 unsigned char p; //bitmask
42 int n;
43
44 if ( i < 8 ) { //first byte
45 p = ( 1 << i );
46 n = 0;
47 } else { //second byte
48 p = ( 1 << ( i - 8 ) );
49 n = 1;
50 }
51
52 if ( b ) {
53 mBits[n] = mBits[n] | p;
54 } else {
55 mBits[n] = mBits[n] & ( 255 - p );
56 }
57}
58
59bool BoolFlags::get( unsigned int i )
60{
61 if ( i > 15 ) {
62 return false;
63 }
64
65 unsigned char p; //bitmask
66 int n;
67
68 if ( i < 8 ) { //first byte
69 p = ( 1 << i );
70 n = 0;
71 } else { //second byte
72 p = ( 1 << ( i - 8 ) );
73 n = 1;
74 }
75
76 return ( ( mBits[n] & p ) > 0 );
77}
78