Changed my email in the copyright statements.
[tagua/yd.git] / src / controllers / abstract.h
blob5a102e9ea8da8853e5d53c02bcff02c9db9f230b
1 /*
2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@gmail.com>
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.
9 */
11 #ifndef CONTROLLER_H
12 #define CONTROLLER_H
14 #include <boost/enable_shared_from_this.hpp>
15 #include <qstring.h>
16 #include "common.h"
17 #include "entitytoken.h"
18 #include "fwd.h"
20 class ChessTable;
21 class UserEntity;
22 class Engine;
23 class PGN;
24 class ActionCollection;
26 /**
27 * @b Controller is the base abstract class for all controllers in Tagua.
28 * Tagua can be used in different modes, such as game editing or position editing.
29 * Each mode corresponds to a concrete subclass of Controller, and defines its behaviour
30 * in response to user events (history navigation, move executions...).
31 * By default, events are routed to the user entity returned by the virtual function
32 * entity.
34 class Controller : public boost::enable_shared_from_this<Controller> {
35 protected:
36 ChessTable* m_view;
37 virtual boost::shared_ptr<UserEntity> entity() const = 0;
38 public:
39 Controller(ChessTable* view);
40 virtual ~Controller();
42 /**
43 * Variant specific actions.
45 virtual ActionCollection* variantActions() const = 0;
47 /**
48 * Variant associated to the controller.
50 virtual QString variant() const = 0;
52 /**
53 * Terminate activity, create another controller and delegate everything to it.
54 * @return The delegate controller, or simply @b this if controller does not need
55 * to be terminated.
57 virtual boost::shared_ptr<Controller> end() { return shared_from_this(); }
59 /**
60 * Detach from resources without disposing them.
62 virtual void detach() { }
64 /**
65 * Clear board. Undefined for almost all controllers.
66 * @return Whether the action has been successfully executed.
68 virtual bool clearBoard() { return false; }
70 /**
71 * Set starting position on the board. Undefined for almost all controllers.
72 * @return Whether the action has been successfully executed.
74 virtual bool setStartingPosition() { return false; }
76 /**
77 * Set a position on the board. Undefined for almost all controllers.
78 * @param fen The position to be set, in FEN notation.
79 * @return Whether the action has been successfully executed.
81 virtual bool setFEN(const QString&) { return false; }
83 /**
84 * Get a FEN string representing the current position on the board.
86 virtual QString fen() { return ""; }
88 /**
89 * @return current position, or a null shared_ptr if no current position
90 * concept is defined for this controller.
92 virtual PositionPtr currentPosition() const { return PositionPtr(); }
94 /**
95 * Change turn. Used for example in edit position mode.
97 virtual void setTurn(int) { }
99 /**
100 * Forward a movelist undo call.
102 virtual bool undo();
105 * Forward a movelist redo call.
107 virtual bool redo();
110 * Forward a movelist truncate call.
112 virtual bool truncate();
115 * Forward a movelist promote variation call.
117 virtual bool promoteVariation();
120 * Navigate back in history.
122 virtual bool back();
125 * Navigate forward in history.
127 virtual bool forward();
130 * Warp to the beginning of the history.
132 virtual void gotoFirst();
135 * Warp to the end of the history.
137 virtual void gotoLast();
140 * Save game.
142 virtual QString save();
145 * Load game from a PGN.
147 virtual void loadPGN(const PGN&);
150 * Create a CTRL Action.
151 * @sa UI::createCtrlAction
153 virtual void createCtrlAction() { }
156 * Destroy a CTRL Action.
157 * @sa UI::createCtrlAction.
159 virtual void destroyCtrlAction() { };
162 * Let an engine play as player @a side.
163 * @return a token which uniquely identifies the engine entity
164 * and can be used to remove it from the entity list.
166 virtual EntityToken addPlayingEngine(int /*side*/, const boost::shared_ptr<Engine>&) { return EntityToken(); }
169 * Remove an entity from the controller list.
171 virtual void removeEntity(const EntityToken&) { }
175 #endif