~ubuntu-branches/ubuntu/quantal/kdegames/quantal

« back to all changes in this revision

Viewing changes to ksudoku/engine/ruleset.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2011-12-15 14:17:50 UTC
  • mfrom: (1.3.14)
  • Revision ID: package-import@ubuntu.com-20111215141750-6tj6brf4azhrt915
Tags: 4:4.7.90-0ubuntu1
new upstream beta release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#ifndef _KSUDOKU_GRAPH_H_
2
 
#define _KSUDOKU_GRAPH_H_
3
 
 
4
 
#include <QObject>
5
 
#include <QVector>
6
 
#include <QHash>
7
 
 
8
 
class Constraint;
9
 
class ConstraintHelper;
10
 
class Item;
11
 
class Storage;
12
 
 
13
 
class Ruleset : public QObject {
14
 
        Q_OBJECT
15
 
        friend class Constraint;
16
 
        friend class ConstraintHelper;
17
 
public:
18
 
        Ruleset();
19
 
        virtual ~Ruleset();
20
 
public:
21
 
        
22
 
public:
23
 
        const QVector<const ConstraintHelper*>& helpers() const {
24
 
                return m_helpers;
25
 
        }
26
 
 
27
 
        QVector<Storage*> storages() const;
28
 
        Storage *storage(int id);
29
 
        const Storage *storage(int id) const;
30
 
        int storageId(const QByteArray &name) const;
31
 
        int regStorage(const QByteArray &name, Storage *storage);
32
 
 
33
 
        void addItem(Item *item);
34
 
        QVector<Item*> itemList() const { return m_items; }
35
 
private:
36
 
        void addHelper(ConstraintHelper* helper);
37
 
 
38
 
private:
39
 
        QVector<const ConstraintHelper*> m_helpers;
40
 
        QVector<Item*> m_items;
41
 
        QHash<QByteArray, int> m_storageIds;
42
 
        QVector<Storage*> m_storages;
43
 
};
44
 
 
45
 
template<class T>
46
 
T *storage(Ruleset *rules) {
47
 
        int storageId = rules->storageId(T::name());
48
 
        if(storageId >= 0) {
49
 
                return static_cast<T*>(rules->storage(storageId));
50
 
        }
51
 
 
52
 
        T *storage = new T();
53
 
        rules->regStorage(T::name(), storage);
54
 
        return storage;
55
 
}
56
 
 
57
 
template<class T>
58
 
T *storage(const Ruleset *rules) {
59
 
        int storageId = rules->storageId(T::name());
60
 
        if(storageId >= 0) {
61
 
                return static_cast<T*>(rules->storage(storageId));
62
 
        }
63
 
        return 0;
64
 
}
65
 
 
66
 
#endif