source: projects/punch-card/punch-card-editor/src/qpunchcard/card.h @ 53

Last change on this file since 53 was 53, checked in by sven, 10 years ago

Punch Card Editor, ongoing development

  • Extended new Deck interface, expanding the undo framework
  • Implemented editor changes via undo framework
  • revised the menu and toolbar actions and structure (now dynamic construction at deck load time), implemented undo viewer
  • Started implementation of device driver framework in menu
  • Embedded the Qextserialport library (http://qextserialport.sourceforge.net/)
  • Started the Documation M200 Client device driver (well, just created the directory structure and qmake project file infrastructure)
  • At the current state, the complete project compiles :-)

Statistics: About 3500 Lines of code (without libqextserialport)

-- sven @ workstation

File size: 2.8 KB
Line 
1#ifndef CARD_H
2#define CARD_H
3
4#include <QBitArray>
5#include <QHash>
6#include <QList>
7#include <QPointer>
8#include <QDebug>
9#include <QUndoStack>
10#include <QFile>
11#include <QSharedPointer>
12
13#include <QModelIndex>
14
15namespace QPunchCard {
16        class Column;
17        class Card;
18        class CardIndex;
19};
20
21namespace QPunchCard {
22
23/**
24 * A Column is a 12 bit storage...
25 **/
26class Column : public QBitArray {
27public:
28        Column() : QBitArray(13) {}
29
30        // TODO: int-Casting komplett entfernen. Das ist nicht Sinn
31        //       der Sache bei der *Modellierung*, sondern eben eher
32        //       beim Import/Export. Natuerlich *kann* man hier Methoden
33        //       fuer sowas bereitstellen.
34        Column(int value) : QBitArray(13) {
35                // TODO: range check, throw exception if bad
36                for(int s=0; s<12; s++) {
37                        setBit(s, (1 << s) & value);
38                        //setBit(s, (value >> s) & 0x01);
39                }
40        }
41
42        operator int() const {
43                int ret=0;
44                for(int s=0; s<12; s++)
45                        ret |= testBit(s) << s;
46                return ret;
47        }
48};
49
50/**
51 * This is a punch card.
52 **/
53class Card {
54
55public:
56        Card() {};
57        QHash<QString,QString> properties;
58
59        Column column[80];
60        Column& get(int x) {
61                if(x < 0 || x > 80)
62                        throw "Out of range exception";
63                return column[x];
64        }
65        const Column& get(int x) const {
66                if(x < 0 || x > 80)
67                        throw "Out of range exception";
68                return column[x];
69        }
70        Column& operator[](int x) { return get(x); }
71        const Column& operator[](int x) const { return column[x]; }
72        int length() const { return 80; } // aja...
73
74        /*Card& operator=(const Card& other) {
75                // copy assignment, etc.
76                for(int x=0; x<80; x++) column[x] = other[x];
77                return *this;
78        }*/
79
80        ~Card() {};
81}; // class Card
82
83/**
84 * An int with bounds (i is in [0, 79]). Behaves like DeckIndex (deck.h),
85 * but slightly less intelligent since it does not need to know the
86 * corresponding Card since all cards have same length (80 columns).
87 * Use this class as an integer.
88 **/
89class CardIndex {
90private:
91        int i;
92
93public:
94        // behaves like int, copy constructor and operator= will be created automatically
95        CardIndex(int i = 0) : i(i) {}
96        operator int() const { return normalized(); }
97        int asInt() const { return normalized(); }
98
99        bool isValid() const { return i >= 0 && i < 80; }
100
101        // "normalisierung" = in Card bounds
102        bool isNormalized() const { return i == normalized(); }
103        int normalized() const { if(i < 0) return 0; else if(i >= 80) return 79; else return i; }
104        void normalize() { i = normalized(); }
105
106        // special positions
107        bool isFirst() const { return i == 0; }
108        bool isLast() const { return i == 79; }
109
110        CardIndex& operator++() { i++; return *this; }
111        CardIndex& operator+=(int x) { i+= x; return *this; }
112};
113
114/****************************************************************************
115  debug functions
116 ***************************************************************************/
117
118QDebug operator<<(QDebug dbg, const Column &c);
119QDebug operator<<(QDebug dbg, const Card &c);
120
121
122}; // Namespace
123#endif // CARD_H
Note: See TracBrowser for help on using the repository browser.
© 2008 - 2013 technikum29 • Sven Köppel • Some rights reserved
Powered by Trac
Expect where otherwise noted, content on this site is licensed under a Creative Commons 3.0 License