• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdenetwork
  • Sitemap
  • Contact Us
 

kget

bitset.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005 by Joris Guisson                                   *
00003  *   joris.guisson@gmail.com                                               *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.             *
00019  ***************************************************************************/
00020 #ifndef BTBITSET_H
00021 #define BTBITSET_H
00022 
00023 #include <kget_export.h>
00024 
00032 class KGET_EXPORT BitSet
00033 {
00034     quint32 num_bits,num_bytes;
00035     quint8* data;
00036     quint32 num_on;
00037 public:
00042     BitSet(quint32 num_bits = 8);
00043     
00049     BitSet(const quint8* data,quint32 num_bits);
00050     
00056     BitSet(const BitSet & bs);
00057     virtual ~BitSet();
00058 
00060     bool isNull() const {return num_bits == 0;}
00061     
00066     bool get(quint32 i) const;
00067     
00073     void set(quint32 i,bool on);
00074     
00076     void setAll(bool on);
00077     
00078     quint32 getNumBytes() const {return num_bytes;}
00079     quint32 getNumBits() const {return num_bits;}
00080     const quint8* getData() const {return data;}
00081     quint8* getData() {return data;}
00082 
00084     quint32 numOnBits() const {return num_on;}
00085     
00089     void clear();
00090 
00095     void orBitSet(const BitSet & other);
00096     
00102     BitSet & operator = (const BitSet & bs);
00103 
00105     bool allOn() const;
00106 
00112     bool operator == (const BitSet & bs);
00113     
00117     bool operator != (const BitSet & bs) {return ! operator == (bs);}
00118 
00119     static BitSet null;
00120 };
00121 
00122 inline bool BitSet::get(quint32 i) const
00123 {
00124     if (i >= num_bits)
00125         return false;
00126     
00127     quint32 byte = i / 8;
00128     quint32 bit = i % 8;
00129     quint8 b = data[byte] & (0x01 << (7 - bit));
00130     return b != 0x00;
00131 }
00132 
00133 inline void BitSet::set(quint32 i,bool on)
00134 {
00135     if (i >= num_bits)
00136         return;
00137     
00138     quint32 byte = i / 8;
00139     quint32 bit = i % 8;
00140     if (on && !get(i))
00141     {
00142         num_on++;
00143         data[byte] |= (0x01 << (7 - bit));
00144     }
00145     else if (!on && get(i))
00146     {
00147         num_on--;
00148         quint8 b = (0x01 << (7 - bit));
00149         data[byte] &= (~b);
00150     }
00151 }
00152 
00153 #endif

kget

Skip menu "kget"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdenetwork

Skip menu "kdenetwork"
  • kget
  • kopete
  •   kopete
  •   libkopete
  •       libpapillon
  • krfb
Generated for kdenetwork by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal