-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValues.pas
More file actions
853 lines (722 loc) · 23.8 KB
/
Values.pas
File metadata and controls
853 lines (722 loc) · 23.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
unit Values;
// The contents of this file are subject to the Mozilla Public License
// Version 1.1 (the "License"); you may not use this file except in
// compliance with the License. You may obtain a copy of the License at
// http://www.mozilla.org/MPL/
//
// Software distributed under the License is distributed on an "AS IS"
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
// License for the specific language governing rights and limitations
// under the License.
//
// The Original Code is DUnitLite.
//
// The Initial Developer of the Original Code is Joe White.
// Portions created by Joe White are Copyright (C) 2007
// Joe White. All Rights Reserved.
//
// Contributor(s):
//
// Alternatively, the contents of this file may be used under the terms
// of the LGPL license (the "LGPL License"), in which case the
// provisions of LGPL License are applicable instead of those
// above. If you wish to allow use of your version of this file only
// under the terms of the LGPL License and not to allow others to use
// your version of this file under the MPL, indicate your decision by
// deleting the provisions above and replace them with the notice and
// other provisions required by the LGPL License. If you do not delete
// the provisions above, a recipient may use your version of this file
// under either the MPL or the LGPL License.
interface
uses
{$DEFINE VALUE_EXTENSIONS_USES}
{$I ValueExtensions.inc}
{$UNDEF VALUE_EXTENSIONS_USES}
SysUtils,
Types,
TypInfo,
ValueComparers;
type
IValue = interface;
TFooEnum = (fooBar, fooBaz);
TBarEnum = (barBaz, barQuux);
TValue = record
public
{$DEFINE VALUE_EXTENSIONS_TVALUE_DECLARATION}
{$I ValueExtensions.inc}
{$UNDEF VALUE_EXTENSIONS_TVALUE_DECLARATION}
strict private
FValue: IValue;
public
constructor Create(AValue: IValue);
function AsString: string;
function ComparesAs(Comparisons: TValueComparisonSet; Other: TValue;
AComparer: IValueComparer): Boolean;
function GetClassName: string;
class operator Implicit(Value: Boolean): TValue;
class operator Implicit(Value: Extended): TValue;
class operator Implicit(Value: IInterface): TValue;
class operator Implicit(Value: Int64): TValue;
class operator Implicit(Value: Integer): TValue;
class operator Implicit(Value: string): TValue;
class operator Implicit(Value: TBarEnum): TValue;
class operator Implicit(Value: TFooEnum): TValue;
class operator Implicit(Value: TObject): TValue;
class operator Implicit(Value: TPoint): TValue;
class operator Implicit(Value: TValueComparison): TValue;
function IndexOfFirstDifference(OtherValue: TValue; AComparer: IValueComparer): Integer;
function Inspect(FirstDifferenceIndex: Integer): string;
function IsOfType(AClass: TClass): Boolean;
function SameInstance(B: TValue): Boolean;
function SameText(B: TValue): Boolean;
property Value: IValue read FValue;
end;
IValue = interface
['{E6E94BEB-BD73-4A85-B707-780CB50AF5EE}']
function AsString: string;
function CompareExtendedTo(Other: Extended; AComparer: IValueComparer): TValueComparison;
function CompareInt64To(Other: Int64): TValueComparison;
function CompareIntegerTo(Other: Integer; AComparer: IValueComparer): TValueComparison;
function ComparesAs(Comparisons: TValueComparisonSet; Other: IValue;
AComparer: IValueComparer): Boolean;
function GetClassName: string;
function GetEnumValue(ATypeInfo: PTypeInfo): Integer;
function get_BooleanValue: Boolean;
function get_PointValue: TPoint;
function get_StringValue: string;
function IndexOfFirstDifference(OtherValue: IValue; AComparer: IValueComparer): Integer;
function Inspect(FirstDifferenceIndex: Integer): string;
function IsOfType(AClass: TClass): Boolean;
function SameInstance(Other: IValue): Boolean;
function SameInstanceAsInterface(Other: IInterface): Boolean;
function SameInstanceAsObject(Other: TObject): Boolean;
function SameText(Other: IValue): Boolean;
property BooleanValue: Boolean read get_BooleanValue;
property PointValue: TPoint read get_PointValue;
property StringValue: string read get_StringValue;
end;
TBaseValue = class(TInterfacedObject, IValue)
strict private
procedure CheckSupportsOrdering;
strict protected
class function CompareInt64s(First, Second: Int64): TValueComparison; static;
class function CompareIntegers(First, Second: Integer): TValueComparison; static;
function CompareTo(Other: IValue; AComparer: IValueComparer): TValueComparison; virtual;
function ExtendedValue: Extended; virtual;
function Int64Value: Int64; virtual;
function IntegerValue: Integer; virtual;
function InvalidCast(TargetType: string): Exception;
function NotSupported(MethodName: string): Exception;
function SameInstanceInterfaceToInterface(A, B: IInterface): Boolean;
function SameInstanceInterfaceToObject(AInterface: IInterface; AObject: TObject): Boolean;
function TypeName: string; virtual;
class function TypeSupportsOrdering: Boolean; virtual;
public
function AsString: string; virtual; abstract;
function CompareExtendedTo(Other: Extended; AComparer: IValueComparer): TValueComparison;
function CompareInt64To(Other: Int64): TValueComparison;
function CompareIntegerTo(Other: Integer; AComparer: IValueComparer): TValueComparison; virtual;
function ComparesAs(Comparisons: TValueComparisonSet; Other: IValue;
AComparer: IValueComparer): Boolean;
function GetClassName: string; virtual;
function GetEnumValue(ATypeInfo: PTypeInfo): Integer; virtual;
function get_BooleanValue: Boolean; virtual;
function get_PointValue: TPoint; virtual;
function get_StringValue: string; virtual;
function IndexOfFirstDifference(OtherValue: IValue;
AComparer: IValueComparer): Integer; virtual;
function Inspect(FirstDifferenceIndex: Integer): string; virtual;
function IsOfType(AClass: TClass): Boolean; virtual;
function SameInstance(Other: IValue): Boolean; virtual;
function SameInstanceAsInterface(Other: IInterface): Boolean; virtual;
function SameInstanceAsObject(Other: TObject): Boolean; virtual;
function SameText(Other: IValue): Boolean;
end;
TBooleanValue = class(TBaseValue)
strict private
FValue: Boolean;
strict protected
function CompareTo(Other: IValue; AComparer: IValueComparer): TValueComparison; override;
public
constructor Create(AValue: Boolean);
function AsString: string; override;
function get_BooleanValue: Boolean; override;
end;
TEnumValue = class(TBaseValue)
strict private
FOrdValue: Integer;
FTypeInfo: PTypeInfo;
strict protected
function CompareTo(Other: IValue; AComparer: IValueComparer): TValueComparison; override;
function TypeName: string; override;
public
constructor Create(AOrdValue: Integer; ATypeInfo: PTypeInfo);
function AsString: string; override;
function GetEnumValue(ATypeInfo: PTypeInfo): Integer; override;
end;
TExtendedValue = class(TBaseValue)
strict private
FValue: Extended;
strict protected
function CompareTo(Other: IValue; AComparer: IValueComparer): TValueComparison; override;
function ExtendedValue: Extended; override;
public
constructor Create(AValue: Extended);
function AsString: string; override;
function CompareIntegerTo(Other: Integer; AComparer: IValueComparer): TValueComparison; override;
end;
TInt64Value = class(TBaseValue)
strict private
FValue: Int64;
strict protected
function CompareTo(Other: IValue; AComparer: IValueComparer): TValueComparison; override;
function Int64Value: Int64; override;
public
constructor Create(AValue: Int64);
function AsString: string; override;
function CompareIntegerTo(Other: Integer; AComparer: IValueComparer): TValueComparison; override;
end;
TIntegerValue = class(TBaseValue)
strict private
FValue: Integer;
strict protected
function CompareTo(Other: IValue; AComparer: IValueComparer): TValueComparison; override;
function ExtendedValue: Extended; override;
function Int64Value: Int64; override;
function IntegerValue: Integer; override;
public
constructor Create(AValue: Integer);
function AsString: string; override;
end;
TInterfaceValue = class(TBaseValue)
strict private
FValue: IInterface;
public
constructor Create(AValue: IInterface);
function AsString: string; override;
function SameInstance(Other: IValue): Boolean; override;
function SameInstanceAsInterface(Other: IInterface): Boolean; override;
function SameInstanceAsObject(Other: TObject): Boolean; override;
end;
TObjectValue = class(TBaseValue)
strict private
FValue: TObject;
public
constructor Create(AValue: TObject);
function AsString: string; override;
function GetClassName: string; override;
function IsOfType(AClass: TClass): Boolean; override;
function SameInstance(Other: IValue): Boolean; override;
function SameInstanceAsInterface(Other: IInterface): Boolean; override;
function SameInstanceAsObject(Other: TObject): Boolean; override;
end;
TPointValue = class(TBaseValue)
strict private
FValue: TPoint;
strict protected
function CompareTo(Other: IValue; AComparer: IValueComparer): TValueComparison; override;
class function TypeSupportsOrdering: Boolean; override;
public
constructor Create(const AValue: TPoint);
function AsString: string; override;
function get_PointValue: TPoint; override;
end;
TStringValue = class(TBaseValue)
strict private
FValue: string;
strict protected
function CompareTo(Other: IValue; AComparer: IValueComparer): TValueComparison; override;
public
constructor Create(AValue: string);
function AsString: string; override;
function get_StringValue: string; override;
function IndexOfFirstDifference(OtherValue: IValue;
AComparer: IValueComparer): Integer; override;
function Inspect(FirstDifferenceIndex: Integer): string; override;
end;
implementation
uses
Classes,
Math,
StringInspectors;
{$DEFINE VALUE_EXTENSIONS_IMPLEMENTATION_SECTION}
{$I ValueExtensions.inc}
{$UNDEF VALUE_EXTENSIONS_IMPLEMENTATION_SECTION}
{ TValue }
function TValue.AsString: string;
begin
Result := FValue.AsString;
end;
function TValue.ComparesAs(Comparisons: TValueComparisonSet; Other: TValue;
AComparer: IValueComparer): Boolean;
begin
Result := FValue.ComparesAs(Comparisons, Other.Value, AComparer);
end;
constructor TValue.Create(AValue: IValue);
begin
inherited;
FValue := AValue;
end;
function TValue.GetClassName: string;
begin
Result := FValue.GetClassName;
end;
class operator TValue.Implicit(Value: Boolean): TValue;
begin
Result := TValue.Create(TBooleanValue.Create(Value));
end;
class operator TValue.Implicit(Value: Extended): TValue;
begin
Result := TValue.Create(TExtendedValue.Create(Value));
end;
class operator TValue.Implicit(Value: IInterface): TValue;
begin
Result := TValue.Create(TInterfaceValue.Create(Value));
end;
class operator TValue.Implicit(Value: Int64): TValue;
begin
Result := TValue.Create(TInt64Value.Create(Value));
end;
class operator TValue.Implicit(Value: Integer): TValue;
begin
Result := TValue.Create(TIntegerValue.Create(Value));
end;
class operator TValue.Implicit(Value: string): TValue;
begin
Result := TValue.Create(TStringValue.Create(Value));
end;
class operator TValue.Implicit(Value: TBarEnum): TValue;
begin
Result := TValue.Create(TEnumValue.Create(Ord(Value), TypeInfo(TBarEnum)));
end;
class operator TValue.Implicit(Value: TFooEnum): TValue;
begin
Result := TValue.Create(TEnumValue.Create(Ord(Value), TypeInfo(TFooEnum)));
end;
class operator TValue.Implicit(Value: TObject): TValue;
begin
Result := TValue.Create(TObjectValue.Create(Value));
end;
class operator TValue.Implicit(Value: TPoint): TValue;
begin
Result := TValue.Create(TPointValue.Create(Value));
end;
class operator TValue.Implicit(Value: TValueComparison): TValue;
begin
Result := TValue.Create(TEnumValue.Create(Ord(Value), TypeInfo(TValueComparison)));
end;
function TValue.IndexOfFirstDifference(OtherValue: TValue;
AComparer: IValueComparer): Integer;
begin
Result := FValue.IndexOfFirstDifference(OtherValue.Value, AComparer);
end;
function TValue.Inspect(FirstDifferenceIndex: Integer): string;
begin
Result := FValue.Inspect(FirstDifferenceIndex);
end;
function TValue.IsOfType(AClass: TClass): Boolean;
begin
Result := FValue.IsOfType(AClass);
end;
function TValue.SameInstance(B: TValue): Boolean;
begin
Result := FValue.SameInstance(B.Value);
end;
function TValue.SameText(B: TValue): Boolean;
begin
Result := FValue.SameText(B.Value);
end;
{ TBaseValue }
procedure TBaseValue.CheckSupportsOrdering;
begin
if not TypeSupportsOrdering then
begin
raise ERangeError.CreateFmt('LessThan and GreaterThan are not supported for %s',
[TypeName]);
end;
end;
function TBaseValue.CompareExtendedTo(Other: Extended; AComparer: IValueComparer): TValueComparison;
begin
Result := AComparer.CompareExtendeds(Other, ExtendedValue);
end;
class function TBaseValue.CompareInt64s(First, Second: Int64): TValueComparison;
begin
if First = Second then
Result := vcEqual
else if First < Second then
Result := vcLess
else
Result := vcGreater;
end;
function TBaseValue.CompareInt64To(Other: Int64): TValueComparison;
begin
Result := CompareInt64s(Other, Int64Value);
end;
class function TBaseValue.CompareIntegers(First, Second: Integer): TValueComparison;
begin
if First = Second then
Result := vcEqual
else if First < Second then
Result := vcLess
else
Result := vcGreater;
end;
function TBaseValue.CompareIntegerTo(Other: Integer; AComparer: IValueComparer): TValueComparison;
begin
Result := CompareIntegers(Other, IntegerValue);
end;
function TBaseValue.ComparesAs(Comparisons: TValueComparisonSet; Other: IValue;
AComparer: IValueComparer): Boolean;
begin
if (Comparisons * [vcGreater, vcLess]) <> [] then
CheckSupportsOrdering;
Result := CompareTo(Other, AComparer) in Comparisons;
end;
function TBaseValue.CompareTo(Other: IValue; AComparer: IValueComparer): TValueComparison;
begin
raise NotSupported('CompareTo');
end;
function TBaseValue.ExtendedValue: Extended;
begin
raise InvalidCast('float');
end;
function TBaseValue.GetClassName: string;
begin
raise NotSupported('GetClassName');
end;
function TBaseValue.GetEnumValue(ATypeInfo: PTypeInfo): Integer;
begin
raise InvalidCast(ATypeInfo.Name);
end;
function TBaseValue.get_BooleanValue: Boolean;
begin
raise InvalidCast('Boolean');
end;
function TBaseValue.get_PointValue: TPoint;
begin
raise InvalidCast('TPoint');
end;
function TBaseValue.get_StringValue: string;
begin
raise InvalidCast('string');
end;
function TBaseValue.IndexOfFirstDifference(OtherValue: IValue;
AComparer: IValueComparer): Integer;
begin
Result := 0;
end;
function TBaseValue.Inspect(FirstDifferenceIndex: Integer): string;
begin
Result := AsString;
end;
function TBaseValue.Int64Value: Int64;
begin
raise InvalidCast('Int64');
end;
function TBaseValue.IntegerValue: Integer;
begin
raise InvalidCast('integer');
end;
function TBaseValue.InvalidCast(TargetType: string): Exception;
begin
raise EInvalidCast.CreateFmt('Cannot cast %s to %s',
[TypeName, TargetType]);
end;
function TBaseValue.IsOfType(AClass: TClass): Boolean;
begin
raise NotSupported('IsOfType');
end;
function TBaseValue.NotSupported(MethodName: string): Exception;
begin
Result := EInvalidOperation.CreateFmt('%s not supported for %s',
[MethodName, ClassName]);
end;
function TBaseValue.SameInstance(Other: IValue): Boolean;
begin
raise NotSupported('SameInstance');
end;
function TBaseValue.SameInstanceAsInterface(Other: IInterface): Boolean;
begin
raise NotSupported('SameInstanceAsInterface');
end;
function TBaseValue.SameInstanceAsObject(Other: TObject): Boolean;
begin
raise NotSupported('SameInstanceAsObject');
end;
function TBaseValue.SameInstanceInterfaceToInterface(A, B: IInterface): Boolean;
var
CanonicalA: IInterface;
CanonicalB: IInterface;
begin
CanonicalA := A as IInterface;
CanonicalB := B as IInterface;
Result := CanonicalA = CanonicalB;
end;
function TBaseValue.SameInstanceInterfaceToObject(AInterface: IInterface;
AObject: TObject): Boolean;
var
ObjectAsInterface: IInterface;
begin
if Supports(AObject, IInterface, ObjectAsInterface) then
Result := SameInstanceInterfaceToInterface(AInterface, ObjectAsInterface)
else
Result := (AInterface = nil) and (AObject = nil);
end;
function TBaseValue.SameText(Other: IValue): Boolean;
begin
Result := SysUtils.SameText(get_StringValue, Other.StringValue);
end;
function TBaseValue.TypeName: string;
begin
Result := ClassName;
end;
class function TBaseValue.TypeSupportsOrdering: Boolean;
begin
Result := True;
end;
{ TBooleanValue }
function TBooleanValue.AsString: string;
begin
Result := BoolToStr(FValue, True);
end;
function TBooleanValue.CompareTo(Other: IValue; AComparer: IValueComparer): TValueComparison;
begin
if FValue = Other.BooleanValue then
Result := vcEqual
else if FValue < Other.BooleanValue then
Result := vcLess
else
Result := vcGreater;
end;
constructor TBooleanValue.Create(AValue: Boolean);
begin
inherited Create;
FValue := AValue;
end;
function TBooleanValue.get_BooleanValue: Boolean;
begin
Result := FValue;
end;
{ TEnumValue }
function TEnumValue.AsString: string;
begin
Result := GetEnumName(FTypeInfo, FOrdValue);
end;
function TEnumValue.CompareTo(Other: IValue; AComparer: IValueComparer): TValueComparison;
begin
if FOrdValue = Other.GetEnumValue(FTypeInfo) then
Result := vcEqual
else if FOrdValue < Other.GetEnumValue(FTypeInfo) then
Result := vcLess
else
Result := vcGreater;
end;
constructor TEnumValue.Create(AOrdValue: Integer; ATypeInfo: PTypeInfo);
begin
inherited Create;
FOrdValue := AOrdValue;
FTypeInfo := ATypeInfo;
end;
function TEnumValue.GetEnumValue(ATypeInfo: PTypeInfo): Integer;
begin
if ATypeInfo <> FTypeInfo then
raise InvalidCast(ATypeInfo.Name);
Result := FOrdValue;
end;
function TEnumValue.TypeName: string;
begin
Result := ClassName + '<' + FTypeInfo.Name + '>';
end;
{ TExtendedValue }
function TExtendedValue.AsString: string;
begin
Result := FloatToStr(FValue);
end;
function TExtendedValue.CompareIntegerTo(Other: Integer; AComparer: IValueComparer): TValueComparison;
begin
Result := CompareExtendedTo(Other, AComparer);
end;
function TExtendedValue.CompareTo(Other: IValue; AComparer: IValueComparer): TValueComparison;
begin
Result := Other.CompareExtendedTo(ExtendedValue, AComparer);
end;
constructor TExtendedValue.Create(AValue: Extended);
begin
inherited Create;
FValue := AValue;
end;
function TExtendedValue.ExtendedValue: Extended;
begin
Result := FValue;
end;
{ TInt64Value }
function TInt64Value.AsString: string;
begin
Result := IntToStr(FValue);
end;
function TInt64Value.CompareIntegerTo(Other: Integer; AComparer: IValueComparer): TValueComparison;
begin
Result := CompareInt64To(Other);
end;
function TInt64Value.CompareTo(Other: IValue; AComparer: IValueComparer): TValueComparison;
begin
Result := Other.CompareInt64To(FValue);
end;
constructor TInt64Value.Create(AValue: Int64);
begin
inherited Create;
FValue := AValue;
end;
function TInt64Value.Int64Value: Int64;
begin
Result := FValue;
end;
{ TIntegerValue }
function TIntegerValue.AsString: string;
begin
Result := IntToStr(FValue);
end;
function TIntegerValue.CompareTo(Other: IValue; AComparer: IValueComparer): TValueComparison;
begin
Result := Other.CompareIntegerTo(FValue, AComparer);
end;
constructor TIntegerValue.Create(AValue: Integer);
begin
inherited Create;
FValue := AValue;
end;
function TIntegerValue.ExtendedValue: Extended;
begin
Result := FValue;
end;
function TIntegerValue.Int64Value: Int64;
begin
Result := FValue;
end;
function TIntegerValue.IntegerValue: Integer;
begin
Result := FValue;
end;
{ TInterfaceValue }
function TInterfaceValue.AsString: string;
begin
if FValue <> nil then
Result := 'interface($' + IntToHex(Integer(FValue), 8) + ')'
else
Result := 'nil interface';
end;
constructor TInterfaceValue.Create(AValue: IInterface);
begin
inherited Create;
FValue := AValue;
end;
function TInterfaceValue.SameInstance(Other: IValue): Boolean;
begin
Result := Other.SameInstanceAsInterface(FValue);
end;
function TInterfaceValue.SameInstanceAsInterface(Other: IInterface): Boolean;
begin
Result := SameInstanceInterfaceToInterface(FValue, Other);
end;
function TInterfaceValue.SameInstanceAsObject(Other: TObject): Boolean;
begin
Result := SameInstanceInterfaceToObject(FValue, Other);
end;
{ TObjectValue }
function TObjectValue.AsString: string;
begin
if FValue <> nil then
Result := FValue.ClassName + '($' + IntToHex(Integer(FValue), 8) + ')'
else
Result := 'nil object';
end;
constructor TObjectValue.Create(AValue: TObject);
begin
inherited Create;
FValue := AValue;
end;
function TObjectValue.GetClassName: string;
begin
if FValue <> nil then
Result := FValue.ClassName
else
Result := 'nil object';
end;
function TObjectValue.IsOfType(AClass: TClass): Boolean;
begin
Result := (FValue <> nil) and (FValue.ClassType = AClass);
end;
function TObjectValue.SameInstance(Other: IValue): Boolean;
begin
Result := Other.SameInstanceAsObject(FValue);
end;
function TObjectValue.SameInstanceAsInterface(Other: IInterface): Boolean;
begin
Result := SameInstanceInterfaceToObject(Other, FValue);
end;
function TObjectValue.SameInstanceAsObject(Other: TObject): Boolean;
begin
Result := FValue = Other;
end;
{ TPointValue }
function TPointValue.AsString: string;
begin
raise Exception.Create('Not specified');
end;
function TPointValue.CompareTo(Other: IValue; AComparer: IValueComparer): TValueComparison;
begin
if (Other.PointValue.X = FValue.X) and (Other.PointValue.Y = FValue.Y) then
Result := vcEqual
else
Result := vcUnorderedAndNotEqual;
end;
constructor TPointValue.Create(const AValue: TPoint);
begin
inherited Create;
FValue := AValue;
end;
function TPointValue.get_PointValue: TPoint;
begin
Result := FValue;
end;
class function TPointValue.TypeSupportsOrdering: Boolean;
begin
Result := False;
end;
{ TStringValue }
function TStringValue.AsString: string;
begin
Result := FValue;
end;
function TStringValue.CompareTo(Other: IValue; AComparer: IValueComparer): TValueComparison;
begin
if FValue = Other.StringValue then
Result := vcEqual
else if FValue < Other.StringValue then
Result := vcLess
else
Result := vcGreater;
end;
constructor TStringValue.Create(AValue: string);
begin
inherited Create;
FValue := AValue;
end;
function TStringValue.get_StringValue: string;
begin
Result := FValue;
end;
function TStringValue.IndexOfFirstDifference(OtherValue: IValue;
AComparer: IValueComparer): Integer;
begin
Result := AComparer.IndexOfFirstDifference(FValue, OtherValue.StringValue);
end;
function TStringValue.Inspect(FirstDifferenceIndex: Integer): string;
const
WindowBefore = 30;
WindowAfter = 30;
begin
Result := TStringInspector.Inspect(FValue,
FirstDifferenceIndex - WindowBefore, WindowBefore + 1 + WindowAfter);
end;
end.