push d05c3c071486b33b66ab6e343e6cce821d847653
[tagua/yd.git] / src / core / moveserializer.h
blob43ae2dd1773f49312402798aa334cb0d222bb13c
1 /*
2 Copyright (c) 2007 Paolo Capriotti <p.capriotti@gmail.com>
3 (c) 2007 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 CORE__MOVE_SERIALIZER_H
12 #define CORE__MOVE_SERIALIZER_H
14 #include <QString>
15 #include "export.h"
17 class IState;
18 class IType;
19 class Move;
21 /**
22 * @brief MoveSerializer takes care of converting moves to a displayable form and vice-versa.
24 class TAGUA_EXPORT IMoveSerializer {
25 public:
26 virtual ~IMoveSerializer();
28 /**
29 * Serialize a move given a reference game state.
30 * It is assumed that the move has already been tested against @a ref.
31 * Calling this function on an untested or illegal move is safe but its return
32 * value is undefined.
33 * Do not try to call this function on an invalid move.
34 * @param ref The position in which this move shall be executed.
35 * @return A string representation for this move.
37 virtual QString serialize(const Move& move, const IState* ref) const = 0;
39 /**
40 * Convert a string representation of a move back to a move object.
41 * @param ref The position in which this move shall be executed.
42 * @return A move corresponding to the given string representation.
44 virtual Move deserialize(const QString& str, const IState* ref) const = 0;
46 /**
47 * @return The symbol associated to the given type.
49 virtual QString symbol(const IType* type) const = 0;
51 /**
52 * Compute a move suffix (e.g. to represent checkmate).
53 * @param ref The position in which this move shall be executed.
54 * @return A suffix for the given move.
56 virtual QString suffix(const Move& move, const IState* ref) const = 0;
58 /**
59 * @return Serializer type.
61 virtual QString type() const = 0;
63 virtual void setDelegator(IMoveSerializer* delegator) = 0;
66 #endif // CORE__MOVE_SERIALIZER_H