3#include <Core/RaCore.hpp>
10class RA_CORE_API Index
13 using IntegerType = int;
17 constexpr Index( IntegerType i = s_invalid );
18 constexpr Index(
const Index& i );
22 template <
typename Integer>
23 explicit constexpr Index( Integer i );
30 constexpr bool isValid()
const;
33 constexpr bool isInvalid()
const;
34 constexpr void setInvalid();
37 static constexpr Index Invalid();
38 static constexpr Index Max();
41 constexpr IntegerType getValue()
const;
42 constexpr void setValue(
const IntegerType i );
45 constexpr operator IntegerType()
const;
48 constexpr Index& operator=(
const Index&
id );
49 constexpr Index& operator++();
50 constexpr Index& operator--();
52 constexpr Index operator+(
const Index&
id );
53 template <
typename Integer>
54 constexpr Index operator+(
const Integer& i );
56 constexpr Index operator-(
const Index&
id );
57 template <
typename Integer>
58 constexpr Index operator-(
const Integer& i );
60 constexpr bool operator==(
const Index&
id );
61 template <
typename Integer>
62 constexpr bool operator==(
const Integer& i );
65 template <
typename Integer>
68 constexpr bool operator<(
const Index& id1 );
69 template <
typename Integer>
70 constexpr bool operator<(
const Integer& i );
73 template <
typename Integer>
76 constexpr bool operator>(
const Index& id1 );
77 template <
typename Integer>
78 constexpr bool operator>(
const Integer& i );
81 template <
typename Integer>
86 IntegerType m_idx { s_invalid };
90 static const IntegerType s_invalid { -1 };
95constexpr Index::Index( IntegerType i ) : m_idx( ( i < 0 ) ? s_invalid : i ) {}
97template <
typename Integer>
98constexpr Index::Index( Integer i ) : m_idx( ( ( i < 0 ) || ( i > s_maxIdx ) ) ? s_invalid : i ) {
102constexpr Index::Index(
const Index& i ) : m_idx( i.m_idx ) {}
105constexpr bool Index::isValid()
const {
106 return ( m_idx != s_invalid );
110constexpr bool Index::isInvalid()
const {
111 return ( m_idx < 0 );
113constexpr void Index::setInvalid() {
116constexpr Index Index::Invalid() {
117 return Index( s_invalid );
119constexpr Index Index::Max() {
120 return Index( s_maxIdx );
124constexpr Index::IntegerType Index::getValue()
const {
127constexpr void Index::setValue(
const IntegerType i ) {
128 m_idx = ( i < 0 ) ? s_invalid : i;
133constexpr Index::operator IntegerType()
const {
138constexpr Index& Index::operator=(
const Index&
id ) {
142constexpr Index& Index::operator++() {
144 if ( m_idx < 0 ) { m_idx = s_invalid; }
147constexpr Index& Index::operator--() {
148 if ( m_idx != s_invalid ) { m_idx--; }
152constexpr Index Index::operator+(
const Index&
id ) {
153 if ( isInvalid() ||
id.isInvalid() ) {
return Index::Invalid(); }
154 return Index( m_idx +
id.m_idx );
156template <
typename Integer>
157constexpr Index Index::operator+(
const Integer&
id ) {
159 return ( *
this ) + Index(
id );
162constexpr Index Index::operator-(
const Index&
id ) {
163 if ( isInvalid() ||
id.isInvalid() ) {
return Index::Invalid(); }
164 return Index( m_idx -
id.m_idx );
166template <
typename Integer>
167constexpr Index Index::operator-(
const Integer&
id ) {
169 return ( *
this ) - Index(
id );
172constexpr bool Index::operator==(
const Index&
id ) {
173 return ( m_idx ==
id.m_idx );
175template <
typename Integer>
176constexpr bool Index::operator==(
const Integer& i ) {
178 return ( *
this == Index( IntegerType( i ) ) );
181constexpr bool Index::operator!=(
const Index&
id ) {
182 return ( !( *
this ==
id ) );
184template <
typename Integer>
185constexpr bool Index::operator!=(
const Integer& i ) {
187 return ( !( *
this == Index( IntegerType( i ) ) ) );
190constexpr bool Index::operator<(
const Index&
id ) {
191 if ( isInvalid() ||
id.isInvalid() ) {
return false; }
192 return ( m_idx <
id.m_idx );
194template <
typename Integer>
195constexpr bool Index::operator<(
const Integer& i ) {
196 return ( *
this < Index( IntegerType( i ) ) );
199constexpr bool Index::operator<=(
const Index&
id ) {
200 if ( isInvalid() ||
id.isInvalid() ) {
return false; }
201 return ( m_idx <=
id.m_idx );
203template <
typename Integer>
204constexpr bool Index::operator<=(
const Integer& i ) {
206 return ( *
this <= Index( IntegerType( i ) ) );
209constexpr bool Index::operator>(
const Index&
id ) {
210 if ( isInvalid() ||
id.isInvalid() ) {
return false; }
211 return ( m_idx >
id.m_idx );
213template <
typename Integer>
214constexpr bool Index::operator>(
const Integer& i ) {
216 return ( *
this > Index( IntegerType( i ) ) );
219constexpr bool Index::operator>=(
const Index&
id ) {
220 if ( isInvalid() ||
id.isInvalid() ) {
return false; }
221 return ( m_idx >=
id.m_idx );
223template <
typename Integer>
224constexpr bool Index::operator>=(
const Integer& i ) {
226 return ( *
this >= Index( IntegerType( i ) ) );
hepler function to manage enum as underlying types in VariableSet