File: PieceTransforms.h

package info (click to toggle)
pentobi 26.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,068 kB
  • sloc: cpp: 25,986; javascript: 897; xml: 57; makefile: 13; sh: 11
file content (71 lines) | stat: -rw-r--r-- 2,111 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//-----------------------------------------------------------------------------
/** @file libpentobi_base/PieceTransforms.h
    @author Markus Enzenberger
    @copyright GNU General Public License version 3 or later */
//-----------------------------------------------------------------------------

#ifndef LIBPENTOBI_PIECE_TRANSFORMS_H
#define LIBPENTOBI_PIECE_TRANSFORMS_H

#include <vector>
#include "libboardgame_base/Transform.h"

namespace libpentobi_base {

using namespace std;
using libboardgame_base::Transform;

//-----------------------------------------------------------------------------

class PieceTransforms
{
public:
    virtual ~PieceTransforms();


    virtual const Transform* get_mirrored_horizontally(
                                            const Transform* transf) const = 0;

    virtual const Transform* get_mirrored_vertically(
                                            const Transform* transf) const = 0;

    virtual const Transform* get_rotated_anticlockwise(
                                            const Transform* transf) const = 0;

    virtual const Transform* get_rotated_clockwise(
                                            const Transform* transf) const = 0;

    const vector<const Transform*>& get_all() const;

    /** Find the transform by its class.
        @tparam T The class of the transform.
        @return The pointer to the transform or null if the transforms do not
        contain the instance of the given class. */
    template<class T>
    const Transform* find() const;

protected:
    /** All piece transformations.
        Must be initialized in constructor of subclass. */
    vector<const Transform*> m_all;
};

template<class T>
const Transform* PieceTransforms::find() const
{
    for (auto t : m_all)
        if (dynamic_cast<const T*>(t))
            return t;
    return nullptr;
}

inline const vector<const Transform*>& PieceTransforms::get_all() const
{
    return m_all;
}

//-----------------------------------------------------------------------------

} // namespace libpentobi_base

#endif // LIBPENTOBI_PIECE_TRANSFORMS_H