source: ObjectBaseTypes/Level 1/UObjectBoolean.pas

Last change on this file was 14, checked in by george, 15 years ago
  • Upraveno: Rozšíření sady tříd objektových typů.
File size: 2.6 KB
Line 
1unit UObjectBoolean;
2
3interface
4
5uses
6 Classes, SysUtils, UObjectTypeBase;
7
8type
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
38implementation
39
40uses
41 UObjectInteger;
42
43{ TBoolean }
44
45function TBoolean.AndTo(Operand: TBoolean): TBoolean;
46begin
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');
51end;
52
53procedure TBoolean.Assign(Source: TInterfacedObject);
54begin
55 if Source is TBoolean then begin
56 Value := TBoolean(Source).Value;
57 end;
58end;
59
60function TBoolean.EqualTo(Operand: IComparable): TBoolean;
61begin
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');
66end;
67
68function TBoolean.HigherThen(Operand: TInterfacedObject): TBoolean;
69begin
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');
74end;
75
76procedure TBoolean.Invert;
77begin
78 Value := not Value;
79end;
80
81function TBoolean.LowerThan(Operand: TInterfacedObject): TBoolean;
82begin
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');
87end;
88
89function TBoolean.OrTo(Operand: TBoolean): TBoolean;
90begin
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');
95end;
96
97
98end.
Note: See TracBrowser for help on using the repository browser.