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.
19 \class Index index.h <index.h>
20 \brief An index in a multi-variations game.
22 This is a class that you can use to refer to a position in a game.
28 Ref(int v
, int n
) : variation(v
), num_moves(n
) {}
32 bool operator==(const Ref
& r
) const {
33 return r
.variation
== variation
34 && r
.num_moves
== num_moves
;
36 bool operator!=(const Ref
& r
) const { return !((*this)==r
); }
40 std::vector
<Ref
> nested
;
42 /** Constructor, you can contruct it from an integer that
43 is the number of moves played in the main line */
44 Index(int n
) : num_moves(n
) {}
46 operator QString() const;
47 int totalNumMoves() const;
48 bool atVariationStart() const;
49 Index
flipVariation(const Index
& vstart
, int v_id
) const;
50 Index
next(int variation_id
= -1, int num
= 1) const;
51 Index
prev(int _num
= 1) const;
52 Index
min(const Index
& ix
) const;
53 std::pair
<int, int> stepsTo(const Index
& ix
) const;
56 /** True if this index refers to a position 'before' than the given one */
57 bool operator<(const Index
& ix
) const {
58 std::pair
<int,int> s
= stepsTo(ix
);
59 return s
.first
== 0 && s
.second
>0;
62 /** True if this index refers to a position 'before or equal' than the given one */
63 bool operator<=(const Index
& ix
) const {
64 std::pair
<int,int> s
= stepsTo(ix
);
68 /** True if this index refers to a position 'after' than the given one */
69 bool operator>(const Index
& ix
) const {
73 /** True if this index refers to a position 'after or equal' than the given one */
74 bool operator>=(const Index
& ix
) const {
78 /** True if this index refers to the same position of the given one */
79 bool operator==(const Index
& ix
) const {
80 std::pair
<int,int> s
= stepsTo(ix
);
81 return s
.first
== 0 && s
.second
== 0;
84 /** True if this index refers to a different position of the given one */
85 bool operator!=(const Index
& ix
) const {
86 return !(*this == ix
);
89 static Index
fromString(const QString
& s
);