boolflags.cpp
00001 /* 00002 boolflags.cpp 00003 00004 KNode, the KDE newsreader 00005 Copyright (c) 1999-2001 the KNode authors. 00006 See file AUTHORS for details 00007 00008 This program is free software; you can redistribute it and/or modify 00009 it under the terms of the GNU General Public License as published by 00010 the Free Software Foundation; either version 2 of the License, or 00011 (at your option) any later version. 00012 You should have received a copy of the GNU General Public License 00013 along with this program; if not, write to the Free Software Foundation, 00014 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US 00015 */ 00016 00017 #include "boolflags.h" 00018 00019 void BoolFlags::set(unsigned int i, bool b) 00020 { 00021 if(i>15) return; 00022 00023 unsigned char p; //bimask 00024 int n; 00025 00026 if(i<8) { //first byte 00027 p=(1 << i); 00028 n=0; 00029 } 00030 else { //second byte 00031 p=(1 << ( i-8 )); 00032 n=1; 00033 } 00034 00035 if(b) 00036 bits[n] = bits[n] | p; 00037 else 00038 bits[n] = bits[n] & (255-p); 00039 } 00040 00041 00042 bool BoolFlags::get(unsigned int i) 00043 { 00044 if(i>15) return false; 00045 00046 unsigned char p; //bimask 00047 int n; 00048 00049 if(i<8) { //first byte 00050 p=(1 << i); 00051 n=0; 00052 } 00053 else { //second byte 00054 p=(1 << (i-8)); 00055 n=1; 00056 } 00057 00058 return ( (bits[n] & p)>0 ); 00059 } 00060 00061