Value :: compare - Compare the values for two value handles
The function compares the values of the two value handles. Instances in both value handles have to be selected. When operands on both sides are of different type or complexity, conversion is performed for the left operator before comparing.
The function returns -1 when the value for the left operand (calling handle) is lower than the value for the right operand (parameter). The function returns 1 when the the value for the left operand is higher than the value for right operand. The function returns 0 when values are equal.
The function throws an exception, when one of the value handles is invalid or when no instance is selected in one of the value handles. An exception is thrown also, when values are not comparable, i.e. when converting the right operand failed. In order to check, whether values are comparable, one may call canCompare().
The result of a comparison is an integer value with the following meaning:
- 0: both operands have the same value
- 1: the calling operand is greater than the passed operand
- -1: the calling operand is smaller than the passed operand
Implementation overview
- Compare with date
Value :: compare ( cDate ) - Compare with double
Value :: compare ( vDouble ) - Compare with integer
Value :: compare ( iValue ) - Compare with string
Value :: compare ( sString ) - Compare with time
Value :: compare ( cTime ) - Compare with value
Value :: compare ( cValue )
Implementation details
-
Compare with date
int32 Value  :: compare ( odaba::Date &cDate )
This implementation compares the value with the date passed in cDate. Data conversion is performed for the passed value when required. Converting date values to string values may result in different string values for the same date value depending on the national setting. Hence, string values should not be compared with date values. In this case it is more appropriate to compare the date values directly by calling toDate().
- cDate
- Date
The date contains day, month and year, but not the time.
to list
- cDate
- Date
- to list
-
Compare with integer
int32 Value  :: compare ( int32 iValue )
This implementation compares the value with the integer value passed in iValue. Data conversion is performed for the passed value when required.
- iValue
- Integer value
The value is passed as platform independent 32-bit integer value.
to list
- iValue
- Integer value
-
Compare with string
int32 Value  :: compare ( odaba::String &sString )
This implementation compares the value with the string value passed in sString. Data conversion is performed for the string when required.
- sString - String value
to list
-
Compare with time
int32 Value  :: compare ( odaba::Time &cTime )
This implementation compares the value with the time passed in cTime. Data conversion is performed for the passed value when required. Converting date values to string values may result in different string values for the same time value depending on the national setting. Hence, string values should not be compared with time values, directly. In this case, it is more appropriate to compare the time value directly by calling toTime().
- cTime
- Time value
The time value is passed in the ODABA Interface::Time format and provides time in 1/100th seconds.
to list
- cTime
- Time value
-
Compare with value
int32 Value  :: compare ( odaba::Value &cValue )
This implementation compares the value with the value passed in cValue. Data conversion is performed for cValue when required.
- cValue
- Value handle
A value handle refers to a (usually) opened value. Invalid value handles may cause an exception.
to list
- cValue
- Value handle