• 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 <btcore_export.h>
00024 #include "constants.h"
00025 
00026 namespace bt
00027 {
00028 
00036     class BTCORE_EXPORT BitSet
00037     {
00038         Uint32 num_bits,num_bytes;
00039         Uint8* data;
00040         Uint32 num_on;
00041     public:
00046         BitSet(Uint32 num_bits = 8);
00047         
00053         BitSet(const Uint8* data,Uint32 num_bits);
00054         
00060         BitSet(const BitSet & bs);
00061         virtual ~BitSet();
00062 
00064         bool isNull() const {return num_bits == 0;}
00065         
00070         bool get(Uint32 i) const;
00071         
00077         void set(Uint32 i,bool on);
00078         
00080         void setAll(bool on);
00081         
00082         Uint32 getNumBytes() const {return num_bytes;}
00083         Uint32 getNumBits() const {return num_bits;}
00084         const Uint8* getData() const {return data;}
00085         Uint8* getData() {return data;}
00086 
00088         Uint32 numOnBits() const {return num_on;}
00089         
00093         void clear();
00094 
00099         void orBitSet(const BitSet & other);
00100         
00106         BitSet & operator = (const BitSet & bs);
00107 
00109         bool allOn() const;
00110 
00116         bool operator == (const BitSet & bs);
00117         
00121         bool operator != (const BitSet & bs) {return ! operator == (bs);}
00122 
00123         static BitSet null;
00124     };
00125 
00126     inline bool BitSet::get(Uint32 i) const
00127     {
00128         if (i >= num_bits)
00129             return false;
00130         
00131         Uint32 byte = i / 8;
00132         Uint32 bit = i % 8;
00133         Uint8 b = data[byte] & (0x01 << (7 - bit));
00134         return b != 0x00;
00135     }
00136     
00137     inline void BitSet::set(Uint32 i,bool on)
00138     {
00139         if (i >= num_bits)
00140             return;
00141         
00142         Uint32 byte = i / 8;
00143         Uint32 bit = i % 8;
00144         if (on && !get(i))
00145         {
00146             num_on++;
00147             data[byte] |= (0x01 << (7 - bit));
00148         }
00149         else if (!on && get(i))
00150         {
00151             num_on--;
00152             Uint8 b = (0x01 << (7 - bit));
00153             data[byte] &= (~b);
00154         }
00155     }
00156 }
00157 
00158 #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