2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@sns.it>
3 (c) 2006 Maurizio Monge <maurizio.monge@kdemail.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
11 #include "highlevel.h"
12 #include "graphicalposition.h"
14 template <typename Variant>
15 class WrappedElement {
18 typedef boost::shared_ptr<PieceSprite> SpritePtr;
20 Element inner() const { return m_inner; }
21 operator bool() const { return m_inner; }
24 WrappedElement(const Element& element)
27 TYPECHECK(*m_inner.piece(), WrappedPiece<Variant>);
28 // if (!dynamic_cast<WrappedPiece<Variant>*>(m_inner.piece().get()))
29 // MISMATCH(m_inner.piece().get(), WrappedPiece<Variant>);
32 const typename Variant::Piece& piece() const {
33 WrappedPiece<Variant>* res = dynamic_cast<WrappedPiece<Variant>*>(m_inner.piece().get());
38 SpritePtr sprite() const { return m_inner.sprite(); }
41 template <typename Variant>
42 class GenericGraphicalPosition {
43 typedef boost::shared_ptr<PieceSprite> SpritePtr;
44 typedef typename Variant::Piece Piece;
46 virtual ~GenericGraphicalPosition() { }
47 virtual int getIntSetting(const QString& key, int def_value) const = 0;
48 virtual bool getBoolSetting(const QString& key, bool def_value) const = 0;
49 virtual QString getStringSetting(const QString& key, const QString& def_value) const = 0;
51 virtual SpritePtr getSprite(const Point& p) const = 0;
53 virtual SpritePtr setPiece(const Point& p, const Piece& e,
54 bool usedrop = false, bool show = false) = 0;
56 virtual WrappedElement<Variant> getElement(const Point& p) const = 0;
58 virtual void setElement(const Point& p, const WrappedElement<Variant>& e) = 0;
60 virtual void removeElement(const Point& p) = 0;
61 virtual void updatePool(AbstractPosition::PoolPtr pool) = 0;
62 virtual void addTag(const QString& name, Point, bool over = false) = 0;
63 virtual void clearTags(const QString& name) = 0;
64 virtual void setTags(const QString& name, Point p1 = Point::invalid(), Point p2 = Point::invalid(),
65 Point p3 = Point::invalid(), Point p4 = Point::invalid(),
66 Point p5 = Point::invalid(), Point p6 = Point::invalid() ) = 0;
68 virtual Point first() const = 0;
69 virtual Point last() const = 0;
70 virtual Point next(const Point& p) const = 0;
71 virtual bool valid(const Point& p) const = 0;
72 virtual bool consistent() const = 0;
76 * @brief A strongly typed wrapper aroung GraphicalPosition.
78 template <typename Variant>
79 class WrappedGraphicalPosition : public GenericGraphicalPosition<Variant> {
80 typedef boost::shared_ptr<PieceSprite> SpritePtr;
81 typedef typename Variant::Piece Piece;
82 GraphicalPosition* m_inner;
84 typedef WrappedElement<Variant> GElement;
85 WrappedGraphicalPosition(GraphicalPosition* inner)
88 virtual int getIntSetting(const QString& key, int def_value) const {
89 return m_inner->getIntSetting(key, def_value);
92 virtual bool getBoolSetting(const QString& key, bool def_value) const {
93 return m_inner->getBoolSetting(key, def_value);
96 virtual QString getStringSetting(const QString& key, const QString& def_value) const {
97 return m_inner->getStringSetting(key, def_value);
100 virtual SpritePtr getSprite(const Point& p) const {
101 return m_inner->getSprite(p);
104 virtual SpritePtr setPiece(const Point& p, const Piece& e,
105 bool usedrop = false, bool show = false) {
106 AbstractPiece::Ptr piece(new WrappedPiece<Variant>(e));
107 return m_inner->setPiece(p, piece, usedrop, show);
110 virtual GElement getElement(const Point& p) const {
111 return m_inner->getElement(p);
114 virtual void setElement(const Point& p, const GElement& e) {
115 m_inner->setElement(p, e.inner());
118 virtual void removeElement(const Point& p) { m_inner->removeElement(p); }
119 virtual void updatePool(AbstractPosition::PoolPtr pool) { m_inner->updatePool(pool); }
120 virtual void addTag(const QString& name, Point p, bool over = false) { m_inner->addTag(name, p, over); }
121 virtual void clearTags(const QString& name) { m_inner->clearTags(name); }
122 virtual void setTags(const QString& name, Point p1 = Point::invalid(), Point p2 = Point::invalid(),
123 Point p3 = Point::invalid(), Point p4 = Point::invalid(),
124 Point p5 = Point::invalid(), Point p6 = Point::invalid() ) {
125 m_inner->setTags(name, p1, p2, p3, p4, p5, p6);
128 virtual Point first() const { return m_inner->first(); }
129 virtual Point last() const { return m_inner->last(); }
130 virtual Point next(const Point& p) const { return m_inner->next(p); }
131 virtual bool valid(const Point& p) const { return m_inner->valid(p); }
132 virtual bool consistent() const { return m_inner->consistent(); }