comparison base/ResizeableBitset.h @ 113:534373d65f39

* Use fractional window overlaps in the spectrogram, instead of percentages (90% is kind of meaningless when none of your window sizes are divisible by 10!) * ResizeableBitmap -> ResizeableBitset and the odd other tidy up
author Chris Cannam
date Wed, 10 May 2006 11:43:52 +0000
parents base/ResizeableBitmap.h@7648e8502822
children 4ab844784152
comparison
equal deleted inserted replaced
112:7648e8502822 113:534373d65f39
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2
3 /*
4 Sonic Visualiser
5 An audio file viewer and annotation editor.
6 Centre for Digital Music, Queen Mary, University of London.
7 This file copyright 2006 Chris Cannam.
8
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation; either version 2 of the
12 License, or (at your option) any later version. See the file
13 COPYING included with this distribution for more information.
14 */
15
16 #ifndef _RESIZEABLE_BITMAP_H_
17 #define _RESIZEABLE_BITMAP_H_
18
19 #include <vector>
20 #include <stdint.h>
21
22 class ResizeableBitset {
23
24 public:
25 ResizeableBitset() : m_bits(0) {
26 }
27 ResizeableBitset(size_t size) : m_bits(new std::vector<uint8_t>) {
28 m_bits->assign(size / 8 + 1, 0);
29 }
30 ResizeableBitset(const ResizeableBitset &b) {
31 m_bits = new std::vector<uint8_t>(*b.m_bits);
32 }
33 ResizeableBitset &operator=(const ResizeableBitset &b) {
34 if (&b != this) return *this;
35 delete m_bits;
36 m_bits = new std::vector<uint8_t>(*b.m_bits);
37 return *this;
38 }
39 ~ResizeableBitset() {
40 delete m_bits;
41 }
42
43 void resize(size_t bits) { // losing all data
44 if (!m_bits || bits < m_bits->size()) {
45 delete m_bits;
46 m_bits = new std::vector<uint8_t>;
47 }
48 m_bits->assign(bits / 8, 0);
49 }
50
51 bool get(size_t column) const {
52 return ((*m_bits)[column / 8]) & (1u << (column % 8));
53 }
54
55 void set(size_t column) {
56 ((*m_bits)[column / 8]) |= (uint8_t(1) << (column % 8));
57 }
58
59 void reset(size_t column) {
60 ((*m_bits)[column / 8]) &= ~(uint8_t(1) << (column % 8));
61 }
62
63 void copy(size_t source, size_t dest) {
64 get(source) ? set(dest) : reset(dest);
65 }
66
67 private:
68 std::vector<uint8_t> *m_bits;
69 };
70
71
72 #endif
73