summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibVT/Position.h
blob: 13a8e5b4b7127a3608237521de6e3c3c9eef0169 (plain)
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
/*
 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

namespace VT {

class Position {
public:
    Position() { }
    Position(int row, int column)
        : m_row(row)
        , m_column(column)
    {
    }

    bool is_valid() const { return m_row >= 0 && m_column >= 0; }
    int row() const { return m_row; }
    int column() const { return m_column; }

    bool operator<(const Position& other) const
    {
        return m_row < other.m_row || (m_row == other.m_row && m_column < other.m_column);
    }

    bool operator<=(const Position& other) const
    {
        return *this < other || *this == other;
    }

    bool operator>=(const Position& other) const
    {
        return !(*this < other);
    }

    bool operator==(const Position& other) const
    {
        return m_row == other.m_row && m_column == other.m_column;
    }

    bool operator!=(const Position& other) const
    {
        return !(*this == other);
    }

private:
    int m_row { -1 };
    int m_column { -1 };
};

}