Cute Chess  0.1
side.h
1 /*
2  This file is part of Cute Chess.
3 
4  Cute Chess is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  Cute Chess is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with Cute Chess. If not, see <http://www.gnu.org/licenses/>.
16 */
17 
18 #ifndef SIDE_H
19 #define SIDE_H
20 
21 #include <QString>
22 #include <QMetaType>
23 #include <QCoreApplication>
24 
25 namespace Chess {
26 
34 class LIB_EXPORT Side
35 {
36  Q_DECLARE_TR_FUNCTIONS(Side)
37 
38  public:
40  enum Type
41  {
44  NoSide
45  };
46 
48  Side();
50  Side(Type type);
57  explicit Side(const QString& symbol);
58 
60  bool isNull() const;
62  operator Type() const;
63 
68  Side opposite() const;
70  QString symbol() const;
72  QString toString() const;
73 
74  private:
75  Type m_type;
76 };
77 
78 inline Side::Side()
79  : m_type(NoSide)
80 {
81 }
82 
83 inline Side::Side(Type type)
84  : m_type(type)
85 {
86 }
87 
88 inline bool Side::isNull() const
89 {
90  return (m_type == NoSide);
91 }
92 
93 inline Side::operator Type() const
94 {
95  return m_type;
96 }
97 
98 inline Side Side::opposite() const
99 {
100  Q_ASSERT(!isNull());
101  return Side(Type(int(m_type) ^ 1));
102 }
103 
104 } // namespace Chess
105 
106 Q_DECLARE_METATYPE(Chess::Side)
107 
108 #endif // SIDE_H
The side with the black pieces.
Definition: side.h:43
The side with the white pieces.
Definition: side.h:42
Definition: boardscene.h:28
Side opposite() const
Definition: side.h:98
The side or color of a chess player.
Definition: side.h:34
No side.
Definition: side.h:44
bool isNull() const
Definition: side.h:88
Side()
Definition: side.h:78
Type
Definition: side.h:40