Cute Chess 0.1
side.h
1/*
2 This file is part of Cute Chess.
3 Copyright (C) 2008-2018 Cute Chess authors
4
5 Cute Chess 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 3 of the License, or
8 (at your option) any later version.
9
10 Cute Chess is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with Cute Chess. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19#ifndef SIDE_H
20#define SIDE_H
21
22#include <QString>
23#include <QMetaType>
24#include <QCoreApplication>
25
26namespace Chess {
27
35class LIB_EXPORT Side
36{
37 Q_DECLARE_TR_FUNCTIONS(Side)
38
39 public:
41 enum Type
42 {
46 };
47
49 Side();
51 Side(Type type);
58 explicit Side(const QString& symbol);
59
61 bool isNull() const;
63 operator Type() const;
64
69 Side opposite() const;
71 QString symbol() const;
73 QString toString() const;
74
75 private:
76 Type m_type;
77};
78
79inline Side::Side()
80 : m_type(NoSide)
81{
82}
83
84inline Side::Side(Type type)
85 : m_type(type)
86{
87}
88
89inline bool Side::isNull() const
90{
91 return (m_type == NoSide);
92}
93
94inline Side::operator Type() const
95{
96 return m_type;
97}
98
99inline Side Side::opposite() const
100{
101 Q_ASSERT(!isNull());
102 return Side(Type(int(m_type) ^ 1));
103}
104
105} // namespace Chess
106
107Q_DECLARE_METATYPE(Chess::Side)
108
109#endif // SIDE_H
The side or color of a chess player.
Definition side.h:36
Type
Definition side.h:42
@ Black
The side with the black pieces.
Definition side.h:44
@ White
The side with the white pieces.
Definition side.h:43
@ NoSide
No side.
Definition side.h:45
Side()
Definition side.h:79
Side opposite() const
Definition side.h:99
bool isNull() const
Definition side.h:89