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

kget

  • sources
  • kde-4.14
  • kdenetwork
  • kget
  • core
bitset.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Joris Guisson *
3  * joris.guisson@gmail.com *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program 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 *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19  ***************************************************************************/
20 #ifndef BTBITSET_H
21 #define BTBITSET_H
22 
23 #include <kget_export.h>
24 
32 class KGET_EXPORT BitSet
33 {
34  quint32 num_bits,num_bytes;
35  quint8* data;
36  quint32 num_on;
37 public:
42  BitSet(quint32 num_bits = 8);
43 
49  BitSet(const quint8* data,quint32 num_bits);
50 
56  BitSet(const BitSet & bs);
57  virtual ~BitSet();
58 
60  bool isNull() const {return num_bits == 0;}
61 
66  bool get(quint32 i) const;
67 
73  void set(quint32 i,bool on);
74 
81  void setRange(quint32 start, quint32 end, bool value);
82 
84  void setAll(bool on);
85 
86  quint32 getNumBytes() const {return num_bytes;}
87  quint32 getNumBits() const {return num_bits;}
88  const quint8* getData() const {return data;}
89  quint8* getData() {return data;}
90 
92  quint32 numOnBits() const {return num_on;}
93 
100  void getContinuousRange(qint32 *start, qint32 *end, bool on);
101 
105  void clear();
106 
111  void orBitSet(const BitSet & other);
112 
118  BitSet & operator = (const BitSet & bs);
119 
121  bool allOn() const;
122  bool allOff() const;
123 
129  bool operator == (const BitSet & bs);
130 
134  bool operator != (const BitSet & bs) {return ! operator == (bs);}
135 
136  static BitSet null;
137 };
138 
139 inline bool BitSet::get(quint32 i) const
140 {
141  if (i >= num_bits)
142  return false;
143 
144  quint32 byte = i / 8;
145  quint32 bit = i % 8;
146  quint8 b = data[byte] & (0x01 << (7 - bit));
147  return b != 0x00;
148 }
149 
150 inline void BitSet::set(quint32 i,bool on)
151 {
152  if (i >= num_bits)
153  return;
154 
155  quint32 byte = i / 8;
156  quint32 bit = i % 8;
157  if (on && !get(i))
158  {
159  num_on++;
160  data[byte] |= (0x01 << (7 - bit));
161  }
162  else if (!on && get(i))
163  {
164  num_on--;
165  quint8 b = (0x01 << (7 - bit));
166  data[byte] &= (~b);
167  }
168 }
169 
170 inline void BitSet::setRange(quint32 start, quint32 end, bool value)
171 {
172  if ((start >= num_bits) || (end >= num_bits)) {
173  return;
174  }
175 
176  for (quint32 i = start; i <= end; ++i) {
177  set(i, value);
178  }
179 }
180 
181 #endif
BitSet::setRange
void setRange(quint32 start, quint32 end, bool value)
Sets the value of a range of bits.
Definition: bitset.h:170
BitSet::get
bool get(quint32 i) const
Get the value of a bit, false means 0, true 1.
Definition: bitset.h:139
BitSet::set
void set(quint32 i, bool on)
Set the value of a bit, false means 0, true 1.
Definition: bitset.h:150
BitSet::getData
quint8 * getData()
Definition: bitset.h:89
BitSet::getNumBytes
quint32 getNumBytes() const
Definition: bitset.h:86
kget_export.h
BitSet
Simple implementation of a BitSet.
Definition: bitset.h:32
BitSet::null
static BitSet null
Definition: bitset.h:136
BitSet::numOnBits
quint32 numOnBits() const
Get the number of on bits.
Definition: bitset.h:92
BitSet::isNull
bool isNull() const
See if the BitSet is null.
Definition: bitset.h:60
KGET_EXPORT
#define KGET_EXPORT
Definition: kget_export.h:24
BitSet::getNumBits
quint32 getNumBits() const
Definition: bitset.h:87
BitSet::getData
const quint8 * getData() const
Definition: bitset.h:88
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:28:43 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kget

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

kdenetwork API Reference

Skip menu "kdenetwork API Reference"
  • kget
  • kopete
  •   kopete
  •   libkopete
  • krdc
  • krfb

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal