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

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

Punch Card Editor: Code reordering and class renaming, rewriting.
Now using the namespace QPunchCard everywhere.

Parted the whole application into 5 parts/directories:

  • app: The application core with MainWindow and main() function
  • qpunchcard: Everything directly binary card related (no interpretation): modeling, input/output, view. Most important classes are Card, Deck, FileFormat, Widget
  • text: Everything related to text interpretation of Cards/Card Decks. Having the abstract Codec classes and the Text::Editor, Text::EditorDock
  • deckviewer: Application components like binary card editing central widget (CardEditor) and Navigator (Model View Controller classes)
  • driver: Basis for the driver framework, must be written soon.

Deck now hides the complete Storage to implement frontend methods that
implement versioning (Undo framework). All code was cleaned up, but doesn't
compile right now (still quite some non heavy errors).

-- Sven @ workstation

File size: 1.9 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; class Deck; class DeckIndex;
17};
18
19namespace QPunchCard {
20
21/**
22 * A Column is a 12 bit storage...
23 **/
24class Column : public QBitArray {
25public:
26        Column() : QBitArray(13) {}
27
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.
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 **/
51class Card {
52
53public:
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        }
63        const Column& get(int x) const {
64                if(x < 0 || x > 80)
65                        throw "Out of range exception";
66                return column[x];
67        }
68        Column& operator[](int x) { return get(x); }
69        const Column& operator[](int x) const { return column[x]; }
70        int length() const { return 80; } // aja...
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
86QDebug operator<<(QDebug dbg, const Column &c);
87QDebug operator<<(QDebug dbg, const Card &c);
88
89
90}; // Namespace
91#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