ICF 3.1.1.10
Technical documentation of ICF Libraries
CIndex2d.h
Go to the documentation of this file.
1/********************************************************************************
2** This file is part of the ICF Framework. Copyright (C) Witold Gantzke & Kirill Lepskiy
3** ICF Framework may be used under the terms of the LGPL License v. 2.1 by the Free Software Foundation.
4********************************************************************************/
5
6#pragma once
7
8
9// Qt includes
10#include <QtCore/QPoint>
11#include <QtCore/QSize>
12
13// ICF includes
14#include <istd/TIndex.h>
15
16
17namespace istd
18{
19
20
24class CIndex2d: public TIndex<2>
25{
26public:
28
29 CIndex2d();
30 CIndex2d(int x, int y);
31 CIndex2d(const TIndex<2>& index);
32 CIndex2d(const QPoint& point);
33 CIndex2d(const QSize& size);
34
35 int GetX() const;
36 void SetX(int value);
37 int GetY() const;
38 void SetY(int value);
39
40 bool operator<(const CIndex2d& index) const;
41 bool operator>(const CIndex2d& index) const;
42 bool operator<=(const CIndex2d& index) const;
43 bool operator>=(const CIndex2d& index) const;
44
48 operator QSize() const;
49
53 operator QPoint() const;
54
58 operator QPointF() const;
59
63 CIndex2d& operator=(const CIndex2d& index);
64
68 CIndex2d& operator=(const TIndex<2>& index);
69};
70
71
72// inline methods
73
75{
76}
77
78
79inline CIndex2d::CIndex2d(int x, int y)
80{
81 SetAt(0, x);
82 SetAt(1, y);
83}
84
85
86inline CIndex2d::CIndex2d(const TIndex<2>& index)
87: BaseClass(index)
88{
89}
90
91inline CIndex2d::CIndex2d(const QPoint& point)
92{
93 SetAt(0, point.x());
94 SetAt(1, point.y());
95}
96
97
98inline CIndex2d::CIndex2d(const QSize& size)
99{
100 SetAt(0, size.width());
101 SetAt(1, size.height());
102}
103
104
105inline int CIndex2d::GetX() const
106{
107 return GetAt(0);
108}
109
110
111inline void CIndex2d::SetX(int value)
112{
113 SetAt(0, value);
114}
115
116
117inline int CIndex2d::GetY() const
118{
119 return GetAt(1);
120}
121
122
123inline void CIndex2d::SetY(int value)
124{
125 SetAt(1, value);
126}
127
128
129inline bool CIndex2d::operator<(const CIndex2d& index) const
130{
131 if (GetY() < index.GetY()){
132 return true;
133 }
134 else if (GetY() > index.GetY()){
135 return false;
136 }
137 else if (GetX() < index.GetX()){
138 return true;
139 }
140
141 return false;
142}
143
144
145inline bool CIndex2d::operator>(const CIndex2d& index) const
146{
147 return (!operator<(index) && !operator==(index));
148}
149
150
151inline bool CIndex2d::operator<=(const CIndex2d& index) const
152{
153 return (operator<(index) || operator==(index));
154}
155
156
157inline bool CIndex2d::operator>=(const CIndex2d& index) const
158{
159 return (!operator<(index) || operator==(index));
160}
161
162
164{
165 BaseClass::operator=(index);
166
167 return *this;
168}
169
170
172{
173 BaseClass::operator=(index);
174
175 return *this;
176}
177
178
179inline CIndex2d::operator QSize() const
180{
181 return QSize(GetX(), GetY());
182}
183
184
185inline CIndex2d::operator QPoint() const
186{
187 return QPoint(GetX(), GetY());
188}
189
190
191inline CIndex2d::operator QPointF() const
192{
193 return QPointF(GetX(), GetY());
194}
195
196
197} // namespace istd
198
199
Index implementation for addressing elements in 2D-space.
Definition CIndex2d.h:25
bool operator>=(const CIndex2d &index) const
Definition CIndex2d.h:157
int GetX() const
Definition CIndex2d.h:105
bool operator<=(const CIndex2d &index) const
Definition CIndex2d.h:151
bool operator>(const CIndex2d &index) const
Definition CIndex2d.h:145
void SetY(int value)
Definition CIndex2d.h:123
int GetY() const
Definition CIndex2d.h:117
void SetX(int value)
Definition CIndex2d.h:111
CIndex2d & operator=(const CIndex2d &index)
Assign value from another index.
Definition CIndex2d.h:163
TIndex< 2 > BaseClass
Definition CIndex2d.h:27
bool operator<(const CIndex2d &index) const
Definition CIndex2d.h:129
Multidimensional index used to addressing fixed-size array.
Definition TIndex.h:22
void SetAt(int index, int value)
Definition TIndex.h:282
int GetAt(int index) const
Definition TIndex.h:272
Standard library.
Definition IComponent.h:17

© Witold Gantzke and Kirill Lepskiy