annotate base/ResizeableBitset.h @ 537:3cc4b7cd2aa5

* Merge from one-fftdataserver-per-fftmodel branch. This bit of reworking (which is not described very accurately by the title of the branch) turns the MatrixFile object into something that either reads or writes, but not both, and separates the FFT file cache reader and writer implementations separately. This allows the FFT data server to have a single thread owning writers and one reader per "customer" thread, and for all locking to be vastly simplified and concentrated in the data server alone (because none of the classes it makes use of is used in more than one thread at a time). The result is faster and more trustworthy code.
author Chris Cannam
date Tue, 27 Jan 2009 13:25:10 +0000
parents 146eb9e35baa
children 95391b480e17
rev   line source
Chris@109 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@109 2
Chris@109 3 /*
Chris@109 4 Sonic Visualiser
Chris@109 5 An audio file viewer and annotation editor.
Chris@109 6 Centre for Digital Music, Queen Mary, University of London.
Chris@109 7 This file copyright 2006 Chris Cannam.
Chris@109 8
Chris@109 9 This program is free software; you can redistribute it and/or
Chris@109 10 modify it under the terms of the GNU General Public License as
Chris@109 11 published by the Free Software Foundation; either version 2 of the
Chris@109 12 License, or (at your option) any later version. See the file
Chris@109 13 COPYING included with this distribution for more information.
Chris@109 14 */
Chris@109 15
Chris@109 16 #ifndef _RESIZEABLE_BITMAP_H_
Chris@109 17 #define _RESIZEABLE_BITMAP_H_
Chris@109 18
Chris@109 19 #include <vector>
Chris@109 20 #include <stdint.h>
Chris@109 21
Chris@113 22 class ResizeableBitset {
Chris@109 23
Chris@109 24 public:
Chris@113 25 ResizeableBitset() : m_bits(0) {
Chris@109 26 }
Chris@113 27 ResizeableBitset(size_t size) : m_bits(new std::vector<uint8_t>) {
Chris@183 28 m_bits->assign((size >> 3) + 1, 0);
Chris@109 29 }
Chris@113 30 ResizeableBitset(const ResizeableBitset &b) {
Chris@109 31 m_bits = new std::vector<uint8_t>(*b.m_bits);
Chris@109 32 }
Chris@113 33 ResizeableBitset &operator=(const ResizeableBitset &b) {
Chris@109 34 if (&b != this) return *this;
Chris@109 35 delete m_bits;
Chris@109 36 m_bits = new std::vector<uint8_t>(*b.m_bits);
Chris@109 37 return *this;
Chris@109 38 }
Chris@113 39 ~ResizeableBitset() {
Chris@109 40 delete m_bits;
Chris@109 41 }
Chris@109 42
Chris@109 43 void resize(size_t bits) { // losing all data
Chris@109 44 if (!m_bits || bits < m_bits->size()) {
Chris@109 45 delete m_bits;
Chris@109 46 m_bits = new std::vector<uint8_t>;
Chris@109 47 }
Chris@183 48 m_bits->assign((bits >> 3) + 1, 0);
Chris@109 49 }
Chris@109 50
Chris@109 51 bool get(size_t column) const {
Chris@183 52 return ((*m_bits)[column >> 3]) & (1u << (column & 0x07));
Chris@109 53 }
Chris@109 54
Chris@112 55 void set(size_t column) {
Chris@183 56 ((*m_bits)[column >> 3]) |= (uint8_t(1) << (column & 0x07));
Chris@112 57 }
Chris@112 58
Chris@112 59 void reset(size_t column) {
Chris@183 60 ((*m_bits)[column >> 3]) &= ~(uint8_t(1) << (column & 0x07));
Chris@112 61 }
Chris@112 62
Chris@112 63 void copy(size_t source, size_t dest) {
Chris@112 64 get(source) ? set(dest) : reset(dest);
Chris@109 65 }
Chris@109 66
Chris@109 67 private:
Chris@109 68 std::vector<uint8_t> *m_bits;
Chris@109 69 };
Chris@109 70
Chris@109 71
Chris@109 72 #endif
Chris@109 73