| 1 | unit UObjectBoolean;
|
|---|
| 2 |
|
|---|
| 3 | interface
|
|---|
| 4 |
|
|---|
| 5 | uses
|
|---|
| 6 | Classes, SysUtils, UObjectTypeBase;
|
|---|
| 7 |
|
|---|
| 8 | type
|
|---|
| 9 | TBoolean = class;
|
|---|
| 10 |
|
|---|
| 11 | IComparable = interface
|
|---|
| 12 | function EqualTo(Operand: IComparable): TBoolean;
|
|---|
| 13 | end;
|
|---|
| 14 |
|
|---|
| 15 | TBoolean = class(TInterfacedObject, IComparable, IAssignable)
|
|---|
| 16 | Value: Boolean;
|
|---|
| 17 | procedure Invert;
|
|---|
| 18 | function EqualTo(Operand: IComparable): TBoolean;
|
|---|
| 19 | function HigherThen(Operand: TInterfacedObject): TBoolean;
|
|---|
| 20 | function LowerThan(Operand: TInterfacedObject): TBoolean;
|
|---|
| 21 | procedure Assign(Source: TInterfacedObject);
|
|---|
| 22 | function AndTo(Operand: TBoolean): TBoolean;
|
|---|
| 23 | function OrTo(Operand: TBoolean): TBoolean;
|
|---|
| 24 | end;
|
|---|
| 25 |
|
|---|
| 26 | IOrderable = interface
|
|---|
| 27 | function HigherThen(Operand: IOrderable): TBoolean;
|
|---|
| 28 | function LowerThan(Operand: IOrderable): TBoolean;
|
|---|
| 29 | function Max(Operand1, Operand2: IOrderable): IOrderable;
|
|---|
| 30 | function Min(Operand1, Operand2: IOrderable): IOrderable;
|
|---|
| 31 | function Predecessor: IOrderable;
|
|---|
| 32 | function Successor: IOrderable;
|
|---|
| 33 | function Low: IOrderable;
|
|---|
| 34 | function High: IOrderable;
|
|---|
| 35 | end;
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 | implementation
|
|---|
| 39 |
|
|---|
| 40 | uses
|
|---|
| 41 | UObjectInteger;
|
|---|
| 42 |
|
|---|
| 43 | { TBoolean }
|
|---|
| 44 |
|
|---|
| 45 | function TBoolean.AndTo(Operand: TBoolean): TBoolean;
|
|---|
| 46 | begin
|
|---|
| 47 | if Operand is TBoolean then begin
|
|---|
| 48 | Result := TBoolean.Create;
|
|---|
| 49 | Result.Value := TBoolean(Operand).Value and Value;
|
|---|
| 50 | end else raise EInvalidCast.Create('Typecast error');
|
|---|
| 51 | end;
|
|---|
| 52 |
|
|---|
| 53 | procedure TBoolean.Assign(Source: TInterfacedObject);
|
|---|
| 54 | begin
|
|---|
| 55 | if Source is TBoolean then begin
|
|---|
| 56 | Value := TBoolean(Source).Value;
|
|---|
| 57 | end;
|
|---|
| 58 | end;
|
|---|
| 59 |
|
|---|
| 60 | function TBoolean.EqualTo(Operand: IComparable): TBoolean;
|
|---|
| 61 | begin
|
|---|
| 62 | if TInterfacedObject(Operand) is TBoolean then begin
|
|---|
| 63 | Result := TBoolean.Create;
|
|---|
| 64 | Result.Value := Value = TBoolean(Operand).Value;
|
|---|
| 65 | end else raise EInvalidCast.Create('Typecast error');
|
|---|
| 66 | end;
|
|---|
| 67 |
|
|---|
| 68 | function TBoolean.HigherThen(Operand: TInterfacedObject): TBoolean;
|
|---|
| 69 | begin
|
|---|
| 70 | if Operand is TBoolean then begin
|
|---|
| 71 | Result := TBoolean.Create;
|
|---|
| 72 | Result.Value := Value > TBoolean(Operand).Value;
|
|---|
| 73 | end else raise EInvalidCast.Create('Typecast error');
|
|---|
| 74 | end;
|
|---|
| 75 |
|
|---|
| 76 | procedure TBoolean.Invert;
|
|---|
| 77 | begin
|
|---|
| 78 | Value := not Value;
|
|---|
| 79 | end;
|
|---|
| 80 |
|
|---|
| 81 | function TBoolean.LowerThan(Operand: TInterfacedObject): TBoolean;
|
|---|
| 82 | begin
|
|---|
| 83 | if Operand is TBoolean then begin
|
|---|
| 84 | Result := TBoolean.Create;
|
|---|
| 85 | Result.Value := Value < TBoolean(Operand).Value;
|
|---|
| 86 | end else raise EInvalidCast.Create('Typecast error');
|
|---|
| 87 | end;
|
|---|
| 88 |
|
|---|
| 89 | function TBoolean.OrTo(Operand: TBoolean): TBoolean;
|
|---|
| 90 | begin
|
|---|
| 91 | if Operand is TBoolean then begin
|
|---|
| 92 | Result := TBoolean.Create;
|
|---|
| 93 | Result.Value := TBoolean(Operand).Value or Value;
|
|---|
| 94 | end else raise EInvalidCast.Create('Typecast error');
|
|---|
| 95 | end;
|
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 | end.
|
|---|