neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
item_index.hpp
Go to the documentation of this file.
1// item_index.hpp
2/*
3 neogfx C++ App/Game Engine
4 Copyright (c) 2015, 2020 Leigh Johnston. All Rights Reserved.
5
6 This program is free software: you can redistribute it and / or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#pragma once
21
22#include <neogfx/neogfx.hpp>
23#include <tuple>
24#include <optional>
25
26namespace neogfx
27{
28 template <typename ModelIndexType>
30 {
31 typedef ModelIndexType index_type;
32 typedef item_index<index_type> self_type;
33 public:
34 typedef self_type abstract_type; // todo: create abstract interface
35 public:
36 typedef uint32_t value_type;
39 typedef std::optional<row_type> optional_row_type;
40 typedef std::optional<column_type> optional_column_type;
41 public:
43 iRow{ 0 }, iColumn{ 0 }
44 {
45 }
47 iRow{ aRow }, iColumn{ 0 }
48 {
49 }
51 iRow{ aRow }, iColumn{ aColumn }
52 {
53 }
54 public:
55 index_type& operator+=(const item_index& aRhs)
56 {
57 iRow += aRhs.iRow;
58 iColumn += aRhs.iColumn;
59 return static_cast<index_type&>(*this);
60 }
61 index_type& operator-=(const item_index& aRhs)
62 {
63 iRow -= aRhs.iRow;
64 iColumn -= aRhs.iColumn;
65 return static_cast<index_type&>(*this);
66 }
67 public:
68 row_type row() const
69 {
70 return iRow;
71 }
72 index_type with_row(row_type aRow) const
73 {
74 return index_type{ aRow, column() };
75 }
76 void set_row(row_type aRow)
77 {
78 iRow = aRow;
79 }
81 {
82 return iColumn;
83 }
84 index_type with_column(column_type aColumn) const
85 {
86 return index_type{ row(), aColumn };
87 }
88 void set_column(column_type aColumn)
89 {
90 iColumn = aColumn;
91 }
92 private:
93 row_type iRow;
94 column_type iColumn;
95 };
96
97 template <typename ModelIndexType>
99 {
100 return aLhs.row() == aRhs.row() && aLhs.column() == aRhs.column();
101 }
102
103 template <typename ModelIndexType>
105 {
106 return !(aLhs == aRhs);
107 }
108
109 template <typename ModelIndexType>
111 {
112 return std::forward_as_tuple(aLhs.row(), aLhs.column()) < std::forward_as_tuple(aRhs.row(), aRhs.column());
113 }
114
115 template <typename ModelIndexType>
117 {
118 return std::forward_as_tuple(aLhs.row(), aLhs.column()) > std::forward_as_tuple(aRhs.row(), aRhs.column());
119 }
120
121 template <typename ModelIndexType>
122 using optional_item_index = std::optional<item_index<ModelIndexType>> ;
123}
void set_column(column_type aColumn)
index_type with_column(column_type aColumn) const
self_type abstract_type
index_type & operator+=(const item_index &aRhs)
row_type row() const
column_type column() const
item_index(row_type aRow, column_type aColumn)
index_type & operator-=(const item_index &aRhs)
item_index(row_type aRow)
std::optional< column_type > optional_column_type
index_type with_row(row_type aRow) const
value_type column_type
void set_row(row_type aRow)
value_type row_type
std::optional< row_type > optional_row_type
std::optional< item_index< ModelIndexType > > optional_item_index
bool operator!=(color_or_gradient const &lhs, color const &rhs) noexcept
bool operator<(const basic_rect< CoordinateType, CoordinateSystem > &left, const basic_rect< CoordinateType, CoordinateSystem > &right)
bool operator==(const basic_rect< CoordinateType, CoordinateSystem > &left, const basic_rect< CoordinateType, CoordinateSystem > &right)
bool operator>(const basic_rect< CoordinateType, CoordinateSystem > &left, const basic_rect< CoordinateType, CoordinateSystem > &right)