-
Notifications
You must be signed in to change notification settings - Fork 140
/
OtlCommon.pas
5115 lines (4576 loc) · 163 KB
/
OtlCommon.pas
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
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
///<summary>Stuff common to the OmniThreadLibrary project.</summary>
///<author>Primoz Gabrijelcic</author>
///<license>
///This software is distributed under the BSD license.
///
///Copyright (c) 2021, Primoz Gabrijelcic
///All rights reserved.
///
///Redistribution and use in source and binary forms, with or without modification,
///are permitted provided that the following conditions are met:
///- Redistributions of source code must retain the above copyright notice, this
/// list of conditions and the following disclaimer.
///- Redistributions in binary form must reproduce the above copyright notice,
/// this list of conditions and the following disclaimer in the documentation
/// and/or other materials provided with the distribution.
///- The name of the Primoz Gabrijelcic may not be used to endorse or promote
/// products derived from this software without specific prior written permission.
///
///THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
///ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
///WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
///DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
///ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
///(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
///LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
///ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
///(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
///SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
///</license>
///<remarks><para>
/// Home : http://www.omnithreadlibrary.com
/// Support : https://en.delphipraxis.net/forum/32-omnithreadlibrary/
/// Author : Primoz Gabrijelcic
/// E-Mail : [email protected]
/// Blog : http://thedelphigeek.com
/// Contributors : GJ, Lee_Nover, scarre, Sean B. Durkin, HHasenack
/// Creation date : 2008-06-12
/// Last modification : 2021-02-15
/// Version : 1.54a
///</para><para>
/// History:
/// 1.54a: 2021-02-15
/// - IOmniIntegerSet/TOmniIntegerSet.AsMask changed to uint64 so it can store
/// 64-bit NativeUInt without problems. [#148]
/// 1.54: 2019-12-09
/// - Added overloaded TOmniValue.FromArray<T> accepting `array of T`.
/// 1.53: 2019-07-26
/// - Various TOmniExecutable method correctly process `nil` parameter.
/// 1.52: 2019-06-28
/// - TOmniWaitableValue constructor optionally accepts intial value for the
/// Value property.
/// 1.51: 2019-01-03
/// - [HHasenack] On XE3 and above, TOmniValue.CastTo<T> supports casting
/// to an interface. Fixes #128.
/// 1.50: 2018-04-13
/// - Implemented TOmniValue.LogValue, useful for debug logging.
/// 1.49: 2018-03-12
/// - Added TOmniValue.FromRecordUnsafe<T> which works same as FromRecord<T> but
/// doesn't enforce a 'record' constraint on T.
/// 1.48: 2017-07-26
/// - TOmniMessageID can now hold TProc<integer>.
/// 1.47: 2017-02-03
/// - AsInt64 now marks TOmniValue as a type ovtInt64 so that
/// ov.CastTo<TArray<Int64>> can work. [issue #89]
/// 1.46a: 2016-10-24
/// - Corrected Environment.GroupAffinity and Environment.LoadNUMAInfo to work
/// on Windows XP.
/// 1.46: 2016-10-19
/// - Implemented TOmniValue.Wrap<T> and .Unwrap<T>, a way to wrap anything
/// (including TMethod and 'reference to procedure') in a TOmniObject.
/// [Unwrap<T> must be called as follows: omnivalue.Unwrap<T>()]
/// 1.45: 2016-10-17
/// - Implemented TOmniRecord<T>, a simple way to wrap "anything" in a record.
/// 1.44b: 2016-08-31
/// - Environment.Thread was not thread safe!
/// 1.44a: 2016-07-29
/// - [HHasenack] TOmniValue.IsInterfacedType was returning wrong result for the
/// 'owned object' data type. This could cause objects assigned to .AsOwnedObject
/// to hang in memory and never be destroyed.
/// 1.44: 2016-07-18
/// - Implemented Environment.NUMANodes.Distance which returns relative distance
/// between two nodes, as reported by the ACPI (5.2.17 System Locality Distance
/// Information Table).
/// 1.43a: 2016-07-13
/// - TOmniIntegerSet only calls OnChange event when value is actually changed.
/// (Was called on each assign.)
/// 1.43: 2016-07-05
/// - Implemented IOmniIntegerSet.
/// - Implemented IOmniThreadEnvironment.GroupAffinity.
/// 1.42: 2016-07-01
/// - Implemented Environment.NUMANodes.FindNode.
/// 1.41: 2016-06-27
/// - Environment.ProcessorGroups and .NUMANodes are supported on all platforms.
/// Pseudo-group 0 and NUMA node 0 are reported on non-Windows platforms.
/// 1.40: 2016-06-23
/// - Implemented Environment.ProcessorGroups and Environment.NUMANodes (Win64 only).
/// - IOmniAffinity.Mask changed from DWORD to NativeUInt to properly support
/// up to 64 processors on Win64.
/// 1.39: 2015-10-03
/// - [Sean] Implemented TOmniAlignedInt32 (clone of GpStuff.TGp4AlignedInt)
/// and TOmniAlignedInt64 (clone of GpStuff.TGp8AlignedInt64).
/// 1.38: 2015-09-28
/// - [Sean] Introduced non-Windows compatibility.
/// 1.37b: 2015-08-30
/// - Fixed record type handling in FromArray<T> and ToArray<T>.
/// 1.37a: 2015-04-17
/// - Added vtWideChar and vtPWideChar handling to TOmniValue.Create and .CreateNamed.
/// 1.37: 2015-02-09
/// - Added writer for TOmniExecutable.Delegate.
/// 1.36: 2015-02-03
/// - Type of TOmniValue data is now an external type - TOmniValueDataType. That
/// way causes less internal errors in the compiler.
/// - Added TOmniValue.DataType property.
/// 1.35: 2014-09-23
/// - Implemented TOmniValueContainer.AssignNamed.
/// 1.34: 2014-01-13
/// - Implemented TOmniValue.HasArrayItem.
/// 1.33: 2014-01-10
/// - TOmniValue can 'own' a TObject (object gets destroyed when a TOmniValue goes
/// out of scope). Supporting properties: IsOwnedObject, AsOwnedObject,
/// OwnsObject.
/// 1.32b: 2013-10-17
/// - Fixed exception format string in TOmniValue.SetAsTValue.
/// 1.32a: 2013-10-14
/// - Removed XE5 compilation warnings.
/// 1.32: 2013-10-13
/// - ToObject<T> is working in D2010 again (thx to [Tomasso Ercole]).
/// 1.31a: 2013-10-07
/// - Compiles with D2009 and D2010 again.
/// 1.31: 2013-05-06
/// - AnsiString type is supported in TOmniValue.
/// - Implemented FromArray<T> and ToArray<T>.
/// - CastAs<T> renamed to CastTo<T>.
/// - AsRecord<T> renamed to ToRecord<T>.
/// - CastFrom<T> and CastTo<T> work for byte- and word-sized integer types.
/// 1.30: 2013-04-29
/// - GetAsXXX family renamed to CastToXXX.
/// - TryGetAsXXX familiy renamed to TryCastToXXX.
/// 1.29: 2013-04-26
/// - Added TOmniValue.TryGetAsXXX family of functions.
/// - Added TOmniValue.GetAsXXXDef family of functions.
/// 1.28a: 2013-02-27
/// - Fixed TOmniValue._AddRef and _Release when 'nil' interface was stored in
/// the TOmniValue.
/// 1.28: 2012-07-30
/// - Implemented TOmniValue.IsRecord.
/// 1.27: 2012-05-18
/// - Added property CountPhysical to the IOmniAffinity.
/// 1.26c: 2012-02-28
/// - Fixed object and interface casting in TOmniValue.CreateNamed.
/// 1.26b: 2012-02-25
/// - TOmniValue.CreateNamed was casting pointer to integer.
/// 1.26a: 2012-02-03
/// - TOmniValueContainer.Insert did not update internal 'count' field.
/// Big thanks to [andi] for bug report and fix.
/// 1.26: 2012-01-19
/// - Added TOmniValueObj, class wrapper for TOmniValue.
/// 1.25g: 2011-12-20
/// - TOmniValue.AsInteger, AsString and AsWideString now work if the TOmniValue
/// contains a Variant of the appropriate type.
/// 1.25f: 2011-12-18
/// - Fixed various TOmniInterfaceDictionary bugs (big tnx to Zarko Gajic).
/// - Clear properly clears interface refence before destroying the bucket.
/// - Resize properly clears interface reference in old bucket after copy.
/// - Resize preserves the internal item count.
/// - Resize releases old buckets.
/// 1.25e: 2011-12-09
/// - Removed compilation hint "Private symbol 'GetAsRecord' declared but never used".
/// 1.25d: 2011-12-02
/// - Removed compilation hint "Private symbol 'GetAsArrayItem' declared but never used".
/// 1.25c: 2011-11-29
/// - Reference count handling in TOmniValue was ignoring array and record wrappers.
/// 1.25b: 2011-11-18
/// - Overloaded property getters in TOmniValue are not inlined on 2009/
/// 2010 because of the buggy compiler.
/// 1.25a: 2011-11-15
/// - Some inlining removed because it would not work reliably.
/// 1.25: 2011-11-08
/// - Less casting in TOmniValue.Create.
/// - TOmniValue can store records by using FromRecord<T> and AsRecord<T>.
/// - Added a class which can wrap any record - TOmniRecordWrapper<T>.
/// - Added an interface which can wrap any object and destroy it when the
/// interface goes out of scope - IOmniAutoDestroyObject.
/// 1.24: 2011-11-05
/// - TOmniValue.Create now internally creates TOmniValueContainer to store values.
/// Variant arrays are no longer used. IsArray tests it TOmniValue contains an
/// array and AsArray returns this internal container. Default indexed property
/// still accesses individual elements in this container. See demo
/// 50_OmniValueArray for an example.
/// - TOmniValue.Create creates internal TOmniValueContainer containing named items.
/// See demo 50_OmniValueArray for an example.
/// 1.23: 2011-09-06
/// - Implemented IOmniCounter.Take.
/// 1.22: 2011-08-31
/// - [Lee_Nover] SetThreadName implementation moved into a separate unit with debug
/// info disabled. That way, debugger doesn't stop on SetThreadName while
/// single-stepping in another thread.
/// 1.21: 2011-08-28
/// - TOmniValue can natively store exception objects (AsException, IsException).
/// 1.20: 2011-07-14
/// - Removed EXIT_EXCEPTION error code.
/// 1.19a: 2010-12-12
/// - Define implicit TOmniValue<->TDateTime conversion operators only for Delphi XE
/// and higher.
/// 1.19: 2010-12-03
/// - [scarre] Added TDateTime support to TOmniValue.
/// 1.18a: 2010-09-21
/// - IOmniWaitableValue fully compatible with TOmniWaitableValue.
/// 1.18: 2010-09-20
/// - Declared interface IOmniWaitableValue and added function CreateWaitableValue.
/// - Implemented TOmniMessageID.AsString.
/// 1.17a: 2010-07-08
/// - TOmniValue.CastAs<T> and .CastFrom<T> are partially supported in D2009.
/// 1.17: 2010-07-01
/// - Includes OTLOptions.inc.
/// 1.16: 2010-05-12
/// - TOmniValue can be cast as Int64.
/// - Implemented TOmniValue.CastFrom<T> and .CastAs<T>.
/// 1.15: 2010-05-08
/// - Implemented conversions from/to TOmniValue to/from TValue (Delphi 2010 and newer).
/// 1.14: 2010-05-06
/// - Implemented TOmniValue._AddRef, _Release, _ReleaseAndClear.
/// 1.13: 2010-04-14
/// - Removed TOmniEnumerableRange and associated code.
/// 1.12: 2010-03-16
/// - Implemented TOmniMessageID record, used internally to implement timers.
/// 1.11: 2010-03-10
/// - Implemented TOmniCounter, auto-initialized wrapper around the IOmniCounter.
/// 1.10b: 2010-03-03
/// - Replacement AnonCopy, by Serg.
/// 1.10a: 2010-02-22
/// - D2009-compatible way of setting a delegate in TOmniExecutable.
/// 1.10: 2010-02-09
/// - Implemented TOmniExecutor - a record that can store TProcedure, TMethod, or
/// TProc.
/// 1.09: 2010-02-01
/// - TOmniValue getters know how to process empty TOmniValue.
/// - Added Environment.Thread interface.
/// - Environment.SystemAffinity moved to Environment.System.Affinity.
/// 1.08: 2010-01-14
/// - Added TOmniValue.IsInteger.
/// - Refactored and enhanced TOmniValueContainer.
/// - Defined IOmniValueEnumerable interface.
/// 1.07: 2010-01-05
/// - Renamed: IInterfaceDictionary -> IOmniInterfaceDictionary,
/// IInterfaceDictionaryEnumerator -> IOmniInterfaceDictionaryEnumerator,
/// TInterfaceDictionaryPair -> TOmniInterfaceDictionaryPair.
/// - Implemented IOmniEnvironment interface and function Environment returning
/// some information on system and process.
/// 1.06: 2009-12-21
/// - Added pointer conversions and AsPointer cast to TOmniValue.
/// 1.05: 2009-11-15
/// - Removed lots of stuff that is now implemented using container observers.
/// 1.04: 2009-04-18
/// - Added WideString support to TOmniValue.
/// 1.03a: 2009-04-05
/// - Bug fixed: TInterfaceDictionaryEnumerator was ignoring first bucket.
/// 1.03: 2009-03-30
/// - TOmniCS and IOmniCriticalSection moved to the OtlSync unit.
/// 1.02a: 2009-02-09
/// - Simplified TOmniCS.Initialize.
/// 1.02: 2009-02-03
/// - Added accessor to the internal critical section to the TOmniCS record.
/// 1.01: 2009-01-26
/// - Implemented TOmniCS critical section wrapper.
/// - Added TOmniWaitableValue class.
/// 1.0d: 2008-10-05
/// - Use GetGoodHashSize from GpStringHash unit.
/// 1.0c: 2008-09-26
/// - Check PostMessage result.
/// 1.0b: 2008-09-19
/// - Bug fixed: TOmniValue.Null was not really initialized to Null.
/// 1.0a: 2008-09-02
/// - Fixed memory leak that could occur in TOmniMonitorSupport.Notify (in fact it
/// was possible to cause it in demo 11).
/// 1.0: 2008-08-26
/// - First official release.
///</para></remarks>
unit OtlCommon;
{$I OtlOptions.inc}
{$WARN SYMBOL_PLATFORM OFF}
interface
uses
Classes,
Variants,
TypInfo,
SyncObjs,
Types,
{$IFDEF MSWINDOWS}
Windows,
DSiWin32,
{$ENDIF}
{$IFDEF POSIX}
Posix.Pthread,
{$ENDIF}
{$IFDEF OTL_ERTTI}
RTTI,
{$ENDIF OTL_ERTTI}
{$IFDEF OTL_Generics}
Generics.Defaults,
Generics.Collections,
{$ENDIF OTL_Generics}
SysUtils;
const
// reserved exit statuses
EXIT_OK = 0;
EXIT_INTERNAL = integer($80000000);
EXIT_THREADPOOL_QUEUE_TOO_LONG = EXIT_INTERNAL + 0;
EXIT_THREADPOOL_STALE_TASK = EXIT_INTERNAL + 1;
EXIT_THREADPOOL_CANCELLED = EXIT_INTERNAL + 2;
EXIT_THREADPOOL_INTERNAL_ERROR = EXIT_INTERNAL + 3;
type
{$IFNDEF OTL_HasCorrectNativeInt}
NativeInt = integer;
NativeUInt = cardinal;
PNativeInt = PInteger;
PNativeUInt = PCardinal;
{$ENDIF}
//:TOmniValue conversion exception.
EOmniValueConv = class(Exception);
TOmniValueContainer = class;
IOmniAutoDestroyObject = interface;
//Update IsInterfacedType function when changing this enum!
TOmniValueDataType = (ovtNull,
{ovData} ovtBoolean, ovtInteger, ovtInt64, ovtDouble, ovtObject, ovtPointer, ovtDateTime, ovtException,
{ovIntf} ovtExtended, ovtString, ovtInterface, ovtVariant, ovtArray, ovtRecord, ovtOwnedObject
{$IFDEF MSWINDOWS}
, ovtWideString, ovtAnsiString
{$ENDIF});
TOmniValue = packed record // 13 bytes in 32-bit, 17 bytes in 64-bit
private
ovData: int64;
ovIntf: IInterface;
ovType: TOmniValueDataType;
function CastToBoolean: boolean; inline;
function CastToCardinal: cardinal; inline;
function CastToDouble: Double;
function CastToDateTime: TDateTime;
function CastToException: Exception;
function CastToExtended: Extended;
function CastToInt64: int64; inline;
function CastToInteger: integer; inline;
function CastToInterface: IInterface; inline;
function CastToObject: TObject; overload; inline;
function CastToPointer: pointer;
function CastToRecord: IOmniAutoDestroyObject; inline;
function CastToString: string;
function CastToVariant: Variant;
function GetAsArray: TOmniValueContainer; inline;
function GetAsArrayItem(idx: integer): TOmniValue; overload; {$IF CompilerVersion >= 22}inline;{$IFEND}
function GetAsArrayItem(const name: string): TOmniValue; overload; {$IF CompilerVersion >= 22}inline;{$IFEND}
{$IF CompilerVersion >= 19}//D2007 has problems understanding this overload
function GetAsArrayItem(const param: TOmniValue): TOmniValue; overload; {$IF CompilerVersion >= 22}inline;{$IFEND}
//GetAsArrayItemOV is used in D2007 instead
{$IFEND}
function GetAsArrayItemOV(const param: TOmniValue): TOmniValue; overload; {$IF CompilerVersion >= 22}inline;{$IFEND}
procedure SetAsArray(value: TOmniValueContainer); inline;
procedure SetAsArrayItem(idx: integer; const value: TOmniValue); overload; {$IF CompilerVersion >= 22}inline;{$IFEND}
procedure SetAsArrayItem(const name: string; const value: TOmniValue); overload; {$IF CompilerVersion >= 22}inline;{$IFEND}
{$IF CompilerVersion >= 19}//D2007 has problems understanding this overload
procedure SetAsArrayItem(const param, value: TOmniValue); overload; {$IF CompilerVersion >= 22}inline;{$IFEND}
//SetAsArrayItemOV is used in D2007 instead
{$IFEND}
procedure SetAsArrayItemOV(const param, value: TOmniValue); overload; {$IF CompilerVersion >= 22}inline;{$IFEND}
procedure SetAsBoolean(const value: boolean); inline;
procedure SetAsCardinal(const value: cardinal); inline;
procedure SetAsDouble(value: Double); inline;
procedure SetAsDateTime(value: TDateTime); inline;
procedure SetAsException(value: Exception);
procedure SetAsExtended(value: Extended);
procedure SetAsInt64(const value: int64); inline;
procedure SetAsInteger(const value: integer); inline;
procedure SetAsInterface(const value: IInterface); //don't inline, something is broken in codegen (XE)
procedure SetAsObject(const value: TObject); inline;
procedure SetAsOwnedObject(const value: TObject); inline;
procedure SetAsPointer(const value: pointer); inline;
procedure SetAsRecord(const intf: IOmniAutoDestroyObject); inline;
procedure SetAsString(const value: string);
procedure SetAsVariant(const value: Variant);
procedure SetOwnsObject(const value: boolean);
{$REGION 'Documentation'}
/// <summary>Most of the code in this method never executes. It is just here so that
/// stupid compilation hints such as "Private symbol 'GetAsArrayItem' declared but
/// never used" are not shown.</summary>
{$ENDREGION}
class procedure _RemoveWarnings; inline; static;
procedure ClearIntf; inline;
{$IFDEF MSWINDOWS}
function CastToAnsiString: AnsiString; inline;
function CastToWideString: WideString;
procedure SetAsAnsiString(const value: AnsiString);
procedure SetAsWideString(const value: WideString);
{$ENDIF}
{$IFDEF OTL_ERTTI}
private
function GetAsTValue: TValue;
function GetArrayFromTValue(const value: TValue): TOmniValueContainer;
function GetTValueFromArray(const a: TOmniValueContainer): TValue;
procedure SetAsTValue(const value: TValue);
{$ENDIF}
public
constructor Create(const values: array of const);
constructor CreateNamed(const values: array of const; const cppDupConWorkaround: boolean = false);
procedure _AddRef; inline;
procedure _Release; inline;
procedure _ReleaseAndClear; inline;
function CastToBooleanDef(defValue: boolean): boolean; inline;
function CastToCardinalDef(defValue: cardinal): cardinal; inline;
function CastToDoubleDef(defValue: Double): Double; inline;
function CastToDateTimeDef(defValue: TDateTime): TDateTime; inline;
function CastToExceptionDef(defValue: Exception): Exception; inline;
function CastToExtendedDef(defValue: Extended): Extended; inline;
function CastToInt64Def(defValue: int64): int64; inline;
function CastToIntegerDef(defValue: integer): integer; inline;
function CastToInterfaceDef(const defValue: IInterface): IInterface; inline;
function CastToObjectDef(defValue: TObject): TObject; inline;
function CastToPointerDef(defValue: pointer): pointer; inline;
function CastToStringDef(const defValue: string): string; inline;
function CastToVariantDef(defValue: Variant): Variant; inline;
procedure Clear; inline;
function HasArrayItem(idx: integer): boolean; overload; inline;
function HasArrayItem(const name: string): boolean; overload; inline;
function HasArrayItem(const param: TOmniValue): boolean; overload; inline;
function IsArray: boolean; inline;
function IsBoolean: boolean; inline;
function IsEmpty: boolean; inline;
function IsException: boolean; inline;
function IsFloating: boolean; inline;
function IsDateTime: boolean; inline;
function IsInteger: boolean; inline;
function IsInterface: boolean; inline;
function IsInterfacedType: boolean; inline;
function IsObject: boolean; inline;
function IsOwnedObject: boolean; inline;
function IsPointer: boolean; inline;
function IsRecord: boolean; inline;
function IsString: boolean; inline;
function IsVariant: boolean; inline;
function LogValue: string;
class function Null: TOmniValue; static;
function RawData: PInt64; inline;
procedure RawZero; inline;
function TryCastToBoolean(var value: boolean): boolean; inline;
function TryCastToCardinal(var value: cardinal): boolean; inline;
function TryCastToDouble(var value: Double): boolean;
function TryCastToDateTime(var value: TDateTime): boolean;
function TryCastToException(var value: Exception): boolean;
function TryCastToExtended(var value: Extended): boolean;
function TryCastToInt64(var value: int64): boolean; inline;
function TryCastToInteger(var value: integer): boolean; inline;
function TryCastToInterface(var value: IInterface): boolean; inline;
function TryCastToObject(var value: TObject): boolean; inline;
function TryCastToPointer(var value: pointer): boolean;
function TryCastToString(var value: string): boolean;
function TryCastToVariant(var value: Variant): boolean;
class operator Equal(const a: TOmniValue; i: integer): boolean; inline;
class operator Equal(const a: TOmniValue; const s: string): boolean; inline;
class operator Implicit(const a: boolean): TOmniValue; inline;
class operator Implicit(const a: Double): TOmniValue; inline;
class operator Implicit(const a: Extended): TOmniValue; inline;
class operator Implicit(const a: integer): TOmniValue; inline;
class operator Implicit(const a: int64): TOmniValue; inline;
class operator Implicit(const a: pointer): TOmniValue; inline;
class operator Implicit(const a: string): TOmniValue; inline;
class operator Implicit(const a: IInterface): TOmniValue; //don't inline, something is broken in codegen (XE)
class operator Implicit(const a: TObject): TOmniValue; inline;
class operator Implicit(const a: Exception): TOmniValue; inline;
class operator Implicit(const a: TOmniValue): int64; inline;
class operator Implicit(const a: TOmniValue): TObject; inline;
class operator Implicit(const a: TOmniValue): Double; inline;
class operator Implicit(const a: TOmniValue): Exception; inline;
class operator Implicit(const a: TOmniValue): Extended; inline;
class operator Implicit(const a: TOmniValue): string; inline;
class operator Implicit(const a: TOmniValue): integer; inline;
class operator Implicit(const a: TOmniValue): pointer; inline;
class operator Implicit(const a: TOmniValue): boolean; inline;
class operator Implicit(const a: TOmniValue): IInterface; inline;
class operator Implicit(const a: Variant): TOmniValue; inline;
{$IFDEF OTL_TOmniValueImplicitDateTime}
class operator Implicit(const a: TDateTime): TOmniValue; inline;
class operator Implicit(const a: TOmniValue): TDateTime; inline;
{$ENDIF OTL_TOmniValueImplicitDateTime}
property AsArray: TOmniValueContainer read GetAsArray;
property AsArrayItem[idx: integer]: TOmniValue read GetAsArrayItem write SetAsArrayItem; default;
property AsArrayItem[const name: string]: TOmniValue read GetAsArrayItem write SetAsArrayItem; default;
{$IF CompilerVersion >= 19}//D2007 has problems understanding this overload
property AsArrayItem[const param: TOmniValue]: TOmniValue read GetAsArrayItem write SetAsArrayItem; default;
{$IFEND}
property AsArrayItemOV[const param: TOmniValue]: TOmniValue read GetAsArrayItemOV write SetAsArrayItemOV;
property AsBoolean: boolean read CastToBoolean write SetAsBoolean;
property AsCardinal: cardinal read CastToCardinal write SetAsCardinal;
property AsDouble: Double read CastToDouble write SetAsDouble;
property AsDateTime: TDateTime read CastToDateTime write SetAsDateTime;
property AsException: Exception read CastToException write SetAsException;
property AsExtended: Extended read CastToExtended write SetAsExtended;
property AsInt64: int64 read CastToInt64 write SetAsInt64;
property AsInteger: integer read CastToInteger write SetAsInteger;
property AsInterface: IInterface read CastToInterface write SetAsInterface;
property AsObject: TObject read CastToObject write SetAsObject;
property AsOwnedObject: TObject read CastToObject write SetAsOwnedObject;
property AsPointer: pointer read CastToPointer write SetAsPointer;
property AsString: string read CastToString write SetAsString;
property AsVariant: Variant read CastToVariant write SetAsVariant;
property DataType: TOmniValueDataType read ovType;
property OwnsObject: boolean read IsOwnedObject write SetOwnsObject;
{$IFDEF MSWINDOWS}
function CastToAnsiStringDef(const defValue: AnsiString): AnsiString; inline;
function CastToWideStringDef(defValue: WideString): WideString; inline;
function IsAnsiString: boolean; inline;
function IsWideString: boolean; inline;
function TryCastToAnsiString(var value: AnsiString): boolean;
function TryCastToWideString(var value: WideString): boolean;
{$IFDEF Unicode}
class operator Implicit(const a: TOmniValue): AnsiString; inline;
class operator Implicit(const a: AnsiString): TOmniValue; inline;
{$ENDIF Unicode}
class operator Implicit(const a: TOmniValue): WideString; inline;
class operator Implicit(const a: WideString): TOmniValue; inline;
property AsAnsiString: AnsiString read CastToAnsiString write SetAsAnsiString;
property AsWideString: WideString read CastToWideString write SetAsWideString;
{$ENDIF}
{$IFDEF OTL_Generics}
class function CastFrom<T>(const value: T): TOmniValue; static;
function CastTo<T>: T;
class function FromRecord<T: record>(const value: T): TOmniValue; static;
class function FromRecordUnsafe<T>(const value: T): TOmniValue; static;
function ToRecord<T>: T;
class function Wrap<T>(const value: T): TOmniValue; static;
function Unwrap<T>: T; //Use this form to call: omnivalue.Unwrap<T>()
{$IFDEF OTL_HasArrayOfT}
class function FromArray<T>(const values: TArray<T>): TOmniValue; overload; static;
class function FromArray<T>(const values: array of T): TOmniValue; overload; static;
function ToArray<T>: TArray<T>;
{$ENDIF OTL_HasArrayOfT}
{$IF CompilerVersion > 20}
function CastToObject<T: class>: T; overload;
function ToObject<T: class>: T;
{$IFEND}
{$ENDIF OTL_Generics}
{$IFDEF OTL_ERTTI}
class operator Implicit(const a: TValue): TOmniValue; inline;
class operator Implicit(const a: TOmniValue): TValue; inline;
property AsTValue: TValue read GetAsTValue write SetAsTValue;
{$ENDIF OTL_ERTTI}
end; { TOmniValue }
/// <summary>TOmniValue wrapper - for when you need to treat TOmniValue as an object.</summary>
TOmniValueObj = class
strict private
FValue: TOmniValue;
public
constructor Create(const value: TOmniValue);
property Value: TOmniValue read FValue;
end; { TOmniValueObj }
{$IFDEF OTL_Generics}
TOmniRecord<T> = record
strict private
FValue: T;
public
constructor Create(const aValue: T);
property Value: T read FValue write FValue;
end;
{$ENDIF OTL_Generics}
///<summary>Slightly different from the IEnumerable:
/// - Returns TOmniValue.
/// - Must ensure correct operation of multiple simultaneous enumerators.
/// - TryTake must be implemented to support mutable collections (as TOmniBlockingCollection).
/// For non-mutable collections TryTake can simply return false if the collection
/// is empty.
/// - TryTake must be threadsafe - when used in Parallel.For, data manager will call
/// it simultaneously from multiple threads at the same time.
///</summary>
IOmniValueEnumerator = interface ['{F60EBBD8-2F87-4ACD-A014-452F296F4699}']
function GetCurrent: TOmniValue;
function MoveNext: boolean;
function TryTake(var value: TOmniValue; timeout_ms: cardinal): boolean;
property Current: TOmniValue read GetCurrent;
end; { IOmniValueEnumerator }
IOmniValueEnumerable = interface ['{50C1C176-C61F-41F5-AA0B-6FD215E5159F}']
function GetEnumerator: IOmniValueEnumerator;
end; { IOmniValueEnumerable }
///<summary>Abstract enumerator class, used as a base for internal classes passed to the
/// OtlDataManager.</summary>
TOmniValueEnumerator = class abstract
function GetCurrent: TOmniValue; virtual; abstract;
function MoveNext: boolean; virtual; abstract;
property Current: TOmniValue read GetCurrent;
end; { TOmniValueEnumerator }
IOmniWaitableValue = interface ['{46EB21E0-B5E8-47DA-8E34-E4DE04C4D8D9}']
{$IFDEF MSWINDOWS}
function GetHandle: THandle;
{$ENDIF}
function GetEvent: TEvent;
function GetValue: TOmniValue;
//
procedure Reset;
procedure Signal; overload;
procedure Signal(const data: TOmniValue); overload;
function WaitFor(maxWait_ms: cardinal = INFINITE): boolean;
{$IFDEF MSWINDOWS}
property Handle: THandle read GetHandle;
{$ENDIF}
property Event: TEvent read GetEvent;
property Value: TOmniValue read GetValue;
end; { IOmniWaitableValue }
TOmniWaitableValue = class(TInterfacedObject, IOmniWaitableValue)
strict private
FEvent: TEvent;
FValue: TOmniValue;
protected
{$IFDEF MSWINDOWS}
function GetHandle: THandle;
{$ENDIF}
function GetEvent: TEvent;
function GetValue: TOmniValue;
public
constructor Create; overload;
constructor Create(const value: TOmniValue); overload;
destructor Destroy; override;
procedure Reset; inline;
procedure Signal; overload; inline;
procedure Signal(const data: TOmniValue); overload; inline;
function WaitFor(maxWait_ms: cardinal = INFINITE): boolean; inline;
{$IFDEF MSWINDOWS}
property Handle: THandle read GetHandle;
{$ENDIF}
property Event: TEvent read GetEvent;
property Value: TOmniValue read GetValue;
end; { TOmniWaitableValue }
TOmniValueContainer = class
strict private
ovcCanModify: boolean;
ovcCount : integer;
ovcNames : array of string;
ovcValues : array of TOmniValue;
strict protected
function AddParam(const paramName: string): integer;
procedure Clear;
function GetItem(paramIdx: integer): TOmniValue; overload;
function GetItem(const paramName: string): TOmniValue; overload;
function GetItem(const param: TOmniValue): TOmniValue; overload;
procedure SetItem(idx: integer; const value: TOmniValue); overload; {$IF CompilerVersion >= 22}inline;{$IFEND}
procedure SetItem(const name: string; const value: TOmniValue); overload;
procedure SetItem(const param, value: TOmniValue); overload;
procedure Grow(requiredIdx: integer = -1);
public
constructor Create;
procedure Add(const paramValue: TOmniValue; const paramName: string = '');
procedure Assign(const parameters: array of TOmniValue);
procedure AssignNamed(const parameters: array of TOmniValue);
function ByName(const paramName: string): TOmniValue; overload;
function ByName(const paramName: string; const defValue: TOmniValue): TOmniValue; overload;
function Count: integer;
function Exists(const paramName: string): boolean;
function IndexOf(const paramName: string): integer;
procedure Insert(paramIdx: integer; const value: TOmniValue);
function IsLocked: boolean; inline;
procedure Lock; inline;
property Item[paramIdx: integer]: TOmniValue read GetItem write SetItem; default;
property Item[const paramName: string]: TOmniValue read GetItem write SetItem; default;
property Item[const param: TOmniValue]: TOmniValue read GetItem write SetItem; default;
end; { TOmniValueContainer }
//:Thread-safe counter
IOmniCounter = interface ['{3A73CCF3-EDC5-484F-8459-532B8C715E3C}']
function GetValue: integer;
procedure SetValue(const value: integer);
//
function Increment: integer;
function Decrement: integer;
function Take(count: integer): integer; overload;
function Take(count: integer; var taken: integer): boolean; overload;
property Value: integer read GetValue write SetValue;
end; { IOmniCounter }
TOmniCounter = record
strict private
{$IFNDEF MSWINDOWS}[Volatile]{$ENDIF}
ocCounter: IOmniCounter;
function GetValue: integer;
procedure SetValue(const value: integer);
public
procedure Initialize;
function Increment: integer;
function Decrement: integer;
function Take(count: integer): integer; overload;
function Take(count: integer; var taken: integer): boolean; overload;
property Value: integer read GetValue write SetValue;
end; { TOmniCounter }
{$IFDEF OTL_GoodGenerics}
TOmniInterfaceDictionaryPair = TPair<int64, IInterface>;
{$ELSE}
TOmniInterfaceDictionaryPair = class
strict private
idpKey : int64;
idpValue: IInterface;
protected
procedure SetKeyValue(const key: int64; const value: IInterface);
public
property Key: int64 read idpKey;
property Value: IInterface read idpValue;
end; { TOmniInterfaceDictionaryPair }
IOmniInterfaceDictionaryEnumerator = interface
function GetCurrent: TOmniInterfaceDictionaryPair;
function MoveNext: boolean;
property Current: TOmniInterfaceDictionaryPair read GetCurrent;
end; { IOmniInterfaceDictionaryEnumerator }
{$ENDIF OTL_GoodGenerics}
IOmniInterfaceDictionary = interface ['{619FCCF3-E810-4DCF-B902-1EF1A5A72DB5}']
{$IFDEF OTL_GoodGenerics}
function GetEnumerator: TDictionary<int64, IInterface>.TPairEnumerator;
{$ELSE}
function GetEnumerator: IOmniInterfaceDictionaryEnumerator;
{$ENDIF OTL_GoodGenerics}
//
procedure Add(const key: int64; const value: IInterface);
procedure Clear;
function Count: integer;
procedure Remove(const key: int64);
function ValueOf(const key: int64): IInterface;
end; { IOmniInterfaceDictionary }
IOmniIntegerSet = interface;
TOmniIntegerSetChangedEvent = procedure(const intSet: IOmniIntegerSet) of object;
IOmniIntegerSet = interface ['{571F85D0-CFD8-40FE-8860-A8C1C932028C}']
function GetAsBits: TBits;
function GetAsIntArray: TIntegerDynArray;
function GetAsMask: uint64;
function GetItem(idx: integer): integer;
function GetOnChange: TOmniIntegerSetChangedEvent;
procedure SetAsBits(const value: TBits);
procedure SetAsIntArray(const Value: TIntegerDynArray);
procedure SetAsMask(const value: uint64);
procedure SetOnChange(const value: TOmniIntegerSetChangedEvent);
{$IFDEF OTL_HasArrayOfT}
function GetAsArray: TArray<integer>;
procedure SetAsArray(const Value: TArray<integer>);
{$ENDIF OTL_HasArrayOfT}
//
function Add(value: integer): boolean;
procedure Assign(const value: IOmniIntegerSet);
procedure Clear;
function Contains(value: integer): boolean;
function Count: integer;
function IsEmpty: boolean;
function Remove(value: integer): boolean;
{$IFDEF OTL_HasArrayOfT}
property AsArray: TArray<integer> read GetAsArray write SetAsArray;
{$ENDIF OTL_HasArrayOfT}
property AsBits: TBits read GetAsBits write SetAsBits;
property AsIntArray: TIntegerDynArray read GetAsIntArray write SetAsIntArray;
property AsMask: uint64 read GetAsMask write SetAsMask;
property OnChange: TOmniIntegerSetChangedEvent read GetOnChange write SetOnChange;
property Item[idx: integer]: integer read GetItem; default;
end; { IOmniIntegerSet }
TOmniIntegerSet = class(TInterfacedObject, IOmniIntegerSet)
strict private
FBits : TBits;
FHasValueCopy: boolean;
FOnChange : TOmniIntegerSetChangedEvent;
FValueCopy : TIntegerDynArray;
protected
procedure DoOnChange;
function GetAsBits: TBits; inline;
function GetAsIntArray: TIntegerDynArray;
function GetAsMask: uint64;
function GetItem(idx: integer): integer;
function GetOnChange: TOmniIntegerSetChangedEvent; inline;
procedure PrepareValueCopy;
procedure SetAsBits(const value: TBits);
procedure SetAsIntArray(const value: TIntegerDynArray);
procedure SetAsMask(const value: uint64);
procedure SetOnChange(const value: TOmniIntegerSetChangedEvent); inline;
{$IFDEF OTL_HasArrayOfT}
function GetAsArray: TArray<integer>;
procedure SetAsArray(const value: TArray<integer>);
{$ENDIF OTL_HasArrayOfT}
public
constructor Create;
constructor Clone(const value: IOmniIntegerSet);
destructor Destroy; override;
function Add(value: integer): boolean;
procedure Assign(const value: IOmniIntegerSet); overload;
procedure Assign(const value: TOmniIntegerSet); overload;
procedure Clear; inline;
function Contains(value: integer): boolean; inline;
function Count: integer;
function IsEmpty: boolean;
function Remove(value: integer): boolean;
{$IFDEF OTL_HasArrayOfT}
property AsArray: TArray<integer> read GetAsArray write SetAsArray;
{$ENDIF OTL_HasArrayOfT}
property AsBits: TBits read GetAsBits write SetAsBits;
property AsIntArray: TIntegerDynArray read GetAsIntArray write SetAsIntArray;
property AsMask: uint64 read GetAsMask write SetAsMask;
property OnChange: TOmniIntegerSetChangedEvent read GetOnChange write SetOnChange;
property Item[idx: integer]: integer read GetItem; default;
end; { TOmniIntegerSet }
IOmniAffinity = interface ['{8A6DDC70-F705-4577-869B-6810E776132B}']
function GetAsString: string;
function GetCount: integer;
function GetCountPhysical: integer;
procedure SetAsString(const value: string);
procedure SetCount(const value: integer);
{$IFDEF MSWINDOWS}
function GetMask: NativeUInt;
procedure SetMask(const value: NativeUInt);
{$ENDIF}
//
property AsString: string read GetAsString write SetAsString;
property Count: integer read GetCount write SetCount;
property CountPhysical: integer read GetCountPhysical;
{$IFDEF MSWINDOWS}
property Mask: NativeUInt read GetMask write SetMask;
{$ENDIF}
end; { IOmniAffinity }
{$IFDEF MSWINDOWS}
TOmniProcessMemoryCounters = TProcessMemoryCounters;
{$ENDIF}
{$IFDEF MSWINDOWS}
TOmniProcessTimes = record
CreationTime: TDateTime;
UserTime : int64;
KernelTime : int64;
end; { TOmniProcessTimes }
{$ENDIF}
TOmniProcessPriorityClass = (pcIdle, pcBelowNormal, pcNormal, pcAboveNormal, pcHigh,
pcRealtime);
IOmniProcessEnvironment = interface ['{98D6BDA3-840B-4E19-B01D-633E6A239FE9}']
function GetAffinity: IOmniAffinity;
function GetPriorityClass: TOmniProcessPriorityClass;
{$IFDEF MSWINDOWS}
function GetMemory: TOmniProcessMemoryCounters;
function GetTimes: TOmniProcessTimes;
{$ENDIF}
//
property Affinity: IOmniAffinity read GetAffinity;
property PriorityClass: TOmniProcessPriorityClass read GetPriorityClass;
{$IFDEF MSWINDOWS}
property Memory: TOmniProcessMemoryCounters read GetMemory;
property Times: TOmniProcessTimes read GetTimes;
{$ENDIF}
end; { IOmniProcessEnvironment }
IOmniSystemEnvironment = interface ['{9BE1EFE3-4ABB-4C2F-B2A4-B014D0949FEC}']
function GetAffinity: IOmniAffinity;
//
property Affinity: IOmniAffinity read GetAffinity;
end; { IOmniSystemEnvironment }
{$IFNDEF OTL_HasThreadID}
TThreadID = LongWord;
{$ENDIF ~OTL_HasThreadID}
TOmniGroupAffinity = record
private
FAffinity: IOmniIntegerSet;
FGroup : integer;
function GetAffinity: IOmniIntegerSet;
public
constructor Create(groupNumber: integer; const affinity: IOmniIntegerSet); overload;
constructor Create(groupNumber: integer; const affinityMask: int64); overload;
property Group: integer read FGroup write FGroup;
property Affinity: IOmniIntegerSet read GetAffinity;
end; { TOmniGroupAffinity }
IOmniThreadEnvironment = interface ['{5C11FEC7-9FBE-423F-B30E-543C8240E3A3}']
function GetAffinity: IOmniAffinity;
function GetGroupAffinity: TOmniGroupAffinity;
function GetID: TThreadId;
procedure SetGroupAffinity(const value: TOmniGroupAffinity);
//
property Affinity: IOmniAffinity read GetAffinity;
property GroupAffinity: TOmniGroupAffinity read GetGroupAffinity write SetGroupAffinity;
property ID: TThreadId read GetID;
end; { IOmniThreadEnvironment }
{$IFDEF OTL_NUMASupport}
IOmniNUMANode = interface ['{8D3B415F-8B13-4BFF-B7C7-2D0BC1705217}']
function GetAffinity: IOmniIntegerSet;
function GetGroupNumber: integer;
function GetNodeNumber: integer;
//
property NodeNumber: integer read GetNodeNumber;
property GroupNumber: integer read GetGroupNumber;
property Affinity: IOmniIntegerSet read GetAffinity;
end; { IOmniNUMANode }
IOmniNUMANodes = interface ['{4407E795-ED35-4DD1-9EC6-D59758BAF581}']
function GetItem(idx: integer): IOmniNUMANode;
//
function All: IOmniIntegerSet;
function Count: integer;
function Distance(fromNode, toNode: integer): integer;
function FindNode(nodeNumber: integer): IOmniNUMANode;
function GetEnumerator: TList<IOmniNUMANode>.TEnumerator;
property Item[idx: integer]: IOmniNUMANode read GetItem; default;
end; { IOmniNUMANodes }
IOmniProcessorGroup = interface ['{BCFB0AE8-A378-4A4B-AD73-EF9B59218B55}']
function GetAffinity: IOmniIntegerSet;
function GetGroupNumber: integer;
//
property GroupNumber: integer read GetGroupNumber;
property Affinity: IOmniIntegerSet read GetAffinity;
end; { IOmniProcessorGroup }
IOmniProcessorGroups = interface ['{B4C871C0-CF61-4BC9-98DE-87F720F51853}']
function GetItem(idx: integer): IOmniProcessorGroup;
//
function All: IOmniIntegerSet;
function Count: integer;
function FindGroup(groupNumber: integer): IOmniProcessorGroup;
function GetEnumerator: TList<IOmniProcessorGroup>.TEnumerator;
property Item[idx: integer]: IOmniProcessorGroup read GetItem; default;
end; { IOmniProcessorGroups }
{$ENDIF OTL_NUMASupport}
IOmniEnvironment = interface ['{4F9594E2-8B88-483C-9616-85B50493406D}']
{$IFDEF OTL_NUMASupport}
function GetNUMANodes: IOmniNUMANodes;
function GetProcessorGroups: IOmniProcessorGroups;
{$ENDIF OTL_NUMASupport}
function GetProcess: IOmniProcessEnvironment;
function GetSystem: IOmniSystemEnvironment;
function GetThread: IOmniThreadEnvironment;
//
{$IFDEF OTL_NUMASupport}
property NUMANodes: IOmniNUMANodes read GetNUMANodes;
property ProcessorGroups: IOmniProcessorGroups read GetProcessorGroups;
{$ENDIF OTL_NUMASupport}
property Process: IOmniProcessEnvironment read GetProcess;
property System: IOmniSystemEnvironment read GetSystem;
property Thread: IOmniThreadEnvironment read GetThread;
end; { IOmniEnvironment }
TOmniExecutableKind = (oekNull, oekProcedure, oekMethod {$IFDEF OTL_Anonymous},
oekDelegate{$ENDIF});
TOmniExecutable = record
{$IFDEF OTL_Anonymous}
strict private
oeDelegate: TProc;
procedure SetAnonDelegate(const value: TProc); inline;
function GetDelegate: TProc; inline;
{$ENDIF OTL_Anonymous}
strict private
oeMethod : TMethod;
oeProcedure: TProcedure;
oeKind : TOmniExecutableKind;
procedure CheckKind(kind: TOmniExecutableKind); inline;
function GetMethod: TMethod; inline;
function GetProc: TProcedure; inline;
procedure SetMethod(const value: TMethod); inline;
procedure SetProc(const value: TProcedure); inline;
public
class operator Explicit(const a: TOmniExecutable): TMethod; inline;
class operator Explicit(const a: TOmniExecutable): TProcedure; inline;
class operator Explicit(const a: TMethod): TOmniExecutable; inline;
class operator Explicit(const a: TProcedure): TOmniExecutable; inline;
class operator Implicit(const a: TMethod): TOmniExecutable; inline;
class operator Implicit(const a: TProcedure): TOmniExecutable; inline;
class operator Implicit(const a: TOmniExecutable): TMethod; inline;
class operator Implicit(const a: TOmniExecutable): TProcedure; inline;
procedure Clear; inline;
function IsNull: boolean; inline;
property Kind: TOmniExecutableKind read oeKind;
property Method: TMethod read GetMethod write SetMethod;
property Proc: TProcedure read GetProc write SetProc;
public
{$IFDEF OTL_Anonymous}
class procedure AnonCopy(var Dest; const Source); static;