Mercurial > dedupe
comparison BitDecoder.cpp @ 45:41cc0d8ac77f
Decode directly from bitString.
| author | Tom Fredrik Blenning Klaussen <bfg@blenning.no> |
|---|---|
| date | Mon, 10 Sep 2012 21:29:43 +0200 |
| parents | 95a10553ff90 |
| children | f8d0ea827db3 |
comparison
equal
deleted
inserted
replaced
| 44:7348d4efa4f6 | 45:41cc0d8ac77f |
|---|---|
| 1 #include "BitDecoder.hpp" | 1 #include "BitDecoder.hpp" |
| 2 | |
| 3 #include "Exception/InvalidDataException.hpp" | |
| 2 | 4 |
| 3 BitDecoder::BitDecoder(BitDecoder* low_in, BitDecoder* high_in) : low(low_in), high(high_in) | 5 BitDecoder::BitDecoder(BitDecoder* low_in, BitDecoder* high_in) : low(low_in), high(high_in) |
| 4 { | 6 { |
| 5 } | 7 } |
| 6 | 8 |
| 59 retVal.insert(it.key(), unite(QBitArray(1, true), it.value())); | 61 retVal.insert(it.key(), unite(QBitArray(1, true), it.value())); |
| 60 } | 62 } |
| 61 } | 63 } |
| 62 return retVal; | 64 return retVal; |
| 63 } | 65 } |
| 66 | |
| 67 QBitArray BitDecoder::bitsFromString(const QString& str) | |
| 68 { | |
| 69 QBitArray bits(str.size()); | |
| 70 for (int i = 0; i < str.size(); ++i) { | |
| 71 if (str[i] == '1') | |
| 72 bits[i] = true; | |
| 73 else if (str[i] == '0') | |
| 74 bits[i] = false; | |
| 75 else | |
| 76 throw InvalidDataException(); | |
| 77 } | |
| 78 return bits; | |
| 79 } | |
| 80 | |
| 81 QString BitDecoder::decode(const QString& bits) const | |
| 82 { | |
| 83 return decode(bitsFromString(bits)); | |
| 84 } |
