|
User Documentation |
|
Centre for Vision, Speech & Signal Processing |
Comments:
The class IndexC is designed as a replacement for the built-in C
int type, in an atttempt to correct some of the perceived
deficiencies of int:
- Unsigned integers:
- When combining signed and unsigned integers in a binary operation, C
always converts the signed integer to unsigned, which can generate
surprising results such as:
(unsigned int) 4 / (-2) = 0.
- Rounding:
- With the
int type, rounding is either towards zero (e.g. on conversion
from floating point representations), or implementation-dependent (e.g.
integer division operations). Where negative numbers are
involved, this behaviour is often not what is required, particularly for
indexing purposes.
The behaviour of IndexC therefore differs from that of int, to
provide more consistent behaviour for indexing purposes, and to improve
portability of code.
The major differences between IndexC and int are:
- Unsigned integers:
- Where relevant, unsigned integers are converted to signed before
combining with IndexC.
- Rounding:
- Rounding is always to the nearest more negative integer. This affects:
- Truncation of floating point values on conversion to IndexC.
- Integer division operations involving IndexC as dividend (numerator),
for which:
- if the divisor is negative, the signs of both divisor and dividend
are reversed before dividing;
- the quotient is always rounded towards
the more negative nearest integer, regardless of the sign of the dividend.
- The modulo operator, which is always consistent with the AMMA divide,
operator as per the C and C++ modulo operator standards. It accordingly
always returns a non-negative value.
Thus (IndexC) -5 / 3 yields -2, and (IndexC) -5 % 3 yields 1.
With the int type, the results would probably be -1 and -2
respectively.
Remember: IndexC is a class, not a built-in. So:
- The type conversion rules are not necessarily the same as for
int. For a class, the type of the first operand of
binary operator determines the class member function used.
- Because there is no implicit conversion from IndexC to
int, you can't use IndexC everywhere you would use an
int. In particular you can't use an IndexC object directly as
an int function argument. You need to use the V() member function to achieve this. (We
could have provided the implicit conversion, but it would then be
very difficult sometimes to know which was actually being used.)
See also the class bugs above.
Bugs:
- operator-:
- Currently, IndexC::operator-(IndexC) returns an IntT, not
(as you might have expected) an IndexC. This can give
surprising results.
Enumerated types:
Variables:
Methods:
- IndexC(const IntT i = 0)
-
Creates the index with the value 'i'.
- IndexC(const SizeT s)
-
Creates the index with the same value as the value of size 's'.
- IndexC(const IndexC & i)
-
Creates the index with the same value as the index 'i' has.
- IndexC(const DoubleT i)
-
Creates the index with the value rounded version of 'i'.
Access functions:
- IntT V(void) const
-
Returns the current value of the index.
- IntT & V(void)
-
Returns the current value of the index.
- BooleanT IsInRange(SizeT size) const
-
True if 0 <= this < size
Conversions:
The obvious conversions from index to integer numbers
are missing to avoid automatic conversion of an index expression
into integer expression. In this way such a conversion
is detected in compilation time and one can decide which
type of expression is proper one.
- operator BooleanT() const
-
Returns TRUE if the index value is different from 0.
- operator bool() const
-
Returns TRUE if the index value is different from 0.
- operator ByteT() const
-
Truncates the index value and returns it as ByteT.
- operator CharT() const
-
Truncates the index value and returns it as CharT.
- operator SCharT() const
-
Truncates the index value and returns it as SCharT.
- operator FloatT() const
-
Converts the index value into float representation.
- operator DoubleT() const
-
Converts the index value into double representation.
Arithmetical operations:
- IndexC operator-() const
-
Returns opposite index (unary minus operator).
- IndexC & operator++()
-
The prefix operator increments the index value by 1.
- IndexC operator++(int)
-
The postfix operator increments the index value by 1.
- IndexC & operator--()
-
The prefix operator decrements the index value by 1.
- IndexC operator--(int)
-
The postfix operator decrements the index value by 1.
- IndexC operator+(const IntT i) const
-
Returns a new index with value of this index added by integer 'i'.
- IndexC operator-(const IntT i) const
-
Returns a new index with value of this index subtracted by integer 'i'.
- IndexC operator*(const IntT i) const
-
Returns a new index with value of this index multiplied by integer 'i'.
- IndexC operator/(const IntT i) const
-
Returns a new index with value of this index divided by integer 'i'.
- const IndexC & operator+=(const IntT i)
-
Returns this index added by integer 'i'.
- const IndexC & operator-=(const IntT i)
-
Returns this index subtracted by integer 'i'.
- const IndexC & operator*=(const IntT i)
-
Returns this index multiplied by integer 'i'.
- const IndexC & operator/=(const IntT i)
-
Returns this index divided by integer 'i'.
- IndexC operator+(const UIntT i) const
-
Returns a new index with value of this index added by integer 'i'.
- IndexC operator-(const UIntT i) const
-
Returns a new index with value of this index subtracted by integer 'i'.
- IndexC operator*(const UIntT i) const
-
Returns a new index with value of this index multiplied by integer 'i'.
- IndexC operator/(const UIntT i) const
-
Returns a new index with value of this index divided by integer 'i'.
- IndexC operator%(const UIntT i) const
-
Returns a new index with value of modulo operation between
this index and integer 'i'.
- IndexC operator%(const IntT i) const
-
Returns a new index with value of modulo operation between
this index and integer 'i'.
- const IndexC & operator+=(const UIntT i)
-
Returns this index added by integer 'i'.
- const IndexC & operator-=(const UIntT i)
-
Returns this index subtracted by integer 'i'.
- const IndexC & operator*=(const UIntT i)
-
Returns this index multiplied by integer 'i'.
- const IndexC & operator/=(const UIntT i)
-
Returns this index divided by integer 'i'.
- DoubleT operator+(const DoubleT i) const
-
Returns a new index with value of this index added by double 'i'
cut to integer value.
- DoubleT operator-(const DoubleT i) const
-
Returns a new index with value of this index subtracted by double 'i'
cut to integer value.
- DoubleT operator*(const DoubleT i) const
-
Returns a new index with value of this index multiplied by double 'i'.
The result is cut to integer value and converted to index value.
- DoubleT operator/(const DoubleT i) const
-
Returns a new index with value of this index divided by double 'i'.
The result is cut to integer value and converted to index value.
- const IndexC & operator+=(const DoubleT i)
-
Returns this index added by double 'i' cut to integer value.
- const IndexC & operator-=(const DoubleT i)
-
Returns this index subtracted by double 'i' cut to integer value.
- const IndexC & operator*=(const DoubleT i)
-
Returns this index multiplied by double 'i' with the result converted to
index value type.
- const IndexC & operator/=(const DoubleT i)
-
Returns this index divided by double 'i' with the result converted to
index value type.
- IndexC operator+(const IndexC & i) const
-
Returns a new index with value of this index added by the value
of index 'i'.
- IntT operator-(const IndexC & i) const
-
Returns a value of this index subtracted by the value
of index 'i'.
- IndexC operator/(const IndexC & i) const
-
Returns a new index with value of this index divided by the value
of index 'i'.
- IndexC operator*(const IndexC & i) const
-
Returns a new index with value of this index multiplied by the value
of index 'i'.
- const IndexC & operator+=(const IndexC & i)
-
Returns this index added by index 'i'.
- const IndexC & operator-=(const IndexC & i)
-
Returns this index subtracted by index 'i'.
- const IndexC & operator*=(const IndexC & i)
-
Returns this index multiplied by index 'i'.
- const IndexC & operator/=(const IndexC & i)
-
Returns his index divided by index 'i'.
Modifications of indices:
- IndexC operator<<(const IntT i) const
-
Returns the new index with the value equal to the value of this
index shifted 'i' position to the left.
- IndexC operator>>(const IntT i) const
-
Returns the new index with the value equal to the value of this
index shifted 'i' position to the right.
Logical operators with integer numbers:
- BooleanT operator==(const IntT i) const
-
Returns TRUE if the value of this index is equal to
the integer number 'i'.
- BooleanT operator!=(const IntT i) const
-
Returns TRUE if the value of this index is not equal to
the integer number 'i'.
- BooleanT operator<(const IntT i) const
-
Returns TRUE if the value of this index is smaller than
the integer number 'i'.
- BooleanT operator<=(const IntT i) const
-
Returns TRUE if the value of this index is smaller than
or equal to the integer number 'i'.
- BooleanT operator>(const IntT i) const
-
Returns TRUE if the value of this index is greater than
the integer number 'i'.
- BooleanT operator>=(const IntT i) const
-
Returns TRUE if the value of this index is greater than
or equal to the integer number 'i'.
Logical operators with unsigned integer numbers:
- BooleanT operator==(const UIntT i) const
-
Returns TRUE if the value of this index is equal to
the integer number 'i'.
- BooleanT operator!=(const UIntT i) const
-
Returns TRUE if the value of this index is not equal to
the integer number 'i'.
- BooleanT operator<(const UIntT i) const
-
Returns TRUE if the value of this index is smaller than
the integer number 'i'.
- BooleanT operator<=(const UIntT i) const
-
Returns TRUE if the value of this index is smaller than
or equal to the integer number 'i'.
- BooleanT operator>(const UIntT i) const
-
Returns TRUE if the value of this index is greater than
the integer number 'i'.
- BooleanT operator>=(const UIntT i) const
-
Returns TRUE if the value of this index is greater than
or equal to the integer number 'i'.
Logical operators with double numbers:
- BooleanT operator==(const DoubleT i) const
-
Returns TRUE if the value of this index is equal to
the integer number 'i'.
- BooleanT operator!=(const DoubleT i) const
-
Returns TRUE if the value of this index is not equal to
the integer number 'i'.
- BooleanT operator<(const DoubleT i) const
-
Returns TRUE if the value of this index is smaller than
the double number 'i'.
- BooleanT operator<=(const DoubleT i) const
-
Returns TRUE if the value of this index is smaller than
or equal to the double number 'i'.
- BooleanT operator>(const DoubleT i) const
-
Returns TRUE if the value of this index is greater than
the double number 'i'.
- BooleanT operator>=(const DoubleT i) const
-
Returns TRUE if the value of this index is greater than
or equal to the double number 'i'.
Logical operators with another index:
- BooleanT operator==(const IndexC & i) const
-
Returns TRUE if the value of this index and index 'i' have got
the same value.
- BooleanT operator!=(const IndexC & i) const
-
Returns TRUE if the value of this index and index 'i' are different.
- BooleanT operator<(const IndexC & i) const
-
Returns TRUE if the value of this index is smaller than
the value of index 'i'.
- BooleanT operator<=(const IndexC & i) const
-
Returns TRUE if the value of this index is smaller than
or equal to the value of index 'i'.
- BooleanT operator>(const IndexC & i) const
-
Returns TRUE if the value of this index is greater than
the value of index 'i'.
- BooleanT operator>=(const IndexC & i) const
-
Returns TRUE if the value of this index is greater than
or equal to the value of index 'i'.
Miscellaneous functions:
- IndexC Abs(void) const
-
Returns the index whose index value is equal to the absolute value
of this index value.
- IndexC & SetAbs(void)
-
Returns this index whose index value is equal to the absolute value
of the original index value.
- IndexC ILog2(void) const
-
Returns the index which is logarithm of this index value
with base 2.
- IndexC Min(const IndexC & i) const
-
Returns the index with the smaller value.
- IndexC Max(const IndexC & i) const
-
Returns the index with the greater value.
Special member functions:
- UIntT Hash(void) const
-
Generates a randomised hash value for this index.
- SizeT Dim(void) const
-
Returns the number of dimensions indexed.
- SizeT GetSize(void) const
-
This function has no useful meaning
|
Programmer:Radek Marik, Bill Christmas, Documentation by CxxDoc: Tue Mar 20 10:48:08 2001
|