libkmime

boolflags.cpp
1/*
2 boolflags.cpp
3
4 KNode, the KDE newsreader
5 Copyright (c) 1999-2001 the KNode authors.
6 See file AUTHORS for details
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software Foundation,
14 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US
15*/
16
17#include "boolflags.h"
18
19void BoolFlags::set(unsigned int i, bool b)
20{
21 if(i>15) return;
22
23 unsigned char p; //bimask
24 int n;
25
26 if(i<8) { //first byte
27 p=(1 << i);
28 n=0;
29 }
30 else { //second byte
31 p=(1 << ( i-8 ));
32 n=1;
33 }
34
35 if(b)
36 bits[n] = bits[n] | p;
37 else
38 bits[n] = bits[n] & (255-p);
39}
40
41
42bool BoolFlags::get(unsigned int i)
43{
44 if(i>15) return false;
45
46 unsigned char p; //bimask
47 int n;
48
49 if(i<8) { //first byte
50 p=(1 << i);
51 n=0;
52 }
53 else { //second byte
54 p=(1 << (i-8));
55 n=1;
56 }
57
58 return ( (bits[n] & p)>0 );
59}
60
61