[44] | 1 | #ifndef CARD_H |
---|
| 2 | #define CARD_H |
---|
| 3 | |
---|
| 4 | #include <QBitArray> |
---|
| 5 | #include <QHash> |
---|
[47] | 6 | #include <QList> |
---|
[44] | 7 | #include <QPointer> |
---|
| 8 | #include <QDebug> |
---|
| 9 | #include <QUndoStack> |
---|
| 10 | #include <QFile> |
---|
[49] | 11 | #include <QSharedPointer> |
---|
[44] | 12 | |
---|
[47] | 13 | #include <QModelIndex> |
---|
| 14 | |
---|
[44] | 15 | namespace QPunchCard { |
---|
[52] | 16 | class Column; class Deck; class DeckIndex; |
---|
[44] | 17 | }; |
---|
| 18 | |
---|
| 19 | namespace QPunchCard { |
---|
| 20 | |
---|
| 21 | /** |
---|
| 22 | * A Column is a 12 bit storage... |
---|
| 23 | **/ |
---|
| 24 | class Column : public QBitArray { |
---|
| 25 | public: |
---|
| 26 | Column() : QBitArray(13) {} |
---|
| 27 | |
---|
[52] | 28 | // TODO: int-Casting komplett entfernen. Das ist nicht Sinn |
---|
| 29 | // der Sache bei der *Modellierung*, sondern eben eher |
---|
| 30 | // beim Import/Export. Natuerlich *kann* man hier Methoden |
---|
| 31 | // fuer sowas bereitstellen. |
---|
[44] | 32 | Column(int value) : QBitArray(13) { |
---|
| 33 | // TODO: range check, throw exception if bad |
---|
| 34 | for(int s=0; s<12; s++) { |
---|
| 35 | setBit(s, (1 << s) & value); |
---|
| 36 | //setBit(s, (value >> s) & 0x01); |
---|
| 37 | } |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | operator int() const { |
---|
| 41 | int ret=0; |
---|
| 42 | for(int s=0; s<12; s++) |
---|
| 43 | ret |= testBit(s) << s; |
---|
| 44 | return ret; |
---|
| 45 | } |
---|
| 46 | }; |
---|
| 47 | |
---|
| 48 | /** |
---|
| 49 | * This is a punch card. |
---|
| 50 | **/ |
---|
[52] | 51 | class Card { |
---|
[44] | 52 | |
---|
| 53 | public: |
---|
| 54 | Card() {}; |
---|
| 55 | QHash<QString,QString> properties; |
---|
| 56 | |
---|
| 57 | Column column[80]; |
---|
| 58 | Column& get(int x) { |
---|
| 59 | if(x < 0 || x > 80) |
---|
| 60 | throw "Out of range exception"; |
---|
| 61 | return column[x]; |
---|
| 62 | } |
---|
[47] | 63 | const Column& get(int x) const { |
---|
| 64 | if(x < 0 || x > 80) |
---|
| 65 | throw "Out of range exception"; |
---|
| 66 | return column[x]; |
---|
| 67 | } |
---|
[44] | 68 | Column& operator[](int x) { return get(x); } |
---|
| 69 | const Column& operator[](int x) const { return column[x]; } |
---|
[47] | 70 | int length() const { return 80; } // aja... |
---|
[44] | 71 | |
---|
| 72 | /*Card& operator=(const Card& other) { |
---|
| 73 | // copy assignment, etc. |
---|
| 74 | for(int x=0; x<80; x++) column[x] = other[x]; |
---|
| 75 | return *this; |
---|
| 76 | }*/ |
---|
| 77 | |
---|
| 78 | ~Card() {}; |
---|
| 79 | }; |
---|
| 80 | |
---|
| 81 | |
---|
| 82 | /**************************************************************************** |
---|
| 83 | debug functions |
---|
| 84 | ***************************************************************************/ |
---|
| 85 | |
---|
[52] | 86 | QDebug operator<<(QDebug dbg, const Column &c); |
---|
| 87 | QDebug operator<<(QDebug dbg, const Card &c); |
---|
[44] | 88 | |
---|
| 89 | |
---|
| 90 | }; // Namespace |
---|
| 91 | #endif // CARD_H |
---|