Operator Overloading
From RemObjects Software
This is a Oxygene Language Feature topic
Feel free to add your notes to this topic below.
Oxygene supports operator overloading on classes and records. The syntax for operator overloading is:
// unary: class operator <name>(val: MyType): MyType; // binary: class operator <name>(val1, val2: MyType): MyType; // cast: class operator explicit(val: MyType): MyType; class operator implicit(val: MyType): MyType;
Supported operators
| | | | |
|---|---|---|---|
|
Plus |
Unary |
x := +5; |
Unary "plus" operator. Usually does nothing for number types but can be overridden. |
|
Minus |
Unary |
x := -5; |
Unary "minus" operator, the operator to negate a value |
|
BitwiseNot |
Unary |
x := not x; |
Bitwise not is used to invert the bits |
|
Increment |
Unary |
inc(x); |
Increment, never called from Oxygene code but is used for when i++ is used from C#. |
|
Decrement |
Unary |
dec(x); |
Decrement, never called from Oxygene code but is used for when i-- is used from C#. |
|
Implicit |
Cast |
var x: TypeX; y: TypeY;
|
Implicit overload; makes two unrelated types assignment compatible with or without a cast. The input type is the type of the supported input value. The output type is the result type. |
|
Explicit |
Cast |
var x: TypeX; y: TypeY;
|
Explicit overload; makes two unrelated types cast compatible. The input type is the type of the supported input value. The output type is the result type. |
|
Add |
Binary |
x := 1+2; |
Binary addition; add two values to each other and return the result |
|
Subtract |
Binary |
x := 2-3; |
Binary subtraction; subtract two values to each other and return the result |
|
Multiply |
Binary |
x := 3*4; |
Multiply two values and return the result. |
|
Divide |
Binary |
x := 4 div 5; |
Divide two values and return the result. |
|
Modulus |
Binary |
x := 5 mod 6; |
Divide and returns the modulus (what's left after a division). |
|
BitwiseAnd |
Binary |
x := $04 and $ff |
binary and operator |
|
BitwiseOr |
Binary |
x := $04 or $ff |
binary or operator. |
|
BitwiseXor |
Binary |
x := $04 xor $ff |
Binary xor operator. |
|
ShiftLeft |
Binary |
x := 4 shl 1; |
shl/shift left operator. |
|
ShiftRight |
Binary |
x := 4 shr 1; |
shr/shift right operator. |
|
Equal |
Binary Boolean |
Return true if the two input parameters are equal. | |
|
NotEqual |
Binary Boolean |
Return true if the two input parameters are not equal. | |
|
Less |
Binary Boolean |
Returns if the left value is less than the right one. | |
|
LessOrEqual |
Binary Boolean |
Returns if the left value is less than or equal to the right one. | |
|
Greater |
Binary Boolean |
Returns if the left value is greater than the right one. | |
|
GreaterOrEqual |
Binary Boolean |
Returns if the left value is greater than or equal the right one. | |
|
In |
Binary Boolean |
a in [a,b,c] |
Returns if the value on the left side is in the value on the right side. For the in keyword in Oxygene. |
See Also
Product: RemObjects Oxygene (formerly known as Chrome)
Current version: 3.0
Previous Versions: 'Joyride' (2.0), 'Floorshow' (1.5), 'Adrenochrome' (1.0)
Glossary — Keywords — Language Features — Platform Features — Samples — Articles — How To — Issues
Categories: Text | Oxygene | Language | Feature
