hexsha
stringlengths 40
40
| size
int64 3
1.05M
| ext
stringclasses 163
values | lang
stringclasses 53
values | max_stars_repo_path
stringlengths 3
945
| max_stars_repo_name
stringlengths 4
112
| max_stars_repo_head_hexsha
stringlengths 40
78
| max_stars_repo_licenses
listlengths 1
10
| max_stars_count
float64 1
191k
⌀ | max_stars_repo_stars_event_min_datetime
stringlengths 24
24
⌀ | max_stars_repo_stars_event_max_datetime
stringlengths 24
24
⌀ | max_issues_repo_path
stringlengths 3
945
| max_issues_repo_name
stringlengths 4
113
| max_issues_repo_head_hexsha
stringlengths 40
78
| max_issues_repo_licenses
listlengths 1
10
| max_issues_count
float64 1
116k
⌀ | max_issues_repo_issues_event_min_datetime
stringlengths 24
24
⌀ | max_issues_repo_issues_event_max_datetime
stringlengths 24
24
⌀ | max_forks_repo_path
stringlengths 3
945
| max_forks_repo_name
stringlengths 4
113
| max_forks_repo_head_hexsha
stringlengths 40
78
| max_forks_repo_licenses
listlengths 1
10
| max_forks_count
float64 1
105k
⌀ | max_forks_repo_forks_event_min_datetime
stringlengths 24
24
⌀ | max_forks_repo_forks_event_max_datetime
stringlengths 24
24
⌀ | content
stringlengths 3
1.05M
| avg_line_length
float64 1
966k
| max_line_length
int64 1
977k
| alphanum_fraction
float64 0
1
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
47bcfc32d5d5a8b9dd6faeb7379cabfbf65d1677 | 7,830 | pas | Pascal | library/fui/fui_validation_wrapper.pas | grahamegrieve/fhirserver | 28f69977bde75490adac663e31a3dd77bc016f7c | [
"BSD-3-Clause"
]
| 132 | 2015-02-02T00:22:40.000Z | 2021-08-11T12:08:08.000Z | library/fui/fui_validation_wrapper.pas | grahamegrieve/fhirserver | 28f69977bde75490adac663e31a3dd77bc016f7c | [
"BSD-3-Clause"
]
| 113 | 2015-03-20T01:55:20.000Z | 2021-10-08T16:15:28.000Z | library/fui/fui_validation_wrapper.pas | grahamegrieve/fhirserver | 28f69977bde75490adac663e31a3dd77bc016f7c | [
"BSD-3-Clause"
]
| 49 | 2015-04-11T14:59:43.000Z | 2021-03-30T10:29:18.000Z | unit fui_validation_wrapper;
{
Copyright (c) 2017+, Health Intersections Pty Ltd (http://www.healthintersections.com.au)
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.
* Neither the name of HL7 nor the names of its contributors may 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 HOLDER 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.
}
{ This code is not functional at this time. It may be brought back to life in the future. }
{$i fhir.inc}
interface
uses
{$IFDEF WINDOWS} Windows, {$ENDIF}
SysUtils, Classes,
fsl_base, fsl_utilities,
fsl_npm_cache,
FHIR.Base.Lang;
type
TOutputLineEvent = procedure (Sender : TObject; line : String) of Object;
TArg<T> = reference to procedure(const Arg: T);
TFHIRValidationWrapper = class (TFslObject)
private
// context
FCache : TFHIRPackageManager;
FJarPath : String;
// settings
FSource: String;
FNative: boolean;
FPackages: TStringList;
FOthers: TStringList;
FVersion: String;
FOnOutput: TOutputLineEvent;
FTxServer : String;
Fmap: String;
FDest: String;
FProfile: String;
procedure executeCommand(cmd : String; CallBack: TArg<PAnsiChar>);
public
constructor Create(Cache : TFHIRPackageManager);
destructor Destroy; override;
function link : TFHIRValidationWrapper;
function validateCmd: string;
function transformCmd: string;
procedure validate;
procedure transform;
property version : String read FVersion write FVersion;
property Packages : TStringList read FPackages;
property Others : TStringList read FOthers;
property native : boolean read FNative write FNative;
property source : String read FSource write FSource;
property map : String read Fmap write FMap;
property profile : String read FProfile write FProfile;
property dest : String read FDest write FDest;
Property txServer : String read FTxServer write FTxServer;
property OnOutput : TOutputLineEvent read FOnOutput write FOnOutput;
end;
implementation
{ TFHIRValidationWrapper }
constructor TFHIRValidationWrapper.Create(Cache: TFHIRPackageManager);
var
ts : TStringList;
begin
inherited create;
FCache := cache;
FPackages := TStringList.create;
FOthers := TStringList.create;
end;
destructor TFHIRValidationWrapper.Destroy;
begin
FPackages.Free;
FOthers.Free;
FCache.free;
inherited;
end;
// OSX: see http://www.fmxexpress.com/read-and-interact-with-a-command-line-pipe-in-delphi-xe7-firemonkey-on-mac-osx/ ?
procedure TFHIRValidationWrapper.validate;
begin
executeCommand(validateCmd,
procedure(const Line: PAnsiChar)
begin
FOnOutput(self, line);
end);
end;
{$IFDEF WINDOWS}
procedure TFHIRValidationWrapper.executeCommand(cmd : String; CallBack: TArg<PAnsiChar>);
const
CReadBuffer = 2400;
var
saSecurity: TSecurityAttributes;
hRead: THandle;
hWrite: THandle;
suiStartup: TStartupInfo;
piProcess: TProcessInformation;
pBuffer: array [0 .. CReadBuffer] of AnsiChar;
dBuffer: array [0 .. CReadBuffer] of AnsiChar;
dRead: DWORD;
dRunning: DWORD;
dAvailable: DWORD;
begin
saSecurity.nLength := SizeOf(TSecurityAttributes);
saSecurity.bInheritHandle := true;
saSecurity.lpSecurityDescriptor := nil;
if CreatePipe(hRead, hWrite, @saSecurity, 0) then
try
FillChar(suiStartup, SizeOf(TStartupInfo), #0);
suiStartup.cb := SizeOf(TStartupInfo);
suiStartup.hStdInput := hRead;
suiStartup.hStdOutput := hWrite;
suiStartup.hStdError := hWrite;
suiStartup.dwFlags := STARTF_USESTDHANDLES or STARTF_USESHOWWINDOW;
suiStartup.wShowWindow := SW_HIDE;
if CreateProcess(nil, PChar(cmd), @saSecurity, @saSecurity, true, NORMAL_PRIORITY_CLASS, nil, nil, suiStartup,
piProcess) then
try
repeat
dRunning := WaitForSingleObject(piProcess.hProcess, 100);
PeekNamedPipe(hRead, nil, 0, nil, @dAvailable, nil);
if (dAvailable > 0) then
repeat
dRead := 0;
ReadFile(hRead, pBuffer[0], CReadBuffer, dRead, nil);
pBuffer[dRead] := #0;
OemToCharA(pBuffer, dBuffer);
CallBack(dBuffer);
until (dRead < CReadBuffer);
until (dRunning <> WAIT_TIMEOUT);
finally
CloseHandle(piProcess.hProcess);
CloseHandle(piProcess.hThread);
end;
finally
CloseHandle(hRead);
CloseHandle(hWrite);
end;
end;
{$ELSE}
procedure TFHIRValidationWrapper.executeCommand(cmd : String; CallBack: TArg<PAnsiChar>);
begin
raise EFHIRTodo.create('TFHIRValidationWrapper.executeCommand');
end;
{$ENDIF}
function TFHIRValidationWrapper.link: TFHIRValidationWrapper;
begin
result := TFHIRValidationWrapper(inherited link);
end;
procedure TFHIRValidationWrapper.transform;
begin
executeCommand(validateCmd,
procedure(const Line: PAnsiChar)
begin
FOnOutput(self, line);
end);
end;
function TFHIRValidationWrapper.validateCmd: string;
var
i : integer;
s : String;
begin
if FJarPath = '' then
exit('Error: validator not installed');
result := 'java -jar "'+FJarPath+'"';
if FSource <> '' then
result := result+' '+source;
result := result + ' -defn hl7.fhir.core-'+FVersion;
if FProfile <> '' then
result := result+' -profile '+FProfile;
if FNative then
result := result +' -native';
if FTxServer <> '' then
result := result + ' -tx '+FtxServer;
for s in FPackages do
result := result +' -ig '+s;
for s in FOthers do
result := result +' -ig '+s;
if FDest <> '' then
result := result+' -output '+FDest;
end;
function TFHIRValidationWrapper.transformCmd: string;
var
i : integer;
s : String;
begin
if FJarPath = '' then
exit('Error: validator not installed');
if FMap = '' then
exit('Error: map not specified');
result := 'java -jar "'+FJarPath+'"';
if FSource <> '' then
result := result+' '+source;
if FMap <> '' then
result := result+' -transform '+FMap+' -defn hl7.fhir.core-'+FVersion;
if FTxServer <> '' then
result := result + ' -tx '+FtxServer;
for s in FPackages do
result := result +' -ig '+s;
for s in FOthers do
result := result +' -ig '+s;
if FDest <> '' then
result := result+' -output '+FDest;
end;
end.
| 29.771863 | 122 | 0.680332 |
47f066ce95dfa5e38ac8f9e604d3480177212b00 | 47 | pas | Pascal | Test/BuildScripts/CircularA.pas | skolkman/dwscript | b9f99d4b8187defac3f3713e2ae0f7b83b63d516 | [
"Condor-1.1"
]
| 79 | 2015-03-18T10:46:13.000Z | 2022-03-17T18:05:11.000Z | Test/BuildScripts/CircularA.pas | skolkman/dwscript | b9f99d4b8187defac3f3713e2ae0f7b83b63d516 | [
"Condor-1.1"
]
| 6 | 2016-03-29T14:39:00.000Z | 2020-09-14T10:04:14.000Z | Test/BuildScripts/CircularA.pas | skolkman/dwscript | b9f99d4b8187defac3f3713e2ae0f7b83b63d516 | [
"Condor-1.1"
]
| 25 | 2016-05-04T13:11:38.000Z | 2021-09-29T13:34:31.000Z | unit CircularA;
interface
uses CircularB; | 9.4 | 16 | 0.744681 |
f1c1e5fa2e9cfe71f1c71932acae8518850fdec5 | 155,107 | pas | Pascal | references/jcl/jcl/source/prototypes/JclGraphics.pas | zekiguven/alcinoe | e55c5368ee8bfe7cd6d92424c29ab07d8a3e844c | [
"Apache-2.0"
]
| 851 | 2018-02-05T09:54:56.000Z | 2022-03-24T23:13:10.000Z | references/jcl/jcl/source/prototypes/JclGraphics.pas | zekiguven/alcinoe | e55c5368ee8bfe7cd6d92424c29ab07d8a3e844c | [
"Apache-2.0"
]
| 200 | 2018-02-06T18:52:39.000Z | 2022-03-24T19:59:14.000Z | references/jcl/jcl/source/prototypes/JclGraphics.pas | zekiguven/alcinoe | e55c5368ee8bfe7cd6d92424c29ab07d8a3e844c | [
"Apache-2.0"
]
| 197 | 2018-03-20T20:49:55.000Z | 2022-03-21T17:38:14.000Z | {**************************************************************************************************}
{ }
{ Project JEDI Code Library (JCL) }
{ }
{ 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 JclGraphics.pas. }
{ }
{ The resampling algorithms and methods used in this library were adapted by Anders Melander from }
{ the article "General Filtered Image Rescaling" by Dale Schumacher which appeared in the book }
{ Graphics Gems III, published by Academic Press, Inc. Additional improvements were done by David }
{ Ullrich and Josha Beukema. }
{ }
{ (C)opyright 1997-1999 Anders Melander }
{ }
{ The Initial Developers of the Original Code are Alex Denissov, Wim De Cleen, Anders Melander }
{ and Mike Lischke. Portions created by these individuals are Copyright (C) of these individuals. }
{ All Rights Reserved. }
{ }
{ Contributors: }
{ Alexander Radchenko }
{ Charlie Calvert }
{ Marcel van Brakel }
{ Marcin Wieczorek }
{ Matthias Thoma (mthoma) }
{ Petr Vones (pvones) }
{ Robert Marquardt (marquardt) }
{ Robert Rossmair (rrossmair) }
{ Dejoy Den (dejoy) }
{ }
{**************************************************************************************************}
{ }
{ Last modified: $Date:: $ }
{ Revision: $Rev:: $ }
{ Author: $Author:: $ }
{ }
{**************************************************************************************************}
unit JclGraphics;
{$I jcl.inc}
interface
uses
{$IFDEF HAS_UNITSCOPE}
Winapi.Windows, System.Classes, System.SysUtils, Vcl.Graphics, Vcl.Controls, Vcl.Forms,
{$ELSE ~HAS_UNITSCOPE}
Windows, Classes, SysUtils, Graphics, Controls, Forms,
{$ENDIF ~HAS_UNITSCOPE}
{$IFDEF UNITVERSIONING}
JclUnitVersioning,
{$ENDIF UNITVERSIONING}
JclGraphUtils, JclBase;
type
EJclGraphicsError = class(EJclError);
TDynDynIntegerArrayArray = array of TDynIntegerArray;
TDynPointArray = array of TPoint;
TDynDynPointArrayArray = array of TDynPointArray;
TPointF = record
X: Single;
Y: Single;
end;
TDynPointArrayF = array of TPointF;
{ TJclBitmap32 draw mode }
TDrawMode = (dmOpaque, dmBlend);
{ stretch filter }
TStretchFilter = (sfNearest, sfLinear, sfSpline);
TConversionKind = (ckRed, ckGreen, ckBlue, ckAlpha, ckUniformRGB, ckWeightedRGB);
{ resampling support types }
TResamplingFilter =
(rfBox, rfTriangle, rfHermite, rfBell, rfSpline, rfLanczos3, rfMitchell);
{ Matrix declaration for transformation }
// modify Jan 28, 2001 for use under BCB5
// the compiler show error 245 "language feature ist not available"
// we must take a record and under this we can use the static array
// Note: the sourcecode modify general from M[] to M.A[] !!!!!
// TMatrix3d = array [0..2, 0..2] of Extended; // 3x3 double precision
TMatrix3d = record
A: array [0..2, 0..2] of Extended;
end;
TDynDynPointArrayArrayF = array of TDynPointArrayF;
TScanLine = array of Integer;
TScanLines = array of TScanLine;
TLUT8 = array [Byte] of Byte;
TGamma = array [Byte] of Byte;
TColorChannel = (ccRed, ccGreen, ccBlue, ccAlpha);
TGradientDirection = (gdVertical, gdHorizontal);
TPolyFillMode = (fmAlternate, fmWinding);
TJclRegionCombineOperator = (coAnd, coDiff, coOr, coXor);
TJclRegionBitmapMode = (rmInclude, rmExclude);
TJclRegionKind = (rkNull, rkSimple, rkComplex, rkError);
// modify Jan 28, 2001 for use under BCB5
// the compiler show error 245 "language feature ist not available"
// wie must take a record and under this we can use the static array
// Note: for init the array we used initialisation at the end of this unit
//
// const
// IdentityMatrix: TMatrix3d = (
// (1, 0, 0),
// (0, 1, 0),
// (0, 0, 1));
var
IdentityMatrix: TMatrix3d;
// Classes
type
{$IFDEF VCL}
TJclDesktopCanvas = class(TCanvas)
private
FDesktop: HDC;
public
constructor Create;
destructor Destroy; override;
end;
TJclRegion = class;
TJclRegionInfo = class(TObject)
private
FData: Pointer;
FDataSize: Integer;
function GetBox: TRect;
protected
function GetCount: Integer;
function GetRect(index: Integer): TRect;
public
constructor Create(Region: TJclRegion);
destructor Destroy; override;
property Box: TRect read GetBox;
property Rectangles[Index: Integer]: TRect read GetRect;
property Count: Integer read GetCount;
end;
TJclRegion = class(TObject)
private
FHandle: HRGN;
FBoxRect: TRect;
FRegionType: Integer;
FOwnsHandle: Boolean;
procedure CheckHandle;
protected
function GetHandle: HRGN;
function GetBox: TRect;
function GetRegionType: TJclRegionKind;
public
constructor Create(RegionHandle: HRGN; OwnsHandle: Boolean = True);
constructor CreateElliptic(const ARect: TRect); overload;
constructor CreateElliptic(const Top, Left, Bottom, Right: Integer); overload;
constructor CreatePoly(const Points: TDynPointArray; Count: Integer; FillMode: TPolyFillMode);
constructor CreatePolyPolygon(const Points: TDynPointArray; const Vertex: TDynIntegerArray;
Count: Integer; FillMode: TPolyFillMode);
constructor CreateRect(const ARect: TRect; DummyForBCB: Boolean = False); overload;
constructor CreateRect(const Top, Left, Bottom, Right: Integer; DummyForBCB: Byte = 0); overload;
constructor CreateRoundRect(const ARect: TRect; CornerWidth, CornerHeight: Integer); overload;
constructor CreateRoundRect(const Top, Left, Bottom, Right, CornerWidth, CornerHeight: Integer); overload;
constructor CreateBitmap(Bitmap: TBitmap; RegionColor: TColor; RegionBitmapMode: TJclRegionBitmapMode);
constructor CreatePath(Canvas: TCanvas);
constructor CreateRegionInfo(RegionInfo: TJclRegionInfo);
constructor CreateMapWindow(InitialRegion: TJclRegion; hWndFrom, hWndTo: THandle); overload;
constructor CreateMapWindow(InitialRegion: TJclRegion; ControlFrom, ControlTo: TWinControl); overload;
destructor Destroy; override;
procedure Clip(Canvas: TCanvas);
procedure Combine(DestRegion, SrcRegion: TJclRegion; CombineOp: TJclRegionCombineOperator); overload;
procedure Combine(SrcRegion: TJclRegion; CombineOp: TJclRegionCombineOperator); overload;
function Copy: TJclRegion;
function Equals(CompareRegion: TJclRegion): Boolean; {$IFDEF RTL200_UP} reintroduce; {$ENDIF RTL200_UP}
procedure Fill(Canvas: TCanvas);
procedure FillGradient(Canvas: TCanvas; ColorCount: Integer; StartColor, EndColor: TColor; ADirection: TGradientDirection);
procedure Frame(Canvas: TCanvas; FrameWidth, FrameHeight: Integer);
procedure Invert(Canvas: TCanvas);
procedure Offset(X, Y: Integer);
procedure Paint(Canvas: TCanvas);
function PointIn(X, Y: Integer): Boolean; overload;
function PointIn(const Point: TPoint): Boolean; overload;
function RectIn(const ARect: TRect): Boolean; overload;
function RectIn(Top, Left, Bottom, Right: Integer): Boolean; overload;
procedure SetWindow(Window: THandle; Redraw: Boolean);
function GetRegionInfo: TJclRegionInfo;
property Box: TRect read GetBox;
property Handle: HRGN read GetHandle;
property RegionType: TJclRegionKind read GetRegionType;
end;
{$ENDIF VCL}
{$IFDEF Bitmap32}
{ TJclThreadPersistent }
{ TJclThreadPersistent is an ancestor for TJclBitmap32 object. In addition to
TPersistent methods, it provides thread-safe locking and change notification }
TJclThreadPersistent = class(TPersistent)
private
{$IFDEF VCL}
FLock: TRTLCriticalSection;
{$ELSE VCL}
FLock: TCriticalSection;
{$ENDIF VCL}
FLockCount: Integer;
FUpdateCount: Integer;
FOnChanging: TNotifyEvent;
FOnChange: TNotifyEvent;
protected
property LockCount: Integer read FLockCount;
property UpdateCount: Integer read FUpdateCount;
public
constructor Create; virtual;
destructor Destroy; override;
procedure Changing; virtual;
procedure Changed; virtual;
procedure BeginUpdate;
procedure EndUpdate;
procedure Lock;
procedure Unlock;
property OnChanging: TNotifyEvent read FOnChanging write FOnChanging;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
end;
{ TJclCustomMap }
{ An ancestor for bitmaps and similar 2D distributions which have width and
height properties }
TJclCustomMap = class(TJclThreadPersistent)
private
FHeight: Integer;
FWidth: Integer;
procedure SetHeight(NewHeight: Integer);
procedure SetWidth(NewWidth: Integer);
public
procedure Delete; virtual;
function Empty: Boolean; virtual;
procedure SetSize(Source: TPersistent); overload;
procedure SetSize(NewWidth, NewHeight: Integer); overload; virtual;
property Height: Integer read FHeight write SetHeight;
property Width: Integer read FWidth write SetWidth;
end;
{ TJclBitmap32 }
{ The TJclBitmap32 class is responsible for storage of a bitmap, as well as for drawing in it }
TJclBitmap32 = class(TJclCustomMap)
private
FBitmapInfo: TBitmapInfo;
FBits: PColor32Array;
FDrawMode: TDrawMode;
FFont: TFont;
FHandle: HBITMAP;
FHDC: HDC;
FMasterAlpha: Byte;
FOuterColor: TColor32; // the value returned when accessing outer areas
FPenColor: TColor32;
FStippleCounter: Single;
FStipplePattern: TArrayOfColor32;
FStippleStep: Single;
FStretchFilter: TStretchFilter;
FResetAlphaOnAssign: Boolean;
function GetPixel(X, Y: Integer): TColor32;
function GetPixelS(X, Y: Integer): TColor32;
function GetPixelPtr(X, Y: Integer): PColor32;
function GetScanLine(Y: Integer): PColor32Array;
procedure SetDrawMode(Value: TDrawMode);
procedure SetFont(Value: TFont);
procedure SetMasterAlpha(Value: Byte);
procedure SetPixel(X, Y: Integer; Value: TColor32);
procedure SetPixelS(X, Y: Integer; Value: TColor32);
procedure SetStippleStep(Value: Single);
procedure SetStretchFilter(Value: TStretchFilter);
protected
FontHandle: HFont;
RasterX: Integer;
RasterY: Integer;
RasterXF: Single;
RasterYF: Single;
procedure AssignTo(Dst: TPersistent); override;
function ClipLine(var X0, Y0, X1, Y1: Integer): Boolean;
class function ClipLineF(var X0, Y0, X1, Y1: Single; MinX, MaxX, MinY, MaxY: Single): Boolean;
procedure FontChanged(Sender: TObject);
procedure SET_T256(X, Y: Integer; C: TColor32);
procedure SET_TS256(X, Y: Integer; C: TColor32);
procedure ReadData(Stream: TStream); virtual;
procedure WriteData(Stream: TStream); virtual;
procedure DefineProperties(Filer: TFiler); override;
property StippleCounter: Single read FStippleCounter;
public
constructor Create; override;
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
procedure SetSize(NewWidth, NewHeight: Integer); override;
function Empty: Boolean; override;
procedure Clear; overload;
procedure Clear(FillColor: TColor32); overload;
procedure Delete; override;
procedure LoadFromStream(Stream: TStream);
procedure SaveToStream(Stream: TStream);
procedure LoadFromFile(const FileName: string);
procedure SaveToFile(const FileName: string);
procedure ResetAlpha;
procedure Draw(DstX, DstY: Integer; Src: TJclBitmap32); overload;
procedure Draw(DstRect, SrcRect: TRect; Src: TJclBitmap32); overload;
procedure Draw(DstRect, SrcRect: TRect; hSrc: HDC); overload;
procedure DrawTo(Dst: TJclBitmap32); overload;
procedure DrawTo(Dst: TJclBitmap32; DstX, DstY: Integer); overload;
procedure DrawTo(Dst: TJclBitmap32; DstRect: TRect); overload;
procedure DrawTo(Dst: TJclBitmap32; DstRect, SrcRect: TRect); overload;
procedure DrawTo(hDst: HDC; DstX, DstY: Integer); overload;
procedure DrawTo(hDst: HDC; DstRect, SrcRect: TRect); overload;
function GetPixelB(X, Y: Integer): TColor32;
procedure SetPixelT(X, Y: Integer; Value: TColor32); overload;
procedure SetPixelT(var Ptr: PColor32; Value: TColor32); overload;
procedure SetPixelTS(X, Y: Integer; Value: TColor32);
procedure SetPixelF(X, Y: Single; Value: TColor32);
procedure SetPixelFS(X, Y: Single; Value: TColor32);
procedure SetStipple(NewStipple: TArrayOfColor32); overload;
procedure SetStipple(NewStipple: array of TColor32); overload;
procedure ResetStippleCounter;
function GetStippleColor: TColor32;
procedure DrawHorzLine(X1, Y, X2: Integer; Value: TColor32);
procedure DrawHorzLineS(X1, Y, X2: Integer; Value: TColor32);
procedure DrawHorzLineT(X1, Y, X2: Integer; Value: TColor32);
procedure DrawHorzLineTS(X1, Y, X2: Integer; Value: TColor32);
procedure DrawHorzLineTSP(X1, Y, X2: Integer);
procedure DrawVertLine(X, Y1, Y2: Integer; Value: TColor32);
procedure DrawVertLineS(X, Y1, Y2: Integer; Value: TColor32);
procedure DrawVertLineT(X, Y1, Y2: Integer; Value: TColor32);
procedure DrawVertLineTS(X, Y1, Y2: Integer; Value: TColor32);
procedure DrawVertLineTSP(X, Y1, Y2: Integer);
procedure DrawLine(X1, Y1, X2, Y2: Integer; Value: TColor32; L: Boolean = False);
procedure DrawLineS(X1, Y1, X2, Y2: Integer; Value: TColor32; L: Boolean = False);
procedure DrawLineT(X1, Y1, X2, Y2: Integer; Value: TColor32; L: Boolean = False);
procedure DrawLineTS(X1, Y1, X2, Y2: Integer; Value: TColor32; L: Boolean = False);
procedure DrawLineA(X1, Y1, X2, Y2: Integer; Value: TColor32; L: Boolean = False);
procedure DrawLineAS(X1, Y1, X2, Y2: Integer; Value: TColor32; L: Boolean = False);
procedure DrawLineF(X1, Y1, X2, Y2: Single; Value: TColor32; L: Boolean = False);
procedure DrawLineFS(X1, Y1, X2, Y2: Single; Value: TColor32; L: Boolean = False);
procedure DrawLineFP(X1, Y1, X2, Y2: Single; L: Boolean = False);
procedure DrawLineFSP(X1, Y1, X2, Y2: Single; L: Boolean = False);
procedure MoveTo(X, Y: Integer);
procedure LineToS(X, Y: Integer);
procedure LineToTS(X, Y: Integer);
procedure LineToAS(X, Y: Integer);
procedure MoveToF(X, Y: Single);
procedure LineToFS(X, Y: Single);
procedure FillRect(X1, Y1, X2, Y2: Integer; Value: TColor32);
procedure FillRectS(X1, Y1, X2, Y2: Integer; Value: TColor32);
procedure FillRectT(X1, Y1, X2, Y2: Integer; Value: TColor32);
procedure FillRectTS(X1, Y1, X2, Y2: Integer; Value: TColor32);
procedure FrameRectS(X1, Y1, X2, Y2: Integer; Value: TColor32);
procedure FrameRectTS(X1, Y1, X2, Y2: Integer; Value: TColor32); overload;
procedure FrameRectTSP(X1, Y1, X2, Y2: Integer); overload;
procedure RaiseRectTS(X1, Y1, X2, Y2: Integer; Contrast: Integer);
procedure UpdateFont;
procedure TextOut(X, Y: Integer; const Text: string); overload;
procedure TextOut(X, Y: Integer; const ClipRect: TRect; const Text: string); overload;
procedure TextOut(ClipRect: TRect; const Flags: Cardinal; const Text: string); overload;
function TextExtent(const Text: string): TSize;
function TextHeight(const Text: string): Integer;
function TextWidth(const Text: string): Integer;
procedure RenderText(X, Y: Integer; const Text: string; AALevel: Integer; Color: TColor32);
property BitmapHandle: HBITMAP read FHandle;
property BitmapInfo: TBitmapInfo read FBitmapInfo;
property Bits: PColor32Array read FBits;
property Font: TFont read FFont write SetFont;
property Handle: HDC read FHDC;
property PenColor: TColor32 read FPenColor write FPenColor;
property Pixel[X, Y: Integer]: TColor32 read GetPixel write SetPixel; default;
property PixelS[X, Y: Integer]: TColor32 read GetPixelS write SetPixelS;
property PixelPtr[X, Y: Integer]: PColor32 read GetPixelPtr;
property ScanLine[Y: Integer]: PColor32Array read GetScanLine;
property StippleStep: Single read FStippleStep write SetStippleStep;
published
property DrawMode: TDrawMode read FDrawMode write SetDrawMode default dmOpaque;
property MasterAlpha: Byte read FMasterAlpha write SetMasterAlpha default $FF;
property OuterColor: TColor32 read FOuterColor write FOuterColor default 0;
property StretchFilter: TStretchFilter read FStretchFilter write SetStretchFilter default sfNearest;
property ResetAlphaOnAssign: Boolean read FResetAlphaOnAssign write FResetAlphaOnAssign default true;
property OnChanging;
property OnChange;
end;
TJclByteMap = class(TJclCustomMap)
private
FBytes: TDynByteArray;
FHeight: Integer;
FWidth: Integer;
function GetValue(X, Y: Integer): Byte;
function GetValPtr(X, Y: Integer): PByte;
procedure SetValue(X, Y: Integer; Value: Byte);
protected
procedure AssignTo(Dst: TPersistent); override;
public
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
function Empty: Boolean; override;
procedure Clear(FillValue: Byte);
procedure ReadFrom(Source: TJclBitmap32; Conversion: TConversionKind);
procedure SetSize(NewWidth, NewHeight: Integer); override;
procedure WriteTo(Dest: TJclBitmap32; Conversion: TConversionKind); overload;
procedure WriteTo(Dest: TJclBitmap32; const Palette: TPalette32); overload;
property Bytes: TDynByteArray read FBytes;
property ValPtr[X, Y: Integer]: PByte read GetValPtr;
property Value[X, Y: Integer]: Byte read GetValue write SetValue; default;
end;
{$ENDIF Bitmap32}
TJclTransformation = class(TObject)
public
function GetTransformedBounds(const Src: TRect): TRect; virtual; abstract;
procedure PrepareTransform; virtual; abstract;
procedure Transform(DstX, DstY: Integer; out SrcX, SrcY: Integer); virtual; abstract;
procedure Transform256(DstX, DstY: Integer; out SrcX256, SrcY256: Integer); virtual; abstract;
end;
TJclLinearTransformation = class(TJclTransformation)
private
FMatrix: TMatrix3d;
protected
A: Integer;
B: Integer;
C: Integer;
D: Integer;
E: Integer;
F: Integer;
public
constructor Create; virtual;
function GetTransformedBounds(const Src: TRect): TRect; override;
procedure PrepareTransform; override;
procedure Transform(DstX, DstY: Integer; out SrcX, SrcY: Integer); override;
procedure Transform256(DstX, DstY: Integer; out SrcX256, SrcY256: Integer); override;
procedure Clear;
procedure Rotate(Cx, Cy, Alpha: Extended); // degrees
procedure Skew(Fx, Fy: Extended);
procedure Scale(Sx, Sy: Extended);
procedure Translate(Dx, Dy: Extended);
property Matrix: TMatrix3d read FMatrix write FMatrix;
end;
// Bitmap Functions
procedure Stretch(NewWidth, NewHeight: Cardinal; Filter: TResamplingFilter;
Radius: Single; Source: TGraphic; Target: TBitmap); overload;
procedure Stretch(NewWidth, NewHeight: Cardinal; Filter: TResamplingFilter;
Radius: Single; Bitmap: TBitmap); overload;
{$IFDEF MSWINDOWS}
procedure DrawBitmap(DC: HDC; Bitmap: HBITMAP; X, Y, Width, Height: Integer);
function ExtractIconCount(const FileName: string): Integer;
function BitmapToIcon(Bitmap: HBITMAP; cx, cy: Integer): HICON; overload;
function BitmapToIcon(Bitmap, Mask: HBITMAP; cx, cy: Integer): HICON; overload;
function IconToBitmap(Icon: HICON): HBITMAP;
{$ENDIF MSWINDOWS}
{$IFDEF VCL}
procedure BitmapToJPeg(const FileName: string);
procedure JPegToBitmap(const FileName: string);
{$IFDEF HAS_UNIT_GIFIMG}
procedure BitmapToGif(const FileName: string);
procedure GifToBitmap(const FileName: string);
{$ENDIF HAS_UNIT_GIFIMG}
{$IFDEF HAS_UNIT_PNGIMAGE}
procedure BitmapToPng(const FileName: string);
procedure PngToBitmap(const FileName: string);
{$ENDIF HAS_UNIT_PNGIMAGE}
procedure SaveIconToFile(Icon: HICON; const FileName: string);
procedure WriteIcon(Stream: TStream; ColorBitmap, MaskBitmap: HBITMAP;
WriteLength: Boolean = False); overload;
procedure WriteIcon(Stream: TStream; Icon: HICON; WriteLength: Boolean = False); overload;
procedure GetIconFromBitmap(Icon: TIcon; Bitmap: TBitmap);
function GetAntialiasedBitmap(const Bitmap: TBitmap): TBitmap;
{$ENDIF VCL}
{$IFDEF Bitmap32}
procedure BlockTransfer(Dst: TJclBitmap32; DstX: Integer; DstY: Integer; Src: TJclBitmap32;
SrcRect: TRect; CombineOp: TDrawMode);
procedure StretchTransfer(Dst: TJclBitmap32; DstRect: TRect; Src: TJclBitmap32; SrcRect: TRect;
StretchFilter: TStretchFilter; CombineOp: TDrawMode);
procedure Transform(Dst, Src: TJclBitmap32; SrcRect: TRect; Transformation: TJclTransformation);
procedure SetBorderTransparent(ABitmap: TJclBitmap32; ARect: TRect);
{$ENDIF Bitmap32}
{$IFDEF MSWINDOWS}
function FillGradient(DC: HDC; ARect: TRect; ColorCount: Integer;
StartColor, EndColor: TColor; ADirection: TGradientDirection): Boolean; overload;
{$ENDIF MSWINDOWS}
{$IFDEF VCL}
function CreateRegionFromBitmap(Bitmap: TBitmap; RegionColor: TColor;
RegionBitmapMode: TJclRegionBitmapMode; UseAlphaChannel: Boolean = False): HRGN;
procedure ScreenShot(bm: TBitmap; Left, Top, Width, Height: Integer; Window: THandle = HWND_DESKTOP); overload;
procedure ScreenShot(bm: TBitmap; IncludeTaskBar: Boolean = True); overload;
procedure ScreenShot(bm: TBitmap; FormToPrint: TCustomForm); overload;
function MapWindowRect(hWndFrom, hWndTo: THandle; ARect: TRect):TRect;
{$ENDIF VCL}
{$IFDEF Bitmap32}
// PolyLines and Polygons
procedure PolyLineTS(Bitmap: TJclBitmap32; const Points: TDynPointArray; Color: TColor32);
procedure PolyLineAS(Bitmap: TJclBitmap32; const Points: TDynPointArray; Color: TColor32);
procedure PolyLineFS(Bitmap: TJclBitmap32; const Points: TDynPointArrayF; Color: TColor32);
procedure PolygonTS(Bitmap: TJclBitmap32; const Points: TDynPointArray; Color: TColor32);
procedure PolygonAS(Bitmap: TJclBitmap32; const Points: TDynPointArray; Color: TColor32);
procedure PolygonFS(Bitmap: TJclBitmap32; const Points: TDynPointArrayF; Color: TColor32);
procedure PolyPolygonTS(Bitmap: TJclBitmap32; const Points: TDynDynPointArrayArray;
Color: TColor32);
procedure PolyPolygonAS(Bitmap: TJclBitmap32; const Points: TDynDynPointArrayArray;
Color: TColor32);
procedure PolyPolygonFS(Bitmap: TJclBitmap32; const Points: TDynDynPointArrayArrayF;
Color: TColor32);
// Filters
procedure AlphaToGrayscale(Dst, Src: TJclBitmap32);
procedure IntensityToAlpha(Dst, Src: TJclBitmap32);
procedure Invert(Dst, Src: TJclBitmap32);
procedure InvertRGB(Dst, Src: TJclBitmap32);
procedure ColorToGrayscale(Dst, Src: TJclBitmap32);
procedure ApplyLUT(Dst, Src: TJclBitmap32; const LUT: TLUT8);
procedure SetGamma(Gamma: Single = 0.7);
{$ENDIF Bitmap32}
{$IFDEF UNITVERSIONING}
const
UnitVersioning: TUnitVersionInfo = (
RCSfile: '$URL$';
Revision: '$Revision$';
Date: '$Date$';
LogPath: 'JCL\source\vcl';
Extra: '';
Data: nil
);
{$ENDIF UNITVERSIONING}
implementation
uses
{$IFDEF HAS_UNITSCOPE}
System.Math,
Winapi.CommCtrl, Winapi.ShellApi,
{$IFDEF HAS_UNIT_GIFIMG}
Vcl.Imaging.GifImg,
{$ENDIF HAS_UNIT_GIFIMG}
{$IFDEF HAS_UNIT_PNGIMAGE}
Vcl.Imaging.PngImage,
{$ENDIF HAS_UNIT_PNGIMAGE}
Vcl.ClipBrd, Vcl.Imaging.JPeg, System.TypInfo,
{$ELSE ~HAS_UNITSCOPE}
Math,
CommCtrl, ShellApi,
{$IFDEF HAS_UNIT_GIFIMG}
GifImg,
{$ENDIF HAS_UNIT_GIFIMG}
{$IFDEF HAS_UNIT_PNGIMAGE}
PngImage,
{$ENDIF HAS_UNIT_PNGIMAGE}
ClipBrd, JPeg, TypInfo,
{$ENDIF ~HAS_UNITSCOPE}
JclVclResources,
JclSysUtils,
JclLogic;
type
PBGRAInt = ^TBGRAInt;
TBGRAInt = record
R: Integer;
G: Integer;
B: Integer;
A: Integer;
end;
PBGRA = ^TBGRA;
TBGRA = packed record
B: Byte;
G: Byte;
R: Byte;
A: Byte;
end;
TBitmapFilterFunction = function(Value: Single): Single;
PContributor = ^TContributor;
TContributor = record
Weight: Integer; // Pixel Weight
Pixel: Integer; // Source Pixel
end;
TContributors = array of TContributor;
// list of source pixels contributing to a destination pixel
PContributorEntry = ^TContributorEntry;
TContributorEntry = record
N: Integer;
Contributors: TContributors;
end;
TContributorList = array of TContributorEntry;
TJclGraphicAccess = class(TGraphic);
const
DefaultFilterRadius: array [TResamplingFilter] of Single =
(0.5, 1.0, 1.0, 1.5, 2.0, 3.0, 2.0);
_RGB: TColor32 = $00FFFFFF;
var
{ Gamma bias for line/pixel antialiasing/shape correction }
GAMMA_TABLE: TGamma;
type
TBGRAIntArray = array of TBGRAInt;
//=== Helper functions =======================================================
function IntToByte(Value: Integer): Byte; {$IFDEF SUPPORTS_INLINE} inline;{$ENDIF}
begin
Result := 255;
if Value >= 0 then
begin
if Value <= 255 then
Result := Value;
end
else
Result := 0;
end;
{$IFDEF Bitmap32}
procedure CheckBitmaps(Dst, Src: TJclBitmap32);
begin
if (Dst = nil) or Dst.Empty then
raise EJclGraphicsError.CreateRes(@RsDestinationBitmapEmpty);
if (Src = nil) or Src.Empty then
raise EJclGraphicsError.CreateRes(@RsSourceBitmapEmpty);
end;
function CheckSrcRect(Src: TJclBitmap32; const SrcRect: TRect): Boolean;
begin
Result := False;
if IsRectEmpty(SrcRect) then
Exit;
if (SrcRect.Left < 0) or (SrcRect.Right > Src.Width) or
(SrcRect.Top < 0) or (SrcRect.Bottom > Src.Height) then
raise EJclGraphicsError.CreateRes(@RsSourceBitmapInvalid);
Result := True;
end;
{$ENDIF Bitmap32}
//=== Internal low level routines ============================================
procedure FillLongword(var X; Count: Integer; Value: Longword);
var
P: PLongword;
begin
P := @X;
while Count > 0 do
begin
P^ := Value;
Inc(P);
Dec(Count);
end;
end;
function Clamp(Value: Integer): TColor32;
begin
if Value < 0 then
Result := 0
else
if Value > 255 then
Result := 255
else
Result := Value;
end;
procedure TestSwap(var A, B: Integer);
var
X: Integer;
begin
X := A; // optimization
if X > B then
begin
A := B;
B := X;
end;
end;
function TestClip(var A, B: Integer; Size: Integer): Boolean;
begin
TestSwap(A, B); // now A = min(A,B) and B = max(A, B)
if A < 0 then
A := 0;
if B >= Size then
B := Size - 1;
Result := B >= A;
end;
function Constrain(Value, Lo, Hi: Integer): Integer;
begin
if Value <= Lo then
Result := Lo
else
if Value >= Hi then
Result := Hi
else
Result := Value;
end;
// Filter functions for stretching of TBitmaps
// f(t) = 2|t|^3 - 3|t|^2 + 1, -1 <= t <= 1
function BitmapHermiteFilter(Value: Single): Single;
begin
if Value < 0.0 then
Value := -Value;
if Value < 1 then
Result := (2 * Value - 3) * Sqr(Value) + 1
else
Result := 0;
end;
// This filter is also known as 'nearest neighbour' Filter.
function BitmapBoxFilter(Value: Single): Single;
begin
if (Value > -0.5) and (Value <= 0.5) then
Result := 1.0
else
Result := 0.0;
end;
// aka 'linear' or 'bilinear' filter
function BitmapTriangleFilter(Value: Single): Single;
begin
if Value < 0.0 then
Value := -Value;
if Value < 1.0 then
Result := 1.0 - Value
else
Result := 0.0;
end;
function BitmapBellFilter(Value: Single): Single;
begin
if Value < 0.0 then
Value := -Value;
if Value < 0.5 then
Result := 0.75 - Sqr(Value)
else
if Value < 1.5 then
begin
Value := Value - 1.5;
Result := 0.5 * Sqr(Value);
end
else
Result := 0.0;
end;
// B-spline filter
function BitmapSplineFilter(Value: Single): Single;
var
Temp: Single;
begin
if Value < 0.0 then
Value := -Value;
if Value < 1.0 then
begin
Temp := Sqr(Value);
Result := 0.5 * Temp * Value - Temp + 2.0 / 3.0;
end
else
if Value < 2.0 then
begin
Value := 2.0 - Value;
Result := Sqr(Value) * Value / 6.0;
end
else
Result := 0.0;
end;
function BitmapLanczos3Filter(Value: Single): Single;
const
OneThird = 1.0 / 3.0;
function SinC(Value: Single): Single;
begin
if Value <> 0.0 then
begin
Value := Value * Pi;
Result := System.Sin(Value) / Value;
end
else
Result := 1.0;
end;
begin
if Value < 0.0 then
Value := -Value;
if Value < 3.0 then
Result := SinC(Value) * SinC(Value * OneThird)
else
Result := 0.0;
end;
function BitmapMitchellFilter(Value: Single): Single;
const
B = 1.0 / 3.0;
C = 1.0 / 3.0;
OneSixth = 1.0 / 6.0;
var
Temp: Single;
begin
if Value < 0.0 then
Value := -Value;
Temp := Sqr(Value);
if Value < 1.0 then
begin
Value := (((12.0 - 9.0 * B - 6.0 * C) * (Value * Temp)) +
((-18.0 + 12.0 * B + 6.0 * C) * Temp) +
(6.0 - 2.0 * B));
Result := Value * OneSixth;
end
else
if Value < 2.0 then
begin
Value := (((-B - 6.0 * C) * (Value * Temp)) +
((6.0 * B + 30.0 * C) * Temp) +
((-12.0 * B - 48.0 * C) * Value) +
(8.0 * B + 24.0 * C));
Result := Value * OneSixth;
end
else
Result := 0.0;
end;
const
FilterList: array [TResamplingFilter] of TBitmapFilterFunction =
(
BitmapBoxFilter,
BitmapTriangleFilter,
BitmapHermiteFilter,
BitmapBellFilter,
BitmapSplineFilter,
BitmapLanczos3Filter,
BitmapMitchellFilter
);
procedure FillLineCacheHorz(N: Integer; Line: Pointer; const ACurrentLine: TBGRAIntArray);
var
Run: PBGRA;
Data: PBGRAInt;
begin
Run := Line;
Data := @ACurrentLine[0];
Dec(N);
while N >= 0 do
begin
Data.B := Run.B;
Data.G := Run.G;
Data.R := Run.R;
Data.A := Run.A;
Inc(Run);
Inc(Data);
Dec(N);
end;
end;
procedure FillLineCacheVert(N, Delta: Integer; Line: Pointer; const ACurrentLine: TBGRAIntArray);
var
Run: PBGRA;
Data: PBGRAInt;
begin
Run := Line;
Data := @ACurrentLine[0];
Dec(N);
while N >= 0 do
begin
Data.B := Run.B;
Data.G := Run.G;
Data.R := Run.R;
Data.A := Run.A;
Inc(PByte(Run), Delta);
Inc(Data);
Dec(N);
end;
end;
function ApplyContributors(Contributor: PContributorEntry; const ACurrentLine: TBGRAIntArray): TBGRA;
var
J: Integer;
RGB: TBGRAInt;
Total, Weight: Integer;
Contr: PContributor;
Data: PBGRAInt;
begin
Total := 0;
RGB.B := Total; // trick compiler into generating better code
RGB.G := Total;
RGB.R := Total;
RGB.A := Total;
Contr := @Contributor.Contributors[0];
for J := 0 to Contributor.N - 1 do
begin
Weight := Contr.Weight;
Inc(Total, Weight);
Data := @ACurrentLine[Contr.Pixel];
Inc(RGB.R, Data.R * Weight);
Inc(RGB.G, Data.G * Weight);
Inc(RGB.B, Data.B * Weight);
Inc(RGB.A, Data.A * Weight);
Inc(Contr);
end;
if Total <> 0 then
begin
Result.B := IntToByte(RGB.B div Total);
Result.G := IntToByte(RGB.G div Total);
Result.R := IntToByte(RGB.R div Total);
Result.A := IntToByte(RGB.A div Total);
end
else
begin
Result.B := IntToByte(RGB.B shr 8);
Result.G := IntToByte(RGB.G shr 8);
Result.R := IntToByte(RGB.R shr 8);
Result.A := IntToByte(RGB.A shr 8);
end;
end;
// This is the actual scaling routine. Target must be allocated already with
// sufficient size. Source must contain valid data, Radius must not be 0 and
// Filter must not be nil.
procedure DoStretch(Filter: TBitmapFilterFunction; Radius: Single; Source, Target: TBitmap);
var
ScaleX, ScaleY: Single; // Zoom scale factors
I, J, K, N: Integer; // Loop variables
Center: Single; // Filter calculation variables
Width: Single;
Weight: Integer; // Filter calculation variables
Left, Right: Integer; // Filter calculation variables
Work: TBitmap;
ContributorList: TContributorList;
SourceLine, DestLine: PBGRA;
DestPixel: PBGRA;
Delta, DestDelta: Integer;
SourceHeight, SourceWidth: Integer;
TargetHeight, TargetWidth: Integer;
CurrentLine: TBGRAIntArray;
begin
// shortcut variables
SourceHeight := Source.Height;
SourceWidth := Source.Width;
TargetHeight := Target.Height;
TargetWidth := Target.Width;
// create intermediate image to hold horizontal zoom
Work := TBitmap.Create;
try
Work.PixelFormat := pf32bit;
Work.Height := SourceHeight;
Work.Width := TargetWidth;
if SourceWidth = 1 then
ScaleX := TargetWidth / SourceWidth
else
ScaleX := (TargetWidth - 1) / (SourceWidth - 1);
if SourceHeight = 1 then
ScaleY := TargetHeight / SourceHeight
else
ScaleY := (TargetHeight - 1) / (SourceHeight - 1);
// pre-calculate filter contributions for a row
SetLength(ContributorList, TargetWidth);
// horizontal sub-sampling
if ScaleX < 1 then
begin
// scales from bigger to smaller Width
Width := Radius / ScaleX;
for I := 0 to TargetWidth - 1 do
begin
ContributorList[I].N := 0;
Center := I / ScaleX;
Left := {$IFDEF HAS_UNITSCOPE}System.{$ENDIF}Math.Floor(Center - Width);
Right := {$IFDEF HAS_UNITSCOPE}System.{$ENDIF}Math.Ceil(Center + Width);
SetLength(ContributorList[I].Contributors, Right - Left + 1);
for J := Left to Right do
begin
Weight := Round(Filter((Center - J) * ScaleX) * ScaleX * 256);
if Weight <> 0 then
begin
if J < 0 then
N := -J
else
if J >= SourceWidth then
N := SourceWidth - J + SourceWidth - 1
else
N := J;
K := ContributorList[I].N;
Inc(ContributorList[I].N);
ContributorList[I].Contributors[K].Pixel := N;
ContributorList[I].Contributors[K].Weight := Weight;
end;
end;
end;
end
else
begin
// horizontal super-sampling
// scales from smaller to bigger Width
for I := 0 to TargetWidth - 1 do
begin
ContributorList[I].N := 0;
Center := I / ScaleX;
Left := {$IFDEF HAS_UNITSCOPE}System.{$ENDIF}Math.Floor(Center - Radius);
Right := {$IFDEF HAS_UNITSCOPE}System.{$ENDIF}Math.Ceil(Center + Radius);
SetLength(ContributorList[I].Contributors, Right - Left + 1);
for J := Left to Right do
begin
Weight := Round(Filter(Center - J) * 256);
if Weight <> 0 then
begin
if J < 0 then
N := -J
else
if J >= SourceWidth then
N := SourceWidth - J + SourceWidth - 1
else
N := J;
K := ContributorList[I].N;
Inc(ContributorList[I].N);
ContributorList[I].Contributors[K].Pixel := N;
ContributorList[I].Contributors[K].Weight := Weight;
end;
end;
end;
end;
if SourceWidth > SourceHeight then
SetLength(CurrentLine, SourceWidth)
else
SetLength(CurrentLine, SourceHeight);
// now apply filter to sample horizontally from Src to Work
for K := 0 to SourceHeight - 1 do
begin
SourceLine := Source.ScanLine[K];
FillLineCacheHorz(SourceWidth, SourceLine, CurrentLine);
DestPixel := Work.ScanLine[K];
for I := 0 to TargetWidth - 1 do
begin
DestPixel^ := ApplyContributors(@ContributorList[I], CurrentLine);
// move on to next column
Inc(DestPixel);
end;
end;
// free the memory allocated for horizontal filter weights, since we need
// the structure again
for I := 0 to TargetWidth - 1 do
ContributorList[I].Contributors := nil;
ContributorList := nil;
// pre-calculate filter contributions for a column
SetLength(ContributorList, TargetHeight);
// vertical sub-sampling
if ScaleY < 1 then
begin
// scales from bigger to smaller height
Width := Radius / ScaleY;
for I := 0 to TargetHeight - 1 do
begin
ContributorList[I].N := 0;
Center := I / ScaleY;
Left := {$IFDEF HAS_UNITSCOPE}System.{$ENDIF}Math.Floor(Center - Width);
Right := {$IFDEF HAS_UNITSCOPE}System.{$ENDIF}Math.Ceil(Center + Width);
SetLength(ContributorList[I].Contributors, Right - Left + 1);
for J := Left to Right do
begin
Weight := Round(Filter((Center - J) * ScaleY) * ScaleY * 256);
if Weight <> 0 then
begin
if J < 0 then
N := -J
else
if J >= SourceHeight then
N := SourceHeight - J + SourceHeight - 1
else
N := J;
K := ContributorList[I].N;
Inc(ContributorList[I].N);
ContributorList[I].Contributors[K].Pixel := N;
ContributorList[I].Contributors[K].Weight := Weight;
end;
end;
end;
end
else
begin
// vertical super-sampling
// scales from smaller to bigger height
for I := 0 to TargetHeight - 1 do
begin
ContributorList[I].N := 0;
Center := I / ScaleY;
Left := {$IFDEF HAS_UNITSCOPE}System.{$ENDIF}Math.Floor(Center - Radius);
Right := {$IFDEF HAS_UNITSCOPE}System.{$ENDIF}Math.Ceil(Center + Radius);
SetLength(ContributorList[I].Contributors, Right - Left + 1);
for J := Left to Right do
begin
Weight := Round(Filter(Center - J) * 256);
if Weight <> 0 then
begin
if J < 0 then
N := -J
else
if J >= SourceHeight then
N := SourceHeight - J + SourceHeight - 1
else
N := J;
K := ContributorList[I].N;
Inc(ContributorList[I].N);
ContributorList[I].Contributors[K].Pixel := N;
ContributorList[I].Contributors[K].Weight := Weight;
end;
end;
end;
end;
// apply filter to sample vertically from Work to Target
SourceLine := Work.ScanLine[0];
Delta := PAnsiChar(Work.ScanLine[1]) - PAnsiChar(SourceLine); // don't use TJclAddr here because of IntOverflow
DestLine := Target.ScanLine[0];
DestDelta := PAnsiChar(Target.ScanLine[1]) - PAnsiChar(DestLine); // don't use TJclAddr here because of IntOverflow
for K := 0 to TargetWidth - 1 do
begin
DestPixel := Pointer(DestLine);
FillLineCacheVert(SourceHeight, Delta, SourceLine, CurrentLine);
for I := 0 to TargetHeight - 1 do
begin
DestPixel^ := ApplyContributors(@ContributorList[I], CurrentLine);
// move on to next row
Inc(INT_PTR(DestPixel), DestDelta);
end;
Inc(SourceLine);
Inc(DestLine);
end;
// free the memory allocated for vertical filter weights
for I := 0 to TargetHeight - 1 do
ContributorList[I].Contributors := nil;
// this one is done automatically on exit, but is here for completeness
ContributorList := nil;
finally
Work.Free;
Target.Modified := True;
end;
end;
// Filter functions for TJclBitmap32
type
TPointRec = record
Pos: Integer;
Weight: Integer;
end;
TCluster = array of TPointRec;
TMappingTable = array of TCluster;
TFilterFunc = function(Value: Extended): Extended;
function NearestFilter(Value: Extended): Extended;
begin
if (Value > -0.5) and (Value <= 0.5) then
Result := 1
else
Result := 0;
end;
function LinearFilter(Value: Extended): Extended;
begin
if Value < -1 then
Result := 0
else
if Value < 0 then
Result := 1 + Value
else
if Value < 1 then
Result := 1 - Value
else
Result := 0;
end;
function SplineFilter(Value: Extended): Extended;
var
tt: Extended;
begin
Value := Abs(Value);
if Value < 1 then
begin
tt := Sqr(Value);
Result := 0.5 * tt * Value - tt + 2 / 3;
end
else
if Value < 2 then
begin
Value := 2 - Value;
Result := 1 / 6 * Sqr(Value) * Value;
end
else
Result := 0;
end;
function BuildMappingTable(DstWidth, SrcFrom, SrcWidth: Integer;
StretchFilter: TStretchFilter): TMappingTable;
const
FILTERS: array [TStretchFilter] of TFilterFunc =
(NearestFilter, LinearFilter, SplineFilter);
var
Filter: TFilterFunc;
FilterWidth: Extended;
Scale, OldScale: Extended;
Center: Extended;
Bias: Extended;
Left, Right: Integer;
I, J, K: Integer;
Weight: Integer;
begin
if SrcWidth = 0 then
begin
Result := nil;
Exit;
end;
Filter := FILTERS[StretchFilter];
if StretchFilter in [sfNearest, sfLinear] then
FilterWidth := 1
else
FilterWidth := 1.5;
SetLength(Result, DstWidth);
Scale := (DstWidth - 1) / (SrcWidth - 1);
if Scale < 1 then
begin
OldScale := Scale;
Scale := 1 / Scale;
FilterWidth := FilterWidth * Scale;
for I := 0 to DstWidth - 1 do
begin
Center := I * Scale;
Left := Floor(Center - FilterWidth);
Right := Ceil(Center + FilterWidth);
Bias := 0;
for J := Left to Right do
begin
Weight := Round(255 * Filter((Center - J) * OldScale) * OldScale);
if Weight <> 0 then
begin
Bias := Bias + Weight / 255;
K := Length(Result[I]);
SetLength(Result[I], K + 1);
Result[I][K].Pos := Constrain(J + SrcFrom, 0, SrcWidth - 1);
Result[I][K].Weight := Weight;
end;
end;
if (Bias > 0) and (Bias <> 1) then
begin
Bias := 1 / Bias;
for K := 0 to High(Result[I]) do
Result[I][K].Weight := Round(Result[I][K].Weight * Bias);
end;
end;
end
else
begin
FilterWidth := 1 / FilterWidth;
Scale := 1 / Scale;
for I := 0 to DstWidth - 1 do
begin
Center := I * Scale;
Left := Floor(Center - FilterWidth);
Right := Ceil(Center + FilterWidth);
for J := Left to Right do
begin
Weight := Round(255 * Filter(Center - J));
if Weight <> 0 then
begin
K := Length(Result[I]);
SetLength(Result[I], K + 1);
Result[I][K].Pos := Constrain(J + SrcFrom, 0, SrcWidth - 1);
Result[I][K].Weight := Weight;
end;
end;
end;
end;
end;
// Bitmap Functions
// Scales the source graphic to the given size (NewWidth, NewHeight) and stores the Result in Target.
// Filter describes the filter function to be applied and Radius the size of the filter area.
// Is Radius = 0 then the recommended filter area will be used (see DefaultFilterRadius).
procedure Stretch(NewWidth, NewHeight: Cardinal; Filter: TResamplingFilter;
Radius: Single; Source: TGraphic; Target: TBitmap);
var
Temp: TBitmap;
OriginalPixelFormat: TPixelFormat;
begin
if Source.Empty then
Exit; // do nothing
if Radius = 0 then
Radius := DefaultFilterRadius[Filter];
Temp := TBitmap.Create;
try
// To allow Source = Target, the following assignment needs to be done initially
Temp.Assign(Source);
Temp.PixelFormat := pf32bit;
OriginalPixelFormat := Target.PixelFormat; //Save format
Target.FreeImage;
Target.PixelFormat := pf32bit;
Target.Width := NewWidth;
Target.Height := NewHeight;
{$IFDEF VCL}if not Target.Empty then{$ENDIF VCL}
DoStretch(FilterList[Filter], Radius, Temp, Target);
Target.PixelFormat := OriginalPixelFormat; //Restore original PixelFormat
finally
Temp.Free;
end;
end;
procedure Stretch(NewWidth, NewHeight: Cardinal; Filter: TResamplingFilter;
Radius: Single; Bitmap: TBitmap);
begin
Stretch(NewWidth, NewHeight, Filter, Radius, Bitmap, Bitmap);
end;
{$IFDEF Bitmap32}
procedure StretchNearest(Dst: TJclBitmap32; DstRect: TRect;
Src: TJclBitmap32; SrcRect: TRect; CombineOp: TDrawMode);
var
SrcW, SrcH, DstW, DstH: Integer;
MapX, MapY: array of Integer;
DstX, DstY: Integer;
R: TRect;
I, J, Y: Integer;
P: PColor32;
MstrAlpha: TColor32;
begin
// check source and destination
CheckBitmaps(Dst, Src);
if not CheckSrcRect(Src, SrcRect) then
Exit;
if IsRectEmpty(DstRect) then
Exit;
IntersectRect(R, DstRect, Rect(0, 0, Dst.Width, Dst.Height));
if IsRectEmpty(R) then
Exit;
if (CombineOp = dmBlend) and (Src.MasterAlpha = 0) then
Exit;
SrcW := SrcRect.Right - SrcRect.Left;
SrcH := SrcRect.Bottom - SrcRect.Top;
DstW := DstRect.Right - DstRect.Left;
DstH := DstRect.Bottom - DstRect.Top;
DstX := DstRect.Left;
DstY := DstRect.Top;
// check if we actually have to stretch anything
if (SrcW = DstW) and (SrcH = DstH) then
begin
BlockTransfer(Dst, DstX, DstY, Src, SrcRect, CombineOp);
Exit;
end;
// build X coord mapping table
SetLength(MapX, DstW);
SetLength(MapY, DstH);
try
for I := 0 to DstW - 1 do
MapX[I] := I * (SrcW) div (DstW) + SrcRect.Left;
// build Y coord mapping table
for J := 0 to DstH - 1 do
MapY[J] := J * (SrcH) div (DstH) + SrcRect.Top;
// transfer pixels
case CombineOp of
dmOpaque:
for J := R.Top to R.Bottom - 1 do
begin
Y := MapY[J - DstY];
P := Dst.PixelPtr[R.Left, J];
for I := R.Left to R.Right - 1 do
begin
P^ := Src[MapX[I - DstX], Y];
Inc(P);
end;
end;
dmBlend:
begin
MstrAlpha := Src.MasterAlpha;
if MstrAlpha = 255 then
for J := R.Top to R.Bottom - 1 do
begin
Y := MapY[J - DstY];
P := Dst.PixelPtr[R.Left, J];
for I := R.Left to R.Right - 1 do
begin
BlendMem(Src[MapX[I - DstX], Y], P^);
Inc(P);
end;
end
else // Master Alpha is in [1..254] range
for J := R.Top to R.Bottom - 1 do
begin
Y := MapY[J - DstY];
P := Dst.PixelPtr[R.Left, J];
for I := R.Left to R.Right - 1 do
begin
BlendMemEx(Src[MapX[I - DstX], Y], P^, MstrAlpha);
Inc(P);
end;
end;
end;
end;
finally
EMMS;
MapX := nil;
MapY := nil;
end;
end;
procedure BlockTransfer(Dst: TJclBitmap32; DstX: Integer; DstY: Integer; Src: TJclBitmap32;
SrcRect: TRect; CombineOp: TDrawMode);
var
SrcX, SrcY: Integer;
S, D: TRect;
J, N: Integer;
Ps, Pd: PColor32;
MstrAlpha: TColor32;
begin
CheckBitmaps(Src, Dst);
if CombineOp = dmOpaque then
begin
BitBlt(Dst.Handle, DstX, DstY, SrcRect.Right - SrcRect.Left,
SrcRect.Bottom - SrcRect.Top, Src.Handle, SrcRect.Left, SrcRect.Top,
SRCCOPY);
Exit;
end;
if Src.MasterAlpha = 0 then
Exit;
// clip the rectangles with bitmap boundaries
SrcX := SrcRect.Left;
SrcY := SrcRect.Top;
IntersectRect(S, SrcRect, Rect(0, 0, Src.Width, Src.Height));
OffsetRect(S, DstX - SrcX, DstY - SrcY);
IntersectRect(D, S, Rect(0, 0, Dst.Width, Dst.Height));
if IsRectEmpty(D) then
Exit;
MstrAlpha := Src.MasterAlpha;
N := D.Right - D.Left;
try
if MstrAlpha = 255 then
for J := D.Top to D.Bottom - 1 do
begin
Ps := Src.PixelPtr[D.Left + SrcX - DstX, J + SrcY - DstY];
Pd := Dst.PixelPtr[D.Left, J];
BlendLine(Ps, Pd, N);
end
else
for J := D.Top to D.Bottom - 1 do
begin
Ps := Src.PixelPtr[D.Left + SrcX - DstX, J + SrcY - DstY];
Pd := Dst.PixelPtr[D.Left, J];
BlendLineEx(Ps, Pd, N, MstrAlpha);
end;
finally
EMMS;
end;
end;
procedure StretchTransfer(Dst: TJclBitmap32; DstRect: TRect; Src: TJclBitmap32; SrcRect: TRect;
StretchFilter: TStretchFilter; CombineOp: TDrawMode);
var
SrcW, SrcH, DstW, DstH: Integer;
MapX, MapY: TMappingTable;
DstX, DstY: Integer;
R: TRect;
I, J, X, Y: Integer;
P: PColor32;
ClusterX, ClusterY: TCluster;
C, Wt, Cr, Cg, Cb, Ca: Integer;
MstrAlpha: TColor32;
begin
// make compiler happy
MapX := nil;
MapY := nil;
ClusterX := nil;
ClusterY := nil;
if StretchFilter = sfNearest then
begin
StretchNearest(Dst, DstRect, Src, SrcRect, CombineOp);
Exit;
end;
// check source and destination
CheckBitmaps(Dst, Src);
if not CheckSrcRect(Src, SrcRect) then
Exit;
if IsRectEmpty(DstRect) then
Exit;
IntersectRect(R, DstRect, Rect(0, 0, Dst.Width, Dst.Height));
if IsRectEmpty(R) then
Exit;
if (CombineOp = dmBlend) and (Src.MasterAlpha = 0) then
Exit;
SrcW := SrcRect.Right - SrcRect.Left;
SrcH := SrcRect.Bottom - SrcRect.Top;
DstW := DstRect.Right - DstRect.Left;
DstH := DstRect.Bottom - DstRect.Top;
DstX := DstRect.Left;
DstY := DstRect.Top;
MstrAlpha := Src.MasterAlpha;
// check if we actually have to stretch anything
if (SrcW = DstW) and (SrcH = DstH) then
begin
BlockTransfer(Dst, DstX, DstY, Src, SrcRect, CombineOp);
Exit;
end;
// mapping tables
MapX := BuildMappingTable(DstW, SrcRect.Left, SrcW, StretchFilter);
MapY := BuildMappingTable(DstH, SrcRect.Top, SrcH, StretchFilter);
try
ClusterX := nil;
ClusterY := nil;
if (MapX = nil) or (MapY = nil) then
Exit;
// transfer pixels
for J := R.Top to R.Bottom - 1 do
begin
ClusterY := MapY[J - DstY];
P := Dst.PixelPtr[R.Left, J];
for I := R.Left to R.Right - 1 do
begin
ClusterX := MapX[I - DstX];
// reset color accumulators
Ca := 0;
Cr := 0;
Cg := 0;
Cb := 0;
// now iterate through each cluster
for Y := 0 to High(ClusterY) do
for X := 0 to High(ClusterX) do
begin
C := Src[ClusterX[X].Pos, ClusterY[Y].Pos];
Wt := ClusterX[X].Weight * ClusterY[Y].Weight;
Inc(Ca, C shr 24 * Wt);
Inc(Cr, (C and $00FF0000) shr 16 * Wt);
Inc(Cg, (C and $0000FF00) shr 8 * Wt);
Inc(Cb, (C and $000000FF) * Wt);
end;
Ca := Ca and $00FF0000;
Cr := Cr and $00FF0000;
Cg := Cg and $00FF0000;
Cb := Cb and $00FF0000;
C := (Ca shl 8) or Cr or (Cg shr 8) or (Cb shr 16);
// combine it with the background
case CombineOp of
dmOpaque:
P^ := C;
dmBlend:
BlendMemEx(C, P^, MstrAlpha);
end;
Inc(P);
end;
end;
finally
EMMS;
MapX := nil;
MapY := nil;
end;
end;
{$ENDIF Bitmap32}
{$IFDEF MSWINDOWS}
procedure DrawBitmap(DC: HDC; Bitmap: HBITMAP; X, Y, Width, Height: Integer);
var
MemDC: HDC;
OldBitmap: HBITMAP;
begin
MemDC := CreateCompatibleDC(DC);
OldBitmap := SelectObject(MemDC, Bitmap);
BitBlt(DC, X, Y, Width, Height, MemDC, 0, 0, SRCCOPY);
SelectObject(MemDC, OldBitmap);
DeleteObject(MemDC);
end;
{$ENDIF MSWINDOWS}
{$IFDEF VCL}
{ TODO : remove VCL-dependency by replacing pf24bit by pf32bit }
function GetAntialiasedBitmap(const Bitmap: TBitmap): TBitmap;
var
Antialias: TBitmap;
X, Y: Integer;
Line1, Line2, Line: PJclByteArray;
begin
Assert(Bitmap <> nil);
if Bitmap.PixelFormat <> pf24bit then
Bitmap.PixelFormat := pf24bit;
Antialias := TBitmap.Create;
with Bitmap do
begin
Antialias.PixelFormat := pf24bit;
Antialias.Width := Width div 2;
Antialias.Height := Height div 2;
for Y := 0 to Antialias.Height - 1 do
begin
Line1 := ScanLine[Y * 2];
Line2 := ScanLine[Y * 2 + 1];
Line := Antialias.ScanLine[Y];
for X := 0 to Antialias.Width - 1 do
begin
Line[X * 3] := (Integer(Line1[X * 6]) + Integer(Line2[X * 6]) +
Integer(Line1[X * 6 + 3]) + Integer(Line2[X * 6 + 3])) div 4;
Line[X * 3 + 1] := (Integer(Line1[X * 6 + 1]) + Integer(Line2[X * 6 + 1]) +
Integer(Line1[X * 6 + 3 + 1]) + Integer(Line2[X * 6 + 3 + 1])) div 4;
Line[X * 3 + 2] := (Integer(Line1[X * 6 + 2]) + Integer(Line2[X * 6 + 2]) +
Integer(Line1[X * 6 + 3 + 2]) + Integer(Line2[X * 6 + 3 + 2])) div 4;
end;
end;
end;
Result := Antialias;
end;
procedure ImgToBitmap(const FileName: string; GraphicClass: TGraphicClass);
var
Bitmap: TBitmap;
Img: TGraphic;
begin
Bitmap := nil;
Img := nil;
try
Img := GraphicClass.Create;
Img.LoadFromFile(FileName);
Bitmap := TBitmap.Create;
Bitmap.Assign(Img);
Bitmap.SaveToFile(ChangeFileExt(FileName, LoadResString(@RsBitmapExtension)));
finally
Bitmap.Free;
Img.Free;
end;
end;
procedure BitmapToImg(const FileName, FileExtension: string; GraphicClass: TGraphicClass);
var
Bitmap: TBitmap;
Img: TGraphic;
begin
Bitmap := nil;
Img := nil;
try
Bitmap := TBitmap.Create;
Bitmap.LoadFromFile(FileName);
Img := GraphicClass.Create;
Img.Assign(Bitmap);
Img.SaveToFile(ChangeFileExt(FileName, FileExtension));
finally
Bitmap.Free;
Img.Free;
end;
end;
procedure JPegToBitmap(const FileName: string);
begin
ImgToBitmap(FileName, TJPegImage);
end;
procedure BitmapToJPeg(const FileName: string);
begin
BitmapToImg(FileName, LoadResString(@RsJpegExtension), TJPEGImage);
end;
{$IFDEF HAS_UNIT_GIFIMG}
procedure GifToBitmap(const FileName: string);
begin
ImgToBitmap(FileName, TGifImage);
end;
procedure BitmapToGif(const FileName: string);
begin
BitmapToImg(FileName, LoadResString(@RsGifExtension), TGifImage);
end;
{$ENDIF HAS_UNIT_GIFIMG}
{$IFDEF HAS_UNIT_PNGIMAGE}
procedure PngToBitmap(const FileName: string);
begin
ImgToBitmap(FileName, TPngImage);
end;
procedure BitmapToPng(const FileName: string);
begin
BitmapToImg(FileName, LoadResString(@RsPngExtension), TPngImage);
end;
{$ENDIF HAS_UNIT_PNGIMAGE}
{$ENDIF VCL}
{$IFDEF MSWINDOWS}
function ExtractIconCount(const FileName: string): Integer;
begin
Result := ExtractIcon(HInstance, PChar(FileName), $FFFFFFFF);
end;
function BitmapToIcon(Bitmap: HBITMAP; cx, cy: Integer): HICON;
var
ImgList: HIMAGELIST;
I: Integer;
begin
ImgList := ImageList_Create(cx, cy, ILC_COLOR, 1, 1);
try
I := ImageList_Add(ImgList, Bitmap, 0);
Result := ImageList_GetIcon(ImgList, I, ILD_NORMAL);
finally
ImageList_Destroy(ImgList);
end;
end;
function BitmapToIcon(Bitmap, Mask: HBITMAP; cx, cy: Integer): HICON;
var
ImgList: HIMAGELIST;
I: Integer;
begin
ImgList := ImageList_Create(cx, cy, ILC_COLOR, 1, 1);
try
I := ImageList_Add(ImgList, Bitmap, Mask);
Result := ImageList_GetIcon(ImgList, I, ILD_TRANSPARENT);
finally
ImageList_Destroy(ImgList);
end;
end;
function IconToBitmap(Icon: HICON): HBITMAP;
var
IconInfo: TIconInfo;
begin
Result := 0;
if GetIconInfo(Icon, IconInfo) then
begin
DeleteObject(IconInfo.hbmMask);
Result := IconInfo.hbmColor;
end;
end;
{$ENDIF MSWINDOWS}
{$IFDEF VCL}
procedure GetIconFromBitmap(Icon: TIcon; Bitmap: TBitmap);
var
IconInfo: TIconInfo;
begin
with TBitmap.Create do
try
Assign(Bitmap);
if not Transparent then
TransparentColor := clNone;
IconInfo.fIcon := True;
IconInfo.hbmMask := MaskHandle;
IconInfo.hbmColor := Handle;
Icon.Handle := CreateIconIndirect(IconInfo);
finally
Free;
end;
end;
const
rc3_Icon = 1;
type
PCursorOrIcon = ^TCursorOrIcon;
TCursorOrIcon = packed record
Reserved: Word;
wType: Word;
Count: Word;
end;
PIconRec = ^TIconRec;
TIconRec = packed record
Width: Byte;
Height: Byte;
Colors: Word;
Reserved1: Word;
Reserved2: Word;
DIBSize: Longint;
DIBOffset: Longint;
end;
procedure WriteIcon(Stream: TStream; ColorBitmap, MaskBitmap: HBITMAP; WriteLength: Boolean = False);
var
MonoInfoSize, ColorInfoSize: DWORD;
MonoBitsSize, ColorBitsSize: DWORD;
MonoInfo, MonoBits, ColorInfo, ColorBits: Pointer;
CI: TCursorOrIcon;
List: TIconRec;
Length: Longint;
begin
ResetMemory(CI, SizeOf(CI));
ResetMemory(List, SizeOf(List));
GetDIBSizes(MaskBitmap, MonoInfoSize, MonoBitsSize);
GetDIBSizes(ColorBitmap, ColorInfoSize, ColorBitsSize);
MonoInfo := nil;
MonoBits := nil;
ColorInfo := nil;
ColorBits := nil;
try
MonoInfo := AllocMem(MonoInfoSize);
MonoBits := AllocMem(MonoBitsSize);
ColorInfo := AllocMem(ColorInfoSize);
ColorBits := AllocMem(ColorBitsSize);
GetDIB(MaskBitmap, 0, MonoInfo^, MonoBits^);
GetDIB(ColorBitmap, 0, ColorInfo^, ColorBits^);
if WriteLength then
begin
Length := SizeOf(CI) + SizeOf(List) + ColorInfoSize +
ColorBitsSize + MonoBitsSize;
Stream.Write(Length, SizeOf(Length));
end;
with CI do
begin
CI.wType := RC3_ICON;
CI.Count := 1;
end;
Stream.Write(CI, SizeOf(CI));
with List, PBitmapInfoHeader(ColorInfo)^ do
begin
Width := biWidth;
Height := biHeight;
Colors := biPlanes * biBitCount;
DIBSize := ColorInfoSize + ColorBitsSize + MonoBitsSize;
DIBOffset := SizeOf(CI) + SizeOf(List);
end;
Stream.Write(List, SizeOf(List));
with PBitmapInfoHeader(ColorInfo)^ do
Inc(biHeight, biHeight); { color height includes mono bits }
Stream.Write(ColorInfo^, ColorInfoSize);
Stream.Write(ColorBits^, ColorBitsSize);
Stream.Write(MonoBits^, MonoBitsSize);
finally
FreeMem(ColorInfo, ColorInfoSize);
FreeMem(ColorBits, ColorBitsSize);
FreeMem(MonoInfo, MonoInfoSize);
FreeMem(MonoBits, MonoBitsSize);
end;
end;
// WriteIcon depends on unit Graphics by use of GetDIBSizes and GetDIB
procedure WriteIcon(Stream: TStream; Icon: HICON; WriteLength: Boolean = False);
var
IconInfo: TIconInfo;
begin
if GetIconInfo(Icon, IconInfo) then
try
WriteIcon(Stream, IconInfo.hbmColor, IconInfo.hbmMask, WriteLength);
finally
DeleteObject(IconInfo.hbmColor);
DeleteObject(IconInfo.hbmMask);
end
else
RaiseLastOSError;
end;
procedure SaveIconToFile(Icon: HICON; const FileName: string);
var
Stream: TFileStream;
begin
Stream := TFileStream.Create(FileName, fmCreate);
try
WriteIcon(Stream, Icon, False);
finally
Stream.Free;
end;
end;
{$ENDIF VCL}
{$IFDEF Bitmap32}
procedure Transform(Dst, Src: TJclBitmap32; SrcRect: TRect;
Transformation: TJclTransformation);
var
SrcBlend: Boolean;
C, SrcAlpha: TColor32;
R, DstRect: TRect;
Pixels: PColor32Array;
I, J, X, Y: Integer;
function GET_S256(X, Y: Integer; out C: TColor32): Boolean;
var
flrx, flry, celx, cely: Longword;
C1, C2, C3, C4: TColor32;
P: PColor32;
begin
flrx := X and $FF;
flry := Y and $FF;
X := Sar(X,8);
Y := Sar(Y,8);
celx := flrx xor 255;
cely := flry xor 255;
if (X >= SrcRect.Left) and (X < SrcRect.Right - 1) and
(Y >= SrcRect.Top) and (Y < SrcRect.Bottom - 1) then
begin
// everything is ok take the four values and interpolate them
P := Src.PixelPtr[X, Y];
C1 := P^;
Inc(P);
C2 := P^;
Inc(P, Src.Width);
C4 := P^;
Dec(P);
C3 := P^;
C := CombineReg(CombineReg(C1, C2, celx), CombineReg(C3, C4, celx), cely);
Result := True;
end
else
begin
// (X,Y) coordinate is out of the SrcRect, do not interpolate
C := 0; // just write something to disable compiler warnings
Result := False;
end;
end;
begin
SrcBlend := (Src.DrawMode = dmBlend);
SrcAlpha := Src.MasterAlpha; // store it into a local variable
// clip SrcRect
R := SrcRect;
IntersectRect(SrcRect, R, Rect(0, 0, Src.Width, Src.Height));
if IsRectEmpty(SrcRect) then
Exit;
// clip DstRect
R := Transformation.GetTransformedBounds(SrcRect);
IntersectRect(DstRect, R, Rect(0, 0, Dst.Width, Dst.Height));
if IsRectEmpty(DstRect) then
Exit;
try
if Src.StretchFilter <> sfNearest then
for J := DstRect.Top to DstRect.Bottom - 1 do
begin
Pixels := Dst.ScanLine[J];
for I := DstRect.Left to DstRect.Right - 1 do
begin
Transformation.Transform256(I, J, X, Y);
if GET_S256(X, Y, C) then
if SrcBlend then
BlendMemEx(C, Pixels[I], SrcAlpha)
else
Pixels[I] := C;
end;
end
else // nearest filter
for J := DstRect.Top to DstRect.Bottom - 1 do
begin
Pixels := Dst.ScanLine[J];
for I := DstRect.Left to DstRect.Right - 1 do
begin
Transformation.Transform(I, J, X, Y);
if (X >= SrcRect.Left) and (X < SrcRect.Right) and
(Y >= SrcRect.Top) and (Y < SrcRect.Bottom) then
begin
if SrcBlend then
BlendMemEx(Src.Pixel[X, Y], Pixels[I], SrcAlpha)
else
Pixels[I] := Src.Pixel[X, Y];
end;
end;
end;
finally
EMMS;
end;
Dst.Changed;
end;
procedure SetBorderTransparent(ABitmap: TJclBitmap32; ARect: TRect);
var
I: Integer;
begin
if TestClip(ARect.Left, ARect.Right, ABitmap.Width) and
TestClip(ARect.Top, ARect.Bottom, ABitmap.Height) then
begin
ABitmap.Changing;
for I := ARect.Left to ARect.Right do
ABitmap[I, ARect.Top] := ABitmap[I, ARect.Top] and $00FFFFFF;
for I := ARect.Left to ARect.Right do
ABitmap[I, ARect.Bottom] := ABitmap[I, ARect.Bottom] and $00FFFFFF;
if ARect.Bottom > ARect.Top + 1 then
for I := ARect.Top + 1 to ARect.Bottom - 1 do
begin
ABitmap[ARect.Left, I] := ABitmap[ARect.Left, I] and $00FFFFFF;
ABitmap[ARect.Right, I] := ABitmap[ARect.Right, I] and $00FFFFFF;
end;
ABitmap.Changed;
end;
end;
{$ENDIF Bitmap32}
{$IFDEF VCL}
function CreateRegionFromBitmap(Bitmap: TBitmap; RegionColor: TColor;
RegionBitmapMode: TJclRegionBitmapMode; UseAlphaChannel: Boolean): HRGN;
var
LBitmap: TBitmap;
X, Y, Width: Integer;
StartX: Integer;
Region: HRGN;
P: PBGRA;
Mask: TColor;
begin
Result := 0;
if Bitmap = nil then
EJclGraphicsError.CreateRes(@RsNoBitmapForRegion);
if (Bitmap.Width = 0) or (Bitmap.Height = 0) then
Exit;
if UseAlphaChannel then
begin
Mask := TColor($FF000000);
// A region can represent only full transparent alpha values
RegionColor := 0;
end
else
begin
Mask := TColor($00FFFFFF);
RegionColor := ColorToRGB(RegionColor);
end;
LBitmap := TBitmap.Create;
try
LBitmap.Assign(Bitmap);
LBitmap.PixelFormat := pf32bit;
Width := LBitmap.Width;
for Y := 0 to LBitmap.Height - 1 do
begin
P := LBitmap.ScanLine[Y];
X := 0;
while X < Width do
begin
if RegionBitmapMode = rmExclude then
begin
while (TColor(P^) and Mask) = RegionColor do
begin
Inc(X);
Inc(P);
if X = Width then
Break;
end;
end
else
begin
while (TColor(P^) and Mask) <> RegionColor do
begin
Inc(X);
Inc(P);
if X = Width then
Break;
end;
end;
if X = Width then
Break;
StartX := X;
if RegionBitmapMode = rmExclude then
begin
while (X < Width) and ((TColor(P^) and Mask) <> RegionColor) do
begin
Inc(X);
Inc(P);
end;
end
else
begin
while (X < Width) and ((TColor(P^) and Mask) = RegionColor) do
begin
Inc(X);
Inc(P);
end;
end;
Region := CreateRectRgn(StartX, Y, X, Y + 1);
if Result = 0 then
Result := Region
else
begin
if Region <> 0 then
begin
CombineRgn(Result, Result, Region, RGN_OR);
DeleteObject(Region);
end;
end;
end;
end;
finally
LBitmap.Free;
end;
end;
procedure ScreenShot(bm: TBitmap; Left, Top, Width, Height: Integer; Window: THandle); overload;
var
WinDC: HDC;
Pal: TMaxLogPalette;
begin
bm.Width := Width;
bm.Height := Height;
// Get the HDC of the window...
WinDC := GetDC(Window);
if WinDC = 0 then
raise EJclGraphicsError.CreateRes(@RsNoDeviceContextForWindow);
try
// Palette-device?
if (GetDeviceCaps(WinDC, RASTERCAPS) and RC_PALETTE) = RC_PALETTE then
begin
ResetMemory(Pal, SizeOf(TMaxLogPalette)); // fill the structure with zeros
Pal.palVersion := $300; // fill in the palette version
// grab the system palette entries...
Pal.palNumEntries := GetSystemPaletteEntries(WinDC, 0, 256, Pal.palPalEntry);
if Pal.PalNumEntries <> 0 then
bm.Palette := CreatePalette(PLogPalette(@Pal)^);
end;
// copy from the screen to our bitmap...
BitBlt(bm.Canvas.Handle, 0, 0, Width, Height, WinDC, Left, Top, SRCCOPY);
finally
ReleaseDC(Window, WinDC); // finally, relase the DC of the window
end;
end;
procedure ScreenShot(bm: TBitmap; IncludeTaskBar: Boolean = True); overload;
var
R: TRect;
begin
if IncludeTaskBar then
begin
R.Left := 0;
R.Top := 0;
R.Right := GetSystemMetrics(SM_CXSCREEN);
R.Bottom := GetSystemMetrics(SM_CYSCREEN);
end
else
SystemParametersInfo(SPI_GETWORKAREA, 0, @R, 0);
ScreenShot(bm, R.Left, R.Top, R.Right, R.Bottom, HWND_DESKTOP);
end;
procedure ScreenShot(bm: TBitmap; FormToPrint: TCustomForm); overload;
begin
//Prints the entire forms area.
if FormToPrint <> nil then
ScreenShot(bm, FormToPrint.Left, FormToPrint.Top, FormToPrint.Width, FormToPrint.Height, FormToPrint.Handle)
else
raise EJclGraphicsError.CreateResFmt(@RSInvalidFormOrComponent, ['form'])
end;
function MapWindowRect(hWndFrom, hWndTo: THandle; ARect:TRect):TRect;
begin
MapWindowPoints(hWndFrom, hWndTo, ARect, 2);
Result := ARect;
end;
{$ENDIF VCL}
{$IFDEF MSWINDOWS}
function FillGradient(DC: HDC; ARect: TRect; ColorCount: Integer;
StartColor, EndColor: TColor; ADirection: TGradientDirection): Boolean;
var
StartRGB: array [0..2] of Byte;
RGBKoef: array [0..2] of Double;
Brush: HBRUSH;
AreaWidth, AreaHeight, I: Integer;
ColorRect: TRect;
RectOffset: Double;
begin
RectOffset := 0;
Result := False;
if ColorCount < 1 then
Exit;
StartColor := ColorToRGB(StartColor);
EndColor := ColorToRGB(EndColor);
StartRGB[0] := GetRValue(StartColor);
StartRGB[1] := GetGValue(StartColor);
StartRGB[2] := GetBValue(StartColor);
RGBKoef[0] := (GetRValue(EndColor) - StartRGB[0]) / ColorCount;
RGBKoef[1] := (GetGValue(EndColor) - StartRGB[1]) / ColorCount;
RGBKoef[2] := (GetBValue(EndColor) - StartRGB[2]) / ColorCount;
AreaWidth := ARect.Right - ARect.Left;
AreaHeight := ARect.Bottom - ARect.Top;
case ADirection of
gdHorizontal:
RectOffset := AreaWidth / ColorCount;
gdVertical:
RectOffset := AreaHeight / ColorCount;
end;
for I := 0 to ColorCount - 1 do
begin
Brush := CreateSolidBrush(RGB(
StartRGB[0] + Round((I + 1) * RGBKoef[0]),
StartRGB[1] + Round((I + 1) * RGBKoef[1]),
StartRGB[2] + Round((I + 1) * RGBKoef[2])));
case ADirection of
gdHorizontal:
SetRect(ColorRect, Round(RectOffset * I), 0, Round(RectOffset * (I + 1)), AreaHeight);
gdVertical:
SetRect(ColorRect, 0, Round(RectOffset * I), AreaWidth, Round(RectOffset * (I + 1)));
end;
OffsetRect(ColorRect, ARect.Left, ARect.Top);
FillRect(DC, ColorRect, Brush);
DeleteObject(Brush);
end;
Result := True;
end;
{$ENDIF MSWINDOWS}
{$IFDEF VCL}
//=== { TJclDesktopCanvas } ==================================================
constructor TJclDesktopCanvas.Create;
begin
inherited Create;
FDesktop := GetDC(HWND_DESKTOP);
Handle := FDesktop;
end;
destructor TJclDesktopCanvas.Destroy;
begin
Handle := 0;
ReleaseDC(HWND_DESKTOP, FDesktop);
inherited Destroy;
end;
//=== { TJclRegionInfo } =====================================================
constructor TJclRegionInfo.Create(Region: TJclRegion);
begin
inherited Create;
if Region = nil then
raise EJclGraphicsError.CreateRes(@RsInvalidRegion);
FData := nil;
FDataSize := GetRegionData(Region.Handle, 0, nil);
GetMem(FData, FDataSize);
GetRegionData(Region.Handle, FDataSize, FData);
end;
destructor TJclRegionInfo.Destroy;
begin
if FData <> nil then
FreeMem(FData);
inherited Destroy;
end;
function TJclRegionInfo.GetBox: TRect;
begin
Result := RectAssign(TRgnData(FData^).rdh.rcBound.Left, TRgnData(FData^).rdh.rcBound.Top,
TRgnData(FData^).rdh.rcBound.Right, TRgnData(FData^).rdh.rcBound.Bottom);
end;
function TJclRegionInfo.GetCount: Integer;
begin
Result := TRgnData(FData^).rdh.nCount;
end;
function TJclRegionInfo.GetRect(Index: Integer): TRect;
var
RectP: PRect;
begin
if (Index < 0) or (DWORD(Index) >= TRgnData(FData^).rdh.nCount) then
raise EJclGraphicsError.CreateRes(@RsRegionDataOutOfBound);
RectP := PRect(PAnsiChar(@TRgnData(FData^).Buffer) + (SizeOf(TRect)*Index));
Result := RectAssign(RectP^.Left, RectP.Top, RectP^.Right, RectP^.Bottom);
end;
//=== { TJclRegion } =========================================================
constructor TJclRegion.Create(RegionHandle: HRGN; OwnsHandle: Boolean = True);
begin
inherited Create;
FHandle := RegionHandle;
FOwnsHandle := OwnsHandle;
CheckHandle;
GetBox;
end;
constructor TJclRegion.CreateBitmap(Bitmap: TBitmap; RegionColor: TColor;
RegionBitmapMode: TJclRegionBitmapMode);
begin
Create(CreateRegionFromBitmap(Bitmap, RegionColor, RegionBitmapMode), True);
end;
constructor TJclRegion.CreateElliptic(const ARect: TRect);
begin
Create(CreateEllipticRgnIndirect(ARect), True);
end;
constructor TJclRegion.CreateElliptic(const Top, Left, Bottom, Right: Integer);
begin
Create(CreateEllipticRgn(Top, Left, Bottom, Right), True);
end;
constructor TJclRegion.CreatePoly(const Points: TDynPointArray; Count: Integer;
FillMode: TPolyFillMode);
begin
case FillMode of
fmAlternate:
Create(CreatePolygonRgn(Points[0], Count, ALTERNATE), True);
fmWinding:
Create(CreatePolygonRgn(Points[0], Count, WINDING), True);
end;
end;
constructor TJclRegion.CreatePolyPolygon(const Points: TDynPointArray;
const Vertex: TDynIntegerArray; Count: Integer; FillMode: TPolyFillMode);
begin
case FillMode of
fmAlternate:
Create(CreatePolyPolygonRgn(Points[0], Vertex[0], Count, ALTERNATE), True);
fmWinding:
Create(CreatePolyPolygonRgn(Points[0], Vertex[0], Count, WINDING), True);
end;
end;
constructor TJclRegion.CreateRect(const ARect: TRect; DummyForBCB: Boolean = False);
begin
Create(CreateRectRgnIndirect(ARect), True);
end;
constructor TJclRegion.CreateRect(const Top, Left, Bottom, Right: Integer; DummyForBCB: Byte = 0);
begin
Create(CreateRectRgn(Top, Left, Bottom, Right), True);
end;
constructor TJclRegion.CreateRoundRect(const ARect: TRect; CornerWidth,
CornerHeight: Integer);
begin
Create(CreateRoundRectRgn(ARect.Top, ARect.Left, ARect.Bottom, ARect.Right,
CornerWidth, CornerHeight), True);
end;
constructor TJclRegion.CreateRoundRect(const Top, Left, Bottom, Right, CornerWidth,
CornerHeight: Integer);
begin
Create(CreateRoundRectRgn(Top, Left, Bottom, Right, CornerWidth, CornerHeight), True);
end;
constructor TJclRegion.CreatePath(Canvas: TCanvas);
begin
Create(PathToRegion(Canvas.Handle), True);
end;
constructor TJclRegion.CreateRegionInfo(RegionInfo: TJclRegionInfo);
begin
if RegionInfo = nil then
raise EJclGraphicsError.CreateRes(@RsInvalidRegionInfo);
Create(ExtCreateRegion(nil,RegionInfo.FDataSize,TRgnData(RegionInfo.FData^)), True);
end;
constructor TJclRegion.CreateMapWindow(InitialRegion: TJclRegion; hWndFrom, hWndTo: THandle);
var
RectRegion: HRGN;
CurrentRegionInfo : TJclRegionInfo;
SimpleRect: TRect;
Index:integer;
begin
Create(CreateRectRgn(0, 0, 0, 0), True);
if (hWndFrom <> 0) or (hWndTo <> 0 ) then
begin
CurrentRegionInfo := InitialRegion.GetRegionInfo;
try
for Index := 0 to CurrentRegionInfo.Count-1 do
begin
SimpleRect := CurrentRegionInfo.Rectangles[Index];
SimpleRect := MapWindowRect(hWndFrom,hWndTo,SimpleRect);
RectRegion := CreateRectRgnIndirect(SimpleRect);
if RectRegion <> 0 then
begin
CombineRgn(Handle, Handle, RectRegion, RGN_OR);
DeleteObject(RectRegion);
end;
end;
finally
CurrentRegionInfo.Free;
GetBox;
end;
end;
end;
constructor TJclRegion.CreateMapWindow(InitialRegion: TJclRegion;
ControlFrom, ControlTo: TWinControl);
begin
CreateMapWindow(InitialRegion,ControlFrom.Handle,ControlTo.Handle);
end;
destructor TJclRegion.Destroy;
begin
if FOwnsHandle and (FHandle <> 0) then
DeleteObject(FHandle);
inherited Destroy;
end;
procedure TJclRegion.CheckHandle;
begin
if FHandle = 0 then
begin
if FOwnsHandle then
raise EJclGraphicsError.CreateRes(@RsRegionCouldNotCreated)
else
raise EJclGraphicsError.CreateRes(@RsInvalidHandleForRegion);
end;
end;
procedure TJclRegion.Combine(DestRegion, SrcRegion: TJclRegion;
CombineOp: TJclRegionCombineOperator);
begin
case CombineOp of
coAnd:
FRegionType := CombineRgn(DestRegion.Handle, SrcRegion.Handle, FHandle, RGN_AND);
coOr:
FRegionType := CombineRgn(DestRegion.Handle, SrcRegion.Handle, FHandle, RGN_OR);
coDiff:
FRegionType := CombineRgn(DestRegion.Handle, SrcRegion.Handle, FHandle, RGN_DIFF);
coXor:
FRegionType := CombineRgn(DestRegion.Handle, SrcRegion.Handle, FHandle, RGN_XOR);
end;
end;
procedure TJclRegion.Combine(SrcRegion: TJclRegion; CombineOp: TJclRegionCombineOperator);
begin
case CombineOp of
coAnd:
FRegionType := CombineRgn(FHandle, SrcRegion.Handle, FHandle, RGN_AND);
coOr:
FRegionType := CombineRgn(FHandle, SrcRegion.Handle, FHandle, RGN_OR);
coDiff:
FRegionType := CombineRgn(FHandle, SrcRegion.Handle, FHandle, RGN_DIFF);
coXor:
FRegionType := CombineRgn(FHandle, SrcRegion.Handle, FHandle, RGN_XOR);
end;
end;
procedure TJclRegion.Clip(Canvas: TCanvas);
begin
FRegionType := SelectClipRgn(Canvas.Handle, FHandle);
end;
function TJclRegion.Equals(CompareRegion: TJclRegion): Boolean;
begin
Result := EqualRgn(CompareRegion.Handle, FHandle);
end;
function TJclRegion.GetHandle: HRGN;
begin
Result := FHandle;
end;
procedure TJclRegion.Fill(Canvas: TCanvas);
begin
FillRgn(Canvas.Handle, FHandle, Canvas.Brush.Handle);
end;
procedure TJclRegion.FillGradient(Canvas: TCanvas; ColorCount: Integer;
StartColor, EndColor: TColor; ADirection: TGradientDirection);
var
DC: integer;
begin
DC := SaveDC(Canvas.Handle);
try
SelectClipRgn(Canvas.Handle,FHandle);
{$IFDEF VCL}JclGraphics.{$ENDIF}FillGradient(Canvas.Handle, Box, ColorCount, StartColor, EndColor, ADirection);
finally
RestoreDC(Canvas.Handle, DC);
end;
end;
procedure TJclRegion.Frame(Canvas: TCanvas; FrameWidth, FrameHeight: Integer);
begin
FrameRgn(Canvas.Handle, FHandle, Canvas.Brush.Handle, FrameWidth, FrameHeight);
end;
function TJclRegion.GetBox: TRect;
begin
FRegionType := GetRgnBox(FHandle, FBoxRect);
Result := FBoxRect;
end;
function TJclRegion.GetRegionType: TJclRegionKind;
begin
case FRegionType of
NULLREGION:
Result := rkNull;
SIMPLEREGION:
Result := rkSimple;
COMPLEXREGION:
Result := rkComplex;
else
Result := rkError;
end;
end;
procedure TJclRegion.Invert(Canvas: TCanvas);
begin
InvertRgn(Canvas.Handle, FHandle);
end;
procedure TJclRegion.Offset(X, Y: Integer);
begin
FRegionType := OffsetRgn(FHandle, X, Y);
end;
procedure TJclRegion.Paint(Canvas: TCanvas);
begin
PaintRgn(Canvas.Handle, FHandle);
end;
function TJclRegion.PointIn(X, Y: Integer): Boolean;
begin
Result := PtInRegion(FHandle, X, Y);
end;
function TJclRegion.PointIn(const Point: TPoint): Boolean;
begin
Result := PtInRegion(FHandle, Point.X, Point.Y);
end;
function TJclRegion.RectIn(const ARect: TRect): Boolean;
begin
Result := RectInRegion(FHandle, ARect);
end;
function TJclRegion.RectIn(Top, Left, Bottom, Right: Integer): Boolean;
begin
Result := RectInRegion(FHandle, RectAssign(Left, Top, Right, Bottom));
end;
{ Documentation Info (from MSDN): After a successful call to SetWindowRgn, the system owns
the region specified by the region handle hRgn. The system does
not make a copy of the region. Thus, you should not make any
further function calls with this region handle. In particular,
do not delete this region handle. The system deletes the region
handle when it no longer needed. }
procedure TJclRegion.SetWindow(Window: THandle; Redraw: Boolean);
begin
if SetWindowRgn(Window, FHandle, Redraw) <> 0 then
FOwnsHandle := False; // Make sure that we do not release the Handle. If we didn't own it before
// please take care that the owner doesn't release it.
end;
function TJclRegion.Copy: TJclRegion;
begin
Result := TJclRegion.CreateRect(0, 0, 0, 0, 0); // (rom) call correct overloaded constructor for BCB
CombineRgn(Result.Handle, FHandle, 0, RGN_COPY);
Result.GetBox;
end;
function TJclRegion.GetRegionInfo: TJclRegionInfo;
begin
Result := TJclRegionInfo.Create(Self);
end;
{$ENDIF VCL}
{$IFDEF Bitmap32}
//=== { TJclThreadPersistent } ===============================================
constructor TJclThreadPersistent.Create;
begin
inherited Create;
{$IFDEF VCL}
InitializeCriticalSection(FLock);
{$ELSE ~VCL}
FLock := TCriticalSection.Create;
{$ENDIF ~VCL}
end;
destructor TJclThreadPersistent.Destroy;
begin
{$IFDEF VCL}
DeleteCriticalSection(FLock);
{$ELSE ~VCL}
FLock.Free;
{$ENDIF ~VCL}
inherited Destroy;
end;
procedure TJclThreadPersistent.BeginUpdate;
begin
Inc(FUpdateCount);
end;
procedure TJclThreadPersistent.Changing;
begin
if (FUpdateCount = 0) and Assigned(FOnChanging) then
FOnChanging(Self);
end;
procedure TJclThreadPersistent.Changed;
begin
if (FUpdateCount = 0) and Assigned(FOnChange) then
FOnChange(Self);
end;
procedure TJclThreadPersistent.EndUpdate;
begin
Assert(FUpdateCount > 0, LoadResString(@RsAssertUnpairedEndUpdate));
Dec(FUpdateCount);
end;
procedure TJclThreadPersistent.Lock;
begin
InterlockedIncrement(FLockCount);
{$IFDEF VCL}
EnterCriticalSection(FLock);
{$ELSE ~VCL}
FLock.Enter;
{$ENDIF ~VCL}
end;
procedure TJclThreadPersistent.Unlock;
begin
{$IFDEF VCL}
LeaveCriticalSection(FLock);
{$ELSE ~VCL}
FLock.Leave;
{$ENDIF ~VCL}
InterlockedDecrement(FLockCount);
end;
//=== { TJclCustomMap } ======================================================
procedure TJclCustomMap.Delete;
begin
SetSize(0, 0);
end;
function TJclCustomMap.Empty: Boolean;
begin
Result := (Width = 0) or (Height = 0);
end;
procedure TJclCustomMap.SetHeight(NewHeight: Integer);
begin
SetSize(Width, NewHeight);
end;
procedure TJclCustomMap.SetSize(NewWidth, NewHeight: Integer);
begin
FWidth := NewWidth;
FHeight := NewHeight;
end;
procedure TJclCustomMap.SetSize(Source: TPersistent);
var
WidthInfo, HeightInfo: PPropInfo;
begin
if Source is TJclCustomMap then
SetSize(TJclCustomMap(Source).Width, TJclCustomMap(Source).Height)
else
if Source is TGraphic then
SetSize(TGraphic(Source).Width, TGraphic(Source).Height)
else
if Source = nil then
SetSize(0, 0)
else
begin
WidthInfo := GetPropInfo(Source, 'Width', [tkInteger]);
HeightInfo := GetPropInfo(Source, 'Height', [tkInteger]);
if Assigned(WidthInfo) and Assigned(HeightInfo) then
SetSize(GetOrdProp(Source, WidthInfo), GetOrdProp(Source, HeightInfo))
else
raise EJclGraphicsError.CreateResFmt(@RsMapSizeFmt,[Source.ClassName]);
end;
end;
procedure TJclCustomMap.SetWidth(NewWidth: Integer);
begin
SetSize(NewWidth, Height);
end;
//=== { TJclBitmap32 } =======================================================
constructor TJclBitmap32.Create;
begin
inherited Create;
FResetAlphaOnAssign := True;
ResetMemory(FBitmapInfo, SizeOf(TBitmapInfo));
with FBitmapInfo.bmiHeader do
begin
biSize := SizeOf(TBitmapInfoHeader);
biPlanes := 1;
biBitCount := 32;
biCompression := BI_RGB;
end;
FOuterColor := $00000000; // by default as full transparency black
FFont := TFont.Create;
FFont.OnChange := FontChanged;
{$IFDEF VCL}
FFont.OwnerCriticalSection := @FLock;
{$ENDIF VCL}
FMasterAlpha := $FF;
FPenColor := clWhite32;
FStippleStep := 1;
end;
destructor TJclBitmap32.Destroy;
begin
Lock;
try
FFont.Free;
SetSize(0, 0);
finally
Unlock;
end;
inherited Destroy;
end;
procedure TJclBitmap32.SetSize(NewWidth, NewHeight: Integer);
begin
if NewWidth <= 0 then
NewWidth := 0;
if NewHeight <= 0 then
NewHeight := 0;
if (NewWidth = Width) and (NewHeight = Height) then
Exit;
Changing;
try
if FHDC <> 0 then
DeleteDC(FHDC);
if FHandle <> 0 then
DeleteObject(FHandle);
FBits := nil;
FWidth := 0;
FHeight := 0;
if (NewWidth > 0) and (NewHeight > 0) then
begin
with FBitmapInfo.bmiHeader do
begin
biWidth := NewWidth;
biHeight := -NewHeight;
end;
FHandle := CreateDIBSection(0, FBitmapInfo, DIB_RGB_COLORS, Pointer(FBits), 0, 0);
if FBits = nil then
raise EJclGraphicsError.CreateRes(@RsDibHandleAllocation);
FHDC := CreateCompatibleDC(0);
if FHDC = 0 then
begin
DeleteObject(FHandle);
FHandle := 0;
FBits := nil;
raise EJclGraphicsError.CreateRes(@RsCreateCompatibleDc);
end;
if SelectObject(FHDC, FHandle) = 0 then
begin
DeleteDC(FHDC);
DeleteObject(FHandle);
FHDC := 0;
FHandle := 0;
FBits := nil;
raise EJclGraphicsError.CreateRes(@RsSelectObjectInDc);
end;
FWidth := NewWidth;
FHeight := NewHeight;
end;
finally
Changed;
end;
end;
function TJclBitmap32.Empty: Boolean;
begin
Result := (FHandle = 0);
end;
procedure TJclBitmap32.Clear;
begin
Clear(clBlack32);
end;
procedure TJclBitmap32.Clear(FillColor: TColor32);
begin
if Empty then
Exit;
Changing;
FillLongword(Bits[0], Width * Height, FillColor);
Changed;
end;
procedure TJclBitmap32.Delete;
begin
Changing;
SetSize(0, 0);
Changed;
end;
procedure TJclBitmap32.Assign(Source: TPersistent);
var
Canvas: TCanvas;
Picture: TPicture;
procedure AssignFromBitmap(SrcBmp: TBitmap);
begin
SetSize(SrcBmp.Width, SrcBmp.Height);
if Empty then
Exit;
BitBlt(Handle, 0, 0, Width, Height, SrcBmp.Canvas.Handle, 0, 0, SRCCOPY);
if ResetAlphaOnAssign then
ResetAlpha;
end;
begin
Changing;
BeginUpdate;
try
if Source = nil then
begin
SetSize(0, 0);
Exit;
end
else
if Source is TJclBitmap32 then
begin
SetSize(TJclBitmap32(Source).Width, TJclBitmap32(Source).Height);
Move(TJclBitmap32(Source).Bits[0], Bits[0], Width * Height * 4);
Exit;
end
else
if Source is TBitmap then
begin
AssignFromBitmap(TBitmap(Source));
Exit;
end
else
if Source is TPicture then
begin
with TPicture(Source) do
begin
if TPicture(Source).Graphic is TBitmap then
AssignFromBitmap(TBitmap(TPicture(Source).Graphic))
else
begin
// icons, metafiles etc...
SetSize(TPicture(Source).Graphic.Width, TPicture(Source).Graphic.Height);
if Empty then
Exit;
Canvas := TCanvas.Create;
try
Canvas.Handle := Self.Handle;
TJclGraphicAccess(Graphic).Draw(Canvas, Rect(0, 0, Width, Height));
if ResetAlphaOnAssign then
ResetAlpha;
finally
Canvas.Free;
end;
end;
end;
Exit;
end
else
if Source is TClipboard then
begin
Picture := TPicture.Create;
try
Picture.Assign(TClipboard(Source));
SetSize(Picture.Width, Picture.Height);
if Empty then
Exit;
Canvas := TCanvas.Create;
try
Canvas.Handle := Self.Handle;
TJclGraphicAccess(Picture.Graphic).Draw(Canvas, Rect(0, 0, Width, Height));
if ResetAlphaOnAssign then
ResetAlpha;
finally
Canvas.Free;
end;
finally
Picture.Free;
end;
Exit;
end
else
inherited Assign(Source); // default handler
finally;
EndUpdate;
Changed;
end;
end;
procedure TJclBitmap32.AssignTo(Dst: TPersistent);
var
Bmp: TBitmap;
begin
if Dst is TPicture then
begin
Bmp := TPicture(Dst).Bitmap;
Bmp.HandleType := bmDIB;
Bmp.PixelFormat := pf32bit;
Bmp.Width := Width;
Bmp.Height := Height;
DrawTo(Bmp.Canvas.Handle, 0, 0);
end
else
if Dst is TBitmap then
begin
Bmp := TBitmap(Dst);
Bmp.HandleType := bmDIB;
Bmp.PixelFormat := pf32bit;
Bmp.Width := Width;
Bmp.Height := Height;
DrawTo(Bmp.Canvas.Handle, 0, 0);
end
else
if Dst is TClipboard then
begin
Bmp := TBitmap.Create;
try
Bmp.HandleType := bmDIB;
Bmp.PixelFormat := pf32bit;
Bmp.Width := Width;
Bmp.Height := Height;
DrawTo(Bmp.Canvas.Handle, 0, 0);
TClipboard(Dst).Assign(Bmp);
finally
Bmp.Free;
end;
end
else
inherited AssignTo(Dst);
end;
procedure TJclBitmap32.SetPixel(X, Y: Integer; Value: TColor32);
begin
Bits[X + Y * Width] := Value;
end;
procedure TJclBitmap32.SetPixelS(X, Y: Integer; Value: TColor32);
begin
if (X >= 0) and (X < Width) and (Y >= 0) and (Y < Height) then
Bits[X + Y * Width] := Value;
end;
function TJclBitmap32.GetScanLine(Y: Integer): PColor32Array;
begin
Result := @Bits[Y * FWidth];
end;
function TJclBitmap32.GetPixel(X, Y: Integer): TColor32;
begin
Result := Bits[X + Y * Width];
end;
function TJclBitmap32.GetPixelS(X, Y: Integer): TColor32;
begin
if (X >= 0) and (X < Width) and (Y >= 0) and (Y < Height) then
Result := Bits[X + Y * Width]
else
Result := OuterColor;
end;
function TJclBitmap32.GetPixelPtr(X, Y: Integer): PColor32;
begin
Result := @Bits[X + Y * Width];
end;
procedure TJclBitmap32.Draw(DstX, DstY: Integer; Src: TJclBitmap32);
begin
Changing;
if Src <> nil then
Src.DrawTo(Self, DstX, DstY);
Changed;
end;
procedure TJclBitmap32.Draw(DstRect, SrcRect: TRect; Src: TJclBitmap32);
begin
Changing;
if Src <> nil then
Src.DrawTo(Self, DstRect, SrcRect);
Changed;
end;
procedure TJclBitmap32.Draw(DstRect, SrcRect: TRect; hSrc: HDC);
begin
if Empty then
Exit;
Changing;
StretchBlt(Handle, DstRect.Left, DstRect.Top, DstRect.Right - DstRect.Left,
DstRect.Bottom - DstRect.Top, hSrc, SrcRect.Left, SrcRect.Top,
SrcRect.Right - SrcRect.Left, SrcRect.Bottom - SrcRect.Top, SRCCOPY);
Changed;
end;
procedure TJclBitmap32.DrawTo(Dst: TJclBitmap32);
begin
if Empty or Dst.Empty then
Exit;
Dst.Changing;
BlockTransfer(Dst, 0, 0, Self, Rect(0, 0, Width, Height), DrawMode);
Dst.Changed;
end;
procedure TJclBitmap32.DrawTo(Dst: TJclBitmap32; DstX, DstY: Integer);
begin
if Empty or Dst.Empty then
Exit;
Dst.Changing;
BlockTransfer(Dst, DstX, DstY, Self, Rect(0, 0, Width, Height), DrawMode);
Dst.Changed;
end;
procedure TJclBitmap32.DrawTo(Dst: TJclBitmap32; DstRect: TRect);
begin
if Empty or Dst.Empty then
Exit;
Dst.Changing;
StretchTransfer(Dst, DstRect, Self, Rect(0, 0, Width, Height), StretchFilter, DrawMode);
Dst.Changed;
end;
procedure TJclBitmap32.DrawTo(Dst: TJclBitmap32; DstRect, SrcRect: TRect);
begin
if Empty or Dst.Empty then
Exit;
Dst.Changing;
StretchTransfer(Dst, DstRect, Self, SrcRect, StretchFilter, DrawMode);
Dst.Changed;
end;
procedure TJclBitmap32.DrawTo(hDst: HDC; DstX, DstY: Integer);
begin
if Empty then
Exit;
BitBlt(hDst, DstX, DstY, Width, Height, Handle, 0, 0, SRCCOPY);
end;
procedure TJclBitmap32.DrawTo(hDst: HDC; DstRect, SrcRect: TRect);
begin
if Empty then
Exit;
StretchDIBits(hDst,
DstRect.Left, DstRect.Top, DstRect.Right - DstRect.Left, DstRect.Bottom - DstRect.Top,
SrcRect.Left, SrcRect.Top, SrcRect.Right - SrcRect.Left, SrcRect.Bottom - SrcRect.Top,
Bits, FBitmapInfo, DIB_RGB_COLORS, SRCCOPY);
end;
procedure TJclBitmap32.ResetAlpha;
var
I: Integer;
P: PByte;
begin
Changing;
P := Pointer(FBits);
Inc(P, 3);
for I := 0 to Width * Height - 1 do
begin
P^ := $FF;
Inc(P, 4)
end;
Changed;
end;
function TJclBitmap32.GetPixelB(X, Y: Integer): TColor32;
begin
// this function should never be used on empty bitmaps !!!
if X < 0 then
X := 0
else
if X >= Width then
X := Width - 1;
if Y < 0 then
Y := 0
else
if Y >= Height then
Y := Height - 1;
Result := Bits[X + Y * Width];
end;
procedure TJclBitmap32.SetPixelT(X, Y: Integer; Value: TColor32);
begin
BlendMem(Value, Bits[X + Y * Width]);
EMMS;
end;
procedure TJclBitmap32.SetPixelT(var Ptr: PColor32; Value: TColor32);
begin
BlendMem(Value, Ptr^);
EMMS;
Inc(Ptr);
end;
procedure TJclBitmap32.SetPixelTS(X, Y: Integer; Value: TColor32);
begin
if (X >= 0) and (X < Width) and (Y >= 0) and (Y < Width) then
begin
BlendMem(Value, Bits[X + Y * Width]);
EMMS;
end;
end;
procedure TJclBitmap32.SET_T256(X, Y: Integer; C: TColor32);
var
flrx, flry, celx, cely: Longword;
P: PColor32;
A: TColor32;
begin
A := C shr 24; // opacity
flrx := X and $FF;
flry := Y and $FF;
X := Sar(X,8);
Y := Sar(Y,8);
celx := A * GAMMA_TABLE[flrx xor 255];
cely := GAMMA_TABLE[flry xor 255];
flrx := A * GAMMA_TABLE[flrx];
flry := GAMMA_TABLE[flry];
P := @FBits[X + Y * FWidth];
CombineMem(C, P^, celx * cely shr 16);
Inc(P);
CombineMem(C, P^, flrx * cely shr 16);
Inc(P, FWidth);
CombineMem(C, P^, flrx * flry shr 16);
Dec(P);
CombineMem(C, P^, celx * flry shr 16);
end;
procedure TJclBitmap32.SET_TS256(X, Y: Integer; C: TColor32);
var
flrx, flry, celx, cely: Longword;
P: PColor32;
A: TColor32;
begin
if (X < -256) or (Y < -256) then
Exit;
flrx := X and $FF;
flry := Y and $FF;
X := Sar(X,8);
Y := Sar(Y,8);
if (X >= FWidth) or (Y >= FHeight) then
Exit;
A := C shr 24; // opacity
celx := A * GAMMA_TABLE[flrx xor 255];
cely := GAMMA_TABLE[flry xor 255];
flrx := A * GAMMA_TABLE[flrx];
flry := GAMMA_TABLE[flry];
P := @FBits[X + Y * FWidth];
if (X >= 0) and (Y >= 0) and (X < FWidth - 1) and (Height < FHeight - 1) then
begin
CombineMem(C, P^, celx * cely shr 16);
Inc(P);
CombineMem(C, P^, flrx * cely shr 16);
Inc(P, FWidth);
CombineMem(C, P^, flrx * flry shr 16);
Dec(P);
CombineMem(C, P^, celx * flry shr 16);
end
else
begin
if (X >= 0) and (Y >= 0) then
CombineMem(C, P^, celx * cely shr 16);
Inc(P);
if (X < FWidth - 1) and (Y >= 0) then
CombineMem(C, P^, flrx * cely shr 16);
Inc(P, FWidth);
if (X < FWidth - 1) and (Y < FHeight - 1) then
CombineMem(C, P^, flrx * flry shr 16);
Dec(P);
if (X >= 0) and (Y < FHeight - 1) then
CombineMem(C, P^, celx * flry shr 16);
end;
end;
procedure TJclBitmap32.SetPixelF(X, Y: Single; Value: TColor32);
begin
SET_T256(Round(X * 256), Round(Y * 256), Value);
EMMS;
end;
procedure TJclBitmap32.SetPixelFS(X, Y: Single; Value: TColor32);
begin
SET_TS256(Round(X * 256), Round(Y * 256), Value);
EMMS;
end;
procedure TJclBitmap32.SetStipple(NewStipple: TArrayOfColor32);
begin
FStippleCounter := 0;
FStipplePattern := Copy(NewStipple, 0, Length(NewStipple));
end;
procedure TJclBitmap32.SetStipple(NewStipple: array of TColor32);
var
L: Integer;
begin
FStippleCounter := 0;
L := High(NewStipple) - Low(NewStipple) + 1;
SetLength(FStipplePattern, L);
Move(NewStipple[Low(NewStipple)], FStipplePattern[0], L * SizeOf(TColor32));
end;
function TJclBitmap32.GetStippleColor: TColor32;
var
L: Integer;
NextIndex, PrevIndex: Integer;
PrevWeight: Integer;
begin
L := Length(FStipplePattern);
if L = 0 then
begin
// no pattern defined, just return something and exit
Result := clBlack32;
Exit;
end;
while FStippleCounter >= L do
FStippleCounter := FStippleCounter - L;
while FStippleCounter < 0 do
FStippleCounter := FStippleCounter + L;
PrevIndex := Round(FStippleCounter - 0.5);
PrevWeight := 255 - Round(255 * (FStippleCounter - PrevIndex));
if PrevIndex < 0 then
FStippleCounter := L - 1;
NextIndex := PrevIndex + 1;
if NextIndex >= L then
NextIndex := 0;
if PrevWeight = 255 then
Result := FStipplePattern[PrevIndex]
else
begin
Result := CombineReg(
FStipplePattern[PrevIndex],
FStipplePattern[NextIndex],
PrevWeight);
EMMS;
end;
FStippleCounter := FStippleCounter + FStippleStep;
end;
procedure TJclBitmap32.SetStippleStep(Value: Single);
begin
FStippleStep := Value;
end;
procedure TJclBitmap32.ResetStippleCounter;
begin
FStippleCounter := 0;
end;
procedure TJclBitmap32.DrawHorzLine(X1, Y, X2: Integer; Value: TColor32);
begin
FillLongword(Bits[X1 + Y * Width], X2 - X1 + 1, Value);
end;
procedure TJclBitmap32.DrawHorzLineS(X1, Y, X2: Integer; Value: TColor32);
begin
if (Y >= 0) and (Y < Height) and TestClip(X1, X2, Width) then
DrawHorzLine(X1, Y, X2, Value);
end;
procedure TJclBitmap32.DrawHorzLineT(X1, Y, X2: Integer; Value: TColor32);
var
I: Integer;
P: PColor32;
begin
if X2 < X1 then
Exit;
P := PixelPtr[X1, Y];
for I := X1 to X2 do
begin
BlendMem(Value, P^);
Inc(P);
end;
EMMS;
end;
procedure TJclBitmap32.DrawHorzLineTS(X1, Y, X2: Integer; Value: TColor32);
begin
if (Y >= 0) and (Y < Height) and TestClip(X1, X2, Width) then
DrawHorzLineT(X1, Y, X2, Value);
end;
procedure TJclBitmap32.DrawHorzLineTSP(X1, Y, X2: Integer);
var
I: Integer;
begin
if Empty then
Exit;
if (Y >= 0) and (Y < Height) then
begin
if ((X1 < 0) and (X2 < 0)) or ((X1 >= Width) and (X2 >= Width)) then
Exit;
if X1 < 0 then
X1 := 0
else
if X1 >= Width then
X1 := Width - 1;
if X2 < 0 then
X2 := 0
else
if X2 >= Width then
X2 := Width - 1;
if X2 >= X1 then
for I := X1 to X2 do
SetPixelT(I, Y, GetStippleColor)
else
for I := X2 downto X1 do
SetPixelT(I, Y, GetStippleColor);
end;
end;
procedure TJclBitmap32.DrawVertLine(X, Y1, Y2: Integer; Value: TColor32);
var
I: Integer;
P: PColor32;
begin
if Y2 < Y1 then
Exit;
P := PixelPtr[X, Y1];
for I := 0 to Y2 - Y1 do
begin
P^ := Value;
Inc(P, Width);
end;
end;
procedure TJclBitmap32.DrawVertLineS(X, Y1, Y2: Integer; Value: TColor32);
begin
if (X >= 0) and (X < Width) and TestClip(Y1, Y2, Height) then
DrawVertLine(X, Y1, Y2, Value);
end;
procedure TJclBitmap32.DrawVertLineT(X, Y1, Y2: Integer; Value: TColor32);
var
I: Integer;
P: PColor32;
begin
P := PixelPtr[X, Y1];
for I := Y1 to Y2 do
begin
BlendMem(Value, P^);
Inc(P, Width);
end;
EMMS;
end;
procedure TJclBitmap32.DrawVertLineTS(X, Y1, Y2: Integer; Value: TColor32);
begin
if (X >= 0) and (X < Width) and TestClip(Y1, Y2, Height) then
DrawVertLineT(X, Y1, Y2, Value);
end;
procedure TJclBitmap32.DrawVertLineTSP(X, Y1, Y2: Integer);
var
I: Integer;
begin
if Empty then
Exit;
if (X >= 0) and (X < Width) then
begin
if ((Y1 < 0) and (Y2 < 0)) or ((Y1 >= Height) and (Y2 >= Height)) then
Exit;
if Y1 < 0 then
Y1 := 0
else
if Y1 >= Height then
Y1 := Height - 1;
if Y2 < 0 then
Y2 := 0
else
if Y2 >= Height then
Y2 := Height - 1;
if Y2 >= Y1 then
for I := Y1 to Y2 do
SetPixelT(X, I, GetStippleColor)
else
for I := Y2 downto Y1 do
SetPixelT(X, I, GetStippleColor);
end;
end;
procedure TJclBitmap32.DrawLine(X1, Y1, X2, Y2: Integer; Value: TColor32; L: Boolean);
var
Dy, Dx, Sy, Sx, I, Delta: Integer;
P: PColor32;
begin
Changing;
try
Dx := X2 - X1;
Dy := Y2 - Y1;
if Dx > 0 then
Sx := 1
else
if Dx < 0 then
begin
Dx := -Dx;
Sx := -1;
end
else // Dx = 0
begin
if Dy > 0 then
DrawVertLine(X1, Y1, Y2 - 1, Value)
else
if Dy < 0 then
DrawVertLine(X1, Y2, Y1 - 1, Value);
if L then
Pixel[X2, Y2] := Value;
Exit;
end;
if Dy > 0 then
Sy := 1
else
if Dy < 0 then
begin
Dy := -Dy;
Sy := -1;
end
else // Dy = 0
begin
if Dx > 0 then
DrawHorzLine(X1, Y1, X2 - 1, Value)
else
DrawHorzLine(X2, Y1, X1 - 1, Value);
if L then
Pixel[X2, Y2] := Value;
Exit;
end;
P := PixelPtr[X1, Y1];
Sy := Sy * Width;
if Dx > Dy then
begin
Delta := Dx shr 1;
for I := 0 to Dx - 1 do
begin
P^ := Value;
Inc(P, Sx);
Delta := Delta + Dy;
if Delta > Dx then
begin
Inc(P, Sy);
Delta := Delta - Dx;
end;
end;
end
else // Dx < Dy
begin
Delta := Dy shr 1;
for I := 0 to Dy - 1 do
begin
P^ := Value;
Inc(P, Sy);
Delta := Delta + Dx;
if Delta > Dy then
begin
Inc(P, Sx);
Delta := Delta - Dy;
end;
end;
end;
if L then
P^ := Value;
finally
Changed;
end;
end;
function TJclBitmap32.ClipLine(var X0, Y0, X1, Y1: Integer): Boolean;
type
TEdge = (Left, Right, Top, Bottom);
TOutCode = set of TEdge;
var
Accept, AllDone: Boolean;
OutCode0, OutCode1, OutCodeOut: TOutCode;
X, Y: Integer;
procedure CompOutCode(X, Y: Integer; var Code: TOutCode);
begin
Code := [];
if X < 0 then
Code := Code + [Left];
if X >= Width then
Code := Code + [Right];
if Y < 0 then
Code := Code + [Top];
if Y >= Height then
Code := Code + [Bottom];
end;
begin
Accept := False;
AllDone := False;
CompOutCode(X0, Y0, OutCode0);
CompOutCode(X1, Y1, OutCode1);
repeat
if (OutCode0 = []) and (OutCode1 = []) then // trivial accept and exit
begin
Accept := True;
AllDone := True;
end
else
if (OutCode0 * OutCode1) <> [] then
AllDone := True // trivial reject
else // calculate intersections
begin
if OutCode0 <> [] then
OutCodeOut := OutCode0
else
OutCodeOut := OutCode1;
X := 0;
Y := 0;
if Left in OutCodeOut then
Y := Y0 + (Y1 - Y0) * (-X0) div (X1 - X0)
else
if Right in OutCodeOut then
begin
Y := Y0 + (Y1 - Y0) * (Width - 1 - X0) div (X1 - X0);
X := Width - 1;
end
else
if Top in OutCodeOut then
X := X0 + (X1 - X0) * (-Y0) div (Y1 - Y0)
else
if Bottom in OutCodeOut then
begin
X := X0 + (X1 - X0) * (Height - 1 - Y0) div (Y1 - Y0);
Y := Height - 1;
end;
if OutCodeOut = OutCode0 then
begin
X0 := X;
Y0 := Y;
CompOutCode(X0, Y0, OutCode0);
end
else
begin
X1 := X;
Y1 := Y;
CompOutCode(X1, Y1, OutCode1);
end;
end;
until AllDone;
Result := Accept;
end;
class function TJclBitmap32.ClipLineF(var X0, Y0, X1, Y1: Single;
MinX, MaxX, MinY, MaxY: Single): Boolean;
type
TEdge = (Left, Right, Top, Bottom);
TOutCode = set of TEdge;
var
Accept, AllDone: Boolean;
OutCode0, OutCode1, OutCodeOut: TOutCode;
X, Y: Single;
procedure CompOutCode(X, Y: Single; var Code: TOutCode);
begin
Code := [];
if X < MinX then
Code := Code + [Left];
if X > MaxX then
Code := Code + [Right];
if Y < MinY then
Code := Code + [Top];
if Y > MaxY then
Code := Code + [Bottom];
end;
begin
Accept := False;
AllDone := False;
CompOutCode(X0, Y0, OutCode0);
CompOutCode(X1, Y1, OutCode1);
repeat
if (OutCode0 = []) and (OutCode1 = []) then // trivial accept and exit
begin
Accept := True;
AllDone := True;
end
else
if (OutCode0 * OutCode1) <> [] then
AllDone := True // trivial reject
else // calculate intersections
begin
if OutCode0 <> [] then
OutCodeOut := OutCode0
else
OutCodeOut := OutCode1;
X := 0;
Y := 0;
if Left in OutCodeOut then
begin
Y := Y0 + (Y1 - Y0) * (MinX - X0) / (X1 - X0);
X := MinX;
end
else
if Right in OutCodeOut then
begin
Y := Y0 + (Y1 - Y0) * (MaxX - X0) / (X1 - X0);
X := MaxX - 1;
end
else
if Top in OutCodeOut then
begin
X := X0 + (X1 - X0) * (MinY - Y0) / (Y1 - Y0);
Y := MinY;
end
else
if Bottom in OutCodeOut then
begin
X := X0 + (X1 - X0) * (MaxY - Y0) / (Y1 - Y0);
Y := MaxY;
end;
if OutCodeOut = OutCode0 then
begin
X0 := X;
Y0 := Y;
CompOutCode(X0, Y0, OutCode0);
end
else
begin
X1 := X;
Y1 := Y;
CompOutCode(X1, Y1, OutCode1);
end;
end;
until AllDone;
Result := Accept;
end;
procedure TJclBitmap32.DrawLineS(X1, Y1, X2, Y2: Integer; Value: TColor32; L: Boolean);
begin
if ClipLine(X1, Y1, X2, Y2) then
DrawLine(X1, Y1, X2, Y2, Value, L);
end;
procedure TJclBitmap32.DrawLineT(X1, Y1, X2, Y2: Integer; Value: TColor32; L: Boolean);
var
Dy, Dx, Sy, Sx, I, Delta: Integer;
P: PColor32;
begin
Changing;
try
Dx := X2 - X1;
Dy := Y2 - Y1;
if Dx > 0 then
Sx := 1
else
if Dx < 0 then
begin
Dx := -Dx;
Sx := -1;
end
else // Dx = 0
begin
if Dy > 0 then
DrawVertLineT(X1, Y1, Y2 - 1, Value)
else
if Dy < 0 then
DrawVertLineT(X1, Y2, Y1 - 1, Value);
if L then
SetPixelT(X2, Y2, Value);
Exit;
end;
if Dy > 0 then
Sy := 1
else
if Dy < 0 then
begin
Dy := -Dy;
Sy := -1;
end
else // Dy = 0
begin
if Dx > 0 then
DrawHorzLineT(X1, Y1, X2 - 1, Value)
else
DrawHorzLineT(X2, Y1, X1 - 1, Value);
if L then
SetPixelT(X2, Y2, Value);
Exit;
end;
P := PixelPtr[X1, Y1];
Sy := Sy * Width;
try
if Dx > Dy then
begin
Delta := Dx shr 1;
for I := 0 to Dx - 1 do
begin
BlendMem(Value, P^);
Inc(P, Sx);
Delta := Delta + Dy;
if Delta > Dx then
begin
Inc(P, Sy);
Delta := Delta - Dx;
end;
end;
end
else // Dx < Dy
begin
Delta := Dy shr 1;
for I := 0 to Dy - 1 do
begin
BlendMem(Value, P^);
Inc(P, Sy);
Delta := Delta + Dx;
if Delta > Dy then
begin
Inc(P, Sx);
Delta := Delta - Dy;
end;
end;
end;
if L then
BlendMem(Value, P^);
finally
EMMS;
end;
finally
Changed;
end;
end;
procedure TJclBitmap32.DrawLineTS(X1, Y1, X2, Y2: Integer; Value: TColor32; L: Boolean);
begin
if ClipLine(X1, Y1, X2, Y2) then
DrawLineT(X1, Y1, X2, Y2, Value, L);
end;
procedure TJclBitmap32.DrawLineF(X1, Y1, X2, Y2: Single; Value: TColor32; L: Boolean);
var
N, I: Integer;
px, py, ex, ey, nx, ny, hyp: Integer;
A: TColor32;
begin
Changing;
try
px := Round(x1 * 65536);
py := Round(y1 * 65536);
ex := Round(x2 * 65536);
ey := Round(y2 * 65536);
nx := ex - px;
ny := ey - py;
hyp := Round(Hypot(nx, ny));
if L then
Inc(hyp, 65536);
if hyp < 256 then
Exit;
N := hyp shr 16;
if N > 0 then
begin
nx := Round(nx / hyp * 65536);
ny := Round(ny / hyp * 65536);
for I := 0 to N - 1 do
begin
SET_T256(px shr 8, py shr 8, Value);
px := px + nx;
py := py + ny;
end;
end;
A := Value shr 24;
hyp := hyp - N shl 16;
A := A * Longword(hyp) shl 8 and $FF000000;
SET_T256((px + ex - nx) shr 9, (py + ey - ny) shr 9, Value and _RGB + A);
finally
EMMS;
Changed;
end;
end;
procedure TJclBitmap32.DrawLineFS(X1, Y1, X2, Y2: Single; Value: TColor32; L: Boolean);
var
N, I: Integer;
px, py, ex, ey, nx, ny, hyp: Integer;
A: TColor32;
begin
if ClipLineF(X1, Y1, X2, Y2, 0, FWidth, 0, FHeight) then
if (X1 < FWidth - 1) and (X2 < FWidth - 1) and
(Y1 < FHeight - 1) and (Y2 < FHeight - 1) then
DrawLineF(X1, Y1, X2, Y2, Value, False)
else // check every pixel
begin
Changing;
try
px := Round(x1 * 65536);
py := Round(y1 * 65536);
ex := Round(x2 * 65536);
ey := Round(y2 * 65536);
nx := ex - px;
ny := ey - py;
hyp := Round(Hypot(nx, ny));
if L then
Inc(Hyp, 65536);
if hyp < 256 then
Exit;
N := hyp shr 16;
if N > 0 then
begin
nx := Round(nx / hyp * 65536);
ny := Round(ny / hyp * 65536);
for I := 0 to N - 1 do
begin
SET_TS256(px div 256, py div 256, Value);
px := px + nx;
py := py + ny;
end;
end;
A := Value shr 24;
hyp := hyp - N shl 16;
A := A * Longword(hyp) shl 8 and $FF000000;
SET_TS256(Sar(px + ex - nx,9), Sar(py + ey - ny,9), Value and _RGB + A);
finally
EMMS;
Changed;
end;
end;
end;
procedure TJclBitmap32.DrawLineFP(X1, Y1, X2, Y2: Single; L: Boolean);
var
N, I: Integer;
px, py, ex, ey, nx, ny, hyp: Integer;
A, C: TColor32;
begin
Changing;
try
px := Round(x1 * 65536);
py := Round(y1 * 65536);
ex := Round(x2 * 65536);
ey := Round(y2 * 65536);
nx := ex - px;
ny := ey - py;
hyp := Round(Hypot(nx, ny));
if L then
Inc(hyp, 65536);
if hyp < 256 then
Exit;
N := hyp shr 16;
if N > 0 then
begin
nx := Round(nx / hyp * 65536);
ny := Round(ny / hyp * 65536);
for I := 0 to N - 1 do
begin
C := GetStippleColor;
SET_T256(px shr 8, py shr 8, C);
EMMS;
px := px + nx;
py := py + ny;
end;
end;
C := GetStippleColor;
A := C shr 24;
hyp := hyp - N shl 16;
A := A * Longword(hyp) shl 8 and $FF000000;
SET_T256((px + ex - nx) shr 9, (py + ey - ny) shr 9, C and _RGB + A);
EMMS;
finally
Changed;
end;
end;
procedure TJclBitmap32.DrawLineFSP(X1, Y1, X2, Y2: Single; L: Boolean);
var
N, I: Integer;
px, py, ex, ey, nx, ny, hyp: Integer;
A, C: TColor32;
begin
if ClipLineF(X1, Y1, X2, Y2, 0, FWidth, 0, FHeight) then
if (X1 < FWidth - 1) and (X2 < FWidth - 1) and
(Y1 < FHeight - 1) and (Y2 < FHeight - 1) then
DrawLineFP(X1, Y1, X2, Y2, False)
else // check every pixel
begin
Changing;
try
px := Round(x1 * 65536);
py := Round(y1 * 65536);
ex := Round(x2 * 65536);
ey := Round(y2 * 65536);
nx := ex - px;
ny := ey - py;
hyp := Round(Hypot(nx, ny));
if L then
Inc(hyp, 65536);
if hyp < 256 then
Exit;
N := hyp shr 16;
if N > 0 then
begin
nx := Round(nx / hyp * 65536);
ny := Round(ny / hyp * 65536);
for I := 0 to N - 1 do
begin
C := GetStippleColor;
SET_TS256(px div 256, py div 256, C);
EMMS;
px := px + nx;
py := py + ny;
end;
end;
C := GetStippleColor;
A := C shr 24;
hyp := hyp - N shl 16;
A := A * Longword(hyp) shl 8 and $FF000000;
SET_TS256(Sar(px + ex - nx,9), Sar(py + ey - ny,9), C and _RGB + A);
EMMS;
finally
Changed;
end;
end;
end;
procedure TJclBitmap32.DrawLineA(X1, Y1, X2, Y2: Integer; Value: TColor32; L: Boolean);
var
Dx, Dy, Sx, Sy, D: Integer;
EC, EA: Word;
CI: Byte;
P: PColor32;
begin
if (X1 = X2) or (Y1 = Y2) then
begin
DrawLineT(X1, Y1, X2, Y2, Value, L);
Exit;
end;
Dx := X2 - X1;
Dy := Y2 - Y1;
if Dx > 0 then
Sx := 1
else
begin
Sx := -1;
Dx := -Dx;
end;
if Dy > 0 then
Sy := 1
else
begin
Sy := -1;
Dy := -Dy;
end;
Changing;
try
EC := 0;
BlendMem(Value, Bits[X1 + Y1 * Width]);
if Dy > Dx then
begin
EA := Dx shl 16 div Dy;
if not L then
Dec(Dy);
while Dy > 0 do
begin
Dec(Dy);
D := EC;
Inc(EC, EA);
if EC <= D then
Inc(X1, Sx);
Inc(Y1, Sy);
CI := EC shr 8;
P := @Bits[X1 + Y1 * Width];
BlendMemEx(Value, P^, GAMMA_TABLE[CI xor 255]);
Inc(P, Sx);
BlendMemEx(Value, P^, GAMMA_TABLE[CI]);
end;
end
else // DY <= DX
begin
EA := Dy shl 16 div Dx;
if not L then
Dec(Dx);
while Dx > 0 do
begin
Dec(Dx);
D := EC;
Inc(EC, EA);
if EC <= D then
Inc(Y1, Sy);
Inc(X1, Sx);
CI := EC shr 8;
P := @Bits[X1 + Y1 * Width];
BlendMemEx(Value, P^, GAMMA_TABLE[CI xor 255]);
if Sy = 1 then
Inc(P, Width)
else
Dec(P, Width);
BlendMemEx(Value, P^, GAMMA_TABLE[CI]);
end;
end;
finally
EMMS;
Changed;
end;
end;
procedure TJclBitmap32.DrawLineAS(X1, Y1, X2, Y2: Integer; Value: TColor32; L: Boolean);
begin
if ClipLine(X1, Y1, X2, Y2) then
DrawLineA(X1, Y1, X2, Y2, Value, L);
end;
procedure TJclBitmap32.MoveTo(X, Y: Integer);
begin
RasterX := X;
RasterY := Y;
end;
procedure TJclBitmap32.LineToS(X, Y: Integer);
begin
DrawLineS(RasterX, RasterY, X, Y, PenColor, False);
RasterX := X;
RasterY := Y;
end;
procedure TJclBitmap32.LineToTS(X, Y: Integer);
begin
DrawLineTS(RasterX, RasterY, X, Y, PenColor, False);
RasterX := X;
RasterY := Y;
end;
procedure TJclBitmap32.LineToAS(X, Y: Integer);
begin
DrawLineAS(RasterX, RasterY, X, Y, PenColor, False);
RasterX := X;
RasterY := Y;
end;
procedure TJclBitmap32.MoveToF(X, Y: Single);
begin
RasterXF := X;
RasterYF := Y;
end;
procedure TJclBitmap32.LineToFS(X, Y: Single);
begin
DrawLineFS(RasterXF, RasterYF, X, Y, PenColor, False);
RasterXF := X;
RasterYF := Y;
end;
procedure TJclBitmap32.FillRect(X1, Y1, X2, Y2: Integer; Value: TColor32);
var
J: Integer;
P: PColor32Array;
begin
Changing;
for J := Y1 to Y2 do
begin
P := Pointer(GetScanLine(J));
FillLongword(P[X1], X2 - X1 + 1, Value);
end;
Changed;
end;
procedure TJclBitmap32.FillRectS(X1, Y1, X2, Y2: Integer; Value: TColor32);
begin
if TestClip(X1, X2, Width) and TestClip(Y1, Y2, Height) then
FillRect(X1, Y1, X2, Y2, Value);
end;
procedure TJclBitmap32.FillRectT(X1, Y1, X2, Y2: Integer; Value: TColor32);
var
I, J: Integer;
P: PColor32;
A: Integer;
begin
A := Value shr 24;
if A = $FF then
FillRect(X1, Y1, X2, Y2, Value)
else
begin
Changing;
try
for J := Y1 to Y2 do
begin
P := GetPixelPtr(X1, J);
for I := X1 to X2 do
begin
CombineMem(Value, P^, A);
Inc(P);
end;
end;
finally
EMMS;
Changed;
end;
end;
end;
procedure TJclBitmap32.FillRectTS(X1, Y1, X2, Y2: Integer; Value: TColor32);
begin
if TestClip(X1, X2, Width) and TestClip(Y1, Y2, Height) then
FillRectT(X1, Y1, X2, Y2, Value);
end;
procedure TJclBitmap32.FrameRectS(X1, Y1, X2, Y2: Integer; Value: TColor32);
begin
Changing;
TestSwap(X1, X2);
TestSwap(Y1, Y2);
DrawHorzLineS(X1, Y1, X2, Value);
if Y2 > Y1 then
DrawHorzLineS(X1, Y2, X2, Value);
if Y2 > Y1 + 1 then
begin
DrawVertLineS(X1, Y1 + 1, Y2 - 1, Value);
if X2 > X1 then
DrawVertLineS(X2, Y1 + 1, Y2 - 1, Value);
end;
Changed;
end;
procedure TJclBitmap32.FrameRectTS(X1, Y1, X2, Y2: Integer; Value: TColor32);
begin
Changing;
TestSwap(X1, X2);
TestSwap(Y1, Y2);
DrawHorzLineTS(X1, Y1, X2, Value);
if Y2 > Y1 then
DrawHorzLineTS(X1, Y2, X2, Value);
if Y2 > Y1 + 1 then
begin
DrawVertLineTS(X1, Y1 + 1, Y2 - 1, Value);
if X2 > X1 then
DrawVertLineTS(X2, Y1 + 1, Y2 - 1, Value);
end;
Changed;
end;
procedure TJclBitmap32.FrameRectTSP(X1, Y1, X2, Y2: Integer);
begin
Changing;
TestSwap(X1, X2);
TestSwap(Y1, Y2);
DrawHorzLineTSP(X1, Y1, X2);
if Y2 > Y1 + 1 then
begin
DrawVertLineTSP(X2, Y1 + 1, Y2 - 1);
if X2 > X1 then
DrawVertLineTSP(X1, Y1 + 1, Y2 - 1);
end;
if Y2 > Y1 then
DrawHorzLineTSP(X1, Y2, X2);
Changed;
end;
procedure TJclBitmap32.RaiseRectTS(X1, Y1, X2, Y2: Integer; Contrast: Integer);
var
C1, C2: TColor32;
begin
Changing;
try
if Contrast > 0 then
begin
C1 := clWhite32;
C2 := clBlack32;
end
else
if Contrast < 0 then
begin
C1 := clBlack32;
C2 := clWhite32;
Contrast := -Contrast;
end
else
Exit;
Contrast := Clamp(Contrast * 255 div 100);
C1 := SetAlpha(C1, Contrast);
C2 := SetAlpha(C2, Contrast);
TestSwap(X1, X2);
TestSwap(Y1, Y2);
DrawHorzLineTS(X1, Y1, X2 - 1, C1);
DrawHorzLineTS(X1 + 1, Y2, X2, C2);
DrawVertLineTS(X1, Y1, Y2 - 1, C1);
DrawVertLineTS(X2, Y1 + 1, Y2, C2);
finally
Changed;
end;
end;
procedure TJclBitmap32.LoadFromStream(Stream: TStream);
var
B: TBitmap;
begin
Changing;
B := TBitmap.Create;
try
B.LoadFromStream(Stream);
Assign(B);
finally
B.Free;
Changed;
end;
end;
procedure TJclBitmap32.SaveToStream(Stream: TStream);
var
B: TBitmap;
begin
B := TBitmap.Create;
try
AssignTo(B);
B.SaveToStream(Stream);
finally
B.Free;
end;
end;
procedure TJclBitmap32.DefineProperties(Filer: TFiler);
function DoWrite: Boolean;
begin
if Filer.Ancestor <> nil then
Result := not (Filer.Ancestor is TGraphic)
else
Result := not Empty;
end;
begin
Filer.DefineBinaryProperty('Data', ReadData, WriteData, DoWrite);
end;
procedure TJclBitmap32.ReadData(Stream: TStream);
var
w, h: Integer;
begin
Changing;
try
Stream.ReadBuffer(w, 4);
Stream.ReadBuffer(h, 4);
SetSize(w, h);
Stream.ReadBuffer(FBits[0], FWidth * FHeight * 4);
finally
Changed;
end;
end;
procedure TJclBitmap32.WriteData(Stream: TStream);
begin
Stream.WriteBuffer(FWidth, 4);
Stream.WriteBuffer(FHeight, 4);
Stream.WriteBuffer(FBits[0], FWidth * FHeight * 4);
end;
procedure TJclBitmap32.LoadFromFile(const FileName: string);
var
P: TPicture;
begin
P := TPicture.Create;
try
P.LoadFromFile(FileName);
Assign(P);
finally
P.Free;
end;
end;
procedure TJclBitmap32.SaveToFile(const FileName: string);
var
B: TBitmap;
begin
B := TBitmap.Create;
try
AssignTo(B);
B.SaveToFile(FileName);
finally
B.Free;
end;
end;
procedure TJclBitmap32.SetFont(Value: TFont);
begin
FFont.Assign(Value);
FontChanged(Self);
end;
procedure TJclBitmap32.FontChanged(Sender: TObject);
begin
if FontHandle > 0 then
begin
SelectObject(Handle, GetStockObject(SYSTEM_FONT));
FontHandle := 0;
end;
end;
procedure TJclBitmap32.UpdateFont;
begin
if FontHandle = 0 then
begin
SelectObject(Handle, Font.Handle);
SetTextColor(Handle, ColorToRGB(Font.Color));
SetBkMode(Handle, {$IFDEF HAS_UNITSCOPE}Winapi.{$ENDIF}Windows.TRANSPARENT);
end;
end;
procedure TJclBitmap32.SetDrawMode(Value: TDrawMode);
begin
if FDrawMode <> Value then
begin
Changing;
FDrawMode := Value;
Changed;
end;
end;
procedure TJclBitmap32.SetMasterAlpha(Value: Byte);
begin
if FMasterAlpha <> Value then
begin
Changing;
FMasterAlpha := Value;
Changed;
end;
end;
procedure TJclBitmap32.SetStretchFilter(Value: TStretchFilter);
begin
if FStretchFilter <> Value then
begin
Changing;
FStretchFilter := Value;
Changed;
end;
end;
function TJclBitmap32.TextExtent(const Text: string): TSize;
begin
UpdateFont;
Result.cX := 0;
Result.cY := 0;
{$IFDEF HAS_UNITSCOPE}Winapi.{$ENDIF}Windows.GetTextExtentPoint32(Handle, PChar(Text), Length(Text), Result);
end;
procedure TJclBitmap32.TextOut(X, Y: Integer; const Text: string);
begin
Changing;
UpdateFont;
ExtTextOut(Handle, X, Y, 0, nil, PChar(Text), Length(Text), nil);
Changed;
end;
procedure TJclBitmap32.TextOut(X, Y: Integer; const ClipRect: TRect;
const Text: string);
begin
Changing;
UpdateFont;
ExtTextOut(Handle, X, Y, ETO_CLIPPED, @ClipRect, PChar(Text), Length(Text), nil);
Changed;
end;
procedure TJclBitmap32.TextOut(ClipRect: TRect; const Flags: Cardinal;
const Text: string);
begin
Changing;
UpdateFont;
DrawText(Handle, PChar(Text), Length(Text), ClipRect, Flags);
Changed;
end;
function TJclBitmap32.TextHeight(const Text: string): Integer;
begin
Result := TextExtent(Text).cY;
end;
function TJclBitmap32.TextWidth(const Text: string): Integer;
begin
Result := TextExtent(Text).cX;
end;
procedure TJclBitmap32.RenderText(X, Y: Integer; const Text: string; AALevel: Integer; Color: TColor32);
var
B, B2: TJclBitmap32;
Sz: TSize;
C: TColor32;
I: Integer;
P: PColor32;
begin
AALevel := Constrain(AALevel, 0, 4);
B := TJclBitmap32.Create;
try
if AALevel = 0 then
begin
Sz := TextExtent(Text + ' ');
B.SetSize(Sz.cX, Sz.cY);
B.Font := Font;
B.Clear(0);
B.Font.Color := clWhite;
B.TextOut(0, 0, Text);
end
else
begin
B2 := TJclBitmap32.Create;
try
B2.SetSize(1, 1); // just need some DC here
B2.Font := Font;
B2.Font.Size := Font.Size shl AALevel;
Sz := B2.TextExtent(Text + ' ');
Sz.cx := (Sz.cx shr AALevel + 1) shl AALevel;
B2.SetSize(Sz.cx, Sz.cy);
B2.Clear(0);
B2.Font.Color := clWhite;
B2.TextOut(0, 0, Text);
B2.StretchFilter := sfLinear;
B.SetSize(Sz.cx shr AALevel, Sz.cy shr AALevel);
B.Draw(Rect(0, 0, B.Width, B.Height), Rect(0, 0, B2.Width, B2.Height), B2);
finally
B2.Free;
end;
end;
// convert intensity and color to alpha
B.MasterAlpha := Color shr 24;
Color := Color and $00FFFFFF;
P := @B.Bits[0];
for I := 0 to B.Width * B.Height - 1 do
begin
C := P^;
if C <> 0 then
begin
C := P^ shl 24; // transfer blue channel to alpha
C := C + Color;
P^ := C;
end;
Inc(P);
end;
B.DrawMode := dmBlend;
B.DrawTo(Self, X, Y);
finally
B.Free;
end;
end;
//=== { TJclByteMap } ========================================================
destructor TJclByteMap.Destroy;
begin
FBytes := nil;
inherited Destroy;
end;
procedure TJclByteMap.Assign(Source: TPersistent);
begin
Changing;
BeginUpdate;
try
if Source is TJclByteMap then
begin
FWidth := TJclByteMap(Source).Width;
FHeight := TJclByteMap(Source).Height;
FBytes := Copy(TJclByteMap(Source).Bytes, 0, FWidth * FHeight);
end
else
if Source is TJclBitmap32 then
ReadFrom(TJclBitmap32(Source), ckWeightedRGB)
else
inherited Assign(Source);
finally
EndUpdate;
Changed;
end;
end;
procedure TJclByteMap.AssignTo(Dst: TPersistent);
begin
if Dst is TJclBitmap32 then
WriteTo(TJclBitmap32(Dst), ckUniformRGB)
else
inherited AssignTo(Dst);
end;
procedure TJclByteMap.Clear(FillValue: Byte);
begin
Changing;
FillChar(Bytes[0], Width * Height, FillValue);
Changed;
end;
function TJclByteMap.Empty: Boolean;
begin
Result := Bytes = nil;
end;
function TJclByteMap.GetValPtr(X, Y: Integer): PByte;
begin
Result := @Bytes[X + Y * Width];
end;
function TJclByteMap.GetValue(X, Y: Integer): Byte;
begin
Result := Bytes[X + Y * Width];
end;
procedure TJclByteMap.ReadFrom(Source: TJclBitmap32; Conversion: TConversionKind);
var
W, H, I, N: Integer;
SrcC: PColor32;
SrcB, DstB: PByte;
Value: TColor32;
begin
Changing;
BeginUpdate;
try
SetSize(Source.Width, Source.Height);
if Empty then
Exit;
W := Source.Width;
H := Source.Height;
N := W * H - 1;
SrcC := Source.PixelPtr[0, 0];
SrcB := Pointer(SrcC);
DstB := @Bytes[0];
case Conversion of
ckRed:
begin
Inc(SrcB, 2);
for I := 0 to N do
begin
DstB^ := SrcB^;
Inc(DstB);
Inc(SrcB, 4);
end;
end;
ckGreen:
begin
Inc(SrcB, 1);
for I := 0 to N do
begin
DstB^ := SrcB^;
Inc(DstB);
Inc(SrcB, 4);
end;
end;
ckBlue:
begin
for I := 0 to N do
begin
DstB^ := SrcB^;
Inc(DstB);
Inc(SrcB, 4);
end;
end;
ckAlpha:
begin
Inc(SrcB, 3);
for I := 0 to N do
begin
DstB^ := SrcB^;
Inc(DstB);
Inc(SrcB, 4);
end;
end;
ckUniformRGB:
begin
for I := 0 to N do
begin
Value := SrcC^;
Value := (Value and $00FF0000) shr 16 + (Value and $0000FF00) shr 8 +
(Value and $000000FF);
Value := Value div 3;
DstB^ := Value;
Inc(DstB);
Inc(SrcC);
end;
end;
ckWeightedRGB:
begin
for I := 0 to N do
begin
DstB^ := Intensity(SrcC^);
Inc(DstB);
Inc(SrcC);
end;
end;
end;
finally
EndUpdate;
Changed;
end;
end;
procedure TJclByteMap.SetValue(X, Y: Integer; Value: Byte);
begin
Bytes[X + Y * Width] := Value;
end;
procedure TJclByteMap.SetSize(NewWidth, NewHeight: Integer);
begin
Changing;
inherited SetSize(NewWidth, NewHeight);
SetLength(FBytes, Width * Height);
Changed;
end;
procedure TJclByteMap.WriteTo(Dest: TJclBitmap32; Conversion: TConversionKind);
var
W, H, I, N: Integer;
DstC: PColor32;
DstB, SrcB: PByte;
begin
Dest.Changing;
Dest.BeginUpdate;
try
Dest.SetSize(Width, Height);
if Empty then
Exit;
W := Width;
H := Height;
N := W * H - 1;
DstC := Dest.PixelPtr[0, 0];
DstB := Pointer(DstC);
SrcB := @Bytes[0];
case Conversion of
ckRed:
begin
Inc(DstB, 2);
for I := 0 to N do
begin
DstB^ := SrcB^;
Inc(DstB, 4);
Inc(SrcB);
end;
end;
ckGreen:
begin
Inc(DstB, 1);
for I := 0 to N do
begin
DstB^ := SrcB^;
Inc(DstB, 4);
Inc(SrcB);
end;
end;
ckBlue:
begin
for I := 0 to N do
begin
DstB^ := SrcB^;
Inc(DstB, 4);
Inc(SrcB);
end;
end;
ckAlpha:
begin
Inc(DstB, 3);
for I := 0 to N do
begin
DstB^ := SrcB^;
Inc(DstB, 4);
Inc(SrcB);
end;
end;
ckUniformRGB, ckWeightedRGB:
begin
for I := 0 to N do
begin
DstC^ := Gray32(SrcB^, $FF);
Inc(DstC);
Inc(SrcB);
end;
end;
end;
finally
Dest.EndUpdate;
Dest.Changed;
end;
end;
procedure TJclByteMap.WriteTo(Dest: TJclBitmap32; const Palette: TPalette32);
var
W, H, I, N: Integer;
DstC: PColor32;
SrcB: PByte;
begin
Dest.Changing;
Dest.BeginUpdate;
try
Dest.SetSize(Width, Height);
if Empty then
Exit;
W := Width;
H := Height;
N := W * H - 1;
DstC := Dest.PixelPtr[0, 0];
SrcB := @Bytes[0];
for I := 0 to N do
begin
DstC^ := Palette[SrcB^];
Inc(DstC);
Inc(SrcB);
end;
finally
Dest.EndUpdate;
Dest.Changed;
end;
end;
{$ENDIF Bitmap32}
//=== Matrices ===============================================================
{ TODO -oWIMDC -cReplace : Insert JclMatrix support }
function _DET(a1, a2, b1, b2: Extended): Extended; overload;
begin
Result := a1 * b2 - a2 * b1;
end;
function _DET(a1, a2, a3, b1, b2, b3, c1, c2, c3: Extended): Extended; overload;
begin
Result :=
a1 * (b2 * c3 - b3 * c2) -
b1 * (a2 * c3 - a3 * c2) +
c1 * (a2 * b3 - a3 * b2);
end;
procedure Adjoint(var M: TMatrix3d);
var
a1, a2, a3: Extended;
b1, b2, b3: Extended;
c1, c2, c3: Extended;
begin
a1 := M.A[0, 0];
a2 := M.A[0, 1];
a3 := M.A[0, 2];
b1 := M.A[1, 0];
b2 := M.A[1, 1];
b3 := M.A[1, 2];
c1 := M.A[2, 0];
c2 := M.A[2, 1];
c3 := M.A[2, 2];
M.A[0, 0]:= _DET(b2, b3, c2, c3);
M.A[0, 1]:= -_DET(a2, a3, c2, c3);
M.A[0, 2]:= _DET(a2, a3, b2, b3);
M.A[1, 0]:= -_DET(b1, b3, c1, c3);
M.A[1, 1]:= _DET(a1, a3, c1, c3);
M.A[1, 2]:= -_DET(a1, a3, b1, b3);
M.A[2, 0]:= _DET(b1, b2, c1, c2);
M.A[2, 1]:= -_DET(a1, a2, c1, c2);
M.A[2, 2]:= _DET(a1, a2, b1, b2);
end;
function Determinant(const M: TMatrix3d): Extended;
begin
Result := _DET(
M.A[0, 0], M.A[1, 0], M.A[2, 0],
M.A[0, 1], M.A[1, 1], M.A[2, 1],
M.A[0, 2], M.A[1, 2], M.A[2, 2]);
end;
procedure Scale(var M: TMatrix3d; Factor: Extended);
var
I, J: Integer;
begin
for I := 0 to 2 do
for J := 0 to 2 do
M.A[I, J] := M.A[I, J] * Factor;
end;
procedure InvertMatrix(var M: TMatrix3d);
var
Det: Extended;
begin
Det := Determinant(M);
if Abs(Det) < 1E-5 then
M := IdentityMatrix
else
begin
Adjoint(M);
Scale(M, 1 / Det);
end;
end;
function Mult(const M1, M2: TMatrix3d): TMatrix3d;
var
I, J: Integer;
begin
for I := 0 to 2 do
for J := 0 to 2 do
Result.A[I, J] :=
M1.A[0, J] * M2.A[I, 0] +
M1.A[1, J] * M2.A[I, 1] +
M1.A[2, J] * M2.A[I, 2];
end;
type
TVector3d = array [0..2] of Extended;
TVector3i = array [0..2] of Integer;
function VectorTransform(const M: TMatrix3d; const V: TVector3d): TVector3d;
begin
Result[0] := M.A[0, 0] * V[0] + M.A[1, 0] * V[1] + M.A[2, 0] * V[2];
Result[1] := M.A[0, 1] * V[0] + M.A[1, 1] * V[1] + M.A[2, 1] * V[2];
Result[2] := M.A[0, 2] * V[0] + M.A[1, 2] * V[1] + M.A[2, 2] * V[2];
end;
//=== { TJclLinearTransformation } ===========================================
constructor TJclLinearTransformation.Create;
begin
inherited Create;
Clear;
end;
procedure TJclLinearTransformation.Clear;
begin
FMatrix := IdentityMatrix;
end;
function TJclLinearTransformation.GetTransformedBounds(const Src: TRect): TRect;
var
V1, V2, V3, V4: TVector3d;
begin
V1[0] := Src.Left;
V1[1] := Src.Top;
V1[2] := 1;
V2[0] := Src.Right - 1;
V2[1] := V1[1];
V2[2] := 1;
V3[0] := V1[0];
V3[1] := Src.Bottom - 1;
V3[2] := 1;
V4[0] := V2[0];
V4[1] := V3[1];
V4[2] := 1;
V1 := VectorTransform(Matrix, V1);
V2 := VectorTransform(Matrix, V2);
V3 := VectorTransform(Matrix, V3);
V4 := VectorTransform(Matrix, V4);
Result.Left := Round(Min(Min(V1[0], V2[0]), Min(V3[0], V4[0])) - 0.5);
Result.Right := Round(Max(Max(V1[0], V2[0]), Max(V3[0], V4[0])) + 0.5);
Result.Top := Round(Min(Min(V1[1], V2[1]), Min(V3[1], V4[1])) - 0.5);
Result.Bottom := Round(Max(Max(V1[1], V2[1]), Max(V3[1], V4[1])) + 0.5);
end;
procedure TJclLinearTransformation.PrepareTransform;
var
M: TMatrix3d;
begin
M := Matrix;
InvertMatrix(M);
// calculate a fixed point (4096) factors
A := Round(M.A[0, 0] * 4096);
B := Round(M.A[1, 0] * 4096);
C := Round(M.A[2, 0] * 4096);
D := Round(M.A[0, 1] * 4096);
E := Round(M.A[1, 1] * 4096);
F := Round(M.A[2, 1] * 4096);
end;
procedure TJclLinearTransformation.Rotate(Cx, Cy, Alpha: Extended);
var
S, C: Extended;
M: TMatrix3d;
begin
if (Cx <> 0) and (Cy <> 0) then
Translate(-Cx, -Cy);
SinCos(DegToRad(Alpha), S, C);
M := IdentityMatrix;
M.A[0, 0] := C;
M.A[1, 0] := S;
M.A[0, 1] := -S;
M.A[1, 1] := C;
FMatrix := Mult(M, FMatrix);
if (Cx <> 0) and (Cy <> 0) then
Translate(Cx, Cy);
end;
procedure TJclLinearTransformation.Scale(Sx, Sy: Extended);
var
M: TMatrix3d;
begin
M := IdentityMatrix;
M.A[0, 0] := Sx;
M.A[1, 1] := Sy;
FMatrix := Mult(M, FMatrix);
end;
procedure TJclLinearTransformation.Skew(Fx, Fy: Extended);
var
M: TMatrix3d;
begin
M := IdentityMatrix;
M.A[1, 0] := Fx;
M.A[0, 1] := Fy;
FMatrix := Mult(M, FMatrix);
end;
procedure TJclLinearTransformation.Transform(DstX, DstY: Integer;
out SrcX, SrcY: Integer);
begin
SrcX := Sar(DstX * A + DstY * B + C, 12);
SrcY := Sar(DstX * D + DstY * E + F, 12);
end;
procedure TJclLinearTransformation.Transform256(DstX, DstY: Integer;
out SrcX256, SrcY256: Integer);
begin
SrcX256 := Sar(DstX * A + DstY * B + C, 4);
SrcY256 := Sar(DstX * D + DstY * E + F, 4);
end;
procedure TJclLinearTransformation.Translate(Dx, Dy: Extended);
var
M: TMatrix3d;
begin
M := IdentityMatrix;
M.A[2, 0] := Dx;
M.A[2, 1] := Dy;
FMatrix := Mult(M, FMatrix);
end;
//=== PolyLines and Polygons =================================================
{$IFDEF Bitmap32}
procedure PolylineTS(Bitmap: TJclBitmap32; const Points: TDynPointArray;
Color: TColor32);
var
I, L: Integer;
DoAlpha: Boolean;
begin
DoAlpha := Color and $FF000000 <> $FF000000;
L := Length(Points);
if L < 2 then
Exit;
Bitmap.Changing;
Bitmap.BeginUpdate;
with Points[L - 1] do
Bitmap.MoveTo(X, Y);
Bitmap.PenColor := Color;
if DoAlpha then
for I := 0 to L - 1 do
with Points[I] do
Bitmap.LineToTS(X, Y)
else
for I := 0 to L - 1 do
with Points[I] do
Bitmap.LineToS(X, Y);
Bitmap.EndUpdate;
Bitmap.Changed;
end;
procedure PolyLineAS(Bitmap: TJclBitmap32; const Points: TDynPointArray;
Color: TColor32);
var
I, L: Integer;
begin
L := Length(Points);
if L < 2 then
Exit;
Bitmap.Changing;
Bitmap.BeginUpdate;
with Points[L - 1] do
Bitmap.MoveTo(X, Y);
Bitmap.PenColor := Color;
for I := 0 to L - 1 do
with Points[I] do
Bitmap.LineToAS(X, Y);
Bitmap.EndUpdate;
Bitmap.Changed;
end;
procedure PolylineFS(Bitmap: TJclBitmap32; const Points: TDynPointArrayF;
Color: TColor32);
var
I, L: Integer;
begin
L := Length(Points);
if L < 2 then
Exit;
Bitmap.Changing;
Bitmap.BeginUpdate;
with Points[L - 1] do
Bitmap.MoveToF(X, Y);
Bitmap.PenColor := Color;
for I := 0 to L - 1 do
with Points[I] do
Bitmap.LineToFS(X, Y);
Bitmap.EndUpdate;
Bitmap.Changed;
end;
{$ENDIF Bitmap32}
procedure QSortLine(const ALine: TScanLine; L, R: Integer);
var
I, J, P: Integer;
begin
repeat
I := L;
J := R;
P := ALine[(L + R) shr 1];
repeat
while ALine[I] < P do
Inc(I);
while ALine[J] > P do
Dec(J);
if I <= J then
begin
SwapOrd(ALine[I], ALine[J]);
Inc(I);
Dec(J);
end;
until I > J;
if L < J then
QSortLine(ALine, L, J);
L := I;
until I >= R;
end;
procedure SortLine(const ALine: TScanLine);
var
L: Integer;
begin
L := Length(ALine);
Assert(not Odd(L));
if L = 2 then
TestSwap(ALine[0], ALine[1])
else
if L > 2 then
QSortLine(ALine, 0, L - 1);
end;
procedure SortLines(const ScanLines: TScanLines);
var
I: Integer;
begin
for I := 0 to High(ScanLines) do
SortLine(ScanLines[I]);
end;
procedure AddPolygon(const Points: TDynPointArray; BaseY: Integer;
MaxX, MaxY: Integer; var ScanLines: TScanLines; SubSampleX: Boolean);
var
I, X1, Y1, X2, Y2: Integer;
Direction, PrevDirection: Integer; // up = 1 or down = -1
procedure AddEdgePoint(X, Y: Integer);
var
L: Integer;
begin
if (Y < 0) or (Y > MaxY) then
Exit;
X := Constrain(X, 0, MaxX);
L := Length(ScanLines[Y - BaseY]);
SetLength(ScanLines[Y - BaseY], L + 1);
ScanLines[Y - BaseY][L] := X;
end;
procedure DrawEdge(X1, Y1, X2, Y2: Integer);
var
X, Y, I: Integer;
Dx, Dy, Sx, Sy: Integer;
Delta: Integer;
begin
// this function 'renders' a line into the edge (ScanLines) buffer
if Y2 = Y1 then
Exit;
Dx := X2 - X1;
Dy := Y2 - Y1;
if Dy > 0 then
Sy := 1
else
begin
Sy := -1;
Dy := -Dy;
end;
if Dx > 0 then
Sx := 1
else
begin
Sx := -1;
Dx := -Dx;
end;
Delta := (Dx mod Dy) shr 1;
X := X1;
Y := Y1;
for I := 0 to Dy - 1 do
begin
AddEdgePoint(X, Y);
Inc(Y, Sy);
Inc(Delta, Dx);
while Delta > Dy do
begin
Inc(X, Sx);
Dec(Delta, Dy);
end;
end;
end;
begin
X1 := Points[0].X;
Y1 := Points[0].Y;
if SubSampleX then
X1 := X1 shl 8;
// find the last Y different from Y1 and assign it to Y0
PrevDirection := 0;
for I := High(Points) downto 1 do
begin
if Points[I].Y > Y1 then
PrevDirection := -1
else
if Points[I].Y < Y1 then
PrevDirection := 1
else
Continue;
Break;
end;
Assert(PrevDirection <> 0);
for I := 1 to High(Points) do
begin
X2 := Points[I].X;
Y2 := Points[I].Y;
if SubSampleX then
X2 := X2 shl 8;
if Y1 <> Y2 then
begin
DrawEdge(X1, Y1, X2, Y2);
if Y2 > Y1 then
Direction := 1 // up
else
Direction := -1; // down
if Direction <> PrevDirection then
begin
AddEdgePoint(X1, Y1);
PrevDirection := Direction;
end;
end;
X1 := X2;
Y1 := Y2;
end;
X2 := Points[0].X;
Y2 := Points[0].Y;
if SubSampleX then
X2 := X2 shl 8;
if Y1 <> Y2 then
begin
DrawEdge(X1, Y1, X2, Y2);
if Y2 > Y1 then
Direction := 1
else
Direction := -1;
if Direction <> PrevDirection then
AddEdgePoint(X1, Y1);
end;
end;
{$IFDEF Bitmap32}
procedure FillLines(Bitmap: TJclBitmap32; BaseY: Integer;
const ScanLines: TScanLines; Color: TColor32);
var
I, J, L: Integer;
Left, Right: Integer;
DoAlpha: Boolean;
begin
DoAlpha := Color and $FF000000 <> $FF000000;
for J := 0 to High(ScanLines) do
begin
L := Length(ScanLines[J]); // assuming length is even
I := 0;
while I < L do
begin
Left := ScanLines[J][I];
Inc(I);
Right := ScanLines[J][I];
if Right > Left then
begin
if (Left and $FF) < $80 then
Left := Left shr 8
else
Left := Left shr 8 + 1;
if (Right and $FF) < $80 then
Right := Right shr 8
else
Right := Right shr 8 + 1;
if DoAlpha then
Bitmap.DrawHorzLineT(Left, BaseY + J, Right, Color)
else
Bitmap.DrawHorzLine(Left, BaseY + J, Right, Color);
end;
Inc(I);
end;
end;
end;
procedure FillLines2(Bitmap: TJclBitmap32; BaseY: Integer;
const ScanLines: TScanLines; Color: TColor32);
var
I, J, L, N: Integer;
MinY, MaxY, Y, Top, Bottom: Integer;
MinX, MaxX, X, Dx: Integer;
Left, Right: Integer;
Buffer: array of Integer;
P: PColor32;
DoAlpha: Boolean;
begin
DoAlpha := Color and $FF000000 <> $FF000000;
// find the range of Y screen coordinates
MinY := BaseY shr 4;
MaxY := (BaseY + Length(ScanLines) + 15) shr 4;
Y := MinY;
while Y < MaxY do
begin
Top := Y shl 4 - BaseY;
Bottom := Top + 15;
if Top < 0 then
Top := 0;
if Bottom > High(ScanLines) then
Bottom := High(ScanLines);
// find left and right edges of the screen scanline
MinX := 1000000;
MaxX := -1000000;
for J := Top to Bottom do
begin
L := High(ScanLines[J]);
Left := ScanLines[J][0] shr 4;
Right := (ScanLines[J][L] + 15) shr 4;
if Left < MinX then
MinX := Left;
if Right > MaxX then
MaxX := Right;
end;
// allocate the buffer for a screen scanline
SetLength(Buffer, MaxX - MinX + 2);
FillLongword(Buffer[0], Length(Buffer), 0);
// and fill it
for J := Top to Bottom do
begin
I := 0;
L := Length(ScanLines[J]);
while I < L do
begin
// Left edge
X := ScanLines[J][I];
Dx := X and $0F;
X := X shr 4 - MinX;
Inc(Buffer[X], Dx xor $0F);
Inc(Buffer[X + 1], Dx);
Inc(I);
// Right edge
X := ScanLines[J][I];
Dx := X and $0F;
X := X shr 4 - MinX;
Dec(Buffer[X], Dx xor $0F);
Dec(Buffer[X + 1], Dx);
Inc(I);
end;
end;
// integrate the buffer
N := 0;
for I := 0 to High(Buffer) do
begin
Inc(N, Buffer[I]);
Buffer[I] := N * 273 shr 8; // some bias
end;
// draw it to the screen
P := Bitmap.PixelPtr[MinX, Y];
try
if DoAlpha then
for I := 0 to High(Buffer) do
begin
BlendMemEx(Color, P^, Buffer[I]);
Inc(P);
end
else
for I := 0 to High(Buffer) do
begin
N := Buffer[I];
if N = 255 then
P^ := Color
else
BlendMemEx(Color, P^, Buffer[I]);
Inc(P);
end;
finally
EMMS;
end;
Inc(Y);
end;
end;
procedure GetMinMax(const Points: TDynPointArray; out MinY, MaxY: Integer);
var
I, Y: Integer;
begin
MinY := 100000;
MaxY := -100000;
for I := 0 to High(Points) do
begin
Y := Points[I].Y;
if Y < MinY then
MinY := Y;
if Y > MaxY then
MaxY := Y;
end;
end;
procedure PolygonTS(Bitmap: TJclBitmap32; const Points: TDynPointArray; Color: TColor32);
var
L, MinY, MaxY: Integer;
ScanLines: TScanLines;
begin
L := Length(Points);
if L < 3 then
Exit;
GetMinMax(Points, MinY, MaxY);
MinY := Constrain(MinY, 0, Bitmap.Height);
MaxY := Constrain(MaxY, 0, Bitmap.Height);
if MinY >= MaxY then
Exit;
SetLength(ScanLines, MaxY - MinY + 1);
AddPolygon(Points, MinY, Bitmap.Width shl 8 - 1, Bitmap.Height - 1,
ScanLines, True);
SortLines(ScanLines);
Bitmap.Changing;
Bitmap.BeginUpdate;
try
FillLines(Bitmap, MinY, ScanLines, Color);
finally
Bitmap.EndUpdate;
Bitmap.Changed;
end;
end;
procedure PolygonAS(Bitmap: TJclBitmap32; const Points: TDynPointArray; Color: TColor32);
var
L, I, MinY, MaxY: Integer;
ScanLines: TScanLines;
PP: TDynPointArray;
begin
L := Length(Points);
if L < 3 then
Exit;
SetLength(PP, L);
for I := 0 to L - 1 do
begin
PP[I].X := Points[I].X shl 4 + 7;
PP[I].Y := Points[I].Y shl 4 + 7;
end;
GetMinMax(PP, MinY, MaxY);
MinY := Constrain(MinY, 0, Bitmap.Height shl 4 - 1);
MaxY := Constrain(MaxY, 0, Bitmap.Height shl 4 - 1);
if MinY >= MaxY then
Exit;
SetLength(ScanLines, MaxY - MinY + 1);
AddPolygon(PP, MinY, Bitmap.Width shl 4 - 1, Bitmap.Height shl 4 - 1,
ScanLines, False);
SortLines(ScanLines);
Bitmap.Changing;
Bitmap.BeginUpdate;
try
FillLines2(Bitmap, MinY, ScanLines, Color);
finally
Bitmap.EndUpdate;
Bitmap.Changed;
end;
end;
procedure PolygonFS(Bitmap: TJclBitmap32; const Points: TDynPointArrayF; Color: TColor32);
var
L, I, MinY, MaxY: Integer;
ScanLines: TScanLines;
PP: TDynPointArray;
begin
L := Length(Points);
if L < 3 then
Exit;
SetLength(PP, L);
for I := 0 to L - 1 do
begin
PP[I].X := Round(Points[I].X * 16) + 7;
PP[I].Y := Round(Points[I].Y * 16) + 7;
end;
GetMinMax(PP, MinY, MaxY);
MinY := Constrain(MinY, 0, Bitmap.Height shl 4 - 1);
MaxY := Constrain(MaxY, 0, Bitmap.Height shl 4 - 1);
if MinY >= MaxY then
Exit;
SetLength(ScanLines, MaxY - MinY + 1);
AddPolygon(PP, MinY, Bitmap.Width shl 4 - 1, Bitmap.Height shl 4 - 1,
ScanLines, False);
SortLines(ScanLines);
Bitmap.Changing;
Bitmap.BeginUpdate;
try
FillLines2(Bitmap, MinY, ScanLines, Color);
finally
Bitmap.EndUpdate;
Bitmap.Changed;
end;
end;
procedure PolyPolygonTS(Bitmap: TJclBitmap32; const Points: TDynDynPointArrayArray;
Color: TColor32);
var
N, L, min, max, MinY, MaxY: Integer;
ScanLines: TScanLines;
begin
MinY := 100000;
MaxY := -100000;
for N := 0 to High(Points) do
begin
L := Length(Points[N]);
if L < 3 then
Exit;
GetMinMax(Points[N], min, max);
if min < MinY then
MinY := min;
if max > MaxY then
MaxY := max;
end;
MinY := Constrain(MinY, 0, Bitmap.Height - 1);
MaxY := Constrain(MaxY, 0, Bitmap.Height - 1);
if MinY >= MaxY then
Exit;
SetLength(ScanLines, MaxY - MinY + 1);
for N := 0 to High(Points) do
AddPolygon(Points[N], MinY, Bitmap.Width shl 8 - 1 , Bitmap.Height - 1,
ScanLines, True);
SortLines(ScanLines);
Bitmap.Changing;
FillLines(Bitmap, MinY, ScanLines, Color);
Bitmap.Changed;
end;
procedure PolyPolygonAS(Bitmap: TJclBitmap32; const Points: TDynDynPointArrayArray;
Color: TColor32);
var
N, L, I, min, max, MinY, MaxY: Integer;
ScanLines: TScanLines;
PPP: TDynDynPointArrayArray;
begin
MinY := 100000;
MaxY := -100000;
SetLength(PPP, Length(Points));
for N := 0 to High(Points) do
begin
L := Length(Points);
SetLength(PPP[N], Length(Points[N]));
for I := 0 to L - 1 do
begin
PPP[N][I].X := Points[N][I].X shl 4 + 7;
PPP[N][I].Y := Points[N][I].Y shl 4 + 7;
end;
if L < 3 then
Continue;
GetMinMax(PPP[N], min, max);
if min < MinY then
MinY := min;
if max > MaxY then
MaxY := max;
end;
MinY := Constrain(MinY, 0, Bitmap.Height shl 4 - 1);
MaxY := Constrain(MaxY, 0, Bitmap.Height shl 4 - 1);
if MinY >= MaxY then
Exit;
SetLength(ScanLines, MaxY - MinY + 1);
for N := 0 to High(PPP) do
begin
AddPolygon(PPP[N], MinY, Bitmap.Width shl 4 - 1, Bitmap.Height shl 4 - 1,
ScanLines, False);
end;
SortLines(ScanLines);
Bitmap.Changing;
FillLines2(Bitmap, MinY, ScanLines, Color);
Bitmap.Changed;
end;
procedure PolyPolygonFS(Bitmap: TJclBitmap32; const Points: TDynDynPointArrayArrayF;
Color: TColor32);
var
N, L, I, min, max, MinY, MaxY: Integer;
ScanLines: TScanLines;
PPP: TDynDynPointArrayArray;
begin
MinY := 100000;
MaxY := -100000;
SetLength(PPP, Length(Points));
for N := 0 to High(Points) do
begin
L := Length(Points);
SetLength(PPP[N], Length(Points[N]));
for I := 0 to L - 1 do
begin
PPP[N][I].X := Round(Points[N][I].X * 16) + 7;
PPP[N][I].Y := Round(Points[N][I].Y * 16) + 7;
end;
if L < 3 then
Continue;
GetMinMax(PPP[N], min, max);
if min < MinY then
MinY := min;
if max > MaxY then
MaxY := max;
end;
MinY := Constrain(MinY, 0, Bitmap.Height shl 4 - 1);
MaxY := Constrain(MaxY, 0, Bitmap.Height shl 4 - 1);
if MinY >= MaxY then
Exit;
SetLength(ScanLines, MaxY - MinY + 1);
for N := 0 to High(PPP) do
AddPolygon(PPP[N], MinY, Bitmap.Width shl 4 - 1, Bitmap.Height shl 4 - 1,
ScanLines, False);
SortLines(ScanLines);
Bitmap.Changing;
FillLines2(Bitmap, MinY, ScanLines, Color);
Bitmap.Changed;
end;
//=== Filters ================================================================
procedure CheckParams(Dst, Src: TJclBitmap32);
begin
if Src = nil then
raise EJclGraphicsError.CreateRes(@RsSourceBitmapEmpty);
if Dst = nil then
raise EJclGraphicsError.CreateRes(@RsDestinationBitmapEmpty);
Dst.SetSize(Src.Width, Src.Height); // Should this go? See #0001513. It is currently of no use.
end;
procedure AlphaToGrayscale(Dst, Src: TJclBitmap32);
var
I: Integer;
D, S: PColor32;
begin
CheckParams(Dst, Src);
Dst.Changing;
Dst.SetSize(Src.Width, Src.Height);
D := @Dst.Bits[0];
S := @Src.Bits[0];
for I := 0 to Src.Width * Src.Height - 1 do
begin
D^ := Gray32(AlphaComponent(S^), $FF);
Inc(S);
Inc(D);
end;
Dst.Changed;
end;
procedure IntensityToAlpha(Dst, Src: TJclBitmap32);
var
I: Integer;
D, S: PColor32;
begin
CheckParams(Dst, Src);
Dst.Changing;
Dst.SetSize(Src.Width, Src.Height);
D := @Dst.Bits[0];
S := @Src.Bits[0];
for I := 0 to Src.Width * Src.Height - 1 do
begin
D^ := SetAlpha(D^, Intensity(S^));
Inc(S);
Inc(D);
end;
Dst.Changed;
end;
procedure Invert(Dst, Src: TJclBitmap32);
var
I: Integer;
D, S: PColor32;
begin
CheckParams(Dst, Src);
Dst.Changing;
Dst.SetSize(Src.Width, Src.Height);
D := @Dst.Bits[0];
S := @Src.Bits[0];
for I := 0 to Src.Width * Src.Height - 1 do
begin
D^ := S^ xor $FFFFFFFF;
Inc(S);
Inc(D);
end;
Dst.Changed;
end;
procedure InvertRGB(Dst, Src: TJclBitmap32);
var
I: Integer;
D, S: PColor32;
begin
CheckParams(Dst, Src);
Dst.Changing;
Dst.SetSize(Src.Width, Src.Height);
D := @Dst.Bits[0];
S := @Src.Bits[0];
for I := 0 to Src.Width * Src.Height - 1 do
begin
D^ := S^ xor $00FFFFFF;
Inc(S);
Inc(D);
end;
Dst.Changed;
end;
procedure ColorToGrayscale(Dst, Src: TJclBitmap32);
var
I: Integer;
D, S: PColor32;
begin
CheckParams(Dst, Src);
Dst.Changing;
Dst.SetSize(Src.Width, Src.Height);
D := @Dst.Bits[0];
S := @Src.Bits[0];
for I := 0 to Src.Width * Src.Height - 1 do
begin
D^ := Gray32(Intensity(S^), $FF);
Inc(S);
Inc(D);
end;
Dst.Changed;
end;
procedure ApplyLUT(Dst, Src: TJclBitmap32; const LUT: TLUT8);
var
I: Integer;
D, S: PColor32;
r, g, b: TColor32;
C: TColor32;
begin
CheckParams(Dst, Src);
Dst.Changing;
Dst.SetSize(Src.Width, Src.Height);
D := @Dst.Bits[0];
S := @Src.Bits[0];
for I := 0 to Src.Width * Src.Height - 1 do
begin
C := S^;
r := C and $00FF0000;
g := C and $0000FF00;
r := r shr 16;
b := C and $000000FF;
g := g shr 8;
r := LUT[r];
g := LUT[g];
b := LUT[b];
D^ := $FF000000 or r shl 16 or g shl 8 or b;
Inc(S);
Inc(D);
end;
Dst.Changed;
end;
{$ENDIF Bitmap32}
// Gamma table support for opacities
procedure SetGamma(Gamma: Single);
var
I: Integer;
begin
for I := Low(GAMMA_TABLE) to High(GAMMA_TABLE) do
GAMMA_TABLE[I] := Round(255 * Power(I / 255, Gamma));
end;
// modify Jan 28, 2001 for use under BCB5
// the compiler show error 245 "language feature ist not available"
// we must take a record and under this we can use the static array
procedure SetIdentityMatrix;
begin
IdentityMatrix.A[0, 0] := 1.0;
IdentityMatrix.A[0, 1] := 0.0;
IdentityMatrix.A[0, 2] := 0.0;
IdentityMatrix.A[1, 0] := 0.0;
IdentityMatrix.A[1, 1] := 1.0;
IdentityMatrix.A[1, 2] := 0.0;
IdentityMatrix.A[2, 0] := 0.0;
IdentityMatrix.A[2, 1] := 0.0;
IdentityMatrix.A[2, 2] := 1.0;
end;
initialization
SetIdentityMatrix;
SetGamma(0.7);
{$IFDEF UNITVERSIONING}
RegisterUnitVersion(HInstance, UnitVersioning);
finalization
UnregisterUnitVersion(HInstance);
{$ENDIF UNITVERSIONING}
end.
| 26.673603 | 128 | 0.588993 |
f18d5bbd1fe9319f167069e5d09b5331d33a482d | 795,765 | pas | Pascal | components/jcl/source/common/JclSortedMaps.pas | padcom/delcos | dc9e8ac8545c0e6c0b4e963d5baf0dc7d72d2bf0 | [
"Apache-2.0"
]
| 15 | 2016-08-24T07:32:49.000Z | 2021-11-16T11:25:00.000Z | components/jcl/source/common/JclSortedMaps.pas | CWBudde/delcos | 656384c43c2980990ea691e4e52752d718fb0277 | [
"Apache-2.0"
]
| 1 | 2016-08-24T19:00:34.000Z | 2016-08-25T19:02:14.000Z | components/jcl/source/common/JclSortedMaps.pas | padcom/delcos | dc9e8ac8545c0e6c0b4e963d5baf0dc7d72d2bf0 | [
"Apache-2.0"
]
| 4 | 2015-11-06T12:15:36.000Z | 2018-10-08T15:17:17.000Z | {**************************************************************************************************}
{ WARNING: JEDI preprocessor generated unit. Do not edit. }
{**************************************************************************************************}
{**************************************************************************************************}
{ }
{ Project JEDI Code Library (JCL) }
{ }
{ 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 JclSortedMaps.pas. }
{ }
{ The Initial Developer of the Original Code is Florent Ouchet. Portions created by }
{ Florent Ouchet are Copyright (C) Florent Ouchet <outchy att users dott sourceforge dott net }
{ All rights reserved. }
{ }
{ Contributors: }
{ }
{**************************************************************************************************}
{ }
{ The Delphi Container Library }
{ }
{**************************************************************************************************}
{ }
{ Last modified: $Date:: 2010-08-09 17:10:10 +0200 (lun., 09 août 2010) $ }
{ Revision: $Rev:: 3291 $ }
{ Author: $Author:: outchy $ }
{ }
{**************************************************************************************************}
unit JclSortedMaps;
interface
{$I jcl.inc}
uses
Classes,
{$IFDEF UNITVERSIONING}
JclUnitVersioning,
{$ENDIF UNITVERSIONING}
JclAlgorithms,
JclBase, JclSynch,
JclAbstractContainers, JclContainerIntf, JclArrayLists, JclArraySets;
type
TJclIntfIntfSortedEntry = record
Key: IInterface;
Value: IInterface;
end;
TJclIntfIntfSortedMap = class(TJclIntfAbstractContainer, {$IFDEF THREADSAFE} IJclLockable, {$ENDIF THREADSAFE}
IJclIntfCloneable, IJclCloneable, IJclGrowable, IJclPackable, IJclContainer,
IJclIntfIntfMap, IJclIntfIntfSortedMap)
protected
function CreateEmptyContainer: TJclAbstractContainerBase; override;
function FreeKey(var Key: IInterface): IInterface;
function FreeValue(var Value: IInterface): IInterface;
function KeysCompare(const A, B: IInterface): Integer;
function ValuesCompare(const A, B: IInterface): Integer;
private
FEntries: array of TJclIntfIntfSortedEntry;
function BinarySearch(const Key: IInterface): Integer;
protected
procedure AssignDataTo(Dest: TJclAbstractContainerBase); override;
procedure MoveArray(FromIndex, ToIndex, Count: Integer);
public
constructor Create(ACapacity: Integer);
destructor Destroy; override;
{ IJclPackable }
procedure SetCapacity(Value: Integer); override;
{ IJclIntfIntfMap }
procedure Clear;
function ContainsKey(const Key: IInterface): Boolean;
function ContainsValue(const Value: IInterface): Boolean;
function Extract(const Key: IInterface): IInterface;
function GetValue(const Key: IInterface): IInterface;
function IsEmpty: Boolean;
function KeyOfValue(const Value: IInterface): IInterface;
function KeySet: IJclIntfSet;
function MapEquals(const AMap: IJclIntfIntfMap): Boolean;
procedure PutAll(const AMap: IJclIntfIntfMap);
procedure PutValue(const Key: IInterface; const Value: IInterface);
function Remove(const Key: IInterface): IInterface;
function Size: Integer;
function Values: IJclIntfCollection;
{ IJclIntfIntfSortedMap }
function FirstKey: IInterface;
function HeadMap(const ToKey: IInterface): IJclIntfIntfSortedMap;
function LastKey: IInterface;
function SubMap(const FromKey, ToKey: IInterface): IJclIntfIntfSortedMap;
function TailMap(const FromKey: IInterface): IJclIntfIntfSortedMap;
end;
TJclAnsiStrIntfSortedEntry = record
Key: AnsiString;
Value: IInterface;
end;
TJclAnsiStrIntfSortedMap = class(TJclAnsiStrAbstractContainer, {$IFDEF THREADSAFE} IJclLockable, {$ENDIF THREADSAFE}
IJclIntfCloneable, IJclCloneable, IJclGrowable, IJclPackable, IJclContainer, IJclStrContainer, IJclAnsiStrContainer,
IJclAnsiStrIntfMap, IJclAnsiStrIntfSortedMap)
protected
function CreateEmptyContainer: TJclAbstractContainerBase; override;
function FreeKey(var Key: AnsiString): AnsiString;
function FreeValue(var Value: IInterface): IInterface;
function KeysCompare(const A, B: AnsiString): Integer;
function ValuesCompare(const A, B: IInterface): Integer;
private
FEntries: array of TJclAnsiStrIntfSortedEntry;
function BinarySearch(const Key: AnsiString): Integer;
protected
procedure AssignDataTo(Dest: TJclAbstractContainerBase); override;
procedure MoveArray(FromIndex, ToIndex, Count: Integer);
public
constructor Create(ACapacity: Integer);
destructor Destroy; override;
{ IJclPackable }
procedure SetCapacity(Value: Integer); override;
{ IJclAnsiStrIntfMap }
procedure Clear;
function ContainsKey(const Key: AnsiString): Boolean;
function ContainsValue(const Value: IInterface): Boolean;
function Extract(const Key: AnsiString): IInterface;
function GetValue(const Key: AnsiString): IInterface;
function IsEmpty: Boolean;
function KeyOfValue(const Value: IInterface): AnsiString;
function KeySet: IJclAnsiStrSet;
function MapEquals(const AMap: IJclAnsiStrIntfMap): Boolean;
procedure PutAll(const AMap: IJclAnsiStrIntfMap);
procedure PutValue(const Key: AnsiString; const Value: IInterface);
function Remove(const Key: AnsiString): IInterface;
function Size: Integer;
function Values: IJclIntfCollection;
{ IJclAnsiStrIntfSortedMap }
function FirstKey: AnsiString;
function HeadMap(const ToKey: AnsiString): IJclAnsiStrIntfSortedMap;
function LastKey: AnsiString;
function SubMap(const FromKey, ToKey: AnsiString): IJclAnsiStrIntfSortedMap;
function TailMap(const FromKey: AnsiString): IJclAnsiStrIntfSortedMap;
end;
TJclIntfAnsiStrSortedEntry = record
Key: IInterface;
Value: AnsiString;
end;
TJclIntfAnsiStrSortedMap = class(TJclAnsiStrAbstractContainer, {$IFDEF THREADSAFE} IJclLockable, {$ENDIF THREADSAFE}
IJclIntfCloneable, IJclCloneable, IJclGrowable, IJclPackable, IJclContainer, IJclStrContainer, IJclAnsiStrContainer,
IJclIntfAnsiStrMap, IJclIntfAnsiStrSortedMap)
protected
function CreateEmptyContainer: TJclAbstractContainerBase; override;
function FreeKey(var Key: IInterface): IInterface;
function FreeValue(var Value: AnsiString): AnsiString;
function KeysCompare(const A, B: IInterface): Integer;
function ValuesCompare(const A, B: AnsiString): Integer;
private
FEntries: array of TJclIntfAnsiStrSortedEntry;
function BinarySearch(const Key: IInterface): Integer;
protected
procedure AssignDataTo(Dest: TJclAbstractContainerBase); override;
procedure MoveArray(FromIndex, ToIndex, Count: Integer);
public
constructor Create(ACapacity: Integer);
destructor Destroy; override;
{ IJclPackable }
procedure SetCapacity(Value: Integer); override;
{ IJclIntfAnsiStrMap }
procedure Clear;
function ContainsKey(const Key: IInterface): Boolean;
function ContainsValue(const Value: AnsiString): Boolean;
function Extract(const Key: IInterface): AnsiString;
function GetValue(const Key: IInterface): AnsiString;
function IsEmpty: Boolean;
function KeyOfValue(const Value: AnsiString): IInterface;
function KeySet: IJclIntfSet;
function MapEquals(const AMap: IJclIntfAnsiStrMap): Boolean;
procedure PutAll(const AMap: IJclIntfAnsiStrMap);
procedure PutValue(const Key: IInterface; const Value: AnsiString);
function Remove(const Key: IInterface): AnsiString;
function Size: Integer;
function Values: IJclAnsiStrCollection;
{ IJclIntfAnsiStrSortedMap }
function FirstKey: IInterface;
function HeadMap(const ToKey: IInterface): IJclIntfAnsiStrSortedMap;
function LastKey: IInterface;
function SubMap(const FromKey, ToKey: IInterface): IJclIntfAnsiStrSortedMap;
function TailMap(const FromKey: IInterface): IJclIntfAnsiStrSortedMap;
end;
TJclAnsiStrAnsiStrSortedEntry = record
Key: AnsiString;
Value: AnsiString;
end;
TJclAnsiStrAnsiStrSortedMap = class(TJclAnsiStrAbstractContainer, {$IFDEF THREADSAFE} IJclLockable, {$ENDIF THREADSAFE}
IJclIntfCloneable, IJclCloneable, IJclGrowable, IJclPackable, IJclContainer, IJclStrContainer, IJclAnsiStrContainer,
IJclAnsiStrAnsiStrMap, IJclAnsiStrAnsiStrSortedMap)
protected
function CreateEmptyContainer: TJclAbstractContainerBase; override;
function FreeKey(var Key: AnsiString): AnsiString;
function FreeValue(var Value: AnsiString): AnsiString;
function KeysCompare(const A, B: AnsiString): Integer;
function ValuesCompare(const A, B: AnsiString): Integer;
private
FEntries: array of TJclAnsiStrAnsiStrSortedEntry;
function BinarySearch(const Key: AnsiString): Integer;
protected
procedure AssignDataTo(Dest: TJclAbstractContainerBase); override;
procedure MoveArray(FromIndex, ToIndex, Count: Integer);
public
constructor Create(ACapacity: Integer);
destructor Destroy; override;
{ IJclPackable }
procedure SetCapacity(Value: Integer); override;
{ IJclAnsiStrAnsiStrMap }
procedure Clear;
function ContainsKey(const Key: AnsiString): Boolean;
function ContainsValue(const Value: AnsiString): Boolean;
function Extract(const Key: AnsiString): AnsiString;
function GetValue(const Key: AnsiString): AnsiString;
function IsEmpty: Boolean;
function KeyOfValue(const Value: AnsiString): AnsiString;
function KeySet: IJclAnsiStrSet;
function MapEquals(const AMap: IJclAnsiStrAnsiStrMap): Boolean;
procedure PutAll(const AMap: IJclAnsiStrAnsiStrMap);
procedure PutValue(const Key: AnsiString; const Value: AnsiString);
function Remove(const Key: AnsiString): AnsiString;
function Size: Integer;
function Values: IJclAnsiStrCollection;
{ IJclAnsiStrAnsiStrSortedMap }
function FirstKey: AnsiString;
function HeadMap(const ToKey: AnsiString): IJclAnsiStrAnsiStrSortedMap;
function LastKey: AnsiString;
function SubMap(const FromKey, ToKey: AnsiString): IJclAnsiStrAnsiStrSortedMap;
function TailMap(const FromKey: AnsiString): IJclAnsiStrAnsiStrSortedMap;
end;
TJclWideStrIntfSortedEntry = record
Key: WideString;
Value: IInterface;
end;
TJclWideStrIntfSortedMap = class(TJclWideStrAbstractContainer, {$IFDEF THREADSAFE} IJclLockable, {$ENDIF THREADSAFE}
IJclIntfCloneable, IJclCloneable, IJclGrowable, IJclPackable, IJclContainer, IJclStrContainer, IJclWideStrContainer,
IJclWideStrIntfMap, IJclWideStrIntfSortedMap)
protected
function CreateEmptyContainer: TJclAbstractContainerBase; override;
function FreeKey(var Key: WideString): WideString;
function FreeValue(var Value: IInterface): IInterface;
function KeysCompare(const A, B: WideString): Integer;
function ValuesCompare(const A, B: IInterface): Integer;
private
FEntries: array of TJclWideStrIntfSortedEntry;
function BinarySearch(const Key: WideString): Integer;
protected
procedure AssignDataTo(Dest: TJclAbstractContainerBase); override;
procedure MoveArray(FromIndex, ToIndex, Count: Integer);
public
constructor Create(ACapacity: Integer);
destructor Destroy; override;
{ IJclPackable }
procedure SetCapacity(Value: Integer); override;
{ IJclWideStrIntfMap }
procedure Clear;
function ContainsKey(const Key: WideString): Boolean;
function ContainsValue(const Value: IInterface): Boolean;
function Extract(const Key: WideString): IInterface;
function GetValue(const Key: WideString): IInterface;
function IsEmpty: Boolean;
function KeyOfValue(const Value: IInterface): WideString;
function KeySet: IJclWideStrSet;
function MapEquals(const AMap: IJclWideStrIntfMap): Boolean;
procedure PutAll(const AMap: IJclWideStrIntfMap);
procedure PutValue(const Key: WideString; const Value: IInterface);
function Remove(const Key: WideString): IInterface;
function Size: Integer;
function Values: IJclIntfCollection;
{ IJclWideStrIntfSortedMap }
function FirstKey: WideString;
function HeadMap(const ToKey: WideString): IJclWideStrIntfSortedMap;
function LastKey: WideString;
function SubMap(const FromKey, ToKey: WideString): IJclWideStrIntfSortedMap;
function TailMap(const FromKey: WideString): IJclWideStrIntfSortedMap;
end;
TJclIntfWideStrSortedEntry = record
Key: IInterface;
Value: WideString;
end;
TJclIntfWideStrSortedMap = class(TJclWideStrAbstractContainer, {$IFDEF THREADSAFE} IJclLockable, {$ENDIF THREADSAFE}
IJclIntfCloneable, IJclCloneable, IJclGrowable, IJclPackable, IJclContainer, IJclStrContainer, IJclWideStrContainer,
IJclIntfWideStrMap, IJclIntfWideStrSortedMap)
protected
function CreateEmptyContainer: TJclAbstractContainerBase; override;
function FreeKey(var Key: IInterface): IInterface;
function FreeValue(var Value: WideString): WideString;
function KeysCompare(const A, B: IInterface): Integer;
function ValuesCompare(const A, B: WideString): Integer;
private
FEntries: array of TJclIntfWideStrSortedEntry;
function BinarySearch(const Key: IInterface): Integer;
protected
procedure AssignDataTo(Dest: TJclAbstractContainerBase); override;
procedure MoveArray(FromIndex, ToIndex, Count: Integer);
public
constructor Create(ACapacity: Integer);
destructor Destroy; override;
{ IJclPackable }
procedure SetCapacity(Value: Integer); override;
{ IJclIntfWideStrMap }
procedure Clear;
function ContainsKey(const Key: IInterface): Boolean;
function ContainsValue(const Value: WideString): Boolean;
function Extract(const Key: IInterface): WideString;
function GetValue(const Key: IInterface): WideString;
function IsEmpty: Boolean;
function KeyOfValue(const Value: WideString): IInterface;
function KeySet: IJclIntfSet;
function MapEquals(const AMap: IJclIntfWideStrMap): Boolean;
procedure PutAll(const AMap: IJclIntfWideStrMap);
procedure PutValue(const Key: IInterface; const Value: WideString);
function Remove(const Key: IInterface): WideString;
function Size: Integer;
function Values: IJclWideStrCollection;
{ IJclIntfWideStrSortedMap }
function FirstKey: IInterface;
function HeadMap(const ToKey: IInterface): IJclIntfWideStrSortedMap;
function LastKey: IInterface;
function SubMap(const FromKey, ToKey: IInterface): IJclIntfWideStrSortedMap;
function TailMap(const FromKey: IInterface): IJclIntfWideStrSortedMap;
end;
TJclWideStrWideStrSortedEntry = record
Key: WideString;
Value: WideString;
end;
TJclWideStrWideStrSortedMap = class(TJclWideStrAbstractContainer, {$IFDEF THREADSAFE} IJclLockable, {$ENDIF THREADSAFE}
IJclIntfCloneable, IJclCloneable, IJclGrowable, IJclPackable, IJclContainer, IJclStrContainer, IJclWideStrContainer,
IJclWideStrWideStrMap, IJclWideStrWideStrSortedMap)
protected
function CreateEmptyContainer: TJclAbstractContainerBase; override;
function FreeKey(var Key: WideString): WideString;
function FreeValue(var Value: WideString): WideString;
function KeysCompare(const A, B: WideString): Integer;
function ValuesCompare(const A, B: WideString): Integer;
private
FEntries: array of TJclWideStrWideStrSortedEntry;
function BinarySearch(const Key: WideString): Integer;
protected
procedure AssignDataTo(Dest: TJclAbstractContainerBase); override;
procedure MoveArray(FromIndex, ToIndex, Count: Integer);
public
constructor Create(ACapacity: Integer);
destructor Destroy; override;
{ IJclPackable }
procedure SetCapacity(Value: Integer); override;
{ IJclWideStrWideStrMap }
procedure Clear;
function ContainsKey(const Key: WideString): Boolean;
function ContainsValue(const Value: WideString): Boolean;
function Extract(const Key: WideString): WideString;
function GetValue(const Key: WideString): WideString;
function IsEmpty: Boolean;
function KeyOfValue(const Value: WideString): WideString;
function KeySet: IJclWideStrSet;
function MapEquals(const AMap: IJclWideStrWideStrMap): Boolean;
procedure PutAll(const AMap: IJclWideStrWideStrMap);
procedure PutValue(const Key: WideString; const Value: WideString);
function Remove(const Key: WideString): WideString;
function Size: Integer;
function Values: IJclWideStrCollection;
{ IJclWideStrWideStrSortedMap }
function FirstKey: WideString;
function HeadMap(const ToKey: WideString): IJclWideStrWideStrSortedMap;
function LastKey: WideString;
function SubMap(const FromKey, ToKey: WideString): IJclWideStrWideStrSortedMap;
function TailMap(const FromKey: WideString): IJclWideStrWideStrSortedMap;
end;
{$IFDEF SUPPORTS_UNICODE_STRING}
TJclUnicodeStrIntfSortedEntry = record
Key: UnicodeString;
Value: IInterface;
end;
{$ENDIF SUPPORTS_UNICODE_STRING}
{$IFDEF SUPPORTS_UNICODE_STRING}
TJclUnicodeStrIntfSortedMap = class(TJclUnicodeStrAbstractContainer, {$IFDEF THREADSAFE} IJclLockable, {$ENDIF THREADSAFE}
IJclIntfCloneable, IJclCloneable, IJclGrowable, IJclPackable, IJclContainer, IJclStrContainer, IJclUnicodeStrContainer,
IJclUnicodeStrIntfMap, IJclUnicodeStrIntfSortedMap)
protected
function CreateEmptyContainer: TJclAbstractContainerBase; override;
function FreeKey(var Key: UnicodeString): UnicodeString;
function FreeValue(var Value: IInterface): IInterface;
function KeysCompare(const A, B: UnicodeString): Integer;
function ValuesCompare(const A, B: IInterface): Integer;
private
FEntries: array of TJclUnicodeStrIntfSortedEntry;
function BinarySearch(const Key: UnicodeString): Integer;
protected
procedure AssignDataTo(Dest: TJclAbstractContainerBase); override;
procedure MoveArray(FromIndex, ToIndex, Count: Integer);
public
constructor Create(ACapacity: Integer);
destructor Destroy; override;
{ IJclPackable }
procedure SetCapacity(Value: Integer); override;
{ IJclUnicodeStrIntfMap }
procedure Clear;
function ContainsKey(const Key: UnicodeString): Boolean;
function ContainsValue(const Value: IInterface): Boolean;
function Extract(const Key: UnicodeString): IInterface;
function GetValue(const Key: UnicodeString): IInterface;
function IsEmpty: Boolean;
function KeyOfValue(const Value: IInterface): UnicodeString;
function KeySet: IJclUnicodeStrSet;
function MapEquals(const AMap: IJclUnicodeStrIntfMap): Boolean;
procedure PutAll(const AMap: IJclUnicodeStrIntfMap);
procedure PutValue(const Key: UnicodeString; const Value: IInterface);
function Remove(const Key: UnicodeString): IInterface;
function Size: Integer;
function Values: IJclIntfCollection;
{ IJclUnicodeStrIntfSortedMap }
function FirstKey: UnicodeString;
function HeadMap(const ToKey: UnicodeString): IJclUnicodeStrIntfSortedMap;
function LastKey: UnicodeString;
function SubMap(const FromKey, ToKey: UnicodeString): IJclUnicodeStrIntfSortedMap;
function TailMap(const FromKey: UnicodeString): IJclUnicodeStrIntfSortedMap;
end;
{$ENDIF SUPPORTS_UNICODE_STRING}
{$IFDEF SUPPORTS_UNICODE_STRING}
TJclIntfUnicodeStrSortedEntry = record
Key: IInterface;
Value: UnicodeString;
end;
{$ENDIF SUPPORTS_UNICODE_STRING}
{$IFDEF SUPPORTS_UNICODE_STRING}
TJclIntfUnicodeStrSortedMap = class(TJclUnicodeStrAbstractContainer, {$IFDEF THREADSAFE} IJclLockable, {$ENDIF THREADSAFE}
IJclIntfCloneable, IJclCloneable, IJclGrowable, IJclPackable, IJclContainer, IJclStrContainer, IJclUnicodeStrContainer,
IJclIntfUnicodeStrMap, IJclIntfUnicodeStrSortedMap)
protected
function CreateEmptyContainer: TJclAbstractContainerBase; override;
function FreeKey(var Key: IInterface): IInterface;
function FreeValue(var Value: UnicodeString): UnicodeString;
function KeysCompare(const A, B: IInterface): Integer;
function ValuesCompare(const A, B: UnicodeString): Integer;
private
FEntries: array of TJclIntfUnicodeStrSortedEntry;
function BinarySearch(const Key: IInterface): Integer;
protected
procedure AssignDataTo(Dest: TJclAbstractContainerBase); override;
procedure MoveArray(FromIndex, ToIndex, Count: Integer);
public
constructor Create(ACapacity: Integer);
destructor Destroy; override;
{ IJclPackable }
procedure SetCapacity(Value: Integer); override;
{ IJclIntfUnicodeStrMap }
procedure Clear;
function ContainsKey(const Key: IInterface): Boolean;
function ContainsValue(const Value: UnicodeString): Boolean;
function Extract(const Key: IInterface): UnicodeString;
function GetValue(const Key: IInterface): UnicodeString;
function IsEmpty: Boolean;
function KeyOfValue(const Value: UnicodeString): IInterface;
function KeySet: IJclIntfSet;
function MapEquals(const AMap: IJclIntfUnicodeStrMap): Boolean;
procedure PutAll(const AMap: IJclIntfUnicodeStrMap);
procedure PutValue(const Key: IInterface; const Value: UnicodeString);
function Remove(const Key: IInterface): UnicodeString;
function Size: Integer;
function Values: IJclUnicodeStrCollection;
{ IJclIntfUnicodeStrSortedMap }
function FirstKey: IInterface;
function HeadMap(const ToKey: IInterface): IJclIntfUnicodeStrSortedMap;
function LastKey: IInterface;
function SubMap(const FromKey, ToKey: IInterface): IJclIntfUnicodeStrSortedMap;
function TailMap(const FromKey: IInterface): IJclIntfUnicodeStrSortedMap;
end;
{$ENDIF SUPPORTS_UNICODE_STRING}
{$IFDEF SUPPORTS_UNICODE_STRING}
TJclUnicodeStrUnicodeStrSortedEntry = record
Key: UnicodeString;
Value: UnicodeString;
end;
{$ENDIF SUPPORTS_UNICODE_STRING}
{$IFDEF SUPPORTS_UNICODE_STRING}
TJclUnicodeStrUnicodeStrSortedMap = class(TJclUnicodeStrAbstractContainer, {$IFDEF THREADSAFE} IJclLockable, {$ENDIF THREADSAFE}
IJclIntfCloneable, IJclCloneable, IJclGrowable, IJclPackable, IJclContainer, IJclStrContainer, IJclUnicodeStrContainer,
IJclUnicodeStrUnicodeStrMap, IJclUnicodeStrUnicodeStrSortedMap)
protected
function CreateEmptyContainer: TJclAbstractContainerBase; override;
function FreeKey(var Key: UnicodeString): UnicodeString;
function FreeValue(var Value: UnicodeString): UnicodeString;
function KeysCompare(const A, B: UnicodeString): Integer;
function ValuesCompare(const A, B: UnicodeString): Integer;
private
FEntries: array of TJclUnicodeStrUnicodeStrSortedEntry;
function BinarySearch(const Key: UnicodeString): Integer;
protected
procedure AssignDataTo(Dest: TJclAbstractContainerBase); override;
procedure MoveArray(FromIndex, ToIndex, Count: Integer);
public
constructor Create(ACapacity: Integer);
destructor Destroy; override;
{ IJclPackable }
procedure SetCapacity(Value: Integer); override;
{ IJclUnicodeStrUnicodeStrMap }
procedure Clear;
function ContainsKey(const Key: UnicodeString): Boolean;
function ContainsValue(const Value: UnicodeString): Boolean;
function Extract(const Key: UnicodeString): UnicodeString;
function GetValue(const Key: UnicodeString): UnicodeString;
function IsEmpty: Boolean;
function KeyOfValue(const Value: UnicodeString): UnicodeString;
function KeySet: IJclUnicodeStrSet;
function MapEquals(const AMap: IJclUnicodeStrUnicodeStrMap): Boolean;
procedure PutAll(const AMap: IJclUnicodeStrUnicodeStrMap);
procedure PutValue(const Key: UnicodeString; const Value: UnicodeString);
function Remove(const Key: UnicodeString): UnicodeString;
function Size: Integer;
function Values: IJclUnicodeStrCollection;
{ IJclUnicodeStrUnicodeStrSortedMap }
function FirstKey: UnicodeString;
function HeadMap(const ToKey: UnicodeString): IJclUnicodeStrUnicodeStrSortedMap;
function LastKey: UnicodeString;
function SubMap(const FromKey, ToKey: UnicodeString): IJclUnicodeStrUnicodeStrSortedMap;
function TailMap(const FromKey: UnicodeString): IJclUnicodeStrUnicodeStrSortedMap;
end;
{$ENDIF SUPPORTS_UNICODE_STRING}
{$IFDEF CONTAINER_ANSISTR}
TJclStrIntfSortedEntry = TJclAnsiStrIntfSortedEntry;
{$ENDIF CONTAINER_ANSISTR}
{$IFDEF CONTAINER_WIDESTR}
TJclStrIntfSortedEntry = TJclWideStrIntfSortedEntry;
{$ENDIF CONTAINER_WIDESTR}
{$IFDEF CONTAINER_UNICODESTR}
TJclStrIntfSortedEntry = TJclUnicodeStrIntfSortedEntry;
{$ENDIF CONTAINER_UNICODESTR}
{$IFDEF CONTAINER_ANSISTR}
TJclStrIntfSortedMap = TJclAnsiStrIntfSortedMap;
{$ENDIF CONTAINER_ANSISTR}
{$IFDEF CONTAINER_WIDESTR}
TJclStrIntfSortedMap = TJclWideStrIntfSortedMap;
{$ENDIF CONTAINER_WIDESTR}
{$IFDEF CONTAINER_UNICODESTR}
TJclStrIntfSortedMap = TJclUnicodeStrIntfSortedMap;
{$ENDIF CONTAINER_UNICODESTR}
{$IFDEF CONTAINER_ANSISTR}
TJclIntfStrSortedEntry = TJclIntfAnsiStrSortedEntry;
{$ENDIF CONTAINER_ANSISTR}
{$IFDEF CONTAINER_WIDESTR}
TJclIntfStrSortedEntry = TJclIntfWideStrSortedEntry;
{$ENDIF CONTAINER_WIDESTR}
{$IFDEF CONTAINER_UNICODESTR}
TJclIntfStrSortedEntry = TJclIntfUnicodeStrSortedEntry;
{$ENDIF CONTAINER_UNICODESTR}
{$IFDEF CONTAINER_ANSISTR}
TJclIntfStrSortedMap = TJclIntfAnsiStrSortedMap;
{$ENDIF CONTAINER_ANSISTR}
{$IFDEF CONTAINER_WIDESTR}
TJclIntfStrSortedMap = TJclIntfWideStrSortedMap;
{$ENDIF CONTAINER_WIDESTR}
{$IFDEF CONTAINER_UNICODESTR}
TJclIntfStrSortedMap = TJclIntfUnicodeStrSortedMap;
{$ENDIF CONTAINER_UNICODESTR}
{$IFDEF CONTAINER_ANSISTR}
TJclStrStrSortedEntry = TJclAnsiStrAnsiStrSortedEntry;
{$ENDIF CONTAINER_ANSISTR}
{$IFDEF CONTAINER_WIDESTR}
TJclStrStrSortedEntry = TJclWideStrWideStrSortedEntry;
{$ENDIF CONTAINER_WIDESTR}
{$IFDEF CONTAINER_UNICODESTR}
TJclStrStrSortedEntry = TJclUnicodeStrUnicodeStrSortedEntry;
{$ENDIF CONTAINER_UNICODESTR}
{$IFDEF CONTAINER_ANSISTR}
TJclStrStrSortedMap = TJclAnsiStrAnsiStrSortedMap;
{$ENDIF CONTAINER_ANSISTR}
{$IFDEF CONTAINER_WIDESTR}
TJclStrStrSortedMap = TJclWideStrWideStrSortedMap;
{$ENDIF CONTAINER_WIDESTR}
{$IFDEF CONTAINER_UNICODESTR}
TJclStrStrSortedMap = TJclUnicodeStrUnicodeStrSortedMap;
{$ENDIF CONTAINER_UNICODESTR}
TJclSingleIntfSortedEntry = record
Key: Single;
Value: IInterface;
end;
TJclSingleIntfSortedMap = class(TJclSingleAbstractContainer, {$IFDEF THREADSAFE} IJclLockable, {$ENDIF THREADSAFE}
IJclIntfCloneable, IJclCloneable, IJclGrowable, IJclPackable, IJclContainer, IJclSingleContainer,
IJclSingleIntfMap, IJclSingleIntfSortedMap)
protected
function CreateEmptyContainer: TJclAbstractContainerBase; override;
function FreeKey(var Key: Single): Single;
function FreeValue(var Value: IInterface): IInterface;
function KeysCompare(const A, B: Single): Integer;
function ValuesCompare(const A, B: IInterface): Integer;
private
FEntries: array of TJclSingleIntfSortedEntry;
function BinarySearch(const Key: Single): Integer;
protected
procedure AssignDataTo(Dest: TJclAbstractContainerBase); override;
procedure MoveArray(FromIndex, ToIndex, Count: Integer);
public
constructor Create(ACapacity: Integer);
destructor Destroy; override;
{ IJclPackable }
procedure SetCapacity(Value: Integer); override;
{ IJclSingleIntfMap }
procedure Clear;
function ContainsKey(const Key: Single): Boolean;
function ContainsValue(const Value: IInterface): Boolean;
function Extract(const Key: Single): IInterface;
function GetValue(const Key: Single): IInterface;
function IsEmpty: Boolean;
function KeyOfValue(const Value: IInterface): Single;
function KeySet: IJclSingleSet;
function MapEquals(const AMap: IJclSingleIntfMap): Boolean;
procedure PutAll(const AMap: IJclSingleIntfMap);
procedure PutValue(const Key: Single; const Value: IInterface);
function Remove(const Key: Single): IInterface;
function Size: Integer;
function Values: IJclIntfCollection;
{ IJclSingleIntfSortedMap }
function FirstKey: Single;
function HeadMap(const ToKey: Single): IJclSingleIntfSortedMap;
function LastKey: Single;
function SubMap(const FromKey, ToKey: Single): IJclSingleIntfSortedMap;
function TailMap(const FromKey: Single): IJclSingleIntfSortedMap;
end;
TJclIntfSingleSortedEntry = record
Key: IInterface;
Value: Single;
end;
TJclIntfSingleSortedMap = class(TJclSingleAbstractContainer, {$IFDEF THREADSAFE} IJclLockable, {$ENDIF THREADSAFE}
IJclIntfCloneable, IJclCloneable, IJclGrowable, IJclPackable, IJclContainer, IJclSingleContainer,
IJclIntfSingleMap, IJclIntfSingleSortedMap)
protected
function CreateEmptyContainer: TJclAbstractContainerBase; override;
function FreeKey(var Key: IInterface): IInterface;
function FreeValue(var Value: Single): Single;
function KeysCompare(const A, B: IInterface): Integer;
function ValuesCompare(const A, B: Single): Integer;
private
FEntries: array of TJclIntfSingleSortedEntry;
function BinarySearch(const Key: IInterface): Integer;
protected
procedure AssignDataTo(Dest: TJclAbstractContainerBase); override;
procedure MoveArray(FromIndex, ToIndex, Count: Integer);
public
constructor Create(ACapacity: Integer);
destructor Destroy; override;
{ IJclPackable }
procedure SetCapacity(Value: Integer); override;
{ IJclIntfSingleMap }
procedure Clear;
function ContainsKey(const Key: IInterface): Boolean;
function ContainsValue(const Value: Single): Boolean;
function Extract(const Key: IInterface): Single;
function GetValue(const Key: IInterface): Single;
function IsEmpty: Boolean;
function KeyOfValue(const Value: Single): IInterface;
function KeySet: IJclIntfSet;
function MapEquals(const AMap: IJclIntfSingleMap): Boolean;
procedure PutAll(const AMap: IJclIntfSingleMap);
procedure PutValue(const Key: IInterface; const Value: Single);
function Remove(const Key: IInterface): Single;
function Size: Integer;
function Values: IJclSingleCollection;
{ IJclIntfSingleSortedMap }
function FirstKey: IInterface;
function HeadMap(const ToKey: IInterface): IJclIntfSingleSortedMap;
function LastKey: IInterface;
function SubMap(const FromKey, ToKey: IInterface): IJclIntfSingleSortedMap;
function TailMap(const FromKey: IInterface): IJclIntfSingleSortedMap;
end;
TJclSingleSingleSortedEntry = record
Key: Single;
Value: Single;
end;
TJclSingleSingleSortedMap = class(TJclSingleAbstractContainer, {$IFDEF THREADSAFE} IJclLockable, {$ENDIF THREADSAFE}
IJclIntfCloneable, IJclCloneable, IJclGrowable, IJclPackable, IJclContainer, IJclSingleContainer,
IJclSingleSingleMap, IJclSingleSingleSortedMap)
protected
function CreateEmptyContainer: TJclAbstractContainerBase; override;
function FreeKey(var Key: Single): Single;
function FreeValue(var Value: Single): Single;
function KeysCompare(const A, B: Single): Integer;
function ValuesCompare(const A, B: Single): Integer;
private
FEntries: array of TJclSingleSingleSortedEntry;
function BinarySearch(const Key: Single): Integer;
protected
procedure AssignDataTo(Dest: TJclAbstractContainerBase); override;
procedure MoveArray(FromIndex, ToIndex, Count: Integer);
public
constructor Create(ACapacity: Integer);
destructor Destroy; override;
{ IJclPackable }
procedure SetCapacity(Value: Integer); override;
{ IJclSingleSingleMap }
procedure Clear;
function ContainsKey(const Key: Single): Boolean;
function ContainsValue(const Value: Single): Boolean;
function Extract(const Key: Single): Single;
function GetValue(const Key: Single): Single;
function IsEmpty: Boolean;
function KeyOfValue(const Value: Single): Single;
function KeySet: IJclSingleSet;
function MapEquals(const AMap: IJclSingleSingleMap): Boolean;
procedure PutAll(const AMap: IJclSingleSingleMap);
procedure PutValue(const Key: Single; const Value: Single);
function Remove(const Key: Single): Single;
function Size: Integer;
function Values: IJclSingleCollection;
{ IJclSingleSingleSortedMap }
function FirstKey: Single;
function HeadMap(const ToKey: Single): IJclSingleSingleSortedMap;
function LastKey: Single;
function SubMap(const FromKey, ToKey: Single): IJclSingleSingleSortedMap;
function TailMap(const FromKey: Single): IJclSingleSingleSortedMap;
end;
TJclDoubleIntfSortedEntry = record
Key: Double;
Value: IInterface;
end;
TJclDoubleIntfSortedMap = class(TJclDoubleAbstractContainer, {$IFDEF THREADSAFE} IJclLockable, {$ENDIF THREADSAFE}
IJclIntfCloneable, IJclCloneable, IJclGrowable, IJclPackable, IJclContainer, IJclDoubleContainer,
IJclDoubleIntfMap, IJclDoubleIntfSortedMap)
protected
function CreateEmptyContainer: TJclAbstractContainerBase; override;
function FreeKey(var Key: Double): Double;
function FreeValue(var Value: IInterface): IInterface;
function KeysCompare(const A, B: Double): Integer;
function ValuesCompare(const A, B: IInterface): Integer;
private
FEntries: array of TJclDoubleIntfSortedEntry;
function BinarySearch(const Key: Double): Integer;
protected
procedure AssignDataTo(Dest: TJclAbstractContainerBase); override;
procedure MoveArray(FromIndex, ToIndex, Count: Integer);
public
constructor Create(ACapacity: Integer);
destructor Destroy; override;
{ IJclPackable }
procedure SetCapacity(Value: Integer); override;
{ IJclDoubleIntfMap }
procedure Clear;
function ContainsKey(const Key: Double): Boolean;
function ContainsValue(const Value: IInterface): Boolean;
function Extract(const Key: Double): IInterface;
function GetValue(const Key: Double): IInterface;
function IsEmpty: Boolean;
function KeyOfValue(const Value: IInterface): Double;
function KeySet: IJclDoubleSet;
function MapEquals(const AMap: IJclDoubleIntfMap): Boolean;
procedure PutAll(const AMap: IJclDoubleIntfMap);
procedure PutValue(const Key: Double; const Value: IInterface);
function Remove(const Key: Double): IInterface;
function Size: Integer;
function Values: IJclIntfCollection;
{ IJclDoubleIntfSortedMap }
function FirstKey: Double;
function HeadMap(const ToKey: Double): IJclDoubleIntfSortedMap;
function LastKey: Double;
function SubMap(const FromKey, ToKey: Double): IJclDoubleIntfSortedMap;
function TailMap(const FromKey: Double): IJclDoubleIntfSortedMap;
end;
TJclIntfDoubleSortedEntry = record
Key: IInterface;
Value: Double;
end;
TJclIntfDoubleSortedMap = class(TJclDoubleAbstractContainer, {$IFDEF THREADSAFE} IJclLockable, {$ENDIF THREADSAFE}
IJclIntfCloneable, IJclCloneable, IJclGrowable, IJclPackable, IJclContainer, IJclDoubleContainer,
IJclIntfDoubleMap, IJclIntfDoubleSortedMap)
protected
function CreateEmptyContainer: TJclAbstractContainerBase; override;
function FreeKey(var Key: IInterface): IInterface;
function FreeValue(var Value: Double): Double;
function KeysCompare(const A, B: IInterface): Integer;
function ValuesCompare(const A, B: Double): Integer;
private
FEntries: array of TJclIntfDoubleSortedEntry;
function BinarySearch(const Key: IInterface): Integer;
protected
procedure AssignDataTo(Dest: TJclAbstractContainerBase); override;
procedure MoveArray(FromIndex, ToIndex, Count: Integer);
public
constructor Create(ACapacity: Integer);
destructor Destroy; override;
{ IJclPackable }
procedure SetCapacity(Value: Integer); override;
{ IJclIntfDoubleMap }
procedure Clear;
function ContainsKey(const Key: IInterface): Boolean;
function ContainsValue(const Value: Double): Boolean;
function Extract(const Key: IInterface): Double;
function GetValue(const Key: IInterface): Double;
function IsEmpty: Boolean;
function KeyOfValue(const Value: Double): IInterface;
function KeySet: IJclIntfSet;
function MapEquals(const AMap: IJclIntfDoubleMap): Boolean;
procedure PutAll(const AMap: IJclIntfDoubleMap);
procedure PutValue(const Key: IInterface; const Value: Double);
function Remove(const Key: IInterface): Double;
function Size: Integer;
function Values: IJclDoubleCollection;
{ IJclIntfDoubleSortedMap }
function FirstKey: IInterface;
function HeadMap(const ToKey: IInterface): IJclIntfDoubleSortedMap;
function LastKey: IInterface;
function SubMap(const FromKey, ToKey: IInterface): IJclIntfDoubleSortedMap;
function TailMap(const FromKey: IInterface): IJclIntfDoubleSortedMap;
end;
TJclDoubleDoubleSortedEntry = record
Key: Double;
Value: Double;
end;
TJclDoubleDoubleSortedMap = class(TJclDoubleAbstractContainer, {$IFDEF THREADSAFE} IJclLockable, {$ENDIF THREADSAFE}
IJclIntfCloneable, IJclCloneable, IJclGrowable, IJclPackable, IJclContainer, IJclDoubleContainer,
IJclDoubleDoubleMap, IJclDoubleDoubleSortedMap)
protected
function CreateEmptyContainer: TJclAbstractContainerBase; override;
function FreeKey(var Key: Double): Double;
function FreeValue(var Value: Double): Double;
function KeysCompare(const A, B: Double): Integer;
function ValuesCompare(const A, B: Double): Integer;
private
FEntries: array of TJclDoubleDoubleSortedEntry;
function BinarySearch(const Key: Double): Integer;
protected
procedure AssignDataTo(Dest: TJclAbstractContainerBase); override;
procedure MoveArray(FromIndex, ToIndex, Count: Integer);
public
constructor Create(ACapacity: Integer);
destructor Destroy; override;
{ IJclPackable }
procedure SetCapacity(Value: Integer); override;
{ IJclDoubleDoubleMap }
procedure Clear;
function ContainsKey(const Key: Double): Boolean;
function ContainsValue(const Value: Double): Boolean;
function Extract(const Key: Double): Double;
function GetValue(const Key: Double): Double;
function IsEmpty: Boolean;
function KeyOfValue(const Value: Double): Double;
function KeySet: IJclDoubleSet;
function MapEquals(const AMap: IJclDoubleDoubleMap): Boolean;
procedure PutAll(const AMap: IJclDoubleDoubleMap);
procedure PutValue(const Key: Double; const Value: Double);
function Remove(const Key: Double): Double;
function Size: Integer;
function Values: IJclDoubleCollection;
{ IJclDoubleDoubleSortedMap }
function FirstKey: Double;
function HeadMap(const ToKey: Double): IJclDoubleDoubleSortedMap;
function LastKey: Double;
function SubMap(const FromKey, ToKey: Double): IJclDoubleDoubleSortedMap;
function TailMap(const FromKey: Double): IJclDoubleDoubleSortedMap;
end;
TJclExtendedIntfSortedEntry = record
Key: Extended;
Value: IInterface;
end;
TJclExtendedIntfSortedMap = class(TJclExtendedAbstractContainer, {$IFDEF THREADSAFE} IJclLockable, {$ENDIF THREADSAFE}
IJclIntfCloneable, IJclCloneable, IJclGrowable, IJclPackable, IJclContainer, IJclExtendedContainer,
IJclExtendedIntfMap, IJclExtendedIntfSortedMap)
protected
function CreateEmptyContainer: TJclAbstractContainerBase; override;
function FreeKey(var Key: Extended): Extended;
function FreeValue(var Value: IInterface): IInterface;
function KeysCompare(const A, B: Extended): Integer;
function ValuesCompare(const A, B: IInterface): Integer;
private
FEntries: array of TJclExtendedIntfSortedEntry;
function BinarySearch(const Key: Extended): Integer;
protected
procedure AssignDataTo(Dest: TJclAbstractContainerBase); override;
procedure MoveArray(FromIndex, ToIndex, Count: Integer);
public
constructor Create(ACapacity: Integer);
destructor Destroy; override;
{ IJclPackable }
procedure SetCapacity(Value: Integer); override;
{ IJclExtendedIntfMap }
procedure Clear;
function ContainsKey(const Key: Extended): Boolean;
function ContainsValue(const Value: IInterface): Boolean;
function Extract(const Key: Extended): IInterface;
function GetValue(const Key: Extended): IInterface;
function IsEmpty: Boolean;
function KeyOfValue(const Value: IInterface): Extended;
function KeySet: IJclExtendedSet;
function MapEquals(const AMap: IJclExtendedIntfMap): Boolean;
procedure PutAll(const AMap: IJclExtendedIntfMap);
procedure PutValue(const Key: Extended; const Value: IInterface);
function Remove(const Key: Extended): IInterface;
function Size: Integer;
function Values: IJclIntfCollection;
{ IJclExtendedIntfSortedMap }
function FirstKey: Extended;
function HeadMap(const ToKey: Extended): IJclExtendedIntfSortedMap;
function LastKey: Extended;
function SubMap(const FromKey, ToKey: Extended): IJclExtendedIntfSortedMap;
function TailMap(const FromKey: Extended): IJclExtendedIntfSortedMap;
end;
TJclIntfExtendedSortedEntry = record
Key: IInterface;
Value: Extended;
end;
TJclIntfExtendedSortedMap = class(TJclExtendedAbstractContainer, {$IFDEF THREADSAFE} IJclLockable, {$ENDIF THREADSAFE}
IJclIntfCloneable, IJclCloneable, IJclGrowable, IJclPackable, IJclContainer, IJclExtendedContainer,
IJclIntfExtendedMap, IJclIntfExtendedSortedMap)
protected
function CreateEmptyContainer: TJclAbstractContainerBase; override;
function FreeKey(var Key: IInterface): IInterface;
function FreeValue(var Value: Extended): Extended;
function KeysCompare(const A, B: IInterface): Integer;
function ValuesCompare(const A, B: Extended): Integer;
private
FEntries: array of TJclIntfExtendedSortedEntry;
function BinarySearch(const Key: IInterface): Integer;
protected
procedure AssignDataTo(Dest: TJclAbstractContainerBase); override;
procedure MoveArray(FromIndex, ToIndex, Count: Integer);
public
constructor Create(ACapacity: Integer);
destructor Destroy; override;
{ IJclPackable }
procedure SetCapacity(Value: Integer); override;
{ IJclIntfExtendedMap }
procedure Clear;
function ContainsKey(const Key: IInterface): Boolean;
function ContainsValue(const Value: Extended): Boolean;
function Extract(const Key: IInterface): Extended;
function GetValue(const Key: IInterface): Extended;
function IsEmpty: Boolean;
function KeyOfValue(const Value: Extended): IInterface;
function KeySet: IJclIntfSet;
function MapEquals(const AMap: IJclIntfExtendedMap): Boolean;
procedure PutAll(const AMap: IJclIntfExtendedMap);
procedure PutValue(const Key: IInterface; const Value: Extended);
function Remove(const Key: IInterface): Extended;
function Size: Integer;
function Values: IJclExtendedCollection;
{ IJclIntfExtendedSortedMap }
function FirstKey: IInterface;
function HeadMap(const ToKey: IInterface): IJclIntfExtendedSortedMap;
function LastKey: IInterface;
function SubMap(const FromKey, ToKey: IInterface): IJclIntfExtendedSortedMap;
function TailMap(const FromKey: IInterface): IJclIntfExtendedSortedMap;
end;
TJclExtendedExtendedSortedEntry = record
Key: Extended;
Value: Extended;
end;
TJclExtendedExtendedSortedMap = class(TJclExtendedAbstractContainer, {$IFDEF THREADSAFE} IJclLockable, {$ENDIF THREADSAFE}
IJclIntfCloneable, IJclCloneable, IJclGrowable, IJclPackable, IJclContainer, IJclExtendedContainer,
IJclExtendedExtendedMap, IJclExtendedExtendedSortedMap)
protected
function CreateEmptyContainer: TJclAbstractContainerBase; override;
function FreeKey(var Key: Extended): Extended;
function FreeValue(var Value: Extended): Extended;
function KeysCompare(const A, B: Extended): Integer;
function ValuesCompare(const A, B: Extended): Integer;
private
FEntries: array of TJclExtendedExtendedSortedEntry;
function BinarySearch(const Key: Extended): Integer;
protected
procedure AssignDataTo(Dest: TJclAbstractContainerBase); override;
procedure MoveArray(FromIndex, ToIndex, Count: Integer);
public
constructor Create(ACapacity: Integer);
destructor Destroy; override;
{ IJclPackable }
procedure SetCapacity(Value: Integer); override;
{ IJclExtendedExtendedMap }
procedure Clear;
function ContainsKey(const Key: Extended): Boolean;
function ContainsValue(const Value: Extended): Boolean;
function Extract(const Key: Extended): Extended;
function GetValue(const Key: Extended): Extended;
function IsEmpty: Boolean;
function KeyOfValue(const Value: Extended): Extended;
function KeySet: IJclExtendedSet;
function MapEquals(const AMap: IJclExtendedExtendedMap): Boolean;
procedure PutAll(const AMap: IJclExtendedExtendedMap);
procedure PutValue(const Key: Extended; const Value: Extended);
function Remove(const Key: Extended): Extended;
function Size: Integer;
function Values: IJclExtendedCollection;
{ IJclExtendedExtendedSortedMap }
function FirstKey: Extended;
function HeadMap(const ToKey: Extended): IJclExtendedExtendedSortedMap;
function LastKey: Extended;
function SubMap(const FromKey, ToKey: Extended): IJclExtendedExtendedSortedMap;
function TailMap(const FromKey: Extended): IJclExtendedExtendedSortedMap;
end;
{$IFDEF MATH_SINGLE_PRECISION}
TJclFloatIntfSortedEntry = TJclSingleIntfSortedEntry;
{$ENDIF MATH_SINGLE_PRECISION}
{$IFDEF MATH_DOUBLE_PRECISION}
TJclFloatIntfSortedEntry = TJclDoubleIntfSortedEntry;
{$ENDIF MATH_DOUBLE_PRECISION}
{$IFDEF MATH_EXTENDED_PRECISION}
TJclFloatIntfSortedEntry = TJclExtendedIntfSortedEntry;
{$ENDIF MATH_EXTENDED_PRECISION}
{$IFDEF MATH_SINGLE_PRECISION}
TJclFloatIntfSortedMap = TJclSingleIntfSortedMap;
{$ENDIF MATH_SINGLE_PRECISION}
{$IFDEF MATH_DOUBLE_PRECISION}
TJclFloatIntfSortedMap = TJclDoubleIntfSortedMap;
{$ENDIF MATH_DOUBLE_PRECISION}
{$IFDEF MATH_EXTENDED_PRECISION}
TJclFloatIntfSortedMap = TJclExtendedIntfSortedMap;
{$ENDIF MATH_EXTENDED_PRECISION}
{$IFDEF MATH_SINGLE_PRECISION}
TJclIntfFloatSortedEntry = TJclIntfSingleSortedEntry;
{$ENDIF MATH_SINGLE_PRECISION}
{$IFDEF MATH_DOUBLE_PRECISION}
TJclIntfFloatSortedEntry = TJclIntfDoubleSortedEntry;
{$ENDIF MATH_DOUBLE_PRECISION}
{$IFDEF MATH_EXTENDED_PRECISION}
TJclIntfFloatSortedEntry = TJclIntfExtendedSortedEntry;
{$ENDIF MATH_EXTENDED_PRECISION}
{$IFDEF MATH_SINGLE_PRECISION}
TJclIntfFloatSortedMap = TJclIntfSingleSortedMap;
{$ENDIF MATH_SINGLE_PRECISION}
{$IFDEF MATH_DOUBLE_PRECISION}
TJclIntfFloatSortedMap = TJclIntfDoubleSortedMap;
{$ENDIF MATH_DOUBLE_PRECISION}
{$IFDEF MATH_EXTENDED_PRECISION}
TJclIntfFloatSortedMap = TJclIntfExtendedSortedMap;
{$ENDIF MATH_EXTENDED_PRECISION}
{$IFDEF MATH_SINGLE_PRECISION}
TJclFloatFloatSortedEntry = TJclSingleSingleSortedEntry;
{$ENDIF MATH_SINGLE_PRECISION}
{$IFDEF MATH_DOUBLE_PRECISION}
TJclFloatFloatSortedEntry = TJclDoubleDoubleSortedEntry;
{$ENDIF MATH_DOUBLE_PRECISION}
{$IFDEF MATH_EXTENDED_PRECISION}
TJclFloatFloatSortedEntry = TJclExtendedExtendedSortedEntry;
{$ENDIF MATH_EXTENDED_PRECISION}
{$IFDEF MATH_SINGLE_PRECISION}
TJclFloatFloatSortedMap = TJclSingleSingleSortedMap;
{$ENDIF MATH_SINGLE_PRECISION}
{$IFDEF MATH_DOUBLE_PRECISION}
TJclFloatFloatSortedMap = TJclDoubleDoubleSortedMap;
{$ENDIF MATH_DOUBLE_PRECISION}
{$IFDEF MATH_EXTENDED_PRECISION}
TJclFloatFloatSortedMap = TJclExtendedExtendedSortedMap;
{$ENDIF MATH_EXTENDED_PRECISION}
TJclIntegerIntfSortedEntry = record
Key: Integer;
Value: IInterface;
end;
TJclIntegerIntfSortedMap = class(TJclIntegerAbstractContainer, {$IFDEF THREADSAFE} IJclLockable, {$ENDIF THREADSAFE}
IJclIntfCloneable, IJclCloneable, IJclGrowable, IJclPackable, IJclContainer,
IJclIntegerIntfMap, IJclIntegerIntfSortedMap)
protected
function CreateEmptyContainer: TJclAbstractContainerBase; override;
function FreeKey(var Key: Integer): Integer;
function FreeValue(var Value: IInterface): IInterface;
function KeysCompare(A, B: Integer): Integer;
function ValuesCompare(const A, B: IInterface): Integer;
private
FEntries: array of TJclIntegerIntfSortedEntry;
function BinarySearch(Key: Integer): Integer;
protected
procedure AssignDataTo(Dest: TJclAbstractContainerBase); override;
procedure MoveArray(FromIndex, ToIndex, Count: Integer);
public
constructor Create(ACapacity: Integer);
destructor Destroy; override;
{ IJclPackable }
procedure SetCapacity(Value: Integer); override;
{ IJclIntegerIntfMap }
procedure Clear;
function ContainsKey(Key: Integer): Boolean;
function ContainsValue(const Value: IInterface): Boolean;
function Extract(Key: Integer): IInterface;
function GetValue(Key: Integer): IInterface;
function IsEmpty: Boolean;
function KeyOfValue(const Value: IInterface): Integer;
function KeySet: IJclIntegerSet;
function MapEquals(const AMap: IJclIntegerIntfMap): Boolean;
procedure PutAll(const AMap: IJclIntegerIntfMap);
procedure PutValue(Key: Integer; const Value: IInterface);
function Remove(Key: Integer): IInterface;
function Size: Integer;
function Values: IJclIntfCollection;
{ IJclIntegerIntfSortedMap }
function FirstKey: Integer;
function HeadMap(ToKey: Integer): IJclIntegerIntfSortedMap;
function LastKey: Integer;
function SubMap(FromKey, ToKey: Integer): IJclIntegerIntfSortedMap;
function TailMap(FromKey: Integer): IJclIntegerIntfSortedMap;
end;
TJclIntfIntegerSortedEntry = record
Key: IInterface;
Value: Integer;
end;
TJclIntfIntegerSortedMap = class(TJclIntegerAbstractContainer, {$IFDEF THREADSAFE} IJclLockable, {$ENDIF THREADSAFE}
IJclIntfCloneable, IJclCloneable, IJclGrowable, IJclPackable, IJclContainer,
IJclIntfIntegerMap, IJclIntfIntegerSortedMap)
protected
function CreateEmptyContainer: TJclAbstractContainerBase; override;
function FreeKey(var Key: IInterface): IInterface;
function FreeValue(var Value: Integer): Integer;
function KeysCompare(const A, B: IInterface): Integer;
function ValuesCompare(A, B: Integer): Integer;
private
FEntries: array of TJclIntfIntegerSortedEntry;
function BinarySearch(const Key: IInterface): Integer;
protected
procedure AssignDataTo(Dest: TJclAbstractContainerBase); override;
procedure MoveArray(FromIndex, ToIndex, Count: Integer);
public
constructor Create(ACapacity: Integer);
destructor Destroy; override;
{ IJclPackable }
procedure SetCapacity(Value: Integer); override;
{ IJclIntfIntegerMap }
procedure Clear;
function ContainsKey(const Key: IInterface): Boolean;
function ContainsValue(Value: Integer): Boolean;
function Extract(const Key: IInterface): Integer;
function GetValue(const Key: IInterface): Integer;
function IsEmpty: Boolean;
function KeyOfValue(Value: Integer): IInterface;
function KeySet: IJclIntfSet;
function MapEquals(const AMap: IJclIntfIntegerMap): Boolean;
procedure PutAll(const AMap: IJclIntfIntegerMap);
procedure PutValue(const Key: IInterface; Value: Integer);
function Remove(const Key: IInterface): Integer;
function Size: Integer;
function Values: IJclIntegerCollection;
{ IJclIntfIntegerSortedMap }
function FirstKey: IInterface;
function HeadMap(const ToKey: IInterface): IJclIntfIntegerSortedMap;
function LastKey: IInterface;
function SubMap(const FromKey, ToKey: IInterface): IJclIntfIntegerSortedMap;
function TailMap(const FromKey: IInterface): IJclIntfIntegerSortedMap;
end;
TJclIntegerIntegerSortedEntry = record
Key: Integer;
Value: Integer;
end;
TJclIntegerIntegerSortedMap = class(TJclIntegerAbstractContainer, {$IFDEF THREADSAFE} IJclLockable, {$ENDIF THREADSAFE}
IJclIntfCloneable, IJclCloneable, IJclGrowable, IJclPackable, IJclContainer,
IJclIntegerIntegerMap, IJclIntegerIntegerSortedMap)
protected
function CreateEmptyContainer: TJclAbstractContainerBase; override;
function FreeKey(var Key: Integer): Integer;
function FreeValue(var Value: Integer): Integer;
function KeysCompare(A, B: Integer): Integer;
function ValuesCompare(A, B: Integer): Integer;
private
FEntries: array of TJclIntegerIntegerSortedEntry;
function BinarySearch(Key: Integer): Integer;
protected
procedure AssignDataTo(Dest: TJclAbstractContainerBase); override;
procedure MoveArray(FromIndex, ToIndex, Count: Integer);
public
constructor Create(ACapacity: Integer);
destructor Destroy; override;
{ IJclPackable }
procedure SetCapacity(Value: Integer); override;
{ IJclIntegerIntegerMap }
procedure Clear;
function ContainsKey(Key: Integer): Boolean;
function ContainsValue(Value: Integer): Boolean;
function Extract(Key: Integer): Integer;
function GetValue(Key: Integer): Integer;
function IsEmpty: Boolean;
function KeyOfValue(Value: Integer): Integer;
function KeySet: IJclIntegerSet;
function MapEquals(const AMap: IJclIntegerIntegerMap): Boolean;
procedure PutAll(const AMap: IJclIntegerIntegerMap);
procedure PutValue(Key: Integer; Value: Integer);
function Remove(Key: Integer): Integer;
function Size: Integer;
function Values: IJclIntegerCollection;
{ IJclIntegerIntegerSortedMap }
function FirstKey: Integer;
function HeadMap(ToKey: Integer): IJclIntegerIntegerSortedMap;
function LastKey: Integer;
function SubMap(FromKey, ToKey: Integer): IJclIntegerIntegerSortedMap;
function TailMap(FromKey: Integer): IJclIntegerIntegerSortedMap;
end;
TJclCardinalIntfSortedEntry = record
Key: Cardinal;
Value: IInterface;
end;
TJclCardinalIntfSortedMap = class(TJclCardinalAbstractContainer, {$IFDEF THREADSAFE} IJclLockable, {$ENDIF THREADSAFE}
IJclIntfCloneable, IJclCloneable, IJclGrowable, IJclPackable, IJclContainer,
IJclCardinalIntfMap, IJclCardinalIntfSortedMap)
protected
function CreateEmptyContainer: TJclAbstractContainerBase; override;
function FreeKey(var Key: Cardinal): Cardinal;
function FreeValue(var Value: IInterface): IInterface;
function KeysCompare(A, B: Cardinal): Integer;
function ValuesCompare(const A, B: IInterface): Integer;
private
FEntries: array of TJclCardinalIntfSortedEntry;
function BinarySearch(Key: Cardinal): Integer;
protected
procedure AssignDataTo(Dest: TJclAbstractContainerBase); override;
procedure MoveArray(FromIndex, ToIndex, Count: Integer);
public
constructor Create(ACapacity: Integer);
destructor Destroy; override;
{ IJclPackable }
procedure SetCapacity(Value: Integer); override;
{ IJclCardinalIntfMap }
procedure Clear;
function ContainsKey(Key: Cardinal): Boolean;
function ContainsValue(const Value: IInterface): Boolean;
function Extract(Key: Cardinal): IInterface;
function GetValue(Key: Cardinal): IInterface;
function IsEmpty: Boolean;
function KeyOfValue(const Value: IInterface): Cardinal;
function KeySet: IJclCardinalSet;
function MapEquals(const AMap: IJclCardinalIntfMap): Boolean;
procedure PutAll(const AMap: IJclCardinalIntfMap);
procedure PutValue(Key: Cardinal; const Value: IInterface);
function Remove(Key: Cardinal): IInterface;
function Size: Integer;
function Values: IJclIntfCollection;
{ IJclCardinalIntfSortedMap }
function FirstKey: Cardinal;
function HeadMap(ToKey: Cardinal): IJclCardinalIntfSortedMap;
function LastKey: Cardinal;
function SubMap(FromKey, ToKey: Cardinal): IJclCardinalIntfSortedMap;
function TailMap(FromKey: Cardinal): IJclCardinalIntfSortedMap;
end;
TJclIntfCardinalSortedEntry = record
Key: IInterface;
Value: Cardinal;
end;
TJclIntfCardinalSortedMap = class(TJclCardinalAbstractContainer, {$IFDEF THREADSAFE} IJclLockable, {$ENDIF THREADSAFE}
IJclIntfCloneable, IJclCloneable, IJclGrowable, IJclPackable, IJclContainer,
IJclIntfCardinalMap, IJclIntfCardinalSortedMap)
protected
function CreateEmptyContainer: TJclAbstractContainerBase; override;
function FreeKey(var Key: IInterface): IInterface;
function FreeValue(var Value: Cardinal): Cardinal;
function KeysCompare(const A, B: IInterface): Integer;
function ValuesCompare(A, B: Cardinal): Integer;
private
FEntries: array of TJclIntfCardinalSortedEntry;
function BinarySearch(const Key: IInterface): Integer;
protected
procedure AssignDataTo(Dest: TJclAbstractContainerBase); override;
procedure MoveArray(FromIndex, ToIndex, Count: Integer);
public
constructor Create(ACapacity: Integer);
destructor Destroy; override;
{ IJclPackable }
procedure SetCapacity(Value: Integer); override;
{ IJclIntfCardinalMap }
procedure Clear;
function ContainsKey(const Key: IInterface): Boolean;
function ContainsValue(Value: Cardinal): Boolean;
function Extract(const Key: IInterface): Cardinal;
function GetValue(const Key: IInterface): Cardinal;
function IsEmpty: Boolean;
function KeyOfValue(Value: Cardinal): IInterface;
function KeySet: IJclIntfSet;
function MapEquals(const AMap: IJclIntfCardinalMap): Boolean;
procedure PutAll(const AMap: IJclIntfCardinalMap);
procedure PutValue(const Key: IInterface; Value: Cardinal);
function Remove(const Key: IInterface): Cardinal;
function Size: Integer;
function Values: IJclCardinalCollection;
{ IJclIntfCardinalSortedMap }
function FirstKey: IInterface;
function HeadMap(const ToKey: IInterface): IJclIntfCardinalSortedMap;
function LastKey: IInterface;
function SubMap(const FromKey, ToKey: IInterface): IJclIntfCardinalSortedMap;
function TailMap(const FromKey: IInterface): IJclIntfCardinalSortedMap;
end;
TJclCardinalCardinalSortedEntry = record
Key: Cardinal;
Value: Cardinal;
end;
TJclCardinalCardinalSortedMap = class(TJclCardinalAbstractContainer, {$IFDEF THREADSAFE} IJclLockable, {$ENDIF THREADSAFE}
IJclIntfCloneable, IJclCloneable, IJclGrowable, IJclPackable, IJclContainer,
IJclCardinalCardinalMap, IJclCardinalCardinalSortedMap)
protected
function CreateEmptyContainer: TJclAbstractContainerBase; override;
function FreeKey(var Key: Cardinal): Cardinal;
function FreeValue(var Value: Cardinal): Cardinal;
function KeysCompare(A, B: Cardinal): Integer;
function ValuesCompare(A, B: Cardinal): Integer;
private
FEntries: array of TJclCardinalCardinalSortedEntry;
function BinarySearch(Key: Cardinal): Integer;
protected
procedure AssignDataTo(Dest: TJclAbstractContainerBase); override;
procedure MoveArray(FromIndex, ToIndex, Count: Integer);
public
constructor Create(ACapacity: Integer);
destructor Destroy; override;
{ IJclPackable }
procedure SetCapacity(Value: Integer); override;
{ IJclCardinalCardinalMap }
procedure Clear;
function ContainsKey(Key: Cardinal): Boolean;
function ContainsValue(Value: Cardinal): Boolean;
function Extract(Key: Cardinal): Cardinal;
function GetValue(Key: Cardinal): Cardinal;
function IsEmpty: Boolean;
function KeyOfValue(Value: Cardinal): Cardinal;
function KeySet: IJclCardinalSet;
function MapEquals(const AMap: IJclCardinalCardinalMap): Boolean;
procedure PutAll(const AMap: IJclCardinalCardinalMap);
procedure PutValue(Key: Cardinal; Value: Cardinal);
function Remove(Key: Cardinal): Cardinal;
function Size: Integer;
function Values: IJclCardinalCollection;
{ IJclCardinalCardinalSortedMap }
function FirstKey: Cardinal;
function HeadMap(ToKey: Cardinal): IJclCardinalCardinalSortedMap;
function LastKey: Cardinal;
function SubMap(FromKey, ToKey: Cardinal): IJclCardinalCardinalSortedMap;
function TailMap(FromKey: Cardinal): IJclCardinalCardinalSortedMap;
end;
TJclInt64IntfSortedEntry = record
Key: Int64;
Value: IInterface;
end;
TJclInt64IntfSortedMap = class(TJclInt64AbstractContainer, {$IFDEF THREADSAFE} IJclLockable, {$ENDIF THREADSAFE}
IJclIntfCloneable, IJclCloneable, IJclGrowable, IJclPackable, IJclContainer,
IJclInt64IntfMap, IJclInt64IntfSortedMap)
protected
function CreateEmptyContainer: TJclAbstractContainerBase; override;
function FreeKey(var Key: Int64): Int64;
function FreeValue(var Value: IInterface): IInterface;
function KeysCompare(const A, B: Int64): Integer;
function ValuesCompare(const A, B: IInterface): Integer;
private
FEntries: array of TJclInt64IntfSortedEntry;
function BinarySearch(const Key: Int64): Integer;
protected
procedure AssignDataTo(Dest: TJclAbstractContainerBase); override;
procedure MoveArray(FromIndex, ToIndex, Count: Integer);
public
constructor Create(ACapacity: Integer);
destructor Destroy; override;
{ IJclPackable }
procedure SetCapacity(Value: Integer); override;
{ IJclInt64IntfMap }
procedure Clear;
function ContainsKey(const Key: Int64): Boolean;
function ContainsValue(const Value: IInterface): Boolean;
function Extract(const Key: Int64): IInterface;
function GetValue(const Key: Int64): IInterface;
function IsEmpty: Boolean;
function KeyOfValue(const Value: IInterface): Int64;
function KeySet: IJclInt64Set;
function MapEquals(const AMap: IJclInt64IntfMap): Boolean;
procedure PutAll(const AMap: IJclInt64IntfMap);
procedure PutValue(const Key: Int64; const Value: IInterface);
function Remove(const Key: Int64): IInterface;
function Size: Integer;
function Values: IJclIntfCollection;
{ IJclInt64IntfSortedMap }
function FirstKey: Int64;
function HeadMap(const ToKey: Int64): IJclInt64IntfSortedMap;
function LastKey: Int64;
function SubMap(const FromKey, ToKey: Int64): IJclInt64IntfSortedMap;
function TailMap(const FromKey: Int64): IJclInt64IntfSortedMap;
end;
TJclIntfInt64SortedEntry = record
Key: IInterface;
Value: Int64;
end;
TJclIntfInt64SortedMap = class(TJclInt64AbstractContainer, {$IFDEF THREADSAFE} IJclLockable, {$ENDIF THREADSAFE}
IJclIntfCloneable, IJclCloneable, IJclGrowable, IJclPackable, IJclContainer,
IJclIntfInt64Map, IJclIntfInt64SortedMap)
protected
function CreateEmptyContainer: TJclAbstractContainerBase; override;
function FreeKey(var Key: IInterface): IInterface;
function FreeValue(var Value: Int64): Int64;
function KeysCompare(const A, B: IInterface): Integer;
function ValuesCompare(const A, B: Int64): Integer;
private
FEntries: array of TJclIntfInt64SortedEntry;
function BinarySearch(const Key: IInterface): Integer;
protected
procedure AssignDataTo(Dest: TJclAbstractContainerBase); override;
procedure MoveArray(FromIndex, ToIndex, Count: Integer);
public
constructor Create(ACapacity: Integer);
destructor Destroy; override;
{ IJclPackable }
procedure SetCapacity(Value: Integer); override;
{ IJclIntfInt64Map }
procedure Clear;
function ContainsKey(const Key: IInterface): Boolean;
function ContainsValue(const Value: Int64): Boolean;
function Extract(const Key: IInterface): Int64;
function GetValue(const Key: IInterface): Int64;
function IsEmpty: Boolean;
function KeyOfValue(const Value: Int64): IInterface;
function KeySet: IJclIntfSet;
function MapEquals(const AMap: IJclIntfInt64Map): Boolean;
procedure PutAll(const AMap: IJclIntfInt64Map);
procedure PutValue(const Key: IInterface; const Value: Int64);
function Remove(const Key: IInterface): Int64;
function Size: Integer;
function Values: IJclInt64Collection;
{ IJclIntfInt64SortedMap }
function FirstKey: IInterface;
function HeadMap(const ToKey: IInterface): IJclIntfInt64SortedMap;
function LastKey: IInterface;
function SubMap(const FromKey, ToKey: IInterface): IJclIntfInt64SortedMap;
function TailMap(const FromKey: IInterface): IJclIntfInt64SortedMap;
end;
TJclInt64Int64SortedEntry = record
Key: Int64;
Value: Int64;
end;
TJclInt64Int64SortedMap = class(TJclInt64AbstractContainer, {$IFDEF THREADSAFE} IJclLockable, {$ENDIF THREADSAFE}
IJclIntfCloneable, IJclCloneable, IJclGrowable, IJclPackable, IJclContainer,
IJclInt64Int64Map, IJclInt64Int64SortedMap)
protected
function CreateEmptyContainer: TJclAbstractContainerBase; override;
function FreeKey(var Key: Int64): Int64;
function FreeValue(var Value: Int64): Int64;
function KeysCompare(const A, B: Int64): Integer;
function ValuesCompare(const A, B: Int64): Integer;
private
FEntries: array of TJclInt64Int64SortedEntry;
function BinarySearch(const Key: Int64): Integer;
protected
procedure AssignDataTo(Dest: TJclAbstractContainerBase); override;
procedure MoveArray(FromIndex, ToIndex, Count: Integer);
public
constructor Create(ACapacity: Integer);
destructor Destroy; override;
{ IJclPackable }
procedure SetCapacity(Value: Integer); override;
{ IJclInt64Int64Map }
procedure Clear;
function ContainsKey(const Key: Int64): Boolean;
function ContainsValue(const Value: Int64): Boolean;
function Extract(const Key: Int64): Int64;
function GetValue(const Key: Int64): Int64;
function IsEmpty: Boolean;
function KeyOfValue(const Value: Int64): Int64;
function KeySet: IJclInt64Set;
function MapEquals(const AMap: IJclInt64Int64Map): Boolean;
procedure PutAll(const AMap: IJclInt64Int64Map);
procedure PutValue(const Key: Int64; const Value: Int64);
function Remove(const Key: Int64): Int64;
function Size: Integer;
function Values: IJclInt64Collection;
{ IJclInt64Int64SortedMap }
function FirstKey: Int64;
function HeadMap(const ToKey: Int64): IJclInt64Int64SortedMap;
function LastKey: Int64;
function SubMap(const FromKey, ToKey: Int64): IJclInt64Int64SortedMap;
function TailMap(const FromKey: Int64): IJclInt64Int64SortedMap;
end;
TJclPtrIntfSortedEntry = record
Key: Pointer;
Value: IInterface;
end;
TJclPtrIntfSortedMap = class(TJclPtrAbstractContainer, {$IFDEF THREADSAFE} IJclLockable, {$ENDIF THREADSAFE}
IJclIntfCloneable, IJclCloneable, IJclGrowable, IJclPackable, IJclContainer,
IJclPtrIntfMap, IJclPtrIntfSortedMap)
protected
function CreateEmptyContainer: TJclAbstractContainerBase; override;
function FreeKey(var Key: Pointer): Pointer;
function FreeValue(var Value: IInterface): IInterface;
function KeysCompare(A, B: Pointer): Integer;
function ValuesCompare(const A, B: IInterface): Integer;
private
FEntries: array of TJclPtrIntfSortedEntry;
function BinarySearch(Key: Pointer): Integer;
protected
procedure AssignDataTo(Dest: TJclAbstractContainerBase); override;
procedure MoveArray(FromIndex, ToIndex, Count: Integer);
public
constructor Create(ACapacity: Integer);
destructor Destroy; override;
{ IJclPackable }
procedure SetCapacity(Value: Integer); override;
{ IJclPtrIntfMap }
procedure Clear;
function ContainsKey(Key: Pointer): Boolean;
function ContainsValue(const Value: IInterface): Boolean;
function Extract(Key: Pointer): IInterface;
function GetValue(Key: Pointer): IInterface;
function IsEmpty: Boolean;
function KeyOfValue(const Value: IInterface): Pointer;
function KeySet: IJclPtrSet;
function MapEquals(const AMap: IJclPtrIntfMap): Boolean;
procedure PutAll(const AMap: IJclPtrIntfMap);
procedure PutValue(Key: Pointer; const Value: IInterface);
function Remove(Key: Pointer): IInterface;
function Size: Integer;
function Values: IJclIntfCollection;
{ IJclPtrIntfSortedMap }
function FirstKey: Pointer;
function HeadMap(ToKey: Pointer): IJclPtrIntfSortedMap;
function LastKey: Pointer;
function SubMap(FromKey, ToKey: Pointer): IJclPtrIntfSortedMap;
function TailMap(FromKey: Pointer): IJclPtrIntfSortedMap;
end;
TJclIntfPtrSortedEntry = record
Key: IInterface;
Value: Pointer;
end;
TJclIntfPtrSortedMap = class(TJclPtrAbstractContainer, {$IFDEF THREADSAFE} IJclLockable, {$ENDIF THREADSAFE}
IJclIntfCloneable, IJclCloneable, IJclGrowable, IJclPackable, IJclContainer,
IJclIntfPtrMap, IJclIntfPtrSortedMap)
protected
function CreateEmptyContainer: TJclAbstractContainerBase; override;
function FreeKey(var Key: IInterface): IInterface;
function FreeValue(var Value: Pointer): Pointer;
function KeysCompare(const A, B: IInterface): Integer;
function ValuesCompare(A, B: Pointer): Integer;
private
FEntries: array of TJclIntfPtrSortedEntry;
function BinarySearch(const Key: IInterface): Integer;
protected
procedure AssignDataTo(Dest: TJclAbstractContainerBase); override;
procedure MoveArray(FromIndex, ToIndex, Count: Integer);
public
constructor Create(ACapacity: Integer);
destructor Destroy; override;
{ IJclPackable }
procedure SetCapacity(Value: Integer); override;
{ IJclIntfPtrMap }
procedure Clear;
function ContainsKey(const Key: IInterface): Boolean;
function ContainsValue(Value: Pointer): Boolean;
function Extract(const Key: IInterface): Pointer;
function GetValue(const Key: IInterface): Pointer;
function IsEmpty: Boolean;
function KeyOfValue(Value: Pointer): IInterface;
function KeySet: IJclIntfSet;
function MapEquals(const AMap: IJclIntfPtrMap): Boolean;
procedure PutAll(const AMap: IJclIntfPtrMap);
procedure PutValue(const Key: IInterface; Value: Pointer);
function Remove(const Key: IInterface): Pointer;
function Size: Integer;
function Values: IJclPtrCollection;
{ IJclIntfPtrSortedMap }
function FirstKey: IInterface;
function HeadMap(const ToKey: IInterface): IJclIntfPtrSortedMap;
function LastKey: IInterface;
function SubMap(const FromKey, ToKey: IInterface): IJclIntfPtrSortedMap;
function TailMap(const FromKey: IInterface): IJclIntfPtrSortedMap;
end;
TJclPtrPtrSortedEntry = record
Key: Pointer;
Value: Pointer;
end;
TJclPtrPtrSortedMap = class(TJclPtrAbstractContainer, {$IFDEF THREADSAFE} IJclLockable, {$ENDIF THREADSAFE}
IJclIntfCloneable, IJclCloneable, IJclGrowable, IJclPackable, IJclContainer,
IJclPtrPtrMap, IJclPtrPtrSortedMap)
protected
function CreateEmptyContainer: TJclAbstractContainerBase; override;
function FreeKey(var Key: Pointer): Pointer;
function FreeValue(var Value: Pointer): Pointer;
function KeysCompare(A, B: Pointer): Integer;
function ValuesCompare(A, B: Pointer): Integer;
private
FEntries: array of TJclPtrPtrSortedEntry;
function BinarySearch(Key: Pointer): Integer;
protected
procedure AssignDataTo(Dest: TJclAbstractContainerBase); override;
procedure MoveArray(FromIndex, ToIndex, Count: Integer);
public
constructor Create(ACapacity: Integer);
destructor Destroy; override;
{ IJclPackable }
procedure SetCapacity(Value: Integer); override;
{ IJclPtrPtrMap }
procedure Clear;
function ContainsKey(Key: Pointer): Boolean;
function ContainsValue(Value: Pointer): Boolean;
function Extract(Key: Pointer): Pointer;
function GetValue(Key: Pointer): Pointer;
function IsEmpty: Boolean;
function KeyOfValue(Value: Pointer): Pointer;
function KeySet: IJclPtrSet;
function MapEquals(const AMap: IJclPtrPtrMap): Boolean;
procedure PutAll(const AMap: IJclPtrPtrMap);
procedure PutValue(Key: Pointer; Value: Pointer);
function Remove(Key: Pointer): Pointer;
function Size: Integer;
function Values: IJclPtrCollection;
{ IJclPtrPtrSortedMap }
function FirstKey: Pointer;
function HeadMap(ToKey: Pointer): IJclPtrPtrSortedMap;
function LastKey: Pointer;
function SubMap(FromKey, ToKey: Pointer): IJclPtrPtrSortedMap;
function TailMap(FromKey: Pointer): IJclPtrPtrSortedMap;
end;
TJclIntfSortedEntry = record
Key: IInterface;
Value: TObject;
end;
TJclIntfSortedMap = class(TJclIntfAbstractContainer, {$IFDEF THREADSAFE} IJclLockable, {$ENDIF THREADSAFE}
IJclIntfCloneable, IJclCloneable, IJclGrowable, IJclPackable, IJclContainer, IJclValueOwner,
IJclIntfMap, IJclIntfSortedMap)
private
FOwnsValues: Boolean;
protected
function CreateEmptyContainer: TJclAbstractContainerBase; override;
function FreeKey(var Key: IInterface): IInterface;
function KeysCompare(const A, B: IInterface): Integer;
function ValuesCompare(A, B: TObject): Integer;
public
{ IJclValueOwner }
function FreeValue(var Value: TObject): TObject;
function GetOwnsValues: Boolean;
property OwnsValues: Boolean read FOwnsValues;
private
FEntries: array of TJclIntfSortedEntry;
function BinarySearch(const Key: IInterface): Integer;
protected
procedure AssignDataTo(Dest: TJclAbstractContainerBase); override;
procedure MoveArray(FromIndex, ToIndex, Count: Integer);
public
constructor Create(ACapacity: Integer; AOwnsValues: Boolean);
destructor Destroy; override;
{ IJclPackable }
procedure SetCapacity(Value: Integer); override;
{ IJclIntfMap }
procedure Clear;
function ContainsKey(const Key: IInterface): Boolean;
function ContainsValue(Value: TObject): Boolean;
function Extract(const Key: IInterface): TObject;
function GetValue(const Key: IInterface): TObject;
function IsEmpty: Boolean;
function KeyOfValue(Value: TObject): IInterface;
function KeySet: IJclIntfSet;
function MapEquals(const AMap: IJclIntfMap): Boolean;
procedure PutAll(const AMap: IJclIntfMap);
procedure PutValue(const Key: IInterface; Value: TObject);
function Remove(const Key: IInterface): TObject;
function Size: Integer;
function Values: IJclCollection;
{ IJclIntfSortedMap }
function FirstKey: IInterface;
function HeadMap(const ToKey: IInterface): IJclIntfSortedMap;
function LastKey: IInterface;
function SubMap(const FromKey, ToKey: IInterface): IJclIntfSortedMap;
function TailMap(const FromKey: IInterface): IJclIntfSortedMap;
end;
TJclAnsiStrSortedEntry = record
Key: AnsiString;
Value: TObject;
end;
TJclAnsiStrSortedMap = class(TJclAnsiStrAbstractContainer, {$IFDEF THREADSAFE} IJclLockable, {$ENDIF THREADSAFE}
IJclIntfCloneable, IJclCloneable, IJclGrowable, IJclPackable, IJclContainer, IJclStrContainer, IJclAnsiStrContainer, IJclValueOwner,
IJclAnsiStrMap, IJclAnsiStrSortedMap)
private
FOwnsValues: Boolean;
protected
function CreateEmptyContainer: TJclAbstractContainerBase; override;
function FreeKey(var Key: AnsiString): AnsiString;
function KeysCompare(const A, B: AnsiString): Integer;
function ValuesCompare(A, B: TObject): Integer;
public
{ IJclValueOwner }
function FreeValue(var Value: TObject): TObject;
function GetOwnsValues: Boolean;
property OwnsValues: Boolean read FOwnsValues;
private
FEntries: array of TJclAnsiStrSortedEntry;
function BinarySearch(const Key: AnsiString): Integer;
protected
procedure AssignDataTo(Dest: TJclAbstractContainerBase); override;
procedure MoveArray(FromIndex, ToIndex, Count: Integer);
public
constructor Create(ACapacity: Integer; AOwnsValues: Boolean);
destructor Destroy; override;
{ IJclPackable }
procedure SetCapacity(Value: Integer); override;
{ IJclAnsiStrMap }
procedure Clear;
function ContainsKey(const Key: AnsiString): Boolean;
function ContainsValue(Value: TObject): Boolean;
function Extract(const Key: AnsiString): TObject;
function GetValue(const Key: AnsiString): TObject;
function IsEmpty: Boolean;
function KeyOfValue(Value: TObject): AnsiString;
function KeySet: IJclAnsiStrSet;
function MapEquals(const AMap: IJclAnsiStrMap): Boolean;
procedure PutAll(const AMap: IJclAnsiStrMap);
procedure PutValue(const Key: AnsiString; Value: TObject);
function Remove(const Key: AnsiString): TObject;
function Size: Integer;
function Values: IJclCollection;
{ IJclAnsiStrSortedMap }
function FirstKey: AnsiString;
function HeadMap(const ToKey: AnsiString): IJclAnsiStrSortedMap;
function LastKey: AnsiString;
function SubMap(const FromKey, ToKey: AnsiString): IJclAnsiStrSortedMap;
function TailMap(const FromKey: AnsiString): IJclAnsiStrSortedMap;
end;
TJclWideStrSortedEntry = record
Key: WideString;
Value: TObject;
end;
TJclWideStrSortedMap = class(TJclWideStrAbstractContainer, {$IFDEF THREADSAFE} IJclLockable, {$ENDIF THREADSAFE}
IJclIntfCloneable, IJclCloneable, IJclGrowable, IJclPackable, IJclContainer, IJclStrContainer, IJclWideStrContainer, IJclValueOwner,
IJclWideStrMap, IJclWideStrSortedMap)
private
FOwnsValues: Boolean;
protected
function CreateEmptyContainer: TJclAbstractContainerBase; override;
function FreeKey(var Key: WideString): WideString;
function KeysCompare(const A, B: WideString): Integer;
function ValuesCompare(A, B: TObject): Integer;
public
{ IJclValueOwner }
function FreeValue(var Value: TObject): TObject;
function GetOwnsValues: Boolean;
property OwnsValues: Boolean read FOwnsValues;
private
FEntries: array of TJclWideStrSortedEntry;
function BinarySearch(const Key: WideString): Integer;
protected
procedure AssignDataTo(Dest: TJclAbstractContainerBase); override;
procedure MoveArray(FromIndex, ToIndex, Count: Integer);
public
constructor Create(ACapacity: Integer; AOwnsValues: Boolean);
destructor Destroy; override;
{ IJclPackable }
procedure SetCapacity(Value: Integer); override;
{ IJclWideStrMap }
procedure Clear;
function ContainsKey(const Key: WideString): Boolean;
function ContainsValue(Value: TObject): Boolean;
function Extract(const Key: WideString): TObject;
function GetValue(const Key: WideString): TObject;
function IsEmpty: Boolean;
function KeyOfValue(Value: TObject): WideString;
function KeySet: IJclWideStrSet;
function MapEquals(const AMap: IJclWideStrMap): Boolean;
procedure PutAll(const AMap: IJclWideStrMap);
procedure PutValue(const Key: WideString; Value: TObject);
function Remove(const Key: WideString): TObject;
function Size: Integer;
function Values: IJclCollection;
{ IJclWideStrSortedMap }
function FirstKey: WideString;
function HeadMap(const ToKey: WideString): IJclWideStrSortedMap;
function LastKey: WideString;
function SubMap(const FromKey, ToKey: WideString): IJclWideStrSortedMap;
function TailMap(const FromKey: WideString): IJclWideStrSortedMap;
end;
{$IFDEF SUPPORTS_UNICODE_STRING}
TJclUnicodeStrSortedEntry = record
Key: UnicodeString;
Value: TObject;
end;
{$ENDIF SUPPORTS_UNICODE_STRING}
{$IFDEF SUPPORTS_UNICODE_STRING}
TJclUnicodeStrSortedMap = class(TJclUnicodeStrAbstractContainer, {$IFDEF THREADSAFE} IJclLockable, {$ENDIF THREADSAFE}
IJclIntfCloneable, IJclCloneable, IJclGrowable, IJclPackable, IJclContainer, IJclStrContainer, IJclUnicodeStrContainer, IJclValueOwner,
IJclUnicodeStrMap, IJclUnicodeStrSortedMap)
private
FOwnsValues: Boolean;
protected
function CreateEmptyContainer: TJclAbstractContainerBase; override;
function FreeKey(var Key: UnicodeString): UnicodeString;
function KeysCompare(const A, B: UnicodeString): Integer;
function ValuesCompare(A, B: TObject): Integer;
public
{ IJclValueOwner }
function FreeValue(var Value: TObject): TObject;
function GetOwnsValues: Boolean;
property OwnsValues: Boolean read FOwnsValues;
private
FEntries: array of TJclUnicodeStrSortedEntry;
function BinarySearch(const Key: UnicodeString): Integer;
protected
procedure AssignDataTo(Dest: TJclAbstractContainerBase); override;
procedure MoveArray(FromIndex, ToIndex, Count: Integer);
public
constructor Create(ACapacity: Integer; AOwnsValues: Boolean);
destructor Destroy; override;
{ IJclPackable }
procedure SetCapacity(Value: Integer); override;
{ IJclUnicodeStrMap }
procedure Clear;
function ContainsKey(const Key: UnicodeString): Boolean;
function ContainsValue(Value: TObject): Boolean;
function Extract(const Key: UnicodeString): TObject;
function GetValue(const Key: UnicodeString): TObject;
function IsEmpty: Boolean;
function KeyOfValue(Value: TObject): UnicodeString;
function KeySet: IJclUnicodeStrSet;
function MapEquals(const AMap: IJclUnicodeStrMap): Boolean;
procedure PutAll(const AMap: IJclUnicodeStrMap);
procedure PutValue(const Key: UnicodeString; Value: TObject);
function Remove(const Key: UnicodeString): TObject;
function Size: Integer;
function Values: IJclCollection;
{ IJclUnicodeStrSortedMap }
function FirstKey: UnicodeString;
function HeadMap(const ToKey: UnicodeString): IJclUnicodeStrSortedMap;
function LastKey: UnicodeString;
function SubMap(const FromKey, ToKey: UnicodeString): IJclUnicodeStrSortedMap;
function TailMap(const FromKey: UnicodeString): IJclUnicodeStrSortedMap;
end;
{$ENDIF SUPPORTS_UNICODE_STRING}
{$IFDEF CONTAINER_ANSISTR}
TJclStrSortedEntry = TJclAnsiStrSortedEntry;
{$ENDIF CONTAINER_ANSISTR}
{$IFDEF CONTAINER_WIDESTR}
TJclStrSortedEntry = TJclWideStrSortedEntry;
{$ENDIF CONTAINER_WIDESTR}
{$IFDEF CONTAINER_UNICODESTR}
TJclStrSortedEntry = TJclUnicodeStrSortedEntry;
{$ENDIF CONTAINER_UNICODESTR}
{$IFDEF CONTAINER_ANSISTR}
TJclStrSortedMap = TJclAnsiStrSortedMap;
{$ENDIF CONTAINER_ANSISTR}
{$IFDEF CONTAINER_WIDESTR}
TJclStrSortedMap = TJclWideStrSortedMap;
{$ENDIF CONTAINER_WIDESTR}
{$IFDEF CONTAINER_UNICODESTR}
TJclStrSortedMap = TJclUnicodeStrSortedMap;
{$ENDIF CONTAINER_UNICODESTR}
TJclSingleSortedEntry = record
Key: Single;
Value: TObject;
end;
TJclSingleSortedMap = class(TJclSingleAbstractContainer, {$IFDEF THREADSAFE} IJclLockable, {$ENDIF THREADSAFE}
IJclIntfCloneable, IJclCloneable, IJclGrowable, IJclPackable, IJclContainer, IJclSingleContainer, IJclValueOwner,
IJclSingleMap, IJclSingleSortedMap)
private
FOwnsValues: Boolean;
protected
function CreateEmptyContainer: TJclAbstractContainerBase; override;
function FreeKey(var Key: Single): Single;
function KeysCompare(const A, B: Single): Integer;
function ValuesCompare(A, B: TObject): Integer;
public
{ IJclValueOwner }
function FreeValue(var Value: TObject): TObject;
function GetOwnsValues: Boolean;
property OwnsValues: Boolean read FOwnsValues;
private
FEntries: array of TJclSingleSortedEntry;
function BinarySearch(const Key: Single): Integer;
protected
procedure AssignDataTo(Dest: TJclAbstractContainerBase); override;
procedure MoveArray(FromIndex, ToIndex, Count: Integer);
public
constructor Create(ACapacity: Integer; AOwnsValues: Boolean);
destructor Destroy; override;
{ IJclPackable }
procedure SetCapacity(Value: Integer); override;
{ IJclSingleMap }
procedure Clear;
function ContainsKey(const Key: Single): Boolean;
function ContainsValue(Value: TObject): Boolean;
function Extract(const Key: Single): TObject;
function GetValue(const Key: Single): TObject;
function IsEmpty: Boolean;
function KeyOfValue(Value: TObject): Single;
function KeySet: IJclSingleSet;
function MapEquals(const AMap: IJclSingleMap): Boolean;
procedure PutAll(const AMap: IJclSingleMap);
procedure PutValue(const Key: Single; Value: TObject);
function Remove(const Key: Single): TObject;
function Size: Integer;
function Values: IJclCollection;
{ IJclSingleSortedMap }
function FirstKey: Single;
function HeadMap(const ToKey: Single): IJclSingleSortedMap;
function LastKey: Single;
function SubMap(const FromKey, ToKey: Single): IJclSingleSortedMap;
function TailMap(const FromKey: Single): IJclSingleSortedMap;
end;
TJclDoubleSortedEntry = record
Key: Double;
Value: TObject;
end;
TJclDoubleSortedMap = class(TJclDoubleAbstractContainer, {$IFDEF THREADSAFE} IJclLockable, {$ENDIF THREADSAFE}
IJclIntfCloneable, IJclCloneable, IJclGrowable, IJclPackable, IJclContainer, IJclDoubleContainer, IJclValueOwner,
IJclDoubleMap, IJclDoubleSortedMap)
private
FOwnsValues: Boolean;
protected
function CreateEmptyContainer: TJclAbstractContainerBase; override;
function FreeKey(var Key: Double): Double;
function KeysCompare(const A, B: Double): Integer;
function ValuesCompare(A, B: TObject): Integer;
public
{ IJclValueOwner }
function FreeValue(var Value: TObject): TObject;
function GetOwnsValues: Boolean;
property OwnsValues: Boolean read FOwnsValues;
private
FEntries: array of TJclDoubleSortedEntry;
function BinarySearch(const Key: Double): Integer;
protected
procedure AssignDataTo(Dest: TJclAbstractContainerBase); override;
procedure MoveArray(FromIndex, ToIndex, Count: Integer);
public
constructor Create(ACapacity: Integer; AOwnsValues: Boolean);
destructor Destroy; override;
{ IJclPackable }
procedure SetCapacity(Value: Integer); override;
{ IJclDoubleMap }
procedure Clear;
function ContainsKey(const Key: Double): Boolean;
function ContainsValue(Value: TObject): Boolean;
function Extract(const Key: Double): TObject;
function GetValue(const Key: Double): TObject;
function IsEmpty: Boolean;
function KeyOfValue(Value: TObject): Double;
function KeySet: IJclDoubleSet;
function MapEquals(const AMap: IJclDoubleMap): Boolean;
procedure PutAll(const AMap: IJclDoubleMap);
procedure PutValue(const Key: Double; Value: TObject);
function Remove(const Key: Double): TObject;
function Size: Integer;
function Values: IJclCollection;
{ IJclDoubleSortedMap }
function FirstKey: Double;
function HeadMap(const ToKey: Double): IJclDoubleSortedMap;
function LastKey: Double;
function SubMap(const FromKey, ToKey: Double): IJclDoubleSortedMap;
function TailMap(const FromKey: Double): IJclDoubleSortedMap;
end;
TJclExtendedSortedEntry = record
Key: Extended;
Value: TObject;
end;
TJclExtendedSortedMap = class(TJclExtendedAbstractContainer, {$IFDEF THREADSAFE} IJclLockable, {$ENDIF THREADSAFE}
IJclIntfCloneable, IJclCloneable, IJclGrowable, IJclPackable, IJclContainer, IJclExtendedContainer, IJclValueOwner,
IJclExtendedMap, IJclExtendedSortedMap)
private
FOwnsValues: Boolean;
protected
function CreateEmptyContainer: TJclAbstractContainerBase; override;
function FreeKey(var Key: Extended): Extended;
function KeysCompare(const A, B: Extended): Integer;
function ValuesCompare(A, B: TObject): Integer;
public
{ IJclValueOwner }
function FreeValue(var Value: TObject): TObject;
function GetOwnsValues: Boolean;
property OwnsValues: Boolean read FOwnsValues;
private
FEntries: array of TJclExtendedSortedEntry;
function BinarySearch(const Key: Extended): Integer;
protected
procedure AssignDataTo(Dest: TJclAbstractContainerBase); override;
procedure MoveArray(FromIndex, ToIndex, Count: Integer);
public
constructor Create(ACapacity: Integer; AOwnsValues: Boolean);
destructor Destroy; override;
{ IJclPackable }
procedure SetCapacity(Value: Integer); override;
{ IJclExtendedMap }
procedure Clear;
function ContainsKey(const Key: Extended): Boolean;
function ContainsValue(Value: TObject): Boolean;
function Extract(const Key: Extended): TObject;
function GetValue(const Key: Extended): TObject;
function IsEmpty: Boolean;
function KeyOfValue(Value: TObject): Extended;
function KeySet: IJclExtendedSet;
function MapEquals(const AMap: IJclExtendedMap): Boolean;
procedure PutAll(const AMap: IJclExtendedMap);
procedure PutValue(const Key: Extended; Value: TObject);
function Remove(const Key: Extended): TObject;
function Size: Integer;
function Values: IJclCollection;
{ IJclExtendedSortedMap }
function FirstKey: Extended;
function HeadMap(const ToKey: Extended): IJclExtendedSortedMap;
function LastKey: Extended;
function SubMap(const FromKey, ToKey: Extended): IJclExtendedSortedMap;
function TailMap(const FromKey: Extended): IJclExtendedSortedMap;
end;
{$IFDEF MATH_SINGLE_PRECISION}
TJclFloatSortedEntry = TJclSingleSortedEntry;
{$ENDIF MATH_SINGLE_PRECISION}
{$IFDEF MATH_DOUBLE_PRECISION}
TJclFloatSortedEntry = TJclDoubleSortedEntry;
{$ENDIF MATH_DOUBLE_PRECISION}
{$IFDEF MATH_EXTENDED_PRECISION}
TJclFloatSortedEntry = TJclExtendedSortedEntry;
{$ENDIF MATH_EXTENDED_PRECISION}
{$IFDEF MATH_SINGLE_PRECISION}
TJclFloatSortedMap = TJclSingleSortedMap;
{$ENDIF MATH_SINGLE_PRECISION}
{$IFDEF MATH_DOUBLE_PRECISION}
TJclFloatSortedMap = TJclDoubleSortedMap;
{$ENDIF MATH_DOUBLE_PRECISION}
{$IFDEF MATH_EXTENDED_PRECISION}
TJclFloatSortedMap = TJclExtendedSortedMap;
{$ENDIF MATH_EXTENDED_PRECISION}
TJclIntegerSortedEntry = record
Key: Integer;
Value: TObject;
end;
TJclIntegerSortedMap = class(TJclIntegerAbstractContainer, {$IFDEF THREADSAFE} IJclLockable, {$ENDIF THREADSAFE}
IJclIntfCloneable, IJclCloneable, IJclGrowable, IJclPackable, IJclContainer, IJclValueOwner,
IJclIntegerMap, IJclIntegerSortedMap)
private
FOwnsValues: Boolean;
protected
function CreateEmptyContainer: TJclAbstractContainerBase; override;
function FreeKey(var Key: Integer): Integer;
function KeysCompare(A, B: Integer): Integer;
function ValuesCompare(A, B: TObject): Integer;
public
{ IJclValueOwner }
function FreeValue(var Value: TObject): TObject;
function GetOwnsValues: Boolean;
property OwnsValues: Boolean read FOwnsValues;
private
FEntries: array of TJclIntegerSortedEntry;
function BinarySearch(Key: Integer): Integer;
protected
procedure AssignDataTo(Dest: TJclAbstractContainerBase); override;
procedure MoveArray(FromIndex, ToIndex, Count: Integer);
public
constructor Create(ACapacity: Integer; AOwnsValues: Boolean);
destructor Destroy; override;
{ IJclPackable }
procedure SetCapacity(Value: Integer); override;
{ IJclIntegerMap }
procedure Clear;
function ContainsKey(Key: Integer): Boolean;
function ContainsValue(Value: TObject): Boolean;
function Extract(Key: Integer): TObject;
function GetValue(Key: Integer): TObject;
function IsEmpty: Boolean;
function KeyOfValue(Value: TObject): Integer;
function KeySet: IJclIntegerSet;
function MapEquals(const AMap: IJclIntegerMap): Boolean;
procedure PutAll(const AMap: IJclIntegerMap);
procedure PutValue(Key: Integer; Value: TObject);
function Remove(Key: Integer): TObject;
function Size: Integer;
function Values: IJclCollection;
{ IJclIntegerSortedMap }
function FirstKey: Integer;
function HeadMap(ToKey: Integer): IJclIntegerSortedMap;
function LastKey: Integer;
function SubMap(FromKey, ToKey: Integer): IJclIntegerSortedMap;
function TailMap(FromKey: Integer): IJclIntegerSortedMap;
end;
TJclCardinalSortedEntry = record
Key: Cardinal;
Value: TObject;
end;
TJclCardinalSortedMap = class(TJclCardinalAbstractContainer, {$IFDEF THREADSAFE} IJclLockable, {$ENDIF THREADSAFE}
IJclIntfCloneable, IJclCloneable, IJclGrowable, IJclPackable, IJclContainer, IJclValueOwner,
IJclCardinalMap, IJclCardinalSortedMap)
private
FOwnsValues: Boolean;
protected
function CreateEmptyContainer: TJclAbstractContainerBase; override;
function FreeKey(var Key: Cardinal): Cardinal;
function KeysCompare(A, B: Cardinal): Integer;
function ValuesCompare(A, B: TObject): Integer;
public
{ IJclValueOwner }
function FreeValue(var Value: TObject): TObject;
function GetOwnsValues: Boolean;
property OwnsValues: Boolean read FOwnsValues;
private
FEntries: array of TJclCardinalSortedEntry;
function BinarySearch(Key: Cardinal): Integer;
protected
procedure AssignDataTo(Dest: TJclAbstractContainerBase); override;
procedure MoveArray(FromIndex, ToIndex, Count: Integer);
public
constructor Create(ACapacity: Integer; AOwnsValues: Boolean);
destructor Destroy; override;
{ IJclPackable }
procedure SetCapacity(Value: Integer); override;
{ IJclCardinalMap }
procedure Clear;
function ContainsKey(Key: Cardinal): Boolean;
function ContainsValue(Value: TObject): Boolean;
function Extract(Key: Cardinal): TObject;
function GetValue(Key: Cardinal): TObject;
function IsEmpty: Boolean;
function KeyOfValue(Value: TObject): Cardinal;
function KeySet: IJclCardinalSet;
function MapEquals(const AMap: IJclCardinalMap): Boolean;
procedure PutAll(const AMap: IJclCardinalMap);
procedure PutValue(Key: Cardinal; Value: TObject);
function Remove(Key: Cardinal): TObject;
function Size: Integer;
function Values: IJclCollection;
{ IJclCardinalSortedMap }
function FirstKey: Cardinal;
function HeadMap(ToKey: Cardinal): IJclCardinalSortedMap;
function LastKey: Cardinal;
function SubMap(FromKey, ToKey: Cardinal): IJclCardinalSortedMap;
function TailMap(FromKey: Cardinal): IJclCardinalSortedMap;
end;
TJclInt64SortedEntry = record
Key: Int64;
Value: TObject;
end;
TJclInt64SortedMap = class(TJclInt64AbstractContainer, {$IFDEF THREADSAFE} IJclLockable, {$ENDIF THREADSAFE}
IJclIntfCloneable, IJclCloneable, IJclGrowable, IJclPackable, IJclContainer, IJclValueOwner,
IJclInt64Map, IJclInt64SortedMap)
private
FOwnsValues: Boolean;
protected
function CreateEmptyContainer: TJclAbstractContainerBase; override;
function FreeKey(var Key: Int64): Int64;
function KeysCompare(const A, B: Int64): Integer;
function ValuesCompare(A, B: TObject): Integer;
public
{ IJclValueOwner }
function FreeValue(var Value: TObject): TObject;
function GetOwnsValues: Boolean;
property OwnsValues: Boolean read FOwnsValues;
private
FEntries: array of TJclInt64SortedEntry;
function BinarySearch(const Key: Int64): Integer;
protected
procedure AssignDataTo(Dest: TJclAbstractContainerBase); override;
procedure MoveArray(FromIndex, ToIndex, Count: Integer);
public
constructor Create(ACapacity: Integer; AOwnsValues: Boolean);
destructor Destroy; override;
{ IJclPackable }
procedure SetCapacity(Value: Integer); override;
{ IJclInt64Map }
procedure Clear;
function ContainsKey(const Key: Int64): Boolean;
function ContainsValue(Value: TObject): Boolean;
function Extract(const Key: Int64): TObject;
function GetValue(const Key: Int64): TObject;
function IsEmpty: Boolean;
function KeyOfValue(Value: TObject): Int64;
function KeySet: IJclInt64Set;
function MapEquals(const AMap: IJclInt64Map): Boolean;
procedure PutAll(const AMap: IJclInt64Map);
procedure PutValue(const Key: Int64; Value: TObject);
function Remove(const Key: Int64): TObject;
function Size: Integer;
function Values: IJclCollection;
{ IJclInt64SortedMap }
function FirstKey: Int64;
function HeadMap(const ToKey: Int64): IJclInt64SortedMap;
function LastKey: Int64;
function SubMap(const FromKey, ToKey: Int64): IJclInt64SortedMap;
function TailMap(const FromKey: Int64): IJclInt64SortedMap;
end;
TJclPtrSortedEntry = record
Key: Pointer;
Value: TObject;
end;
TJclPtrSortedMap = class(TJclPtrAbstractContainer, {$IFDEF THREADSAFE} IJclLockable, {$ENDIF THREADSAFE}
IJclIntfCloneable, IJclCloneable, IJclGrowable, IJclPackable, IJclContainer, IJclValueOwner,
IJclPtrMap, IJclPtrSortedMap)
private
FOwnsValues: Boolean;
protected
function CreateEmptyContainer: TJclAbstractContainerBase; override;
function FreeKey(var Key: Pointer): Pointer;
function KeysCompare(A, B: Pointer): Integer;
function ValuesCompare(A, B: TObject): Integer;
public
{ IJclValueOwner }
function FreeValue(var Value: TObject): TObject;
function GetOwnsValues: Boolean;
property OwnsValues: Boolean read FOwnsValues;
private
FEntries: array of TJclPtrSortedEntry;
function BinarySearch(Key: Pointer): Integer;
protected
procedure AssignDataTo(Dest: TJclAbstractContainerBase); override;
procedure MoveArray(FromIndex, ToIndex, Count: Integer);
public
constructor Create(ACapacity: Integer; AOwnsValues: Boolean);
destructor Destroy; override;
{ IJclPackable }
procedure SetCapacity(Value: Integer); override;
{ IJclPtrMap }
procedure Clear;
function ContainsKey(Key: Pointer): Boolean;
function ContainsValue(Value: TObject): Boolean;
function Extract(Key: Pointer): TObject;
function GetValue(Key: Pointer): TObject;
function IsEmpty: Boolean;
function KeyOfValue(Value: TObject): Pointer;
function KeySet: IJclPtrSet;
function MapEquals(const AMap: IJclPtrMap): Boolean;
procedure PutAll(const AMap: IJclPtrMap);
procedure PutValue(Key: Pointer; Value: TObject);
function Remove(Key: Pointer): TObject;
function Size: Integer;
function Values: IJclCollection;
{ IJclPtrSortedMap }
function FirstKey: Pointer;
function HeadMap(ToKey: Pointer): IJclPtrSortedMap;
function LastKey: Pointer;
function SubMap(FromKey, ToKey: Pointer): IJclPtrSortedMap;
function TailMap(FromKey: Pointer): IJclPtrSortedMap;
end;
TJclSortedEntry = record
Key: TObject;
Value: TObject;
end;
TJclSortedMap = class(TJclAbstractContainerBase, {$IFDEF THREADSAFE} IJclLockable, {$ENDIF THREADSAFE}
IJclIntfCloneable, IJclCloneable, IJclGrowable, IJclPackable, IJclContainer, IJclKeyOwner, IJclValueOwner,
IJclMap, IJclSortedMap)
private
FOwnsKeys: Boolean;
FOwnsValues: Boolean;
protected
function CreateEmptyContainer: TJclAbstractContainerBase; override;
function KeysCompare(A, B: TObject): Integer;
function ValuesCompare(A, B: TObject): Integer;
public
{ IJclKeyOwner }
function FreeKey(var Key: TObject): TObject;
function GetOwnsKeys: Boolean;
property OwnsKeys: Boolean read FOwnsKeys;
{ IJclValueOwner }
function FreeValue(var Value: TObject): TObject;
function GetOwnsValues: Boolean;
property OwnsValues: Boolean read FOwnsValues;
private
FEntries: array of TJclSortedEntry;
function BinarySearch(Key: TObject): Integer;
protected
procedure AssignDataTo(Dest: TJclAbstractContainerBase); override;
procedure MoveArray(FromIndex, ToIndex, Count: Integer);
public
constructor Create(ACapacity: Integer; AOwnsValues: Boolean; AOwnsKeys: Boolean);
destructor Destroy; override;
{ IJclPackable }
procedure SetCapacity(Value: Integer); override;
{ IJclMap }
procedure Clear;
function ContainsKey(Key: TObject): Boolean;
function ContainsValue(Value: TObject): Boolean;
function Extract(Key: TObject): TObject;
function GetValue(Key: TObject): TObject;
function IsEmpty: Boolean;
function KeyOfValue(Value: TObject): TObject;
function KeySet: IJclSet;
function MapEquals(const AMap: IJclMap): Boolean;
procedure PutAll(const AMap: IJclMap);
procedure PutValue(Key: TObject; Value: TObject);
function Remove(Key: TObject): TObject;
function Size: Integer;
function Values: IJclCollection;
{ IJclSortedMap }
function FirstKey: TObject;
function HeadMap(ToKey: TObject): IJclSortedMap;
function LastKey: TObject;
function SubMap(FromKey, ToKey: TObject): IJclSortedMap;
function TailMap(FromKey: TObject): IJclSortedMap;
end;
{$IFDEF SUPPORTS_GENERICS}
TJclSortedEntry<TKey,TValue> = record
Key: TKey;
Value: TValue;
end;
TJclSortedMap<TKey,TValue> = class(TJclAbstractContainerBase, {$IFDEF THREADSAFE} IJclLockable, {$ENDIF THREADSAFE}
IJclIntfCloneable, IJclCloneable, IJclGrowable, IJclPackable, IJclContainer, IJclPairOwner<TKey,TValue>,
IJclMap<TKey,TValue>, IJclSortedMap<TKey,TValue>)
protected
type
TSortedEntry = TJclSortedEntry<TKey,TValue>;
private
FOwnsKeys: Boolean;
FOwnsValues: Boolean;
protected
function KeysCompare(const A, B: TKey): Integer; virtual; abstract;
function ValuesCompare(const A, B: TValue): Integer; virtual; abstract;
function CreateEmptyArrayList(ACapacity: Integer; AOwnsObjects: Boolean): IJclCollection<TValue>; virtual; abstract;
function CreateEmptyArraySet(ACapacity: Integer; AOwnsObjects: Boolean): IJclSet<TKey>; virtual; abstract;
public
{ IJclPairOwner }
function FreeKey(var Key: TKey): TKey;
function FreeValue(var Value: TValue): TValue;
function GetOwnsKeys: Boolean;
function GetOwnsValues: Boolean;
property OwnsKeys: Boolean read FOwnsKeys;
property OwnsValues: Boolean read FOwnsValues;
private
FEntries: array of TSortedEntry;
function BinarySearch(const Key: TKey): Integer;
protected
procedure AssignDataTo(Dest: TJclAbstractContainerBase); override;
procedure MoveArray(FromIndex, ToIndex, Count: Integer);
public
constructor Create(ACapacity: Integer; AOwnsValues: Boolean; AOwnsKeys: Boolean);
destructor Destroy; override;
{ IJclPackable }
procedure SetCapacity(Value: Integer); override;
{ IJclMap<TKey,TValue> }
procedure Clear;
function ContainsKey(const Key: TKey): Boolean;
function ContainsValue(const Value: TValue): Boolean;
function Extract(const Key: TKey): TValue;
function GetValue(const Key: TKey): TValue;
function IsEmpty: Boolean;
function KeyOfValue(const Value: TValue): TKey;
function KeySet: IJclSet<TKey>;
function MapEquals(const AMap: IJclMap<TKey,TValue>): Boolean;
procedure PutAll(const AMap: IJclMap<TKey,TValue>);
procedure PutValue(const Key: TKey; const Value: TValue);
function Remove(const Key: TKey): TValue;
function Size: Integer;
function Values: IJclCollection<TValue>;
{ IJclSortedMap<TKey,TValue> }
function FirstKey: TKey;
function HeadMap(const ToKey: TKey): IJclSortedMap<TKey,TValue>;
function LastKey: TKey;
function SubMap(const FromKey, ToKey: TKey): IJclSortedMap<TKey,TValue>;
function TailMap(const FromKey: TKey): IJclSortedMap<TKey,TValue>;
end;
// E = external helper to compare items
TJclSortedMapE<TKey, TValue> = class(TJclSortedMap<TKey,TValue>, {$IFDEF THREADSAFE} IJclLockable, {$ENDIF THREADSAFE}
IJclIntfCloneable, IJclCloneable, IJclPackable, IJclContainer, IJclMap<TKey,TValue>, IJclSortedMap<TKey,TValue>, IJclPairOwner<TKey,TValue>)
protected
type
TArrayList = TJclArrayListE<TValue>;
TArraySet = TJclArraySetE<TKey>;
private
FKeyComparer: IJclComparer<TKey>;
FValueComparer: IJclComparer<TValue>;
FValueEqualityComparer: IJclEqualityComparer<TValue>;
protected
procedure AssignPropertiesTo(Dest: TJclAbstractContainerBase); override;
function KeysCompare(const A, B: TKey): Integer; override;
function ValuesCompare(const A, B: TValue): Integer; override;
function CreateEmptyArrayList(ACapacity: Integer; AOwnsObjects: Boolean): IJclCollection<TValue>; override;
function CreateEmptyContainer: TJclAbstractContainerBase; override;
function CreateEmptyArraySet(ACapacity: Integer; AOwnsObjects: Boolean): IJclSet<TKey>; override;
public
constructor Create(const AKeyComparer: IJclComparer<TKey>; const AValueComparer: IJclComparer<TValue>;
const AValueEqualityComparer: IJclEqualityComparer<TValue>; ACapacity: Integer; AOwnsValues: Boolean;
AOwnsKeys: Boolean);
property KeyComparer: IJclComparer<TKey> read FKeyComparer write FKeyComparer;
property ValueComparer: IJclComparer<TValue> read FValueComparer write FValueComparer;
property ValueEqualityComparer: IJclEqualityComparer<TValue> read FValueEqualityComparer write FValueEqualityComparer;
end;
// F = Functions to compare items
TJclSortedMapF<TKey, TValue> = class(TJclSortedMap<TKey, TValue>, {$IFDEF THREADSAFE} IJclLockable, {$ENDIF THREADSAFE}
IJclIntfCloneable, IJclCloneable, IJclPackable, IJclContainer, IJclMap<TKey,TValue>, IJclSortedMap<TKey,TValue>, IJclPairOwner<TKey, TValue>)
protected
type
TArrayList = TJclArrayListF<TValue>;
TArraySet = TJclArraySetF<TKey>;
private
FKeyCompare: TCompare<TKey>;
FValueCompare: TCompare<TValue>;
FValueEqualityCompare: TEqualityCompare<TValue>;
protected
procedure AssignPropertiesTo(Dest: TJclAbstractContainerBase); override;
function KeysCompare(const A, B: TKey): Integer; override;
function ValuesCompare(const A, B: TValue): Integer; override;
function CreateEmptyArrayList(ACapacity: Integer; AOwnsObjects: Boolean): IJclCollection<TValue>; override;
function CreateEmptyContainer: TJclAbstractContainerBase; override;
function CreateEmptyArraySet(ACapacity: Integer; AOwnsObjects: Boolean): IJclSet<TKey>; override;
public
constructor Create(AKeyCompare: TCompare<TKey>; AValueCompare: TCompare<TValue>;
AValueEqualityCompare: TEqualityCompare<TValue>; ACapacity: Integer; AOwnsValues: Boolean; AOwnsKeys: Boolean);
property KeyCompare: TCompare<TKey> read FKeyCompare write FKeyCompare;
property ValueCompare: TCompare<TValue> read FValueCompare write FValueCompare;
property ValueEqualityCompare: TEqualityCompare<TValue> read FValueEqualityCompare write FValueEqualityCompare;
end;
// I = items can compare themselves to an other
TJclSortedMapI<TKey: IComparable<TKey>; TValue: IComparable<TValue>, IEquatable<TValue>> = class(TJclSortedMap<TKey, TValue>,
{$IFDEF THREADSAFE} IJclLockable, {$ENDIF THREADSAFE} IJclIntfCloneable, IJclCloneable, IJclPackable, IJclContainer,
IJclMap<TKey,TValue>, IJclSortedMap<TKey,TValue>, IJclPairOwner<TKey, TValue>)
protected
type
TArrayList = TJclArrayListI<TValue>;
TArraySet = TJclArraySetI<TKey>;
protected
function KeysCompare(const A, B: TKey): Integer; override;
function ValuesCompare(const A, B: TValue): Integer; override;
function CreateEmptyArrayList(ACapacity: Integer; AOwnsObjects: Boolean): IJclCollection<TValue>; override;
function CreateEmptyContainer: TJclAbstractContainerBase; override;
function CreateEmptyArraySet(ACapacity: Integer; AOwnsObjects: Boolean): IJclSet<TKey>; override;
end;
{$ENDIF SUPPORTS_GENERICS}
{$IFDEF UNITVERSIONING}
const
UnitVersioning: TUnitVersionInfo = (
RCSfile: '$URL: https://jcl.svn.sourceforge.net:443/svnroot/jcl/tags/JCL-2.2-Build3970/jcl/source/common/JclSortedMaps.pas $';
Revision: '$Revision: 3291 $';
Date: '$Date: 2010-08-09 17:10:10 +0200 (lun., 09 août 2010) $';
LogPath: 'JCL\source\common';
Extra: '';
Data: nil
);
{$ENDIF UNITVERSIONING}
implementation
uses
SysUtils;
//=== { TJclIntfIntfSortedMap } ==============================================
constructor TJclIntfIntfSortedMap.Create(ACapacity: Integer);
begin
inherited Create();
SetCapacity(ACapacity);
end;
destructor TJclIntfIntfSortedMap.Destroy;
begin
FReadOnly := False;
Clear;
inherited Destroy;
end;
procedure TJclIntfIntfSortedMap.AssignDataTo(Dest: TJclAbstractContainerBase);
var
MyDest: TJclIntfIntfSortedMap;
begin
inherited AssignDataTo(Dest);
if Dest is TJclIntfIntfSortedMap then
begin
MyDest := TJclIntfIntfSortedMap(Dest);
MyDest.SetCapacity(FSize);
MyDest.FEntries := FEntries;
MyDest.FSize := FSize;
end;
end;
function TJclIntfIntfSortedMap.BinarySearch(const Key: IInterface): Integer;
var
HiPos, LoPos, CompPos: Integer;
Comp: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
LoPos := 0;
HiPos := FSize - 1;
CompPos := (HiPos + LoPos) div 2;
while HiPos >= LoPos do
begin
Comp := KeysCompare(FEntries[CompPos].Key, Key);
if Comp < 0 then
LoPos := CompPos + 1
else
if Comp > 0 then
HiPos := CompPos - 1
else
begin
HiPos := CompPos;
LoPos := CompPos + 1;
end;
CompPos := (HiPos + LoPos) div 2;
end;
Result := HiPos;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntfIntfSortedMap.Clear;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
for Index := 0 to FSize - 1 do
begin
FreeKey(FEntries[Index].Key);
FreeValue(FEntries[Index].Value);
end;
FSize := 0;
AutoPack;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfIntfSortedMap.ContainsKey(const Key: IInterface): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfIntfSortedMap.ContainsValue(const Value: IInterface): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := True;
Break;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfIntfSortedMap.FirstKey: IInterface;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := nil;
if FSize > 0 then
Result := FEntries[0].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfIntfSortedMap.Extract(const Key: IInterface): IInterface;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
Result := FEntries[Index].Value;
FEntries[Index].Value := nil;
FreeKey(FEntries[Index].Key);
if Index < (FSize - 1) then
MoveArray(Index + 1, Index, FSize - Index - 1);
Dec(FSize);
AutoPack;
end
else
Result := nil;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfIntfSortedMap.GetValue(const Key: IInterface): IInterface;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := nil;
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
Result := FEntries[Index].Value
else if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfIntfSortedMap.HeadMap(const ToKey: IInterface): IJclIntfIntfSortedMap;
var
ToIndex: Integer;
NewMap: TJclIntfIntfSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclIntfIntfSortedMap;
ToIndex := BinarySearch(ToKey);
if ToIndex >= 0 then
begin
NewMap.SetCapacity(ToIndex + 1);
NewMap.FSize := ToIndex + 1;
while ToIndex >= 0 do
begin
NewMap.FEntries[ToIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfIntfSortedMap.IsEmpty: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := FSize = 0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfIntfSortedMap.KeyOfValue(const Value: IInterface): IInterface;
var
Index: Integer;
Found: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Found := False;
Result := nil;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := FEntries[Index].Key;
Found := True;
Break;
end;
if (not Found) and (not FReturnDefaultElements) then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfIntfSortedMap.KeySet: IJclIntfSet;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclIntfArraySet.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Key);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfIntfSortedMap.LastKey: IInterface;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := nil;
if FSize > 0 then
Result := FEntries[FSize - 1].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfIntfSortedMap.MapEquals(const AMap: IJclIntfIntfMap): Boolean;
var
It: IJclIntfIterator;
Index: Integer;
AKey: IInterface;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
if AMap = nil then
Exit;
if FSize <> AMap.Size then
Exit;
It := AMap.KeySet.First;
Index := 0;
while It.HasNext do
begin
if Index >= FSize then
Exit;
AKey := It.Next;
if ValuesCompare(AMap.GetValue(AKey), FEntries[Index].Value) <> 0 then
Exit;
Inc(Index);
end;
Result := True;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntfIntfSortedMap.MoveArray(FromIndex, ToIndex, Count: Integer);
begin
if Count > 0 then
begin
Move(FEntries[FromIndex], FEntries[ToIndex], Count * SizeOf(FEntries[0]));
{ Keep reference counting working }
if FromIndex < ToIndex then
begin
if (ToIndex - FromIndex) < Count then
FillChar(FEntries[FromIndex], (ToIndex - FromIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end
else
if FromIndex > ToIndex then
begin
if (FromIndex - ToIndex) < Count then
FillChar(FEntries[ToIndex + Count], (FromIndex - ToIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end;
end;
end;
procedure TJclIntfIntfSortedMap.PutAll(const AMap: IJclIntfIntfMap);
var
It: IJclIntfIterator;
Key: IInterface;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if AMap = nil then
Exit;
It := AMap.KeySet.First;
while It.HasNext do
begin
Key := It.Next;
PutValue(Key, AMap.GetValue(Key));
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntfIntfSortedMap.PutValue(const Key: IInterface; const Value: IInterface);
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FAllowDefaultElements or ((KeysCompare(Key, nil) <> 0) and (ValuesCompare(Value, nil) <> 0)) then
begin
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
FreeValue(FEntries[Index].Value);
FEntries[Index].Value := Value;
end
else
begin
if FSize = FCapacity then
AutoGrow;
if FSize < FCapacity then
begin
Inc(Index);
if (Index < FSize) and (KeysCompare(FEntries[Index].Key, Key) <> 0) then
MoveArray(Index, Index + 1, FSize - Index);
FEntries[Index].Key := Key;
FEntries[Index].Value := Value;
Inc(FSize);
end;
end;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfIntfSortedMap.Remove(const Key: IInterface): IInterface;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Result := Extract(Key);
Result := FreeValue(Result);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntfIntfSortedMap.SetCapacity(Value: Integer);
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FSize <= Value then
begin
SetLength(FEntries, Value);
inherited SetCapacity(Value);
end
else
raise EJclOperationNotSupportedError.Create;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfIntfSortedMap.Size: Integer;
begin
Result := FSize;
end;
function TJclIntfIntfSortedMap.SubMap(const FromKey, ToKey: IInterface): IJclIntfIntfSortedMap;
var
FromIndex, ToIndex: Integer;
NewMap: TJclIntfIntfSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclIntfIntfSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
ToIndex := BinarySearch(ToKey);
if (FromIndex >= 0) and (FromIndex <= ToIndex) then
begin
NewMap.SetCapacity(ToIndex - FromIndex + 1);
NewMap.FSize := ToIndex - FromIndex + 1;
while ToIndex >= FromIndex do
begin
NewMap.FEntries[ToIndex - FromIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfIntfSortedMap.TailMap(const FromKey: IInterface): IJclIntfIntfSortedMap;
var
FromIndex, Index: Integer;
NewMap: TJclIntfIntfSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclIntfIntfSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
if (FromIndex >= 0) and (FromIndex < FSize) then
begin
NewMap.SetCapacity(FSize - FromIndex);
NewMap.FSize := FSize - FromIndex;
Index := FromIndex;
while Index < FSize do
begin
NewMap.FEntries[Index - FromIndex] := FEntries[Index];
Inc(Index);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfIntfSortedMap.Values: IJclIntfCollection;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclIntfArrayList.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Value);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfIntfSortedMap.CreateEmptyContainer: TJclAbstractContainerBase;
begin
Result := TJclIntfIntfSortedMap.Create(FSize);
AssignPropertiesTo(Result);
end;
function TJclIntfIntfSortedMap.FreeKey(var Key: IInterface): IInterface;
begin
Result := Key;
Key := nil;
end;
function TJclIntfIntfSortedMap.FreeValue(var Value: IInterface): IInterface;
begin
Result := Value;
Value := nil;
end;
function TJclIntfIntfSortedMap.KeysCompare(const A, B: IInterface): Integer;
begin
Result := ItemsCompare(A, B);
end;
function TJclIntfIntfSortedMap.ValuesCompare(const A, B: IInterface): Integer;
begin
Result := ItemsCompare(A, B);
end;
//=== { TJclAnsiStrIntfSortedMap } ==============================================
constructor TJclAnsiStrIntfSortedMap.Create(ACapacity: Integer);
begin
inherited Create();
SetCapacity(ACapacity);
end;
destructor TJclAnsiStrIntfSortedMap.Destroy;
begin
FReadOnly := False;
Clear;
inherited Destroy;
end;
procedure TJclAnsiStrIntfSortedMap.AssignDataTo(Dest: TJclAbstractContainerBase);
var
MyDest: TJclAnsiStrIntfSortedMap;
begin
inherited AssignDataTo(Dest);
if Dest is TJclAnsiStrIntfSortedMap then
begin
MyDest := TJclAnsiStrIntfSortedMap(Dest);
MyDest.SetCapacity(FSize);
MyDest.FEntries := FEntries;
MyDest.FSize := FSize;
end;
end;
function TJclAnsiStrIntfSortedMap.BinarySearch(const Key: AnsiString): Integer;
var
HiPos, LoPos, CompPos: Integer;
Comp: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
LoPos := 0;
HiPos := FSize - 1;
CompPos := (HiPos + LoPos) div 2;
while HiPos >= LoPos do
begin
Comp := KeysCompare(FEntries[CompPos].Key, Key);
if Comp < 0 then
LoPos := CompPos + 1
else
if Comp > 0 then
HiPos := CompPos - 1
else
begin
HiPos := CompPos;
LoPos := CompPos + 1;
end;
CompPos := (HiPos + LoPos) div 2;
end;
Result := HiPos;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclAnsiStrIntfSortedMap.Clear;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
for Index := 0 to FSize - 1 do
begin
FreeKey(FEntries[Index].Key);
FreeValue(FEntries[Index].Value);
end;
FSize := 0;
AutoPack;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclAnsiStrIntfSortedMap.ContainsKey(const Key: AnsiString): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclAnsiStrIntfSortedMap.ContainsValue(const Value: IInterface): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := True;
Break;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclAnsiStrIntfSortedMap.FirstKey: AnsiString;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := '';
if FSize > 0 then
Result := FEntries[0].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclAnsiStrIntfSortedMap.Extract(const Key: AnsiString): IInterface;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
Result := FEntries[Index].Value;
FEntries[Index].Value := nil;
FreeKey(FEntries[Index].Key);
if Index < (FSize - 1) then
MoveArray(Index + 1, Index, FSize - Index - 1);
Dec(FSize);
AutoPack;
end
else
Result := nil;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclAnsiStrIntfSortedMap.GetValue(const Key: AnsiString): IInterface;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := nil;
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
Result := FEntries[Index].Value
else if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclAnsiStrIntfSortedMap.HeadMap(const ToKey: AnsiString): IJclAnsiStrIntfSortedMap;
var
ToIndex: Integer;
NewMap: TJclAnsiStrIntfSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclAnsiStrIntfSortedMap;
ToIndex := BinarySearch(ToKey);
if ToIndex >= 0 then
begin
NewMap.SetCapacity(ToIndex + 1);
NewMap.FSize := ToIndex + 1;
while ToIndex >= 0 do
begin
NewMap.FEntries[ToIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclAnsiStrIntfSortedMap.IsEmpty: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := FSize = 0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclAnsiStrIntfSortedMap.KeyOfValue(const Value: IInterface): AnsiString;
var
Index: Integer;
Found: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Found := False;
Result := '';
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := FEntries[Index].Key;
Found := True;
Break;
end;
if (not Found) and (not FReturnDefaultElements) then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclAnsiStrIntfSortedMap.KeySet: IJclAnsiStrSet;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclAnsiStrArraySet.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Key);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclAnsiStrIntfSortedMap.LastKey: AnsiString;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := '';
if FSize > 0 then
Result := FEntries[FSize - 1].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclAnsiStrIntfSortedMap.MapEquals(const AMap: IJclAnsiStrIntfMap): Boolean;
var
It: IJclAnsiStrIterator;
Index: Integer;
AKey: AnsiString;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
if AMap = nil then
Exit;
if FSize <> AMap.Size then
Exit;
It := AMap.KeySet.First;
Index := 0;
while It.HasNext do
begin
if Index >= FSize then
Exit;
AKey := It.Next;
if ValuesCompare(AMap.GetValue(AKey), FEntries[Index].Value) <> 0 then
Exit;
Inc(Index);
end;
Result := True;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclAnsiStrIntfSortedMap.MoveArray(FromIndex, ToIndex, Count: Integer);
begin
if Count > 0 then
begin
Move(FEntries[FromIndex], FEntries[ToIndex], Count * SizeOf(FEntries[0]));
{ Keep reference counting working }
if FromIndex < ToIndex then
begin
if (ToIndex - FromIndex) < Count then
FillChar(FEntries[FromIndex], (ToIndex - FromIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end
else
if FromIndex > ToIndex then
begin
if (FromIndex - ToIndex) < Count then
FillChar(FEntries[ToIndex + Count], (FromIndex - ToIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end;
end;
end;
procedure TJclAnsiStrIntfSortedMap.PutAll(const AMap: IJclAnsiStrIntfMap);
var
It: IJclAnsiStrIterator;
Key: AnsiString;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if AMap = nil then
Exit;
It := AMap.KeySet.First;
while It.HasNext do
begin
Key := It.Next;
PutValue(Key, AMap.GetValue(Key));
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclAnsiStrIntfSortedMap.PutValue(const Key: AnsiString; const Value: IInterface);
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FAllowDefaultElements or ((KeysCompare(Key, '') <> 0) and (ValuesCompare(Value, nil) <> 0)) then
begin
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
FreeValue(FEntries[Index].Value);
FEntries[Index].Value := Value;
end
else
begin
if FSize = FCapacity then
AutoGrow;
if FSize < FCapacity then
begin
Inc(Index);
if (Index < FSize) and (KeysCompare(FEntries[Index].Key, Key) <> 0) then
MoveArray(Index, Index + 1, FSize - Index);
FEntries[Index].Key := Key;
FEntries[Index].Value := Value;
Inc(FSize);
end;
end;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclAnsiStrIntfSortedMap.Remove(const Key: AnsiString): IInterface;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Result := Extract(Key);
Result := FreeValue(Result);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclAnsiStrIntfSortedMap.SetCapacity(Value: Integer);
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FSize <= Value then
begin
SetLength(FEntries, Value);
inherited SetCapacity(Value);
end
else
raise EJclOperationNotSupportedError.Create;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclAnsiStrIntfSortedMap.Size: Integer;
begin
Result := FSize;
end;
function TJclAnsiStrIntfSortedMap.SubMap(const FromKey, ToKey: AnsiString): IJclAnsiStrIntfSortedMap;
var
FromIndex, ToIndex: Integer;
NewMap: TJclAnsiStrIntfSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclAnsiStrIntfSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
ToIndex := BinarySearch(ToKey);
if (FromIndex >= 0) and (FromIndex <= ToIndex) then
begin
NewMap.SetCapacity(ToIndex - FromIndex + 1);
NewMap.FSize := ToIndex - FromIndex + 1;
while ToIndex >= FromIndex do
begin
NewMap.FEntries[ToIndex - FromIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclAnsiStrIntfSortedMap.TailMap(const FromKey: AnsiString): IJclAnsiStrIntfSortedMap;
var
FromIndex, Index: Integer;
NewMap: TJclAnsiStrIntfSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclAnsiStrIntfSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
if (FromIndex >= 0) and (FromIndex < FSize) then
begin
NewMap.SetCapacity(FSize - FromIndex);
NewMap.FSize := FSize - FromIndex;
Index := FromIndex;
while Index < FSize do
begin
NewMap.FEntries[Index - FromIndex] := FEntries[Index];
Inc(Index);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclAnsiStrIntfSortedMap.Values: IJclIntfCollection;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclIntfArrayList.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Value);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclAnsiStrIntfSortedMap.CreateEmptyContainer: TJclAbstractContainerBase;
begin
Result := TJclAnsiStrIntfSortedMap.Create(FSize);
AssignPropertiesTo(Result);
end;
function TJclAnsiStrIntfSortedMap.FreeKey(var Key: AnsiString): AnsiString;
begin
Result := Key;
Key := '';
end;
function TJclAnsiStrIntfSortedMap.FreeValue(var Value: IInterface): IInterface;
begin
Result := Value;
Value := nil;
end;
function TJclAnsiStrIntfSortedMap.KeysCompare(const A, B: AnsiString): Integer;
begin
Result := ItemsCompare(A, B);
end;
function TJclAnsiStrIntfSortedMap.ValuesCompare(const A, B: IInterface): Integer;
begin
Result := IntfSimpleCompare(A, B);
end;
//=== { TJclIntfAnsiStrSortedMap } ==============================================
constructor TJclIntfAnsiStrSortedMap.Create(ACapacity: Integer);
begin
inherited Create();
SetCapacity(ACapacity);
end;
destructor TJclIntfAnsiStrSortedMap.Destroy;
begin
FReadOnly := False;
Clear;
inherited Destroy;
end;
procedure TJclIntfAnsiStrSortedMap.AssignDataTo(Dest: TJclAbstractContainerBase);
var
MyDest: TJclIntfAnsiStrSortedMap;
begin
inherited AssignDataTo(Dest);
if Dest is TJclIntfAnsiStrSortedMap then
begin
MyDest := TJclIntfAnsiStrSortedMap(Dest);
MyDest.SetCapacity(FSize);
MyDest.FEntries := FEntries;
MyDest.FSize := FSize;
end;
end;
function TJclIntfAnsiStrSortedMap.BinarySearch(const Key: IInterface): Integer;
var
HiPos, LoPos, CompPos: Integer;
Comp: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
LoPos := 0;
HiPos := FSize - 1;
CompPos := (HiPos + LoPos) div 2;
while HiPos >= LoPos do
begin
Comp := KeysCompare(FEntries[CompPos].Key, Key);
if Comp < 0 then
LoPos := CompPos + 1
else
if Comp > 0 then
HiPos := CompPos - 1
else
begin
HiPos := CompPos;
LoPos := CompPos + 1;
end;
CompPos := (HiPos + LoPos) div 2;
end;
Result := HiPos;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntfAnsiStrSortedMap.Clear;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
for Index := 0 to FSize - 1 do
begin
FreeKey(FEntries[Index].Key);
FreeValue(FEntries[Index].Value);
end;
FSize := 0;
AutoPack;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfAnsiStrSortedMap.ContainsKey(const Key: IInterface): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfAnsiStrSortedMap.ContainsValue(const Value: AnsiString): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := True;
Break;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfAnsiStrSortedMap.FirstKey: IInterface;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := nil;
if FSize > 0 then
Result := FEntries[0].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfAnsiStrSortedMap.Extract(const Key: IInterface): AnsiString;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
Result := FEntries[Index].Value;
FEntries[Index].Value := '';
FreeKey(FEntries[Index].Key);
if Index < (FSize - 1) then
MoveArray(Index + 1, Index, FSize - Index - 1);
Dec(FSize);
AutoPack;
end
else
Result := '';
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfAnsiStrSortedMap.GetValue(const Key: IInterface): AnsiString;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := '';
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
Result := FEntries[Index].Value
else if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfAnsiStrSortedMap.HeadMap(const ToKey: IInterface): IJclIntfAnsiStrSortedMap;
var
ToIndex: Integer;
NewMap: TJclIntfAnsiStrSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclIntfAnsiStrSortedMap;
ToIndex := BinarySearch(ToKey);
if ToIndex >= 0 then
begin
NewMap.SetCapacity(ToIndex + 1);
NewMap.FSize := ToIndex + 1;
while ToIndex >= 0 do
begin
NewMap.FEntries[ToIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfAnsiStrSortedMap.IsEmpty: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := FSize = 0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfAnsiStrSortedMap.KeyOfValue(const Value: AnsiString): IInterface;
var
Index: Integer;
Found: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Found := False;
Result := nil;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := FEntries[Index].Key;
Found := True;
Break;
end;
if (not Found) and (not FReturnDefaultElements) then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfAnsiStrSortedMap.KeySet: IJclIntfSet;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclIntfArraySet.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Key);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfAnsiStrSortedMap.LastKey: IInterface;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := nil;
if FSize > 0 then
Result := FEntries[FSize - 1].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfAnsiStrSortedMap.MapEquals(const AMap: IJclIntfAnsiStrMap): Boolean;
var
It: IJclIntfIterator;
Index: Integer;
AKey: IInterface;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
if AMap = nil then
Exit;
if FSize <> AMap.Size then
Exit;
It := AMap.KeySet.First;
Index := 0;
while It.HasNext do
begin
if Index >= FSize then
Exit;
AKey := It.Next;
if ValuesCompare(AMap.GetValue(AKey), FEntries[Index].Value) <> 0 then
Exit;
Inc(Index);
end;
Result := True;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntfAnsiStrSortedMap.MoveArray(FromIndex, ToIndex, Count: Integer);
begin
if Count > 0 then
begin
Move(FEntries[FromIndex], FEntries[ToIndex], Count * SizeOf(FEntries[0]));
{ Keep reference counting working }
if FromIndex < ToIndex then
begin
if (ToIndex - FromIndex) < Count then
FillChar(FEntries[FromIndex], (ToIndex - FromIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end
else
if FromIndex > ToIndex then
begin
if (FromIndex - ToIndex) < Count then
FillChar(FEntries[ToIndex + Count], (FromIndex - ToIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end;
end;
end;
procedure TJclIntfAnsiStrSortedMap.PutAll(const AMap: IJclIntfAnsiStrMap);
var
It: IJclIntfIterator;
Key: IInterface;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if AMap = nil then
Exit;
It := AMap.KeySet.First;
while It.HasNext do
begin
Key := It.Next;
PutValue(Key, AMap.GetValue(Key));
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntfAnsiStrSortedMap.PutValue(const Key: IInterface; const Value: AnsiString);
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FAllowDefaultElements or ((KeysCompare(Key, nil) <> 0) and (ValuesCompare(Value, '') <> 0)) then
begin
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
FreeValue(FEntries[Index].Value);
FEntries[Index].Value := Value;
end
else
begin
if FSize = FCapacity then
AutoGrow;
if FSize < FCapacity then
begin
Inc(Index);
if (Index < FSize) and (KeysCompare(FEntries[Index].Key, Key) <> 0) then
MoveArray(Index, Index + 1, FSize - Index);
FEntries[Index].Key := Key;
FEntries[Index].Value := Value;
Inc(FSize);
end;
end;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfAnsiStrSortedMap.Remove(const Key: IInterface): AnsiString;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Result := Extract(Key);
Result := FreeValue(Result);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntfAnsiStrSortedMap.SetCapacity(Value: Integer);
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FSize <= Value then
begin
SetLength(FEntries, Value);
inherited SetCapacity(Value);
end
else
raise EJclOperationNotSupportedError.Create;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfAnsiStrSortedMap.Size: Integer;
begin
Result := FSize;
end;
function TJclIntfAnsiStrSortedMap.SubMap(const FromKey, ToKey: IInterface): IJclIntfAnsiStrSortedMap;
var
FromIndex, ToIndex: Integer;
NewMap: TJclIntfAnsiStrSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclIntfAnsiStrSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
ToIndex := BinarySearch(ToKey);
if (FromIndex >= 0) and (FromIndex <= ToIndex) then
begin
NewMap.SetCapacity(ToIndex - FromIndex + 1);
NewMap.FSize := ToIndex - FromIndex + 1;
while ToIndex >= FromIndex do
begin
NewMap.FEntries[ToIndex - FromIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfAnsiStrSortedMap.TailMap(const FromKey: IInterface): IJclIntfAnsiStrSortedMap;
var
FromIndex, Index: Integer;
NewMap: TJclIntfAnsiStrSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclIntfAnsiStrSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
if (FromIndex >= 0) and (FromIndex < FSize) then
begin
NewMap.SetCapacity(FSize - FromIndex);
NewMap.FSize := FSize - FromIndex;
Index := FromIndex;
while Index < FSize do
begin
NewMap.FEntries[Index - FromIndex] := FEntries[Index];
Inc(Index);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfAnsiStrSortedMap.Values: IJclAnsiStrCollection;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclAnsiStrArrayList.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Value);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfAnsiStrSortedMap.CreateEmptyContainer: TJclAbstractContainerBase;
begin
Result := TJclIntfAnsiStrSortedMap.Create(FSize);
AssignPropertiesTo(Result);
end;
function TJclIntfAnsiStrSortedMap.FreeKey(var Key: IInterface): IInterface;
begin
Result := Key;
Key := nil;
end;
function TJclIntfAnsiStrSortedMap.FreeValue(var Value: AnsiString): AnsiString;
begin
Result := Value;
Value := '';
end;
function TJclIntfAnsiStrSortedMap.KeysCompare(const A, B: IInterface): Integer;
begin
Result := IntfSimpleCompare(A, B);
end;
function TJclIntfAnsiStrSortedMap.ValuesCompare(const A, B: AnsiString): Integer;
begin
Result := ItemsCompare(A, B);
end;
//=== { TJclAnsiStrAnsiStrSortedMap } ==============================================
constructor TJclAnsiStrAnsiStrSortedMap.Create(ACapacity: Integer);
begin
inherited Create();
SetCapacity(ACapacity);
end;
destructor TJclAnsiStrAnsiStrSortedMap.Destroy;
begin
FReadOnly := False;
Clear;
inherited Destroy;
end;
procedure TJclAnsiStrAnsiStrSortedMap.AssignDataTo(Dest: TJclAbstractContainerBase);
var
MyDest: TJclAnsiStrAnsiStrSortedMap;
begin
inherited AssignDataTo(Dest);
if Dest is TJclAnsiStrAnsiStrSortedMap then
begin
MyDest := TJclAnsiStrAnsiStrSortedMap(Dest);
MyDest.SetCapacity(FSize);
MyDest.FEntries := FEntries;
MyDest.FSize := FSize;
end;
end;
function TJclAnsiStrAnsiStrSortedMap.BinarySearch(const Key: AnsiString): Integer;
var
HiPos, LoPos, CompPos: Integer;
Comp: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
LoPos := 0;
HiPos := FSize - 1;
CompPos := (HiPos + LoPos) div 2;
while HiPos >= LoPos do
begin
Comp := KeysCompare(FEntries[CompPos].Key, Key);
if Comp < 0 then
LoPos := CompPos + 1
else
if Comp > 0 then
HiPos := CompPos - 1
else
begin
HiPos := CompPos;
LoPos := CompPos + 1;
end;
CompPos := (HiPos + LoPos) div 2;
end;
Result := HiPos;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclAnsiStrAnsiStrSortedMap.Clear;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
for Index := 0 to FSize - 1 do
begin
FreeKey(FEntries[Index].Key);
FreeValue(FEntries[Index].Value);
end;
FSize := 0;
AutoPack;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclAnsiStrAnsiStrSortedMap.ContainsKey(const Key: AnsiString): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclAnsiStrAnsiStrSortedMap.ContainsValue(const Value: AnsiString): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := True;
Break;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclAnsiStrAnsiStrSortedMap.FirstKey: AnsiString;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := '';
if FSize > 0 then
Result := FEntries[0].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclAnsiStrAnsiStrSortedMap.Extract(const Key: AnsiString): AnsiString;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
Result := FEntries[Index].Value;
FEntries[Index].Value := '';
FreeKey(FEntries[Index].Key);
if Index < (FSize - 1) then
MoveArray(Index + 1, Index, FSize - Index - 1);
Dec(FSize);
AutoPack;
end
else
Result := '';
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclAnsiStrAnsiStrSortedMap.GetValue(const Key: AnsiString): AnsiString;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := '';
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
Result := FEntries[Index].Value
else if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclAnsiStrAnsiStrSortedMap.HeadMap(const ToKey: AnsiString): IJclAnsiStrAnsiStrSortedMap;
var
ToIndex: Integer;
NewMap: TJclAnsiStrAnsiStrSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclAnsiStrAnsiStrSortedMap;
ToIndex := BinarySearch(ToKey);
if ToIndex >= 0 then
begin
NewMap.SetCapacity(ToIndex + 1);
NewMap.FSize := ToIndex + 1;
while ToIndex >= 0 do
begin
NewMap.FEntries[ToIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclAnsiStrAnsiStrSortedMap.IsEmpty: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := FSize = 0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclAnsiStrAnsiStrSortedMap.KeyOfValue(const Value: AnsiString): AnsiString;
var
Index: Integer;
Found: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Found := False;
Result := '';
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := FEntries[Index].Key;
Found := True;
Break;
end;
if (not Found) and (not FReturnDefaultElements) then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclAnsiStrAnsiStrSortedMap.KeySet: IJclAnsiStrSet;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclAnsiStrArraySet.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Key);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclAnsiStrAnsiStrSortedMap.LastKey: AnsiString;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := '';
if FSize > 0 then
Result := FEntries[FSize - 1].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclAnsiStrAnsiStrSortedMap.MapEquals(const AMap: IJclAnsiStrAnsiStrMap): Boolean;
var
It: IJclAnsiStrIterator;
Index: Integer;
AKey: AnsiString;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
if AMap = nil then
Exit;
if FSize <> AMap.Size then
Exit;
It := AMap.KeySet.First;
Index := 0;
while It.HasNext do
begin
if Index >= FSize then
Exit;
AKey := It.Next;
if ValuesCompare(AMap.GetValue(AKey), FEntries[Index].Value) <> 0 then
Exit;
Inc(Index);
end;
Result := True;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclAnsiStrAnsiStrSortedMap.MoveArray(FromIndex, ToIndex, Count: Integer);
begin
if Count > 0 then
begin
Move(FEntries[FromIndex], FEntries[ToIndex], Count * SizeOf(FEntries[0]));
{ Keep reference counting working }
if FromIndex < ToIndex then
begin
if (ToIndex - FromIndex) < Count then
FillChar(FEntries[FromIndex], (ToIndex - FromIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end
else
if FromIndex > ToIndex then
begin
if (FromIndex - ToIndex) < Count then
FillChar(FEntries[ToIndex + Count], (FromIndex - ToIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end;
end;
end;
procedure TJclAnsiStrAnsiStrSortedMap.PutAll(const AMap: IJclAnsiStrAnsiStrMap);
var
It: IJclAnsiStrIterator;
Key: AnsiString;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if AMap = nil then
Exit;
It := AMap.KeySet.First;
while It.HasNext do
begin
Key := It.Next;
PutValue(Key, AMap.GetValue(Key));
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclAnsiStrAnsiStrSortedMap.PutValue(const Key: AnsiString; const Value: AnsiString);
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FAllowDefaultElements or ((KeysCompare(Key, '') <> 0) and (ValuesCompare(Value, '') <> 0)) then
begin
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
FreeValue(FEntries[Index].Value);
FEntries[Index].Value := Value;
end
else
begin
if FSize = FCapacity then
AutoGrow;
if FSize < FCapacity then
begin
Inc(Index);
if (Index < FSize) and (KeysCompare(FEntries[Index].Key, Key) <> 0) then
MoveArray(Index, Index + 1, FSize - Index);
FEntries[Index].Key := Key;
FEntries[Index].Value := Value;
Inc(FSize);
end;
end;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclAnsiStrAnsiStrSortedMap.Remove(const Key: AnsiString): AnsiString;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Result := Extract(Key);
Result := FreeValue(Result);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclAnsiStrAnsiStrSortedMap.SetCapacity(Value: Integer);
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FSize <= Value then
begin
SetLength(FEntries, Value);
inherited SetCapacity(Value);
end
else
raise EJclOperationNotSupportedError.Create;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclAnsiStrAnsiStrSortedMap.Size: Integer;
begin
Result := FSize;
end;
function TJclAnsiStrAnsiStrSortedMap.SubMap(const FromKey, ToKey: AnsiString): IJclAnsiStrAnsiStrSortedMap;
var
FromIndex, ToIndex: Integer;
NewMap: TJclAnsiStrAnsiStrSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclAnsiStrAnsiStrSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
ToIndex := BinarySearch(ToKey);
if (FromIndex >= 0) and (FromIndex <= ToIndex) then
begin
NewMap.SetCapacity(ToIndex - FromIndex + 1);
NewMap.FSize := ToIndex - FromIndex + 1;
while ToIndex >= FromIndex do
begin
NewMap.FEntries[ToIndex - FromIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclAnsiStrAnsiStrSortedMap.TailMap(const FromKey: AnsiString): IJclAnsiStrAnsiStrSortedMap;
var
FromIndex, Index: Integer;
NewMap: TJclAnsiStrAnsiStrSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclAnsiStrAnsiStrSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
if (FromIndex >= 0) and (FromIndex < FSize) then
begin
NewMap.SetCapacity(FSize - FromIndex);
NewMap.FSize := FSize - FromIndex;
Index := FromIndex;
while Index < FSize do
begin
NewMap.FEntries[Index - FromIndex] := FEntries[Index];
Inc(Index);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclAnsiStrAnsiStrSortedMap.Values: IJclAnsiStrCollection;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclAnsiStrArrayList.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Value);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclAnsiStrAnsiStrSortedMap.CreateEmptyContainer: TJclAbstractContainerBase;
begin
Result := TJclAnsiStrAnsiStrSortedMap.Create(FSize);
AssignPropertiesTo(Result);
end;
function TJclAnsiStrAnsiStrSortedMap.FreeKey(var Key: AnsiString): AnsiString;
begin
Result := Key;
Key := '';
end;
function TJclAnsiStrAnsiStrSortedMap.FreeValue(var Value: AnsiString): AnsiString;
begin
Result := Value;
Value := '';
end;
function TJclAnsiStrAnsiStrSortedMap.KeysCompare(const A, B: AnsiString): Integer;
begin
Result := ItemsCompare(A, B);
end;
function TJclAnsiStrAnsiStrSortedMap.ValuesCompare(const A, B: AnsiString): Integer;
begin
Result := ItemsCompare(A, B);
end;
//=== { TJclWideStrIntfSortedMap } ==============================================
constructor TJclWideStrIntfSortedMap.Create(ACapacity: Integer);
begin
inherited Create();
SetCapacity(ACapacity);
end;
destructor TJclWideStrIntfSortedMap.Destroy;
begin
FReadOnly := False;
Clear;
inherited Destroy;
end;
procedure TJclWideStrIntfSortedMap.AssignDataTo(Dest: TJclAbstractContainerBase);
var
MyDest: TJclWideStrIntfSortedMap;
begin
inherited AssignDataTo(Dest);
if Dest is TJclWideStrIntfSortedMap then
begin
MyDest := TJclWideStrIntfSortedMap(Dest);
MyDest.SetCapacity(FSize);
MyDest.FEntries := FEntries;
MyDest.FSize := FSize;
end;
end;
function TJclWideStrIntfSortedMap.BinarySearch(const Key: WideString): Integer;
var
HiPos, LoPos, CompPos: Integer;
Comp: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
LoPos := 0;
HiPos := FSize - 1;
CompPos := (HiPos + LoPos) div 2;
while HiPos >= LoPos do
begin
Comp := KeysCompare(FEntries[CompPos].Key, Key);
if Comp < 0 then
LoPos := CompPos + 1
else
if Comp > 0 then
HiPos := CompPos - 1
else
begin
HiPos := CompPos;
LoPos := CompPos + 1;
end;
CompPos := (HiPos + LoPos) div 2;
end;
Result := HiPos;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclWideStrIntfSortedMap.Clear;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
for Index := 0 to FSize - 1 do
begin
FreeKey(FEntries[Index].Key);
FreeValue(FEntries[Index].Value);
end;
FSize := 0;
AutoPack;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclWideStrIntfSortedMap.ContainsKey(const Key: WideString): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclWideStrIntfSortedMap.ContainsValue(const Value: IInterface): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := True;
Break;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclWideStrIntfSortedMap.FirstKey: WideString;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := '';
if FSize > 0 then
Result := FEntries[0].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclWideStrIntfSortedMap.Extract(const Key: WideString): IInterface;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
Result := FEntries[Index].Value;
FEntries[Index].Value := nil;
FreeKey(FEntries[Index].Key);
if Index < (FSize - 1) then
MoveArray(Index + 1, Index, FSize - Index - 1);
Dec(FSize);
AutoPack;
end
else
Result := nil;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclWideStrIntfSortedMap.GetValue(const Key: WideString): IInterface;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := nil;
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
Result := FEntries[Index].Value
else if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclWideStrIntfSortedMap.HeadMap(const ToKey: WideString): IJclWideStrIntfSortedMap;
var
ToIndex: Integer;
NewMap: TJclWideStrIntfSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclWideStrIntfSortedMap;
ToIndex := BinarySearch(ToKey);
if ToIndex >= 0 then
begin
NewMap.SetCapacity(ToIndex + 1);
NewMap.FSize := ToIndex + 1;
while ToIndex >= 0 do
begin
NewMap.FEntries[ToIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclWideStrIntfSortedMap.IsEmpty: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := FSize = 0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclWideStrIntfSortedMap.KeyOfValue(const Value: IInterface): WideString;
var
Index: Integer;
Found: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Found := False;
Result := '';
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := FEntries[Index].Key;
Found := True;
Break;
end;
if (not Found) and (not FReturnDefaultElements) then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclWideStrIntfSortedMap.KeySet: IJclWideStrSet;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclWideStrArraySet.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Key);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclWideStrIntfSortedMap.LastKey: WideString;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := '';
if FSize > 0 then
Result := FEntries[FSize - 1].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclWideStrIntfSortedMap.MapEquals(const AMap: IJclWideStrIntfMap): Boolean;
var
It: IJclWideStrIterator;
Index: Integer;
AKey: WideString;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
if AMap = nil then
Exit;
if FSize <> AMap.Size then
Exit;
It := AMap.KeySet.First;
Index := 0;
while It.HasNext do
begin
if Index >= FSize then
Exit;
AKey := It.Next;
if ValuesCompare(AMap.GetValue(AKey), FEntries[Index].Value) <> 0 then
Exit;
Inc(Index);
end;
Result := True;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclWideStrIntfSortedMap.MoveArray(FromIndex, ToIndex, Count: Integer);
begin
if Count > 0 then
begin
Move(FEntries[FromIndex], FEntries[ToIndex], Count * SizeOf(FEntries[0]));
{ Keep reference counting working }
if FromIndex < ToIndex then
begin
if (ToIndex - FromIndex) < Count then
FillChar(FEntries[FromIndex], (ToIndex - FromIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end
else
if FromIndex > ToIndex then
begin
if (FromIndex - ToIndex) < Count then
FillChar(FEntries[ToIndex + Count], (FromIndex - ToIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end;
end;
end;
procedure TJclWideStrIntfSortedMap.PutAll(const AMap: IJclWideStrIntfMap);
var
It: IJclWideStrIterator;
Key: WideString;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if AMap = nil then
Exit;
It := AMap.KeySet.First;
while It.HasNext do
begin
Key := It.Next;
PutValue(Key, AMap.GetValue(Key));
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclWideStrIntfSortedMap.PutValue(const Key: WideString; const Value: IInterface);
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FAllowDefaultElements or ((KeysCompare(Key, '') <> 0) and (ValuesCompare(Value, nil) <> 0)) then
begin
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
FreeValue(FEntries[Index].Value);
FEntries[Index].Value := Value;
end
else
begin
if FSize = FCapacity then
AutoGrow;
if FSize < FCapacity then
begin
Inc(Index);
if (Index < FSize) and (KeysCompare(FEntries[Index].Key, Key) <> 0) then
MoveArray(Index, Index + 1, FSize - Index);
FEntries[Index].Key := Key;
FEntries[Index].Value := Value;
Inc(FSize);
end;
end;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclWideStrIntfSortedMap.Remove(const Key: WideString): IInterface;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Result := Extract(Key);
Result := FreeValue(Result);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclWideStrIntfSortedMap.SetCapacity(Value: Integer);
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FSize <= Value then
begin
SetLength(FEntries, Value);
inherited SetCapacity(Value);
end
else
raise EJclOperationNotSupportedError.Create;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclWideStrIntfSortedMap.Size: Integer;
begin
Result := FSize;
end;
function TJclWideStrIntfSortedMap.SubMap(const FromKey, ToKey: WideString): IJclWideStrIntfSortedMap;
var
FromIndex, ToIndex: Integer;
NewMap: TJclWideStrIntfSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclWideStrIntfSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
ToIndex := BinarySearch(ToKey);
if (FromIndex >= 0) and (FromIndex <= ToIndex) then
begin
NewMap.SetCapacity(ToIndex - FromIndex + 1);
NewMap.FSize := ToIndex - FromIndex + 1;
while ToIndex >= FromIndex do
begin
NewMap.FEntries[ToIndex - FromIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclWideStrIntfSortedMap.TailMap(const FromKey: WideString): IJclWideStrIntfSortedMap;
var
FromIndex, Index: Integer;
NewMap: TJclWideStrIntfSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclWideStrIntfSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
if (FromIndex >= 0) and (FromIndex < FSize) then
begin
NewMap.SetCapacity(FSize - FromIndex);
NewMap.FSize := FSize - FromIndex;
Index := FromIndex;
while Index < FSize do
begin
NewMap.FEntries[Index - FromIndex] := FEntries[Index];
Inc(Index);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclWideStrIntfSortedMap.Values: IJclIntfCollection;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclIntfArrayList.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Value);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclWideStrIntfSortedMap.CreateEmptyContainer: TJclAbstractContainerBase;
begin
Result := TJclWideStrIntfSortedMap.Create(FSize);
AssignPropertiesTo(Result);
end;
function TJclWideStrIntfSortedMap.FreeKey(var Key: WideString): WideString;
begin
Result := Key;
Key := '';
end;
function TJclWideStrIntfSortedMap.FreeValue(var Value: IInterface): IInterface;
begin
Result := Value;
Value := nil;
end;
function TJclWideStrIntfSortedMap.KeysCompare(const A, B: WideString): Integer;
begin
Result := ItemsCompare(A, B);
end;
function TJclWideStrIntfSortedMap.ValuesCompare(const A, B: IInterface): Integer;
begin
Result := IntfSimpleCompare(A, B);
end;
//=== { TJclIntfWideStrSortedMap } ==============================================
constructor TJclIntfWideStrSortedMap.Create(ACapacity: Integer);
begin
inherited Create();
SetCapacity(ACapacity);
end;
destructor TJclIntfWideStrSortedMap.Destroy;
begin
FReadOnly := False;
Clear;
inherited Destroy;
end;
procedure TJclIntfWideStrSortedMap.AssignDataTo(Dest: TJclAbstractContainerBase);
var
MyDest: TJclIntfWideStrSortedMap;
begin
inherited AssignDataTo(Dest);
if Dest is TJclIntfWideStrSortedMap then
begin
MyDest := TJclIntfWideStrSortedMap(Dest);
MyDest.SetCapacity(FSize);
MyDest.FEntries := FEntries;
MyDest.FSize := FSize;
end;
end;
function TJclIntfWideStrSortedMap.BinarySearch(const Key: IInterface): Integer;
var
HiPos, LoPos, CompPos: Integer;
Comp: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
LoPos := 0;
HiPos := FSize - 1;
CompPos := (HiPos + LoPos) div 2;
while HiPos >= LoPos do
begin
Comp := KeysCompare(FEntries[CompPos].Key, Key);
if Comp < 0 then
LoPos := CompPos + 1
else
if Comp > 0 then
HiPos := CompPos - 1
else
begin
HiPos := CompPos;
LoPos := CompPos + 1;
end;
CompPos := (HiPos + LoPos) div 2;
end;
Result := HiPos;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntfWideStrSortedMap.Clear;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
for Index := 0 to FSize - 1 do
begin
FreeKey(FEntries[Index].Key);
FreeValue(FEntries[Index].Value);
end;
FSize := 0;
AutoPack;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfWideStrSortedMap.ContainsKey(const Key: IInterface): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfWideStrSortedMap.ContainsValue(const Value: WideString): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := True;
Break;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfWideStrSortedMap.FirstKey: IInterface;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := nil;
if FSize > 0 then
Result := FEntries[0].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfWideStrSortedMap.Extract(const Key: IInterface): WideString;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
Result := FEntries[Index].Value;
FEntries[Index].Value := '';
FreeKey(FEntries[Index].Key);
if Index < (FSize - 1) then
MoveArray(Index + 1, Index, FSize - Index - 1);
Dec(FSize);
AutoPack;
end
else
Result := '';
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfWideStrSortedMap.GetValue(const Key: IInterface): WideString;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := '';
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
Result := FEntries[Index].Value
else if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfWideStrSortedMap.HeadMap(const ToKey: IInterface): IJclIntfWideStrSortedMap;
var
ToIndex: Integer;
NewMap: TJclIntfWideStrSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclIntfWideStrSortedMap;
ToIndex := BinarySearch(ToKey);
if ToIndex >= 0 then
begin
NewMap.SetCapacity(ToIndex + 1);
NewMap.FSize := ToIndex + 1;
while ToIndex >= 0 do
begin
NewMap.FEntries[ToIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfWideStrSortedMap.IsEmpty: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := FSize = 0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfWideStrSortedMap.KeyOfValue(const Value: WideString): IInterface;
var
Index: Integer;
Found: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Found := False;
Result := nil;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := FEntries[Index].Key;
Found := True;
Break;
end;
if (not Found) and (not FReturnDefaultElements) then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfWideStrSortedMap.KeySet: IJclIntfSet;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclIntfArraySet.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Key);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfWideStrSortedMap.LastKey: IInterface;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := nil;
if FSize > 0 then
Result := FEntries[FSize - 1].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfWideStrSortedMap.MapEquals(const AMap: IJclIntfWideStrMap): Boolean;
var
It: IJclIntfIterator;
Index: Integer;
AKey: IInterface;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
if AMap = nil then
Exit;
if FSize <> AMap.Size then
Exit;
It := AMap.KeySet.First;
Index := 0;
while It.HasNext do
begin
if Index >= FSize then
Exit;
AKey := It.Next;
if ValuesCompare(AMap.GetValue(AKey), FEntries[Index].Value) <> 0 then
Exit;
Inc(Index);
end;
Result := True;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntfWideStrSortedMap.MoveArray(FromIndex, ToIndex, Count: Integer);
begin
if Count > 0 then
begin
Move(FEntries[FromIndex], FEntries[ToIndex], Count * SizeOf(FEntries[0]));
{ Keep reference counting working }
if FromIndex < ToIndex then
begin
if (ToIndex - FromIndex) < Count then
FillChar(FEntries[FromIndex], (ToIndex - FromIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end
else
if FromIndex > ToIndex then
begin
if (FromIndex - ToIndex) < Count then
FillChar(FEntries[ToIndex + Count], (FromIndex - ToIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end;
end;
end;
procedure TJclIntfWideStrSortedMap.PutAll(const AMap: IJclIntfWideStrMap);
var
It: IJclIntfIterator;
Key: IInterface;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if AMap = nil then
Exit;
It := AMap.KeySet.First;
while It.HasNext do
begin
Key := It.Next;
PutValue(Key, AMap.GetValue(Key));
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntfWideStrSortedMap.PutValue(const Key: IInterface; const Value: WideString);
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FAllowDefaultElements or ((KeysCompare(Key, nil) <> 0) and (ValuesCompare(Value, '') <> 0)) then
begin
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
FreeValue(FEntries[Index].Value);
FEntries[Index].Value := Value;
end
else
begin
if FSize = FCapacity then
AutoGrow;
if FSize < FCapacity then
begin
Inc(Index);
if (Index < FSize) and (KeysCompare(FEntries[Index].Key, Key) <> 0) then
MoveArray(Index, Index + 1, FSize - Index);
FEntries[Index].Key := Key;
FEntries[Index].Value := Value;
Inc(FSize);
end;
end;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfWideStrSortedMap.Remove(const Key: IInterface): WideString;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Result := Extract(Key);
Result := FreeValue(Result);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntfWideStrSortedMap.SetCapacity(Value: Integer);
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FSize <= Value then
begin
SetLength(FEntries, Value);
inherited SetCapacity(Value);
end
else
raise EJclOperationNotSupportedError.Create;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfWideStrSortedMap.Size: Integer;
begin
Result := FSize;
end;
function TJclIntfWideStrSortedMap.SubMap(const FromKey, ToKey: IInterface): IJclIntfWideStrSortedMap;
var
FromIndex, ToIndex: Integer;
NewMap: TJclIntfWideStrSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclIntfWideStrSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
ToIndex := BinarySearch(ToKey);
if (FromIndex >= 0) and (FromIndex <= ToIndex) then
begin
NewMap.SetCapacity(ToIndex - FromIndex + 1);
NewMap.FSize := ToIndex - FromIndex + 1;
while ToIndex >= FromIndex do
begin
NewMap.FEntries[ToIndex - FromIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfWideStrSortedMap.TailMap(const FromKey: IInterface): IJclIntfWideStrSortedMap;
var
FromIndex, Index: Integer;
NewMap: TJclIntfWideStrSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclIntfWideStrSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
if (FromIndex >= 0) and (FromIndex < FSize) then
begin
NewMap.SetCapacity(FSize - FromIndex);
NewMap.FSize := FSize - FromIndex;
Index := FromIndex;
while Index < FSize do
begin
NewMap.FEntries[Index - FromIndex] := FEntries[Index];
Inc(Index);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfWideStrSortedMap.Values: IJclWideStrCollection;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclWideStrArrayList.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Value);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfWideStrSortedMap.CreateEmptyContainer: TJclAbstractContainerBase;
begin
Result := TJclIntfWideStrSortedMap.Create(FSize);
AssignPropertiesTo(Result);
end;
function TJclIntfWideStrSortedMap.FreeKey(var Key: IInterface): IInterface;
begin
Result := Key;
Key := nil;
end;
function TJclIntfWideStrSortedMap.FreeValue(var Value: WideString): WideString;
begin
Result := Value;
Value := '';
end;
function TJclIntfWideStrSortedMap.KeysCompare(const A, B: IInterface): Integer;
begin
Result := IntfSimpleCompare(A, B);
end;
function TJclIntfWideStrSortedMap.ValuesCompare(const A, B: WideString): Integer;
begin
Result := ItemsCompare(A, B);
end;
//=== { TJclWideStrWideStrSortedMap } ==============================================
constructor TJclWideStrWideStrSortedMap.Create(ACapacity: Integer);
begin
inherited Create();
SetCapacity(ACapacity);
end;
destructor TJclWideStrWideStrSortedMap.Destroy;
begin
FReadOnly := False;
Clear;
inherited Destroy;
end;
procedure TJclWideStrWideStrSortedMap.AssignDataTo(Dest: TJclAbstractContainerBase);
var
MyDest: TJclWideStrWideStrSortedMap;
begin
inherited AssignDataTo(Dest);
if Dest is TJclWideStrWideStrSortedMap then
begin
MyDest := TJclWideStrWideStrSortedMap(Dest);
MyDest.SetCapacity(FSize);
MyDest.FEntries := FEntries;
MyDest.FSize := FSize;
end;
end;
function TJclWideStrWideStrSortedMap.BinarySearch(const Key: WideString): Integer;
var
HiPos, LoPos, CompPos: Integer;
Comp: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
LoPos := 0;
HiPos := FSize - 1;
CompPos := (HiPos + LoPos) div 2;
while HiPos >= LoPos do
begin
Comp := KeysCompare(FEntries[CompPos].Key, Key);
if Comp < 0 then
LoPos := CompPos + 1
else
if Comp > 0 then
HiPos := CompPos - 1
else
begin
HiPos := CompPos;
LoPos := CompPos + 1;
end;
CompPos := (HiPos + LoPos) div 2;
end;
Result := HiPos;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclWideStrWideStrSortedMap.Clear;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
for Index := 0 to FSize - 1 do
begin
FreeKey(FEntries[Index].Key);
FreeValue(FEntries[Index].Value);
end;
FSize := 0;
AutoPack;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclWideStrWideStrSortedMap.ContainsKey(const Key: WideString): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclWideStrWideStrSortedMap.ContainsValue(const Value: WideString): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := True;
Break;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclWideStrWideStrSortedMap.FirstKey: WideString;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := '';
if FSize > 0 then
Result := FEntries[0].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclWideStrWideStrSortedMap.Extract(const Key: WideString): WideString;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
Result := FEntries[Index].Value;
FEntries[Index].Value := '';
FreeKey(FEntries[Index].Key);
if Index < (FSize - 1) then
MoveArray(Index + 1, Index, FSize - Index - 1);
Dec(FSize);
AutoPack;
end
else
Result := '';
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclWideStrWideStrSortedMap.GetValue(const Key: WideString): WideString;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := '';
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
Result := FEntries[Index].Value
else if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclWideStrWideStrSortedMap.HeadMap(const ToKey: WideString): IJclWideStrWideStrSortedMap;
var
ToIndex: Integer;
NewMap: TJclWideStrWideStrSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclWideStrWideStrSortedMap;
ToIndex := BinarySearch(ToKey);
if ToIndex >= 0 then
begin
NewMap.SetCapacity(ToIndex + 1);
NewMap.FSize := ToIndex + 1;
while ToIndex >= 0 do
begin
NewMap.FEntries[ToIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclWideStrWideStrSortedMap.IsEmpty: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := FSize = 0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclWideStrWideStrSortedMap.KeyOfValue(const Value: WideString): WideString;
var
Index: Integer;
Found: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Found := False;
Result := '';
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := FEntries[Index].Key;
Found := True;
Break;
end;
if (not Found) and (not FReturnDefaultElements) then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclWideStrWideStrSortedMap.KeySet: IJclWideStrSet;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclWideStrArraySet.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Key);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclWideStrWideStrSortedMap.LastKey: WideString;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := '';
if FSize > 0 then
Result := FEntries[FSize - 1].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclWideStrWideStrSortedMap.MapEquals(const AMap: IJclWideStrWideStrMap): Boolean;
var
It: IJclWideStrIterator;
Index: Integer;
AKey: WideString;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
if AMap = nil then
Exit;
if FSize <> AMap.Size then
Exit;
It := AMap.KeySet.First;
Index := 0;
while It.HasNext do
begin
if Index >= FSize then
Exit;
AKey := It.Next;
if ValuesCompare(AMap.GetValue(AKey), FEntries[Index].Value) <> 0 then
Exit;
Inc(Index);
end;
Result := True;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclWideStrWideStrSortedMap.MoveArray(FromIndex, ToIndex, Count: Integer);
begin
if Count > 0 then
begin
Move(FEntries[FromIndex], FEntries[ToIndex], Count * SizeOf(FEntries[0]));
{ Keep reference counting working }
if FromIndex < ToIndex then
begin
if (ToIndex - FromIndex) < Count then
FillChar(FEntries[FromIndex], (ToIndex - FromIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end
else
if FromIndex > ToIndex then
begin
if (FromIndex - ToIndex) < Count then
FillChar(FEntries[ToIndex + Count], (FromIndex - ToIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end;
end;
end;
procedure TJclWideStrWideStrSortedMap.PutAll(const AMap: IJclWideStrWideStrMap);
var
It: IJclWideStrIterator;
Key: WideString;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if AMap = nil then
Exit;
It := AMap.KeySet.First;
while It.HasNext do
begin
Key := It.Next;
PutValue(Key, AMap.GetValue(Key));
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclWideStrWideStrSortedMap.PutValue(const Key: WideString; const Value: WideString);
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FAllowDefaultElements or ((KeysCompare(Key, '') <> 0) and (ValuesCompare(Value, '') <> 0)) then
begin
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
FreeValue(FEntries[Index].Value);
FEntries[Index].Value := Value;
end
else
begin
if FSize = FCapacity then
AutoGrow;
if FSize < FCapacity then
begin
Inc(Index);
if (Index < FSize) and (KeysCompare(FEntries[Index].Key, Key) <> 0) then
MoveArray(Index, Index + 1, FSize - Index);
FEntries[Index].Key := Key;
FEntries[Index].Value := Value;
Inc(FSize);
end;
end;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclWideStrWideStrSortedMap.Remove(const Key: WideString): WideString;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Result := Extract(Key);
Result := FreeValue(Result);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclWideStrWideStrSortedMap.SetCapacity(Value: Integer);
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FSize <= Value then
begin
SetLength(FEntries, Value);
inherited SetCapacity(Value);
end
else
raise EJclOperationNotSupportedError.Create;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclWideStrWideStrSortedMap.Size: Integer;
begin
Result := FSize;
end;
function TJclWideStrWideStrSortedMap.SubMap(const FromKey, ToKey: WideString): IJclWideStrWideStrSortedMap;
var
FromIndex, ToIndex: Integer;
NewMap: TJclWideStrWideStrSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclWideStrWideStrSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
ToIndex := BinarySearch(ToKey);
if (FromIndex >= 0) and (FromIndex <= ToIndex) then
begin
NewMap.SetCapacity(ToIndex - FromIndex + 1);
NewMap.FSize := ToIndex - FromIndex + 1;
while ToIndex >= FromIndex do
begin
NewMap.FEntries[ToIndex - FromIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclWideStrWideStrSortedMap.TailMap(const FromKey: WideString): IJclWideStrWideStrSortedMap;
var
FromIndex, Index: Integer;
NewMap: TJclWideStrWideStrSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclWideStrWideStrSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
if (FromIndex >= 0) and (FromIndex < FSize) then
begin
NewMap.SetCapacity(FSize - FromIndex);
NewMap.FSize := FSize - FromIndex;
Index := FromIndex;
while Index < FSize do
begin
NewMap.FEntries[Index - FromIndex] := FEntries[Index];
Inc(Index);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclWideStrWideStrSortedMap.Values: IJclWideStrCollection;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclWideStrArrayList.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Value);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclWideStrWideStrSortedMap.CreateEmptyContainer: TJclAbstractContainerBase;
begin
Result := TJclWideStrWideStrSortedMap.Create(FSize);
AssignPropertiesTo(Result);
end;
function TJclWideStrWideStrSortedMap.FreeKey(var Key: WideString): WideString;
begin
Result := Key;
Key := '';
end;
function TJclWideStrWideStrSortedMap.FreeValue(var Value: WideString): WideString;
begin
Result := Value;
Value := '';
end;
function TJclWideStrWideStrSortedMap.KeysCompare(const A, B: WideString): Integer;
begin
Result := ItemsCompare(A, B);
end;
function TJclWideStrWideStrSortedMap.ValuesCompare(const A, B: WideString): Integer;
begin
Result := ItemsCompare(A, B);
end;
{$IFDEF SUPPORTS_UNICODE_STRING}
//=== { TJclUnicodeStrIntfSortedMap } ==============================================
constructor TJclUnicodeStrIntfSortedMap.Create(ACapacity: Integer);
begin
inherited Create();
SetCapacity(ACapacity);
end;
destructor TJclUnicodeStrIntfSortedMap.Destroy;
begin
FReadOnly := False;
Clear;
inherited Destroy;
end;
procedure TJclUnicodeStrIntfSortedMap.AssignDataTo(Dest: TJclAbstractContainerBase);
var
MyDest: TJclUnicodeStrIntfSortedMap;
begin
inherited AssignDataTo(Dest);
if Dest is TJclUnicodeStrIntfSortedMap then
begin
MyDest := TJclUnicodeStrIntfSortedMap(Dest);
MyDest.SetCapacity(FSize);
MyDest.FEntries := FEntries;
MyDest.FSize := FSize;
end;
end;
function TJclUnicodeStrIntfSortedMap.BinarySearch(const Key: UnicodeString): Integer;
var
HiPos, LoPos, CompPos: Integer;
Comp: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
LoPos := 0;
HiPos := FSize - 1;
CompPos := (HiPos + LoPos) div 2;
while HiPos >= LoPos do
begin
Comp := KeysCompare(FEntries[CompPos].Key, Key);
if Comp < 0 then
LoPos := CompPos + 1
else
if Comp > 0 then
HiPos := CompPos - 1
else
begin
HiPos := CompPos;
LoPos := CompPos + 1;
end;
CompPos := (HiPos + LoPos) div 2;
end;
Result := HiPos;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclUnicodeStrIntfSortedMap.Clear;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
for Index := 0 to FSize - 1 do
begin
FreeKey(FEntries[Index].Key);
FreeValue(FEntries[Index].Value);
end;
FSize := 0;
AutoPack;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclUnicodeStrIntfSortedMap.ContainsKey(const Key: UnicodeString): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclUnicodeStrIntfSortedMap.ContainsValue(const Value: IInterface): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := True;
Break;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclUnicodeStrIntfSortedMap.FirstKey: UnicodeString;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := '';
if FSize > 0 then
Result := FEntries[0].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclUnicodeStrIntfSortedMap.Extract(const Key: UnicodeString): IInterface;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
Result := FEntries[Index].Value;
FEntries[Index].Value := nil;
FreeKey(FEntries[Index].Key);
if Index < (FSize - 1) then
MoveArray(Index + 1, Index, FSize - Index - 1);
Dec(FSize);
AutoPack;
end
else
Result := nil;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclUnicodeStrIntfSortedMap.GetValue(const Key: UnicodeString): IInterface;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := nil;
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
Result := FEntries[Index].Value
else if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclUnicodeStrIntfSortedMap.HeadMap(const ToKey: UnicodeString): IJclUnicodeStrIntfSortedMap;
var
ToIndex: Integer;
NewMap: TJclUnicodeStrIntfSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclUnicodeStrIntfSortedMap;
ToIndex := BinarySearch(ToKey);
if ToIndex >= 0 then
begin
NewMap.SetCapacity(ToIndex + 1);
NewMap.FSize := ToIndex + 1;
while ToIndex >= 0 do
begin
NewMap.FEntries[ToIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclUnicodeStrIntfSortedMap.IsEmpty: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := FSize = 0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclUnicodeStrIntfSortedMap.KeyOfValue(const Value: IInterface): UnicodeString;
var
Index: Integer;
Found: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Found := False;
Result := '';
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := FEntries[Index].Key;
Found := True;
Break;
end;
if (not Found) and (not FReturnDefaultElements) then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclUnicodeStrIntfSortedMap.KeySet: IJclUnicodeStrSet;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclUnicodeStrArraySet.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Key);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclUnicodeStrIntfSortedMap.LastKey: UnicodeString;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := '';
if FSize > 0 then
Result := FEntries[FSize - 1].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclUnicodeStrIntfSortedMap.MapEquals(const AMap: IJclUnicodeStrIntfMap): Boolean;
var
It: IJclUnicodeStrIterator;
Index: Integer;
AKey: UnicodeString;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
if AMap = nil then
Exit;
if FSize <> AMap.Size then
Exit;
It := AMap.KeySet.First;
Index := 0;
while It.HasNext do
begin
if Index >= FSize then
Exit;
AKey := It.Next;
if ValuesCompare(AMap.GetValue(AKey), FEntries[Index].Value) <> 0 then
Exit;
Inc(Index);
end;
Result := True;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclUnicodeStrIntfSortedMap.MoveArray(FromIndex, ToIndex, Count: Integer);
begin
if Count > 0 then
begin
Move(FEntries[FromIndex], FEntries[ToIndex], Count * SizeOf(FEntries[0]));
{ Keep reference counting working }
if FromIndex < ToIndex then
begin
if (ToIndex - FromIndex) < Count then
FillChar(FEntries[FromIndex], (ToIndex - FromIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end
else
if FromIndex > ToIndex then
begin
if (FromIndex - ToIndex) < Count then
FillChar(FEntries[ToIndex + Count], (FromIndex - ToIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end;
end;
end;
procedure TJclUnicodeStrIntfSortedMap.PutAll(const AMap: IJclUnicodeStrIntfMap);
var
It: IJclUnicodeStrIterator;
Key: UnicodeString;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if AMap = nil then
Exit;
It := AMap.KeySet.First;
while It.HasNext do
begin
Key := It.Next;
PutValue(Key, AMap.GetValue(Key));
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclUnicodeStrIntfSortedMap.PutValue(const Key: UnicodeString; const Value: IInterface);
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FAllowDefaultElements or ((KeysCompare(Key, '') <> 0) and (ValuesCompare(Value, nil) <> 0)) then
begin
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
FreeValue(FEntries[Index].Value);
FEntries[Index].Value := Value;
end
else
begin
if FSize = FCapacity then
AutoGrow;
if FSize < FCapacity then
begin
Inc(Index);
if (Index < FSize) and (KeysCompare(FEntries[Index].Key, Key) <> 0) then
MoveArray(Index, Index + 1, FSize - Index);
FEntries[Index].Key := Key;
FEntries[Index].Value := Value;
Inc(FSize);
end;
end;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclUnicodeStrIntfSortedMap.Remove(const Key: UnicodeString): IInterface;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Result := Extract(Key);
Result := FreeValue(Result);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclUnicodeStrIntfSortedMap.SetCapacity(Value: Integer);
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FSize <= Value then
begin
SetLength(FEntries, Value);
inherited SetCapacity(Value);
end
else
raise EJclOperationNotSupportedError.Create;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclUnicodeStrIntfSortedMap.Size: Integer;
begin
Result := FSize;
end;
function TJclUnicodeStrIntfSortedMap.SubMap(const FromKey, ToKey: UnicodeString): IJclUnicodeStrIntfSortedMap;
var
FromIndex, ToIndex: Integer;
NewMap: TJclUnicodeStrIntfSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclUnicodeStrIntfSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
ToIndex := BinarySearch(ToKey);
if (FromIndex >= 0) and (FromIndex <= ToIndex) then
begin
NewMap.SetCapacity(ToIndex - FromIndex + 1);
NewMap.FSize := ToIndex - FromIndex + 1;
while ToIndex >= FromIndex do
begin
NewMap.FEntries[ToIndex - FromIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclUnicodeStrIntfSortedMap.TailMap(const FromKey: UnicodeString): IJclUnicodeStrIntfSortedMap;
var
FromIndex, Index: Integer;
NewMap: TJclUnicodeStrIntfSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclUnicodeStrIntfSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
if (FromIndex >= 0) and (FromIndex < FSize) then
begin
NewMap.SetCapacity(FSize - FromIndex);
NewMap.FSize := FSize - FromIndex;
Index := FromIndex;
while Index < FSize do
begin
NewMap.FEntries[Index - FromIndex] := FEntries[Index];
Inc(Index);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclUnicodeStrIntfSortedMap.Values: IJclIntfCollection;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclIntfArrayList.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Value);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclUnicodeStrIntfSortedMap.CreateEmptyContainer: TJclAbstractContainerBase;
begin
Result := TJclUnicodeStrIntfSortedMap.Create(FSize);
AssignPropertiesTo(Result);
end;
function TJclUnicodeStrIntfSortedMap.FreeKey(var Key: UnicodeString): UnicodeString;
begin
Result := Key;
Key := '';
end;
function TJclUnicodeStrIntfSortedMap.FreeValue(var Value: IInterface): IInterface;
begin
Result := Value;
Value := nil;
end;
function TJclUnicodeStrIntfSortedMap.KeysCompare(const A, B: UnicodeString): Integer;
begin
Result := ItemsCompare(A, B);
end;
function TJclUnicodeStrIntfSortedMap.ValuesCompare(const A, B: IInterface): Integer;
begin
Result := IntfSimpleCompare(A, B);
end;
{$ENDIF SUPPORTS_UNICODE_STRING}
{$IFDEF SUPPORTS_UNICODE_STRING}
//=== { TJclIntfUnicodeStrSortedMap } ==============================================
constructor TJclIntfUnicodeStrSortedMap.Create(ACapacity: Integer);
begin
inherited Create();
SetCapacity(ACapacity);
end;
destructor TJclIntfUnicodeStrSortedMap.Destroy;
begin
FReadOnly := False;
Clear;
inherited Destroy;
end;
procedure TJclIntfUnicodeStrSortedMap.AssignDataTo(Dest: TJclAbstractContainerBase);
var
MyDest: TJclIntfUnicodeStrSortedMap;
begin
inherited AssignDataTo(Dest);
if Dest is TJclIntfUnicodeStrSortedMap then
begin
MyDest := TJclIntfUnicodeStrSortedMap(Dest);
MyDest.SetCapacity(FSize);
MyDest.FEntries := FEntries;
MyDest.FSize := FSize;
end;
end;
function TJclIntfUnicodeStrSortedMap.BinarySearch(const Key: IInterface): Integer;
var
HiPos, LoPos, CompPos: Integer;
Comp: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
LoPos := 0;
HiPos := FSize - 1;
CompPos := (HiPos + LoPos) div 2;
while HiPos >= LoPos do
begin
Comp := KeysCompare(FEntries[CompPos].Key, Key);
if Comp < 0 then
LoPos := CompPos + 1
else
if Comp > 0 then
HiPos := CompPos - 1
else
begin
HiPos := CompPos;
LoPos := CompPos + 1;
end;
CompPos := (HiPos + LoPos) div 2;
end;
Result := HiPos;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntfUnicodeStrSortedMap.Clear;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
for Index := 0 to FSize - 1 do
begin
FreeKey(FEntries[Index].Key);
FreeValue(FEntries[Index].Value);
end;
FSize := 0;
AutoPack;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfUnicodeStrSortedMap.ContainsKey(const Key: IInterface): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfUnicodeStrSortedMap.ContainsValue(const Value: UnicodeString): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := True;
Break;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfUnicodeStrSortedMap.FirstKey: IInterface;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := nil;
if FSize > 0 then
Result := FEntries[0].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfUnicodeStrSortedMap.Extract(const Key: IInterface): UnicodeString;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
Result := FEntries[Index].Value;
FEntries[Index].Value := '';
FreeKey(FEntries[Index].Key);
if Index < (FSize - 1) then
MoveArray(Index + 1, Index, FSize - Index - 1);
Dec(FSize);
AutoPack;
end
else
Result := '';
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfUnicodeStrSortedMap.GetValue(const Key: IInterface): UnicodeString;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := '';
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
Result := FEntries[Index].Value
else if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfUnicodeStrSortedMap.HeadMap(const ToKey: IInterface): IJclIntfUnicodeStrSortedMap;
var
ToIndex: Integer;
NewMap: TJclIntfUnicodeStrSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclIntfUnicodeStrSortedMap;
ToIndex := BinarySearch(ToKey);
if ToIndex >= 0 then
begin
NewMap.SetCapacity(ToIndex + 1);
NewMap.FSize := ToIndex + 1;
while ToIndex >= 0 do
begin
NewMap.FEntries[ToIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfUnicodeStrSortedMap.IsEmpty: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := FSize = 0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfUnicodeStrSortedMap.KeyOfValue(const Value: UnicodeString): IInterface;
var
Index: Integer;
Found: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Found := False;
Result := nil;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := FEntries[Index].Key;
Found := True;
Break;
end;
if (not Found) and (not FReturnDefaultElements) then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfUnicodeStrSortedMap.KeySet: IJclIntfSet;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclIntfArraySet.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Key);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfUnicodeStrSortedMap.LastKey: IInterface;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := nil;
if FSize > 0 then
Result := FEntries[FSize - 1].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfUnicodeStrSortedMap.MapEquals(const AMap: IJclIntfUnicodeStrMap): Boolean;
var
It: IJclIntfIterator;
Index: Integer;
AKey: IInterface;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
if AMap = nil then
Exit;
if FSize <> AMap.Size then
Exit;
It := AMap.KeySet.First;
Index := 0;
while It.HasNext do
begin
if Index >= FSize then
Exit;
AKey := It.Next;
if ValuesCompare(AMap.GetValue(AKey), FEntries[Index].Value) <> 0 then
Exit;
Inc(Index);
end;
Result := True;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntfUnicodeStrSortedMap.MoveArray(FromIndex, ToIndex, Count: Integer);
begin
if Count > 0 then
begin
Move(FEntries[FromIndex], FEntries[ToIndex], Count * SizeOf(FEntries[0]));
{ Keep reference counting working }
if FromIndex < ToIndex then
begin
if (ToIndex - FromIndex) < Count then
FillChar(FEntries[FromIndex], (ToIndex - FromIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end
else
if FromIndex > ToIndex then
begin
if (FromIndex - ToIndex) < Count then
FillChar(FEntries[ToIndex + Count], (FromIndex - ToIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end;
end;
end;
procedure TJclIntfUnicodeStrSortedMap.PutAll(const AMap: IJclIntfUnicodeStrMap);
var
It: IJclIntfIterator;
Key: IInterface;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if AMap = nil then
Exit;
It := AMap.KeySet.First;
while It.HasNext do
begin
Key := It.Next;
PutValue(Key, AMap.GetValue(Key));
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntfUnicodeStrSortedMap.PutValue(const Key: IInterface; const Value: UnicodeString);
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FAllowDefaultElements or ((KeysCompare(Key, nil) <> 0) and (ValuesCompare(Value, '') <> 0)) then
begin
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
FreeValue(FEntries[Index].Value);
FEntries[Index].Value := Value;
end
else
begin
if FSize = FCapacity then
AutoGrow;
if FSize < FCapacity then
begin
Inc(Index);
if (Index < FSize) and (KeysCompare(FEntries[Index].Key, Key) <> 0) then
MoveArray(Index, Index + 1, FSize - Index);
FEntries[Index].Key := Key;
FEntries[Index].Value := Value;
Inc(FSize);
end;
end;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfUnicodeStrSortedMap.Remove(const Key: IInterface): UnicodeString;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Result := Extract(Key);
Result := FreeValue(Result);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntfUnicodeStrSortedMap.SetCapacity(Value: Integer);
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FSize <= Value then
begin
SetLength(FEntries, Value);
inherited SetCapacity(Value);
end
else
raise EJclOperationNotSupportedError.Create;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfUnicodeStrSortedMap.Size: Integer;
begin
Result := FSize;
end;
function TJclIntfUnicodeStrSortedMap.SubMap(const FromKey, ToKey: IInterface): IJclIntfUnicodeStrSortedMap;
var
FromIndex, ToIndex: Integer;
NewMap: TJclIntfUnicodeStrSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclIntfUnicodeStrSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
ToIndex := BinarySearch(ToKey);
if (FromIndex >= 0) and (FromIndex <= ToIndex) then
begin
NewMap.SetCapacity(ToIndex - FromIndex + 1);
NewMap.FSize := ToIndex - FromIndex + 1;
while ToIndex >= FromIndex do
begin
NewMap.FEntries[ToIndex - FromIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfUnicodeStrSortedMap.TailMap(const FromKey: IInterface): IJclIntfUnicodeStrSortedMap;
var
FromIndex, Index: Integer;
NewMap: TJclIntfUnicodeStrSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclIntfUnicodeStrSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
if (FromIndex >= 0) and (FromIndex < FSize) then
begin
NewMap.SetCapacity(FSize - FromIndex);
NewMap.FSize := FSize - FromIndex;
Index := FromIndex;
while Index < FSize do
begin
NewMap.FEntries[Index - FromIndex] := FEntries[Index];
Inc(Index);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfUnicodeStrSortedMap.Values: IJclUnicodeStrCollection;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclUnicodeStrArrayList.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Value);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfUnicodeStrSortedMap.CreateEmptyContainer: TJclAbstractContainerBase;
begin
Result := TJclIntfUnicodeStrSortedMap.Create(FSize);
AssignPropertiesTo(Result);
end;
function TJclIntfUnicodeStrSortedMap.FreeKey(var Key: IInterface): IInterface;
begin
Result := Key;
Key := nil;
end;
function TJclIntfUnicodeStrSortedMap.FreeValue(var Value: UnicodeString): UnicodeString;
begin
Result := Value;
Value := '';
end;
function TJclIntfUnicodeStrSortedMap.KeysCompare(const A, B: IInterface): Integer;
begin
Result := IntfSimpleCompare(A, B);
end;
function TJclIntfUnicodeStrSortedMap.ValuesCompare(const A, B: UnicodeString): Integer;
begin
Result := ItemsCompare(A, B);
end;
{$ENDIF SUPPORTS_UNICODE_STRING}
{$IFDEF SUPPORTS_UNICODE_STRING}
//=== { TJclUnicodeStrUnicodeStrSortedMap } ==============================================
constructor TJclUnicodeStrUnicodeStrSortedMap.Create(ACapacity: Integer);
begin
inherited Create();
SetCapacity(ACapacity);
end;
destructor TJclUnicodeStrUnicodeStrSortedMap.Destroy;
begin
FReadOnly := False;
Clear;
inherited Destroy;
end;
procedure TJclUnicodeStrUnicodeStrSortedMap.AssignDataTo(Dest: TJclAbstractContainerBase);
var
MyDest: TJclUnicodeStrUnicodeStrSortedMap;
begin
inherited AssignDataTo(Dest);
if Dest is TJclUnicodeStrUnicodeStrSortedMap then
begin
MyDest := TJclUnicodeStrUnicodeStrSortedMap(Dest);
MyDest.SetCapacity(FSize);
MyDest.FEntries := FEntries;
MyDest.FSize := FSize;
end;
end;
function TJclUnicodeStrUnicodeStrSortedMap.BinarySearch(const Key: UnicodeString): Integer;
var
HiPos, LoPos, CompPos: Integer;
Comp: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
LoPos := 0;
HiPos := FSize - 1;
CompPos := (HiPos + LoPos) div 2;
while HiPos >= LoPos do
begin
Comp := KeysCompare(FEntries[CompPos].Key, Key);
if Comp < 0 then
LoPos := CompPos + 1
else
if Comp > 0 then
HiPos := CompPos - 1
else
begin
HiPos := CompPos;
LoPos := CompPos + 1;
end;
CompPos := (HiPos + LoPos) div 2;
end;
Result := HiPos;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclUnicodeStrUnicodeStrSortedMap.Clear;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
for Index := 0 to FSize - 1 do
begin
FreeKey(FEntries[Index].Key);
FreeValue(FEntries[Index].Value);
end;
FSize := 0;
AutoPack;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclUnicodeStrUnicodeStrSortedMap.ContainsKey(const Key: UnicodeString): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclUnicodeStrUnicodeStrSortedMap.ContainsValue(const Value: UnicodeString): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := True;
Break;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclUnicodeStrUnicodeStrSortedMap.FirstKey: UnicodeString;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := '';
if FSize > 0 then
Result := FEntries[0].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclUnicodeStrUnicodeStrSortedMap.Extract(const Key: UnicodeString): UnicodeString;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
Result := FEntries[Index].Value;
FEntries[Index].Value := '';
FreeKey(FEntries[Index].Key);
if Index < (FSize - 1) then
MoveArray(Index + 1, Index, FSize - Index - 1);
Dec(FSize);
AutoPack;
end
else
Result := '';
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclUnicodeStrUnicodeStrSortedMap.GetValue(const Key: UnicodeString): UnicodeString;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := '';
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
Result := FEntries[Index].Value
else if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclUnicodeStrUnicodeStrSortedMap.HeadMap(const ToKey: UnicodeString): IJclUnicodeStrUnicodeStrSortedMap;
var
ToIndex: Integer;
NewMap: TJclUnicodeStrUnicodeStrSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclUnicodeStrUnicodeStrSortedMap;
ToIndex := BinarySearch(ToKey);
if ToIndex >= 0 then
begin
NewMap.SetCapacity(ToIndex + 1);
NewMap.FSize := ToIndex + 1;
while ToIndex >= 0 do
begin
NewMap.FEntries[ToIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclUnicodeStrUnicodeStrSortedMap.IsEmpty: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := FSize = 0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclUnicodeStrUnicodeStrSortedMap.KeyOfValue(const Value: UnicodeString): UnicodeString;
var
Index: Integer;
Found: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Found := False;
Result := '';
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := FEntries[Index].Key;
Found := True;
Break;
end;
if (not Found) and (not FReturnDefaultElements) then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclUnicodeStrUnicodeStrSortedMap.KeySet: IJclUnicodeStrSet;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclUnicodeStrArraySet.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Key);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclUnicodeStrUnicodeStrSortedMap.LastKey: UnicodeString;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := '';
if FSize > 0 then
Result := FEntries[FSize - 1].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclUnicodeStrUnicodeStrSortedMap.MapEquals(const AMap: IJclUnicodeStrUnicodeStrMap): Boolean;
var
It: IJclUnicodeStrIterator;
Index: Integer;
AKey: UnicodeString;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
if AMap = nil then
Exit;
if FSize <> AMap.Size then
Exit;
It := AMap.KeySet.First;
Index := 0;
while It.HasNext do
begin
if Index >= FSize then
Exit;
AKey := It.Next;
if ValuesCompare(AMap.GetValue(AKey), FEntries[Index].Value) <> 0 then
Exit;
Inc(Index);
end;
Result := True;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclUnicodeStrUnicodeStrSortedMap.MoveArray(FromIndex, ToIndex, Count: Integer);
begin
if Count > 0 then
begin
Move(FEntries[FromIndex], FEntries[ToIndex], Count * SizeOf(FEntries[0]));
{ Keep reference counting working }
if FromIndex < ToIndex then
begin
if (ToIndex - FromIndex) < Count then
FillChar(FEntries[FromIndex], (ToIndex - FromIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end
else
if FromIndex > ToIndex then
begin
if (FromIndex - ToIndex) < Count then
FillChar(FEntries[ToIndex + Count], (FromIndex - ToIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end;
end;
end;
procedure TJclUnicodeStrUnicodeStrSortedMap.PutAll(const AMap: IJclUnicodeStrUnicodeStrMap);
var
It: IJclUnicodeStrIterator;
Key: UnicodeString;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if AMap = nil then
Exit;
It := AMap.KeySet.First;
while It.HasNext do
begin
Key := It.Next;
PutValue(Key, AMap.GetValue(Key));
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclUnicodeStrUnicodeStrSortedMap.PutValue(const Key: UnicodeString; const Value: UnicodeString);
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FAllowDefaultElements or ((KeysCompare(Key, '') <> 0) and (ValuesCompare(Value, '') <> 0)) then
begin
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
FreeValue(FEntries[Index].Value);
FEntries[Index].Value := Value;
end
else
begin
if FSize = FCapacity then
AutoGrow;
if FSize < FCapacity then
begin
Inc(Index);
if (Index < FSize) and (KeysCompare(FEntries[Index].Key, Key) <> 0) then
MoveArray(Index, Index + 1, FSize - Index);
FEntries[Index].Key := Key;
FEntries[Index].Value := Value;
Inc(FSize);
end;
end;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclUnicodeStrUnicodeStrSortedMap.Remove(const Key: UnicodeString): UnicodeString;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Result := Extract(Key);
Result := FreeValue(Result);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclUnicodeStrUnicodeStrSortedMap.SetCapacity(Value: Integer);
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FSize <= Value then
begin
SetLength(FEntries, Value);
inherited SetCapacity(Value);
end
else
raise EJclOperationNotSupportedError.Create;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclUnicodeStrUnicodeStrSortedMap.Size: Integer;
begin
Result := FSize;
end;
function TJclUnicodeStrUnicodeStrSortedMap.SubMap(const FromKey, ToKey: UnicodeString): IJclUnicodeStrUnicodeStrSortedMap;
var
FromIndex, ToIndex: Integer;
NewMap: TJclUnicodeStrUnicodeStrSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclUnicodeStrUnicodeStrSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
ToIndex := BinarySearch(ToKey);
if (FromIndex >= 0) and (FromIndex <= ToIndex) then
begin
NewMap.SetCapacity(ToIndex - FromIndex + 1);
NewMap.FSize := ToIndex - FromIndex + 1;
while ToIndex >= FromIndex do
begin
NewMap.FEntries[ToIndex - FromIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclUnicodeStrUnicodeStrSortedMap.TailMap(const FromKey: UnicodeString): IJclUnicodeStrUnicodeStrSortedMap;
var
FromIndex, Index: Integer;
NewMap: TJclUnicodeStrUnicodeStrSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclUnicodeStrUnicodeStrSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
if (FromIndex >= 0) and (FromIndex < FSize) then
begin
NewMap.SetCapacity(FSize - FromIndex);
NewMap.FSize := FSize - FromIndex;
Index := FromIndex;
while Index < FSize do
begin
NewMap.FEntries[Index - FromIndex] := FEntries[Index];
Inc(Index);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclUnicodeStrUnicodeStrSortedMap.Values: IJclUnicodeStrCollection;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclUnicodeStrArrayList.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Value);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclUnicodeStrUnicodeStrSortedMap.CreateEmptyContainer: TJclAbstractContainerBase;
begin
Result := TJclUnicodeStrUnicodeStrSortedMap.Create(FSize);
AssignPropertiesTo(Result);
end;
function TJclUnicodeStrUnicodeStrSortedMap.FreeKey(var Key: UnicodeString): UnicodeString;
begin
Result := Key;
Key := '';
end;
function TJclUnicodeStrUnicodeStrSortedMap.FreeValue(var Value: UnicodeString): UnicodeString;
begin
Result := Value;
Value := '';
end;
function TJclUnicodeStrUnicodeStrSortedMap.KeysCompare(const A, B: UnicodeString): Integer;
begin
Result := ItemsCompare(A, B);
end;
function TJclUnicodeStrUnicodeStrSortedMap.ValuesCompare(const A, B: UnicodeString): Integer;
begin
Result := ItemsCompare(A, B);
end;
{$ENDIF SUPPORTS_UNICODE_STRING}
//=== { TJclSingleIntfSortedMap } ==============================================
constructor TJclSingleIntfSortedMap.Create(ACapacity: Integer);
begin
inherited Create();
SetCapacity(ACapacity);
end;
destructor TJclSingleIntfSortedMap.Destroy;
begin
FReadOnly := False;
Clear;
inherited Destroy;
end;
procedure TJclSingleIntfSortedMap.AssignDataTo(Dest: TJclAbstractContainerBase);
var
MyDest: TJclSingleIntfSortedMap;
begin
inherited AssignDataTo(Dest);
if Dest is TJclSingleIntfSortedMap then
begin
MyDest := TJclSingleIntfSortedMap(Dest);
MyDest.SetCapacity(FSize);
MyDest.FEntries := FEntries;
MyDest.FSize := FSize;
end;
end;
function TJclSingleIntfSortedMap.BinarySearch(const Key: Single): Integer;
var
HiPos, LoPos, CompPos: Integer;
Comp: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
LoPos := 0;
HiPos := FSize - 1;
CompPos := (HiPos + LoPos) div 2;
while HiPos >= LoPos do
begin
Comp := KeysCompare(FEntries[CompPos].Key, Key);
if Comp < 0 then
LoPos := CompPos + 1
else
if Comp > 0 then
HiPos := CompPos - 1
else
begin
HiPos := CompPos;
LoPos := CompPos + 1;
end;
CompPos := (HiPos + LoPos) div 2;
end;
Result := HiPos;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclSingleIntfSortedMap.Clear;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
for Index := 0 to FSize - 1 do
begin
FreeKey(FEntries[Index].Key);
FreeValue(FEntries[Index].Value);
end;
FSize := 0;
AutoPack;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclSingleIntfSortedMap.ContainsKey(const Key: Single): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSingleIntfSortedMap.ContainsValue(const Value: IInterface): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := True;
Break;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSingleIntfSortedMap.FirstKey: Single;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := 0.0;
if FSize > 0 then
Result := FEntries[0].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSingleIntfSortedMap.Extract(const Key: Single): IInterface;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
Result := FEntries[Index].Value;
FEntries[Index].Value := nil;
FreeKey(FEntries[Index].Key);
if Index < (FSize - 1) then
MoveArray(Index + 1, Index, FSize - Index - 1);
Dec(FSize);
AutoPack;
end
else
Result := nil;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclSingleIntfSortedMap.GetValue(const Key: Single): IInterface;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := nil;
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
Result := FEntries[Index].Value
else if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSingleIntfSortedMap.HeadMap(const ToKey: Single): IJclSingleIntfSortedMap;
var
ToIndex: Integer;
NewMap: TJclSingleIntfSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclSingleIntfSortedMap;
ToIndex := BinarySearch(ToKey);
if ToIndex >= 0 then
begin
NewMap.SetCapacity(ToIndex + 1);
NewMap.FSize := ToIndex + 1;
while ToIndex >= 0 do
begin
NewMap.FEntries[ToIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSingleIntfSortedMap.IsEmpty: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := FSize = 0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSingleIntfSortedMap.KeyOfValue(const Value: IInterface): Single;
var
Index: Integer;
Found: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Found := False;
Result := 0.0;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := FEntries[Index].Key;
Found := True;
Break;
end;
if (not Found) and (not FReturnDefaultElements) then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSingleIntfSortedMap.KeySet: IJclSingleSet;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclSingleArraySet.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Key);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSingleIntfSortedMap.LastKey: Single;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := 0.0;
if FSize > 0 then
Result := FEntries[FSize - 1].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSingleIntfSortedMap.MapEquals(const AMap: IJclSingleIntfMap): Boolean;
var
It: IJclSingleIterator;
Index: Integer;
AKey: Single;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
if AMap = nil then
Exit;
if FSize <> AMap.Size then
Exit;
It := AMap.KeySet.First;
Index := 0;
while It.HasNext do
begin
if Index >= FSize then
Exit;
AKey := It.Next;
if ValuesCompare(AMap.GetValue(AKey), FEntries[Index].Value) <> 0 then
Exit;
Inc(Index);
end;
Result := True;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclSingleIntfSortedMap.MoveArray(FromIndex, ToIndex, Count: Integer);
begin
if Count > 0 then
begin
Move(FEntries[FromIndex], FEntries[ToIndex], Count * SizeOf(FEntries[0]));
{ Keep reference counting working }
if FromIndex < ToIndex then
begin
if (ToIndex - FromIndex) < Count then
FillChar(FEntries[FromIndex], (ToIndex - FromIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end
else
if FromIndex > ToIndex then
begin
if (FromIndex - ToIndex) < Count then
FillChar(FEntries[ToIndex + Count], (FromIndex - ToIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end;
end;
end;
procedure TJclSingleIntfSortedMap.PutAll(const AMap: IJclSingleIntfMap);
var
It: IJclSingleIterator;
Key: Single;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if AMap = nil then
Exit;
It := AMap.KeySet.First;
while It.HasNext do
begin
Key := It.Next;
PutValue(Key, AMap.GetValue(Key));
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclSingleIntfSortedMap.PutValue(const Key: Single; const Value: IInterface);
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FAllowDefaultElements or ((KeysCompare(Key, 0.0) <> 0) and (ValuesCompare(Value, nil) <> 0)) then
begin
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
FreeValue(FEntries[Index].Value);
FEntries[Index].Value := Value;
end
else
begin
if FSize = FCapacity then
AutoGrow;
if FSize < FCapacity then
begin
Inc(Index);
if (Index < FSize) and (KeysCompare(FEntries[Index].Key, Key) <> 0) then
MoveArray(Index, Index + 1, FSize - Index);
FEntries[Index].Key := Key;
FEntries[Index].Value := Value;
Inc(FSize);
end;
end;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclSingleIntfSortedMap.Remove(const Key: Single): IInterface;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Result := Extract(Key);
Result := FreeValue(Result);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclSingleIntfSortedMap.SetCapacity(Value: Integer);
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FSize <= Value then
begin
SetLength(FEntries, Value);
inherited SetCapacity(Value);
end
else
raise EJclOperationNotSupportedError.Create;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclSingleIntfSortedMap.Size: Integer;
begin
Result := FSize;
end;
function TJclSingleIntfSortedMap.SubMap(const FromKey, ToKey: Single): IJclSingleIntfSortedMap;
var
FromIndex, ToIndex: Integer;
NewMap: TJclSingleIntfSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclSingleIntfSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
ToIndex := BinarySearch(ToKey);
if (FromIndex >= 0) and (FromIndex <= ToIndex) then
begin
NewMap.SetCapacity(ToIndex - FromIndex + 1);
NewMap.FSize := ToIndex - FromIndex + 1;
while ToIndex >= FromIndex do
begin
NewMap.FEntries[ToIndex - FromIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSingleIntfSortedMap.TailMap(const FromKey: Single): IJclSingleIntfSortedMap;
var
FromIndex, Index: Integer;
NewMap: TJclSingleIntfSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclSingleIntfSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
if (FromIndex >= 0) and (FromIndex < FSize) then
begin
NewMap.SetCapacity(FSize - FromIndex);
NewMap.FSize := FSize - FromIndex;
Index := FromIndex;
while Index < FSize do
begin
NewMap.FEntries[Index - FromIndex] := FEntries[Index];
Inc(Index);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSingleIntfSortedMap.Values: IJclIntfCollection;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclIntfArrayList.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Value);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSingleIntfSortedMap.CreateEmptyContainer: TJclAbstractContainerBase;
begin
Result := TJclSingleIntfSortedMap.Create(FSize);
AssignPropertiesTo(Result);
end;
function TJclSingleIntfSortedMap.FreeKey(var Key: Single): Single;
begin
Result := Key;
Key := 0.0;
end;
function TJclSingleIntfSortedMap.FreeValue(var Value: IInterface): IInterface;
begin
Result := Value;
Value := nil;
end;
function TJclSingleIntfSortedMap.KeysCompare(const A, B: Single): Integer;
begin
Result := ItemsCompare(A, B);
end;
function TJclSingleIntfSortedMap.ValuesCompare(const A, B: IInterface): Integer;
begin
Result := IntfSimpleCompare(A, B);
end;
//=== { TJclIntfSingleSortedMap } ==============================================
constructor TJclIntfSingleSortedMap.Create(ACapacity: Integer);
begin
inherited Create();
SetCapacity(ACapacity);
end;
destructor TJclIntfSingleSortedMap.Destroy;
begin
FReadOnly := False;
Clear;
inherited Destroy;
end;
procedure TJclIntfSingleSortedMap.AssignDataTo(Dest: TJclAbstractContainerBase);
var
MyDest: TJclIntfSingleSortedMap;
begin
inherited AssignDataTo(Dest);
if Dest is TJclIntfSingleSortedMap then
begin
MyDest := TJclIntfSingleSortedMap(Dest);
MyDest.SetCapacity(FSize);
MyDest.FEntries := FEntries;
MyDest.FSize := FSize;
end;
end;
function TJclIntfSingleSortedMap.BinarySearch(const Key: IInterface): Integer;
var
HiPos, LoPos, CompPos: Integer;
Comp: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
LoPos := 0;
HiPos := FSize - 1;
CompPos := (HiPos + LoPos) div 2;
while HiPos >= LoPos do
begin
Comp := KeysCompare(FEntries[CompPos].Key, Key);
if Comp < 0 then
LoPos := CompPos + 1
else
if Comp > 0 then
HiPos := CompPos - 1
else
begin
HiPos := CompPos;
LoPos := CompPos + 1;
end;
CompPos := (HiPos + LoPos) div 2;
end;
Result := HiPos;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntfSingleSortedMap.Clear;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
for Index := 0 to FSize - 1 do
begin
FreeKey(FEntries[Index].Key);
FreeValue(FEntries[Index].Value);
end;
FSize := 0;
AutoPack;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfSingleSortedMap.ContainsKey(const Key: IInterface): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfSingleSortedMap.ContainsValue(const Value: Single): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := True;
Break;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfSingleSortedMap.FirstKey: IInterface;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := nil;
if FSize > 0 then
Result := FEntries[0].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfSingleSortedMap.Extract(const Key: IInterface): Single;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
Result := FEntries[Index].Value;
FEntries[Index].Value := 0.0;
FreeKey(FEntries[Index].Key);
if Index < (FSize - 1) then
MoveArray(Index + 1, Index, FSize - Index - 1);
Dec(FSize);
AutoPack;
end
else
Result := 0.0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfSingleSortedMap.GetValue(const Key: IInterface): Single;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := 0.0;
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
Result := FEntries[Index].Value
else if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfSingleSortedMap.HeadMap(const ToKey: IInterface): IJclIntfSingleSortedMap;
var
ToIndex: Integer;
NewMap: TJclIntfSingleSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclIntfSingleSortedMap;
ToIndex := BinarySearch(ToKey);
if ToIndex >= 0 then
begin
NewMap.SetCapacity(ToIndex + 1);
NewMap.FSize := ToIndex + 1;
while ToIndex >= 0 do
begin
NewMap.FEntries[ToIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfSingleSortedMap.IsEmpty: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := FSize = 0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfSingleSortedMap.KeyOfValue(const Value: Single): IInterface;
var
Index: Integer;
Found: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Found := False;
Result := nil;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := FEntries[Index].Key;
Found := True;
Break;
end;
if (not Found) and (not FReturnDefaultElements) then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfSingleSortedMap.KeySet: IJclIntfSet;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclIntfArraySet.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Key);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfSingleSortedMap.LastKey: IInterface;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := nil;
if FSize > 0 then
Result := FEntries[FSize - 1].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfSingleSortedMap.MapEquals(const AMap: IJclIntfSingleMap): Boolean;
var
It: IJclIntfIterator;
Index: Integer;
AKey: IInterface;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
if AMap = nil then
Exit;
if FSize <> AMap.Size then
Exit;
It := AMap.KeySet.First;
Index := 0;
while It.HasNext do
begin
if Index >= FSize then
Exit;
AKey := It.Next;
if ValuesCompare(AMap.GetValue(AKey), FEntries[Index].Value) <> 0 then
Exit;
Inc(Index);
end;
Result := True;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntfSingleSortedMap.MoveArray(FromIndex, ToIndex, Count: Integer);
begin
if Count > 0 then
begin
Move(FEntries[FromIndex], FEntries[ToIndex], Count * SizeOf(FEntries[0]));
{ Keep reference counting working }
if FromIndex < ToIndex then
begin
if (ToIndex - FromIndex) < Count then
FillChar(FEntries[FromIndex], (ToIndex - FromIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end
else
if FromIndex > ToIndex then
begin
if (FromIndex - ToIndex) < Count then
FillChar(FEntries[ToIndex + Count], (FromIndex - ToIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end;
end;
end;
procedure TJclIntfSingleSortedMap.PutAll(const AMap: IJclIntfSingleMap);
var
It: IJclIntfIterator;
Key: IInterface;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if AMap = nil then
Exit;
It := AMap.KeySet.First;
while It.HasNext do
begin
Key := It.Next;
PutValue(Key, AMap.GetValue(Key));
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntfSingleSortedMap.PutValue(const Key: IInterface; const Value: Single);
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FAllowDefaultElements or ((KeysCompare(Key, nil) <> 0) and (ValuesCompare(Value, 0.0) <> 0)) then
begin
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
FreeValue(FEntries[Index].Value);
FEntries[Index].Value := Value;
end
else
begin
if FSize = FCapacity then
AutoGrow;
if FSize < FCapacity then
begin
Inc(Index);
if (Index < FSize) and (KeysCompare(FEntries[Index].Key, Key) <> 0) then
MoveArray(Index, Index + 1, FSize - Index);
FEntries[Index].Key := Key;
FEntries[Index].Value := Value;
Inc(FSize);
end;
end;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfSingleSortedMap.Remove(const Key: IInterface): Single;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Result := Extract(Key);
Result := FreeValue(Result);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntfSingleSortedMap.SetCapacity(Value: Integer);
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FSize <= Value then
begin
SetLength(FEntries, Value);
inherited SetCapacity(Value);
end
else
raise EJclOperationNotSupportedError.Create;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfSingleSortedMap.Size: Integer;
begin
Result := FSize;
end;
function TJclIntfSingleSortedMap.SubMap(const FromKey, ToKey: IInterface): IJclIntfSingleSortedMap;
var
FromIndex, ToIndex: Integer;
NewMap: TJclIntfSingleSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclIntfSingleSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
ToIndex := BinarySearch(ToKey);
if (FromIndex >= 0) and (FromIndex <= ToIndex) then
begin
NewMap.SetCapacity(ToIndex - FromIndex + 1);
NewMap.FSize := ToIndex - FromIndex + 1;
while ToIndex >= FromIndex do
begin
NewMap.FEntries[ToIndex - FromIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfSingleSortedMap.TailMap(const FromKey: IInterface): IJclIntfSingleSortedMap;
var
FromIndex, Index: Integer;
NewMap: TJclIntfSingleSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclIntfSingleSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
if (FromIndex >= 0) and (FromIndex < FSize) then
begin
NewMap.SetCapacity(FSize - FromIndex);
NewMap.FSize := FSize - FromIndex;
Index := FromIndex;
while Index < FSize do
begin
NewMap.FEntries[Index - FromIndex] := FEntries[Index];
Inc(Index);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfSingleSortedMap.Values: IJclSingleCollection;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclSingleArrayList.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Value);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfSingleSortedMap.CreateEmptyContainer: TJclAbstractContainerBase;
begin
Result := TJclIntfSingleSortedMap.Create(FSize);
AssignPropertiesTo(Result);
end;
function TJclIntfSingleSortedMap.FreeKey(var Key: IInterface): IInterface;
begin
Result := Key;
Key := nil;
end;
function TJclIntfSingleSortedMap.FreeValue(var Value: Single): Single;
begin
Result := Value;
Value := 0.0;
end;
function TJclIntfSingleSortedMap.KeysCompare(const A, B: IInterface): Integer;
begin
Result := IntfSimpleCompare(A, B);
end;
function TJclIntfSingleSortedMap.ValuesCompare(const A, B: Single): Integer;
begin
Result := ItemsCompare(A, B);
end;
//=== { TJclSingleSingleSortedMap } ==============================================
constructor TJclSingleSingleSortedMap.Create(ACapacity: Integer);
begin
inherited Create();
SetCapacity(ACapacity);
end;
destructor TJclSingleSingleSortedMap.Destroy;
begin
FReadOnly := False;
Clear;
inherited Destroy;
end;
procedure TJclSingleSingleSortedMap.AssignDataTo(Dest: TJclAbstractContainerBase);
var
MyDest: TJclSingleSingleSortedMap;
begin
inherited AssignDataTo(Dest);
if Dest is TJclSingleSingleSortedMap then
begin
MyDest := TJclSingleSingleSortedMap(Dest);
MyDest.SetCapacity(FSize);
MyDest.FEntries := FEntries;
MyDest.FSize := FSize;
end;
end;
function TJclSingleSingleSortedMap.BinarySearch(const Key: Single): Integer;
var
HiPos, LoPos, CompPos: Integer;
Comp: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
LoPos := 0;
HiPos := FSize - 1;
CompPos := (HiPos + LoPos) div 2;
while HiPos >= LoPos do
begin
Comp := KeysCompare(FEntries[CompPos].Key, Key);
if Comp < 0 then
LoPos := CompPos + 1
else
if Comp > 0 then
HiPos := CompPos - 1
else
begin
HiPos := CompPos;
LoPos := CompPos + 1;
end;
CompPos := (HiPos + LoPos) div 2;
end;
Result := HiPos;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclSingleSingleSortedMap.Clear;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
for Index := 0 to FSize - 1 do
begin
FreeKey(FEntries[Index].Key);
FreeValue(FEntries[Index].Value);
end;
FSize := 0;
AutoPack;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclSingleSingleSortedMap.ContainsKey(const Key: Single): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSingleSingleSortedMap.ContainsValue(const Value: Single): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := True;
Break;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSingleSingleSortedMap.FirstKey: Single;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := 0.0;
if FSize > 0 then
Result := FEntries[0].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSingleSingleSortedMap.Extract(const Key: Single): Single;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
Result := FEntries[Index].Value;
FEntries[Index].Value := 0.0;
FreeKey(FEntries[Index].Key);
if Index < (FSize - 1) then
MoveArray(Index + 1, Index, FSize - Index - 1);
Dec(FSize);
AutoPack;
end
else
Result := 0.0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclSingleSingleSortedMap.GetValue(const Key: Single): Single;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := 0.0;
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
Result := FEntries[Index].Value
else if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSingleSingleSortedMap.HeadMap(const ToKey: Single): IJclSingleSingleSortedMap;
var
ToIndex: Integer;
NewMap: TJclSingleSingleSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclSingleSingleSortedMap;
ToIndex := BinarySearch(ToKey);
if ToIndex >= 0 then
begin
NewMap.SetCapacity(ToIndex + 1);
NewMap.FSize := ToIndex + 1;
while ToIndex >= 0 do
begin
NewMap.FEntries[ToIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSingleSingleSortedMap.IsEmpty: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := FSize = 0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSingleSingleSortedMap.KeyOfValue(const Value: Single): Single;
var
Index: Integer;
Found: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Found := False;
Result := 0.0;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := FEntries[Index].Key;
Found := True;
Break;
end;
if (not Found) and (not FReturnDefaultElements) then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSingleSingleSortedMap.KeySet: IJclSingleSet;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclSingleArraySet.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Key);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSingleSingleSortedMap.LastKey: Single;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := 0.0;
if FSize > 0 then
Result := FEntries[FSize - 1].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSingleSingleSortedMap.MapEquals(const AMap: IJclSingleSingleMap): Boolean;
var
It: IJclSingleIterator;
Index: Integer;
AKey: Single;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
if AMap = nil then
Exit;
if FSize <> AMap.Size then
Exit;
It := AMap.KeySet.First;
Index := 0;
while It.HasNext do
begin
if Index >= FSize then
Exit;
AKey := It.Next;
if ValuesCompare(AMap.GetValue(AKey), FEntries[Index].Value) <> 0 then
Exit;
Inc(Index);
end;
Result := True;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclSingleSingleSortedMap.MoveArray(FromIndex, ToIndex, Count: Integer);
begin
if Count > 0 then
begin
Move(FEntries[FromIndex], FEntries[ToIndex], Count * SizeOf(FEntries[0]));
{ Keep reference counting working }
if FromIndex < ToIndex then
begin
if (ToIndex - FromIndex) < Count then
FillChar(FEntries[FromIndex], (ToIndex - FromIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end
else
if FromIndex > ToIndex then
begin
if (FromIndex - ToIndex) < Count then
FillChar(FEntries[ToIndex + Count], (FromIndex - ToIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end;
end;
end;
procedure TJclSingleSingleSortedMap.PutAll(const AMap: IJclSingleSingleMap);
var
It: IJclSingleIterator;
Key: Single;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if AMap = nil then
Exit;
It := AMap.KeySet.First;
while It.HasNext do
begin
Key := It.Next;
PutValue(Key, AMap.GetValue(Key));
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclSingleSingleSortedMap.PutValue(const Key: Single; const Value: Single);
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FAllowDefaultElements or ((KeysCompare(Key, 0.0) <> 0) and (ValuesCompare(Value, 0.0) <> 0)) then
begin
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
FreeValue(FEntries[Index].Value);
FEntries[Index].Value := Value;
end
else
begin
if FSize = FCapacity then
AutoGrow;
if FSize < FCapacity then
begin
Inc(Index);
if (Index < FSize) and (KeysCompare(FEntries[Index].Key, Key) <> 0) then
MoveArray(Index, Index + 1, FSize - Index);
FEntries[Index].Key := Key;
FEntries[Index].Value := Value;
Inc(FSize);
end;
end;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclSingleSingleSortedMap.Remove(const Key: Single): Single;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Result := Extract(Key);
Result := FreeValue(Result);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclSingleSingleSortedMap.SetCapacity(Value: Integer);
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FSize <= Value then
begin
SetLength(FEntries, Value);
inherited SetCapacity(Value);
end
else
raise EJclOperationNotSupportedError.Create;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclSingleSingleSortedMap.Size: Integer;
begin
Result := FSize;
end;
function TJclSingleSingleSortedMap.SubMap(const FromKey, ToKey: Single): IJclSingleSingleSortedMap;
var
FromIndex, ToIndex: Integer;
NewMap: TJclSingleSingleSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclSingleSingleSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
ToIndex := BinarySearch(ToKey);
if (FromIndex >= 0) and (FromIndex <= ToIndex) then
begin
NewMap.SetCapacity(ToIndex - FromIndex + 1);
NewMap.FSize := ToIndex - FromIndex + 1;
while ToIndex >= FromIndex do
begin
NewMap.FEntries[ToIndex - FromIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSingleSingleSortedMap.TailMap(const FromKey: Single): IJclSingleSingleSortedMap;
var
FromIndex, Index: Integer;
NewMap: TJclSingleSingleSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclSingleSingleSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
if (FromIndex >= 0) and (FromIndex < FSize) then
begin
NewMap.SetCapacity(FSize - FromIndex);
NewMap.FSize := FSize - FromIndex;
Index := FromIndex;
while Index < FSize do
begin
NewMap.FEntries[Index - FromIndex] := FEntries[Index];
Inc(Index);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSingleSingleSortedMap.Values: IJclSingleCollection;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclSingleArrayList.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Value);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSingleSingleSortedMap.CreateEmptyContainer: TJclAbstractContainerBase;
begin
Result := TJclSingleSingleSortedMap.Create(FSize);
AssignPropertiesTo(Result);
end;
function TJclSingleSingleSortedMap.FreeKey(var Key: Single): Single;
begin
Result := Key;
Key := 0.0;
end;
function TJclSingleSingleSortedMap.FreeValue(var Value: Single): Single;
begin
Result := Value;
Value := 0.0;
end;
function TJclSingleSingleSortedMap.KeysCompare(const A, B: Single): Integer;
begin
Result := ItemsCompare(A, B);
end;
function TJclSingleSingleSortedMap.ValuesCompare(const A, B: Single): Integer;
begin
Result := ItemsCompare(A, B);
end;
//=== { TJclDoubleIntfSortedMap } ==============================================
constructor TJclDoubleIntfSortedMap.Create(ACapacity: Integer);
begin
inherited Create();
SetCapacity(ACapacity);
end;
destructor TJclDoubleIntfSortedMap.Destroy;
begin
FReadOnly := False;
Clear;
inherited Destroy;
end;
procedure TJclDoubleIntfSortedMap.AssignDataTo(Dest: TJclAbstractContainerBase);
var
MyDest: TJclDoubleIntfSortedMap;
begin
inherited AssignDataTo(Dest);
if Dest is TJclDoubleIntfSortedMap then
begin
MyDest := TJclDoubleIntfSortedMap(Dest);
MyDest.SetCapacity(FSize);
MyDest.FEntries := FEntries;
MyDest.FSize := FSize;
end;
end;
function TJclDoubleIntfSortedMap.BinarySearch(const Key: Double): Integer;
var
HiPos, LoPos, CompPos: Integer;
Comp: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
LoPos := 0;
HiPos := FSize - 1;
CompPos := (HiPos + LoPos) div 2;
while HiPos >= LoPos do
begin
Comp := KeysCompare(FEntries[CompPos].Key, Key);
if Comp < 0 then
LoPos := CompPos + 1
else
if Comp > 0 then
HiPos := CompPos - 1
else
begin
HiPos := CompPos;
LoPos := CompPos + 1;
end;
CompPos := (HiPos + LoPos) div 2;
end;
Result := HiPos;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclDoubleIntfSortedMap.Clear;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
for Index := 0 to FSize - 1 do
begin
FreeKey(FEntries[Index].Key);
FreeValue(FEntries[Index].Value);
end;
FSize := 0;
AutoPack;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclDoubleIntfSortedMap.ContainsKey(const Key: Double): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclDoubleIntfSortedMap.ContainsValue(const Value: IInterface): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := True;
Break;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclDoubleIntfSortedMap.FirstKey: Double;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := 0.0;
if FSize > 0 then
Result := FEntries[0].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclDoubleIntfSortedMap.Extract(const Key: Double): IInterface;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
Result := FEntries[Index].Value;
FEntries[Index].Value := nil;
FreeKey(FEntries[Index].Key);
if Index < (FSize - 1) then
MoveArray(Index + 1, Index, FSize - Index - 1);
Dec(FSize);
AutoPack;
end
else
Result := nil;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclDoubleIntfSortedMap.GetValue(const Key: Double): IInterface;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := nil;
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
Result := FEntries[Index].Value
else if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclDoubleIntfSortedMap.HeadMap(const ToKey: Double): IJclDoubleIntfSortedMap;
var
ToIndex: Integer;
NewMap: TJclDoubleIntfSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclDoubleIntfSortedMap;
ToIndex := BinarySearch(ToKey);
if ToIndex >= 0 then
begin
NewMap.SetCapacity(ToIndex + 1);
NewMap.FSize := ToIndex + 1;
while ToIndex >= 0 do
begin
NewMap.FEntries[ToIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclDoubleIntfSortedMap.IsEmpty: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := FSize = 0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclDoubleIntfSortedMap.KeyOfValue(const Value: IInterface): Double;
var
Index: Integer;
Found: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Found := False;
Result := 0.0;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := FEntries[Index].Key;
Found := True;
Break;
end;
if (not Found) and (not FReturnDefaultElements) then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclDoubleIntfSortedMap.KeySet: IJclDoubleSet;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclDoubleArraySet.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Key);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclDoubleIntfSortedMap.LastKey: Double;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := 0.0;
if FSize > 0 then
Result := FEntries[FSize - 1].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclDoubleIntfSortedMap.MapEquals(const AMap: IJclDoubleIntfMap): Boolean;
var
It: IJclDoubleIterator;
Index: Integer;
AKey: Double;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
if AMap = nil then
Exit;
if FSize <> AMap.Size then
Exit;
It := AMap.KeySet.First;
Index := 0;
while It.HasNext do
begin
if Index >= FSize then
Exit;
AKey := It.Next;
if ValuesCompare(AMap.GetValue(AKey), FEntries[Index].Value) <> 0 then
Exit;
Inc(Index);
end;
Result := True;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclDoubleIntfSortedMap.MoveArray(FromIndex, ToIndex, Count: Integer);
begin
if Count > 0 then
begin
Move(FEntries[FromIndex], FEntries[ToIndex], Count * SizeOf(FEntries[0]));
{ Keep reference counting working }
if FromIndex < ToIndex then
begin
if (ToIndex - FromIndex) < Count then
FillChar(FEntries[FromIndex], (ToIndex - FromIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end
else
if FromIndex > ToIndex then
begin
if (FromIndex - ToIndex) < Count then
FillChar(FEntries[ToIndex + Count], (FromIndex - ToIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end;
end;
end;
procedure TJclDoubleIntfSortedMap.PutAll(const AMap: IJclDoubleIntfMap);
var
It: IJclDoubleIterator;
Key: Double;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if AMap = nil then
Exit;
It := AMap.KeySet.First;
while It.HasNext do
begin
Key := It.Next;
PutValue(Key, AMap.GetValue(Key));
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclDoubleIntfSortedMap.PutValue(const Key: Double; const Value: IInterface);
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FAllowDefaultElements or ((KeysCompare(Key, 0.0) <> 0) and (ValuesCompare(Value, nil) <> 0)) then
begin
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
FreeValue(FEntries[Index].Value);
FEntries[Index].Value := Value;
end
else
begin
if FSize = FCapacity then
AutoGrow;
if FSize < FCapacity then
begin
Inc(Index);
if (Index < FSize) and (KeysCompare(FEntries[Index].Key, Key) <> 0) then
MoveArray(Index, Index + 1, FSize - Index);
FEntries[Index].Key := Key;
FEntries[Index].Value := Value;
Inc(FSize);
end;
end;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclDoubleIntfSortedMap.Remove(const Key: Double): IInterface;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Result := Extract(Key);
Result := FreeValue(Result);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclDoubleIntfSortedMap.SetCapacity(Value: Integer);
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FSize <= Value then
begin
SetLength(FEntries, Value);
inherited SetCapacity(Value);
end
else
raise EJclOperationNotSupportedError.Create;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclDoubleIntfSortedMap.Size: Integer;
begin
Result := FSize;
end;
function TJclDoubleIntfSortedMap.SubMap(const FromKey, ToKey: Double): IJclDoubleIntfSortedMap;
var
FromIndex, ToIndex: Integer;
NewMap: TJclDoubleIntfSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclDoubleIntfSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
ToIndex := BinarySearch(ToKey);
if (FromIndex >= 0) and (FromIndex <= ToIndex) then
begin
NewMap.SetCapacity(ToIndex - FromIndex + 1);
NewMap.FSize := ToIndex - FromIndex + 1;
while ToIndex >= FromIndex do
begin
NewMap.FEntries[ToIndex - FromIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclDoubleIntfSortedMap.TailMap(const FromKey: Double): IJclDoubleIntfSortedMap;
var
FromIndex, Index: Integer;
NewMap: TJclDoubleIntfSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclDoubleIntfSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
if (FromIndex >= 0) and (FromIndex < FSize) then
begin
NewMap.SetCapacity(FSize - FromIndex);
NewMap.FSize := FSize - FromIndex;
Index := FromIndex;
while Index < FSize do
begin
NewMap.FEntries[Index - FromIndex] := FEntries[Index];
Inc(Index);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclDoubleIntfSortedMap.Values: IJclIntfCollection;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclIntfArrayList.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Value);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclDoubleIntfSortedMap.CreateEmptyContainer: TJclAbstractContainerBase;
begin
Result := TJclDoubleIntfSortedMap.Create(FSize);
AssignPropertiesTo(Result);
end;
function TJclDoubleIntfSortedMap.FreeKey(var Key: Double): Double;
begin
Result := Key;
Key := 0.0;
end;
function TJclDoubleIntfSortedMap.FreeValue(var Value: IInterface): IInterface;
begin
Result := Value;
Value := nil;
end;
function TJclDoubleIntfSortedMap.KeysCompare(const A, B: Double): Integer;
begin
Result := ItemsCompare(A, B);
end;
function TJclDoubleIntfSortedMap.ValuesCompare(const A, B: IInterface): Integer;
begin
Result := IntfSimpleCompare(A, B);
end;
//=== { TJclIntfDoubleSortedMap } ==============================================
constructor TJclIntfDoubleSortedMap.Create(ACapacity: Integer);
begin
inherited Create();
SetCapacity(ACapacity);
end;
destructor TJclIntfDoubleSortedMap.Destroy;
begin
FReadOnly := False;
Clear;
inherited Destroy;
end;
procedure TJclIntfDoubleSortedMap.AssignDataTo(Dest: TJclAbstractContainerBase);
var
MyDest: TJclIntfDoubleSortedMap;
begin
inherited AssignDataTo(Dest);
if Dest is TJclIntfDoubleSortedMap then
begin
MyDest := TJclIntfDoubleSortedMap(Dest);
MyDest.SetCapacity(FSize);
MyDest.FEntries := FEntries;
MyDest.FSize := FSize;
end;
end;
function TJclIntfDoubleSortedMap.BinarySearch(const Key: IInterface): Integer;
var
HiPos, LoPos, CompPos: Integer;
Comp: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
LoPos := 0;
HiPos := FSize - 1;
CompPos := (HiPos + LoPos) div 2;
while HiPos >= LoPos do
begin
Comp := KeysCompare(FEntries[CompPos].Key, Key);
if Comp < 0 then
LoPos := CompPos + 1
else
if Comp > 0 then
HiPos := CompPos - 1
else
begin
HiPos := CompPos;
LoPos := CompPos + 1;
end;
CompPos := (HiPos + LoPos) div 2;
end;
Result := HiPos;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntfDoubleSortedMap.Clear;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
for Index := 0 to FSize - 1 do
begin
FreeKey(FEntries[Index].Key);
FreeValue(FEntries[Index].Value);
end;
FSize := 0;
AutoPack;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfDoubleSortedMap.ContainsKey(const Key: IInterface): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfDoubleSortedMap.ContainsValue(const Value: Double): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := True;
Break;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfDoubleSortedMap.FirstKey: IInterface;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := nil;
if FSize > 0 then
Result := FEntries[0].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfDoubleSortedMap.Extract(const Key: IInterface): Double;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
Result := FEntries[Index].Value;
FEntries[Index].Value := 0.0;
FreeKey(FEntries[Index].Key);
if Index < (FSize - 1) then
MoveArray(Index + 1, Index, FSize - Index - 1);
Dec(FSize);
AutoPack;
end
else
Result := 0.0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfDoubleSortedMap.GetValue(const Key: IInterface): Double;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := 0.0;
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
Result := FEntries[Index].Value
else if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfDoubleSortedMap.HeadMap(const ToKey: IInterface): IJclIntfDoubleSortedMap;
var
ToIndex: Integer;
NewMap: TJclIntfDoubleSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclIntfDoubleSortedMap;
ToIndex := BinarySearch(ToKey);
if ToIndex >= 0 then
begin
NewMap.SetCapacity(ToIndex + 1);
NewMap.FSize := ToIndex + 1;
while ToIndex >= 0 do
begin
NewMap.FEntries[ToIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfDoubleSortedMap.IsEmpty: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := FSize = 0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfDoubleSortedMap.KeyOfValue(const Value: Double): IInterface;
var
Index: Integer;
Found: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Found := False;
Result := nil;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := FEntries[Index].Key;
Found := True;
Break;
end;
if (not Found) and (not FReturnDefaultElements) then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfDoubleSortedMap.KeySet: IJclIntfSet;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclIntfArraySet.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Key);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfDoubleSortedMap.LastKey: IInterface;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := nil;
if FSize > 0 then
Result := FEntries[FSize - 1].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfDoubleSortedMap.MapEquals(const AMap: IJclIntfDoubleMap): Boolean;
var
It: IJclIntfIterator;
Index: Integer;
AKey: IInterface;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
if AMap = nil then
Exit;
if FSize <> AMap.Size then
Exit;
It := AMap.KeySet.First;
Index := 0;
while It.HasNext do
begin
if Index >= FSize then
Exit;
AKey := It.Next;
if ValuesCompare(AMap.GetValue(AKey), FEntries[Index].Value) <> 0 then
Exit;
Inc(Index);
end;
Result := True;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntfDoubleSortedMap.MoveArray(FromIndex, ToIndex, Count: Integer);
begin
if Count > 0 then
begin
Move(FEntries[FromIndex], FEntries[ToIndex], Count * SizeOf(FEntries[0]));
{ Keep reference counting working }
if FromIndex < ToIndex then
begin
if (ToIndex - FromIndex) < Count then
FillChar(FEntries[FromIndex], (ToIndex - FromIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end
else
if FromIndex > ToIndex then
begin
if (FromIndex - ToIndex) < Count then
FillChar(FEntries[ToIndex + Count], (FromIndex - ToIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end;
end;
end;
procedure TJclIntfDoubleSortedMap.PutAll(const AMap: IJclIntfDoubleMap);
var
It: IJclIntfIterator;
Key: IInterface;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if AMap = nil then
Exit;
It := AMap.KeySet.First;
while It.HasNext do
begin
Key := It.Next;
PutValue(Key, AMap.GetValue(Key));
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntfDoubleSortedMap.PutValue(const Key: IInterface; const Value: Double);
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FAllowDefaultElements or ((KeysCompare(Key, nil) <> 0) and (ValuesCompare(Value, 0.0) <> 0)) then
begin
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
FreeValue(FEntries[Index].Value);
FEntries[Index].Value := Value;
end
else
begin
if FSize = FCapacity then
AutoGrow;
if FSize < FCapacity then
begin
Inc(Index);
if (Index < FSize) and (KeysCompare(FEntries[Index].Key, Key) <> 0) then
MoveArray(Index, Index + 1, FSize - Index);
FEntries[Index].Key := Key;
FEntries[Index].Value := Value;
Inc(FSize);
end;
end;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfDoubleSortedMap.Remove(const Key: IInterface): Double;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Result := Extract(Key);
Result := FreeValue(Result);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntfDoubleSortedMap.SetCapacity(Value: Integer);
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FSize <= Value then
begin
SetLength(FEntries, Value);
inherited SetCapacity(Value);
end
else
raise EJclOperationNotSupportedError.Create;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfDoubleSortedMap.Size: Integer;
begin
Result := FSize;
end;
function TJclIntfDoubleSortedMap.SubMap(const FromKey, ToKey: IInterface): IJclIntfDoubleSortedMap;
var
FromIndex, ToIndex: Integer;
NewMap: TJclIntfDoubleSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclIntfDoubleSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
ToIndex := BinarySearch(ToKey);
if (FromIndex >= 0) and (FromIndex <= ToIndex) then
begin
NewMap.SetCapacity(ToIndex - FromIndex + 1);
NewMap.FSize := ToIndex - FromIndex + 1;
while ToIndex >= FromIndex do
begin
NewMap.FEntries[ToIndex - FromIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfDoubleSortedMap.TailMap(const FromKey: IInterface): IJclIntfDoubleSortedMap;
var
FromIndex, Index: Integer;
NewMap: TJclIntfDoubleSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclIntfDoubleSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
if (FromIndex >= 0) and (FromIndex < FSize) then
begin
NewMap.SetCapacity(FSize - FromIndex);
NewMap.FSize := FSize - FromIndex;
Index := FromIndex;
while Index < FSize do
begin
NewMap.FEntries[Index - FromIndex] := FEntries[Index];
Inc(Index);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfDoubleSortedMap.Values: IJclDoubleCollection;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclDoubleArrayList.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Value);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfDoubleSortedMap.CreateEmptyContainer: TJclAbstractContainerBase;
begin
Result := TJclIntfDoubleSortedMap.Create(FSize);
AssignPropertiesTo(Result);
end;
function TJclIntfDoubleSortedMap.FreeKey(var Key: IInterface): IInterface;
begin
Result := Key;
Key := nil;
end;
function TJclIntfDoubleSortedMap.FreeValue(var Value: Double): Double;
begin
Result := Value;
Value := 0.0;
end;
function TJclIntfDoubleSortedMap.KeysCompare(const A, B: IInterface): Integer;
begin
Result := IntfSimpleCompare(A, B);
end;
function TJclIntfDoubleSortedMap.ValuesCompare(const A, B: Double): Integer;
begin
Result := ItemsCompare(A, B);
end;
//=== { TJclDoubleDoubleSortedMap } ==============================================
constructor TJclDoubleDoubleSortedMap.Create(ACapacity: Integer);
begin
inherited Create();
SetCapacity(ACapacity);
end;
destructor TJclDoubleDoubleSortedMap.Destroy;
begin
FReadOnly := False;
Clear;
inherited Destroy;
end;
procedure TJclDoubleDoubleSortedMap.AssignDataTo(Dest: TJclAbstractContainerBase);
var
MyDest: TJclDoubleDoubleSortedMap;
begin
inherited AssignDataTo(Dest);
if Dest is TJclDoubleDoubleSortedMap then
begin
MyDest := TJclDoubleDoubleSortedMap(Dest);
MyDest.SetCapacity(FSize);
MyDest.FEntries := FEntries;
MyDest.FSize := FSize;
end;
end;
function TJclDoubleDoubleSortedMap.BinarySearch(const Key: Double): Integer;
var
HiPos, LoPos, CompPos: Integer;
Comp: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
LoPos := 0;
HiPos := FSize - 1;
CompPos := (HiPos + LoPos) div 2;
while HiPos >= LoPos do
begin
Comp := KeysCompare(FEntries[CompPos].Key, Key);
if Comp < 0 then
LoPos := CompPos + 1
else
if Comp > 0 then
HiPos := CompPos - 1
else
begin
HiPos := CompPos;
LoPos := CompPos + 1;
end;
CompPos := (HiPos + LoPos) div 2;
end;
Result := HiPos;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclDoubleDoubleSortedMap.Clear;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
for Index := 0 to FSize - 1 do
begin
FreeKey(FEntries[Index].Key);
FreeValue(FEntries[Index].Value);
end;
FSize := 0;
AutoPack;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclDoubleDoubleSortedMap.ContainsKey(const Key: Double): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclDoubleDoubleSortedMap.ContainsValue(const Value: Double): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := True;
Break;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclDoubleDoubleSortedMap.FirstKey: Double;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := 0.0;
if FSize > 0 then
Result := FEntries[0].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclDoubleDoubleSortedMap.Extract(const Key: Double): Double;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
Result := FEntries[Index].Value;
FEntries[Index].Value := 0.0;
FreeKey(FEntries[Index].Key);
if Index < (FSize - 1) then
MoveArray(Index + 1, Index, FSize - Index - 1);
Dec(FSize);
AutoPack;
end
else
Result := 0.0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclDoubleDoubleSortedMap.GetValue(const Key: Double): Double;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := 0.0;
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
Result := FEntries[Index].Value
else if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclDoubleDoubleSortedMap.HeadMap(const ToKey: Double): IJclDoubleDoubleSortedMap;
var
ToIndex: Integer;
NewMap: TJclDoubleDoubleSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclDoubleDoubleSortedMap;
ToIndex := BinarySearch(ToKey);
if ToIndex >= 0 then
begin
NewMap.SetCapacity(ToIndex + 1);
NewMap.FSize := ToIndex + 1;
while ToIndex >= 0 do
begin
NewMap.FEntries[ToIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclDoubleDoubleSortedMap.IsEmpty: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := FSize = 0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclDoubleDoubleSortedMap.KeyOfValue(const Value: Double): Double;
var
Index: Integer;
Found: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Found := False;
Result := 0.0;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := FEntries[Index].Key;
Found := True;
Break;
end;
if (not Found) and (not FReturnDefaultElements) then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclDoubleDoubleSortedMap.KeySet: IJclDoubleSet;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclDoubleArraySet.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Key);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclDoubleDoubleSortedMap.LastKey: Double;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := 0.0;
if FSize > 0 then
Result := FEntries[FSize - 1].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclDoubleDoubleSortedMap.MapEquals(const AMap: IJclDoubleDoubleMap): Boolean;
var
It: IJclDoubleIterator;
Index: Integer;
AKey: Double;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
if AMap = nil then
Exit;
if FSize <> AMap.Size then
Exit;
It := AMap.KeySet.First;
Index := 0;
while It.HasNext do
begin
if Index >= FSize then
Exit;
AKey := It.Next;
if ValuesCompare(AMap.GetValue(AKey), FEntries[Index].Value) <> 0 then
Exit;
Inc(Index);
end;
Result := True;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclDoubleDoubleSortedMap.MoveArray(FromIndex, ToIndex, Count: Integer);
begin
if Count > 0 then
begin
Move(FEntries[FromIndex], FEntries[ToIndex], Count * SizeOf(FEntries[0]));
{ Keep reference counting working }
if FromIndex < ToIndex then
begin
if (ToIndex - FromIndex) < Count then
FillChar(FEntries[FromIndex], (ToIndex - FromIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end
else
if FromIndex > ToIndex then
begin
if (FromIndex - ToIndex) < Count then
FillChar(FEntries[ToIndex + Count], (FromIndex - ToIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end;
end;
end;
procedure TJclDoubleDoubleSortedMap.PutAll(const AMap: IJclDoubleDoubleMap);
var
It: IJclDoubleIterator;
Key: Double;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if AMap = nil then
Exit;
It := AMap.KeySet.First;
while It.HasNext do
begin
Key := It.Next;
PutValue(Key, AMap.GetValue(Key));
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclDoubleDoubleSortedMap.PutValue(const Key: Double; const Value: Double);
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FAllowDefaultElements or ((KeysCompare(Key, 0.0) <> 0) and (ValuesCompare(Value, 0.0) <> 0)) then
begin
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
FreeValue(FEntries[Index].Value);
FEntries[Index].Value := Value;
end
else
begin
if FSize = FCapacity then
AutoGrow;
if FSize < FCapacity then
begin
Inc(Index);
if (Index < FSize) and (KeysCompare(FEntries[Index].Key, Key) <> 0) then
MoveArray(Index, Index + 1, FSize - Index);
FEntries[Index].Key := Key;
FEntries[Index].Value := Value;
Inc(FSize);
end;
end;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclDoubleDoubleSortedMap.Remove(const Key: Double): Double;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Result := Extract(Key);
Result := FreeValue(Result);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclDoubleDoubleSortedMap.SetCapacity(Value: Integer);
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FSize <= Value then
begin
SetLength(FEntries, Value);
inherited SetCapacity(Value);
end
else
raise EJclOperationNotSupportedError.Create;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclDoubleDoubleSortedMap.Size: Integer;
begin
Result := FSize;
end;
function TJclDoubleDoubleSortedMap.SubMap(const FromKey, ToKey: Double): IJclDoubleDoubleSortedMap;
var
FromIndex, ToIndex: Integer;
NewMap: TJclDoubleDoubleSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclDoubleDoubleSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
ToIndex := BinarySearch(ToKey);
if (FromIndex >= 0) and (FromIndex <= ToIndex) then
begin
NewMap.SetCapacity(ToIndex - FromIndex + 1);
NewMap.FSize := ToIndex - FromIndex + 1;
while ToIndex >= FromIndex do
begin
NewMap.FEntries[ToIndex - FromIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclDoubleDoubleSortedMap.TailMap(const FromKey: Double): IJclDoubleDoubleSortedMap;
var
FromIndex, Index: Integer;
NewMap: TJclDoubleDoubleSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclDoubleDoubleSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
if (FromIndex >= 0) and (FromIndex < FSize) then
begin
NewMap.SetCapacity(FSize - FromIndex);
NewMap.FSize := FSize - FromIndex;
Index := FromIndex;
while Index < FSize do
begin
NewMap.FEntries[Index - FromIndex] := FEntries[Index];
Inc(Index);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclDoubleDoubleSortedMap.Values: IJclDoubleCollection;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclDoubleArrayList.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Value);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclDoubleDoubleSortedMap.CreateEmptyContainer: TJclAbstractContainerBase;
begin
Result := TJclDoubleDoubleSortedMap.Create(FSize);
AssignPropertiesTo(Result);
end;
function TJclDoubleDoubleSortedMap.FreeKey(var Key: Double): Double;
begin
Result := Key;
Key := 0.0;
end;
function TJclDoubleDoubleSortedMap.FreeValue(var Value: Double): Double;
begin
Result := Value;
Value := 0.0;
end;
function TJclDoubleDoubleSortedMap.KeysCompare(const A, B: Double): Integer;
begin
Result := ItemsCompare(A, B);
end;
function TJclDoubleDoubleSortedMap.ValuesCompare(const A, B: Double): Integer;
begin
Result := ItemsCompare(A, B);
end;
//=== { TJclExtendedIntfSortedMap } ==============================================
constructor TJclExtendedIntfSortedMap.Create(ACapacity: Integer);
begin
inherited Create();
SetCapacity(ACapacity);
end;
destructor TJclExtendedIntfSortedMap.Destroy;
begin
FReadOnly := False;
Clear;
inherited Destroy;
end;
procedure TJclExtendedIntfSortedMap.AssignDataTo(Dest: TJclAbstractContainerBase);
var
MyDest: TJclExtendedIntfSortedMap;
begin
inherited AssignDataTo(Dest);
if Dest is TJclExtendedIntfSortedMap then
begin
MyDest := TJclExtendedIntfSortedMap(Dest);
MyDest.SetCapacity(FSize);
MyDest.FEntries := FEntries;
MyDest.FSize := FSize;
end;
end;
function TJclExtendedIntfSortedMap.BinarySearch(const Key: Extended): Integer;
var
HiPos, LoPos, CompPos: Integer;
Comp: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
LoPos := 0;
HiPos := FSize - 1;
CompPos := (HiPos + LoPos) div 2;
while HiPos >= LoPos do
begin
Comp := KeysCompare(FEntries[CompPos].Key, Key);
if Comp < 0 then
LoPos := CompPos + 1
else
if Comp > 0 then
HiPos := CompPos - 1
else
begin
HiPos := CompPos;
LoPos := CompPos + 1;
end;
CompPos := (HiPos + LoPos) div 2;
end;
Result := HiPos;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclExtendedIntfSortedMap.Clear;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
for Index := 0 to FSize - 1 do
begin
FreeKey(FEntries[Index].Key);
FreeValue(FEntries[Index].Value);
end;
FSize := 0;
AutoPack;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclExtendedIntfSortedMap.ContainsKey(const Key: Extended): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclExtendedIntfSortedMap.ContainsValue(const Value: IInterface): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := True;
Break;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclExtendedIntfSortedMap.FirstKey: Extended;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := 0.0;
if FSize > 0 then
Result := FEntries[0].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclExtendedIntfSortedMap.Extract(const Key: Extended): IInterface;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
Result := FEntries[Index].Value;
FEntries[Index].Value := nil;
FreeKey(FEntries[Index].Key);
if Index < (FSize - 1) then
MoveArray(Index + 1, Index, FSize - Index - 1);
Dec(FSize);
AutoPack;
end
else
Result := nil;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclExtendedIntfSortedMap.GetValue(const Key: Extended): IInterface;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := nil;
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
Result := FEntries[Index].Value
else if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclExtendedIntfSortedMap.HeadMap(const ToKey: Extended): IJclExtendedIntfSortedMap;
var
ToIndex: Integer;
NewMap: TJclExtendedIntfSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclExtendedIntfSortedMap;
ToIndex := BinarySearch(ToKey);
if ToIndex >= 0 then
begin
NewMap.SetCapacity(ToIndex + 1);
NewMap.FSize := ToIndex + 1;
while ToIndex >= 0 do
begin
NewMap.FEntries[ToIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclExtendedIntfSortedMap.IsEmpty: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := FSize = 0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclExtendedIntfSortedMap.KeyOfValue(const Value: IInterface): Extended;
var
Index: Integer;
Found: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Found := False;
Result := 0.0;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := FEntries[Index].Key;
Found := True;
Break;
end;
if (not Found) and (not FReturnDefaultElements) then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclExtendedIntfSortedMap.KeySet: IJclExtendedSet;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclExtendedArraySet.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Key);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclExtendedIntfSortedMap.LastKey: Extended;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := 0.0;
if FSize > 0 then
Result := FEntries[FSize - 1].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclExtendedIntfSortedMap.MapEquals(const AMap: IJclExtendedIntfMap): Boolean;
var
It: IJclExtendedIterator;
Index: Integer;
AKey: Extended;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
if AMap = nil then
Exit;
if FSize <> AMap.Size then
Exit;
It := AMap.KeySet.First;
Index := 0;
while It.HasNext do
begin
if Index >= FSize then
Exit;
AKey := It.Next;
if ValuesCompare(AMap.GetValue(AKey), FEntries[Index].Value) <> 0 then
Exit;
Inc(Index);
end;
Result := True;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclExtendedIntfSortedMap.MoveArray(FromIndex, ToIndex, Count: Integer);
begin
if Count > 0 then
begin
Move(FEntries[FromIndex], FEntries[ToIndex], Count * SizeOf(FEntries[0]));
{ Keep reference counting working }
if FromIndex < ToIndex then
begin
if (ToIndex - FromIndex) < Count then
FillChar(FEntries[FromIndex], (ToIndex - FromIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end
else
if FromIndex > ToIndex then
begin
if (FromIndex - ToIndex) < Count then
FillChar(FEntries[ToIndex + Count], (FromIndex - ToIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end;
end;
end;
procedure TJclExtendedIntfSortedMap.PutAll(const AMap: IJclExtendedIntfMap);
var
It: IJclExtendedIterator;
Key: Extended;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if AMap = nil then
Exit;
It := AMap.KeySet.First;
while It.HasNext do
begin
Key := It.Next;
PutValue(Key, AMap.GetValue(Key));
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclExtendedIntfSortedMap.PutValue(const Key: Extended; const Value: IInterface);
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FAllowDefaultElements or ((KeysCompare(Key, 0.0) <> 0) and (ValuesCompare(Value, nil) <> 0)) then
begin
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
FreeValue(FEntries[Index].Value);
FEntries[Index].Value := Value;
end
else
begin
if FSize = FCapacity then
AutoGrow;
if FSize < FCapacity then
begin
Inc(Index);
if (Index < FSize) and (KeysCompare(FEntries[Index].Key, Key) <> 0) then
MoveArray(Index, Index + 1, FSize - Index);
FEntries[Index].Key := Key;
FEntries[Index].Value := Value;
Inc(FSize);
end;
end;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclExtendedIntfSortedMap.Remove(const Key: Extended): IInterface;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Result := Extract(Key);
Result := FreeValue(Result);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclExtendedIntfSortedMap.SetCapacity(Value: Integer);
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FSize <= Value then
begin
SetLength(FEntries, Value);
inherited SetCapacity(Value);
end
else
raise EJclOperationNotSupportedError.Create;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclExtendedIntfSortedMap.Size: Integer;
begin
Result := FSize;
end;
function TJclExtendedIntfSortedMap.SubMap(const FromKey, ToKey: Extended): IJclExtendedIntfSortedMap;
var
FromIndex, ToIndex: Integer;
NewMap: TJclExtendedIntfSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclExtendedIntfSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
ToIndex := BinarySearch(ToKey);
if (FromIndex >= 0) and (FromIndex <= ToIndex) then
begin
NewMap.SetCapacity(ToIndex - FromIndex + 1);
NewMap.FSize := ToIndex - FromIndex + 1;
while ToIndex >= FromIndex do
begin
NewMap.FEntries[ToIndex - FromIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclExtendedIntfSortedMap.TailMap(const FromKey: Extended): IJclExtendedIntfSortedMap;
var
FromIndex, Index: Integer;
NewMap: TJclExtendedIntfSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclExtendedIntfSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
if (FromIndex >= 0) and (FromIndex < FSize) then
begin
NewMap.SetCapacity(FSize - FromIndex);
NewMap.FSize := FSize - FromIndex;
Index := FromIndex;
while Index < FSize do
begin
NewMap.FEntries[Index - FromIndex] := FEntries[Index];
Inc(Index);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclExtendedIntfSortedMap.Values: IJclIntfCollection;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclIntfArrayList.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Value);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclExtendedIntfSortedMap.CreateEmptyContainer: TJclAbstractContainerBase;
begin
Result := TJclExtendedIntfSortedMap.Create(FSize);
AssignPropertiesTo(Result);
end;
function TJclExtendedIntfSortedMap.FreeKey(var Key: Extended): Extended;
begin
Result := Key;
Key := 0.0;
end;
function TJclExtendedIntfSortedMap.FreeValue(var Value: IInterface): IInterface;
begin
Result := Value;
Value := nil;
end;
function TJclExtendedIntfSortedMap.KeysCompare(const A, B: Extended): Integer;
begin
Result := ItemsCompare(A, B);
end;
function TJclExtendedIntfSortedMap.ValuesCompare(const A, B: IInterface): Integer;
begin
Result := IntfSimpleCompare(A, B);
end;
//=== { TJclIntfExtendedSortedMap } ==============================================
constructor TJclIntfExtendedSortedMap.Create(ACapacity: Integer);
begin
inherited Create();
SetCapacity(ACapacity);
end;
destructor TJclIntfExtendedSortedMap.Destroy;
begin
FReadOnly := False;
Clear;
inherited Destroy;
end;
procedure TJclIntfExtendedSortedMap.AssignDataTo(Dest: TJclAbstractContainerBase);
var
MyDest: TJclIntfExtendedSortedMap;
begin
inherited AssignDataTo(Dest);
if Dest is TJclIntfExtendedSortedMap then
begin
MyDest := TJclIntfExtendedSortedMap(Dest);
MyDest.SetCapacity(FSize);
MyDest.FEntries := FEntries;
MyDest.FSize := FSize;
end;
end;
function TJclIntfExtendedSortedMap.BinarySearch(const Key: IInterface): Integer;
var
HiPos, LoPos, CompPos: Integer;
Comp: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
LoPos := 0;
HiPos := FSize - 1;
CompPos := (HiPos + LoPos) div 2;
while HiPos >= LoPos do
begin
Comp := KeysCompare(FEntries[CompPos].Key, Key);
if Comp < 0 then
LoPos := CompPos + 1
else
if Comp > 0 then
HiPos := CompPos - 1
else
begin
HiPos := CompPos;
LoPos := CompPos + 1;
end;
CompPos := (HiPos + LoPos) div 2;
end;
Result := HiPos;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntfExtendedSortedMap.Clear;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
for Index := 0 to FSize - 1 do
begin
FreeKey(FEntries[Index].Key);
FreeValue(FEntries[Index].Value);
end;
FSize := 0;
AutoPack;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfExtendedSortedMap.ContainsKey(const Key: IInterface): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfExtendedSortedMap.ContainsValue(const Value: Extended): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := True;
Break;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfExtendedSortedMap.FirstKey: IInterface;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := nil;
if FSize > 0 then
Result := FEntries[0].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfExtendedSortedMap.Extract(const Key: IInterface): Extended;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
Result := FEntries[Index].Value;
FEntries[Index].Value := 0.0;
FreeKey(FEntries[Index].Key);
if Index < (FSize - 1) then
MoveArray(Index + 1, Index, FSize - Index - 1);
Dec(FSize);
AutoPack;
end
else
Result := 0.0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfExtendedSortedMap.GetValue(const Key: IInterface): Extended;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := 0.0;
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
Result := FEntries[Index].Value
else if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfExtendedSortedMap.HeadMap(const ToKey: IInterface): IJclIntfExtendedSortedMap;
var
ToIndex: Integer;
NewMap: TJclIntfExtendedSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclIntfExtendedSortedMap;
ToIndex := BinarySearch(ToKey);
if ToIndex >= 0 then
begin
NewMap.SetCapacity(ToIndex + 1);
NewMap.FSize := ToIndex + 1;
while ToIndex >= 0 do
begin
NewMap.FEntries[ToIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfExtendedSortedMap.IsEmpty: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := FSize = 0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfExtendedSortedMap.KeyOfValue(const Value: Extended): IInterface;
var
Index: Integer;
Found: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Found := False;
Result := nil;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := FEntries[Index].Key;
Found := True;
Break;
end;
if (not Found) and (not FReturnDefaultElements) then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfExtendedSortedMap.KeySet: IJclIntfSet;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclIntfArraySet.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Key);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfExtendedSortedMap.LastKey: IInterface;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := nil;
if FSize > 0 then
Result := FEntries[FSize - 1].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfExtendedSortedMap.MapEquals(const AMap: IJclIntfExtendedMap): Boolean;
var
It: IJclIntfIterator;
Index: Integer;
AKey: IInterface;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
if AMap = nil then
Exit;
if FSize <> AMap.Size then
Exit;
It := AMap.KeySet.First;
Index := 0;
while It.HasNext do
begin
if Index >= FSize then
Exit;
AKey := It.Next;
if ValuesCompare(AMap.GetValue(AKey), FEntries[Index].Value) <> 0 then
Exit;
Inc(Index);
end;
Result := True;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntfExtendedSortedMap.MoveArray(FromIndex, ToIndex, Count: Integer);
begin
if Count > 0 then
begin
Move(FEntries[FromIndex], FEntries[ToIndex], Count * SizeOf(FEntries[0]));
{ Keep reference counting working }
if FromIndex < ToIndex then
begin
if (ToIndex - FromIndex) < Count then
FillChar(FEntries[FromIndex], (ToIndex - FromIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end
else
if FromIndex > ToIndex then
begin
if (FromIndex - ToIndex) < Count then
FillChar(FEntries[ToIndex + Count], (FromIndex - ToIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end;
end;
end;
procedure TJclIntfExtendedSortedMap.PutAll(const AMap: IJclIntfExtendedMap);
var
It: IJclIntfIterator;
Key: IInterface;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if AMap = nil then
Exit;
It := AMap.KeySet.First;
while It.HasNext do
begin
Key := It.Next;
PutValue(Key, AMap.GetValue(Key));
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntfExtendedSortedMap.PutValue(const Key: IInterface; const Value: Extended);
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FAllowDefaultElements or ((KeysCompare(Key, nil) <> 0) and (ValuesCompare(Value, 0.0) <> 0)) then
begin
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
FreeValue(FEntries[Index].Value);
FEntries[Index].Value := Value;
end
else
begin
if FSize = FCapacity then
AutoGrow;
if FSize < FCapacity then
begin
Inc(Index);
if (Index < FSize) and (KeysCompare(FEntries[Index].Key, Key) <> 0) then
MoveArray(Index, Index + 1, FSize - Index);
FEntries[Index].Key := Key;
FEntries[Index].Value := Value;
Inc(FSize);
end;
end;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfExtendedSortedMap.Remove(const Key: IInterface): Extended;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Result := Extract(Key);
Result := FreeValue(Result);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntfExtendedSortedMap.SetCapacity(Value: Integer);
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FSize <= Value then
begin
SetLength(FEntries, Value);
inherited SetCapacity(Value);
end
else
raise EJclOperationNotSupportedError.Create;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfExtendedSortedMap.Size: Integer;
begin
Result := FSize;
end;
function TJclIntfExtendedSortedMap.SubMap(const FromKey, ToKey: IInterface): IJclIntfExtendedSortedMap;
var
FromIndex, ToIndex: Integer;
NewMap: TJclIntfExtendedSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclIntfExtendedSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
ToIndex := BinarySearch(ToKey);
if (FromIndex >= 0) and (FromIndex <= ToIndex) then
begin
NewMap.SetCapacity(ToIndex - FromIndex + 1);
NewMap.FSize := ToIndex - FromIndex + 1;
while ToIndex >= FromIndex do
begin
NewMap.FEntries[ToIndex - FromIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfExtendedSortedMap.TailMap(const FromKey: IInterface): IJclIntfExtendedSortedMap;
var
FromIndex, Index: Integer;
NewMap: TJclIntfExtendedSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclIntfExtendedSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
if (FromIndex >= 0) and (FromIndex < FSize) then
begin
NewMap.SetCapacity(FSize - FromIndex);
NewMap.FSize := FSize - FromIndex;
Index := FromIndex;
while Index < FSize do
begin
NewMap.FEntries[Index - FromIndex] := FEntries[Index];
Inc(Index);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfExtendedSortedMap.Values: IJclExtendedCollection;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclExtendedArrayList.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Value);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfExtendedSortedMap.CreateEmptyContainer: TJclAbstractContainerBase;
begin
Result := TJclIntfExtendedSortedMap.Create(FSize);
AssignPropertiesTo(Result);
end;
function TJclIntfExtendedSortedMap.FreeKey(var Key: IInterface): IInterface;
begin
Result := Key;
Key := nil;
end;
function TJclIntfExtendedSortedMap.FreeValue(var Value: Extended): Extended;
begin
Result := Value;
Value := 0.0;
end;
function TJclIntfExtendedSortedMap.KeysCompare(const A, B: IInterface): Integer;
begin
Result := IntfSimpleCompare(A, B);
end;
function TJclIntfExtendedSortedMap.ValuesCompare(const A, B: Extended): Integer;
begin
Result := ItemsCompare(A, B);
end;
//=== { TJclExtendedExtendedSortedMap } ==============================================
constructor TJclExtendedExtendedSortedMap.Create(ACapacity: Integer);
begin
inherited Create();
SetCapacity(ACapacity);
end;
destructor TJclExtendedExtendedSortedMap.Destroy;
begin
FReadOnly := False;
Clear;
inherited Destroy;
end;
procedure TJclExtendedExtendedSortedMap.AssignDataTo(Dest: TJclAbstractContainerBase);
var
MyDest: TJclExtendedExtendedSortedMap;
begin
inherited AssignDataTo(Dest);
if Dest is TJclExtendedExtendedSortedMap then
begin
MyDest := TJclExtendedExtendedSortedMap(Dest);
MyDest.SetCapacity(FSize);
MyDest.FEntries := FEntries;
MyDest.FSize := FSize;
end;
end;
function TJclExtendedExtendedSortedMap.BinarySearch(const Key: Extended): Integer;
var
HiPos, LoPos, CompPos: Integer;
Comp: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
LoPos := 0;
HiPos := FSize - 1;
CompPos := (HiPos + LoPos) div 2;
while HiPos >= LoPos do
begin
Comp := KeysCompare(FEntries[CompPos].Key, Key);
if Comp < 0 then
LoPos := CompPos + 1
else
if Comp > 0 then
HiPos := CompPos - 1
else
begin
HiPos := CompPos;
LoPos := CompPos + 1;
end;
CompPos := (HiPos + LoPos) div 2;
end;
Result := HiPos;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclExtendedExtendedSortedMap.Clear;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
for Index := 0 to FSize - 1 do
begin
FreeKey(FEntries[Index].Key);
FreeValue(FEntries[Index].Value);
end;
FSize := 0;
AutoPack;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclExtendedExtendedSortedMap.ContainsKey(const Key: Extended): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclExtendedExtendedSortedMap.ContainsValue(const Value: Extended): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := True;
Break;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclExtendedExtendedSortedMap.FirstKey: Extended;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := 0.0;
if FSize > 0 then
Result := FEntries[0].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclExtendedExtendedSortedMap.Extract(const Key: Extended): Extended;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
Result := FEntries[Index].Value;
FEntries[Index].Value := 0.0;
FreeKey(FEntries[Index].Key);
if Index < (FSize - 1) then
MoveArray(Index + 1, Index, FSize - Index - 1);
Dec(FSize);
AutoPack;
end
else
Result := 0.0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclExtendedExtendedSortedMap.GetValue(const Key: Extended): Extended;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := 0.0;
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
Result := FEntries[Index].Value
else if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclExtendedExtendedSortedMap.HeadMap(const ToKey: Extended): IJclExtendedExtendedSortedMap;
var
ToIndex: Integer;
NewMap: TJclExtendedExtendedSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclExtendedExtendedSortedMap;
ToIndex := BinarySearch(ToKey);
if ToIndex >= 0 then
begin
NewMap.SetCapacity(ToIndex + 1);
NewMap.FSize := ToIndex + 1;
while ToIndex >= 0 do
begin
NewMap.FEntries[ToIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclExtendedExtendedSortedMap.IsEmpty: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := FSize = 0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclExtendedExtendedSortedMap.KeyOfValue(const Value: Extended): Extended;
var
Index: Integer;
Found: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Found := False;
Result := 0.0;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := FEntries[Index].Key;
Found := True;
Break;
end;
if (not Found) and (not FReturnDefaultElements) then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclExtendedExtendedSortedMap.KeySet: IJclExtendedSet;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclExtendedArraySet.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Key);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclExtendedExtendedSortedMap.LastKey: Extended;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := 0.0;
if FSize > 0 then
Result := FEntries[FSize - 1].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclExtendedExtendedSortedMap.MapEquals(const AMap: IJclExtendedExtendedMap): Boolean;
var
It: IJclExtendedIterator;
Index: Integer;
AKey: Extended;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
if AMap = nil then
Exit;
if FSize <> AMap.Size then
Exit;
It := AMap.KeySet.First;
Index := 0;
while It.HasNext do
begin
if Index >= FSize then
Exit;
AKey := It.Next;
if ValuesCompare(AMap.GetValue(AKey), FEntries[Index].Value) <> 0 then
Exit;
Inc(Index);
end;
Result := True;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclExtendedExtendedSortedMap.MoveArray(FromIndex, ToIndex, Count: Integer);
begin
if Count > 0 then
begin
Move(FEntries[FromIndex], FEntries[ToIndex], Count * SizeOf(FEntries[0]));
{ Keep reference counting working }
if FromIndex < ToIndex then
begin
if (ToIndex - FromIndex) < Count then
FillChar(FEntries[FromIndex], (ToIndex - FromIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end
else
if FromIndex > ToIndex then
begin
if (FromIndex - ToIndex) < Count then
FillChar(FEntries[ToIndex + Count], (FromIndex - ToIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end;
end;
end;
procedure TJclExtendedExtendedSortedMap.PutAll(const AMap: IJclExtendedExtendedMap);
var
It: IJclExtendedIterator;
Key: Extended;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if AMap = nil then
Exit;
It := AMap.KeySet.First;
while It.HasNext do
begin
Key := It.Next;
PutValue(Key, AMap.GetValue(Key));
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclExtendedExtendedSortedMap.PutValue(const Key: Extended; const Value: Extended);
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FAllowDefaultElements or ((KeysCompare(Key, 0.0) <> 0) and (ValuesCompare(Value, 0.0) <> 0)) then
begin
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
FreeValue(FEntries[Index].Value);
FEntries[Index].Value := Value;
end
else
begin
if FSize = FCapacity then
AutoGrow;
if FSize < FCapacity then
begin
Inc(Index);
if (Index < FSize) and (KeysCompare(FEntries[Index].Key, Key) <> 0) then
MoveArray(Index, Index + 1, FSize - Index);
FEntries[Index].Key := Key;
FEntries[Index].Value := Value;
Inc(FSize);
end;
end;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclExtendedExtendedSortedMap.Remove(const Key: Extended): Extended;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Result := Extract(Key);
Result := FreeValue(Result);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclExtendedExtendedSortedMap.SetCapacity(Value: Integer);
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FSize <= Value then
begin
SetLength(FEntries, Value);
inherited SetCapacity(Value);
end
else
raise EJclOperationNotSupportedError.Create;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclExtendedExtendedSortedMap.Size: Integer;
begin
Result := FSize;
end;
function TJclExtendedExtendedSortedMap.SubMap(const FromKey, ToKey: Extended): IJclExtendedExtendedSortedMap;
var
FromIndex, ToIndex: Integer;
NewMap: TJclExtendedExtendedSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclExtendedExtendedSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
ToIndex := BinarySearch(ToKey);
if (FromIndex >= 0) and (FromIndex <= ToIndex) then
begin
NewMap.SetCapacity(ToIndex - FromIndex + 1);
NewMap.FSize := ToIndex - FromIndex + 1;
while ToIndex >= FromIndex do
begin
NewMap.FEntries[ToIndex - FromIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclExtendedExtendedSortedMap.TailMap(const FromKey: Extended): IJclExtendedExtendedSortedMap;
var
FromIndex, Index: Integer;
NewMap: TJclExtendedExtendedSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclExtendedExtendedSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
if (FromIndex >= 0) and (FromIndex < FSize) then
begin
NewMap.SetCapacity(FSize - FromIndex);
NewMap.FSize := FSize - FromIndex;
Index := FromIndex;
while Index < FSize do
begin
NewMap.FEntries[Index - FromIndex] := FEntries[Index];
Inc(Index);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclExtendedExtendedSortedMap.Values: IJclExtendedCollection;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclExtendedArrayList.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Value);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclExtendedExtendedSortedMap.CreateEmptyContainer: TJclAbstractContainerBase;
begin
Result := TJclExtendedExtendedSortedMap.Create(FSize);
AssignPropertiesTo(Result);
end;
function TJclExtendedExtendedSortedMap.FreeKey(var Key: Extended): Extended;
begin
Result := Key;
Key := 0.0;
end;
function TJclExtendedExtendedSortedMap.FreeValue(var Value: Extended): Extended;
begin
Result := Value;
Value := 0.0;
end;
function TJclExtendedExtendedSortedMap.KeysCompare(const A, B: Extended): Integer;
begin
Result := ItemsCompare(A, B);
end;
function TJclExtendedExtendedSortedMap.ValuesCompare(const A, B: Extended): Integer;
begin
Result := ItemsCompare(A, B);
end;
//=== { TJclIntegerIntfSortedMap } ==============================================
constructor TJclIntegerIntfSortedMap.Create(ACapacity: Integer);
begin
inherited Create();
SetCapacity(ACapacity);
end;
destructor TJclIntegerIntfSortedMap.Destroy;
begin
FReadOnly := False;
Clear;
inherited Destroy;
end;
procedure TJclIntegerIntfSortedMap.AssignDataTo(Dest: TJclAbstractContainerBase);
var
MyDest: TJclIntegerIntfSortedMap;
begin
inherited AssignDataTo(Dest);
if Dest is TJclIntegerIntfSortedMap then
begin
MyDest := TJclIntegerIntfSortedMap(Dest);
MyDest.SetCapacity(FSize);
MyDest.FEntries := FEntries;
MyDest.FSize := FSize;
end;
end;
function TJclIntegerIntfSortedMap.BinarySearch(Key: Integer): Integer;
var
HiPos, LoPos, CompPos: Integer;
Comp: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
LoPos := 0;
HiPos := FSize - 1;
CompPos := (HiPos + LoPos) div 2;
while HiPos >= LoPos do
begin
Comp := KeysCompare(FEntries[CompPos].Key, Key);
if Comp < 0 then
LoPos := CompPos + 1
else
if Comp > 0 then
HiPos := CompPos - 1
else
begin
HiPos := CompPos;
LoPos := CompPos + 1;
end;
CompPos := (HiPos + LoPos) div 2;
end;
Result := HiPos;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntegerIntfSortedMap.Clear;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
for Index := 0 to FSize - 1 do
begin
FreeKey(FEntries[Index].Key);
FreeValue(FEntries[Index].Value);
end;
FSize := 0;
AutoPack;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntegerIntfSortedMap.ContainsKey(Key: Integer): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntegerIntfSortedMap.ContainsValue(const Value: IInterface): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := True;
Break;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntegerIntfSortedMap.FirstKey: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := 0;
if FSize > 0 then
Result := FEntries[0].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntegerIntfSortedMap.Extract(Key: Integer): IInterface;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
Result := FEntries[Index].Value;
FEntries[Index].Value := nil;
FreeKey(FEntries[Index].Key);
if Index < (FSize - 1) then
MoveArray(Index + 1, Index, FSize - Index - 1);
Dec(FSize);
AutoPack;
end
else
Result := nil;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntegerIntfSortedMap.GetValue(Key: Integer): IInterface;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := nil;
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
Result := FEntries[Index].Value
else if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntegerIntfSortedMap.HeadMap(ToKey: Integer): IJclIntegerIntfSortedMap;
var
ToIndex: Integer;
NewMap: TJclIntegerIntfSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclIntegerIntfSortedMap;
ToIndex := BinarySearch(ToKey);
if ToIndex >= 0 then
begin
NewMap.SetCapacity(ToIndex + 1);
NewMap.FSize := ToIndex + 1;
while ToIndex >= 0 do
begin
NewMap.FEntries[ToIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntegerIntfSortedMap.IsEmpty: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := FSize = 0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntegerIntfSortedMap.KeyOfValue(const Value: IInterface): Integer;
var
Index: Integer;
Found: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Found := False;
Result := 0;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := FEntries[Index].Key;
Found := True;
Break;
end;
if (not Found) and (not FReturnDefaultElements) then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntegerIntfSortedMap.KeySet: IJclIntegerSet;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclIntegerArraySet.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Key);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntegerIntfSortedMap.LastKey: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := 0;
if FSize > 0 then
Result := FEntries[FSize - 1].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntegerIntfSortedMap.MapEquals(const AMap: IJclIntegerIntfMap): Boolean;
var
It: IJclIntegerIterator;
Index: Integer;
AKey: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
if AMap = nil then
Exit;
if FSize <> AMap.Size then
Exit;
It := AMap.KeySet.First;
Index := 0;
while It.HasNext do
begin
if Index >= FSize then
Exit;
AKey := It.Next;
if ValuesCompare(AMap.GetValue(AKey), FEntries[Index].Value) <> 0 then
Exit;
Inc(Index);
end;
Result := True;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntegerIntfSortedMap.MoveArray(FromIndex, ToIndex, Count: Integer);
begin
if Count > 0 then
begin
Move(FEntries[FromIndex], FEntries[ToIndex], Count * SizeOf(FEntries[0]));
{ Keep reference counting working }
if FromIndex < ToIndex then
begin
if (ToIndex - FromIndex) < Count then
FillChar(FEntries[FromIndex], (ToIndex - FromIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end
else
if FromIndex > ToIndex then
begin
if (FromIndex - ToIndex) < Count then
FillChar(FEntries[ToIndex + Count], (FromIndex - ToIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end;
end;
end;
procedure TJclIntegerIntfSortedMap.PutAll(const AMap: IJclIntegerIntfMap);
var
It: IJclIntegerIterator;
Key: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if AMap = nil then
Exit;
It := AMap.KeySet.First;
while It.HasNext do
begin
Key := It.Next;
PutValue(Key, AMap.GetValue(Key));
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntegerIntfSortedMap.PutValue(Key: Integer; const Value: IInterface);
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FAllowDefaultElements or ((KeysCompare(Key, 0) <> 0) and (ValuesCompare(Value, nil) <> 0)) then
begin
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
FreeValue(FEntries[Index].Value);
FEntries[Index].Value := Value;
end
else
begin
if FSize = FCapacity then
AutoGrow;
if FSize < FCapacity then
begin
Inc(Index);
if (Index < FSize) and (KeysCompare(FEntries[Index].Key, Key) <> 0) then
MoveArray(Index, Index + 1, FSize - Index);
FEntries[Index].Key := Key;
FEntries[Index].Value := Value;
Inc(FSize);
end;
end;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntegerIntfSortedMap.Remove(Key: Integer): IInterface;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Result := Extract(Key);
Result := FreeValue(Result);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntegerIntfSortedMap.SetCapacity(Value: Integer);
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FSize <= Value then
begin
SetLength(FEntries, Value);
inherited SetCapacity(Value);
end
else
raise EJclOperationNotSupportedError.Create;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntegerIntfSortedMap.Size: Integer;
begin
Result := FSize;
end;
function TJclIntegerIntfSortedMap.SubMap(FromKey, ToKey: Integer): IJclIntegerIntfSortedMap;
var
FromIndex, ToIndex: Integer;
NewMap: TJclIntegerIntfSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclIntegerIntfSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
ToIndex := BinarySearch(ToKey);
if (FromIndex >= 0) and (FromIndex <= ToIndex) then
begin
NewMap.SetCapacity(ToIndex - FromIndex + 1);
NewMap.FSize := ToIndex - FromIndex + 1;
while ToIndex >= FromIndex do
begin
NewMap.FEntries[ToIndex - FromIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntegerIntfSortedMap.TailMap(FromKey: Integer): IJclIntegerIntfSortedMap;
var
FromIndex, Index: Integer;
NewMap: TJclIntegerIntfSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclIntegerIntfSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
if (FromIndex >= 0) and (FromIndex < FSize) then
begin
NewMap.SetCapacity(FSize - FromIndex);
NewMap.FSize := FSize - FromIndex;
Index := FromIndex;
while Index < FSize do
begin
NewMap.FEntries[Index - FromIndex] := FEntries[Index];
Inc(Index);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntegerIntfSortedMap.Values: IJclIntfCollection;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclIntfArrayList.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Value);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntegerIntfSortedMap.CreateEmptyContainer: TJclAbstractContainerBase;
begin
Result := TJclIntegerIntfSortedMap.Create(FSize);
AssignPropertiesTo(Result);
end;
function TJclIntegerIntfSortedMap.FreeKey(var Key: Integer): Integer;
begin
Result := Key;
Key := 0;
end;
function TJclIntegerIntfSortedMap.FreeValue(var Value: IInterface): IInterface;
begin
Result := Value;
Value := nil;
end;
function TJclIntegerIntfSortedMap.KeysCompare(A, B: Integer): Integer;
begin
Result := ItemsCompare(A, B);
end;
function TJclIntegerIntfSortedMap.ValuesCompare(const A, B: IInterface): Integer;
begin
Result := IntfSimpleCompare(A, B);
end;
//=== { TJclIntfIntegerSortedMap } ==============================================
constructor TJclIntfIntegerSortedMap.Create(ACapacity: Integer);
begin
inherited Create();
SetCapacity(ACapacity);
end;
destructor TJclIntfIntegerSortedMap.Destroy;
begin
FReadOnly := False;
Clear;
inherited Destroy;
end;
procedure TJclIntfIntegerSortedMap.AssignDataTo(Dest: TJclAbstractContainerBase);
var
MyDest: TJclIntfIntegerSortedMap;
begin
inherited AssignDataTo(Dest);
if Dest is TJclIntfIntegerSortedMap then
begin
MyDest := TJclIntfIntegerSortedMap(Dest);
MyDest.SetCapacity(FSize);
MyDest.FEntries := FEntries;
MyDest.FSize := FSize;
end;
end;
function TJclIntfIntegerSortedMap.BinarySearch(const Key: IInterface): Integer;
var
HiPos, LoPos, CompPos: Integer;
Comp: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
LoPos := 0;
HiPos := FSize - 1;
CompPos := (HiPos + LoPos) div 2;
while HiPos >= LoPos do
begin
Comp := KeysCompare(FEntries[CompPos].Key, Key);
if Comp < 0 then
LoPos := CompPos + 1
else
if Comp > 0 then
HiPos := CompPos - 1
else
begin
HiPos := CompPos;
LoPos := CompPos + 1;
end;
CompPos := (HiPos + LoPos) div 2;
end;
Result := HiPos;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntfIntegerSortedMap.Clear;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
for Index := 0 to FSize - 1 do
begin
FreeKey(FEntries[Index].Key);
FreeValue(FEntries[Index].Value);
end;
FSize := 0;
AutoPack;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfIntegerSortedMap.ContainsKey(const Key: IInterface): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfIntegerSortedMap.ContainsValue(Value: Integer): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := True;
Break;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfIntegerSortedMap.FirstKey: IInterface;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := nil;
if FSize > 0 then
Result := FEntries[0].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfIntegerSortedMap.Extract(const Key: IInterface): Integer;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
Result := FEntries[Index].Value;
FEntries[Index].Value := 0;
FreeKey(FEntries[Index].Key);
if Index < (FSize - 1) then
MoveArray(Index + 1, Index, FSize - Index - 1);
Dec(FSize);
AutoPack;
end
else
Result := 0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfIntegerSortedMap.GetValue(const Key: IInterface): Integer;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := 0;
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
Result := FEntries[Index].Value
else if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfIntegerSortedMap.HeadMap(const ToKey: IInterface): IJclIntfIntegerSortedMap;
var
ToIndex: Integer;
NewMap: TJclIntfIntegerSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclIntfIntegerSortedMap;
ToIndex := BinarySearch(ToKey);
if ToIndex >= 0 then
begin
NewMap.SetCapacity(ToIndex + 1);
NewMap.FSize := ToIndex + 1;
while ToIndex >= 0 do
begin
NewMap.FEntries[ToIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfIntegerSortedMap.IsEmpty: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := FSize = 0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfIntegerSortedMap.KeyOfValue(Value: Integer): IInterface;
var
Index: Integer;
Found: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Found := False;
Result := nil;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := FEntries[Index].Key;
Found := True;
Break;
end;
if (not Found) and (not FReturnDefaultElements) then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfIntegerSortedMap.KeySet: IJclIntfSet;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclIntfArraySet.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Key);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfIntegerSortedMap.LastKey: IInterface;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := nil;
if FSize > 0 then
Result := FEntries[FSize - 1].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfIntegerSortedMap.MapEquals(const AMap: IJclIntfIntegerMap): Boolean;
var
It: IJclIntfIterator;
Index: Integer;
AKey: IInterface;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
if AMap = nil then
Exit;
if FSize <> AMap.Size then
Exit;
It := AMap.KeySet.First;
Index := 0;
while It.HasNext do
begin
if Index >= FSize then
Exit;
AKey := It.Next;
if ValuesCompare(AMap.GetValue(AKey), FEntries[Index].Value) <> 0 then
Exit;
Inc(Index);
end;
Result := True;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntfIntegerSortedMap.MoveArray(FromIndex, ToIndex, Count: Integer);
begin
if Count > 0 then
begin
Move(FEntries[FromIndex], FEntries[ToIndex], Count * SizeOf(FEntries[0]));
{ Keep reference counting working }
if FromIndex < ToIndex then
begin
if (ToIndex - FromIndex) < Count then
FillChar(FEntries[FromIndex], (ToIndex - FromIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end
else
if FromIndex > ToIndex then
begin
if (FromIndex - ToIndex) < Count then
FillChar(FEntries[ToIndex + Count], (FromIndex - ToIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end;
end;
end;
procedure TJclIntfIntegerSortedMap.PutAll(const AMap: IJclIntfIntegerMap);
var
It: IJclIntfIterator;
Key: IInterface;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if AMap = nil then
Exit;
It := AMap.KeySet.First;
while It.HasNext do
begin
Key := It.Next;
PutValue(Key, AMap.GetValue(Key));
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntfIntegerSortedMap.PutValue(const Key: IInterface; Value: Integer);
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FAllowDefaultElements or ((KeysCompare(Key, nil) <> 0) and (ValuesCompare(Value, 0) <> 0)) then
begin
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
FreeValue(FEntries[Index].Value);
FEntries[Index].Value := Value;
end
else
begin
if FSize = FCapacity then
AutoGrow;
if FSize < FCapacity then
begin
Inc(Index);
if (Index < FSize) and (KeysCompare(FEntries[Index].Key, Key) <> 0) then
MoveArray(Index, Index + 1, FSize - Index);
FEntries[Index].Key := Key;
FEntries[Index].Value := Value;
Inc(FSize);
end;
end;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfIntegerSortedMap.Remove(const Key: IInterface): Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Result := Extract(Key);
Result := FreeValue(Result);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntfIntegerSortedMap.SetCapacity(Value: Integer);
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FSize <= Value then
begin
SetLength(FEntries, Value);
inherited SetCapacity(Value);
end
else
raise EJclOperationNotSupportedError.Create;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfIntegerSortedMap.Size: Integer;
begin
Result := FSize;
end;
function TJclIntfIntegerSortedMap.SubMap(const FromKey, ToKey: IInterface): IJclIntfIntegerSortedMap;
var
FromIndex, ToIndex: Integer;
NewMap: TJclIntfIntegerSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclIntfIntegerSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
ToIndex := BinarySearch(ToKey);
if (FromIndex >= 0) and (FromIndex <= ToIndex) then
begin
NewMap.SetCapacity(ToIndex - FromIndex + 1);
NewMap.FSize := ToIndex - FromIndex + 1;
while ToIndex >= FromIndex do
begin
NewMap.FEntries[ToIndex - FromIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfIntegerSortedMap.TailMap(const FromKey: IInterface): IJclIntfIntegerSortedMap;
var
FromIndex, Index: Integer;
NewMap: TJclIntfIntegerSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclIntfIntegerSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
if (FromIndex >= 0) and (FromIndex < FSize) then
begin
NewMap.SetCapacity(FSize - FromIndex);
NewMap.FSize := FSize - FromIndex;
Index := FromIndex;
while Index < FSize do
begin
NewMap.FEntries[Index - FromIndex] := FEntries[Index];
Inc(Index);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfIntegerSortedMap.Values: IJclIntegerCollection;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclIntegerArrayList.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Value);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfIntegerSortedMap.CreateEmptyContainer: TJclAbstractContainerBase;
begin
Result := TJclIntfIntegerSortedMap.Create(FSize);
AssignPropertiesTo(Result);
end;
function TJclIntfIntegerSortedMap.FreeKey(var Key: IInterface): IInterface;
begin
Result := Key;
Key := nil;
end;
function TJclIntfIntegerSortedMap.FreeValue(var Value: Integer): Integer;
begin
Result := Value;
Value := 0;
end;
function TJclIntfIntegerSortedMap.KeysCompare(const A, B: IInterface): Integer;
begin
Result := IntfSimpleCompare(A, B);
end;
function TJclIntfIntegerSortedMap.ValuesCompare(A, B: Integer): Integer;
begin
Result := ItemsCompare(A, B);
end;
//=== { TJclIntegerIntegerSortedMap } ==============================================
constructor TJclIntegerIntegerSortedMap.Create(ACapacity: Integer);
begin
inherited Create();
SetCapacity(ACapacity);
end;
destructor TJclIntegerIntegerSortedMap.Destroy;
begin
FReadOnly := False;
Clear;
inherited Destroy;
end;
procedure TJclIntegerIntegerSortedMap.AssignDataTo(Dest: TJclAbstractContainerBase);
var
MyDest: TJclIntegerIntegerSortedMap;
begin
inherited AssignDataTo(Dest);
if Dest is TJclIntegerIntegerSortedMap then
begin
MyDest := TJclIntegerIntegerSortedMap(Dest);
MyDest.SetCapacity(FSize);
MyDest.FEntries := FEntries;
MyDest.FSize := FSize;
end;
end;
function TJclIntegerIntegerSortedMap.BinarySearch(Key: Integer): Integer;
var
HiPos, LoPos, CompPos: Integer;
Comp: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
LoPos := 0;
HiPos := FSize - 1;
CompPos := (HiPos + LoPos) div 2;
while HiPos >= LoPos do
begin
Comp := KeysCompare(FEntries[CompPos].Key, Key);
if Comp < 0 then
LoPos := CompPos + 1
else
if Comp > 0 then
HiPos := CompPos - 1
else
begin
HiPos := CompPos;
LoPos := CompPos + 1;
end;
CompPos := (HiPos + LoPos) div 2;
end;
Result := HiPos;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntegerIntegerSortedMap.Clear;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
for Index := 0 to FSize - 1 do
begin
FreeKey(FEntries[Index].Key);
FreeValue(FEntries[Index].Value);
end;
FSize := 0;
AutoPack;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntegerIntegerSortedMap.ContainsKey(Key: Integer): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntegerIntegerSortedMap.ContainsValue(Value: Integer): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := True;
Break;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntegerIntegerSortedMap.FirstKey: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := 0;
if FSize > 0 then
Result := FEntries[0].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntegerIntegerSortedMap.Extract(Key: Integer): Integer;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
Result := FEntries[Index].Value;
FEntries[Index].Value := 0;
FreeKey(FEntries[Index].Key);
if Index < (FSize - 1) then
MoveArray(Index + 1, Index, FSize - Index - 1);
Dec(FSize);
AutoPack;
end
else
Result := 0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntegerIntegerSortedMap.GetValue(Key: Integer): Integer;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := 0;
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
Result := FEntries[Index].Value
else if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntegerIntegerSortedMap.HeadMap(ToKey: Integer): IJclIntegerIntegerSortedMap;
var
ToIndex: Integer;
NewMap: TJclIntegerIntegerSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclIntegerIntegerSortedMap;
ToIndex := BinarySearch(ToKey);
if ToIndex >= 0 then
begin
NewMap.SetCapacity(ToIndex + 1);
NewMap.FSize := ToIndex + 1;
while ToIndex >= 0 do
begin
NewMap.FEntries[ToIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntegerIntegerSortedMap.IsEmpty: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := FSize = 0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntegerIntegerSortedMap.KeyOfValue(Value: Integer): Integer;
var
Index: Integer;
Found: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Found := False;
Result := 0;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := FEntries[Index].Key;
Found := True;
Break;
end;
if (not Found) and (not FReturnDefaultElements) then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntegerIntegerSortedMap.KeySet: IJclIntegerSet;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclIntegerArraySet.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Key);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntegerIntegerSortedMap.LastKey: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := 0;
if FSize > 0 then
Result := FEntries[FSize - 1].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntegerIntegerSortedMap.MapEquals(const AMap: IJclIntegerIntegerMap): Boolean;
var
It: IJclIntegerIterator;
Index: Integer;
AKey: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
if AMap = nil then
Exit;
if FSize <> AMap.Size then
Exit;
It := AMap.KeySet.First;
Index := 0;
while It.HasNext do
begin
if Index >= FSize then
Exit;
AKey := It.Next;
if ValuesCompare(AMap.GetValue(AKey), FEntries[Index].Value) <> 0 then
Exit;
Inc(Index);
end;
Result := True;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntegerIntegerSortedMap.MoveArray(FromIndex, ToIndex, Count: Integer);
begin
if Count > 0 then
begin
Move(FEntries[FromIndex], FEntries[ToIndex], Count * SizeOf(FEntries[0]));
{ Keep reference counting working }
if FromIndex < ToIndex then
begin
if (ToIndex - FromIndex) < Count then
FillChar(FEntries[FromIndex], (ToIndex - FromIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end
else
if FromIndex > ToIndex then
begin
if (FromIndex - ToIndex) < Count then
FillChar(FEntries[ToIndex + Count], (FromIndex - ToIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end;
end;
end;
procedure TJclIntegerIntegerSortedMap.PutAll(const AMap: IJclIntegerIntegerMap);
var
It: IJclIntegerIterator;
Key: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if AMap = nil then
Exit;
It := AMap.KeySet.First;
while It.HasNext do
begin
Key := It.Next;
PutValue(Key, AMap.GetValue(Key));
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntegerIntegerSortedMap.PutValue(Key: Integer; Value: Integer);
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FAllowDefaultElements or ((KeysCompare(Key, 0) <> 0) and (ValuesCompare(Value, 0) <> 0)) then
begin
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
FreeValue(FEntries[Index].Value);
FEntries[Index].Value := Value;
end
else
begin
if FSize = FCapacity then
AutoGrow;
if FSize < FCapacity then
begin
Inc(Index);
if (Index < FSize) and (KeysCompare(FEntries[Index].Key, Key) <> 0) then
MoveArray(Index, Index + 1, FSize - Index);
FEntries[Index].Key := Key;
FEntries[Index].Value := Value;
Inc(FSize);
end;
end;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntegerIntegerSortedMap.Remove(Key: Integer): Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Result := Extract(Key);
Result := FreeValue(Result);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntegerIntegerSortedMap.SetCapacity(Value: Integer);
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FSize <= Value then
begin
SetLength(FEntries, Value);
inherited SetCapacity(Value);
end
else
raise EJclOperationNotSupportedError.Create;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntegerIntegerSortedMap.Size: Integer;
begin
Result := FSize;
end;
function TJclIntegerIntegerSortedMap.SubMap(FromKey, ToKey: Integer): IJclIntegerIntegerSortedMap;
var
FromIndex, ToIndex: Integer;
NewMap: TJclIntegerIntegerSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclIntegerIntegerSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
ToIndex := BinarySearch(ToKey);
if (FromIndex >= 0) and (FromIndex <= ToIndex) then
begin
NewMap.SetCapacity(ToIndex - FromIndex + 1);
NewMap.FSize := ToIndex - FromIndex + 1;
while ToIndex >= FromIndex do
begin
NewMap.FEntries[ToIndex - FromIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntegerIntegerSortedMap.TailMap(FromKey: Integer): IJclIntegerIntegerSortedMap;
var
FromIndex, Index: Integer;
NewMap: TJclIntegerIntegerSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclIntegerIntegerSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
if (FromIndex >= 0) and (FromIndex < FSize) then
begin
NewMap.SetCapacity(FSize - FromIndex);
NewMap.FSize := FSize - FromIndex;
Index := FromIndex;
while Index < FSize do
begin
NewMap.FEntries[Index - FromIndex] := FEntries[Index];
Inc(Index);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntegerIntegerSortedMap.Values: IJclIntegerCollection;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclIntegerArrayList.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Value);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntegerIntegerSortedMap.CreateEmptyContainer: TJclAbstractContainerBase;
begin
Result := TJclIntegerIntegerSortedMap.Create(FSize);
AssignPropertiesTo(Result);
end;
function TJclIntegerIntegerSortedMap.FreeKey(var Key: Integer): Integer;
begin
Result := Key;
Key := 0;
end;
function TJclIntegerIntegerSortedMap.FreeValue(var Value: Integer): Integer;
begin
Result := Value;
Value := 0;
end;
function TJclIntegerIntegerSortedMap.KeysCompare(A, B: Integer): Integer;
begin
Result := ItemsCompare(A, B);
end;
function TJclIntegerIntegerSortedMap.ValuesCompare(A, B: Integer): Integer;
begin
Result := ItemsCompare(A, B);
end;
//=== { TJclCardinalIntfSortedMap } ==============================================
constructor TJclCardinalIntfSortedMap.Create(ACapacity: Integer);
begin
inherited Create();
SetCapacity(ACapacity);
end;
destructor TJclCardinalIntfSortedMap.Destroy;
begin
FReadOnly := False;
Clear;
inherited Destroy;
end;
procedure TJclCardinalIntfSortedMap.AssignDataTo(Dest: TJclAbstractContainerBase);
var
MyDest: TJclCardinalIntfSortedMap;
begin
inherited AssignDataTo(Dest);
if Dest is TJclCardinalIntfSortedMap then
begin
MyDest := TJclCardinalIntfSortedMap(Dest);
MyDest.SetCapacity(FSize);
MyDest.FEntries := FEntries;
MyDest.FSize := FSize;
end;
end;
function TJclCardinalIntfSortedMap.BinarySearch(Key: Cardinal): Integer;
var
HiPos, LoPos, CompPos: Integer;
Comp: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
LoPos := 0;
HiPos := FSize - 1;
CompPos := (HiPos + LoPos) div 2;
while HiPos >= LoPos do
begin
Comp := KeysCompare(FEntries[CompPos].Key, Key);
if Comp < 0 then
LoPos := CompPos + 1
else
if Comp > 0 then
HiPos := CompPos - 1
else
begin
HiPos := CompPos;
LoPos := CompPos + 1;
end;
CompPos := (HiPos + LoPos) div 2;
end;
Result := HiPos;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclCardinalIntfSortedMap.Clear;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
for Index := 0 to FSize - 1 do
begin
FreeKey(FEntries[Index].Key);
FreeValue(FEntries[Index].Value);
end;
FSize := 0;
AutoPack;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclCardinalIntfSortedMap.ContainsKey(Key: Cardinal): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclCardinalIntfSortedMap.ContainsValue(const Value: IInterface): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := True;
Break;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclCardinalIntfSortedMap.FirstKey: Cardinal;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := 0;
if FSize > 0 then
Result := FEntries[0].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclCardinalIntfSortedMap.Extract(Key: Cardinal): IInterface;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
Result := FEntries[Index].Value;
FEntries[Index].Value := nil;
FreeKey(FEntries[Index].Key);
if Index < (FSize - 1) then
MoveArray(Index + 1, Index, FSize - Index - 1);
Dec(FSize);
AutoPack;
end
else
Result := nil;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclCardinalIntfSortedMap.GetValue(Key: Cardinal): IInterface;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := nil;
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
Result := FEntries[Index].Value
else if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclCardinalIntfSortedMap.HeadMap(ToKey: Cardinal): IJclCardinalIntfSortedMap;
var
ToIndex: Integer;
NewMap: TJclCardinalIntfSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclCardinalIntfSortedMap;
ToIndex := BinarySearch(ToKey);
if ToIndex >= 0 then
begin
NewMap.SetCapacity(ToIndex + 1);
NewMap.FSize := ToIndex + 1;
while ToIndex >= 0 do
begin
NewMap.FEntries[ToIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclCardinalIntfSortedMap.IsEmpty: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := FSize = 0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclCardinalIntfSortedMap.KeyOfValue(const Value: IInterface): Cardinal;
var
Index: Integer;
Found: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Found := False;
Result := 0;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := FEntries[Index].Key;
Found := True;
Break;
end;
if (not Found) and (not FReturnDefaultElements) then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclCardinalIntfSortedMap.KeySet: IJclCardinalSet;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclCardinalArraySet.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Key);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclCardinalIntfSortedMap.LastKey: Cardinal;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := 0;
if FSize > 0 then
Result := FEntries[FSize - 1].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclCardinalIntfSortedMap.MapEquals(const AMap: IJclCardinalIntfMap): Boolean;
var
It: IJclCardinalIterator;
Index: Integer;
AKey: Cardinal;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
if AMap = nil then
Exit;
if FSize <> AMap.Size then
Exit;
It := AMap.KeySet.First;
Index := 0;
while It.HasNext do
begin
if Index >= FSize then
Exit;
AKey := It.Next;
if ValuesCompare(AMap.GetValue(AKey), FEntries[Index].Value) <> 0 then
Exit;
Inc(Index);
end;
Result := True;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclCardinalIntfSortedMap.MoveArray(FromIndex, ToIndex, Count: Integer);
begin
if Count > 0 then
begin
Move(FEntries[FromIndex], FEntries[ToIndex], Count * SizeOf(FEntries[0]));
{ Keep reference counting working }
if FromIndex < ToIndex then
begin
if (ToIndex - FromIndex) < Count then
FillChar(FEntries[FromIndex], (ToIndex - FromIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end
else
if FromIndex > ToIndex then
begin
if (FromIndex - ToIndex) < Count then
FillChar(FEntries[ToIndex + Count], (FromIndex - ToIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end;
end;
end;
procedure TJclCardinalIntfSortedMap.PutAll(const AMap: IJclCardinalIntfMap);
var
It: IJclCardinalIterator;
Key: Cardinal;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if AMap = nil then
Exit;
It := AMap.KeySet.First;
while It.HasNext do
begin
Key := It.Next;
PutValue(Key, AMap.GetValue(Key));
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclCardinalIntfSortedMap.PutValue(Key: Cardinal; const Value: IInterface);
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FAllowDefaultElements or ((KeysCompare(Key, 0) <> 0) and (ValuesCompare(Value, nil) <> 0)) then
begin
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
FreeValue(FEntries[Index].Value);
FEntries[Index].Value := Value;
end
else
begin
if FSize = FCapacity then
AutoGrow;
if FSize < FCapacity then
begin
Inc(Index);
if (Index < FSize) and (KeysCompare(FEntries[Index].Key, Key) <> 0) then
MoveArray(Index, Index + 1, FSize - Index);
FEntries[Index].Key := Key;
FEntries[Index].Value := Value;
Inc(FSize);
end;
end;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclCardinalIntfSortedMap.Remove(Key: Cardinal): IInterface;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Result := Extract(Key);
Result := FreeValue(Result);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclCardinalIntfSortedMap.SetCapacity(Value: Integer);
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FSize <= Value then
begin
SetLength(FEntries, Value);
inherited SetCapacity(Value);
end
else
raise EJclOperationNotSupportedError.Create;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclCardinalIntfSortedMap.Size: Integer;
begin
Result := FSize;
end;
function TJclCardinalIntfSortedMap.SubMap(FromKey, ToKey: Cardinal): IJclCardinalIntfSortedMap;
var
FromIndex, ToIndex: Integer;
NewMap: TJclCardinalIntfSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclCardinalIntfSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
ToIndex := BinarySearch(ToKey);
if (FromIndex >= 0) and (FromIndex <= ToIndex) then
begin
NewMap.SetCapacity(ToIndex - FromIndex + 1);
NewMap.FSize := ToIndex - FromIndex + 1;
while ToIndex >= FromIndex do
begin
NewMap.FEntries[ToIndex - FromIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclCardinalIntfSortedMap.TailMap(FromKey: Cardinal): IJclCardinalIntfSortedMap;
var
FromIndex, Index: Integer;
NewMap: TJclCardinalIntfSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclCardinalIntfSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
if (FromIndex >= 0) and (FromIndex < FSize) then
begin
NewMap.SetCapacity(FSize - FromIndex);
NewMap.FSize := FSize - FromIndex;
Index := FromIndex;
while Index < FSize do
begin
NewMap.FEntries[Index - FromIndex] := FEntries[Index];
Inc(Index);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclCardinalIntfSortedMap.Values: IJclIntfCollection;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclIntfArrayList.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Value);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclCardinalIntfSortedMap.CreateEmptyContainer: TJclAbstractContainerBase;
begin
Result := TJclCardinalIntfSortedMap.Create(FSize);
AssignPropertiesTo(Result);
end;
function TJclCardinalIntfSortedMap.FreeKey(var Key: Cardinal): Cardinal;
begin
Result := Key;
Key := 0;
end;
function TJclCardinalIntfSortedMap.FreeValue(var Value: IInterface): IInterface;
begin
Result := Value;
Value := nil;
end;
function TJclCardinalIntfSortedMap.KeysCompare(A, B: Cardinal): Integer;
begin
Result := ItemsCompare(A, B);
end;
function TJclCardinalIntfSortedMap.ValuesCompare(const A, B: IInterface): Integer;
begin
Result := IntfSimpleCompare(A, B);
end;
//=== { TJclIntfCardinalSortedMap } ==============================================
constructor TJclIntfCardinalSortedMap.Create(ACapacity: Integer);
begin
inherited Create();
SetCapacity(ACapacity);
end;
destructor TJclIntfCardinalSortedMap.Destroy;
begin
FReadOnly := False;
Clear;
inherited Destroy;
end;
procedure TJclIntfCardinalSortedMap.AssignDataTo(Dest: TJclAbstractContainerBase);
var
MyDest: TJclIntfCardinalSortedMap;
begin
inherited AssignDataTo(Dest);
if Dest is TJclIntfCardinalSortedMap then
begin
MyDest := TJclIntfCardinalSortedMap(Dest);
MyDest.SetCapacity(FSize);
MyDest.FEntries := FEntries;
MyDest.FSize := FSize;
end;
end;
function TJclIntfCardinalSortedMap.BinarySearch(const Key: IInterface): Integer;
var
HiPos, LoPos, CompPos: Integer;
Comp: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
LoPos := 0;
HiPos := FSize - 1;
CompPos := (HiPos + LoPos) div 2;
while HiPos >= LoPos do
begin
Comp := KeysCompare(FEntries[CompPos].Key, Key);
if Comp < 0 then
LoPos := CompPos + 1
else
if Comp > 0 then
HiPos := CompPos - 1
else
begin
HiPos := CompPos;
LoPos := CompPos + 1;
end;
CompPos := (HiPos + LoPos) div 2;
end;
Result := HiPos;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntfCardinalSortedMap.Clear;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
for Index := 0 to FSize - 1 do
begin
FreeKey(FEntries[Index].Key);
FreeValue(FEntries[Index].Value);
end;
FSize := 0;
AutoPack;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfCardinalSortedMap.ContainsKey(const Key: IInterface): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfCardinalSortedMap.ContainsValue(Value: Cardinal): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := True;
Break;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfCardinalSortedMap.FirstKey: IInterface;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := nil;
if FSize > 0 then
Result := FEntries[0].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfCardinalSortedMap.Extract(const Key: IInterface): Cardinal;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
Result := FEntries[Index].Value;
FEntries[Index].Value := 0;
FreeKey(FEntries[Index].Key);
if Index < (FSize - 1) then
MoveArray(Index + 1, Index, FSize - Index - 1);
Dec(FSize);
AutoPack;
end
else
Result := 0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfCardinalSortedMap.GetValue(const Key: IInterface): Cardinal;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := 0;
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
Result := FEntries[Index].Value
else if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfCardinalSortedMap.HeadMap(const ToKey: IInterface): IJclIntfCardinalSortedMap;
var
ToIndex: Integer;
NewMap: TJclIntfCardinalSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclIntfCardinalSortedMap;
ToIndex := BinarySearch(ToKey);
if ToIndex >= 0 then
begin
NewMap.SetCapacity(ToIndex + 1);
NewMap.FSize := ToIndex + 1;
while ToIndex >= 0 do
begin
NewMap.FEntries[ToIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfCardinalSortedMap.IsEmpty: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := FSize = 0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfCardinalSortedMap.KeyOfValue(Value: Cardinal): IInterface;
var
Index: Integer;
Found: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Found := False;
Result := nil;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := FEntries[Index].Key;
Found := True;
Break;
end;
if (not Found) and (not FReturnDefaultElements) then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfCardinalSortedMap.KeySet: IJclIntfSet;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclIntfArraySet.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Key);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfCardinalSortedMap.LastKey: IInterface;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := nil;
if FSize > 0 then
Result := FEntries[FSize - 1].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfCardinalSortedMap.MapEquals(const AMap: IJclIntfCardinalMap): Boolean;
var
It: IJclIntfIterator;
Index: Integer;
AKey: IInterface;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
if AMap = nil then
Exit;
if FSize <> AMap.Size then
Exit;
It := AMap.KeySet.First;
Index := 0;
while It.HasNext do
begin
if Index >= FSize then
Exit;
AKey := It.Next;
if ValuesCompare(AMap.GetValue(AKey), FEntries[Index].Value) <> 0 then
Exit;
Inc(Index);
end;
Result := True;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntfCardinalSortedMap.MoveArray(FromIndex, ToIndex, Count: Integer);
begin
if Count > 0 then
begin
Move(FEntries[FromIndex], FEntries[ToIndex], Count * SizeOf(FEntries[0]));
{ Keep reference counting working }
if FromIndex < ToIndex then
begin
if (ToIndex - FromIndex) < Count then
FillChar(FEntries[FromIndex], (ToIndex - FromIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end
else
if FromIndex > ToIndex then
begin
if (FromIndex - ToIndex) < Count then
FillChar(FEntries[ToIndex + Count], (FromIndex - ToIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end;
end;
end;
procedure TJclIntfCardinalSortedMap.PutAll(const AMap: IJclIntfCardinalMap);
var
It: IJclIntfIterator;
Key: IInterface;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if AMap = nil then
Exit;
It := AMap.KeySet.First;
while It.HasNext do
begin
Key := It.Next;
PutValue(Key, AMap.GetValue(Key));
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntfCardinalSortedMap.PutValue(const Key: IInterface; Value: Cardinal);
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FAllowDefaultElements or ((KeysCompare(Key, nil) <> 0) and (ValuesCompare(Value, 0) <> 0)) then
begin
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
FreeValue(FEntries[Index].Value);
FEntries[Index].Value := Value;
end
else
begin
if FSize = FCapacity then
AutoGrow;
if FSize < FCapacity then
begin
Inc(Index);
if (Index < FSize) and (KeysCompare(FEntries[Index].Key, Key) <> 0) then
MoveArray(Index, Index + 1, FSize - Index);
FEntries[Index].Key := Key;
FEntries[Index].Value := Value;
Inc(FSize);
end;
end;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfCardinalSortedMap.Remove(const Key: IInterface): Cardinal;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Result := Extract(Key);
Result := FreeValue(Result);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntfCardinalSortedMap.SetCapacity(Value: Integer);
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FSize <= Value then
begin
SetLength(FEntries, Value);
inherited SetCapacity(Value);
end
else
raise EJclOperationNotSupportedError.Create;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfCardinalSortedMap.Size: Integer;
begin
Result := FSize;
end;
function TJclIntfCardinalSortedMap.SubMap(const FromKey, ToKey: IInterface): IJclIntfCardinalSortedMap;
var
FromIndex, ToIndex: Integer;
NewMap: TJclIntfCardinalSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclIntfCardinalSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
ToIndex := BinarySearch(ToKey);
if (FromIndex >= 0) and (FromIndex <= ToIndex) then
begin
NewMap.SetCapacity(ToIndex - FromIndex + 1);
NewMap.FSize := ToIndex - FromIndex + 1;
while ToIndex >= FromIndex do
begin
NewMap.FEntries[ToIndex - FromIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfCardinalSortedMap.TailMap(const FromKey: IInterface): IJclIntfCardinalSortedMap;
var
FromIndex, Index: Integer;
NewMap: TJclIntfCardinalSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclIntfCardinalSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
if (FromIndex >= 0) and (FromIndex < FSize) then
begin
NewMap.SetCapacity(FSize - FromIndex);
NewMap.FSize := FSize - FromIndex;
Index := FromIndex;
while Index < FSize do
begin
NewMap.FEntries[Index - FromIndex] := FEntries[Index];
Inc(Index);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfCardinalSortedMap.Values: IJclCardinalCollection;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclCardinalArrayList.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Value);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfCardinalSortedMap.CreateEmptyContainer: TJclAbstractContainerBase;
begin
Result := TJclIntfCardinalSortedMap.Create(FSize);
AssignPropertiesTo(Result);
end;
function TJclIntfCardinalSortedMap.FreeKey(var Key: IInterface): IInterface;
begin
Result := Key;
Key := nil;
end;
function TJclIntfCardinalSortedMap.FreeValue(var Value: Cardinal): Cardinal;
begin
Result := Value;
Value := 0;
end;
function TJclIntfCardinalSortedMap.KeysCompare(const A, B: IInterface): Integer;
begin
Result := IntfSimpleCompare(A, B);
end;
function TJclIntfCardinalSortedMap.ValuesCompare(A, B: Cardinal): Integer;
begin
Result := ItemsCompare(A, B);
end;
//=== { TJclCardinalCardinalSortedMap } ==============================================
constructor TJclCardinalCardinalSortedMap.Create(ACapacity: Integer);
begin
inherited Create();
SetCapacity(ACapacity);
end;
destructor TJclCardinalCardinalSortedMap.Destroy;
begin
FReadOnly := False;
Clear;
inherited Destroy;
end;
procedure TJclCardinalCardinalSortedMap.AssignDataTo(Dest: TJclAbstractContainerBase);
var
MyDest: TJclCardinalCardinalSortedMap;
begin
inherited AssignDataTo(Dest);
if Dest is TJclCardinalCardinalSortedMap then
begin
MyDest := TJclCardinalCardinalSortedMap(Dest);
MyDest.SetCapacity(FSize);
MyDest.FEntries := FEntries;
MyDest.FSize := FSize;
end;
end;
function TJclCardinalCardinalSortedMap.BinarySearch(Key: Cardinal): Integer;
var
HiPos, LoPos, CompPos: Integer;
Comp: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
LoPos := 0;
HiPos := FSize - 1;
CompPos := (HiPos + LoPos) div 2;
while HiPos >= LoPos do
begin
Comp := KeysCompare(FEntries[CompPos].Key, Key);
if Comp < 0 then
LoPos := CompPos + 1
else
if Comp > 0 then
HiPos := CompPos - 1
else
begin
HiPos := CompPos;
LoPos := CompPos + 1;
end;
CompPos := (HiPos + LoPos) div 2;
end;
Result := HiPos;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclCardinalCardinalSortedMap.Clear;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
for Index := 0 to FSize - 1 do
begin
FreeKey(FEntries[Index].Key);
FreeValue(FEntries[Index].Value);
end;
FSize := 0;
AutoPack;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclCardinalCardinalSortedMap.ContainsKey(Key: Cardinal): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclCardinalCardinalSortedMap.ContainsValue(Value: Cardinal): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := True;
Break;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclCardinalCardinalSortedMap.FirstKey: Cardinal;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := 0;
if FSize > 0 then
Result := FEntries[0].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclCardinalCardinalSortedMap.Extract(Key: Cardinal): Cardinal;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
Result := FEntries[Index].Value;
FEntries[Index].Value := 0;
FreeKey(FEntries[Index].Key);
if Index < (FSize - 1) then
MoveArray(Index + 1, Index, FSize - Index - 1);
Dec(FSize);
AutoPack;
end
else
Result := 0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclCardinalCardinalSortedMap.GetValue(Key: Cardinal): Cardinal;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := 0;
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
Result := FEntries[Index].Value
else if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclCardinalCardinalSortedMap.HeadMap(ToKey: Cardinal): IJclCardinalCardinalSortedMap;
var
ToIndex: Integer;
NewMap: TJclCardinalCardinalSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclCardinalCardinalSortedMap;
ToIndex := BinarySearch(ToKey);
if ToIndex >= 0 then
begin
NewMap.SetCapacity(ToIndex + 1);
NewMap.FSize := ToIndex + 1;
while ToIndex >= 0 do
begin
NewMap.FEntries[ToIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclCardinalCardinalSortedMap.IsEmpty: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := FSize = 0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclCardinalCardinalSortedMap.KeyOfValue(Value: Cardinal): Cardinal;
var
Index: Integer;
Found: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Found := False;
Result := 0;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := FEntries[Index].Key;
Found := True;
Break;
end;
if (not Found) and (not FReturnDefaultElements) then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclCardinalCardinalSortedMap.KeySet: IJclCardinalSet;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclCardinalArraySet.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Key);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclCardinalCardinalSortedMap.LastKey: Cardinal;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := 0;
if FSize > 0 then
Result := FEntries[FSize - 1].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclCardinalCardinalSortedMap.MapEquals(const AMap: IJclCardinalCardinalMap): Boolean;
var
It: IJclCardinalIterator;
Index: Integer;
AKey: Cardinal;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
if AMap = nil then
Exit;
if FSize <> AMap.Size then
Exit;
It := AMap.KeySet.First;
Index := 0;
while It.HasNext do
begin
if Index >= FSize then
Exit;
AKey := It.Next;
if ValuesCompare(AMap.GetValue(AKey), FEntries[Index].Value) <> 0 then
Exit;
Inc(Index);
end;
Result := True;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclCardinalCardinalSortedMap.MoveArray(FromIndex, ToIndex, Count: Integer);
begin
if Count > 0 then
begin
Move(FEntries[FromIndex], FEntries[ToIndex], Count * SizeOf(FEntries[0]));
{ Keep reference counting working }
if FromIndex < ToIndex then
begin
if (ToIndex - FromIndex) < Count then
FillChar(FEntries[FromIndex], (ToIndex - FromIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end
else
if FromIndex > ToIndex then
begin
if (FromIndex - ToIndex) < Count then
FillChar(FEntries[ToIndex + Count], (FromIndex - ToIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end;
end;
end;
procedure TJclCardinalCardinalSortedMap.PutAll(const AMap: IJclCardinalCardinalMap);
var
It: IJclCardinalIterator;
Key: Cardinal;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if AMap = nil then
Exit;
It := AMap.KeySet.First;
while It.HasNext do
begin
Key := It.Next;
PutValue(Key, AMap.GetValue(Key));
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclCardinalCardinalSortedMap.PutValue(Key: Cardinal; Value: Cardinal);
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FAllowDefaultElements or ((KeysCompare(Key, 0) <> 0) and (ValuesCompare(Value, 0) <> 0)) then
begin
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
FreeValue(FEntries[Index].Value);
FEntries[Index].Value := Value;
end
else
begin
if FSize = FCapacity then
AutoGrow;
if FSize < FCapacity then
begin
Inc(Index);
if (Index < FSize) and (KeysCompare(FEntries[Index].Key, Key) <> 0) then
MoveArray(Index, Index + 1, FSize - Index);
FEntries[Index].Key := Key;
FEntries[Index].Value := Value;
Inc(FSize);
end;
end;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclCardinalCardinalSortedMap.Remove(Key: Cardinal): Cardinal;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Result := Extract(Key);
Result := FreeValue(Result);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclCardinalCardinalSortedMap.SetCapacity(Value: Integer);
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FSize <= Value then
begin
SetLength(FEntries, Value);
inherited SetCapacity(Value);
end
else
raise EJclOperationNotSupportedError.Create;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclCardinalCardinalSortedMap.Size: Integer;
begin
Result := FSize;
end;
function TJclCardinalCardinalSortedMap.SubMap(FromKey, ToKey: Cardinal): IJclCardinalCardinalSortedMap;
var
FromIndex, ToIndex: Integer;
NewMap: TJclCardinalCardinalSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclCardinalCardinalSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
ToIndex := BinarySearch(ToKey);
if (FromIndex >= 0) and (FromIndex <= ToIndex) then
begin
NewMap.SetCapacity(ToIndex - FromIndex + 1);
NewMap.FSize := ToIndex - FromIndex + 1;
while ToIndex >= FromIndex do
begin
NewMap.FEntries[ToIndex - FromIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclCardinalCardinalSortedMap.TailMap(FromKey: Cardinal): IJclCardinalCardinalSortedMap;
var
FromIndex, Index: Integer;
NewMap: TJclCardinalCardinalSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclCardinalCardinalSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
if (FromIndex >= 0) and (FromIndex < FSize) then
begin
NewMap.SetCapacity(FSize - FromIndex);
NewMap.FSize := FSize - FromIndex;
Index := FromIndex;
while Index < FSize do
begin
NewMap.FEntries[Index - FromIndex] := FEntries[Index];
Inc(Index);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclCardinalCardinalSortedMap.Values: IJclCardinalCollection;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclCardinalArrayList.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Value);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclCardinalCardinalSortedMap.CreateEmptyContainer: TJclAbstractContainerBase;
begin
Result := TJclCardinalCardinalSortedMap.Create(FSize);
AssignPropertiesTo(Result);
end;
function TJclCardinalCardinalSortedMap.FreeKey(var Key: Cardinal): Cardinal;
begin
Result := Key;
Key := 0;
end;
function TJclCardinalCardinalSortedMap.FreeValue(var Value: Cardinal): Cardinal;
begin
Result := Value;
Value := 0;
end;
function TJclCardinalCardinalSortedMap.KeysCompare(A, B: Cardinal): Integer;
begin
Result := ItemsCompare(A, B);
end;
function TJclCardinalCardinalSortedMap.ValuesCompare(A, B: Cardinal): Integer;
begin
Result := ItemsCompare(A, B);
end;
//=== { TJclInt64IntfSortedMap } ==============================================
constructor TJclInt64IntfSortedMap.Create(ACapacity: Integer);
begin
inherited Create();
SetCapacity(ACapacity);
end;
destructor TJclInt64IntfSortedMap.Destroy;
begin
FReadOnly := False;
Clear;
inherited Destroy;
end;
procedure TJclInt64IntfSortedMap.AssignDataTo(Dest: TJclAbstractContainerBase);
var
MyDest: TJclInt64IntfSortedMap;
begin
inherited AssignDataTo(Dest);
if Dest is TJclInt64IntfSortedMap then
begin
MyDest := TJclInt64IntfSortedMap(Dest);
MyDest.SetCapacity(FSize);
MyDest.FEntries := FEntries;
MyDest.FSize := FSize;
end;
end;
function TJclInt64IntfSortedMap.BinarySearch(const Key: Int64): Integer;
var
HiPos, LoPos, CompPos: Integer;
Comp: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
LoPos := 0;
HiPos := FSize - 1;
CompPos := (HiPos + LoPos) div 2;
while HiPos >= LoPos do
begin
Comp := KeysCompare(FEntries[CompPos].Key, Key);
if Comp < 0 then
LoPos := CompPos + 1
else
if Comp > 0 then
HiPos := CompPos - 1
else
begin
HiPos := CompPos;
LoPos := CompPos + 1;
end;
CompPos := (HiPos + LoPos) div 2;
end;
Result := HiPos;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclInt64IntfSortedMap.Clear;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
for Index := 0 to FSize - 1 do
begin
FreeKey(FEntries[Index].Key);
FreeValue(FEntries[Index].Value);
end;
FSize := 0;
AutoPack;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclInt64IntfSortedMap.ContainsKey(const Key: Int64): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclInt64IntfSortedMap.ContainsValue(const Value: IInterface): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := True;
Break;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclInt64IntfSortedMap.FirstKey: Int64;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := 0;
if FSize > 0 then
Result := FEntries[0].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclInt64IntfSortedMap.Extract(const Key: Int64): IInterface;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
Result := FEntries[Index].Value;
FEntries[Index].Value := nil;
FreeKey(FEntries[Index].Key);
if Index < (FSize - 1) then
MoveArray(Index + 1, Index, FSize - Index - 1);
Dec(FSize);
AutoPack;
end
else
Result := nil;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclInt64IntfSortedMap.GetValue(const Key: Int64): IInterface;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := nil;
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
Result := FEntries[Index].Value
else if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclInt64IntfSortedMap.HeadMap(const ToKey: Int64): IJclInt64IntfSortedMap;
var
ToIndex: Integer;
NewMap: TJclInt64IntfSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclInt64IntfSortedMap;
ToIndex := BinarySearch(ToKey);
if ToIndex >= 0 then
begin
NewMap.SetCapacity(ToIndex + 1);
NewMap.FSize := ToIndex + 1;
while ToIndex >= 0 do
begin
NewMap.FEntries[ToIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclInt64IntfSortedMap.IsEmpty: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := FSize = 0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclInt64IntfSortedMap.KeyOfValue(const Value: IInterface): Int64;
var
Index: Integer;
Found: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Found := False;
Result := 0;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := FEntries[Index].Key;
Found := True;
Break;
end;
if (not Found) and (not FReturnDefaultElements) then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclInt64IntfSortedMap.KeySet: IJclInt64Set;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclInt64ArraySet.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Key);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclInt64IntfSortedMap.LastKey: Int64;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := 0;
if FSize > 0 then
Result := FEntries[FSize - 1].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclInt64IntfSortedMap.MapEquals(const AMap: IJclInt64IntfMap): Boolean;
var
It: IJclInt64Iterator;
Index: Integer;
AKey: Int64;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
if AMap = nil then
Exit;
if FSize <> AMap.Size then
Exit;
It := AMap.KeySet.First;
Index := 0;
while It.HasNext do
begin
if Index >= FSize then
Exit;
AKey := It.Next;
if ValuesCompare(AMap.GetValue(AKey), FEntries[Index].Value) <> 0 then
Exit;
Inc(Index);
end;
Result := True;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclInt64IntfSortedMap.MoveArray(FromIndex, ToIndex, Count: Integer);
begin
if Count > 0 then
begin
Move(FEntries[FromIndex], FEntries[ToIndex], Count * SizeOf(FEntries[0]));
{ Keep reference counting working }
if FromIndex < ToIndex then
begin
if (ToIndex - FromIndex) < Count then
FillChar(FEntries[FromIndex], (ToIndex - FromIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end
else
if FromIndex > ToIndex then
begin
if (FromIndex - ToIndex) < Count then
FillChar(FEntries[ToIndex + Count], (FromIndex - ToIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end;
end;
end;
procedure TJclInt64IntfSortedMap.PutAll(const AMap: IJclInt64IntfMap);
var
It: IJclInt64Iterator;
Key: Int64;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if AMap = nil then
Exit;
It := AMap.KeySet.First;
while It.HasNext do
begin
Key := It.Next;
PutValue(Key, AMap.GetValue(Key));
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclInt64IntfSortedMap.PutValue(const Key: Int64; const Value: IInterface);
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FAllowDefaultElements or ((KeysCompare(Key, 0) <> 0) and (ValuesCompare(Value, nil) <> 0)) then
begin
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
FreeValue(FEntries[Index].Value);
FEntries[Index].Value := Value;
end
else
begin
if FSize = FCapacity then
AutoGrow;
if FSize < FCapacity then
begin
Inc(Index);
if (Index < FSize) and (KeysCompare(FEntries[Index].Key, Key) <> 0) then
MoveArray(Index, Index + 1, FSize - Index);
FEntries[Index].Key := Key;
FEntries[Index].Value := Value;
Inc(FSize);
end;
end;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclInt64IntfSortedMap.Remove(const Key: Int64): IInterface;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Result := Extract(Key);
Result := FreeValue(Result);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclInt64IntfSortedMap.SetCapacity(Value: Integer);
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FSize <= Value then
begin
SetLength(FEntries, Value);
inherited SetCapacity(Value);
end
else
raise EJclOperationNotSupportedError.Create;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclInt64IntfSortedMap.Size: Integer;
begin
Result := FSize;
end;
function TJclInt64IntfSortedMap.SubMap(const FromKey, ToKey: Int64): IJclInt64IntfSortedMap;
var
FromIndex, ToIndex: Integer;
NewMap: TJclInt64IntfSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclInt64IntfSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
ToIndex := BinarySearch(ToKey);
if (FromIndex >= 0) and (FromIndex <= ToIndex) then
begin
NewMap.SetCapacity(ToIndex - FromIndex + 1);
NewMap.FSize := ToIndex - FromIndex + 1;
while ToIndex >= FromIndex do
begin
NewMap.FEntries[ToIndex - FromIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclInt64IntfSortedMap.TailMap(const FromKey: Int64): IJclInt64IntfSortedMap;
var
FromIndex, Index: Integer;
NewMap: TJclInt64IntfSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclInt64IntfSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
if (FromIndex >= 0) and (FromIndex < FSize) then
begin
NewMap.SetCapacity(FSize - FromIndex);
NewMap.FSize := FSize - FromIndex;
Index := FromIndex;
while Index < FSize do
begin
NewMap.FEntries[Index - FromIndex] := FEntries[Index];
Inc(Index);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclInt64IntfSortedMap.Values: IJclIntfCollection;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclIntfArrayList.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Value);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclInt64IntfSortedMap.CreateEmptyContainer: TJclAbstractContainerBase;
begin
Result := TJclInt64IntfSortedMap.Create(FSize);
AssignPropertiesTo(Result);
end;
function TJclInt64IntfSortedMap.FreeKey(var Key: Int64): Int64;
begin
Result := Key;
Key := 0;
end;
function TJclInt64IntfSortedMap.FreeValue(var Value: IInterface): IInterface;
begin
Result := Value;
Value := nil;
end;
function TJclInt64IntfSortedMap.KeysCompare(const A, B: Int64): Integer;
begin
Result := ItemsCompare(A, B);
end;
function TJclInt64IntfSortedMap.ValuesCompare(const A, B: IInterface): Integer;
begin
Result := IntfSimpleCompare(A, B);
end;
//=== { TJclIntfInt64SortedMap } ==============================================
constructor TJclIntfInt64SortedMap.Create(ACapacity: Integer);
begin
inherited Create();
SetCapacity(ACapacity);
end;
destructor TJclIntfInt64SortedMap.Destroy;
begin
FReadOnly := False;
Clear;
inherited Destroy;
end;
procedure TJclIntfInt64SortedMap.AssignDataTo(Dest: TJclAbstractContainerBase);
var
MyDest: TJclIntfInt64SortedMap;
begin
inherited AssignDataTo(Dest);
if Dest is TJclIntfInt64SortedMap then
begin
MyDest := TJclIntfInt64SortedMap(Dest);
MyDest.SetCapacity(FSize);
MyDest.FEntries := FEntries;
MyDest.FSize := FSize;
end;
end;
function TJclIntfInt64SortedMap.BinarySearch(const Key: IInterface): Integer;
var
HiPos, LoPos, CompPos: Integer;
Comp: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
LoPos := 0;
HiPos := FSize - 1;
CompPos := (HiPos + LoPos) div 2;
while HiPos >= LoPos do
begin
Comp := KeysCompare(FEntries[CompPos].Key, Key);
if Comp < 0 then
LoPos := CompPos + 1
else
if Comp > 0 then
HiPos := CompPos - 1
else
begin
HiPos := CompPos;
LoPos := CompPos + 1;
end;
CompPos := (HiPos + LoPos) div 2;
end;
Result := HiPos;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntfInt64SortedMap.Clear;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
for Index := 0 to FSize - 1 do
begin
FreeKey(FEntries[Index].Key);
FreeValue(FEntries[Index].Value);
end;
FSize := 0;
AutoPack;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfInt64SortedMap.ContainsKey(const Key: IInterface): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfInt64SortedMap.ContainsValue(const Value: Int64): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := True;
Break;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfInt64SortedMap.FirstKey: IInterface;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := nil;
if FSize > 0 then
Result := FEntries[0].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfInt64SortedMap.Extract(const Key: IInterface): Int64;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
Result := FEntries[Index].Value;
FEntries[Index].Value := 0;
FreeKey(FEntries[Index].Key);
if Index < (FSize - 1) then
MoveArray(Index + 1, Index, FSize - Index - 1);
Dec(FSize);
AutoPack;
end
else
Result := 0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfInt64SortedMap.GetValue(const Key: IInterface): Int64;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := 0;
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
Result := FEntries[Index].Value
else if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfInt64SortedMap.HeadMap(const ToKey: IInterface): IJclIntfInt64SortedMap;
var
ToIndex: Integer;
NewMap: TJclIntfInt64SortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclIntfInt64SortedMap;
ToIndex := BinarySearch(ToKey);
if ToIndex >= 0 then
begin
NewMap.SetCapacity(ToIndex + 1);
NewMap.FSize := ToIndex + 1;
while ToIndex >= 0 do
begin
NewMap.FEntries[ToIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfInt64SortedMap.IsEmpty: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := FSize = 0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfInt64SortedMap.KeyOfValue(const Value: Int64): IInterface;
var
Index: Integer;
Found: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Found := False;
Result := nil;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := FEntries[Index].Key;
Found := True;
Break;
end;
if (not Found) and (not FReturnDefaultElements) then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfInt64SortedMap.KeySet: IJclIntfSet;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclIntfArraySet.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Key);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfInt64SortedMap.LastKey: IInterface;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := nil;
if FSize > 0 then
Result := FEntries[FSize - 1].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfInt64SortedMap.MapEquals(const AMap: IJclIntfInt64Map): Boolean;
var
It: IJclIntfIterator;
Index: Integer;
AKey: IInterface;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
if AMap = nil then
Exit;
if FSize <> AMap.Size then
Exit;
It := AMap.KeySet.First;
Index := 0;
while It.HasNext do
begin
if Index >= FSize then
Exit;
AKey := It.Next;
if ValuesCompare(AMap.GetValue(AKey), FEntries[Index].Value) <> 0 then
Exit;
Inc(Index);
end;
Result := True;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntfInt64SortedMap.MoveArray(FromIndex, ToIndex, Count: Integer);
begin
if Count > 0 then
begin
Move(FEntries[FromIndex], FEntries[ToIndex], Count * SizeOf(FEntries[0]));
{ Keep reference counting working }
if FromIndex < ToIndex then
begin
if (ToIndex - FromIndex) < Count then
FillChar(FEntries[FromIndex], (ToIndex - FromIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end
else
if FromIndex > ToIndex then
begin
if (FromIndex - ToIndex) < Count then
FillChar(FEntries[ToIndex + Count], (FromIndex - ToIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end;
end;
end;
procedure TJclIntfInt64SortedMap.PutAll(const AMap: IJclIntfInt64Map);
var
It: IJclIntfIterator;
Key: IInterface;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if AMap = nil then
Exit;
It := AMap.KeySet.First;
while It.HasNext do
begin
Key := It.Next;
PutValue(Key, AMap.GetValue(Key));
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntfInt64SortedMap.PutValue(const Key: IInterface; const Value: Int64);
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FAllowDefaultElements or ((KeysCompare(Key, nil) <> 0) and (ValuesCompare(Value, 0) <> 0)) then
begin
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
FreeValue(FEntries[Index].Value);
FEntries[Index].Value := Value;
end
else
begin
if FSize = FCapacity then
AutoGrow;
if FSize < FCapacity then
begin
Inc(Index);
if (Index < FSize) and (KeysCompare(FEntries[Index].Key, Key) <> 0) then
MoveArray(Index, Index + 1, FSize - Index);
FEntries[Index].Key := Key;
FEntries[Index].Value := Value;
Inc(FSize);
end;
end;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfInt64SortedMap.Remove(const Key: IInterface): Int64;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Result := Extract(Key);
Result := FreeValue(Result);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntfInt64SortedMap.SetCapacity(Value: Integer);
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FSize <= Value then
begin
SetLength(FEntries, Value);
inherited SetCapacity(Value);
end
else
raise EJclOperationNotSupportedError.Create;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfInt64SortedMap.Size: Integer;
begin
Result := FSize;
end;
function TJclIntfInt64SortedMap.SubMap(const FromKey, ToKey: IInterface): IJclIntfInt64SortedMap;
var
FromIndex, ToIndex: Integer;
NewMap: TJclIntfInt64SortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclIntfInt64SortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
ToIndex := BinarySearch(ToKey);
if (FromIndex >= 0) and (FromIndex <= ToIndex) then
begin
NewMap.SetCapacity(ToIndex - FromIndex + 1);
NewMap.FSize := ToIndex - FromIndex + 1;
while ToIndex >= FromIndex do
begin
NewMap.FEntries[ToIndex - FromIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfInt64SortedMap.TailMap(const FromKey: IInterface): IJclIntfInt64SortedMap;
var
FromIndex, Index: Integer;
NewMap: TJclIntfInt64SortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclIntfInt64SortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
if (FromIndex >= 0) and (FromIndex < FSize) then
begin
NewMap.SetCapacity(FSize - FromIndex);
NewMap.FSize := FSize - FromIndex;
Index := FromIndex;
while Index < FSize do
begin
NewMap.FEntries[Index - FromIndex] := FEntries[Index];
Inc(Index);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfInt64SortedMap.Values: IJclInt64Collection;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclInt64ArrayList.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Value);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfInt64SortedMap.CreateEmptyContainer: TJclAbstractContainerBase;
begin
Result := TJclIntfInt64SortedMap.Create(FSize);
AssignPropertiesTo(Result);
end;
function TJclIntfInt64SortedMap.FreeKey(var Key: IInterface): IInterface;
begin
Result := Key;
Key := nil;
end;
function TJclIntfInt64SortedMap.FreeValue(var Value: Int64): Int64;
begin
Result := Value;
Value := 0;
end;
function TJclIntfInt64SortedMap.KeysCompare(const A, B: IInterface): Integer;
begin
Result := IntfSimpleCompare(A, B);
end;
function TJclIntfInt64SortedMap.ValuesCompare(const A, B: Int64): Integer;
begin
Result := ItemsCompare(A, B);
end;
//=== { TJclInt64Int64SortedMap } ==============================================
constructor TJclInt64Int64SortedMap.Create(ACapacity: Integer);
begin
inherited Create();
SetCapacity(ACapacity);
end;
destructor TJclInt64Int64SortedMap.Destroy;
begin
FReadOnly := False;
Clear;
inherited Destroy;
end;
procedure TJclInt64Int64SortedMap.AssignDataTo(Dest: TJclAbstractContainerBase);
var
MyDest: TJclInt64Int64SortedMap;
begin
inherited AssignDataTo(Dest);
if Dest is TJclInt64Int64SortedMap then
begin
MyDest := TJclInt64Int64SortedMap(Dest);
MyDest.SetCapacity(FSize);
MyDest.FEntries := FEntries;
MyDest.FSize := FSize;
end;
end;
function TJclInt64Int64SortedMap.BinarySearch(const Key: Int64): Integer;
var
HiPos, LoPos, CompPos: Integer;
Comp: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
LoPos := 0;
HiPos := FSize - 1;
CompPos := (HiPos + LoPos) div 2;
while HiPos >= LoPos do
begin
Comp := KeysCompare(FEntries[CompPos].Key, Key);
if Comp < 0 then
LoPos := CompPos + 1
else
if Comp > 0 then
HiPos := CompPos - 1
else
begin
HiPos := CompPos;
LoPos := CompPos + 1;
end;
CompPos := (HiPos + LoPos) div 2;
end;
Result := HiPos;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclInt64Int64SortedMap.Clear;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
for Index := 0 to FSize - 1 do
begin
FreeKey(FEntries[Index].Key);
FreeValue(FEntries[Index].Value);
end;
FSize := 0;
AutoPack;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclInt64Int64SortedMap.ContainsKey(const Key: Int64): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclInt64Int64SortedMap.ContainsValue(const Value: Int64): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := True;
Break;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclInt64Int64SortedMap.FirstKey: Int64;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := 0;
if FSize > 0 then
Result := FEntries[0].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclInt64Int64SortedMap.Extract(const Key: Int64): Int64;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
Result := FEntries[Index].Value;
FEntries[Index].Value := 0;
FreeKey(FEntries[Index].Key);
if Index < (FSize - 1) then
MoveArray(Index + 1, Index, FSize - Index - 1);
Dec(FSize);
AutoPack;
end
else
Result := 0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclInt64Int64SortedMap.GetValue(const Key: Int64): Int64;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := 0;
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
Result := FEntries[Index].Value
else if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclInt64Int64SortedMap.HeadMap(const ToKey: Int64): IJclInt64Int64SortedMap;
var
ToIndex: Integer;
NewMap: TJclInt64Int64SortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclInt64Int64SortedMap;
ToIndex := BinarySearch(ToKey);
if ToIndex >= 0 then
begin
NewMap.SetCapacity(ToIndex + 1);
NewMap.FSize := ToIndex + 1;
while ToIndex >= 0 do
begin
NewMap.FEntries[ToIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclInt64Int64SortedMap.IsEmpty: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := FSize = 0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclInt64Int64SortedMap.KeyOfValue(const Value: Int64): Int64;
var
Index: Integer;
Found: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Found := False;
Result := 0;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := FEntries[Index].Key;
Found := True;
Break;
end;
if (not Found) and (not FReturnDefaultElements) then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclInt64Int64SortedMap.KeySet: IJclInt64Set;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclInt64ArraySet.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Key);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclInt64Int64SortedMap.LastKey: Int64;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := 0;
if FSize > 0 then
Result := FEntries[FSize - 1].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclInt64Int64SortedMap.MapEquals(const AMap: IJclInt64Int64Map): Boolean;
var
It: IJclInt64Iterator;
Index: Integer;
AKey: Int64;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
if AMap = nil then
Exit;
if FSize <> AMap.Size then
Exit;
It := AMap.KeySet.First;
Index := 0;
while It.HasNext do
begin
if Index >= FSize then
Exit;
AKey := It.Next;
if ValuesCompare(AMap.GetValue(AKey), FEntries[Index].Value) <> 0 then
Exit;
Inc(Index);
end;
Result := True;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclInt64Int64SortedMap.MoveArray(FromIndex, ToIndex, Count: Integer);
begin
if Count > 0 then
begin
Move(FEntries[FromIndex], FEntries[ToIndex], Count * SizeOf(FEntries[0]));
{ Keep reference counting working }
if FromIndex < ToIndex then
begin
if (ToIndex - FromIndex) < Count then
FillChar(FEntries[FromIndex], (ToIndex - FromIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end
else
if FromIndex > ToIndex then
begin
if (FromIndex - ToIndex) < Count then
FillChar(FEntries[ToIndex + Count], (FromIndex - ToIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end;
end;
end;
procedure TJclInt64Int64SortedMap.PutAll(const AMap: IJclInt64Int64Map);
var
It: IJclInt64Iterator;
Key: Int64;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if AMap = nil then
Exit;
It := AMap.KeySet.First;
while It.HasNext do
begin
Key := It.Next;
PutValue(Key, AMap.GetValue(Key));
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclInt64Int64SortedMap.PutValue(const Key: Int64; const Value: Int64);
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FAllowDefaultElements or ((KeysCompare(Key, 0) <> 0) and (ValuesCompare(Value, 0) <> 0)) then
begin
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
FreeValue(FEntries[Index].Value);
FEntries[Index].Value := Value;
end
else
begin
if FSize = FCapacity then
AutoGrow;
if FSize < FCapacity then
begin
Inc(Index);
if (Index < FSize) and (KeysCompare(FEntries[Index].Key, Key) <> 0) then
MoveArray(Index, Index + 1, FSize - Index);
FEntries[Index].Key := Key;
FEntries[Index].Value := Value;
Inc(FSize);
end;
end;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclInt64Int64SortedMap.Remove(const Key: Int64): Int64;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Result := Extract(Key);
Result := FreeValue(Result);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclInt64Int64SortedMap.SetCapacity(Value: Integer);
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FSize <= Value then
begin
SetLength(FEntries, Value);
inherited SetCapacity(Value);
end
else
raise EJclOperationNotSupportedError.Create;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclInt64Int64SortedMap.Size: Integer;
begin
Result := FSize;
end;
function TJclInt64Int64SortedMap.SubMap(const FromKey, ToKey: Int64): IJclInt64Int64SortedMap;
var
FromIndex, ToIndex: Integer;
NewMap: TJclInt64Int64SortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclInt64Int64SortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
ToIndex := BinarySearch(ToKey);
if (FromIndex >= 0) and (FromIndex <= ToIndex) then
begin
NewMap.SetCapacity(ToIndex - FromIndex + 1);
NewMap.FSize := ToIndex - FromIndex + 1;
while ToIndex >= FromIndex do
begin
NewMap.FEntries[ToIndex - FromIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclInt64Int64SortedMap.TailMap(const FromKey: Int64): IJclInt64Int64SortedMap;
var
FromIndex, Index: Integer;
NewMap: TJclInt64Int64SortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclInt64Int64SortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
if (FromIndex >= 0) and (FromIndex < FSize) then
begin
NewMap.SetCapacity(FSize - FromIndex);
NewMap.FSize := FSize - FromIndex;
Index := FromIndex;
while Index < FSize do
begin
NewMap.FEntries[Index - FromIndex] := FEntries[Index];
Inc(Index);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclInt64Int64SortedMap.Values: IJclInt64Collection;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclInt64ArrayList.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Value);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclInt64Int64SortedMap.CreateEmptyContainer: TJclAbstractContainerBase;
begin
Result := TJclInt64Int64SortedMap.Create(FSize);
AssignPropertiesTo(Result);
end;
function TJclInt64Int64SortedMap.FreeKey(var Key: Int64): Int64;
begin
Result := Key;
Key := 0;
end;
function TJclInt64Int64SortedMap.FreeValue(var Value: Int64): Int64;
begin
Result := Value;
Value := 0;
end;
function TJclInt64Int64SortedMap.KeysCompare(const A, B: Int64): Integer;
begin
Result := ItemsCompare(A, B);
end;
function TJclInt64Int64SortedMap.ValuesCompare(const A, B: Int64): Integer;
begin
Result := ItemsCompare(A, B);
end;
//=== { TJclPtrIntfSortedMap } ==============================================
constructor TJclPtrIntfSortedMap.Create(ACapacity: Integer);
begin
inherited Create();
SetCapacity(ACapacity);
end;
destructor TJclPtrIntfSortedMap.Destroy;
begin
FReadOnly := False;
Clear;
inherited Destroy;
end;
procedure TJclPtrIntfSortedMap.AssignDataTo(Dest: TJclAbstractContainerBase);
var
MyDest: TJclPtrIntfSortedMap;
begin
inherited AssignDataTo(Dest);
if Dest is TJclPtrIntfSortedMap then
begin
MyDest := TJclPtrIntfSortedMap(Dest);
MyDest.SetCapacity(FSize);
MyDest.FEntries := FEntries;
MyDest.FSize := FSize;
end;
end;
function TJclPtrIntfSortedMap.BinarySearch(Key: Pointer): Integer;
var
HiPos, LoPos, CompPos: Integer;
Comp: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
LoPos := 0;
HiPos := FSize - 1;
CompPos := (HiPos + LoPos) div 2;
while HiPos >= LoPos do
begin
Comp := KeysCompare(FEntries[CompPos].Key, Key);
if Comp < 0 then
LoPos := CompPos + 1
else
if Comp > 0 then
HiPos := CompPos - 1
else
begin
HiPos := CompPos;
LoPos := CompPos + 1;
end;
CompPos := (HiPos + LoPos) div 2;
end;
Result := HiPos;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclPtrIntfSortedMap.Clear;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
for Index := 0 to FSize - 1 do
begin
FreeKey(FEntries[Index].Key);
FreeValue(FEntries[Index].Value);
end;
FSize := 0;
AutoPack;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclPtrIntfSortedMap.ContainsKey(Key: Pointer): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclPtrIntfSortedMap.ContainsValue(const Value: IInterface): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := True;
Break;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclPtrIntfSortedMap.FirstKey: Pointer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := nil;
if FSize > 0 then
Result := FEntries[0].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclPtrIntfSortedMap.Extract(Key: Pointer): IInterface;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
Result := FEntries[Index].Value;
FEntries[Index].Value := nil;
FreeKey(FEntries[Index].Key);
if Index < (FSize - 1) then
MoveArray(Index + 1, Index, FSize - Index - 1);
Dec(FSize);
AutoPack;
end
else
Result := nil;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclPtrIntfSortedMap.GetValue(Key: Pointer): IInterface;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := nil;
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
Result := FEntries[Index].Value
else if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclPtrIntfSortedMap.HeadMap(ToKey: Pointer): IJclPtrIntfSortedMap;
var
ToIndex: Integer;
NewMap: TJclPtrIntfSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclPtrIntfSortedMap;
ToIndex := BinarySearch(ToKey);
if ToIndex >= 0 then
begin
NewMap.SetCapacity(ToIndex + 1);
NewMap.FSize := ToIndex + 1;
while ToIndex >= 0 do
begin
NewMap.FEntries[ToIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclPtrIntfSortedMap.IsEmpty: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := FSize = 0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclPtrIntfSortedMap.KeyOfValue(const Value: IInterface): Pointer;
var
Index: Integer;
Found: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Found := False;
Result := nil;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := FEntries[Index].Key;
Found := True;
Break;
end;
if (not Found) and (not FReturnDefaultElements) then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclPtrIntfSortedMap.KeySet: IJclPtrSet;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclPtrArraySet.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Key);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclPtrIntfSortedMap.LastKey: Pointer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := nil;
if FSize > 0 then
Result := FEntries[FSize - 1].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclPtrIntfSortedMap.MapEquals(const AMap: IJclPtrIntfMap): Boolean;
var
It: IJclPtrIterator;
Index: Integer;
AKey: Pointer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
if AMap = nil then
Exit;
if FSize <> AMap.Size then
Exit;
It := AMap.KeySet.First;
Index := 0;
while It.HasNext do
begin
if Index >= FSize then
Exit;
AKey := It.Next;
if ValuesCompare(AMap.GetValue(AKey), FEntries[Index].Value) <> 0 then
Exit;
Inc(Index);
end;
Result := True;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclPtrIntfSortedMap.MoveArray(FromIndex, ToIndex, Count: Integer);
begin
if Count > 0 then
begin
Move(FEntries[FromIndex], FEntries[ToIndex], Count * SizeOf(FEntries[0]));
{ Keep reference counting working }
if FromIndex < ToIndex then
begin
if (ToIndex - FromIndex) < Count then
FillChar(FEntries[FromIndex], (ToIndex - FromIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end
else
if FromIndex > ToIndex then
begin
if (FromIndex - ToIndex) < Count then
FillChar(FEntries[ToIndex + Count], (FromIndex - ToIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end;
end;
end;
procedure TJclPtrIntfSortedMap.PutAll(const AMap: IJclPtrIntfMap);
var
It: IJclPtrIterator;
Key: Pointer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if AMap = nil then
Exit;
It := AMap.KeySet.First;
while It.HasNext do
begin
Key := It.Next;
PutValue(Key, AMap.GetValue(Key));
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclPtrIntfSortedMap.PutValue(Key: Pointer; const Value: IInterface);
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FAllowDefaultElements or ((KeysCompare(Key, nil) <> 0) and (ValuesCompare(Value, nil) <> 0)) then
begin
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
FreeValue(FEntries[Index].Value);
FEntries[Index].Value := Value;
end
else
begin
if FSize = FCapacity then
AutoGrow;
if FSize < FCapacity then
begin
Inc(Index);
if (Index < FSize) and (KeysCompare(FEntries[Index].Key, Key) <> 0) then
MoveArray(Index, Index + 1, FSize - Index);
FEntries[Index].Key := Key;
FEntries[Index].Value := Value;
Inc(FSize);
end;
end;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclPtrIntfSortedMap.Remove(Key: Pointer): IInterface;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Result := Extract(Key);
Result := FreeValue(Result);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclPtrIntfSortedMap.SetCapacity(Value: Integer);
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FSize <= Value then
begin
SetLength(FEntries, Value);
inherited SetCapacity(Value);
end
else
raise EJclOperationNotSupportedError.Create;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclPtrIntfSortedMap.Size: Integer;
begin
Result := FSize;
end;
function TJclPtrIntfSortedMap.SubMap(FromKey, ToKey: Pointer): IJclPtrIntfSortedMap;
var
FromIndex, ToIndex: Integer;
NewMap: TJclPtrIntfSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclPtrIntfSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
ToIndex := BinarySearch(ToKey);
if (FromIndex >= 0) and (FromIndex <= ToIndex) then
begin
NewMap.SetCapacity(ToIndex - FromIndex + 1);
NewMap.FSize := ToIndex - FromIndex + 1;
while ToIndex >= FromIndex do
begin
NewMap.FEntries[ToIndex - FromIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclPtrIntfSortedMap.TailMap(FromKey: Pointer): IJclPtrIntfSortedMap;
var
FromIndex, Index: Integer;
NewMap: TJclPtrIntfSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclPtrIntfSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
if (FromIndex >= 0) and (FromIndex < FSize) then
begin
NewMap.SetCapacity(FSize - FromIndex);
NewMap.FSize := FSize - FromIndex;
Index := FromIndex;
while Index < FSize do
begin
NewMap.FEntries[Index - FromIndex] := FEntries[Index];
Inc(Index);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclPtrIntfSortedMap.Values: IJclIntfCollection;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclIntfArrayList.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Value);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclPtrIntfSortedMap.CreateEmptyContainer: TJclAbstractContainerBase;
begin
Result := TJclPtrIntfSortedMap.Create(FSize);
AssignPropertiesTo(Result);
end;
function TJclPtrIntfSortedMap.FreeKey(var Key: Pointer): Pointer;
begin
Result := Key;
Key := nil;
end;
function TJclPtrIntfSortedMap.FreeValue(var Value: IInterface): IInterface;
begin
Result := Value;
Value := nil;
end;
function TJclPtrIntfSortedMap.KeysCompare(A, B: Pointer): Integer;
begin
Result := ItemsCompare(A, B);
end;
function TJclPtrIntfSortedMap.ValuesCompare(const A, B: IInterface): Integer;
begin
Result := IntfSimpleCompare(A, B);
end;
//=== { TJclIntfPtrSortedMap } ==============================================
constructor TJclIntfPtrSortedMap.Create(ACapacity: Integer);
begin
inherited Create();
SetCapacity(ACapacity);
end;
destructor TJclIntfPtrSortedMap.Destroy;
begin
FReadOnly := False;
Clear;
inherited Destroy;
end;
procedure TJclIntfPtrSortedMap.AssignDataTo(Dest: TJclAbstractContainerBase);
var
MyDest: TJclIntfPtrSortedMap;
begin
inherited AssignDataTo(Dest);
if Dest is TJclIntfPtrSortedMap then
begin
MyDest := TJclIntfPtrSortedMap(Dest);
MyDest.SetCapacity(FSize);
MyDest.FEntries := FEntries;
MyDest.FSize := FSize;
end;
end;
function TJclIntfPtrSortedMap.BinarySearch(const Key: IInterface): Integer;
var
HiPos, LoPos, CompPos: Integer;
Comp: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
LoPos := 0;
HiPos := FSize - 1;
CompPos := (HiPos + LoPos) div 2;
while HiPos >= LoPos do
begin
Comp := KeysCompare(FEntries[CompPos].Key, Key);
if Comp < 0 then
LoPos := CompPos + 1
else
if Comp > 0 then
HiPos := CompPos - 1
else
begin
HiPos := CompPos;
LoPos := CompPos + 1;
end;
CompPos := (HiPos + LoPos) div 2;
end;
Result := HiPos;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntfPtrSortedMap.Clear;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
for Index := 0 to FSize - 1 do
begin
FreeKey(FEntries[Index].Key);
FreeValue(FEntries[Index].Value);
end;
FSize := 0;
AutoPack;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfPtrSortedMap.ContainsKey(const Key: IInterface): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfPtrSortedMap.ContainsValue(Value: Pointer): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := True;
Break;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfPtrSortedMap.FirstKey: IInterface;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := nil;
if FSize > 0 then
Result := FEntries[0].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfPtrSortedMap.Extract(const Key: IInterface): Pointer;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
Result := FEntries[Index].Value;
FEntries[Index].Value := nil;
FreeKey(FEntries[Index].Key);
if Index < (FSize - 1) then
MoveArray(Index + 1, Index, FSize - Index - 1);
Dec(FSize);
AutoPack;
end
else
Result := nil;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfPtrSortedMap.GetValue(const Key: IInterface): Pointer;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := nil;
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
Result := FEntries[Index].Value
else if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfPtrSortedMap.HeadMap(const ToKey: IInterface): IJclIntfPtrSortedMap;
var
ToIndex: Integer;
NewMap: TJclIntfPtrSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclIntfPtrSortedMap;
ToIndex := BinarySearch(ToKey);
if ToIndex >= 0 then
begin
NewMap.SetCapacity(ToIndex + 1);
NewMap.FSize := ToIndex + 1;
while ToIndex >= 0 do
begin
NewMap.FEntries[ToIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfPtrSortedMap.IsEmpty: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := FSize = 0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfPtrSortedMap.KeyOfValue(Value: Pointer): IInterface;
var
Index: Integer;
Found: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Found := False;
Result := nil;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := FEntries[Index].Key;
Found := True;
Break;
end;
if (not Found) and (not FReturnDefaultElements) then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfPtrSortedMap.KeySet: IJclIntfSet;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclIntfArraySet.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Key);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfPtrSortedMap.LastKey: IInterface;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := nil;
if FSize > 0 then
Result := FEntries[FSize - 1].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfPtrSortedMap.MapEquals(const AMap: IJclIntfPtrMap): Boolean;
var
It: IJclIntfIterator;
Index: Integer;
AKey: IInterface;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
if AMap = nil then
Exit;
if FSize <> AMap.Size then
Exit;
It := AMap.KeySet.First;
Index := 0;
while It.HasNext do
begin
if Index >= FSize then
Exit;
AKey := It.Next;
if ValuesCompare(AMap.GetValue(AKey), FEntries[Index].Value) <> 0 then
Exit;
Inc(Index);
end;
Result := True;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntfPtrSortedMap.MoveArray(FromIndex, ToIndex, Count: Integer);
begin
if Count > 0 then
begin
Move(FEntries[FromIndex], FEntries[ToIndex], Count * SizeOf(FEntries[0]));
{ Keep reference counting working }
if FromIndex < ToIndex then
begin
if (ToIndex - FromIndex) < Count then
FillChar(FEntries[FromIndex], (ToIndex - FromIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end
else
if FromIndex > ToIndex then
begin
if (FromIndex - ToIndex) < Count then
FillChar(FEntries[ToIndex + Count], (FromIndex - ToIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end;
end;
end;
procedure TJclIntfPtrSortedMap.PutAll(const AMap: IJclIntfPtrMap);
var
It: IJclIntfIterator;
Key: IInterface;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if AMap = nil then
Exit;
It := AMap.KeySet.First;
while It.HasNext do
begin
Key := It.Next;
PutValue(Key, AMap.GetValue(Key));
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntfPtrSortedMap.PutValue(const Key: IInterface; Value: Pointer);
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FAllowDefaultElements or ((KeysCompare(Key, nil) <> 0) and (ValuesCompare(Value, nil) <> 0)) then
begin
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
FreeValue(FEntries[Index].Value);
FEntries[Index].Value := Value;
end
else
begin
if FSize = FCapacity then
AutoGrow;
if FSize < FCapacity then
begin
Inc(Index);
if (Index < FSize) and (KeysCompare(FEntries[Index].Key, Key) <> 0) then
MoveArray(Index, Index + 1, FSize - Index);
FEntries[Index].Key := Key;
FEntries[Index].Value := Value;
Inc(FSize);
end;
end;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfPtrSortedMap.Remove(const Key: IInterface): Pointer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Result := Extract(Key);
Result := FreeValue(Result);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntfPtrSortedMap.SetCapacity(Value: Integer);
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FSize <= Value then
begin
SetLength(FEntries, Value);
inherited SetCapacity(Value);
end
else
raise EJclOperationNotSupportedError.Create;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfPtrSortedMap.Size: Integer;
begin
Result := FSize;
end;
function TJclIntfPtrSortedMap.SubMap(const FromKey, ToKey: IInterface): IJclIntfPtrSortedMap;
var
FromIndex, ToIndex: Integer;
NewMap: TJclIntfPtrSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclIntfPtrSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
ToIndex := BinarySearch(ToKey);
if (FromIndex >= 0) and (FromIndex <= ToIndex) then
begin
NewMap.SetCapacity(ToIndex - FromIndex + 1);
NewMap.FSize := ToIndex - FromIndex + 1;
while ToIndex >= FromIndex do
begin
NewMap.FEntries[ToIndex - FromIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfPtrSortedMap.TailMap(const FromKey: IInterface): IJclIntfPtrSortedMap;
var
FromIndex, Index: Integer;
NewMap: TJclIntfPtrSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclIntfPtrSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
if (FromIndex >= 0) and (FromIndex < FSize) then
begin
NewMap.SetCapacity(FSize - FromIndex);
NewMap.FSize := FSize - FromIndex;
Index := FromIndex;
while Index < FSize do
begin
NewMap.FEntries[Index - FromIndex] := FEntries[Index];
Inc(Index);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfPtrSortedMap.Values: IJclPtrCollection;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclPtrArrayList.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Value);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfPtrSortedMap.CreateEmptyContainer: TJclAbstractContainerBase;
begin
Result := TJclIntfPtrSortedMap.Create(FSize);
AssignPropertiesTo(Result);
end;
function TJclIntfPtrSortedMap.FreeKey(var Key: IInterface): IInterface;
begin
Result := Key;
Key := nil;
end;
function TJclIntfPtrSortedMap.FreeValue(var Value: Pointer): Pointer;
begin
Result := Value;
Value := nil;
end;
function TJclIntfPtrSortedMap.KeysCompare(const A, B: IInterface): Integer;
begin
Result := IntfSimpleCompare(A, B);
end;
function TJclIntfPtrSortedMap.ValuesCompare(A, B: Pointer): Integer;
begin
Result := ItemsCompare(A, B);
end;
//=== { TJclPtrPtrSortedMap } ==============================================
constructor TJclPtrPtrSortedMap.Create(ACapacity: Integer);
begin
inherited Create();
SetCapacity(ACapacity);
end;
destructor TJclPtrPtrSortedMap.Destroy;
begin
FReadOnly := False;
Clear;
inherited Destroy;
end;
procedure TJclPtrPtrSortedMap.AssignDataTo(Dest: TJclAbstractContainerBase);
var
MyDest: TJclPtrPtrSortedMap;
begin
inherited AssignDataTo(Dest);
if Dest is TJclPtrPtrSortedMap then
begin
MyDest := TJclPtrPtrSortedMap(Dest);
MyDest.SetCapacity(FSize);
MyDest.FEntries := FEntries;
MyDest.FSize := FSize;
end;
end;
function TJclPtrPtrSortedMap.BinarySearch(Key: Pointer): Integer;
var
HiPos, LoPos, CompPos: Integer;
Comp: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
LoPos := 0;
HiPos := FSize - 1;
CompPos := (HiPos + LoPos) div 2;
while HiPos >= LoPos do
begin
Comp := KeysCompare(FEntries[CompPos].Key, Key);
if Comp < 0 then
LoPos := CompPos + 1
else
if Comp > 0 then
HiPos := CompPos - 1
else
begin
HiPos := CompPos;
LoPos := CompPos + 1;
end;
CompPos := (HiPos + LoPos) div 2;
end;
Result := HiPos;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclPtrPtrSortedMap.Clear;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
for Index := 0 to FSize - 1 do
begin
FreeKey(FEntries[Index].Key);
FreeValue(FEntries[Index].Value);
end;
FSize := 0;
AutoPack;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclPtrPtrSortedMap.ContainsKey(Key: Pointer): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclPtrPtrSortedMap.ContainsValue(Value: Pointer): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := True;
Break;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclPtrPtrSortedMap.FirstKey: Pointer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := nil;
if FSize > 0 then
Result := FEntries[0].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclPtrPtrSortedMap.Extract(Key: Pointer): Pointer;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
Result := FEntries[Index].Value;
FEntries[Index].Value := nil;
FreeKey(FEntries[Index].Key);
if Index < (FSize - 1) then
MoveArray(Index + 1, Index, FSize - Index - 1);
Dec(FSize);
AutoPack;
end
else
Result := nil;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclPtrPtrSortedMap.GetValue(Key: Pointer): Pointer;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := nil;
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
Result := FEntries[Index].Value
else if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclPtrPtrSortedMap.HeadMap(ToKey: Pointer): IJclPtrPtrSortedMap;
var
ToIndex: Integer;
NewMap: TJclPtrPtrSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclPtrPtrSortedMap;
ToIndex := BinarySearch(ToKey);
if ToIndex >= 0 then
begin
NewMap.SetCapacity(ToIndex + 1);
NewMap.FSize := ToIndex + 1;
while ToIndex >= 0 do
begin
NewMap.FEntries[ToIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclPtrPtrSortedMap.IsEmpty: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := FSize = 0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclPtrPtrSortedMap.KeyOfValue(Value: Pointer): Pointer;
var
Index: Integer;
Found: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Found := False;
Result := nil;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := FEntries[Index].Key;
Found := True;
Break;
end;
if (not Found) and (not FReturnDefaultElements) then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclPtrPtrSortedMap.KeySet: IJclPtrSet;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclPtrArraySet.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Key);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclPtrPtrSortedMap.LastKey: Pointer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := nil;
if FSize > 0 then
Result := FEntries[FSize - 1].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclPtrPtrSortedMap.MapEquals(const AMap: IJclPtrPtrMap): Boolean;
var
It: IJclPtrIterator;
Index: Integer;
AKey: Pointer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
if AMap = nil then
Exit;
if FSize <> AMap.Size then
Exit;
It := AMap.KeySet.First;
Index := 0;
while It.HasNext do
begin
if Index >= FSize then
Exit;
AKey := It.Next;
if ValuesCompare(AMap.GetValue(AKey), FEntries[Index].Value) <> 0 then
Exit;
Inc(Index);
end;
Result := True;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclPtrPtrSortedMap.MoveArray(FromIndex, ToIndex, Count: Integer);
begin
if Count > 0 then
begin
Move(FEntries[FromIndex], FEntries[ToIndex], Count * SizeOf(FEntries[0]));
{ Keep reference counting working }
if FromIndex < ToIndex then
begin
if (ToIndex - FromIndex) < Count then
FillChar(FEntries[FromIndex], (ToIndex - FromIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end
else
if FromIndex > ToIndex then
begin
if (FromIndex - ToIndex) < Count then
FillChar(FEntries[ToIndex + Count], (FromIndex - ToIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end;
end;
end;
procedure TJclPtrPtrSortedMap.PutAll(const AMap: IJclPtrPtrMap);
var
It: IJclPtrIterator;
Key: Pointer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if AMap = nil then
Exit;
It := AMap.KeySet.First;
while It.HasNext do
begin
Key := It.Next;
PutValue(Key, AMap.GetValue(Key));
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclPtrPtrSortedMap.PutValue(Key: Pointer; Value: Pointer);
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FAllowDefaultElements or ((KeysCompare(Key, nil) <> 0) and (ValuesCompare(Value, nil) <> 0)) then
begin
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
FreeValue(FEntries[Index].Value);
FEntries[Index].Value := Value;
end
else
begin
if FSize = FCapacity then
AutoGrow;
if FSize < FCapacity then
begin
Inc(Index);
if (Index < FSize) and (KeysCompare(FEntries[Index].Key, Key) <> 0) then
MoveArray(Index, Index + 1, FSize - Index);
FEntries[Index].Key := Key;
FEntries[Index].Value := Value;
Inc(FSize);
end;
end;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclPtrPtrSortedMap.Remove(Key: Pointer): Pointer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Result := Extract(Key);
Result := FreeValue(Result);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclPtrPtrSortedMap.SetCapacity(Value: Integer);
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FSize <= Value then
begin
SetLength(FEntries, Value);
inherited SetCapacity(Value);
end
else
raise EJclOperationNotSupportedError.Create;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclPtrPtrSortedMap.Size: Integer;
begin
Result := FSize;
end;
function TJclPtrPtrSortedMap.SubMap(FromKey, ToKey: Pointer): IJclPtrPtrSortedMap;
var
FromIndex, ToIndex: Integer;
NewMap: TJclPtrPtrSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclPtrPtrSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
ToIndex := BinarySearch(ToKey);
if (FromIndex >= 0) and (FromIndex <= ToIndex) then
begin
NewMap.SetCapacity(ToIndex - FromIndex + 1);
NewMap.FSize := ToIndex - FromIndex + 1;
while ToIndex >= FromIndex do
begin
NewMap.FEntries[ToIndex - FromIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclPtrPtrSortedMap.TailMap(FromKey: Pointer): IJclPtrPtrSortedMap;
var
FromIndex, Index: Integer;
NewMap: TJclPtrPtrSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclPtrPtrSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
if (FromIndex >= 0) and (FromIndex < FSize) then
begin
NewMap.SetCapacity(FSize - FromIndex);
NewMap.FSize := FSize - FromIndex;
Index := FromIndex;
while Index < FSize do
begin
NewMap.FEntries[Index - FromIndex] := FEntries[Index];
Inc(Index);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclPtrPtrSortedMap.Values: IJclPtrCollection;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclPtrArrayList.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Value);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclPtrPtrSortedMap.CreateEmptyContainer: TJclAbstractContainerBase;
begin
Result := TJclPtrPtrSortedMap.Create(FSize);
AssignPropertiesTo(Result);
end;
function TJclPtrPtrSortedMap.FreeKey(var Key: Pointer): Pointer;
begin
Result := Key;
Key := nil;
end;
function TJclPtrPtrSortedMap.FreeValue(var Value: Pointer): Pointer;
begin
Result := Value;
Value := nil;
end;
function TJclPtrPtrSortedMap.KeysCompare(A, B: Pointer): Integer;
begin
Result := ItemsCompare(A, B);
end;
function TJclPtrPtrSortedMap.ValuesCompare(A, B: Pointer): Integer;
begin
Result := ItemsCompare(A, B);
end;
//=== { TJclIntfSortedMap } ==============================================
constructor TJclIntfSortedMap.Create(ACapacity: Integer; AOwnsValues: Boolean);
begin
inherited Create();
FOwnsValues := AOwnsValues;
SetCapacity(ACapacity);
end;
destructor TJclIntfSortedMap.Destroy;
begin
FReadOnly := False;
Clear;
inherited Destroy;
end;
procedure TJclIntfSortedMap.AssignDataTo(Dest: TJclAbstractContainerBase);
var
MyDest: TJclIntfSortedMap;
begin
inherited AssignDataTo(Dest);
if Dest is TJclIntfSortedMap then
begin
MyDest := TJclIntfSortedMap(Dest);
MyDest.SetCapacity(FSize);
MyDest.FEntries := FEntries;
MyDest.FSize := FSize;
end;
end;
function TJclIntfSortedMap.BinarySearch(const Key: IInterface): Integer;
var
HiPos, LoPos, CompPos: Integer;
Comp: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
LoPos := 0;
HiPos := FSize - 1;
CompPos := (HiPos + LoPos) div 2;
while HiPos >= LoPos do
begin
Comp := KeysCompare(FEntries[CompPos].Key, Key);
if Comp < 0 then
LoPos := CompPos + 1
else
if Comp > 0 then
HiPos := CompPos - 1
else
begin
HiPos := CompPos;
LoPos := CompPos + 1;
end;
CompPos := (HiPos + LoPos) div 2;
end;
Result := HiPos;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntfSortedMap.Clear;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
for Index := 0 to FSize - 1 do
begin
FreeKey(FEntries[Index].Key);
FreeValue(FEntries[Index].Value);
end;
FSize := 0;
AutoPack;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfSortedMap.ContainsKey(const Key: IInterface): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfSortedMap.ContainsValue(Value: TObject): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := True;
Break;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfSortedMap.FirstKey: IInterface;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := nil;
if FSize > 0 then
Result := FEntries[0].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfSortedMap.Extract(const Key: IInterface): TObject;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
Result := FEntries[Index].Value;
FEntries[Index].Value := nil;
FreeKey(FEntries[Index].Key);
if Index < (FSize - 1) then
MoveArray(Index + 1, Index, FSize - Index - 1);
Dec(FSize);
AutoPack;
end
else
Result := nil;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfSortedMap.GetValue(const Key: IInterface): TObject;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := nil;
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
Result := FEntries[Index].Value
else if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfSortedMap.HeadMap(const ToKey: IInterface): IJclIntfSortedMap;
var
ToIndex: Integer;
NewMap: TJclIntfSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclIntfSortedMap;
ToIndex := BinarySearch(ToKey);
if ToIndex >= 0 then
begin
NewMap.SetCapacity(ToIndex + 1);
NewMap.FSize := ToIndex + 1;
while ToIndex >= 0 do
begin
NewMap.FEntries[ToIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfSortedMap.IsEmpty: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := FSize = 0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfSortedMap.KeyOfValue(Value: TObject): IInterface;
var
Index: Integer;
Found: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Found := False;
Result := nil;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := FEntries[Index].Key;
Found := True;
Break;
end;
if (not Found) and (not FReturnDefaultElements) then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfSortedMap.KeySet: IJclIntfSet;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclIntfArraySet.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Key);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfSortedMap.LastKey: IInterface;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := nil;
if FSize > 0 then
Result := FEntries[FSize - 1].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfSortedMap.MapEquals(const AMap: IJclIntfMap): Boolean;
var
It: IJclIntfIterator;
Index: Integer;
AKey: IInterface;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
if AMap = nil then
Exit;
if FSize <> AMap.Size then
Exit;
It := AMap.KeySet.First;
Index := 0;
while It.HasNext do
begin
if Index >= FSize then
Exit;
AKey := It.Next;
if ValuesCompare(AMap.GetValue(AKey), FEntries[Index].Value) <> 0 then
Exit;
Inc(Index);
end;
Result := True;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntfSortedMap.MoveArray(FromIndex, ToIndex, Count: Integer);
begin
if Count > 0 then
begin
Move(FEntries[FromIndex], FEntries[ToIndex], Count * SizeOf(FEntries[0]));
{ Keep reference counting working }
if FromIndex < ToIndex then
begin
if (ToIndex - FromIndex) < Count then
FillChar(FEntries[FromIndex], (ToIndex - FromIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end
else
if FromIndex > ToIndex then
begin
if (FromIndex - ToIndex) < Count then
FillChar(FEntries[ToIndex + Count], (FromIndex - ToIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end;
end;
end;
procedure TJclIntfSortedMap.PutAll(const AMap: IJclIntfMap);
var
It: IJclIntfIterator;
Key: IInterface;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if AMap = nil then
Exit;
It := AMap.KeySet.First;
while It.HasNext do
begin
Key := It.Next;
PutValue(Key, AMap.GetValue(Key));
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntfSortedMap.PutValue(const Key: IInterface; Value: TObject);
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FAllowDefaultElements or ((KeysCompare(Key, nil) <> 0) and (ValuesCompare(Value, nil) <> 0)) then
begin
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
FreeValue(FEntries[Index].Value);
FEntries[Index].Value := Value;
end
else
begin
if FSize = FCapacity then
AutoGrow;
if FSize < FCapacity then
begin
Inc(Index);
if (Index < FSize) and (KeysCompare(FEntries[Index].Key, Key) <> 0) then
MoveArray(Index, Index + 1, FSize - Index);
FEntries[Index].Key := Key;
FEntries[Index].Value := Value;
Inc(FSize);
end;
end;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfSortedMap.Remove(const Key: IInterface): TObject;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Result := Extract(Key);
Result := FreeValue(Result);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntfSortedMap.SetCapacity(Value: Integer);
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FSize <= Value then
begin
SetLength(FEntries, Value);
inherited SetCapacity(Value);
end
else
raise EJclOperationNotSupportedError.Create;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfSortedMap.Size: Integer;
begin
Result := FSize;
end;
function TJclIntfSortedMap.SubMap(const FromKey, ToKey: IInterface): IJclIntfSortedMap;
var
FromIndex, ToIndex: Integer;
NewMap: TJclIntfSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclIntfSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
ToIndex := BinarySearch(ToKey);
if (FromIndex >= 0) and (FromIndex <= ToIndex) then
begin
NewMap.SetCapacity(ToIndex - FromIndex + 1);
NewMap.FSize := ToIndex - FromIndex + 1;
while ToIndex >= FromIndex do
begin
NewMap.FEntries[ToIndex - FromIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfSortedMap.TailMap(const FromKey: IInterface): IJclIntfSortedMap;
var
FromIndex, Index: Integer;
NewMap: TJclIntfSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclIntfSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
if (FromIndex >= 0) and (FromIndex < FSize) then
begin
NewMap.SetCapacity(FSize - FromIndex);
NewMap.FSize := FSize - FromIndex;
Index := FromIndex;
while Index < FSize do
begin
NewMap.FEntries[Index - FromIndex] := FEntries[Index];
Inc(Index);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfSortedMap.Values: IJclCollection;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclArrayList.Create(FSize, False);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Value);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntfSortedMap.CreateEmptyContainer: TJclAbstractContainerBase;
begin
Result := TJclIntfSortedMap.Create(FSize, False);
AssignPropertiesTo(Result);
end;
function TJclIntfSortedMap.FreeKey(var Key: IInterface): IInterface;
begin
Result := Key;
Key := nil;
end;
function TJclIntfSortedMap.FreeValue(var Value: TObject): TObject;
begin
if FOwnsValues then
begin
Result := nil;
FreeAndNil(Value);
end
else
begin
Result := Value;
Value := nil;
end;
end;
function TJclIntfSortedMap.GetOwnsValues: Boolean;
begin
Result := FOwnsValues;
end;
function TJclIntfSortedMap.KeysCompare(const A, B: IInterface): Integer;
begin
Result := ItemsCompare(A, B);
end;
function TJclIntfSortedMap.ValuesCompare(A, B: TObject): Integer;
begin
Result := SimpleCompare(A, B);
end;
//=== { TJclAnsiStrSortedMap } ==============================================
constructor TJclAnsiStrSortedMap.Create(ACapacity: Integer; AOwnsValues: Boolean);
begin
inherited Create();
FOwnsValues := AOwnsValues;
SetCapacity(ACapacity);
end;
destructor TJclAnsiStrSortedMap.Destroy;
begin
FReadOnly := False;
Clear;
inherited Destroy;
end;
procedure TJclAnsiStrSortedMap.AssignDataTo(Dest: TJclAbstractContainerBase);
var
MyDest: TJclAnsiStrSortedMap;
begin
inherited AssignDataTo(Dest);
if Dest is TJclAnsiStrSortedMap then
begin
MyDest := TJclAnsiStrSortedMap(Dest);
MyDest.SetCapacity(FSize);
MyDest.FEntries := FEntries;
MyDest.FSize := FSize;
end;
end;
function TJclAnsiStrSortedMap.BinarySearch(const Key: AnsiString): Integer;
var
HiPos, LoPos, CompPos: Integer;
Comp: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
LoPos := 0;
HiPos := FSize - 1;
CompPos := (HiPos + LoPos) div 2;
while HiPos >= LoPos do
begin
Comp := KeysCompare(FEntries[CompPos].Key, Key);
if Comp < 0 then
LoPos := CompPos + 1
else
if Comp > 0 then
HiPos := CompPos - 1
else
begin
HiPos := CompPos;
LoPos := CompPos + 1;
end;
CompPos := (HiPos + LoPos) div 2;
end;
Result := HiPos;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclAnsiStrSortedMap.Clear;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
for Index := 0 to FSize - 1 do
begin
FreeKey(FEntries[Index].Key);
FreeValue(FEntries[Index].Value);
end;
FSize := 0;
AutoPack;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclAnsiStrSortedMap.ContainsKey(const Key: AnsiString): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclAnsiStrSortedMap.ContainsValue(Value: TObject): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := True;
Break;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclAnsiStrSortedMap.FirstKey: AnsiString;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := '';
if FSize > 0 then
Result := FEntries[0].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclAnsiStrSortedMap.Extract(const Key: AnsiString): TObject;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
Result := FEntries[Index].Value;
FEntries[Index].Value := nil;
FreeKey(FEntries[Index].Key);
if Index < (FSize - 1) then
MoveArray(Index + 1, Index, FSize - Index - 1);
Dec(FSize);
AutoPack;
end
else
Result := nil;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclAnsiStrSortedMap.GetValue(const Key: AnsiString): TObject;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := nil;
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
Result := FEntries[Index].Value
else if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclAnsiStrSortedMap.HeadMap(const ToKey: AnsiString): IJclAnsiStrSortedMap;
var
ToIndex: Integer;
NewMap: TJclAnsiStrSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclAnsiStrSortedMap;
ToIndex := BinarySearch(ToKey);
if ToIndex >= 0 then
begin
NewMap.SetCapacity(ToIndex + 1);
NewMap.FSize := ToIndex + 1;
while ToIndex >= 0 do
begin
NewMap.FEntries[ToIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclAnsiStrSortedMap.IsEmpty: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := FSize = 0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclAnsiStrSortedMap.KeyOfValue(Value: TObject): AnsiString;
var
Index: Integer;
Found: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Found := False;
Result := '';
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := FEntries[Index].Key;
Found := True;
Break;
end;
if (not Found) and (not FReturnDefaultElements) then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclAnsiStrSortedMap.KeySet: IJclAnsiStrSet;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclAnsiStrArraySet.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Key);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclAnsiStrSortedMap.LastKey: AnsiString;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := '';
if FSize > 0 then
Result := FEntries[FSize - 1].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclAnsiStrSortedMap.MapEquals(const AMap: IJclAnsiStrMap): Boolean;
var
It: IJclAnsiStrIterator;
Index: Integer;
AKey: AnsiString;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
if AMap = nil then
Exit;
if FSize <> AMap.Size then
Exit;
It := AMap.KeySet.First;
Index := 0;
while It.HasNext do
begin
if Index >= FSize then
Exit;
AKey := It.Next;
if ValuesCompare(AMap.GetValue(AKey), FEntries[Index].Value) <> 0 then
Exit;
Inc(Index);
end;
Result := True;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclAnsiStrSortedMap.MoveArray(FromIndex, ToIndex, Count: Integer);
begin
if Count > 0 then
begin
Move(FEntries[FromIndex], FEntries[ToIndex], Count * SizeOf(FEntries[0]));
{ Keep reference counting working }
if FromIndex < ToIndex then
begin
if (ToIndex - FromIndex) < Count then
FillChar(FEntries[FromIndex], (ToIndex - FromIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end
else
if FromIndex > ToIndex then
begin
if (FromIndex - ToIndex) < Count then
FillChar(FEntries[ToIndex + Count], (FromIndex - ToIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end;
end;
end;
procedure TJclAnsiStrSortedMap.PutAll(const AMap: IJclAnsiStrMap);
var
It: IJclAnsiStrIterator;
Key: AnsiString;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if AMap = nil then
Exit;
It := AMap.KeySet.First;
while It.HasNext do
begin
Key := It.Next;
PutValue(Key, AMap.GetValue(Key));
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclAnsiStrSortedMap.PutValue(const Key: AnsiString; Value: TObject);
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FAllowDefaultElements or ((KeysCompare(Key, '') <> 0) and (ValuesCompare(Value, nil) <> 0)) then
begin
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
FreeValue(FEntries[Index].Value);
FEntries[Index].Value := Value;
end
else
begin
if FSize = FCapacity then
AutoGrow;
if FSize < FCapacity then
begin
Inc(Index);
if (Index < FSize) and (KeysCompare(FEntries[Index].Key, Key) <> 0) then
MoveArray(Index, Index + 1, FSize - Index);
FEntries[Index].Key := Key;
FEntries[Index].Value := Value;
Inc(FSize);
end;
end;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclAnsiStrSortedMap.Remove(const Key: AnsiString): TObject;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Result := Extract(Key);
Result := FreeValue(Result);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclAnsiStrSortedMap.SetCapacity(Value: Integer);
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FSize <= Value then
begin
SetLength(FEntries, Value);
inherited SetCapacity(Value);
end
else
raise EJclOperationNotSupportedError.Create;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclAnsiStrSortedMap.Size: Integer;
begin
Result := FSize;
end;
function TJclAnsiStrSortedMap.SubMap(const FromKey, ToKey: AnsiString): IJclAnsiStrSortedMap;
var
FromIndex, ToIndex: Integer;
NewMap: TJclAnsiStrSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclAnsiStrSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
ToIndex := BinarySearch(ToKey);
if (FromIndex >= 0) and (FromIndex <= ToIndex) then
begin
NewMap.SetCapacity(ToIndex - FromIndex + 1);
NewMap.FSize := ToIndex - FromIndex + 1;
while ToIndex >= FromIndex do
begin
NewMap.FEntries[ToIndex - FromIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclAnsiStrSortedMap.TailMap(const FromKey: AnsiString): IJclAnsiStrSortedMap;
var
FromIndex, Index: Integer;
NewMap: TJclAnsiStrSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclAnsiStrSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
if (FromIndex >= 0) and (FromIndex < FSize) then
begin
NewMap.SetCapacity(FSize - FromIndex);
NewMap.FSize := FSize - FromIndex;
Index := FromIndex;
while Index < FSize do
begin
NewMap.FEntries[Index - FromIndex] := FEntries[Index];
Inc(Index);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclAnsiStrSortedMap.Values: IJclCollection;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclArrayList.Create(FSize, False);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Value);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclAnsiStrSortedMap.CreateEmptyContainer: TJclAbstractContainerBase;
begin
Result := TJclAnsiStrSortedMap.Create(FSize, False);
AssignPropertiesTo(Result);
end;
function TJclAnsiStrSortedMap.FreeKey(var Key: AnsiString): AnsiString;
begin
Result := Key;
Key := '';
end;
function TJclAnsiStrSortedMap.FreeValue(var Value: TObject): TObject;
begin
if FOwnsValues then
begin
Result := nil;
FreeAndNil(Value);
end
else
begin
Result := Value;
Value := nil;
end;
end;
function TJclAnsiStrSortedMap.GetOwnsValues: Boolean;
begin
Result := FOwnsValues;
end;
function TJclAnsiStrSortedMap.KeysCompare(const A, B: AnsiString): Integer;
begin
Result := ItemsCompare(A, B);
end;
function TJclAnsiStrSortedMap.ValuesCompare(A, B: TObject): Integer;
begin
Result := SimpleCompare(A, B);
end;
//=== { TJclWideStrSortedMap } ==============================================
constructor TJclWideStrSortedMap.Create(ACapacity: Integer; AOwnsValues: Boolean);
begin
inherited Create();
FOwnsValues := AOwnsValues;
SetCapacity(ACapacity);
end;
destructor TJclWideStrSortedMap.Destroy;
begin
FReadOnly := False;
Clear;
inherited Destroy;
end;
procedure TJclWideStrSortedMap.AssignDataTo(Dest: TJclAbstractContainerBase);
var
MyDest: TJclWideStrSortedMap;
begin
inherited AssignDataTo(Dest);
if Dest is TJclWideStrSortedMap then
begin
MyDest := TJclWideStrSortedMap(Dest);
MyDest.SetCapacity(FSize);
MyDest.FEntries := FEntries;
MyDest.FSize := FSize;
end;
end;
function TJclWideStrSortedMap.BinarySearch(const Key: WideString): Integer;
var
HiPos, LoPos, CompPos: Integer;
Comp: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
LoPos := 0;
HiPos := FSize - 1;
CompPos := (HiPos + LoPos) div 2;
while HiPos >= LoPos do
begin
Comp := KeysCompare(FEntries[CompPos].Key, Key);
if Comp < 0 then
LoPos := CompPos + 1
else
if Comp > 0 then
HiPos := CompPos - 1
else
begin
HiPos := CompPos;
LoPos := CompPos + 1;
end;
CompPos := (HiPos + LoPos) div 2;
end;
Result := HiPos;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclWideStrSortedMap.Clear;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
for Index := 0 to FSize - 1 do
begin
FreeKey(FEntries[Index].Key);
FreeValue(FEntries[Index].Value);
end;
FSize := 0;
AutoPack;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclWideStrSortedMap.ContainsKey(const Key: WideString): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclWideStrSortedMap.ContainsValue(Value: TObject): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := True;
Break;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclWideStrSortedMap.FirstKey: WideString;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := '';
if FSize > 0 then
Result := FEntries[0].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclWideStrSortedMap.Extract(const Key: WideString): TObject;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
Result := FEntries[Index].Value;
FEntries[Index].Value := nil;
FreeKey(FEntries[Index].Key);
if Index < (FSize - 1) then
MoveArray(Index + 1, Index, FSize - Index - 1);
Dec(FSize);
AutoPack;
end
else
Result := nil;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclWideStrSortedMap.GetValue(const Key: WideString): TObject;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := nil;
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
Result := FEntries[Index].Value
else if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclWideStrSortedMap.HeadMap(const ToKey: WideString): IJclWideStrSortedMap;
var
ToIndex: Integer;
NewMap: TJclWideStrSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclWideStrSortedMap;
ToIndex := BinarySearch(ToKey);
if ToIndex >= 0 then
begin
NewMap.SetCapacity(ToIndex + 1);
NewMap.FSize := ToIndex + 1;
while ToIndex >= 0 do
begin
NewMap.FEntries[ToIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclWideStrSortedMap.IsEmpty: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := FSize = 0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclWideStrSortedMap.KeyOfValue(Value: TObject): WideString;
var
Index: Integer;
Found: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Found := False;
Result := '';
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := FEntries[Index].Key;
Found := True;
Break;
end;
if (not Found) and (not FReturnDefaultElements) then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclWideStrSortedMap.KeySet: IJclWideStrSet;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclWideStrArraySet.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Key);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclWideStrSortedMap.LastKey: WideString;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := '';
if FSize > 0 then
Result := FEntries[FSize - 1].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclWideStrSortedMap.MapEquals(const AMap: IJclWideStrMap): Boolean;
var
It: IJclWideStrIterator;
Index: Integer;
AKey: WideString;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
if AMap = nil then
Exit;
if FSize <> AMap.Size then
Exit;
It := AMap.KeySet.First;
Index := 0;
while It.HasNext do
begin
if Index >= FSize then
Exit;
AKey := It.Next;
if ValuesCompare(AMap.GetValue(AKey), FEntries[Index].Value) <> 0 then
Exit;
Inc(Index);
end;
Result := True;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclWideStrSortedMap.MoveArray(FromIndex, ToIndex, Count: Integer);
begin
if Count > 0 then
begin
Move(FEntries[FromIndex], FEntries[ToIndex], Count * SizeOf(FEntries[0]));
{ Keep reference counting working }
if FromIndex < ToIndex then
begin
if (ToIndex - FromIndex) < Count then
FillChar(FEntries[FromIndex], (ToIndex - FromIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end
else
if FromIndex > ToIndex then
begin
if (FromIndex - ToIndex) < Count then
FillChar(FEntries[ToIndex + Count], (FromIndex - ToIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end;
end;
end;
procedure TJclWideStrSortedMap.PutAll(const AMap: IJclWideStrMap);
var
It: IJclWideStrIterator;
Key: WideString;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if AMap = nil then
Exit;
It := AMap.KeySet.First;
while It.HasNext do
begin
Key := It.Next;
PutValue(Key, AMap.GetValue(Key));
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclWideStrSortedMap.PutValue(const Key: WideString; Value: TObject);
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FAllowDefaultElements or ((KeysCompare(Key, '') <> 0) and (ValuesCompare(Value, nil) <> 0)) then
begin
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
FreeValue(FEntries[Index].Value);
FEntries[Index].Value := Value;
end
else
begin
if FSize = FCapacity then
AutoGrow;
if FSize < FCapacity then
begin
Inc(Index);
if (Index < FSize) and (KeysCompare(FEntries[Index].Key, Key) <> 0) then
MoveArray(Index, Index + 1, FSize - Index);
FEntries[Index].Key := Key;
FEntries[Index].Value := Value;
Inc(FSize);
end;
end;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclWideStrSortedMap.Remove(const Key: WideString): TObject;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Result := Extract(Key);
Result := FreeValue(Result);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclWideStrSortedMap.SetCapacity(Value: Integer);
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FSize <= Value then
begin
SetLength(FEntries, Value);
inherited SetCapacity(Value);
end
else
raise EJclOperationNotSupportedError.Create;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclWideStrSortedMap.Size: Integer;
begin
Result := FSize;
end;
function TJclWideStrSortedMap.SubMap(const FromKey, ToKey: WideString): IJclWideStrSortedMap;
var
FromIndex, ToIndex: Integer;
NewMap: TJclWideStrSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclWideStrSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
ToIndex := BinarySearch(ToKey);
if (FromIndex >= 0) and (FromIndex <= ToIndex) then
begin
NewMap.SetCapacity(ToIndex - FromIndex + 1);
NewMap.FSize := ToIndex - FromIndex + 1;
while ToIndex >= FromIndex do
begin
NewMap.FEntries[ToIndex - FromIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclWideStrSortedMap.TailMap(const FromKey: WideString): IJclWideStrSortedMap;
var
FromIndex, Index: Integer;
NewMap: TJclWideStrSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclWideStrSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
if (FromIndex >= 0) and (FromIndex < FSize) then
begin
NewMap.SetCapacity(FSize - FromIndex);
NewMap.FSize := FSize - FromIndex;
Index := FromIndex;
while Index < FSize do
begin
NewMap.FEntries[Index - FromIndex] := FEntries[Index];
Inc(Index);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclWideStrSortedMap.Values: IJclCollection;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclArrayList.Create(FSize, False);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Value);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclWideStrSortedMap.CreateEmptyContainer: TJclAbstractContainerBase;
begin
Result := TJclWideStrSortedMap.Create(FSize, False);
AssignPropertiesTo(Result);
end;
function TJclWideStrSortedMap.FreeKey(var Key: WideString): WideString;
begin
Result := Key;
Key := '';
end;
function TJclWideStrSortedMap.FreeValue(var Value: TObject): TObject;
begin
if FOwnsValues then
begin
Result := nil;
FreeAndNil(Value);
end
else
begin
Result := Value;
Value := nil;
end;
end;
function TJclWideStrSortedMap.GetOwnsValues: Boolean;
begin
Result := FOwnsValues;
end;
function TJclWideStrSortedMap.KeysCompare(const A, B: WideString): Integer;
begin
Result := ItemsCompare(A, B);
end;
function TJclWideStrSortedMap.ValuesCompare(A, B: TObject): Integer;
begin
Result := SimpleCompare(A, B);
end;
{$IFDEF SUPPORTS_UNICODE_STRING}
//=== { TJclUnicodeStrSortedMap } ==============================================
constructor TJclUnicodeStrSortedMap.Create(ACapacity: Integer; AOwnsValues: Boolean);
begin
inherited Create();
FOwnsValues := AOwnsValues;
SetCapacity(ACapacity);
end;
destructor TJclUnicodeStrSortedMap.Destroy;
begin
FReadOnly := False;
Clear;
inherited Destroy;
end;
procedure TJclUnicodeStrSortedMap.AssignDataTo(Dest: TJclAbstractContainerBase);
var
MyDest: TJclUnicodeStrSortedMap;
begin
inherited AssignDataTo(Dest);
if Dest is TJclUnicodeStrSortedMap then
begin
MyDest := TJclUnicodeStrSortedMap(Dest);
MyDest.SetCapacity(FSize);
MyDest.FEntries := FEntries;
MyDest.FSize := FSize;
end;
end;
function TJclUnicodeStrSortedMap.BinarySearch(const Key: UnicodeString): Integer;
var
HiPos, LoPos, CompPos: Integer;
Comp: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
LoPos := 0;
HiPos := FSize - 1;
CompPos := (HiPos + LoPos) div 2;
while HiPos >= LoPos do
begin
Comp := KeysCompare(FEntries[CompPos].Key, Key);
if Comp < 0 then
LoPos := CompPos + 1
else
if Comp > 0 then
HiPos := CompPos - 1
else
begin
HiPos := CompPos;
LoPos := CompPos + 1;
end;
CompPos := (HiPos + LoPos) div 2;
end;
Result := HiPos;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclUnicodeStrSortedMap.Clear;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
for Index := 0 to FSize - 1 do
begin
FreeKey(FEntries[Index].Key);
FreeValue(FEntries[Index].Value);
end;
FSize := 0;
AutoPack;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclUnicodeStrSortedMap.ContainsKey(const Key: UnicodeString): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclUnicodeStrSortedMap.ContainsValue(Value: TObject): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := True;
Break;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclUnicodeStrSortedMap.FirstKey: UnicodeString;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := '';
if FSize > 0 then
Result := FEntries[0].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclUnicodeStrSortedMap.Extract(const Key: UnicodeString): TObject;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
Result := FEntries[Index].Value;
FEntries[Index].Value := nil;
FreeKey(FEntries[Index].Key);
if Index < (FSize - 1) then
MoveArray(Index + 1, Index, FSize - Index - 1);
Dec(FSize);
AutoPack;
end
else
Result := nil;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclUnicodeStrSortedMap.GetValue(const Key: UnicodeString): TObject;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := nil;
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
Result := FEntries[Index].Value
else if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclUnicodeStrSortedMap.HeadMap(const ToKey: UnicodeString): IJclUnicodeStrSortedMap;
var
ToIndex: Integer;
NewMap: TJclUnicodeStrSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclUnicodeStrSortedMap;
ToIndex := BinarySearch(ToKey);
if ToIndex >= 0 then
begin
NewMap.SetCapacity(ToIndex + 1);
NewMap.FSize := ToIndex + 1;
while ToIndex >= 0 do
begin
NewMap.FEntries[ToIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclUnicodeStrSortedMap.IsEmpty: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := FSize = 0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclUnicodeStrSortedMap.KeyOfValue(Value: TObject): UnicodeString;
var
Index: Integer;
Found: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Found := False;
Result := '';
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := FEntries[Index].Key;
Found := True;
Break;
end;
if (not Found) and (not FReturnDefaultElements) then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclUnicodeStrSortedMap.KeySet: IJclUnicodeStrSet;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclUnicodeStrArraySet.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Key);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclUnicodeStrSortedMap.LastKey: UnicodeString;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := '';
if FSize > 0 then
Result := FEntries[FSize - 1].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclUnicodeStrSortedMap.MapEquals(const AMap: IJclUnicodeStrMap): Boolean;
var
It: IJclUnicodeStrIterator;
Index: Integer;
AKey: UnicodeString;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
if AMap = nil then
Exit;
if FSize <> AMap.Size then
Exit;
It := AMap.KeySet.First;
Index := 0;
while It.HasNext do
begin
if Index >= FSize then
Exit;
AKey := It.Next;
if ValuesCompare(AMap.GetValue(AKey), FEntries[Index].Value) <> 0 then
Exit;
Inc(Index);
end;
Result := True;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclUnicodeStrSortedMap.MoveArray(FromIndex, ToIndex, Count: Integer);
begin
if Count > 0 then
begin
Move(FEntries[FromIndex], FEntries[ToIndex], Count * SizeOf(FEntries[0]));
{ Keep reference counting working }
if FromIndex < ToIndex then
begin
if (ToIndex - FromIndex) < Count then
FillChar(FEntries[FromIndex], (ToIndex - FromIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end
else
if FromIndex > ToIndex then
begin
if (FromIndex - ToIndex) < Count then
FillChar(FEntries[ToIndex + Count], (FromIndex - ToIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end;
end;
end;
procedure TJclUnicodeStrSortedMap.PutAll(const AMap: IJclUnicodeStrMap);
var
It: IJclUnicodeStrIterator;
Key: UnicodeString;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if AMap = nil then
Exit;
It := AMap.KeySet.First;
while It.HasNext do
begin
Key := It.Next;
PutValue(Key, AMap.GetValue(Key));
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclUnicodeStrSortedMap.PutValue(const Key: UnicodeString; Value: TObject);
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FAllowDefaultElements or ((KeysCompare(Key, '') <> 0) and (ValuesCompare(Value, nil) <> 0)) then
begin
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
FreeValue(FEntries[Index].Value);
FEntries[Index].Value := Value;
end
else
begin
if FSize = FCapacity then
AutoGrow;
if FSize < FCapacity then
begin
Inc(Index);
if (Index < FSize) and (KeysCompare(FEntries[Index].Key, Key) <> 0) then
MoveArray(Index, Index + 1, FSize - Index);
FEntries[Index].Key := Key;
FEntries[Index].Value := Value;
Inc(FSize);
end;
end;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclUnicodeStrSortedMap.Remove(const Key: UnicodeString): TObject;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Result := Extract(Key);
Result := FreeValue(Result);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclUnicodeStrSortedMap.SetCapacity(Value: Integer);
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FSize <= Value then
begin
SetLength(FEntries, Value);
inherited SetCapacity(Value);
end
else
raise EJclOperationNotSupportedError.Create;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclUnicodeStrSortedMap.Size: Integer;
begin
Result := FSize;
end;
function TJclUnicodeStrSortedMap.SubMap(const FromKey, ToKey: UnicodeString): IJclUnicodeStrSortedMap;
var
FromIndex, ToIndex: Integer;
NewMap: TJclUnicodeStrSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclUnicodeStrSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
ToIndex := BinarySearch(ToKey);
if (FromIndex >= 0) and (FromIndex <= ToIndex) then
begin
NewMap.SetCapacity(ToIndex - FromIndex + 1);
NewMap.FSize := ToIndex - FromIndex + 1;
while ToIndex >= FromIndex do
begin
NewMap.FEntries[ToIndex - FromIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclUnicodeStrSortedMap.TailMap(const FromKey: UnicodeString): IJclUnicodeStrSortedMap;
var
FromIndex, Index: Integer;
NewMap: TJclUnicodeStrSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclUnicodeStrSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
if (FromIndex >= 0) and (FromIndex < FSize) then
begin
NewMap.SetCapacity(FSize - FromIndex);
NewMap.FSize := FSize - FromIndex;
Index := FromIndex;
while Index < FSize do
begin
NewMap.FEntries[Index - FromIndex] := FEntries[Index];
Inc(Index);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclUnicodeStrSortedMap.Values: IJclCollection;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclArrayList.Create(FSize, False);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Value);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclUnicodeStrSortedMap.CreateEmptyContainer: TJclAbstractContainerBase;
begin
Result := TJclUnicodeStrSortedMap.Create(FSize, False);
AssignPropertiesTo(Result);
end;
function TJclUnicodeStrSortedMap.FreeKey(var Key: UnicodeString): UnicodeString;
begin
Result := Key;
Key := '';
end;
function TJclUnicodeStrSortedMap.FreeValue(var Value: TObject): TObject;
begin
if FOwnsValues then
begin
Result := nil;
FreeAndNil(Value);
end
else
begin
Result := Value;
Value := nil;
end;
end;
function TJclUnicodeStrSortedMap.GetOwnsValues: Boolean;
begin
Result := FOwnsValues;
end;
function TJclUnicodeStrSortedMap.KeysCompare(const A, B: UnicodeString): Integer;
begin
Result := ItemsCompare(A, B);
end;
function TJclUnicodeStrSortedMap.ValuesCompare(A, B: TObject): Integer;
begin
Result := SimpleCompare(A, B);
end;
{$ENDIF SUPPORTS_UNICODE_STRING}
//=== { TJclSingleSortedMap } ==============================================
constructor TJclSingleSortedMap.Create(ACapacity: Integer; AOwnsValues: Boolean);
begin
inherited Create();
FOwnsValues := AOwnsValues;
SetCapacity(ACapacity);
end;
destructor TJclSingleSortedMap.Destroy;
begin
FReadOnly := False;
Clear;
inherited Destroy;
end;
procedure TJclSingleSortedMap.AssignDataTo(Dest: TJclAbstractContainerBase);
var
MyDest: TJclSingleSortedMap;
begin
inherited AssignDataTo(Dest);
if Dest is TJclSingleSortedMap then
begin
MyDest := TJclSingleSortedMap(Dest);
MyDest.SetCapacity(FSize);
MyDest.FEntries := FEntries;
MyDest.FSize := FSize;
end;
end;
function TJclSingleSortedMap.BinarySearch(const Key: Single): Integer;
var
HiPos, LoPos, CompPos: Integer;
Comp: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
LoPos := 0;
HiPos := FSize - 1;
CompPos := (HiPos + LoPos) div 2;
while HiPos >= LoPos do
begin
Comp := KeysCompare(FEntries[CompPos].Key, Key);
if Comp < 0 then
LoPos := CompPos + 1
else
if Comp > 0 then
HiPos := CompPos - 1
else
begin
HiPos := CompPos;
LoPos := CompPos + 1;
end;
CompPos := (HiPos + LoPos) div 2;
end;
Result := HiPos;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclSingleSortedMap.Clear;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
for Index := 0 to FSize - 1 do
begin
FreeKey(FEntries[Index].Key);
FreeValue(FEntries[Index].Value);
end;
FSize := 0;
AutoPack;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclSingleSortedMap.ContainsKey(const Key: Single): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSingleSortedMap.ContainsValue(Value: TObject): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := True;
Break;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSingleSortedMap.FirstKey: Single;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := 0.0;
if FSize > 0 then
Result := FEntries[0].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSingleSortedMap.Extract(const Key: Single): TObject;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
Result := FEntries[Index].Value;
FEntries[Index].Value := nil;
FreeKey(FEntries[Index].Key);
if Index < (FSize - 1) then
MoveArray(Index + 1, Index, FSize - Index - 1);
Dec(FSize);
AutoPack;
end
else
Result := nil;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclSingleSortedMap.GetValue(const Key: Single): TObject;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := nil;
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
Result := FEntries[Index].Value
else if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSingleSortedMap.HeadMap(const ToKey: Single): IJclSingleSortedMap;
var
ToIndex: Integer;
NewMap: TJclSingleSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclSingleSortedMap;
ToIndex := BinarySearch(ToKey);
if ToIndex >= 0 then
begin
NewMap.SetCapacity(ToIndex + 1);
NewMap.FSize := ToIndex + 1;
while ToIndex >= 0 do
begin
NewMap.FEntries[ToIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSingleSortedMap.IsEmpty: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := FSize = 0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSingleSortedMap.KeyOfValue(Value: TObject): Single;
var
Index: Integer;
Found: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Found := False;
Result := 0.0;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := FEntries[Index].Key;
Found := True;
Break;
end;
if (not Found) and (not FReturnDefaultElements) then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSingleSortedMap.KeySet: IJclSingleSet;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclSingleArraySet.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Key);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSingleSortedMap.LastKey: Single;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := 0.0;
if FSize > 0 then
Result := FEntries[FSize - 1].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSingleSortedMap.MapEquals(const AMap: IJclSingleMap): Boolean;
var
It: IJclSingleIterator;
Index: Integer;
AKey: Single;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
if AMap = nil then
Exit;
if FSize <> AMap.Size then
Exit;
It := AMap.KeySet.First;
Index := 0;
while It.HasNext do
begin
if Index >= FSize then
Exit;
AKey := It.Next;
if ValuesCompare(AMap.GetValue(AKey), FEntries[Index].Value) <> 0 then
Exit;
Inc(Index);
end;
Result := True;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclSingleSortedMap.MoveArray(FromIndex, ToIndex, Count: Integer);
begin
if Count > 0 then
begin
Move(FEntries[FromIndex], FEntries[ToIndex], Count * SizeOf(FEntries[0]));
{ Keep reference counting working }
if FromIndex < ToIndex then
begin
if (ToIndex - FromIndex) < Count then
FillChar(FEntries[FromIndex], (ToIndex - FromIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end
else
if FromIndex > ToIndex then
begin
if (FromIndex - ToIndex) < Count then
FillChar(FEntries[ToIndex + Count], (FromIndex - ToIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end;
end;
end;
procedure TJclSingleSortedMap.PutAll(const AMap: IJclSingleMap);
var
It: IJclSingleIterator;
Key: Single;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if AMap = nil then
Exit;
It := AMap.KeySet.First;
while It.HasNext do
begin
Key := It.Next;
PutValue(Key, AMap.GetValue(Key));
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclSingleSortedMap.PutValue(const Key: Single; Value: TObject);
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FAllowDefaultElements or ((KeysCompare(Key, 0.0) <> 0) and (ValuesCompare(Value, nil) <> 0)) then
begin
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
FreeValue(FEntries[Index].Value);
FEntries[Index].Value := Value;
end
else
begin
if FSize = FCapacity then
AutoGrow;
if FSize < FCapacity then
begin
Inc(Index);
if (Index < FSize) and (KeysCompare(FEntries[Index].Key, Key) <> 0) then
MoveArray(Index, Index + 1, FSize - Index);
FEntries[Index].Key := Key;
FEntries[Index].Value := Value;
Inc(FSize);
end;
end;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclSingleSortedMap.Remove(const Key: Single): TObject;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Result := Extract(Key);
Result := FreeValue(Result);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclSingleSortedMap.SetCapacity(Value: Integer);
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FSize <= Value then
begin
SetLength(FEntries, Value);
inherited SetCapacity(Value);
end
else
raise EJclOperationNotSupportedError.Create;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclSingleSortedMap.Size: Integer;
begin
Result := FSize;
end;
function TJclSingleSortedMap.SubMap(const FromKey, ToKey: Single): IJclSingleSortedMap;
var
FromIndex, ToIndex: Integer;
NewMap: TJclSingleSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclSingleSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
ToIndex := BinarySearch(ToKey);
if (FromIndex >= 0) and (FromIndex <= ToIndex) then
begin
NewMap.SetCapacity(ToIndex - FromIndex + 1);
NewMap.FSize := ToIndex - FromIndex + 1;
while ToIndex >= FromIndex do
begin
NewMap.FEntries[ToIndex - FromIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSingleSortedMap.TailMap(const FromKey: Single): IJclSingleSortedMap;
var
FromIndex, Index: Integer;
NewMap: TJclSingleSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclSingleSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
if (FromIndex >= 0) and (FromIndex < FSize) then
begin
NewMap.SetCapacity(FSize - FromIndex);
NewMap.FSize := FSize - FromIndex;
Index := FromIndex;
while Index < FSize do
begin
NewMap.FEntries[Index - FromIndex] := FEntries[Index];
Inc(Index);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSingleSortedMap.Values: IJclCollection;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclArrayList.Create(FSize, False);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Value);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSingleSortedMap.CreateEmptyContainer: TJclAbstractContainerBase;
begin
Result := TJclSingleSortedMap.Create(FSize, False);
AssignPropertiesTo(Result);
end;
function TJclSingleSortedMap.FreeKey(var Key: Single): Single;
begin
Result := Key;
Key := 0.0;
end;
function TJclSingleSortedMap.FreeValue(var Value: TObject): TObject;
begin
if FOwnsValues then
begin
Result := nil;
FreeAndNil(Value);
end
else
begin
Result := Value;
Value := nil;
end;
end;
function TJclSingleSortedMap.GetOwnsValues: Boolean;
begin
Result := FOwnsValues;
end;
function TJclSingleSortedMap.KeysCompare(const A, B: Single): Integer;
begin
Result := ItemsCompare(A, B);
end;
function TJclSingleSortedMap.ValuesCompare(A, B: TObject): Integer;
begin
Result := SimpleCompare(A, B);
end;
//=== { TJclDoubleSortedMap } ==============================================
constructor TJclDoubleSortedMap.Create(ACapacity: Integer; AOwnsValues: Boolean);
begin
inherited Create();
FOwnsValues := AOwnsValues;
SetCapacity(ACapacity);
end;
destructor TJclDoubleSortedMap.Destroy;
begin
FReadOnly := False;
Clear;
inherited Destroy;
end;
procedure TJclDoubleSortedMap.AssignDataTo(Dest: TJclAbstractContainerBase);
var
MyDest: TJclDoubleSortedMap;
begin
inherited AssignDataTo(Dest);
if Dest is TJclDoubleSortedMap then
begin
MyDest := TJclDoubleSortedMap(Dest);
MyDest.SetCapacity(FSize);
MyDest.FEntries := FEntries;
MyDest.FSize := FSize;
end;
end;
function TJclDoubleSortedMap.BinarySearch(const Key: Double): Integer;
var
HiPos, LoPos, CompPos: Integer;
Comp: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
LoPos := 0;
HiPos := FSize - 1;
CompPos := (HiPos + LoPos) div 2;
while HiPos >= LoPos do
begin
Comp := KeysCompare(FEntries[CompPos].Key, Key);
if Comp < 0 then
LoPos := CompPos + 1
else
if Comp > 0 then
HiPos := CompPos - 1
else
begin
HiPos := CompPos;
LoPos := CompPos + 1;
end;
CompPos := (HiPos + LoPos) div 2;
end;
Result := HiPos;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclDoubleSortedMap.Clear;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
for Index := 0 to FSize - 1 do
begin
FreeKey(FEntries[Index].Key);
FreeValue(FEntries[Index].Value);
end;
FSize := 0;
AutoPack;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclDoubleSortedMap.ContainsKey(const Key: Double): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclDoubleSortedMap.ContainsValue(Value: TObject): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := True;
Break;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclDoubleSortedMap.FirstKey: Double;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := 0.0;
if FSize > 0 then
Result := FEntries[0].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclDoubleSortedMap.Extract(const Key: Double): TObject;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
Result := FEntries[Index].Value;
FEntries[Index].Value := nil;
FreeKey(FEntries[Index].Key);
if Index < (FSize - 1) then
MoveArray(Index + 1, Index, FSize - Index - 1);
Dec(FSize);
AutoPack;
end
else
Result := nil;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclDoubleSortedMap.GetValue(const Key: Double): TObject;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := nil;
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
Result := FEntries[Index].Value
else if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclDoubleSortedMap.HeadMap(const ToKey: Double): IJclDoubleSortedMap;
var
ToIndex: Integer;
NewMap: TJclDoubleSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclDoubleSortedMap;
ToIndex := BinarySearch(ToKey);
if ToIndex >= 0 then
begin
NewMap.SetCapacity(ToIndex + 1);
NewMap.FSize := ToIndex + 1;
while ToIndex >= 0 do
begin
NewMap.FEntries[ToIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclDoubleSortedMap.IsEmpty: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := FSize = 0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclDoubleSortedMap.KeyOfValue(Value: TObject): Double;
var
Index: Integer;
Found: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Found := False;
Result := 0.0;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := FEntries[Index].Key;
Found := True;
Break;
end;
if (not Found) and (not FReturnDefaultElements) then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclDoubleSortedMap.KeySet: IJclDoubleSet;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclDoubleArraySet.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Key);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclDoubleSortedMap.LastKey: Double;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := 0.0;
if FSize > 0 then
Result := FEntries[FSize - 1].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclDoubleSortedMap.MapEquals(const AMap: IJclDoubleMap): Boolean;
var
It: IJclDoubleIterator;
Index: Integer;
AKey: Double;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
if AMap = nil then
Exit;
if FSize <> AMap.Size then
Exit;
It := AMap.KeySet.First;
Index := 0;
while It.HasNext do
begin
if Index >= FSize then
Exit;
AKey := It.Next;
if ValuesCompare(AMap.GetValue(AKey), FEntries[Index].Value) <> 0 then
Exit;
Inc(Index);
end;
Result := True;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclDoubleSortedMap.MoveArray(FromIndex, ToIndex, Count: Integer);
begin
if Count > 0 then
begin
Move(FEntries[FromIndex], FEntries[ToIndex], Count * SizeOf(FEntries[0]));
{ Keep reference counting working }
if FromIndex < ToIndex then
begin
if (ToIndex - FromIndex) < Count then
FillChar(FEntries[FromIndex], (ToIndex - FromIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end
else
if FromIndex > ToIndex then
begin
if (FromIndex - ToIndex) < Count then
FillChar(FEntries[ToIndex + Count], (FromIndex - ToIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end;
end;
end;
procedure TJclDoubleSortedMap.PutAll(const AMap: IJclDoubleMap);
var
It: IJclDoubleIterator;
Key: Double;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if AMap = nil then
Exit;
It := AMap.KeySet.First;
while It.HasNext do
begin
Key := It.Next;
PutValue(Key, AMap.GetValue(Key));
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclDoubleSortedMap.PutValue(const Key: Double; Value: TObject);
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FAllowDefaultElements or ((KeysCompare(Key, 0.0) <> 0) and (ValuesCompare(Value, nil) <> 0)) then
begin
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
FreeValue(FEntries[Index].Value);
FEntries[Index].Value := Value;
end
else
begin
if FSize = FCapacity then
AutoGrow;
if FSize < FCapacity then
begin
Inc(Index);
if (Index < FSize) and (KeysCompare(FEntries[Index].Key, Key) <> 0) then
MoveArray(Index, Index + 1, FSize - Index);
FEntries[Index].Key := Key;
FEntries[Index].Value := Value;
Inc(FSize);
end;
end;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclDoubleSortedMap.Remove(const Key: Double): TObject;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Result := Extract(Key);
Result := FreeValue(Result);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclDoubleSortedMap.SetCapacity(Value: Integer);
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FSize <= Value then
begin
SetLength(FEntries, Value);
inherited SetCapacity(Value);
end
else
raise EJclOperationNotSupportedError.Create;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclDoubleSortedMap.Size: Integer;
begin
Result := FSize;
end;
function TJclDoubleSortedMap.SubMap(const FromKey, ToKey: Double): IJclDoubleSortedMap;
var
FromIndex, ToIndex: Integer;
NewMap: TJclDoubleSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclDoubleSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
ToIndex := BinarySearch(ToKey);
if (FromIndex >= 0) and (FromIndex <= ToIndex) then
begin
NewMap.SetCapacity(ToIndex - FromIndex + 1);
NewMap.FSize := ToIndex - FromIndex + 1;
while ToIndex >= FromIndex do
begin
NewMap.FEntries[ToIndex - FromIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclDoubleSortedMap.TailMap(const FromKey: Double): IJclDoubleSortedMap;
var
FromIndex, Index: Integer;
NewMap: TJclDoubleSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclDoubleSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
if (FromIndex >= 0) and (FromIndex < FSize) then
begin
NewMap.SetCapacity(FSize - FromIndex);
NewMap.FSize := FSize - FromIndex;
Index := FromIndex;
while Index < FSize do
begin
NewMap.FEntries[Index - FromIndex] := FEntries[Index];
Inc(Index);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclDoubleSortedMap.Values: IJclCollection;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclArrayList.Create(FSize, False);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Value);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclDoubleSortedMap.CreateEmptyContainer: TJclAbstractContainerBase;
begin
Result := TJclDoubleSortedMap.Create(FSize, False);
AssignPropertiesTo(Result);
end;
function TJclDoubleSortedMap.FreeKey(var Key: Double): Double;
begin
Result := Key;
Key := 0.0;
end;
function TJclDoubleSortedMap.FreeValue(var Value: TObject): TObject;
begin
if FOwnsValues then
begin
Result := nil;
FreeAndNil(Value);
end
else
begin
Result := Value;
Value := nil;
end;
end;
function TJclDoubleSortedMap.GetOwnsValues: Boolean;
begin
Result := FOwnsValues;
end;
function TJclDoubleSortedMap.KeysCompare(const A, B: Double): Integer;
begin
Result := ItemsCompare(A, B);
end;
function TJclDoubleSortedMap.ValuesCompare(A, B: TObject): Integer;
begin
Result := SimpleCompare(A, B);
end;
//=== { TJclExtendedSortedMap } ==============================================
constructor TJclExtendedSortedMap.Create(ACapacity: Integer; AOwnsValues: Boolean);
begin
inherited Create();
FOwnsValues := AOwnsValues;
SetCapacity(ACapacity);
end;
destructor TJclExtendedSortedMap.Destroy;
begin
FReadOnly := False;
Clear;
inherited Destroy;
end;
procedure TJclExtendedSortedMap.AssignDataTo(Dest: TJclAbstractContainerBase);
var
MyDest: TJclExtendedSortedMap;
begin
inherited AssignDataTo(Dest);
if Dest is TJclExtendedSortedMap then
begin
MyDest := TJclExtendedSortedMap(Dest);
MyDest.SetCapacity(FSize);
MyDest.FEntries := FEntries;
MyDest.FSize := FSize;
end;
end;
function TJclExtendedSortedMap.BinarySearch(const Key: Extended): Integer;
var
HiPos, LoPos, CompPos: Integer;
Comp: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
LoPos := 0;
HiPos := FSize - 1;
CompPos := (HiPos + LoPos) div 2;
while HiPos >= LoPos do
begin
Comp := KeysCompare(FEntries[CompPos].Key, Key);
if Comp < 0 then
LoPos := CompPos + 1
else
if Comp > 0 then
HiPos := CompPos - 1
else
begin
HiPos := CompPos;
LoPos := CompPos + 1;
end;
CompPos := (HiPos + LoPos) div 2;
end;
Result := HiPos;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclExtendedSortedMap.Clear;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
for Index := 0 to FSize - 1 do
begin
FreeKey(FEntries[Index].Key);
FreeValue(FEntries[Index].Value);
end;
FSize := 0;
AutoPack;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclExtendedSortedMap.ContainsKey(const Key: Extended): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclExtendedSortedMap.ContainsValue(Value: TObject): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := True;
Break;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclExtendedSortedMap.FirstKey: Extended;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := 0.0;
if FSize > 0 then
Result := FEntries[0].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclExtendedSortedMap.Extract(const Key: Extended): TObject;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
Result := FEntries[Index].Value;
FEntries[Index].Value := nil;
FreeKey(FEntries[Index].Key);
if Index < (FSize - 1) then
MoveArray(Index + 1, Index, FSize - Index - 1);
Dec(FSize);
AutoPack;
end
else
Result := nil;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclExtendedSortedMap.GetValue(const Key: Extended): TObject;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := nil;
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
Result := FEntries[Index].Value
else if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclExtendedSortedMap.HeadMap(const ToKey: Extended): IJclExtendedSortedMap;
var
ToIndex: Integer;
NewMap: TJclExtendedSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclExtendedSortedMap;
ToIndex := BinarySearch(ToKey);
if ToIndex >= 0 then
begin
NewMap.SetCapacity(ToIndex + 1);
NewMap.FSize := ToIndex + 1;
while ToIndex >= 0 do
begin
NewMap.FEntries[ToIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclExtendedSortedMap.IsEmpty: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := FSize = 0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclExtendedSortedMap.KeyOfValue(Value: TObject): Extended;
var
Index: Integer;
Found: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Found := False;
Result := 0.0;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := FEntries[Index].Key;
Found := True;
Break;
end;
if (not Found) and (not FReturnDefaultElements) then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclExtendedSortedMap.KeySet: IJclExtendedSet;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclExtendedArraySet.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Key);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclExtendedSortedMap.LastKey: Extended;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := 0.0;
if FSize > 0 then
Result := FEntries[FSize - 1].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclExtendedSortedMap.MapEquals(const AMap: IJclExtendedMap): Boolean;
var
It: IJclExtendedIterator;
Index: Integer;
AKey: Extended;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
if AMap = nil then
Exit;
if FSize <> AMap.Size then
Exit;
It := AMap.KeySet.First;
Index := 0;
while It.HasNext do
begin
if Index >= FSize then
Exit;
AKey := It.Next;
if ValuesCompare(AMap.GetValue(AKey), FEntries[Index].Value) <> 0 then
Exit;
Inc(Index);
end;
Result := True;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclExtendedSortedMap.MoveArray(FromIndex, ToIndex, Count: Integer);
begin
if Count > 0 then
begin
Move(FEntries[FromIndex], FEntries[ToIndex], Count * SizeOf(FEntries[0]));
{ Keep reference counting working }
if FromIndex < ToIndex then
begin
if (ToIndex - FromIndex) < Count then
FillChar(FEntries[FromIndex], (ToIndex - FromIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end
else
if FromIndex > ToIndex then
begin
if (FromIndex - ToIndex) < Count then
FillChar(FEntries[ToIndex + Count], (FromIndex - ToIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end;
end;
end;
procedure TJclExtendedSortedMap.PutAll(const AMap: IJclExtendedMap);
var
It: IJclExtendedIterator;
Key: Extended;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if AMap = nil then
Exit;
It := AMap.KeySet.First;
while It.HasNext do
begin
Key := It.Next;
PutValue(Key, AMap.GetValue(Key));
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclExtendedSortedMap.PutValue(const Key: Extended; Value: TObject);
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FAllowDefaultElements or ((KeysCompare(Key, 0.0) <> 0) and (ValuesCompare(Value, nil) <> 0)) then
begin
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
FreeValue(FEntries[Index].Value);
FEntries[Index].Value := Value;
end
else
begin
if FSize = FCapacity then
AutoGrow;
if FSize < FCapacity then
begin
Inc(Index);
if (Index < FSize) and (KeysCompare(FEntries[Index].Key, Key) <> 0) then
MoveArray(Index, Index + 1, FSize - Index);
FEntries[Index].Key := Key;
FEntries[Index].Value := Value;
Inc(FSize);
end;
end;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclExtendedSortedMap.Remove(const Key: Extended): TObject;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Result := Extract(Key);
Result := FreeValue(Result);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclExtendedSortedMap.SetCapacity(Value: Integer);
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FSize <= Value then
begin
SetLength(FEntries, Value);
inherited SetCapacity(Value);
end
else
raise EJclOperationNotSupportedError.Create;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclExtendedSortedMap.Size: Integer;
begin
Result := FSize;
end;
function TJclExtendedSortedMap.SubMap(const FromKey, ToKey: Extended): IJclExtendedSortedMap;
var
FromIndex, ToIndex: Integer;
NewMap: TJclExtendedSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclExtendedSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
ToIndex := BinarySearch(ToKey);
if (FromIndex >= 0) and (FromIndex <= ToIndex) then
begin
NewMap.SetCapacity(ToIndex - FromIndex + 1);
NewMap.FSize := ToIndex - FromIndex + 1;
while ToIndex >= FromIndex do
begin
NewMap.FEntries[ToIndex - FromIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclExtendedSortedMap.TailMap(const FromKey: Extended): IJclExtendedSortedMap;
var
FromIndex, Index: Integer;
NewMap: TJclExtendedSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclExtendedSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
if (FromIndex >= 0) and (FromIndex < FSize) then
begin
NewMap.SetCapacity(FSize - FromIndex);
NewMap.FSize := FSize - FromIndex;
Index := FromIndex;
while Index < FSize do
begin
NewMap.FEntries[Index - FromIndex] := FEntries[Index];
Inc(Index);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclExtendedSortedMap.Values: IJclCollection;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclArrayList.Create(FSize, False);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Value);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclExtendedSortedMap.CreateEmptyContainer: TJclAbstractContainerBase;
begin
Result := TJclExtendedSortedMap.Create(FSize, False);
AssignPropertiesTo(Result);
end;
function TJclExtendedSortedMap.FreeKey(var Key: Extended): Extended;
begin
Result := Key;
Key := 0.0;
end;
function TJclExtendedSortedMap.FreeValue(var Value: TObject): TObject;
begin
if FOwnsValues then
begin
Result := nil;
FreeAndNil(Value);
end
else
begin
Result := Value;
Value := nil;
end;
end;
function TJclExtendedSortedMap.GetOwnsValues: Boolean;
begin
Result := FOwnsValues;
end;
function TJclExtendedSortedMap.KeysCompare(const A, B: Extended): Integer;
begin
Result := ItemsCompare(A, B);
end;
function TJclExtendedSortedMap.ValuesCompare(A, B: TObject): Integer;
begin
Result := SimpleCompare(A, B);
end;
//=== { TJclIntegerSortedMap } ==============================================
constructor TJclIntegerSortedMap.Create(ACapacity: Integer; AOwnsValues: Boolean);
begin
inherited Create();
FOwnsValues := AOwnsValues;
SetCapacity(ACapacity);
end;
destructor TJclIntegerSortedMap.Destroy;
begin
FReadOnly := False;
Clear;
inherited Destroy;
end;
procedure TJclIntegerSortedMap.AssignDataTo(Dest: TJclAbstractContainerBase);
var
MyDest: TJclIntegerSortedMap;
begin
inherited AssignDataTo(Dest);
if Dest is TJclIntegerSortedMap then
begin
MyDest := TJclIntegerSortedMap(Dest);
MyDest.SetCapacity(FSize);
MyDest.FEntries := FEntries;
MyDest.FSize := FSize;
end;
end;
function TJclIntegerSortedMap.BinarySearch(Key: Integer): Integer;
var
HiPos, LoPos, CompPos: Integer;
Comp: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
LoPos := 0;
HiPos := FSize - 1;
CompPos := (HiPos + LoPos) div 2;
while HiPos >= LoPos do
begin
Comp := KeysCompare(FEntries[CompPos].Key, Key);
if Comp < 0 then
LoPos := CompPos + 1
else
if Comp > 0 then
HiPos := CompPos - 1
else
begin
HiPos := CompPos;
LoPos := CompPos + 1;
end;
CompPos := (HiPos + LoPos) div 2;
end;
Result := HiPos;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntegerSortedMap.Clear;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
for Index := 0 to FSize - 1 do
begin
FreeKey(FEntries[Index].Key);
FreeValue(FEntries[Index].Value);
end;
FSize := 0;
AutoPack;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntegerSortedMap.ContainsKey(Key: Integer): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntegerSortedMap.ContainsValue(Value: TObject): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := True;
Break;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntegerSortedMap.FirstKey: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := 0;
if FSize > 0 then
Result := FEntries[0].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntegerSortedMap.Extract(Key: Integer): TObject;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
Result := FEntries[Index].Value;
FEntries[Index].Value := nil;
FreeKey(FEntries[Index].Key);
if Index < (FSize - 1) then
MoveArray(Index + 1, Index, FSize - Index - 1);
Dec(FSize);
AutoPack;
end
else
Result := nil;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntegerSortedMap.GetValue(Key: Integer): TObject;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := nil;
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
Result := FEntries[Index].Value
else if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntegerSortedMap.HeadMap(ToKey: Integer): IJclIntegerSortedMap;
var
ToIndex: Integer;
NewMap: TJclIntegerSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclIntegerSortedMap;
ToIndex := BinarySearch(ToKey);
if ToIndex >= 0 then
begin
NewMap.SetCapacity(ToIndex + 1);
NewMap.FSize := ToIndex + 1;
while ToIndex >= 0 do
begin
NewMap.FEntries[ToIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntegerSortedMap.IsEmpty: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := FSize = 0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntegerSortedMap.KeyOfValue(Value: TObject): Integer;
var
Index: Integer;
Found: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Found := False;
Result := 0;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := FEntries[Index].Key;
Found := True;
Break;
end;
if (not Found) and (not FReturnDefaultElements) then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntegerSortedMap.KeySet: IJclIntegerSet;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclIntegerArraySet.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Key);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntegerSortedMap.LastKey: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := 0;
if FSize > 0 then
Result := FEntries[FSize - 1].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntegerSortedMap.MapEquals(const AMap: IJclIntegerMap): Boolean;
var
It: IJclIntegerIterator;
Index: Integer;
AKey: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
if AMap = nil then
Exit;
if FSize <> AMap.Size then
Exit;
It := AMap.KeySet.First;
Index := 0;
while It.HasNext do
begin
if Index >= FSize then
Exit;
AKey := It.Next;
if ValuesCompare(AMap.GetValue(AKey), FEntries[Index].Value) <> 0 then
Exit;
Inc(Index);
end;
Result := True;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntegerSortedMap.MoveArray(FromIndex, ToIndex, Count: Integer);
begin
if Count > 0 then
begin
Move(FEntries[FromIndex], FEntries[ToIndex], Count * SizeOf(FEntries[0]));
{ Keep reference counting working }
if FromIndex < ToIndex then
begin
if (ToIndex - FromIndex) < Count then
FillChar(FEntries[FromIndex], (ToIndex - FromIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end
else
if FromIndex > ToIndex then
begin
if (FromIndex - ToIndex) < Count then
FillChar(FEntries[ToIndex + Count], (FromIndex - ToIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end;
end;
end;
procedure TJclIntegerSortedMap.PutAll(const AMap: IJclIntegerMap);
var
It: IJclIntegerIterator;
Key: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if AMap = nil then
Exit;
It := AMap.KeySet.First;
while It.HasNext do
begin
Key := It.Next;
PutValue(Key, AMap.GetValue(Key));
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntegerSortedMap.PutValue(Key: Integer; Value: TObject);
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FAllowDefaultElements or ((KeysCompare(Key, 0) <> 0) and (ValuesCompare(Value, nil) <> 0)) then
begin
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
FreeValue(FEntries[Index].Value);
FEntries[Index].Value := Value;
end
else
begin
if FSize = FCapacity then
AutoGrow;
if FSize < FCapacity then
begin
Inc(Index);
if (Index < FSize) and (KeysCompare(FEntries[Index].Key, Key) <> 0) then
MoveArray(Index, Index + 1, FSize - Index);
FEntries[Index].Key := Key;
FEntries[Index].Value := Value;
Inc(FSize);
end;
end;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntegerSortedMap.Remove(Key: Integer): TObject;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Result := Extract(Key);
Result := FreeValue(Result);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclIntegerSortedMap.SetCapacity(Value: Integer);
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FSize <= Value then
begin
SetLength(FEntries, Value);
inherited SetCapacity(Value);
end
else
raise EJclOperationNotSupportedError.Create;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntegerSortedMap.Size: Integer;
begin
Result := FSize;
end;
function TJclIntegerSortedMap.SubMap(FromKey, ToKey: Integer): IJclIntegerSortedMap;
var
FromIndex, ToIndex: Integer;
NewMap: TJclIntegerSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclIntegerSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
ToIndex := BinarySearch(ToKey);
if (FromIndex >= 0) and (FromIndex <= ToIndex) then
begin
NewMap.SetCapacity(ToIndex - FromIndex + 1);
NewMap.FSize := ToIndex - FromIndex + 1;
while ToIndex >= FromIndex do
begin
NewMap.FEntries[ToIndex - FromIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntegerSortedMap.TailMap(FromKey: Integer): IJclIntegerSortedMap;
var
FromIndex, Index: Integer;
NewMap: TJclIntegerSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclIntegerSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
if (FromIndex >= 0) and (FromIndex < FSize) then
begin
NewMap.SetCapacity(FSize - FromIndex);
NewMap.FSize := FSize - FromIndex;
Index := FromIndex;
while Index < FSize do
begin
NewMap.FEntries[Index - FromIndex] := FEntries[Index];
Inc(Index);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntegerSortedMap.Values: IJclCollection;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclArrayList.Create(FSize, False);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Value);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclIntegerSortedMap.CreateEmptyContainer: TJclAbstractContainerBase;
begin
Result := TJclIntegerSortedMap.Create(FSize, False);
AssignPropertiesTo(Result);
end;
function TJclIntegerSortedMap.FreeKey(var Key: Integer): Integer;
begin
Result := Key;
Key := 0;
end;
function TJclIntegerSortedMap.FreeValue(var Value: TObject): TObject;
begin
if FOwnsValues then
begin
Result := nil;
FreeAndNil(Value);
end
else
begin
Result := Value;
Value := nil;
end;
end;
function TJclIntegerSortedMap.GetOwnsValues: Boolean;
begin
Result := FOwnsValues;
end;
function TJclIntegerSortedMap.KeysCompare(A, B: Integer): Integer;
begin
Result := ItemsCompare(A, B);
end;
function TJclIntegerSortedMap.ValuesCompare(A, B: TObject): Integer;
begin
Result := SimpleCompare(A, B);
end;
//=== { TJclCardinalSortedMap } ==============================================
constructor TJclCardinalSortedMap.Create(ACapacity: Integer; AOwnsValues: Boolean);
begin
inherited Create();
FOwnsValues := AOwnsValues;
SetCapacity(ACapacity);
end;
destructor TJclCardinalSortedMap.Destroy;
begin
FReadOnly := False;
Clear;
inherited Destroy;
end;
procedure TJclCardinalSortedMap.AssignDataTo(Dest: TJclAbstractContainerBase);
var
MyDest: TJclCardinalSortedMap;
begin
inherited AssignDataTo(Dest);
if Dest is TJclCardinalSortedMap then
begin
MyDest := TJclCardinalSortedMap(Dest);
MyDest.SetCapacity(FSize);
MyDest.FEntries := FEntries;
MyDest.FSize := FSize;
end;
end;
function TJclCardinalSortedMap.BinarySearch(Key: Cardinal): Integer;
var
HiPos, LoPos, CompPos: Integer;
Comp: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
LoPos := 0;
HiPos := FSize - 1;
CompPos := (HiPos + LoPos) div 2;
while HiPos >= LoPos do
begin
Comp := KeysCompare(FEntries[CompPos].Key, Key);
if Comp < 0 then
LoPos := CompPos + 1
else
if Comp > 0 then
HiPos := CompPos - 1
else
begin
HiPos := CompPos;
LoPos := CompPos + 1;
end;
CompPos := (HiPos + LoPos) div 2;
end;
Result := HiPos;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclCardinalSortedMap.Clear;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
for Index := 0 to FSize - 1 do
begin
FreeKey(FEntries[Index].Key);
FreeValue(FEntries[Index].Value);
end;
FSize := 0;
AutoPack;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclCardinalSortedMap.ContainsKey(Key: Cardinal): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclCardinalSortedMap.ContainsValue(Value: TObject): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := True;
Break;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclCardinalSortedMap.FirstKey: Cardinal;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := 0;
if FSize > 0 then
Result := FEntries[0].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclCardinalSortedMap.Extract(Key: Cardinal): TObject;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
Result := FEntries[Index].Value;
FEntries[Index].Value := nil;
FreeKey(FEntries[Index].Key);
if Index < (FSize - 1) then
MoveArray(Index + 1, Index, FSize - Index - 1);
Dec(FSize);
AutoPack;
end
else
Result := nil;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclCardinalSortedMap.GetValue(Key: Cardinal): TObject;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := nil;
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
Result := FEntries[Index].Value
else if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclCardinalSortedMap.HeadMap(ToKey: Cardinal): IJclCardinalSortedMap;
var
ToIndex: Integer;
NewMap: TJclCardinalSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclCardinalSortedMap;
ToIndex := BinarySearch(ToKey);
if ToIndex >= 0 then
begin
NewMap.SetCapacity(ToIndex + 1);
NewMap.FSize := ToIndex + 1;
while ToIndex >= 0 do
begin
NewMap.FEntries[ToIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclCardinalSortedMap.IsEmpty: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := FSize = 0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclCardinalSortedMap.KeyOfValue(Value: TObject): Cardinal;
var
Index: Integer;
Found: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Found := False;
Result := 0;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := FEntries[Index].Key;
Found := True;
Break;
end;
if (not Found) and (not FReturnDefaultElements) then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclCardinalSortedMap.KeySet: IJclCardinalSet;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclCardinalArraySet.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Key);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclCardinalSortedMap.LastKey: Cardinal;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := 0;
if FSize > 0 then
Result := FEntries[FSize - 1].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclCardinalSortedMap.MapEquals(const AMap: IJclCardinalMap): Boolean;
var
It: IJclCardinalIterator;
Index: Integer;
AKey: Cardinal;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
if AMap = nil then
Exit;
if FSize <> AMap.Size then
Exit;
It := AMap.KeySet.First;
Index := 0;
while It.HasNext do
begin
if Index >= FSize then
Exit;
AKey := It.Next;
if ValuesCompare(AMap.GetValue(AKey), FEntries[Index].Value) <> 0 then
Exit;
Inc(Index);
end;
Result := True;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclCardinalSortedMap.MoveArray(FromIndex, ToIndex, Count: Integer);
begin
if Count > 0 then
begin
Move(FEntries[FromIndex], FEntries[ToIndex], Count * SizeOf(FEntries[0]));
{ Keep reference counting working }
if FromIndex < ToIndex then
begin
if (ToIndex - FromIndex) < Count then
FillChar(FEntries[FromIndex], (ToIndex - FromIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end
else
if FromIndex > ToIndex then
begin
if (FromIndex - ToIndex) < Count then
FillChar(FEntries[ToIndex + Count], (FromIndex - ToIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end;
end;
end;
procedure TJclCardinalSortedMap.PutAll(const AMap: IJclCardinalMap);
var
It: IJclCardinalIterator;
Key: Cardinal;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if AMap = nil then
Exit;
It := AMap.KeySet.First;
while It.HasNext do
begin
Key := It.Next;
PutValue(Key, AMap.GetValue(Key));
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclCardinalSortedMap.PutValue(Key: Cardinal; Value: TObject);
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FAllowDefaultElements or ((KeysCompare(Key, 0) <> 0) and (ValuesCompare(Value, nil) <> 0)) then
begin
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
FreeValue(FEntries[Index].Value);
FEntries[Index].Value := Value;
end
else
begin
if FSize = FCapacity then
AutoGrow;
if FSize < FCapacity then
begin
Inc(Index);
if (Index < FSize) and (KeysCompare(FEntries[Index].Key, Key) <> 0) then
MoveArray(Index, Index + 1, FSize - Index);
FEntries[Index].Key := Key;
FEntries[Index].Value := Value;
Inc(FSize);
end;
end;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclCardinalSortedMap.Remove(Key: Cardinal): TObject;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Result := Extract(Key);
Result := FreeValue(Result);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclCardinalSortedMap.SetCapacity(Value: Integer);
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FSize <= Value then
begin
SetLength(FEntries, Value);
inherited SetCapacity(Value);
end
else
raise EJclOperationNotSupportedError.Create;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclCardinalSortedMap.Size: Integer;
begin
Result := FSize;
end;
function TJclCardinalSortedMap.SubMap(FromKey, ToKey: Cardinal): IJclCardinalSortedMap;
var
FromIndex, ToIndex: Integer;
NewMap: TJclCardinalSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclCardinalSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
ToIndex := BinarySearch(ToKey);
if (FromIndex >= 0) and (FromIndex <= ToIndex) then
begin
NewMap.SetCapacity(ToIndex - FromIndex + 1);
NewMap.FSize := ToIndex - FromIndex + 1;
while ToIndex >= FromIndex do
begin
NewMap.FEntries[ToIndex - FromIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclCardinalSortedMap.TailMap(FromKey: Cardinal): IJclCardinalSortedMap;
var
FromIndex, Index: Integer;
NewMap: TJclCardinalSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclCardinalSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
if (FromIndex >= 0) and (FromIndex < FSize) then
begin
NewMap.SetCapacity(FSize - FromIndex);
NewMap.FSize := FSize - FromIndex;
Index := FromIndex;
while Index < FSize do
begin
NewMap.FEntries[Index - FromIndex] := FEntries[Index];
Inc(Index);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclCardinalSortedMap.Values: IJclCollection;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclArrayList.Create(FSize, False);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Value);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclCardinalSortedMap.CreateEmptyContainer: TJclAbstractContainerBase;
begin
Result := TJclCardinalSortedMap.Create(FSize, False);
AssignPropertiesTo(Result);
end;
function TJclCardinalSortedMap.FreeKey(var Key: Cardinal): Cardinal;
begin
Result := Key;
Key := 0;
end;
function TJclCardinalSortedMap.FreeValue(var Value: TObject): TObject;
begin
if FOwnsValues then
begin
Result := nil;
FreeAndNil(Value);
end
else
begin
Result := Value;
Value := nil;
end;
end;
function TJclCardinalSortedMap.GetOwnsValues: Boolean;
begin
Result := FOwnsValues;
end;
function TJclCardinalSortedMap.KeysCompare(A, B: Cardinal): Integer;
begin
Result := ItemsCompare(A, B);
end;
function TJclCardinalSortedMap.ValuesCompare(A, B: TObject): Integer;
begin
Result := SimpleCompare(A, B);
end;
//=== { TJclInt64SortedMap } ==============================================
constructor TJclInt64SortedMap.Create(ACapacity: Integer; AOwnsValues: Boolean);
begin
inherited Create();
FOwnsValues := AOwnsValues;
SetCapacity(ACapacity);
end;
destructor TJclInt64SortedMap.Destroy;
begin
FReadOnly := False;
Clear;
inherited Destroy;
end;
procedure TJclInt64SortedMap.AssignDataTo(Dest: TJclAbstractContainerBase);
var
MyDest: TJclInt64SortedMap;
begin
inherited AssignDataTo(Dest);
if Dest is TJclInt64SortedMap then
begin
MyDest := TJclInt64SortedMap(Dest);
MyDest.SetCapacity(FSize);
MyDest.FEntries := FEntries;
MyDest.FSize := FSize;
end;
end;
function TJclInt64SortedMap.BinarySearch(const Key: Int64): Integer;
var
HiPos, LoPos, CompPos: Integer;
Comp: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
LoPos := 0;
HiPos := FSize - 1;
CompPos := (HiPos + LoPos) div 2;
while HiPos >= LoPos do
begin
Comp := KeysCompare(FEntries[CompPos].Key, Key);
if Comp < 0 then
LoPos := CompPos + 1
else
if Comp > 0 then
HiPos := CompPos - 1
else
begin
HiPos := CompPos;
LoPos := CompPos + 1;
end;
CompPos := (HiPos + LoPos) div 2;
end;
Result := HiPos;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclInt64SortedMap.Clear;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
for Index := 0 to FSize - 1 do
begin
FreeKey(FEntries[Index].Key);
FreeValue(FEntries[Index].Value);
end;
FSize := 0;
AutoPack;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclInt64SortedMap.ContainsKey(const Key: Int64): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclInt64SortedMap.ContainsValue(Value: TObject): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := True;
Break;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclInt64SortedMap.FirstKey: Int64;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := 0;
if FSize > 0 then
Result := FEntries[0].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclInt64SortedMap.Extract(const Key: Int64): TObject;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
Result := FEntries[Index].Value;
FEntries[Index].Value := nil;
FreeKey(FEntries[Index].Key);
if Index < (FSize - 1) then
MoveArray(Index + 1, Index, FSize - Index - 1);
Dec(FSize);
AutoPack;
end
else
Result := nil;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclInt64SortedMap.GetValue(const Key: Int64): TObject;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := nil;
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
Result := FEntries[Index].Value
else if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclInt64SortedMap.HeadMap(const ToKey: Int64): IJclInt64SortedMap;
var
ToIndex: Integer;
NewMap: TJclInt64SortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclInt64SortedMap;
ToIndex := BinarySearch(ToKey);
if ToIndex >= 0 then
begin
NewMap.SetCapacity(ToIndex + 1);
NewMap.FSize := ToIndex + 1;
while ToIndex >= 0 do
begin
NewMap.FEntries[ToIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclInt64SortedMap.IsEmpty: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := FSize = 0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclInt64SortedMap.KeyOfValue(Value: TObject): Int64;
var
Index: Integer;
Found: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Found := False;
Result := 0;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := FEntries[Index].Key;
Found := True;
Break;
end;
if (not Found) and (not FReturnDefaultElements) then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclInt64SortedMap.KeySet: IJclInt64Set;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclInt64ArraySet.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Key);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclInt64SortedMap.LastKey: Int64;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := 0;
if FSize > 0 then
Result := FEntries[FSize - 1].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclInt64SortedMap.MapEquals(const AMap: IJclInt64Map): Boolean;
var
It: IJclInt64Iterator;
Index: Integer;
AKey: Int64;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
if AMap = nil then
Exit;
if FSize <> AMap.Size then
Exit;
It := AMap.KeySet.First;
Index := 0;
while It.HasNext do
begin
if Index >= FSize then
Exit;
AKey := It.Next;
if ValuesCompare(AMap.GetValue(AKey), FEntries[Index].Value) <> 0 then
Exit;
Inc(Index);
end;
Result := True;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclInt64SortedMap.MoveArray(FromIndex, ToIndex, Count: Integer);
begin
if Count > 0 then
begin
Move(FEntries[FromIndex], FEntries[ToIndex], Count * SizeOf(FEntries[0]));
{ Keep reference counting working }
if FromIndex < ToIndex then
begin
if (ToIndex - FromIndex) < Count then
FillChar(FEntries[FromIndex], (ToIndex - FromIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end
else
if FromIndex > ToIndex then
begin
if (FromIndex - ToIndex) < Count then
FillChar(FEntries[ToIndex + Count], (FromIndex - ToIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end;
end;
end;
procedure TJclInt64SortedMap.PutAll(const AMap: IJclInt64Map);
var
It: IJclInt64Iterator;
Key: Int64;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if AMap = nil then
Exit;
It := AMap.KeySet.First;
while It.HasNext do
begin
Key := It.Next;
PutValue(Key, AMap.GetValue(Key));
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclInt64SortedMap.PutValue(const Key: Int64; Value: TObject);
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FAllowDefaultElements or ((KeysCompare(Key, 0) <> 0) and (ValuesCompare(Value, nil) <> 0)) then
begin
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
FreeValue(FEntries[Index].Value);
FEntries[Index].Value := Value;
end
else
begin
if FSize = FCapacity then
AutoGrow;
if FSize < FCapacity then
begin
Inc(Index);
if (Index < FSize) and (KeysCompare(FEntries[Index].Key, Key) <> 0) then
MoveArray(Index, Index + 1, FSize - Index);
FEntries[Index].Key := Key;
FEntries[Index].Value := Value;
Inc(FSize);
end;
end;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclInt64SortedMap.Remove(const Key: Int64): TObject;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Result := Extract(Key);
Result := FreeValue(Result);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclInt64SortedMap.SetCapacity(Value: Integer);
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FSize <= Value then
begin
SetLength(FEntries, Value);
inherited SetCapacity(Value);
end
else
raise EJclOperationNotSupportedError.Create;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclInt64SortedMap.Size: Integer;
begin
Result := FSize;
end;
function TJclInt64SortedMap.SubMap(const FromKey, ToKey: Int64): IJclInt64SortedMap;
var
FromIndex, ToIndex: Integer;
NewMap: TJclInt64SortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclInt64SortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
ToIndex := BinarySearch(ToKey);
if (FromIndex >= 0) and (FromIndex <= ToIndex) then
begin
NewMap.SetCapacity(ToIndex - FromIndex + 1);
NewMap.FSize := ToIndex - FromIndex + 1;
while ToIndex >= FromIndex do
begin
NewMap.FEntries[ToIndex - FromIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclInt64SortedMap.TailMap(const FromKey: Int64): IJclInt64SortedMap;
var
FromIndex, Index: Integer;
NewMap: TJclInt64SortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclInt64SortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
if (FromIndex >= 0) and (FromIndex < FSize) then
begin
NewMap.SetCapacity(FSize - FromIndex);
NewMap.FSize := FSize - FromIndex;
Index := FromIndex;
while Index < FSize do
begin
NewMap.FEntries[Index - FromIndex] := FEntries[Index];
Inc(Index);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclInt64SortedMap.Values: IJclCollection;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclArrayList.Create(FSize, False);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Value);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclInt64SortedMap.CreateEmptyContainer: TJclAbstractContainerBase;
begin
Result := TJclInt64SortedMap.Create(FSize, False);
AssignPropertiesTo(Result);
end;
function TJclInt64SortedMap.FreeKey(var Key: Int64): Int64;
begin
Result := Key;
Key := 0;
end;
function TJclInt64SortedMap.FreeValue(var Value: TObject): TObject;
begin
if FOwnsValues then
begin
Result := nil;
FreeAndNil(Value);
end
else
begin
Result := Value;
Value := nil;
end;
end;
function TJclInt64SortedMap.GetOwnsValues: Boolean;
begin
Result := FOwnsValues;
end;
function TJclInt64SortedMap.KeysCompare(const A, B: Int64): Integer;
begin
Result := ItemsCompare(A, B);
end;
function TJclInt64SortedMap.ValuesCompare(A, B: TObject): Integer;
begin
Result := SimpleCompare(A, B);
end;
//=== { TJclPtrSortedMap } ==============================================
constructor TJclPtrSortedMap.Create(ACapacity: Integer; AOwnsValues: Boolean);
begin
inherited Create();
FOwnsValues := AOwnsValues;
SetCapacity(ACapacity);
end;
destructor TJclPtrSortedMap.Destroy;
begin
FReadOnly := False;
Clear;
inherited Destroy;
end;
procedure TJclPtrSortedMap.AssignDataTo(Dest: TJclAbstractContainerBase);
var
MyDest: TJclPtrSortedMap;
begin
inherited AssignDataTo(Dest);
if Dest is TJclPtrSortedMap then
begin
MyDest := TJclPtrSortedMap(Dest);
MyDest.SetCapacity(FSize);
MyDest.FEntries := FEntries;
MyDest.FSize := FSize;
end;
end;
function TJclPtrSortedMap.BinarySearch(Key: Pointer): Integer;
var
HiPos, LoPos, CompPos: Integer;
Comp: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
LoPos := 0;
HiPos := FSize - 1;
CompPos := (HiPos + LoPos) div 2;
while HiPos >= LoPos do
begin
Comp := KeysCompare(FEntries[CompPos].Key, Key);
if Comp < 0 then
LoPos := CompPos + 1
else
if Comp > 0 then
HiPos := CompPos - 1
else
begin
HiPos := CompPos;
LoPos := CompPos + 1;
end;
CompPos := (HiPos + LoPos) div 2;
end;
Result := HiPos;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclPtrSortedMap.Clear;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
for Index := 0 to FSize - 1 do
begin
FreeKey(FEntries[Index].Key);
FreeValue(FEntries[Index].Value);
end;
FSize := 0;
AutoPack;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclPtrSortedMap.ContainsKey(Key: Pointer): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclPtrSortedMap.ContainsValue(Value: TObject): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := True;
Break;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclPtrSortedMap.FirstKey: Pointer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := nil;
if FSize > 0 then
Result := FEntries[0].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclPtrSortedMap.Extract(Key: Pointer): TObject;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
Result := FEntries[Index].Value;
FEntries[Index].Value := nil;
FreeKey(FEntries[Index].Key);
if Index < (FSize - 1) then
MoveArray(Index + 1, Index, FSize - Index - 1);
Dec(FSize);
AutoPack;
end
else
Result := nil;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclPtrSortedMap.GetValue(Key: Pointer): TObject;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := nil;
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
Result := FEntries[Index].Value
else if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclPtrSortedMap.HeadMap(ToKey: Pointer): IJclPtrSortedMap;
var
ToIndex: Integer;
NewMap: TJclPtrSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclPtrSortedMap;
ToIndex := BinarySearch(ToKey);
if ToIndex >= 0 then
begin
NewMap.SetCapacity(ToIndex + 1);
NewMap.FSize := ToIndex + 1;
while ToIndex >= 0 do
begin
NewMap.FEntries[ToIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclPtrSortedMap.IsEmpty: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := FSize = 0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclPtrSortedMap.KeyOfValue(Value: TObject): Pointer;
var
Index: Integer;
Found: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Found := False;
Result := nil;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := FEntries[Index].Key;
Found := True;
Break;
end;
if (not Found) and (not FReturnDefaultElements) then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclPtrSortedMap.KeySet: IJclPtrSet;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclPtrArraySet.Create(FSize);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Key);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclPtrSortedMap.LastKey: Pointer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := nil;
if FSize > 0 then
Result := FEntries[FSize - 1].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclPtrSortedMap.MapEquals(const AMap: IJclPtrMap): Boolean;
var
It: IJclPtrIterator;
Index: Integer;
AKey: Pointer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
if AMap = nil then
Exit;
if FSize <> AMap.Size then
Exit;
It := AMap.KeySet.First;
Index := 0;
while It.HasNext do
begin
if Index >= FSize then
Exit;
AKey := It.Next;
if ValuesCompare(AMap.GetValue(AKey), FEntries[Index].Value) <> 0 then
Exit;
Inc(Index);
end;
Result := True;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclPtrSortedMap.MoveArray(FromIndex, ToIndex, Count: Integer);
begin
if Count > 0 then
begin
Move(FEntries[FromIndex], FEntries[ToIndex], Count * SizeOf(FEntries[0]));
{ Keep reference counting working }
if FromIndex < ToIndex then
begin
if (ToIndex - FromIndex) < Count then
FillChar(FEntries[FromIndex], (ToIndex - FromIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end
else
if FromIndex > ToIndex then
begin
if (FromIndex - ToIndex) < Count then
FillChar(FEntries[ToIndex + Count], (FromIndex - ToIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end;
end;
end;
procedure TJclPtrSortedMap.PutAll(const AMap: IJclPtrMap);
var
It: IJclPtrIterator;
Key: Pointer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if AMap = nil then
Exit;
It := AMap.KeySet.First;
while It.HasNext do
begin
Key := It.Next;
PutValue(Key, AMap.GetValue(Key));
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclPtrSortedMap.PutValue(Key: Pointer; Value: TObject);
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FAllowDefaultElements or ((KeysCompare(Key, nil) <> 0) and (ValuesCompare(Value, nil) <> 0)) then
begin
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
FreeValue(FEntries[Index].Value);
FEntries[Index].Value := Value;
end
else
begin
if FSize = FCapacity then
AutoGrow;
if FSize < FCapacity then
begin
Inc(Index);
if (Index < FSize) and (KeysCompare(FEntries[Index].Key, Key) <> 0) then
MoveArray(Index, Index + 1, FSize - Index);
FEntries[Index].Key := Key;
FEntries[Index].Value := Value;
Inc(FSize);
end;
end;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclPtrSortedMap.Remove(Key: Pointer): TObject;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Result := Extract(Key);
Result := FreeValue(Result);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclPtrSortedMap.SetCapacity(Value: Integer);
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FSize <= Value then
begin
SetLength(FEntries, Value);
inherited SetCapacity(Value);
end
else
raise EJclOperationNotSupportedError.Create;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclPtrSortedMap.Size: Integer;
begin
Result := FSize;
end;
function TJclPtrSortedMap.SubMap(FromKey, ToKey: Pointer): IJclPtrSortedMap;
var
FromIndex, ToIndex: Integer;
NewMap: TJclPtrSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclPtrSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
ToIndex := BinarySearch(ToKey);
if (FromIndex >= 0) and (FromIndex <= ToIndex) then
begin
NewMap.SetCapacity(ToIndex - FromIndex + 1);
NewMap.FSize := ToIndex - FromIndex + 1;
while ToIndex >= FromIndex do
begin
NewMap.FEntries[ToIndex - FromIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclPtrSortedMap.TailMap(FromKey: Pointer): IJclPtrSortedMap;
var
FromIndex, Index: Integer;
NewMap: TJclPtrSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclPtrSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
if (FromIndex >= 0) and (FromIndex < FSize) then
begin
NewMap.SetCapacity(FSize - FromIndex);
NewMap.FSize := FSize - FromIndex;
Index := FromIndex;
while Index < FSize do
begin
NewMap.FEntries[Index - FromIndex] := FEntries[Index];
Inc(Index);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclPtrSortedMap.Values: IJclCollection;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclArrayList.Create(FSize, False);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Value);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclPtrSortedMap.CreateEmptyContainer: TJclAbstractContainerBase;
begin
Result := TJclPtrSortedMap.Create(FSize, False);
AssignPropertiesTo(Result);
end;
function TJclPtrSortedMap.FreeKey(var Key: Pointer): Pointer;
begin
Result := Key;
Key := nil;
end;
function TJclPtrSortedMap.FreeValue(var Value: TObject): TObject;
begin
if FOwnsValues then
begin
Result := nil;
FreeAndNil(Value);
end
else
begin
Result := Value;
Value := nil;
end;
end;
function TJclPtrSortedMap.GetOwnsValues: Boolean;
begin
Result := FOwnsValues;
end;
function TJclPtrSortedMap.KeysCompare(A, B: Pointer): Integer;
begin
Result := ItemsCompare(A, B);
end;
function TJclPtrSortedMap.ValuesCompare(A, B: TObject): Integer;
begin
Result := SimpleCompare(A, B);
end;
//=== { TJclSortedMap } ==============================================
constructor TJclSortedMap.Create(ACapacity: Integer; AOwnsValues: Boolean; AOwnsKeys: Boolean);
begin
inherited Create();
FOwnsKeys := AOwnsKeys;
FOwnsValues := AOwnsValues;
SetCapacity(ACapacity);
end;
destructor TJclSortedMap.Destroy;
begin
FReadOnly := False;
Clear;
inherited Destroy;
end;
procedure TJclSortedMap.AssignDataTo(Dest: TJclAbstractContainerBase);
var
MyDest: TJclSortedMap;
begin
inherited AssignDataTo(Dest);
if Dest is TJclSortedMap then
begin
MyDest := TJclSortedMap(Dest);
MyDest.SetCapacity(FSize);
MyDest.FEntries := FEntries;
MyDest.FSize := FSize;
end;
end;
function TJclSortedMap.BinarySearch(Key: TObject): Integer;
var
HiPos, LoPos, CompPos: Integer;
Comp: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
LoPos := 0;
HiPos := FSize - 1;
CompPos := (HiPos + LoPos) div 2;
while HiPos >= LoPos do
begin
Comp := KeysCompare(FEntries[CompPos].Key, Key);
if Comp < 0 then
LoPos := CompPos + 1
else
if Comp > 0 then
HiPos := CompPos - 1
else
begin
HiPos := CompPos;
LoPos := CompPos + 1;
end;
CompPos := (HiPos + LoPos) div 2;
end;
Result := HiPos;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclSortedMap.Clear;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
for Index := 0 to FSize - 1 do
begin
FreeKey(FEntries[Index].Key);
FreeValue(FEntries[Index].Value);
end;
FSize := 0;
AutoPack;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclSortedMap.ContainsKey(Key: TObject): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSortedMap.ContainsValue(Value: TObject): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := True;
Break;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSortedMap.FirstKey: TObject;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := nil;
if FSize > 0 then
Result := FEntries[0].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSortedMap.Extract(Key: TObject): TObject;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
Result := FEntries[Index].Value;
FEntries[Index].Value := nil;
FreeKey(FEntries[Index].Key);
if Index < (FSize - 1) then
MoveArray(Index + 1, Index, FSize - Index - 1);
Dec(FSize);
AutoPack;
end
else
Result := nil;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclSortedMap.GetValue(Key: TObject): TObject;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := nil;
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
Result := FEntries[Index].Value
else if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSortedMap.HeadMap(ToKey: TObject): IJclSortedMap;
var
ToIndex: Integer;
NewMap: TJclSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclSortedMap;
ToIndex := BinarySearch(ToKey);
if ToIndex >= 0 then
begin
NewMap.SetCapacity(ToIndex + 1);
NewMap.FSize := ToIndex + 1;
while ToIndex >= 0 do
begin
NewMap.FEntries[ToIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSortedMap.IsEmpty: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := FSize = 0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSortedMap.KeyOfValue(Value: TObject): TObject;
var
Index: Integer;
Found: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Found := False;
Result := nil;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := FEntries[Index].Key;
Found := True;
Break;
end;
if (not Found) and (not FReturnDefaultElements) then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSortedMap.KeySet: IJclSet;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclArraySet.Create(FSize, False);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Key);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSortedMap.LastKey: TObject;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := nil;
if FSize > 0 then
Result := FEntries[FSize - 1].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSortedMap.MapEquals(const AMap: IJclMap): Boolean;
var
It: IJclIterator;
Index: Integer;
AKey: TObject;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
if AMap = nil then
Exit;
if FSize <> AMap.Size then
Exit;
It := AMap.KeySet.First;
Index := 0;
while It.HasNext do
begin
if Index >= FSize then
Exit;
AKey := It.Next;
if ValuesCompare(AMap.GetValue(AKey), FEntries[Index].Value) <> 0 then
Exit;
Inc(Index);
end;
Result := True;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclSortedMap.MoveArray(FromIndex, ToIndex, Count: Integer);
begin
if Count > 0 then
begin
Move(FEntries[FromIndex], FEntries[ToIndex], Count * SizeOf(FEntries[0]));
{ Keep reference counting working }
if FromIndex < ToIndex then
begin
if (ToIndex - FromIndex) < Count then
FillChar(FEntries[FromIndex], (ToIndex - FromIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end
else
if FromIndex > ToIndex then
begin
if (FromIndex - ToIndex) < Count then
FillChar(FEntries[ToIndex + Count], (FromIndex - ToIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end;
end;
end;
procedure TJclSortedMap.PutAll(const AMap: IJclMap);
var
It: IJclIterator;
Key: TObject;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if AMap = nil then
Exit;
It := AMap.KeySet.First;
while It.HasNext do
begin
Key := It.Next;
PutValue(Key, AMap.GetValue(Key));
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclSortedMap.PutValue(Key: TObject; Value: TObject);
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FAllowDefaultElements or ((KeysCompare(Key, nil) <> 0) and (ValuesCompare(Value, nil) <> 0)) then
begin
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
FreeValue(FEntries[Index].Value);
FEntries[Index].Value := Value;
end
else
begin
if FSize = FCapacity then
AutoGrow;
if FSize < FCapacity then
begin
Inc(Index);
if (Index < FSize) and (KeysCompare(FEntries[Index].Key, Key) <> 0) then
MoveArray(Index, Index + 1, FSize - Index);
FEntries[Index].Key := Key;
FEntries[Index].Value := Value;
Inc(FSize);
end;
end;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclSortedMap.Remove(Key: TObject): TObject;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Result := Extract(Key);
Result := FreeValue(Result);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclSortedMap.SetCapacity(Value: Integer);
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FSize <= Value then
begin
SetLength(FEntries, Value);
inherited SetCapacity(Value);
end
else
raise EJclOperationNotSupportedError.Create;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclSortedMap.Size: Integer;
begin
Result := FSize;
end;
function TJclSortedMap.SubMap(FromKey, ToKey: TObject): IJclSortedMap;
var
FromIndex, ToIndex: Integer;
NewMap: TJclSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
ToIndex := BinarySearch(ToKey);
if (FromIndex >= 0) and (FromIndex <= ToIndex) then
begin
NewMap.SetCapacity(ToIndex - FromIndex + 1);
NewMap.FSize := ToIndex - FromIndex + 1;
while ToIndex >= FromIndex do
begin
NewMap.FEntries[ToIndex - FromIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSortedMap.TailMap(FromKey: TObject): IJclSortedMap;
var
FromIndex, Index: Integer;
NewMap: TJclSortedMap;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclSortedMap;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
if (FromIndex >= 0) and (FromIndex < FSize) then
begin
NewMap.SetCapacity(FSize - FromIndex);
NewMap.FSize := FSize - FromIndex;
Index := FromIndex;
while Index < FSize do
begin
NewMap.FEntries[Index - FromIndex] := FEntries[Index];
Inc(Index);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSortedMap.Values: IJclCollection;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := TJclArrayList.Create(FSize, False);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Value);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSortedMap.CreateEmptyContainer: TJclAbstractContainerBase;
begin
Result := TJclSortedMap.Create(FSize, False, False);
AssignPropertiesTo(Result);
end;
function TJclSortedMap.FreeKey(var Key: TObject): TObject;
begin
if FOwnsKeys then
begin
Result := nil;
FreeAndNil(Key);
end
else
begin
Result := Key;
Key := nil;
end;
end;
function TJclSortedMap.FreeValue(var Value: TObject): TObject;
begin
if FOwnsValues then
begin
Result := nil;
FreeAndNil(Value);
end
else
begin
Result := Value;
Value := nil;
end;
end;
function TJclSortedMap.GetOwnsKeys: Boolean;
begin
Result := FOwnsKeys;
end;
function TJclSortedMap.GetOwnsValues: Boolean;
begin
Result := FOwnsValues;
end;
function TJclSortedMap.KeysCompare(A, B: TObject): Integer;
begin
Result := SimpleCompare(A, B);
end;
function TJclSortedMap.ValuesCompare(A, B: TObject): Integer;
begin
Result := SimpleCompare(A, B);
end;
{$IFDEF SUPPORTS_GENERICS}
//=== { TJclSortedMap<TKey,TValue> } ==============================================
constructor TJclSortedMap<TKey,TValue>.Create(ACapacity: Integer; AOwnsValues: Boolean; AOwnsKeys: Boolean);
begin
inherited Create();
FOwnsKeys := AOwnsKeys;
FOwnsValues := AOwnsValues;
SetCapacity(ACapacity);
end;
destructor TJclSortedMap<TKey,TValue>.Destroy;
begin
FReadOnly := False;
Clear;
inherited Destroy;
end;
procedure TJclSortedMap<TKey,TValue>.AssignDataTo(Dest: TJclAbstractContainerBase);
var
MyDest: TJclSortedMap<TKey,TValue>;
begin
inherited AssignDataTo(Dest);
if Dest is TJclSortedMap<TKey,TValue> then
begin
MyDest := TJclSortedMap<TKey,TValue>(Dest);
MyDest.SetCapacity(FSize);
MyDest.FEntries := FEntries;
MyDest.FSize := FSize;
end;
end;
function TJclSortedMap<TKey,TValue>.BinarySearch(const Key: TKey): Integer;
var
HiPos, LoPos, CompPos: Integer;
Comp: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
LoPos := 0;
HiPos := FSize - 1;
CompPos := (HiPos + LoPos) div 2;
while HiPos >= LoPos do
begin
Comp := KeysCompare(FEntries[CompPos].Key, Key);
if Comp < 0 then
LoPos := CompPos + 1
else
if Comp > 0 then
HiPos := CompPos - 1
else
begin
HiPos := CompPos;
LoPos := CompPos + 1;
end;
CompPos := (HiPos + LoPos) div 2;
end;
Result := HiPos;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclSortedMap<TKey,TValue>.Clear;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
for Index := 0 to FSize - 1 do
begin
FreeKey(FEntries[Index].Key);
FreeValue(FEntries[Index].Value);
end;
FSize := 0;
AutoPack;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclSortedMap<TKey,TValue>.ContainsKey(const Key: TKey): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSortedMap<TKey,TValue>.ContainsValue(const Value: TValue): Boolean;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := True;
Break;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSortedMap<TKey,TValue>.FirstKey: TKey;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := Default(TKey);
if FSize > 0 then
Result := FEntries[0].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSortedMap<TKey,TValue>.Extract(const Key: TKey): TValue;
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
Result := FEntries[Index].Value;
FEntries[Index].Value := Default(TValue);
FreeKey(FEntries[Index].Key);
if Index < (FSize - 1) then
MoveArray(Index + 1, Index, FSize - Index - 1);
Dec(FSize);
AutoPack;
end
else
Result := Default(TValue);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclSortedMap<TKey,TValue>.GetValue(const Key: TKey): TValue;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Index := BinarySearch(Key);
Result := Default(TValue);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
Result := FEntries[Index].Value
else if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSortedMap<TKey,TValue>.HeadMap(const ToKey: TKey): IJclSortedMap<TKey,TValue>;
var
ToIndex: Integer;
NewMap: TJclSortedMap<TKey,TValue>;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclSortedMap<TKey,TValue>;
ToIndex := BinarySearch(ToKey);
if ToIndex >= 0 then
begin
NewMap.SetCapacity(ToIndex + 1);
NewMap.FSize := ToIndex + 1;
while ToIndex >= 0 do
begin
NewMap.FEntries[ToIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSortedMap<TKey,TValue>.IsEmpty: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := FSize = 0;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSortedMap<TKey,TValue>.KeyOfValue(const Value: TValue): TKey;
var
Index: Integer;
Found: Boolean;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Found := False;
Result := Default(TKey);
for Index := 0 to FSize - 1 do
if ValuesCompare(FEntries[Index].Value, Value) = 0 then
begin
Result := FEntries[Index].Key;
Found := True;
Break;
end;
if (not Found) and (not FReturnDefaultElements) then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSortedMap<TKey,TValue>.KeySet: IJclSet<TKey>;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := CreateEmptyArraySet(FSize, False);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Key);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSortedMap<TKey,TValue>.LastKey: TKey;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := Default(TKey);
if FSize > 0 then
Result := FEntries[FSize - 1].Key
else
if not FReturnDefaultElements then
raise EJclNoSuchElementError.Create('');
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSortedMap<TKey,TValue>.MapEquals(const AMap: IJclMap<TKey,TValue>): Boolean;
var
It: IJclIterator<TKey>;
Index: Integer;
AKey: TKey;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := False;
if AMap = nil then
Exit;
if FSize <> AMap.Size then
Exit;
It := AMap.KeySet.First;
Index := 0;
while It.HasNext do
begin
if Index >= FSize then
Exit;
AKey := It.Next;
if ValuesCompare(AMap.GetValue(AKey), FEntries[Index].Value) <> 0 then
Exit;
Inc(Index);
end;
Result := True;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclSortedMap<TKey,TValue>.MoveArray(FromIndex, ToIndex, Count: Integer);
begin
if Count > 0 then
begin
Move(FEntries[FromIndex], FEntries[ToIndex], Count * SizeOf(FEntries[0]));
{ Keep reference counting working }
if FromIndex < ToIndex then
begin
if (ToIndex - FromIndex) < Count then
FillChar(FEntries[FromIndex], (ToIndex - FromIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end
else
if FromIndex > ToIndex then
begin
if (FromIndex - ToIndex) < Count then
FillChar(FEntries[ToIndex + Count], (FromIndex - ToIndex) * SizeOf(FEntries[0]), 0)
else
FillChar(FEntries[FromIndex], Count * SizeOf(FEntries[0]), 0);
end;
end;
end;
procedure TJclSortedMap<TKey,TValue>.PutAll(const AMap: IJclMap<TKey,TValue>);
var
It: IJclIterator<TKey>;
Key: TKey;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if AMap = nil then
Exit;
It := AMap.KeySet.First;
while It.HasNext do
begin
Key := It.Next;
PutValue(Key, AMap.GetValue(Key));
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclSortedMap<TKey,TValue>.PutValue(const Key: TKey; const Value: TValue);
var
Index: Integer;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FAllowDefaultElements or ((KeysCompare(Key, Default(TKey)) <> 0) and (ValuesCompare(Value, Default(TValue)) <> 0)) then
begin
Index := BinarySearch(Key);
if (Index >= 0) and (KeysCompare(FEntries[Index].Key, Key) = 0) then
begin
FreeValue(FEntries[Index].Value);
FEntries[Index].Value := Value;
end
else
begin
if FSize = FCapacity then
AutoGrow;
if FSize < FCapacity then
begin
Inc(Index);
if (Index < FSize) and (KeysCompare(FEntries[Index].Key, Key) <> 0) then
MoveArray(Index, Index + 1, FSize - Index);
FEntries[Index].Key := Key;
FEntries[Index].Value := Value;
Inc(FSize);
end;
end;
end;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclSortedMap<TKey,TValue>.Remove(const Key: TKey): TValue;
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
Result := Extract(Key);
Result := FreeValue(Result);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
procedure TJclSortedMap<TKey,TValue>.SetCapacity(Value: Integer);
begin
if ReadOnly then
raise EJclReadOnlyError.Create;
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginWrite;
try
{$ENDIF THREADSAFE}
if FSize <= Value then
begin
SetLength(FEntries, Value);
inherited SetCapacity(Value);
end
else
raise EJclOperationNotSupportedError.Create;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndWrite;
end;
{$ENDIF THREADSAFE}
end;
function TJclSortedMap<TKey,TValue>.Size: Integer;
begin
Result := FSize;
end;
function TJclSortedMap<TKey,TValue>.SubMap(const FromKey, ToKey: TKey): IJclSortedMap<TKey,TValue>;
var
FromIndex, ToIndex: Integer;
NewMap: TJclSortedMap<TKey,TValue>;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclSortedMap<TKey,TValue>;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
ToIndex := BinarySearch(ToKey);
if (FromIndex >= 0) and (FromIndex <= ToIndex) then
begin
NewMap.SetCapacity(ToIndex - FromIndex + 1);
NewMap.FSize := ToIndex - FromIndex + 1;
while ToIndex >= FromIndex do
begin
NewMap.FEntries[ToIndex - FromIndex] := FEntries[ToIndex];
Dec(ToIndex);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSortedMap<TKey,TValue>.TailMap(const FromKey: TKey): IJclSortedMap<TKey,TValue>;
var
FromIndex, Index: Integer;
NewMap: TJclSortedMap<TKey,TValue>;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
NewMap := CreateEmptyContainer as TJclSortedMap<TKey,TValue>;
FromIndex := BinarySearch(FromKey);
if (FromIndex = -1) or (KeysCompare(FEntries[FromIndex].Key, FromKey) < 0) then
Inc(FromIndex);
if (FromIndex >= 0) and (FromIndex < FSize) then
begin
NewMap.SetCapacity(FSize - FromIndex);
NewMap.FSize := FSize - FromIndex;
Index := FromIndex;
while Index < FSize do
begin
NewMap.FEntries[Index - FromIndex] := FEntries[Index];
Inc(Index);
end;
end;
Result := NewMap;
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSortedMap<TKey,TValue>.Values: IJclCollection<TValue>;
var
Index: Integer;
begin
{$IFDEF THREADSAFE}
if FThreadSafe then
SyncReaderWriter.BeginRead;
try
{$ENDIF THREADSAFE}
Result := CreateEmptyArrayList(FSize, False);
for Index := 0 to FSize - 1 do
Result.Add(FEntries[Index].Value);
{$IFDEF THREADSAFE}
finally
if FThreadSafe then
SyncReaderWriter.EndRead;
end;
{$ENDIF THREADSAFE}
end;
function TJclSortedMap<TKey,TValue>.FreeKey(var Key: TKey): TKey;
begin
if FOwnsKeys then
begin
Result := Default(TKey);
FreeAndNil(Key);
end
else
begin
Result := Key;
Key := Default(TKey);
end;
end;
function TJclSortedMap<TKey,TValue>.FreeValue(var Value: TValue): TValue;
begin
if FOwnsValues then
begin
Result := Default(TValue);
FreeAndNil(Value);
end
else
begin
Result := Value;
Value := Default(TValue);
end;
end;
function TJclSortedMap<TKey,TValue>.GetOWnsKeys: Boolean;
begin
Result := FOwnsKeys;
end;
function TJclSortedMap<TKey,TValue>.GetOwnsValues: Boolean;
begin
Result := FOwnsValues;
end;
//=== { TJclSortedMapE<TKey, TValue> } =======================================
constructor TJclSortedMapE<TKey, TValue>.Create(const AKeyComparer: IJclComparer<TKey>;
const AValueComparer: IJclComparer<TValue>; const AValueEqualityComparer: IJclEqualityComparer<TValue>; ACapacity: Integer;
AOwnsValues: Boolean; AOwnsKeys: Boolean);
begin
inherited Create(ACapacity, AOwnsValues, AOwnsKeys);
FKeyComparer := AKeyComparer;
FValueComparer := AValueComparer;
FValueEqualityComparer := AValueEqualityComparer;
end;
procedure TJclSortedMapE<TKey, TValue>.AssignPropertiesTo(Dest: TJclAbstractContainerBase);
var
ADest: TJclSortedMapE<TKey, TValue>;
begin
inherited AssignPropertiesTo(Dest);
if Dest is TJclSortedMapE<TKey, TValue> then
begin
ADest := TJclSortedMapE<TKey, TValue>(Dest);
ADest.FKeyComparer := FKeyComparer;
ADest.FValueComparer := FValueComparer;
end;
end;
function TJclSortedMapE<TKey, TValue>.CreateEmptyArrayList(ACapacity: Integer;
AOwnsObjects: Boolean): IJclCollection<TValue>;
begin
if FValueEqualityComparer = nil then
raise EJclNoEqualityComparerError.Create;
Result := TArrayList.Create(FValueEqualityComparer, ACapacity, AOwnsObjects);
end;
function TJclSortedMapE<TKey, TValue>.CreateEmptyContainer: TJclAbstractContainerBase;
begin
Result := TJclSortedMapE<TKey, TValue>.Create(FKeyComparer, FValueComparer, FValueEqualityComparer, FCapacity,
FOwnsValues, FOwnsKeys);
AssignPropertiesTo(Result);
end;
function TJclSortedMapE<TKey, TValue>.CreateEmptyArraySet(ACapacity: Integer; AOwnsObjects: Boolean): IJclSet<TKey>;
begin
Result := TArraySet.Create(FKeyComparer, FCapacity, AOwnsObjects);
end;
function TJclSortedMapE<TKey, TValue>.KeysCompare(const A, B: TKey): Integer;
begin
if KeyComparer = nil then
raise EJclNoComparerError.Create;
Result := KeyComparer.Compare(A, B);
end;
function TJclSortedMapE<TKey, TValue>.ValuesCompare(const A, B: TValue): Integer;
begin
if ValueComparer = nil then
raise EJclNoComparerError.Create;
Result := ValueComparer.Compare(A, B);
end;
//=== { TJclSortedMapF<TKey, TValue> } =======================================
constructor TJclSortedMapF<TKey, TValue>.Create(AKeyCompare: TCompare<TKey>; AValueCompare: TCompare<TValue>;
AValueEqualityCompare: TEqualityCompare<TValue>; ACapacity: Integer; AOwnsValues: Boolean; AOwnsKeys: Boolean);
begin
inherited Create(ACapacity, AOwnsValues, AOwnsKeys);
FKeyCompare := AKeyCompare;
FValueCompare := AValueCompare;
FValueEqualityCompare := AValueEqualityCompare;
end;
procedure TJclSortedMapF<TKey, TValue>.AssignPropertiesTo(Dest: TJclAbstractContainerBase);
var
ADest: TJclSortedMapF<TKey, TValue>;
begin
inherited AssignPropertiesTo(Dest);
if Dest is TJclSortedMapF<TKey, TValue> then
begin
ADest := TJclSortedMapF<TKey, TValue>(Dest);
ADest.FKeyCompare := FKeyCompare;
ADest.FValueCompare := FValueCompare;
end;
end;
function TJclSortedMapF<TKey, TValue>.CreateEmptyArrayList(ACapacity: Integer;
AOwnsObjects: Boolean): IJclCollection<TValue>;
begin
if not Assigned(FValueEqualityCompare) then
raise EJclNoEqualityComparerError.Create;
Result := TArrayList.Create(FValueEqualityCompare, ACapacity, AOwnsObjects);
end;
function TJclSortedMapF<TKey, TValue>.CreateEmptyContainer: TJclAbstractContainerBase;
begin
Result := TJclSortedMapF<TKey, TValue>.Create(FKeyCompare, FValueCompare, FValueEqualityCompare, FCapacity,
FOwnsValues, FOwnsKeys);
AssignPropertiesTo(Result);
end;
function TJclSortedMapF<TKey, TValue>.CreateEmptyArraySet(ACapacity: Integer; AOwnsObjects: Boolean): IJclSet<TKey>;
begin
Result := TArraySet.Create(FKeyCompare, FCapacity, AOwnsObjects);
end;
function TJclSortedMapF<TKey, TValue>.KeysCompare(const A, B: TKey): Integer;
begin
if not Assigned(KeyCompare) then
raise EJclNoComparerError.Create;
Result := KeyCompare(A, B);
end;
function TJclSortedMapF<TKey, TValue>.ValuesCompare(const A, B: TValue): Integer;
begin
if not Assigned(ValueCompare) then
raise EJclNoComparerError.Create;
Result := ValueCompare(A, B);
end;
//=== { TJclSortedMapI<TKey, TValue> } =======================================
function TJclSortedMapI<TKey, TValue>.CreateEmptyArrayList(ACapacity: Integer;
AOwnsObjects: Boolean): IJclCollection<TValue>;
begin
Result := TArrayList.Create(ACapacity, AOwnsObjects);
end;
function TJclSortedMapI<TKey, TValue>.CreateEmptyContainer: TJclAbstractContainerBase;
begin
Result := TJclSortedMapI<TKey, TValue>.Create(FCapacity, FOwnsValues, FOwnsKeys);
AssignPropertiesTo(Result);
end;
function TJclSortedMapI<TKey, TValue>.CreateEmptyArraySet(ACapacity: Integer; AOwnsObjects: Boolean): IJclSet<TKey>;
begin
Result := TArraySet.Create(FCapacity, AOwnsObjects);
end;
function TJclSortedMapI<TKey, TValue>.KeysCompare(const A, B: TKey): Integer;
begin
Result := A.CompareTo(B);
end;
function TJclSortedMapI<TKey, TValue>.ValuesCompare(const A, B: TValue): Integer;
begin
Result := A.CompareTo(B);
end;
{$ENDIF SUPPORTS_GENERICS}
{$IFDEF UNITVERSIONING}
initialization
RegisterUnitVersion(HInstance, UnitVersioning);
finalization
UnregisterUnitVersion(HInstance);
{$ENDIF UNITVERSIONING}
end.
| 26.224789 | 146 | 0.662981 |
47e0f3b4e20df9c6145bbe1f1b62b2dfe5d793e9 | 2,615 | dpr | Pascal | PDF.co Web API/PDF Merging API/Delphi/Merge Any Documents From URLs/MergeAnyDocumentsFromURLs.dpr | bytescout/ByteScout-SDK-SourceCode | 5ee8d4310e08d7b848d116aa65ab2c9c07b5f89e | [
"Apache-2.0"
]
| 24 | 2017-01-13T13:43:21.000Z | 2021-12-23T07:57:19.000Z | PDF.co Web API/PDF Merging API/Delphi/Merge Any Documents From URLs/MergeAnyDocumentsFromURLs.dpr | bytescout/ByteScout-SDK-SourceCode | 5ee8d4310e08d7b848d116aa65ab2c9c07b5f89e | [
"Apache-2.0"
]
| 1 | 2017-03-29T08:22:18.000Z | 2017-05-13T12:27:02.000Z | PDF.co Web API/PDF Merging API/Delphi/Merge Any Documents From URLs/MergeAnyDocumentsFromURLs.dpr | bytescout/ByteScout-SDK-SourceCode | 5ee8d4310e08d7b848d116aa65ab2c9c07b5f89e | [
"Apache-2.0"
]
| 35 | 2016-08-03T19:15:44.000Z | 2022-03-27T16:38:58.000Z | program MergeAnyDocumentsFromURLs;
//*******************************************************************************************//
// //
// Download Free Evaluation Version From: https://bytescout.com/download/web-installer //
// //
// Also available as Web API! Get Your Free API Key: https://app.pdf.co/signup //
// //
// Copyright � 2017-2020 ByteScout, Inc. All rights reserved. //
// https://www.bytescout.com //
// https://pdf.co //
// //
//*******************************************************************************************//
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
Classes,
IdURI,
ByteScoutWebApiExec in 'ByteScoutWebApiExec.pas';
const
// The authentication key (API Key).
// Get your own by registering at https://app.pdf.co
API_KEY: string = '********************************************'
// Destination PDF file name
DESTINATION_FILE: string = 'result.pdf';
// Direct URLs of files to merge. Supports documents, spreadsheets, images as sources.
SOURCE_FILES: array [0..1] of string = (
'https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/pdf-merge/sample1.pdf',
'https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/doc-to-pdf/sample.docx'
);
var
query: string;
file_name: string;
waiting_any_key: char;
files: string;
i: integer;
begin
try
// Prepare URL for `Merge PDF` API call
files := '';
for i := 0 to High(SOURCE_FILES) do begin
if (Length(files) > 0) then
files := files + ',';
files := files + SOURCE_FILES[i];
end;
query := TIdURI.URLEncode(Format('https://api.pdf.co/v1/pdf/merge2' +
'?name=%s&url=%s',
[ExtractFileName(DESTINATION_FILE), files]));
if (WebAPIExec(query, API_KEY, file_name)) then
Writeln(Format('Generated PDF file saved as "%s" file.', [file_name]));
finally
Writeln('Press any key to continue...');
Readln(waiting_any_key);
end;
end.
| 40.859375 | 108 | 0.439006 |
fc47970b737fb5e9b75e02578c4f3437f4e0cfbd | 16,069 | pas | Pascal | Source/Modules/DDuce.EditList.pas | beNative/dduce | cedbe2e847cc49fe8bcd5ba12b76327eee43d639 | [
"Apache-2.0"
]
| 52 | 2015-03-17T16:34:08.000Z | 2022-03-16T12:06:09.000Z | Source/Modules/DDuce.EditList.pas | beNative/dduce | cedbe2e847cc49fe8bcd5ba12b76327eee43d639 | [
"Apache-2.0"
]
| 2 | 2016-06-04T11:26:16.000Z | 2018-07-11T04:14:16.000Z | Source/Modules/DDuce.EditList.pas | beNative/dduce | cedbe2e847cc49fe8bcd5ba12b76327eee43d639 | [
"Apache-2.0"
]
| 10 | 2015-03-25T06:12:24.000Z | 2019-11-13T13:20:27.000Z | {
Copyright (C) 2013-2021 Tim Sinaeve tim.sinaeve@gmail.com
Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
}
{$I DDuce.inc}
unit DDuce.EditList;
{ A user configurable list of key-value pairs. }
interface
uses
Winapi.Windows, Winapi.Messages,
System.SysUtils, System.Variants, System.Classes, System.ImageList,
System.Actions, System.Rtti,
Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ActnList,
Vcl.ComCtrls, Vcl.ExtCtrls, Vcl.Menus, Vcl.ImgList, Vcl.ToolWin,
Spring,
VirtualTrees,
DDuce.DynamicRecord, DDuce.Components.ValueList, DDuce.Logger;
{$REGION 'documentation'}
{ TODO :
- support for drag and drop
- Multiselect move
}
{$ENDREGION}
type
TEditListItemEvent = procedure(
ASender : TObject;
var AName : string;
var AValue : TValue
) of object;
type
TEditList = class(TForm)
{$REGION 'designer controls'}
aclMain : TActionList;
actAdd : TAction;
actDelete : TAction;
actDuplicate : TAction;
actEdit : TAction;
actExecute : TAction;
actMoveDown : TAction;
actMoveUp : TAction;
actRefresh : TAction;
btn1 : TToolButton;
btnAdd : TToolButton;
btnDelete : TToolButton;
btnDuplicate : TToolButton;
btnExecute : TToolButton;
btnMoveDown : TToolButton;
btnMoveUp : TToolButton;
btnRefresh : TToolButton;
btnSpacer1 : TToolButton;
btnSpacer2 : TToolButton;
imlMain : TImageList;
mniAdd : TMenuItem;
mniDelete : TMenuItem;
mniDuplicate : TMenuItem;
mniExecute : TMenuItem;
mniMoveDown : TMenuItem;
mniMoveUp : TMenuItem;
mniN1 : TMenuItem;
mniN2 : TMenuItem;
mniN3 : TMenuItem;
mniRefresh : TMenuItem;
pnlMain : TPanel;
ppmMain : TPopupMenu;
tlbMain : TToolBar;
{$ENDREGION}
{$REGION 'action handlers'}
procedure actMoveUpExecute(Sender: TObject);
procedure actMoveDownExecute(Sender: TObject);
procedure actAddExecute(Sender: TObject);
procedure actDeleteExecute(Sender: TObject);
procedure actDuplicateExecute(Sender: TObject);
procedure actExecuteExecute(Sender: TObject);
procedure actRefreshExecute(Sender: TObject);
procedure actEditExecute(Sender: TObject);
{$ENDREGION}
private
FValueList : TValueList;
FOnItemAdd : Event<TEditListItemEvent>;
FOnItemDuplicate : Event<TEditListItemEvent>;
FOnItemDelete : Event<TEditListItemEvent>;
FOnItemExecute : Event<TEditListItemEvent>;
FOnItemMoveUp : Event<TEditListItemEvent>;
FOnItemMoveDown : Event<TEditListItemEvent>;
FOnDuplicate : Event<TEditListItemEvent>;
FOnDelete : Event<TEditListItemEvent>;
FOnExecute : Event<TEditListItemEvent>;
FUpdate : Boolean;
{$REGION 'property access methods'}
function GetOnAdd: IEvent<TEditListItemEvent>;
function GetOnDelete: IEvent<TEditListItemEvent>;
function GetOnItemDelete: IEvent<TEditListItemEvent>;
function GetOnExecute: IEvent<TEditListItemEvent>;
function GetOnItemExecute: IEvent<TEditListItemEvent>;
function GetOnDuplicate: IEvent<TEditListItemEvent>;
function GetOnItemMoveUp: IEvent<TEditListItemEvent>;
function GetOnItemDuplicate: IEvent<TEditListItemEvent>;
function GetOnItemMoveDown: IEvent<TEditListItemEvent>;
function GetValueList: TValueList;
function GetData: IDynamicRecord;
function GetActionAdd: TAction;
function GetActionDelete: TAction;
function GetActionDuplicate: TAction;
function GetActionExecute: TAction;
function GetActionMoveDown: TAction;
function GetActionMoveUp: TAction;
function GetActionRefresh: TAction;
function GetMultiSelect: Boolean;
procedure SetMultiSelect(const Value: Boolean);
{$ENDREGION}
procedure FValueListDataChanged(ASender: TObject);
protected
function CanMoveUp: Boolean; virtual;
function CanMoveDown: Boolean; virtual;
procedure UpdateActions; override;
procedure Modified;
procedure DoItemAdd(
var AName : string;
var AValue : TValue
);
procedure DoDuplicate(
var AName : string;
var AValue : TValue
);
procedure DoItemDuplicate(
var AName : string;
var AValue : TValue
);
procedure DoExecute(
var AName : string;
var AValue : TValue
);
procedure DoItemExecute(
var AName : string;
var AValue : TValue
);
procedure DoDelete(
var AName : string;
var AValue : TValue
);
procedure DoItemDelete(
var AName : string;
var AValue : TValue
);
procedure DoItemMoveUp(
var AName : string;
var AValue : TValue
);
procedure DoItemMoveDown(
var AName : string;
var AValue : TValue
);
public
procedure AfterConstruction; override;
constructor Create(
AOwner : TComponent;
AParent : TWinControl
); reintroduce; virtual;
procedure Refresh; virtual;
property ValueList: TValueList
read GetValueList;
property Data: IDynamicRecord
read GetData;
property MultiSelect: Boolean
read GetMultiSelect write SetMultiSelect;
property ActionMoveUp: TAction
read GetActionMoveUp;
property ActionMoveDown: TAction
read GetActionMoveDown;
property ActionExecute: TAction
read GetActionExecute;
property ActionAdd: TAction
read GetActionAdd;
property ActionDelete: TAction
read GetActionDelete;
property ActionDuplicate: TAction
read GetActionDuplicate;
property ActionRefresh: TAction
read GetActionRefresh;
property OnAdd: IEvent<TEditListItemEvent>
read GetOnAdd;
property OnDuplicate: IEvent<TEditListItemEvent>
read GetOnDuplicate;
property OnItemDuplicate: IEvent<TEditListItemEvent>
read GetOnItemDuplicate;
property OnDelete: IEvent<TEditListItemEvent>
read GetOnDelete;
property OnItemDelete: IEvent<TEditListItemEvent>
read GetOnItemDelete;
property OnExecute: IEvent<TEditListItemEvent>
read GetOnExecute;
property OnItemExecute: IEvent<TEditListItemEvent>
read GetOnItemExecute;
property OnItemMoveUp: IEvent<TEditListItemEvent>
read GetOnItemMoveUp;
property OnItemMoveDown: IEvent<TEditListItemEvent>
read GetOnItemMoveDown;
end;
implementation
uses
DDuce.Utils;
{$R *.dfm}
{$REGION 'construction and destruction'}
procedure TEditList.AfterConstruction;
begin
inherited AfterConstruction;
FValueList := TValueList.Create(Self);
FValueList.Parent := pnlMain;
FValueList.Align := alClient;
FValueList.Data := DynamicRecord.CreateDynamicRecord;
FValueList.Data.OnChanged.Add(FValueListDataChanged);
FValueList.BorderStyle := bsNone;
FValueList.ShowGutter := False;
actAdd.Enabled := True;
actRefresh.Enabled := True;
end;
constructor TEditList.Create(AOwner: TComponent; AParent: TWinControl);
begin
inherited Create(AOwner);
if Assigned(AParent) then
AssignFormParent(Self, AParent);
end;
{$ENDREGION}
{$REGION 'action handlers'}
procedure TEditList.actAddExecute(Sender: TObject);
var
I : Integer;
S : string;
LName : string;
LValue : TValue;
begin
LName := 'New';
LValue := '';
I := 0;
S := LName;
while Data.ContainsField(S) do
begin
Inc(I);
S := Format('%s_%d', [LName, I]);
end;
LName := S;
DoItemAdd(LName, LValue);
FValueList.Data[LName] := LValue;
if FValueList.Data.ContainsField(LName) then
begin
Guard.CheckNotNull(FValueList.Data.Fields[LName], LName);
FValueList.SelectNode(Data.Count - 1);
Abort;
FValueList.FocusedField := FValueList.Data.Fields[LName];
end;
Modified;
end;
procedure TEditList.actDeleteExecute(Sender: TObject);
var
LName : string;
LNode : TValueListNode;
LValue : TValue;
begin
for LNode in FValueList.GetSelectedData<TValueListNode> do
begin
LValue := LNode.Data.Value;
LName := LNode.Data.Name;
if FValueList.SelectedCount >= 1 then
DoDelete(LName, LValue);
DoItemDelete(LName, LValue);
Data.DeleteField(LName);
FValueList.DeleteNode(LNode.VNode);
end;
end;
procedure TEditList.actDuplicateExecute(Sender: TObject);
var
I : Integer;
S : string;
LName : string;
LNode : TValueListNode;
LValue : TValue;
begin
for LNode in FValueList.GetSelectedData<TValueListNode> do
begin
LValue := LNode.Data.Value;
LName := LNode.Data.Name;
I := 0;
S := LName;
while Data.ContainsField(S) do
begin
Inc(I);
S := Format('%s_%d', [LName, I]);
end;
LName := S;
DoItemDuplicate(LName, LValue);
FValueList.Data[LName] := LValue;
end;
Modified;
end;
procedure TEditList.actEditExecute(Sender: TObject);
begin
FValueList.EditNode(FValueList.FocusedNode, FValueList.FocusedColumn);
end;
procedure TEditList.actExecuteExecute(Sender: TObject);
var
LName : string;
LNode : TValueListNode;
LValue : TValue;
begin
for LNode in FValueList.GetSelectedData<TValueListNode> do
begin
LValue := LNode.Data.Value;
LName := LNode.Data.Name;
DoItemExecute(LName, LValue);
end;
end;
procedure TEditList.actMoveDownExecute(Sender: TObject);
var
LName : string;
LNode : TValueListNode;
LValue : TValue;
begin
// if Assigned(FValueList.FocusedField) then
// begin
for LNode in FValueList.GetSelectedData<TValueListNode> do
begin
LValue := LNode.Data.Value;
LName := LNode.Data.Name;
//LNode := FValueList.GetFirstSelectedNodeData<TValueListNode>;
LNode.Data.Index := LNode.Data.Index + 1;
FValueList.MoveTo(LNode.VNode, LNode.VNode.NextSibling, amInsertAfter, False);
FValueList.FocusedNode := LNode.VNode;
LValue := LNode.Data.Value;
LName := LNode.Data.Name;
DoItemMoveDown(LName, LValue);
end;
end;
procedure TEditList.actMoveUpExecute(Sender: TObject);
var
LName : string;
LNode : TValueListNode;
LValue : TValue;
begin
if Assigned(FValueList.FocusedField) then
begin
LNode := FValueList.GetFirstSelectedNodeData<TValueListNode>;
LNode.Data.Index := LNode.Data.Index - 1;
FValueList.MoveTo(LNode.VNode, LNode.VNode.PrevSibling, amInsertBefore, False);
FValueList.FocusedNode := LNode.VNode;
LValue := LNode.Data.Value;
LName := LNode.Data.Name;
DoItemMoveUp(LName, LValue);
end;
end;
procedure TEditList.actRefreshExecute(Sender: TObject);
begin
Refresh;
end;
{$ENDREGION}
{$REGION 'event handlers'}
procedure TEditList.FValueListDataChanged(ASender: TObject);
begin
Logger.Track(Self, 'FValueListDataChanged');
Modified;
end;
{$ENDREGION}
{$REGION 'event dispatch methods'}
procedure TEditList.DoItemAdd(var AName: string; var AValue: TValue);
begin
Logger.Track(Self, 'DoItemAdd');
if FOnItemAdd.CanInvoke then
FOnItemAdd.Invoke(Self, AName, AValue);
Modified;
end;
procedure TEditList.DoDelete(var AName: string; var AValue: TValue);
begin
if FOnDelete.CanInvoke then
FOnDelete.Invoke(Self, AName, AValue);
end;
{ Called for every selected item if MutiSelect is enabled }
procedure TEditList.DoItemDelete(var AName: string; var AValue: TValue);
begin
if FOnItemDelete.CanInvoke then
FOnItemDelete.Invoke(Self, AName, AValue);
end;
procedure TEditList.DoItemDuplicate(var AName: string; var AValue: TValue);
begin
if FOnItemDuplicate.CanInvoke then
FOnItemDuplicate.Invoke(Self, AName, AValue);
Modified;
end;
procedure TEditList.DoDuplicate(var AName: string; var AValue: TValue);
begin
if FOnDuplicate.CanInvoke then
FOnDuplicate.Invoke(Self, AName, AValue);
Modified;
end;
procedure TEditList.DoExecute(var AName: string; var AValue: TValue);
begin
if FOnExecute.CanInvoke then
FOnExecute.Invoke(Self, AName, AValue);
end;
{ Called for every selected item if MutiSelect is enabled }
procedure TEditList.DoItemExecute(var AName: string; var AValue: TValue);
begin
if FOnItemExecute.CanInvoke then
FOnItemExecute.Invoke(Self, AName, AValue);
Modified;
end;
procedure TEditList.DoItemMoveDown(var AName: string; var AValue: TValue);
begin
if FOnItemMoveDown.CanInvoke then
FOnItemMoveDown.Invoke(Self, AName, AValue);
Modified;
end;
procedure TEditList.DoItemMoveUp(var AName: string; var AValue: TValue);
begin
if FOnItemMoveUp.CanInvoke then
FOnItemMoveUp.Invoke(Self, AName, AValue);
Modified;
end;
{$ENDREGION}
{$REGION 'property access methods'}
function TEditList.GetActionAdd: TAction;
begin
Result := actAdd;
end;
function TEditList.GetActionDelete: TAction;
begin
Result := actDelete;
end;
function TEditList.GetActionDuplicate: TAction;
begin
Result := actDuplicate;
end;
function TEditList.GetActionExecute: TAction;
begin
Result := actExecute;
end;
function TEditList.GetActionMoveDown: TAction;
begin
Result := actMoveDown;
end;
function TEditList.GetActionMoveUp: TAction;
begin
Result := actMoveUp;
end;
function TEditList.GetActionRefresh: TAction;
begin
Result := actRefresh;
end;
function TEditList.GetData: IDynamicRecord;
begin
Result := FValueList.Data;
end;
function TEditList.GetMultiSelect: Boolean;
begin
Result := FValueList.MultiSelect;
end;
procedure TEditList.SetMultiSelect(const Value: Boolean);
begin
FValueList.MultiSelect := Value;
end;
function TEditList.GetOnAdd: IEvent<TEditListItemEvent>;
begin
Result := FOnItemAdd;
end;
function TEditList.GetOnDelete: IEvent<TEditListItemEvent>;
begin
Result := FOnDelete;
end;
function TEditList.GetOnItemDelete: IEvent<TEditListItemEvent>;
begin
Result := FOnItemDelete;
end;
function TEditList.GetOnItemDuplicate: IEvent<TEditListItemEvent>;
begin
Result := FOnItemDuplicate;
end;
function TEditList.GetOnDuplicate: IEvent<TEditListItemEvent>;
begin
Result := FOnDuplicate;
end;
function TEditList.GetOnExecute: IEvent<TEditListItemEvent>;
begin
Result := FOnExecute;
end;
function TEditList.GetOnItemExecute: IEvent<TEditListItemEvent>;
begin
Result := FOnItemExecute;
end;
function TEditList.GetOnItemMoveDown: IEvent<TEditListItemEvent>;
begin
Result := FOnItemMoveDown;
end;
function TEditList.GetOnItemMoveUp: IEvent<TEditListItemEvent>;
begin
Result := FOnItemMoveUp;
end;
function TEditList.GetValueList: TValueList;
begin
Result := FValueList;
end;
{$ENDREGION}
{$REGION 'protected methods'}
function TEditList.CanMoveDown: Boolean;
begin
if Assigned(FValueList.FocusedNode) and (FValueList.SelectedCount = 1) then
Result := Assigned(FValueList.FocusedNode.NextSibling)
else
Result := False;
end;
function TEditList.CanMoveUp: Boolean;
begin
if Assigned(FValueList.FocusedNode) and (FValueList.SelectedCount = 1) then
Result := Assigned(FValueList.FocusedNode.PrevSibling)
else
Result := False;
end;
procedure TEditList.Modified;
begin
FUpdate := True;
end;
procedure TEditList.UpdateActions;
begin
inherited UpdateActions;
actMoveUp.Enabled := CanMoveUp;
actMoveDown.Enabled := CanMoveDown;
actDuplicate.Enabled := not Data.IsEmpty;
actDelete.Enabled := not Data.IsEmpty;
actExecute.Enabled := not Data.IsEmpty and FOnExecute.CanInvoke;
actEdit.Enabled := ValueList.SelectedCount = 1;
if FUpdate then
begin
Refresh;
FUpdate := False;
end;
end;
{$ENDREGION}
{$REGION 'public methods'}
procedure TEditList.Refresh;
begin
if Assigned(FValueList) then
FValueList.Refresh;
end;
{$ENDREGION}
end.
| 24.951863 | 83 | 0.718402 |
fc0163f55f42a8a8ac9d4eab4a3d8f86f3e54efd | 2,163 | dfm | Pascal | Chapter07/Memento/EditorMain.dfm | PacktPublishing/Hands-On-Design-Patterns-with-Delphi | 30f6ab51e61d583f822be4918f4b088e2255cd82 | [
"MIT"
]
| 38 | 2019-02-28T06:22:52.000Z | 2022-03-16T12:30:43.000Z | Chapter07/Memento/EditorMain.dfm | alefragnani/Hands-On-Design-Patterns-with-Delphi | 3d29e5b2ce9e99e809a6a9a178c3f5e549a8a03d | [
"MIT"
]
| null | null | null | Chapter07/Memento/EditorMain.dfm | alefragnani/Hands-On-Design-Patterns-with-Delphi | 3d29e5b2ce9e99e809a6a9a178c3f5e549a8a03d | [
"MIT"
]
| 18 | 2019-03-29T08:36:14.000Z | 2022-03-30T00:31:28.000Z | object frmMemento: TfrmMemento
Left = 0
Top = 0
Caption = 'Memento pattern'
ClientHeight = 224
ClientWidth = 402
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
KeyPreview = True
OldCreateOrder = False
OnCreate = FormCreate
OnDestroy = FormDestroy
OnKeyPress = FormKeyPress
DesignSize = (
402
224)
PixelsPerInch = 96
TextHeight = 13
object btnUndo: TButton
Left = 16
Top = 16
Width = 156
Height = 49
Action = actUndo
TabOrder = 0
end
object btnMacro: TButton
Left = 16
Top = 71
Width = 75
Height = 50
Action = actRecord
TabOrder = 1
end
object btnPlay: TButton
Left = 97
Top = 71
Width = 75
Height = 50
Action = actPlay
TabOrder = 2
end
object PageControl1: TPageControl
Left = 192
Top = 16
Width = 193
Height = 193
ActivePage = TabSheet2
Anchors = [akLeft, akTop, akRight, akBottom]
TabOrder = 3
object TabSheet1: TTabSheet
Caption = 'Editor 1'
ExplicitLeft = 0
ExplicitTop = 0
ExplicitWidth = 0
ExplicitHeight = 0
object Memo1: TMemo
Left = 0
Top = 0
Width = 185
Height = 165
Align = alClient
ReadOnly = True
TabOrder = 0
end
end
object TabSheet2: TTabSheet
Caption = 'Editor 2'
ImageIndex = 1
object Memo2: TMemo
Left = 0
Top = 0
Width = 185
Height = 165
Align = alClient
ReadOnly = True
TabOrder = 0
end
end
end
object ActionList1: TActionList
Left = 104
Top = 152
object actUndo: TAction
Caption = 'Undo'
OnExecute = actUndoExecute
OnUpdate = actUndoUpdate
end
object actRecord: TAction
Caption = 'Record'
OnExecute = actRecordExecute
end
object actStop: TAction
Caption = 'Stop'
OnExecute = actStopExecute
end
object actPlay: TAction
Caption = 'Play'
OnExecute = actPlayExecute
OnUpdate = actPlayUpdate
end
end
end
| 20.027778 | 48 | 0.594545 |
f10d7dcb16f586a7509d82709886728d923aab0f | 856 | dpr | Pascal | VirtualMachine/GUIApp/GUIAppProject.dpr | ObjectPascalInterpreter/BookPart_3 | 95150d4d02f7e13e5b1ebb58c249073a384f2a0a | [
"Apache-2.0"
]
| 8 | 2021-11-07T22:45:25.000Z | 2022-03-12T21:38:53.000Z | VirtualMachine/GUIApp/GUIAppProject.dpr | Irwin1985/BookPart_2 | 4e8c2e47cd09b77c6e5bd3455ddfe7492adf26bf | [
"Apache-2.0"
]
| 4 | 2021-09-23T02:13:55.000Z | 2021-12-07T06:08:17.000Z | VirtualMachine/GUIApp/GUIAppProject.dpr | Irwin1985/BookPart_2 | 4e8c2e47cd09b77c6e5bd3455ddfe7492adf26bf | [
"Apache-2.0"
]
| 4 | 2021-11-24T17:24:56.000Z | 2021-12-21T04:56:58.000Z | program GUIAppProject;
uses
Vcl.Forms,
ufMain in 'ufMain.pas' {frmMain},
uAssembler in '..\uAssembler.pas',
uOpCodes in '..\uOpCodes.pas',
uVM in '..\uVM.pas',
uConstantTable in '..\uConstantTable.pas',
uUtils in '..\uUtils.pas',
uBuiltinFunctions in '..\uBuiltinFunctions.pas',
uMachineStack in '..\uMachineStack.pas',
uListObject in '..\uListObject.pas',
uMemoryManager in '..\uMemoryManager.pas',
uStringObject in '..\uStringObject.pas',
uVMExceptions in '..\uVMExceptions.pas',
uSyntaxAnalysis in '..\..\Rhodus_Version_1\uSyntaxAnalysis.pas',
uScanner in '..\..\Rhodus_Version_1\uScanner.pas',
uModule in '..\uModule.pas',
uSymbolTable in '..\uSymbolTable.pas';
{$R *.res}
begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TfrmMain, frmMain);
Application.Run;
end.
| 28.533333 | 66 | 0.707944 |
fcebc437a0ea33946d4c5af4769d42688c2709ce | 880 | pas | Pascal | Aula 06/lista 08/exe01/exe01 (1).pas | WelsonGomes/IPM | fb7300f0bb3a149e46db3dd254e919697a3ac7f1 | [
"MIT"
]
| null | null | null | Aula 06/lista 08/exe01/exe01 (1).pas | WelsonGomes/IPM | fb7300f0bb3a149e46db3dd254e919697a3ac7f1 | [
"MIT"
]
| null | null | null | Aula 06/lista 08/exe01/exe01 (1).pas | WelsonGomes/IPM | fb7300f0bb3a149e46db3dd254e919697a3ac7f1 | [
"MIT"
]
| null | null | null | unit exe01;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, XPMan;
type
TForm1 = class(TForm)
edt1: TEdit;
xpmnfst1: TXPManifest;
edt2: TEdit;
edt3: TEdit;
edt4: TEdit;
edt5: TEdit;
btnValidar: TButton;
mmoApresentar: TMemo;
procedure btnValidarClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.btnValidarClick(Sender: TObject);
var
iNum: array[0..4] of Integer;
iCont: Integer;
begin
iNum[0]:= StrToInt(edt1.Text);
iNum[1]:= StrToInt(edt2.Text);
iNum[2]:= StrToInt(edt3.Text);
iNum[3]:= StrToInt(edt4.Text);
iNum[4]:= StrToInt(edt5.Text);
for iCont:= Low(iNum) to High(iNum) do
mmoApresentar.Lines.Add(iNum(iCont));
end;
end.
| 17.959184 | 76 | 0.673864 |
fc1584effca70bd50eeb424f320f1e98c7697014 | 196 | dpr | Pascal | ClipView.dpr | delphi-pascal-archive/clipboard_viewer | 8a1d29f9e7461d6f85c6e59c349ddde644f0618a | [
"Unlicense"
]
| null | null | null | ClipView.dpr | delphi-pascal-archive/clipboard_viewer | 8a1d29f9e7461d6f85c6e59c349ddde644f0618a | [
"Unlicense"
]
| null | null | null | ClipView.dpr | delphi-pascal-archive/clipboard_viewer | 8a1d29f9e7461d6f85c6e59c349ddde644f0618a | [
"Unlicense"
]
| null | null | null | program ClipView;
uses
Forms,
ClipViewU in 'ClipViewU.pas' {Form1};
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
| 14 | 41 | 0.668367 |
47c2bf06c110935f91ee619833bf34a81293506f | 1,200 | dfm | Pascal | Chapter 7/OmniThreadLibrary/tests/60_Map/test_60_Map.dfm | PacktPublishing/Delphi-High-Performance | bcb84190e8660a28cbc0caada2e1bed3b8adfe42 | [
"MIT"
]
| 45 | 2018-04-08T07:01:13.000Z | 2022-02-18T17:28:10.000Z | Chapter 7/OmniThreadLibrary/tests/60_Map/test_60_Map.dfm | anomous/Delphi-High-Performance | 051a8f7d7460345b60cb8d2a10a974ea8179ea41 | [
"MIT"
]
| null | null | null | Chapter 7/OmniThreadLibrary/tests/60_Map/test_60_Map.dfm | anomous/Delphi-High-Performance | 051a8f7d7460345b60cb8d2a10a974ea8179ea41 | [
"MIT"
]
| 17 | 2018-03-21T11:22:15.000Z | 2022-03-16T05:55:54.000Z | object frmTestParallelMap: TfrmTestParallelMap
Left = 0
Top = 0
Caption = 'Parallel.Map tester'
ClientHeight = 411
ClientWidth = 629
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
DesignSize = (
629
411)
PixelsPerInch = 96
TextHeight = 13
object btnMap: TButton
Left = 16
Top = 16
Width = 75
Height = 25
Caption = 'Map'
TabOrder = 0
OnClick = btnMapClick
end
object lbLog: TListBox
Left = 108
Top = 8
Width = 513
Height = 395
Anchors = [akLeft, akTop, akRight, akBottom]
ItemHeight = 13
TabOrder = 1
end
object btnMap2: TButton
Left = 16
Top = 47
Width = 75
Height = 25
Caption = 'Map'
TabOrder = 2
OnClick = btnMap2Click
end
object btnSerial: TButton
Left = 16
Top = 120
Width = 75
Height = 25
Caption = 'Serial'
TabOrder = 3
OnClick = btnSerialClick
end
object btnParallel: TButton
Left = 16
Top = 151
Width = 75
Height = 25
Caption = 'Parallel'
TabOrder = 4
OnClick = btnParallelClick
end
end
| 18.461538 | 48 | 0.615 |
475ec4482ca8681f63cc88e4fcf4a5dab7e6c153 | 18,169 | pas | Pascal | MainForm.pas | NetVaIT/SOFOM | 186ba21b1e33eac9f432d6764131ad9db5f28637 | [
"Apache-2.0"
]
| null | null | null | MainForm.pas | NetVaIT/SOFOM | 186ba21b1e33eac9f432d6764131ad9db5f28637 | [
"Apache-2.0"
]
| 51 | 2018-07-25T15:39:25.000Z | 2021-04-21T17:40:57.000Z | MainForm.pas | NetVaIT/SOFOM | 186ba21b1e33eac9f432d6764131ad9db5f28637 | [
"Apache-2.0"
]
| 1 | 2021-02-23T17:27:06.000Z | 2021-02-23T17:27:06.000Z | unit MainForm;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, _MainRibbonForm, cxGraphics, cxControls,
cxLookAndFeels, cxLookAndFeelPainters, dxRibbonSkins, dxSkinsCore,
dxSkinBlack, dxSkinBlue, dxSkinBlueprint, dxSkinCaramel, dxSkinCoffee,
dxSkinDarkRoom, dxSkinDarkSide, dxSkinDevExpressDarkStyle,
dxSkinDevExpressStyle, dxSkinFoggy, dxSkinGlassOceans, dxSkinHighContrast,
dxSkiniMaginary, dxSkinLilian, dxSkinLiquidSky, dxSkinLondonLiquidSky,
dxSkinMcSkin, dxSkinMoneyTwins, dxSkinOffice2007Black, dxSkinOffice2007Blue,
dxSkinOffice2007Green, dxSkinOffice2007Pink, dxSkinOffice2007Silver,
dxSkinOffice2010Black, dxSkinOffice2010Blue, dxSkinOffice2010Silver,
dxSkinOffice2013White, dxSkinPumpkin, dxSkinSeven, dxSkinSevenClassic,
dxSkinSharp, dxSkinSharpPlus, dxSkinSilver, dxSkinSpringTime, dxSkinStardust,
dxSkinSummer2008, dxSkinTheAsphaltWorld, dxSkinsDefaultPainters,
dxSkinValentine, dxSkinVS2010, dxSkinWhiteprint, dxSkinXmas2008Blue,
dxSkinsdxRibbonPainter, cxContainer, cxEdit, dxSkinsdxBarPainter,
Vcl.StdActns, System.Actions, Vcl.ActnList, Vcl.ImgList, dxSkinsForm, dxBar,
Vcl.ExtCtrls, dxStatusBar, dxRibbonStatusBar, cxLabel, dxGallery,
dxGalleryControl, dxRibbonBackstageViewGalleryControl, dxRibbonBackstageView,
cxClasses, dxRibbon, dxScreenTip, _Utils, _StandarDMod, _ReportDMod,
UsuariosDM, ProcesosType;
type
TfrmMain = class(T_frmMainRibbon)
actCatalogo: TAction;
dxRibbon1Tab2: TdxRibbonTab;
dxbEjemplo: TdxBar;
dxBarLargeButton1: TdxBarLargeButton;
actUbicaciones: TAction;
dxBarLargeButton2: TdxBarLargeButton;
actBancos: TAction;
dxBarLargeButton3: TdxBarLargeButton;
actMonedas: TAction;
dxBarLargeButton6: TdxBarLargeButton;
actPuestos: TAction;
dxBarLargeButton11: TdxBarLargeButton;
actPlazasTurnos: TAction;
dxBarLargeButton9: TdxBarLargeButton;
dxBarLargeButton10: TdxBarLargeButton;
actEstablecimientos: TAction;
dxbOrganizacion: TdxBar;
actCapacitaciones: TAction;
dxbPresonas: TdxBar;
dxBarLargeButton12: TdxBarLargeButton;
actEmpleados: TAction;
actClientes: TAction;
actProveedores: TAction;
dxBarLargeButton15: TdxBarLargeButton;
dxBarLargeButton16: TdxBarLargeButton;
dxbEsquemas: TdxBar;
dxBarButton1: TdxBarButton;
dxBarButton2: TdxBarButton;
dxBarButton3: TdxBarButton;
dxBarLargeButton4: TdxBarLargeButton;
dxBarButton4: TdxBarButton;
dxBarButton5: TdxBarButton;
dxBarLargeButton5: TdxBarLargeButton;
actPersonas: TAction;
actDuenoProceso: TAction;
actOutsourcing: TAction;
dxBarLargeButton7: TdxBarLargeButton;
dxBarLargeButton8: TdxBarLargeButton;
dxRibbon1Tab3: TdxRibbonTab;
dxBarLargeButton14: TdxBarLargeButton;
dxBarLargeButton17: TdxBarLargeButton;
dxBarLargeButton18: TdxBarLargeButton;
actComisionistas: TAction;
actSocios: TAction;
dxBarButton8: TdxBarButton;
dxBarLargeButton21: TdxBarLargeButton;
dxBarLargeButton23: TdxBarLargeButton;
dxBarLargeButton24: TdxBarLargeButton;
dxRibbon1Tab5: TdxRibbonTab;
dxBarLargeButton25: TdxBarLargeButton;
actCXCConceptos: TAction;
dxBarLargeButton27: TdxBarLargeButton;
dxtshConfiguracion: TdxRibbonBackstageViewTabSheet;
dxtshUsuarios: TdxRibbonBackstageViewTabSheet;
dxBarLargeButton34: TdxBarLargeButton;
actRptPlaza: TAction;
dxBarButton13: TdxBarButton;
actProductos: TAction;
dxBarLargeButton29: TdxBarLargeButton;
dxbProductos: TdxBar;
dxBarButton15: TdxBarButton;
dxBarButton16: TdxBarButton;
actMarcas: TAction;
actFamilias: TAction;
actProductosTipos: TAction;
dxBarButton17: TdxBarButton;
dxBarManagerBar1: TdxBar;
actContratos: TAction;
dxBarLargeButton35: TdxBarLargeButton;
dxBarLargeButton38: TdxBarLargeButton;
actAmortizaciones: TAction;
actFacturacion: TAction;
dxBarLargeButton39: TdxBarLargeButton;
actEmisor: TAction;
dxBrLrgBtnCuentasXCobrar: TdxBarLargeButton;
actCuentasXCobrar: TAction;
dxBrLrgBtnPagos: TdxBarLargeButton;
actPagos: TAction;
actAplicacionPagos: TAction;
actCotizaciones: TAction;
dxBarLargeButton40: TdxBarLargeButton;
dxBrMngrReportes: TdxBar;
dxBrLrgBtnAntiguedad: TdxBarLargeButton;
actRptAntiguedadSaldos: TAction;
dxBrLrgBtnEstadoCuenta: TdxBarLargeButton;
actEstadoCuenta: TAction;
actListasRestringidas: TAction;
dxBarLargeButton19: TdxBarLargeButton;
dxBrLrgBtnSeguimiento: TdxBarLargeButton;
actSeguimiento: TAction;
dxBrLrgBtnInformacionContratos: TdxBarLargeButton;
actInformacionContratos: TAction;
actMonedasCotizaciones: TAction;
dxBarLargeButton22: TdxBarLargeButton;
actRptCobertura: TAction;
dxBarLargeButton26: TdxBarLargeButton;
actRptExpecientes: TAction;
dxBarLargeButton31: TdxBarLargeButton;
actReporteCartera: TAction;
actRptColocacion: TAction;
dxBarLargeButton32: TdxBarLargeButton;
actColocacionAcumulado: TAction;
dxBarLargeButton33: TdxBarLargeButton;
actPoneFechaActual: TAction;
dxBrLrgBtnPoneFechaActual: TdxBarLargeButton;
dxBarManagerBar2: TdxBar;
dxBarLargeButton36: TdxBarLargeButton;
actBuroCredito: TAction;
actNotasCredito: TAction;
actAlertasPLD: TAction;
dxBarLargeButton41: TdxBarLargeButton;
actRptPagoAplicacionesMensual: TAction;
actAgregarAlerta3: TAction;
dxBarButton11: TdxBarButton;
actPLDAlertasConfiguracion: TAction;
dxBarLargeButton20: TdxBarLargeButton;
dxBarButton6: TdxBarButton;
dxBarButton7: TdxBarButton;
dxBarButton9: TdxBarButton;
dxBarButton10: TdxBarButton;
actCFDIPagos: TAction;
dxBrLrgBtnMatrizRiesgo: TdxBarLargeButton;
actMatrizRiesgo: TAction;
dxBarLargeButton13: TdxBarLargeButton;
dxBrLrgBtnEvaluacionRiesgo: TdxBarLargeButton;
actEvaluacionRiesgo: TAction;
dxBrLrgBtnPagoReal: TdxBarLargeButton;
actPagosPorCliente: TAction;
actRptCFDIContabilidad: TAction;
dxBarButton12: TdxBarButton;
dxBarButton14: TdxBarButton;
dxBarButton18: TdxBarButton;
dxBarButton19: TdxBarButton;
dxBarButton20: TdxBarButton;
dxBarLargeButton28: TdxBarLargeButton;
dxBarButton21: TdxBarButton;
dxBarButton22: TdxBarButton;
dxBarButton23: TdxBarButton;
dxBarLargeButton30: TdxBarLargeButton;
dxBarButton24: TdxBarButton;
dxBarButton25: TdxBarButton;
dxBarButton26: TdxBarButton;
dxBarButton27: TdxBarButton;
dxBarButton28: TdxBarButton;
actPerfiles: TAction;
dxBrLrgBtnPerfiles: TdxBarLargeButton;
actAgregarAlerta2: TAction;
dxBarButton29: TdxBarButton;
procedure actCatalogoExecute(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure dxRibbon1ApplicationMenuClick(Sender: TdxCustomRibbon;
var AHandled: Boolean);
procedure actPoneFechaActualExecute(Sender: TObject);
procedure actAgregarAlerta3Execute(Sender: TObject);
procedure actAgregarAlerta2Execute(Sender: TObject);
private
procedure UsarPermisos;
{ Private declarations }
protected
gModulo: T_dmStandar;
gReport: T_dmReport;
dmUsuarios: TdmUsuarios;
procedure CreateModule(pModulo: Integer; pCaption: String); override;
procedure ConfigControls; override;
procedure DestroyModule; override;
public
{ Public declarations }
end;
var
frmMain: TfrmMain;
implementation
{$R *.dfm}
uses ConfiguracionDM, UbicacionesDM, BancosDM, MonedasDM, PuestosDM, PlazasTurnosDM,
EstablecimientosDM, CapacitacionDM, PersonasDM, RptPlazasDM, ProductosDM,
MarcasDM, FamiliasDM, ContratosDM, AmortizacionesDM, FacturasDM,
CuentasXCobrarDM, PagosDM, CotizacionesDM, rptAntiguedadSaldosDM,
AplicacionesConsultaDM, EstadosCuentaDM, ListasRestringidasDM,
SeguimientoCobranzaDM, rptInformacionContratosDM, MonedasCotizacionesDM,
RptCoberturaDM, RptExpedientesRecibidosDM, rptReporteCarteraDM,
RptAnexosProductosDM, RptColocacionAcumuladoDM, PonerFechaActualForm,
BuroCreditoDM, PLDAlertasDM, RptPagoAplicacionesMensualDM, _ConectionDmod,
PLDAlertasConfiguracionDM, MatrizRiesgoDM, EvaluacionesRiesgoDM,
PagosRealesDM, RptCFDIContabilidadDM, UsuariosPerfilesDM;
procedure TfrmMain.actAgregarAlerta2Execute(Sender: TObject);
var
dmPLDAlertas: TdmPLDAlertas;
begin
inherited;
dmPLDAlertas := TdmPLDAlertas.Create(Self);
try
dmPLDAlertas.GenerarAlerta(pldtInusual);
finally
dmPLDAlertas.Free;
end;
end;
procedure TfrmMain.actAgregarAlerta3Execute(Sender: TObject);
var
dmPLDAlertas: TdmPLDAlertas;
begin
inherited;
dmPLDAlertas := TdmPLDAlertas.Create(Self);
try
dmPLDAlertas.GenerarAlerta(pldtPreocupante);
finally
dmPLDAlertas.Free;
end;
end;
procedure TfrmMain.actCatalogoExecute(Sender: TObject);
begin
inherited;
CreateModule(TAction(Sender).Tag, TAction(Sender).Caption);
end;
procedure TfrmMain.CreateModule(pModulo: Integer; pCaption: String);
begin
inherited;
DestroyModule;
case pModulo of
//Catalogos
1: gModulo := TdmUbicaciones.Create(Self);
2: gModulo := TdmBancos.Create(Self);
3: gModulo := TdmMonedas.Create(Self);
4: gModulo := TdmPlazasTurnos.Create(Self);
5: gModulo := TdmListasRestringidas.Create(Self);
6: gModulo := TdmMonedasCotizaciones.Create(Self);
8: gModulo := TdmPuestos.Create(Self);
9: gModulo := TdmEstablecimientos.Create(Self);
10: gModulo := TdmCapacitacion.Create(Self);
11: gModulo := TdmProductos.Create(Self);
12: gModulo := TdmMarcas.Create(Self);
13: gModulo := TdmFamilias.Create(Self);
20: gModulo := TdmPersonas.CreateWRol(Self, rNone);
21: gModulo := TdmPersonas.CreateWRol(Self, rEmpleado);
22: gModulo := TdmPersonas.CreateWRol(Self, rCliente);
23: gModulo := TdmPersonas.CreateWRol(Self, rProveedor);
24: gModulo := TdmPersonas.CreateWRol(Self, rDuenoProceso);
25: gModulo := TdmPersonas.CreateWRol(Self, rOutSourcing);
26: gModulo := TdmPersonas.CreateWRol(Self, rComisionista);
27: gModulo := TdmPersonas.CreateWRol(Self, rSocio);
28: gModulo := TdmPersonas.CreateWRol(Self, rEmisor);
29: gModulo := TdmPLDAlertasConfiguracion.Create(Self);
30: gModulo := TdmContratos.Create(Self);
31: gModulo := TdmAmortizaciones.Create(Self);
32: gModulo := TDMFacturas.CreateWMostrar(Self,True,tdFactura);
33: gModulo := TDMCuentasXCobrar.Create(Self);
34: gModulo := TdmPagos.Create(Self);
35: gModulo := TdmAplicacionesConsulta.Create(Self);
36: gModulo := TdmCotizaciones.Create(Self);
37: gModulo := TdmSeguimientoCobranza.Create(Self);
38: gModulo := TDMFacturas.CreateWMostrar(Self,True,tdNotaCredito);
39: gModulo := TdmPLDAlertas.Create(Self);
40: gModulo := TDMFacturas.CreateWMostrar(Self,True,tdCFDIPago);
50: gModulo := TdmRptAntiguedadSaldos.Create(Self);
51: gModulo := TdmEstadosCuenta.Create(Self);
52: gModulo := TdmRptInformacionContratos.Create(Self);
53: gModulo := TdmRptReporteCartera.Create(Self);
54: begin
gReport := TdmRptCobertura.Create(Self);
gReport.Title := pCaption;
gReport.Execute;
end;
55: begin
gReport := TdmRptExpedientesRecibidos.Create(Self);
gReport.Title := pCaption;
gReport.Execute;
end;
56: begin
gReport := TdmRptAnexosProductos.Create(Self);
gReport.Title := pCaption;
gReport.Execute;
end;
57: begin
gReport := TdmRptColocacionAcumulado.Create(Self);
gReport.Title := pCaption;
gReport.Execute;
end;
58: begin
gModulo := TdmBuroCredito.Create(Self);
TdmBuroCredito(gModulo).Execute;
end;
59: begin
gModulo := TdmRptPlazas.Create(Self);
end;
60: begin
gReport := TdmRptPagoAplicacionesMensual.Create(Self);
gReport.Title := pCaption;
gReport.Execute;
end;
61: gModulo := TdmMatrizRiesgo.Create(Self); //Matriz Riesgo
62: gModulo := TdmEvaluacionRiesgo.Create(Self); //Matriz Riesgo
63: gModulo := TdmPagosReales.Create(Self); //Pagos por Cliente
64: gModulo := TdmRptCFDIContabilidad.Create(Self);
65: gModulo := TdmUsuariosPerfiles.Create(Self); //Perfiles de usuario ene 18/19
end;
if Assigned(gModulo) then
begin
gModulo.ShowModule(pnlMain, pCaption);
Caption := pCaption + strSeparador + strProductName + strSeparador + strFileDescription;
end;
end;
procedure TfrmMain.actPoneFechaActualExecute(Sender: TObject);
var FrmPoneFechaActual:TFrmPoneFechaActual;
begin
inherited;
if not FileExists(ExtractFilePath(application.ExeName)+'EnProduccion.txt') then //Oct 4/17
begin
FrmPoneFechaActual:=TFrmPoneFechaActual.Create(self);
FrmPoneFechaActual.ShowModal;
FrmPoneFechaActual.Free;
end
else
Showmessage('En Produccion No es posible cambiar de fecha'); //Oct 4/17
end;
procedure TfrmMain.ConfigControls;
begin
inherited;
// actCFDI.Enabled:= Conected and _dmConection.EnabledAction(actCFDI.Tag);
actUbicaciones.Enabled := Conected;
actBancos.Enabled := Conected;
actMonedas.Enabled := Conected;
actMonedasCotizaciones.Enabled := Conected;
actListasRestringidas.Enabled := Conected;
actPuestos.Enabled := Conected;
actCapacitaciones.Enabled := Conected;
actPlazasTurnos.Enabled := Conected;
actEstablecimientos.Enabled := Conected;
actProductos.Enabled := Conected;
actMarcas.Enabled := Conected;
actFamilias.Enabled := Conected;
actProductosTipos.Enabled := Conected;
actPersonas.Enabled := Conected;
actEmpleados.Enabled := Conected;
actClientes.Enabled := Conected;
actProveedores.Enabled := Conected;
actDuenoProceso.Enabled := Conected;
actOutsourcing.Enabled := Conected;
actComisionistas.Enabled := Conected;
actSocios.Enabled := Conected;
actEmisor.Enabled := Conected;
actCXCConceptos.Enabled := Conected;
actAmortizaciones.Enabled := Conected;
actCotizaciones.Enabled := Conected;
actContratos.Enabled := Conected;
actFacturacion.Enabled := Conected;
actCuentasXCobrar.Enabled := Conected;
actPagos.Enabled := Conected;
actCFDIPagos.Enabled := Conected;
actAplicacionPagos.Enabled := Conected;
actSeguimiento.Enabled := Conected;
actRptPlaza.Enabled := Conected;
actRptAntiguedadSaldos.Enabled:= Conected;
actEstadoCuenta.Enabled := Conected;
actInformacionContratos.Enabled:= Conected;
actReporteCartera.Enabled := Conected;
actRptCobertura.Enabled := Conected;
actRptExpecientes.Enabled := Conected;
actRptColocacion.Enabled := Conected;
actRptPagoAplicacionesMensual.Enabled := Conected;
actColocacionAcumulado.Enabled:= Conected;
actBuroCredito.Enabled := Conected;
actNotasCredito.Enabled := Conected;
actAlertasPLD.Enabled := Conected and _dmConection.OficialCumplimiento;
actPLDAlertasConfiguracion.Enabled := Conected and _dmConection.OficialCumplimiento;
actAgregarAlerta2.Enabled := Conected;
actAgregarAlerta3.Enabled := Conected;
actMatrizRiesgo.Enabled := Conected;
actEvaluacionRiesgo.Enabled := Conected;
actRptCFDIContabilidad.Enabled := Conected;
actPoneFechaActual.Enabled:=Conected;
actPagosPorCliente.Enabled:=Conected; //Ene 23/19
actPerfiles.Enabled:=Conected; //Ene 23/19
if conected then
UsarPermisos; // Ene 21/19
end;
procedure TfrmMain.DestroyModule;
begin
if Assigned(gModulo) then FreeAndNil(gModulo);
end;
procedure TfrmMain.dxRibbon1ApplicationMenuClick(Sender: TdxCustomRibbon;
var AHandled: Boolean);
begin
inherited;
if Conected then
dmConfiguracion.OpenDataSet
else
dmConfiguracion.CloseDataSet;
if Conected then
dmUsuarios.OpenDataSet
else
dmUsuarios.CloseDataSet;
end;
procedure TfrmMain.FormCreate(Sender: TObject);
begin
inherited;
dmUsuarios:= TdmUsuarios.Create(nil);
end;
procedure TfrmMain.FormDestroy(Sender: TObject);
begin
inherited;
FreeAndNil(dmUsuarios);
end;
procedure TfrmMain.FormShow(Sender: TObject);
begin
inherited;
dmConfiguracion.ShowModule(dxtshConfiguracion, '');
dmUsuarios.ShowModule(dxtshUsuarios, '');
if FileExists(ExtractFilePath(application.ExeName)+'EnProduccion.txt') then //Oct 4/17
begin
dxRibbonStatusBar1.Panels[2].Text:= 'PRODUCCION';
end;
end;
procedure TfrmMain.UsarPermisos;
var //Copiado de TP Ene 21/19
i, tagAux:Integer;
MenuTxt, OpcionTxt :String;
begin
MenuTxt:=_dmConection.PerMenu;
OpcionTxt:=_dmConection.PerOpcion;
for I := 0 to ComponentCount -1 do
begin
if (components[i] is TdxRibbonTab) then
begin
tagAux:=(components[i] as TdxRibbonTab).Tag; //Al inicio
(components[i] as TdxRibbonTab).visible:= (pos('|'+intToStr(tagAux)+'|', MenuTxt)>0) or(pos(intToStr(tagAux)+'|', MenuTxt)=1);
end; //Para evitar lo que van fijos
if (components[i] is TdxBarLargeButton) and ((components[i] as TdxBarLargeButton).Tag<>-1) then
begin
tagAux:=(components[i] as TdxBarLargeButton).Tag;
(components[i] as TdxBarLargeButton).enabled:= (pos('|'+intToStr(tagAux)+'|', OpcionTxt)>0) or(pos(intToStr(tagAux)+'|', OpcionTxt)=1);
end;
end;
end;
end.
| 37.461856 | 142 | 0.723595 |
fccf25cb30ecaaffa48597cb6a53deee0d14c3fd | 1,783 | pas | Pascal | Source/Logger/DDuce.Logger.Factories.pas | beNative/dduce | cedbe2e847cc49fe8bcd5ba12b76327eee43d639 | [
"Apache-2.0"
]
| 52 | 2015-03-17T16:34:08.000Z | 2022-03-16T12:06:09.000Z | Source/Logger/DDuce.Logger.Factories.pas | beNative/dduce | cedbe2e847cc49fe8bcd5ba12b76327eee43d639 | [
"Apache-2.0"
]
| 2 | 2016-06-04T11:26:16.000Z | 2018-07-11T04:14:16.000Z | Source/Logger/DDuce.Logger.Factories.pas | beNative/dduce | cedbe2e847cc49fe8bcd5ba12b76327eee43d639 | [
"Apache-2.0"
]
| 10 | 2015-03-25T06:12:24.000Z | 2019-11-13T13:20:27.000Z | {
Copyright (C) 2013-2021 Tim Sinaeve tim.sinaeve@gmail.com
Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
}
{$I .\..\DDuce.inc}
unit DDuce.Logger.Factories;
interface
uses
DDuce.Logger.Interfaces;
type
TLoggerFactories = class sealed
class function CreateLogger: ILogger;
class function CreateWinipcChannel: IWinipcChannel;
class function CreateZmqChannel: IZmqChannel;
class function CreateMqttChannel: IMqttChannel;
class function CreateLogFileChannel(AFileName: string = ''): ILogFileChannel;
end;
implementation
uses
DDuce.Logger.Base, DDuce.Logger.Channels.Winipc, DDuce.Logger.Channels.Zmq,
{DDuce.Logger.Channels.Mqtt,} DDuce.Logger.Channels.LogFile;
class function TLoggerFactories.CreateLogger: ILogger;
begin
Result := TLogger.Create;
end;
class function TLoggerFactories.CreateMqttChannel: IMqttChannel;
begin
// Result := TMQTTChannel.Create;
end;
class function TLoggerFactories.CreateWinipcChannel: IWinipcChannel;
begin
Result := TWinipcChannel.Create;
end;
class function TLoggerFactories.CreateZmqChannel: IZmqChannel;
begin
Result := TZmqChannel.Create;
end;
class function TLoggerFactories.CreateLogFileChannel(AFileName: string)
: ILogFileChannel;
begin
Result := TLogFileChannel.Create(AFileName);
end;
end.
| 25.84058 | 81 | 0.779024 |
478560f86bfe92b8b443e84d37d83e21ba7939e8 | 203 | pas | Pascal | desktop/MODEL/u_viajem.pas | rpcajr/TransporteApp | 665555340d8cd49ce875d672a5b043fc31c6e4db | [
"MIT"
]
| 1 | 2021-05-12T23:09:21.000Z | 2021-05-12T23:09:21.000Z | desktop/MODEL/u_viajem.pas | bravesoftdz/TransporteApp | 4e298ec94e4c02455f5b1b9e38aa36a0869b01c0 | [
"MIT"
]
| null | null | null | desktop/MODEL/u_viajem.pas | bravesoftdz/TransporteApp | 4e298ec94e4c02455f5b1b9e38aa36a0869b01c0 | [
"MIT"
]
| 2 | 2021-03-12T00:39:19.000Z | 2021-05-12T23:09:22.000Z | unit U_Viajem;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils;
type
TViajem = class
cpf: string;
Data: TDateTime;
tipo: integer;
obs: integer;
end;
implementation
end.
| 9.227273 | 20 | 0.640394 |
fc57b070fb209d02f2871e874b9d9026af23ee88 | 2,304 | pas | Pascal | cpm_1998/disk1/park.pas | mteletin/hc2000 | 502a980fdd539fbe3458b88f264ec38ceb1bcd14 | [
"MIT"
]
| 1 | 2020-12-06T05:31:27.000Z | 2020-12-06T05:31:27.000Z | cpm_1998/disk1/park.pas | mteletin/hc2000 | 502a980fdd539fbe3458b88f264ec38ceb1bcd14 | [
"MIT"
]
| null | null | null | cpm_1998/disk1/park.pas | mteletin/hc2000 | 502a980fdd539fbe3458b88f264ec38ceb1bcd14 | [
"MIT"
]
| null | null | null | type tip=string[200];tpi=char;
var f,f1:text;c:char;h,j,x,y,n,k:integer;s,m:tip;
procedure hal;begin writeln('Reading $$$.SUB...');
halt;end;
procedure cop(s1,s2:tip);var f1,f2:text;c:char;begin
assign(f1,s1);assign(f2,s2);reset(f1);rewrite(f2);
while not(eof(f1)) do begin read(f1,c);write(f2,c);end;
close(f1);close(f2);end;
procedure commandprompt;begin
if h=0 then begin assign(f,'$$$.sub');rename(f,'BACKUP.PRK');end;
end;
procedure restoresub;begin
if j=0 then begin assign(f,'BACKUP.PRK');rename(f,'$$$.sub');end;
end;
procedure restore;begin
assign(f,'AUTO.SUB');rename(f,'PARK.TMP');
assign(f,'AUTO.OLD');rename(f,'AUTO.SUB');
assign(f,'PARK.TMP');rename(f,'AUTO.OLD');
end;
procedure specify;
begin write('Input the name of SUB-file:');readln(s);
assign(f,s); {$i-} reset(f); {$i+} x:=0;
if ioresult<>0 then x:=1;close(f);if x=1 then
writeln('File:',s,' does not exists!')
else begin if k=1 then begin assign(f,'auto.old');erase(f);end;
assign(f,'AUTO.SUB');rename(f,'AUTO.OLD');assign(f1,'AUTO.SUB');
assign(f,s);reset(f);rewrite(f1);while not(eof(f)) do begin
read(f,c);write(f1,c);end;close(f);close(f1);end;end;
begin
repeat
assign(f,'AUTO.SUB'); {$i-} reset(f); {$i+}
if ioresult<>0 then begin writeln('AUTO.SUB is missing!');
writeln('PARK cannot run without this file...');halt;end;
assign(f,'BACKUP.PRK');j:=0;
{$i-} reset(f); {$i+} if ioresult<>0 then j:=1;
assign(f,'AUTO.OLD');
{$i-} reset(f); {$i+} k:=1;if ioresult<>0 then k:=0;
assign(f,'$$$.sub');h:=0;
{$i-} reset(f); {$i+} if ioresult<>0 then h:=2;
clrscr;
writeln('CP/M 2.22 Startup menu:');writeln;
writeln('1.Command prompt only');
writeln('2.Continue with current configuration');
if j=0 then writeln('3.Reinstall PARK');
writeln('4.Install a specified SUB-file');
if k=1 then writeln('0.Restore old AUTO.SUB');
close(f);writeln;
if k=1 then
writeln('WARNING! File AUTO.OLD existence confirmed!');
write('Option:');
repeat
repeat read(kbd,c);write(c,chr(8));
until (c>='0')and(c<='9');
until (c<>'0')or(k=1);
writeln(c);
if c='1' then begin commandprompt;hal;end;
if c='2' then hal;
if c='3' then restoresub;
if c='0' then restore;
if c='4' then specify;
until false;
end. | 32.450704 | 68 | 0.627604 |
fc7fe52950d946a95058cc6190261668f96368ff | 2,540 | dpr | Pascal | Premium Suite/Delphi/Convert PDF To JPEG with PDF Renderer SDK/PdfToJpeg.dpr | atkins126/ByteScout-SDK-SourceCode | cc4bc9e779ad95f85be0a8630c17878006059684 | [
"Apache-2.0"
]
| 24 | 2017-01-13T13:43:21.000Z | 2021-12-23T07:57:19.000Z | Premium Suite/Delphi/Convert PDF To JPEG with PDF Renderer SDK/PdfToJpeg.dpr | atkins126/ByteScout-SDK-SourceCode | cc4bc9e779ad95f85be0a8630c17878006059684 | [
"Apache-2.0"
]
| 1 | 2017-03-29T08:22:18.000Z | 2017-05-13T12:27:02.000Z | Premium Suite/Delphi/Convert PDF To JPEG with PDF Renderer SDK/PdfToJpeg.dpr | atkins126/ByteScout-SDK-SourceCode | cc4bc9e779ad95f85be0a8630c17878006059684 | [
"Apache-2.0"
]
| 35 | 2016-08-03T19:15:44.000Z | 2022-03-27T16:38:58.000Z | //*******************************************************************
// ByteScout PDF Renderer SDK
//
// Copyright © 2020 ByteScout - http://www.bytescout.com
// ALL RIGHTS RESERVED
//
//*******************************************************************
{
IMPORTANT NOTICE for DELPHI 2007, Delphi 2006 or earlier versions:
-----------------------------------------------------------------------
Usual approach with type library import (so called "early binding") will crash with "stackoverflow" or "floating point error" due to issues in this versions of Delphi.
SOLUTION: Please use so called "late binding" that requires NO type library import and works by creating objects at the runtime like this:
// -----------------
program Project1;
uses
SysUtils,
ComObj,
ActiveX;
var
extractor: Variant;
begin
CoInitialize(nil);
// Create and initialize
extractor := CreateOleObject('Bytescout.PDFExtractor.CSVExtractor') ;
// as usual
extractor.LoadDocumentFromFile ('../../sample3.pdf');
// …
// destroy the object by setting to varEmpty
extractor := varEmpty;
end.
// -----------------
}
program PdfToJpeg;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
ComObj,
ActiveX;
var
renderer: Variant;
renderingResolution: Integer;
outputImageFormat: Integer;
pageIndex: Integer;
begin
try
CoInitialize(nil);
// Create and initialize Bytescout.PDFRenderer.RasterRenderer object
renderer := CreateOleObject('Bytescout.PDFRenderer.RasterRenderer');
renderer.RegistrationName := 'demo';
renderer.RegistrationKey := 'demo';
// Load sample PDF document
renderer.LoadDocumentFromFile('..\..\multipage.pdf');
// Render PDF document at 96 DPI - default PC display resolution
// To get higher quality output, set 200, 300 or more
renderingResolution := 96;
// Image format: 0 - BMP; 1 - JPEG; 2 - PNG; 3 - TIFF; 4 - GIF
outputImageFormat := 1;
// Iterate through pages
for pageIndex := 0 to renderer.GetPageCount - 1 do
begin
// Render document page to JPEG image file
renderer.Save('page' + IntToStr(pageIndex) + '.jpg', outputImageFormat, pageIndex, renderingResolution);
end;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.
| 29.195402 | 169 | 0.56378 |
47c5c1eb38e0e61e6138e33509a8fbe0ac468ad3 | 7,264 | dfm | Pascal | windows/src/ext/jedi/jvcl/jvcl/examples/JvPackageModify/PackageModifierMainForm.dfm | bravogeorge/keyman | c0797e36292de903d7313214d1f765e3d9a2bf4d | [
"MIT"
]
| 219 | 2017-06-21T03:37:03.000Z | 2022-03-27T12:09:28.000Z | windows/src/ext/jedi/jvcl/jvcl/examples/JvPackageModify/PackageModifierMainForm.dfm | bravogeorge/keyman | c0797e36292de903d7313214d1f765e3d9a2bf4d | [
"MIT"
]
| 4,451 | 2017-05-29T02:52:06.000Z | 2022-03-31T23:53:23.000Z | windows/src/ext/jedi/jvcl/jvcl/examples/JvPackageModify/PackageModifierMainForm.dfm | bravogeorge/keyman | c0797e36292de903d7313214d1f765e3d9a2bf4d | [
"MIT"
]
| 72 | 2017-05-26T04:08:37.000Z | 2022-03-03T10:26:20.000Z | object PackageModifierMainFrm: TPackageModifierMainFrm
Left = 354
Top = 190
Width = 432
Height = 484
Caption = 'Package modifier'
Color = clBtnFace
Constraints.MinHeight = 480
Constraints.MinWidth = 430
DefaultMonitor = dmDesktop
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Shell Dlg 2'
Font.Style = []
OldCreateOrder = False
Position = poScreenCenter
Scaled = False
OnCloseQuery = FormCloseQuery
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object PageControl1: TPageControl
Left = 8
Top = 8
Width = 406
Height = 389
ActivePage = tabOptions
Anchors = [akLeft, akTop, akRight, akBottom]
object tabOptions: TTabSheet
Caption = 'Options'
object GroupBox1: TGroupBox
Left = 16
Top = 16
Width = 185
Height = 73
Caption = ' Build options '
TabOrder = 0
object rbImplicitBuildOff: TRadioButton
Left = 16
Top = 46
Width = 113
Height = 17
Caption = 'Explicit rebuild'
Checked = True
TabOrder = 0
TabStop = True
end
object rbImplicitBuildOn: TRadioButton
Left = 16
Top = 24
Width = 113
Height = 17
Caption = 'Rebuild as needed'
TabOrder = 1
end
end
object GroupBox2: TGroupBox
Left = 16
Top = 96
Width = 185
Height = 81
Caption = ' Code generation '
TabOrder = 1
object ckhOptimization: TCheckBox
Left = 16
Top = 24
Width = 97
Height = 17
Caption = 'Optimization'
Checked = True
State = cbChecked
TabOrder = 0
end
object chkStackFrames: TCheckBox
Left = 16
Top = 40
Width = 145
Height = 17
Caption = 'Stack frames'
TabOrder = 1
end
object chkSafeDivide: TCheckBox
Left = 16
Top = 56
Width = 129
Height = 17
Caption = 'Pentium safe FDIV'
TabOrder = 2
end
end
object GroupBox3: TGroupBox
Left = 16
Top = 184
Width = 185
Height = 153
Caption = ' Syntax options '
TabOrder = 2
object chkVarStringChecks: TCheckBox
Left = 16
Top = 24
Width = 97
Height = 17
Caption = 'Strict var-strings'
Checked = True
State = cbChecked
TabOrder = 0
end
object chkBoolEval: TCheckBox
Left = 16
Top = 40
Width = 145
Height = 17
Caption = 'Complete boolean eval'
TabOrder = 1
end
object chkExtendedSyntax: TCheckBox
Left = 16
Top = 56
Width = 129
Height = 17
Caption = 'Extended syntax'
Checked = True
State = cbChecked
TabOrder = 2
end
object chkTypedAddress: TCheckBox
Left = 16
Top = 72
Width = 137
Height = 17
Caption = 'Typed @ operator'
TabOrder = 3
end
object chkOpenStrings: TCheckBox
Left = 16
Top = 88
Width = 137
Height = 17
Caption = 'Open parameters'
Checked = True
State = cbChecked
TabOrder = 4
end
object chkLongStrings: TCheckBox
Left = 16
Top = 104
Width = 97
Height = 17
Caption = 'Huge strings'
Checked = True
State = cbChecked
TabOrder = 5
end
object chkWriteableConst: TCheckBox
Left = 16
Top = 120
Width = 153
Height = 17
Caption = 'Assignable typed constants'
Checked = True
State = cbChecked
TabOrder = 6
end
end
object GroupBox4: TGroupBox
Left = 208
Top = 16
Width = 185
Height = 81
Caption = ' Runtime errors '
TabOrder = 3
object chkOverflowChecks: TCheckBox
Left = 16
Top = 56
Width = 129
Height = 17
Caption = 'Overflow checking'
TabOrder = 2
end
object chkIOChecks: TCheckBox
Left = 16
Top = 40
Width = 145
Height = 17
Caption = 'I/O checking'
Checked = True
State = cbChecked
TabOrder = 1
end
object chkRangeChecks: TCheckBox
Left = 16
Top = 24
Width = 97
Height = 17
Caption = 'Range checking'
TabOrder = 0
end
end
object GroupBox5: TGroupBox
Left = 208
Top = 104
Width = 185
Height = 97
Caption = ' Debugging '
TabOrder = 4
object chkDebugInfo: TCheckBox
Left = 16
Top = 24
Width = 113
Height = 17
Caption = 'Debug information'
TabOrder = 0
end
object chkLocalSymbols: TCheckBox
Left = 16
Top = 40
Width = 145
Height = 17
Caption = 'Local symbols'
TabOrder = 1
end
object chkReferenceInfo: TCheckBox
Left = 16
Top = 56
Width = 129
Height = 17
Caption = 'Reference info'
TabOrder = 2
end
object chkAssertions: TCheckBox
Left = 16
Top = 72
Width = 145
Height = 17
Caption = 'Assertions'
TabOrder = 3
end
end
end
object tabFiles: TTabSheet
Caption = 'Files'
ImageIndex = 1
object reFiles: TRichEdit
Left = 8
Top = 16
Width = 381
Height = 289
Anchors = [akLeft, akTop, akRight, akBottom]
ScrollBars = ssBoth
TabOrder = 0
WordWrap = False
OnChange = reFilesChange
end
object btnAdd: TButton
Left = 24
Top = 312
Width = 75
Height = 25
Anchors = [akLeft, akBottom]
Caption = '&Add...'
TabOrder = 1
OnClick = btnAddClick
end
end
end
object btnOK: TButton
Left = 248
Top = 416
Width = 75
Height = 25
Anchors = [akRight, akBottom]
Caption = 'OK'
Default = True
Enabled = False
ModalResult = 1
TabOrder = 1
OnClick = btnOKClick
end
object btnCancel: TButton
Left = 328
Top = 416
Width = 75
Height = 25
Anchors = [akRight, akBottom]
Cancel = True
Caption = 'Close'
ModalResult = 2
TabOrder = 2
OnClick = btnCancelClick
end
object OpenDialog1: TOpenDialog
DefaultExt = 'dpk'
Filter = 'Package files|*.dpk;bpk|All files|*.*'
InitialDir = '.'
Options = [ofHideReadOnly, ofAllowMultiSelect, ofPathMustExist, ofFileMustExist, ofNoReadOnlyReturn, ofEnableSizing]
Title = 'Select packages to modify'
Left = 276
Top = 304
end
end
| 24.05298 | 120 | 0.507296 |
fcb8001c9af14fd33a41c1bc729818bd2f284859 | 405 | lpr | Pascal | 01_INTRO/04_EJERCICIOS/01_HIPOTENUSA/hipotenusa.lpr | RafaelMalgor/AlgoritmosUTNFRCU | ca972e8644e1ab3b9e689e1ba50dcb3fb1cfb40c | [
"MIT"
]
| null | null | null | 01_INTRO/04_EJERCICIOS/01_HIPOTENUSA/hipotenusa.lpr | RafaelMalgor/AlgoritmosUTNFRCU | ca972e8644e1ab3b9e689e1ba50dcb3fb1cfb40c | [
"MIT"
]
| null | null | null | 01_INTRO/04_EJERCICIOS/01_HIPOTENUSA/hipotenusa.lpr | RafaelMalgor/AlgoritmosUTNFRCU | ca972e8644e1ab3b9e689e1ba50dcb3fb1cfb40c | [
"MIT"
]
| null | null | null | program hipotenusa;
uses crt;
var
cateto_opuesto:real;
cateto_adyacente:real;
resultado:real;
begin
write('Ingrese el cateto adyacente: ');
readln(cateto_adyacente);
write('Ingrese el cateto opuesto: ');
readln(cateto_opuesto);
resultado:=sqrt(cateto_opuesto*cateto_opuesto+cateto_adyacente*cateto_adyacente);
write('La hipotenusa es: ', resultado:0:4);
readkey;
end.
| 23.823529 | 84 | 0.725926 |
fcbd8f35e45960a721e9c03f55bd51c5da31ab1c | 18,009 | pas | Pascal | Delphi/Lib/lz4/lz4io.pas | ebakoJP/SimpleBSAExtractor | 2a7be77f605b5ab7c47e45133a99bd380c47360e | [
"BSD-2-Clause",
"MIT"
]
| 3 | 2020-07-26T01:10:04.000Z | 2021-06-27T13:37:39.000Z | Delphi/Lib/lz4/lz4io.pas | ebakoJP/SimpleBSAExtractor | 2a7be77f605b5ab7c47e45133a99bd380c47360e | [
"BSD-2-Clause",
"MIT"
]
| null | null | null | Delphi/Lib/lz4/lz4io.pas | ebakoJP/SimpleBSAExtractor | 2a7be77f605b5ab7c47e45133a99bd380c47360e | [
"BSD-2-Clause",
"MIT"
]
| 1 | 2020-07-26T01:10:06.000Z | 2020-07-26T01:10:06.000Z | (*
LZ4Delphi
Copyright (C) 2015, Jose Pascoa (atelierwebgm@gmail.com)
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
*************************************************************************
LZ4 - Fast LZ compression algorithm
xxHash - Fast Hash algorithm
LZ4 source repository : http://code.google.com/p/lz4/
xxHash source repository : http://code.google.com/p/xxhash/
Copyright (c) 2011-2014, Yann Collet
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
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.
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.
******************************************************************************
*)
unit lz4io;
{$POINTERMATH ON}
interface
uses Windows, Classes, SysUtils, Math, lz4frame_static, xxHash, lz4, lz4common, lz4frame, lz4HC;
const
LZ4_BLOCKSIZEID_DEFAULT = 7;
ENDOFSTREAM = uint64(-1);
LZ4S_MAGICNUMBER = $184D2204;
LZ4S_SKIPPABLE0 = $184D2A50;
LZ4S_SKIPPABLEMASK = $FFFFFFF0;
LEGACY_MAGICNUMBER = $184C2102;
MAGICNUMBER_SIZE = 4;
LEGACY_BLOCKSIZE = 8388608;
MIN_STREAM_BUFSIZE = 196608;
var
lz4_overwrite_file: boolean = true;
globalblockSizeID: integer = LZ4_BLOCKSIZEID_DEFAULT;
blockIndependence: integer = 1;
streamChecksum: integer = 1;
function LZ4IO_compressFilename_Legacy(input_filename: string; output_filename: string; compressionLevel: integer): integer;
function LZ4IO_compressFilename(input_filename: string; output_filename: string; compressionLevel: integer): integer;
function LZ4IO_decompressFilename(input_filename: string; output_filename: string): integer;
procedure lz4DecompressToUserBuf(const InBuf: Pointer; InBytes: Integer;
const OutBuf: Pointer; BufSize: Integer);
implementation
const
minBlockSizeID: integer = 4;
maxBlockSizeID: integer = 7;
function reportError(err: string): integer;
begin
//LZ4Client.Memo.Lines.Add(err);
result := 0;
end;
procedure LZ4IO_writeLE32(p: pointer; value32: cardinal);
var
dstPtr: pByte;
begin
dstPtr := p;
dstPtr[0] := byte(value32);
dstPtr[1] := byte(value32 shr 8);
dstPtr[2] := byte(value32 shr 16);
dstPtr[3] := byte(value32 shr 24);
end;
function LZ4IO_compressFilename_Legacy(input_filename: string; output_filename: string; compressionLevel: integer): integer;
type
TCompressionFunction =
function(c1: pAnsiChar; c2: pAnsiChar; c3: integer): integer;
var
compressionFunction: TCompressionFunction;
filesize: uint64;
compressedfilesize: uint64;
in_buff: pAnsiChar;
out_buff: pAnsiChar;
fileIn: TFileSTream;
fileOut: TFileSTream;
sizeCheck: size_t;
outSize, inSize: cardinal;
begin
filesize := 0;
compressedfilesize := MAGICNUMBER_SIZE;
if (compressionLevel < 3) then
compressionFunction := LZ4_compress
else
compressionFunction := LZ4_compressHC;
fileIn := TFileSTream.Create(input_filename, fmOpenRead);
fileOut := TFileSTream.Create(output_filename, fmCreate);
in_buff := allocmem(LEGACY_BLOCKSIZE);
out_buff := allocmem(LZ4_compressBound(LEGACY_BLOCKSIZE));
try
if (in_buff = nil) or (out_buff = nil) then
exit(reportError('Allocation error : not enough memory'));
LZ4IO_writeLE32(out_buff, LEGACY_MAGICNUMBER);
sizeCheck := fileOut.Write(out_buff^, MAGICNUMBER_SIZE);
if sizeCheck <> MAGICNUMBER_SIZE then
exit(reportError('Write error : cannot write header'));
while true do
begin
inSize := fileIn.Read(in_buff^, LEGACY_BLOCKSIZE);
if inSize <= 0 then
break;
inc(filesize, inSize);
outSize := compressionFunction(in_buff, out_buff + 4, inSize);
inc(compressedfilesize, outSize + 4);
LZ4IO_writeLE32(out_buff, outSize);
sizeCheck := fileOut.Write(out_buff^, outSize + 4);
if sizeCheck <> size_t(outSize + 4) then
exit(reportError('Write error : cannot write compressed block'));
end;
finally
if in_buff <> nil then
freemem(in_buff);
if out_buff <> nil then
freemem(out_buff);
fileIn.Free;
fileOut.Free;
result := 0;
end;
end;
function LZ4IO_setBlockSizeID(bsid: integer): integer;
const
blockSizeTable: array [0 .. 3] of integer = (65536, 262144, 1048576, 4194304);
begin
if (bsid < minBlockSizeID) or (bsid > maxBlockSizeID) then
exit(-1);
globalblockSizeID := bsid;
result := blockSizeTable[globalblockSizeID - minBlockSizeID];
end;
function LZ4IO_compressFilename(input_filename: string; output_filename: string; compressionLevel: integer): integer;
var
filesize: uint64;
errorCode: LZ4F_errorCode_t;
ctx: PLZ4F_compressionContext_t;
blockSize: integer;
fileIn: TFileSTream;
fileOut: TFileSTream;
prefs: LZ4F_preferences_t;
in_buff: pAnsiChar;
out_buff: pAnsiChar;
outBuffSize: size_t;
headerSize: size_t;
sizeCheck: size_t;
readSize: size_t;
outSize: size_t;
begin
result := 0;
filesize := 0;
errorCode := LZ4F_createCompressionContext(ctx, LZ4F_VERSION);
if (LZ4F_isError(errorCode)) then
exit(reportError(format('Allocation error : can''t create LZ4F context: %s', [LZ4F_getErrorName(errorCode)])));
fileIn := TFileSTream.Create(input_filename, fmOpenRead);
fileOut := TFileSTream.Create(output_filename, fmCreate);
blockSize := 1 shl (8 + 2 * globalblockSizeID);
fillchar(prefs, sizeof(LZ4F_preferences_t), 0);
prefs.autoFlush := 1;
prefs.compressionLevel := compressionLevel;
prefs.frameInfo.blockMode := blockMode_t(blockIndependence);
prefs.frameInfo.blockSizeID := blockSizeID_t(globalblockSizeID);
prefs.frameInfo.contentChecksumFlag := contentChecksum_t(streamChecksum);
// Allocate Memory
in_buff := allocmem(blockSize);
outBuffSize := LZ4F_compressBound(blockSize, @prefs);
out_buff := allocmem(outBuffSize);
try
if (in_buff = nil) or (out_buff = nil) then
exit(reportError('Allocation error : not enough memory'));
// Write Archive Header
headerSize := LZ4F_compressBegin(ctx, out_buff, outBuffSize, @prefs);
if (LZ4F_isError(headerSize)) then
exit(reportError(format('File header generation failed: %s', [LZ4F_getErrorName(errorCode)])));
sizeCheck := fileOut.Write(out_buff^, headerSize);
if sizeCheck <> headerSize then
exit(reportError('Write error : cannot write header'));
readSize := fileIn.Read(in_buff^, blockSize);
inc(filesize, readSize);
while readSize > 0 do
begin
outSize := LZ4F_compressUpdate(ctx, out_buff, outBuffSize, in_buff, readSize, Nil);
if (LZ4F_isError(outSize)) then
exit(reportError(format('Compression failed: %s', [LZ4F_getErrorName(errorCode)])));
sizeCheck := fileOut.Write(out_buff^, outSize);
if sizeCheck <> outSize then
exit(reportError('Write error : cannot write compressed block'));
readSize := fileIn.Read(in_buff^, blockSize);
inc(filesize, readSize);
end;
// End of Stream mark
headerSize := LZ4F_compressEnd(ctx, out_buff, outBuffSize, Nil);
if LZ4F_isError(headerSize) then
exit(reportError(format('End of file generation failed: %s', [LZ4F_getErrorName(errorCode)])));
sizeCheck := fileOut.Write(out_buff^, headerSize);
if sizeCheck <> headerSize then
exit(reportError('Write error : cannot write end of stream'));
errorCode := LZ4F_freeCompressionContext(ctx);
if LZ4F_isError(errorCode) then
exit(reportError(format('Error : can''t free LZ4F context resource: %s', [LZ4F_getErrorName(errorCode)])));
finally
if in_buff <> nil then
freemem(in_buff);
if out_buff <> nil then
freemem(out_buff);
fileIn.Free;;
fileOut.Free;
end;
end;
function LZ4IO_readLE32(s: pointer): cardinal;
var
srcPtr: pByte;
value32: cardinal;
begin
srcPtr := s;
value32 := srcPtr[0];
inc(value32, (srcPtr[1] shl 8));
inc(value32, (srcPtr[2] shl 16));
inc(value32, (srcPtr[3] shl 24));
result := value32;
end;
function LZ4S_isSkippableMagicNumber(magic: cardinal): boolean;
begin
result := (magic and LZ4S_SKIPPABLEMASK) = LZ4S_SKIPPABLE0;
end;
function decodeLZ4S(finput, foutput: TSTream): uint64;
const
HEADERMAX = 20;
var
filesize: uint64;
inBuff: pAnsiChar;
outBuff: pAnsiChar;
headerBuff: array [0 .. HEADERMAX - 1] of ansiChar;
sizeCheck, nextToRead, outBuffSize, inBuffSize: size_t;
ctx: PLZ4F_decompressionContext_t;
errorCode: LZ4F_errorCode_t;
frameInfo: LZ4F_frameInfo_t;
decodedBytes: size_t;
begin
filesize := 0;
errorCode := LZ4F_createDecompressionContext(ctx, LZ4F_VERSION);
if LZ4F_isError(errorCode) then
exit(reportError(format('Allocation error : can''t create context: %s', [LZ4F_getErrorName(errorCode)])));
LZ4IO_writeLE32(@headerBuff, LZ4S_MAGICNUMBER);
outBuffSize := 0;
inBuffSize := 0;
sizeCheck := MAGICNUMBER_SIZE;
nextToRead := LZ4F_decompress(ctx, Nil, @outBuffSize, @headerBuff, @sizeCheck, Nil);
if LZ4F_isError(nextToRead) then
exit(reportError(format('Decompression error: %s', [LZ4F_getErrorName(errorCode)])));
if nextToRead > HEADERMAX then
exit(reportError(format('Header too large (%d>%d)', [integer(nextToRead), HEADERMAX])));
sizeCheck := finput.Read(headerBuff, nextToRead);
if sizeCheck <> nextToRead then
exit(reportError('Read error'));
nextToRead := LZ4F_decompress(ctx, Nil, @outBuffSize, @headerBuff, @sizeCheck, Nil);
errorCode := LZ4F_getFrameInfo(ctx, @frameInfo, Nil, @inBuffSize);
if LZ4F_isError(errorCode) then
exit(reportError(format('can''t decode frame header: %s', [LZ4F_getErrorName(errorCode)])));
outBuffSize := LZ4IO_setBlockSizeID(integer(frameInfo.blockSizeID));
inBuffSize := outBuffSize + 4;
inBuff := allocmem(inBuffSize);
outBuff := allocmem(outBuffSize);
try
if (inBuff = nil) or (outBuff = nil) then
exit(reportError('Allocation error : not enough memory'));
while (nextToRead <> 0) do
begin
decodedBytes := outBuffSize;
sizeCheck := finput.Read(inBuff^, nextToRead);
if sizeCheck <> nextToRead then
exit(reportError('Read error'));
errorCode := LZ4F_decompress(ctx, outBuff, @decodedBytes, inBuff, @sizeCheck, Nil);
if LZ4F_isError(errorCode) then
exit(reportError(format('Decompression error: %s', [LZ4F_getErrorName(errorCode)])));
if sizeCheck <> nextToRead then
exit(reportError('Synchronization error'));
nextToRead := errorCode;
inc(filesize, decodedBytes);
sizeCheck := foutput.Write(outBuff^, decodedBytes);
if sizeCheck <> decodedBytes then
exit(reportError('Write error : cannot write decoded block'));
end;
errorCode := LZ4F_freeDecompressionContext(ctx);
if LZ4F_isError(errorCode) then
exit(reportError(format('Error : can''t free LZ4F context resource: %s', [LZ4F_getErrorName(errorCode)])));
finally
if inBuff <> nil then
freemem(inBuff);
if outBuff <> nil then
freemem(outBuff);
result := filesize;
end;
end;
function decodeLegacyStream(finput, foutput: TSTream): uint64;
var
filesize: uint64;
in_buff: pAnsiChar;
out_buff: pAnsiChar;
decodeSize: integer;
sizeCheck: size_t;
blockSize: cardinal;
begin
filesize := 0;
in_buff := allocmem(LZ4_compressBound(LEGACY_BLOCKSIZE));
out_buff := allocmem(LEGACY_BLOCKSIZE);
try
if (in_buff = nil) or (out_buff = nil) then
exit(reportError('Allocation error : not enough memory'));
while true do
begin
sizeCheck := finput.Read(in_buff^, 4);
if sizeCheck = 0 then
break;
blockSize := LZ4IO_readLE32(in_buff);
if blockSize > LZ4_compressBound(LEGACY_BLOCKSIZE) then
begin
finput.Seek(-4, soFromCurrent);
break;
end;
sizeCheck := finput.Read(in_buff^, blockSize);
if sizeCheck <> blockSize then
exit(reportError('Error reading input file'));
decodeSize := LZ4_decompress_safe(in_buff, out_buff, blockSize, LEGACY_BLOCKSIZE);
if (decodeSize < 0) then
exit(reportError('Decoding Failed ! Corrupted input detected'));
inc(filesize, decodeSize);
sizeCheck := foutput.Write(out_buff^, decodeSize);
if sizeCheck <> size_t(decodeSize) then
exit(reportError('Write error : cannot write decoded block into output'));
end;
finally
if in_buff <> nil then
freemem(in_buff);
if out_buff <> nil then
freemem(out_buff);
result := filesize;
end;
end;
function selectDecoder(finput, foutput: TSTream): uint64;
var
nbReadBytes: size_t;
U32Store: array [0 .. MAGICNUMBER_SIZE - 1] of byte;
magicNumber, Size: cardinal;
newPos: uint64;
begin
nbReadBytes := finput.Read(U32Store, MAGICNUMBER_SIZE);
if nbReadBytes = 0 then
exit(ENDOFSTREAM);
if nbReadBytes <> MAGICNUMBER_SIZE then
exit(reportError('Unrecognized header : Magic Number unreadable'));
magicNumber := LZ4IO_readLE32(@U32Store);
if LZ4S_isSkippableMagicNumber(magicNumber) then
magicNumber := LZ4S_SKIPPABLE0;
case magicNumber of
LZ4S_MAGICNUMBER: result := decodeLZ4S(finput, foutput);
LEGACY_MAGICNUMBER:
begin
result := decodeLegacyStream(finput, foutput);
end;
LZ4S_SKIPPABLE0:
begin
nbReadBytes := finput.Read(U32Store, 4);
if (nbReadBytes <> 4) then
exit(reportError('Stream error : skippable size unreadable'));
Size := LZ4IO_readLE32(@U32Store);
newPos := finput.Seek(Size, soFromCurrent);
if newPos <> finput.Position then
exit(reportError('Stream error : cannot skip skippable area'));
result := selectDecoder(finput, foutput);
end;
else
begin
if finput.Position = MAGICNUMBER_SIZE then
exit(reportError('Unrecognized header : file cannot be decoded'));
reportError('Stream followed by unrecognized data');
result := ENDOFSTREAM;
end;
end;
end;
function LZ4IO_decompressFilename(input_filename: string; output_filename: string): integer;
var
fileIn: TFileSTream;
fileOut: TFileSTream;
decodedSize: int64;
filesize: int64;
begin
result := 0;
filesize := 0;
fileIn := TFileSTream.Create(input_filename, fmOpenRead);
fileOut := TFileSTream.Create(output_filename, fmCreate);
repeat
decodedSize := selectDecoder(fileIn, fileOut);
if decodedSize <> ENDOFSTREAM then
inc(filesize, decodedSize);
until decodedSize = ENDOFSTREAM;
fileIn.Free;;
fileOut.Free;
end;
type
TPreallocatedMemoryStream = class(TCustomMemoryStream)
public
constructor Create(Ptr: Pointer; Size: Int64);
function Write(const Buffer; Count: Longint): Longint; override;
end;
constructor TPreallocatedMemoryStream.Create(Ptr: Pointer; Size: Int64);
begin
inherited Create;
SetPointer(Ptr, Size);
end;
function TPreallocatedMemoryStream.Write(const Buffer; Count: Integer): Longint;
begin
Result := Min(Count, Size-Position);
System.Move(Buffer, Pointer(PByte(Memory) + Position)^, Result);
Seek(Result, soCurrent);
end;
procedure lz4DecompressToUserBuf(const InBuf: Pointer; InBytes: Integer;
const OutBuf: Pointer; BufSize: Integer);
var
stin, stout: TPreallocatedMemoryStream;
decodedSize: int64;
decompressedSize: int64;
begin
stin := TPreallocatedMemoryStream.Create(InBuf, InBytes);
stout := TPreallocatedMemoryStream.Create(OutBuf, BufSize);
try
decompressedSize := 0;
repeat
decodedSize := selectDecoder(stin, stout);
if decodedSize <> ENDOFSTREAM then
Inc(decompressedSize, decodedSize);
until decodedSize = ENDOFSTREAM;
if decompressedSize <> BufSize then
Exception.Create('lz4 decompression size mismatch');
//Move(stout.Memory^, OutBuf^, BufSize);
finally
stin.Free;
stout.Free;
end;
end;
end.
| 36.828221 | 124 | 0.6665 |
470697c3edb93b3402f50f1f88cc46d0afeda4f3 | 15,953 | pas | Pascal | Source/TextEditor.Compare.ScrollBar.pas | edwinyzh/TTextEditor | d1844c5ff10fe302457b8d58348c7dbd015703e7 | [
"MIT"
]
| null | null | null | Source/TextEditor.Compare.ScrollBar.pas | edwinyzh/TTextEditor | d1844c5ff10fe302457b8d58348c7dbd015703e7 | [
"MIT"
]
| null | null | null | Source/TextEditor.Compare.ScrollBar.pas | edwinyzh/TTextEditor | d1844c5ff10fe302457b8d58348c7dbd015703e7 | [
"MIT"
]
| null | null | null | unit TextEditor.Compare.ScrollBar;
interface
uses
Winapi.Messages, System.Classes, System.Types, Vcl.Controls, TextEditor
{$IFDEF ALPHASKINS}, acSBUtils, sCommonData{$ENDIF};
type
TTextEditorCompareScrollBar = class(TCustomControl)
strict private
{$IFDEF ALPHASKINS}
FSkinData: TsScrollWndData;
{$ENDIF}
FEditorLeft: TTextEditor;
FEditorRight: TTextEditor;
FMouseDownY: Integer;
FScrollBarClicked: Boolean;
FScrollBarDragging: Boolean;
FScrollBarOffsetY: Integer;
FScrollBarTopLine: Integer;
{$IFDEF ALPHASKINS}
FScrollWnd: TacScrollWnd;
{$ENDIF}
FScrollBarVisible: Boolean;
FSystemMetricsCYDRAG: Integer;
FTopLine: Integer;
FVisibleLines: Integer;
procedure DoOnScrollBarClick(const Y: Integer);
procedure DragMinimap(const AY: Integer);
procedure FillRect(const ARect: TRect);
procedure SetEditorLeft(const AEditor: TTextEditor);
procedure SetTopLine(const AValue: Integer);
procedure WMEraseBkgnd(var AMessage: TWMEraseBkgnd); message WM_ERASEBKGND;
procedure WMPaint(var AMessage: TWMPaint); message WM_PAINT;
procedure WMSize(var AMessage: TWMSize); message WM_SIZE;
procedure WMVScroll(var AMessage: TWMScroll); message WM_VSCROLL;
protected
procedure CreateParams(var AParams: TCreateParams); override;
procedure MouseDown(AButton: TMouseButton; AShift: TShiftState; X, Y: Integer); override;
procedure MouseMove(AShift: TShiftState; X, Y: Integer); override;
procedure MouseUp(AButton: TMouseButton; AShift: TShiftState; X, Y: Integer); override;
procedure Paint; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function CanFocus: Boolean; override;
procedure AfterConstruction; override;
procedure Invalidate; override;
procedure UpdateScrollBars;
{$IFDEF ALPHASKINS}
procedure WndProc(var AMessage: TMessage); override;
property SkinData: TsScrollWndData read FSkinData write FSkinData;
{$ENDIF}
property TopLine: Integer read FTopLine write SetTopLine;
published
property Align;
property EditorLeft: TTextEditor read FEditorLeft write SetEditorLeft;
property EditorRight: TTextEditor read FEditorRight write FEditorRight;
property ScrollBarVisible: Boolean read FScrollBarVisible write FScrollBarVisible default False;
end;
implementation
uses
Winapi.Windows, System.Math, System.SysUtils, System.UITypes, Vcl.Forms, Vcl.Graphics, TextEditor.Consts,
TextEditor.Types
{$IFDEF ALPHASKINS}, Winapi.CommCtrl, sConst, sMessages, sStyleSimply, sVCLUtils{$ENDIF};
constructor TTextEditorCompareScrollBar.Create(AOwner: TComponent);
begin
{$IFDEF ALPHASKINS}
FSkinData := TsScrollWndData.Create(Self);
FSkinData.COC := COC_TsMemo;
{$ENDIF}
inherited Create(AOwner);
FScrollBarVisible := False;
Color := TColors.SysWindow;
DoubleBuffered := False;
ControlStyle := ControlStyle + [csOpaque, csSetCaption, csNeedsBorderPaint];
FSystemMetricsCYDRAG := GetSystemMetrics(SM_CYDRAG);
end;
procedure TTextEditorCompareScrollBar.CreateParams(var AParams: TCreateParams);
const
LClassStylesOff = CS_VREDRAW or CS_HREDRAW;
begin
StrDispose(WindowText);
WindowText := nil;
inherited CreateParams(AParams);
with AParams do
begin
WindowClass.Style := WindowClass.Style and not LClassStylesOff;
Style := Style or WS_BORDER or WS_CLIPCHILDREN;
if NewStyleControls and Ctl3D then
begin
Style := Style and not WS_BORDER;
ExStyle := ExStyle or WS_EX_CLIENTEDGE;
end;
end;
end;
destructor TTextEditorCompareScrollBar.Destroy;
begin
{$IFDEF ALPHASKINS}
if Assigned(FScrollWnd) then
begin
FScrollWnd.Free;
FScrollWnd := nil;
end;
if Assigned(FSkinData) then
begin
FSkinData.Free;
FSkinData := nil;
end;
{$ENDIF}
inherited Destroy;
end;
procedure TTextEditorCompareScrollBar.AfterConstruction;
begin
inherited AfterConstruction;
{$IFDEF ALPHASKINS}
if HandleAllocated then
RefreshEditScrolls(SkinData, FScrollWnd);
UpdateData(FSkinData);
{$ENDIF}
end;
procedure TTextEditorCompareScrollBar.WMEraseBkgnd(var AMessage: TWMEraseBkgnd);
begin
AMessage.Result := 1;
end;
procedure TTextEditorCompareScrollBar.WMPaint(var AMessage: TWMPaint);
var
LDC, LCompatibleDC: HDC;
LCompatibleBitmap, LOldBitmap: HBITMAP;
LPaintStruct: TPaintStruct;
begin
if AMessage.DC <> 0 then
begin
if not (csCustomPaint in ControlState) and (ControlCount = 0) then
inherited
else
PaintHandler(AMessage);
end
else
begin
LDC := GetDC(0);
LCompatibleBitmap := CreateCompatibleBitmap(LDC, ClientWidth, ClientHeight);
ReleaseDC(0, LDC);
LCompatibleDC := CreateCompatibleDC(0);
LOldBitmap := SelectObject(LCompatibleDC, LCompatibleBitmap);
try
LDC := BeginPaint(Handle, LPaintStruct);
AMessage.DC := LCompatibleDC;
WMPaint(AMessage);
BitBlt(LDC, 0, 0, ClientWidth, ClientHeight, LCompatibleDC, 0, 0, SRCCOPY);
EndPaint(Handle, LPaintStruct);
finally
SelectObject(LCompatibleDC, LOldBitmap);
DeleteObject(LCompatibleBitmap);
DeleteDC(LCompatibleDC);
end;
end;
end;
procedure TTextEditorCompareScrollBar.FillRect(const ARect: TRect);
begin
Winapi.Windows.ExtTextOut(Canvas.Handle, 0, 0, ETO_OPAQUE, ARect, '', 0, nil);
end;
procedure TTextEditorCompareScrollBar.Paint;
const
CPaleRed: TColor = $E6E6FC;
var
LClipRect: TRect;
LIndex, LLine, LHalfWidth: Integer;
LStringRecord: TTextEditorStringRecord;
begin
if not Assigned(FEditorLeft) or not Assigned(FEditorRight) then
Exit;
LClipRect := ClientRect;
Canvas.Brush.Color := FEditorLeft.Colors.Background;
FillRect(LClipRect);
if FEditorLeft.Lines.Count <> FEditorRight.Lines.Count then
Exit;
if csDesigning in ComponentState then
Exit;
Canvas.Pen.Width := 1;
Canvas.Pen.Style := psSolid;
Canvas.Pen.Color := TColors.Red;
LLine := 1;
LHalfWidth := ClientWidth div 2;
for LIndex := FScrollBarTopLine to Min(FScrollBarTopLine + ClientHeight, FEditorLeft.Lines.Count - 1) do
begin
if (LLine >= FTopLine - FScrollBarTopLine) and (LLine < FTopLine - FScrollBarTopLine + FVisibleLines) then
Canvas.Pen.Color := TColors.Red
else
Canvas.Pen.Color := CPaleRed;
LStringRecord := FEditorLeft.Lines.Items^[LIndex];
if sfModify in LStringRecord.Flags then
begin
Canvas.MoveTo(0, LLine);
Canvas.LineTo(LHalfWidth, LLine);
end;
if sfEmptyLine in LStringRecord.Flags then
begin
Canvas.MoveTo(LHalfWidth, LLine);
Canvas.LineTo(Width, LLine);
end;
LStringRecord := FEditorRight.Lines.Items^[LIndex];
if sfModify in LStringRecord.Flags then
begin
Canvas.MoveTo(LHalfWidth, LLine);
Canvas.LineTo(Width, LLine);
end;
if sfEmptyLine in LStringRecord.Flags then
begin
Canvas.MoveTo(0, LLine);
Canvas.LineTo(LHalfWidth, LLine);
end;
Inc(LLine);
end;
LClipRect.Top := FTopLine - FScrollBarTopLine;
LClipRect.Bottom := LClipRect.Top + FVisibleLines;
{$IFDEF ALPHASKINS}
Canvas.Pen.Color := SkinData.SkinManager.GetHighlightColor;
{$ELSE}
Canvas.Pen.Color := TColors.SysHighlight;
{$ENDIF}
Canvas.Brush.Style := bsClear;
Canvas.Rectangle(LClipRect);
end;
procedure TTextEditorCompareScrollBar.Invalidate;
begin
if csDesigning in ComponentState then
Exit;
if Assigned(FEditorLeft) then
FVisibleLines := FEditorLeft.VisibleLineCount;
UpdateScrollBars;
inherited Invalidate;
end;
procedure TTextEditorCompareScrollBar.WMSize(var AMessage: TWMSize);
begin
Invalidate;
end;
procedure TTextEditorCompareScrollBar.SetEditorLeft(const AEditor: TTextEditor);
begin
FEditorLeft := AEditor;
Invalidate;
end;
procedure TTextEditorCompareScrollBar.UpdateScrollBars;
var
LScrollInfo: TScrollInfo;
LVerticalMaxScroll: Integer;
begin
if ScrollBarVisible and not (csDesigning in ComponentState) then
begin
LScrollInfo.cbSize := SizeOf(ScrollInfo);
LScrollInfo.fMask := SIF_ALL;
LScrollInfo.fMask := LScrollInfo.fMask or SIF_DISABLENOSCROLL;
if Assigned(FEditorLeft) then
LVerticalMaxScroll := FEditorLeft.LineNumbersCount
else
LVerticalMaxScroll := 1;
LScrollInfo.nMin := 1;
LScrollInfo.nTrackPos := 0;
if LVerticalMaxScroll <= TEXT_EDITOR_MAX_SCROLL_RANGE then
begin
LScrollInfo.nMax := Max(1, LVerticalMaxScroll);
LScrollInfo.nPage := FVisibleLines;
LScrollInfo.nPos := TopLine;
end
else
begin
LScrollInfo.nMax := TEXT_EDITOR_MAX_SCROLL_RANGE;
LScrollInfo.nPage := MulDiv(TEXT_EDITOR_MAX_SCROLL_RANGE, FVisibleLines, LVerticalMaxScroll);
LScrollInfo.nPos := MulDiv(TEXT_EDITOR_MAX_SCROLL_RANGE, TopLine, LVerticalMaxScroll);
end;
if Assigned(FEditorLeft) and (FEditorLeft.LineNumbersCount <= FVisibleLines) then
TopLine := 1;
ShowScrollBar(Handle, SB_VERT, LScrollInfo.nMax > FVisibleLines);
SetScrollInfo(Handle, SB_VERT, LScrollInfo, True);
EnableScrollBar(Handle, SB_VERT, ESB_ENABLE_BOTH);
end
else
ShowScrollBar(Handle, SB_VERT, False);
end;
procedure TTextEditorCompareScrollBar.SetTopLine(const AValue: Integer);
var
LValue: Integer;
begin
if csDesigning in ComponentState then
Exit;
LValue := Min(AValue, FEditorLeft.LineNumbersCount - FVisibleLines + 1);
LValue := Max(LValue, 1);
if FTopLine <> LValue then
begin
FTopLine := LValue;
FScrollBarTopLine := 1;
if Assigned(FEditorLeft) then
FScrollBarTopLine := Max(FTopLine - Abs(Trunc((ClientHeight - FVisibleLines) *
(FTopLine / Max(FEditorLeft.LineNumbersCount - FVisibleLines, 1)))), 1);
if Assigned(FEditorLeft) then
FEditorLeft.TopLine := FTopLine;
if Assigned(FEditorRight) then
FEditorRight.TopLine := FTopLine;
UpdateScrollBars;
Invalidate;
end;
end;
procedure TTextEditorCompareScrollBar.MouseMove(AShift: TShiftState; X, Y: Integer);
begin
if FScrollBarClicked then
begin
if FScrollBarDragging then
begin
DragMinimap(Y);
if Assigned(FEditorLeft) then
FEditorLeft.Invalidate;
if Assigned(FEditorRight) then
FEditorRight.Invalidate;
end;
if not FScrollBarDragging and (ssLeft in AShift) and MouseCapture and (Abs(FMouseDownY - Y) >= FSystemMetricsCYDRAG) then
FScrollBarDragging := True;
Exit;
end;
inherited MouseMove(AShift, X, Y);
end;
procedure TTextEditorCompareScrollBar.MouseUp(AButton: TMouseButton; AShift: TShiftState; X, Y: Integer);
begin
FScrollBarClicked := False;
FScrollBarDragging := False;
inherited MouseUp(AButton, AShift, X, Y);
end;
procedure TTextEditorCompareScrollBar.MouseDown(AButton: TMouseButton; AShift: TShiftState; X, Y: Integer);
begin
if AButton = mbLeft then
FMouseDownY := Y;
if not FScrollBarDragging then
if InRange(X, ClientRect.Left, ClientRect.Right) then
begin
DoOnScrollBarClick(Y);
Invalidate;
Exit;
end;
inherited MouseDown(AButton, AShift, X, Y);
end;
procedure TTextEditorCompareScrollBar.DoOnScrollBarClick(const Y: Integer);
var
LNewLine, LPreviousLine, LStep: Integer;
begin
FScrollBarClicked := True;
LPreviousLine := -1;
LNewLine := Max(1, FScrollBarTopLine + Y);
if (LNewLine >= TopLine) and (LNewLine <= TopLine + FVisibleLines) then
TopLine := LNewLine
else
begin
LNewLine := LNewLine - FVisibleLines div 2;
LStep := Abs(LNewLine - TopLine) div 5;
if LNewLine < TopLine then
while LNewLine < TopLine - LStep do
begin
TopLine := TopLine - LStep;
if TopLine = LPreviousLine then
Break
else
LPreviousLine := TopLine;
Invalidate;
end
else
while LNewLine > TopLine + LStep do
begin
TopLine := TopLine + LStep;
if TopLine = LPreviousLine then
Break
else
LPreviousLine := TopLine;
Invalidate;
end;
TopLine := LNewLine;
end;
FScrollBarOffsetY := LNewLine - TopLine;
end;
procedure TTextEditorCompareScrollBar.DragMinimap(const AY: Integer);
var
LTopLine, LTemp, LTemp2: Integer;
begin
LTemp := FEditorLeft.LineNumbersCount - ClientHeight;
LTemp2 := Max(AY - FScrollBarOffsetY, 0);
FScrollBarTopLine := Max(1, Trunc((LTemp / Max(ClientHeight - FVisibleLines, 1)) * LTemp2));
if (LTemp > 0) and (FScrollBarTopLine > LTemp) then
FScrollBarTopLine := LTemp;
LTopLine := Max(1, FScrollBarTopLine + LTemp2);
if TopLine <> LTopLine then
begin
TopLine := LTopLine;
FScrollBarTopLine := Max(FTopLine - Abs(Trunc((ClientHeight - FVisibleLines) *
(FTopLine / Max(Max(FEditorLeft.LineNumbersCount, 1) - FVisibleLines, 1)))), 1);
Repaint;
end;
end;
procedure TTextEditorCompareScrollBar.WMVScroll(var AMessage: TWMScroll);
var
LLineNumbersCount: Integer;
begin
AMessage.Result := 0;
{$IFDEF ALPHASKINS}
Skindata.BeginUpdate;
{$ENDIF}
case AMessage.ScrollCode of
SB_TOP:
TopLine := 1;
SB_BOTTOM:
if Assigned(FEditorLeft) then
TopLine := FEditorLeft.LineNumbersCount - FVisibleLines;
SB_LINEDOWN:
TopLine := TopLine + 1;
SB_LINEUP:
TopLine := TopLine - 1;
SB_PAGEDOWN:
TopLine := TopLine + FVisibleLines;
SB_PAGEUP:
TopLine := TopLine - FVisibleLines;
SB_THUMBPOSITION, SB_THUMBTRACK:
begin
LLineNumbersCount := Max(FEditorLeft.LineNumbersCount, FEditorRight.LineNumbersCount);
if LLineNumbersCount > TEXT_EDITOR_MAX_SCROLL_RANGE then
TopLine := MulDiv(FVisibleLines + LLineNumbersCount - 1, AMessage.Pos, TEXT_EDITOR_MAX_SCROLL_RANGE)
else
TopLine := AMessage.Pos;
end;
end;
{$IFDEF ALPHASKINS}
Skindata.EndUpdate(True);
{$ENDIF}
end;
{$IFDEF ALPHASKINS}
procedure TTextEditorCompareScrollBar.WndProc(var AMessage: TMessage);
const
ALT_KEY_DOWN = $20000000;
begin
if AMessage.Msg = SM_ALPHACMD then
case AMessage.WParamHi of
AC_CTRLHANDLED:
begin
AMessage.Result := 1;
Exit;
end;
AC_GETAPPLICATION:
begin
AMessage.Result := LRESULT(Application);
Exit
end;
AC_REMOVESKIN:
if (ACUInt(AMessage.LParam) = ACUInt(SkinData.SkinManager)) and not (csDestroying in ComponentState) then
begin
if Assigned(FScrollWnd) then
begin
FreeAndNil(FScrollWnd);
RecreateWnd;
end;
Exit;
end;
AC_REFRESH:
if (ACUInt(AMessage.LParam) = ACUInt(SkinData.SkinManager)) and Visible then
begin
RefreshEditScrolls(SkinData, FScrollWnd);
CommonMessage(AMessage, FSkinData);
Perform(WM_NCPAINT, 0, 0);
Exit;
end;
AC_SETNEWSKIN:
if (ACUInt(AMessage.LParam) = ACUInt(SkinData.SkinManager)) then
begin
CommonMessage(AMessage, FSkinData);
Exit;
end;
AC_GETDEFINDEX:
begin
if Assigned(FSkinData.SkinManager) then
AMessage.Result := FSkinData.SkinManager.SkinCommonInfo.Sections[ssEdit] + 1;
Exit;
end;
AC_ENDUPDATE:
Perform(CM_INVALIDATE, 0, 0);
end;
if not ControlIsReady(Self) or not Assigned(FSkinData) or not FSkinData.Skinned then
inherited
else
begin
if AMessage.Msg = SM_ALPHACMD then
case AMessage.WParamHi of
AC_ENDPARENTUPDATE:
if FSkinData.Updating then
begin
if not InUpdating(FSkinData, True) then
Perform(WM_NCPAINT, 0, 0);
Exit;
end;
end;
CommonWndProc(AMessage, FSkinData);
inherited;
case AMessage.Msg of
TB_SETANCHORHIGHLIGHT, WM_SIZE:
Perform(WM_NCPAINT, 0, 0);
CM_SHOWINGCHANGED:
RefreshEditScrolls(SkinData, FScrollWnd);
end;
end;
end;
{$ENDIF}
function TTextEditorCompareScrollBar.CanFocus: Boolean;
begin
if csDesigning in ComponentState then
Result := False
else
Result := inherited CanFocus;
end;
end.
| 27.600346 | 125 | 0.715101 |
fc6298b2888147c5b329c8341339a53f43ba3a2c | 4,710 | pas | Pascal | lazarus/lazutils/laztracer.pas | rarnu/golcl-liblcl | 6f238af742857921062365656a1b13b44b2330ce | [
"Apache-2.0"
]
| 3 | 2021-06-10T12:33:29.000Z | 2021-12-13T06:59:48.000Z | iscbase/lazutils/laztracer.pas | isyscore/isc-fpbase | ce2469c977eba901005982dc7f89fee2d0718f76 | [
"MIT"
]
| null | null | null | iscbase/lazutils/laztracer.pas | isyscore/isc-fpbase | ce2469c977eba901005982dc7f89fee2d0718f76 | [
"MIT"
]
| null | null | null | unit LazTracer;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Laz_AVL_Tree,
// LazUtils
LazLoggerBase, LazUtilities, LazUtilsStrConsts;
type
TStackTracePointers = array of Pointer;
TLineInfoCacheItem = record
Addr: Pointer;
Info: string;
end;
PLineInfoCacheItem = ^TLineInfoCacheItem;
procedure RaiseGDBException(const Msg: string);
procedure RaiseAndCatchException;
function GetStackTrace(UseCache: boolean): string;
procedure GetStackTracePointers(var AStack: TStackTracePointers);
function StackTraceAsString(const AStack: TStackTracePointers;
UseCache: boolean): string;
function GetLineInfo(Addr: Pointer; UseCache: boolean): string;
implementation
var
LineInfoCache: TAvlTree = nil;
{------------------------------------------------------------------------------
procedure RaiseGDBException(const Msg: string);
Raises an exception.
Normally gdb does not catch fpc Exception objects, therefore this procedure
raises a standard "division by zero" exception which is catched by gdb.
This allows one to stop a program, without extra gdb configuration.
------------------------------------------------------------------------------}
procedure RaiseGDBException(const Msg: string);
begin
DebugLn(lrsERRORInCode, Msg);
// creates an exception, that gdb catches:
DebugLn(lrsCreatingGdbCatchableError);
DumpStack;
{$ifndef HASAMIGA} // On Amiga Division by 0 is not catchable, just crash
if (length(Msg) div (length(Msg) div 10000))=0 then ;
{$endif}
end;
procedure RaiseAndCatchException;
begin
try
{$ifndef HASAMIGA} // On Amiga Division by 0 is not catchable, just crash
if (length(lrsERRORInCode) div (length(lrsERRORInCode) div 10000))=0 then ;
{$else}
DumpStack;
{$endif}
except
end;
end;
function GetStackTrace(UseCache: boolean): string;
var
bp: Pointer;
addr: Pointer;
oldbp: Pointer;
CurAddress: Shortstring;
begin
Result:='';
{ retrieve backtrace info }
bp:=get_caller_frame(get_frame);
while bp<>nil do begin
addr:=get_caller_addr(bp);
CurAddress:=GetLineInfo(addr,UseCache);
//DebugLn('GetStackTrace ',CurAddress);
Result:=Result+CurAddress+LineEnding;
oldbp:=bp;
bp:=get_caller_frame(bp);
if (bp<=oldbp) or (bp>(StackBottom + StackLength)) then
bp:=nil;
end;
end;
procedure GetStackTracePointers(var AStack: TStackTracePointers);
var
Depth: Integer;
bp: Pointer;
oldbp: Pointer;
begin
// get stack depth
Depth:=0;
bp:=get_caller_frame(get_frame);
while bp<>nil do begin
inc(Depth);
oldbp:=bp;
bp:=get_caller_frame(bp);
if (bp<=oldbp) or (bp>(StackBottom + StackLength)) then
bp:=nil;
end;
SetLength(AStack,Depth);
if Depth>0 then begin
Depth:=0;
bp:=get_caller_frame(get_frame);
while bp<>nil do begin
AStack[Depth]:=get_caller_addr(bp);
inc(Depth);
oldbp:=bp;
bp:=get_caller_frame(bp);
if (bp<=oldbp) or (bp>(StackBottom + StackLength)) then
bp:=nil;
end;
end;
end;
function StackTraceAsString(const AStack: TStackTracePointers;
UseCache: boolean): string;
var
i: Integer;
CurAddress: String;
begin
Result:='';
for i:=0 to length(AStack)-1 do begin
CurAddress:=GetLineInfo(AStack[i],UseCache);
Result:=Result+CurAddress+LineEnding;
end;
end;
function CompareLineInfoCacheItems(Data1, Data2: Pointer): integer;
begin
Result:=ComparePointers(PLineInfoCacheItem(Data1)^.Addr,
PLineInfoCacheItem(Data2)^.Addr);
end;
function CompareAddrWithLineInfoCacheItem(Addr, Item: Pointer): integer;
begin
Result:=ComparePointers(Addr,PLineInfoCacheItem(Item)^.Addr);
end;
function GetLineInfo(Addr: Pointer; UseCache: boolean): string;
var
ANode: TAvlTreeNode;
Item: PLineInfoCacheItem;
begin
if UseCache then begin
if LineInfoCache=nil then
LineInfoCache:=TAvlTree.Create(@CompareLineInfoCacheItems);
ANode:=LineInfoCache.FindKey(Addr,@CompareAddrWithLineInfoCacheItem);
if ANode=nil then begin
Result:=BackTraceStrFunc(Addr);
New(Item);
Item^.Addr:=Addr;
Item^.Info:=Result;
LineInfoCache.Add(Item);
end else begin
Result:=PLineInfoCacheItem(ANode.Data)^.Info;
end;
end else
Result:=BackTraceStrFunc(Addr);
end;
procedure FreeLineInfoCache;
var
ANode: TAvlTreeNode;
Item: PLineInfoCacheItem;
begin
if LineInfoCache=nil then exit;
ANode:=LineInfoCache.FindLowest;
while ANode<>nil do begin
Item:=PLineInfoCacheItem(ANode.Data);
Dispose(Item);
ANode:=LineInfoCache.FindSuccessor(ANode);
end;
LineInfoCache.Free;
LineInfoCache:=nil;
end;
finalization
FreeLineInfoCache;
end.
| 25.187166 | 80 | 0.691932 |
f13e16632147f446f0068826e069f89f5136a3d4 | 60,197 | pas | Pascal | widgets/grids.pas | seryal/Pas2JS_Widget | 2d3e1b86e5308709c87bec750b43bf9796d50f6a | [
"MIT"
]
| 5 | 2020-12-11T15:39:54.000Z | 2021-08-22T06:41:04.000Z | widgets/grids.pas | seryal/Pas2JS_Widget | 2d3e1b86e5308709c87bec750b43bf9796d50f6a | [
"MIT"
]
| null | null | null | widgets/grids.pas | seryal/Pas2JS_Widget | 2d3e1b86e5308709c87bec750b43bf9796d50f6a | [
"MIT"
]
| null | null | null | {
/***************************************************************************
grids.pas
---------
Initial Revision : Fri Oct 30 CST 2020
***************************************************************************/
*****************************************************************************
This file is part of the Web Component Library (WCL)
See the file COPYING.modifiedLGPL.txt, included in this distribution,
for details about the license.
*****************************************************************************
}
unit Grids;
{$mode objfpc}{$H+}
{.$define DEBUG_GRID}
interface
uses
SysUtils, Classes, Controls, Types, Web, Graphics, StdCtrls;
const
DEFCOLWIDTH = 64;
type
TCustomGrid = class;
TGridColumn = class;
EGridException = class(Exception);
TGridOption = (
goRowSelect { select a complete row instead of only a single cell }
);
TGridOptions = set of TGridOption;
TGridState = (gsNormal, gsSelecting, gsRowSizing, gsColSizing, gsRowMoving,
gsColMoving, gsHeaderClicking, gsButtonColumnClicking);
TGridZone = (gzNormal, gzFixedCols, gzFixedRows, gzFixedCells, gzInvalid);
TGridZoneSet = set of TGridZone;
TGridDataCache = record
FixedWidth: Integer; { Sum( Fixed ColsWidths[i] ) }
FixedHeight: Integer; { Sum( Fixed RowsHeights[i] ) }
GridWidth: Integer; { Sum( ColWidths[i] ) }
GridHeight: Integer; { Sum( RowHeights[i] ) }
AccumWidth: TIntegerList; { Accumulated width per column }
AccumHeight: TIntegerList; { Accumulated Height per row }
HotGridZone: TGridZone; { GridZone of last MouseMove }
ClickCell: TPoint; { cell coords of the latest mouse click }
ClickMouse: TPoint; { mouse coords of the latest mouse click }
end;
const
DefaultGridOptions = [];
type
TOnSelectEvent = procedure(aSender: TObject; aCol, aRow: Integer) of object;
{ TGridColumnTitle }
TGridColumnTitle = class(TPersistent)
private
fColumn: TGridColumn;
fAlignment: TAlignment;
fCaption: TCaption;
fIsDefaultAlignment: Boolean;
fIsDefaultCaption: Boolean;
fIsDefaultLayout: Boolean;
fLayout: TTextLayout;
function GetAlignment: TAlignment;
function GetLayout: TTextLayout;
function IsAlignmentStored: Boolean;
function IsCaptionStored: Boolean;
function IsLayoutStored: Boolean;
procedure SetAlignment(aValue: TAlignment);
procedure SetLayout(aValue: TTextLayout);
procedure WriteCaption(aWriter: TWriter);
protected
function GetDefaultAlignment: TAlignment;
function GetDefaultCaption: String; virtual;
function GetDefaultLayout: TTextLayout;
function GetCaption: TCaption;
procedure SetCaption(const aValue: TCaption); virtual;
public
constructor Create(aColumn: TGridColumn); virtual;
procedure Assign(aSource: TPersistent); override;
function IsDefault: Boolean;
property Column: TGridColumn read fColumn;
published
property Alignment: TAlignment read GetAlignment write SetAlignment stored IsAlignmentStored;
property Caption: TCaption read GetCaption write SetCaption stored IsCaptionStored;
property Layout: TTextLayout read GetLayout write SetLayout stored IsLayoutStored;
end;
{ TGridColumn }
TGridColumn = class(TCollectionItem)
private
fAlignment: TAlignment;
fLayout: TTextLayout;
fTitle: TGridColumnTitle;
function GetGrid: TCustomGrid;
procedure SetAlignment(aValue: TAlignment);
procedure SetLayout(AValue: TTextLayout);
procedure SetTitle(aValue: TGridColumnTitle);
protected
function GetDefaultAlignment: TAlignment; virtual;
function GetDefaultLayout: TTextLayout; virtual;
procedure ColumnChanged; virtual;
function CreateTitle: TGridColumnTitle; virtual;
public
constructor Create(aCollection: TCollection); override;
destructor Destroy; override;
function IsDefault: Boolean;
property Grid: TCustomGrid read GetGrid;
published
property Alignment: TAlignment read fAlignment write SetAlignment;
property Layout: TTextLayout read fLayout write SetLayout;
property Title: TGridColumnTitle read fTitle write SetTitle;
end;
{ TGridColumns }
TGridColumns = class(TCollection)
private
fGrid: TCustomGrid;
function GetColumn(Index: Integer): TGridColumn;
function GetEnabled: Boolean;
function GetVisibleCount: Integer;
procedure SetColumn(Index: Integer; AValue: TGridColumn);
protected
procedure Update(aItem: TCollectionItem); override;
public
constructor Create(aGrid: TCustomGrid; aItemClass: TCollectionItemClass);
function Add: TGridColumn;
procedure Clear;
function ColumnByTitle(const aTitle: String): TGridColumn;
function IndexOf(aColumn: TGridColumn): Integer;
function IsDefault: Boolean;
function RealIndex(aIndex: Integer): Integer;
property Enabled: Boolean read GetEnabled;
property Grid: TCustomGrid read fGrid;
property Items[Index: Integer]: TGridColumn read GetColumn write SetColumn; default;
property VisibleCount: Integer read GetVisibleCount;
end;
TGridRect = TRect;
TGridCoord = TPoint;
{ TCustomGrid }
TCustomGrid = class(TCustomControl)
private
fAllowOutboundEvents: Boolean;
fBorderColor: TColor;
fCol: Integer;
fCols: TIntegerList;
fColumns: TGridColumns;
fContentTable: TJSHTMLTableElement;
fDefColWidth: Integer;
fDefRowHeight: Integer;
fEditorMode: Boolean;
fGCache: TGridDataCache;
fFixedColor: TColor;
fFixedCols: Integer;
fFixedColsTable: TJSHTMLTableElement;
fFixedGridLineColor: TColor;
fFixedRows: Integer;
fFixedRowsTable: TJSHTMLTableElement;
fFixedTopLeftTable: TJSHTMLTableElement;
fFlat: Boolean;
fGridBorderStyle: TBorderStyle;
fGridLineColor: TColor;
fGridLineStyle: TPenStyle;
fGridLineWidth: Integer;
fOnAfterSelection: TOnSelectEvent;
fOnBeforeSelection: TOnSelectEvent;
fOnSelection: TOnSelectEvent;
fOnTopLeftChanged: TNotifyEvent;
fOptions: TGridOptions;
fRange: TGridRect;
fRealizedDefColWidth: Integer;
fRealizedDefRowHeight: Integer;
fRow: Integer;
fRows: TIntegerList;
fScrollBars: TScrollStyle;
fSelectedColor: TColor;
fTopLeft: TPoint;
fUpdateCount: Integer;
procedure AdjustGrid(aIsColumn: Boolean; aOld, aNew: Integer);
procedure CheckCount(aNewColCount, aNewRowCount: Integer);
procedure CheckFixed(aCols, aRows, aFixedCols, aFixedRows: Integer);
function DefaultColWidthIsStored: Boolean;
function DefaultRowHeightIsStored: Boolean;
procedure DoTopLeftChanged;
procedure FixPosition(aIsColumn: Boolean; aIndex: Integer);
function GetColCount: Integer;
function GetColumns: TGridColumns;
function GetColWidths(aCol: Integer): Integer;
function GetDefColWidth: Integer;
function GetDefRowHeight: Integer;
function GetFixedColor: TColor; virtual;
function GetRowCount: Integer;
function GetRowHeights(aRow: Integer): Integer;
function GetSelectedColor: TColor; virtual;
procedure HeadersMouseMove(const aX, aY: Integer);
function IsColumnsStored: Boolean;
procedure ResetHotCell;
function ScrollToCell(const aCol, aRow: Integer; const aForceFullyVisible: Boolean = True): Boolean;
procedure SetBorderColor(aValue: TColor);
procedure SetBorderStyle(aValue: TBorderStyle);
procedure SetCol(aValue: Integer);
procedure SetColCount(aValue: Integer);
procedure SetColumns(aValue: TGridColumns);
procedure SetColWidths(aCol: Integer; aValue: Integer);
procedure SetDefColWidth(aValue: Integer);
procedure SetDefRowHeight(aValue: Integer);
procedure SetEditorMode(aValue: Boolean);
procedure SetFixedColor(aValue: TColor); virtual;
procedure SetFixedCols(aValue: Integer);
procedure SetFixedGridLineColor(AValue: TColor);
procedure SetFixedRows(aValue: Integer);
procedure SetFlat(aValue: Boolean);
procedure SetGridLineColor(aValue: TColor);
procedure SetGridLineStyle(aValue: TPenStyle);
procedure SetGridLineWidth(aValue: Integer);
procedure SetOptions(aValue: TGridOptions);
procedure SetRow(aValue: Integer);
procedure SetRowCount(aValue: Integer);
procedure SetRowHeights(aRow: Integer; aValue: Integer);
procedure SetScrollBars(aValue: TScrollStyle);
procedure SetSelectedColor(aValue: TColor); virtual;
procedure UpdateCachedSizes;
protected
fGridState: TGridState;
procedure AfterMoveSelection(const aPrevCol, aPrevRow: Integer); virtual;
procedure BeforeMoveSelection(const aCol, aRow: Integer); virtual;
procedure CacheMouseDown(aX, aY: Integer);
procedure CellClick(const aCol, aRow: Integer; const aButton: TMouseButton); virtual;
procedure Changed; override;
procedure CheckLimits(var aCol, aRow: Integer);
function ColumnFromGridColumn(aColumn: Integer): TGridColumn;
function ColumnIndexFromGridColumn(aColumn: Integer): Integer;
procedure ColumnsChanged(aColumn: TGridColumn);
function CreateColumns: TGridColumns; virtual;
function CreateHandleElement: TJSHTMLElement; override;
procedure DoScroll; override;
function FirstGridColumn: Integer; virtual;
function FixedGrid: Boolean;
function GetCells(aCol, aRow: Integer): String; virtual;
function GetDefaultRowHeight: Integer; virtual;
function GetIsCellSelected(aCol, aRow: Integer): Boolean; virtual;
function GridColumnFromColumnIndex(aColumnIndex: Integer): Integer;
procedure InternalSetColCount(aCount: Integer);
procedure InvalidateCell(aCol, aRow: Integer; aRedraw: Boolean); overload;
function IsColumnIndexValid(aIndex: Integer): Boolean;
function IsColumnIndexVariable(aIndex: Integer): Boolean;
function IsRowIndexValid(aIndex: Integer): Boolean;
function IsRowIndexVariable(aIndex: Integer): Boolean;
procedure MouseDown(aButton: TMouseButton; aShift: TShiftState; aX, aY: integer); override;
procedure MouseMove(aShift: TShiftState; aX, aY: integer); override;
procedure MouseUp(aButton: TMouseButton; aShift: TShiftState; aX, aY: integer); override;
function MoveExtend(aRelative: Boolean; aCol, aRow: Integer; aForceFullyVisible: Boolean = True): Boolean;
function MoveNextSelectable(aRelative: Boolean; aDCol, aDRow: Integer): Boolean; virtual;
procedure MoveSelection; virtual;
function OffsetToColRow(aIsCol, aFisical: Boolean; aOffset: Integer; out aIndex, aRest: Integer): Boolean;
function SelectCell(aCol, aRow: Integer): Boolean; virtual;
procedure SizeChanged(aOldColCount, aOldRowCount: Integer); virtual;
function TryMoveSelection(aRelative: Boolean; var aCol, aRow: Integer): Boolean;
procedure TopLeftChanged; virtual;
procedure UpdateBorderStyle;
procedure VisualChange; virtual;
property AllowOutboundEvents: Boolean read fAllowOutboundEvents write fAllowOutboundEvents default True;
property BorderColor: TColor read fBorderColor write SetBorderColor default cl3DDKShadow;
property BorderStyle: TBorderStyle read fGridBorderStyle write SetBorderStyle default bsSingle;
property Col: Integer read fCol write SetCol;
property ColCount: Integer read GetColCount write SetColCount default 5;
property ColWidths[Col: Integer]: Integer read GetColWidths write SetColWidths;
property Columns: TGridColumns read GetColumns write SetColumns stored IsColumnsStored;
property DefaultColWidth: Integer read GetDefColWidth write SetDefColWidth stored DefaultColWidthIsStored;
property DefaultRowHeight: Integer read GetDefRowHeight write SetDefRowHeight stored DefaultRowHeightIsStored;
property FixedColor: TColor read GetFixedColor write SetFixedColor default clBtnFace;
property FixedGridLineColor: TColor read fFixedGridLineColor write SetFixedGridLineColor default cl3DDKShadow;
property Flat: Boolean read fFlat write SetFlat default False;
property GridLineColor: TColor read fGridLineColor write SetGridLineColor default clSilver;
property GridLineStyle: TPenStyle read fGridLineStyle write SetGridLineStyle;
property GridLineWidth: Integer read fGridLineWidth write SetGridLineWidth default 1;
property Options: TGridOptions read fOptions write SetOptions default DefaultGridOptions;
property Row: Integer read fRow write SetRow;
property RowCount: Integer read GetRowCount write SetRowCount default 5;
property RowHeights[Row: Integer]: Integer read GetRowHeights write SetRowHeights;
property ScrollBars: TScrollStyle read fScrollBars write SetScrollBars default ssAutoBoth;
property SelectedColor: TColor read GetSelectedColor write SetSelectedColor;
property OnAfterSelection: TOnSelectEvent read fOnAfterSelection write fOnAfterSelection;
property OnBeforeSelection: TOnSelectEvent read fOnBeforeSelection write fOnBeforeSelection;
property OnSelection: TOnSelectEvent read fOnSelection write fOnSelection;
public
constructor Create(aOwner: TComponent); override;
destructor Destroy; override;
function CellToGridZone(aCol, aRow: Integer): TGridZone;
procedure Clear;
function ClearCols: Boolean;
function ClearRows: Boolean;
procedure InvalidateCell(aCol, aRow: Integer); overload;
procedure MouseToCell(aX, aY: Integer; out aCol, aRow: Integer); overload;
function MouseToCell(const aMouse: TPoint): TGridCoord; overload; inline;
function MouseToGridZone(aX, aY: Integer): TGridZone;
property EditorMode: Boolean read fEditorMode write SetEditorMode;
property FixedCols: Integer read fFixedCols write SetFixedCols default 1;
property FixedRows: Integer read fFixedRows write SetFixedRows default 1;
property OnTopLeftChanged: TNotifyEvent read fOnTopLeftChanged write fOnTopLeftChanged;
end;
TCellProps = class
Data: TObject;
Text: String;
end;
TColRowProps = class
Size: Integer;
end;
{ TVirtualGrid }
TVirtualGrid = class
private type
TCellPropsArray = array of TCellProps;
TCellPropsArrayArray = array of TCellPropsArray;
TColRowPropsArray = array of TColRowProps;
private
fColCount: Integer;
fRowCount: Integer;
fCellArr: TCellPropsArrayArray;
fColArr, fRowArr: TColRowPropsArray;
function GetCells(aCol, aRow: Integer): TCellProps;
function GetCols(aCol: Integer): TColRowProps;
function GetRows(aRow: Integer): TColRowProps;
procedure SetCells(aCol, aRow: Integer; aValue: TCellProps);
procedure SetColCount(aValue: Integer);
procedure SetCols(aCol: Integer; aValue: TColRowProps);
procedure SetRowCount(aValue: Integer);
procedure SetRows(aRow: Integer; aValue: TColRowProps);
protected
public
procedure Clear;
function GetDefaultCell: TCellProps;
function GetDefaultColRow: TColRowProps;
property ColCount: Integer read fColCount write SetColCount;
property RowCount: Integer read fRowCount write SetRowCount;
property Celda[Col, Row: Integer]: TCellProps read GetCells write SetCells;
property Cols[Col: Integer]: TColRowProps read GetCols write SetCols;
property Rows[Row: Integer]: TColRowProps read GetRows write SetRows;
end;
{ TCustomDrawGrid }
TCustomDrawGrid = class(TCustomGrid)
protected
FGrid: TVirtualGrid;
function CreateVirtualGrid: TVirtualGrid; virtual;
procedure SizeChanged(aOldColCount, aOldRowCount: Integer); override;
public
constructor Create(aOwner: TComponent); override;
destructor Destroy; override;
property AllowOutboundEvents;
property Col;
property ColCount;
property ColWidths;
property Options;
property Row;
property RowCount;
property RowHeights;
end;
{ TCustomStringGrid }
TCustomStringGrid = class(TCustomDrawGrid)
private
fModified: Boolean;
protected
function GetCells(aCol, aRow: Integer): String; override;
procedure SetCells(aCol, aRow: Integer; const aValue: String); virtual;
property Modified: Boolean read fModified write fModified;
public
property Cells[Col, Row: Integer]: String read GetCells write SetCells;
{property Cols[Index: Integer]: TStrings read GetCols write SetCols;
property Objects[Col, Row: Integer]: TObject read GetObjects write SetObjects;
property Rows[Index: Integer]: TStrings read GetRows write SetRows;}
end;
TWStringGrid = class(TCustomStringGrid)
published
property Anchors;
property ColCount;
property Columns;
property DefaultColWidth;
property DefaultRowHeight;
property FixedCols;
property FixedRows;
property Options;
property RowCount;
property OnSelection;
end;
implementation
uses
TypInfo, WCLStrConsts;
{ TCustomStringGrid }
function TCustomStringGrid.GetCells(aCol, aRow: Integer): String;
var
c: TCellProps;
begin
Result := '';
c := fGrid.Celda[aCol, aRow];
if Assigned(c) then
Result := c.Text;
end;
procedure TCustomStringGrid.SetCells(aCol, aRow: Integer; const aValue: String);
procedure UpdateCell;
begin
InvalidateCell(aCol, aRow);
end;
var
c: TCellProps;
begin
c := fGrid.Celda[aCol, aRow];
if Assigned(c) then begin
c.Text := aValue;
UpdateCell;
fModified := True;
end else if aValue <> '' then begin
c := TCellProps.Create;
c.Text := aValue;
fGrid.Celda[aCol, aRow] := c;
UpdateCell;
fModified := True;
end;
end;
{ TCustomDrawGrid }
function TCustomDrawGrid.CreateVirtualGrid: TVirtualGrid;
begin
Result := TVirtualGrid.Create;
end;
procedure TCustomDrawGrid.SizeChanged(aOldColCount, aOldRowCount: Integer);
begin
if aOldColCount <> ColCount then begin
fGrid.ColCount := ColCount;
end;
if aOldRowCount <> RowCount then begin
fGrid.RowCount := RowCount;
end;
end;
constructor TCustomDrawGrid.Create(aOwner: TComponent);
begin
fGrid := CreateVirtualGrid;
inherited Create(aOwner);
end;
destructor TCustomDrawGrid.Destroy;
begin
fGrid.Free;
inherited Destroy;
end;
{ TVirtualGrid }
procedure TVirtualGrid.SetColCount(aValue: Integer);
begin
if fColCount = aValue then
Exit;
fColCount := aValue;
SetLength(fColArr, fColCount);
SetLength(fCellArr, fColCount, fRowCount);
end;
function TVirtualGrid.GetCells(aCol, aRow: Integer): TCellProps;
begin
Result := fCellArr[aCol, aRow];
end;
function TVirtualGrid.GetCols(aCol: Integer): TColRowProps;
begin
Result := fColArr[aCol];
end;
function TVirtualGrid.GetRows(aRow: Integer): TColRowProps;
begin
Result := fRowArr[aRow];
end;
procedure TVirtualGrid.SetCells(aCol, aRow: Integer; aValue: TCellProps);
begin
fCellArr[aCol, aRow].Free;
fCellArr[aCol, aRow] := aValue;
end;
procedure TVirtualGrid.SetCols(aCol: Integer; aValue: TColRowProps);
begin
fColArr[aCol].Free;
fColArr[aCol] := aValue;
end;
procedure TVirtualGrid.SetRowCount(aValue: Integer);
begin
if fRowCount = AValue then
Exit;
fRowCount := aValue;
SetLength(fRowArr, fRowCount);
SetLength(fCellArr, fColCount, fRowCount);
end;
procedure TVirtualGrid.SetRows(aRow: Integer; aValue: TColRowProps);
begin
fRowArr[aRow].Free;
fRowArr[aRow] := aValue;
end;
procedure TVirtualGrid.Clear;
begin
fRowCount := 0;
fColCount := 0;
end;
function TVirtualGrid.GetDefaultCell: TCellProps;
begin
Result := TCellProps.Create;
end;
function TVirtualGrid.GetDefaultColRow: TColRowProps;
begin
Result := TColRowProps.Create;
end;
{ TGridColumnTitle }
function TGridColumnTitle.IsCaptionStored: Boolean;
begin
Result := not fIsDefaultCaption;
end;
function TGridColumnTitle.GetAlignment: TAlignment;
begin
if fIsDefaultAlignment then
Result := GetDefaultAlignment
else
Result := fAlignment;
end;
function TGridColumnTitle.GetLayout: TTextLayout;
begin
if fIsDefaultLayout then
Result := GetDefaultLayout
else
Result := fLayout;
end;
function TGridColumnTitle.IsAlignmentStored: Boolean;
begin
Result := not fIsDefaultAlignment;
end;
function TGridColumnTitle.IsLayoutStored: Boolean;
begin
Result := not fIsDefaultLayout;
end;
procedure TGridColumnTitle.SetAlignment(aValue: TAlignment);
begin
if fIsDefaultAlignment or (fAlignment <> aValue) then begin
fIsDefaultAlignment := False;
fAlignment := aValue;
fColumn.ColumnChanged;
end;
end;
procedure TGridColumnTitle.SetLayout(aValue: TTextLayout);
begin
if fIsDefaultLayout or (fLayout <> aValue) then begin
fIsDefaultLayout := False;
fLayout := aValue;
fColumn.ColumnChanged;
end;
end;
procedure TGridColumnTitle.WriteCaption(aWriter: TWriter);
var
s: TCaption;
pi: TTypeMemberProperty;
begin
s := Caption;
if Assigned(aWriter.OnWriteStringProperty) then begin
pi := GetPropInfo(Self, 'Caption');
aWriter.OnWriteStringProperty(aWriter, Self, pi, s);
end;
aWriter.WriteString(s);
end;
function TGridColumnTitle.GetDefaultAlignment: TAlignment;
begin
Result := taLeftJustify;
end;
function TGridColumnTitle.GetCaption: TCaption;
begin
if fIsDefaultCaption then
Result := GetDefaultCaption
else
Result := fCaption;
end;
procedure TGridColumnTitle.SetCaption(const aValue: TCaption);
begin
if fIsDefaultCaption or (fCaption <> aValue) then begin
fIsDefaultCaption := False;
fCaption := aValue;
fColumn.ColumnChanged;
end;
end;
function TGridColumnTitle.GetDefaultCaption: String;
begin
Result := 'Title';
end;
function TGridColumnTitle.GetDefaultLayout: TTextLayout;
begin
Result := tlCenter;
end;
constructor TGridColumnTitle.Create(aColumn: TGridColumn);
begin
fColumn := aColumn;
fIsDefaultAlignment := True;
fIsDefaultCaption := True;
fIsDefaultLayout := True;
fAlignment := taLeftJustify;
fLayout := tlCenter;
end;
procedure TGridColumnTitle.Assign(aSource: TPersistent);
begin
if aSource is TGridColumnTitle then begin
Caption := TGridColumnTitle(aSource).Caption;
end else
inherited Assign(aSource);
end;
function TGridColumnTitle.IsDefault: Boolean;
begin
Result := fIsDefaultCaption and
fIsDefaultAlignment and
fIsDefaultLayout;
end;
{ TGridColumn }
function TGridColumn.GetGrid: TCustomGrid;
begin
if Collection is TGridColumns then
Result := (Collection as TGridColumns).Grid
else
Result := nil;
end;
procedure TGridColumn.SetAlignment(aValue: TAlignment);
begin
if fAlignment <> aValue then begin
fAlignment := aValue;
ColumnChanged;
end;
end;
procedure TGridColumn.SetLayout(AValue: TTextLayout);
begin
if fLayout = aValue then
Exit;
fLayout := aValue;
ColumnChanged;
end;
procedure TGridColumn.SetTitle(aValue: TGridColumnTitle);
begin
fTitle.Assign(aValue);
end;
function TGridColumn.GetDefaultAlignment: TAlignment;
begin
Result := taLeftJustify;
end;
function TGridColumn.GetDefaultLayout: TTextLayout;
begin
Result := tlCenter;
end;
procedure TGridColumn.ColumnChanged;
begin
Changed(False);
end;
function TGridColumn.CreateTitle: TGridColumnTitle;
begin
Result := TGridColumnTitle.Create(Self);
end;
constructor TGridColumn.Create(aCollection: TCollection);
begin
inherited Create(aCollection);
fTitle := CreateTitle;
fAlignment := GetDefaultAlignment;
end;
destructor TGridColumn.Destroy;
begin
fTitle.Free;
inherited Destroy;
end;
function TGridColumn.IsDefault: Boolean;
begin
Result := fTitle.IsDefault;
end;
{ TGridColumns }
function TGridColumns.GetColumn(Index: Integer): TGridColumn;
begin
Result := TGridColumn(inherited Items[Index]);
end;
function TGridColumns.GetEnabled: Boolean;
begin
Result := VisibleCount > 0;
end;
function TGridColumns.GetVisibleCount: Integer;
begin
Result := Count;
end;
procedure TGridColumns.SetColumn(Index: Integer; AValue: TGridColumn);
begin
Items[Index].Assign(aValue);
end;
procedure TGridColumns.Update(aItem: TCollectionItem);
begin
fGrid.ColumnsChanged(TGridColumn(aItem));
end;
constructor TGridColumns.Create(aGrid: TCustomGrid;
aItemClass: TCollectionItemClass);
begin
inherited Create(aItemClass);
fGrid := aGrid;
end;
function TGridColumns.Add: TGridColumn;
begin
Result := TGridColumn(inherited Add);
end;
procedure TGridColumns.Clear;
begin
BeginUpdate;
try
inherited Clear;
finally
EndUpdate;
end;
end;
function TGridColumns.ColumnByTitle(const aTitle: String): TGridColumn;
var
i: Integer;
begin
Result := Nil;
for i := 0 to Count - 1 do
if SameText(Items[i].Title.Caption, aTitle) then begin
Result := Items[i];
Break;
end;
end;
function TGridColumns.IndexOf(aColumn: TGridColumn): Integer;
var
i: Integer;
begin
Result := -1;
for i := 0 to Count - 1 do
if Items[i] = aColumn then begin
Result := i;
Break;
end;
end;
function TGridColumns.IsDefault: Boolean;
var
i: Integer;
begin
Result := True;
for i := 0 to Count - 1 do begin
Result := Result and Items[i].IsDefault;
if not Result then
Break;
end;
end;
function TGridColumns.RealIndex(aIndex: Integer): Integer;
begin
if aIndex >= Count then
Result := -1
else
Result := aIndex;
end;
{ TCustomGrid }
procedure TCustomGrid.AdjustGrid(aIsColumn: Boolean; aOld, aNew: Integer);
procedure AdjustList(aList: TIntegerList; aCount: Integer);
begin
{ add new elements with the default size }
while aList.Count < aCount do
aList.Add(-1);
aList.Count := aCount;
end;
var
oldcount, newcount: Integer;
begin
if aIsColumn then begin
AdjustList(fCols, aNew);
fGCache.AccumWidth.Count := aNew;
oldcount := RowCount;
if (aOld = 0) and (aNew >= 0) then begin
fTopLeft.X := fFixedCols;
if RowCount = 0 then begin
newcount := 1;
fTopLeft.Y := fFixedRows;
AdjustList(fRows, newcount);
fGCache.AccumHeight.Count := newcount;
end;
end;
UpdateCachedSizes;
SizeChanged(aOld, oldcount);
{ if new count makes current Col out of range, adjust position if not,
position should not change (fake changed col to be the last one) }
Dec(aNew);
if aNew < Col then
aNew := Col;
FixPosition(True, aNew);
end else begin
AdjustList(fRows, aNew);
fGCache.AccumHeight.Count := aNew;
oldcount := ColCount;
if (aOld = 0) and (aNew >= 0) then begin
fTopLeft.Y := fFixedRows;
if ColCount = 0 then begin
newcount := 1;
fTopLeft.X := fFixedCols;
AdjustList(fCols, newcount);
fGCache.AccumWidth.Count := newcount;
end;
end;
UpdateCachedSizes;
SizeChanged(oldcount, aOld);
{ if new count makes current Row out of range, adjust position if not,
position should not change (fake changed row to be the last one) }
Dec(aNew);
if aNew < Row then
aNew := Row;
FixPosition(False, aNew);
end;
end;
procedure TCustomGrid.CheckCount(aNewColCount, aNewRowCount: Integer);
var
newcol, newrow: Integer;
begin
if Col >= aNewColCount then
newcol := aNewColCount - 1
else
newcol := Col;
if Row >= aNewRowCount then
newrow := aNewRowCount - 1
else
newrow := Row;
if (newcol >= 0) and (newrow >= 0) and ((newcol <> Col) or (newrow <> Row)) then begin
if (aNewColCount <> fFixedCols) and (aNewRowCount <> fFixedRows) then
MoveNextSelectable(False, NewCol, NewRow);
end;
end;
procedure TCustomGrid.CheckFixed(aCols, aRows, aFixedCols, aFixedRows: Integer);
begin
if aFixedCols < 0 then
raise EGridException.Create('FixedCols < 0');
if aFixedRows < 0 then
raise EGridException.Create('FixedRows < 0');
if csLoading in ComponentState then
Exit;
if aFixedCols > aCols then
raise EGridException.Create(rsFixedColsTooBig);
if aFixedRows > aRows then
raise EGridException.Create(rsFixedRowsTooBig);
end;
function TCustomGrid.DefaultColWidthIsStored: Boolean;
begin
Result := fDefColWidth >= 0;
end;
function TCustomGrid.DefaultRowHeightIsStored: Boolean;
begin
Result := fDefRowHeight >= 0;
end;
procedure TCustomGrid.DoTopLeftChanged;
begin
TopLeftChanged;
VisualChange;
end;
procedure TCustomGrid.FixPosition(aIsColumn: Boolean; aIndex: Integer);
procedure FixSelection;
begin
if fRow > fRows.Count - 1 then
fRow := fRows.Count - 1
else if (fRow < FixedRows) and (FixedRows < fRows.Count) then
fRow := FixedRows;
if fCol > fCols.Count - 1 then
fCol := fCols.Count - 1
else if (fCol < FixedCols) and (FixedCols < fCols.Count) then
fCol := FixedCols;
end;
begin
FixSelection;
VisualChange;
end;
function TCustomGrid.GetColCount: Integer;
begin
Result := fCols.Count;
end;
function TCustomGrid.GetColumns: TGridColumns;
begin
Result := fColumns;
end;
function TCustomGrid.GetColWidths(aCol: Integer): Integer;
begin
if IsColumnIndexValid(aCol) then
Result := FCols[aCol]
else
Result := -1;
if Result < 0 then
Result := DefaultColWidth;
end;
function TCustomGrid.GetDefColWidth: Integer;
begin
if fDefColWidth < 0 then begin
if fRealizedDefColWidth <= 0 then
fRealizedDefColWidth := DEFCOLWIDTH;
Result := fRealizedDefColWidth;
end else
Result := fDefColWidth;
end;
function TCustomGrid.GetDefRowHeight: Integer;
begin
if fDefRowHeight < 0 then begin
if fRealizedDefRowHeight <= 0 then
fRealizedDefRowHeight := GetDefaultRowHeight;
Result := fRealizedDefRowHeight;
end else
Result := fDefRowHeight;
end;
function TCustomGrid.GetFixedColor: TColor;
begin
Result := fFixedColor;
end;
function TCustomGrid.GetRowCount: Integer;
begin
Result := fRows.Count;
end;
function TCustomGrid.GetRowHeights(aRow: Integer): Integer;
begin
if IsRowIndexValid(aRow) then
Result := FRows[aRow]
else
Result := -1;
if Result < 0 then
Result := DefaultRowHeight;
end;
function TCustomGrid.GetSelectedColor: TColor;
begin
Result := fSelectedColor;
end;
procedure TCustomGrid.HeadersMouseMove(const aX, aY: Integer);
var
gz: TGridZone;
begin
gz := MouseToGridZone(aX, aY);
fGCache.HotGridZone := gz;
end;
function TCustomGrid.IsColumnsStored: Boolean;
begin
Result := Columns.Enabled;
end;
procedure TCustomGrid.ResetHotCell;
begin
with FGCache do begin
HotGridZone := gzInvalid;
end;
end;
function TCustomGrid.ScrollToCell(const aCol, aRow: Integer;
const aForceFullyVisible: Boolean): Boolean;
begin
{ ToDo }
Result := False;
end;
procedure TCustomGrid.SetBorderColor(aValue: TColor);
begin
if fBorderColor = aValue then
Exit;
fBorderColor := aValue;
if BorderStyle <> bsNone then
Changed;
end;
procedure TCustomGrid.SetBorderStyle(aValue: TBorderStyle);
begin
if fGridBorderStyle = aValue then
Exit;
fGridBorderStyle := aValue;
UpdateBorderStyle;
end;
procedure TCustomGrid.SetCol(aValue: Integer);
begin
if fCol = aValue then
Exit;
MoveExtend(False, aValue, fRow, True);
Click;
Changed;
end;
procedure TCustomGrid.SetColCount(aValue: Integer);
begin
if Columns.Enabled then
raise EGridException.Create('Use Columns property to add/remove columns');
InternalSetColCount(AValue);
Changed;
end;
procedure TCustomGrid.SetColumns(aValue: TGridColumns);
begin
fColumns.Assign(aValue);
end;
procedure TCustomGrid.SetColWidths(aCol: Integer; aValue: Integer);
begin
if not IsColumnIndexValid(aCol) then
Exit;
if aValue < 0 then
aValue := -1;
if fCols[aCol] = aValue then
Exit;
fCols[aCol] := aValue;
Changed;
end;
procedure TCustomGrid.SetDefColWidth(aValue: Integer);
begin
if fDefColWidth = aValue then
Exit;
fDefColWidth := aValue;
Changed;
end;
procedure TCustomGrid.SetDefRowHeight(aValue: Integer);
begin
if fDefRowHeight = aValue then
Exit;
fDefRowHeight := aValue;
Changed;
end;
procedure TCustomGrid.SetEditorMode(aValue: Boolean);
begin
if fEditorMode = aValue then
Exit;
fEditorMode := aValue;
end;
procedure TCustomGrid.SetFixedColor(aValue: TColor);
begin
if fFixedColor = aValue then
Exit;
fFixedColor := aValue;
Invalidate;
end;
procedure TCustomGrid.SetFixedCols(aValue: Integer);
begin
if fFixedCols = aValue then
Exit;
CheckFixed(ColCount, RowCount, aValue, FixedRows);
if EditorMode then
EditorMode := False;
fFixedCols := aValue;
fTopLeft.x := aValue;
if Columns.Enabled then begin
if not (csLoading in ComponentState) then
DoTopLeftChanged;
ColumnsChanged(Nil);
end else begin
if not (csLoading in ComponentState) then
DoTopLeftChanged;
end;
UpdateCachedSizes;
end;
procedure TCustomGrid.SetFixedGridLineColor(AValue: TColor);
begin
if FFixedGridLineColor=AValue then Exit;
FFixedGridLineColor:=AValue;
end;
procedure TCustomGrid.SetFixedRows(aValue: Integer);
begin
if fFixedRows = aValue then
Exit;
CheckFixed(ColCount, RowCount, FixedCols, aValue);
if EditorMode then
EditorMode := False;
fFixedRows := aValue;
fTopLeft.y := aValue;
if not (csLoading in ComponentState) then
DoTopLeftChanged;
UpdateCachedSizes;
end;
procedure TCustomGrid.SetFlat(aValue: Boolean);
begin
if fFlat = aValue then
Exit;
fFlat := aValue;
end;
procedure TCustomGrid.SetGridLineColor(aValue: TColor);
begin
if fGridLineColor = aValue then
Exit;
fGridLineColor := aValue;
Invalidate;
end;
procedure TCustomGrid.SetGridLineStyle(aValue: TPenStyle);
begin
if fGridLineStyle = aValue then
Exit;
fGridLineStyle:=AValue;
Invalidate;
end;
procedure TCustomGrid.SetGridLineWidth(aValue: Integer);
begin
if fGridLineWidth = aValue then
Exit;
fGridLineWidth := aValue;
Invalidate;
end;
procedure TCustomGrid.SetOptions(aValue: TGridOptions);
begin
if fOptions = aValue then
Exit;
fOptions := aValue;
Changed;
end;
procedure TCustomGrid.SetRow(aValue: Integer);
begin
if fRow = aValue then
Exit;
MoveExtend(False, fCol, aValue, True);
Changed;
Click;
end;
procedure TCustomGrid.SetRowCount(aValue: Integer);
var
old: Integer;
begin
old := fRows.Count;
if aValue = old then
Exit;
if aValue >= 0 then begin
if EditorMode and (aValue < old) then
EditorMode := False;
CheckFixed(ColCount, aValue, fFixedCols, fFixedRows);
CheckCount(ColCount, aValue);
AdjustGrid(False, old, aValue);
end else
ClearRows;
Changed;
end;
procedure TCustomGrid.SetRowHeights(aRow: Integer; aValue: Integer);
begin
if not IsRowIndexValid(aRow) then
Exit;
if aValue < 0 then
aValue := -1;
if fRows[aRow] = aValue then
Exit;
fRows[aRow] := aValue;
Changed;
end;
procedure TCustomGrid.SetScrollBars(aValue: TScrollStyle);
begin
if fScrollBars = aValue then
Exit;
fScrollBars := aValue;
Changed;
end;
procedure TCustomGrid.SetSelectedColor(aValue: TColor);
begin
if fSelectedColor = aValue then
Exit;
fSelectedColor := aValue;
Changed;
end;
procedure TCustomGrid.UpdateCachedSizes;
var
i: Integer;
begin
fGCache.GridWidth := 0;
fGCache.GridHeight := 0;
fGCache.FixedWidth := 0;
fGCache.FixedHeight := 0;
for i := 0 to ColCount - 1 do begin
fGCache.AccumWidth[i] := fGCache.GridWidth;
fGCache.GridWidth := fGCache.GridWidth + GetColWidths(i);
if i < FixedCols then
fGCache.FixedWidth := fGCache.GridWidth;
end;
for i := 0 to RowCount - 1 do begin
fGCache.AccumHeight[i] := fGCache.GridHeight;
fGCache.GridHeight := fGCache.GridHeight + GetRowHeights(i);
if i < FixedRows then
fGCache.FixedHeight := fGCache.GridHeight;
end;
{$ifdef DEBUG_GRID}
Writeln('Cached Grid Information: ');
Writeln('GridWidth: ', fGCache.GridWidth);
Writeln('GridHeight: ', fGCache.GridHeight);
Writeln('FixedWidth: ', fGCache.FixedWidth);
Writeln('FixedHeight: ', fGCache.FixedHeight);
Writeln('AccumWidth: ', fGCache.AccumWidth.Count);
for i := 0 to ColCount - 1 do
Writeln(' ', i, ': ', fGCache.AccumWidth[i]);
Writeln('AccumHeight: ', fGCache.AccumHeight.Count);
for i := 0 to RowCount - 1 do
Writeln(' ', i, ': ', fGCache.AccumHeight[i]);
{$endif}
end;
procedure TCustomGrid.AfterMoveSelection(const aPrevCol, aPrevRow: Integer);
begin
if Assigned(fOnAfterSelection) then
fOnAfterSelection(Self, aPrevCol, aPrevRow);
end;
procedure TCustomGrid.BeforeMoveSelection(const aCol, aRow: Integer);
begin
if Assigned(fOnBeforeSelection) then
fOnBeforeSelection(Self, aCol, aRow);
end;
procedure TCustomGrid.CacheMouseDown(aX, aY: Integer);
begin
fGCache.ClickMouse := Point(aX, aY);
fGCache.ClickCell := MouseToCell(fGCache.ClickMouse);
if fGCache.HotGridZone = gzInvalid then
fGCache.HotGridZone := CellToGridZone(fGCache.ClickCell.X, fGCache.ClickCell.Y);
end;
procedure TCustomGrid.CellClick(const aCol, aRow: Integer;
const aButton: TMouseButton);
begin
{ empty }
end;
procedure TCustomGrid.Changed;
procedure AdjustRows(aTable: TJSHTMLTableElement; aCount: LongInt);
begin
if aTable.rows.length <> aCount then begin
while aTable.rows.length > aCount do
aTable.deleteRow(aTable.rows.length - 1);
while aTable.rows.length < aCount do
aTable.insertRow(aTable.rows.length);
end;
end;
procedure AdjustCells(aRow: TJSHTMLTableRowElement; aCount: LongInt);
var
cell: TJSHTMLTableCellElement;
begin
if aRow.cells.length <> aCount then begin
while aRow.cells.length > aCount do
aRow.deleteCell(aRow.cells.length - 1);
while aRow.cells.length < aCount do begin
cell := aRow.insertCell(aRow.cells.length);
cell.appendChild(document.createElement('div'));
end;
end;
end;
procedure UpdateCell(aCell: TJSHTMLTableDataCellElement; aCol, aRow: LongInt; aColumn: TGridColumn; aIsLastCol, aIsLastRow: Boolean);
var
content: TJSHTMLElement;
w, h: LongInt;
style: TJSCSSStyleDeclaration;
bs: String;
alignment: TAlignment;
layout: TTextLayout;
begin
content := TJSHTMLElement(aCell.getElementsByTagName('div')[0]);
if Assigned(aColumn) and (aRow = 0) then
content.textContent := aColumn.Title.Caption
else
content.textContent := GetCells(aCol, aRow);
alignment := taLeftJustify;
layout := tlCenter;
if Assigned(aColumn) then begin
if aRow = 0 then begin
alignment := aColumn.Title.Alignment;
layout := aColumn.Title.Layout;
end else begin
alignment := aColumn.Alignment;
layout := aColumn.Layout;
end;
end;
w := fCols[aCol];
if w < 0 then
w := DefaultColWidth;
{ respect border width }
if w > 0 then
Dec(w);
if (w > 0) and (aCol = 0) then
Dec(w);
if w < 0 then
content.style.removeProperty('width')
else
content.style.setProperty('width', IntToStr(w) + 'px');
h := fRows[aRow];
if h < 0 then
h := DefaultRowHeight;
{ respect border width }
if h > 0 then
Dec(h);
if (h > 0) and (aRow = 0) then
Dec(h);
if h < 0 then begin
content.style.removeProperty('height');
content.style.removeProperty('line-height');
end else begin
content.style.setProperty('height', IntToStr(h) + 'px');
content.style.setProperty('line-height', IntToStr(h) + 'px');
end;
style := aCell.style;
style.SetProperty('white-space', 'nowrap');
style.SetProperty('overflow', 'hidden');
if (fSelectedColor <> clNone) and GetIsCellSelected(aCol, aRow) and
(aCol >= fFixedCols) and (aRow >= fFixedRows) then
content.style.setProperty('background-color', JSColor(fSelectedColor, 255))
else
content.style.removeProperty('background-color');
content.style.setProperty('text-align', AlignmentToCSSAlignment(alignment));
{ does not yet work :/ }
content.style.setProperty('vertical-align', TextLayoutToCSSVerticalAlign(layout));
bs := PenStyleToCSSBorderStyle(fGridLineStyle);
style.SetProperty('border-left-style', bs);
style.SetProperty('border-top-style', bs);
if aIsLastCol then
style.SetProperty('border-right-style', bs)
else
style.RemoveProperty('border-right-style');
if aIsLastRow then
style.SetProperty('border-bottom-style', bs)
else
style.RemoveProperty('border-bottom-style');
style.SetProperty('border-width', IntToStr(fGridLineWidth) + 'px');
style.SetProperty('border-color', JSColor(fGridLineColor, 255));
end;
procedure UpdateFixedCell(aCell: TJSHTMLTableDataCellElement; aCol, aRow: LongInt; aColumn: TGridColumn; aIsLastCol, aIsLastRow: Boolean);
var
c: TColor;
begin
UpdateCell(aCell, aCol, aRow, aColumn, aIsLastCol, aIsLastRow);
c := FixedColor;
if c <> clNone then
aCell.style.SetProperty('background-color', JSColor(c))
else
aCell.style.removeProperty('background-color');
aCell.style.SetProperty('border-color', JSColor(fFixedGridLineColor));
if (aCol = 0) then
aCell.style.setProperty('border-left-color', JSColor(fGridLineColor));
if (aRow = 0) then
aCell.style.setProperty('border-top-color', JSColor(fGridLineColor));
end;
procedure AppendOrRemoveNode(aContainer, aNode: TJSHTMLElement; aAdd: Boolean);
begin
if aAdd then begin
if not aContainer.contains(aNode) then
aContainer.appendChild(aNode);
end else begin
if aContainer.contains(aNode) then
aContainer.removeChild(aNode);
end;
end;
var
row, rowtop, rowleft, rowtopleft: TJSHTMLTableRowElement;
i, j: LongInt;
cell: TJSHTMLTableDataCellElement;
container: TJSHTMLElement;
usecolumns: Boolean;
column: TGridColumn;
begin
inherited Changed;
container := TJSHTMLElement(HandleElement);
ApplyScrollStyleToStyle(container.style, ScrollBars);
if BorderStyle = bsSingle then begin
container.style.setProperty('border-color', JSColor(BorderColor));
container.style.setProperty('border-style', 'solid');
container.style.setProperty('border-width', '1px');
end;
{ ensure that a new stacking context for the z-index is opened }
container.style.SetProperty('opacity', '0.99');
if not Assigned(fContentTable) then begin
fContentTable := TJSHTMLTableElement(document.createElement('table'));
fContentTable.style.setProperty('position', 'relative');
fContentTable.style.setProperty('z-index', '1');
fContentTable.cellSpacing := '0px';
fContentTable.cellPadding := '0px';
{ always add the content table }
container.appendChild(fContentTable);
end;
if not Assigned(fFixedColsTable) then begin
fFixedColsTable := TJSHTMLTableElement(document.createElement('table'));
fFixedColsTable.style.setProperty('position', 'absolute');
fFixedColsTable.style.setProperty('z-index', '2');
fFixedColsTable.style.setProperty('left', '0px');
fFixedColsTable.style.setProperty('top', '0px');
fFixedColsTable.cellSpacing := '0px';
fFixedColsTable.cellPadding := '0px';
end;
if not Assigned(fFixedRowsTable) then begin
fFixedRowsTable := TJSHTMLTableElement(document.createElement('table'));
fFixedRowsTable.style.setProperty('position', 'absolute');
fFixedRowsTable.style.setProperty('z-index', '3');
fFixedRowsTable.style.setProperty('left', '0px');
fFixedRowsTable.style.setProperty('top', '0px');
fFixedRowsTable.cellSpacing := '0px';
fFixedRowsTable.cellPadding := '0px';
end;
if not Assigned(fFixedTopLeftTable) then begin
fFixedTopLeftTable := TJSHTMLTableElement(document.createElement('table'));
fFixedTopLeftTable.style.setProperty('position', 'absolute');
fFixedTopLeftTable.style.setProperty('z-index', '4');
fFixedTopLeftTable.style.setProperty('left', '0px');
fFixedTopLeftTable.style.setProperty('top', '0px');
fFixedTopLeftTable.cellSpacing := '0px';
fFixedTopLeftTable.cellPadding := '0px';
end;
AppendOrRemoveNode(container, fFixedRowsTable, FixedRows > 0);
AppendOrRemoveNode(container, fFixedColsTable, FixedCols > 0);
AppendOrRemoveNode(container, fFixedTopLeftTable, (FixedRows > 0) and (FixedCols > 0));
AdjustRows(fContentTable, fRows.Count);
AdjustRows(fFixedColsTable, fRows.Count);
AdjustRows(fFixedRowsTable, FixedRows);
AdjustRows(fFixedTopLeftTable, FixedRows);
usecolumns := columns.Enabled;
for i := 0 to fContentTable.rows.length - 1 do begin
row := TJSHTMLTableRowElement(fContentTable.rows[i]);
AdjustCells(row, fCols.Count);
if i < FixedRows then begin
rowtop := TJSHTMLTableRowElement(fFixedRowsTable.rows[i]);
AdjustCells(rowtop, fCols.Count);
end else
rowtop := Nil;
if FixedCols > 0 then begin
rowleft := TJSHTMLTableRowElement(fFixedColsTable.rows[i]);
AdjustCells(rowleft, FixedCols);
end else
rowleft := Nil;
if (i < FixedRows) and (FixedCols > 0) then begin
rowtopleft := TJSHTMLTableRowElement(fFixedTopLeftTable.rows[i]);
AdjustCells(rowtopleft, FixedCols);
end else
rowtopleft := Nil;
for j := 0 to row.cells.length - 1 do begin
cell := TJSHTMLTableDataCellElement(row.cells[j]);
column := Nil;
if usecolumns and IsColumnIndexVariable(j) then
column := ColumnFromGridColumn(j);
UpdateCell(cell, j, i, column, j = ColCount - 1, i = RowCount - 1);
if j < FixedCols then begin
cell := TJSHTMLTableDataCellElement(rowleft.cells[j]);
UpdateFixedCell(cell, j, i, column, j = FixedCols - 1, (i = FixedRows - 1) and (RowCount = 1))
end;
if i < FixedRows then begin
cell := TJSHTMLTableDataCellElement(rowtop.cells[j]);
UpdateFixedCell(cell, j, i, column, (j = FixedCols - 1) and (ColCount = 1), i = FixedRows - 1);
end;
if (j < FixedCols) and (i < FixedRows) then begin
cell := TJSHTMLTableDataCellElement(rowtopleft.cells[j]);
UpdateFixedCell(cell, j, i, column, (j = FixedCols - 1) and (ColCount = 1), (i = FixedRows - 1) and (RowCount = 1));
end;
end;
end;
end;
procedure TCustomGrid.CheckLimits(var aCol, aRow: Integer);
begin
if aCol < fFixedCols then
aCol := fFixedCols
else if aCol > ColCount - 1 then
aCol := ColCount - 1;
if aRow < fFixedRows then
aRow := fFixedRows
else if aRow > RowCount - 1 then
aRow := RowCount - 1;
end;
function TCustomGrid.ColumnFromGridColumn(aColumn: Integer): TGridColumn;
var
idx: Integer;
begin
idx := ColumnIndexFromGridColumn(aColumn);
if idx >= 0 then
Result := Columns[idx]
else
Result := Nil;
end;
function TCustomGrid.ColumnIndexFromGridColumn(aColumn: Integer): Integer;
begin
if Columns.Enabled and (aColumn >= FirstGridColumn) then
Result := Columns.RealIndex(aColumn - FirstGridColumn)
else
Result := -1;
end;
procedure TCustomGrid.ColumnsChanged(aColumn: TGridColumn);
begin
if csDestroying in ComponentState then
Exit;
if not Assigned(aColumn) then begin
if FirstGridColumn + Columns.VisibleCount <> ColCount then
InternalSetColCount(FirstGridColumn + Columns.VisibleCount)
else
Changed;
end else begin
if Columns.IndexOf(aColumn) >= 0 then
Changed;
end;
end;
function TCustomGrid.CreateColumns: TGridColumns;
begin
Result := TGridColumns.Create(Self, TGridColumn);
end;
function TCustomGrid.CreateHandleElement: TJSHTMLElement;
begin
Result := TJSHTMLElement(document.createElement('div'));
end;
procedure TCustomGrid.DoScroll;
var
container: TJSHTMLElement;
begin
inherited DoScroll;
container := HandleElement;
if Assigned(fFixedColsTable) then
fFixedColsTable.style.setProperty('left', IntToStr(container.scrollLeft) + 'px');
if Assigned(fFixedColsTable) then
fFixedRowsTable.style.setProperty('top', IntToStr(container.scrollTop) + 'px');
if Assigned(fFixedTopLeftTable) then begin
fFixedTopLeftTable.style.setProperty('top', IntToStr(container.scrollTop) + 'px');
fFixedTopLeftTable.style.setProperty('left', IntToStr(container.scrollLeft) + 'px');
end;
end;
function TCustomGrid.FirstGridColumn: Integer;
begin
Result := FixedCols;
end;
function TCustomGrid.FixedGrid: Boolean;
begin
Result := (FixedCols = ColCount) or (FixedRows = RowCount);
end;
function TCustomGrid.GetCells(aCol, aRow: Integer): String;
begin
Result := '';
end;
function TCustomGrid.GetDefaultRowHeight: Integer;
begin
Result := Font.TextHeight('Xy') + 7;
end;
function TCustomGrid.GetIsCellSelected(aCol, aRow: Integer): Boolean;
begin
Result := (fRange.Left <= aCol) and (aCol <= fRange.Right) and
(fRange.Top <= aRow) and (aRow <= fRange.Bottom);
end;
function TCustomGrid.GridColumnFromColumnIndex(aColumnIndex: Integer): Integer;
begin
Result := aColumnIndex + FirstGridColumn;
if Result > ColCount - 1 then
Result := -1;
end;
procedure TCustomGrid.InternalSetColCount(aCount: Integer);
var
old: Integer;
begin
old := fCols.Count;
if old = aCount then
Exit;
if aCount < 1 then
Clear
else begin
if EditorMode and (aCount < old) then
EditorMode := False;
CheckFixed(aCount, RowCount, FixedCols, FixedRows);
CheckCount(aCount, RowCount);
AdjustGrid(True, old, aCount);
end;
end;
procedure TCustomGrid.InvalidateCell(aCol, aRow: Integer; aRedraw: Boolean);
begin
{ ToDo }
end;
function TCustomGrid.IsColumnIndexValid(aIndex: Integer): Boolean;
begin
Result := (aIndex >= 0) and (aIndex < ColCount);
end;
function TCustomGrid.IsColumnIndexVariable(aIndex: Integer): Boolean;
begin
Result := (aIndex >= fFixedCols) and (aIndex < ColCount);
end;
function TCustomGrid.IsRowIndexValid(aIndex: Integer): Boolean;
begin
Result := (aIndex >= 0) and (aIndex < RowCount);
end;
function TCustomGrid.IsRowIndexVariable(aIndex: Integer): Boolean;
begin
Result := (aIndex >= fFixedRows) and (aIndex < RowCount);
end;
procedure TCustomGrid.MouseDown(aButton: TMouseButton; aShift: TShiftState; aX,
aY: integer);
begin
inherited MouseDown(aButton, aShift, aX, aY);
if csDesigning in ComponentState then
Exit;
if not Focused then begin
SetFocus;
if not Focused then
Exit;
end;
CacheMouseDown(aX, aY);
case fGCache.HotGridZone of
gzNormal: begin
if not FixedGrid then begin
fGridState := gsSelecting;
if not MoveExtend(False, fGCache.ClickCell.x, fGCache.ClickCell.y, False) then begin
MoveSelection;
end else
fGridState := gsSelecting;
Changed;
end;
end;
{ ToDo }
gzFixedCols: ;
gzFixedRows: ;
gzFixedCells: ;
end;
end;
procedure TCustomGrid.MouseMove(aShift: TShiftState; aX, aY: integer);
var
cell: TGridCoord;
begin
inherited MouseMove(aShift, aX, aY);
HeadersMouseMove(aX, aY);
end;
procedure TCustomGrid.MouseUp(aButton: TMouseButton; aShift: TShiftState; aX,
aY: integer);
var
cur: TGridCoord;
gz: TGridZone;
function IsValidCellClick: Boolean;
begin
Result := (Cur.X = fGCache.ClickCell.X) and (Cur.Y = fGCache.ClickCell.Y) and (gz <> gzInvalid);
end;
begin
inherited MouseUp(aButton, aShift, aX, aY);
cur := MouseToCell(Point(aX, aY));
gz := CellToGridZone(cur.x, cur.y);
case fGridState of
gsNormal: begin
if not FixedGrid and IsValidCellClick then begin
CellClick(cur.x, cur.y, aButton);
end;
end;
gsSelecting: begin
CellClick(cur.x, cur.y, aButton);
end;
{ ToDo }
gsRowSizing: ;
gsColSizing: ;
gsRowMoving: ;
gsColMoving: ;
gsHeaderClicking: ;
gsButtonColumnClicking: ;
end;
end;
function TCustomGrid.MoveExtend(aRelative: Boolean; aCol, aRow: Integer;
aForceFullyVisible: Boolean): Boolean;
var
oldrange: TGridRect;
prevrow, prevcol: Integer;
begin
Result := TryMoveSelection(aRelative, aCol, aRow);
if not Result then
Exit;
BeforeMoveSelection(aCol, aRow);
oldrange := fRange;
prevrow := fRow;
prevcol := fCol;
if goRowSelect in Options then
fRange := Rect(fFixedCols, aRow, ColCount - 1, aRow)
else
fRange := Rect(aCol, aRow, aCol, aRow);
{if not }ScrollToCell(aCol, aRow, aForceFullyVisible){ then
InvalidateMovement(aCol, aRow, oldrange)};
//Writeln('New selection: ', fCol, ' ', fRow);
fCol := aCol;
fRow := aRow;
MoveSelection;
AfterMoveSelection(prevcol, prevrow);
end;
function TCustomGrid.MoveNextSelectable(aRelative: Boolean; aDCol,
aDRow: Integer): Boolean;
var
cinc, rinc: Integer;
ncol, nrow: Integer;
begin
{ Reference }
if not aRelative then begin
ncol := aDCol;
nrow := aDRow;
aDCol := ncol - fCol;
aDRow := nrow - fRow;
end else begin
ncol := fCol + aDCol;
nrow := fRow + aDRow;
end;
CheckLimits(ncol, nrow);
{ Increment }
if aDCol < 0 then
cinc := -1
else if aDCol > 0 then
cinc := 1
else
cinc := 0;
if aDRow < 0 then
rinc := -1
else if aDRow > 0 then
rinc := 1
else
rinc := 0;
{ Calculate }
Result := False;
while ((ColWidths[ncol] = 0) and (cinc <> 0))
or ((RowHeights[nrow] = 0) and (rinc <> 0)) do
begin
if not (IsRowIndexVariable(nrow + rinc) and IsColumnIndexVariable(ncol + cinc)) then
Exit;
Inc(ncol, cinc);
Inc(nrow, rinc);
end;
Result := MoveExtend(False, ncol, nrow, True);
end;
procedure TCustomGrid.MoveSelection;
begin
if Assigned(fOnSelection) then
fOnSelection(Self, fCol, fRow);
end;
function TCustomGrid.OffsetToColRow(aIsCol, aFisical: Boolean;
aOffset: Integer; out aIndex, aRest: Integer): Boolean;
begin
aIndex := 0;
aRest := 0;
Result := False;
//aOffset := aOffset - GetBorderWidth;
if aOffset < 0 then
Exit;
if aIsCol then begin
if aFisical and (aOffset > fGCache.FixedWidth - 1) then begin
aIndex := fTopLeft.X;
if IsColumnIndexValid(aIndex) then begin
aOffset := aOffset - fGCache.FixedWidth + fGCache.AccumWidth[aIndex];
end;
if not IsColumnIndexValid(aIndex) or (aOffset > fGCache.GridWidth - 1) then begin
if AllowOutboundEvents then
aIndex := ColCount - 1
else
aIndex := -1;
Exit;
end;
end;
while aOffset > fGCache.AccumWidth[aIndex] + GetColWidths(aIndex) - 1 do begin
Inc(aIndex);
if not IsColumnIndexValid(aIndex) then begin
if AllowOutBoundEvents then
aIndex := ColCount - 1
else
aIndex := -1;
Exit;
end;
end;
aRest := aOffset;
if aIndex <> 0 then
aRest := aOffset - fGCache.AccumWidth[aIndex];
end else begin
if aFisical and (aOffset > fGCache.FixedHeight - 1) then begin
aIndex := fTopLeft.Y;
if IsRowIndexValid(aIndex) then begin
aOffset := aOffset - fGCache.FixedHeight + fGCache.AccumHeight[aIndex];
end;
if not IsRowIndexValid(aIndex) or (aOffset > fGCache.GridHeight - 1) then begin
if AllowOutboundEvents then
aIndex := RowCount - 1
else
aIndex := -1;
Exit;
end;
end;
while aOffset > fGCache.AccumHeight[aIndex] + GetRowHeights(aIndex) - 1 do begin
Inc(aIndex);
if not IsRowIndexValid(aIndex) then begin
if AllowOutBoundEvents then
aIndex := RowCount - 1
else
aIndex := -1;
Exit;
end;
end;
aRest := aOffset;
if aIndex <> 0 then
aRest := aOffset - fGCache.AccumHeight[aIndex];
end;
Result := True;
end;
function TCustomGrid.SelectCell(aCol, aRow: Integer): Boolean;
begin
Result := (ColWidths[aCol] > 0) and (RowHeights[aRow] > 0);
end;
procedure TCustomGrid.SizeChanged(aOldColCount, aOldRowCount: Integer);
begin
{ empty }
end;
function TCustomGrid.TryMoveSelection(aRelative: Boolean; var aCol,
aRow: Integer): Boolean;
begin
Result := False;
if FixedGrid then
Exit;
if aRelative then begin
Inc(aCol, fCol);
Inc(aRow, fRow);
end;
CheckLimits(aCol, aRow);
// Change on Focused cell?
if (aCol = fCol) and (aRow = fRow) then
SelectCell(aCol, aRow)
else
Result := SelectCell(aCol, aRow);
end;
procedure TCustomGrid.TopLeftChanged;
begin
if Assigned(OnTopLeftChanged) and not (csDesigning in ComponentState) then
OnTopLeftChanged(Self);
end;
procedure TCustomGrid.UpdateBorderStyle;
var
bs: TBorderStyle;
begin
if not Flat and (fGridBorderStyle = bsSingle) then
bs := bsSingle
else
bs := bsNone;
inherited SetBorderStyle(bs);
if [csDestroying, csLoading] * ComponentState = [] then begin
VisualChange;
end;
end;
procedure TCustomGrid.VisualChange;
begin
if fUpdateCount <> 0 then
Exit;
Invalidate;
end;
constructor TCustomGrid.Create(aOwner: TComponent);
begin
fGCache.AccumWidth := TIntegerList.Create;
fGCache.AccumHeight := TIntegerList.Create;
fGCache.ClickCell := point(-1, -1);
inherited Create(aOwner);
fTopLeft := Point(1, 1);
fCols := TIntegerList.Create;
fRows := TIntegerList.Create;
fColumns := CreateColumns;
fDefColWidth := -1;
fDefRowHeight := -1;
fAllowOutboundEvents := True;
fScrollBars := ssAutoBoth;
fGridLineColor := clSilver;
fGridLineWidth := 1;
fGridLineStyle := psSolid;
fFixedColor := clBtnFace;
fFixedGridLineColor := cl3DDkShadow;
fBorderColor := cl3DDkShadow;
fOptions := DefaultGridOptions;
fGridState := gsNormal;
fFlat := False;
fGridBorderStyle := bsSingle;
UpdateBorderStyle;
fRange := Rect(-1, -1, -1, -1);
fSelectedColor := clHighlight;
ResetHotCell;
ColCount := 5;
RowCount := 5;
FixedRows := 1;
FixedCols := 1;
end;
destructor TCustomGrid.Destroy;
begin
fColumns.Free;
fCols.Free;
fRows.Free;
fGCache.AccumHeight.Free;
fGCache.AccumWidth.Free;
inherited Destroy;
end;
function TCustomGrid.CellToGridZone(aCol, aRow: Integer): TGridZone;
begin
if (aCol < 0) or (aRow < 0) then
Result := gzInvalid
else if aCol < FFixedCols then
if aRow < FFixedRows then
Result := gzFixedCells
else
Result := gzFixedRows
else if aRow < FFixedRows then
if aCol < FFixedCols then
Result := gzFixedCells
else
Result := gzFixedCols
else
Result := gzNormal;
end;
procedure TCustomGrid.Clear;
var
rowschanged, colschanged: Boolean;
begin
rowschanged := ClearRows;
colschanged := ClearCols;
if not (rowschanged or colschanged) then
Exit;
fRange := Rect(-1, -1, -1, -1);
ResetHotCell;
Changed;
end;
function TCustomGrid.ClearCols: Boolean;
begin
Result := False;
if fCols.Count = 0 then
Exit;
fFixedCols := 0;
fCols.Clear;
Result := True;
end;
function TCustomGrid.ClearRows: Boolean;
begin
Result := False;
if fRows.Count = 0 then
Exit;
fFixedRows := 0;
fRows.Clear;
Result := True;
end;
procedure TCustomGrid.InvalidateCell(aCol, aRow: Integer);
begin
InvalidateCell(aCol, aRow, True);
end;
procedure TCustomGrid.MouseToCell(aX, aY: Integer; out aCol, aRow: Integer);
var
dummy: Integer;
begin
OffsetToColRow(True, True, aX + HandleElement.scrollLeft, aCol, dummy);
if aCol < 0 then
aRow := -1
else begin
OffsetToColRow(False, True, aY + HandleElement.scrollTop, aRow, dummy);
if aRow < 0 then
aCol := -1;
end;
end;
function TCustomGrid.MouseToCell(const aMouse: TPoint): TGridCoord;
begin
MouseToCell(aMouse.X, aMouse.Y, Result.X, Result.Y);
end;
function TCustomGrid.MouseToGridZone(aX, aY: Integer): TGridZone;
var
bw, r, c: Integer;
begin
bw := 0;
if aX < fGCache.FixedWidth + bw then begin
{ in fixed width zone }
if aY < fGCache.FixedHeight + bw then
Result := gzFixedCells
else begin
OffsetToColRow(False, True, aY, r, c);
if (r < 0) or (RowCount <= FixedRows) then
Result := gzInvalid
else
Result := gzFixedRows;
end;
end else if aY < fGCache.FixedHeight + bw then begin
{ in fixed height zone }
if aX < fGCache.FixedWidth + bw then
Result := gzFixedCells
else begin
OffsetToColRow(True, True, aX, r, c);
if (c < 0) or (ColCount <= FixedCols) then
Result := gzInvalid
else
Result := gzFixedCols;
end;
end else if not FixedGrid then begin
{ in normal cell zone }
MouseToCell(aX, aY, c, r);
if (c < 0) or (r < 0) then
Result := gzInvalid
else
Result := gzNormal;
end else
Result := gzInvalid;
end;
end.
| 26.206791 | 140 | 0.710384 |
47543251d8b670a7230e0f4de4f4e05de2804c7a | 1,809 | pas | Pascal | windows/src/ext/jedi/jvcl/tests/archive/jvcl/examples/JvPlugin/1SimplePlugin/SamplePluginOneU.pas | bravogeorge/keyman | c0797e36292de903d7313214d1f765e3d9a2bf4d | [
"MIT"
]
| 219 | 2017-06-21T03:37:03.000Z | 2022-03-27T12:09:28.000Z | windows/src/ext/jedi/jvcl/tests/archive/jvcl/examples/JvPlugin/1SimplePlugin/SamplePluginOneU.pas | bravogeorge/keyman | c0797e36292de903d7313214d1f765e3d9a2bf4d | [
"MIT"
]
| 4,451 | 2017-05-29T02:52:06.000Z | 2022-03-31T23:53:23.000Z | windows/src/ext/jedi/jvcl/tests/archive/jvcl/examples/JvPlugin/1SimplePlugin/SamplePluginOneU.pas | bravogeorge/keyman | c0797e36292de903d7313214d1f765e3d9a2bf4d | [
"MIT"
]
| 72 | 2017-05-26T04:08:37.000Z | 2022-03-03T10:26:20.000Z | unit SamplePluginOneU;
interface
uses
Windows,
Messages,
SysUtils,
Classes,
Dialogs,
Forms,
JvPlugin;
type
TSampleUILPlugin = class(TJvPlugin)
procedure uilPlugin1Commands0Execute(Sender: TObject);
procedure uilPlugin1Commands1Execute(Sender: TObject);
procedure uilPlugin1Commands2Execute(Sender: TObject);
procedure uilPlugin1PluginMessage(Sender: TObject; APluginMessage: Integer; AMessageText: string);
procedure uilPlugin1Configure(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
function RegisterPlugin: TSampleUILPlugin; stdcall;
implementation
{$R *.DFM}
// IMPORTANT NOTE: If you change the name of the Plugin container,
// you must set the type below to the same type. (Delphi changes
// the declaration, but not the procedure itself. Both the return
// type and the type created must be the same as the declared type above.
function RegisterPlugin: TSampleUILPlugin;
begin
Result := TSampleUILPlugin.Create(nil);
end;
procedure TSampleUILPlugin.uilPlugin1Commands0Execute(Sender: TObject);
begin
ShowMessage('Command One clicked');
end;
procedure TSampleUILPlugin.uilPlugin1Commands1Execute(Sender: TObject);
begin
ShowMessage('Command Two clicked');
end;
procedure TSampleUILPlugin.uilPlugin1Commands2Execute(Sender: TObject);
begin
ShowMessage('Command Three clicked');
end;
procedure TSampleUILPlugin.uilPlugin1PluginMessage(Sender: TObject;
APluginMessage: Integer; AMessageText: string);
begin
ShowMessage(Format('Plugin Message number %d received. MessageText: %s', [APluginMessage, AMessageText]));
end;
procedure TSampleUILPlugin.uilPlugin1Configure(Sender: TObject);
begin
ShowMessage('You could put a configuration dialog here, if your plugin requires one.');
end;
end.
| 25.478873 | 108 | 0.7822 |
47a610b9652e543db42b5694ee939a3793d2d2c3 | 941 | pas | Pascal | src/interfaces/Ragna.Criteria.Intf.pas | GussCloud/ragna | 3cf388e0d85b53e8547d534958a6c1886155d37e | [
"MIT"
]
| null | null | null | src/interfaces/Ragna.Criteria.Intf.pas | GussCloud/ragna | 3cf388e0d85b53e8547d534958a6c1886155d37e | [
"MIT"
]
| null | null | null | src/interfaces/Ragna.Criteria.Intf.pas | GussCloud/ragna | 3cf388e0d85b53e8547d534958a6c1886155d37e | [
"MIT"
]
| null | null | null | unit Ragna.Criteria.Intf;
interface
uses Data.DB;
type
ICriteria = interface
['{BC7603D3-DB7D-4A61-AA73-E1152A933E07}']
procedure Where(const AField: string); overload;
procedure Where(const AField: TField); overload;
procedure Where(const AValue: Boolean); overload;
procedure &Or(const AField: string); overload;
procedure &Or(const AField: TField); overload;
procedure &And(const AField: string); overload;
procedure &And(const AField: TField); overload;
procedure Like(const AValue: string);
procedure &Equals(const AValue: Int64); overload;
procedure &Equals(const AValue: Boolean); overload;
procedure &Equals(const AValue: string); overload;
procedure Less(const AField: string); overload;
procedure Less(const AField: TField); overload;
procedure Order(const AField: string); overload;
procedure Order(const AField: TField); overload;
end;
implementation
end.
| 31.366667 | 55 | 0.724761 |
fc030845f1e777645de05e8f6e58d5da46cb4ff4 | 15,349 | pas | Pascal | src/vbitmapfont.pas | tehtmi/fpcvalkyrie | b8c65c99f3109e2df21fda6d33b7e1c17e13e411 | [
"MIT"
]
| 17 | 2016-12-06T23:58:53.000Z | 2019-05-20T16:23:14.000Z | src/vbitmapfont.pas | tehtmi/fpcvalkyrie | b8c65c99f3109e2df21fda6d33b7e1c17e13e411 | [
"MIT"
]
| 3 | 2016-12-07T14:54:36.000Z | 2018-01-27T07:25:15.000Z | src/vbitmapfont.pas | tehtmi/fpcvalkyrie | b8c65c99f3109e2df21fda6d33b7e1c17e13e411 | [
"MIT"
]
| 13 | 2016-12-06T20:35:57.000Z | 2019-04-12T18:21:09.000Z | {$INCLUDE valkyrie.inc}
unit vbitmapfont;
interface
uses Classes, SysUtils, vtextures, vgltypes, vimage, vnode, DOM;
type TBitmapFontGylph = record
Present : Boolean;
Advance : Word;
Position : TGLVec2i;
Size : TGLVec2i;
GLQTexCoord : TGLRawQTexCoord;
Kerning : array[32..127] of Byte;
end;
type TBitmapFont = class(TVObject)
constructor CreateFromGrid( aTextureID : TTextureID; aGridX : DWord; aCount : Byte; aShift : Byte = 0 );
constructor CreateFromGrid( aTextureID : TTextureID; aCount : DWord; aWidthData : PByte; aShift : Byte = 0; aSkip : Byte = 0 );
constructor CreateFromXML( aTextureID : TTextureID; aXML : TXMLDocument );
constructor CreateFromTTF( aTTFStream : TStream; aStreamSize, aSize : Word );
destructor Destroy; override;
function SetTexCoord( out aTexCoord : TGLRawQTexCoord; aChar : Char ) : Word;
function GetPosition( aChar : Char ) : TGLVec2i;
function GetSize( aChar : Char ) : TGLVec2i;
function GetAdvance( aChar : Char ) : Word;
function GetKerning( aChar,aChar2 : Char ) : Word;
protected
procedure Prepare( aCount : DWord );
procedure GenerateGridCoord( out aTexCoord : TGLRawQTexCoord; aGylphSize : TGLVec2f; aGridX : Byte; aIndex : Byte );
function GetGLTexture : DWord;
function GetImage : TImage;
public
FGLGylphSize : TGLVec2f;
FGylphSize : TGLVec2i;
FLowerCase : Boolean;
FCount : DWord;
FTextureID : TTextureID;
FHeight : Word;
FAscent : Integer;
FDescent : Integer;
FLineSkip : Integer;
FGylphs : array of TBitmapFontGylph;
public
property Image : TImage read GetImage;
property GLGylphSize : TGLVec2f read FGLGylphSize;
property GylphSize : TGLVec2i read FGylphSize;
property TextureID : TTextureID read FTextureID;
property GLTexture : DWord read GetGLTexture;
property LowerCase : Boolean read FLowerCase write FLowerCase;
property Height : Word read FHeight;
property Ascent : Integer read FAscent;
property Descent : Integer read FDescent;
property LineSkip : Integer read FLineSkip;
end;
implementation
uses vsdllibrary, vsdlttflibrary, vmath, math;
function CharNameToChar( const aCharName : AnsiString ) : Char;
begin
if Length( aCharName ) = 1 then Exit( aCharName[1] );
if aCharName = 'zero' then Exit('0');
if aCharName = 'one' then Exit('1');
if aCharName = 'two' then Exit('2');
if aCharName = 'three' then Exit('3');
if aCharName = 'four' then Exit('4');
if aCharName = 'five' then Exit('5');
if aCharName = 'six' then Exit('6');
if aCharName = 'seven' then Exit('7');
if aCharName = 'eight' then Exit('8');
if aCharName = 'nine' then Exit('9');
if aCharName = 'backslash' then Exit('\');
if aCharName = 'frontslash' then Exit('/');
if aCharName = 'percent' then Exit('%');
if aCharName = 'exclamation' then Exit('!');
if aCharName = 'question' then Exit('?');
if aCharName = 'space' then Exit(' ');
if aCharName = 'para_left' then Exit('(');
if aCharName = 'para_right' then Exit(')');
if aCharName = 'bracket_left' then Exit('[');
if aCharName = 'bracket_right' then Exit(']');
if aCharName = 'guillemet_left' then Exit('<');
if aCharName = 'guillemet_right' then Exit('>');
if aCharName = 'period' then Exit('.');
if aCharName = 'comma' then Exit(',');
if aCharName = 'colon' then Exit(':');
if aCharName = 'semicolon' then Exit(';');
if aCharName = 'at' then Exit('@');
if aCharName = 'quote' then Exit('"');
if aCharName = 'singlequote' then Exit('''');
if aCharName = 'caret' then Exit('^');
if aCharName = 'amp' then Exit('&');
if aCharName = 'dollar' then Exit('$');
if aCharName = 'euro' then Exit(#0);
if aCharName = 'number' then Exit('#');
if aCharName = 'bullet' then Exit(#0);
if aCharName = 'vbar' then Exit('|');
if aCharName = 'dash' then Exit(#0);
if aCharName = 'minus' then Exit('-');
if aCharName = 'plus' then Exit('+');
if aCharName = 'equals' then Exit('=');
if aCharName = 'cross' then Exit('*');
Exit(#0);
end;
{ TBitmapFont }
constructor TBitmapFont.CreateFromGrid ( aTextureID : TTextureID; aGridX : DWord; aCount : Byte; aShift : Byte ) ;
var iIndex : Byte;
iCount : Byte;
iGridY : Byte;
iTexture : TTexture;
begin
FTextureID := aTextureID;
FLowerCase := False;
Prepare( aCount + aShift );
iGridY := Ceil( aCount / aGridX );
iTexture := TTextureManager.Get().Texture[ aTextureID ];
FGylphSize.Init( iTexture.Size.X div aGridX, iTexture.Size.Y div iGridY );
FGLGylphSize.Init( iTexture.GLSize.X / aGridX, iTexture.GLSize.Y / iGridY );
for iIndex := 0 to aCount - 1 do
with FGylphs[iIndex+aShift] do
begin
GenerateGridCoord( GLQTexCoord, FGLGylphSize, aGridX, iIndex );
Position.Init( 0, 0 );
Present := True;
Advance := FGylphSize.X + 1;
Size := FGylphSize;
for iCount := Low( Kerning ) to High( Kerning ) do
Kerning[ iCount ] := Advance;
end;
FHeight := FGylphSize.Y;
FAscent := FGylphSize.Y;
FDescent := 0;
FLineSkip := FHeight+1;
end;
constructor TBitmapFont.CreateFromGrid ( aTextureID : TTextureID; aCount : DWord; aWidthData : System.PByte; aShift : Byte; aSkip : Byte ) ;
var iIndex : Byte;
iCount : Byte;
iTexture : TTexture;
begin
FTextureID := aTextureID;
FLowerCase := False;
Prepare( aCount + aShift );
iTexture := TTextureManager.Get().Texture[ aTextureID ];
FGylphSize.Init( iTexture.Size.X div 16, iTexture.Size.Y div 16 );
FGLGylphSize.Init( iTexture.GLSize.X / 16, iTexture.GLSize.Y / 16 );
for iIndex := 0 to aCount - 1 do
with FGylphs[iIndex+aShift] do
begin
GenerateGridCoord( GLQTexCoord, FGLGylphSize, 16, iIndex+aSkip );
Position.Init( 0, 0 );
Present := True;
Advance := aWidthData[ iIndex ] + 1;
Size := FGylphSize;
for iCount := Low( Kerning ) to High( Kerning ) do
Kerning[ iCount ] := Advance;
end;
FHeight := FGylphSize.Y;
FAscent := FGylphSize.Y;
FDescent := 0;
FLineSkip := FHeight+1;
end;
constructor TBitmapFont.CreateFromXML ( aTextureID : TTextureID; aXML : TXMLDocument ) ;
var iCount : Word;
iCount2 : Word;
iCharElement : TDOMElement;
iChar : Char;
iTexture : TTexture;
iPixel : TGLVec2f;
iPosA, iPosB : TGLVec2i;
iTPosA, iTPosB : TGLVec2f;
begin
FTextureID := aTextureID;
FLowerCase := True;
Prepare( 128 );
iTexture := TTextureManager.Get().Texture[ aTextureID ];
FGylphSize.Init( 0,0 );
iPixel.Init( iTexture.GLSize.X / iTexture.Size.X, iTexture.GLSize.Y / iTexture.Size.Y );
if aXML.DocumentElement.ChildNodes.Count > 0 then
for iCount := 0 to aXML.DocumentElement.ChildNodes.Count-1 do
begin
iCharElement := TDOMElement( aXML.DocumentElement.ChildNodes.Item[iCount] );
iChar := CharNameToChar( iCharElement.GetAttribute('name') );
if (iChar = #0) or (Ord(iChar) > 127) then Continue;
if iChar in ['A'..'Z'] then FLowerCase := False;
iPosA.X := StrToInt( iCharElement.GetElementsByTagName('pos_x')[0].TextContent );
iPosA.Y := StrToInt( iCharElement.GetElementsByTagName('pos_y')[0].TextContent );
iPosB.X := StrToInt( iCharElement.GetElementsByTagName('width')[0].TextContent );
iPosB.Y := StrToInt( iCharElement.GetElementsByTagName('height')[0].TextContent );
FGylphSize.X := Max( FGylphSize.X, iPosB.X );
FGylphSize.Y := Max( FGylphSize.Y, iPosB.Y );
FGylphs[ Ord(iChar) ].Present := True;
FGylphs[ Ord(iChar) ].Advance := iPosB.X + 1;
FGylphs[ Ord(iChar) ].Size := iPosB;
iTPosA.Init( iPixel.X * iPosA.X, iPixel.Y * iPosA.Y );
iTPosB.Init( iPixel.X * iPosB.X, iPixel.Y * iPosB.Y );
FGylphs[ Ord(iChar) ].GLQTexCoord.Init( iTPosA, iTPosA + iTPosB );
for iCount2 := Low( FGylphs[ Ord(iChar) ].Kerning ) to High( FGylphs[ Ord(iChar) ].Kerning ) do
FGylphs[ Ord(iChar) ].Kerning[ iCount2 ] := FGylphs[ Ord(iChar) ].Advance ;
end;
FGLGylphSize.Init( iPixel.X * FGylphSize.X, iPixel.Y * FGylphSize.Y );
for iCount := 0 to 127 do
if FGylphs[ iCount ].Present then
FGylphs[ iCount ].Position.Init( 0, 0 );
FHeight := FGylphSize.Y;
FAscent := FGylphSize.Y;
FDescent := 0;
FLineSkip := FHeight+1;
end;
constructor TBitmapFont.CreateFromTTF ( aTTFStream : TStream; aStreamSize, aSize : Word ) ;
var iFont : PTTF_Font;
iMap : PSDL_Surface;
iColor : TSDL_Color;
iCache : array[32..127] of PSDL_Surface;
iMaxLen : array[0..5] of Integer;
iCount : DWord;
iCount2 : DWord;
iTexWidth : LongInt;
iImage : TImage;
iID : AnsiString;
iChar3 : array[0..2] of Char;
iWidth : Integer;
iUnused : Integer;
iGMMinX : Integer;
iGMMaxX : Integer;
iGMMinY : Integer;
iGMMaxY : Integer;
iGMAdv : Integer;
iX, iY : Integer;
iRect : SDL_Rect;
iPixel : TGLVec2f;
iPosA : TGLVec2f;
iPosB : TGLVec2f;
begin
LoadSDLTTF;
if TTF_WasInit() = 0 then TTF_Init();
FLowerCase := False;
Prepare( 128 );
iMap := nil;
iFont := TTF_OpenFontRWOrThrow( SDL_RWopsFromStream( aTTFStream, aStreamSize ), 0, aSize );
FHeight := TTF_FontHeight( iFont );
FAscent := TTF_FontAscent( iFont );
FDescent := TTF_FontDescent( iFont );
FLineSkip := TTF_FontLineSkip( iFont );
iID := TTF_FontFaceFamilyName( iFont );
for iCount := 0 to 5 do iMaxLen[iCount] := 0;
iColor.r := 255;
iColor.g := 255;
iColor.b := 255;
iColor.unused := 0;
for iCount := 32 to 127 do
begin
iCache[iCount] := TTF_RenderGlyph_Blended( iFont, iCount, iColor );
SDL_SetAlpha( iCache[iCount], 0, 0 );
iMaxLen[ (iCount-32) div 16 ] += iCache[iCount]^.w;
end;
iTexWidth := 0;
for iCount := 0 to 5 do
if iMaxLen[iCount] > iTexWidth then
iTexWidth := iMaxLen[iCount];
iTexWidth := UpToPowerOf2( iTexWidth );
iMap := SDL_CreateRGBSurface( SDL_SWSURFACE, iTexWidth, iTexWidth, 32,
{$IFDEF ENDIAN_LITTLE}
$000000FF, $0000FF00, $00FF0000, $FF000000
{$ELSE}
$FF000000, $00FF0000, $0000FF00, $000000FF
{$ENDIF}
);
SDL_FillRect( iMap, nil, SDL_MapRGBA( iMap^.format, 0, 0, 0, 0) );
iPixel.Init( 1.0 / iTexWidth, 1.0 / iTexWidth );
iX := 0;
iY := 0;
for iCount := 32 to 127 do
begin
FGylphs[iCount].Present := True;
TTF_GlyphMetrics( iFont, iCount, iGMMinX, iGMMaxX, iGMMinY, iGMMaxY, iGMAdv );
iRect.x := iX;
iRect.y := iY;
iRect.w := iCache[iCount]^.w;
iRect.h := iCache[iCount]^.h;
SDL_UpperBlit( iCache[iCount], nil, iMap, @iRect );
FGylphs[iCount].Advance := iGMAdv;
FGylphs[iCount].Position.Init( iGMMinX, FAscent - iGMMaxY );
FGylphs[iCount].Size.Init(iCache[iCount]^.w,iCache[iCount]^.h);
iPosA.Init( iX * iPixel.X, iY * iPixel.Y );
iPosB.Init( (iX + iCache[iCount]^.w) * iPixel.X, (iY + iCache[iCount]^.h) * iPixel.Y );
FGylphs[iCount].GLQTexCoord.Init(iPosA,iPosB);
iX += iCache[iCount]^.w;
if iCount mod 16 = 15 then
begin
iY += FHeight;
iX := 0;
end;
for iCount2 := 32 to 127 do
begin
iChar3[0] := Chr(iCount2);
iChar3[1] := Chr(iCount);
iChar3[2] := #0;
TTF_SizeText( iFont, iChar3, iWidth, iUnused );
FGylphs[iCount2].Kerning[iCount] := iWidth - iGMAdv;
end;
end;
for iCount := 32 to 127 do
begin
SDL_FreeSurface( iCache[ iCount ] );
end;
TTF_CloseFont( iFont );
SDL_SetAlpha( iMap,SDL_SRCALPHA or SDL_RLEACCEL , 0 );
// SDL_SetAlpha( iMap, 0, 0 );
SDL_SaveBMP( iMap, 'test.bmp' );
iImage := TImage.Create( iMap^.pixels, iTexWidth, iTexWidth );
for iCount := 512 to 2000 do Log( IntToStr( iImage.Color[ iCount ].A ) );
iImage.RawX := iTexWidth;
iImage.RawY := iTexWidth;
SDL_FreeSurface( iMap );
iID += '_'+IntToStr( aSize );
FTextureID := TTextureManager.Get().AddImage( iID, iImage, False );
TTextureManager.Get()[FTextureID].Upload;
FGylphSize.Init( iGMMaxX - iGMMinX, iGMMaxY - iGMMinY );
FGLGylphSize.Init( iPixel.X * FGylphSize.X, iPixel.Y * FGylphSize.Y );
end;
procedure TBitmapFont.Prepare ( aCount : DWord ) ;
var iCount : DWord;
begin
SetLength( FGylphs, aCount );
FCount := aCount;
for iCount := 0 to aCount-1 do
FGylphs[ iCount ].Present := false;
end;
procedure TBitmapFont.GenerateGridCoord ( out aTexCoord : TGLRawQTexCoord; aGylphSize : TGLVec2f; aGridX : Byte; aIndex : Byte ) ;
var iPosA, iPosB : TGLVec2f;
iTex : TGLVec2i;
begin
iTex := TGLVec2i.CreateModDiv( aIndex, aGridX );
iPosA := TGLVec2f.Create( iTex.X * aGylphSize.X, iTex.Y * aGylphSize.Y );
iPosB := TGLVec2f.Create( (iTex.X+1) * aGylphSize.X, (iTex.Y+1) * aGylphSize.Y );
aTexCoord.Init( iPosA, iPosB );
end;
function TBitmapFont.GetGLTexture : DWord;
begin
Exit( TTextureManager.Get().Texture[ FTextureID ].GLTexture )
end;
function TBitmapFont.GetImage : TImage;
begin
Exit( TTextureManager.Get().Texture[ FTextureID ].Image )
end;
destructor TBitmapFont.Destroy;
begin
inherited Destroy;
end;
function TBitmapFont.SetTexCoord( out aTexCoord : TGLRawQTexCoord; aChar : Char ) : Word;
var iIndex : Byte;
begin
iIndex := Ord( aChar );
if FLowerCase and (iIndex in [Ord('A')..Ord('Z')]) then iIndex := iIndex + 32;
if (iIndex >= FCount) or (not FGylphs[ iIndex ].Present) then
begin
// log?
Exit(0);
end;
aTexCoord := FGylphs[ iIndex ].GLQTexCoord;
Exit( FGylphs[ iIndex ].Advance );
end;
function TBitmapFont.GetPosition ( aChar : Char ) : TGLVec2i;
var iIndex : Byte;
begin
iIndex := Ord( aChar );
if FLowerCase and (iIndex in [Ord('A')..Ord('Z')]) then iIndex := iIndex + 32;
if (iIndex >= FCount) or (not FGylphs[ iIndex ].Present) then
begin
Exit(TGLVec2i.Create(0,0));
end;
Exit( FGylphs[ iIndex ].Position );
end;
function TBitmapFont.GetSize ( aChar : Char ) : TGLVec2i;
var iIndex : Byte;
begin
iIndex := Ord( aChar );
if FLowerCase and (iIndex in [Ord('A')..Ord('Z')]) then iIndex := iIndex + 32;
if (iIndex >= FCount) or (not FGylphs[ iIndex ].Present) then
begin
Exit(TGLVec2i.Create(0,0));
end;
Exit( FGylphs[ iIndex ].Size );
end;
function TBitmapFont.GetAdvance ( aChar : Char ) : Word;
var iIndex : Byte;
begin
iIndex := Ord( aChar );
if FLowerCase and (iIndex in [Ord('A')..Ord('Z')]) then iIndex := iIndex + 32;
if (iIndex >= FCount) or (not FGylphs[ iIndex ].Present) then
begin
Exit(0);
end;
Exit( FGylphs[ iIndex ].Advance );
end;
function TBitmapFont.GetKerning ( aChar, aChar2 : Char ) : Word;
var iIndex : Byte;
iIndex2 : Byte;
begin
iIndex := Ord( aChar );
iIndex2 := Ord( aChar2 );
if FLowerCase then
begin
if (iIndex in [Ord('A')..Ord('Z')]) then iIndex := iIndex + 32;
if (iIndex2 in [Ord('A')..Ord('Z')]) then iIndex2 := iIndex2 + 32;
end;
if (iIndex >= FCount) or (not FGylphs[ iIndex ].Present)
or (iIndex2 >= FCount) or (not FGylphs[ iIndex2 ].Present) then
begin
Exit(0);
end;
Exit( FGylphs[ iIndex ].Kerning[ iIndex2 ] );
end;
end.
| 33.008602 | 140 | 0.637892 |
fc02232655cb286eb54ddcb9dcf62e99c8968c74 | 34,838 | pas | Pascal | Library/Embarcadero/Mels/VCL/UTQRThreading.pas | Jeanmilost/Mels | 0384db41dd1ae365f72384857e3a3dbf0b688367 | [
"MIT"
]
| 3 | 2019-10-23T13:42:42.000Z | 2021-02-13T08:15:15.000Z | Library/Embarcadero/Mels/VCL/UTQRThreading.pas | Jeanmilost/Mels | 0384db41dd1ae365f72384857e3a3dbf0b688367 | [
"MIT"
]
| null | null | null | Library/Embarcadero/Mels/VCL/UTQRThreading.pas | Jeanmilost/Mels | 0384db41dd1ae365f72384857e3a3dbf0b688367 | [
"MIT"
]
| 3 | 2018-06-17T15:35:57.000Z | 2021-02-15T15:24:11.000Z | // *************************************************************************************************
// * ==> UTQRThreading ----------------------------------------------------------------------------*
// *************************************************************************************************
// * MIT License - The Mels Library, a free and easy-to-use 3D Models library *
// * *
// * Permission is hereby granted, free of charge, to any person obtaining a copy of this software *
// * and associated documentation files (the "Software"), to deal in the Software without *
// * restriction, including without limitation the rights to use, copy, modify, merge, publish, *
// * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the *
// * Software is furnished to do so, subject to the following conditions: *
// * *
// * The above copyright notice and this permission notice shall be included in all copies or *
// * substantial portions of the Software. *
// * *
// * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING *
// * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND *
// * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
// * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
// * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
// *************************************************************************************************
{**
@abstract(@name provides the basic features to create threaded jobs and to send them to a worker.)
@image(Resources/Images/Documentation/Mels.svg)
@author(Jean-Milost Reymond)
@created(2015 - 2017, this file is part of the Mels library)
}
unit UTQRThreading;
interface
uses System.Classes,
System.SysUtils,
System.SyncObjs,
Winapi.Windows;
type
{$REGION 'Documentation'}
{**
Job status enumeration
@value(EQR_JS_Unknown Indicates that the job was still not added)
@value(EQR_JS_NotStarted Indicates that the job was added to job list, but still not started)
@value(EQR_JS_Processing Indicates that the job was started)
@value(EQR_JS_Done Indicates that the job is done)
@value(EQR_JS_Canceled Indicates that the job was canceled)
@value(EQR_JS_Error Indicates that the job is done but an error occurred)
}
{$ENDREGION}
EQRThreadJobStatus =
(
EQR_JS_Unknown = 0,
EQR_JS_NotStarted,
EQR_JS_Processing,
EQR_JS_Done,
EQR_JS_Canceled,
EQR_JS_Error
);
{$REGION 'Documentation'}
{**
Thread job helper
}
{$ENDREGION}
TQRThreadJobHelper = record
{$REGION 'Documentation'}
{**
Converts job status enumeration to string
@param(status Job status to convert)
@return(Job status as string)
}
{$ENDREGION}
class function JobStatusToStr(status: EQRThreadJobStatus): UnicodeString; static;
end;
{$REGION 'Documentation'}
{**
Basic interface for threaded jobs (NOTE using class instead of interface to avoid to use the
reference counting. Here an interface is just a basic contract that certify that several
functions should be implemented and to access them in a generic way)
}
{$ENDREGION}
TQRThreadJob = class
public
{$REGION 'Documentation'}
{**
Constructor
}
{$ENDREGION}
constructor Create; virtual;
{$REGION 'Documentation'}
{**
Destructor
}
{$ENDREGION}
destructor Destroy; override;
{$REGION 'Documentation'}
{**
Processes the job
@return(@true on success, otherwise @false)
}
{$ENDREGION}
function Process: Boolean; virtual; abstract;
{$REGION 'Documentation'}
{**
Cancels the job
}
{$ENDREGION}
procedure Cancel; virtual; abstract;
{$REGION 'Documentation'}
{**
Gets the job status
@return(The job status)
}
{$ENDREGION}
function GetStatus: EQRThreadJobStatus; virtual; abstract;
{$REGION 'Documentation'}
{**
Sets the job status
@param(status The job status)
}
{$ENDREGION}
procedure SetStatus(status: EQRThreadJobStatus); virtual; abstract;
end;
{$REGION 'Documentation'}
{**
Thread lock interface (NOTE using class instead of interface to avoid to use the reference
counting. Here an interface is just a basic contract that certify that several functions
should be implemented and to access them in a generic way)
}
{$ENDREGION}
TQRThreadLock = class
public
{$REGION 'Documentation'}
{**
Constructor
}
{$ENDREGION}
constructor Create; virtual;
{$REGION 'Documentation'}
{**
Destructor
}
{$ENDREGION}
destructor Destroy; override;
{$REGION 'Documentation'}
{**
Locks a code block to prevent access by other threads
}
{$ENDREGION}
procedure Lock; virtual; abstract;
{$REGION 'Documentation'}
{**
Unlocks a code block to allow access by other threads
}
{$ENDREGION}
procedure Unlock; virtual; abstract;
end;
{$REGION 'Documentation'}
{**
Multi threading lock using Windows features
}
{$ENDREGION}
TQRWinThreadLock = class(TQRThreadLock)
private
m_pCritical: RTL_CRITICAL_SECTION;
public
{$REGION 'Documentation'}
{**
Constructor
}
{$ENDREGION}
constructor Create; override;
{$REGION 'Documentation'}
{**
Destructor
}
{$ENDREGION}
destructor Destroy; override;
{$REGION 'Documentation'}
{**
Locks a code block to prevent access by other threads
}
{$ENDREGION}
procedure Lock; override;
{$REGION 'Documentation'}
{**
Unlocks a code block to allow access by other threads
}
{$ENDREGION}
procedure Unlock; override;
end;
{$REGION 'Documentation'}
{**
Multi threading lock using VCL features
}
{$ENDREGION}
TQRVCLThreadLock = class(TQRThreadLock)
private
m_pCritical: TCriticalSection;
public
{$REGION 'Documentation'}
{**
Constructor
}
{$ENDREGION}
constructor Create; override;
{$REGION 'Documentation'}
{**
Destructor
}
{$ENDREGION}
destructor Destroy; override;
{$REGION 'Documentation'}
{**
Locks a code block to prevent access by other threads
}
{$ENDREGION}
procedure Lock; override;
{$REGION 'Documentation'}
{**
Unlocks a code block to allow access by other threads
}
{$ENDREGION}
procedure Unlock; override;
end;
{$REGION 'Documentation'}
{**
VCL thread worker job, processes a job in a worker thread using VCL
}
{$ENDREGION}
TQRVCLThreadWorkerJob = class(TQRThreadJob)
private
m_Status: EQRThreadJobStatus;
protected
m_pLock: TQRVCLThreadLock;
public
{$REGION 'Documentation'}
{**
Constructor
}
{$ENDREGION}
constructor Create; override;
{$REGION 'Documentation'}
{**
Destructor
}
{$ENDREGION}
destructor Destroy; override;
{$REGION 'Documentation'}
{**
Gets the job status
@return(The job status)
}
{$ENDREGION}
function GetStatus: EQRThreadJobStatus; override;
{$REGION 'Documentation'}
{**
Sets the job status
@param(status The job status)
}
{$ENDREGION}
procedure SetStatus(status: EQRThreadJobStatus); override;
end;
{$REGION 'Documentation'}
{**
Called when a job is about to be processed
@param(pJob Job to process)
}
{$ENDREGION}
TQRThreadJobProcessEvent = procedure(pJob: TQRThreadJob) of object;
{$REGION 'Documentation'}
{**
Called when a job is done
@param(pJob Done job)
}
{$ENDREGION}
TQRThreadJobDoneEvent = procedure(pJob: TQRThreadJob) of object;
{$REGION 'Documentation'}
{**
Called when a job is canceled
@param(pJob Canceled job)
}
{$ENDREGION}
TQRThreadJobCancelEvent = procedure(pJob: TQRThreadJob) of object;
{$REGION 'Documentation'}
{**
Called when a job is idle
}
{$ENDREGION}
TQRThreadJobIdleEvent = procedure of object;
{$REGION 'Documentation'}
{**
Windows thread worker, executes a list of jobs, one by one, until all jobs are processed
}
{$ENDREGION}
TQRVCLThreadWorker = class(TThread)
private
m_pLock: TQRVCLThreadLock;
m_pJobs: TList;
m_pProcessingJob: TQRThreadJob;
m_Idle: Boolean;
m_IsIdle: Boolean;
m_Canceled: Boolean;
m_fOnProcess: TQRThreadJobProcessEvent;
m_fOnDone: TQRThreadJobDoneEvent;
m_fOnCanceled: TQRThreadJobCancelEvent;
m_fOnIdle: TQRThreadJobIdleEvent;
{$IF CompilerVersion <= 25}
m_Started: Boolean;
{$ENDIF}
protected
{$REGION 'Documentation'}
{**
Gets currently processing job
@return(Currently processing job, @nil if no job is currently processing)
}
{$ENDREGION}
function GetProcessingJob: TQRThreadJob; virtual;
{$REGION 'Documentation'}
{**
Gets the OnProcess callback
@return(OnProcess callback)
}
{$ENDREGION}
function GetOnProcess: TQRThreadJobProcessEvent; virtual;
{$REGION 'Documentation'}
{**
Sets the OnProcess callback
@param(fOnProcess OnProcess callback)
}
{$ENDREGION}
procedure SetOnProcess(fOnProcess: TQRThreadJobProcessEvent); virtual;
{$REGION 'Documentation'}
{**
Gets the OnDone callback
@return(OnDone callback)
}
{$ENDREGION}
function GetOnDone: TQRThreadJobDoneEvent; virtual;
{$REGION 'Documentation'}
{**
Sets the OnDone callback
@param(fOnDone OnDone callback)
}
{$ENDREGION}
procedure SetOnDone(fOnDone: TQRThreadJobDoneEvent); virtual;
{$REGION 'Documentation'}
{**
Gets the OnCanceled callback
@return(OnCanceled callback)
}
{$ENDREGION}
function GetOnCanceled: TQRThreadJobCancelEvent; virtual;
{$REGION 'Documentation'}
{**
Sets the OnCanceled callback
@param(OnCanceled OnCanceled callback)
}
{$ENDREGION}
procedure SetOnCanceled(fOnCanceled: TQRThreadJobCancelEvent); virtual;
{$REGION 'Documentation'}
{**
Gets the OnIdle callback
@return(OnIdle callback)
}
{$ENDREGION}
function GetOnIdle: TQRThreadJobIdleEvent; virtual;
{$REGION 'Documentation'}
{**
Sets the OnIdle callback
@param(OnIdle OnIdle callback)
}
{$ENDREGION}
procedure SetOnIdle(fOnIDle: TQRThreadJobIdleEvent); virtual;
{$REGION 'Documentation'}
{**
Executes work
}
{$ENDREGION}
procedure Execute; override;
{$REGION 'Documentation'}
{**
Notifies that job is about to be processed
@br @bold(NOTE) This function is executed on the calling thread side
}
{$ENDREGION}
procedure OnProcessNotify; virtual;
{$REGION 'Documentation'}
{**
Notifies that job is done
@br @bold(NOTE) This function is executed on the calling thread side
}
{$ENDREGION}
procedure OnDoneNotify; virtual;
{$REGION 'Documentation'}
{**
Notifies that job is canceled
@br @bold(NOTE) This function is executed on the calling thread side
}
{$ENDREGION}
procedure OnCanceledNotify; virtual;
{$REGION 'Documentation'}
{**
Notifies that worker is idle
@br @bold(NOTE) This function is executed on the calling thread side
}
{$ENDREGION}
procedure OnIdleNotify; virtual;
public
{$REGION 'Documentation'}
{**
Constructor
}
{$ENDREGION}
constructor Create; virtual;
{$REGION 'Documentation'}
{**
Destructor
}
{$ENDREGION}
destructor Destroy; override;
{$REGION 'Documentation'}
{**
Adds job to process list
@param(pJob Job to add)
}
{$ENDREGION}
procedure AddJob(pJob: TQRThreadJob); virtual;
{$REGION 'Documentation'}
{**
Deletes job from process list
@param(pJob Job to delete)
@param(doCancel If @true, job will be canceled before deleted)
}
{$ENDREGION}
procedure DeleteJob(pJob: TQRThreadJob; doCancel: Boolean = True); virtual;
{$REGION 'Documentation'}
{**
Pauses or resumes thread activity
@param(value If @true, thread will become idle, otherwise resume from idle state)
}
{$ENDREGION}
procedure MakeIdle(value: Boolean); virtual;
{$REGION 'Documentation'}
{**
Cancels all the jobs
}
{$ENDREGION}
procedure Cancel; virtual;
{$REGION 'Documentation'}
{**
Check if worker was canceled
@return(@true if worker was canceled, otherwise @false)
}
{$ENDREGION}
function IsCanceled: Boolean; virtual;
// Properties
public
{$REGION 'Documentation'}
{**
Gets the processing job
}
{$ENDREGION}
property ProcessingJob: TQRThreadJob read GetProcessingJob;
{$REGION 'Documentation'}
{**
Gets or sets the OnProcess event
}
{$ENDREGION}
property OnProcess: TQRThreadJobProcessEvent read GetOnProcess write SetOnProcess;
{$REGION 'Documentation'}
{**
Gets or sets the OnDone event
}
{$ENDREGION}
property OnDone: TQRThreadJobDoneEvent read GetOnDone write SetOnDone;
{$REGION 'Documentation'}
{**
Gets or sets the OnCanceled event
}
{$ENDREGION}
property OnCanceled: TQRThreadJobCancelEvent read GetOnCanceled write SetOnCanceled;
{$REGION 'Documentation'}
{**
Gets or sets the OnIdle event
}
{$ENDREGION}
property OnIdle: TQRThreadJobIdleEvent read GetOnIdle write SetOnIdle;
{$REGION 'Documentation'}
{**
Gets if the worker started
@br @bold(NOTE) This property is implemented by the VCL in RAD Studio XE7 or above
}
{$ENDREGION}
{$IF CompilerVersion <= 25}
property Started: Boolean read m_Started;
{$ENDIF}
end;
implementation
//--------------------------------------------------------------------------------------------------
// TQRThreadJobHelper
//--------------------------------------------------------------------------------------------------
class function TQRThreadJobHelper.JobStatusToStr(status: EQRThreadJobStatus): UnicodeString;
begin
case status of
EQR_JS_Unknown: Result := 'EQR_JS_Unknown';
EQR_JS_NotStarted: Result := 'EQR_JS_NotStarted';
EQR_JS_Processing: Result := 'EQR_JS_Processing';
EQR_JS_Done: Result := 'EQR_JS_Done';
EQR_JS_Canceled: Result := 'EQR_JS_Canceled';
EQR_JS_Error: Result := 'EQR_JS_Error';
else
Result := '<#ERROR (' + IntToStr(NativeInt(status)) + ')>';
end;
end;
//--------------------------------------------------------------------------------------------------
// TQRThreadJob
//--------------------------------------------------------------------------------------------------
constructor TQRThreadJob.Create;
begin
inherited Create;
end;
//--------------------------------------------------------------------------------------------------
destructor TQRThreadJob.Destroy;
begin
inherited Destroy;
end;
//--------------------------------------------------------------------------------------------------
// TQRThreadLock
//--------------------------------------------------------------------------------------------------
constructor TQRThreadLock.Create;
begin
inherited Create;
end;
//--------------------------------------------------------------------------------------------------
destructor TQRThreadLock.Destroy;
begin
inherited Destroy;
end;
//--------------------------------------------------------------------------------------------------
// TQRWinThreadLock
//--------------------------------------------------------------------------------------------------
constructor TQRWinThreadLock.Create;
begin
inherited Create;
InitializeCriticalSection(m_pCritical);
end;
//--------------------------------------------------------------------------------------------------
destructor TQRWinThreadLock.Destroy;
begin
DeleteCriticalSection(m_pCritical);
inherited Destroy;
end;
//--------------------------------------------------------------------------------------------------
procedure TQRWinThreadLock.Lock;
begin
EnterCriticalSection(m_pCritical);
end;
//--------------------------------------------------------------------------------------------------
procedure TQRWinThreadLock.Unlock;
begin
LeaveCriticalSection(m_pCritical);
end;
//--------------------------------------------------------------------------------------------------
// TQRVCLThreadLock
//--------------------------------------------------------------------------------------------------
constructor TQRVCLThreadLock.Create;
begin
inherited Create;
m_pCritical := TCriticalSection.Create;
end;
//--------------------------------------------------------------------------------------------------
destructor TQRVCLThreadLock.Destroy;
begin
m_pCritical.Free;
inherited Destroy;
end;
//--------------------------------------------------------------------------------------------------
procedure TQRVCLThreadLock.Lock;
begin
m_pCritical.Acquire;
end;
//--------------------------------------------------------------------------------------------------
procedure TQRVCLThreadLock.Unlock;
begin
m_pCritical.Release;
end;
//--------------------------------------------------------------------------------------------------
// TQRVCLThreadWorkerJob
//--------------------------------------------------------------------------------------------------
constructor TQRVCLThreadWorkerJob.Create;
begin
inherited Create;
m_Status := EQR_JS_Unknown;
m_pLock := TQRVCLThreadLock.Create;
end;
//--------------------------------------------------------------------------------------------------
destructor TQRVCLThreadWorkerJob.Destroy;
begin
m_pLock.Free;
inherited Destroy;
end;
//--------------------------------------------------------------------------------------------------
function TQRVCLThreadWorkerJob.GetStatus: EQRThreadJobStatus;
var
status: EQRThreadJobStatus;
begin
// lock thread, and access data only when entering in critical section is allowed
m_pLock.Lock;
status := m_Status;
m_pLock.Unlock;
Result := status;
end;
//--------------------------------------------------------------------------------------------------
procedure TQRVCLThreadWorkerJob.SetStatus(status: EQRThreadJobStatus);
begin
// lock thread, and access data only when entering in critical section is allowed
m_pLock.Lock;
m_Status := status;
m_pLock.Unlock;
end;
//--------------------------------------------------------------------------------------------------
// TQRVCLThreadWorker
//--------------------------------------------------------------------------------------------------
constructor TQRVCLThreadWorker.Create;
begin
inherited Create;
m_pLock := TQRVCLThreadLock.Create;
m_pJobs := TList.Create;
m_Idle := False;
m_Canceled := False;
m_pProcessingJob := nil;
m_fOnProcess := nil;
m_fOnDone := nil;
m_fOnCanceled := nil;
{$IF CompilerVersion <= 25}
m_Started := False;
{$ENDIF}
end;
//--------------------------------------------------------------------------------------------------
destructor TQRVCLThreadWorker.Destroy;
begin
// break the thread execution
Terminate;
{$IF CompilerVersion <= 25}
if (m_Started) then
{$ELSE}
if (Started) then
{$ENDIF}
// wait until worker has really stopped to work
WaitFor;
m_pJobs.Free;
m_pLock.Free;
inherited Destroy;
end;
//--------------------------------------------------------------------------------------------------
function TQRVCLThreadWorker.GetProcessingJob: TQRThreadJob;
begin
m_pLock.Lock;
Result := m_pProcessingJob;
m_pLock.Unlock;
end;
//--------------------------------------------------------------------------------------------------
function TQRVCLThreadWorker.GetOnProcess: TQRThreadJobProcessEvent;
begin
m_pLock.Lock;
Result := m_fOnProcess;
m_pLock.Unlock;
end;
//--------------------------------------------------------------------------------------------------
procedure TQRVCLThreadWorker.SetOnProcess(fOnProcess: TQRThreadJobProcessEvent);
begin
m_pLock.Lock;
m_fOnProcess := fOnProcess;
m_pLock.Unlock;
end;
//--------------------------------------------------------------------------------------------------
function TQRVCLThreadWorker.GetOnDone: TQRThreadJobDoneEvent;
begin
m_pLock.Lock;
Result := m_fOnDone;
m_pLock.Unlock;
end;
//--------------------------------------------------------------------------------------------------
procedure TQRVCLThreadWorker.SetOnDone(fOnDone: TQRThreadJobDoneEvent);
begin
m_pLock.Lock;
m_fOnDone := fOnDone;
m_pLock.Unlock;
end;
//--------------------------------------------------------------------------------------------------
function TQRVCLThreadWorker.GetOnCanceled: TQRThreadJobCancelEvent;
begin
m_pLock.Lock;
Result := m_fOnCanceled;
m_pLock.Unlock;
end;
//--------------------------------------------------------------------------------------------------
procedure TQRVCLThreadWorker.SetOnCanceled(fOnCanceled: TQRThreadJobCancelEvent);
begin
m_pLock.Lock;
m_fOnCanceled := fOnCanceled;
m_pLock.Unlock;
end;
//--------------------------------------------------------------------------------------------------
function TQRVCLThreadWorker.GetOnIdle: TQRThreadJobIdleEvent;
begin
m_pLock.Lock;
Result := m_fOnIdle;
m_pLock.Unlock;
end;
//--------------------------------------------------------------------------------------------------
procedure TQRVCLThreadWorker.SetOnIdle(fOnIdle: TQRThreadJobIdleEvent);
begin
m_pLock.Lock;
m_fOnIdle := fOnIdle;
m_pLock.Unlock;
end;
//--------------------------------------------------------------------------------------------------
procedure TQRVCLThreadWorker.Execute;
var
pProcessingJob: TQRThreadJob;
count: NativeUInt;
idle, success: Boolean;
fOnIdle: TQRThreadJobIdleEvent;
begin
{$IF CompilerVersion <= 25}
m_Started := True;
{$ENDIF}
// repeat thread execution until terminated
while (not Terminated) do
begin
m_pLock.Lock;
m_IsIdle := False;
idle := m_Idle;
m_pLock.Unlock;
// is thread idle?
if (idle) then
begin
m_pLock.Lock;
m_IsIdle := True;
fOnIdle := m_fOnIdle;
m_pLock.Unlock;
// is idle event defined?
if (not Assigned(fOnIdle)) then
// wait 10 ms to not overload the processor
Sleep(10)
else
// notify that job is idle
Synchronize(OnIdleNotify);
continue;
end;
// get job count
m_pLock.Lock;
count := m_pJobs.Count;
m_pLock.Unlock;
// no job to process for now?
if (count = 0) then
begin
// wait 10ms to not overload the processor
Sleep(10);
continue;
end;
// break the loop if worker was canceled
if (IsCanceled) then
break;
m_pLock.Lock;
try
// get job to process
m_pProcessingJob := m_pJobs[0];
// job is get and will be processed, can delete it from list
m_pJobs.Delete(0);
pProcessingJob := m_pProcessingJob;
finally
m_pLock.Unlock;
end;
// break the loop if worker was canceled
if (IsCanceled) then
break;
// skip canceled job
if (pProcessingJob.GetStatus = EQR_JS_Canceled) then
begin
m_pLock.Lock;
m_pProcessingJob := nil;
m_pLock.Unlock;
continue;
end;
// set next job status to processing
pProcessingJob.SetStatus(EQR_JS_Processing);
// notify that job is about to be processed
Synchronize(OnProcessNotify);
// process next job
success := pProcessingJob.Process;
// break the loop if worker was canceled
if (IsCanceled) then
break;
// skip canceled job
if (pProcessingJob.GetStatus = EQR_JS_Canceled) then
begin
m_pLock.Lock;
m_pProcessingJob := nil;
m_pLock.Unlock;
continue;
end;
// set job status
if (success) then
pProcessingJob.SetStatus(EQR_JS_Done)
else
pProcessingJob.SetStatus(EQR_JS_Error);
// notify that job is done
Synchronize(OnDoneNotify);
m_pLock.Lock;
m_pProcessingJob := nil;
m_pLock.Unlock;
end;
m_pLock.Lock;
m_pProcessingJob := nil;
m_pLock.Unlock;
end;
//--------------------------------------------------------------------------------------------------
procedure TQRVCLThreadWorker.OnProcessNotify;
var
pJob: TQRThreadJob;
fOnProcess: TQRThreadJobProcessEvent;
begin
// lock thread, and access data only when entering in critical section is allowed
m_pLock.Lock;
pJob := m_pProcessingJob;
fOnProcess := m_fOnProcess;
m_pLock.Unlock;
// break the loop if worker was canceled
if (IsCanceled) then
Exit;
// notify that job is about to be processed
if (Assigned(fOnProcess)) then
fOnProcess(pJob);
end;
//--------------------------------------------------------------------------------------------------
procedure TQRVCLThreadWorker.OnDoneNotify;
var
pJob: TQRThreadJob;
fOnDone: TQRThreadJobDoneEvent;
begin
// lock thread, and access data only when entering in critical section is allowed
m_pLock.Lock;
pJob := m_pProcessingJob;
fOnDone := m_fOnDone;
m_pLock.Unlock;
// break the loop if worker was canceled
if (IsCanceled) then
Exit;
// notify that job is done
if (Assigned(fOnDone)) then
fOnDone(pJob);
end;
//--------------------------------------------------------------------------------------------------
procedure TQRVCLThreadWorker.OnCanceledNotify;
var
pJob: TQRThreadJob;
fOnCanceled: TQRThreadJobCancelEvent;
begin
// lock thread, and access data only when entering in critical section is allowed
m_pLock.Lock;
pJob := m_pProcessingJob;
fOnCanceled := m_fOnCanceled;
m_pLock.Unlock;
// notify that job is canceled
if (Assigned(fOnCanceled)) then
fOnCanceled(pJob);
end;
//--------------------------------------------------------------------------------------------------
procedure TQRVCLThreadWorker.OnIdleNotify;
var
fOnIdle: TQRThreadJobIdleEvent;
begin
// lock thread, and access data only when entering in critical section is allowed
m_pLock.Lock;
fOnIdle := m_fOnIdle;
m_pLock.Unlock;
// notify that job is canceled
if (Assigned(fOnIdle)) then
fOnIdle;
end;
//--------------------------------------------------------------------------------------------------
procedure TQRVCLThreadWorker.AddJob(pJob: TQRThreadJob);
begin
m_pLock.Lock;
try
// check if job is already in the list, add it to job list if not
if (m_pJobs.IndexOf(pJob) = -1) then
begin
pJob.SetStatus(EQR_JS_NotStarted);
m_pJobs.Add(pJob);
end;
finally
m_pLock.Unlock;
end;
end;
//--------------------------------------------------------------------------------------------------
procedure TQRVCLThreadWorker.DeleteJob(pJob: TQRThreadJob; doCancel: Boolean);
begin
// no job to cancel?
if (not Assigned(pJob)) then
Exit;
// do cancel job?
if (doCancel) then
begin
// cancel processing job, if any
pJob.Cancel;
pJob.SetStatus(EQR_JS_Canceled);
end;
m_pLock.Lock;
try
m_pJobs.Remove(pJob);
finally
m_pLock.Unlock;
end;
end;
//--------------------------------------------------------------------------------------------------
procedure TQRVCLThreadWorker.MakeIdle(value: Boolean);
begin
m_pLock.Lock;
m_Idle := value;
m_pLock.Unlock;
end;
//--------------------------------------------------------------------------------------------------
procedure TQRVCLThreadWorker.Cancel;
var
pJob: Pointer;
running: Boolean;
begin
running := False;
m_pLock.Lock;
try
m_Canceled := true;
// cancel processing job, if any
if (Assigned(m_pProcessingJob)) then
begin
m_pProcessingJob.Cancel;
m_pProcessingJob.SetStatus(EQR_JS_Canceled);
running := True;
end;
finally
m_pLock.Unlock;
end;
{$IF CompilerVersion <= 25}
if (m_Started and running) then
{$ELSE}
if (Started and running) then
{$ENDIF}
begin
// wait until worker has really stopped to work
Terminate;
WaitFor;
end;
// notify that job is canceled
Synchronize(OnCanceledNotify);
// iterate through jobs to cancel
for pJob in m_pJobs do
begin
m_pLock.Lock;
try
// get next job to cancel
m_pProcessingJob := pJob;
m_pProcessingJob.SetStatus(EQR_JS_Canceled);
finally
m_pLock.Unlock;
end;
// notify that job is canceled
Synchronize(OnCanceledNotify);
end;
// clear local values
m_pLock.Lock;
m_pJobs.Clear;
m_pProcessingJob := nil;
m_pLock.Unlock;
end;
//--------------------------------------------------------------------------------------------------
function TQRVCLThreadWorker.IsCanceled: Boolean;
begin
m_pLock.Lock;
Result := m_Canceled;
m_pLock.Unlock;
end;
//--------------------------------------------------------------------------------------------------
end.
| 31.670909 | 101 | 0.474281 |
838848d258e2bc0a1a19f46a8ba8810bad80e992 | 401 | pas | Pascal | test/code_test/if_2.pas | BSpwr/Paskell | ab4a0fc750277bba54458fee5fec1a800edcbaee | [
"BSD-3-Clause"
]
| null | null | null | test/code_test/if_2.pas | BSpwr/Paskell | ab4a0fc750277bba54458fee5fec1a800edcbaee | [
"BSD-3-Clause"
]
| null | null | null | test/code_test/if_2.pas | BSpwr/Paskell | ab4a0fc750277bba54458fee5fec1a800edcbaee | [
"BSD-3-Clause"
]
| null | null | null | program If2Test;
var
grade: string = 'A';
begin
grade := 'F';
if grade = 'B' then
begin
writeln('good');
writeln('second statement of compound')
end
else if grade = 'A' then
writeln('WOW A!')
else if grade <> 'F' then
writeln('Not Fail!')
else begin
writeln('Compound statement 1');
writeln('Compound statement 2')
end;
end. | 18.227273 | 45 | 0.561097 |
c30a289d67cc0f38854f336aafc7aae0bf39fbca | 4,956 | pas | Pascal | c/sharutils-4.2.1/contrib/uuencode.pas | tolkien/misc | 84651346a3a0053b6a2af31db26c227a34da33c8 | [
"MIT"
]
| null | null | null | c/sharutils-4.2.1/contrib/uuencode.pas | tolkien/misc | 84651346a3a0053b6a2af31db26c227a34da33c8 | [
"MIT"
]
| null | null | null | c/sharutils-4.2.1/contrib/uuencode.pas | tolkien/misc | 84651346a3a0053b6a2af31db26c227a34da33c8 | [
"MIT"
]
| null | null | null | Program uuencode;
CONST header = 'begin';
trailer = 'end';
defaultMode = '644';
defaultExtension = '.uue';
offset = 32;
charsPerLine = 60;
bytesPerHunk = 3;
sixBitMask = $3F;
TYPE string80 = string[80];
VAR infile: file of byte;
outfile: text;
infilename, outfilename, mode: string80;
lineLength, numbytes, bytesInLine: integer;
line: array [0..59] of char;
hunk: array [0..2] of byte;
chars: array [0..3] of byte;
size,remaining :real;
{ procedure debug;
var i: integer;
procedure writebin(x: byte);
var i: integer;
begin
for i := 1 to 8 do
begin
write ((x and $80) shr 7);
x := x shl 1
end;
write (' ')
end;
begin
for i := 0 to 2 do writebin(hunk[i]);
writeln;
for i := 0 to 3 do writebin(chars[i]);
writeln;
for i := 0 to 3 do writebin(chars[i] and sixBitMask);
writeln
end; }
procedure Abort (message: string80);
begin {abort}
writeln(message);
close(infile);
close(outfile);
halt
end; {abort}
procedure Init;
procedure GetFiles;
VAR i: integer;
temp: string80;
ch: char;
begin {GetFiles}
if ParamCount < 1 then abort ('No input file specified.');
infilename := ParamStr(1);
{$I-}
assign (infile, infilename);
reset (infile);
{$i+}
if IOResult > 0 then abort (concat ('Can''t open file ', infilename));
size:=FileSize(infile);
if size < 0 then size:=size+65536.0;
remaining:=size;
write('Uuencoding file ', infilename);
i := pos('.', infilename);
if i = 0
then outfilename := infilename
else outfilename := copy (infilename, 1, pred(i));
mode := defaultMode;
if ParamCount > 1 then
for i := 2 to ParamCount do
begin
temp := Paramstr(i);
if temp[1] in ['0'..'9']
then mode := temp
else outfilename := temp
end;
if pos ('.', outfilename) = 0
then outfilename := concat(outfilename, defaultExtension);
assign (outfile, outfilename);
writeln (' to file ', outfilename, '.');
{$i-}
reset(outfile);
{$i+}
if IOresult = 0 then
begin
Write ('Overwrite current ', outfilename, '? [Y/N] ');
repeat
read (kbd, ch);
ch := Upcase(ch)
until ch in ['Y', 'N'];
writeln (ch);
if ch = 'N' then abort(concat (outfilename, ' not overwritten.'))
end;
close(outfile);
{$i-}
rewrite(outfile);
{$i+}
if ioresult > 0 then abort(concat('Can''t open ', outfilename));
end; {getfiles}
begin {Init}
GetFiles;
bytesInLine := 0;
lineLength := 0;
numbytes := 0;
writeln (outfile, header, ' ', mode, ' ', infilename);
end; {init}
procedure FlushLine;
VAR i: integer;
procedure writeout(ch: char);
begin {writeout}
if ch = ' ' then write(outfile, '`')
else write(outfile, ch)
end; {writeout}
begin {FlushLine}
{write ('.');}
write('bytes remaining: ',remaining:7:0,' (',
remaining/size*100.0:3:0,'%)',chr(13));
writeout(chr(bytesInLine + offset));
for i := 0 to pred(lineLength) do
writeout(line[i]);
writeln (outfile);
lineLength := 0;
bytesInLine := 0
end; {FlushLine}
procedure FlushHunk;
VAR i: integer;
begin {FlushHunk}
if lineLength = charsPerLine then FlushLine;
chars[0] := hunk[0] shr 2;
chars[1] := (hunk[0] shl 4) + (hunk[1] shr 4);
chars[2] := (hunk[1] shl 2) + (hunk[2] shr 6);
chars[3] := hunk[2] and sixBitMask;
{debug;}
for i := 0 to 3 do
begin
line[lineLength] := chr((chars[i] and sixBitMask) + offset);
{write(line[linelength]:2);}
lineLength := succ(lineLength)
end;
{writeln;}
bytesInLine := bytesInLine + numbytes;
numbytes := 0
end; {FlushHunk}
procedure encode1;
begin {encode1};
if numbytes = bytesperhunk then flushhunk;
read (infile, hunk[numbytes]);
remaining:=remaining-1;
numbytes := succ(numbytes)
end; {encode1}
procedure terminate;
begin {terminate}
if numbytes > 0 then flushhunk;
if lineLength > 0
then
begin
flushLine;
flushLine;
end
else flushline;
writeln (outfile, trailer);
close (outfile);
close (infile);
end; {terminate}
begin {uuencode}
init;
while not eof (infile) do encode1;
terminate;
writeln;
end. {uuencode}
| 24.413793 | 78 | 0.51816 |
47cff563282284ea5c311eb755d734f4596bbb70 | 14,672 | pas | Pascal | Forms/Concepts.Indy.TCP.Form.pas | Patiencer/Concepts | e63910643b2401815dd4f6b19fbdf0cd7d443392 | [
"Apache-2.0"
]
| null | null | null | Forms/Concepts.Indy.TCP.Form.pas | Patiencer/Concepts | e63910643b2401815dd4f6b19fbdf0cd7d443392 | [
"Apache-2.0"
]
| null | null | null | Forms/Concepts.Indy.TCP.Form.pas | Patiencer/Concepts | e63910643b2401815dd4f6b19fbdf0cd7d443392 | [
"Apache-2.0"
]
| 1 | 2018-10-08T07:57:42.000Z | 2018-10-08T07:57:42.000Z | {
Copyright (C) 2013-2018 Tim Sinaeve tim.sinaeve@gmail.com
Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
}
{$I Concepts.inc}
unit Concepts.Indy.TCP.Form;
{ Demonstrates how to create a TCP socket connection using Indy 10. }
{
REMARKS:
- AFAICC commandhandlers cannot be used for communication that does not
involve welcome messages and replies consisting of less than 3 characters,
unless you write your own reply class.
}
interface
uses
System.SysUtils, System.Actions, System.Classes, System.ImageList,
Vcl.Dialogs, Vcl.ActnList, Vcl.ImgList, Vcl.Menus, Vcl.Controls, Vcl.StdCtrls,
Vcl.Buttons, Vcl.ExtCtrls, Vcl.Forms, Vcl.ComCtrls,
Spring.Collections,
DDuce.Components.LogTree, DDuce.Components.PropertyInspector, DDuce.Logger,
zObjInspector, zObjInspTypes,
IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdCmdTCPClient,
IdContext, IdIntercept, IdGlobal, IdIOHandler, IdIOHandlerSocket,
IdIOHandlerStack, IdCommandHandlers;
type
TfrmIndyTCP = class(TForm)
{$REGION 'designer controls'}
aclMain : TActionList;
actClearReceived : TAction;
actClearSent : TAction;
actConnect : TAction;
actDisconnect : TAction;
actSave : TAction;
actSend : TAction;
actSendCommand : TAction;
btnClearReceived : TSpeedButton;
btnClearSent : TSpeedButton;
btnConnect : TButton;
btnDisconnect : TButton;
btnSendString : TButton;
cbxSent : TComboBox;
dlgSave : TSaveDialog;
edtPort : TEdit;
edtServer : TEdit;
IdConnectionIntercept : TIdConnectionIntercept;
ilMain : TImageList;
mmoReceivedText : TMemo;
mmoSentText : TMemo;
mniClearReceivedText : TMenuItem;
mniSave : TMenuItem;
pgcReceived : TPageControl;
pgcSend : TPageControl;
pgcSent : TPageControl;
pnlCommands : TGridPanel;
pnlLeft : TPanel;
pnlLeftBottom : TPanel;
pnlLeftTop : TPanel;
pnlLeftTopTop : TPanel;
pnlReceived : TPanel;
pnlRight : TPanel;
pnlRightBottom : TPanel;
pnlRightTop : TPanel;
pnlSend : TPanel;
pnlSent : TPanel;
ppmReceivedText : TPopupMenu;
sbrMain : TStatusBar;
splLeftHorizontal : TSplitter;
splRightHorizontal : TSplitter;
splVertical : TSplitter;
tsCommands : TTabSheet;
tsReceivedLog : TTabSheet;
tsReceivedText : TTabSheet;
tsSentLog : TTabSheet;
tsSentText : TTabSheet;
IdTCPClient: TIdTCPClient;
{$ENDREGION}
procedure actClearReceivedExecute(Sender: TObject);
procedure actClearSentExecute(Sender: TObject);
procedure actConnectExecute(Sender: TObject);
procedure actDisconnectExecute(Sender: TObject);
procedure actSaveExecute(Sender: TObject);
procedure actSendExecute(Sender: TObject);
procedure InspectorModified(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure edtServerChange(Sender: TObject);
procedure edtPortChange(Sender: TObject);
procedure IdTCPClientStatus(ASender: TObject; const AStatus: TIdStatus;
const AStatusText: string);
procedure IdConnectionInterceptReceive(ASender: TIdConnectionIntercept;
var ABuffer: TIdBytes);
private
FLogIn : TLogTree;
FLogOut : TLogTree;
FInspector : TzObjectInspector;
FUpdate : Boolean;
FPort : Integer;
FCommands : IList<TContainedAction>;
FServer : string;
function GetPort: Integer;
procedure SetPort(const Value: Integer);
function GetConnected: Boolean;
procedure SetConnected(const Value: Boolean);
function GetClient: TIdTCPClient;
procedure SetServer(const Value: string);
procedure FCommandExecute(Sender: TObject);
function FInspectorBeforeAddItem(
Sender : TControl;
PItem : PPropItem
): Boolean;
procedure CreateCommandControls;
protected
function MakeLogString(const AString: string): string;
procedure LoadSettings; virtual;
procedure SaveSettings; virtual;
procedure DoStringReceived(const AString: RawByteString); virtual;
procedure UpdateActions; override;
procedure UpdateControls; virtual;
procedure SendString(const AString: RawByteString); virtual;
procedure Modified;
property Port: Integer
read GetPort write SetPort;
property Connected: Boolean
read GetConnected write SetConnected;
property LogIn: TLogTree
read FLogIn;
property LogOut: TLogTree
read FLogIn;
property Server: string
read FServer write SetServer;
property Client: TIdTCPClient
read GetClient;
public
procedure AfterConstruction; override;
procedure BeforeDestruction; override;
end;
implementation
{$R *.dfm}
uses
System.AnsiStrings, System.Rtti,
Vcl.Graphics,
DDuce.Components.Factories, DDuce.Factories.zObjInspector,
VirtualTrees,
Spring.Cryptography,
Concepts.Factories, Concepts.Settings;
const
// conversion from a low-level control Char to its corresponding text
// - contains at least all used LIS1-A control chars
CTRL_TO_TEXT: array[#0..#31] of RawByteString = (
'NUL',
'SOH',
'STX',
'ETX',
'EOT',
'ENQ',
'ACK',
'BEL',
'BS',
'TAB',
'LF',
'VT',
'FF',
'CR',
'SO',
'SI',
'DLE',
'DC1',
'DC2',
'DC3',
'DC4',
'NAK',
'SYN',
'ETB',
'CAN',
'EM',
'SUB',
'ESC',
'FS',
'GS',
'RS',
'US'
);
SON = '<font-color=clBlack><b>ON</b></font-color>';
SOFF = '<font-color=clRed><b>OFF</b></font-color>';
{$REGION 'construction and destruction'}
procedure TfrmIndyTCP.AfterConstruction;
begin
inherited AfterConstruction;
FCommands := TCollections.CreateObjectList<TContainedAction>(False);
CreateCommandControls;
LoadSettings;
FInspector := TzObjectInspectorFactory.Create(
Self,
pnlLeftTop,
idTCPClient
);
FInspector.OnBeforeAddItem := FInspectorBeforeAddItem;
FLogIn := TDDuceComponents.CreateLogTree(Self, tsReceivedLog);
FLogIn.DateTimeFormat := 'hh:nn:ss.zzz';
FLogIn.Images := ilMain;
FLogOut := TDDuceComponents.CreateLogTree(Self, tsSentLog);
FLogOut.Images := ilMain;
FLogOut.DateTimeFormat := 'hh:nn:ss.zzz';
Modified;
end;
procedure TfrmIndyTCP.BeforeDestruction;
begin
FInspector.Component := nil;
IdTCPClient.Intercept.OnReceive := nil;
IdTCPClient.OnStatus := nil;
IdTCPClient.Intercept.Disconnect;
IdTCPClient.Disconnect;
SaveSettings;
inherited BeforeDestruction;
end;
{$ENDREGION}
{$REGION 'property access methods'}
function TfrmIndyTCP.GetPort: Integer;
begin
Result := FPort;
end;
procedure TfrmIndyTCP.SetPort(const Value: Integer);
begin
if Value <> Port then
begin
FPort := Value;
Client.Port := Value;
edtPort.Text := Value.ToString;
Modified;
end;
end;
procedure TfrmIndyTCP.SetServer(const Value: string);
begin
FServer := Value;
Client.Host := FServer;
edtServer.Text := Value;
end;
function TfrmIndyTCP.GetClient: TIdTCPClient;
begin
Result := IdTCPClient;
end;
function TfrmIndyTCP.GetConnected: Boolean;
begin
Result := Client.Connected;
end;
procedure TfrmIndyTCP.SetConnected(const Value: Boolean);
begin
if Value then
begin
// Will connect with the default port settings.
Client.Connect;
end
else
begin
Client.Disconnect(False);
end;
Modified;
end;
{$ENDREGION}
{$REGION 'action handlers'}
procedure TfrmIndyTCP.actClearReceivedExecute(Sender: TObject);
begin
FLogIn.Clear;
mmoReceivedText.Lines.Clear;
end;
procedure TfrmIndyTCP.actClearSentExecute(Sender: TObject);
begin
FLogOut.Clear;
cbxSent.Items.Clear;
cbxSent.Text := '';
mmoSentText.Lines.Clear;
end;
procedure TfrmIndyTCP.actConnectExecute(Sender: TObject);
begin
Port := StrToInt(edtPort.Text);
try
Connected := True;
Modified;
except
on E: Exception do
begin
FLogIn.Log(E.Message, llError);
end;
end;
end;
procedure TfrmIndyTCP.actDisconnectExecute(Sender: TObject);
begin
Connected := False;
Modified;
end;
procedure TfrmIndyTCP.actSaveExecute(Sender: TObject);
begin
if dlgSave.Execute then
begin
mmoSentText.Lines.SaveToFile(dlgSave.FileName);
end;
end;
procedure TfrmIndyTCP.actSendExecute(Sender: TObject);
begin
SendString(RawByteString(cbxSent.Text));
end;
{$ENDREGION}
{$REGION 'event handlers'}
procedure TfrmIndyTCP.IdConnectionInterceptReceive(
ASender: TIdConnectionIntercept; var ABuffer: TIdBytes);
begin
//ToHex()
//DoStringReceived(RawByteString(PAnsiChar(ABuffer)));
DoStringReceived(RawByteString(ToHex(ABuffer)));
UpdateControls;
Logger.Send('InterceptReceive', string(PAnsiChar(ABuffer)));
end;
procedure TfrmIndyTCP.IdTCPClientStatus(ASender: TObject;
const AStatus: TIdStatus; const AStatusText: string);
begin
Logger.Track('IdTCPClientStatus');
if Assigned(FLogin) then
FLogIn.Log(AStatusText);
Logger.Send('ClientStatus', AStatusText);
end;
procedure TfrmIndyTCP.InspectorModified(Sender: TObject);
begin
Modified;
end;
procedure TfrmIndyTCP.FCommandExecute(Sender: TObject);
begin
SendString(RawByteString((Sender as TContainedAction).Caption));
end;
function TfrmIndyTCP.FInspectorBeforeAddItem(Sender: TControl;
PItem: PPropItem): Boolean;
begin
Result := not PItem.Name.Contains('ComObject');
Result := Result and (not (PItem.Prop.PropertyType is TRttiMethodType));
end;
procedure TfrmIndyTCP.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
end;
procedure TfrmIndyTCP.edtPortChange(Sender: TObject);
begin
Port := StrToInt(edtPort.Text);
end;
procedure TfrmIndyTCP.edtServerChange(Sender: TObject);
begin
Server := edtServer.Text;
end;
{$ENDREGION}
{$REGION 'private methods'}
procedure TfrmIndyTCP.Modified;
begin
FUpdate := True;
UpdateActions;
end;
procedure TfrmIndyTCP.CreateCommandControls;
var
I : Integer;
CA : TContainedAction;
B : TButton;
begin
for I := 1 to 18 do
begin
CA := TControlAction.Create(aclMain);
CA.Name := Format('actCommand%d', [I]);
CA.OnExecute := FCommandExecute;
FCommands.Add(CA);
B := TButton.Create(Self);
B.Action := CA;
pnlCommands.ControlCollection.AddControl(B);
B.Align := alClient;
B.AlignWithMargins := True;
B.Font.Style := [fsBold];
B.Parent := pnlCommands;
end;
end;
procedure TfrmIndyTCP.DoStringReceived(const AString: RawByteString);
begin
if Assigned(FLogin) then
FLogIn.Log(string(AString));
//MakeLogString(string(AString)));
mmoReceivedText.DisableAlign;
mmoReceivedText.Text :=
mmoReceivedText.Text + AdjustLineBreaks(string(AString), tlbsCRLF);
mmoReceivedText.EnableAlign;
// scroll to last entry
mmoReceivedText.SelStart := Length(mmoReceivedText.Text) - 1;
mmoReceivedText.SelLength := 1;
end;
function TfrmIndyTCP.MakeLogString(const AString: string): string;
const
LOG_FORMAT =
'<font-color=clSilver>' +
'<font-family=Consolas>' +
'[%s]' +
'</font-family>' +
'</font-color>';
var
S : RawByteString;
I : Integer;
N : Integer;
C : AnsiChar;
K : RawByteString;
R : RawByteString;
begin
N := Length(AString);
if N > 0 then
begin
SetLength(S, N);
for I := 1 to N do
begin
C := AnsiChar(Byte(AString[I]));
if Integer(C) <= $7B then // filter non-readable chars (checksum)
S[I] := C
else
S[I] := '#';
end;
end;
for C := Low(CTRL_TO_TEXT) to High(CTRL_TO_TEXT) do
begin
K := C;
R := System.AnsiStrings.Format(LOG_FORMAT, [CTRL_TO_TEXT[C]]);
S := System.AnsiStrings.StringReplace(S, K, R, [rfReplaceAll]);
end;
S := System.AnsiStrings.StringReplace(
S, '#', System.AnsiStrings.Format(LOG_FORMAT, ['{BCC}']), [rfReplaceAll]
);
S := System.AnsiStrings.Format('<font-family=Terminal_Ctrl+Hex><font-size=9>%s</font-size></font-family>', [S]);
Result := string(S);
end;
{$ENDREGION}
{$REGION 'protected methods'}
procedure TfrmIndyTCP.UpdateControls;
var
CA : TContainedAction;
begin
actConnect.Enabled := not Connected;
actDisconnect.Enabled := Connected;
actSend.Enabled := Connected;
for CA in FCommands do
CA.Enabled := Connected;
if Assigned(FInspector) then
FInspector.UpdateProperties;
end;
procedure TfrmIndyTCP.UpdateActions;
begin
inherited UpdateActions;
if FUpdate then
begin
UpdateControls;
FUpdate := False;
end;
end;
procedure TfrmIndyTCP.LoadSettings;
var
I : Integer;
begin
Server := Settings.ReadString(UnitName, 'Server', '');
Port := Settings.ReadInteger(UnitName, 'Port', 0);
for I := 0 to FCommands.Count - 1 do
begin
FCommands[I].Caption := Settings.ReadString(
UnitName,
Format('Command%d', [I + 1]),
''
);
end;
end;
procedure TfrmIndyTCP.SaveSettings;
var
I : Integer;
begin
Settings.WriteString(UnitName, 'Server', Server);
Settings.WriteInteger(UnitName, 'Port', Port);
for I := 0 to FCommands.Count - 1 do
begin
Settings.WriteString(
UnitName,
Format('Command%d', [I + 1]),
FCommands[I].Caption
);
end;
end;
procedure TfrmIndyTCP.SendString(const AString: RawByteString);
var
S : string;
begin
Client.IOHandler.Write(string(AString));
//DoStringReceived(Client.IOHandler.AllData);
FLogOut.Log(string(AString));
S := string(Trim(AString));
if cbxSent.Items.IndexOf(S) = -1 then
cbxSent.Items.Add(S);
mmoSentText.Lines.Add(string(AString));
if Client.IOHandler.CheckForDataOnSource then
begin
Client.IOHandler.WaitFor(#0, True, False, IndyTextEncoding_ASCII, 200);
end;
//DoStringReceived();
end;
{$ENDREGION}
end.
| 24.783784 | 114 | 0.680207 |
fc49bf8a0ed252674abc390962a4112671207dfa | 31,790 | pas | Pascal | iss_gus2.pas | chainq/iss | 4838053f01d78a8736a057b6085d2dbeaa7f9229 | [
"0BSD"
]
| 1 | 2018-11-03T17:12:21.000Z | 2018-11-03T17:12:21.000Z | iss_gus2.pas | chainq/iss | 4838053f01d78a8736a057b6085d2dbeaa7f9229 | [
"0BSD"
]
| null | null | null | iss_gus2.pas | chainq/iss | 4838053f01d78a8736a057b6085d2dbeaa7f9229 | [
"0BSD"
]
| null | null | null | {
Copyright (c) 1998-2001,2014 Karoly Balogh <charlie@amigaspirit.hu>
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
}
{ * ISS_GUS2.PAS - Device Driver for GF1/Interwave based cards under OS/2 }
{ via the Manley Drivers native API. }
{ OS - OS/2 only. }
{ * This unit is heavily based on the work of Sander van Leeuwen author of }
{ the latest OS/2 GUS2 drivers and Timo Maier, who ported the native API }
{ C include file to Virtual Pascal/2. Thank you. }
{$INCLUDE ISS_SET.INC}
{$ASMMODE INTEL}
{$MODE FPC}
{$HINTS OFF} { * Enable this if you modify the source! * }
{$NOTES OFF} { * Enable this if you modify the source! * }
{$IFDEF _ISS_GUSNATIVE_OLDVOLUMETABLE_}
{$INFO GUS2 driver will use the old volume table!}
{$ENDIF}
Unit ISS_GUS2;
Interface
Uses ISS_Var, { * Uses the system variables and types * }
OS2Def, { * Uses OS/2 system interface * }
DOSCalls;{ * Uses OS/2 DOSCALLS.DLL * }
Const ISS_GUS2VersionStr = '0.1.0';
ISS_GUS2Name = 'OS/2 GF1/Interwave Driver';
ISS_GUS2LongDesc = 'OS/2 GF1/Interwave Based Device Driver';
Var ISS_GUS2Device : ISS_TSoundDevice; { * GUS2 Device Structure * }
ISS_GUS2Driver : ISS_TSoundDriver; { * GUS2 Device Driver * }
Procedure ISS_GUS2DevInit; { * Inits the GUS2 driver structures * }
Implementation
Type UltraAllocStruct = Packed Record
SmpSize : LongInt; { * Memory size to allocate * }
SmpLocation : LongInt; { * Location (return value) * }
SmpType : Byte; { * 0 = 8bit sample, 4 = 16bit sample * }
End;
UltraFreeStruct = Packed Record
SmpSize : LongInt; { * Memory size to free * }
SmpLocation : LongInt; { * Location to free * }
End;
UltraXferStruct = Packed Record
XferControl : Byte;
XferDRAMLoc : LongInt;
End;
UltraTimerStruct = Packed Record
Timer : Integer; { * GUS timer interrupt number * }
Time : Byte; { * Time between interrupts * }
End;
UltraVolumeStruct = Packed Record
Voice : Integer;
End_idx : word;
Rate : byte;
Mode : byte;
End;
UltraBalanceStruct = Packed Record
Voice : Integer;
Data : Byte;
End;
UltraFreqStruct = Packed Record
Voice : Integer;
Speed_Khz : LongInt;
End;
UltraVoiceStruct = Packed Record
VoiceNum : Integer; { voice to start }
VoiceStart : LongInt;
VoiceLoopStart : LongInt; { start loop location in ultra DRAM }
VoiceLoopEnd : LongInt; { end location in ultra DRAM }
VoiceMode : Byte; { mode to run the voice (loop etc) }
End;
Const GUS2_Commands = $0F;
UltraDevStartEffectVoice = $4B;
UltraDevAddEffectToVoice = $4C;
UltraDevRemoveEffectFromVoice = $4D;
UltraDevGetUltraType = $4E;
UltraDevSetNVoices = $50;
UltraDevEnableOutput = $51;
UltraDevDisableOutput = $52;
UltraDevPokeData = $53;
UltraDevPeekData = $54;
UltraDevMemAlloc = $55;
UltraDevMemFree = $56;
UltraDevMemInit = $57;
UltraDevStartTimer = $58;
UltraDevStopTimer = $59;
UltraDevBlockTimerHandler1 = $5A;
UltraDevBlockTimerHandler2 = $5B;
UltraDevStartVoice = $5C;
UltraDevStopVoice = $5D;
UltraDevSetBalance = $5E;
UltraDevSetFrequency = $5F;
UltraDevVectorLinearVolume = $60;
UltraDevPrepare4DMAXfer = $61;
UltraDevUnblockAll = $62;
UltraDevSetAll = $63;
UltraDevGetAccess = $6A;
UltraDevReleaseAccess = $6B;
UltraDevSizeDRAM = $6D;
UltraDevGetRegStatus = $6C;
UltraDevGetDriverVersion = $6E;
UltraDevStopAll = $6F;
UltraDevSetLoopMode = $73;
UltraDevVoiceStopped = $74;
UltraDevSetLoopStart = $78;
{ * Here are the dma to/from DRAM control bit definitions: * }
UltraDramRead = $02;
UltraDram16Bit = $40;
UltraDram8Bit = $80;
Var ISS_GUS2DRAMOffset : DWord;
ISS_GUS2ActiveChannels : Word; { * Number of active hardware channels * }
ISS_GUS2Handle : DWord;
ISS_GUS2UpdThreadID : LongInt;
ISS_GUS2Thread_Exit : Boolean;
ISS_GUS2PeriodicCall : Procedure;
{ * >>> O S / 2 S Y S T E M C O N S T A N T S <<< * }
{ * The constants here should be added later to the FPC OS/2 RTL (?) * }
Const { * DosOpen/DosQFHandState/DosQueryFileInfo et al file attributes; also * }
{ * known as Dos File Mode bits... * }
FILE_NORMAL = $0000;
FILE_READONLY = $0001;
FILE_HIDDEN = $0002;
FILE_SYSTEM = $0004;
FILE_DIRECTORY = $0010;
FILE_ARCHIVED = $0020;
{ * DosOpen() actions * }
FILE_EXISTED = $0001;
FILE_CREATED = $0002;
FILE_TRUNCATED = $0003;
{ * DosOpen() open flags * }
FILE_OPEN = $0001;
FILE_TRUNCATE = $0002;
FILE_CREATE = $0010;
{ * DosOpen/DosSetFHandState flags * }
OPEN_ACCESS_READONLY = $0000; { * ---- ---- ---- -000 * }
OPEN_ACCESS_WRITEONLY = $0001; { * ---- ---- ---- -001 * }
OPEN_ACCESS_READWRITE = $0002; { * ---- ---- ---- -010 * }
OPEN_SHARE_DENYREADWRITE = $0010; { * ---- ---- -001 ---- * }
OPEN_SHARE_DENYWRITE = $0020; { * ---- ---- -010 ---- * }
OPEN_SHARE_DENYREAD = $0030; { * ---- ---- -011 ---- * }
OPEN_SHARE_DENYNONE = $0040; { * ---- ---- -100 ---- * }
OPEN_FLAGS_NOINHERIT = $0080; { * ---- ---- 1--- ---- * }
OPEN_FLAGS_NO_LOCALITY = $0000; { * ---- -000 ---- ---- * }
OPEN_FLAGS_SEQUENTIAL = $0100; { * ---- -001 ---- ---- * }
OPEN_FLAGS_RANDOM = $0200; { * ---- -010 ---- ---- * }
OPEN_FLAGS_RANDOMSEQUENTIAL = $0300; { * ---- -011 ---- ---- * }
OPEN_FLAGS_NO_CACHE = $1000; { * ---1 ---- ---- ---- * }
OPEN_FLAGS_FAIL_ON_ERROR = $2000; { * --1- ---- ---- ---- * }
OPEN_FLAGS_WRITE_THROUGH = $4000; { * -1-- ---- ---- ---- * }
OPEN_FLAGS_DASD = $8000; { * 1--- ---- ---- ---- * }
OPEN_FLAGS_NONSPOOLED = $00040000;
OPEN_FLAGS_PROTECTED_HANDLE = $40000000;
{ * definitions for DosError - combine with Or * }
FERR_DISABLEHARDERR = $00000000; { * disable hard error popups * }
FERR_ENABLEHARDERR = $00000001; { * enable hard error popups * }
FERR_ENABLEEXCEPTION = $00000000; { * enable exception popups * }
FERR_DISABLEEXCEPTION = $00000002; { * disable exception popups * }
{ * Workaround for DosDevIOCtl definition in DOSCALLS.DLL using pointers. * }
Function DosDevIOCtl(Handle, Category, Func : LongInt;
Params: Pointer; ParamLen: LongInt; Var ParamSize: LongInt;
Data: Pointer; DataLen: LongInt; Var DataSize: LongInt): LongInt; CDecl;
External 'DOSCALLS' Index 284;
{ * >>> D E B U G F U N C T I O N S <<< * }
{$IFDEF _ISS_GUSNATIVE_DEBUGMODE_}
Function WriteHex(Num : Word) : String[4];
Const DigitTab : String[16]='0123456789ABCDEF';
Var HexStr : String[4];
Counter : Integer;
Begin
HexStr:='';
For Counter:=3 DownTo 0 Do Begin
HexStr:=HexStr+DigitTab[(Num And ($F Shl (Counter*4))) Shr
(Counter*4)+1];
End;
WriteHex:=HexStr;
End;
{$ENDIF}
{ * >>> I N T E R N A L F U N C T I O N S <<< * }
{ * HW initializating and basic settings * }
Function UltraGetAccess : LongInt;
var ParmLength,DataLength : LongInt;
Begin
DataLength := 0; ParmLength := 0;
UltraGetAccess:=DosDevIOCtl(ISS_GUS2Handle,GUS2_Commands,
UltraDevGetAccess,
NIL,0,ParmLength,NIL,0,DataLength);
End;
Function UltraReleaseAccess : LongInt;
Var ParmLength,DataLength : LongInt;
Begin
DataLength := 0; ParmLength := 0;
UltraReleaseAccess:=DosDevIOCtl(ISS_GUS2Handle,GUS2_Commands,
UltraDevReleaseAccess,
NIL,0,ParmLength,NIL,0,DataLength);
End;
Function UltraEnableOutput : LongInt;
Var ParmLength,DataLength : LongInt;
Begin
DataLength := 0; ParmLength := 0;
UltraEnableOutput:=DosDevIOCtl(ISS_GUS2Handle,GUS2_Commands,
UltraDevEnableOutput,
NIL,0,ParmLength,NIL,0,DataLength);
End;
Function UltraDisableOutput : LongInt;
var ParmLength,DataLength : LongInt;
Begin
DataLength := 0; ParmLength := 0;
UltraDisableOutput:=DosDevIOCtl(ISS_GUS2Handle,GUS2_Commands,
UltraDevDisableOutput,
NIL,0,ParmLength,NIL,0,DataLength);
End;
Function UltraSetNumVoices(NumVoices : DWord) : LongInt;
Var ParmLength,DataLength : LongInt;
Begin
ParmLength := 0;
DataLength := SizeOf(NumVoices);
{ * Make sure, voices is in the 14-32 range. * }
If NumVoices < 14 Then NumVoices := 14 Else
If NumVoices > 32 Then NumVoices := 32;
UltraSetNumVoices:=DosDevIOCtl(ISS_GUS2Handle,GUS2_Commands,
UltraDevSetNVoices,
NIL,0,ParmLength,
@NumVoices,DataLength,DataLength);
End;
Function UltraSizeDram : LongInt;
Var ParmLength,DataLength : LongInt;
DRAMSize : LongInt;
Begin
ParmLength := 0;
DataLength := SizeOf(DRAMSize);
DosDevIOCtl(ISS_GUS2Handle,GUS2_Commands,UltraDevSizeDRAM,NIL,0,
ParmLength,@DRAMSize,DataLength,DataLength);
UltraSizeDram:=DRAMSize;
End;
Function UltraGetDriverVersion : Word;
var ParmLength,DataLength : LongInt;
DrvVersion : Word;
Begin
ParmLength := 0;
DataLength := SizeOf(DrvVersion);
{ High byte Contains major version,low byte minor version }
DosDevIOCtl(ISS_GUS2Handle,GUS2_Commands,UltraDevGetDriverVersion,NIL,0,
ParmLength,@DrvVersion,DataLength,DataLength);
UltraGetDriverVersion:=DrvVersion;
End;
Function UltraGetDriverVersionStr : String;
{ * This procedure was GetManleyVersion in the original VP/2 version * }
Var DrvVersion : Word;
DrvVersionStr : String[5];
Begin
DrvVersion:=UltraGetDriverVersion;
Str(DrvVersion,DrvVersionStr);
While Length(DrvVersionStr) < 4 Do
DrvVersionStr:=' '+DrvVersionStr;
UltraGetDriverVersionStr:=
Copy(DrvVersionStr,1,2)+'.'+Copy(DrvVersionStr,3,2);
End;
Function UltraGetUltraType : LongInt;
Var ParmLength,DataLength : LongInt;
GUSType : LongInt;
Begin
ParmLength := 0;
DataLength := SizeOf(GUSType);
DosDevIOCtl(ISS_GUS2Handle,GUS2_Commands,UltraDevGetUltraType,NIL,0,
ParmLength,@GUSType,DataLength,DataLength);
UltraGetUltraType:=GUSType;
End;
Function UltraGetUltraTypeStr : String;
Const TypeStr : Array[1..11] Of String[10] = (
('PLAIN'),('ICS2101FLR'),('ICS2101'),('CS4231'),('ACE'),('CD3'),
('ICS2102'),('MAX23'),('CS4231_DB'),('?'),('PNP'));
Var GUSType : LongInt;
Begin
GUSType:=UltraGetUltraType;
If (GUSType >=1) And (GUSType <= 11) Then Begin
UltraGetUltraTypeStr := TypeStr[GUSType]
End Else Begin
UltraGetUltraTypeStr := 'UNKNOWN';
End;
End;
{ * Memory handling * }
Function UltraMemAlloc(Size : LongInt; Var Location : LongInt; Smp16Bit : Boolean) : LongInt;
Var ParmLength,DataLength : LongInt;
AllocBuffer : UltraAllocStruct;
Begin
ParmLength := 0;
DataLength := SizeOf(UltraAllocStruct);
If (Size MOD 32) <> 0 Then
Inc(Size,32 - (Size MOD 32)); { * Bring Size up to a 32 byte boundary * }
With AllocBuffer Do Begin
SmpSize := Size;
SmpLocation := Location;
If Smp16Bit Then SmpType:=$04 Else SmpType:=$00;
End;
UltraMemAlloc:=DosDevIOCtl(ISS_GUS2Handle,GUS2_Commands,
UltraDevMemAlloc,
NIL,0,ParmLength,
@AllocBuffer,DataLength,DataLength);
Location := AllocBuffer.SmpLocation; { * location in GUS DRAM * }
End;
Function UltraMemFree(Size,Location : LongInt) : LongInt;
Var ParmLength,DataLength : LongInt;
FreeBuffer : UltraFreeStruct;
Begin
ParmLength := 0;
DataLength := SizeOf(UltraFreeStruct);
With FreeBuffer Do Begin
SmpSize := Size;
SmpLocation := Location;
End;
DosDevIOCtl(ISS_GUS2Handle,GUS2_Commands,
UltraDevMemFree,
NIL,0,ParmLength,
@FreeBuffer,DataLength,DataLength);
UltraMemFree := FreeBuffer.SmpSize;
End;
Function UltraDownload(DataPtr : Pointer; Control : Byte; DRAMLoc, Size : LongInt) : LongInt;
{ * Requires Driver Version >= 1.10 * }
Const Max = 64*1000;
Var ParmLength,DataLength : LongInt;
RC : LongInt;
Written : LongInt;
XferBuffer : UltraXferStruct;
Buffer64k : Pointer;
Begin
ParmLength := 0;
DataLength := SizeOf(UltraXferStruct);
With XferBuffer Do Begin
XferControl := Control;
XferDRAMLoc := DRAMLoc;
End;
RC := 0;
{ * NEED to allocate a buffer to transfer samples > 64 kb !!! * }
RC := DosAllocMem(Buffer64k,64*1024,PAG_COMMIT or PAG_WRITE);
If RC = 0 Then Begin
{ * 16 bit segments in a 32 bit world :( * }
{ * Another good example for the weakness of x86 architecture... * }
While (Size > Max) And (RC = 0) Do Begin
Move(DataPtr^,Buffer64k^,Max);
RC := DosDevIOCtl(ISS_GUS2Handle,GUS2_COMMANDS,
UltraDevPrepare4DMAXfer,
NIL,0,ParmLength,
@XferBuffer,DataLength,DataLength);
If RC = 0 Then Begin
RC := DosWrite(ISS_GUS2Handle,Buffer64k^,Max,Written);
If RC = 0 Then Begin
Inc(DRAMLoc,Max);
With XferBuffer Do Begin
XferDRAMLoc := DRAMLoc;
XferControl := Control;
End;
Dec(Size,Max);
Inc(DWord(DataPtr),Max);
End;
End;
End;
If (Size > 0) And (RC = 0) Then Begin
Move(DataPtr^,Buffer64k^,Size);
RC := DosDevIOCtl(ISS_GUS2Handle,GUS2_COMMANDS,
UltraDevPrepare4DMAXfer,
NIL,0,ParmLength,
@XferBuffer,DataLength,DataLength);
If RC = 0 Then Begin { * Last transfer * }
RC := DosWrite(ISS_GUS2Handle,Buffer64k^,Size,Written);
End;
End;
DosFreeMem(Buffer64k);
End;
UltraDownLoad := RC;
End;
{ * Timer handling * }
Function UltraBlockTimerHandler1 : LongInt;
Var ParmLength,DataLength : LongInt;
Begin
DataLength := 0; ParmLength := 0;
{ * block until GUS timer1 interrupt * }
UltraBlockTimerHandler1:=DosDevIOCtl(ISS_GUS2Handle,GUS2_Commands,
UltraDevBlockTimerHandler1,
NIL,0,ParmLength,
NIL,DataLength,DataLength);
End;
Function UltraBlockTimerHandler2 : LongInt;
Var ParmLength,DataLength : LongInt;
Begin
DataLength := 0; ParmLength := 0;
{ * block until GUS timer2 interrupt * }
UltraBlockTimerHandler2:=DosDevIOCtl(ISS_GUS2Handle,GUS2_Commands,
UltraDevBlockTimerHandler2,
NIL,0,ParmLength,
NIL,DataLength,DataLength);
End;
Function UltraStartTimer(Timer,Time : LongInt) : LongInt;
Var ParmLength,DataLength : LongInt;
TimerBuffer : UltraTimerStruct;
Begin
ParmLength := 0;
DataLength := SizeOf(UltraTimerStruct);
TimerBuffer.Timer:=Timer;
TimerBuffer.Time :=Time;
UltraStartTimer:=DosDevIOCtl(ISS_GUS2Handle,GUS2_Commands,
UltraDevStartTimer,
NIL,0,ParmLength,
@TimerBuffer,DataLength,DataLength);
End;
Function UltraStopTimer(Timer : LongInt) : LongInt;
Var ParmLength,DataLength : LongInt;
Begin
ParmLength := 0;
DataLength := SizeOf(Timer);
UltraStopTimer:=DosDevIOCtl(ISS_GUS2Handle,GUS2_Commands,
UltraDevStopTimer,
NIL,0,ParmLength,
@Timer,DataLength,DataLength);
End;
{ * Voice management * }
Function UltraStopVoice(Voice : Integer) : LongInt;
Var ParmLength,DataLength : LongInt;
Begin
ParmLength := 0;
DataLength := SizeOf(Voice);
UltraStopVoice:=DosDevIOCtl(ISS_GUS2Handle,GUS2_Commands,
UltraDevStopVoice,
NIL,0,ParmLength,
@Voice,DataLength,DataLength);
End;
Function UltraVoiceStopped(Voice : Integer) : Boolean;
{ * Returns false while playing Voice * }
Var ParmLength,DataLength : LongInt;
Begin
ParmLength := 0;
DataLength := SizeOf(Voice);
DosDevIOCtl(ISS_GUS2Handle,GUS2_Commands,
UltraDevVoiceStopped,
NIL,0,ParmLength,
@Voice,DataLength,DataLength);
UltraVoiceStopped := (Voice > 0);
End;
Function UltraVectorLinearVolume(Voice,End_Idx : Word; Rate,
Mode : Byte): LongInt;
{ * End_Idx; Voice end level * }
{ * Rate; 0 to 63 * }
{ * Mode; mode to run the volume ramp in ... * }
Var ParmLength,DataLength : LongInt;
VolBuffer : UltraVolumeStruct;
Begin
VolBuffer.Voice := Voice;
VolBuffer.End_Idx := End_Idx;
VolBuffer.Rate := Rate;
VolBuffer.Mode := Mode;
ParmLength := 0;
DataLength := SizeOf(UltraVolumeStruct);
UltraVectorLinearVolume := DosDevIOCtl(ISS_GUS2Handle,GUS2_Commands,
UltraDevVectorLinearVolume,
NIL,0,ParmLength,
@VolBuffer,DataLength,DataLength);
End;
Function UltraSetBalance(Voice : Integer; Data : Byte) : LongInt;
Var ParmLength,DataLength : LongInt;
BalanceBuffer : UltraBalanceStruct;
Begin
ParmLength := 0;
DataLength := SizeOf(UltraBalanceStruct);
BalanceBuffer.Voice := Voice;
BalanceBuffer.Data := Data;
UltraSetBalance:=DosDevIOCtl(ISS_GUS2Handle,GUS2_Commands,
UltraDevSetBalance,
NIL,0,ParmLength,
@BalanceBuffer,DataLength,DataLength);
End;
Function UltraSetFrequency(Voice : Integer; Freq : LongInt) : LongInt;
Var ParmLength,DataLength : LongInt;
FreqBuffer : UltraFreqStruct;
Begin
ParmLength := 0;
DataLength := SizeOf(UltraFreqStruct);
FreqBuffer.Voice := Voice;
FreqBuffer.Speed_Khz := Freq;
UltraSetFrequency:=DosDevIOCtl(ISS_GUS2Handle,GUS2_Commands,
UltraDevSetFrequency,
NIL,0,ParmLength,
@FreqBuffer,DataLength,DataLength);
End;
Function UltraStartVoice(GusVoice : Integer; begin_,start,end_ : LongInt;
Mode : Byte) : LongInt;
{ * gusvoice voice to start * }
{ * begin_ start location in ultra DRAM * }
{ * start start loop location in ultra DRAM * }
{ * end_ end location in ultra DRAM * }
{ * mode mode to run the voice (loop etc) * }
Var ParmLength,DataLength : LongInt;
Voice : UltraVoiceStruct;
Begin
ParmLength := 0;
With Voice Do Begin
VoiceNUm := GusVoice;
VoiceStart := Begin_; { start in DRAM }
VoiceLoopStart := Start; { start loop }
VoiceLoopEnd := End_;
VoiceMode := Mode;
End;
DataLength := SizeOf(UltraVoiceStruct);
UltraStartVoice:=DosDevIOCtl(ISS_GUS2Handle,GUS2_Commands,
UltraDevStartVoice,
NIL,0,ParmLength,
@Voice,DataLength,DataLength);
End;
{ * HW open/close * }
Function OpenUltraSound : Boolean; { * True if successful * }
Var Status : LongInt;
Action : LongInt;
Begin
DOSCalls.DosError(fErr_DisableHardErr);
Status := DosOpen('ULTRA1$',ISS_GUS2Handle,Action,0,FILE_NORMAL,
FILE_OPEN,OPEN_ACCESS_READWRITE or
OPEN_SHARE_DENYNONE or OPEN_FLAGS_WRITE_THROUGH,
NIL );
If Status <> 0 Then Begin
OpenUltraSound := FALSE
End Else Begin
If UltraGetAccess > 0 Then Begin
DosClose(ISS_GUS2Handle);
OpenUltraSound:=False; { * Not only owner * }
End Else Begin
OpenUltraSound:=True; { * Ultrasound access ok * }
End;
End;
DOSCalls.DosError(fErr_EnableHardErr);
End;
Procedure CloseUltraSound;
Begin
UltraDisableOutPut;
UltraReleaseAccess;
DosClose(ISS_GUS2Handle);
End;
{ * >>> U L T R A S O U N D U P D A T E T H R E A D <<< * }
Function ISS_GUS2HandlerThread(Param : Pointer) : LongInt; CDecl;
Var DGUSTimer : DWord;
Begin
DGUSTimer:=12800000 Div (140*128*32);
ISS_TimerDiff:=1193180 Div 140;
UltraStartTimer(2,DGUSTimer);
Repeat
ISS_GUS2PeriodicCall;
UltraBlockTimerHandler2;
Until ISS_GUS2Thread_Exit;
UltraStopTimer(2);
ISS_GUS2HandlerThread:=0;
End;
{ * >>> E X T E R N A L D E V I C E - D R I V E R F U N C T I O N S <<< * }
Function ISS_GUS2Detect : Boolean;
Begin
ISS_GUS2Detect:=ISS_GUS2Device.DevAvail;
End;
Function ISS_GUS2Init : Boolean;
Begin
ISS_GUS2Init:=False;
If Not ISS_GUS2Device.DevAvail Then Begin
{ * ERROR CODE! * }
Exit;
End;
If Not OpenUltraSound Then Exit;
ISS_GUS2DRAMOffset:=0;
ISS_GUS2Init:=True;
End;
Function ISS_GUS2Done : Boolean;
Begin
ISS_GUS2DRAMOffset:=0;
CloseUltraSound;
ISS_GUS2Done:=True;
End;
Function ISS_GUS2LoadSample(SStruc : ISS_PSample) : Boolean;
Type PInteger = ^Integer;
PShortInt = ^ShortInt;
Var SmpConvBuf : Pointer;
Counter : DWord;
RealSLength : DWord;
SmpDRAMPos : DWord;
Status : Boolean;
Begin
ISS_GUS2LoadSample:=False;
Status:=False;
{ * Uploading sample * }
With SStruc^ Do Begin
{ * If sample is 16bit, divide size with 2 * }
If (SType And ISS_Smp16BitData)>0 Then Begin
RealSLength:=SLength Div 2;
End Else Begin
RealSLength:=SLength;
End;
{ * Is the sample fits into GUSRAM? * }
If RealSLength+ISS_GUS2DRAMOffset+1>ISS_GUS2Device.DevDRAMSize Then Begin
{ * ERROR CODE! * }
Exit;
End;
GetMem(SmpConvBuf,RealSLength);
{ * GUS has some limitations when using 16bit samples, noteably a 16bit * }
{ * sample can't cross a 256k boundary. To simplify the driver, and * }
{ * because the lack of time, i decided to convert the samples to 8bit * }
{ * before loading into the GUS RAM. Later, a GUS heap manager should * }
{ * be implemented to handle 16bit samples correctly, but the mixer * }
{ * and other tasks has higher priority now. * }
{ * UPDATE: instead of a heap handler, an intelligent sample manager * }
{ * should be implemented, to allow playing XM's bigger than * }
{ * the available wavetable memory on wavetable soundcards. * }
If (SType And ISS_Smp16BitData)>0 Then Begin
For Counter:=0 To RealSLength-1 Do Begin
PShortInt(SmpConvBuf)[Counter]:=PInteger(SData)[Counter] Shr 8;
End;
End Else Begin
Move(SData^,SmpConvBuf^,RealSLength);
End;
{ * Modifying sample beginning to avoid some clickings * }
PShortInt(SmpConvBuf)[0]:=0;
If UltraMemAlloc(RealSLength,SmpDRAMPos,FALSE)=0 Then Begin
Status:=(UltraDownLoad(SmpConvBuf,UltraDram16bit,SmpDRAMPos,RealSLength)=0);
End;
FreeMem(SmpConvBuf,RealSLength);
SStruc^.SDRAMOffs:=SmpDRAMPos;
If Status Then Inc(ISS_GUS2DRAMOffset,RealSLength);
End;
ISS_GUS2LoadSample:=Status;
End;
Function ISS_GUS2FreeSample(SStruc : ISS_PSample) : Boolean;
Begin
ISS_GUS2FreeSample:=True;
End;
Function ISS_GUS2SetVolume(Volume : DWord) : Boolean;
Begin
{ * Dummy. Old GUSes have no mixer. :( Later, the support for the * }
{ * newer-series GF1's ICS mixer should be added. I'm looking for * }
{ * some programing docs about the ICS mixer! If you have the docs, * }
{ * please contact me, so i can add support for it. * }
ISS_GUS2SetVolume:=True;
End;
Function ISS_GUS2StartOutput(PeriodicCall : Pointer) : Boolean;
Var GUS2HandlerThread : TThreadEntry;
Begin
ISS_GUS2StartOutput:=False;
If ISS_ActiveSSChannels>32 Then ISS_GUS2ActiveChannels:=32
Else ISS_GUS2ActiveChannels:=ISS_ActiveSSChannels;
If ISS_GUS2ActiveChannels<14 Then ISS_GUS2ActiveChannels:=14;
{ * Boostin' up "The Queen Of The SoundCards" :) * }
UltraSetNumVoices(ISS_GUS2ActiveChannels);
UltraEnableOutput;
{ * Phew, this was easy, wasn't it? Compare this with a Sound Blaster * }
{ * initialization code... :) * }
{ * Now initializing the handler thread * }
ISS_GUS2Thread_Exit:=False;
GUS2HandlerThread:=@ISS_GUS2HandlerThread;
Pointer(ISS_GUS2PeriodicCall):=PeriodicCall;
If DosCreateThread(ISS_GUS2UpdThreadID,GUS2HandlerThread,NIL,0,8192)=0 Then Begin
DosSetPriority(dpThread,dpTimeCritical,31,ISS_GUS2UpdThreadID);
ISS_GUS2StartOutput:=True;
{$IFDEF _ISS_GUSNATIVE_DEBUGMODE_}
WriteLn('DEV_INIT: Starting ',ISS_GUS2Name,' output...');
{$ENDIF}
End Else Begin
{$IFDEF _ISS_GUSNATIVE_DEBUGMODE_}
WriteLn('DEV_FAIL: ERROR! Failed to start ',ISS_GUS2Name,' output!');
{$ENDIF}
End;
End;
Function ISS_GUS2StopOutput(PeriodicCall : Pointer) : Boolean;
Begin
UltraDisableOutput;
{ * Terminating GUS update thread * }
ISS_GUS2Thread_Exit:=True;
DosWaitThread(ISS_GUS2UpdThreadID,dtWait);
ISS_GUS2StopOutput:=True{ISS_StopTimer(PeriodicCall)}; { * Stops timer call * }
{$IFDEF _ISS_GUSNATIVE_DEBUGMODE_}
WriteLn('DEV_INIT: ',ISS_GUS2Name,' output stopped.');
{$ENDIF}
End;
Procedure ISS_GUS2UpdateOutput; { * Updates the sound output * }
{ * This is the main driver, which runs on the timer at 140hz frequency * }
{ * so it should be as fast as possible. Because it's a low-level driver, * }
{ * hardware and platform dependent, it's a good idea to implement this * }
{ * later again - in full-assembly. * }
Var ChannelCounter : Word;
SampleBegin : DWord;
SampleEnd : DWord;
SampleFreq : DWord;
LoopBegin : DWord;
LoopEnd : DWord;
RealLength : DWord;
RealLoopStart : DWord;
RealLoopEnd : DWord;
Begin
{ * Stop Voices If Needed * }
For ChannelCounter:=0 To ISS_GUS2ActiveChannels-1 Do Begin
With ISS_VirtualChannels^[ChannelCounter] Do Begin
If ((VChControl And ISS_CCActive)>0) And
((VChControl And ISS_CCStop)>0) Then Begin
Dec(VChControl,ISS_CCStop);
UltraStopVoice(ChannelCounter);
End;
End;
End;
{ * Start Voices Update * }
For ChannelCounter:=0 To ISS_GUS2ActiveChannels-1 Do Begin
With ISS_VirtualChannels^[ChannelCounter] Do Begin
{ * Anything to do on this channel? * }
If (VChControl>1) And ((VChControl And ISS_CCActive)>0) Then Begin
{ * Start a Sample ? * }
If (VChControl And ISS_CCSample)>0 Then Begin
Dec(VChControl,ISS_CCSample);
With VChSmpAddr^ Do Begin
{ * 16bit sample values conversion * }
If (SType And ISS_Smp16BitData)>0 Then Begin
RealLength :=SLength Div 2;
RealLoopStart:=SLoopStart Div 2;
RealLoopEnd :=SLoopEnd Div 2;
End Else Begin
RealLength :=SLength;
RealLoopStart:=SLoopStart;
RealLoopEnd :=SLoopEnd;
End;
{ * Sample & Loop End Address Calc. * }
{ * -1 is needed, because SampleEnd value _must_ contain the * }
{ * _last_ sample position and not the last+1!!! * }
SampleEnd:=SDRAMOffs+RealLength-1;
If (SType And ISS_SmpPingPongLoop)>0 Then Begin
{ * Offset limit checking * }
If (VChSmpOffs>RealLength-1) Then VChSmpOffs:=RealLoopStart;
{ * Sample end value checking * }
LoopEnd:=SDRAMOffs+RealLoopEnd-1; { * Same here as above... * }
If LoopEnd>SampleEnd Then LoopEnd:=SampleEnd;
End Else Begin
LoopEnd:=SampleEnd;
End;
{ * Sample & Loop Start Address Calc. * }
SampleBegin:=SDRAMOffs+VChSmpOffs;
LoopBegin :=SDRAMOffs+RealLoopStart;
{ * Now we're going to tell to the GUS these values * }
UltraStartVoice(ChannelCounter,SampleBegin,
LoopBegin,LoopEnd,SType And %00011000);
End;
End;
{ * Change Channel Panning ? * }
If (VChControl And ISS_CCPanning)>0 Then Begin
Dec(VChControl,ISS_CCPanning);
UltraSetBalance(ChannelCounter,VChFinalPanning Shr 4);
End;
{ * Change Channel Volume ? * }
If (VChControl And ISS_CCVolume)>0 Then Begin
Dec(VChControl,ISS_CCVolume);
UltraVectorLinearVolume(ChannelCounter,VChFinalVolume Shl 2,$2F,0);
End;
{ * Change Channel Frequency ? * }
If (VChControl And ISS_CCPeriod)>0 Then Begin
Dec(VChControl,ISS_CCPeriod);
UltraSetFrequency(ChannelCounter,VChFreq);
End;
{ * Is Channel Still Active ? * }
If UltraVoiceStopped(ChannelCounter) Then Begin
VChControl:=VChControl And Not ISS_CCActive;
End;
End;
End;
End;
End;
{ * >>> P U B L I C F U N C T I O N S <<< * }
{ * Inits the GUS2 driver structures * }
Procedure ISS_GUS2DevInit;
Begin
With ISS_GUS2Driver Do Begin
Detect :=@ISS_GUS2Detect;
Init :=@ISS_GUS2Init;
Done :=@ISS_GUS2Done;
LoadSample:=@ISS_GUS2LoadSample;
FreeSample:=@ISS_GUS2FreeSample;
SetVolume :=@ISS_GUS2SetVolume;
StartOut :=@ISS_GUS2StartOutput;
StopOut :=@ISS_GUS2StopOutput;
UpdateOut :=@ISS_GUS2UpdateOutput;
End;
ISS_GUS2Device.DevDriver:=@ISS_GUS2Driver;
{$IFDEF _ISS_GUSNATIVE_DEBUGMODE_}
WriteLn('DEV_INIT: Device - ',ISS_GUS2LongDesc,' ',ISS_GUS2VersionStr);
{$ENDIF}
{ * Reading ULTRASND Environment Settings * }
If OpenUltraSound Then Begin
{ * If ULTRASND found, assigning hardware parameters * }
With ISS_GUS2Device Do Begin
DevName :=ISS_GUS2Name; { * Name of the device * }
DevType :=ISS_Dev16Bit+ISS_DevStereo+ISS_DevWaveTable;{ * Device Type * }
DevBaseport:=0;
DevIRQ :=0;
DevDMA1 :=0;
DevDMA2 :=0;
DevFreq :=44100;
DevMaxChan :=32;
DevDRAMSize:=UltraSizeDRAM*1024;
If DevDRAMSize>0 Then DevAvail:=True;
DevHWVer :=UltraGetUltraTypeStr;
DevSWVer :=UltraGetDriverVersionStr;
End;
CloseUltraSound;
End;
If ISS_GUS2Device.DevAvail Then Begin
With ISS_GUS2Device Do Begin
{$IFDEF _ISS_GUSNATIVE_DEBUGMODE_}
WriteLn('DEV_INIT: - Hardware Revision: ',DevHWVer,' - DRAM Size: ',DevDRAMSize Div 1024,'KB');
WriteLn('DEV_INIT: - Using Manley Driver Version: ',DevSWVer);
{$ENDIF}
End;
End Else Begin
{$IFDEF _ISS_GUSNATIVE_DEBUGMODE_}
WriteLn('DEV_INIT: - GF1/INTERWAVE DETECTION FAILED!');
{$ENDIF}
End;
End;
Begin
End.
| 33.463158 | 108 | 0.627933 |
f1c7d52d5f5b9e14fc6b7ff486656a7bbf9b1c46 | 4,319 | pas | Pascal | Rootkits/vault/admin/ce54releasesvn/frmGDTunit.pas | dendisuhubdy/grokmachine | 120a21a25c2730ed356739231ec8b99fc0575c8b | [
"BSD-3-Clause"
]
| 46 | 2017-05-15T11:15:08.000Z | 2018-07-02T03:32:52.000Z | Rootkits/vault/admin/ce54releasesvn/frmGDTunit.pas | dendisuhubdy/grokmachine | 120a21a25c2730ed356739231ec8b99fc0575c8b | [
"BSD-3-Clause"
]
| null | null | null | Rootkits/vault/admin/ce54releasesvn/frmGDTunit.pas | dendisuhubdy/grokmachine | 120a21a25c2730ed356739231ec8b99fc0575c8b | [
"BSD-3-Clause"
]
| 24 | 2017-05-17T03:26:17.000Z | 2018-07-09T07:00:50.000Z | unit frmGDTunit;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls,cefuncproc,newkernelhandler;
type
TfrmGDTinfo = class(TForm)
TreeView1: TTreeView;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
procedure dissectGDTentry(entry: uint64; var segmentlimit_0_15: word; var baseaddress_0_23: dword; var segmenttype: byte; var dpl: byte; var p: byte; var segmentlimit_16_19: byte; var AVL: byte; var bigordefault: byte; var gran: byte; var baseaddress_24_31: byte );
public
{ Public declarations }
end;
implementation
{$R *.dfm}
procedure TfrmGDTinfo.dissectGDTentry(entry: uint64; var segmentlimit_0_15: word; var baseaddress_0_23: dword; var segmenttype: byte; var dpl: byte; var p: byte; var segmentlimit_16_19: byte; var AVL: byte; var bigordefault: byte; var gran: byte; var baseaddress_24_31: byte );
begin
segmentlimit_0_15:=entry and $ffff;
baseaddress_0_23:=(entry shr 16) and $ffffff;
segmenttype:=(entry shr (32+8)) and $1f;
dpl:=(entry shr (32+13)) and 3;
p:=(entry shr (32+15)) and 1;
segmentlimit_16_19:=(entry shr (32+16)) and $f;
avl:=(entry shr (32+20)) and 1;
bigordefault:=(entry shr (32+22)) and 1;
gran:=(entry shr (32+23)) and 1;
baseaddress_24_31:=(entry shr (32+24)) and $ff;
end;
procedure TfrmGDTinfo.FormClose(Sender: TObject; var Action: TCloseAction);
begin
action:=cafree;
end;
procedure TfrmGDTinfo.FormCreate(Sender: TObject);
var limit: word;
address: dword;
x: puint64array;
i: integer;
br:dword;
t: ttreenode;
segmentlimit_0_15: word;
baseaddress_0_23: dword;
segmenttype: byte;
dpl: byte;
p: byte;
segmentlimit_16_19: byte;
AVL: byte;
bigordefault: byte;
gran: byte;
baseaddress_24_31: byte;
seglimit: dword;
baseaddress: dword;
segtype: integer;
title: string;
begin
address:=getgdt(limit);
getmem(x,limit*8);
try
newkernelhandler.kernelreadprocessmemory(processhandle,pointer(address),x,limit,br);
if br>0 then
begin
for i:=0 to (br div 8)-1 do
begin
dissectGDTentry(x[i],segmentlimit_0_15,baseaddress_0_23, segmenttype, dpl,p, segmentlimit_16_19,avl,bigordefault,gran, baseaddress_24_31);
title:=inttohex(8*i,4)+': ';
if p=1 then
begin
if (segmenttype shr 4)=1 then
begin
if ((segmenttype shr 3) and 1)=1 then
begin
title:=title+'Code Segment';
segtype:=1;
end
else
begin
segtype:=0;
title:=title+'Data Segment';
end;
end else
begin
segtype:=2;
title:=title+'System Segment';
end;
baseaddress:=baseaddress_0_23+(baseaddress_24_31 shl 24);
seglimit:=segmentlimit_0_15+(segmentlimit_16_19 shl 16);
if gran=1 then
seglimit:=seglimit*4096+$FFF;
title:=title+' ('+inttohex(baseaddress,8)+' - '+inttohex(baseaddress+seglimit,8)+')';
end
else title:='Not present';
t:=treeview1.Items.Add(nil,title);
if p=1 then
begin
if segtype in [0,1] then
treeview1.items.addchild(t,'Accessed='+inttostr(segmenttype and 1));
if segtype = 0 then //data
begin
treeview1.items.addchild(t,'Writable='+inttostr((segmenttype shr 1) and 1));
treeview1.items.addchild(t,'Expansion direction='+inttostr((segmenttype shr 2) and 1));
end;
if segtype = 1 then //code
begin
treeview1.items.addchild(t,'Readable='+inttostr((segmenttype shr 1) and 1));
treeview1.items.addchild(t,'Conforming='+inttostr((segmenttype shr 2) and 1));
end;
treeview1.items.addchild(t,'DPL='+inttostr(dpl));
treeview1.items.addchild(t,'AVL='+inttostr(AVL));
end;
end;
end else showmessage('Read error');
finally
freemem(x);
end;
end;
end.
| 28.045455 | 278 | 0.608474 |
fcfd03bc9e461b74e96390033c782ca7f762e270 | 469 | pas | Pascal | boring/pascal/src/examples/array_test.pas | tekhnus/misc | cf4c6e29434c546e3c29f24f7bb16a0ac65005f5 | [
"Unlicense"
]
| null | null | null | boring/pascal/src/examples/array_test.pas | tekhnus/misc | cf4c6e29434c546e3c29f24f7bb16a0ac65005f5 | [
"Unlicense"
]
| null | null | null | boring/pascal/src/examples/array_test.pas | tekhnus/misc | cf4c6e29434c546e3c29f24f7bb16a0ac65005f5 | [
"Unlicense"
]
| null | null | null | program array_test;
var arr : array 10 of integer;
var i : integer;
begin
i := 1;
while i < 11 do
begin
arr[i - 1] := i * i;
i := i + 1
end;
i := 1;
while i < 11 do
begin
write(arr[i - 1]);
i := i + 1
end;
i := 1;
while i < 11 do
begin
dec(arr[i - 1]);
i := i + 1
end;
i := 1;
while i < 11 do
begin
write(arr[i - 1]);
i := i + 1
end
end. | 14.212121 | 30 | 0.394456 |
fcef8c4a204b5545bee2752c1b272989baa2ec5c | 5,743 | pas | Pascal | Source/uPreviewContainer.pas | atkins126/SVGShellExtensions | 96526b79d2053a4b969a845a640501b613ff4b1f | [
"Apache-2.0"
]
| 63 | 2021-02-05T15:47:56.000Z | 2022-03-09T11:36:39.000Z | Source/uPreviewContainer.pas | atkins126/SVGShellExtensions | 96526b79d2053a4b969a845a640501b613ff4b1f | [
"Apache-2.0"
]
| 13 | 2021-02-11T08:39:38.000Z | 2022-03-28T22:48:09.000Z | Source/uPreviewContainer.pas | atkins126/SVGShellExtensions | 96526b79d2053a4b969a845a640501b613ff4b1f | [
"Apache-2.0"
]
| 5 | 2021-02-12T15:35:55.000Z | 2021-07-11T02:34:40.000Z | {******************************************************************************}
{ }
{ SVG Shell Extensions: Shell extensions for SVG files }
{ (Preview Panel, Thumbnail Icon, SVG Editor) }
{ }
{ Copyright (c) 2021 (Ethea S.r.l.) }
{ Author: Carlo Barazzetta }
{ }
{ https://github.com/EtheaDev/SVGShellExtensions }
{ }
{******************************************************************************}
{ }
{ Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 }
{ }
{ Unless required by applicable law or agreed to in writing, software }
{ distributed under the License is distributed on an "AS IS" BASIS, }
{ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. }
{ See the License for the specific language governing permissions and }
{ limitations under the License. }
{ }
{ The Original Code is: }
{ Delphi Preview Handler https://github.com/RRUZ/delphi-preview-handler }
{ }
{ The Initial Developer of the Original Code is Rodrigo Ruz V. }
{ Portions created by Rodrigo Ruz V. are Copyright 2011-2021 Rodrigo Ruz V. }
{ All Rights Reserved. }
{******************************************************************************}
unit uPreviewContainer;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TPreviewContainer = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
FPreviewHandler: TObject;
public
procedure SetFocusTabFirst;
procedure SetFocusTabLast;
procedure SetBackgroundColor(color: TColorRef);
procedure SetBoundsRectAndPPI(const ARect: TRect;
const AOldPPI, ANewPPI: Integer); virtual;
procedure SetTextColor(color: TColorRef);
procedure SetTextFont(const plf: TLogFont);
property PreviewHandler: TObject read FPreviewHandler write FPreviewHandler;
end;
implementation
uses
SynEdit,
System.Math,
{$IFNDEF DISABLE_STYLES}
Vcl.Styles.Ext,
Vcl.Styles,
Vcl.Themes,
{$ENDIF}
uLogExcept,
uSVGSettings;
{$R *.dfm}
procedure TPreviewContainer.SetFocusTabFirst;
begin
SelectNext(nil, True, True);
end;
procedure TPreviewContainer.SetFocusTabLast;
begin
SelectNext(nil, False, True);
end;
procedure TPreviewContainer.FormCreate(Sender: TObject);
var
LSettings: TPreviewSettings;
begin
TLogPreview.Add('TPreviewContainer.FormCreate'+
'ScaleFactor: '+Self.ScaleFactor.ToString+
'CurrentPPI '+Self.CurrentPPI.ToString);
LSettings := TPreviewSettings.CreateSettings(nil);
try
{$IFNDEF DISABLE_STYLES}
if not IsStyleHookRegistered(TCustomSynEdit, TScrollingStyleHook) then
TStyleManager.Engine.RegisterStyleHook(TCustomSynEdit, TScrollingStyleHook);
if (Trim(LSettings.StyleName) <> '') and not SameText('Windows', LSettings.StyleName) then
TStyleManager.TrySetStyle(LSettings.StyleName, False);
{$ENDIF}
finally
LSettings.Free;
end;
TLogPreview.Add('TPreviewContainer.FormCreate Done');
end;
procedure TPreviewContainer.FormDestroy(Sender: TObject);
begin
TLogPreview.Add('TPreviewContainer.FormDestroy');
end;
procedure TPreviewContainer.SetBackgroundColor(color: TColorRef);
begin
end;
procedure TPreviewContainer.SetBoundsRectAndPPI(const ARect: TRect;
const AOldPPI, ANewPPI: Integer);
begin
if (ARect.Width <> 0) and (ARect.Height <> 0) then
begin
TLogPreview.Add('TPreviewContainer.SetBoundsRect:'+
' Visible: '+Self.Visible.Tostring+
' CurrentPPI:'+Self.CurrentPPI.ToString+
' AOldPPI:'+AOldPPI.ToString+
' ANewPPI:'+ANewPPI.ToString+
' Scaled:'+Self.Scaled.ToString+
' ARect.Width: '+ARect.Width.ToString+
' ARect.Height: '+ARect.Height.ToString);
if ANewPPI <> AOldPPI then
begin
SetBounds(
ARect.Left,
ARect.Top,
MulDiv(ARect.Width, ANewPPI, AOldPPI),
MulDiv(ARect.Height, ANewPPI, AOldPPI));
end
else
begin
SetBounds(
ARect.Left,
ARect.Top,
ARect.Width,
ARect.Height);
end;
FCurrentPPI := ANewPPI;
end;
end;
procedure TPreviewContainer.SetTextColor(color: TColorRef);
begin
end;
procedure TPreviewContainer.SetTextFont(const plf: TLogFont);
begin
end;
end.
| 36.579618 | 95 | 0.52133 |
fc4137f6f98dcf93fab3200884f73a9b001fa4a4 | 23,967 | dfm | Pascal | examples/CBuilder/Simple/ObjectSpace/AssociationClass/MainForm.dfm | LenakeTech/BoldForDelphi | 3ef25517d5c92ebccc097c6bc2f2af62fc506c71 | [
"MIT"
]
| 121 | 2020-09-22T10:46:20.000Z | 2021-11-17T12:33:35.000Z | examples/CBuilder/Simple/ObjectSpace/AssociationClass/MainForm.dfm | LenakeTech/BoldForDelphi | 3ef25517d5c92ebccc097c6bc2f2af62fc506c71 | [
"MIT"
]
| 8 | 2020-09-23T12:32:23.000Z | 2021-07-28T07:01:26.000Z | examples/CBuilder/Simple/ObjectSpace/AssociationClass/MainForm.dfm | LenakeTech/BoldForDelphi | 3ef25517d5c92ebccc097c6bc2f2af62fc506c71 | [
"MIT"
]
| 42 | 2020-09-22T14:37:20.000Z | 2021-10-04T10:24:12.000Z | object frmMain: TfrmMain
Left = -4
Top = -3
Width = 872
Height = 449
Caption = 'Association Class Example'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
OnCloseQuery = FormCloseQuery
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object Label3: TLabel
Left = 8
Top = 4
Width = 52
Height = 13
Caption = 'All Persons'
end
object Label1: TLabel
Left = 293
Top = 4
Width = 48
Height = 13
Caption = 'Employers'
end
object Label4: TLabel
Left = 397
Top = 4
Width = 142
Height = 13
Caption = 'The jobs of the current person'
end
object Label5: TLabel
Left = 8
Top = 140
Width = 116
Height = 13
Caption = 'All Jobs (the link objects)'
end
object Label6: TLabel
Left = 8
Top = 244
Width = 66
Height = 13
Caption = 'All Companies'
end
object Label2: TLabel
Left = 296
Top = 244
Width = 51
Height = 13
Caption = 'Employees'
end
object Label7: TLabel
Left = 400
Top = 244
Width = 153
Height = 13
Caption = 'The jobs of the current company'
end
object AllPersonsGrid: TBoldGrid
Left = 8
Top = 20
Width = 276
Height = 113
AddNewAtEnd = False
BoldAutoColumns = False
BoldShowConstraints = False
BoldHandle = AllPersons
BoldProperties.InternalDrag = False
BoldProperties.NilElementMode = neNone
Columns = <
item
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
end
item
BoldProperties.Expression = 'name'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
Title.Caption = 'Name'
end
item
BoldProperties.Expression = 'job.salary->Sum'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
Title.Caption = 'TotalSalary'
end
item
BoldProperties.Expression = 'employer->Size'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
Title.Caption = '# Jobs'
end
item
BoldProperties.Expression = 'job.Salary->Average->Round'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
Title.Caption = 'Average Pay'
end>
DefaultRowHeight = 17
EnableColAdjust = False
TabOrder = 0
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -11
TitleFont.Name = 'MS Sans Serif'
TitleFont.Style = []
ColWidths = (
17
73
64
42
72)
end
object PersonEmployersListBox: TBoldListBox
Left = 293
Top = 20
Width = 97
Height = 81
Hint = 'Drop a company here to create a job'
Alignment = taLeftJustify
BoldHandle = PersonEmployers
BoldProperties.InternalDrag = False
BoldProperties.NilElementMode = neNone
BoldRowProperties.Expression = 'name'
DragMode = dmAutomatic
ItemHeight = 16
ParentShowHint = False
ShowHint = True
TabOrder = 1
end
object PersonNavigator: TBoldNavigator
Left = 293
Top = 108
Width = 96
Height = 25
Hint = 'Create / remove Persons'
BoldHandle = AllPersons
ParentShowHint = False
ShowHint = True
TabOrder = 2
VisibleButtons = [nbInsert, nbDelete]
ImageIndices.nbFirst = -1
ImageIndices.nbPrior = -1
ImageIndices.nbNext = -1
ImageIndices.nbLast = -1
ImageIndices.nbInsert = -1
ImageIndices.nbDelete = -1
ImageIndices.nbMoveUp = -1
ImageIndices.nbMoveDown = -1
DeleteQuestion = 'Delete object?'
UnlinkQuestion = 'Unlink "%1:s" from "%2:s"?'
RemoveQuestion = 'Remove "%1:s" from the list?'
end
object PersonJobGrid: TBoldGrid
Left = 397
Top = 20
Width = 275
Height = 113
AddNewAtEnd = False
BoldAutoColumns = False
BoldShowConstraints = False
BoldHandle = PersonJobs
BoldProperties.InternalDrag = False
BoldProperties.NilElementMode = neNone
Columns = <
item
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
end
item
BoldProperties.Expression = 'employer.name'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
Title.Caption = 'Name of Employer'
end
item
BoldProperties.Expression = 'salary'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
Title.Caption = 'Salary'
end
item
BoldProperties.Expression = 'title'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
Title.Caption = 'Title'
end>
DefaultRowHeight = 17
EnableColAdjust = False
TabOrder = 3
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -11
TitleFont.Name = 'MS Sans Serif'
TitleFont.Style = []
ColWidths = (
17
93
58
100)
end
object JobGrid: TBoldGrid
Left = 8
Top = 156
Width = 665
Height = 81
AddNewAtEnd = False
BoldAutoColumns = False
BoldShowConstraints = False
BoldHandle = AllJobs
BoldProperties.InternalDrag = False
BoldProperties.NilElementMode = neNone
Columns = <
item
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
end
item
BoldProperties.Expression = 'title'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
Title.Caption = 'Title'
end
item
BoldProperties.Expression = 'salary'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
Title.Caption = 'Salary'
end
item
BoldProperties.Expression = 'employer.name'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
Title.Caption = 'Name of Employer'
end
item
BoldProperties.Expression = 'employee.name'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
Title.Caption = 'Name of Employee'
end>
DefaultRowHeight = 17
EnableColAdjust = False
TabOrder = 4
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -11
TitleFont.Name = 'MS Sans Serif'
TitleFont.Style = []
ColWidths = (
17
264
59
153
164)
end
object CompanyGrid: TBoldGrid
Left = 8
Top = 260
Width = 279
Height = 121
AddNewAtEnd = False
BoldAutoColumns = False
BoldShowConstraints = False
BoldHandle = AllCompanies
BoldProperties.InternalDrag = False
BoldProperties.NilElementMode = neNone
Columns = <
item
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
end
item
BoldProperties.Expression = 'name'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
Title.Caption = 'Name'
end
item
BoldProperties.Expression = 'job.salary->Sum'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
Title.Caption = 'TotalSalary'
end
item
BoldProperties.Expression = 'employee->Size'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
Title.Caption = '# Employees'
end
item
BoldProperties.Expression = 'job.salary->Average->Round'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
Title.Caption = 'Avg Salary'
end>
DefaultRowHeight = 17
EnableColAdjust = False
TabOrder = 5
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -11
TitleFont.Name = 'MS Sans Serif'
TitleFont.Style = []
ColWidths = (
17
64
58
68
64)
end
object CompanyEmployeesListBox: TBoldListBox
Left = 296
Top = 260
Width = 97
Height = 89
Hint = 'Drop a person here to create a job'
Alignment = taLeftJustify
BoldHandle = CompanyEmployees
BoldProperties.InternalDrag = False
BoldProperties.NilElementMode = neNone
BoldRowProperties.Expression = 'name'
DragMode = dmAutomatic
ItemHeight = 16
ParentShowHint = False
ShowHint = True
TabOrder = 6
end
object CompanyNavigator: TBoldNavigator
Left = 296
Top = 356
Width = 96
Height = 25
Hint = 'Create / remove Companies'
BoldHandle = AllCompanies
ParentShowHint = False
ShowHint = True
TabOrder = 7
VisibleButtons = [nbInsert, nbDelete]
ImageIndices.nbFirst = -1
ImageIndices.nbPrior = -1
ImageIndices.nbNext = -1
ImageIndices.nbLast = -1
ImageIndices.nbInsert = -1
ImageIndices.nbDelete = -1
ImageIndices.nbMoveUp = -1
ImageIndices.nbMoveDown = -1
DeleteQuestion = 'Delete object?'
UnlinkQuestion = 'Unlink "%1:s" from "%2:s"?'
RemoveQuestion = 'Remove "%1:s" from the list?'
end
object CompanyJobGrid: TBoldGrid
Left = 400
Top = 260
Width = 271
Height = 121
AddNewAtEnd = False
BoldAutoColumns = False
BoldShowConstraints = False
BoldHandle = CompanyJobs
BoldProperties.InternalDrag = False
BoldProperties.NilElementMode = neNone
Columns = <
item
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
end
item
BoldProperties.Expression = 'employee.name'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
Title.Caption = 'Name of Employee'
end
item
BoldProperties.Expression = 'salary'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
Title.Caption = 'Salary'
end
item
BoldProperties.Expression = 'title'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
Title.Caption = 'Title'
end>
DefaultRowHeight = 17
EnableColAdjust = False
TabOrder = 8
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -11
TitleFont.Name = 'MS Sans Serif'
TitleFont.Style = []
ColWidths = (
17
95
54
98)
end
object Button1: TButton
Left = 8
Top = 388
Width = 109
Height = 25
Action = BoldActivateSystemAction1
TabOrder = 9
end
object Button2: TButton
Left = 124
Top = 388
Width = 109
Height = 25
Action = BoldIBDatabaseAction1
TabOrder = 10
end
object AllPersons: TBoldListHandle
RootHandle = BoldSystemHandle1
Expression = 'Employee.allInstances'
Left = 144
Top = 64
end
object PersonEmployers: TBoldListHandle
RootHandle = AllPersons
Expression = 'employer'
Left = 328
Top = 56
end
object PersonJobs: TBoldListHandle
RootHandle = AllPersons
Expression = 'job'
Left = 512
Top = 56
end
object AllJobs: TBoldListHandle
RootHandle = BoldSystemHandle1
Expression = 'Job.allInstances'
Left = 128
Top = 192
end
object AllCompanies: TBoldListHandle
RootHandle = BoldSystemHandle1
Expression = 'Company.allInstances'
Left = 112
Top = 296
end
object CompanyEmployees: TBoldListHandle
RootHandle = AllCompanies
Expression = 'employee'
Left = 336
Top = 280
end
object CompanyJobs: TBoldListHandle
RootHandle = AllCompanies
Expression = 'job'
Left = 520
Top = 288
end
object BoldModel1: TBoldModel
UMLModelMode = ummNone
Boldify.EnforceDefaultUMLCase = False
Boldify.DefaultNavigableMultiplicity = '0..1'
Boldify.DefaultNonNavigableMultiplicity = '0..*'
Left = 776
Top = 36
Model = (
'VERSION 19'
'(Model'
#9'"AssociationClassExampleClasses"'
#9'"BusinessClassesRoot"'
#9'""'
#9'""'
#9'"_Boldify.boldified=True,_BoldInternal.flattened=True,_BoldInte' +
'rnal.toolId=35331A920220,Bold.DelphiName=<Name>,Bold.RootClass=B' +
'usinessClassesRoot,Bold.UnitName=AssociationClassExampleClasses"'
#9'(Classes'
#9#9'(Class'
#9#9#9'"BusinessClassesRoot"'
#9#9#9'"<NONE>"'
#9#9#9'TRUE'
#9#9#9'FALSE'
#9#9#9'""'
#9#9#9'""'
#9#9#9'"_Boldify.autoCreated=True,persistence=Persistent,Bold.TableN' +
'ame=<Prefix>_OBJECT"'
#9#9#9'(Attributes'
#9#9#9')'
#9#9#9'(Methods'
#9#9#9')'
#9#9')'
#9#9'(Class'
#9#9#9'"Employee"'
#9#9#9'"BusinessClassesRoot"'
#9#9#9'TRUE'
#9#9#9'FALSE'
#9#9#9'""'
#9#9#9'""'
#9#9#9'"_BoldInternal.toolId=35331A9A025C,persistence=Persistent"'
#9#9#9'(Attributes'
#9#9#9#9'(Attribute'
#9#9#9#9#9'"name"'
#9#9#9#9#9'"String"'
#9#9#9#9#9'FALSE'
#9#9#9#9#9'""'
#9#9#9#9#9'""'
#9#9#9#9#9'2'
#9#9#9#9#9'""'
#9#9#9#9#9'"_BoldInternal.toolId=35331AC20015,persistence=Persistent"'
#9#9#9#9')'
#9#9#9')'
#9#9#9'(Methods'
#9#9#9#9'(Method'
#9#9#9#9#9'"CompleteCreate"'
#9#9#9#9#9'""'
#9#9#9#9#9'FALSE'
#9#9#9#9#9'""'
#9#9#9#9#9'""'
#9#9#9#9#9'2'
#9#9#9#9#9'"=False"'
#9#9#9#9#9'"_BoldInternal.toolId=35BB4CD2030F,Bold.OperationKind=Overr' +
'ide"'
#9#9#9#9')'
#9#9#9')'
#9#9')'
#9#9'(Class'
#9#9#9'"Company"'
#9#9#9'"BusinessClassesRoot"'
#9#9#9'TRUE'
#9#9#9'FALSE'
#9#9#9'""'
#9#9#9'""'
#9#9#9'"_BoldInternal.toolId=35331AA0019D,persistence=Persistent"'
#9#9#9'(Attributes'
#9#9#9#9'(Attribute'
#9#9#9#9#9'"name"'
#9#9#9#9#9'"String"'
#9#9#9#9#9'FALSE'
#9#9#9#9#9'""'
#9#9#9#9#9'""'
#9#9#9#9#9'2'
#9#9#9#9#9'""'
#9#9#9#9#9'"_BoldInternal.toolId=35331B550084,persistence=Persistent"'
#9#9#9#9')'
#9#9#9')'
#9#9#9'(Methods'
#9#9#9#9'(Method'
#9#9#9#9#9'"CompleteCreate"'
#9#9#9#9#9'""'
#9#9#9#9#9'FALSE'
#9#9#9#9#9'""'
#9#9#9#9#9'""'
#9#9#9#9#9'2'
#9#9#9#9#9'"=False"'
#9#9#9#9#9'"_BoldInternal.toolId=35BB4CEB0383,Bold.OperationKind=Overr' +
'ide"'
#9#9#9#9')'
#9#9#9')'
#9#9')'
#9#9'(Class'
#9#9#9'"Job"'
#9#9#9'"BusinessClassesRoot"'
#9#9#9'TRUE'
#9#9#9'FALSE'
#9#9#9'""'
#9#9#9'""'
#9#9#9'"_BoldInternal.toolId=35331AAE01B1,persistence=Persistent"'
#9#9#9'(Attributes'
#9#9#9#9'(Attribute'
#9#9#9#9#9'"title"'
#9#9#9#9#9'"String"'
#9#9#9#9#9'FALSE'
#9#9#9#9#9'""'
#9#9#9#9#9'""'
#9#9#9#9#9'2'
#9#9#9#9#9'""'
#9#9#9#9#9'"_BoldInternal.toolId=35331B1D0387,persistence=Persistent"'
#9#9#9#9')'
#9#9#9#9'(Attribute'
#9#9#9#9#9'"salary"'
#9#9#9#9#9'"Currency"'
#9#9#9#9#9'FALSE'
#9#9#9#9#9'""'
#9#9#9#9#9'""'
#9#9#9#9#9'2'
#9#9#9#9#9'""'
#9#9#9#9#9'"_BoldInternal.toolId=35331B3A018A,persistence=Persistent"'
#9#9#9#9')'
#9#9#9')'
#9#9#9'(Methods'
#9#9#9#9'(Method'
#9#9#9#9#9'"CompleteCreate"'
#9#9#9#9#9'""'
#9#9#9#9#9'FALSE'
#9#9#9#9#9'""'
#9#9#9#9#9'""'
#9#9#9#9#9'2'
#9#9#9#9#9'"=False"'
#9#9#9#9#9'"_BoldInternal.toolId=35BB4D0603B4,Bold.OperationKind=Overr' +
'ide"'
#9#9#9#9')'
#9#9#9')'
#9#9')'
#9')'
#9'(Associations'
#9#9'(Association'
#9#9#9'"Job"'
#9#9#9'"Job"'
#9#9#9'""'
#9#9#9'""'
#9#9#9'"persistence=Persistent,_BoldInternal.toolId=35331AA601CD,Bol' +
'd.DelphiName=<Name>"'
#9#9#9'FALSE'
#9#9#9'(Roles'
#9#9#9#9'(Role'
#9#9#9#9#9'"Employer"'
#9#9#9#9#9'TRUE'
#9#9#9#9#9'FALSE'
#9#9#9#9#9'"Employee"'
#9#9#9#9#9'""'
#9#9#9#9#9'"0..n"'
#9#9#9#9#9'""'
#9#9#9#9#9'0'
#9#9#9#9#9'2'
#9#9#9#9#9'0'
#9#9#9#9#9'"_BoldInternal.toolId=35331AA701BB,Bold.Embed=False"'
#9#9#9#9#9'(Qualifiers'
#9#9#9#9#9')'
#9#9#9#9')'
#9#9#9#9'(Role'
#9#9#9#9#9'"Employee"'
#9#9#9#9#9'TRUE'
#9#9#9#9#9'FALSE'
#9#9#9#9#9'"Company"'
#9#9#9#9#9'""'
#9#9#9#9#9'"0..n"'
#9#9#9#9#9'""'
#9#9#9#9#9'0'
#9#9#9#9#9'2'
#9#9#9#9#9'0'
#9#9#9#9#9'"_BoldInternal.toolId=35331AA701CF,Bold.Embed=False"'
#9#9#9#9#9'(Qualifiers'
#9#9#9#9#9')'
#9#9#9#9')'
#9#9#9')'
#9#9')'
#9')'
')')
end
object BoldSystemHandle1: TBoldSystemHandle
IsDefault = True
SystemTypeInfoHandle = BoldSystemTypeInfoHandle1
Active = False
PersistenceHandle = BoldPersistenceHandleDB1
Left = 776
Top = 84
end
object BoldSystemTypeInfoHandle1: TBoldSystemTypeInfoHandle
BoldModel = BoldModel1
Left = 776
Top = 128
end
object ActionList1: TActionList
Left = 776
Top = 224
object BoldActivateSystemAction1: TBoldActivateSystemAction
Category = 'Bold Actions'
Caption = 'Open system'
BoldSystemHandle = BoldSystemHandle1
OpenCaption = 'Open system'
CloseCaption = 'Close system'
SaveQuestion = 'There are dirty objects. Save them before exit?'
SaveOnClose = saAsk
end
object BoldIBDatabaseAction1: TBoldIBDatabaseAction
Category = 'Bold Actions'
Caption = 'Create DB'
BoldSystemHandle = BoldSystemHandle1
Username = 'SYSDBA'
Password = 'masterkey'
end
end
object BoldPersistenceHandleDB1: TBoldPersistenceHandleDB
BoldModel = BoldModel1
ClockLogGranularity = '0:0:0.0'
DatabaseAdapter = BoldDatabaseAdapterIB1
Left = 488
Top = 384
end
object BoldDatabaseAdapterIB1: TBoldDatabaseAdapterIB
SQLDatabaseConfig.ColumnTypeForDate = 'TIMESTAMP'
SQLDatabaseConfig.ColumnTypeForTime = 'TIMESTAMP'
SQLDatabaseConfig.ColumnTypeForDateTime = 'TIMESTAMP'
SQLDatabaseConfig.ColumnTypeForBlob = 'BLOB'
SQLDatabaseConfig.ColumnTypeForFloat = 'DOUBLE PRECISION'
SQLDatabaseConfig.ColumnTypeForCurrency = 'DOUBLE PRECISION'
SQLDatabaseConfig.ColumnTypeForString = 'VARCHAR(%d)'
SQLDatabaseConfig.ColumnTypeForInteger = 'INTEGER'
SQLDatabaseConfig.ColumnTypeForSmallInt = 'SMALLINT'
SQLDatabaseConfig.DropColumnTemplate = 'ALTER TABLE <TableName> DROP <ColumnName>'
SQLDatabaseConfig.DropTableTemplate = 'DROP TABLE <TableName>'
SQLDatabaseConfig.DropIndexTemplate = 'DROP INDEX <IndexName>'
SQLDatabaseConfig.MaxDbIdentifierLength = 31
SQLDatabaseConfig.MaxIndexNameLength = 31
SQLDatabaseConfig.SQLforNotNull = 'NOT NULL'
SQLDatabaseConfig.QuoteNonStringDefaultValues = False
SQLDatabaseConfig.SupportsConstraintsInCreateTable = True
SQLDatabaseConfig.SupportsStringDefaultValues = True
SQLDatabaseConfig.DBGenerationMode = dbgQuery
SQLDatabaseConfig.ReservedWords.Strings = (
'ACTIVE, ADD, ALL, AFTER, ALTER'
'AND, ANY, AS, ASC, ASCENDING,'
'AT, AUTO, AUTOINC, AVG, BASE_NAME'
'BEFORE, BEGIN, BETWEEN, BLOB, BOOLEAN,'
'BOTH, BY, BYTES, CACHE, CAST, CHAR'
'CHARACTER, CHECK, CHECK_POINT_LENGTH, COLLATE,'
'COLUMN, COMMIT, COMMITTED, COMPUTED'
'CONDITIONAL, CONSTRAINT, CONTAINING, COUNT, CREATE, CSTRING,'
'CURRENT, CURSOR, DATABASE, DATE, DAY'
'DEBUG, DEC, DECIMAL, DECLARE, DEFAULT,'
'DELETE, DESC, DESCENDING, DISTINCT, DO'
'DOMAIN, DOUBLE, DROP, ELSE, END,'
'ENTRY_POINT, ESCAPE, EXCEPTION, EXECUTE'
'EXISTS, EXIT, EXTERNAL, EXTRACT, FILE, FILTER,'
'FLOAT, FOR, FOREIGN, FROM, FULL, FUNCTION'
'GDSCODE, GENERATOR, GEN_ID, GRANT,'
'GROUP, GROUP_COMMIT_WAIT_TIME, HAVING'
'HOUR, IF, IN, INT, INACTIVE, INDEX, INNER,'
'INPUT_TYPE, INSERT, INTEGER, INTO'
'IS, ISOLATION, JOIN, KEY, LONG, LENGTH,'
'LOGFILE, LOWER, LEADING, LEFT, LEVEL'
'LIKE, LOG_BUFFER_SIZE, MANUAL, MAX, MAXIMUM_SEGMENT,'
'MERGE, MESSAGE, MIN, MINUTE, MODULE_NAME'
'MONEY, MONTH, NAMES, NATIONAL, NATURAL,'
'NCHAR, NO, NOT, NULL, NUM_LOG_BUFFERS'
'NUMERIC, OF, ON, ONLY, OPTION,'
'OR, ORDER, OUTER, OUTPUT_TYPE, OVERFLOW'
'PAGE_SIZE, PAGE, PAGES, PARAMETER, PASSWORD,'
'PLAN, POSITION, POST_EVENT, PRECISION'
'PROCEDURE, PROTECTED, PRIMARY, PRIVILEGES, RAW_PARTITIONS, RDB$D' +
'B_KEY,'
'READ, REAL, RECORD_VERSION, REFERENCES'
'RESERV, RESERVING, RETAIN, RETURNING_VALUES, RETURNS, REVOKE,'
'RIGHT, ROLE, ROLLBACK, SECOND, SEGMENT'
'SELECT, SET, SHARED, SHADOW, SCHEMA, SINGULAR,'
'SIZE, SMALLINT, SNAPSHOT, SOME, SORT'
'SQLCODE, STABILITY, STARTING, STARTS, STATISTICS,'
'SUB_TYPE, SUBSTRING, SUM, SUSPEND, TABLE'
'THEN, TIME, TIMESTAMP, TIMEZONE_HOUR, TIMEZONE_MINUTE,'
'TO, TRAILING, TRANSACTION, TRIGGER, TRIM'
'UNCOMMITTED, UNION, UNIQUE, UPDATE, UPPER,'
'USER, VALUE, VALUES, VARCHAR, VARIABLE'
'VARYING, VIEW, WAIT, WHEN, WHERE,'
'WHILE, WITH, WORK, WRITE, YEAR')
SQLDatabaseConfig.StoreEmptyStringsAsNULL = False
SQLDatabaseConfig.SystemTablePrefix = 'BOLD'
DataBase = IBDatabase1
DatabaseEngine = dbeInterbaseSQLDialect3
Left = 528
Top = 384
end
object IBDatabase1: TIBDatabase
Params.Strings = (
'user_name=sysdba'
'password=masterkey')
LoginPrompt = False
IdleTimer = 0
SQLDialect = 3
TraceFlags = []
Left = 568
Top = 384
end
object BoldUMLRoseLink1: TBoldUMLRoseLink
FileName =
'C:\vss\dev\BfD\examples\Simple\ObjectSpace\AssociationClass\Empl' +
'oyer.mdl'
BoldModel = BoldModel1
Left = 624
Top = 380
end
end
| 27.579977 | 86 | 0.5939 |
47031c319ed5b8681abb68c633b7ba3c4ba5e701 | 6,427 | pas | Pascal | uDBHamsterNews.pas | HeikoStudt/GoldFind3 | f82b1e5c6fbc4d1389fa238db6ec2e1a2f38f628 | [
"MIT"
]
| null | null | null | uDBHamsterNews.pas | HeikoStudt/GoldFind3 | f82b1e5c6fbc4d1389fa238db6ec2e1a2f38f628 | [
"MIT"
]
| null | null | null | uDBHamsterNews.pas | HeikoStudt/GoldFind3 | f82b1e5c6fbc4d1389fa238db6ec2e1a2f38f628 | [
"MIT"
]
| null | null | null | unit uDBHamsterNews;
interface
uses VirtualTrees, cIndexRC, uTools, cArticle, uDBBase, Classes;
type
tDBGroup = class(tDBBase) //Group I/O
private
IndexFile: TIndexedRecords;
FSdat: TFileStreamEx;
fPos: Integer;
function ReadArticle(ArtNo: Integer; var MaxSize: Integer): String;
function ReadHeader(ArtNum: integer; var ArtSize: Integer): String;
public
procedure ReadFolderList(res : tVirtualStringTree;
RootNode : PVirtualNode; BasePath : String;
PathStrings : tList); override;
procedure GetArticle (ArtNum : integer; var ResArt : String; var ResSize : Integer); override;
procedure GetHeader (ArtNum : integer; var ResHdr : String; var ArtSize : Integer); override;
function Count : longint; override;
function Max : longint; override;
function Min : longint; override;
function Open(Path : String): boolean; override;
procedure Close; override;
end;
implementation
uses sysutils, filectrl;
type
PIndexRec = ^TIndexRec;
TIndexRec = record
DatKey : LongInt;
DatPos : LongInt
end;
const
FileUsage = fmShareDenyNone or fmOpenRead;
DATMASK_SIZE = $00FFFFFF;
DATMASK_RESERVED = $7F000000;
DATMASK_DELETED = LongInt($80000000);
{ tGroup }
function tDBGroup.Open(Path : String) : boolean;
begin
inherited Open(Path);
//Result := false;
fPos := -1;
if not fCreated then begin
//Create
FSDat := nil;
fCreated := true
end;
//Open
try
FSdat := TFileStreamEx.Create( Path + 'data.dat', FileUsage );
except
on E:EFOpenError do begin
// Log( LOGID_DEBUG, FFileBase + EXT_DAT + ': ' + E.Message );
FSdat := nil;
raise
end;
on E:Exception do begin
// Log( LOGID_DEBUG, FFileBase + EXT_DAT + ': ' + E.Message );
raise
end
end;
IndexFile := TIndexedRecords.Create( Path + 'data.idx',
sizeof(TIndexRec) );
IndexFile.LoadFromFile;
if (IndexFile.Count=0) and (FSdat.Size>0) then
raise Exception.Create('IndexFile damaged?');
Result := true
end;
{function tDBGroup.ReadSize( Key: LongInt ): Integer; //Hamster 23.170
var siz: LongInt;
begin
try
Result := 0;
if key<0 then exit;
FSdat.Seek( GetDatPos(key), soFromBeginning );
FSdat.Read( siz, sizeof(siz) );
Result := siz and DATMASK_SIZE;
except
on E:Exception do begin
// Log( LOGID_ERROR, 'cArtFile.ReadSize: ' + E.Message );
raise;
end;
end;
end;
}
function tDBGroup.ReadHeader(ArtNum: integer; var ArtSize: Integer): String;
var
MaxLength : Integer;
posi : Integer;
begin
MaxLength := 3072;
Result := ReadArticle(ArtNum-1, MaxLength);
posi := pos(#13#10#13#10, Result);
if (posi<=0) then begin
MaxLength := 0;
Result := ReadArticle(ArtNum-1, MaxLength);
posi := pos(#13#10#13#10, Result)
end;
if (posi>0) then SetLength(Result, posi);
ArtSize := MaxLength;
end;
function tDBGroup.ReadArticle( ArtNo: Integer; var MaxSize: Integer ): String; //Hamster 23.170
var dpos: LongWord;
siz: LongInt;
begin
try
Result := '';
if ArtNo<0 then exit;
dpos := PIndexRec( IndexFile.RecPtr(ArtNo) )^.DatPos;
// if dpos<0 then exit;
FSdat.Seek( dpos, soFromBeginning );
FSdat.Read( siz, sizeof(siz) );
siz := siz and DATMASK_SIZE;
if (siz>MaxSize) and (MaxSize>0) then
siz := MaxSize;
MaxSize := siz;
if siz<=0 then exit;
SetLength ( Result, siz );
FSdat.Read( Result[1], siz )
except
on E:Exception do begin
// Log( LOGID_ERROR, 'cArtFile.ReadArticle: ' + E.Message );
Result := '';
raise
end
end
end;
procedure tDBGroup.Close;
begin
if fCreated then begin
if Assigned( IndexFile ) then
FreeAndNil(IndexFile);
if FSdat<>nil then begin
FSdat.Free;
FSdat := nil
end
end;
fCreated := false
end;
procedure tDBGroup.GetHeader(ArtNum: integer; var ResHdr: String; var ArtSize : Integer);
begin
if (ArtNum <= Max) and (ArtNum >= Min) then begin
ResHdr := ReadHeader(ArtNum-1, ArtSize)
end else
ResHdr := ''
end;
procedure tDBGroup.GetArticle (ArtNum : integer; var ResArt : String; var ResSize : Integer);
begin
ResSize := 0;
if (ArtNum <= Max) and (ArtNum >= Min) then begin
ResArt := ReadArticle(ArtNum-1, ResSize)
end else
ResArt := ''
end;
function tDBGroup.Count: longint;
begin
if Assigned(IndexFile) then Result := IndexFile.Count
else Result := 0
end;
function tDBGroup.Max: longint;
begin
Result := Count
end;
function tDBGroup.Min: longint;
begin
Result := 0
end;
procedure tDBGroup.ReadFolderList(res: tVirtualStringTree;
RootNode: PVirtualNode; BasePath: String; PathStrings : tList);
var
f : Textfile;
s : string;
EntryNode: PVirtualNode;
temData: pTreeData;
OldBasePath : String;
begin
OldBasePath := copy(BasePath,pos(';',BasePath)+1,length(BasePath));
BasePath := copy(BasePath,1, pos(';',BasePath)-1);
if not DirectoryExists(BasePath) then
exit;
AssignFile(f, OldBasePath + 'groups.hst');
reset(f);
while not eof(f) do begin //Alle Gruppen einlesen
readln(f,s);
if FileExists(BasePath + s + '\data.dat') then begin
EntryNode := res.AddChild(RootNode);
temData := res.GetNodeData(EntryNode);
with temData^ do begin
new(Path);
PathStrings.Add(Path);
Caption := s;
Path^ := BasePath + s + '\';
imgidx := 31; //2: Pull or not
// typ := HamsterNews;
DB := tDBGroup;
try
if Path^<>'' then begin
open(Path^);
Count := self.count;
close;
end else
Count := -1
except end;
end;
end;
end;
CloseFile(f);
end;
{
function tDBGroup.ReadHeader(ArtNum: integer): String;
var
MaxLength : Integer;
begin
with fCurrentArticle do begin
MaxLength := 3072;
Text := ReadArticle(ArtNum-1, MaxLength);
if FullBody = '' then begin
MaxLength := 0;
Text := ReadArticle(ArtNum-1, MaxLength)
end;
Result := FullHeader
end;
fCurrentOnlyHeader := true
end;
}
end.
| 24.344697 | 100 | 0.610549 |
47e7656d22f63943d104a620ba6d3bfa57908b9c | 110 | pas | Pascal | Source/Source/Tools/LuaWorkshop/synedit/Source/QSynHighlighterPerl.pas | uvbs/FullSource | 07601c5f18d243fb478735b7bdcb8955598b9a90 | [
"MIT"
]
| 2 | 2018-07-26T07:58:14.000Z | 2019-05-31T14:32:18.000Z | Jx3Full/Source/Source/Tools/LuaWorkshop/synedit/Source/QSynHighlighterPerl.pas | RivenZoo/FullSource | cfd7fd7ad422fd2dae5d657a18839c91ff9521fd | [
"MIT"
]
| null | null | null | Jx3Full/Source/Source/Tools/LuaWorkshop/synedit/Source/QSynHighlighterPerl.pas | RivenZoo/FullSource | cfd7fd7ad422fd2dae5d657a18839c91ff9521fd | [
"MIT"
]
| 5 | 2021-02-03T10:25:39.000Z | 2022-02-23T07:08:37.000Z | unit QSynHighlighterPerl;
{$DEFINE SYN_CLX}
{$DEFINE QSYNHIGHLIGHTERPERL}
{$I SynHighlighterPerl.pas}
| 15.714286 | 30 | 0.754545 |
fc5888d074c627ff855341f5ba08ccb9fec7895c | 289 | pas | Pascal | Wke4Delphi/Langji.Wke.Reg.pas | delphilite/AriaNgWke | 80e99f3162db5205c9f9a5fe9f65d2fac3b05024 | [
"MIT"
]
| 22 | 2019-10-18T02:57:00.000Z | 2022-03-24T08:47:38.000Z | Wke4Delphi/Langji.Wke.Reg.pas | delphilite/AriaNgWke | 80e99f3162db5205c9f9a5fe9f65d2fac3b05024 | [
"MIT"
]
| 2 | 2020-08-01T12:48:39.000Z | 2021-01-01T11:09:07.000Z | Wke4Delphi/Langji.Wke.Reg.pas | delphilite/AriaNgWke | 80e99f3162db5205c9f9a5fe9f65d2fac3b05024 | [
"MIT"
]
| 6 | 2019-10-24T03:21:54.000Z | 2022-01-18T21:06:39.000Z | unit Langji.Wke.Reg;
interface
uses classes, Langji.Wke.Webbrowser, Langji.Wke.CustomPage;
procedure Register;
{$R wkelogo.res}
implementation
procedure Register;
begin
RegisterComponents('Langji.Wke', [TWkeWebBrowser, TWkeApp,
TWkeTransparentPage, TWkePopupPage]);
end;
end.
| 14.45 | 60 | 0.775087 |
fc001312f59a83afcfa53939a0a27daddb0cb22b | 337 | dpr | Pascal | src/Delphi/App/App.dpr | sauter-direkt/Delphi-CSharp | 18a681171cd8ef9fc4f843f4fe06cf47072b22a9 | [
"MIT"
]
| 5 | 2021-02-28T08:52:40.000Z | 2021-04-01T13:31:25.000Z | src/Delphi/App/App.dpr | sauter-direkt/Delphi-CSharp | 18a681171cd8ef9fc4f843f4fe06cf47072b22a9 | [
"MIT"
]
| null | null | null | src/Delphi/App/App.dpr | sauter-direkt/Delphi-CSharp | 18a681171cd8ef9fc4f843f4fe06cf47072b22a9 | [
"MIT"
]
| null | null | null | program App;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
UStarter in 'UStarter.pas',
UEngine in 'UEngine.pas',
UCommon in 'UCommon.pas';
begin
try
//TStarter.Execute;
TEngine.Execute;
readln;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.
| 14.652174 | 45 | 0.590504 |
6a3ef0baeaf30fa94af7d50dbd6d397186ffebaf | 1,425 | pas | Pascal | Routes.fattura_preview.pas | andrea-magni/OSItalia_FEMobileClient | 775dc3cb0f688c5f10e36eb114c103eded081a81 | [
"Apache-2.0"
]
| 2 | 2021-12-15T15:13:10.000Z | 2022-02-04T08:41:51.000Z | Routes.fattura_preview.pas | andrea-magni/OSItalia_FEMobileClient | 775dc3cb0f688c5f10e36eb114c103eded081a81 | [
"Apache-2.0"
]
| null | null | null | Routes.fattura_preview.pas | andrea-magni/OSItalia_FEMobileClient | 775dc3cb0f688c5f10e36eb114c103eded081a81 | [
"Apache-2.0"
]
| 2 | 2021-12-16T10:29:03.000Z | 2022-02-04T08:40:58.000Z | unit Routes.fattura_preview;
interface
uses
Classes, SysUtils, UITypes, FMX.Dialogs, FMX.ListView.Appearances, FMX.Types
;
procedure fattura_preview_definition();
implementation
uses
FMXER.Navigator, FMXER.ScaffoldForm, FMXER.WebViewFrame, FMXER.RowForm
, FMXER.IconFontsData, FMXER.IconFontsGlyphFrame
, Data.Remote, Utils.UI
, OSItalia.FE.Classes
;
procedure fattura_preview_definition();
begin
Navigator.DefineRoute<TScaffoldForm>(
'fattura_preview'
, procedure(AForm: TScaffoldForm)
begin
AForm.Title := 'Anteprima HTML fattura';
AForm.SetContentAsFrame<TWebViewFrame>(
procedure (AWebView: TWebViewFrame)
begin
try
AWebView.URL := RemoteData.GetFatturaPreviewURL();
except on E:Exception do
AForm.ShowSnackBar(E.ToString, 3000);
end;
end);
AForm.SetTitleDetailContentAsForm<TRowForm>(
procedure(AForm: TRowForm)
begin
AForm.ElementAlign := TAlignLayout.Right;
AForm.AddFrame<TIconFontsGlyphFrame>(64
, procedure(AGlyphFrame: TIconFontsGlyphFrame)
begin
AGlyphFrame.ImageIndex := UIUtils.BackImageIndex;
AGlyphFrame.OnClickProc :=
procedure
begin
Navigator.CloseRoute('fattura_preview');
end;
end);
end);
end);
end;
end.
| 23.75 | 78 | 0.645614 |
fcb590677b440d5423abc6ec2c6a35c80e9083bb | 23,530 | pas | Pascal | MUSIC_PRO/components/MasterMix.pas | delphi-pascal-archive/music-pro | 85376ca55a478613638e0fa31c10721634dd5227 | [
"Unlicense"
]
| null | null | null | MUSIC_PRO/components/MasterMix.pas | delphi-pascal-archive/music-pro | 85376ca55a478613638e0fa31c10721634dd5227 | [
"Unlicense"
]
| null | null | null | MUSIC_PRO/components/MasterMix.pas | delphi-pascal-archive/music-pro | 85376ca55a478613638e0fa31c10721634dd5227 | [
"Unlicense"
]
| null | null | null | unit MasterMix;
interface
uses
Forms, Windows, Messages, SysUtils, Classes, Controls, Graphics;
type
{>>TITLE}
TMasterTitle = class(TCustomControl)
private
fColorTitle:TColor;
fColorSubTitle:TColor;
fColorRectTitle:TColor;
fTitle:String;
fSubTitle:String;
Procedure setColorTitle(Value:TColor);
Procedure setColorSubTitle(Value:TColor);
Procedure setColorRectTitle(Value:TColor);
Procedure SetTitle(Value:String);
Procedure SetSubTitle(Value:String);
protected
procedure Paint; override;
procedure Resize; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
Property ColorTitle:TColor Read fColorTitle Write SetColorTitle;
Property ColorSubTitle:TColor Read fColorSubTitle Write SetColorSubTitle;
Property ColorRectTitle:TColor Read fColorRectTitle Write SetColorRectTitle;
Property Title:String Read fTitle Write SetTitle;
Property SubTitle:String Read fSubTitle Write SetSubTitle;
end;
{>>TSlider}
TSlider = class(TCustomControl)
private
fCaption:String;
fColorBackGrnd:TColor;
fColorSlot:TColor;
fMin:Integer;
fMax:Integer;
fPos:Integer;
fOnChange : TNotifyEvent;
Procedure Set_Caption(Value:String);
Procedure Set_ColorSlot(Value:TColor);
Procedure Set_ColorBackGrnd(Value:TColor);
Procedure Set_Min(Value:Integer);
Procedure Set_Max(Value:Integer);
Procedure Set_Pos(Value:Integer);
protected
procedure Resize; override;
procedure Paint; override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: integer); override;
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
Property Caption : String Read fCaption Write Set_Caption;
Property ColorSlot:TColor Read fColorSlot Write Set_ColorSlot;
Property ColorBackGrnd:TColor Read fColorBackGrnd Write Set_ColorBackGrnd;
Property Min:Integer Read fMin Write Set_Min;
Property Max:Integer Read fMax Write Set_Max;
Property Pos:Integer Read fPos Write Set_Pos;
Property Tag;
Property Enabled;
Property OnMouseDown;
Property OnMouseMove;
Property OnMouseUp;
Property OnClick;
Property OnDblClick;
Property Color;
Property OnChange:TNotifyEvent Read fOnChange Write fOnChange;
Property OnEnter;
Property OnExit;
Property OnKeyPress;
Property OnKeyDown;
Property OnKeyUp;
end;
{>>TPrgrBar}
TPrgrBar = class(TCustomControl)
private
fColorFirst:TColor;
fColorSecond:TColor;
fColorThird:TColor;
fColorEmpty:TColor;
fMin:Integer;
fMax:Integer;
fPos:Integer;
Procedure Set_ColorFirst(Value:TColor);
Procedure Set_ColorSecond(Value:TColor);
Procedure Set_ColorThird(Value:TColor);
Procedure Set_ColorEmpty(Value:TColor);
Procedure Set_Min(Value:Integer);
Procedure Set_Max(Value:Integer);
Procedure Set_Pos(Value:Integer);
protected
procedure Resize; override;
procedure Paint; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
Property ColorFirst:TColor Read fColorFirst Write Set_ColorFirst;
Property ColorSecond:TColor Read fColorSecond Write Set_ColorSecond;
Property ColorThird:TColor Read fColorThird Write Set_ColorThird;
Property ColorEmpty:TColor Read fColorEmpty Write Set_ColorEmpty;
Property Min:Integer Read fMin Write Set_Min;
Property Max:Integer Read fMax Write Set_Max;
Property Pos:Integer Read fPos Write Set_Pos;
Property Tag;
Property Enabled;
Property OnMouseDown;
Property OnMouseMove;
Property OnMouseUp;
Property OnClick;
Property OnDblClick;
Property Color;
Property OnEnter;
Property OnExit;
Property OnKeyPress;
Property OnKeyDown;
Property OnKeyUp;
end;
{>>TFader}
TFader = class(TCustomControl)
private
fColorSlot:TColor;
fColorLine:TColor;
fColorTop:TColor;
fColorBottom:TColor;
fMin:Integer;
fMax:Integer;
fPos:Integer;
fOnChange : TNotifyEvent;
Procedure Set_ColorSlot(Value:TColor);
Procedure Set_ColorLine(Value:TColor);
Procedure Set_ColorTop(Value:TColor);
Procedure Set_ColorBottom(Value:TColor);
Procedure Set_Min(Value:Integer);
Procedure Set_Max(Value:Integer);
Procedure Set_Pos(Value:Integer);
protected
procedure Resize; override;
procedure Paint; override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: integer); override;
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
Property ColorSlot:TColor Read fColorSlot Write Set_ColorSlot;
Property ColorLine:TColor Read fColorLine Write Set_ColorLine;
Property ColorTop:TColor Read fColorTop Write Set_ColorTop;
Property ColorBottom:TColor Read fColorBottom Write Set_ColorBottom;
Property Min:Integer Read fMin Write Set_Min;
Property Max:Integer Read fMax Write Set_Max;
Property Pos:Integer Read fPos Write Set_Pos;
Property Tag;
Property Enabled;
Property OnMouseDown;
Property OnMouseMove;
Property OnMouseUp;
Property OnClick;
Property OnDblClick;
Property Color;
Property OnChange:TNotifyEvent Read fOnChange Write fOnChange;
Property OnEnter;
Property OnExit;
Property OnKeyPress;
Property OnKeyDown;
Property OnKeyUp;
end;
TMasterMix = class(TCustomControl)
private
fCaption:String;
fMasterTitle:TMasterTitle;
fSlider:TSlider;
fPrgrBar:TPrgrBar;
fFader:TFader;
fOnChange : TNotifyEvent;
Procedure Set_Caption(Value:String);
protected
procedure Resize; override;
procedure Paint; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
Property Caption : String Read fCaption Write Set_Caption;
Property Slider:TSlider Read fSlider Write fSlider;
Property PrgrBar:TPrgrBar Read fPrgrBar Write fPrgrBar;
Property Fader:TFader Read fFader Write fFader;
Property MasterTitle:TMasterTitle Read fMasterTitle Write fMasterTitle;
Property Tag;
Property Enabled;
Property OnMouseDown;
Property OnMouseMove;
Property OnMouseUp;
Property OnClick;
Property OnDblClick;
Property Color;
Property OnChange:TNotifyEvent Read fOnChange Write fOnChange;
Property OnEnter;
Property OnExit;
Property OnKeyPress;
Property OnKeyDown;
Property OnKeyUp;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('MUSIC_PRO', [TMasterMix]);
end;
{>>TITLE}
constructor TMasterTitle.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
fColorRectTitle:=$00CBD5DA;
Title:='Music Pro';
fColorTitle:=clWhite;
SubTitle:='Master';
fColorSubTitle:=$000F16AC;
end;
destructor TMasterTitle.Destroy;
begin
Inherited Destroy;
end;
Procedure TMasterTitle.setColorTitle(Value:TColor);
Begin
fColorTitle:=Value;
Invalidate;
End;
Procedure TMasterTitle.setColorSubTitle(Value:TColor);
Begin
fColorSubTitle:=Value;
Invalidate;
End;
Procedure TMasterTitle.setColorRectTitle(Value:TColor);
Begin
fColorRectTitle:=Value;
Invalidate;
End;
Procedure TMasterTitle.SetTitle(Value:String);
Begin
fTitle:=Value;
Invalidate;
End;
Procedure TMasterTitle.SetSubTitle(Value:String);
Begin
fSubTitle:=Value;
Invalidate;
End;
procedure TMasterTitle.Resize;
Begin
inherited;
Width:=100;
Height:=49;
Invalidate;
End;
procedure TMasterTitle.Paint;
Var
RectTitle:TRect;
WidthString,HeightString,LeftString,TopString:Integer;
Begin
InHerited;
With Canvas Do
Begin
Brush.Style:=BsClear;
With RectTitle Do
Begin
Left:=1;
Right:=Width;
Top:=1;
Bottom:=Height;
Brush.Color:=fColorRectTitle;
Pen.Color:=ClBlack;
Pen.Width:=2;
Rectangle(RectTitle);
Font.Name:='ARIAL';
Font.Size:=12;
Font.Color:=fColorTitle;
LeftString:=Round(0.05*Width);
TopString:=Pen.Width;
TextOut(LeftString,TopString,fTitle);
Font.Name:='Comic Sans MS';
Font.Size:=13;
Font.Color:=Self.fColorSubTitle;
WidthString:=TextWidth(fSubTitle);
HeightString:=TextHeight(fSubTitle);
LeftString:=Self.Width-WidthString-10;
TopString:=Bottom-Pen.Width-HeightString;
TextOut(LeftString,TopString,fSubTitle);
End;
End
End;
{>>TSlider}
constructor TSlider.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
DoubleBuffered:=True;
fMin:=-50;
fMax:=50;
fPos:=0;
Color:=$00A3B4BE;
ColorSlot:=clWhite;
end;
destructor TSlider.Destroy;
begin
inherited;
end;
Procedure TSlider.Set_Caption(Value:String);
begin
fCaption:=Value;
Invalidate;
end;
Procedure TSlider.Set_ColorSlot(Value:TColor);
begin
fColorSlot:=Value;
Invalidate;
end;
Procedure TSlider.Set_ColorBackGrnd(Value:TColor);
begin
fColorBackGrnd:=Value;
Invalidate;
end;
Procedure TSlider.Set_Min(Value:Integer);
begin
if (Value<=fPos) And (Value<fMax) Then
Begin
fMin:=Value;
Invalidate;
End;
end;
Procedure TSlider.Set_Max(Value:Integer);
begin
if (Value>=fPos) And (Value>fMin) Then
Begin
fMax:=Value;
Invalidate;
End;
end;
Procedure TSlider.Set_Pos(Value:Integer);
begin
if (Value>=fMin) And (Value<=fMax) Then
Begin
fPos:=Value;
Invalidate;
End;
end;
procedure TSlider.Resize;
Begin
InHerited;
Width:=100;
Height:=35;
End;
procedure TSlider.Paint;
Var
UpperCorner,LowerCorner:Array [0..2] Of TPoint;
SlotRect,Rect:TRect;
X,WidthText,HeightText:Integer;
ValueStr:String;
Begin
InHerited;
With Canvas Do
Begin
Pen.Width:=2;
UpperCorner[0]:=Point(0,Height);
UpperCorner[1]:=Point(0,0);
UpperCorner[2]:=Point(Width,0);
LowerCorner[0]:=Point(0,Self.Height);
LowerCorner[1]:=Point(Width,Height);
LowerCorner[2]:=Point(Width,0);
Pen.Color:=ClWhite;
Polyline(UpperCorner);
Pen.Color:=$00657271;
Polyline(LowerCorner);
Pen.Width:=1;
Brush.Color:=fColorBackGrnd;
With Rect Do
Begin
Left:=Width Div 10;
Right:=9*Width Div 10;
Top:=55*Height Div 100;
Bottom:=95*Height Div 100;
End;
Rectangle(Rect);
X:=(8*Width Div 10)*(fPos-fMin) Div (fMax-fMin)+Width Div 10;
Pen.Width:=1;
Brush.Color:=fColorSlot;
With SlotRect Do
Begin
Left:=X-2;
Right:=X+2;
Top:=55*Height Div 100;
Bottom:=95*Height Div 100;
End;
Rectangle(SlotRect);
Pen.Width:=0;
ValueStr:=fCaption+' '+IntToStr(fPos);
WidthText:=(Width-TextWidth(ValueStr)) Div 2;
HeightText:=(Height Div 2 - TextHeight(ValueStr)) Div 2;
Brush.Style:=BsClear;
TextOut(WidthText,HeightText,ValueStr);
End;
End;
procedure TSlider.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: integer);
Begin
InHerited;
If SSLeft In Shift Then
MouseMove(Shift, X, Y);
End;
procedure TSlider.MouseMove(Shift: TShiftState; X, Y: Integer);
Begin
InHerited;
If SSLeft In Shift Then
Begin
fPos:=(X-Width Div 10)*(fMax-fMin) Div (8*Width Div 10)+fMin;
If fPos>fMax Then fPos:=fMax;
if fPos<fMin Then fPos:=fMin;
Invalidate;
If Assigned(fOnChange) Then fOnChange(Self);
End;
End;
{>>TPrgrBar}
constructor TPrgrBar.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
DoubleBuffered:=True;
Width:=44;
fMin:=0;
fMax:=100;
fPos:=100;
Color:=$00A3B4BE;
ColorFirst:=$009CE8F5;
ColorSecond:=$001ACBEA;
ColorThird:=$0013AECA;
ColorEmpty:=$00F7F4F2;
end;
destructor TPrgrBar.Destroy;
begin
inherited;
end;
Procedure TPrgrBar.Set_ColorFirst(Value:TColor);
begin
fColorFirst:=Value;
Invalidate;
end;
Procedure TPrgrBar.Set_ColorSecond(Value:TColor);
begin
fColorSecond:=Value;
Invalidate;
end;
Procedure TPrgrBar.Set_ColorThird(Value:TColor);
begin
fColorThird:=Value;
Invalidate;
end;
Procedure TPrgrBar.Set_ColorEmpty(Value:TColor);
begin
fColorEmpty:=Value;
Invalidate;
end;
Procedure TPrgrBar.Set_Min(Value:Integer);
begin
if (Value<=fPos) And (Value<fMax) Then
Begin
fMin:=Value;
Invalidate;
End;
end;
Procedure TPrgrBar.Set_Max(Value:Integer);
begin
if (Value>=fPos) And (Value>fMin) Then
Begin
fMax:=Value;
Invalidate;
End;
end;
Procedure TPrgrBar.Set_Pos(Value:Integer);
begin
if (Value>=fMin) And (Value<=fMax) Then
Begin
fPos:=Value;
Invalidate;
End;
end;
procedure TPrgrBar.Resize;
Begin
InHerited;
Width:=(Width Div 2)*2;
If Width<50 Then Width:=50;
Height:=6*Width;
End;
procedure TPrgrBar.Paint;
Const
HeightRect=5;
Var
UpperCorner,LowerCorner:Array [0..2] Of TPoint;
HeightCurrent, IndexRect, NbRect, PosInDiv:Integer;
ElemRect:TRect;
Begin
InHerited;
With Canvas Do
Begin
Pen.Width:=2;
UpperCorner[0]:=Point(0,Height);
UpperCorner[1]:=Point(0,0);
UpperCorner[2]:=Point(Width,0);
LowerCorner[0]:=Point(0,Self.Height);
LowerCorner[1]:=Point(Width,Height);
LowerCorner[2]:=Point(Width,0);
Pen.Color:=ClWhite;
Polyline(UpperCorner);
Pen.Color:=$00657271;
Polyline(LowerCorner);
Pen.Width:=1;
HeightCurrent:=8*Height Div 10;
NbRect:=HeightCurrent Div HeightRect;
PosInDiv:=(fMax-fPos)*NbRect Div (fMax-fMin);
For IndexRect:=0 To (NbRect-1) Do
With ElemRect Do
Begin
Left:=Width Div 3;
Right:=2*Width Div 3;
Top:=Height Div 10 + IndexRect*HeightRect ;
Bottom:=Top+HeightRect;
If IndexRect<PosInDiv Then Brush.Color:=fColorEmpty
Else
Begin
Brush.Color:=ColorThird;
If IndexRect<(2*NbRect Div 3) Then Brush.Color:=ColorSecond;
If IndexRect<(NbRect Div 3) Then Brush.Color:=ColorFirst;
End;
Pen.Color:=ClBlack;
Rectangle(ElemRect);
End;
End;
End;
{>>TFader}
constructor TFader.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
DoubleBuffered:=True;
Width:=44;
fMin:=0;
fMax:=100;
fPos:=100;
Color:=$00A3B4BE;
ColorLine:=clWhite;
ColorSlot:=clBlack;
ColorBottom:=$00B5A293;
ColorTop:=$00CDC0B6;
end;
destructor TFader.Destroy;
begin
inherited;
end;
Procedure TFader.Set_ColorSlot(Value:TColor);
begin
fColorSlot:=Value;
Invalidate;
end;
Procedure TFader.Set_ColorLine(Value:TColor);
begin
fColorLine:=Value;
Invalidate;
end;
Procedure TFader.Set_ColorTop(Value:TColor);
begin
fColorTop:=Value;
Invalidate;
end;
Procedure TFader.Set_ColorBottom(Value:TColor);
begin
fColorBottom:=Value;
Invalidate;
end;
Procedure TFader.Set_Min(Value:Integer);
begin
if (Value<=fPos) And (Value<fMax) Then
Begin
fMin:=Value;
Invalidate;
End;
end;
Procedure TFader.Set_Max(Value:Integer);
begin
if (Value>=fPos) And (Value>fMin) Then
Begin
fMax:=Value;
Invalidate;
End;
end;
Procedure TFader.Set_Pos(Value:Integer);
begin
if (Value>=fMin) And (Value<=fMax) Then
Begin
fPos:=Value;
Invalidate;
End;
end;
procedure TFader.Resize;
Begin
InHerited;
Width:=(Width Div 2)*2;
If Width<50 Then Width:=50;
Height:=6*Width;
End;
procedure TFader.Paint;
Var
UpperCorner,LowerCorner:Array [0..2] Of TPoint;
SlotRect,BottomRect,TopRect, PanelRect:TRect;
WidthSlot, HeightSlot,HeightText, DelimTop,DelimBottom, IndexLine:Integer;
ValueStr:String;
Begin
InHerited;
With Canvas Do
Begin
Pen.Width:=2;
UpperCorner[0]:=Point(0,Height);
UpperCorner[1]:=Point(0,0);
UpperCorner[2]:=Point(Width,0);
LowerCorner[0]:=Point(0,Self.Height);
LowerCorner[1]:=Point(Width,Height);
LowerCorner[2]:=Point(Width,0);
Pen.Color:=ClWhite;
Polyline(UpperCorner);
Pen.Color:=$00657271;
Polyline(LowerCorner);
Pen.Width:=1;
WidthSlot:=Width Div 8;
HeightSlot:=8*Height Div 10;
Pen.Color:=fColorSlot;
Brush.Color:=fColorSlot;
With SlotRect Do
Begin
Left:=(Width-WidthSlot) Div 2;
Right:=Left+WidthSlot;
Top:=(Height-HeightSlot) Div 2;
Bottom:=Top+HeightSlot;
End;
Rectangle(SlotRect);
Pen.Color:=fColorLine;
Brush.Color:=fColorLine;
Brush.Style:=BsClear;
Font.Name:='Small Fonts';
Font.Size:=Width Div 10;
Font.Color:=ClWhite;
For IndexLine:=0 To 4 Do
Begin
MoveTo(SlotRect.Left Div 2,Height Div 10 + HeightSlot*IndexLine Div 4);
LineTo(SlotRect.Left,Height Div 10 + HeightSlot*IndexLine Div 4);
ValueStr:=format('%.0f', [fMax-(fMax-fMin)*IndexLine / 4]);
HeightText:=TextHeight(ValueStr);
TextOut(2*Width Div 3,Height Div 10 + HeightSlot*IndexLine Div 4 - HeightText Div 2,ValueStr);
End;
MoveTo(SlotRect.Left Div 2,SlotRect.Top);
LineTo(SlotRect.Left Div 2,SlotRect.Bottom);
DelimTop:=Height Div 10;
DelimBottom:=9*Height Div 10;
With TopRect Do
Begin
Left:=Width Div 3;
Right:=2*Width Div 3;
Bottom:=Round(DelimBottom-(fMin-fPos)*(DelimBottom-DelimTop)/(fMin-fMax));
Top:=Bottom-2*DelimTop Div 3;
End;
Brush.Color:=fColorTop;
Pen.Color:=fColorTop;
Rectangle(TopRect);
With BottomRect Do
Begin
Left:=Width Div 3;
Right:=2*Width Div 3;
Top:=Round(DelimBottom-(fMin-fPos)*(DelimBottom-DelimTop)/(fMin-fMax));
Bottom:=Top+2*DelimTop Div 3;
End;
Brush.Color:=fColorBottom;
Pen.Color:=fColorBottom;
Rectangle(BottomRect);
Brush.Color:=fColorLine;
Pen.Color:=fColorLine;
MoveTo(TopRect.Left,TopRect.Bottom);
LineTo(TopRect.Right,TopRect.Bottom);
With BottomRect Do
For IndexLine:=1 To 2 Do
Begin
Brush.Color:=fColorLine;
Pen.Color:=fColorLine;
MoveTo(TopRect.Left,Top+(Bottom-Top)*IndexLine Div 3);
LineTo(TopRect.Right,Top+(Bottom-Top)*IndexLine Div 3);
Brush.Color:=$00657271;
Pen.Color:=$00657271;
MoveTo(TopRect.Left,Top+(Bottom-Top)*IndexLine Div 3+1);
LineTo(TopRect.Right,Top+(Bottom-Top)*IndexLine Div 3+1);
End;
UpperCorner[0]:=Point(TopRect.Right,TopRect.Top);
UpperCorner[1]:=Point(TopRect.Left,TopRect.Top);
UpperCorner[2]:=Point(TopRect.Left,BottomRect.Bottom);
LowerCorner[0]:=Point(TopRect.Left,BottomRect.Bottom);
LowerCorner[1]:=Point(BottomRect.Right,BottomRect.Bottom);
LowerCorner[2]:=Point(BottomRect.Right,TopRect.Top);
Pen.Color:=ClWhite;
Polyline(UpperCorner);
Pen.Color:=$00657271;
Polyline(LowerCorner);
End;
End;
procedure TFader.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: integer);
Begin
InHerited;
If SSLeft In Shift Then
MouseMove(Shift, X, Y);
End;
procedure TFader.MouseMove(Shift: TShiftState; X, Y: Integer);
Var
DelimTop,DelimBottom:Integer;
Begin
InHerited;
If SSLeft In Shift Then
Begin
DelimTop:=Height Div 10;
DelimBottom:=9*Height Div 10;
fPos:=Round(fMin-(DelimBottom-Y)*(fMin-fMax)/(DelimBottom-DelimTop));
If fPos>fMax Then fPos:=fMax;
if fPos<fMin Then fPos:=fMin;
Invalidate;
If Assigned(fOnChange) Then fOnChange(Self);
End;
End;
{>>TMasterMix}
constructor TMasterMix.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
fCaption:='MASTER';
Color:=$00A3B4BE;
fMasterTitle:=TMasterTitle.Create(Self);
With fMasterTitle Do
Begin
Parent:=Self;
Left:=5;
Top:=5;
End;
fSlider:=TSlider.Create(Self);
With fSlider Do
Begin
Parent:=Self;
Name:='Slider';
SetSubComponent(True);
Width:=100;
Height:=35;
Left:=5;
Top:=56;
Caption:='Pan';
End;
fFader:=TFader.Create(Self);
With fFader Do
Begin
Parent:=Self;
Name:='Fader';
SetSubComponent(True);
Width:=50;
Height:=300;
Left:=5;
Top:=fSlider.Top+fSlider.Height;
End;
fPrgrBar:=TPrgrBar.Create(Self);
With fPrgrBar Do
Begin
Parent:=Self;
Name:='PrgrBar';
SetSubComponent(True);
Width:=50;
Height:=300;
Left:=fFader.Left+fFader.Width;
Top:=fSlider.Top+fSlider.Height;
End;
end;
destructor TMasterMix.Destroy;
begin
fMasterTitle.Free;
fSlider.Free;
// fFader.Free;
// fPrgrBar.Free;
inherited;
end;
Procedure TMasterMix.Set_Caption(Value:String);
begin
fCaption:=Value;
Invalidate;
end;
procedure TMasterMix.Resize;
Begin
InHerited;
Width:=110;
Height:=416;
End;
procedure TMasterMix.Paint;
Var
UpperCorner,LowerCorner:Array [0..2] Of TPoint;
TopOffset,DecHeight,WidthText,HeightText:Integer;
Rect:TRect;
Begin
InHerited;
With Canvas Do
Begin
Pen.Width:=4;
UpperCorner[0]:=Point(0,Height);
UpperCorner[1]:=Point(0,0);
UpperCorner[2]:=Point(Width,0);
LowerCorner[0]:=Point(0,Self.Height);
LowerCorner[1]:=Point(Width,Height);
LowerCorner[2]:=Point(Width,0);
Pen.Color:=ClWhite;
Polyline(UpperCorner);
Pen.Color:=$00AEAEAE;
Polyline(LowerCorner);
Pen.Width:=0;
TopOffset:=fFader.Top+fFader.Height;
DecHeight:=Height-TopOffset;
Brush.Color:=$00E1E1E1;
Pen.Color:=$00E1E1E1;
With Rect Do
Begin
Left:=5;
Right:=Width-5;
Top:=TopOffset+1;
Bottom:=Height-5;
End;
Rectangle(Rect);
UpperCorner[0]:=Point(Width-6,TopOffset+1);
UpperCorner[1]:=Point(6,TopOffset+1);
UpperCorner[2]:=Point(6,Height-5);
LowerCorner[0]:=Point(6,Height-5);
LowerCorner[1]:=Point(Width-6,Height-5);
LowerCorner[2]:=Point(Width-6,TopOffset+1);
Pen.Color:=$00657271;
Polyline(UpperCorner);
Pen.Color:=ClWhite;
Polyline(LowerCorner);
WidthText:=(Width-TextWidth(fCaption)) Div 2;
HeightText:=TopOffset+(DecHeight-TextHeight(fCaption)) Div 2;
Brush.Style:=BsClear;
TextOut(WidthText,heightText,fCaption);
End;
End;
end.
| 25.355603 | 105 | 0.653549 |
c30797b3c2399a14da98b6f83218a249b692a22f | 141 | pas | Pascal | Test/FailureScripts/empty_body.pas | synapsea/DW-Script | b36c2e57f0285c217f8f0cae8e4e158d21127163 | [
"Condor-1.1"
]
| 1 | 2022-02-18T22:14:44.000Z | 2022-02-18T22:14:44.000Z | Test/FailureScripts/empty_body.pas | synapsea/DW-Script | b36c2e57f0285c217f8f0cae8e4e158d21127163 | [
"Condor-1.1"
]
| null | null | null | Test/FailureScripts/empty_body.pas | synapsea/DW-Script | b36c2e57f0285c217f8f0cae8e4e158d21127163 | [
"Condor-1.1"
]
| null | null | null | type
TTest = class
method Proc; empty;
end;
method TTest.Proc;
begin
end;
type
TTest2 = class
method Proc; empty
| 10.846154 | 25 | 0.602837 |
fcc2e03940e5d503afac15be8c9979fb4c59e928 | 5,746 | pas | Pascal | windows/src/engine/tsysinfo/si_language.pas | bravogeorge/keyman | c0797e36292de903d7313214d1f765e3d9a2bf4d | [
"MIT"
]
| 219 | 2017-06-21T03:37:03.000Z | 2022-03-27T12:09:28.000Z | windows/src/engine/tsysinfo/si_language.pas | bravogeorge/keyman | c0797e36292de903d7313214d1f765e3d9a2bf4d | [
"MIT"
]
| 4,451 | 2017-05-29T02:52:06.000Z | 2022-03-31T23:53:23.000Z | windows/src/engine/tsysinfo/si_language.pas | bravogeorge/keyman | c0797e36292de903d7313214d1f765e3d9a2bf4d | [
"MIT"
]
| 72 | 2017-05-26T04:08:37.000Z | 2022-03-03T10:26:20.000Z | (*
Name: si_language
Copyright: Copyright (C) SIL International.
Documentation: km4.1
Description: Get language environment details from system
Create Date: 13 May 2005
Modified Date: 15 Apr 2015
Authors: mcdurdin
Related Files:
Dependencies:
Bugs:
Todo:
Notes:
History: 13 May 2005 - mcdurdin - Integrated into kmshell from tsysinfo
09 Jun 2005 - mcdurdin - Use MSXML_TLB not MSXML2_TLB
20 Jul 2008 - mcdurdin - I1532 - Report on additional items in tsysinfo
03 May 2011 - mcdurdin - I2890 - Record diagnostic data when encountering registry errors
19 Jul 2011 - mcdurdin - I3000 - Tweak display of diagnostics using .xslt files
15 Apr 2015 - mcdurdin - I4659 - V9.0 - Add more detailed keyboard diagnostics
*)
unit si_language;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, si_base, StdCtrls, msxml;
type
TGetLocalInfoEx = function(lpLocaleName: PWideChar; LCType: DWORD; lpLCData: PWideChar; cchData: Integer): Integer; stdcall;
TSI_Language = class(TSI_Base)
private
FLocaleNode: IXMLDOMNode;
FGetLocaleInfoEx: TGetLocalInfoEx;
procedure AddLocale(localeName: WideString; dwFlags: DWORD);
procedure AddLocaleEx(localeName: WideString; dwFlags: DWORD);
protected
function DoCollect: Boolean; override;
class function GetCaption: String; override;
function GetUseGlobalData: Boolean; override;
end;
implementation
uses ErrorControlledRegistry, RegistryKeys, WideStrings, sysinfo_Util, ComObj, ShlObj;
{ TSI_Language }
class function TSI_Language.GetCaption: String;
begin
Result := 'Language Environment';
end;
function TSI_Language.GetUseGlobalData: Boolean;
begin
Result := True;
end;
var
FSILanguage: TSI_Language = nil;
const
LOCALE_WINDOWS = 1;
LOCALE_SUPPLEMENTAL = 2;
function LocaleEnumProc(const localeName: PWideChar): DWORD; stdcall;
begin
FSILanguage.AddLocale(localeName, LOCALE_WINDOWS);
Result := 1;
end;
function LocaleEnumProcEx(const localeName: PWideChar; dwFlags: DWord; lParam: LPARAM): DWORD; stdcall;
begin
TSI_Language(lParam).AddLocaleEx(localeName, dwFlags);
Result := 1;
end;
procedure TSI_Language.AddLocale(localeName: WideString; dwFlags: DWORD);
var
node: IXMLDOMNode;
buf: array[0..255] of WideChar;
begin
node := xmlAddChild(FLocaleNode,'Locale');
xmlSetAttribute(node, 'ID', localeName);
xmlSetAttribute(node, 'Flags', IntToHex(dwFlags,8));
if GetLocaleInfoW(StrToIntDef('$'+localeName, 8), LOCALE_SENGLANGUAGE, buf, 255) > 0 then
xmlSetAttribute(node, 'Name', buf);
if GetLocaleInfoW(StrToIntDef('$'+localeName, 8), LOCALE_SENGCOUNTRY, buf, 255) > 0 then
xmlSetAttribute(node, 'Country', buf);
end;
procedure TSI_Language.AddLocaleEx(localeName: WideString; dwFlags: DWORD);
var
node: IXMLDOMNode;
buf: array[0..255] of WideChar;
begin
node := xmlAddChild(FLocaleNode,'Locale');
if FGetLocaleInfoEx(PWideChar(localeName), LOCALE_ILANGUAGE, buf, 255) > 0 then
xmlSetAttribute(node, 'ID', '0000'+buf);
xmlSetAttribute(node, 'StringID', localeName);
xmlSetAttribute(node, 'Flags', IntToHex(dwFlags,8));
if FGetLocaleInfoEx(PWideChar(localeName), LOCALE_SENGLANGUAGE, buf, 255) > 0 then
xmlSetAttribute(node, 'Name', buf);
if FGetLocaleInfoEx(PWideChar(localeName), LOCALE_SENGCOUNTRY, buf, 255) > 0 then
xmlSetAttribute(node, 'Country', buf);
end;
function TSI_Language.DoCollect: Boolean;
type
TLocale_EnumProcExW = function(const lpLocaleString: PWideChar; dwFlags: DWord; lParam: LPARAM): DWORD; stdcall;
TEnumSystemLocalesExW = function(lpLocaleEnumProcEx: TLocale_EnumProcExW; dwFlags: DWORD; lParam: LPARAM; lpReserved: Pointer): BOOL; stdcall;
const
CSIDL_SYSTEM = $25;
var
regnode, subnode, node: IXMLDOMNode;
str: TStringList;
I: Integer;
FEnumSystemLocalesEx: TEnumSystemLocalesExW;
begin
node := xmlAddChild(rootnode,'Languages');
subnode := xmlAddChild(node,'Registry');
regnode := xmlAddChild(subnode,'LocalMachine');
AddRegistry(regnode, HKEY_LOCAL_MACHINE, SRegKey_KeyboardLayouts_LM);
AddRegistry(regnode, HKEY_LOCAL_MACHINE, 'Software\Microsoft\CTF');
AddRegistry(regnode, HKEY_LOCAL_MACHINE, 'System\CurrentControlSet\Control\Nls');
FLocaleNode := xmlAddChild(rootnode, 'Locales');
FEnumSystemLocalesEx := GetProcAddress(GetModuleHandle(Kernel32), 'EnumSystemLocalesEx');
FGetLocaleInfoEx := GetProcAddress(GetModuleHandle(Kernel32), 'GetLocaleInfoEx');
if Assigned(FEnumSystemLocalesEx) and Assigned(FGetLocaleInfoEx) then
begin
FEnumSystemLocalesEx(LocaleEnumProcEx, LOCALE_WINDOWS or LOCALE_SUPPLEMENTAL, LPARAM(Self), nil);
end
else
begin
FSILanguage := Self;
EnumSystemLocalesW(@LocaleEnumProc, LCID_SUPPORTED);
FSILanguage := nil;
end;
FLocaleNode := nil;
regnode := xmlAddChild(subnode,'CurrentUser');
AddRegistry(regnode, HKEY_CURRENT_USER, SRegKey_KeyboardLayout_CU);
subnode := xmlAddChild(node,'Uniscribe');
AddFileVersion(subnode, GetFolderPath(CSIDL_SYSTEM) + 'usp10.dll');
str := TStringList.Create;
with TRegistryErrorControlled.Create do // I2890
try
RootKey := HKEY_LOCAL_MACHINE;
if OpenKeyReadOnly('Software\Microsoft\Windows\CurrentVersion\SharedDlls') then
begin
GetValueNames(str);
for I := 0 to str.Count - 1 do
begin
if SameText(Copy(str[i], Length(str[i])-8, 9), 'usp10.dll') then
AddFileVersion(subnode, str[i]);
end;
end;
finally
Free;
str.Free;
end;
Result := True;
end;
initialization
TSI_Language.Register;
end.
| 33.213873 | 144 | 0.723634 |
83a03747079c320dd337bfa5b053546e26ce243b | 269 | pas | Pascal | test_pascal/data/sdsadasd.pas | tranleduy2000/pascalnide | c7f3f79ecf4cf6a81b32c7d389aad7f4034c8f01 | [
"Apache-2.0"
]
| 81 | 2017-05-07T13:26:56.000Z | 2022-03-03T19:39:15.000Z | test_pascal/data/sdsadasd.pas | tranleduy2000/pascalnide | c7f3f79ecf4cf6a81b32c7d389aad7f4034c8f01 | [
"Apache-2.0"
]
| 52 | 2017-06-13T08:46:43.000Z | 2021-06-09T09:50:07.000Z | test_pascal/data/sdsadasd.pas | tranleduy2000/pascalnide | c7f3f79ecf4cf6a81b32c7d389aad7f4034c8f01 | [
"Apache-2.0"
]
| 28 | 2017-05-22T21:09:58.000Z | 2021-09-07T13:05:27.000Z | {Пример программы для процедуры Ellipse}
Uses Graph;
Var
Gd, Gm : Integer;
Begin
Gd := Detect;
InitGraph(Gd, Gm, '');
If GraphResult <> grOk Then Halt(1);
Ellipse(100, 100, 0, 360, 30, 50);
Ellipse(100, 100, 0, 180, 50, 30);
ReadLn;
CloseGraph;
End.
| 15.823529 | 40 | 0.63197 |
839567c7798262763dfd978dadc3ec14770ddd75 | 470 | pas | Pascal | Object Pascal/algorithms/GridSearchAlgorithm.pas | Zoomicon/GridSearchDemo | 9a1da46ec349eff995bcf193fc2309bd47c48a2b | [
"MIT"
]
| 3 | 2016-07-22T02:18:03.000Z | 2021-11-04T19:55:54.000Z | Object Pascal/algorithms/GridSearchAlgorithm.pas | Zoomicon/GridSearchDemo | 9a1da46ec349eff995bcf193fc2309bd47c48a2b | [
"MIT"
]
| null | null | null | Object Pascal/algorithms/GridSearchAlgorithm.pas | Zoomicon/GridSearchDemo | 9a1da46ec349eff995bcf193fc2309bd47c48a2b | [
"MIT"
]
| 2 | 2016-07-22T01:48:11.000Z | 2021-11-04T19:55:55.000Z | //Project: GridSearchDemo (http://github.com/Zoomicon/GridSearchDemo)
//Author: George Birbilis
//Version: 18Dec2016
unit GridSearchAlgorithm;
interface
uses Grid;
type TGridSearchAlgorithm=class
protected
grid:TGrid;
public
stopped:boolean;
constructor Create(theGrid:TGrid); virtual;
procedure search; virtual; abstract;
end;
implementation
constructor TGridSearchAlgorithm.Create;
begin
grid:=theGrid;
end;
end.
| 16.785714 | 69 | 0.725532 |
4798409518af30d08b339507fcd06d84022c2cbf | 4,886 | pas | Pascal | source/Http/Fido.Http.Request.pas | sonjli/FidoLib | d86c5bdf97e13cd2317ace207a6494da6cfe92f3 | [
"MIT"
]
| null | null | null | source/Http/Fido.Http.Request.pas | sonjli/FidoLib | d86c5bdf97e13cd2317ace207a6494da6cfe92f3 | [
"MIT"
]
| null | null | null | source/Http/Fido.Http.Request.pas | sonjli/FidoLib | d86c5bdf97e13cd2317ace207a6494da6cfe92f3 | [
"MIT"
]
| null | null | null | (*
* Copyright 2021 Mirko Bianco (email: writetomirko@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*)
unit Fido.Http.Request;
interface
uses
System.Classes,
System.SysUtils,
Generics.Defaults,
Spring,
Spring.Collections,
Fido.Http.Types,
Fido.Http.RequestInfo.Intf,
Fido.Http.Request.Intf;
type
THttpRequest = class(TInterfacedObject, IHttpRequest)
private
FMethod: THttpMethod;
FURI: string;
FBody: string;
FFormParams: IDictionary<string, string>;
FQueryParams: IDictionary<string, string>;
FHeaderParams: IDictionary<string, string>;
FMimeType: TMimeType;
constructor StringsToDictionary(const Strings: TStrings; const Dictionary: IDictionary<string, string>);
public
constructor Create(const RequestInfo: IHttpRequestInfo);
function Method: THttpMethod;
function URI: string;
function Body: string;
function FormParams: IReadOnlyDictionary<string, string>;
function HeaderParams: IReadOnlyDictionary<string, string>;
function QueryParams: IReadOnlyDictionary<string, string>;
function MimeType: TMimeType;
end;
implementation
{ THttpRequest }
constructor THttpRequest.StringsToDictionary(
const Strings: TStrings;
const Dictionary: IDictionary<string, string>);
var
I: Integer;
begin
Guard.CheckNotNull(Strings, 'Strings');
Guard.CheckNotNull(Dictionary, 'Dictionary');
for I := 0 to Strings.Count - 1 do
Dictionary[Strings.Names[I]] := Strings.ValueFromIndex[I];
end;
function THttpRequest.URI: string;
begin
Result := FURI;
end;
constructor THttpRequest.Create(const RequestInfo: IHttpRequestInfo);
var
TempBodyParams: Shared<TStringList>;
StringMimeType: string;
MimeTypeIndex: Integer;
ContentType: string;
function ConvertToRestCommand(const Item: string): THttpMethod;
var
I: Integer;
begin
Result := rmUnknown;
for I := 0 to Integer(High(SHttpMethod)) do
if UpperCase(SHttpMethod[THttpMethod(I)]) = UpperCase(Item) then
Exit(THttpMethod(I));
end;
begin
Guard.CheckNotNull(RequestInfo, 'RequestInfo');
inherited Create;
FFormParams := TCollections.CreateDictionary<string, string>(TIStringComparer.Ordinal);
FQueryParams := TCollections.CreateDictionary<string, string>(TIStringComparer.Ordinal);
FHeaderParams := TCollections.CreateDictionary<string, string>(TIStringComparer.Ordinal);
MimeTypeIndex := -1;
ContentType := RequestInfo.ContentType.ToUpper;
if ContentType.IsEmpty then
ContentType := DEFAULTMIME;
for StringMimeType in SMimeType do
begin
Inc(MimeTypeIndex);
if ContentType.ToUpper = StringMimeType.ToUpper then
Break;
end;
FMimeType := TMimeType(MimeTypeIndex);
TempBodyParams := TStringList.Create;
if Assigned(RequestInfo.PostStream) then
TempBodyParams.Value.LoadFromStream(RequestInfo.PostStream);
FBody := RequestInfo.UnparsedParams;
if FBody.IsEmpty then
FBody := TempBodyParams.Value.Text;
StringsToDictionary(RequestInfo.FormParams, FFormParams);
StringsToDictionary(RequestInfo.QueryParams, FQueryParams);
StringsToDictionary(RequestInfo.RawHeaders, FHeaderParams);
FUri := RequestInfo.URI;
FMethod := ConvertToRestCommand(RequestInfo.Command);
end;
function THttpRequest.Method: THttpMethod;
begin
Result := FMethod;
end;
function THttpRequest.MimeType: TMimeType;
begin
Result := FMimeType;
end;
function THttpRequest.Body: string;
begin
Result := FBody;
end;
function THttpRequest.FormParams: IReadOnlyDictionary<string, string>;
begin
Result := FFormParams.AsReadOnlyDictionary;
end;
function THttpRequest.HeaderParams: IReadOnlyDictionary<string, string>;
begin
Result := FHeaderParams.AsReadOnlyDictionary;
end;
function THttpRequest.QueryParams: IReadOnlyDictionary<string, string>;
begin
Result := FQueryParams.AsReadOnlyDictionary;
end;
end.
| 28.406977 | 108 | 0.762382 |
c305094198bacf4a756eecddc358f013755f619a | 1,376 | pas | Pascal | Painting/CopyModeUnit1.pas | rustkas/dephi_do | 96025a01d5cb49136472b7e6bb5f037b27145fba | [
"MIT"
]
| null | null | null | Painting/CopyModeUnit1.pas | rustkas/dephi_do | 96025a01d5cb49136472b7e6bb5f037b27145fba | [
"MIT"
]
| null | null | null | Painting/CopyModeUnit1.pas | rustkas/dephi_do | 96025a01d5cb49136472b7e6bb5f037b27145fba | [
"MIT"
]
| null | null | null | unit CopyModeUnit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls;
type
TCopyModeForm1 = class(TForm)
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormCreate(Sender: TObject);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
StartX, StartY: Integer;
dragging: Boolean;
public
{ Public declarations }
end;
var
CopyModeForm1: TCopyModeForm1;
implementation
{$R *.dfm}
procedure TCopyModeForm1.FormCreate(Sender: TObject);
begin
dragging := false;
end;
procedure TCopyModeForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
StartX := X;
StartY := Y;
dragging := true;
end;
procedure TCopyModeForm1.FormMouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
begin
if dragging = false then
exit;
Canvas.Rectangle(StartX, StartY, X, Y);
end;
procedure TCopyModeForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
dragging := false;
end;
end.
| 21.84127 | 80 | 0.726017 |
fc8dba5da7652b9964f9ef17dd0ba67dec8f3d6f | 1,601 | pas | Pascal | Libraries/KControls/source/kmemodlghyperlink.pas | jomael/Concepts | 82d18029e41d55e897d007f826c021cdf63e53f8 | [
"Apache-2.0"
]
| 62 | 2016-01-20T16:26:25.000Z | 2022-02-28T14:25:52.000Z | Libraries/KControls/source/kmemodlghyperlink.pas | jomael/Concepts | 82d18029e41d55e897d007f826c021cdf63e53f8 | [
"Apache-2.0"
]
| null | null | null | Libraries/KControls/source/kmemodlghyperlink.pas | jomael/Concepts | 82d18029e41d55e897d007f826c021cdf63e53f8 | [
"Apache-2.0"
]
| 20 | 2016-09-08T00:15:22.000Z | 2022-01-26T13:13:08.000Z | { @abstract(This file is part of the KControls component suite for Delphi and Lazarus.)
@author(Tomas Krysl)
Copyright (c) 2020 Tomas Krysl<BR><BR>
<B>License:</B><BR>
This code is licensed under BSD 3-Clause Clear License, see file License.txt or https://spdx.org/licenses/BSD-3-Clause-Clear.html.
}
unit kmemodlghyperlink; // lowercase name because of Lazarus/Linux
interface
uses
{$IFDEF FPC}
LCLType, LCLIntf, LMessages, LCLProc, LResources,
{$ELSE}
Windows, Messages,
{$ENDIF}
SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, KControls, KMemo;
type
TKMemoHyperlinkForm = class(TForm)
BUOk: TButton;
BUCancel: TButton;
LBText: TLabel;
EDText: TEdit;
LBHyperlink: TLabel;
CoBURL: TComboBox;
private
{ Private declarations }
public
{ Public declarations }
procedure Clear;
procedure Load(AItem: TKMemoHyperlink);
procedure Save(AItem: TKMemoHyperlink);
end;
implementation
{$IFDEF FPC}
{$R *.lfm}
{$ELSE}
{$R *.dfm}
{$ENDIF}
uses
KGraphics;
{ TKMemoHyperlinkForm }
procedure TKMemoHyperlinkForm.Clear;
begin
EDText.Text := '';
CoBURL.Text := '';
end;
procedure TKMemoHyperlinkForm.Load(AItem: TKMemoHyperlink);
begin
if AItem <> nil then
begin
EDText.Text := AItem.Text;
CoBURL.Text := AItem.URL;
end;
end;
procedure TKMemoHyperlinkForm.Save(AItem: TKMemoHyperlink);
begin
if AItem <> nil then
begin
if CoBURL.Items.IndexOf(CoBURL.Text) < 0 then
CoBURL.Items.Add(CoBURL.Text);
AItem.Text := EDText.Text;
AItem.URL := CoBURL.Text;
end;
end;
end.
| 20.0125 | 132 | 0.698938 |
f174cce3e20f61abc81406adaa468a1d61b9c8a8 | 7,031 | pas | Pascal | udrafter.pas | joxeankoret/drafter | ff8d45c458682be74f3315485cfaf7a03d3fefd4 | [
"Unlicense"
]
| null | null | null | udrafter.pas | joxeankoret/drafter | ff8d45c458682be74f3315485cfaf7a03d3fefd4 | [
"Unlicense"
]
| null | null | null | udrafter.pas | joxeankoret/drafter | ff8d45c458682be74f3315485cfaf7a03d3fefd4 | [
"Unlicense"
]
| null | null | null | unit udrafter;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, Menus,
SynEdit, SynCompletion, LCLType, ExtDlgs, IniFiles;
type
{ TfrmMain }
TfrmMain = class(TForm)
dlgCalculator: TCalculatorDialog;
dlgCalendar: TCalendarDialog;
dlgFont: TFontDialog;
dlgFind: TFindDialog;
mainMenu: TMainMenu;
MenuItem1: TMenuItem;
MenuItem2: TMenuItem;
menuFont: TMenuItem;
menuCalendar: TMenuItem;
menuCalculator: TMenuItem;
menuTools: TMenuItem;
menuSelectWord: TMenuItem;
menuSelectLine: TMenuItem;
MenuItem4: TMenuItem;
menuSearch: TMenuItem;
menuRedo: TMenuItem;
menuPaste: TMenuItem;
menuSelectAll: TMenuItem;
MenuItem12: TMenuItem;
menuAbout: TMenuItem;
N3: TMenuItem;
menuOpen: TMenuItem;
menuSave: TMenuItem;
menuExit: TMenuItem;
MenuItem5: TMenuItem;
menuUndo: TMenuItem;
menuCut: TMenuItem;
menuCopy: TMenuItem;
N2: TMenuItem;
N1: TMenuItem;
dlgOpen: TOpenDialog;
dlgSave: TSaveDialog;
txtTweets: TSynEdit;
procedure dlgFindFind(Sender: TObject);
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure menuAboutClick(Sender: TObject);
procedure menuCalculatorClick(Sender: TObject);
procedure menuCalendarClick(Sender: TObject);
procedure menuCopyClick(Sender: TObject);
procedure menuCutClick(Sender: TObject);
procedure menuExitClick(Sender: TObject);
procedure menuFontClick(Sender: TObject);
procedure menuOpenClick(Sender: TObject);
procedure menuPasteClick(Sender: TObject);
procedure menuRedoClick(Sender: TObject);
procedure menuSaveClick(Sender: TObject);
procedure menuSearchClick(Sender: TObject);
procedure menuSelectAllClick(Sender: TObject);
procedure menuSelectLineClick(Sender: TObject);
procedure menuSelectWordClick(Sender: TObject);
procedure menuUndoClick(Sender: TObject);
procedure txtTweetsChange(Sender: TObject);
procedure txtTweetsDblClick(Sender: TObject);
private
public
end;
var
frmMain: TfrmMain;
g_modifying : boolean;
g_saved : boolean;
implementation
{$R *.lfm}
{ TfrmMain }
procedure TfrmMain.txtTweetsChange(Sender: TObject);
var
i : integer;
iPos : integer;
iTotal : integer;
iLength: integer;
tmp1, tmp2 : string;
begin
g_saved := false;
iTotal := 0;
if g_modifying then
begin
exit;
end;
g_modifying := true;
for i := 0 to txtTweets.Lines.Count - 1 do
begin
iLength := Length(txtTweets.lines[i]);
if iLength > 280 then
begin
iPos := txtTweets.SelStart;
tmp1 := txtTweets.lines[i].Substring(0, 280);
tmp2 := txtTweets.lines[i].Substring(280);
txtTweets.Lines[i] := tmp1;
txtTweets.Lines.Insert(i+1, '');
txtTweets.Lines.Insert(i+2, tmp2);
txtTweets.SelStart := iPos;
break;
end;
iTotal += iLength;
end;
g_modifying := false;
end;
procedure TfrmMain.txtTweetsDblClick(Sender: TObject);
begin
ShowMessage('Total lines ' + IntToStr(txtTweets.Lines.Count));
end;
procedure TfrmMain.FormCreate(Sender: TObject);
var
INI : TIniFile;
begin
g_modifying := false;
g_saved := true;
if FileExists('drafter.ini') then
begin
Ini := TIniFile.Create('drafter.ini');
frmMain.Top := Ini.ReadInteger('Window', 'Top', 0);
frmMain.Left := Ini.ReadInteger('Window', 'Left', 0);
frmMain.Height := Ini.ReadInteger('Window', 'Height', 600);
frmMain.Width := Ini.ReadInteger('Window', 'Width', 800);
txtTweets.Font.Name := Ini.ReadString ('Font', 'Name', 'Courier New');
txtTweets.Font.Size := Ini.ReadInteger('Font', 'Size', 10);
Ini.Free;
end;
end;
procedure TfrmMain.FormClose(Sender: TObject; var CloseAction: TCloseAction);
var
Ini : TIniFile;
begin
Ini := TIniFile.Create('drafter.ini');
Ini.WriteInteger('Window', 'Top', frmMain.Top);
Ini.WriteInteger('Window', 'Left', frmMain.Left);
Ini.WriteInteger('Window', 'Height', frmMain.Height);
Ini.WriteInteger('Window', 'Width', frmMain.Width);
Ini.WriteString ('Font', 'Name', txtTweets.Font.Name);
Ini.WriteInteger('Font', 'Size', txtTweets.Font.Size);
Ini.Free;
end;
procedure TfrmMain.dlgFindFind(Sender: TObject);
var
k : integer;
begin
with Sender as TFindDialog do begin
k := Pos(FindText, txtTweets.Lines.Text);
if k > 0 then
begin
txtTweets.SelStart := k;
txtTweets.SelectWord;
txtTweets.SetFocus;
end else
Beep;
end;
end;
procedure TfrmMain.menuAboutClick(Sender: TObject);
begin
ShowMessage('Drafter v1.0' + #13#10#13#10 + 'Herramienta simple para creación de hilos en Twitter.' + #13#10 + 'License: Public Domain');
end;
procedure TfrmMain.menuCalculatorClick(Sender: TObject);
begin
dlgCalculator.Execute;
end;
procedure TfrmMain.menuCalendarClick(Sender: TObject);
begin
dlgCalendar.Execute;
end;
procedure TfrmMain.menuCopyClick(Sender: TObject);
begin
txtTweets.CopyToClipboard;
end;
procedure TfrmMain.menuCutClick(Sender: TObject);
begin
txtTweets.CutToClipboard;
end;
procedure TfrmMain.menuExitClick(Sender: TObject);
var
BoxStyle : integer;
Reply : integer;
begin
if not g_saved then
begin
BoxStyle := MB_ICONQUESTION + MB_YESNO;
Reply := Application.MessageBox('El archivo no ha sido guardado. ¿Quieres salir de todos modos?', 'MessageBoxDemo', BoxStyle);
if Reply <> IDYES then
begin
exit;
end;
end;
Application.Terminate;
end;
procedure TfrmMain.menuFontClick(Sender: TObject);
begin
if dlgFont.Execute then
begin
txtTweets.Font := dlgFont.Font;
end;
end;
procedure TfrmMain.menuOpenClick(Sender: TObject);
var
Reply : integer;
BoxStyle : integer;
begin
if not g_saved then
begin
BoxStyle := MB_ICONQUESTION + MB_YESNO;
Reply := Application.MessageBox('El archivo no ha sido guardado. ¿Quieres abrir otro archivo de todos modos?', 'MessageBoxDemo', BoxStyle);
if Reply <> IDYES then
begin
exit;
end;
end;
if dlgOpen.Execute then
begin
txtTweets.Lines.LoadFromFile( dlgOpen.FileName );
g_saved := true;
end;
end;
procedure TfrmMain.menuPasteClick(Sender: TObject);
begin
txtTweets.PasteFromClipboard;
end;
procedure TfrmMain.menuRedoClick(Sender: TObject);
begin
txtTweets.Redo;
end;
procedure TfrmMain.menuSaveClick(Sender: TObject);
begin
if dlgSave.Execute then
begin
txtTweets.lines.SaveToFile( dlgSave.FileName );
g_saved := true;
end;
end;
procedure TfrmMain.menuSearchClick(Sender: TObject);
begin
dlgFind.Execute;
end;
procedure TfrmMain.menuSelectAllClick(Sender: TObject);
begin
txtTweets.SelectAll;
end;
procedure TfrmMain.menuSelectLineClick(Sender: TObject);
begin
txtTweets.SelectLine();
end;
procedure TfrmMain.menuSelectWordClick(Sender: TObject);
begin
txtTweets.SelectWord;
end;
procedure TfrmMain.menuUndoClick(Sender: TObject);
begin
txtTweets.Undo;
end;
end.
| 23.358804 | 143 | 0.709572 |
c3180863b19987e90835150e27d491c0acb481df | 554 | dpr | Pascal | windows/src/ext/jedi/jvcl/tests/archive/jvcl/examples/DSADialogs/DSAExamples.dpr | bravogeorge/keyman | c0797e36292de903d7313214d1f765e3d9a2bf4d | [
"MIT"
]
| 219 | 2017-06-21T03:37:03.000Z | 2022-03-27T12:09:28.000Z | windows/src/ext/jedi/jvcl/tests/archive/jvcl/examples/DSADialogs/DSAExamples.dpr | bravogeorge/keyman | c0797e36292de903d7313214d1f765e3d9a2bf4d | [
"MIT"
]
| 4,451 | 2017-05-29T02:52:06.000Z | 2022-03-31T23:53:23.000Z | windows/src/ext/jedi/jvcl/tests/archive/jvcl/examples/DSADialogs/DSAExamples.dpr | bravogeorge/keyman | c0797e36292de903d7313214d1f765e3d9a2bf4d | [
"MIT"
]
| 72 | 2017-05-26T04:08:37.000Z | 2022-03-03T10:26:20.000Z | program DSAExamples;
uses
Forms,
DSAExamplesCustom1 in 'DSAExamplesCustom1.pas' {frmDSAExamplesCustomDlg1},
DSAExamplesCustom2 in 'DSAExamplesCustom2.pas' {frmDSAExamplesCustomDlg2},
DSAExamplesProgressDlg in 'DSAExamplesProgressDlg.pas' {frmDSAExamplesProgressDlg},
DSADialogsMainFormU in 'DSADialogsMainFormU.pas' {DSADialogsMainForm};
{$R *.RES}
begin
Application.Initialize;
Application.Title := 'Don''t Show Again (DSA) Examples and tests';
Application.CreateForm(TDSADialogsMainForm, DSADialogsMainForm);
Application.Run;
end.
| 30.777778 | 85 | 0.803249 |
fc1e46f2c75ba125b642496fbe05ef3e4258acfd | 1,083 | dfm | Pascal | Forms/Concepts.Spring.Interception.Form.dfm | jpluimers/Concepts | 78598ab6f1b4206bbc4ed9c7bc15705ad4ade1fe | [
"Apache-2.0"
]
| 2 | 2020-01-04T08:19:10.000Z | 2020-02-19T22:25:38.000Z | Forms/Concepts.Spring.Interception.Form.dfm | jpluimers/Concepts | 78598ab6f1b4206bbc4ed9c7bc15705ad4ade1fe | [
"Apache-2.0"
]
| null | null | null | Forms/Concepts.Spring.Interception.Form.dfm | jpluimers/Concepts | 78598ab6f1b4206bbc4ed9c7bc15705ad4ade1fe | [
"Apache-2.0"
]
| 1 | 2020-02-19T22:25:42.000Z | 2020-02-19T22:25:42.000Z | object frmSpringInterception: TfrmSpringInterception
Left = 0
Top = 0
Caption = 'Spring Interception'
ClientHeight = 94
ClientWidth = 257
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object btnStart: TButton
Left = 8
Top = 8
Width = 75
Height = 25
Action = actStart
TabOrder = 0
end
object btnStop: TButton
Left = 89
Top = 8
Width = 75
Height = 25
Action = actStop
TabOrder = 1
end
object btnMove: TButton
Left = 170
Top = 8
Width = 75
Height = 25
Action = actMove
TabOrder = 2
end
object aclMain: TActionList
Left = 64
Top = 48
object actStart: TAction
Caption = 'Start'
OnExecute = actStartExecute
end
object actStop: TAction
Caption = 'Stop'
OnExecute = actStopExecute
end
object actMove: TAction
Caption = 'Move'
OnExecute = actMoveExecute
end
end
end
| 19 | 52 | 0.627886 |
470a6f22be755d6d762870c8c66e71fd7197a9cd | 2,781 | pas | Pascal | Chapter09/Code/RECIPE05/TTS/MainMobileFormU.pas | PacktPublishing/DelphiCookbookThirdEdition | 760fd16277dd21a75320571c664553af33e29950 | [
"MIT"
]
| 51 | 2018-08-03T06:27:36.000Z | 2022-03-16T09:10:10.000Z | Chapter09/Code/RECIPE05/TTS/MainMobileFormU.pas | PacktPublishing/DelphiCookbookThirdEdition | 760fd16277dd21a75320571c664553af33e29950 | [
"MIT"
]
| 1 | 2019-10-28T16:51:11.000Z | 2019-10-28T16:51:11.000Z | Chapter09/Code/RECIPE05/TTS/MainMobileFormU.pas | PacktPublishing/DelphiCookbookThirdEdition | 760fd16277dd21a75320571c664553af33e29950 | [
"MIT"
]
| 28 | 2018-08-03T22:20:00.000Z | 2021-12-02T03:49:03.000Z | unit MainMobileFormU;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
Androidapi.JNI.TTS, FMX.StdCtrls, FMX.Layouts, FMX.Memo, Androidapi.JNIBridge,
IPPeerClient, IPPeerServer, IdBaseComponent, IdComponent, IdUDPBase,
IdUDPServer, IdGlobal, IdSocketHandle, TTSListenerU, FMX.Controls.Presentation;
type
TMainForm = class(TForm)
Timer1: TTimer;
IdUDPServer1: TIdUDPServer;
Label1: TLabel;
procedure Timer1Timer(Sender: TObject);
procedure IdUDPServer1UDPRead(AThread: TIdUDPListenerThread;
const AData: TIdBytes; ABinding: TIdSocketHandle);
private
{ Private declarations }
FTTSListener: TttsOnInitListener;
FTTS: JTextToSpeech;
procedure Speak(const AText: string);
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
end;
var
MainForm: TMainForm;
implementation
{$R *.fmx}
uses
Androidapi.JNI.JavaTypes, FMX.Helpers.Android, Androidapi.JNI.GraphicsContentViewText, Androidapi.Helpers;
constructor TMainForm.Create(AOwner: TComponent);
begin
inherited;
FTTSListener := TttsOnInitListener.Create(
procedure(AInitOK: boolean)
var
Res: Integer;
begin
if AInitOK then
begin
Res := FTTS.setLanguage(TJLocale.JavaClass.ENGLISH);
//Res := FTTS.setLanguage(TJLocale.JavaClass.ITALIAN);
//Res := FTTS.setLanguage(TJLocale.JavaClass.JAPANESE);
//Res := FTTS.setLanguage(TJLocale.JavaClass.GERMAN);
//Res := FTTS.setLanguage(TJLocale.JavaClass.FRENCH);
if (Res = TJTextToSpeech.JavaClass.LANG_MISSING_DATA) or
(Res = TJTextToSpeech.JavaClass.LANG_NOT_SUPPORTED) then
Label1.Text := 'Selected language is not supported'
else
begin
Label1.Text := 'READY To SPEAK!';
IdUDPServer1.Active := True;
end;
end
else
Label1.Text := 'Initialization Failed!';
end);
end;
destructor TMainForm.Destroy;
begin
if Assigned(FTTS) then
begin
FTTS.stop;
FTTS.shutdown;
FTTS := nil;
end;
FTTSListener := nil;
inherited;
end;
procedure TMainForm.IdUDPServer1UDPRead(AThread: TIdUDPListenerThread;
const AData: TIdBytes; ABinding: TIdSocketHandle);
var
bytes: TBytes;
begin
bytes := TBytes(AData);
Speak(TEncoding.ASCII.GetString(bytes));
end;
procedure TMainForm.Speak(const AText: string);
begin
FTTS.Speak(StringToJString(AText), TJTextToSpeech.JavaClass.QUEUE_FLUSH, nil);
end;
procedure TMainForm.Timer1Timer(Sender: TObject);
begin
Timer1.Enabled := False;
FTTS := TJTextToSpeech.JavaClass.init(TAndroidHelper.Context, FTTSListener);
end;
end.
| 26.485714 | 108 | 0.717008 |
fc739c1ad5f4df8d2f0d4e44ea9edea4f98f3c95 | 1,450 | pas | Pascal | Projects/UIStateForm.pas | winter-wh/issrc-is-5_4 | bebd906f45bcaa3e3a22944e2511c583ae3dfb13 | [
"FSFAP"
]
| null | null | null | Projects/UIStateForm.pas | winter-wh/issrc-is-5_4 | bebd906f45bcaa3e3a22944e2511c583ae3dfb13 | [
"FSFAP"
]
| 1 | 2019-01-12T22:44:23.000Z | 2019-01-12T22:44:23.000Z | Projects/UIStateForm.pas | winter-wh/issrc-is-5_4 | bebd906f45bcaa3e3a22944e2511c583ae3dfb13 | [
"FSFAP"
]
| null | null | null | unit UIStateForm;
{
Inno Setup
Copyright (C) 1997-2004 Jordan Russell
Portions by Martijn Laan
For conditions of distribution and use, see LICENSE.TXT.
TUIStateForm, a TForm descendant which correctly handles the hiding of
accelerator key characters and focus rectangles on Windows 2000 and later
when the "Hide keyboard navigation indicators" option is enabled.
$jrsoftware: issrc/Projects/UIStateForm.pas,v 1.2 2004/06/26 04:36:08 jr Exp $
}
interface
uses
Windows, SysUtils, Messages, Classes, Graphics, Controls, Forms, Dialogs;
type
TUIStateForm = class(TForm)
private
procedure CMDialogKey(var Message: TCMDialogKey); message CM_DIALOGKEY;
procedure CMShowingChanged(var Message: TMessage); message CM_SHOWINGCHANGED;
end;
implementation
const
WM_CHANGEUISTATE = $0127;
UIS_SET = 1;
UIS_CLEAR = 2;
UIS_INITIALIZE = 3;
UISF_HIDEFOCUS = $1;
UISF_HIDEACCEL = $2;
procedure TUIStateForm.CMShowingChanged(var Message: TMessage);
begin
if Showing then
SendMessage(Handle, WM_CHANGEUISTATE, UIS_INITIALIZE, 0);
inherited;
end;
procedure TUIStateForm.CMDialogKey(var Message: TCMDialogKey);
begin
case Message.CharCode of
VK_LEFT..VK_DOWN, VK_TAB:
SendMessage(Handle, WM_CHANGEUISTATE, UIS_CLEAR or (UISF_HIDEFOCUS shl 16), 0);
VK_MENU:
SendMessage(Handle, WM_CHANGEUISTATE, UIS_CLEAR or ((UISF_HIDEFOCUS or UISF_HIDEACCEL) shl 16), 0);
end;
inherited;
end;
end.
| 25.438596 | 105 | 0.756552 |
47d0b8e9c6cd52a7eee9d3812000fb7f21b2d690 | 277 | dpr | Pascal | testoutlook.dpr | geoffsmith82/ReadEmailSettings | 0f47334821e6ab4cda396398e0696eecd43b28ff | [
"MIT"
]
| null | null | null | testoutlook.dpr | geoffsmith82/ReadEmailSettings | 0f47334821e6ab4cda396398e0696eecd43b28ff | [
"MIT"
]
| null | null | null | testoutlook.dpr | geoffsmith82/ReadEmailSettings | 0f47334821e6ab4cda396398e0696eecd43b28ff | [
"MIT"
]
| null | null | null | program testoutlook;
uses
Forms,
frmtestoutlook in 'frmtestoutlook.pas' {Form2},
EmailSettings in 'EmailSettings.pas';
{$R *.res}
begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TForm2, Form2);
Application.Run;
end.
| 17.3125 | 49 | 0.747292 |
fc92940a1803e0d13d3afe438a5c1bd7b9f76cd6 | 1,043 | pas | Pascal | HODLER_Multiplatform_Win_And_iOS_Linux/additionalUnits/CryptoLib/src/Base/HlpKDF.pas | devilking6105/HODLER-Open-Source-Multi-Asset-Wallet | 2554bce0ad3e3e08e4617787acf93176243ce758 | [
"Unlicense"
]
| 35 | 2018-11-04T12:02:34.000Z | 2022-02-15T06:00:19.000Z | HODLER_Multiplatform_Win_And_iOS_Linux/additionalUnits/CryptoLib/src/Base/HlpKDF.pas | Ecoent/HODLER-Open-Source-Multi-Asset-Wallet | a8c54ecfc569d0ee959b6f0e7826c4ee4b5c4848 | [
"Unlicense"
]
| 85 | 2018-10-23T17:09:20.000Z | 2022-01-12T07:12:54.000Z | HODLER_Multiplatform_Win_And_iOS_Linux/additionalUnits/CryptoLib/src/Base/HlpKDF.pas | Ecoent/HODLER-Open-Source-Multi-Asset-Wallet | a8c54ecfc569d0ee959b6f0e7826c4ee4b5c4848 | [
"Unlicense"
]
| 34 | 2018-10-30T00:40:37.000Z | 2022-02-15T06:00:15.000Z | unit HlpKDF;
{$I ..\Include\HashLib.inc}
interface
uses
HlpIKDF,
HlpHashLibTypes;
type
TKDF = class abstract(TInterfacedObject, IKDF)
strict protected
// Not really needed because there is an Intristic default constructor always
// called for classes if none is defined by the developer but I just put it
// for readability reasons.
constructor Create();
public
/// <summary>
/// Returns the pseudo-random bytes for this object.
/// </summary>
/// <param name="bc">The number of pseudo-random key bytes to generate.</param>
/// <returns>A byte array filled with pseudo-random key bytes.</returns>
/// <exception cref="EArgumentOutOfRangeHashLibException">bc must be greater than zero.</exception>
/// <exception cref="EArgumentHashLibException">invalid start index or end index of internal buffer.</exception>
function GetBytes(bc: Int32): THashLibByteArray; virtual; abstract;
end;
implementation
{ TKDF }
constructor TKDF.Create;
begin
Inherited Create();
end;
end.
| 23.704545 | 116 | 0.713327 |
fc0576ad829859c8f58cbff25d383d5f17a995cc | 8,244 | pas | Pascal | Ext/VCLStyleUtils/Common/Vcl.Styles.OwnerDrawFix.pas | atkins126/VCLThemeSelector | 3d0ba05c9199c8cf182b32bbaa300a5d70962102 | [
"Apache-2.0"
]
| 63 | 2021-02-05T15:47:56.000Z | 2022-03-09T11:36:39.000Z | Ext/VCLStyleUtils/Common/Vcl.Styles.OwnerDrawFix.pas | atkins126/VCLThemeSelector | 3d0ba05c9199c8cf182b32bbaa300a5d70962102 | [
"Apache-2.0"
]
| 13 | 2021-02-11T08:39:38.000Z | 2022-03-28T22:48:09.000Z | Ext/VCLStyleUtils/Common/Vcl.Styles.OwnerDrawFix.pas | atkins126/VCLThemeSelector | 3d0ba05c9199c8cf182b32bbaa300a5d70962102 | [
"Apache-2.0"
]
| 5 | 2021-02-12T15:35:55.000Z | 2021-07-11T02:34:40.000Z | // **************************************************************************************************
//
// Unit Vcl.Styles.OwnerDrawFix
// unit for the VCL Styles Utils
// https://github.com/RRUZ/vcl-styles-utils/
//
// 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 Vcl.Styles.OwnerDrawFix.pas.
//
// The Initial Developer of the Original Code is Rodrigo Ruz V.
// Portions created by Rodrigo Ruz V. are Copyright (C) 2012-2021 Rodrigo Ruz V.
// All Rights Reserved.
//
// **************************************************************************************************
unit Vcl.Styles.OwnerDrawFix;
interface
uses
Winapi.Windows,
Winapi.CommCtrl,
Vcl.ComCtrls,
Vcl.Graphics,
Vcl.StdCtrls,
Vcl.Controls,
Vcl.Styles,
Vcl.Themes,
System.Classes;
type
TVclStylesOwnerDrawFix = class
public
procedure ComboBoxDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
procedure ListBoxDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
procedure ListViewDrawItem(Sender: TCustomListView; Item: TListItem; Rect: TRect; State: TOwnerDrawState);
procedure ListViewMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
end deprecated 'Use the Vcl.Styles.Hooks unit Instead';
{$WARN SYMBOL_DEPRECATED OFF}
var
VclStylesOwnerDrawFix: TVclStylesOwnerDrawFix;
implementation
uses
System.SysUtils;
type
TCustomListViewClass = class(TCustomListView);
{ TVclStylesOwnerDrawFix }
procedure TVclStylesOwnerDrawFix.ComboBoxDrawItem(Control: TWinControl; Index: Integer; Rect: TRect;
State: TOwnerDrawState);
const
ColorStates: array [Boolean] of TStyleColor = (scComboBoxDisabled, scComboBox);
FontColorStates: array [Boolean] of TStyleFont = (sfComboBoxItemDisabled, sfComboBoxItemNormal);
var
LStyles: TCustomStyleServices;
begin
LStyles := StyleServices;
with Control as TComboBox do
begin
Canvas.Brush.Color := LStyles.GetStyleColor(ColorStates[Control.Enabled]);
Canvas.Font.Color := LStyles.GetStyleFontColor(FontColorStates[Control.Enabled]);
if odSelected in State then
begin
Canvas.Brush.Color := LStyles.GetSystemColor(clHighlight);
Canvas.Font.Color := LStyles.GetSystemColor(clHighlightText);
end;
Canvas.FillRect(Rect);
Canvas.TextOut(Rect.Left + 2, Rect.Top, Items[Index]);
end;
end;
procedure TVclStylesOwnerDrawFix.ListBoxDrawItem(Control: TWinControl; Index: Integer; Rect: TRect;
State: TOwnerDrawState);
Var
LListBox: TListBox;
LStyles: TCustomStyleServices;
LDetails: TThemedElementDetails;
begin
LListBox := TListBox(Control);
LStyles := StyleServices;
if odSelected in State then
LListBox.Brush.Color := LStyles.GetSystemColor(clHighlight);
LDetails := StyleServices.GetElementDetails(tlListItemNormal);
LListBox.Canvas.FillRect(Rect);
Rect.Left := Rect.Left + 2;
LStyles.DrawText(LListBox.Canvas.Handle, LDetails, LListBox.Items[Index], Rect,
[tfLeft, tfSingleLine, tfVerticalCenter]);
if odFocused In State then
begin
LListBox.Canvas.Brush.Color := LStyles.GetSystemColor(clHighlight);
LListBox.Canvas.DrawFocusRect(Rect);
end;
end;
procedure TVclStylesOwnerDrawFix.ListViewDrawItem(Sender: TCustomListView; Item: TListItem; Rect: TRect;
State: TOwnerDrawState);
const
Spacing = 4;
var
Dx: Integer;
r: TRect;
rc: TRect;
ColIdx: Integer;
s: string;
LDetails: TThemedElementDetails;
LStyles: TCustomStyleServices;
BoxSize: TSize;
LColor: TColor;
ImageSize: Integer;
begin
LStyles := StyleServices;
if not LStyles.GetElementColor(LStyles.GetElementDetails(ttItemNormal), ecTextColor, LColor) or (LColor = clNone) then
LColor := LStyles.GetSystemColor(clWindowText);
Sender.Canvas.Brush.Color := LStyles.GetStyleColor(scListView);
Sender.Canvas.Font.Color := LColor;
Sender.Canvas.FillRect(Rect);
r := Rect;
inc(r.Left, Spacing);
for ColIdx := 0 to TListView(Sender).Columns.Count - 1 do
begin
Dx := 0;
r.Right := r.Left + Sender.Column[ColIdx].Width;
if (ColIdx > 0) and (Item.SubItems.Count >= ColIdx) then
s := Item.SubItems[ColIdx - 1]
else
begin
BoxSize.cx := GetSystemMetrics(SM_CXMENUCHECK);
BoxSize.cy := GetSystemMetrics(SM_CYMENUCHECK);
s := Item.Caption;
if TListView(Sender).Checkboxes then
begin
inc(Dx, BoxSize.cx + 3);
r.Left := r.Left + BoxSize.cx + 3;
end;
end;
if ColIdx = 0 then
begin
if not IsWindowVisible(ListView_GetEditControl(Sender.Handle)) and ([odSelected, odHotLight] * State <> []) then
begin
if ([odSelected, odHotLight] * State <> []) then
begin
rc := Rect;
if TListView(Sender).Checkboxes then
rc.Left := rc.Left + BoxSize.cx + Spacing;
if not TListView(Sender).RowSelect then
rc.Right := Sender.Column[0].Width;
Sender.Canvas.Brush.Color := LStyles.GetSystemColor(clHighlight);
Sender.Canvas.FillRect(rc);
end;
end;
end;
if TListView(Sender).RowSelect then
Sender.Canvas.Brush.Color := LStyles.GetSystemColor(clHighlight);
if (ColIdx = 0) and (TCustomListViewClass(Sender).SmallImages <> nil) and
(TCustomListViewClass(Sender).SmallImages.Handle <> 0) and (Item.ImageIndex >= 0) then
begin
ImageList_Draw(TCustomListViewClass(Sender).SmallImages.Handle, Item.ImageIndex, Sender.Canvas.Handle, r.Left - 2,
r.Top, ILD_NORMAL);
ImageSize := TCustomListViewClass(Sender).SmallImages.Width;
inc(Dx, ImageSize);
r.Left := r.Left + ImageSize;
end;
if ([odSelected, odHotLight] * State <> []) then
LDetails := StyleServices.GetElementDetails(tlListItemSelected)
else
LDetails := StyleServices.GetElementDetails(tlListItemNormal);
Sender.Canvas.Brush.Style := bsClear;
LStyles.DrawText(Sender.Canvas.Handle, LDetails, s, r, [tfLeft, tfSingleLine, tfVerticalCenter, tfEndEllipsis]);
if (ColIdx = 0) and TListView(Sender).Checkboxes then
begin
rc := Rect;
rc.Top := Rect.Top + (Rect.Bottom - Rect.Top - BoxSize.cy) div 2;
rc.Bottom := rc.Top + BoxSize.cy;
rc.Left := rc.Left + Spacing;
rc.Right := rc.Left + BoxSize.cx;
if Item.Checked then
LDetails := StyleServices.GetElementDetails(tbCheckBoxCheckedNormal)
else
LDetails := StyleServices.GetElementDetails(tbCheckBoxUncheckedNormal);
LStyles.DrawElement(Sender.Canvas.Handle, LDetails, rc);
end;
if ColIdx = 0 then
r.Left := r.Left - Dx;
{ else }
inc(r.Left, Sender.Column[ColIdx].Width);
end;
end;
procedure TVclStylesOwnerDrawFix.ListViewMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState;
X, Y: Integer);
const
Spacing = 4;
var
LDetails: TThemedElementDetails;
Size: TSize;
begin
if TListView(Sender).OwnerDraw and (TListView(Sender).Checkboxes) then
begin
LDetails := StyleServices.GetElementDetails(tbCheckBoxCheckedNormal);
Size.cx := 0;
Size.cy := 0;
if StyleServices.GetElementSize(TListView(Sender).Canvas.Handle, LDetails, esMinimum, Size) and (X > Spacing) and
(X <= Size.Width) then
TListView(Sender).Selected.Checked := not TListView(Sender).Selected.Checked;
// OutputDebugString(PChar(Format('X %d Size.Width %d',[X, Size.Width])));
end;
end;
initialization
VclStylesOwnerDrawFix := TVclStylesOwnerDrawFix.Create;
finalization
VclStylesOwnerDrawFix.Free;
end.
| 32.714286 | 121 | 0.673581 |
85ec188b173e047f3cf4901b6c0304941b8a75d0 | 5,579 | dfm | Pascal | Client/fUserMemberGroups.dfm | Sembium/Sembium3 | 0179c38c6a217f71016f18f8a419edd147294b73 | [
"Apache-2.0"
]
| null | null | null | Client/fUserMemberGroups.dfm | Sembium/Sembium3 | 0179c38c6a217f71016f18f8a419edd147294b73 | [
"Apache-2.0"
]
| null | null | null | Client/fUserMemberGroups.dfm | Sembium/Sembium3 | 0179c38c6a217f71016f18f8a419edd147294b73 | [
"Apache-2.0"
]
| 3 | 2021-06-30T10:11:17.000Z | 2021-07-01T09:13:29.000Z | inherited fmUserMemberGroups: TfmUserMemberGroups
Caption = #1043#1088#1091#1087#1080' '#1085#1072' '#1055#1086#1090#1088#1077#1073#1080#1090#1077#1083
ClientHeight = 450
ClientWidth = 708
PixelsPerInch = 96
TextHeight = 13
inherited pnlBottomButtons: TPanel
Top = 415
Width = 708
inherited pnlOKCancel: TPanel
Left = 440
end
inherited pnlClose: TPanel
Left = 351
end
inherited pnlApply: TPanel
Left = 619
Visible = False
end
end
inherited pnlUser: TPanel
Width = 692
end
inherited pnlMain: TPanel
Width = 708
Height = 415
inherited pnlGrid: TPanel
Width = 692
Height = 399
inherited pnlNavigator: TPanel
Width = 692
inherited navData: TDBColorNavigator
Hints.Strings = ()
end
end
inherited grdData: TAbmesDBGrid
Top = 59
Width = 333
Height = 340
TitleParams.MultiTitle = True
TitleParams.VTitleMargin = 5
Columns = <
item
CellButtons = <>
DynProps = <>
EditButtons = <>
FieldName = 'USER_GROUP_CODE'
Footers = <>
Title.Caption = #1063#1083#1077#1085' '#1085#1072'|'#1050#1086#1076
end
item
CellButtons = <>
DynProps = <>
EditButtons = <>
FieldName = 'USER_GROUP_NAME'
Footers = <>
Title.Caption = #1063#1083#1077#1085' '#1085#1072'|'#1053#1072#1080#1084#1077#1085#1086#1074#1072#1085#1080#1077
Width = 235
end>
end
inherited grdOtherData: TAbmesDBGrid
Left = 359
Top = 59
Width = 333
Height = 340
TitleParams.MultiTitle = True
TitleParams.VTitleMargin = 5
Columns = <
item
CellButtons = <>
DynProps = <>
EditButtons = <>
FieldName = 'USER_GROUP_CODE'
Footers = <>
Title.Caption = #1053#1045' '#1077' '#1095#1083#1077#1085' '#1085#1072'|'#1050#1086#1076
end
item
CellButtons = <>
DynProps = <>
EditButtons = <>
FieldName = 'USER_GROUP_NAME'
Footers = <>
Title.Caption = #1053#1045' '#1077' '#1095#1083#1077#1085' '#1085#1072'|'#1053#1072#1080#1084#1077#1085#1086#1074#1072#1085#1080#1077
Width = 235
end>
end
inherited pnlMoveButtons: TPanel
Left = 333
Top = 59
Height = 340
end
object pnlInfo: TPanel
Left = 0
Top = 24
Width = 692
Height = 35
Align = alTop
BevelOuter = bvNone
TabOrder = 4
object pnlUserInfo: TPanel
Left = 0
Top = 0
Width = 692
Height = 29
Align = alTop
TabOrder = 0
object lblUser: TLabel
Left = 8
Top = 8
Width = 60
Height = 13
Caption = #1055#1086#1090#1088#1077#1073#1080#1090#1077#1083
end
object edtUser: TDBEdit
Left = 73
Top = 4
Width = 278
Height = 21
Color = clBtnFace
DataField = 'EMPLOYEE_NAME'
DataSource = dsData
ReadOnly = True
TabOrder = 0
end
end
end
end
end
inherited cdsGridData: TAbmesClientDataSet
ConnectionBroker = dmMain.conCompany
FieldDefs = <
item
Name = 'EMPLOYEE_CODE'
DataType = ftFloat
end
item
Name = 'USER_GROUP_CODE'
DataType = ftFloat
end
item
Name = 'USER_GROUP_NAME'
DataType = ftWideString
Size = 50
end>
Params = <
item
DataType = ftFloat
Name = 'EMPLOYEE_CODE'
ParamType = ptInput
Size = 8
end>
ProviderName = 'prvUserMemberGroups'
object cdsGridDataEMPLOYEE_CODE: TAbmesFloatField
FieldName = 'EMPLOYEE_CODE'
end
object cdsGridDataUSER_GROUP_CODE: TAbmesFloatField
FieldName = 'USER_GROUP_CODE'
end
object cdsGridDataUSER_GROUP_NAME: TAbmesWideStringField
FieldName = 'USER_GROUP_NAME'
Size = 50
end
end
inherited alActions: TActionList
inherited actForm: TAction
Caption = #1043#1088#1091#1087#1080' '#1085#1072' '#1055#1086#1090#1088#1077#1073#1080#1090#1077#1083
end
end
inherited pdsGridDataParams: TParamDataSet
object pdsGridDataParamsEMPLOYEE_CODE: TAbmesFloatField
FieldName = 'EMPLOYEE_CODE'
end
end
inherited cdsOtherGridData: TAbmesClientDataSet
ConnectionBroker = dmMain.conCompany
Params = <
item
DataType = ftFloat
Name = 'EMPLOYEE_CODE'
ParamType = ptInput
end
item
DataType = ftFloat
Name = 'EMPLOYEE_CODE'
ParamType = ptInput
end>
ProviderName = 'prvUserNotMemberGroups'
object cdsOtherGridDataEMPLOYEE_CODE: TAbmesFloatField
FieldName = 'EMPLOYEE_CODE'
end
object cdsOtherGridDataUSER_GROUP_CODE: TAbmesFloatField
FieldName = 'USER_GROUP_CODE'
end
object cdsOtherGridDataUSER_GROUP_NAME: TAbmesWideStringField
FieldName = 'USER_GROUP_NAME'
Size = 50
end
end
end
| 27.895 | 146 | 0.545617 |
475347343930cdc0c4372546daa5bcd606efdfb8 | 3,467 | pas | Pascal | Unit1.pas | matheusd/DelphiProfileInit | 95f8511b4982c586c0f4e5db515cab92a4ed3dd1 | [
"Unlicense"
]
| null | null | null | Unit1.pas | matheusd/DelphiProfileInit | 95f8511b4982c586c0f4e5db515cab92a4ed3dd1 | [
"Unlicense"
]
| null | null | null | Unit1.pas | matheusd/DelphiProfileInit | 95f8511b4982c586c0f4e5db515cab92a4ed3dd1 | [
"Unlicense"
]
| null | null | null | unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, filectrl;
type
TForm1 = class(TForm)
Button1: TButton;
ListBox1: TListBox;
Button2: TButton;
edtDir: TEdit;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
const
NOME_UNIT_PERF = 'unPerfCounter';
procedure DirList(ASource: string; ADirList: TStringList);
var
SearchRec: TSearchRec;
Result: integer;
begin
Result := FindFirst(ASource + '*.*', faAnyFile or faDirectory, SearchRec);
if Result = 0 then
while (Result = 0) do
begin
if (SearchRec.Name = '.') or (SearchRec.name = '..') then begin
Result := FindNext(SearchRec);
continue;
end;
if (SearchRec.Attr and faDirectory) = faDirectory then DirList(aSource + SearchRec.name + '\', ADirList);
if (ExtractFileExt(searchRec.name) = '.pas') then
begin
ADirList.Add(ASource + SearchRec.Name);
end;
Result := FindNext(SearchRec);
end;
//FindClose( SearchRec );
ADirList.Sort;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
arqs: TStringList;
dir: string;
begin
arqs:= TStringList.create;
dir:= edtDir.Text;
if dir[length(dir)] <> '\' then dir:= dir + '\';
DirList( dir, arqs);
ListBox1.Items.Assign(arqs);
arqs.free;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
i, lin: integer;
arq: TStringList;
gotUses, gotInit: boolean;
s, up, tr: string;
initLine, intfLine, finLine: integer;
begin
arq:= TStringList.Create;
for i := 0 to ListBox1.Items.count - 1 do begin
listBox1.ItemIndex:= i;
application.ProcessMessages;
arq.LoadFromFile(ListBox1.Items[i]);
gotUses:= false;
gotInit:= false;
initLine:= -1;
intfLine:= -1;
for lin := 0 to arq.Count - 1 do begin
up:= UpperCase(arq[lin]);
tr:= Trim(up);
if not gotUses and
( (Pos('USES ', up) > 0) or
(tr = 'USES') ) then
begin
s:= StringReplace(arq[lin], 'uses', 'uses ' + NOME_UNIT_PERF + ', ', [rfIgnoreCase]);
gotUses:= true;
arq[lin]:= s;
end;
if tr = 'INITIALIZATION' then begin
initLine:= lin;
gotInit:= true;
end;
if tr = 'INTERFACE' then
intfLine:= lin;
if (tr = 'END.') or
(tr = 'FINALIZATION') then
begin
finLine:= lin;
if not gotUses then begin
arq.Insert(intfLine+1, 'uses ' + NOME_UNIT_PERF + ';');
end;
if not gotInit then begin
arq.Insert(lin, 'initialization');
finLine:= lin + 1;
end else begin
arq.Insert(initLine+1,
' masterPerf.currentToConsole(''' +
ExtractFileName(listbox1.items[i] +
' start init'');'));
finLine:= finLine + 1;
end;
arq.Insert(finLine,
' masterPerf.currentToConsole(''' +
ExtractFileName(listbox1.items[i] +
' initialized'');'));
break;
end;
end;
arq.SaveToFile(ListBox1.Items[i]);
//break; //<---- aqui
end;
arq.free;
end;
end.
| 22.367742 | 112 | 0.567638 |
83d3e993e16c139a08f8e4e3cfbdb1019c6bb623 | 4,681 | pas | Pascal | dependencies/Indy10/Protocols/IdIdentServer.pas | danka74/fhirserver | 1fc53b6fba67a54be6bee39159d3db28d42eb8e2 | [
"BSD-3-Clause"
]
| 1 | 2022-02-28T11:28:18.000Z | 2022-02-28T11:28:18.000Z | dependencies/Indy10/Protocols/IdIdentServer.pas | danka74/fhirserver | 1fc53b6fba67a54be6bee39159d3db28d42eb8e2 | [
"BSD-3-Clause"
]
| null | null | null | dependencies/Indy10/Protocols/IdIdentServer.pas | danka74/fhirserver | 1fc53b6fba67a54be6bee39159d3db28d42eb8e2 | [
"BSD-3-Clause"
]
| null | null | null | {
$Project$
$Workfile$
$Revision$
$DateUTC$
$Id$
This file is part of the Indy (Internet Direct) project, and is offered
under the dual-licensing agreement described on the Indy website.
(http://www.indyproject.org/)
Copyright:
(c) 1993-2005, Chad Z. Hower and the Indy Pit Crew. All rights reserved.
}
{
$Log$
}
{
Rev 1.8 12/2/2004 4:23:54 PM JPMugaas
Adjusted for changes in Core.
Rev 1.7 2004.02.03 5:43:48 PM czhower
Name changes
Rev 1.6 1/21/2004 3:10:38 PM JPMugaas
InitComponent
Rev 1.5 3/27/2003 3:42:02 PM BGooijen
Changed because some properties are moved to IOHandler
Rev 1.4 2/24/2003 09:00:38 PM JPMugaas
Rev 1.3 1/17/2003 07:10:32 PM JPMugaas
Now compiles under new framework.
Rev 1.2 1-1-2003 20:13:20 BGooijen
Changed to support the new TIdContext class
Rev 1.1 12/6/2002 04:35:16 PM JPMugaas
Now compiles with new code.
Rev 1.0 11/13/2002 07:54:44 AM JPMugaas
2001 - Feb 11 - J. Peter Mugaas
Started this component.
}
unit IdIdentServer;
{
This is based on RFC 1413 - Identification Protocol
Note that the default port is assigned to IdPORT_AUTH
The reason for this is that the RFC specifies port 113 and the old protocol
name was Authentication Server Protocol. This was renamed Ident to better
reflect what it does.
}
interface
{$i IdCompilerDefines.inc}
uses
IdAssignedNumbers, IdContext, IdCustomTCPServer, IdGlobal;
const
IdDefIdentQueryTimeOut = 60000; // 1 minute
type
TIdIdentQueryEvent = procedure (AContext:TIdContext; AServerPort, AClientPort : TIdPort) of object;
TIdIdentErrorType = (ieInvalidPort, ieNoUser, ieHiddenUser, ieUnknownError);
TIdIdentServer = class(TIdCustomTCPServer)
protected
FOnIdentQuery : TIdIdentQueryEvent;
FQueryTimeOut : Integer;
function DoExecute(AContext:TIdContext): boolean; override;
procedure InitComponent; override;
public
Procedure ReplyError(AContext:TIdContext; AServerPort, AClientPort : TIdPort; AErr : TIdIdentErrorType);
Procedure ReplyIdent(AContext:TIdContext; AServerPort, AClientPort : TIdPort; AOS, AUserName : String; const ACharset : String = ''); {Do not Localize}
Procedure ReplyOther(AContext:TIdContext; AServerPort, AClientPort : TIdPort; AOther : String);
published
property QueryTimeOut : Integer read FQueryTimeOut write FQueryTimeOut default IdDefIdentQueryTimeOut;
Property OnIdentQuery : TIdIdentQueryEvent read FOnIdentQuery write FOnIdentQuery;
Property DefaultPort default IdPORT_AUTH;
end;
implementation
uses
SysUtils;
{ TIdIdentServer }
procedure TIdIdentServer.InitComponent;
begin
inherited;
DefaultPort := IdPORT_AUTH;
FQueryTimeOut := IdDefIdentQueryTimeOut;
end;
function TIdIdentServer.DoExecute(AContext:TIdContext): Boolean;
var
s : String;
ServerPort, ClientPort : TIdPort;
begin
Result := True;
s := AContext.Connection.IOHandler.ReadLn('', FQueryTimeOut); {Do not Localize}
if not AContext.Connection.IOHandler.ReadLnTimedOut then begin
ServerPort := IndyStrToInt(Fetch(s,',')); {Do not Localize}
ClientPort := IndyStrToInt(s);
if Assigned(FOnIdentQuery) then begin
FOnIdentQuery(AContext, ServerPort, ClientPort);
Exit;
end;
ReplyError(AContext, ServerPort, ClientPort, ieUnknownError);
end;
AContext.Connection.Disconnect;
end;
procedure TIdIdentServer.ReplyError(AContext:TIdContext; AServerPort,
AClientPort: TIdPort; AErr : TIdIdentErrorType);
var s : String;
begin
s := IntToStr(AServerPort)+', '+IntToStr(AClientPort) + ' : ERROR : '; {Do not Localize}
case AErr of
ieInvalidPort : s := s + 'INVALID-PORT'; {Do not Localize}
ieNoUser : s := s + 'NO-USER'; {Do not Localize}
ieHiddenUser : s := s + 'HIDDEN-USER'; {Do not Localize}
ieUnknownError : s := s + 'UNKNOWN-ERROR'; {Do not Localize}
end;
AContext.Connection.IOHandler.WriteLn(s);
end;
procedure TIdIdentServer.ReplyIdent(AContext:TIdContext; AServerPort,
AClientPort: TIdPort; AOS, AUserName: String; const ACharset: String);
var s : String;
begin
s := IntToStr(AServerPort)+', '+IntToStr(AClientPort) + ' : USERID : '; {Do not Localize}
s := s + AOS;
if Length(ACharset) > 0 then
s := s + ','+ACharset; {Do not Localize}
s := s + ' : '+AUserName; {Do not Localize}
AContext.Connection.IOHandler.WriteLn(s);
end;
procedure TIdIdentServer.ReplyOther(AContext:TIdContext; AServerPort,
AClientPort: TIdPort; AOther: String);
begin
AContext.Connection.IOHandler.WriteLn(IntToStr(AServerPort)+', '+IntToStr(AClientPort) + ' : USERID : OTHER : '+AOther); {Do not Localize}
end;
end.
| 30.2 | 158 | 0.720359 |
47a4301301908619e4877d7eacbb8574bee31952 | 22,123 | pas | Pascal | Source/ICS/icsv8/Z.OverbyteIcsHttpContCod.pas | PassByYou888/ZNet | 8f5439ec275ee4eb5d68e00c33675e6117379fcf | [
"BSD-3-Clause"
]
| 24 | 2022-01-20T13:59:38.000Z | 2022-03-25T01:11:43.000Z | Source/ICS/icsv8/Z.OverbyteIcsHttpContCod.pas | lovong/ZNet | ad67382654ea1979c316c2dc9716fd6d8509f028 | [
"BSD-3-Clause"
]
| null | null | null | Source/ICS/icsv8/Z.OverbyteIcsHttpContCod.pas | lovong/ZNet | ad67382654ea1979c316c2dc9716fd6d8509f028 | [
"BSD-3-Clause"
]
| 5 | 2022-01-20T14:44:24.000Z | 2022-02-13T10:07:38.000Z | {*_* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Author: Maurizio Lotauro <Lotauro.Maurizio@dnet.it>
Code donated to the ICS project
Creation: July 2005
Version: 8.01
Description: This unit contains the class used by THttpCli to handle the
Accept-Encoding and Content-Encoding header fields.
It also contains the THttpContentCoding class needed to implement
a class able to handle a specific encoding.
How to create a class to handle a specific encoding
- define in a separate unit a class inherited from THttpContentCoding
- if the class name start with THttpContentCoding followed by the coding
identifier (for example THttpContentCodingGzip) then that part is taken
automatically as coding identifier. Otherwise you must override the
GetCoding method. This must return the name of the coding.
- most probably you must override the Create constructor to initialize
the structure to handle the decoding process.
Remember to call the inherited.
The same for Destroy.
- override the WriteBuffer method. This will called right before the
THttpCli.TriggerDocData. The parameters are the same.
There you could do two different think. If it is possible to decode on the
fly then call OutputWriteBuffer passing the decoded data. Otherwise store
the data somewhere to decode the whole at the end.
- if there is not possible to decode on the fly then you must override the
Complete method. This will called right before the THttpCli.TriggerDocEnd.
Like for WriteBuffer there you must call OutputWriteBuffer.
- add an inizialization section where you call
THttpContCodHandler.RegisterContentCoding
The first parameter is the default quality (greater than 0 and less or equal
than 1) and the second is the class.
To use it the unit must be added to the uses clause of one unit of the project
History
Jan 08, 2006 V1.01 Maurizio fixed GetCoding
Francois Piette reformated the code to fit the ICS rules,
added compilation directives.
Mar 26, 2006 V6.00 New version 6 started
May 2012 - V8.00 - Arno added FireMonkey cross platform support with POSIX/MacOS
also IPv6 support, include files now in sub-directory
Oct 8, 2012, V8.01 may be more than one encoding type specified, parse them
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
unit Z.OverbyteIcsHttpContCod;
interface
{$B-} { Enable partial boolean evaluation }
{$T-} { Untyped pointers }
{$X+} { Enable extended syntax }
{$I Include\Z.OverbyteIcsDefs.inc}
{$IFDEF COMPILER14_UP}
{$IFDEF NO_EXTENDED_RTTI}
{$RTTI EXPLICIT METHODS([]) FIELDS([]) PROPERTIES([])}
{$ENDIF}
{$ENDIF}
{$IFDEF DELPHI6_UP}
{$WARN SYMBOL_PLATFORM OFF}
{$WARN SYMBOL_LIBRARY OFF}
{$WARN SYMBOL_DEPRECATED OFF}
{$ENDIF}
{$IFDEF COMPILER2_UP} { Not for Delphi 1 }
{$H+} { Use long strings }
{$J+} { Allow typed constant to be modified }
{$ENDIF}
{$IFDEF BCB3_UP}
{$ObjExportAll On}
{$ENDIF}
uses
{$IFDEF RTL_NAMESPACES}System.Classes{$ELSE}Classes{$ENDIF},
{$IFDEF RTL_NAMESPACES}System.SysUtils{$ELSE}SysUtils{$ENDIF};
type
EHttpContentCodingException = class(Exception);
PStream = ^TStream;
TWriteBufferProcedure = procedure(Buffer: Pointer; Count: Integer) of object;
THttpContentCodingClass = class of THttpContentCoding;
THttpContentCoding = class(TObject)
private
FOutputWriteBuffer: TWriteBufferProcedure;
protected
class function GetActive: Boolean; virtual;
function PropGetActive: Boolean;
class function GetCoding: String; virtual;
function PropGetCoding: String;
property OutputWriteBuffer: TWriteBufferProcedure read FOutputWriteBuffer;
public
constructor Create(WriteBufferProc: TWriteBufferProcedure); virtual;
procedure Complete; virtual;
procedure WriteBuffer(Buffer: Pointer; Count: Integer); virtual; abstract;
property Active: Boolean read PropGetActive;
property Coding: String read PropGetCoding;
end;
THttpCCodIdentity = class(THttpContentCoding)
protected
class function GetCoding: String; override;
end;
THttpCCodStar = class(THttpContentCoding)
protected
class function GetCoding: String; override;
end;
THttpContCodItem = class(TObject)
private
FCodingClass: THttpContentCodingClass;
FEnabled : Boolean;
FQuality : Single;
function GetCoding: String;
function GetEnabled: Boolean;
public
constructor Create(const ACodingClass : THttpContentCodingClass;
const AQuality : Single);
property Coding: String read GetCoding;
property Enabled: Boolean read GetEnabled
write FEnabled;
property Quality: Single read FQuality
write FQuality;
end;
THttpContCodHandler = class(TObject)
private
FCodingList : TList;
FCodingParams : TList;
FOutputStream : PStream;
FInputWriteBuffer : TWriteBufferProcedure;
FOutputWriteBuffer : TWriteBufferProcedure;
FHeaderText : String;
FRecalcHeader : Boolean;
FEnabled : Boolean;
FUseQuality : Boolean;
function GetCodingItem(const Coding: String): THttpContCodItem;
function GetCodingEnabled(const Coding: String): Boolean;
procedure SetCodingEnabled(const Coding: String; const Value: Boolean);
function GetCodingQuality(const Coding: String): Single;
procedure SetCodingQuality(const Coding: String; const Value: Single);
function GetHeaderText: String;
function GetOutputStream: TStream;
procedure SetUseQuality(const Value: Boolean);
procedure ClearCodingList;
procedure InputWriteBuffer(Buffer: Pointer; Count: Integer);
public
constructor Create(OutStream : PStream;
WriteBufferProc : TWriteBufferProcedure);
destructor Destroy; override;
class procedure RegisterContentCoding(
const DefaultQuality : Single;
ContCodClass : THttpContentCodingClass);
class procedure UnregisterAuthenticateClass(
ContCodClass: THttpContentCodingClass);
procedure Complete;
function Prepare(const Encodings: String): Boolean;
property CodingEnabled[const Coding: String] : Boolean
read GetCodingEnabled
write SetCodingEnabled;
property CodingQuality[const Coding: String] : Single
read GetCodingQuality
write SetCodingQuality;
property OutputStream : TStream read GetOutputStream;
property HeaderText : String read GetHeaderText;
property Enabled : Boolean read FEnabled
write FEnabled;
property UseQuality : Boolean read FUseQuality
write SetUseQuality;
property WriteBuffer : TWriteBufferProcedure
read FInputWriteBuffer;
end;
implementation
resourcestring
ERR_GETCODING_OVERRIDE = 'GetCoding must be overridden in %s';
type
PContCoding = ^TContCoding;
TContCoding = record
ContClass : THttpContentCodingClass;
Quality : Single;
end;
TContCodingsList = class(TList)
public
constructor Create;
destructor Destroy; override;
procedure Add(const Quality: Single; AClass: THttpContentCodingClass);
function FindCoding(Coding: String): THttpContentCodingClass;
procedure Remove(AClass: THttpContentCodingClass);
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
constructor TContCodingsList.Create;
begin
inherited Create;
Add(0, THttpCCodIdentity);
Add(0, THttpCCodStar);
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
destructor TContCodingsList.Destroy;
var
I: Integer;
begin
for I := 0 to Count - 1 do
Dispose(PContCoding(Items[I]));
inherited Destroy;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TContCodingsList.Add(
const Quality : Single;
AClass : THttpContentCodingClass);
var
NewRec: PContCoding;
begin
New(NewRec);
NewRec.Quality := Quality;
NewRec.ContClass := AClass;
inherited Add(NewRec);
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
function TContCodingsList.FindCoding(Coding: String): THttpContentCodingClass;
var
I, J: Integer;
EncList : TStringList;
begin
EncList := TStringList.Create; // V8.01 may be more than one encoding type specified
try
for I := Count - 1 downto 0 do begin
EncList.CommaText := PContCoding(Items[I])^.ContClass.GetCoding; // ie 'gzip, deflate'
for J := 0 to EncList.Count - 1 do begin // V8.01 test each type in turn
if SameText(EncList [J], Coding) then begin
Result := PContCoding(Items[I])^.ContClass;
Exit;
end;
end;
end;
Result := nil;
finally
EncList.Free;
end;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TContCodingsList.Remove(AClass: THttpContentCodingClass);
var
I : Integer;
P : PContCoding;
begin
for I := Count - 1 downto 0 do begin
P := PContCoding(Items[I]);
if P^.ContClass.InheritsFrom(AClass) then begin
Dispose(P);
Delete(I);
end;
end;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
var
ContCodings: TContCodingsList = nil;
function GetContentCodings: TContCodingsList;
begin
if ContCodings = nil then
ContCodings := TContCodingsList.Create;
Result := ContCodings;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
constructor THttpContentCoding.Create(WriteBufferProc: TWriteBufferProcedure);
begin
inherited Create;
FOutputWriteBuffer := WriteBufferProc;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
class function THttpContentCoding.GetActive: Boolean;
begin
Result := TRUE;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
class function THttpContentCoding.GetCoding: String;
const
BASE_CLASS_NAME = 'THttpContentCoding';
begin
if Pos(BASE_CLASS_NAME, ClassName) = 1 then
Result := Copy(ClassName, Length(BASE_CLASS_NAME) + 1, MAXINT)
else
raise EHttpContentCodingException.CreateFmt(ERR_GETCODING_OVERRIDE,
[ClassName]);
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
function THttpContentCoding.PropGetActive: Boolean;
begin
Result := GetActive;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
function THttpContentCoding.PropGetCoding: String;
begin
Result := GetCoding;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure THttpContentCoding.Complete;
begin
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
class function THttpCCodIdentity.GetCoding: String;
begin
Result := 'identity';
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
class function THttpCCodStar.GetCoding: String;
begin
Result := '*';
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
constructor THttpContCodItem.Create(
const ACodingClass : THttpContentCodingClass;
const AQuality : Single);
begin
inherited Create;
FCodingClass := ACodingClass;
FEnabled := TRUE;
FQuality := AQuality;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
function THttpContCodItem.GetCoding: String;
begin
Result := FCodingClass.GetCoding;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
function THttpContCodItem.GetEnabled: Boolean;
begin
Result := FEnabled and FCodingClass.GetActive;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
constructor THttpContCodHandler.Create(
OutStream : PStream;
WriteBufferProc : TWriteBufferProcedure);
var
I: Integer;
begin
inherited Create;
FOutputStream := OutStream;
FInputWriteBuffer := InputWriteBuffer;
FOutputWriteBuffer := WriteBufferProc;
FHeaderText := '';
FRecalcHeader := TRUE;
FEnabled := FALSE;
FUseQuality := FALSE;
FCodingList := TList.Create;
FCodingParams := TList.Create;
GetContentCodings;
for I := 0 to ContCodings.Count - 1 do begin
FCodingParams.Add(THttpContCodItem.Create(
PContCoding(ContCodings.Items[I])^.ContClass,
PContCoding(ContCodings.Items[I])^.Quality));
end;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
destructor THttpContCodHandler.Destroy;
var
I: Integer;
begin
ClearCodingList;
FCodingList.Free;
if FCodingParams <> nil then begin
for I := FCodingParams.Count - 1 downto 0 do
THttpContCodItem(FCodingParams.Items[I]).Free;
FCodingParams.Free;
end;
inherited Destroy;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
function THttpContCodHandler.GetCodingItem(
const Coding: String): THttpContCodItem;
var
I: Integer;
begin
for I := FCodingParams.Count - 1 downto 0 do
if SameText(THttpContCodItem(FCodingParams.Items[I]).Coding,
Coding) then begin
Result := THttpContCodItem(FCodingParams.Items[I]);
Exit;
end;
Result := nil;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
function THttpContCodHandler.GetCodingEnabled(
const Coding: String): Boolean;
var
AItem: THttpContCodItem;
begin
AItem := GetCodingItem(Coding);
Result := (AItem <> nil) and AItem.Enabled;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure THttpContCodHandler.SetCodingEnabled(
const Coding : String;
const Value : Boolean);
var
AItem: THttpContCodItem;
begin
AItem := GetCodingItem(Coding);
if (AItem <> nil) and (AItem.Enabled <> Value) then begin
AItem.Enabled := Value;
FRecalcHeader := TRUE;
end;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
function THttpContCodHandler.GetCodingQuality(
const Coding: String): Single;
var
AItem: THttpContCodItem;
begin
AItem := GetCodingItem(Coding);
if AItem <> nil then
Result := AItem.Quality
else
Result := -1;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure THttpContCodHandler.SetCodingQuality(
const Coding : String;
const Value : Single);
var
AItem: THttpContCodItem;
begin
AItem := GetCodingItem(Coding);
if (AItem <> nil) and (AItem.Quality <> Value) then begin
AItem.Quality := Value;
FRecalcHeader := TRUE;
end;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
function THttpContCodHandler.GetHeaderText: String;
var
ContItem : THttpContCodItem;
AddQuality : Boolean;
DecPos : Integer;
QualStr : String;
I : Integer;
begin
if not FEnabled then begin
Result := '';
Exit;
end;
if FRecalcHeader then begin
if UseQuality then begin
{ Quality will be added only if there are more than one coding enabled }
AddQuality := FCodingParams.Count > 0;
for I := FCodingParams.Count - 1 downto 0 do begin
if THttpContCodItem(FCodingParams.Items[I]).Enabled then begin
if AddQuality then
AddQuality := FALSE
else begin
AddQuality := TRUE;
Break;
end;
end;
end;
end
else
AddQuality := FALSE;
FHeaderText := '';
for I := 0 to FCodingParams.Count - 1 do begin
ContItem := THttpContCodItem(FCodingParams.Items[I]);
if ContItem.Enabled then begin
if AddQuality then begin
QualStr := FormatFloat('0.###', ContItem.Quality);
{ Force the point as decimal separator }
if {$IFDEF COMPILER16_UP}FormatSettings.{$ENDIF}DecimalSeparator <> '.' then begin
DecPos := Pos({$IFDEF COMPILER16_UP}FormatSettings.{$ENDIF}DecimalSeparator, QualStr);
if DecPos > 0 then
QualStr[DecPos] := '.';
end;
if FHeaderText = '' then
FHeaderText := Format('%s;q=%s', [ContItem.Coding, QualStr])
else
FHeaderText := Format('%s, %s;q=%s',
[FHeaderText, ContItem.Coding,
QualStr]);
end
else if ContItem.Quality > 0 then begin
if FHeaderText = '' then
FHeaderText := ContItem.Coding
else
FHeaderText := Format('%s, %s',
[FHeaderText, ContItem.Coding]);
end;
end;
end;
FRecalcHeader := FALSE;
end;
Result := FHeaderText;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
function THttpContCodHandler.GetOutputStream: TStream;
begin
Result := FOutputStream^;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure THttpContCodHandler.SetUseQuality(const Value: Boolean);
begin
if FUseQuality = Value then
Exit;
FUseQuality := Value;
FRecalcHeader := TRUE;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
class procedure THttpContCodHandler.RegisterContentCoding(
const DefaultQuality : Single;
ContCodClass : THttpContentCodingClass);
begin
GetContentCodings.Add(DefaultQuality, ContCodClass);
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
class procedure THttpContCodHandler.UnregisterAuthenticateClass(
ContCodClass: THttpContentCodingClass);
begin
if ContCodings <> nil then
ContCodings.Remove(ContCodClass);
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure THttpContCodHandler.ClearCodingList;
var
I: Integer;
begin
if FCodingList <> nil then begin
for I := FCodingList.Count - 1 downto 0 do
THttpContentCoding(FCodingList.Items[I]).Free;
FCodingList.Clear;
end;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure THttpContCodHandler.InputWriteBuffer(Buffer: Pointer; Count: Integer);
begin
if Assigned(OutputStream) then
OutputStream.WriteBuffer(Buffer^, Count);
FOutputWriteBuffer(Buffer, Count);
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure THttpContCodHandler.Complete;
var
I: Integer;
begin
for I := FCodingList.Count - 1 downto 0 do
THttpContentCoding(FCodingList[I]).Complete;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
function THttpContCodHandler.Prepare(const Encodings: String): Boolean;
var
EncList : TStringList;
AClass : THttpContentCodingClass;
ContCod : THttpContentCoding;
I : Integer;
begin
Result := TRUE;
ClearCodingList;
FInputWriteBuffer := InputWriteBuffer;
if not FEnabled or (Encodings = '') then
Exit;
EncList := TStringList.Create;
try
EncList.CommaText := Encodings; // unsure why a server would report more than one encoding!!!
for I := 0 to EncList.Count - 1 do begin
AClass := GetContentCodings.FindCoding(EncList[I]);
if AClass = nil then begin
Result := FALSE;
Break;
end;
ContCod := AClass.Create(FInputWriteBuffer);
FCodingList.Add(ContCod);
FInputWriteBuffer := ContCod.WriteBuffer;
end;
finally
EncList.Free;
end;
if not Result then begin
ClearCodingList;
FInputWriteBuffer := InputWriteBuffer;
end;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
initialization
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
finalization
ContCodings.Free;
ContCodings := nil; // Avoid exception at package uninstall when
// UnregisterAuthenticateClass is called
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
end.
| 32.921131 | 110 | 0.544546 |
8516cd746b5838c243bdb5a62816ee27ec4b3e58 | 384 | pas | Pascal | ALG-1/lista_07/remover_do_vetor/remover_elemento.pas | leommartin/ERE-2-UFPR | b6dfe367507566b4bd7fa10aa15ed7567880a4d2 | [
"MIT"
]
| null | null | null | ALG-1/lista_07/remover_do_vetor/remover_elemento.pas | leommartin/ERE-2-UFPR | b6dfe367507566b4bd7fa10aa15ed7567880a4d2 | [
"MIT"
]
| null | null | null | ALG-1/lista_07/remover_do_vetor/remover_elemento.pas | leommartin/ERE-2-UFPR | b6dfe367507566b4bd7fa10aa15ed7567880a4d2 | [
"MIT"
]
| null | null | null | program remover_qualquer_dado;
const MIN=1; MAX=200;
var n, i, tam: integer;
v: array [MIN..MAX] of integer;
begin
read(n);
tam:= 0;
while n <> 0 do
begin
tam+=1;
v[tam] := n;
read(n);
end;
read(n);
for i:=1 to tam do
begin
if v[i] = n then
begin
v[tam+1] := v[i];
tam-=1;
end;
end;
for i:=1 to tam+2 do
write(v[i],' ');
writeln;
end.
| 12.387097 | 35 | 0.539063 |
f18fc8c617f8f5d2936ebb337f047a6b02eee88b | 2,068 | pas | Pascal | Lib/Classes/Common/ZXing.Common.BitArray.pas | igorbastosib/ZXing.Delphi | c113597d06f493f3715b30e54317af61e7b558c0 | [
"Apache-2.0"
]
| 384 | 2015-05-30T16:32:43.000Z | 2022-03-23T12:07:48.000Z | Lib/Classes/Common/ZXing.Common.BitArray.pas | kattunga/ZXing.Delphi | 28d32866d4d0871c97bc84130e976366a892586e | [
"Apache-2.0"
]
| 119 | 2015-06-08T14:49:22.000Z | 2022-03-31T16:25:18.000Z | Lib/Classes/Common/ZXing.Common.BitArray.pas | kattunga/ZXing.Delphi | 28d32866d4d0871c97bc84130e976366a892586e | [
"Apache-2.0"
]
| 182 | 2015-06-01T01:05:29.000Z | 2022-02-22T07:08:05.000Z | {
* Copyright 2008 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Original Author: Sean Owen
* Delphi Implementation by E. Spelt and K. Gossens
}
unit ZXing.Common.BitArray;
interface
type
IBitArray = interface
['{3D65F451-E408-4015-A637-73CD05877BCB}']
// property getters and setters
function GetBit(i: Integer): Boolean;
procedure SetBit(i: Integer; Value: Boolean);
function GetBits: TArray<Integer>;
function Size: Integer;
function SizeInBytes: Integer;
property Self[i: Integer]: Boolean read GetBit write SetBit; default;
property Bits: TArray<Integer> read GetBits;
function getNextSet(from: Integer): Integer;
function getNextUnset(from: Integer): Integer;
procedure setBulk(i, newBits: Integer);
procedure setRange(start, ending: Integer);
procedure appendBit(bit: Boolean);
procedure Reverse();
procedure clear();
function isRange(start, ending: Integer; const value: Boolean): Boolean;
end;
TBitArrayHelpers = class
class function CreateBitArray:IBitArray; overload;
class function CreateBitArray(const Size: Integer):IBitArray; overload;
end;
implementation
uses ZXing.Common.BitArrayImplementation;
class function TBitArrayHelpers.CreateBitArray:IBitArray;
begin
result := ZXing.Common.BitArrayImplementation.NewBitArray;
end;
class function TBitArrayHelpers.CreateBitArray(const Size: Integer):IBitArray;
begin
result := ZXing.Common.BitArrayImplementation.NewBitArray(size);
end;
end.
| 29.126761 | 78 | 0.735493 |
cdea7684a2ff756a1600270051e59d21e9ddd8f3 | 6,156 | pas | Pascal | sources/MVCFramework.FireDAC.Utils.pas | joaoduarte19/delphimvcframework | 17cc5d5eea42dccbb9b78dd4d66260b306143909 | [
"Apache-2.0"
]
| 1,009 | 2015-05-28T12:34:39.000Z | 2022-03-30T14:10:18.000Z | sources/MVCFramework.FireDAC.Utils.pas | FinCodeur/delphimvcframework | a45cb1383eaffc9e81a836247643390acbb7b9b0 | [
"Apache-2.0"
]
| 454 | 2015-05-28T12:44:27.000Z | 2022-03-31T22:35:45.000Z | sources/MVCFramework.FireDAC.Utils.pas | FinCodeur/delphimvcframework | a45cb1383eaffc9e81a836247643390acbb7b9b0 | [
"Apache-2.0"
]
| 377 | 2015-05-28T16:29:21.000Z | 2022-03-21T18:36:12.000Z | // ***************************************************************************
//
// Delphi MVC Framework
//
// Copyright (c) 2010-2021 Daniele Teti and the DMVCFramework Team
//
// https://github.com/danieleteti/delphimvcframework
//
// ***************************************************************************
//
// Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// *************************************************************************** }
unit MVCFramework.FireDAC.Utils;
{$I dmvcframework.inc}
interface
uses
FireDAC.Comp.Client, FireDAC.Stan.Param, System.Rtti, JsonDataObjects;
type
TFireDACUtils = class sealed
private
class var CTX: TRttiContext;
class function InternalExecuteQuery(AQuery: TFDQuery; AObject: TObject;
WithResult: boolean): Int64;
public
class constructor Create;
class destructor Destroy;
class function ExecuteQueryNoResult(AQuery: TFDQuery;
AObject: TObject): Int64;
class procedure ExecuteQuery(AQuery: TFDQuery; AObject: TObject);
class procedure ObjectToParameters(AFDParams: TFDParams; AObject: TObject; AParamPrefix: string = '';
ASetParamTypes: boolean = True);
class procedure CreateDatasetFromMetadata(AFDMemTable: TFDMemTable; AMeta: TJSONObject);
end;
implementation
uses
System.Generics.Collections,
Data.DB,
System.Classes,
MVCFramework.Serializer.Commons,
System.SysUtils;
{ TFireDACUtils }
class constructor TFireDACUtils.Create;
begin
TFireDACUtils.CTX := TRttiContext.Create;
end;
class procedure TFireDACUtils.CreateDatasetFromMetadata(
AFDMemTable: TFDMemTable; AMeta: TJSONObject);
var
lJArr: TJSONArray;
I: Integer;
lJObj: TJSONObject;
begin
if AMeta.IsNull('fielddefs') then
begin
raise EMVCDeserializationException.Create('Invalid Metadata objects. Property [fielddefs] required.');
end;
AFDMemTable.Active := False;;
AFDMemTable.FieldDefs.Clear;
lJArr := AMeta.A['fielddefs'];
for I := 0 to lJArr.Count - 1 do
begin
lJObj := lJArr.Items[I].ObjectValue;
AFDMemTable.FieldDefs.Add(
lJObj.S['fieldname'],
TFieldType(lJObj.I['datatype']),
lJObj.I['size']);
{ TODO -oDanieleT -cGeneral : Why don't change the display name? }
AFDMemTable.FieldDefs[I].DisplayName := lJObj.S['displayname'];
end;
AFDMemTable.CreateDataset;
end;
class destructor TFireDACUtils.Destroy;
begin
TFireDACUtils.CTX.Free;
end;
class procedure TFireDACUtils.ExecuteQuery(AQuery: TFDQuery; AObject: TObject);
begin
InternalExecuteQuery(AQuery, AObject, True);
end;
class function TFireDACUtils.ExecuteQueryNoResult(AQuery: TFDQuery;
AObject: TObject): Int64;
begin
Result := InternalExecuteQuery(AQuery, AObject, False);
end;
class procedure TFireDACUtils.ObjectToParameters(AFDParams: TFDParams;
AObject: TObject; AParamPrefix: string; ASetParamTypes: boolean);
var
I: Integer;
pname: string;
_rttiType: TRttiType;
obj_fields: TArray<TRttiProperty>;
obj_field: TRttiProperty;
obj_field_attr: MVCColumnAttribute;
Map: TObjectDictionary<string, TRttiProperty>;
f: TRttiProperty;
fv: TValue;
PrefixLength: Integer;
function KindToFieldType(AKind: TTypeKind; AProp: TRttiProperty): TFieldType;
begin
case AKind of
tkInteger:
Result := ftInteger;
tkFloat:
begin // daniele teti 2014-05-23
if AProp.PropertyType.QualifiedName = 'System.TDate' then
Result := ftDate
else if AProp.PropertyType.QualifiedName = 'System.TDateTime' then
Result := ftDateTime
else if AProp.PropertyType.QualifiedName = 'System.TTime' then
Result := ftTime
else
Result := ftFloat;
end;
tkChar, tkString:
Result := ftString;
tkWChar, tkUString, tkLString, tkWString:
Result := ftWideString;
tkVariant:
Result := ftVariant;
tkArray:
Result := ftArray;
tkInterface:
Result := ftInterface;
tkInt64:
Result := ftLongWord;
else
Result := ftUnknown;
end;
end;
begin
PrefixLength := Length(AParamPrefix);
Map := TObjectDictionary<string, TRttiProperty>.Create;
try
if Assigned(AObject) then
begin
_rttiType := CTX.GetType(AObject.ClassType);
obj_fields := _rttiType.GetProperties;
for obj_field in obj_fields do
begin
if TMVCSerializerHelper.HasAttribute<MVCColumnAttribute>(obj_field, obj_field_attr) then
begin
Map.Add(MVCColumnAttribute(obj_field_attr).FieldName.ToLower,
obj_field);
end
else
begin
Map.Add(obj_field.Name.ToLower, obj_field);
end
end;
end;
for I := 0 to AFDParams.Count - 1 do
begin
pname := AFDParams[I].Name.ToLower;
if pname.StartsWith(AParamPrefix, True) then
Delete(pname, 1, PrefixLength);
if Map.TryGetValue(pname, f) then
begin
fv := f.GetValue(AObject);
// #001: Erro ao definir parametros
if ASetParamTypes then
begin
AFDParams[I].DataType := KindToFieldType(fv.Kind, f);
end;
// #001: FIM
// DmitryG - 2014-03-28
AFDParams[I].Value := fv.AsVariant;
end
else
begin
AFDParams[I].Clear;
end;
end;
finally
Map.Free;
end
end;
class function TFireDACUtils.InternalExecuteQuery(AQuery: TFDQuery; AObject: TObject;
WithResult: boolean): Int64;
begin
ObjectToParameters(AQuery.Params, AObject);
Result := 0;
if WithResult then
AQuery.Open
else
begin
AQuery.ExecSQL;
Result := AQuery.RowsAffected;
end;
end;
end.
| 27.855204 | 106 | 0.663093 |
fcb310ec9ad3e15e0d1f9601972a33a028a0206f | 3,586 | pas | Pascal | sipcclient.pas | z505/SimpleIPC-lib | f183c5368b730134c05a9546c5c1fec0160407ef | [
"MIT"
]
| 30 | 2017-12-13T13:46:09.000Z | 2022-02-28T02:41:48.000Z | sipcclient.pas | z505/SimpleIPC-lib | f183c5368b730134c05a9546c5c1fec0160407ef | [
"MIT"
]
| 1 | 2018-09-14T23:37:55.000Z | 2018-09-16T07:08:27.000Z | sipcclient.pas | z505/SimpleIPC-lib | f183c5368b730134c05a9546c5c1fec0160407ef | [
"MIT"
]
| 10 | 2018-04-08T11:49:34.000Z | 2020-10-06T10:02:43.000Z | {
IPC functions for creating and running ipc client
Todo:
- custom message type? integer above a fixed number like mtCustom (integer over 100)
- Google protocol buffers optional
Copyright 2017, Z505 Software
License: BSD/MIT
Todo:
-could SetLastErrors whenever there is an exception in DLL, and pass on
detailed error information into a function that sets a global variable
similar to GetLastError}
unit sIpcClient;
{$mode objfpc}{$H+}
interface
uses
{$ifdef unix}cthreads,{$endif}
Classes, SimpleIPC, SysUtils;
{$I libdeclare.inc}
procedure DefaultStatusLn(s: string);
var StatusLn: procedure (s: string) = @DefaultStatusLn;
implementation
var IpcCli: TSimpleIPCClient;
procedure DefaultStatusLn(s: string);
begin
writeln(':: ' + s);
end;
// write a status, "yes" if boolean true, "no" otherwise
procedure StatusYesLn(b: boolean; s: string);
begin
if b then StatusLn(s +'yes') else StatusLn(s +'no');
end;
{ returns errors:
0: success
1: ipc client already created, can't create until freed first }
function sIpcCreateClient(): int32; cdecl;
begin
if assigned(IpcCli) then exit(1);
IpcCli := TSimpleIPCClient.Create(nil);
result := 0;
end; exports sIpcCreateClient;
{ returns errors:
0: success
1: ipc client not assigned (is nil), can't free variable that doesn't exist }
function sIpcFreeClient: int32; cdecl;
begin
if not assigned(IpcCli) then exit(1);
IpcCli.free; IpcCli := nil;
result := 0;
end; exports sIpcFreeClient;
{ returns errors:
0: success
1: IpcCli not assigned (is nil), not created
2: error connecting to server }
function sIpcStartClient(servID: pchar): int32; cdecl;
begin
if not assigned(IpcCli) then exit(1);
try
IpcCli.ServerID := servID;
IpcCli.Connect;
except
exit(2);
end;
result := 0;
end; exports sIpcStartClient;
{ General function to send any msg type
Returns errors:
0: success
1: ipc client not assigned (is nil), it is not created
2: ipc client not active
3: ipc server is not running }
function SendMsg(msgType: int32; x1: int32; x2: int32; x3: int32; x4: int32; s: pchar): int32;
begin
if not assigned(IpcCli) then exit(1);
if not IpcCli.Active then exit(2);
if not IpcCli.ServerRunning then exit(3);
case msgType of
mtUnknown: { not implemented } ;
mtString: IpcCli.SendStringMessage(msgType, s);
mtInt32: IpcCli.SendStringMessage(msgType, inttostr(x1));
mtXY: IpcCli.SendStringMessage(msgType, inttostr(x1)+';'+inttostr(x2));
mtInts: IpcCli.SendStringMessage(msgType, inttostr(x1)+';'+inttostr(x2)+';'+inttostr(x3)+';'+inttostr(x4));
mtIntStr: IpcCli.SendStringMessage(msgType, inttostr(x1)+';'+s);
end;
result := 0;
end;
function sIpcSendStringMsg(s: pchar): int32; cdecl;
begin
result := SendMsg(mtString,0,0,0,0,s);
end; exports sIpcSendStringMsg;
function sIpcSendXYMsg(x: int32; y: int32): int32; cdecl;
begin
result := SendMsg(mtXY,x,y,0,0,nil);
end; exports sIpcSendXYMsg;
function sIpcSendInt32Msg(i: int32): int32; cdecl;
begin
result := SendMsg(mtInt32,i,0,0,0,nil);
end; exports sIpcSendInt32Msg;
function sIpcSendIntStrMsg(i: int32; s: pchar): int32; cdecl;
begin
result := SendMsg(mtIntStr,i,0,0,0,s);
end; exports sIpcSendIntStrMsg;
function sIpcSendIntsMsg(x1: int32; x2: int32; x3: int32; x4: int32): int32; cdecl;
begin
result := SendMsg(mtInts,x1,x2,x3,x4,nil);
end; exports sIpcSendIntsMsg;
end.
| 26.562963 | 114 | 0.683212 |
f1c440ae9e6d5ee1daee521eb69e797f55be4ec2 | 938 | pas | Pascal | diota/dto/response/DIOTA.Dto.Response.GetInclusionStatesResponse.pas | lubovaskov/iota-delphi | 6451459f881fea2797da5d2db2dce1f66ec910a1 | [
"MIT"
]
| null | null | null | diota/dto/response/DIOTA.Dto.Response.GetInclusionStatesResponse.pas | lubovaskov/iota-delphi | 6451459f881fea2797da5d2db2dce1f66ec910a1 | [
"MIT"
]
| null | null | null | diota/dto/response/DIOTA.Dto.Response.GetInclusionStatesResponse.pas | lubovaskov/iota-delphi | 6451459f881fea2797da5d2db2dce1f66ec910a1 | [
"MIT"
]
| 1 | 2019-02-14T00:40:46.000Z | 2019-02-14T00:40:46.000Z | unit DIOTA.Dto.Response.GetInclusionStatesResponse;
interface
uses
DIOTA.IotaAPIClasses;
type
TGetInclusionStatesResponse = class(TIotaAPIResponse)
private
FStates: TArray<Boolean>;
function GetStates(Index: Integer): Boolean;
function GetStatesCount: Integer;
public
constructor Create(AStates: TArray<Boolean>); reintroduce; virtual;
property StatesCount: Integer read GetStatesCount;
property States[Index: Integer]: Boolean read GetStates;
end;
implementation
{ TGetInclusionStatesResponse }
constructor TGetInclusionStatesResponse.Create(AStates: TArray<Boolean>);
begin
inherited Create;
FStates := AStates;
end;
function TGetInclusionStatesResponse.GetStates(Index: Integer): Boolean;
begin
Result := FStates[Index];
end;
function TGetInclusionStatesResponse.GetStatesCount: Integer;
begin
if Assigned(FStates) then
Result := Length(FStates)
else
Result := 0;
end;
end.
| 21.318182 | 73 | 0.772921 |
fcb2bdbe2e04a4e89add470f09cfc4451ba1db14 | 1,098 | pas | Pascal | source/modules/lmpmc.pas | lysee/lysee | 2300e9a2d8c190b15bc07e9b2e85f018b016feae | [
"BSD-3-Clause"
]
| 15 | 2017-03-03T22:32:51.000Z | 2022-02-04T11:11:56.000Z | source/modules/lmpmc.pas | lysee/lysee | 2300e9a2d8c190b15bc07e9b2e85f018b016feae | [
"BSD-3-Clause"
]
| null | null | null | source/modules/lmpmc.pas | lysee/lysee | 2300e9a2d8c190b15bc07e9b2e85f018b016feae | [
"BSD-3-Clause"
]
| 6 | 2017-04-15T14:53:28.000Z | 2022-01-03T05:33:53.000Z | {==============================================================================}
{ PROJECT: lysee_pmc }
{ DESCRIPTION: pascal module compilter (PMC) }
{ COPYRIGHT: Copyright (c) 2012, Li Yun Jie. All Rights Reserved. }
{ LICENSE: modified BSD license }
{ CREATED: 2012/03/07 }
{ MODIFIED: 2013/09/16 }
{==============================================================================}
{ Contributor(s): }
{==============================================================================}
unit lmpmc;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, lpmc;
{@pmc-description pascal module compiler (PMC)}
{@pmc-funcs
function build(const pasFile, options: string): string;
function wrap(const pasFile: string; register: boolean): string;
}
implementation
end.
| 36.6 | 80 | 0.342441 |
47aa705e44bf43d97386cff8169851db86b7edaf | 34,015 | pas | Pascal | Parsing Expression Grammar/Samples/MiniH/Language.MiniH.pas | helton/HSharp | 186227af9a102b8522c0ebfc1b3439f32eaf2f79 | [
"Apache-2.0"
]
| null | null | null | Parsing Expression Grammar/Samples/MiniH/Language.MiniH.pas | helton/HSharp | 186227af9a102b8522c0ebfc1b3439f32eaf2f79 | [
"Apache-2.0"
]
| null | null | null | Parsing Expression Grammar/Samples/MiniH/Language.MiniH.pas | helton/HSharp | 186227af9a102b8522c0ebfc1b3439f32eaf2f79 | [
"Apache-2.0"
]
| 3 | 2016-12-05T21:05:56.000Z | 2019-02-12T08:14:16.000Z | {***************************************************************************}
{ }
{ HSharp Framework for Delphi }
{ }
{ Copyright (C) 2014 Helton Carlos de Souza }
{ }
{***************************************************************************}
{ }
{ Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 }
{ }
{ Unless required by applicable law or agreed to in writing, software }
{ distributed under the License is distributed on an "AS IS" BASIS, }
{ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. }
{ See the License for the specific language governing permissions and }
{ limitations under the License. }
{ }
{***************************************************************************}
unit Language.MiniH;
interface
uses
System.Generics.Collections,
System.Rtti,
System.SysUtils,
HSharp.Core.Arrays,
HSharp.Core.ArrayString,
HSharp.Collections,
HSharp.Collections.Interfaces,
HSharp.PEG.Grammar,
HSharp.PEG.Grammar.Attributes,
HSharp.PEG.Grammar.Interfaces,
HSharp.PEG.Node,
HSharp.PEG.Node.Interfaces;
type
{$REGION 'Types'}
EVariableNotDefinedException = class(Exception);
EMethodNotDefinedException = class(Exception);
EArgumentCountException = class(Exception);
{$SCOPEDENUMS ON}
TArithmeticOperator = (None, Addition, Subtraction, Multiplication, Division, IntegerDivision, Modulo, Power, Radix);
TRelationalOperator = (None, Equal, NotEqual, GreaterThan, LessThan, GreaterOrEqualThan, LessOrEqualThan);
TLogicalOperator = (None, LogicalAnd, LogicalOr, LogicalXor);
TIncrementDecrementOperator = (Increment, Decrement);
TCompoundAssignment = (AdditionAssignment, SubtractionAssignment, MultiplicationAssignment, DivisionAssignment, IntegerDivisionAssignment, ModuloAssignment, PowerAssignment);
{$SCOPEDENUMS OFF}
{$ENDREGION}
{$REGION 'Interfaces'}
IMiniH = interface(IGrammar)
['{48EF9501-978B-41E7-839E-9FE71C53C788}']
function Execute(const aExpression: string): TValue;
end;
IMethod = interface
['{46A35246-32F3-4657-90B4-1907928C238E}']
function GetParameters: IArrayString;
function GetBodyNode: INode;
property Parameters: IArrayString read GetParameters;
property BodyNode: INode read GetBodyNode;
end;
IScope = interface
['{DDC8FB74-9A06-4517-98C4-7BF3B2419E3E}']
function GetVariables: IDictionary<string, Extended>;
function GetMethods: IDictionary<string, IMethod>;
property Variables: IDictionary<string, Extended> read GetVariables;
property Methods: IDictionary<string, IMethod> read GetMethods;
end;
{$ENDREGION}
TScope = class(TInterfacedObject, IScope)
strict private
FVariables: IDictionary<string, Extended>;
FMethods: IDictionary<string, IMethod>;
strict protected
{ IScope }
function GetVariables: IDictionary<string, Extended>;
function GetMethods: IDictionary<string, IMethod>;
public
constructor Create(const aInnerScope: IScope = nil); reintroduce;
end;
TMethod = class(TInterfacedObject, IMethod)
strict private
FParameters: IArrayString;
FBodyNode: INode;
strict protected
{ IMethod }
function GetParameters: IArrayString;
function GetBodyNode: INode;
public
constructor Create(const aParameters: IArrayString;
const aBodyNode: INode);
end;
TMiniH = class(TGrammar, IMiniH)
strict private
FScopeStack: IStack<IScope>;
strict protected
function StrToOperation(const aArithmeticOperator: string): TArithmeticOperator;
function StrToRelationalOperator(const aRelationalOperator: string): TRelationalOperator;
function StrToLogicalOperator(const aLogicalOperator: string): TLogicalOperator;
function StrToIncrementDecrementOperator(const aIncrementDecrementOperator: string): TIncrementDecrementOperator;
function ApplyArithmeticOperator(aOperation: TArithmeticOperator; aLeft, aRight: Extended): Extended;
function ApplyIncrementDecrementOperator(aValue: Extended; aIncrementDecrementOperator: TIncrementDecrementOperator): Extended;
function DoCompoundAssignment(const aVariableName: string; aExpressionValue: Extended; aCompoundAssignment: TCompoundAssignment): Extended;
function Scope: IScope;
public
constructor Create; override;
public
[Rule('program = statementList')]
function Visit_Program(const aNode: INode): TValue;
[Rule('statementList = statement statement_list:(";" statement)* ";"? _')]
function Visit_StatementList(const aNode: INode): TValue;
[Rule('statement = _ stmt:(function | expression) _')]
function Visit_Statement(const aNode: INode): TValue;
[Rule('statementBlock = "{" _ statementList _ "}" _')]
function Visit_StatementBlock(const aNode: INode): TValue;
[Rule('statementBody = statementBlock | statement')]
function Visit_StatementBody(const aNode: INode): TValue;
[Rule('function = "def" _ identifier _ "(" _ parameters _ ")" _ statementBody _')]
[LazyRule]
function Visit_Function(const aNode: INode): TValue;
[Rule('parameters = identifier params:(_ "," _ identifier)* _')]
function Visit_Parameters(const aNode: INode): TValue;
[Rule('expression = ifElse | while | for | simpleExpression')]
function Visit_Expression(const aNode: INode): TValue;
[Rule('simpleExpression = _ negate term term_list:( addOp term )*')]
function Visit_SimpleExpression(const aNode: INode): TValue;
[Rule('term = factor factor_list:( mulOp factor )*')]
function Visit_Term(const aNode: INode): TValue;
[Rule('factor = atom atom_list:( expOp atom )*')]
function Visit_Factor(const aNode: INode): TValue;
[Rule('atom = call | parenthesizedExp | number | assignment | prefixExpression | posfixExpression | variable')]
function Visit_Atom(const aNode: INode): TValue;
[Rule('prefixExpression = incrementDecrementOperator _ identifier')]
function Visit_PrefixExpression(const aNode: INode): TValue;
[Rule('posfixExpression = identifier _ incrementDecrementOperator')]
function Visit_PosfixExpression(const aNode: INode): TValue;
[Rule('incrementDecrementOperator = "++" | "--"')]
function Visit_IncrementDecrementOperator(const aNode: INode): TValue;
[Rule('parenthesizedExp = "(" _ expression ")" _')]
function Visit_ParenthesizedExp(const aNode: INode): TValue;
[Rule('assignment = simpleAssignment | compoundAssignment')]
function Visit_Assignment(const aNode: INode): TValue;
[Rule('simpleAssignment = identifier _ "=" _ expression')]
function Visit_SimpleAssignment(const aNode: INode): TValue;
[Rule('compoundAssignment = additionAssignment | subtractionAssignment | multiplicationAssignment | divisionAssignment | integerDivisionAssignment | moduloAssignment | powerAssignment')]
function Visit_CompoundAssignment(const aNode: INode): TValue;
[Rule('additionAssignment = identifier _ "+=" _ expression')]
function Visit_AdditionAssignment(const aNode: INode): TValue;
[Rule('subtractionAssignment = identifier _ "-=" _ expression')]
function Visit_SubtractionAssignment(const aNode: INode): TValue;
[Rule('multiplicationAssignment = identifier _ "*=" _ expression')]
function Visit_MultiplicationAssignment(const aNode: INode): TValue;
[Rule('divisionAssignment = identifier _ "/=" _ expression')]
function Visit_DivisionAssignment(const aNode: INode): TValue;
[Rule('integerDivisionAssignment = identifier _ "//=" _ expression')]
function Visit_IntegerDivisionAssignment(const aNode: INode): TValue;
[Rule('moduloAssignment = identifier _ "%=" _ expression')]
function Visit_ModuloAssignment(const aNode: INode): TValue;
[Rule('powerAssignment = identifier _ "**=" _ expression')]
function Visit_PowerAssignment(const aNode: INode): TValue;
[Rule('addOp = op:("+" | "-") _')]
function Visit_AddOp(const aNode: INode): TValue;
[Rule('mulOp = op:("*" | "//" | "div" | "/" | "%" | "mod") _')]
function Visit_MulOp(const aNode: INode): TValue;
[Rule('expOp = op:("**" | "r") _')]
function Visit_ExpOp(const aNode: INode): TValue;
[Rule('number = num:/[0-9]*\.?[0-9]+(e[-+]?[0-9]+)?/ _')]
function Visit_Number(const aNode: INode): TValue;
[Rule('variable = identifier _')]
function Visit_Variable(const aNode: INode): TValue;
[Rule('identifier = id:/[a-z_][a-z0-9_]*/i _')]
function Visit_Identifier(const aNode: INode): TValue;
[Rule('negate = "-"?')]
function Visit_Negate(const aNode: INode): TValue;
[Rule('booleanExpression = booleanNegateOperator _ simpleBooleanExpression')]
function Visit_BooleanExpression(const aNode: INode): TValue;
[Rule('simpleBooleanExpression = booleanComparisonList | booleanNumericExpression | booleanConstant')]
function Visit_SimpleBooleanExpression(const aNode: INode): TValue;
[Rule('booleanNumericExpression = expression _')]
function Visit_BooleanNumericExpression(const aNode: INode): TValue;
[Rule('booleanComparisonList = comparisonExpression comparison_expr_list:(booleanLogicalOperator booleanExpression)*')]
function Visit_BooleanComparisonList(const aNode: INode): TValue;
[Rule('comparisonExpression = booleanRelationalExpression | parenthesizedBooleanExpression')]
function Visit_ComparisonExpression(const aNode: INode): TValue;
[Rule('parenthesizedBooleanExpression = "(" booleanExpression ")" _')]
function Visit_ParenthesizedBooleanExpression(const aNode: INode): TValue;
[Rule('booleanRelationalExpression = expression relational_expr_list:(booleanRelationalOperator expression)+')]
function Visit_BooleanRelationalExpression(const aNode: INode): TValue;
[Rule('booleanRelationalOperator = op:("==" | "!="| "<>" | ">=" | "<=" | "<" | ">") _')]
function Visit_BooleanRelationalOperator(const aNode: INode): TValue;
[Rule('booleanLogicalOperator = op:("or" | "and" | "xor" | "||" | "&&" | "^") _')]
function Visit_BooleanLogicalOperator(const aNode: INode): TValue;
[Rule('booleanNegateOperator = ("not" | "!")?')]
function Visit_BooleanNegateOperator(const aNode: INode): TValue;
[Rule('booleanConstant = bool_const:("true" | "false") _')]
function Visit_BooleanConstant(const aNode: INode): TValue;
[Rule('ifElse = "if" _ booleanExpression _ ( "then" _ )? statementBody elsePart:(_ "else" _ statementBody)?')]
[LazyRule]
function Visit_IfElse(const aNode: INode): TValue;
[Rule('while = "while" _ booleanExpression _ ( "do" _ )? statementBody')]
[LazyRule]
function Visit_While(const aNode: INode): TValue;
[Rule('for = "for" _ identifier _ "=" _ initialExp:expression _ "to" _ finalExp:expression _ ( "do" _ )? statementBody')]
[LazyRule]
function Visit_For(const aNode: INode): TValue;
[Rule('call = identifier _ "(" _ arguments _ ")" _')]
function Visit_Call(const aNode: INode): TValue;
[Rule('arguments = expression _ args:(_ "," _ expression)* _')]
function Visit_Arguments(const aNode: INode): TValue;
[Rule('_ = /\s+/?')]
function Visit__(const aNode: INode): TValue;
public
function Execute(const aExpression: string): TValue;
end;
implementation
uses
FMX.Dialogs,
System.Math,
System.StrUtils,
System.Typinfo,
HSharp.PEG.Utils;
{ TMiniH }
function TMiniH.ApplyIncrementDecrementOperator(
aValue: Extended; aIncrementDecrementOperator: TIncrementDecrementOperator): Extended;
begin
if aIncrementDecrementOperator = TIncrementDecrementOperator.Increment then
Result := aValue + 1
else
Result := aValue - 1;
end;
constructor TMiniH.Create;
begin
inherited;
FScopeStack := Collections.CreateStack<IScope>;
FScopeStack.Push(TScope.Create);
end;
function TMiniH.DoCompoundAssignment(const aVariableName: string;
aExpressionValue: Extended; aCompoundAssignment: TCompoundAssignment): Extended;
var
VariableValue, Value: Extended;
begin
if Scope.Variables.TryGetValue(aVariableName, VariableValue) then
begin
Value := VariableValue;
case aCompoundAssignment of
TCompoundAssignment.AdditionAssignment:
Value := Value + aExpressionValue;
TCompoundAssignment.SubtractionAssignment:
Value := Value - aExpressionValue;
TCompoundAssignment.MultiplicationAssignment:
Value := Value * aExpressionValue;
TCompoundAssignment.DivisionAssignment:
Value := Value / aExpressionValue;
TCompoundAssignment.IntegerDivisionAssignment:
Value := Trunc(Value) div Trunc(aExpressionValue); {TODO -oHelton -cCheck this again : Check if this Trunc is correct}
TCompoundAssignment.ModuloAssignment:
Value := Trunc(Value) mod Trunc(aExpressionValue); {TODO -oHelton -cCheck this again : Check if this Trunc is correct}
TCompoundAssignment.PowerAssignment:
Value := Power(Value, aExpressionValue);
end;
Scope.Variables.AddOrSetValue(aVariableName, Value);
end
else
raise EVariableNotDefinedException.CreateFmt('Variable "%s" is not defined in this ' +
'scope', [aVariableName]);
Result := Value;
end;
function TMiniH.Execute(const aExpression: string): TValue;
begin
ShowMessage(NodeToStr(Parse(aExpression)));
Result := ParseAndVisit(aExpression);
end;
function TMiniH.ApplyArithmeticOperator(aOperation: TArithmeticOperator; aLeft,
aRight: Extended): Extended;
begin
case aOperation of
TArithmeticOperator.Addition:
Result := aLeft + aRight;
TArithmeticOperator.Subtraction:
Result := aLeft - aRight;
TArithmeticOperator.Multiplication:
Result := aLeft * aRight;
TArithmeticOperator.Division:
Result := aLeft / aRight;
TArithmeticOperator.IntegerDivision:
Result := Trunc(aLeft) div Trunc(aRight); {TODO -oHelton -cCheck this again : Check if this Trunc is correct}
TArithmeticOperator.Modulo:
Result := Trunc(aLeft) mod Trunc(aRight); {TODO -oHelton -cCheck this again : Check if this Trunc is correct}
TArithmeticOperator.Power:
Result := Power(aLeft, aRight);
TArithmeticOperator.Radix:
Result := Power(aRight, 1/aLeft);
else
Result := 0;
end;
end;
function TMiniH.Scope: IScope;
begin
Result := FScopeStack.Peek;
end;
function TMiniH.StrToRelationalOperator(
const aRelationalOperator: string): TRelationalOperator;
begin
Result := TRelationalOperator.Equal;
if aRelationalOperator = '==' then
Result := TRelationalOperator.Equal
else if (aRelationalOperator = '!=') or
(aRelationalOperator = '<>') then
Result := TRelationalOperator.NotEqual
else if aRelationalOperator = '>=' then
Result := TRelationalOperator.GreaterOrEqualThan
else if aRelationalOperator = '<=' then
Result := TRelationalOperator.LessOrEqualThan
else if aRelationalOperator = '>' then
Result := TRelationalOperator.GreaterThan
else if aRelationalOperator = '<' then
Result := TRelationalOperator.LessThan
end;
function TMiniH.StrToIncrementDecrementOperator(
const aIncrementDecrementOperator: string): TIncrementDecrementOperator;
begin
if aIncrementDecrementOperator = '++' then
Result := TIncrementDecrementOperator.Increment
else
Result := TIncrementDecrementOperator.Decrement;
end;
function TMiniH.StrToLogicalOperator(
const aLogicalOperator: string): TLogicalOperator;
begin
if (aLogicalOperator = 'and') or
(aLogicalOperator = '&&') then
Result := TLogicalOperator.LogicalAnd
else if (aLogicalOperator = 'or') or
(aLogicalOperator = '||') then
Result := TLogicalOperator.LogicalOr
else if (aLogicalOperator = 'xor') or
(aLogicalOperator = '^') then
Result := TLogicalOperator.LogicalXor
else
Result := TLogicalOperator.None;
end;
function TMiniH.StrToOperation(const aArithmeticOperator: string): TArithmeticOperator;
begin
if aArithmeticOperator = '+' then
Result := TArithmeticOperator.Addition
else if aArithmeticOperator = '-' then
Result := TArithmeticOperator.Subtraction
else if aArithmeticOperator = '*' then
Result := TArithmeticOperator.Multiplication
else if aArithmeticOperator = '/' then
Result := TArithmeticOperator.Division
else if (aArithmeticOperator = '//') or
(aArithmeticOperator = 'div') then
Result := TArithmeticOperator.IntegerDivision
else if (aArithmeticOperator = '%') or
(aArithmeticOperator = 'mod') then
Result := TArithmeticOperator.Modulo
else if aArithmeticOperator = '**' then
Result := TArithmeticOperator.Power
else if aArithmeticOperator = 'r' then
Result := TArithmeticOperator.Radix
else
Result := TArithmeticOperator.None;
end;
function TMiniH.Visit_AdditionAssignment(const aNode: INode): TValue;
begin
Result := DoCompoundAssignment(aNode.Children['identifier'].Value.AsString,
aNode.Children['expression'].Value.AsExtended,
TCompoundAssignment.AdditionAssignment
);
end;
function TMiniH.Visit_AddOp(const aNode: INode): TValue;
begin
Result := TValue.From<TArithmeticOperator>(StrToOperation(aNode.Children['op'].Text));
end;
function TMiniH.Visit_Arguments(const aNode: INode): TValue;
var
Args: IArray<Extended>;
Node: INode;
begin
Args := TArray<Extended>.Create;
Args.Add(aNode.Children['expression'].Value.AsExtended);
if Assigned(aNode.Children['args'].Children) then
begin
for Node in aNode.Children['args'].Children do
Args.Add(Node.Children['expression'].Value.AsExtended);
end;
Result := TValue.From<IArray<Extended>>(Args);
end;
function TMiniH.Visit_Assignment(const aNode: INode): TValue;
begin
Result := aNode.Children.First.Value;
end;
function TMiniH.Visit_Atom(const aNode: INode): TValue;
begin
Result := aNode.Children.First.Value.AsExtended;
end;
function TMiniH.Visit_BooleanComparisonList(const aNode: INode): TValue;
var
ChildNode: INode;
begin
Result := aNode.Children['comparisonExpression'].Value.AsBoolean;
if Assigned(aNode.Children['comparison_expr_list'].Children) then
begin
for ChildNode in aNode.Children['comparison_expr_list'].Children do
begin
case ChildNode.Children['booleanLogicalOperator'].Value.AsType<TLogicalOperator> of
TLogicalOperator.LogicalOr:
Result := Result.AsBoolean or ChildNode.Children['booleanExpression'].Value.AsBoolean;
TLogicalOperator.LogicalAnd:
Result := Result.AsBoolean and ChildNode.Children['booleanExpression'].Value.AsBoolean;
TLogicalOperator.LogicalXor:
Result := Result.AsBoolean xor ChildNode.Children['booleanExpression'].Value.AsBoolean;
end;
end;
end;
end;
function TMiniH.Visit_BooleanConstant(const aNode: INode): TValue;
begin
Result := aNode.Children['bool_const'].Text = 'true';
end;
function TMiniH.Visit_BooleanExpression(const aNode: INode): TValue;
begin
Result := aNode.Children['simpleBooleanExpression'].Value;
if aNode.Children['booleanNegateOperator'].Value.AsBoolean then
Result := not Result.AsBoolean;
end;
function TMiniH.Visit_BooleanLogicalOperator(const aNode: INode): TValue;
begin
Result := TValue.From<TLogicalOperator>(StrToLogicalOperator(aNode.Children['op'].Text));
end;
function TMiniH.Visit_BooleanNegateOperator(const aNode: INode): TValue;
begin
Result := Assigned(aNode.Children);
end;
function TMiniH.Visit_BooleanNumericExpression(const aNode: INode): TValue;
begin
Result := aNode.Children['expression'].Value.AsExtended <> 0;
end;
function TMiniH.Visit_BooleanRelationalExpression(const aNode: INode): TValue;
var
ChildNode: INode;
LeftValue: Extended;
begin
Result := True;
LeftValue := aNode.Children['expression'].Value.AsExtended;
if Assigned(aNode.Children['relational_expr_list'].Children) then
begin
for ChildNode in aNode.Children['relational_expr_list'].Children do
begin
case ChildNode.Children['booleanRelationalOperator'].Value.AsType<TRelationalOperator> of
TRelationalOperator.Equal:
Result := LeftValue = ChildNode.Children['expression'].Value.AsExtended;
TRelationalOperator.NotEqual:
Result := LeftValue <> ChildNode.Children['expression'].Value.AsExtended;
TRelationalOperator.GreaterThan:
Result := LeftValue > ChildNode.Children['expression'].Value.AsExtended;
TRelationalOperator.LessThan:
Result := LeftValue < ChildNode.Children['expression'].Value.AsExtended;
TRelationalOperator.GreaterOrEqualThan:
Result := LeftValue >= ChildNode.Children['expression'].Value.AsExtended;
TRelationalOperator.LessOrEqualThan:
Result := LeftValue <= ChildNode.Children['expression'].Value.AsExtended;
end;
LeftValue := ChildNode.Children['expression'].Value.AsExtended;
if not Result.AsBoolean then
Break;
end;
end;
end;
function TMiniH.Visit_BooleanRelationalOperator(const aNode: INode): TValue;
begin
Result := TValue.From<TRelationalOperator>(StrToRelationalOperator(aNode.Children['op'].Text));
end;
function TMiniH.Visit_Call(const aNode: INode): TValue;
var
MethodName: string;
Method: IMethod;
MethodScope: IScope;
Arguments: IArray<Extended>;
begin
MethodName := aNode.Children['identifier'].Value.AsString;
if Scope.Methods.TryGetValue(MethodName, Method) then
begin
Arguments := aNode.Children['arguments'].Value.AsType<IArray<Extended>>;
MethodScope := TScope.Create(Scope);
if Method.Parameters.Count <> Arguments.Count then
raise EArgumentCountException.CreateFmt('Method "%s" expect %d parameter%s,' +
' but %d got it.',
[MethodName, Method.Parameters.Count, IfThen(Method.Parameters.Count > 1, 's'), Arguments.Count]);
Method.Parameters.ForEachIndex(
procedure (const aParam: string; aIndex: Integer)
begin
MethodScope.Variables.AddOrSetValue(aParam, Arguments[aIndex]);
end
);
FScopeStack.Push(MethodScope);
Result := Visit(Method.BodyNode);
FScopeStack.Pop;
end
else
raise EMethodNotDefinedException.CreateFmt('Method "%s" is not defined in this ' +
'scope', [MethodName]);
end;
function TMiniH.Visit_ComparisonExpression(const aNode: INode): TValue;
begin
Result := aNode.Children.First.Value;
end;
function TMiniH.Visit_CompoundAssignment(const aNode: INode): TValue;
begin
Result := aNode.Children.First.Value;
end;
function TMiniH.Visit_DivisionAssignment(const aNode: INode): TValue;
begin
Result := DoCompoundAssignment(aNode.Children['identifier'].Value.AsString,
aNode.Children['expression'].Value.AsExtended,
TCompoundAssignment.DivisionAssignment
);
end;
function TMiniH.Visit_ExpOp(const aNode: INode): TValue;
begin
Result := TValue.From<TArithmeticOperator>(StrToOperation(aNode.Children['op'].Text));
end;
function TMiniH.Visit_Expression(const aNode: INode): TValue;
begin
Result := aNode.Children.First.Value;
end;
function TMiniH.Visit_Factor(const aNode: INode): TValue;
var
ChildNode: INode;
begin
Result := aNode.Children['atom'].Value.AsExtended;
if Assigned(aNode.Children['atom_list'].Children) then
begin
for ChildNode in aNode.Children['atom_list'].Children do
begin
Result := ApplyArithmeticOperator(
ChildNode.Children['expOp'].Value.AsType<TArithmeticOperator>,
Result.AsExtended,
ChildNode.Children['atom'].Value.AsExtended
);
end;
end;
end;
function TMiniH.Visit_For(const aNode: INode): TValue;
var
VariableName: string;
InitialValue: Extended;
begin
Result := nil;
InitialValue := Visit(aNode.Children[6]).AsExtended;//initialExpr
VariableName := Visit(aNode.Children['identifier']).AsString;
Scope.Variables.AddOrSetValue(VariableName, InitialValue);
while Scope.Variables.Items[VariableName] <= Visit(aNode.Children[10]).AsExtended do //'finalExp'
begin
Result := Visit(aNode.Children['statementBody']);
Scope.Variables.AddOrSetValue(VariableName, Scope.Variables.Items[VariableName] + 1);
end;
Scope.Variables.Remove(VariableName); //loop variable is only available inside loop
end;
function TMiniH.Visit_Function(const aNode: INode): TValue;
var
Method: IMethod;
MethodName: string;
begin
MethodName := Visit(aNode.Children['identifier']).AsString;
Method := TMethod.Create(Visit(aNode.Children['parameters']).AsType<IArrayString>,
aNode.Children['statementBody'].Children.First);
Scope.Methods.AddOrSetValue(MethodName, Method); //overwrite the methods if it already exists
Result := nil;
end;
function TMiniH.Visit_Identifier(const aNode: INode): TValue;
begin
Result := aNode.Children['id'].Text;
end;
function TMiniH.Visit_IfElse(const aNode: INode): TValue;
var
ExpressionValue: TValue;
begin
Result := nil;
ExpressionValue := Visit(aNode.Children['booleanExpression']);
if ExpressionValue.AsBoolean then
Result := Visit(aNode.Children['statementBody'])
else
begin
if Assigned(aNode.Children['elsePart'].Children) then
begin
Visit(aNode.Children['elsePart']);
Result := aNode.Children['elsePart'].Children.First.Children['statementBody'].Value;
end;
end;
end;
function TMiniH.Visit_IncrementDecrementOperator(const aNode: INode): TValue;
begin
Result := TValue.From<TIncrementDecrementOperator>(StrToIncrementDecrementOperator(aNode.Text));
end;
function TMiniH.Visit_IntegerDivisionAssignment(const aNode: INode): TValue;
begin
Result := DoCompoundAssignment(aNode.Children['identifier'].Value.AsString,
aNode.Children['expression'].Value.AsExtended,
TCompoundAssignment.IntegerDivisionAssignment
);
end;
function TMiniH.Visit_ModuloAssignment(const aNode: INode): TValue;
begin
Result := DoCompoundAssignment(aNode.Children['identifier'].Value.AsString,
aNode.Children['expression'].Value.AsExtended,
TCompoundAssignment.ModuloAssignment
);
end;
function TMiniH.Visit_MulOp(const aNode: INode): TValue;
begin
Result := TValue.From<TArithmeticOperator>(StrToOperation(aNode.Children['op'].Text));
end;
function TMiniH.Visit_MultiplicationAssignment(const aNode: INode): TValue;
begin
Result := DoCompoundAssignment(aNode.Children['identifier'].Value.AsString,
aNode.Children['expression'].Value.AsExtended,
TCompoundAssignment.MultiplicationAssignment
);
end;
function TMiniH.Visit_Negate(const aNode: INode): TValue;
begin
Result := Assigned(aNode.Children);
end;
function TMiniH.Visit_Number(const aNode: INode): TValue;
begin
Result := aNode.Children['num'].Text.Replace('.', ',').ToExtended; {TODO -oHelton -cFix : Check locale before do the text replace}
end;
function TMiniH.Visit_Parameters(const aNode: INode): TValue;
var
Params: IArrayString;
Node: INode;
begin
Params := TArrayString.Create;
Params.Add(aNode.Children['identifier'].Text);
if Assigned(aNode.Children['params'].Children) then
begin
for Node in aNode.Children['params'].Children do
Params.Add(Node.Children['identifier'].Text);
end;
Result := TValue.From<IArrayString>(Params);
end;
function TMiniH.Visit_ParenthesizedBooleanExpression(
const aNode: INode): TValue;
begin
Result := aNode.Children['booleanExpression'].Value;
end;
function TMiniH.Visit_ParenthesizedExp(const aNode: INode): TValue;
begin
Result := aNode.Children['expression'].Value.AsExtended;
end;
function TMiniH.Visit_PosfixExpression(const aNode: INode): TValue;
var
VariableName: string;
Value: Extended;
begin
VariableName := aNode.Children['identifier'].Value.AsString;
if Scope.Variables.TryGetValue(VariableName, Value) then
begin
Result := Value;
Scope.Variables.AddOrSetValue(VariableName,
ApplyIncrementDecrementOperator(Value,
aNode.Children['incrementDecrementOperator'].Value.AsType<TIncrementDecrementOperator>));
end
else
raise EVariableNotDefinedException.CreateFmt('Variable "%s" is not defined in this ' +
'scope', [VariableName]);
end;
function TMiniH.Visit_PowerAssignment(const aNode: INode): TValue;
begin
Result := DoCompoundAssignment(aNode.Children['identifier'].Value.AsString,
aNode.Children['expression'].Value.AsExtended,
TCompoundAssignment.PowerAssignment
);
end;
function TMiniH.Visit_PrefixExpression(const aNode: INode): TValue;
var
VariableName: string;
Value: Extended;
begin
VariableName := aNode.Children['identifier'].Value.AsString;
if Scope.Variables.TryGetValue(VariableName, Value) then
begin
Scope.Variables.AddOrSetValue(VariableName,
ApplyIncrementDecrementOperator(Value, aNode.Children['incrementDecrementOperator'].Value.AsType<TIncrementDecrementOperator>));
Result := Scope.Variables.Items[VariableName];
end
else
raise EVariableNotDefinedException.CreateFmt('Variable "%s" is not defined in this ' +
'scope', [VariableName]);
end;
function TMiniH.Visit_Program(const aNode: INode): TValue;
begin
Result := aNode.Children['statementList'].Value;
end;
function TMiniH.Visit_SimpleAssignment(const aNode: INode): TValue;
var
VariableName: string;
Value: Extended;
begin
VariableName := aNode.Children['identifier'].Value.AsString;
Value := aNode.Children['expression'].Value.AsExtended;
Scope.Variables.AddOrSetValue(VariableName, Value);
Result := Value;
end;
function TMiniH.Visit_SimpleBooleanExpression(const aNode: INode): TValue;
begin
Result := aNode.Children.First.Value;
end;
function TMiniH.Visit_SimpleExpression(const aNode: INode): TValue;
var
ChildNode: INode;
begin
Result := aNode.Children['term'].Value.AsExtended;
if Assigned(aNode.Children['term_list'].Children) then
begin
for ChildNode in aNode.Children['term_list'].Children do
begin
Result := ApplyArithmeticOperator(
ChildNode.Children['addOp'].Value.AsType<TArithmeticOperator>,
Result.AsExtended,
ChildNode.Children['term'].Value.AsExtended
);
end;
end;
if aNode.Children['negate'].Value.AsBoolean then
Result := -Result.AsExtended;
end;
function TMiniH.Visit_Statement(const aNode: INode): TValue;
begin
Result := aNode.Children['stmt'].Children.First.Value;
end;
function TMiniH.Visit_StatementBlock(const aNode: INode): TValue;
begin
Result := aNode.Children['statementList'].Value;
end;
function TMiniH.Visit_StatementBody(const aNode: INode): TValue;
begin
Result := aNode.Children.First.Value;
end;
function TMiniH.Visit_StatementList(const aNode: INode): TValue;
begin
Result := aNode.Children['statement'].Value;
if Assigned(aNode.Children['statement_list'].Children) then
Result := aNode.Children['statement_list'].Children.Last.Children['statement'].Value;
end;
function TMiniH.Visit_SubtractionAssignment(const aNode: INode): TValue;
begin
Result := DoCompoundAssignment(aNode.Children['identifier'].Value.AsString,
aNode.Children['expression'].Value.AsExtended,
TCompoundAssignment.SubtractionAssignment
);
end;
function TMiniH.Visit_Term(const aNode: INode): TValue;
var
ChildNode: INode;
begin
Result := aNode.Children['factor'].Value.AsExtended;
if Assigned(aNode.Children['factor_list'].Children) then
begin
for ChildNode in aNode.Children['factor_list'].Children do
begin
Result := ApplyArithmeticOperator(
ChildNode.Children['mulOp'].Value.AsType<TArithmeticOperator>,
Result.AsExtended,
ChildNode.Children['factor'].Value.AsExtended
);
end;
end;
end;
function TMiniH.Visit_Variable(const aNode: INode): TValue;
var
VariableName: string;
Value: Extended;
begin
VariableName := aNode.Children['identifier'].Value.AsString;
if Scope.Variables.TryGetValue(VariableName, Value) then
Result := Value
else
raise EVariableNotDefinedException.CreateFmt('Variable "%s" is not defined in this ' +
'scope', [VariableName]);
end;
function TMiniH.Visit_While(const aNode: INode): TValue;
begin
Result := nil;
while Visit(aNode.Children['booleanExpression']).AsBoolean do
Result := Visit(aNode.Children['statementBody']);
end;
function TMiniH.Visit__(const aNode: INode): TValue;
begin
end;
{ TScope }
constructor TScope.Create(const aInnerScope: IScope);
procedure CopyInnerScope;
var
Variable: TPair<string, Extended>;
Method: TPair<string, IMethod>;
begin
for Variable in aInnerScope.Variables do
FVariables.Add(Variable.Key, Variable.Value);
for Method in aInnerScope.Methods do
FMethods.Add(Method.Key, Method.Value);
end;
begin
inherited Create;
FVariables := Collections.CreateDictionary<string, Extended>;
FMethods := Collections.CreateDictionary<string, IMethod>;
if Assigned(aInnerScope) then
CopyInnerScope;
end;
function TScope.GetMethods: IDictionary<string, IMethod>;
begin
Result := FMethods;
end;
function TScope.GetVariables: IDictionary<string, Extended>;
begin
Result := FVariables;
end;
{ TMethod }
constructor TMethod.Create(const aParameters: IArrayString;
const aBodyNode: INode);
begin
inherited Create;
FParameters := aParameters;
FBodyNode := aBodyNode;
end;
function TMethod.GetBodyNode: INode;
begin
Result := FBodyNode;
end;
function TMethod.GetParameters: IArrayString;
begin
Result := FParameters;
end;
end.
| 36.892625 | 190 | 0.717272 |
47893bbd7b49c123e7d393d8bc7de7183f09384a | 761 | dfm | Pascal | UsingComponents/MyEdit.dfm | rustkas/dephi_do | 96025a01d5cb49136472b7e6bb5f037b27145fba | [
"MIT"
]
| null | null | null | UsingComponents/MyEdit.dfm | rustkas/dephi_do | 96025a01d5cb49136472b7e6bb5f037b27145fba | [
"MIT"
]
| null | null | null | UsingComponents/MyEdit.dfm | rustkas/dephi_do | 96025a01d5cb49136472b7e6bb5f037b27145fba | [
"MIT"
]
| null | null | null | object FTEdit: TFTEdit
Left = 0
Top = 0
Caption = 'Edit'
ClientHeight = 117
ClientWidth = 143
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Edit1: TEdit
Left = 8
Top = 16
Width = 121
Height = 21
PasswordChar = #10084
TabOrder = 0
end
object MyFirstButton: TButton
Left = 32
Top = 70
Width = 75
Height = 25
Caption = ' '#1053#1072#1078#1084#1080' '#1084#1077#1085#1103'!'
TabOrder = 1
OnClick = MyFirstButtonClick
end
object Edit2: TEdit
Left = 8
Top = 43
Width = 121
Height = 21
TabOrder = 2
end
end
| 18.560976 | 68 | 0.617608 |
fc1a9cacee7cba50f083372c3081b9c44a09d67b | 5,520 | pas | Pascal | CryptoLib.Tests/src/Crypto/SHA224HMacTests.pas | stlcours/CryptoLib4Pascal | 82344d4a4b74422559fa693466ca04652e42cf8b | [
"MIT"
]
| 2 | 2019-07-09T10:06:53.000Z | 2021-08-15T18:19:31.000Z | CryptoLib.Tests/src/Crypto/SHA224HMacTests.pas | stlcours/CryptoLib4Pascal | 82344d4a4b74422559fa693466ca04652e42cf8b | [
"MIT"
]
| null | null | null | CryptoLib.Tests/src/Crypto/SHA224HMacTests.pas | stlcours/CryptoLib4Pascal | 82344d4a4b74422559fa693466ca04652e42cf8b | [
"MIT"
]
| null | null | null | { *********************************************************************************** }
{ * CryptoLib Library * }
{ * Copyright (c) 2018 - 20XX Ugochukwu Mmaduekwe * }
{ * Github Repository <https://github.com/Xor-el> * }
{ * Distributed under the MIT software license, see the accompanying file LICENSE * }
{ * or visit http://www.opensource.org/licenses/mit-license.php. * }
{ * Acknowledgements: * }
{ * * }
{ * Thanks to Sphere 10 Software (http://www.sphere10.com/) for sponsoring * }
{ * development of this library * }
{ * ******************************************************************************* * }
(* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *)
unit SHA224HMacTests;
interface
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF FPC}
uses
SysUtils,
{$IFDEF FPC}
fpcunit,
testregistry,
{$ELSE}
TestFramework,
{$ENDIF FPC}
ClpKeyParameter,
ClpHMac,
ClpIMac,
ClpDigestUtilities,
ClpEncoders,
ClpArrayUtils,
ClpStringUtils,
ClpConverters,
ClpCryptoLibTypes;
type
TCryptoLibTestCase = class abstract(TTestCase)
end;
type
/// <summary>
/// SHA224 HMac Test, test vectors from RFC 2202
/// </summary>
TTestSHA224HMac = class(TCryptoLibTestCase)
private
var
Fkeys, Fdigests, Fmessages: TCryptoLibStringArray;
protected
procedure SetUp; override;
procedure TearDown; override;
published
procedure TestSHA224HMac;
end;
implementation
{ TTestSHA224HMac }
procedure TTestSHA224HMac.SetUp;
begin
inherited;
Fkeys := TCryptoLibStringArray.Create
('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b', '4a656665',
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
'0102030405060708090a0b0c0d0e0f10111213141516171819',
'0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c',
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
+ 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
+ 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
Fdigests := TCryptoLibStringArray.Create
('896fb1128abbdf196832107cd49df33f47b4b1169912ba4f53684b22',
'a30e01098bc6dbbf45690f3a7e9e6d0f8bbea2a39e6148008fd05e44',
'7fb3cb3588c6c1f6ffa9694d7d6ad2649365b0c1f65d69d1ec8333ea',
'6c11506874013cac6a2abc1bb382627cec6a90d86efc012de7afec5a',
'0e2aea68a90c8d37c988bcdb9fca6fa8099cd857c7ec4a1815cac54c',
'95e9a0db962095adaebe9b2d6f0dbce2d499f112f2d2b7273fa6870e',
'3a854166ac5d9f023f54d517d0b39dbd946770db9c2b95c9f6f565d1');
Fmessages := TCryptoLibStringArray.Create('Hi There',
'what do ya want for nothing?',
'0xdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd',
'0xcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd',
'Test With Truncation',
'Test Using Larger Than Block-Size Key - Hash Key First',
'This is a test using a larger than block-size key and a larger than block-size data. The key needs to be hashed before being used by the HMAC algorithm.');
end;
procedure TTestSHA224HMac.TearDown;
begin
inherited;
end;
procedure TTestSHA224HMac.TestSHA224HMac;
var
hmac: IMac;
resBuf, m, m2: TBytes;
i, vector: Int32;
begin
hmac := THMac.Create(TDigestUtilities.GetDigest('SHA-224'));
System.SetLength(resBuf, hmac.GetMacSize());
for i := 0 to System.Pred(System.Length(Fmessages)) do
begin
m := TConverters.ConvertStringToBytes(Fmessages[i], TEncoding.ASCII);
if (TStringUtils.BeginsWith(Fmessages[i], '0x', True)) then
begin
m := THex.Decode(System.Copy(Fmessages[i], 3,
System.Length(Fmessages[i]) - 2));
end;
hmac.Init(TKeyParameter.Create(THex.Decode(Fkeys[i])));
hmac.BlockUpdate(m, 0, System.Length(m));
hmac.DoFinal(resBuf, 0);
if (not TArrayUtils.AreEqual(resBuf, THex.Decode(Fdigests[i]))) then
begin
Fail('Vector ' + IntToStr(i) + ' failed');
end;
end;
// test reset
vector := 0; // vector used for test
m2 := TConverters.ConvertStringToBytes(Fmessages[vector], TEncoding.ASCII);
if (TStringUtils.BeginsWith(Fmessages[vector], '0x', True)) then
begin
m2 := THex.Decode(System.Copy(Fmessages[vector], 3,
System.Length(Fmessages[vector]) - 2));
end;
hmac.Init(TKeyParameter.Create(THex.Decode(Fkeys[vector])));
hmac.BlockUpdate(m2, 0, System.Length(m2));
hmac.DoFinal(resBuf, 0);
hmac.Reset();
hmac.BlockUpdate(m2, 0, System.Length(m2));
hmac.DoFinal(resBuf, 0);
if (not TArrayUtils.AreEqual(resBuf, THex.Decode(Fdigests[vector]))) then
begin
Fail('Reset with vector ' + IntToStr(vector) + ' failed');
end;
end;
initialization
// Register any test cases with the test runner
{$IFDEF FPC}
RegisterTest(TTestSHA224HMac);
{$ELSE}
RegisterTest(TTestSHA224HMac.Suite);
{$ENDIF FPC}
end.
| 32.280702 | 185 | 0.672645 |
f1fb6ecd7193d2671742cca690d8f41a96cf8b11 | 681 | dpr | Pascal | Pascal/1-8/1-3/ACT3_/X5/ACT3X3.dpr | DirkyJerky/OtherProgrammingClass | b7267d814e5cd235e56fd682b899602762401fa2 | [
"MIT"
]
| null | null | null | Pascal/1-8/1-3/ACT3_/X5/ACT3X3.dpr | DirkyJerky/OtherProgrammingClass | b7267d814e5cd235e56fd682b899602762401fa2 | [
"MIT"
]
| null | null | null | Pascal/1-8/1-3/ACT3_/X5/ACT3X3.dpr | DirkyJerky/OtherProgrammingClass | b7267d814e5cd235e56fd682b899602762401fa2 | [
"MIT"
]
| null | null | null | program ACT3X3;
{
Name: Geoff Yoerger
Assignment: Lesson 3 EC 5
Due: EC
Purpose: Calculate simple interest
}
{$APPTYPE CONSOLE}
uses
SysUtils;
var
interest, principle : real;
years : integer;
begin
{ Intro to program }
writeln('Welcome to the Simple Interest calulator');
writeln;
{ User Input }
writeln('Priciple investment?');
readln(principle);
writeln('Number of years?');
readln(years);
writeln('Rate? (as decimal)');
readln(interest);
{ Calculations }
principle := principle + (principle * interest * years);
{ Output }
writeln('After ', years,' years you will have $', principle:0:2, '.');
{ Halt the console }
readln;
end.
| 16.609756 | 72 | 0.665198 |
47b73bc958e1079e8b491e23b9194da60b1a778c | 597 | dfm | Pascal | Source/experiments/ProjectRCL/withTreeView.dfm | atkins126/DelphiRTL | f0ea29598025346577870cc9a27338592c4dac1b | [
"BSD-2-Clause"
]
| 40 | 2016-09-28T21:34:23.000Z | 2021-12-25T23:02:09.000Z | Source/experiments/ProjectRCL/withTreeView.dfm | anomous/DelphiRTL | 0bd427025b479a1356da846b7788e3ba3bc9a3c8 | [
"BSD-2-Clause"
]
| 11 | 2017-08-30T13:03:00.000Z | 2020-08-25T13:46:05.000Z | Source/experiments/ProjectRCL/withTreeView.dfm | anomous/DelphiRTL | 0bd427025b479a1356da846b7788e3ba3bc9a3c8 | [
"BSD-2-Clause"
]
| 15 | 2016-11-24T05:52:39.000Z | 2021-11-11T00:50:12.000Z | object Form6: TForm6
Left = 0
Top = 0
Caption = 'Form6'
ClientHeight = 336
ClientWidth = 635
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object TreeView1: TTreeView
Left = 32
Top = 24
Width = 201
Height = 273
Indent = 19
TabOrder = 0
end
object Button1: TButton
Left = 256
Top = 24
Width = 75
Height = 25
Caption = 'Add'
TabOrder = 1
OnClick = Button1Click
end
end
| 17.558824 | 32 | 0.623116 |
fc727081c06a7e49000d66acf61a8bda21150d57 | 353 | dfm | Pascal | UnitDM.dfm | PauloRamalho7/99Money2 | 5cc600a47281d75a2656ab31dfa22c6e59f33077 | [
"MIT"
]
| null | null | null | UnitDM.dfm | PauloRamalho7/99Money2 | 5cc600a47281d75a2656ab31dfa22c6e59f33077 | [
"MIT"
]
| null | null | null | UnitDM.dfm | PauloRamalho7/99Money2 | 5cc600a47281d75a2656ab31dfa22c6e59f33077 | [
"MIT"
]
| null | null | null | object dm: Tdm
OldCreateOrder = False
OnCreate = DataModuleCreate
Height = 328
Width = 354
object conn: TFDConnection
Params.Strings = (
'Database=D:\99Coders\Curso99Money2\Fontes\DB\banco.db'
'OpenMode=ReadWrite'
'LockingMode=Normal'
'DriverID=SQLite')
LoginPrompt = False
Left = 56
Top = 32
end
end
| 20.764706 | 61 | 0.660057 |
85d60edc4cb5b466f5cd20900c4c8c398332193c | 13,575 | pas | Pascal | vcl/XLSReadWrite6/SrcXLS/XLSNames5.pas | 1aq/PBox | 67ced599ee36ceaff097c6584f8100cf96006dfe | [
"MIT"
]
| null | null | null | vcl/XLSReadWrite6/SrcXLS/XLSNames5.pas | 1aq/PBox | 67ced599ee36ceaff097c6584f8100cf96006dfe | [
"MIT"
]
| null | null | null | vcl/XLSReadWrite6/SrcXLS/XLSNames5.pas | 1aq/PBox | 67ced599ee36ceaff097c6584f8100cf96006dfe | [
"MIT"
]
| null | null | null | unit XLSNames5;
{-
********************************************************************************
******* XLSReadWriteII V6.00 *******
******* *******
******* Copyright(C) 1999,2017 Lars Arvidsson, Axolot Data *******
******* *******
******* email: components@axolot.com *******
******* URL: http://www.axolot.com *******
********************************************************************************
** Users of the XLSReadWriteII component must accept the following **
** disclaimer of warranty: **
** **
** XLSReadWriteII is supplied as is. The author disclaims all warranties, **
** expressedor implied, including, without limitation, the warranties of **
** merchantability and of fitness for any purpose. The author assumes no **
** liability for damages, direct or consequential, which may result from the **
** use of XLSReadWriteII. **
********************************************************************************
}
{$B-}
{$H+}
{$R-}
{$I AxCompilers.inc}
{$I XLSRWII.inc}
interface
uses Classes, SysUtils, Contnrs,
Xc12Utils5, Xc12DataWorkbook5, Xc12Manager5,
BIFF_Names5,
XLSUtils5, XLSFormulaTypes5, XLSEncodeFmla5, XLSFormula5, XLSClassFactory5;
type TXLSNames = class;
TXLSName = class(TXc12DefinedName)
private
procedure SetName(const Value: AxUCString);
function GetArea: PXLS3dCellArea;
protected
FParent: TXLSNames;
procedure ClearDefinition;
procedure Compile;
function GetContent: AxUCString; override;
function GetDefinition: AxUCString;
// Do not overload SetContent of base class as SetDefinition also calls
// Compile, and SetContent can't do that as SetContent is called when
// file is read. At that time formulas can't be compiled until all data
// is read.
procedure SetDefinition(const Value: AxUCString);
// Hide props from TXc12DefinedName
property Ptgs;
property PtgsSz;
property Content;
property OrigContent;
property Deleted;
property Unused97;
public
constructor Create(AParent: TXLSNames);
procedure Update;
//* Returns True it the names area is on ASheetIndex and within ACol and ARow.
function Hit(const ASheetIndex, ACol, ARow: integer): boolean;
property Name: AxUCString read FName write SetName;
property Definition: AxUCString read GetDefinition write SetDefinition;
property Area: PXLS3dCellArea read GetArea;
end;
TXLSNames = class(TXc12DefinedNames)
private
function GetItems(Index: integer): TXLSName;
protected
FManager: TXc12Manager;
FFormulas: TXLSFormulaHandler;
function DoAdd(const AName,ADefinition: AxUCString; const ALocalSheetId: integer): TXLSName;
public
constructor Create(AClassFactory: TXLSClassFactory; AManager: TXc12Manager; AFormulas: TXLSFormulaHandler);
//* Copy the names that belongs to ASheetId to a Strings object.
//* If ASetObject is True, the Objects property of AList is assigned with
//* the relevant TXLSName object.
procedure ToStrings(const ASheetId: integer; AList: TStrings; const ASetObject: boolean = False);
procedure DumpNames(AList: TStrings);
//* Returns a name that is on ASheetIndex and has an area is within ACol and ARow. If not found,
//* Nil is returned.
function Hit(const ASheetIndex,ACol,ARow: integer): TXLSName;
function Add(const AName,ASheetName: AxUCString; const ACol,ARow: integer): TXLSName; overload;
function Add(const AName,ASheetName: AxUCString; const ACol1,ARow1,ACol2,ARow2: integer): TXLSName; overload;
function Add(const AName,ADefinition: AxUCString; const ALocalSheetId: integer = -1): TXLSName; overload;
// Creates a local name on Sheet ASheetName.
function Add(const AName,ADefinition,ASheetName: AxUCString): TXLSName; overload;
function Find(const AName: AxUCString): TXLSName;
property Items[Index: integer]: TXLSName read GetItems; default;
end;
TXLSNames_Int = class(TXLSNames)
protected
procedure AdjustSheetInsert(const ASheetIndex, ACount: integer);
procedure AdjustSheetDelete(const ASheetIndex, ACount: integer);
public
procedure AfterRead;
procedure AdjustSheetIndex(const ASheetIndex, ACount: integer);
property HashValid: boolean read FHashValid write FHashValid;
end;
implementation
{ TXLSNames }
function TXLSNames.Add(const AName,ADefinition: AxUCString; const ALocalSheetId: integer = -1): TXLSName;
begin
Result := DoAdd(AName,ADefinition,ALocalSheetId);
end;
function TXLSNames.Add(const AName, ADefinition, ASheetName: AxUCString): TXLSName;
var
i: integer;
begin
i := FManager.Worksheets.Find(ASheetName);
if i < 0 then begin
FManager.Errors.Error(ASheetName,XLSERR_FMLA_UNKNOWNSHEET);
Result := Nil;
end
else
Result := DoAdd(AName,ADefinition,i);
end;
function TXLSNames.Add(const AName, ASheetName: AxUCString; const ACol, ARow: integer): TXLSName;
var
Def: AxUCString;
begin
if FManager.Worksheets.Find(ASheetName) < 0 then begin
FManager.Errors.Error(ASheetName,XLSERR_FMLA_UNKNOWNSHEET);
Result := Nil;
end
else begin
Def := ASheetName + '!' + ColRowToRefStr(ACol,ARow,True,True);
Result := Add(AName,Def);
end;
end;
function TXLSNames.Add(const AName, ASheetName: AxUCString; const ACol1, ARow1, ACol2, ARow2: integer): TXLSName;
var
Def: AxUCString;
begin
if FManager.Worksheets.Find(ASheetName) < 0 then begin
FManager.Errors.Error(ASheetName,XLSERR_FMLA_UNKNOWNSHEET);
Result := Nil;
end
else begin
Def := ASheetName + '!' + AreaToRefStr(ACol1,ARow1,ACol2,ARow2,True,True,True,True);
Result := Add(AName,Def);
end;
end;
constructor TXLSNames.Create(AClassFactory: TXLSClassFactory; AManager: TXc12Manager; AFormulas: TXLSFormulaHandler);
begin
inherited Create(AClassFactory);
FManager := AManager;
FFormulas := AFormulas;
end;
function TXLSNames.DoAdd(const AName, ADefinition: AxUCString; const ALocalSheetId: integer): TXLSName;
begin
Result := Nil;
if Trim(AName) = '' then
FManager.Errors.Error('',XLSERR_NAME_EMPTY)
else begin
if (ALocalSheetId >= 0) and (FindIdInSheet(AName,ALocalSheetId) >= 0) then
FManager.Errors.Error(AName,XLSERR_NAME_DUPLICATE)
else if Find(AName) <> Nil then
FManager.Errors.Error(AName,XLSERR_NAME_DUPLICATE)
else begin
Result := TXLSName(inherited Add(AName,ALocalSheetId));
Result.Definition := ADefinition;
if FManager.Version = xvExcel97 then
{$ifdef XLS_BIFF}
FManager.Names97.Add(AName,ADefinition);
{$endif}
// Result.Compile;
end;
end;
end;
procedure TXLSNames.DumpNames(AList: TStrings);
var
i: integer;
S: AxUCString;
begin
for i := 0 to Count - 1 do begin
S := '"' + Items[i].Name + '","' + Items[i].Definition + '",';
if (Items[i].LocalSheetId >= 0) then
S := '"' + FManager.Worksheets[Items[i].LocalSheetId].Name + '"'
else
S := S + '"Workbook"';
AList.Add(S);
end;
end;
function TXLSNames.Find(const AName: AxUCString): TXLSName;
var
i: integer;
begin
i := FindId(AName,-1);
if (i >= 0) and not Items[i].Deleted then
Result := Items[i]
else
Result := Nil;
end;
function TXLSNames.GetItems(Index: integer): TXLSName;
begin
Result := TXLSName(inherited Items[Index]);
end;
function TXLSNames.Hit(const ASheetIndex,ACol, ARow: integer): TXLSName;
var
i: integer;
begin
for i := 0 to Count - 1 do begin
if Items[i].Hit(ASheetIndex,ACol,ARow) then begin
Result := Items[i];
Exit;
end;
end;
Result := Nil;
end;
procedure TXLSNames.ToStrings(const ASheetId: integer; AList: TStrings; const ASetObject: boolean);
var
i: integer;
S: AxUCString;
begin
for i := 0 to Count - 1 do begin
S := Items[i].Name;
if (Items[i].LocalSheetId < 0) or (Items[i].LocalSheetId = ASheetId) then begin
if ASetObject then
AList.AddObject(S,Items[i])
else
AList.Add(S);
end;
end;
end;
{ TXLSName }
procedure TXLSName.ClearDefinition;
begin
if FPtgs <> Nil then
FreeMem(FPtgs);
FPtgs := Nil;
FPtgsSz := 0;
FSimpleName := xsntNone;
end;
procedure TXLSName.Compile;
begin
if FPtgs = Nil then begin
FPtgsSz := FParent.FFormulas.EncodeFormula(FContent,FPtgs,-1);
if FPtgsSz = 0 then begin
FParent.FManager.Errors.Error('',XLSERR_FMLA_BADSHEETNAME);
Exit;
end;
end;
FSimpleName := IsSimpleName(FParent.FManager,FPtgs,FPtgsSz,@FArea);
end;
constructor TXLSName.Create(AParent: TXLSNames);
begin
FParent := AParent;
end;
function TXLSName.GetArea: PXLS3dCellArea;
begin
if FSimpleName > xsntNone then
Result := @FArea
else
Result := Nil;
end;
function TXLSName.GetContent: AxUCString;
begin
case FSimpleName of
xsntNone : begin
Result := FParent.FFormulas.DecodeFormula(Nil,-1,FPtgs,FPtgsSz,True);
Exit;
end;
xsntRef : Result := FParent.FManager.Worksheets[FArea.SheetIndex].QuotedName + '!' + ColRowToRefStrEnc(FArea.Col1,FArea.Row1);
xsntArea : Result := FParent.FManager.Worksheets[FArea.SheetIndex].QuotedName + '!' + AreaToRefStrEnc(FArea.Col1,FArea.Row1,FArea.Col2,FArea.Row2);
xsntError: Result := Xc12CellErrorNames[errRef];
end;
end;
function TXLSName.GetDefinition: AxUCString;
begin
case FSimpleName of
xsntNone : begin
if FPtgsSz > 0 then
Result := FParent.FFormulas.DecodeFormula(Nil,-1,FPtgs,FPtgsSz,False)
else
Result := '';
Exit;
end;
xsntRef : Result := FParent.FManager.Worksheets[FArea.SheetIndex].QuotedName + '!' + ColRowToRefStrEnc(FArea.Col1,FArea.Row1);
xsntArea : Result := FParent.FManager.Worksheets[FArea.SheetIndex].QuotedName + '!' + AreaToRefStrEnc(FArea.Col1,FArea.Row1,FArea.Col2,FArea.Row2);
xsntError: Result := Xc12CellErrorNames[errRef];
end;
end;
function TXLSName.Hit(const ASheetIndex, ACol, ARow: integer): boolean;
begin
case SimpleName of
xsntNone : Result := False;
xsntRef : Result := (SimpleArea.SheetIndex = ASheetIndex) and
((SimpleArea.Col1 and not COL_ABSFLAG) = ACol) and
((SimpleArea.Row1 and not ROW_ABSFLAG) = ARow);
xsntArea : Result := (SimpleArea.SheetIndex = ASheetIndex) and
((SimpleArea.Col1 and not COL_ABSFLAG) >= ACol) and
((SimpleArea.Row1 and not ROW_ABSFLAG) >= ARow) and
((SimpleArea.Col2 and not COL_ABSFLAG) <= ACol) and
((SimpleArea.Row2 and not ROW_ABSFLAG) <= ARow);
xsntError: Result := False;
else Result := False;
end;
end;
procedure TXLSName.SetDefinition(const Value: AxUCString);
begin
ClearDefinition;
FContent := Value;
Compile;
end;
procedure TXLSName.SetName(const Value: AxUCString);
begin
if FParent.Find(Value) <> Nil then
FParent.FManager.Errors.Error(Value,XLSERR_NAME_DUPLICATE)
else begin
FName := Value;
TXLSNames_Int(FParent).HashValid := False;
end;
end;
procedure TXLSName.Update;
begin
FSimpleName := IsSimpleName(FParent.FManager,FPtgs,FPtgsSz,@FArea);
end;
{ TXLSNames_Int }
procedure TXLSNames_Int.AdjustSheetDelete(const ASheetIndex, ACount: integer);
var
i: integer;
N: TXLSName;
begin
for i := 0 to Count - 1 do begin
N := Items[i];
if (N.LocalSheetId >= ASheetIndex) and (N.LocalSheetId <= (ASheetIndex + ACount - 1)) then
N.Deleted := True
else begin
case N.SimpleName of
xsntNone: begin
FFormulas.AdjustSheetIndex(N.Ptgs,N.PtgsSz,ASheetIndex,-ACount);
N.LocalSheetId := N.LocalSheetId - ACount;
end;
xsntRef,
xsntArea: begin
if N.Area.SheetIndex >= ASheetIndex then begin
if (N.Area.SheetIndex) < (ASheetIndex + ACount) then begin
N.Area.SheetIndex := -1;
N.FSimpleName := xsntError;
end
else
N.Area.SheetIndex := N.Area.SheetIndex - ACount;
end;
end;
xsntError: ;
end;
end;
end;
end;
procedure TXLSNames_Int.AdjustSheetIndex(const ASheetIndex, ACount: integer);
begin
if ACount < 0 then
AdjustSheetDelete(ASheetIndex,-ACount)
else
AdjustSheetInsert(ASheetIndex,ACount);
end;
procedure TXLSNames_Int.AdjustSheetInsert(const ASheetIndex, ACount: integer);
var
i,j: integer;
N: TXLSName;
begin
for i := 0 to Count - 1 do begin
N := Items[i];
case N.SimpleName of
xsntNone: begin
FFormulas.AdjustSheetIndex(N.Ptgs,N.PtgsSz,ASheetIndex,ACount);
N.LocalSheetId := N.LocalSheetId + ACount;
end;
xsntRef,
xsntArea: begin
if N.Area.SheetIndex >= ASheetIndex then begin
j := N.Area.SheetIndex + ACount;
if (j >= 0) and (j < XLS_MAXSHEETS) then
N.Area.SheetIndex := N.Area.SheetIndex + ACount
else
N.Area.SheetIndex := -1;
end;
end;
xsntError: ;
end;
end;
end;
procedure TXLSNames_Int.AfterRead;
var
i: integer;
begin
for i := 0 to Count - 1 do
Items[i].Compile;
end;
end.
| 30.71267 | 151 | 0.647219 |
fcd517c1c0332dc88c02d712609aff1bb937680d | 1,230 | pas | Pascal | source/Plugins/Plugin_VariablesCmdLine.pas | atkins126/CodeImatic.build | 00af106c2e300d57c7cc8bcd81fec442325dfc25 | [
"Apache-2.0"
]
| 1 | 2021-03-04T02:11:47.000Z | 2021-03-04T02:11:47.000Z | source/Plugins/Plugin_VariablesCmdLine.pas | atkins126/CodeImatic.build | 00af106c2e300d57c7cc8bcd81fec442325dfc25 | [
"Apache-2.0"
]
| 2 | 2020-03-10T00:00:18.000Z | 2020-03-14T13:16:49.000Z | source/Plugins/Plugin_VariablesCmdLine.pas | atkins126/CodeImatic.build | 00af106c2e300d57c7cc8bcd81fec442325dfc25 | [
"Apache-2.0"
]
| 4 | 2019-12-26T05:41:42.000Z | 2021-03-04T02:11:51.000Z | unit Plugin_VariablesCmdLine;
interface
uses Classes, Plugin, uPSRuntime, uPSCompiler, uPSI_API_VariablesCmdLine,
PluginsMapFactory;
type
tPlugin_VariablesCmdLine = class(TPascalScriptInternalPlugin)
private
protected
public
function CustomOnUses(var aCompiler: TPSPascalCompiler): Boolean; override;
procedure RegisterFunction(var aExec: TPSExec); override;
procedure SetVariantToClass(var aExec: TPSExec); override;
procedure RegisterImport; override;
end;
implementation
function tPlugin_VariablesCmdLine.CustomOnUses(var aCompiler: TPSPascalCompiler): Boolean;
begin
Result := True;
SIRegister_API_VariablesCmdLine(aCompiler);
AddImportedClassVariable(aCompiler, 'VariablesCmdLine', 'TAPI_VariablesCmdLine');
end;
procedure tPlugin_VariablesCmdLine.RegisterFunction(var aExec: TPSExec);
begin
end;
procedure tPlugin_VariablesCmdLine.SetVariantToClass(var aExec: TPSExec);
begin
uPSRuntime.SetVariantToClass(aExec.GetVarNo(aExec.GetVar('VariablesCmdLine')),
foAPI_Output);
end;
procedure tPlugin_VariablesCmdLine.RegisterImport;
begin
RIRegister_API_VariablesCmdLine(FImp);
end;
Initialization
begin
tPluginsMapFactory.RegisterClass(tPlugin_VariablesCmdLine);
end;
end.
| 23.653846 | 90 | 0.820325 |
c31a6597333e3ce2ac310508c6b167c6f88b00bc | 3,139 | pas | Pascal | LogViewer.Receivers.Winipc.Settings.pas | atkins126/LogViewer | 47b331478b74c89ffffc48bb20bbe62f4362c556 | [
"Apache-2.0"
]
| null | null | null | LogViewer.Receivers.Winipc.Settings.pas | atkins126/LogViewer | 47b331478b74c89ffffc48bb20bbe62f4362c556 | [
"Apache-2.0"
]
| null | null | null | LogViewer.Receivers.Winipc.Settings.pas | atkins126/LogViewer | 47b331478b74c89ffffc48bb20bbe62f4362c556 | [
"Apache-2.0"
]
| null | null | null | {
Copyright (C) 2013-2021 Tim Sinaeve tim.sinaeve@gmail.com
Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
}
unit LogViewer.Receivers.Winipc.Settings;
{ Persistable settings for WinIPC receivers. }
interface
uses
System.Classes,
Spring;
type
TWinipcSettings = class(TPersistent)
const
DEFAULT_POLLING_INTERVAL = 10;
private
FOnChanged : Event<TNotifyEvent>;
FEnabled : Boolean;
FPollingInterval : Integer;
protected
{$REGION 'property access methods'}
function GetOnChanged: IEvent<TNotifyEvent>;
function GetEnabled: Boolean;
procedure SetEnabled(const Value: Boolean);
function GetPollingInterval: Integer;
procedure SetPollingInterval(const Value: Integer);
{$ENDREGION}
procedure Changed;
public
procedure AfterConstruction; override;
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
property OnChanged: IEvent<TNotifyEvent>
read GetOnChanged;
published
property Enabled: Boolean
read GetEnabled write SetEnabled;
property PollingInterval: Integer // in ms
read GetPollingInterval write SetPollingInterval
default DEFAULT_POLLING_INTERVAL;
end;
implementation
{$REGION 'construction and destruction'}
procedure TWinipcSettings.AfterConstruction;
begin
inherited AfterConstruction;
FPollingInterval := DEFAULT_POLLING_INTERVAL;
FOnChanged.UseFreeNotification := False;
end;
destructor TWinipcSettings.Destroy;
begin
FOnChanged.RemoveAll(Self);
inherited Destroy;
end;
{$ENDREGION}
{$REGION 'property access methods'}
function TWinipcSettings.GetEnabled: Boolean;
begin
Result := FEnabled;
end;
procedure TWinipcSettings.SetEnabled(const Value: Boolean);
begin
if Value <> Enabled then
begin
FEnabled := Value;
Changed;
end;
end;
function TWinipcSettings.GetOnChanged: IEvent<TNotifyEvent>;
begin
Result := FOnChanged;
end;
function TWinipcSettings.GetPollingInterval: Integer;
begin
Result := FPollingInterval;
end;
procedure TWinipcSettings.SetPollingInterval(const Value: Integer);
begin
if Value <> PollingInterval then
begin
FPollingInterval := Value;
Changed;
end;
end;
{$ENDREGION}
{$REGION 'protected methods'}
procedure TWinipcSettings.Changed;
begin
FOnChanged.Invoke(Self);
end;
{$ENDREGION}
{$REGION 'public methods'}
procedure TWinipcSettings.Assign(Source: TPersistent);
var
LSettings: TWinipcSettings;
begin
if Source is TWinipcSettings then
begin
LSettings := TWinipcSettings(Source);
Enabled := LSettings.Enabled;
end
else
inherited Assign(Source);
end;
{$ENDREGION}
end.
| 22.262411 | 74 | 0.751513 |
4708684c939b499c732d721b96f5325ce89edc92 | 412 | dpr | Pascal | U9030/U9030DisAsm.dpr | sboydlns/univacemulators | c630b2497bee9cb9a18b4fa05be9157d7161bca3 | [
"MIT"
]
| 2 | 2021-02-09T21:54:54.000Z | 2021-09-04T03:30:50.000Z | U9030/U9030DisAsm.dpr | sboydlns/univacemulators | c630b2497bee9cb9a18b4fa05be9157d7161bca3 | [
"MIT"
]
| null | null | null | U9030/U9030DisAsm.dpr | sboydlns/univacemulators | c630b2497bee9cb9a18b4fa05be9157d7161bca3 | [
"MIT"
]
| null | null | null | program U9030DisAsm;
uses
Vcl.Forms,
U9030DisAsmFrm in 'U9030DisAsmFrm.pas' {U9030DisAsmForm},
CardFile in '..\Common\CardFile.pas',
EmulatorTypes in '..\Common\EmulatorTypes.pas',
U9030Types in 'U9030Types.pas';
{$R *.res}
begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TU9030DisAsmForm, U9030DisAsmForm);
Application.Run;
end.
| 22.888889 | 61 | 0.723301 |
fc7353c66e17a6f9036da344a153bfc6866c733c | 5,861 | dfm | Pascal | source/uFrmConfig.dfm | roneysousa/infoboletos | e709fbf32a9f2541a8d1e54ecf1aed672ba121f4 | [
"MIT"
]
| null | null | null | source/uFrmConfig.dfm | roneysousa/infoboletos | e709fbf32a9f2541a8d1e54ecf1aed672ba121f4 | [
"MIT"
]
| null | null | null | source/uFrmConfig.dfm | roneysousa/infoboletos | e709fbf32a9f2541a8d1e54ecf1aed672ba121f4 | [
"MIT"
]
| null | null | null | object FrmConfig: TFrmConfig
Left = 192
Top = 124
BorderIcons = [biSystemMenu]
BorderStyle = bsSingle
Caption = 'Configura'#231#245'es'
ClientHeight = 500
ClientWidth = 587
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
Position = poScreenCenter
OnShow = FormShow
PixelsPerInch = 96
TextHeight = 13
object Panel1: TPanel
Left = 0
Top = 0
Width = 587
Height = 459
Align = alClient
TabOrder = 0
object Label1: TLabel
Left = 24
Top = 10
Width = 27
Height = 13
Caption = 'CNPJ'
FocusControl = dbeCNPJ
end
object Label2: TLabel
Left = 24
Top = 50
Width = 63
Height = 13
Caption = 'Raz'#227'o Social'
FocusControl = dbeRazao
end
object Label3: TLabel
Left = 24
Top = 90
Width = 40
Height = 13
Caption = 'Fantasia'
FocusControl = dbeFantasia
end
object Label4: TLabel
Left = 24
Top = 130
Width = 46
Height = 13
Caption = 'Endere'#231'o'
FocusControl = txtEndereco
end
object Label5: TLabel
Left = 24
Top = 239
Width = 52
Height = 13
Caption = 'Mensagem'
FocusControl = dbeMsg1
end
object Label6: TLabel
Left = 352
Top = 282
Width = 61
Height = 13
Caption = 'Mensagem 2'
FocusControl = dbeMsg2
Visible = False
end
object Label7: TLabel
Left = 344
Top = 322
Width = 24
Height = 13
Caption = 'Logo'
FocusControl = DBImage1
Visible = False
end
object Label8: TLabel
Left = 24
Top = 281
Width = 106
Height = 13
Caption = 'Digito C'#243'digo Cedente'
FocusControl = dbeCarteira
Transparent = True
end
object dbeCNPJ: TDBEdit
Left = 24
Top = 26
Width = 186
Height = 21
DataField = 'CNPJ'
DataSource = dsCadastro
MaxLength = 18
TabOrder = 0
end
object dbeRazao: TDBEdit
Left = 24
Top = 66
Width = 500
Height = 21
CharCase = ecUpperCase
DataField = 'RAZAO'
DataSource = dsCadastro
TabOrder = 1
OnExit = dbeRazaoExit
end
object dbeFantasia: TDBEdit
Left = 24
Top = 106
Width = 500
Height = 21
CharCase = ecUpperCase
DataField = 'FANTASIA'
DataSource = dsCadastro
TabOrder = 2
OnExit = dbeFantasiaExit
end
object txtEndereco: TDBMemo
Left = 24
Top = 146
Width = 281
Height = 89
DataField = 'ENDERECO'
DataSource = dsCadastro
TabOrder = 3
OnExit = txtEnderecoExit
end
object dbeMsg1: TDBEdit
Left = 24
Top = 258
Width = 500
Height = 21
DataField = 'MENSAGEM2'
DataSource = dsCadastro
TabOrder = 4
OnExit = dbeMsg1Exit
end
object dbeMsg2: TDBEdit
Left = 352
Top = 298
Width = 193
Height = 21
DataField = 'MENSAGEM1'
DataSource = dsCadastro
TabOrder = 5
Visible = False
OnExit = dbeMsg2Exit
end
object DBImage1: TDBImage
Left = 344
Top = 338
Width = 105
Height = 105
DataField = 'LOGO'
DataSource = dsCadastro
TabOrder = 6
Visible = False
end
object dbeCarteira: TDBEdit
Left = 24
Top = 297
Width = 20
Height = 21
DataField = 'CARTEIRA'
DataSource = dsCadastro
TabOrder = 7
OnKeyPress = dbeCarteiraKeyPress
end
object DBRadioGroup1: TDBRadioGroup
Left = 24
Top = 322
Width = 185
Height = 63
Caption = '[ Modelo Texto Boleto ]'
DataField = 'MODELO_TEXTO_BOLETO'
DataSource = dsCadastro
Items.Strings = (
'Modelo 1'
'Modelo 2')
TabOrder = 8
Values.Strings = (
'1'
'2')
end
end
object Panel2: TPanel
Left = 0
Top = 459
Width = 587
Height = 41
Align = alBottom
Color = clNavy
TabOrder = 1
object BitBtn1: TBitBtn
Left = 351
Top = 8
Width = 75
Height = 25
Caption = '&OK'
ModalResult = 1
TabOrder = 0
OnClick = BitBtn1Click
Glyph.Data = {
DE010000424DDE01000000000000760000002800000024000000120000000100
0400000000006801000000000000000000001000000000000000000000000000
80000080000000808000800000008000800080800000C0C0C000808080000000
FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00333333333333
3333333333333333333333330000333333333333333333333333F33333333333
00003333344333333333333333388F3333333333000033334224333333333333
338338F3333333330000333422224333333333333833338F3333333300003342
222224333333333383333338F3333333000034222A22224333333338F338F333
8F33333300003222A3A2224333333338F3838F338F33333300003A2A333A2224
33333338F83338F338F33333000033A33333A222433333338333338F338F3333
0000333333333A222433333333333338F338F33300003333333333A222433333
333333338F338F33000033333333333A222433333333333338F338F300003333
33333333A222433333333333338F338F00003333333333333A22433333333333
3338F38F000033333333333333A223333333333333338F830000333333333333
333A333333333333333338330000333333333333333333333333333333333333
0000}
NumGlyphs = 2
end
object BitBtn2: TBitBtn
Left = 447
Top = 8
Width = 75
Height = 25
Caption = '&Cancelar'
TabOrder = 1
OnClick = BitBtn2Click
Kind = bkCancel
end
end
object dsCadastro: TDataSource
DataSet = dmDados.cdsConfig
Left = 336
Top = 224
end
end
| 23.728745 | 72 | 0.615083 |
fc5e5466e7da6947a34762d46dea56100ac38a99 | 489 | dpr | Pascal | Samples/Low Level/02 Context Popup/ContextPopup.dpr | FDE-LC2L/RibbonFramework | 4769c64e17b56cc794a5263a63ac260d733ac665 | [
"BSD-3-Clause"
]
| 42 | 2020-06-18T05:41:11.000Z | 2022-03-15T13:26:23.000Z | Samples/Low Level/02 Context Popup/ContextPopup.dpr | FDE-LC2L/RibbonFramework | 4769c64e17b56cc794a5263a63ac260d733ac665 | [
"BSD-3-Clause"
]
| 14 | 2018-12-12T10:06:24.000Z | 2020-02-06T16:05:43.000Z | Samples/Low Level/02 Context Popup/ContextPopup.dpr | FDE-LC2L/RibbonFramework | 4769c64e17b56cc794a5263a63ac260d733ac665 | [
"BSD-3-Clause"
]
| 16 | 2020-05-29T12:01:06.000Z | 2022-02-13T07:53:17.000Z | program ContextPopup;
{$R 'ContextPopupUI.res' 'Ribbon\ContextPopupUI.rc'}
uses
Forms,
FMain in 'FMain.pas' {FormMain},
ContextPopupConst in 'Ribbon\ContextPopupConst.pas',
UIRibbonApi in '..\..\..\Lib\UIRibbonApi.pas',
WinApiEx in '..\..\..\Lib\WinApiEx.pas';
{$R *.res}
begin
ReportMemoryLeaksOnShutdown := True;
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TFormMain, FormMain);
Application.Run;
end.
| 23.285714 | 55 | 0.691207 |
fcf8ee77c183b862e1a7f1d7287c1d9ea8e9faec | 1,409 | dfm | Pascal | windows/src/desktop/kmshell/main/UfrmHTML.dfm | srl295/keyman | 4dfd0f71f3f4ccf81d1badbd824900deee1bb6d1 | [
"MIT"
]
| 219 | 2017-06-21T03:37:03.000Z | 2022-03-27T12:09:28.000Z | windows/src/desktop/kmshell/main/UfrmHTML.dfm | srl295/keyman | 4dfd0f71f3f4ccf81d1badbd824900deee1bb6d1 | [
"MIT"
]
| 4,451 | 2017-05-29T02:52:06.000Z | 2022-03-31T23:53:23.000Z | windows/src/desktop/kmshell/main/UfrmHTML.dfm | srl295/keyman | 4dfd0f71f3f4ccf81d1badbd824900deee1bb6d1 | [
"MIT"
]
| 72 | 2017-05-26T04:08:37.000Z | 2022-03-03T10:26:20.000Z | object frmHTML: TfrmHTML
Left = 192
Top = 107
ClientHeight = 313
ClientWidth = 477
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
KeyPreview = True
OldCreateOrder = False
Position = poScreenCenter
OnCreate = FormCreate
OnDestroy = FormDestroy
OnKeyDown = FormKeyDown
DesignSize = (
477
313)
PixelsPerInch = 96
TextHeight = 13
object panHTML: TPanel
Left = 0
Top = 0
Width = 477
Height = 273
Anchors = [akLeft, akTop, akRight, akBottom]
BevelOuter = bvNone
TabOrder = 0
end
object cmdOK: TButton
Left = 202
Top = 280
Width = 73
Height = 25
Anchors = [akBottom]
Caption = 'OK'
Default = True
ModalResult = 1
TabOrder = 2
end
object cmdPrint: TButton
Left = 8
Top = 280
Width = 73
Height = 25
Anchors = [akLeft, akBottom]
Caption = '&Print...'
TabOrder = 1
OnClick = cmdPrintClick
end
object cmdBack: TButton
Left = 87
Top = 280
Width = 30
Height = 25
Anchors = [akLeft, akBottom]
Caption = '<'
TabOrder = 3
OnClick = cmdBackClick
end
object cmdForward: TButton
Left = 123
Top = 280
Width = 30
Height = 25
Anchors = [akLeft, akBottom]
Caption = '>'
TabOrder = 4
OnClick = cmdForwardClick
end
end
| 19.040541 | 48 | 0.613911 |
f12d486915c88e7ed02f63589f874b5de3816ec2 | 743 | pas | Pascal | 2. Semester/AUD/Uebung 4/WC_ADT_TEST.pas | AndreasRoither/SE-Hagenberg | 8c437bcfef203b84475224b8efecafdcede8f2b9 | [
"MIT"
]
| null | null | null | 2. Semester/AUD/Uebung 4/WC_ADT_TEST.pas | AndreasRoither/SE-Hagenberg | 8c437bcfef203b84475224b8efecafdcede8f2b9 | [
"MIT"
]
| null | null | null | 2. Semester/AUD/Uebung 4/WC_ADT_TEST.pas | AndreasRoither/SE-Hagenberg | 8c437bcfef203b84475224b8efecafdcede8f2b9 | [
"MIT"
]
| null | null | null | (* WC_ADT_TEST 23.04.2017 *)
(* Container for strings *)
(* Hidden data test *)
PROGRAM WC_ADT_Test;
USES WC_ADT;
VAR f1: POINTER;
BEGIN
InitTree(f1);
(* test cases *)
WriteLn('== WC_ADT_Test ==');
WriteLn('Empty Test: ', IsEmpty(f1));
WriteLn('Inserted Test');
Insert(f1,'Test');
WriteLn('Inserted Hallo');
Insert(f1,'Hallo');
WriteLn('Empty Test: ', IsEmpty(f1));
WriteLn('Contains Test: ', Contains(f1,'Test'));
WriteLn('Contains Hallo: ', Contains(f1,'Hallo'));
WriteLn('Inserted Hallo');
Insert(f1,'Hallo');
Remove(f1,'Hallo');
WriteLn('Contains Hallo: ', Contains(f1,'Hallo'));
WriteLn('Duplicate texts are not saved.');
DisposeTree(f1);
END.
| 21.852941 | 52 | 0.598923 |
474b50fdd9f5ba08159feee6702b3a861ae43934 | 1,720 | pas | Pascal | Source/Services/LexRuntimeV2/Base/Transform/AWS.LexRuntimeV2.Transform.SlotMarshaller.pas | herux/aws-sdk-delphi | 4ef36e5bfc536b1d9426f78095d8fda887f390b5 | [
"Apache-2.0"
]
| 67 | 2021-07-28T23:47:09.000Z | 2022-03-15T11:48:35.000Z | Source/Services/LexRuntimeV2/Base/Transform/AWS.LexRuntimeV2.Transform.SlotMarshaller.pas | herux/aws-sdk-delphi | 4ef36e5bfc536b1d9426f78095d8fda887f390b5 | [
"Apache-2.0"
]
| 5 | 2021-09-01T09:31:16.000Z | 2022-03-16T18:19:21.000Z | Source/Services/LexRuntimeV2/Base/Transform/AWS.LexRuntimeV2.Transform.SlotMarshaller.pas | herux/aws-sdk-delphi | 4ef36e5bfc536b1d9426f78095d8fda887f390b5 | [
"Apache-2.0"
]
| 13 | 2021-07-29T02:41:16.000Z | 2022-03-16T10:22:38.000Z | unit AWS.LexRuntimeV2.Transform.SlotMarshaller;
interface
uses
AWS.LexRuntimeV2.Model.Slot,
AWS.Transform.RequestMarshaller,
AWS.LexRuntimeV2.Transform.ValueMarshaller;
type
ISlotMarshaller = IRequestMarshaller<TSlot, TJsonMarshallerContext>;
TSlotMarshaller = class(TInterfacedObject, IRequestMarshaller<TSlot, TJsonMarshallerContext>)
strict private
class var FInstance: ISlotMarshaller;
class constructor Create;
public
procedure Marshall(ARequestObject: TSlot; Context: TJsonMarshallerContext);
class function Instance: ISlotMarshaller; static;
end;
implementation
{ TSlotMarshaller }
procedure TSlotMarshaller.Marshall(ARequestObject: TSlot; Context: TJsonMarshallerContext);
begin
if ARequestObject.IsSetShape then
begin
Context.Writer.WriteName('shape');
Context.Writer.WriteString(ARequestObject.Shape.Value);
end;
if ARequestObject.IsSetValue then
begin
Context.Writer.WriteName('value');
Context.Writer.WriteBeginObject;
TValueMarshaller.Instance.Marshall(ARequestObject.Value, Context);
Context.Writer.WriteEndObject;
end;
if ARequestObject.IsSetValues then
begin
Context.Writer.WriteName('values');
Context.Writer.WriteBeginArray;
for var ARequestObjectValuesListValue in ARequestObject.Values do
begin
Context.Writer.WriteBeginObject;
TSlotMarshaller.Instance.Marshall(ARequestObjectValuesListValue, Context);
Context.Writer.WriteEndObject;
end;
Context.Writer.WriteEndArray;
end;
end;
class constructor TSlotMarshaller.Create;
begin
FInstance := TSlotMarshaller.Create;
end;
class function TSlotMarshaller.Instance: ISlotMarshaller;
begin
Result := FInstance;
end;
end.
| 26.461538 | 95 | 0.783721 |
c300e7059a9b476a1376c71a9c60ed835311c4cf | 2,627 | pas | Pascal | dos/0117.pas | nickelsworth/swag | 7c21c0da2291fc249b9dc5cfe121a7672a4ffc08 | [
"BSD-2-Clause"
]
| 11 | 2015-12-12T05:13:15.000Z | 2020-10-14T13:32:08.000Z | dos/0117.pas | nickelsworth/swag | 7c21c0da2291fc249b9dc5cfe121a7672a4ffc08 | [
"BSD-2-Clause"
]
| null | null | null | dos/0117.pas | nickelsworth/swag | 7c21c0da2291fc249b9dc5cfe121a7672a4ffc08 | [
"BSD-2-Clause"
]
| 8 | 2017-05-05T05:24:01.000Z | 2021-07-03T20:30:09.000Z | uses
crt;
type
EXEHEAD=record
ID:array [1..2]of char;
LASTPAGE:word;
PAGES:word;
RELOCATION:word;
HEADERSIZE:word;
MIN:word;
MAX:word;
OFFSET:word;
SP:word;
CHECKSUM:word;
IP:word;
CS:word;
FIRST:WORD;
OVERLAY:WORD;
end;
var
exe:exehead;
f,f1,f2:file;
s:string[12];
w:byte;
buf:array[1..4096]of byte;
i,j:word;
function FILEEXISTS(FILENAME:STRING) : BOOLEAN;
var
f:file;
begin
{$I-}
assign(f,fileName);
reset(f);
close(f);
{$I+}
FILEEXISTS:=(ioresult=0) and (fileName<>'');
end;
begin
textattr:=white;
writeln;
writeln('MARKEXE, (C) Copyright DOTAN BARAK, 1997. ver 1.0');
writeln('Put copywrite message in an EXE file.');
writeln;
writeln;
textattr:=lightgray;
if paramcount<2 then
begin
writeln('usage: MARKEXE [exefile] [textfile]');
writeln;
halt(1);
end;
s:=paramstr(1);
if not fileexists(s) then
begin
writeln('THE FILE ',s, ' NOT FOUND !');
halt(1)
end;
if not fileexists(paramstr(2)) then
begin
writeln('THE FILE ',paramstr(2), ' NOT FOUND !');
halt(1)
end;
for w:=1 to length(s) do
s[w]:=upcase(s[w]);
assign(f,paramstr(1));
reset(f,1);
blockread(f,exe,sizeof(exe));
if (exe.id<>'MZ') then
if (exe.id<>'ZM') then
begin
close(f);
writeln('The file ',s,' is not an EXE file.');
halt(255);
end;
assign(f1,paramstr(2));
reset(f1,1);
assign(f2,'MARKEXE.$$$');
rewrite(f2,1);
seek(f,0);
blockread(f,buf,exe.headersize*16,i);
blockwrite(f2,buf,i);
repeat
blockread(f1,buf,4096,i);
blockwrite(f2,buf,i,j);
until (i<>4096) or (i<>j);
j:=filesize(f2) div 16;
i:=filesize(f2) mod 16;
if i<>0 then
begin
exe.headersize:=j+1;
fillchar(buf,16,0);
blockwrite(f2,buf,16-i);
end
else
exe.headersize:=j;
repeat
blockread(f,buf,4096,i);
blockwrite(f2,buf,i,j);
until (i<>4096) or (i<>j);
i:=filesize(f2);
exe.lastpage:=i mod 512;
exe.pages:=(i div 512)+1;
seek(f2,0);
blockwrite(f2,exe,sizeof(exe));
close(f);
erase(f);
close(f1);
close(f2);
assign(f,'MARKEXE.$$$');
rename(f,s);
writeln(' The file ',s,' was marked .');
end.
| 23.04386 | 67 | 0.497906 |
47c2b3da2d3010cf88a14d48670b1b1302f464ae | 12,140 | pas | Pascal | IGDIPlusHelpers.pas | gzwplato/IGDIPlusMod | 9e24c4932de730813f4972426519829ee22c5e26 | [
"Zlib"
]
| 18 | 2020-01-15T09:06:14.000Z | 2022-01-13T09:46:31.000Z | IGDIPlusHelpers.pas | jackdp/IGDIPlusMod | 9e24c4932de730813f4972426519829ee22c5e26 | [
"Zlib"
]
| null | null | null | IGDIPlusHelpers.pas | jackdp/IGDIPlusMod | 9e24c4932de730813f4972426519829ee22c5e26 | [
"Zlib"
]
| 6 | 2020-02-13T05:27:47.000Z | 2021-09-18T14:28:20.000Z | unit IGDIPlusHelpers;
{$IFDEF FPC}
{$mode delphi}
{$I IGDIPlusAPI_FPC}
{$ENDIF}
{$IFDEF DCC}{$I IGDIPlusAPI_DCC.inc}{$ENDIF}
interface
uses
Classes, SysUtils, Graphics, Types,
IGDIPlus
{$IFDEF DELPHIXE2_OR_ABOVE},System.UITypes{$ENDIF}
;
{$IFDEF FPC}
type
TPointFHelper = record helper for Types.TPointF
public
class function Create(const ax, ay: Single): TPointF; overload; static; inline;
class function Create(const apt: TPoint): TPointF; overload; static; inline;
end;
{$ENDIF}
type
TGPHatchStyleDynArray = array of TIGPHatchStyle;
function GPPointF(const ax, ay: Single): TPointF; overload;
function GPPointF(const apt: TPoint): TPointF; overload;
function GPPointFMove(const Point: TPointF; const dx, dy: Single): TPointF;
function GPColor(const AColor: TColor; Alpha: Byte = 255): TAlphaColor;
{$IFDEF MSWINDOWS}
function GPTextWidthF(gr: IGPGraphics; Text: string; Font: IGPFont; px: Single = 0; py: Single = 0): Single;
function GPTextHeightF(gr: IGPGraphics; Text: string; Font: IGPFont; px: Single = 0; py: Single = 0): Single;
{$ENDIF}
function GPHatchStyleToStrID(const HatchStyle: TIGPHatchStyle): string;
function GPHatchStyleToDisplayName(const HatchStyle: TIGPHatchStyle): string;
function GPTryStrIDToHatchStyle(const StrID: string; var hs: TIGPHatchStyle): Boolean;
function GPGetAllHatchStylesArray: TGPHatchStyleDynArray;
implementation
function GPGetAllHatchStylesArray: TGPHatchStyleDynArray;
var
i: integer;
begin
SetLength(Result, GPHatchStyleTotal);
for i := 0 to High(Result) do
Result[i] := TIGPHatchStyle(i);
end;
function GPHatchStyleToStrID(const HatchStyle: TIGPHatchStyle): string;
var
s: string;
begin
case HatchStyle of
HatchStyleHorizontal: s := 'Horizontal';
HatchStyleVertical: s := 'Vertical';
HatchStyleForwardDiagonal: s := 'ForwardDiagonal';
HatchStyleBackwardDiagonal: s := 'BackwardDiagonal';
HatchStyleCross: s := 'Cross';
HatchStyleDiagonalCross: s := 'DiagonalCross';
HatchStyle05Percent: s := '05Percent';
HatchStyle10Percent: s := '10Percent';
HatchStyle20Percent: s := '20Percent';
HatchStyle25Percent: s := '25Percent';
HatchStyle30Percent: s := '30Percent';
HatchStyle40Percent: s := '40Percent';
HatchStyle50Percent: s := '50Percent';
HatchStyle60Percent: s := '60Percent';
HatchStyle70Percent: s := '70Percent';
HatchStyle75Percent: s := '75Percent';
HatchStyle80Percent: s := '80Percent';
HatchStyle90Percent: s := '90Percent';
HatchStyleLightDownwardDiagonal: s := 'LightDownwardDiagonal';
HatchStyleLightUpwardDiagonal: s:= 'LightUpwardDiagonal';
HatchStyleDarkDownwardDiagonal: s := 'DarkDownwardDiagonal';
HatchStyleDarkUpwardDiagonal: s := 'DarkUpwardDiagonal';
HatchStyleWideDownwardDiagonal: s := 'WideDownwardDiagonal';
HatchStyleWideUpwardDiagonal: s := 'WideUpwardDiagonal';
HatchStyleLightVertical: s := 'LightVertical';
HatchStyleLightHorizontal: s := 'LightHorizontal';
HatchStyleNarrowVertical: s := 'NarrowVertical';
HatchStyleNarrowHorizontal: s := 'NarrowHorizontal';
HatchStyleDarkVertical: s := 'DarkVertical';
HatchStyleDarkHorizontal: s := 'DarkHorizontal';
HatchStyleDashedDownwardDiagonal: s := 'DashedDownwardDiagonal';
HatchStyleDashedUpwardDiagonal: s := 'DashedUpwardDiagonal';
HatchStyleDashedHorizontal: s := 'DashedHorizontal';
HatchStyleDashedVertical: s := 'DashedVertical';
HatchStyleSmallConfetti: s := 'SmallConfetti';
HatchStyleLargeConfetti: s := 'LargeConfetti';
HatchStyleZigZag: s := 'ZigZag';
HatchStyleWave: s := 'Wave';
HatchStyleDiagonalBrick: s := 'DiagonalBrick';
HatchStyleHorizontalBrick: s := 'HorizontalBrick';
HatchStyleWeave: s := 'Weave';
HatchStylePlaid: s := 'Plaid';
HatchStyleDivot: s := 'Divot';
HatchStyleDottedGrid: s := 'DottedGrid';
HatchStyleDottedDiamond: s := 'DottedDiamond';
HatchStyleShingle: s := 'Shingle';
HatchStyleTrellis: s := 'Trellis';
HatchStyleSphere: s := 'Sphere';
HatchStyleSmallGrid: s := 'SmallGrid';
HatchStyleSmallCheckerBoard: s := 'SmallCheckerBoard';
HatchStyleLargeCheckerBoard: s := 'LargeCheckerBoard';
HatchStyleOutlinedDiamond: s := 'OutlinedDiamond';
HatchStyleSolidDiamond: s := 'SolidDiamond';
end;
Result := s;
end;
function GPHatchStyleToDisplayName(const HatchStyle: TIGPHatchStyle): string;
var
s: string;
begin
case HatchStyle of
HatchStyleHorizontal: s := 'Horizontal';
HatchStyleVertical: s := 'Vertical';
HatchStyleForwardDiagonal: s := 'Forward Diagonal';
HatchStyleBackwardDiagonal: s := 'Backward Diagonal';
HatchStyleCross: s := 'Cross';
HatchStyleDiagonalCross: s := 'Diagonal Cross';
HatchStyle05Percent: s := '5%';
HatchStyle10Percent: s := '10%';
HatchStyle20Percent: s := '20%';
HatchStyle25Percent: s := '25%';
HatchStyle30Percent: s := '30%';
HatchStyle40Percent: s := '40%';
HatchStyle50Percent: s := '50%';
HatchStyle60Percent: s := '60%';
HatchStyle70Percent: s := '70%';
HatchStyle75Percent: s := '75%';
HatchStyle80Percent: s := '80%';
HatchStyle90Percent: s := '90%';
HatchStyleLightDownwardDiagonal: s := 'Light Downward Diagonal';
HatchStyleLightUpwardDiagonal: s:= 'Light Upward Diagonal';
HatchStyleDarkDownwardDiagonal: s := 'Dark Downward Diagonal';
HatchStyleDarkUpwardDiagonal: s := 'Dark Upward Diagonal';
HatchStyleWideDownwardDiagonal: s := 'Wide Downward Diagonal';
HatchStyleWideUpwardDiagonal: s := 'Wide Upward Diagonal';
HatchStyleLightVertical: s := 'Light Vertical';
HatchStyleLightHorizontal: s := 'Light Horizontal';
HatchStyleNarrowVertical: s := 'Narrow Vertical';
HatchStyleNarrowHorizontal: s := 'Narrow Horizontal';
HatchStyleDarkVertical: s := 'Dark Vertical';
HatchStyleDarkHorizontal: s := 'Dark Horizontal';
HatchStyleDashedDownwardDiagonal: s := 'Dashed Downward Diagonal';
HatchStyleDashedUpwardDiagonal: s := 'Dashed Upward Diagonal';
HatchStyleDashedHorizontal: s := 'Dashed Horizontal';
HatchStyleDashedVertical: s := 'Dashed Vertical';
HatchStyleSmallConfetti: s := 'Small Confetti';
HatchStyleLargeConfetti: s := 'Large Confetti';
HatchStyleZigZag: s := 'Zig Zag';
HatchStyleWave: s := 'Wave';
HatchStyleDiagonalBrick: s := 'Diagonal Brick';
HatchStyleHorizontalBrick: s := 'Horizontal Brick';
HatchStyleWeave: s := 'Weave';
HatchStylePlaid: s := 'Plaid';
HatchStyleDivot: s := 'Divot';
HatchStyleDottedGrid: s := 'Dotted Grid';
HatchStyleDottedDiamond: s := 'Dotted Diamond';
HatchStyleShingle: s := 'Shingle';
HatchStyleTrellis: s := 'Trellis';
HatchStyleSphere: s := 'Sphere';
HatchStyleSmallGrid: s := 'Small Grid';
HatchStyleSmallCheckerBoard: s := 'Small Checker Board';
HatchStyleLargeCheckerBoard: s := 'Large Checker Board';
HatchStyleOutlinedDiamond: s := 'Outlined Diamond';
HatchStyleSolidDiamond: s := 'Solid Diamond';
end;
Result := s;
end;
function GPTryStrIDToHatchStyle(const StrID: string; var hs: TIGPHatchStyle): Boolean;
var
s: string;
function TrimFromStart(const s: string; const StringToCut: string): string;
begin
if Copy(s, 1, Length(StringToCut)) = StringToCut then Result := Copy(s, Length(StringToCut) + 1, Length(s))
else Result := s;
end;
begin
Result := False;
s := StrID;
s := TrimFromStart(s, 'HatchStyle');
s := Trim(LowerCase(s));
if s = 'horizontal' then hs := HatchStyleHorizontal
else if s = 'vertical' then hs := HatchStyleVertical
else if s = 'forwarddiagonal' then hs := HatchStyleForwardDiagonal
else if s = 'backwarddiagonal' then hs := HatchStyleBackwardDiagonal
else if s = 'cross' then hs := HatchStyleCross
else if s = 'diagonalcross' then hs := HatchStyleDiagonalCross
else if s = '05percent' then hs := HatchStyle05Percent
else if s = '10percent' then hs := HatchStyle10Percent
else if s = '20percent' then hs := HatchStyle20Percent
else if s = '25percent' then hs := HatchStyle25Percent
else if s = '30percent' then hs := HatchStyle30Percent
else if s = '40percent' then hs := HatchStyle40Percent
else if s = '50percent' then hs := HatchStyle50Percent
else if s = '60percent' then hs := HatchStyle60Percent
else if s = '70percent' then hs := HatchStyle70Percent
else if s = '75percent' then hs := HatchStyle75Percent
else if s = '80percent' then hs := HatchStyle80Percent
else if s = '90percent' then hs := HatchStyle90Percent
else if s = 'lightdownwarddiagonal' then hs := HatchStyleLightDownwardDiagonal
else if s = 'lightupwarddiagonal' then hs := HatchStyleLightUpwardDiagonal
else if s = 'darkdownwarddiagonal' then hs := HatchStyleDarkDownwardDiagonal
else if s = 'darkupwarddiagonal' then hs := HatchStyleDarkUpwardDiagonal
else if s = 'widedownwarddiagonal' then hs := HatchStyleWideDownwardDiagonal
else if s = 'wideupwarddiagonal' then hs := HatchStyleWideUpwardDiagonal
else if s = 'lightvertical' then hs := HatchStyleLightVertical
else if s = 'lighthorizontal' then hs := HatchStyleLightHorizontal
else if s = 'narrowvertical' then hs := HatchStyleNarrowVertical
else if s = 'narrowhorizontal' then hs := HatchStyleNarrowHorizontal
else if s = 'darkvertical' then hs := HatchStyleDarkVertical
else if s = 'darkhorizontal' then hs := HatchStyleDarkHorizontal
else if s = 'dasheddownwarddiagonal' then hs := HatchStyleDashedDownwardDiagonal
else if s = 'dashedupwarddiagonal' then hs := HatchStyleDashedUpwardDiagonal
else if s = 'dashedhorizontal' then hs := HatchStyleDashedHorizontal
else if s = 'dashedvertical' then hs := HatchStyleDashedVertical
else if s = 'smallconfetti' then hs := HatchStyleSmallConfetti
else if s = 'largeconfetti' then hs := HatchStyleLargeConfetti
else if s = 'zigzag' then hs := HatchStyleZigZag
else if s = 'wave' then hs := HatchStyleWave
else if s = 'diagonalbrick' then hs := HatchStyleDiagonalBrick
else if s = 'horizontalbrick' then hs := HatchStyleHorizontalBrick
else if s = 'weave' then hs := HatchStyleWeave
else if s = 'plaid' then hs := HatchStylePlaid
else if s = 'divot' then hs := HatchStyleDivot
else if s = 'dottedgrid' then hs := HatchStyleDottedGrid
else if s = 'dotteddiamond' then hs := HatchStyleDottedDiamond
else if s = 'shingle' then hs := HatchStyleShingle
else if s = 'trellis' then hs := HatchStyleTrellis
else if s = 'sphere' then hs := HatchStyleSphere
else if s = 'smallgrid' then hs := HatchStyleSmallGrid
else if s = 'smallcheckerboard' then hs := HatchStyleSmallCheckerBoard
else if s = 'largecheckerboard' then hs := HatchStyleLargeCheckerBoard
else if s = 'outlineddiamond' then hs := HatchStyleOutlinedDiamond
else if s = 'soliddiamond' then hs := HatchStyleSolidDiamond
else Exit;
Result := True;
end;
function GPPointF(const ax, ay: Single): TPointF;
begin
Result.x := ax;
Result.y := ay;
end;
function GPPointF(const apt: TPoint): TPointF;
begin
Result.x := apt.X;
Result.y := apt.Y;
end;
function GPPointFMove(const Point: TPointF; const dx, dy: Single): TPointF;
begin
Result.X := Point.X + dx;
Result.Y := Point.Y + dy;
end;
function GPColor(const AColor: TColor; Alpha: Byte): TAlphaColor;
begin
Result := GPMakeColor(Alpha, AColor);
end;
{$IFDEF MSWINDOWS}
function GPTextWidthF(gr: IGPGraphics; Text: string; Font: IGPFont; px: Single = 0; py: Single = 0): Single;
var
RectF: TIGPRectF;
begin
RectF := gr.GetStringBoundingBoxF(WideString(Text), Font, GPPointF(px, py));
Result := RectF.Width;
end;
function GPTextHeightF(gr: IGPGraphics; Text: string; Font: IGPFont; px: Single = 0; py: Single = 0): Single;
var
RectF: TIGPRectF;
begin
RectF := gr.GetStringBoundingBoxF(WideString(Text), Font, GPPointF(px, py));
Result := RectF.Height;
end;
{$ENDIF}
{$IFDEF FPC}
class function TPointFHelper.Create(const ax, ay: Single): TPointF;
begin
Result.x := ax;
Result.y := ay;
end;
class function TPointFHelper.Create(const apt: TPoint): TPointF;
begin
Result.x := apt.X;
Result.y := apt.Y;
end;
{$ENDIF}
end.
| 37.585139 | 111 | 0.720511 |
85ce2f1a7049da2fe7bbc93f96405616ef760257 | 10,488 | pas | Pascal | Backend for the win/dependencies/mars/MARS.Core.MessageBodyReader.pas | GodsAndCakes/SAID-ist-ein-schlechter-Name | af0bc9b9413a93e68f0c2e07d75bd5124567d4f8 | [
"Apache-2.0"
]
| null | null | null | Backend for the win/dependencies/mars/MARS.Core.MessageBodyReader.pas | GodsAndCakes/SAID-ist-ein-schlechter-Name | af0bc9b9413a93e68f0c2e07d75bd5124567d4f8 | [
"Apache-2.0"
]
| null | null | null | Backend for the win/dependencies/mars/MARS.Core.MessageBodyReader.pas | GodsAndCakes/SAID-ist-ein-schlechter-Name | af0bc9b9413a93e68f0c2e07d75bd5124567d4f8 | [
"Apache-2.0"
]
| null | null | null | (*
Copyright 2016, MARS-Curiosity library
Home: https://github.com/andrea-magni/MARS
*)
unit MARS.Core.MessageBodyReader;
{$I MARS.inc}
interface
uses
Classes
, SysUtils
, Rtti
, Generics.Defaults
, Generics.Collections
, MARS.Core.MediaType
, MARS.Core.Declarations
, MARS.Core.Classes
, MARS.Core.Activation.Interfaces
;
type
IMessageBodyReader = interface
['{C22068E1-3085-482D-9EAB-4829C7AE87C0}']
function ReadFrom(
{$ifdef Delphi10Berlin_UP}const AInputData: TBytes;{$else}const AInputData: AnsiString;{$endif}
const ADestination: TRttiObject; const AMediaType: TMediaType;
const AActivation: IMARSActivation
): TValue;
end;
TIsReadableFunction = reference to function(AType: TRttiType;
const AAttributes: TAttributeArray; AMediaType: string): Boolean;
TGetAffinityFunction = reference to function(AType: TRttiType;
const AAttributes: TAttributeArray; AMediaType: string): Integer;
TReaderEntryInfo = record
_RttiType: TRttiType;
RttiName: string;
CreateInstance: TFunc<IMessageBodyReader>;
IsReadable: TIsReadableFunction;
GetAffinity: TGetAffinityFunction;
end;
TMARSMessageBodyReaderRegistry = class
private
private
FRegistry: TList<TReaderEntryInfo>;
FRttiContext: TRttiContext;
class var _Instance: TMARSMessageBodyReaderRegistry;
class function GetInstance: TMARSMessageBodyReaderRegistry; static;
protected
function GetConsumesMediaTypes(const AObject: TRttiObject): TMediaTypeList;
public
constructor Create;
destructor Destroy; override;
procedure RegisterReader(
const ACreateInstance: TFunc<IMessageBodyReader>;
const AIsReadable: TIsReadableFunction;
const AGetAffinity: TGetAffinityFunction;
AReaderRttiType: TRttiType); overload;
procedure RegisterReader(
const AReaderClass: TClass;
const AIsReadable: TIsReadableFunction;
const AGetAffinity: TGetAffinityFunction); overload;
procedure RegisterReader(const AReaderClass: TClass; const ASubjectClass: TClass;
const AGetAffinity: TGetAffinityFunction); overload;
procedure RegisterReader<T>(const AReaderClass: TClass); overload;
procedure FindReader(const ADestination: TRttiObject;
out AReader: IMessageBodyReader; out AMediaType: TMediaType);
procedure Enumerate(const AProc: TProc<TReaderEntryInfo>);
class property Instance: TMARSMessageBodyReaderRegistry read GetInstance;
class function GetDefaultClassAffinityFunc<T>: TGetAffinityFunction;
class destructor ClassDestructor;
const AFFINITY_HIGH = 100;
const AFFINITY_MEDIUM = 50;
const AFFINITY_LOW = 10;
const AFFINITY_VERY_LOW = 1;
const AFFINITY_ZERO = 0;
end;
implementation
uses
MARS.Core.Utils
, MARS.Rtti.Utils
, MARS.Core.Exceptions
, MARS.Core.Attributes
;
{ TMARSMessageBodyReaderRegistry }
class destructor TMARSMessageBodyReaderRegistry.ClassDestructor;
begin
if Assigned(_Instance) then
FreeAndNil(_Instance);
end;
constructor TMARSMessageBodyReaderRegistry.Create;
begin
inherited Create;
FRegistry := TList<TReaderEntryInfo>.Create;
FRttiContext := TRttiContext.Create;
end;
destructor TMARSMessageBodyReaderRegistry.Destroy;
begin
FRegistry.Free;
inherited;
end;
procedure TMARSMessageBodyReaderRegistry.Enumerate(const AProc: TProc<TReaderEntryInfo>);
var
LEntry: TReaderEntryInfo;
begin
for LEntry in FRegistry do
AProc(LEntry);
end;
procedure TMARSMessageBodyReaderRegistry.FindReader(const ADestination: TRttiObject;
out AReader: IMessageBodyReader; out AMediaType: TMediaType);
var
LMethod: TRttiMethod;
LReaderEntry: TReaderEntryInfo;
LFound: Boolean;
LCandidateAffinity: Integer;
LCandidate: TReaderEntryInfo;
LReaderRttiType: TRttiType;
LReaderMediaTypes: TMediaTypeList;
LConsumesMediaTypes: TMediaTypeList;
LAllowedMediaTypes: TArray<string>;
LMediaTypes: TArray<string>;
LMediaType: string;
LCandidateMediaType: string;
LAttributes: TArray<TCustomAttribute>;
// LCandidateQualityFactor: Double;
begin
AMediaType := nil;
AReader := nil;
LFound := False;
LCandidateAffinity := -1;
LCandidateMediaType := '';
// LCandidateQualityFactor := -1;
Assert(Assigned(ADestination));
if ADestination.Parent is TRttiMethod then
begin
LMethod := ADestination.Parent as TRttiMethod;
LConsumesMediaTypes := GetConsumesMediaTypes(LMethod);
LAttributes := LMethod.GetAttributes;
end
else begin
LConsumesMediaTypes := GetConsumesMediaTypes(ADestination);
LAttributes := ADestination.GetAttributes;
end;
try
if LConsumesMediaTypes.Count > 0 then
LAllowedMediaTypes := LConsumesMediaTypes.ToArrayOfString
else
{$ifdef DelphiXE7_UP}
LAllowedMediaTypes := [];
{$else}
SetLength(LAllowedMediaTypes, 0);
{$endif}
if (Length(LAllowedMediaTypes) = 0)
or ((Length(LAllowedMediaTypes) = 1) and (LAllowedMediaTypes[0] = TMediaType.WILDCARD))
then // defaults
begin
if LConsumesMediaTypes.Count > 0 then
LAllowedMediaTypes := LConsumesMediaTypes.ToArrayOfString
else
begin
SetLength(LAllowedMediaTypes, 2);
LAllowedMediaTypes[0] := TMediaType.APPLICATION_JSON;
LAllowedMediaTypes[1] := TMediaType.WILDCARD;
end;
end;
// collect compatible Readers
for LReaderEntry in FRegistry do
begin
LReaderRttiType := FRttiContext.FindType(LReaderEntry.RttiName);
LReaderMediaTypes := GetConsumesMediaTypes(LReaderRttiType);
try
if LReaderMediaTypes.Contains(TMediaType.WILDCARD) then
LMediaTypes := LAllowedMediaTypes
else
LMediaTypes := TMediaTypeList.Intersect(LAllowedMediaTypes, LReaderMediaTypes);
for LMediaType in LMediaTypes do
if LReaderEntry.IsReadable(ADestination.GetRttiType, LAttributes, LMediaType) then
begin
if not LFound
or (
(LCandidateAffinity < LReaderEntry.GetAffinity(ADestination.GetRttiType, LAttributes, LMediaType))
// or (LCandidateQualityFactor < LAcceptMediaTypes.GetQualityFactor(LMediaType))
)
then
begin
LCandidate := LReaderEntry;
LCandidateAffinity := LCandidate.GetAffinity(ADestination.GetRttiType, LAttributes, LMediaType);
LCandidateMediaType := LMediaType;
// LCandidateQualityFactor := 1;
LFound := True;
end;
end;
finally
LReaderMediaTypes.Free;
end;
end;
if LFound then
begin
AReader := LCandidate.CreateInstance();
AMediaType := TMediaType.Create(LCandidateMediaType);
end;
finally
LConsumesMediaTypes.Free;
end;
end;
class function TMARSMessageBodyReaderRegistry.GetDefaultClassAffinityFunc<T>: TGetAffinityFunction;
begin
Result :=
function (AType: TRttiType; const AAttributes: TAttributeArray; AMediaType: string): Integer
var
LType: TRttiType;
begin
Result := 0;
if not Assigned(AType) then
Exit;
LType := TRttiContext.Create.GetType(TypeInfo(T));
if (AType = LType) then
Result := 100
else if AType.IsObjectOfType<T>(False) then
Result := 95
else if AType.IsObjectOfType<T> then
Result := 90;
end
end;
class function TMARSMessageBodyReaderRegistry.GetInstance: TMARSMessageBodyReaderRegistry;
begin
if not Assigned(_Instance) then
_Instance := TMARSMessageBodyReaderRegistry.Create;
Result := _Instance;
end;
function TMARSMessageBodyReaderRegistry.GetConsumesMediaTypes(
const AObject: TRttiObject): TMediaTypeList;
var
LList: TMediaTypeList;
begin
LList := TMediaTypeList.Create;
AObject.ForEachAttribute<ConsumesAttribute>(
procedure (AConsumes: ConsumesAttribute)
begin
LList.Add( TMediaType.Create(AConsumes.Value) );
end
);
// if AObject is a method, fall back to its class
if (LList.Count = 0) and (AObject is TRttiMethod) then
begin
(TRttiMethod(AObject).Parent).ForEachAttribute<ConsumesAttribute>(
procedure (AConsumes: ConsumesAttribute)
begin
LList.Add( TMediaType.Create(AConsumes.Value) );
end
);
end;
Result := LList;
end;
procedure TMARSMessageBodyReaderRegistry.RegisterReader(const AReaderClass: TClass;
const AIsReadable: TIsReadableFunction; const AGetAffinity: TGetAffinityFunction);
begin
RegisterReader(
function : IMessageBodyReader
var LInstance: TObject;
begin
LInstance := AReaderClass.Create;
if not Supports(LInstance, IMessageBodyReader, Result) then
raise EMARSException.Create('Interface IMessageBodyReader not implemented');
end
, AIsReadable
, AGetAffinity
, TRttiContext.Create.GetType(AReaderClass)
);
end;
procedure TMARSMessageBodyReaderRegistry.RegisterReader(const AReaderClass,
ASubjectClass: TClass; const AGetAffinity: TGetAffinityFunction);
begin
RegisterReader(
AReaderClass,
function (AType: TRttiType; const AAttributes: TAttributeArray; AMediaType: string): Boolean
begin
Result := Assigned(AType) and AType.IsObjectOfType(ASubjectClass);
end,
AGetAffinity
);
end;
procedure TMARSMessageBodyReaderRegistry.RegisterReader<T>(const AReaderClass: TClass);
begin
RegisterReader(
AReaderClass
, function (AType: TRttiType; const AAttributes: TAttributeArray; AMediaType: string): Boolean
var
LType: TRttiType;
begin
LType := TRttiContext.Create.GetType(TypeInfo(T));
Result := False;
if Assigned(AType) then
begin
Result := (AType = LType);
if not Result then
Result := AType.IsObjectOfType<T>();
end;
end
, Self.GetDefaultClassAffinityFunc<T>()
);
end;
procedure TMARSMessageBodyReaderRegistry.RegisterReader(
const ACreateInstance: TFunc<IMessageBodyReader>;
const AIsReadable: TIsReadableFunction;
const AGetAffinity: TGetAffinityFunction;
AReaderRttiType: TRttiType);
var
LEntryInfo: TReaderEntryInfo;
begin
LEntryInfo.CreateInstance := ACreateInstance;
LEntryInfo.IsReadable := AIsReadable;
LEntryInfo._RttiType := AReaderRttiType;
LEntryInfo.RttiName := AReaderRttiType.QualifiedName;
LEntryInfo.GetAffinity := AGetAffinity;
FRegistry.Add(LEntryInfo)
end;
end.
| 28.972376 | 117 | 0.721301 |
c31b6eaf4a0f0d68baeeb5a6f44c8e6f7f600a7f | 24,427 | dfm | Pascal | furqAbout.dfm | fireton/fireurq | 74fa7399ce4402e3a657a55913eaaaf73494a70d | [
"Apache-2.0"
]
| 12 | 2017-12-04T07:09:13.000Z | 2021-01-14T07:12:32.000Z | furqAbout.dfm | fireton/fireurq | 74fa7399ce4402e3a657a55913eaaaf73494a70d | [
"Apache-2.0"
]
| null | null | null | furqAbout.dfm | fireton/fireurq | 74fa7399ce4402e3a657a55913eaaaf73494a70d | [
"Apache-2.0"
]
| 1 | 2018-07-31T07:00:02.000Z | 2018-07-31T07:00:02.000Z | object AboutBox: TAboutBox
Left = 200
Top = 108
BorderStyle = bsDialog
Caption = #1054' '#1087#1088#1086#1075#1088#1072#1084#1084#1077
ClientHeight = 191
ClientWidth = 298
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = True
Position = poScreenCenter
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object Panel1: TPanel
Left = 8
Top = 8
Width = 281
Height = 145
BevelInner = bvRaised
BevelOuter = bvLowered
ParentColor = True
TabOrder = 0
object lblVersion: TLabel
Left = 62
Top = 108
Width = 155
Height = 13
Alignment = taCenter
AutoSize = False
Caption = #1042#1077#1088#1089#1080#1103' 0.0.1'
end
object Image1: TImage
Left = 62
Top = 24
Width = 155
Height = 64
AutoSize = True
Picture.Data = {
07544269746D6170BE270000424DBE27000000000000BE000000280000009B00
000040000000010008000000000000270000120B0000120B0000220000002200
0000FF00FF00FF500A00FE5A1800FD642700FC6E3500FB784300FA825200F98C
6000F8966F00F7A07D00F6AA8B00F5B49A00F4BEA800F3C8B600F2D2C500F0E6
E200F1DCD300E5E5E500DADADA00D0D0D000C5C5C500BABABA00B0B0B000A5A5
A5009A9A9A0090909000858585007A7A7A0070707000656565005A5A5A005050
50004545450000000000000000000000000013181B1C1C1C1C1C1C1C1C1C1C1C
1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C
1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C
1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C
1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1813000000
000000000000000000000000151E202020202020202020202020202020202020
2020202020202020202020202020202020202020202020202020202020202020
2020202020202020202020202020202020202020202020202020202020202020
2020202020202020202020202020202020202020202020202020202020202020
202020202020202020202020202020202020202020202020201E160000000000
000000000000111B202020202020202020202020202020202020202020202020
2020202020202020202020202020202020202020202020202020202020202020
2020202020202020202020202020202020202020202020202020202020202020
2020202020202020202020202020202020202020202020202020202020202020
20202020202020202020202020202020202020202020201C1100000000000000
00111D2020201E17130000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000013171E2020201D11000000000000001D2020
1F17000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000171F20201D1100000000001820201F13000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
00000000000000000000131F2020190000000012202020140000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000D0D0D0D0D0D
0D0D0D0E00000013202020120000001920201A00000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000080101010101010101010105
00000000192020190000001E2020120000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000A01010101010101010101010500000000
1220201E00001120201D00000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000601010101010101010101010500000000001C2020
1200142020190000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000011141718
18181714110000000000000000000000000000000D0907050505080A0E000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000005010101010101010101010105000000000018202014001420
2018000000000000002020202020202020201400001420202020202020202000
00002020202020202020201400000000000000000000141B2020202020202020
201A1200000000000000000000100702010101010101010101030B0000000000
000005010101010101010105000005010101010101010100000000000000000E
08050101010101010101050C0D0D0D0E00000000001820201400142020180000
0000000000202020202020202020140000142020202020202020200000002020
20202020202020140000000000000000111C2020202020202020202020202016
00000000000000000B0201010101010101010101010101060F00000000000501
0101010101010105000005010101010101010100000000000010050101010101
0101010101010D00000000000000000000182020140014202018000000000000
0020202020202020202014000014202020202020202020000000202020202020
2020201400000000000000111D20202020202020202020202020202016000000
0000000901010101010101010101010101010101050000000000050101010101
01010105000005010101010101010100000000000E0201010101010101010101
010101050B000000000000000018202014001420201800000000000000202020
2020202020201400001420202020202020202000000020202020202020202014
000000000000001B202020202020202020202020202020202013000000000D01
0101010101010101010101010101010101090000000005010101010101010105
0000050101010101010101000000001002010101010101010101010101010101
01050F0000000000001820201400142020180000000000000020202020202020
2020140000142020202020202020200000002020202020202020201400000000
0000132020202020202020202020202020202020201C00000000050101010101
01010101010101010101010101020F0000000501010101010101010500000501
0101010101010100000000070101010101010101010101010101010101010600
0000000000182020140014202018000000000000002020202020202020201400
0014202020202020202020000000202020202020202020140000000000001920
2020202020202017001A20202020202020201200001001010101010101010105
060101010101010101010B000000050101010101010101050000050101010101
0101010000000F01010101010101010105050101010101010101010E00000000
0018202014001420201800000000000000202020202020202020140000142020
20202020202020000000202020202020202020140000000000001C2020202020
20202013001420202020202020201600000B0101010101010101010F00020101
0101010101010800000005010101010101010105000005010101010101010100
00000C0101010101010101030000020101010101010101090000000000182020
1400142020180000000000000020202020202020202014000014202020202020
2020200000002020202020202020201400000000000020202020202020202000
0011202020202020202018000009010101010101010101000005010101010101
0101050000000501010101010101010500000501010101010101010000000901
0101010101010105000005010101010101010106000000000018202014001420
2018000000000000002020202020202020201400001420202020202020202000
0000202020202020202020140000000000002020202020202020200000002020
2020202020201800000901010101010101010100000501010101010101010500
0000050101010101010101050000050101010101010101000000070101010101
0101010500000501010101010101010500000000001820201400142020180000
0000000000202020202020202020140000142020202020202020200000002020
2020202020202014000000000000202020202020202020000000202020202020
2020180000090101010101010101010000050101010101010101050000000501
0101010101010105000005010101010101010100000005010101010101010105
0000050101010101010101050000000000182020140014202018000000000000
0020202020202020202014000014202020202020202020000000202020202020
2020201400000000000020202020202020202000000020202020202020201800
0009010101010101010101000005010101010101010105000000050101010101
0101010500000501010101010101010000000501010101010101010500000501
0101010101010105000000000018202014001420201800000000000000202020
2020202020201400001420202020202020202000000020202020202020202014
0000000000002020202020202020200000002020202020202020180000090101
0101010101010100000501010101010101010500000005010101010101010105
0000050101010101010101000000050101010101010101050000050101010101
0101010500000000001820201400142020180000000000000020202020202020
2020140000142020202020202020200000002020202020202020201400000000
0000202020202020202020000000181818181818181814000009010101010101
0101010000050101010101010101050000000501010101010101010500000501
0101010101010100000005010101010101010105000005010101010101010105
0000000000182020140014202018000000000000002020202020202020201400
0014202020202020202020000000202020202020202020140000000000002020
2020202020202000000000000000000000000000000901010101010101010100
0005010101010101010105000000050101010101010101050000050101010101
0101010000000501010101010101010500000501010101010101010500000000
0018202014001420201800000000000000202020202020202020140000142020
2020202020202000000020202020202020202014000000000000202020202020
2020202020202020202020202020180000090101010101010101010000050101
0101010101010500000005010101010101010105000002010101010101010100
0000050101010101010101050000050101010101010101050000000000182020
1400142020180000000000000020202020202020202014000014202020202020
2020200000002020202020202020201400000000000020202020202020202020
2020202020202020202018000009010101010101010101000005010101010101
01010500000005010101010101010105000B0101010101010101060000000501
0101010101010105000005010101010101010105000000000018202014001420
2018000000000000002020202020202020201400001420202020202020202000
0000202020202020202020160000000000002020202020202020202020202020
2020202020201800000901010101010101010100000501010101010101010500
0000050101010101010101010101010101010101010210000000050101010101
0101010500000501010101010101010500000000001820201400142020180000
0000000000202020202020202020140000142020202020202020200000002020
202020202020201A000000000000202020202020202020202020202020202020
2020180000090101010101010101010000050101010101010101050000000501
01010101010101010101010101010101020C0000000005010101010101010105
0000050101010101010101050000000000182020140014202018000000000000
0020202020202020202014000014202020202020202020000000202020202020
2020202017000000000020202020202020202020202020202020202020201800
0009010101010101010101000005010101010101010105000000050101010101
0101010101010101010101080F00000000000501010101010101010500000501
0101010101010105000000000018202014001420201800000000000000202020
2020202020201400001420202020202020202000000020202020202020202020
201F1C18140020202020202020202014141A2020202020202020180000090101
0101010101010100000501010101010101010500000005010101010101010101
0101010101010101040E00000000050101010101010101050000050101010101
0101010500000000001820201400142020180000000000000020202020202020
2020140000142020202020202020200000002020202020202020202020202020
1800202020202020202020000018202020202020202018000009010101010101
0101010000050101010101010101050000000501010101010101010101010101
0101010101011000000005010101010101010105000005010101010101010105
0000000000182020140014202018000000000000002020202020202020201400
0014202020202020202020000000202020202020202020202020202018002020
2020202020202000001820202020202020201700000901010101010101010100
0005010101010101010105000000050101010101010101010101010101010101
0101070000000501010101010101010500000501010101010101010500000000
0018202014001420201800000000000000202020202020202020140000142020
20202020202020000000202020202020202020202020202018001E2020202020
2020200000182020202020202020140000090101010101010101010000050101
0101010101010500000005010101010101010105000C01010101010101010400
0000050101010101010101050000050101010101010101050000000000182020
1400142020180000000000000020202020202020202014000014202020202020
202020000000202020202020202020202020202018001B202020202020202014
001C202020202020202011000009010101010101010101000005010101010101
0101050000000501010101010101010500000301010101010101010000000501
0101010101010105000005010101010101010105000000000018202014001420
201800000000001C202020202020202020202020141420202020202020202000
0000202020202020202020202020202018001620202020202020201C19202020
20202020201B0000000901010101010101010100000501010101010101010500
0000050101010101010101050000050101010101010101000000050101010101
0101010500000501010101010101010500000000001820201400142020180000
0000001C20202020202020202020202014142020202020202020200000002020
2020202020202020202020201800111F20202020202020202020202020202020
2014000000090101010101010101010000050101010101010101050000000501
0101010101010105000005010101010101010100000005010101010101010105
000005010101010101010105000000000018202014001420201800000000001C
2020202020202020202020201414202020202020202020000000202020202020
2020201F2020202018000017202020202020202020202020202020201A000000
0009010101010101010101000005010101010101010105000000050101010101
0101010500000501010101010101010000000501010101010101010500000501
0101010101010105000000000018202014001420201800000000001C20202020
2020202020202020141420202020202020202000000020202020202020202015
20202020180000001920202020202020202020202020201A0000000000090101
0101010101010100000501010101010101010500000005010101010101010105
0000050101010101010101000000050101010101010101050000050101010101
0101010500000000001820201400142020180000000000191C20202020202020
1E1C1C1C13142020202020202020200000002020202020202020200016202020
1800000000151E202020202020202020201E1600000000000009010101010101
01010100000501010101010101010500000005010101010101010105000F0101
0101010101010100000008010101010101010105000005010101010101010106
0000000000182020140014202018000000000000002020202020202018000000
00121818181818181818180000001818181818181818181200121A1E18000000
00000015191C202020201C1A1500000000000000000901010101010101010100
0005010101010101010105000000050101010101010101030903010101010101
0101040000000A0101010101010101020F000301010101010101010900000000
0018202014001420201800000000000000202020202020201B00000000000000
0F0D0D0D00000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000090101010101010101010000050101
0101010101010500000005010101010101010101010101010101010101010700
00001001010101010101010103040101010101010101010E0000000000182020
14001420201800000000000000202020202020202020201C1300000801030503
020A000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000009010101010101010101000005010101010101
01010500000005010101010101010101010101010101010101010C0000000005
0101010101010101010101010101010101010500000000000018202014001420
2018000000000000001E20202020202020202020140005010B00000007010900
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000901010101010101010100000501010101010101010500
0000050101010101010101010101010101010101010400000000000E01010101
01010101010101010101010101010E0000000000001820201400142020180000
00000000001820202020202020202020140B0107000000000003011000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000090101010101010101010000050101010101010101050000000501
01010101010101010101010101010101020E0000000000000B01010101010101
0101010101010101010B00000000000000182020140014202018000000000000
00001A2020202020202020201405010C00000000000801080000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0009010101010101010101000005010101010101010105000000050101010101
0101010101010101010101051000000000000000000B02010101010101010101
010101020C000000000000000018202014001420201900000000000000000013
181C1C1F202020201401010A0000000000070105000000000000000000000000
0000000000000000000000000000000000000000000000000000000000090101
0101010101010100000501010101010101010500000005010101010101010102
0505050508090E0000000000000000000000100701010101010101010103090F
00000000000000000018202014001220201D0000000000000000000000000000
0000000000010108000000000004010500000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000F0C09090508090A0E00000000000000
00000000001C20201200001E2020120000000000000000000000000000000000
0001010400000000100101050000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
1120201F0004001920201A000000000000000000000000000000000000050101
100000000A010109000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000001820201A
0000001220202014000000000000000000000000000000000006010108000000
0301010A00000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000132020201200000000
1920201F1300000000000000000000000000000000090101020F000B0101010D
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000131F2020190000000000111D2020
1F160000000000000000000000000000000D0101010700030101010000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000151F20201D11000000000000111D2020201D16
1200000000000000000000000000010101010501010105000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
00000000000012161C2020201E120000000000000000111C2020202020202020
202020202020201C0000050101010101010109001C2020202020202020202020
2020202020202020202020202020202020202020202020202020202020202020
2020202020202020202020202020202020202020202020202020202020202020
2020202020202020202020202020202020202020202020202020202020202020
202020202020201C110000000000000000000000161E20202020202020202020
2020201C00000A010101010101010E001C202020202020202020202020202020
2020202020202020202020202020202020202020202020202020202020202020
2020202020202020202020202020202020202020202020202020202020202020
2020202020202020202020202020202020202020202020202020202020202020
201E1600000000000000000000000000000015181C1C1C1C1C1C1C1C1C1C1C19
000010010101010101030000191C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C
1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C
1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C
1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1C1915000000
0000000000000000000000000000000000000000000000000000000000000005
0101010101090000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000B01010101
0110000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000F0201010105000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000090101010C00000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000010010103000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000008010B00000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000F07000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
00000000000000000000}
Transparent = True
end
end
object OKButton: TButton
Left = 111
Top = 159
Width = 75
Height = 25
Caption = 'OK'
Default = True
ModalResult = 1
TabOrder = 1
end
end
| 64.793103 | 72 | 0.863635 |
fcbbc44bf856748cc4b5c37682b44f810da1a1e5 | 251 | lpr | Pascal | idee/FPC/prj_TestfvApp1.lpr | joecare99/Public | 9eee060fbdd32bab33cf65044602976ac83f4b83 | [
"MIT"
]
| 11 | 2017-06-17T05:13:45.000Z | 2021-07-11T13:18:48.000Z | idee/FPC/prj_TestfvApp1.lpr | joecare99/Public | 9eee060fbdd32bab33cf65044602976ac83f4b83 | [
"MIT"
]
| 2 | 2019-03-05T12:52:40.000Z | 2021-12-03T12:34:26.000Z | idee/FPC/prj_TestfvApp1.lpr | joecare99/Public | 9eee060fbdd32bab33cf65044602976ac83f4b83 | [
"MIT"
]
| 6 | 2017-09-07T09:10:09.000Z | 2022-02-19T20:19:58.000Z | program prj_TestfvApp1;
{$mode delphi}{$H+}
{$apptype console}
{$R *.res}
uses app_TestFvMain, fvAppExt, fvForms,app;
begin
PAppExt(Application).initialize;
PAppExt(Application).CreateForm(TVDemo,TTVDemo);
Application.Run;
end.
| 17.928571 | 51 | 0.705179 |
c3222b09192bd1d02eda15d4b4e63689b5163044 | 58,732 | dfm | Pascal | source - Copia/untMenu.dfm | roneysousa/infoboletos | e709fbf32a9f2541a8d1e54ecf1aed672ba121f4 | [
"MIT"
]
| null | null | null | source - Copia/untMenu.dfm | roneysousa/infoboletos | e709fbf32a9f2541a8d1e54ecf1aed672ba121f4 | [
"MIT"
]
| null | null | null | source - Copia/untMenu.dfm | roneysousa/infoboletos | e709fbf32a9f2541a8d1e54ecf1aed672ba121f4 | [
"MIT"
]
| null | null | null | object FrmMainBoletos: TFrmMainBoletos
Left = 203
Top = 134
BorderStyle = bsSingle
Caption = 'Boletos'
ClientHeight = 521
ClientWidth = 946
Color = clGray
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
Menu = mmPrincipal
OldCreateOrder = False
Position = poScreenCenter
ShowHint = True
OnCloseQuery = FormCloseQuery
OnCreate = FormCreate
OnShow = FormShow
PixelsPerInch = 96
TextHeight = 13
object StatusBar1: TStatusBar
Left = 0
Top = 502
Width = 946
Height = 19
Panels = <
item
Width = 300
end
item
Width = 200
end
item
Width = 50
end>
end
object Panel1: TPanel
Left = 0
Top = 0
Width = 946
Height = 93
Align = alTop
TabOrder = 1
object Label1: TLabel
Left = 16
Top = 3
Width = 112
Height = 13
Caption = '&Per'#237'odo de Vencimento'
FocusControl = edtDTINIC
Transparent = True
end
object Label2: TLabel
Left = 141
Top = 23
Width = 6
Height = 13
Caption = #224
Transparent = True
end
object Label3: TLabel
Left = 16
Top = 42
Width = 85
Height = 13
Caption = '&N'#186'. Placa Ve'#237'culo'
Transparent = True
end
object Label4: TLabel
Left = 286
Top = 3
Width = 73
Height = 13
Caption = 'Conta &Banc'#225'ria'
Transparent = True
end
object Label5: TLabel
Left = 552
Top = 3
Width = 34
Height = 13
Caption = '&Grupos'
FocusControl = RxCheckListBoxGrupos
end
object edtDTINIC: TDateEdit
Left = 16
Top = 19
Width = 121
Height = 21
Hint = 'Digite o per'#237'odo inicial'
NumGlyphs = 2
TabOrder = 0
OnChange = edtDTINICChange
OnEnter = edtDTINICEnter
OnExit = edtDTINICExit
OnKeyPress = edtDTINICKeyPress
end
object edtDTFINAL: TDateEdit
Left = 155
Top = 19
Width = 121
Height = 21
Hint = 'Digite o per'#237'odo final'
NumGlyphs = 2
TabOrder = 1
OnEnter = edtDTFINALEnter
OnExit = edtDTFINALExit
OnKeyPress = edtDTFINALKeyPress
end
object btnConsulta: TBitBtn
Left = 155
Top = 55
Width = 75
Height = 25
Action = actConsulta
Caption = '&Consultar'
TabOrder = 4
Glyph.Data = {
F6000000424DF600000000000000760000002800000010000000100000000100
0400000000008000000000000000000000001000000000000000000000000000
80000080000000808000800000008000800080800000C0C0C000808080000000
FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00777777777777
7777777777777777777744444777774444474B444777774B44474B444777774B
4447444444474444444744B444444B44444744B444744B44444744B444744B44
44477444444444444477774B44474B4447777744444744444777777444777444
77777774B47774B4777777744477744477777777777777777777}
end
object edtNumPlaca: TMaskEdit
Left = 16
Top = 58
Width = 120
Height = 21
CharCase = ecUpperCase
EditMask = 'AAA-####;0;_'
MaxLength = 8
TabOrder = 3
OnKeyPress = edtNumPlacaKeyPress
end
object GroupBox1: TGroupBox
Left = 712
Top = 1
Width = 161
Height = 84
Caption = '[ Op'#231#245'es ]'
TabOrder = 5
Visible = False
object chkMultaJuros: TCheckBox
Left = 13
Top = 25
Width = 217
Height = 17
Caption = 'Exibir mensagem de multa/juros'
Checked = True
Font.Charset = DEFAULT_CHARSET
Font.Color = clBlue
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = [fsBold]
ParentFont = False
State = cbChecked
TabOrder = 0
end
object ckbMsg: TCheckBox
Left = 13
Top = 47
Width = 239
Height = 17
Caption = 'Mensagem: Receber at'#233' o vencimento'
Font.Charset = DEFAULT_CHARSET
Font.Color = clBlue
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = [fsBold]
ParentFont = False
TabOrder = 1
end
end
object rgTipoCarne: TRadioGroup
Left = 822
Top = 1
Width = 123
Height = 91
Align = alRight
Caption = '[ Carn'#234' Impress'#227'o ]'
ItemIndex = 1
Items.Strings = (
'Retrato'
'Paisagem'
'Individual')
TabOrder = 6
end
object cmbContaBancaria: TComboBox
Left = 286
Top = 19
Width = 259
Height = 22
Style = csOwnerDrawFixed
ItemHeight = 16
TabOrder = 2
OnChange = cmbContaBancariaChange
OnClick = cmbContaBancariaClick
end
object cbkRegistro: TCheckBox
Left = 288
Top = 58
Width = 177
Height = 17
Caption = 'Apartir do registro selecionado '
TabOrder = 7
end
object RxCheckListBoxGrupos: TRxCheckListBox
Left = 552
Top = 19
Width = 246
Height = 68
ItemHeight = 13
TabOrder = 8
OnClick = RxCheckListBoxGruposClick
InternalVersion = 202
end
end
object Panel2: TPanel
Left = 0
Top = 93
Width = 946
Height = 368
Align = alClient
TabOrder = 2
object DBGridDados: TDBGrid
Left = 1
Top = 1
Width = 944
Height = 366
Align = alClient
DataSource = dsConsulta
Options = [dgTitles, dgIndicator, dgColLines, dgRowLines, dgTabs, dgRowSelect, dgConfirmDelete, dgCancelOnExit]
ReadOnly = True
TabOrder = 0
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -11
TitleFont.Name = 'MS Sans Serif'
TitleFont.Style = []
OnDblClick = DBGridDadosDblClick
OnKeyPress = DBGridDadosKeyPress
Columns = <
item
Alignment = taCenter
Expanded = False
FieldName = 'placa'
Title.Alignment = taCenter
Title.Caption = 'Ve'#237'culo'
Title.Font.Charset = ANSI_CHARSET
Title.Font.Color = clWindowText
Title.Font.Height = -11
Title.Font.Name = 'Verdana'
Title.Font.Style = [fsBold]
Width = 68
Visible = True
end
item
Expanded = False
FieldName = 'nome'
Title.Alignment = taCenter
Title.Caption = 'Cliente'
Title.Font.Charset = ANSI_CHARSET
Title.Font.Color = clWindowText
Title.Font.Height = -11
Title.Font.Name = 'Verdana'
Title.Font.Style = [fsBold]
Width = 350
Visible = True
end
item
Alignment = taCenter
Expanded = False
FieldName = 'CPFCNPJ'
Title.Alignment = taCenter
Title.Caption = 'CPF/CNPJ'
Title.Font.Charset = ANSI_CHARSET
Title.Font.Color = clWindowText
Title.Font.Height = -11
Title.Font.Name = 'Verdana'
Title.Font.Style = [fsBold]
Visible = True
end
item
Expanded = False
FieldName = 'valor'
Title.Alignment = taRightJustify
Title.Caption = 'Valor'
Title.Font.Charset = ANSI_CHARSET
Title.Font.Color = clWindowText
Title.Font.Height = -11
Title.Font.Name = 'Verdana'
Title.Font.Style = [fsBold]
Visible = True
end
item
Alignment = taCenter
Expanded = False
FieldName = 'data_vencimento'
Title.Alignment = taCenter
Title.Caption = 'Dt.Vcto'
Title.Font.Charset = ANSI_CHARSET
Title.Font.Color = clWindowText
Title.Font.Height = -11
Title.Font.Name = 'Verdana'
Title.Font.Style = [fsBold]
Visible = True
end
item
Expanded = False
FieldName = 'data_pagamento'
Title.Alignment = taRightJustify
Title.Caption = 'Dt.Pgto'
Title.Font.Charset = ANSI_CHARSET
Title.Font.Color = clWindowText
Title.Font.Height = -11
Title.Font.Name = 'Verdana'
Title.Font.Style = [fsBold]
Visible = False
end
item
Expanded = False
FieldName = 'valor_juros'
Title.Alignment = taRightJustify
Title.Caption = 'Juros'
Title.Font.Charset = ANSI_CHARSET
Title.Font.Color = clWindowText
Title.Font.Height = -11
Title.Font.Name = 'Verdana'
Title.Font.Style = [fsBold]
Visible = True
end
item
Expanded = False
FieldName = 'valor_multa'
Title.Alignment = taRightJustify
Title.Caption = 'Multa'
Title.Font.Charset = ANSI_CHARSET
Title.Font.Color = clWindowText
Title.Font.Height = -11
Title.Font.Name = 'Verdana'
Title.Font.Style = [fsBold]
Visible = True
end
item
Expanded = False
FieldName = 'email'
Title.Caption = 'E-mail'
Title.Font.Charset = ANSI_CHARSET
Title.Font.Color = clWindowText
Title.Font.Height = -11
Title.Font.Name = 'Verdana'
Title.Font.Style = [fsBold]
Width = 400
Visible = True
end>
end
object Memo1: TMemo
Left = 320
Top = 280
Width = 241
Height = 89
Lines.Strings = (
'DESCONTO DE XXX ATE '
'99/99/9999'
'JUROS DE MORA DE 2.0% '
'MENSAL ()'
'MULTA DE 2.0% A PARTIR DE '
'99/99/9999')
TabOrder = 1
Visible = False
end
object mnoListaMensagem: TMemo
Left = 584
Top = 184
Width = 281
Height = 89
TabOrder = 2
Visible = False
end
end
object Panel3: TPanel
Left = 0
Top = 461
Width = 946
Height = 41
Align = alBottom
Color = clNavy
TabOrder = 3
DesignSize = (
946
41)
object lblRegistro: TLabel
Left = 16
Top = 14
Width = 66
Height = 13
Caption = 'Registro(s):'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWhite
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = [fsBold]
ParentFont = False
end
object btnVisualizar: TBitBtn
Left = 438
Top = 9
Width = 75
Height = 25
Action = actVisualizar
Anchors = [akTop, akRight]
Caption = '&Visualizar'
TabOrder = 0
Glyph.Data = {
36030000424D3603000000000000360000002800000010000000100000000100
18000000000000030000120B0000120B00000000000000000000FF00FFFF00FF
A46769A46769A46769A46769A46769A46769A46769A46769A46769A46769A467
69A46769A46769FF00FFFF00FFFF00FF485360FEE9C7F4DAB5F3D5AAF2D0A0EF
CB96EFC68BEDC182EBC17FEBC180EBC180F2C782A46769FF00FFFF00FF4380B7
1F6FC2656B86F3DABCF2D5B1F0D0A7EECB9EEDC793EDC28BE9BD81E9BD7FE9BD
7FEFC481A46769FF00FFFF00FFFF00FF32A3FF1672D76B6A80F2DABCF2D5B2EF
D0A9EECB9EEDC796EBC28CE9BD82E9BD7FEFC481A46769FF00FFFF00FFFF00FF
A0675B34A1FF1572D45E6782F3DABBF2D5B1F0D0A6EECB9EEDC795EBC28AEABF
81EFC480A46769FF00FFFF00FFFF00FFA7756BFFFBF033A6FF4078AD8E675EAC
7F7597645EAC7D6FCAA083EDC695EBC28AEFC583A46769FF00FFFF00FFFF00FF
A7756BFFFFFCFAF0E6AD8A88B78F84D8BAA5EED5B6D7B298B58877CBA083EBC7
93F2C98CA46769FF00FFFF00FFFF00FFBC8268FFFFFFFEF7F2AF847FDAC0B4F7
E3CFF6E0C5FFFFF4D7B198AC7D6FEECC9EF3CE97A46769FF00FFFF00FFFF00FF
BC8268FFFFFFFFFEFC976560F6E9E0F7EADAF6E3CFFFFFEBEFD4B797645EF0D0
A6F6D3A0A46769FF00FFFF00FFFF00FFD1926DFFFFFFFFFFFFB08884DECAC4FA
EFE5F8EAD9FFFFD4D9B8A5AC7F74F4D8B1EBCFA4A46769FF00FFFF00FFFF00FF
D1926DFFFFFFFFFFFFD5BFBCBA9793DECAC4F6E9DEDAC0B4B78F84B28C7BDECE
B4B6AA93A46769FF00FFFF00FFFF00FFDA9D75FFFFFFFFFFFFFFFFFFD5BFBCB0
8884976560AF867FCAA79DA56B5FA56B5FA56B5FA46769FF00FFFF00FFFF00FF
DA9D75FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFBFFFEF7DAC1BAA56B5FE19E
55E68F31B56D4DFF00FFFF00FFFF00FFE7AB79FFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFDCC7C5A56B5FF8B55CBF7A5CFF00FFFF00FFFF00FFFF00FF
E7AB79FBF4F0FBF4EFFAF3EFFAF3EFF8F2EFF7F2EFF7F2EFD8C2C0A56B5FC183
6CFF00FFFF00FFFF00FFFF00FFFF00FFE7AB79D1926DD1926DD1926DD1926DD1
926DD1926DD1926DD1926DA56B5FFF00FFFF00FFFF00FFFF00FF}
end
object btnImprimir: TBitBtn
Left = 518
Top = 9
Width = 75
Height = 25
Action = actImprimir
Anchors = [akTop, akRight]
Caption = '&Imprimir'
TabOrder = 1
Glyph.Data = {
36050000424D3605000000000000360400002800000010000000100000000100
0800000000000001000000000000000000000001000000000000000000004000
000080000000FF000000002000004020000080200000FF200000004000004040
000080400000FF400000006000004060000080600000FF600000008000004080
000080800000FF80000000A0000040A0000080A00000FFA0000000C0000040C0
000080C00000FFC0000000FF000040FF000080FF0000FFFF0000000020004000
200080002000FF002000002020004020200080202000FF202000004020004040
200080402000FF402000006020004060200080602000FF602000008020004080
200080802000FF80200000A0200040A0200080A02000FFA0200000C0200040C0
200080C02000FFC0200000FF200040FF200080FF2000FFFF2000000040004000
400080004000FF004000002040004020400080204000FF204000004040004040
400080404000FF404000006040004060400080604000FF604000008040004080
400080804000FF80400000A0400040A0400080A04000FFA0400000C0400040C0
400080C04000FFC0400000FF400040FF400080FF4000FFFF4000000060004000
600080006000FF006000002060004020600080206000FF206000004060004040
600080406000FF406000006060004060600080606000FF606000008060004080
600080806000FF80600000A0600040A0600080A06000FFA0600000C0600040C0
600080C06000FFC0600000FF600040FF600080FF6000FFFF6000000080004000
800080008000FF008000002080004020800080208000FF208000004080004040
800080408000FF408000006080004060800080608000FF608000008080004080
800080808000FF80800000A0800040A0800080A08000FFA0800000C0800040C0
800080C08000FFC0800000FF800040FF800080FF8000FFFF80000000A0004000
A0008000A000FF00A0000020A0004020A0008020A000FF20A0000040A0004040
A0008040A000FF40A0000060A0004060A0008060A000FF60A0000080A0004080
A0008080A000FF80A00000A0A00040A0A00080A0A000FFA0A00000C0A00040C0
A00080C0A000FFC0A00000FFA00040FFA00080FFA000FFFFA0000000C0004000
C0008000C000FF00C0000020C0004020C0008020C000FF20C0000040C0004040
C0008040C000FF40C0000060C0004060C0008060C000FF60C0000080C0004080
C0008080C000FF80C00000A0C00040A0C00080A0C000FFA0C00000C0C00040C0
C00080C0C000FFC0C00000FFC00040FFC00080FFC000FFFFC0000000FF004000
FF008000FF00FF00FF000020FF004020FF008020FF00FF20FF000040FF004040
FF008040FF00FF40FF000060FF004060FF008060FF00FF60FF000080FF004080
FF008080FF00FF80FF0000A0FF0040A0FF0080A0FF00FFA0FF0000C0FF0040C0
FF0080C0FF00FFC0FF0000FFFF0040FFFF0080FFFF00FFFFFF00DBDBDBDBDBDB
DBDBDBDBDBDBDBDBDBDBDBDB0000000000000000000000DBDBDBDB00DBDBDBDB
DBDBDBDBDB00DB00DBDB00000000000000000000000000DB00DB00DBDBDBDBDB
DBFCFCFCDBDB000000DB00DBDBDBDBDBDB929292DBDB00DB00DB000000000000
00000000000000DBDB0000DBDBDBDBDBDBDBDBDBDB00DB00DB00DB0000000000
0000000000DB00DB0000DBDB00FFFFFFFFFFFFFFFF00DB00DB00DBDBDB00FF00
00000000FF00000000DBDBDBDB00FFFFFFFFFFFFFFFF00DBDBDBDBDBDBDB00FF
0000000000FF00DBDBDBDBDBDBDB00FFFFFFFFFFFFFFFF00DBDBDBDBDBDBDB00
0000000000000000DBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDB}
end
object btnFechar: TBitBtn
Left = 856
Top = 9
Width = 75
Height = 25
Action = actFechar
Anchors = [akTop, akRight]
Caption = '&Fechar'
TabOrder = 5
Glyph.Data = {
36030000424D3603000000000000360000002800000010000000100000000100
18000000000000030000120B0000120B00000000000000000000FF00FFFF00FF
FF00FFFF00FFFF00FFFF00FFFF00FF824B4B4E1E1FFF00FFFF00FFFF00FFFF00
FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FF824B4B824B4BA64B4BA9
4D4D4E1E1FFF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FF
824B4B824B4BB64F50C24F50C54D4EB24D4E4E1E1F824B4B824B4B824B4B824B
4B824B4B824B4BFF00FFFF00FFFF00FF824B4BD45859CB5556C95455C95253B7
4F524E1E1FFE8B8CFB9A9CF8AAABF7B5B6F7B5B6824B4BFF00FFFF00FFFF00FF
824B4BD75C5DD05A5BCF595ACF5758BD53564E1E1F23B54A13C14816BD480CBC
41F7B5B6824B4BFF00FFFF00FFFF00FF824B4BDD6364D75F60D55E5FD55C5DC2
575A4E1E1F2AB44D1CBF4C1EBC4C13BC45F7B5B6824B4BFF00FFFF00FFFF00FF
824B4BE36869DD6566DA6364DE6667C6595B4E1E1F26B14916BC481BBB4910BB
43F7B5B6824B4BFF00FFFF00FFFF00FF824B4BEB6D6EE26768E67E7FFAD3D4CC
6E704E1E1FA5D89750D16F42C9662DC758F7B5B6824B4BFF00FFFF00FFFF00FF
824B4BF27374E96C6DEB8182FCD1D3CF6E704E1E1FFFF2CCFFFFD7FFFFD4E6FC
C7F7B5B6824B4BFF00FFFF00FFFF00FF824B4BF87879F07576EE7273F07374D1
65664E1E1FFCEFC7FFFFD5FFFFD3FFFFD7F7B5B6824B4BFF00FFFF00FFFF00FF
824B4BFE7F80F77A7BF6797AF77779D76B6B4E1E1FFCEFC7FFFFD5FFFFD3FFFF
D5F7B5B6824B4BFF00FFFF00FFFF00FF824B4BFF8384FC7F80FB7E7FFE7F80DA
6E6F4E1E1FFCEFC7FFFFD5FFFFD3FFFFD5F7B5B6824B4BFF00FFFF00FFFF00FF
824B4BFF8889FF8283FF8182FF8283E073744E1E1FFCEFC7FFFFD5FFFFD3FFFF
D5F7B5B6824B4BFF00FFFF00FFFF00FF824B4B824B4BE27576FE8182FF8687E5
76774E1E1FFAEBC5FCFBD1FCFBCFFCFBD1F7B5B6824B4BFF00FFFF00FFFF00FF
FF00FFFF00FF824B4B9C5657CB6C6DCF6E6E4E1E1F824B4B824B4B824B4B824B
4B824B4B824B4BFF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FF824B4B82
4B4B4E1E1FFF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FF}
end
object btnGeraPDF: TBitBtn
Left = 600
Top = 9
Width = 75
Height = 25
Hint = 'Gerar boletos em arquivo no formato PDF'
Anchors = [akTop, akRight]
Caption = '&Gerar PDF'
TabOrder = 2
OnClick = btnGeraPDFClick
Glyph.Data = {
36030000424D3603000000000000360000002800000010000000100000000100
18000000000000030000C40E0000C40E00000000000000000000FFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA7A7A762626260606060606060606060
6060606060606060606060606060646464BDBDBDFFFFFFFFFFFFFFFFFFC9C9C9
4D4D4DB3B3B3B6B6B6B1B1B1AFAFAFADADADABABABAAAAAAA8A8A8A6A6A69B9B
9B232323E9E9E9FFFFFFFFFFFFA7A7A7959595DDDDDDE0E0E0C4C8DDDADADADB
DBDBDADADAD9D9D9D8D8D8D7D7D7D4D4D4474747CDCDCDFFFFFFFFFFFFA7A7A7
979797DFDFDFC6CBE54C63E87B8ADED9D9D9DCDCDCDBDBDBDADADAD9D9D9D7D7
D7474747CDCDCDFFFFFFFFFFFFA7A7A7989898E0E0E0E4E4E4B5BCE55F74E88F
9BDBDDDDDCDDDDDDDCDCDCD9D9D9D1D1D1474747CDCDCDFFFFFFFFFFFFA7A7A7
989898D2D2D2E5E5E5E2E2E2E1E1E15169EF7383E18E9AE0A6AFE17082E5C4C6
D2484848CDCDCDFFFFFFFFFFFFA7A7A7999999E4E4E4E7E7E7E4E4E4E3E3E398
A4EAAAB1DB9BA6E8536AEB798AEACBCEDD484848CDCDCDFFFFFFFFFFFFA7A7A7
9A9A9AE6E6E6E8E8E8E6E6E6E5E5E5D6D8E5677AE44A63EDDADBDEE0E0E0DFDF
DF494949CDCDCDFFFFFFFFFFFFA7A7A79B9B9BE8E8E8EAEAEAE7E7E7E6E6E6E6
E6E53854F39FA9E2E2E2E2E2E2E2E1E1E1494949CDCDCDFFFFFFFFFFFFA7A7A7
9A9A9AD7D7D7ECECECE9E9E9E8E8E8E8E7E73E59F1DFDFDEE4E4E4E3E3E3E2E2
E24A4A4ACDCDCDFFFFFFFFFFFFA7A7A79D9D9DECECECEDEDEDEBEBEBEAEAEADB
DDEA1637F5DCDCDEE6E6E6E5E5E5E4E4E44B4B4BCDCDCDFFFFFFFFFFFFA7A7A7
9E9E9EEEEEEEEFEFEFEDEDEDECECECE4E5EB4F67F2E4E4E4E8E8E8E7E7E7E6E6
E64C4C4CCDCDCDFFFFFFFFFFFFA9A9A9999999F0F0F0F0F0F0EEEEEEEDEDEDEC
ECECEBEBEBEAEAEAE9E9E9E8E8E8E7E7E74A4A4AD1D1D1FFFFFFFFFFFFE7E7E7
3333336F6F6F6F6F6F6F6F6F6E6E6E6D6D6D6C6C6C6B6B6B6B6B6B6A6A6A5F5F
5F343434F9F9F9FFFFFFFFFFFFFFFFFFEFEFEFC3C3C3C1C1C1C1C1C1C1C1C1C1
C1C1C1C1C1C1C1C1C1C1C1C1C1C1C5C5C5F5F5F5FFFFFFFFFFFF}
end
object btEtiqueta: TBitBtn
Left = 770
Top = 9
Width = 75
Height = 25
Hint = 'Impress'#227'o de etiqueta de clientes'
Anchors = [akTop, akRight]
Caption = '&Etiqueta'
TabOrder = 4
OnClick = btEtiquetaClick
Glyph.Data = {
36050000424D3605000000000000360400002800000010000000100000000100
08000000000000010000430B0000430B00000001000027000000000000004000
000080000000FF000000002000004020000080200000FF200000004000004040
000080400000FF400000006000004060000080600000FF600000008000004080
000080800000FF80000000A0000040A0000080A00000FFA0000000C0000040C0
000080C00000FFC0000000FF000040FF000080FF0000FFFF0000000020004000
200080002000FF002000002020004020200080202000FF202000004020004040
200080402000FF402000006020004060200080602000FF602000008020004080
200080802000FF80200000A0200040A0200080A02000FFA0200000C0200040C0
200080C02000FFC0200000FF200040FF200080FF2000FFFF2000000040004000
400080004000FF004000002040004020400080204000FF204000004040004040
400080404000FF404000006040004060400080604000FF604000008040004080
400080804000FF80400000A0400040A0400080A04000FFA0400000C0400040C0
400080C04000FFC0400000FF400040FF400080FF4000FFFF4000000060004000
600080006000FF006000002060004020600080206000FF206000004060004040
600080406000FF406000006060004060600080606000FF606000008060004080
600080806000FF80600000A0600040A0600080A06000FFA0600000C0600040C0
600080C06000FFC0600000FF600040FF600080FF6000FFFF6000000080004000
800080008000FF008000002080004020800080208000FF208000004080004040
800080408000FF408000006080004060800080608000FF608000008080004080
800080808000FF80800000A0800040A0800080A08000FFA0800000C0800040C0
800080C08000FFC0800000FF800040FF800080FF8000FFFF80000000A0004000
A0008000A000FF00A0000020A0004020A0008020A000FF20A0000040A0004040
A0008040A000FF40A0000060A0004060A0008060A000FF60A0000080A0004080
A0008080A000FF80A00000A0A00040A0A00080A0A000FFA0A00000C0A00040C0
A00080C0A000FFC0A00000FFA00040FFA00080FFA000FFFFA0000000C0004000
C0008000C000FF00C0000020C0004020C0008020C000FF20C0000040C0004040
C0008040C000FF40C0000060C0004060C0008060C000FF60C0000080C0004080
C0008080C000FF80C00000A0C00040A0C00080A0C000FFA0C00000C0C00040C0
C00080C0C000FFC0C00000FFC00040FFC00080FFC000FFFFC0000000FF004000
FF008000FF00FF00FF000020FF004020FF008020FF00FF20FF000040FF004040
FF008040FF00FF40FF000060FF004060FF008060FF00FF60FF000080FF004080
FF008080FF00FF80FF0000A0FF0040A0FF0080A0FF00FFA0FF0000C0FF0040C0
FF0080C0FF00FFC0FF0000FFFF0040FFFF0080FFFF00FFFFFF00E3E300E3E3E3
00E3E300E3E3E300E3E3E300E300E3E300E300E300E3E300E3E3E300E300E3E3
00E300E300E3E300E3E3E300E300E30000E300E300E30000E3E3E3E300E3E3E3
00E3E300E3E3E300E3E3E300000000000000000000E3E3E3E3E3E300FFFFFFFF
FFFFFFFF00E3E300E3E3E300FF929292929292DB00E3030300E3E300FFDBDBDB
DBDBDBDBFC0303030300E300FF929292929292FFFCE3030300E3E300FFFFFFFF
FFFFFFFF0000030300E3E300FF929292929203030303030300E3E300FFFFFFFF
FFFCFCFCFCE3E3E3E3E3E300FFFFFFFFFFFCFCFCE3E3E3E3E3E3E30000000000
000000E3E3E3E3E3E3E3E3E3E3E3E3E3E3E3E3E3E3E3E3E3E3E3}
end
object btnCarne: TBitBtn
Left = 683
Top = 9
Width = 75
Height = 25
Hint = 'Impress'#227'o de carn'#234' do clientes'
Anchors = [akTop, akRight]
Caption = 'C&arn'#234
TabOrder = 3
OnClick = btnCarneClick
Glyph.Data = {
36030000424D3603000000000000360000002800000010000000100000000100
18000000000000030000C40E0000C40E000000000000000000009F9F9F000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000009F9F9F000000F5F5F5F5F5F5F5F5F5F5F6F6F6F5F5F6F6F6F7
F7F7F8F8F8F9F9FAFBFBFAFCFCFCFDFEFDFEFFFFFFFFFF000000000000FFFFFF
F2F2F3F3F2F2F3F3F3F3F3F4F4F4F4F5F5F5F7F6F6F7F7F7F8F9F8FAFAFAFCFB
FBFDFDFDFEFEFF000000000000FFFFFFF0F0F0666667F1F1F1676767F2F2F267
6767686868F5F6F5696969F8F9F86A6A6AFCFCFBFEFDFD000000000000FFFFFF
EEEEEE656565EEEFEEEFEFEFF0EFF0F1F1F1F2F2F2F3F3F3F4F4F5F6F6F76A6A
6AF9FAFAFCFCFC000000000000FFFFFFECECEC646464ECECEC656565656565EF
EFEF666666F2F2F1676767F5F5F5696969F9F9F9FBFAFA000000000000FFFFFF
E9E9E9646363EAEAEA646464646464EDEDED656565F0F0F0676767F4F3F36868
68F7F7F7F9FAF9000000000000FFFFFFE7E7E7626262E7E8E8636363646364EB
EBEC646464EFEEEF666666F2F2F2686868F6F6F6F8F8F9000000000000FFFFFF
E5E4E5616161E5E5E6626262626263EAE9EA646464EDEDED656666F1F1F16767
67F5F5F5F7F8F7000000000000FFFFFFE2E2E2616160E4E3E3616161626262E8
E8E8646364ECECEC656565F0F0F0676767F4F4F4F7F7F6000000000000FFFFFF
E0E0E05F6060E1E1E1616161616161E6E7E7636363EBEAEA656565EFEFEF6767
67F4F3F4F6F5F6000000000000FFFFFFDDDEDE5E5E5EE0E0E0606060616161E5
E5E5626362EAEAEA646464EEEEEE666666F3F3F2F5F6F5000000000000FFFFFF
DBDBDB5E5E5EDEDEDE5F6060606160E5E5E5626262E9EAEA646464EEEEEE6666
66F2F2F3F5F5F5000000000000FFFFFFD9D9D9DBDCDBDDDEDEE0E0E0E2E2E2E4
E5E4E7E7E7E9EAE9EBEBECEEEEEEF0F0F0F2F2F2F5F4F5000000000000FFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFF5F4F50000009F9F9F00000000000000000000000000000000000000
00000000000000000000000000000000000000000000009F9F9F}
end
object DBNavigator1: TDBNavigator
Left = 176
Top = 9
Width = 168
Height = 25
DataSource = dsConsulta
VisibleButtons = [nbFirst, nbPrior, nbNext, nbLast]
TabOrder = 6
end
end
object mmPrincipal: TMainMenu
Images = ImageList1
Left = 616
Top = 104
object mnuArquivo: TMenuItem
Caption = '&Arquivo'
object mnuVisualizarItem: TMenuItem
Action = actVisualizar
end
object mnuImprimirItem: TMenuItem
Action = actImprimir
end
object N5: TMenuItem
Caption = '-'
end
object GeraRemessa1: TMenuItem
Action = actGeraRemessa
end
object N4: TMenuItem
Caption = '-'
end
object mnuReciboItem: TMenuItem
Caption = '&Recibo...'
OnClick = mnuReciboItemClick
end
object ListadeCancelados1: TMenuItem
Action = actListaCanc
end
object N3: TMenuItem
Caption = '-'
end
object mnuEnviarEmailItem: TMenuItem
Caption = 'Enviar Email'
ImageIndex = 6
object mnuEnviarEmailClienteSelecionadoItem: TMenuItem
Action = actEmailNew
end
object mnuEnviarTodosItem: TMenuItem
Action = actEnviarEmail
end
end
object N2: TMenuItem
Caption = '-'
end
object Configuraes1: TMenuItem
Action = actConfig
end
object N1: TMenuItem
Caption = '-'
end
object mnuSairItem: TMenuItem
Action = actFechar
end
end
object mnuLocalizar: TMenuItem
Caption = '&Localizar'
object mnuClienteItem: TMenuItem
Action = actLocCliente
end
end
object mnuAjuda: TMenuItem
Caption = 'A&juda'
object Sobre1: TMenuItem
Action = actSobre
end
end
end
object dsConsulta: TDataSource
AutoEdit = False
DataSet = dmDados.ZQryCReceber
OnDataChange = dsConsultaDataChange
Left = 560
Top = 96
end
object ActionList1: TActionList
Images = ImageList1
Left = 512
Top = 96
object actVisualizar: TAction
Caption = '&Visualizar'
Hint = 'Visualizar Impress'#227'o'
ImageIndex = 2
OnExecute = actVisualizarExecute
end
object actImprimir: TAction
Caption = '&Imprimir'
Hint = 'Imprimir Todos os Boletos'
ImageIndex = 3
OnExecute = actImprimirExecute
end
object actConsulta: TAction
Caption = '&Consultar'
Hint = 'Clique aqui para consultar o per'#237'odo indicado.'
ImageIndex = 1
OnExecute = actConsultaExecute
end
object actFechar: TAction
Caption = '&Fechar'
Hint = 'Sair do Sistema'
ImageIndex = 0
OnExecute = actFecharExecute
end
object actSobre: TAction
Caption = '&Sobre'
ImageIndex = 4
OnExecute = actSobreExecute
end
object actLocCliente: TAction
Caption = '&Cliente por Nome'
Hint = 'Localizar Cliente'
ImageIndex = 5
ShortCut = 116
OnExecute = actLocClienteExecute
end
object actConfig: TAction
Caption = 'Configura'#231#245'es'
OnExecute = actConfigExecute
end
object actEnviarEmail: TAction
Caption = 'Enviar Email para Todos...'
OnExecute = actEnviarEmailExecute
end
object actListaCanc: TAction
Caption = 'Lista de Cancelados'
OnExecute = actListaCancExecute
end
object actGeraRemessa: TAction
Caption = 'Gera &Remessa para Banco'
ImageIndex = 7
OnExecute = actGeraRemessaExecute
end
object actEmailNew: TAction
Caption = 'Enviar Email Cliente Selecionado...'
OnExecute = actEmailNewExecute
end
end
object ImageList1: TImageList
Left = 432
Top = 176
Bitmap = {
494C010108000900040010001000FFFFFFFFFF10FFFFFFFFFFFFFFFF424D3600
0000000000003600000028000000400000003000000001002000000000000030
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
00000000000000000000D5AA9800BDA39800B4968B00C99E8E00000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000D8AA9700CEBFBB00B7BBC0009E9CA0009F8C8600D8AA97000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000FF000000
0000000000000000000000000000000000000000000000000000000000000000
0000D8AF9A00E1D1CE00DADDE100C2917E00B4837000A09A9D00A08E8800C79E
8C00000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000FFFFFF00FFFFFF00FFFF
FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00000000000000
0000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000FF000000
FF0000000000000000000000000000000000000000000000000000000000D8AA
9700EADED900F2FEFF00C67D5D00A7250300AA260300B1654800A39FA3009E8A
8700D8AA97000000000000000000000000000000000000000000000000000000
0000FFFFFF00FFFFFF0000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000FFFFFF00FFFF
FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000FF000000FF000000FF000000FF000000FF000000
FF000000FF000000000000000000000000000000000000000000D8AA9700EFE1
D900FEFFFF00CE876A00B5411A00DD9F8200DD9E8100B8421A00B05E4000A19E
A3009E8B8700C69D8B0000000000000000000000000000000000000000000000
000000000000FFFFFF00FFFFFF00000000000000000000000000000000000000
00000000000000000000000000000000000000000000FFFFFF0000000000FFFF
FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF0000000000FFFFFF00FFFFFF00C0C0
C000C0C0C000C0C0C000C0C0C0000000000000000000FFFFFF00FFFFFF00FFFF
FF00FFFFFF00000000000000FF000000FF000000FF000000FF000000FF000000
FF000000FF000000FF00000000000000000000000000D8AA9700F2E2DD00FFFF
FF00D58F7200A72A0600AD361000F6E5DC00F4E1D700AD361000AC2D0800B162
4300A39EA1009E8A8700D8AA9700000000000000000000000000000000000000
00000000000000000000FFFFFF00FFFFFF000000000000000000000000000000
00000000000000000000000000000000000000000000FFFFFF00FFFFFF000000
0000FFFFFF00FFFFFF00FFFFFF00000000000000000000FFFF00808080000000
00000000000080808000C0C0C0000000000000000000FFFFFF00FFFFFF00FFFF
FF00FFFFFF00000000000000FF000000FF000000FF000000FF000000FF000000
FF000000FF000000FF000000FF0000000000D8AA9600F2E1DA00FFFFFF00E1A6
8800B43B1000B0350F00AF360F00F2D8CC00F0D4C700AD330E00AC310D00AD2D
0800B05E4000A0989C0099888400C79E8B000000000000000000000000000000
0000000000000000000000000000FFFFFF00FFFFFF00FFFFFF00000000000000
00000000000000000000000000000000000000000000FFFFFF0000000000FFFF
FF00000000000000000000000000FFFFFF0000000000FFFFFF0000000000C0C0
C000FFFFFF0000000000C0C0C0000000000000000000FFFFFF00000000000000
0000FFFFFF00000000000000FF000000FF000000FF000000FF000000FF000000
FF000000FF000000FF000000000000000000E0BAAA00FFFFFF00F3D9C500C65D
2700C0542200BB4A1C00B6411700F3DCCF00F0D5C900AD340F00AC320D00AD35
0F00AD2C0700B47F6A009F9EA100B1958B000000000000000000000000000000
FF0000000000000000000000000000000000FFFFFF0000008000000080000000
8000000080000000000000000000000000000000000000000000FFFFFF00C0C0
C000FFFFFF00C0C0C000FFFFFF00C0C0C0000000000000FFFF0000000000C0C0
C00000FFFF0000000000C0C0C0000000000000000000FFFFFF00FFFFFF00FFFF
FF00FFFFFF00000000000000FF000000FF000000FF000000FF000000FF000000
FF000000FF00000000000000000000000000E0BAAA00FFFFFF00F6DECB00D376
3600CC692F00C65D2800C0542200F6E3D800F2DACE00AF371000AC320D00AC32
0D00AB2E0900C2978700B8BBC000C1A398000000000000000000000000000000
00000000FF000000000000000000000000000000800000008000000080000000
00000000000000FFFF00000000000000000000000000FFFFFF00C0C0C000FFFF
FF00C0C0C000FFFFFF00C0C0C000FFFFFF0000000000FFFFFF0000000000C0C0
C000FFFFFF0000000000C0C0C0000000000000000000FFFFFF00000000000000
0000FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00000000000000FF000000
FF0000000000000000000000000000000000D8AA9600F2E1D900FFFFFF00EFCB
A700D57D3B00CE6F3100D37B4600F2D4BF00E7BA9F00B8451900B0370F00AA2D
0900CA886D00DAE1E500CFBCB600D5A793000000000000000000000000000000
00000000000000000000000000000000FF000000FF0000008000000000000000
000000FFFF000000000000000000000000000000000000000000FFFFFF00C0C0
C000FFFFFF00C0C0C000FFFFFF00C0C0C0000000000000FFFF0000000000C0C0
C00000FFFF0000000000C0C0C0000000000000000000FFFFFF00FFFFFF00FFFF
FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00000000000000FF000000
00000000000000000000000000000000000000000000D8AA9700EFDDD500FFFF
FF00F3D4B200DC8A4500D57E3E00D8895500D0794800C0542100BB471800D79A
7F00F0FEFF00E0CFC900D8AA9700000000000000000000000000000000000000
00000000000000000000000000000000FF000000FF000000FF000000000000FF
FF0000000000000000000000000000000000000000000000000000000000FFFF
FF00C0C0C000FFFFFF00C0C0C000FFFFFF0000000000FFFFFF0000000000C0C0
C000FFFFFF0000000000C0C0C0000000000000000000FFFFFF00000000000000
0000FFFFFF000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000D7A79300EEDD
D400FFFFFF00F6D7B600E0924A00FAEADA00F7E0D000C9642800E1A48200FEFF
FF00E9DCD700D7AA970000000000000000000000000000000000000000000000
00000000000000000000000000000000FF000000FF000000000000FFFF000000
0000000000000000000000000000000000000000000000000000000000000000
0000FFFFFF00C0C0C000FFFFFF00000000000000000000FFFF0000000000C0C0
C00000FFFF00FFFFFF0000FFFF000000000000000000FFFFFF00FFFFFF00FFFF
FF00FFFFFF0000000000FFFFFF00FFFFFF000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000D8AA
9700EEDAD000FFFFFF00F6DCBB00F0C58F00EAB07900EBBC9300FFFFFF00F0E2
DA00D8AA97000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000FF000000000000FFFF00000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000008080
80008080800000000000000000000000000000000000FFFFFF0000000000BFBF
BF00FFFFFF0000000000FFFFFF00000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000D7A69100EED9D000FFFFFF00FAEAD300F6E0C600FFFFFF00F4E5DE00D8AD
9900000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000FFFF0000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000C0C0
C000FFFFFF0000000000000000000000000000000000FFFFFF00FFFFFF00FFFF
FF00FFFFFF000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000D8AA9700EED9CF00FFFFFF00FFFFFF00F3E6E000D8AA97000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000808080000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
00000000000000000000D8AA9600E0BAAA00E0BAAA00D8AA9600000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000824B4B004E1E1F0000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000A4676900A467
6900A4676900A4676900A4676900A4676900A4676900A4676900A4676900A467
6900A4676900A4676900A4676900000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000824B4B00824B4B00A64B4B00A94D4D004E1E1F0000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000048536000FEE9
C700F4DAB500F3D5AA00F2D0A000EFCB9600EFC68B00EDC18200EBC17F00EBC1
8000EBC18000F2C78200A4676900000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000824B4B00824B
4B00B64F5000C24F5000C54D4E00B24D4E004E1E1F00824B4B00824B4B00824B
4B00824B4B00824B4B00824B4B00000000008400000084000000840000008400
0000840000000000000000000000000000000000000000000000840000008400
000084000000840000008400000000000000000000004380B7001F6FC200656B
8600F3DABC00F2D5B100F0D0A700EECB9E00EDC79300EDC28B00E9BD8100E9BD
7F00E9BD7F00EFC48100A4676900000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000824B4B00D458
5900CB555600C9545500C9525300B74F52004E1E1F00FE8B8C00FB9A9C00F8AA
AB00F7B5B600F7B5B600824B4B00000000008400000000FFFF00840000008400
00008400000000000000000000000000000000000000000000008400000000FF
FF0084000000840000008400000000000000000000000000000032A3FF001672
D7006B6A8000F2DABC00F2D5B200EFD0A900EECB9E00EDC79600EBC28C00E9BD
8200E9BD7F00EFC48100A4676900000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000824B4B00D75C
5D00D05A5B00CF595A00CF575800BD5356004E1E1F0023B54A0013C1480016BD
48000CBC4100F7B5B600824B4B00000000008400000000FFFF00840000008400
00008400000000000000000000000000000000000000000000008400000000FF
FF00840000008400000084000000000000000000000000000000A0675B0034A1
FF001572D4005E678200F3DABB00F2D5B100F0D0A600EECB9E00EDC79500EBC2
8A00EABF8100EFC48000A4676900000000000000000000000000000000000000
000000000000000000000000000000FFFF0000FFFF0000FFFF00000000000000
0000000000000000000000000000000000000000000000000000824B4B00DD63
6400D75F6000D55E5F00D55C5D00C2575A004E1E1F002AB44D001CBF4C001EBC
4C0013BC4500F7B5B600824B4B00000000008400000084000000840000008400
0000840000008400000084000000000000008400000084000000840000008400
0000840000008400000084000000000000000000000000000000A7756B00FFFB
F00033A6FF004078AD008E675E00AC7F750097645E00AC7D6F00CAA08300EDC6
9500EBC28A00EFC58300A4676900000000000000000000000000000000000000
0000000000000000000000000000808080008080800080808000000000000000
0000000000000000000000000000000000000000000000000000824B4B00E368
6900DD656600DA636400DE666700C6595B004E1E1F0026B1490016BC48001BBB
490010BB4300F7B5B600824B4B0000000000840000008400000000FFFF008400
0000840000008400000084000000840000008400000000FFFF00840000008400
0000840000008400000084000000000000000000000000000000A7756B00FFFF
FC00FAF0E600AD8A8800B78F8400D8BAA500EED5B600D7B29800B5887700CBA0
8300EBC79300F2C98C00A4676900000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000824B4B00EB6D
6E00E2676800E67E7F00FAD3D400CC6E70004E1E1F00A5D8970050D16F0042C9
66002DC75800F7B5B600824B4B0000000000840000008400000000FFFF008400
0000840000008400000000000000840000008400000000FFFF00840000008400
0000840000008400000084000000000000000000000000000000BC826800FFFF
FF00FEF7F200AF847F00DAC0B400F7E3CF00F6E0C500FFFFF400D7B19800AC7D
6F00EECC9E00F3CE9700A4676900000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000824B4B00F273
7400E96C6D00EB818200FCD1D300CF6E70004E1E1F00FFF2CC00FFFFD700FFFF
D400E6FCC700F7B5B600824B4B0000000000840000008400000000FFFF008400
0000840000008400000000000000840000008400000000FFFF00840000008400
0000840000008400000084000000000000000000000000000000BC826800FFFF
FF00FFFEFC0097656000F6E9E000F7EADA00F6E3CF00FFFFEB00EFD4B7009764
5E00F0D0A600F6D3A000A4676900000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000824B4B00F878
7900F0757600EE727300F0737400D16566004E1E1F00FCEFC700FFFFD500FFFF
D300FFFFD700F7B5B600824B4B00000000000000000084000000840000008400
0000840000008400000084000000840000008400000084000000840000008400
0000840000008400000000000000000000000000000000000000D1926D00FFFF
FF00FFFFFF00B0888400DECAC400FAEFE500F8EAD900FFFFD400D9B8A500AC7F
7400F4D8B100EBCFA400A467690000000000000000000000000000000000FFFF
FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF000000
0000000000000000000000000000000000000000000000000000824B4B00FE7F
8000F77A7B00F6797A00F7777900D76B6B004E1E1F00FCEFC700FFFFD500FFFF
D300FFFFD500F7B5B600824B4B000000000000000000000000008400000000FF
FF00840000008400000084000000000000008400000000FFFF00840000008400
0000840000000000000000000000000000000000000000000000D1926D00FFFF
FF00FFFFFF00D5BFBC00BA979300DECAC400F6E9DE00DAC0B400B78F8400B28C
7B00DECEB400B6AA9300A4676900000000000000000000000000000000000000
0000FFFFFF000000000000000000000000000000000000000000FFFFFF000000
0000000000000000000000000000000000000000000000000000824B4B00FF83
8400FC7F8000FB7E7F00FE7F8000DA6E6F004E1E1F00FCEFC700FFFFD500FFFF
D300FFFFD500F7B5B600824B4B00000000000000000000000000840000008400
0000840000008400000084000000000000008400000084000000840000008400
0000840000000000000000000000000000000000000000000000DA9D7500FFFF
FF00FFFFFF00FFFFFF00D5BFBC00B088840097656000AF867F00CAA79D00A56B
5F00A56B5F00A56B5F00A4676900000000000000000000000000000000000000
0000FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF
FF00000000000000000000000000000000000000000000000000824B4B00FF88
8900FF828300FF818200FF828300E07374004E1E1F00FCEFC700FFFFD500FFFF
D300FFFFD500F7B5B600824B4B00000000000000000000000000000000008400
0000840000008400000000000000000000000000000084000000840000008400
0000000000000000000000000000000000000000000000000000DA9D7500FFFF
FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFEFB00FFFEF700DAC1BA00A56B
5F00E19E5500E68F3100B56D4D00000000000000000000000000000000000000
000000000000FFFFFF000000000000000000000000000000000000000000FFFF
FF00000000000000000000000000000000000000000000000000824B4B00824B
4B00E2757600FE818200FF868700E57677004E1E1F00FAEBC500FCFBD100FCFB
CF00FCFBD100F7B5B600824B4B00000000000000000000000000000000008400
000000FFFF00840000000000000000000000000000008400000000FFFF008400
0000000000000000000000000000000000000000000000000000E7AB7900FFFF
FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00DCC7C500A56B
5F00F8B55C00BF7A5C0000000000000000000000000000000000000000000000
000000000000FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF
FF00FFFFFF000000000000000000000000000000000000000000000000000000
0000824B4B009C565700CB6C6D00CF6E6E004E1E1F00824B4B00824B4B00824B
4B00824B4B00824B4B00824B4B00000000000000000000000000000000008400
0000840000008400000000000000000000000000000084000000840000008400
0000000000000000000000000000000000000000000000000000E7AB7900FBF4
F000FBF4EF00FAF3EF00FAF3EF00F8F2EF00F7F2EF00F7F2EF00D8C2C000A56B
5F00C1836C000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
00000000000000000000824B4B00824B4B004E1E1F0000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000E7AB7900D192
6D00D1926D00D1926D00D1926D00D1926D00D1926D00D1926D00D1926D00A56B
5F00000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000424D3E000000000000003E000000
2800000040000000300000000100010000000000800100000000000000000000
000000000000000000000000FFFFFF0000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000FC3FFFFFFFFFFFDFF81FFFFF001FFFCF
F00FF3FF001FFFC7E007E1FF00000003C003D8FF000000018001DC7F00000000
0000EE0F000000010000E703000000030000F313000000070000FA278000000F
8001FC0FC000001FC003FC1FE000007FE007FC3FF10000FFF00FFE7FFFC301FF
F81FFFFFFFC703FFFC3FFFFFFFFFFFFFFE7FFFFFC001FFFFF07FFFFFC001C007
C00107C18001BFEBC00107C1C0010005C00107C1C0017E31C0010101C0017E35
C0010001C0010006C0010201C0017FEAC0010201C0018014C0018003C001C00A
C001C107C001E001C001C107C001E007C001E38FC001F007C001E38FC003F003
F001E38FC007F803FC7FFFFFC00FFFFF00000000000000000000000000000000
000000000000}
end
object RvProject1: TRvProject
Left = 560
Top = 230
end
object RvSystem1: TRvSystem
TitleSetup = 'Output Options'
TitleStatus = 'Report Status'
TitlePreview = 'Report Preview'
SystemFiler.StatusFormat = 'Generating page %p'
SystemPreview.ZoomFactor = 100.000000000000000000
SystemPrinter.ScaleX = 100.000000000000000000
SystemPrinter.ScaleY = 100.000000000000000000
SystemPrinter.StatusFormat = 'Printing page %p'
SystemPrinter.Title = 'ReportPrinter Report'
SystemPrinter.UnitsFactor = 1.000000000000000000
Left = 600
Top = 238
end
end
| 47.364516 | 117 | 0.804689 |
fcefec03027017fcf9ac5d2596484ac963d41ea9 | 66,509 | pas | Pascal | RequestInfo.pas | randydom/commonx | 2315f1acf41167bd77ba4d040b3f5b15a5c5b81a | [
"MIT"
]
| 1 | 2020-08-25T00:02:54.000Z | 2020-08-25T00:02:54.000Z | RequestInfo.pas | randydom/commonx | 2315f1acf41167bd77ba4d040b3f5b15a5c5b81a | [
"MIT"
]
| null | null | null | RequestInfo.pas | randydom/commonx | 2315f1acf41167bd77ba4d040b3f5b15a5c5b81a | [
"MIT"
]
| 1 | 2020-02-13T02:33:54.000Z | 2020-02-13T02:33:54.000Z | unit RequestInfo;
interface
uses typex, classes, DataObjectCache, DataObjectServices, DataObjectCacheManager, DataObject, ServerInterfaceInterface, windows,
errorHandler, Exceptions, ErrorResource, webstring, webconfig, sharedobject, stringx, XMLTools, variants, simpleserverinterface, httpclient, variantlist, interfacelist, debug, sysutils;
type
EObjectMissing = class(Exception);
TRequestInfo = class;
TParamSource = (pcHeader, pcContent, pcCookie, pcInline, pcDirectory, pcGenerated);
TMotherShipWebRequest = class;
TMotherShipWebResponse = class;
TMotherShipWebHook = procedure of object;
TMotherShipWebChunkEvent = procedure of object;
TWebHookProcedure = procedure(rqInfo: TRequestInfo);
TRQConnectionCommand = (rqcAuto, rqcClose, rqcKeepAlive);
TProgressCallbackProcedure = procedure (pos, max: integer; sMessage: string) of object;
IVarpoolVarExtender = interface
['{E5075499-372E-4E01-A9C7-D2CB3D7BF14A}']
function LoadVar(sName: string): variant;
function AgeOfVar(sName: string):real;
function IsDefined(sVar: string): boolean;
end;
//------------------------------------------------------------------------------
TRequestInfo = class(TSharedObject)
//This class encapsulates TMotherShipWebRequest and TMotherShipWebResponse. And that's
//about it. The two classes it encapsulates represent all the information
//needed to be known about the request being made, and all the data
//that needs to be spoken for in the response.
private
FCopied: boolean;
FDTID: integer;
FISRNDTID: integer;
FSessionID: integer;
FPercentComplete: single;
FServer: IServerInterface;
FHTTPClient: THTTPClient;
FDoTransactions: boolean;
FNoHit: boolean;
FProgressMax: integer;
FProgressPos: integer;
FStatus: string;
FProgressHook: TProgressCallbackProcedure;
FPopto: TRequestInfo;
FThreadID: integer;
procedure SetHTTPClient(const Value: THTTPClient);
function GetHTTPClient: THTTPClient;
function GetThreadID: integer;
function InitDTID: integer;
function GetSessionID: integer;
procedure SetDTID(const Value: integer);
procedure SetISRNDTID(const Value: integer);
procedure SetSessionID(const Value: integer);
function GetSessionHash: string;
procedure SetSessionHash(const Value: string);
function GetDTID: integer;
function GetServer: IServerInterface;
function GetDoTransactions: boolean;
protected
bInitialized: boolean;
FRequest: TMotherShipWebRequest;
FResponse: TMotherShipWebResponse;
public
constructor Create;override;
constructor CopyCreate(source: TRequestInfo; bNewCache: boolean = true);
procedure BeforeDestruction;override;
destructor destroy; override;
property Request: TMotherShipWebRequest read FRequest;
property Response: TMotherShipWebResponse read FResponse;
procedure SetupDefaultVarPool;
procedure InitializeEngine;
property DTID: integer read GetDTID write SetDTID;
property SessionID: integer read GetSessionID write SetSessionID;
property SessionHash: string read GetSessionHash write SetSessionHash;
property Copied: boolean read FCopied;
procedure ForceInit;
property PercentComplete: single read FPErcentComplete write FPercentComplete;
property Server: IServerInterface read GetServer write FServer;
property DoTransactions: boolean read FDoTransactions write FDoTransactions;
procedure CloseServer;
property ProgressMax: integer read FProgressMax write FProgressMax;
property ProgressPos: integer read FProgressPos write FProgressPos;
property Status: string read FStatus write FStatus;
property ProgressHook: TProgressCallbackProcedure read FProgressHook write FProgresshook;
procedure UpdateProgress(pos, max: integer; sMessage: string);
function ProcessQuery(sQuery: string): string;
procedure Commit;
procedure Rollback;
property NoHit: boolean read FNoHit write FNoHit;
procedure SaveVar(sName, sValue: string);
procedure DeleteVar(sName: string);
function LoadVar(sName: string; sDefault: string = ''): string;overload;
function LoadVar(sName: string; iDefault: integer): integer;overload;
function LoadVar(sName: string; rDefault: real): real;overload;
procedure LoadVars;
procedure SaveVars;
property ThreadID: integer read GetThreadID write FThreadID;
property PopTo: TRequestInfo read FPopto write FPopTo;
function Push: TRequestInfo;
function Pop: TrequestInfo;
property HTTPClient: THTTPClient read GetHTTPClient write SetHTTPClient;
function StealHTTPClient: THTTPClient;
end;
//------------------------------------------------------------------------------
TMotherShipWebRequest = class(TFakeLockQueuedObject)
private
FClientIP: string;
FCopied: boolean;
FRequestInfo: TRequestInfo;
FOriginalDocument: string;
FIsSecure: boolean;
function GetUserAgent: string;
procedure SetParams(sName: string; const Value: string);
function GetReferer: string;
function GetParamsByPatternMatch(sLeftMatch: string;
idx: integer): string;
function GetParamNamesByPatternMatch(sLeftMatch: string;
idx: integer): string;
function GetParamPatternCount(sLeftMatch: string): integer;
procedure SetDocument(const Value: string);
function GetDocument: string;
function GetOriginalDocument: string;
function GetFullURL: string;
//Provides all needed information about the request being made of the
//Web server.
//Note: the only information that is represented is the information that
//we've determined we needed for MotherShip Web Learning Network.
protected
FRaw: string;
FContent: string;
Fheader: TStringList;
FCommand: string;
FDocument: string;
FDocumentExt: string;
FParams: TStringList;
FParamNames: TStringList;
FParamSources: TList;
FRequestContent: TStringList;
procedure SetBinaryContentLength(iLength: integer);
function GetParams(sName: string): string;
function GetParamCount: integer;
function GetParamNames(idx: integer): string;
function GetDocumentExt: string;
function GetParamSources(idx: integer): TParamSource;
function GetParamsByIndex(idx: integer): string;
public
constructor Create;override;
constructor CopyCreate(source: TMotherShipWebRequest); virtual;
destructor destroy; override;
procedure DecodeMultiPart;
procedure AddDirectoriesAsParameters;
//Request Parameters
procedure AddParam(sName, value: string; source: TParamSource);
//Used by the abstraction driver. Define all parameters passed through the
//HTTP request here
procedure RemoveParam(sName: string);
property IsSecure: boolean read FIsSecure write FIsSecure;
property Params[sName: string]: string read GetParams write SetParams; default;
//Lookup a parameter by name
property ParamCount: integer read GetParamCount;
property ParamNames[idx: integer]: string read GetParamNames;
//Lookup the name of a parameter by index
property ParamSources[idx: integer]: TParamSource read GetParamSources;
//Find the source of a param by index
property ParamsbyIndex[idx: integer]: string read GetParamsByIndex;
//Find a parameter by matching a pattern
property ParamsbyPatternMatch[sLeftMatch: string; idx: integer]: string read GetParamsByPatternMatch;
function ParamPatternSum(sPattern: string): real;
property ParamNamesbyPatternMatch[sLeftMatch: string; idx: integer]: string read GetParamNamesByPatternMatch;
//
property ParamPatternCount[sLeftMatch: string]: integer read GetParamPatternCount;
//Find the value of a param by index
function HasParam(sName: string): boolean;
function HasParamWithValue(sName: string): boolean;
function IndexOfParam(sName: string): integer;
//Returns whether or not a parameter has been defined by given name
property Command: string read FCommand write FCommand;
//GET/POST/PUT Command (also called METHOD)
property Document: string read GetDocument write SetDocument;
//Document being requested from server excluding HOST information.
property OriginalDocument: string read GetOriginalDocument;
//If document name was mangled by proxy, this will be different than Document. Shows the original document name
property DocumentExt: string read GetDocumentExt;
//Extension of document being requested.
property Raw: string read FRaw write Fraw;
//Place to put the raw HTTP header that was sent (may not be applicable in
//some implementations)
property Content: string read FContent write FContent;
property Header: TStringList read FHeader write FHeader;
//Content of HTTP request body -- used only for POST operations.
//property SessionID: integer read GetSessionID;
//Special place for database session as an integer (figured we would always
//need it)
property ClientIP: string read FClientIP write FClientIP;
property UserAgent: string read GetUserAgent;
property Copied: boolean read FCopied;
property Referer: string read GetReferer;
function RebuildInlineParameters: string;
function RebuildParameters: string;
procedure Default(sParamName, sDefaultValue: string);
property RequestInfo: TRequestInfo read FRequestInfo write FRequestInfo;
function PatternQuery(sPattern: string): TStringList;
property FullURL: string read GetFullURL;
end;
//------------------------------------------------------------------------------
TMotherShipWebResponse = class
private
FRequest: TMotherShipWebRequest;
FTransferEncoding: string;
FDoSendChunk: TMotherShipWebChunkEvent;
FDoSendHeader: TMotherShipWebHook;
FHeaderSent: boolean;
FNoDebug: boolean;
FRequestInfo: TRequestInfo;
FCopiedWithOldCache: boolean;
FFramed: boolean;
FSendTime: cardinal;
FOnResponseSent: TWebHookProcedure;
FMessage: string;
FcookieNames, FCookieValues: TStringList;
FDeleteStreamedFile: boolean;
FDeleteFile: string;
FDeleteTempFile: string;
FDEbugLog: TStringList;
FRawHeader: string;
FConnection: TRQConnectionCommand;
FExtenderStack: TInterfaceList;
FRangeStart: int64;
FRangeEnd: int64;
FAcceptRanges: boolean;
FFakeContentLength: boolean;
FIgnore: boolean;
function GetDataObjectCache: TDataObjectCache;
function GetObjectPool(sName: string): TDataObject;
procedure SetObjectPool(sName: string; const Value: TDataObject);
function GetDOSV: TDataObjectServices;
function getVarByIndex(idx: integer): string;
function GetVarNames(idx: integer): string;
procedure SetVarByIndex(idx: integer; const Value: string);
procedure SetVarNames(idx: integer; const Value: string);
function GetCookieCount: integer;
function GetCookieNames(idx: integer): string;
function GetCookieValues(idx: integer): string;
procedure SetContentStream(const Value: TStream);
function GetHasCache: boolean;
function GetXMLPool(sName: string): string;
procedure SetXMLPool(sName: string; const Value: string);
function GetXMLDocs(sName: string): TXmlDocument;
function GetDebugLog: TStringList;
procedure SetVArPoolExtender(const Value: IVarpoolVarExtender);
function GetVArPoolExtender: IVarpoolVarExtender;
protected
FContent: TStringList;
FContentType: string;
FContentEncoding: string;
FcontentStream: TStream;
FVarNames: TStringList;
FVarValues: TVariantlist;
FLocation: string;
FResultCode: integer;
FContentLength: int64;
FDOCache: TDataObjectCache;
bNeedsProcessing: boolean;
FObjectPool: TStringList;
FXMLPool: TStringList;
FAuthHeaders: tStringlist;
function GetVarpool(sVarName: string): variant;
procedure SetVarPool(sVarName: string; const Value: variant);
function GetVarCount: integer;
procedure Setlocation(sLoc: string);
public
constructor Create;reintroduce;virtual;
constructor CopyCreate(source: TMotherShipWebResponse; bNewCache: boolean = true);
destructor destroy; override;
procedure EmptyXMLPool;
procedure ProcessDynamicVariables(bAllowAlternateContentTypes: boolean);overload;
procedure ProcessDynamicVariables(progress_callback: TProgressCallbackProcedure);overload;
procedure ProcessDynamicVariables(bAllowAlternateContentTypes: boolean; progress_callback: TProgressCallbackProcedure);overload;
procedure ProcessDynamicVariables();overload;
//processes in-code variables marked [[[varname]]]
property Content: TStringList read FContent;
//Body of HTTP response (HTML or whatever goes here)
property ContentStream: TStream read FContentStream write SetContentStream;
//If assigned, response will override the use of the CONTENT parameter
//and instead use this stream class-- better suited for streaming files,
//CGI-generated graphics, or other binary types.
property Connection: TRQConnectionCommand read FConnection write FConnection;
property DeleteFileOnDestroy: string read FDeleteFile write FDeleteFile;
property DeleteTempFileOnDestroy: string read FDeleteTempFile write FDeleteTempFile;
procedure ProcessHTML;
//If a file is streamed via a TFileStream object attaached to the ContentStream property,
//setting this to TRUE will delete the file when the request is destroyed.
property ContentType: string read FContentType write FcontentType;
property ContentEncoding: string read FContentEncoding write FcontentEncoding;
//Content type as defined in HTTP response header -- defaults to "text/html"
property FakeContentLength: boolean read FFakeContentLength write FFakeContentLength;
property ContentLength: int64 read FContentLength write FContentLength;
//Length of Content -- if not specified, the implementation of the
//abstraction should automatically set it to the length of the
//content-stream or length
property TransferEncoding: string read FTransferEncoding write FTransferEncoding;
property Location: string read FLocation write Setlocation;
//Set location to send a redirect in the header of the HTTP response
property ResultCode: integer read FResultCode write FResultCode;
//Result code e.g. 404 Not Found, 200 Ok
property VarNames[idx: integer]: string read GetVarNames write SetVarNames;
property VarByIndex[idx: integer]: string read getVarByIndex write SetVarByIndex;
property VarPool[sVarName: string]: variant read GetVarpool write SetVarPool;
//Variable pool. Set variables here named identical to parameters in
//html encoded as such: [[[varname]]]. The variable will then be
//replaced with the value in the varpool.
property VarCount: integer read GetVarCount;
//Count of the numbder of variable in varpool.
function HasVar(sVarName: string): boolean;
//Returns whether or not the particular variable name is defined in the varpool.
procedure REmoveVAr(sName: string);
//remove a var
procedure SetupDefaultVarPool(request: TMotherShipWebRequest);
//Sets up a default Auto-Variable Pool from the parameters passed in an
//HTTP Request represented in the passed "request" parameter
property DOCache: TDataObjectCache read GetDataObjectCache;
property ObjectPool[sName: string]: TDataObject read GetObjectPool write SetObjectPool;
function HasObject(sName: string): boolean;
property Request: TMotherShipWebRequest read FRequest write FRequest;
property XMLPool[sName: string]: string read GetXMLPool write SetXMLPool;
//attaches XML to the document which may be used to supply dynamic data to the
//scripts. The documents are indexed by a string name. Don't start the name with a number
property XMlDocs[sName: string]: TXMLDocument read GetXMLDocs;
//when an XML string is added to the XMLPool it actually creates an instance
//of TXMLDocument and stores the string in it. you can get read-only access
//to the XML using the methods of TXMLDocument returned from this array property.
procedure AddAuthHeader(sValue: string);
procedure AddCookie(sName, sValue: string);overload;
procedure AddCookie(sFullCookie: string);overload;
//property CookieName: string read FCookieName write FCookieName;
//property CookieValue: string read FCookieValue write FCookieValue;
property CookieNames[idx: integer]: string read GetCookieNames;
property CookieValues[idx: integer]:string read GetCookieValues;
property CookieCount: integer read GetCookieCount;
property Message: string read FMessage write FMessage;
function VarPoolStatus: string;
property NeedsProcessing: boolean read bNeedsProcessing write bNeedsProcessing;
property DoSendChunk: TMotherShipWebChunkEvent read FDoSendChunk write FDoSendChunk;
property DoSendHeader: TMotherShipWebHook read FDoSendHeader write FDoSendHeader;
property HeaderSent: boolean read FHeaderSent;
property NoDebug: boolean read FNoDebug write FNoDebug;
property RequestInfo: TRequestInfo read FRequestInfo write FRequestInfo;
procedure SendChunk;overload;
procedure SendChunk(endrow: integer);overload;
procedure SendHeader;
procedure SendFooter;
property CopiedWithOldCache: boolean read FCopiedWithOldCAche;
property Framed: boolean read FFramed write Fframed;
property SendTime: cardinal read FSendTime write FSendTime;
property OnResponseSent: TWebHookProcedure read FOnResponseSent write FOnResponseSent;
property DOSV: TDataObjectServices read GetDOSV;
function ExportVarPool: string;
procedure ImportVarPool(sImportString: string);
property HasCache: boolean read GetHasCache;
procedure Default(varName, varValue: variant);
property DebugLog: TStringList read FDEbugLog;
procedure MassageDebugStats;
property RawHeader: string read FRawHeader write FRawHeader;
property VArpoolExtender: IVarpoolVarExtender read GetVArPoolExtender write SetVArPoolExtender;
procedure RaiseVarPool;
property RangeStart: int64 read FRangeStart write FRangeStart;
property RangeEnd: int64 read FRangeEnd write FRangeEnd;
property AcceptRanges: boolean read FAcceptRanges write FAcceptRanges;
property Ignore: boolean read FIgnore write FIgnore;
end;
implementation
uses webfunctions, requestManager, WebScript,
mothership_html_compiler;
//------------------------------------------------------------------------------
procedure CopyList(lstSource, lstTarget: TList);
var
t: integer;
begin
lstTarget.clear;
for t:= 0 to lstSource.count-1 do begin
lstTarget.Add(lstSource[t]);
end;
end;
//------------------------------------------------------------------------------
procedure CopyStringList(slSource: TStringList; slTarget: TStringList; bMakeThreadSafe: boolean = false);
var
t: integer;
s: string;
begin
slTarget.clear;
for t:= 0 to slSource.count-1 do begin
s := slSource[t];
//Make string safe across threads if specified
if bMakeThreadSafe then
UniqueString(s);
slTarget.AddObject(s, slSource.Objects[t]);
end;
end;
//------------------------------------------------------------------------------
procedure CopyVariantList(slSource: TVariantList; slTarget: TVariantList);
var
t: integer;
s: variant;
begin
slTarget.clear;
for t:= 0 to slSource.count-1 do begin
s := slSource[t];
slTarget.Add(s);
end;
end;
//------------------------------------------------------------------------------
{ TRequestInfo }
procedure TMotherShipWebRequest.AddDirectoriesAsParameters;
//This function takes the path to the file and add each subdirectory as a prameter
//dir1, dir2, dir3 etc.
var
sLeft, sRight: string;
t: integer;
begin
//ignore the first slash
SplitString(document, '/', sLeft, sRight);
t:= 1;
while SplitString(sRight, '/', sLeft, sRight) do begin
self.AddParam('_dir'+inttostr(t), DecodeWebString(sLeft, '*'), pcDirectory);
inc(t);
end;
self.AddParam('_dir'+inttostr(t), sLeft, pcDirectory);
end;
procedure TMotherShipWebRequest.AddParam(sName, value: string; source: TParamSource);
//Defines a parameter. To be used by the abstraction driver. The driver
//of the abstraction should do what is necessary to extract the parameters
//beit from the actual RAW HTTP header string itself, or by calling functions
//in ISAPI to return definitions that are from already-parsed HTTP headers.
//Source is an ennumerated type with values:
// pcHeader -- for parameters as part of the HTTP header e.g. User-Agent,
// referer, Content-Type, etc.
// pcContent -- parameters passed as a part of a HTTP post response.
// !!!Abstraction driver should ONLY parse the content
// of a POST operation if the CONTENT-TYPE of the body
// is "x-www-form-urlencoded" else it could be a JPG or something
// pcCookie -- cookie parameters
// pcInline -- parameters passed in-line as part of the URL
var
idx: integer;
begin
sName := lowercase(sName);
//if already has a param by name... overwrite it
idx := FParamNames.indexof(sName);
if idx>-1 then begin
//change existsing param
FParamNames[idx] := lowercase(sName);
FParams[idx] := value;
FParamSources[idx]:=pointer(source);
end
else begin
//add new param
FParamNames.add(lowercase(sName));
FParams.add(value);
FParamSources.add(pointer(source));
//sessionID hook
if (sName = 'sessionid') or (sName = 'key') then begin
RequestInfo.SessionHash := value;
end;
//user agent registration hook
if (sName = 'user-agent') then begin
RqMan.UserAgents.Tally(value);
end;
end;
end;
//------------------------------------------------------------------------------
procedure TRequestInfo.BeforeDestruction;
begin
try
FHttpClient.free;
except
end;
inherited;
end;
procedure TRequestInfo.CloseServer;
begin
if self.Response.FDOCache <> nil then begin
self.Response.FDOCache.server := nil;
DOCM.FreeCache(self.Response.FDOCache);
self.response.FDOCache := nil;
end;
Response.FObjectPool.Clear;
//FServer.free;
DOSVPool[DTID].NoNeedServer(FServer);
FServer := nil;
end;
procedure TRequestInfo.Commit;
begin
if assigned(self.FServer) then
server.Commit;
end;
constructor TRequestInfo.CopyCreate(source: TRequestInfo; bNewCache: boolean = true);
begin
debug.log('Request Info Copied','leak');
inherited;
FRequest := TMotherShipWebRequest.CopyCreate(source.request);
FResponse := TMotherShipWebResponse.CopyCreate(source.FResponse, bNewCache);
FResponse.Request := FRequest;
self.DoTransactions := source.DoTransactions;
FResponse.RequestInfo := self;
FRequest.RequestInfo := self;
FSessionID := source.FSessionID;
FDTID := source.FDTID;
FISRNDTID := source.FISRNDTID;
FCopied := true;
if bNewCache then begin
FServer := nil;
end else begin
FServer := source.FServer;
end;
//inc(GelementCount);
//writeln('+',GElementCount);
end;
//------------------------------------------------------------------------------
constructor TRequestInfo.Create;
begin
// debug.log('Request Info Created','leak');
inherited;
FThreadID := GetCurrentThreadID;
FSessionID := -1;
bInitialized := false;
FRequest := nil;
FResponse := nil;
try
FRequest := TMotherShipWebRequest.create;
FResponse := TMotherShipWebResponse.create;
finally
end;
FResponse.Request := FRequest;
FResponse.RequestInfo := self;
FRequest.RequestInfo := self;
FRequest.Default('Host', '');
Fcopied:=false;
FDTID := 0;
rqMan.RegisterRequest(self);
DoTransactions := true;
//StrAlloc(1000000);
//inc(GelementCount);
//writeln('+',GElementCount);
end;
procedure TRequestInfo.DeleteVar(sName: string);
begin
server.UpdateQuery(response.DOCache,'DELETE from session_vars where varname="'+sName+'" and sessionid='+inttostr(sessionid), sessionid);
end;
//------------------------------------------------------------------------------
destructor TRequestInfo.destroy;
begin
// debug.log('Request Info Destroyed','leak');
rqMan.DeRegisterRequest(self);
FRequest.free;
FResponse.free;
if DoTransactions then begin
if DTID < DOSVPool.count then
DOSVPool[DTID].NoNeedServer(FServer);
FServer := nil;
end;
// FServer.free;
inherited;
//dec(GelementCount);
//writeln('-',GElementCount);
end;
//------------------------------------------------------------------------------
constructor TMotherShipWebRequest.CopyCreate(source: TMotherShipWebRequest);
begin
// result := TRequestInfo.create;
inherited Create;
//CopyStringList(source.FContent, FContent);
Fcontent := source.FContent;
FRaw:= '';
FRaw := source.Fraw;
UniqueString(FRaw);
FParams:= TStringList.create;
CopyStringList(source.FParams, FParams, true);
FParamNames := TStringList.create;
CopyStringList(source.FParamNames, FParamNames, true);
FParamSources := TList.create;
CopyList(source.FParamSources, FParamSources);
FRequestContent := TStringList.create;
CopyStringList(source.FRequestContent, FRequestContent, true);
Fheader := TStringList.create;
CopyStringList(source.FHeader, FHEader, true);
FCommand := source.FCommand;
UniqueString(FCommand);
FDocument := source.FDocument;
FClientIP := source.FClientIP;
FCopied := true;
end;
constructor TMotherShipWebRequest.Create;
begin
inherited;
FIsSecure := false;
FRaw:= '';
FHeader:= TStringList.create;
FParams:= TStringList.create;
FParamNames := TStringList.create;
FParamSources := TList.create;
FRequestInfo := nil;
FRequestContent := TStringList.create;
FOriginalDocument := 'untitled';
FCommand:= '';
FDocument:= 'untitled';
FClientIP := '0.0.0.0';
Fcopied:=false;
end;
//------------------------------------------------------------------------------
procedure TMotherShipWebRequest.DecodeMultiPart;
var
sTemp: string;
begin
sTemp := self.Content;
//Get the multipart header
//Get the multipart content-type
//if the content type is application/www-form-urlencoded
//add the vars as parameters
end;
//------------------------------------------------------------------------------
procedure TMotherShipWebRequest.Default(sParamName, sDefaultValue: string);
begin
if not HasParam(sParamName) then
params[sParamName] := sDefaultValue;
end;
//------------------------------------------------------------------------------
destructor TMotherShipWebRequest.destroy;
begin
Fheader.free;
FParams.free;
FParamNames.free;
FRequestContent.free;
FParamSources.free;
inherited;
end;
//------------------------------------------------------------------------------
procedure TRequestInfo.ForceInit;
begin
request.AddParam('accountid', '0', pcCookie);
self.SessionId := 0;
request.AddParam('sessionid', self.SessionHash, pcCookie);
end;
function TMotherShipWebRequest.GetDocument: string;
//WARNING!: This function may be read by other threads.
begin
LockRead;
try
Result := FDocument;
finally
UnlockRead;
end;
end;
function TMotherShipWebRequest.GetDocumentExt: string;
begin
LockString;
try
if FDocumentExt = '' then
FDocumentExt := ExtractFileExt(FDocument);
result := FDocumentExt;
uniquestring(result);
finally
UnlockString;
end;
end;
//------------------------------------------------------------------------------
function TMotherShipWebRequest.GetFullURL: string;
begin
result := copy(document, 2, length(document))+'?'+RebuildInlineParameters;
end;
function TMotherShipWebRequest.GetOriginalDocument: string;
begin
Lock;
try
result := FOriginalDocument;
UniqueString(result);
finally
Unlock;
end;
end;
function TMotherShipWebRequest.GetParamCount: integer;
begin
result := FParams.count;
end;
//------------------------------------------------------------------------------
function TMotherShipWebRequest.GetParamNames(idx: integer): string;
begin
result := FParamNames[idx];
end;
//------------------------------------------------------------------------------
function TMotherShipWebRequest.GetParamNamesByPatternMatch(sLeftMatch: string;
idx: integer): string;
var
iLength, icount, t: integer;
begin
icount := 0;
sLeftMatch := lowercase(sLeftMatch);
iLength := length(sLeftMatch);
result := '';
for t:= 0 to paramcount-1 do begin
if copy(ParamNames[t], 1, iLength) = sLeftMatch then begin
if icount = idx then begin
result := paramnames[t];
exit;
end;
inc(icount);
end;
end;
Raise Exception.create('Pattern match not found. Index: '+ inttostr(iCount)+' Pattern: '+sLeftMatch);
end;
function TMotherShipWebRequest.GetParamPatternCount(sLeftMatch: string): integer;
var
t: integer;
begin
result := 0;
sLeftMatch := lowercase(sLeftMatch);
for t:= 0 to paramcount-1 do begin
if copy(paramnames[t], 1, length(sLeftMatch)) = sLeftMatch then
inc(result);
end;
end;
//------------------------------------------------------------------------------
function TMotherShipWebRequest.GetParams(sName: string): string;
var
i: integer;
begin
sName := lowercase(sName);
i := FParamNames.indexof(sName);
if i = -1 then
raise EMissingInputValue.create(sName);
result := FParams[i];
end;
//------------------------------------------------------------------------------
function TMotherShipWebRequest.GetParamsByIndex(idx: integer): string;
begin
result := FParams[idx];
end;
//------------------------------------------------------------------------------
function TMotherShipWebRequest.GetParamsByPatternMatch(sLeftMatch: string;
idx: integer): string;
//description: Finds the IDXth parameter matching the left side of sLeftMatch
//(case insensitive)
var
iLength, icount, t: integer;
begin
icount := 0;
sLeftMatch := lowercase(sLeftMatch);
iLength := length(sLeftMatch);
result := '';
for t:= 0 to paramcount-1 do begin
if copy(ParamNames[t], 1, iLength) = sLeftMatch then begin
if icount = idx then begin
result := paramsbyIndex[t];
exit;
end;
inc(icount);
end;
end;
Raise Exception.create('Pattern match not found. Index: '+ inttostr(iCount)+' Pattern: '+sLeftMatch);
end;
function TMotherShipWebRequest.GetParamSources(idx: integer): TParamSource;
begin
result := TParamSource(FParamSources[idx]);
end;
//------------------------------------------------------------------------------
function TMotherShipWebRequest.GetReferer: string;
begin
if self.HasParam('referer') then
result := self['referer']
else
result := '';
end;
//------------------------------------------------------------------------------
function TMotherShipWebRequest.GetUserAgent: string;
begin
result := '';
if HasParam('User-Agent') then
result := params['User-Agent'];
end;
function TMotherShipWebRequest.HasParam(sName: string): boolean;
//Returns whether or not a parameter with the specific name is defined
begin
result := (Fparamnames.indexof(sName) > -1)
end;
//------------------------------------------------------------------------------
function TMotherShipWebResponse.GetVarCount: integer;
begin
result := FVarNames.count;
end;
//------------------------------------------------------------------------------
function TMotherShipWebResponse.GetVarpool(sVarName: string): variant;
var
idx: integer;
begin
//Get the index
idx := FVarNames.IndexOf(sVarName);
//if found then
if idx >=0 then
result := FVarValues[idx]
else begin
if Assigned(VArPoolExtender) then begin
if varpoolextender.IsDefined(sVarNAme) then begin
result := varpoolextender.LoadVar(sVarName);
end else begin
raise EScriptVarError.create('Variable '+sVarName+' needed but undefined');
end;
end else begin
raise EScriptVarError.create('Variable '+sVarName+' needed but undefined');
end;
end;
end;
function TMotherShipWebResponse.GetVArPoolExtender: IVarpoolVarExtender;
begin
if FExtenderStack.count = 0 then begin
result := nil;
end
else begin
result := FExtenderStack[FExtenderStack.count-1] as IVarPoolVarExtender;
end;
end;
//------------------------------------------------------------------------------
procedure TMotherShipWebResponse.SetVarPool(sVarName: string; const Value: variant);
//Sets a dynamic variable in the var pool (settter for VarPool property)
var
idx: integer;
begin
bNeedsProcessing := true;
//Get the index of the variable in question
idx := FVarNames.IndexOf(sVarName);
//Change the value of the variable IF FOUND
if not (idx<0) then begin
FVArValues[idx] := Value;
end
//otherwise add it and set the value
else begin
FVarNames.Add(sVarName);
FVarValues.Add(Value);
end;
end;
procedure TMotherShipWebResponse.SetVArPoolExtender(
const Value: IVarpoolVarExtender);
begin
if value = nil then begin
if FExtenderStack.count > 0 then begin
FExtenderStack.delete(FExtenderstack.count-1);
end;
end else begin
FExtenderStack.add(value);
end;
end;
{ TMotherShipWebResponse }
//------------------------------------------------------------------------------
constructor TMotherShipWebResponse.Create;
//Constructor
begin
inherited;
FRangeEnd := -1;
FExtenderStack := TInterfaceList.create;
FDebugLog := TStringList.create;
FOnResponseSent:= nil;
FSendTime := 0;
FAuthHeaders:= TStringList.create;
FConnection := rqcAuto;
FFramed := false;
FContentLength := -1;
FContent := TStringList.create;
FcontentStream := nil;
FObjectPool := nil;
FContentType := 'text/html';
FResultCode := 200;
FObjectPool := TStringList.create;
FVarNames := TStringList.create;
FVarValues := TVariantList.create;
FCookieNames := TStringList.create;
FCookieValues := TStringList.create;
FXMLPool := TStringList.create;
FDOCache := nil;
FDoSendChunk := nil;
FDoSendHeader := nil;
FHeaderSent := false;
FNoDebug:= false;
FRequestInfo := nil;
FcopiedWithOldCache:=false;
FDeleteFile := '';
FDeleteTempFile := '';
end;
//------------------------------------------------------------------------------
destructor TMotherShipWebResponse.destroy;
begin
FauthHeaders.free;
FContentStream.free;
FContentStream := nil;
FVarValues.free;
FVarNames.free;
FObjectPool.free;
FContent.free;
FCookieNames.free;
FCookieValues.free;
FExtenderStack.free;
EmptyXMlPool;
FXMLPool.free;
// FContentstream.free;
if (FDOCache <> nil) and (not CopiedWithOldCache) then begin
DOCM.FreeCache(FDOCache);
end;
inherited;
try
if FDeleteFile <>'' then begin
DeleteFile(FDeleteFile);
end;
if FDeleteTempFile <> '' then begin
DeleteFile(FDeleteTempFile);
end;
except
end;
FDebugLog.free;
end;
//------------------------------------------------------------------------------
procedure TMotherShipWebResponse.ProcessDynamicVariables();
var
nullmethod: TProgressCallbackProcedure;
begin
nullmethod := nil;
ProcessDynamicVariables(false, nullmethod);
end;
procedure TMotherShipWebResponse.ProcessDynamicVariables(progress_callback: TProgressCallbackProcedure);
begin
ProcessDynamicVariables(false, progress_callback);
end;
procedure TMotherShipWebResponse.ProcessDynamicVariables(bAllowAlternateContentTypes: boolean ; progress_callback: TProgressCallbackProcedure);
//Replaces all variables marked with [[[varname]]] in the content with
//variables from the variable pool.
var
t: integer;
begin
//fix script problems that might occur if session ID is 0 or -1
if HasVar('sessionid') then begin
if VarPool['sessionid'] = '0' then begin
Varpool['sessionid'] := Inttohash([INVALID_DATATIER, INVALID_DATATIER],0); end;// else
//Varpool['sessionid'] := Inttohash([self.RequestInfo.DTID, self.RequestInfo.ISRNDTID], hashtoint(Varpool['sessionid']));
end else begin
Varpool['sessionid'] := Inttohash([INVALID_DATATIER, INVALID_DATATIER],-1);
self.Request.AddParam('sessionid', '-1', pcCookie);
end;
if not bNeedsProcessing then begin
exit;
end;
if (not bAllowAlternateContentTypes) and (not (lowercase(copy(ContentType,1,4)) = 'text')) then
exit;
// if lowercase(contenttype) <> 'text/html' then
// exit;
// contentlength := -1;
content.text := stringReplace(content.text, #01, '[[[', [rfReplaceAll]);
ReplaceEscSequences(self.RequestInfo, Content, progress_callback);
if lowercase(contenttype) = 'text/html' then
begin
ProcessHTML;
end;
// for t:= content.count-1 downto 0 do begin
// //content[t] := Trim(StringReplace(content[t], '<!---->', '', [rfReplaceAll]));
//// content[t] := stringReplace(content[t], #9, '', [rfReplaceAll]);
// if content[t] = '' then
// content.delete(t);
// end;
contentlength := length(requestinfo.response.content.text);
bNeedsProcessing := false;
end;
//------------------------------------------------------------------------------
procedure TMotherShipWebResponse.SetupDefaultVarPool(request: TMotherShipWebRequest);
//This sets up a default Auto-VarPool from the parameters passed through an
//HTTP request represented by request:TMotherShipWebRequest;
var
t: integer;
begin
//raise exception if this is called without a corresponding request partner object
if request = nil then
raise Exception.create('Invalid class instance of TMotherShipWebRequest passed to TMotherShipWebResponse.SetupDefaultVarPool');
//morph the referer in case someone tries to use it as the target of the
//next page
if request.hasparam('referer') then begin
if not (lowercase(request.DocumentExt) = '.asp') or (lowercase(request.DocumentExt) = 'asp') then
request.AddParam('referer', MorphURL(request['referer']), request.paramsources[request.IndexOfParam('referer')]);
end;
for t:= 0 to request.ParamCount-1 do begin
VarPool[request.ParamNames[t]] := request.ParamsByIndex[t];
end;
VarPool['document'] := copy(request.document, 2, length(request.document));
end;
function TRequestInfo.GetDoTransactions: boolean;
begin
Result := FDoTransactions and (FServer <> nil);
end;
function TRequestInfo.GetDTID: integer;
var
iAccountID: integer;
begin
// AuditLog('Selecting Data Tier');
//if we couldn't find via DTID then try by accountID
if (FDTID = INVALID_DATATIER) or (FDTID= 254)then begin
// AuditLog('No Data Tier found in Session ID Scanning for account');
if request.HasParam('accountid') then begin
iAccountID := strtoint(request['accountid']);
if iAccountid = 1 then
FDTID := 0
else begin
// AuditLog('Entering DOSV Select Function');
FDTID := 0;
// AuditLog('DOSV Selected: '+ inttostr(FDTID));
end;
request['sessionid'] := IntToHash([FDTID, FISRNDTID], sessionid);
end;
end;
result := FDTID;
end;
function TRequestInfo.GetHTTPClient: THTTPClient;
begin
if not assigned(FHTTPClient) then begin
FHTTPClient := THTTPClient.create;
FHTTPClient.DownloadLinks := false;
end;
result := FHTTPclient;
end;
function TRequestInfo.GetServer: IServerInterface;
begin
if DTID = 255 then
DTID := 0;
if FServer = nil then begin
if DoTransactions then
FServer := DOSVpool[DTID].NewServer
else begin
raise exception.create('only transactional servers allowed');
end;
// FServer := DOSVpool[DTID].NewServer;
LoadVars;
end;
result := FServer;
end;
function TRequestInfo.GetSessionHash: string;
begin
result := InttoHash([FDTID, FISRNDTID], sessionid);
end;
function TRequestInfo.GetSessionID: integer;
begin
result := FSessionID;
end;
function TRequestInfo.GetThreadID: integer;
begin
Lock;
try
Result := FThreadID;
finally
Unlock;
end;
end;
function TRequestInfo.InitDTID: integer;
begin
if request.HasParam('sessionid') then begin
result := HashToDataTierID(request['sessionid'], DT_INDEX_PWLN);
end else
result := INVALID_DATATIER;
end;
procedure TRequestInfo.InitializeEngine;
begin
self.bInitialized := true;
//convert 'key' param to 'sessionid' if session id not provided
if request.hasParam('key') and (not request.hasParam('sessionid')) then
request['sessionid'] := request['key'];
//convert 'pwlnacocuntnumber' param to 'accountid'
if request.hasParam('pwlnaccountnumber') then
request['accountid'] := request['pwlnaccountnumber'];
//fake a sessionID if not provided
if not request.hasparam('sessionid') then begin
request['sessionid'] := InttoHash([INVALID_DATATIER, INVALID_DATATIER], 0, 0);
end;
//windows.beep(800,100);
response.SetupDefaultVarPool(request);
try
if request.HasParam('accountid') then
strtoint(request['accountid']);
except
request.RemoveParam('accountid');
end;
//allocate a data tier to handle stuff for this account;
DTID := HashToDataTierID(request['sessionid'], DT_INDEX_PWLN);
request.AddPAram('sessionid', self.SessionHash, pcInline);
//windows.beep(1200,100);
// AuditLog('Entering InitDTID');
InitDTID;
// AuditLog('Done InitDTID');
//windows.beep(1600,100);
//allocate a cache for Data objects
// DOSV.CacheManager.AllocateCAche(FDOCache, request.Sessionid, cbSmall);
bInitialized := true;
end;
function TRequestInfo.LoadVar(sName: string; iDefault: integer): integer;
begin
result := strtoint(LoadVar(sName, inttostr(iDefault)));
end;
function TRequestInfo.LoadVar(sName: string; rDefault: real): real;
begin
result := strtofloat(LoadVar(sName, floattostr(rDefault)));
end;
function TRequestInfo.LoadVar(sName, sDefault: string): string;
var
obj: TDataObject;
t: integer;
begin
obj := response.DOCache.GetExistingObject('TdoSessionVar', vararrayof([sessionid,lowercase(sName)]), 0,0);
if obj <> nil then begin
result := obj['varvalue'].AsString;
end;
self.server.LazyQueryMap(self.Response.DOCache, obj, 'SELECT * from session_vars where sessionid='+inttostr(sessionid), sessionid, 10000,'TdoSessionVars', sessionid, nil, 'TdoSessionVar', 2);
result := sDefault;
for t:= 0 to obj.ObjectCount-1 do begin
if lowercase(obj.obj[t].token.params[1]) = lowercase(sName) then begin
result := obj.obj[t]['varValue'].AsString;
end;
end;
end;
procedure TRequestInfo.LoadVars;
var
obj, obj2: TDataObject;
t: integer;
begin
try
if sessionid <= 0 then
exit;
if not self.server.LazyQueryMap(self.Response.DOCache, obj, 'SELECT * from session_vars where sessionid='+inttostr(sessionid), sessionid, 10000,'TdoSessionVars', sessionid, nil, 'TdoSessionVar', 2)
then
exit;
for t:= 0 to obj.ObjectCount-1 do begin
request.Default(obj.obj[t]['varName'].AsString,obj.obj[t]['varValue'].AsString);
// request.AddParam(obj.obj[t]['varName'].AsString,obj.obj[t]['varValue'].AsString, pcCookie);
end;
if self.server.LazyQueryMap(self.Response.DOCache, obj2, 'SELECT user_vars.* from session join user_vars on session.userid=user_vars.userid where sessionid='+inttostr(sessionid), sessionid, 10000,'TdoUserVars', sessionid, nil, 'TdoUserVar', 2) then
for t:= 0 to obj2.ObjectCount-1 do begin
request.Default(obj2.obj[t]['varName'].AsString,decodewebstring(obj2.obj[t]['varValue'].AsString));
// request.AddParam(obj.obj[t]['varName'].AsString,obj.obj[t]['varValue'].AsString, pcCookie);
end;
finally
self.SetupDefaultVarPool;
end;
end;
procedure TRequestInfo.SaveVars;
var
obj: TDataObject;
t: integer;
sValues: string;
begin
if sessionid = 0 then
exit;
server.UpdateQuery(response.docache, 'delete * from session_vars where sessionid='+inttostr(sessionid), sessionid);
sValues := '';
for t:= 0 to self.Response.VarCount-1 do begin
sValues := sValues + '('+inttostr(sessionid)+',"'+
response.VarNames[t]+'","'+
response.VarNames[t]+'","'+
response.VarByIndex[t]+'")';
if t < self.Response.varcount-1 then
sValues := sValues + ',';
// SaveVar(response.VarNames[t], response.VarByIndex[t]);
end;
server.NoTransupdateQuery(response.docache, 'INSERT INTO SESSION_VARS Values'+sValues, sessionid);
end;
function TRequestInfo.Pop: TrequestInfo;
begin
result := FPopto;
self.FPopto := nil;
self.free;
end;
function TRequestInfo.ProcessQuery(sQuery: string): string;
var
s: string;
sT: string;
b: boolean;
cl: int64;
begin
if pos('[[[',sQuery) < 1 then begin
result := sQuery;
exit;
end;
b := self.response.NeedsProcessing;
sT := self.response.ContentType;
s := self.response.content.text;
cl := self.Response.ContentLength;
self.response.contenttype := 'text/plain';
self.response.content.text := sQuery;
self.response.ProcessDynamicVariables(true);
result := self.response.content.text;
self.response.content.text := s;
self.response.contentType := sT;
self.response.NeedsProcessing := b;
self.response.ContentLength := cl;
end;
function TRequestInfo.Push: TRequestInfo;
begin
result := TRequestInfo.copycreate(self);
result.FPopto := self;
result.ProgressHook := self.ProgressHook;
end;
procedure TRequestInfo.Rollback;
begin
if assigned(self.FServer) then
server.Rollback;
end;
procedure TRequestInfo.SaveVar(sName, sValue: string);
var
obj: TDataObject;
t: integer;
bFound: boolean;
begin
if sessionid = 0 then
exit;
self.server.LazyQueryMap(self.Response.DOCache, obj, 'SELECT * from session_vars where sessionid='+inttostr(sessionid), sessionid, 10000,'TdoSessionVars', sessionid, nil, 'TdoSessionVar', 2);
bFound := false;
for t:= 0 to obj.ObjectCount-1 do begin
if lowercase(obj.obj[t].token.params[1]) = lowercase(sName) then begin
obj.obj[t]['VarValue'].AsString := sValue;
server.NoTRansUpdateQuery(response.DOCache,'UPDATE session_vars set varvalue="'+sValue+'" where varname="'+sName+'" and sessionid='+inttostr(sessionid), sessionid);
bFound := true;
end;
end;
if not bFound then begin
server.NoTRansUpdateQuery(response.DOCache,'DELETE from session_vars where varname="'+sName+'" and sessionid='+inttostr(sessionid), sessionid);
server.NoTransUpdateQuery(response.DOCache,'INSERT into session_vars values ('+inttostr(sessionid)+',"'+lowercase(sName)+'","'+lowercase(sName)+'","'+sValue+'")', sessionid);
end;
request[sName] := sValue;
response.varpool[sName] := sValue;
end;
procedure TRequestInfo.SetDTID(const Value: integer);
begin
FDTID := Value;
rqMan.UpdateDTID(self, value);
end;
procedure TRequestInfo.SetHTTPClient(const Value: THTTPClient);
begin
if assigned(FHTTPClient) then
raise exception.create('HTTPClient already assigned');
FHTTPClient := value;
end;
procedure TRequestInfo.SetISRNDTID(const Value: integer);
begin
FISRNDTID := Value;
end;
procedure TRequestInfo.SetSessionHash(const Value: string);
begin
FSessionID := HashToInt(Value);
FDTID := HashToDataTierID(value, 0);
FISRNDTID := HashToDataTierID(value, 1);
end;
procedure TRequestInfo.SetSessionID(const Value: integer);
begin
FSessionID := value;
response.varpool['sessionid'] := sessionhash;
end;
procedure TRequestInfo.SetupDefaultVarPool;
//A friendly helper function that calls the same function in the RESPONSE half
//of the class, passing the REQUEST half.
//See TMotherShipWebResponse.SetupDefaultVarPool for more information
begin
response.SetupDefaultVarPool(request);
end;
function TRequestInfo.StealHTTPClient: THTTPClient;
begin
result := FHTTPClient;
FHTTPClient := nil;
end;
//------------------------------------------------------------------------------
function TMotherShipWebResponse.GetDataObjectCache: TDataObjectCache;
begin
if FDOCache = nil then begin
//assign threadvar DOSV
//if DataTierID is part of session... then use the datatier ID in the session
DOCM.AllocateCAche(FDOCache, REquestInfo.Sessionid, WebServerconfig.DataCenterID, RequestInfo.DTID, cbSmall);
FDOCache.Server := self.RequestInfo.server;
end;
result := FDOCache;
end;
//------------------------------------------------------------------------------
function TMotherShipWebResponse.GetObjectPool(sName: string): TDataObject;
var
idx: integer;
begin
//Find index of name
idx := FObjectPool.IndexOf(sName);
//if name not found then EXCEPT
if idx<0 then begin
raise EObjectMissing.create('Object '+sName+' needed but undefined.');
end
//else result = object
else
result := TDataObject(FObjectPool.objects[idx]);
end;
function TMotherShipWebResponse.GetXMLPool(sName: string): string;
var
idx: integer;
begin
//Find index of name
idx := FXMLPool.IndexOf(lowercase(sName));
//if name not found then EXCEPT
if idx<0 then begin
raise exception.create('XML document '''+sName+''' needed but undefined.');
end
//else result = object
else
result := TXMLDOcument(FXMLPool.objects[idx]).Value;
end;
function TMotherShipWebResponse.GetXMLDocs(sName: string): TXmlDocument;
var
idx: integer;
begin
//Find index of name
idx := FXMLPool.IndexOf(lowercase(sName));
//if name not found then EXCEPT
if idx<0 then begin
raise exception.create('XML document '''+sName+''' needed but undefined.');
end
//else result = object
else
result := TXMLDocument(FXMLPool.objects[idx]);
end;
//------------------------------------------------------------------------------
procedure TMotherShipWebResponse.SetObjectPool(sName: string;
const Value: TDataObject);
var
idx: integer;
begin
if Value = nil then
Raise Exception.create('NIL object in object pool: '+sName);
if not (value is TDataObject) then
Raise Exception.create('Object in object pool is not a Data object');
//Find index of name
idx := FObjectPool.IndexOf(sName);
//if name not found then add
if idx<0 then begin
FObjectPool.AddObject(sName, Value);
end
//else result = object
else
FObjectPool.objects[idx] := Value;
end;
procedure TMotherShipWebResponse.SetXMLPool(sName: string;
const Value: string);
var
idx: integer;
doc: TXMLDocument;
begin
//Find index of name
idx := FObjectPool.IndexOf(lowercase(sName));
//if name not found then add
if idx<0 then begin
doc := TXMLDocument.create;
doc.value := VAlue;
FXMLPOOL.AddObject(lowercase(sName), doc);
end
//else result = object
else
TXMLDocument(FXMLPool.objects[idx]).Value := Value;
end;
//------------------------------------------------------------------------------
function TMotherShipWebResponse.HasVar(sVarName: string): boolean;
begin
result := FVarNames.IndexOf(sVarName)>=0;
end;
//------------------------------------------------------------------------------
function TMotherShipWebResponse.VarPoolStatus: string;
var
sl: TStringList;
obj: TDataObject;
t: integer;
begin
sl := TStringList.create;
try
sl.add('<table width="100%">');
for t:= 0 to FObjectPool.count-1 do begin
obj:= TDataObject(FObjectPool.objects[t]);
sl.add('<TR>');
sl.add('<td><B>'+FObjectPool[t]+'</B></td>');
try
sl.add('<td><B>'+obj.name+'</B></td>');
except
sl.add('<td>exception</td>');
end;
try
sl.add('<td>'+obj.classname+'</td>');
except
sl.add('<td>exception</td>');
end;
try
sl.add('<td>'+inttostr(obj.fieldcount)+'</td>');
except
sl.add('<td>exception</td>');
end;
try
sl.add('<td>'+inttostr(obj.objectcount)+'</td>');
except
sl.add('<td>exception</td>');
end;
sl.add('</TR>');
end;
sl.add('</table>');
//Variables
sl.add('<table width="100%">');
for t:= 0 to FVarNames.count-1 do begin
sl.add('<TR>');
try
sl.add('<td><B>'+FVarNames[t]+'</B></td>');
sl.add('<td><B>'+FVarValues[t]+'</B></td>');
except
sl.add('<td>exception</td>');
end;
sl.add('</TR>');
end;
sl.add('</table>');
result := sl.text;
finally
sl.free;
end;
end;
//------------------------------------------------------------------------------
procedure TMotherShipWebResponse.SendChunk;
begin
SendChunk(FContent.count-1);
end;
//------------------------------------------------------------------------------
procedure TMotherShipWebResponse.SendChunk(endrow: integer);
var
sTemp: string;
t: integer;
slTemp: TStringList;
begin
if (EndRow<0) or (FContent.count=0) then
exit;
if not assigned(FDoSendChunk)then
exit;
if not(pos('ie', lowercase(request['User-Agent']))>0) and not(pos('explorer', lowercase(request['User-Agent']))>0) then
exit;
slTemp := TStringList.create;
try
//isolate the chunked area
if EndRow<FContent.count-1 then begin
for t:=EndRow to Fcontent.count-1 do begin
slTemp.Add(Fcontent[t]);
end;
while ((FContent.count-1)>endRow) do begin
if FContent.count>0 then
Fcontent.delete(Fcontent.count-1);
end;
end;
//Force transfer encoding to chunked
self.TransferEncoding := 'chunked';
if not HeaderSent then
SendHeader;
self.ProcessDynamicVariables;
//Insert length as ASCII line at beginning of content
sTemp := Fcontent.text;
FContent.insert(0, inttohex(length(sTemp), 1));
//Insert CRLF at end of content
FContent.add('');
//Make the callback to send the chunk*)
DoSendChunk;
//Clear the content for further encoding
FContent.clear;
for t:=0 to slTemp.count-1 do begin
FContent.add(slTemp[t]);
end;
finally
slTemp.free;
end;
end;
//------------------------------------------------------------------------------
procedure TMotherShipWebResponse.SendHeader;
begin
if not assigned(FDoSendHeader) then
exit;
DoSendHeader;
FHeaderSent := true;
end;
//------------------------------------------------------------------------------
procedure TMotherShipWebResponse.SendFooter;
begin
if not assigned(DoSendChunk) then
exit;
if not(pos('ie', lowercase(request['User-Agent']))>0) and not(pos('explorer', lowercase(request['User-Agent']))>0) then
exit;
if FContent.count >0 then
SendChunk;
FContent.insert(0,'0');
FContent.add('');
DoSendChunk;
end;
function TMotherShipWebRequest.HasParamWithValue(sName: string): boolean;
begin
result := HasParam(sName) and (Params[sName] <> '');
end;
function TMotherShipWebRequest.IndexOfParam(sName: string): integer;
begin
result := FParamNames.IndexOf(sName)
end;
function TMotherShipWebRequest.ParamPatternSum(sPattern: string): real;
var
t: integer;
begin
result := 0.0;
for t:= 0 to parampatterncount[sPattern]-1 do begin
result := result + strtofloat(paramsbypatternmatch[sPattern,t]);
end;
end;
function TMotherShipWebRequest.PatternQuery(sPattern: string): TStringList;
var
t: integer;
begin
result := TStringList.create;
for t := 0 to ParamPatternCount[sPattern]-1 do begin
result.add(ParamsByPatternMatch[sPattern, t]);
end;
end;
function TMotherShipWebRequest.RebuildInlineParameters: string;
//returns all Header/Inline parameters in URL encoded
//form. Effectively used to rebuild the URL from which the
//request was originated when encapsulated in APIs that
//do not directly provide such information
var
t: integer;
sTemp : string;
begin
self['sessionid'] := self.FRequestInfo.SessionHash;
result := '';
//cycle through all parameters
for t:= 0 to self.ParamCount-1 do begin
//if an inline parameter
if self.ParamSources[t] in [pcInline] then begin
//if NOT the first parameter add '&'
if not (result = '') then
result := result + '&';
//encode the parameter
sTemp := self.ParamNames[t]+'='+EncodeWebString(self.ParamsbyIndex[t]);
//add the parameter to the result
result := result + sTemp;
end;
end;
end;
function TMotherShipWebRequest.RebuildParameters: string;
//returns all Header/Inline parameters in URL encoded
//form. Effectively used to rebuild the URL from which the
//request was originated when encapsulated in APIs that
//do not directly provide such information
var
t: integer;
sTemp : string;
begin
result := '';
//cycle through all parameters
for t:= 0 to self.ParamCount-1 do begin
//if an inline parameter
if self.ParamSources[t] in [pcInline, pcContent] then begin
//if NOT the first parameter add '&'
if not (result = '') then
result := result + '&';
//encode the parameter
sTemp := self.ParamNames[t]+'='+EncodeWebString(self.ParamsbyIndex[t]);
//add the parameter to the result
result := result + sTemp;
end;
end;
end;
procedure TMotherShipWebRequest.RemoveParam(sName: string);
var
i: integer;
begin
i := FParamNames.IndexOf(sName);
if i >-1 then begin
FParamNames.delete(i);
FParams.delete(i);
FParamSources.delete(i);
end;
end;
procedure TMotherShipWebRequest.SetBinaryContentLength(iLength: integer);
begin
//TODO -cunimplemented: unimplemented block
end;
procedure TMotherShipWebRequest.SetDocument(const Value: string);
var
sTemp: string;
begin
// rqMan.Lock;
try
Lock;
try
// rqMan.DeRegisterRequest(self.FRequestInfo);
FDocument := Value;
if FOriginalDocument = 'untitled' then
FOriginalDocument := Value;
// rqMan.RegisterRequest(self.FRequestInfo);
finally
Unlock;
end;
finally
// rqMan.Unlock;
end;
end;
procedure TMotherShipWebRequest.SetParams(sName: string; const Value: string);
var
i: integer;
pc: TParamsource;
begin
i := FParamNames.IndexOf(sName);
pc := pcGenerated;
if i>-1 then begin
pc := Tparamsource(FParamSources[i]);
FParams.delete(i);
FParamNames.delete(i);
FParamSources.delete(i);
end;
AddParam(sName, Value, pc);
self.RequestInfo.SetupDefaultVarPool;
end;
constructor TMotherShipWebResponse.CopyCreate(source: TMotherShipWebResponse; bNewCache: boolean = true);
var
t: integer;
begin
FExtenderStack := TInterfaceList.create;
FDebugLog := TStringList.create;
FContent := TStringList.create;
// FNeedsProcessing := true;
//nocopy
FcontentStream := nil;
//nocopy
FContentType := 'text/html';
FResultCode := 200;
FObjectPool := TStringList.create;
CopyStringList(source.FObjectPool, FObjectPool, true);
FXMLPool := TStringList.create;
for t:= 0 to source.FXMLPool.Count-1 do begin
self.XMLPool[source.FXMLpool[t]] := Source.XMLPool[source.FXMLpool[t]];
end;
//CopyStringList(source.FXMLPool, FXMLPool, true);
FVarNames := TStringList.create;
CopyStringList(source.FVarNames, FVarNames, true);
FVarValues := TVariantList.create;
CopyVariantList(source.FVarValues, FVarValues);
if bNewCache then begin
FDoCache := nil;
FCopiedWithOldCache := false;
end
else begin
FCopiedWithOldCache := true;
FDOCache := source.DoCache;
end;
FDoSendChunk := source.FDoSendChunk;
FDoSendHeader := source.FDoSendHeader;
FHeaderSent := false;
FNoDebug:= false;
FRequestInfo := nil;
bNeedsProcessing := true;
VarpoolExtender := source.VarPoolExtender;
end;
//------------------------------------------------------------------------------
function TMotherShipWebResponse.GetDOSV: TDataObjectServices;
//this is a cludge for correcting namespace and DOSV initialization issues
begin
result := DOSVPool[RequestInfo.DTID];
end;
//------------------------------------------------------------------------------
procedure TMotherShipWebResponse.ImportVarPool(sImportString: string);
var
sLeft, sRight: string;
sName, sValue: string;
begin
sRight := sImportString;
while SplitString(sRight, '&', sLeft, sRight) do begin
SplitString(sLeft, '=', sName, sValue);
VarPool[sName] := sValue;
end;
SplitString(sLeft, '=', sName, sValue);
VarPool[sName] := sValue;
end;
//------------------------------------------------------------------------------
function TMotherShipWebResponse.ExportVarPool: string;
var
t: integer;
begin
result := '';
for t:= 0 to VarCount -1 do begin
result := result + EncodeWebString(VarNames[t])+'='+EncodeWebString(VarByIndex[t])+'&';
end;
end;
//------------------------------------------------------------------------------
function TMotherShipWebResponse.getVarByIndex(idx: integer): string;
begin
result := FVarValues[idx]
end;
//------------------------------------------------------------------------------
function TMotherShipWebResponse.GetVarNames(idx: integer): string;
begin
result := FVarNames[idx]
end;
//------------------------------------------------------------------------------
procedure TMotherShipWebResponse.SetVarByIndex(idx: integer;
const Value: string);
begin
FVarValues[idx] := value;
end;
//------------------------------------------------------------------------------
procedure TMotherShipWebResponse.SetVarNames(idx: integer; const Value: string);
begin
FVarNames[idx] := value;
end;
procedure TMotherShipWebResponse.AddCookie(sName, sValue: string);
var
iPos: integer;
begin
iPos := FCookieNames.IndexOf(sName);
//if a cookie by the name already exists then change existing value
if iPos>-1 then begin
FCookieValues[iPos] := sValue
end
//else, add a new cookie to the list
else begin
FcookieNames.add(sName);
FcookieValues.add(sValue);
end;
end;
procedure TMotherShipWebResponse.AddAuthHeader(sValue: string);
begin
fauthHeaders.Add(sValue);
end;
procedure TMothershipWebResponse.AddCookie(sFullCookie: string);
var
sLeft, sright, sCookie, sValue: string;
begin
if SplitString(sFullCookie, '=', sCookie, sValue) then begin
SplitString(sValue, ';', sValue, sRight);
AddCookie(sCookie, sValue);
end;
end;
function TMotherShipWebResponse.GetCookieCount: integer;
begin
result := FCookieValues.count;
end;
function TMotherShipWebResponse.GetCookieNames(idx: integer): string;
begin
result := FCookieNames[idx];
end;
function TMotherShipWebResponse.GetCookieValues(idx: integer): string;
begin
result := FCookieValues[idx];
end;
procedure TMotherShipWebResponse.SetContentStream(const Value: TStream);
begin
FContentStream := Value;
if value <> nil then begin
ContentLength := value.Size-value.position;
end;
end;
function TMotherShipWebResponse.GetHasCache: boolean;
begin
result := FDOCache <> nil;
end;
procedure TMotherShipWebResponse.Default(varName, varValue: variant);
begin
if self.FVarNames.IndexOf(varNAme) < 0 then begin
self.varpool[varName] := varValue;
end;
end;
procedure TMotherShipWebResponse.EmptyXMLPool;
begin
while FXMLPool.Count > 0 do begin
TXMLDocument(FXMLPool.Objects[0]).free;
FXMlPool.Delete(0);
end;
end;
function TMotherShipWebResponse.GetDebugLog: TStringList;
begin
result := FDebugLog;
end;
procedure TMotherShipWebResponse.MassageDebugStats;
type
TStat = record
time: int64;
name: string;
end;
var
iFreq: int64;
t: integer;
stats: array of TStat;
function IndexOfStat(var stats: array of TStat; name: string): integer;
var
t: integer;
begin
result := -1;
for t:= Low(Stats) to High(stats) do begin
if stats[t].Name = name then begin
result := t;
end;
end;
end;
function GetMax(var stats: array of TStat): integer;
var
t: integer;
i: integer;
begin
i := -1;
for t:= Low(Stats) to High(stats) do begin
if (i> -1) and (stats[t].time > stats[i].time) then begin
i := t;
end else if i = -1 then i:= t;
end;
result := i;
end;
var
sLeft, sRight: string;
i: integer;
begin
setLength(stats, 0);
for t:= 0 to debuglog.count-1 do begin
try
if not SplitString(debuglog[t], '~', sLeft, sRight) then
continue;
i := IndexOfStat(stats, sRight);
if i > -1 then begin
stats[i].time := stats[i].time + strtoint64(sLeft);
end else begin
setLength(stats, length(stats)+1);
i := High(stats);
stats[i].time := strtoint64(sLeft);
stats[i].Name := sRight;
end;
except
end;
end;
debuglog.Clear;
QueryPerformanceFrequency(iFreq);
repeat
i := GetMax(stats);
if i >= 0 then begin
debuglog.Add(floattostr(stats[i].time / iFreq)+': '+stats[i].name);
stats[i].time := 0;
end;
until i<= 0;
end;
function TMotherShipWebResponse.HasObject(sName: string): boolean;
begin
result := FObjectPool.IndexOf(sName) > -1;
end;
procedure TMotherShipWebResponse.ProcessDynamicVariables(
bAllowAlternateContentTypes: boolean);
var
nullmethod: TProgressCallbackProcedure;
begin
nullmethod := nil;
processdynamicvariables(bAllowAlternateContentTypes, nullmethod);
end;
procedure TRequestInfo.UpdateProgress(pos, max: integer; sMessage: string);
begin
ProgressPos := pos;
ProgressMax := max;
if sMEssage <> '' then
Status := sMessage;
if assigned(ProgressHook) then begin
try
ProgressHook(pos,max,Status);
except
end;
end;
end;
procedure TMothershipwebResponse.Setlocation(sLoc: string);
begin
fLocation := sLoc;
if sLoc <> '' then
self.ResultCode := 302;
end;
procedure TMotherShipWebREsponse.ProcessHTML;
var
compiler: TMothershipHTMLPromoter;
begin
{$IFDEF NOHTMLPROCESS}
exit;
{$ENDIF}
default('post_process_html', 'false');
if not strtobool(VarPool['post_process_html']) then
exit;
compiler := TMothershipHTMLPromoter.create;
try
compiler.rqInfo := self.FRequestInfo;
compiler.Feed := self.Content.text;
compiler.Process;
self.Content.text := compiler.Result;
finally
compiler.free;
end;
end;
procedure TMotherShipWebResponse.RaiseVarPool;
var
t: integer;
sName: string;
vValue: variant;
begin
if self.RequestInfo.popto = nil then
exit;
for t:= 0 to self.VarCount -1 do begin
sName := self.VarNames[t];
vValue := self.VarByIndex[t];
requestinfo.popto.response.VarPool[sName] := vValue;
end;
end;
procedure TMotherShipWebResponse.RemoveVAr(sName: string);
var
i: integer;
begin
i := self.FVarNames.indexof(lowercase(sName));
if i > -1 then begin
FVArNames.Delete(i);
FVarValues.delete(i);
end;
end;
initialization
end.
| 27.631491 | 253 | 0.681006 |
fc7672919a60e2d7831d954b80c87d02f2f893a0 | 21,317 | lpr | Pascal | LazGL_25_Camera ver 2.0/LazGL.lpr | Den3D/SrcExLazarusOpenGL | 63614778c3d000fad0d051d886df6ce09fa26f6f | [
"MIT"
]
| 3 | 2019-07-22T18:14:39.000Z | 2020-10-09T16:53:20.000Z | LazGL_25_Camera ver 2.0/LazGL.lpr | Den3D/SrcExLazarusOpenGL | 63614778c3d000fad0d051d886df6ce09fa26f6f | [
"MIT"
]
| null | null | null | LazGL_25_Camera ver 2.0/LazGL.lpr | Den3D/SrcExLazarusOpenGL | 63614778c3d000fad0d051d886df6ce09fa26f6f | [
"MIT"
]
| null | null | null | program LazGL;
{$mode objfpc}{$H+}
uses
gl, glu, glut, GLext, sdl, sdl_image ;
// sdl - многофункциональная библиотека, в данном примере будет
// использоваться для загрузки изображений
// Для нормальной работы приложения необходимо загружать рисунки в формате *.tga.
// Используемые текстуры должны быть сохр. с использованием 32 битного канала.
// Для конвертирования в формат *.tga можно использовать Paint.net
//****************************************************//
//******** Описание вектора **********//
//****************************************************//
type
Vector3D = record
X, Y, Z: real;
end;
//****************************************************//
//******** Класс камеры **********//
//****************************************************//
type
Camera = class
private
mPos: Vector3D; // Вектор позиции камеры
mView: Vector3D; // Направление, куда смотрит камера
mUp: Vector3D; // Вектор направления вверх
mStrafe: Vector3D; // Вектор для стрейфа (движения влево и вправо) камеры
private
//--------------------------------------------------------------
// Перпендикулярный вектор от трех переданных векторов
//--------------------------------------------------------------
function Cross(vV1, vV2, vVector2: Vector3D): Vector3D;
//--------------------------------------------------------------
// Возвращает величину вектора
//--------------------------------------------------------------
function Magnitude(vNormal: Vector3D): real;
//--------------------------------------------------------------
// Возвращает нормализированный вектор
//--------------------------------------------------------------
function Normalize(vVector: Vector3D): Vector3D;
//--------------------------------------------------------------
public
//--------------------------------------------------------------
// Установить позицию камеры
//--------------------------------------------------------------
procedure Position_Camera(pos_x, pos_y, pos_z, view_x, view_y, view_z,
up_x, up_y, up_z : real);
//--------------------------------------------------------------
// Вращение камеры вокруг своей оси (от первого лица)
//--------------------------------------------------------------
procedure Rotate_View(speed: real);
//--------------------------------------------------------------
// Перемещение камеры (вперед и назад)
//--------------------------------------------------------------
procedure Move_Camera(speed: real);
//--------------------------------------------------------------
// Перемещение камеры (влево и вправо)
//--------------------------------------------------------------
procedure Strafe(speed: real);
//--------------------------------------------------------------
// Перемещение вверх и вниз
//--------------------------------------------------------------
procedure upDown(speed: real);
//--------------------------------------------------------------
// Вращение вверх и вниз
//--------------------------------------------------------------
procedure upDownAngle(speed: real);
//--------------------------------------------------------------
// Установка камеры
//--------------------------------------------------------------
procedure Look();
//--------------------------------------------------------------
// Обновление
//--------------------------------------------------------------
procedure update();
//--------------------------------------------------------------
// Возвращает позицию камеры по Х
//--------------------------------------------------------------
function getPosX: real;
//--------------------------------------------------------------
// Возвращает позицию камеры по Y
//--------------------------------------------------------------
function getPosY() : real;
//--------------------------------------------------------------
// Возвращает позицию камеры по Z
//--------------------------------------------------------------
function getPosZ() : real;
//--------------------------------------------------------------
// Возвращает позицию взгляда по Х
//--------------------------------------------------------------
function getViewX() : real;
//--------------------------------------------------------------
// Возвращает позицию взгляда по Y
//--------------------------------------------------------------
function getViewY() : real;
//--------------------------------------------------------------
// Возвращает позицию взгляда по Z
//--------------------------------------------------------------
function getViewZ() : real;
end; //END CLASS
//----------------------------------------------
//--------------------------------------------------------------
// Перпендикулярный вектор от трех переданных векторов
//--------------------------------------------------------------
function Camera.Cross(vV1, vV2, vVector2: Vector3D): Vector3D;
var
vNormal, vVector1: Vector3D;
begin
vVector1.x := vV1.x - vV2.x;
vVector1.y := vV1.y - vV2.y;
vVector1.z := vV1.z - vV2.z;
// Если у нас есть 2 вектора (вектор взгляда и вертикальный вектор),
// У нас есть плоскость, от которой мы можем вычислить угол в 90 градусов.
// Рассчет cross'a прост, но его сложно запомнить с первого раза.
// Значение X для вектора = (V1.y * V2.z) - (V1.z * V2.y)
vNormal.x := ((vVector1.y * vVector2.z) - (vVector1.z * vVector2.y));
vNormal.y := ((vVector1.z * vVector2.x) - (vVector1.x * vVector2.z));
vNormal.z := ((vVector1.x * vVector2.y) - (vVector1.y * vVector2.x));
result := vNormal;
end;
//--------------------------------------------------------------
// Возвращает величину вектора
//--------------------------------------------------------------
function Camera.Magnitude(vNormal: Vector3D): real;
begin
// Даёт величину нормали, т.е. длину вектора.
// Мы используем эту информацию для нормализации вектора.
result := Sqrt((vNormal.x * vNormal.x) +
(vNormal.y * vNormal.y) + (vNormal.z * vNormal.z));
end;
//--------------------------------------------------------------
// Возвращает нормализированный вектор
//--------------------------------------------------------------
function Camera.Normalize(vVector: Vector3D): Vector3D;
var
magnit: real;
begin
// Вектор нормализирован - значит, его длинна равна 1. Например,
// вектор (2, 0, 0) после нормализации будет (1, 0, 0).
// Вычислим величину нормали
magnit := Magnitude(vVector);
// Теперь у нас есть величина, и мы можем разделить наш вектор на его величину.
// Это сделает длинну вектора равной единице, так с ним будет легче работать.
vVector.x := vVector.x / magnit;
vVector.y := vVector.y / magnit;
vVector.z := vVector.z / magnit;
result := vVector;
end;
//--------------------------------------------------------------
// Установить позицию камеры
//--------------------------------------------------------------
procedure Camera.Position_Camera(pos_x, pos_y, pos_z, view_x, view_y, view_z,
up_x, up_y, up_z : real);
begin
// Позиция камеры
mPos.x := pos_x;
mPos.y := pos_y;
mPos.z := pos_z;
// Куда смотрит, т.е. взгляд
mView.x := view_x;
mView.y := view_y;
mView.z := view_z;
// Вертикальный вектор камеры
mUp.x := up_x;
mUp.y := up_y;
mUp.z := up_z;
end;
//--------------------------------------------------------------
// Вращение камеры вокруг своей оси (от первого лица)
//--------------------------------------------------------------
procedure Camera.Rotate_View(speed: real);
var
vVector: Vector3D;
begin
// Полчим вектор взгляда
vVector.x := mView.x - mPos.x;
vVector.y := mView.y - mPos.y;
vVector.z := mView.z - mPos.z;
mView.z := (mPos.z + Sin(speed) * vVector.x + Cos(speed) * vVector.z);
mView.x := (mPos.x + Cos(speed) * vVector.x - Sin(speed) * vVector.z);
end;
//--------------------------------------------------------------
// Перемещение камеры (вперед и назад)
//--------------------------------------------------------------
procedure Camera.Move_Camera(speed: real);
var
vVector: Vector3D;
begin
// Получаем вектор взгляда
vVector.x := mView.x - mPos.x;
vVector.y := mView.y - mPos.y;
vVector.z := mView.z - mPos.z;
vVector.y := 0.0; // Это запрещает камере подниматься вверх
vVector := Normalize(vVector);
mPos.x += vVector.x * speed;
mPos.z += vVector.z * speed;
mView.x += vVector.x * speed;
mView.z += vVector.z * speed;
end;
//--------------------------------------------------------------
// Перемещение камеры (влево и вправо)
//--------------------------------------------------------------
procedure Camera.Strafe(speed: real);
begin
// добавим вектор стрейфа к позиции
mPos.x += mStrafe.x * speed;
mPos.z += mStrafe.z * speed;
// Добавим теперь к взгляду
mView.x += mStrafe.x * speed;
mView.z += mStrafe.z * speed;
end;
//--------------------------------------------------------------
// Перемещение вверх и вниз
//--------------------------------------------------------------
procedure Camera.upDown(speed: real);
begin
mPos.y += speed;
mView.y += speed;
end;
//--------------------------------------------------------------
// Вращение вверх и вниз
//--------------------------------------------------------------
procedure Camera.upDownAngle(speed: real);
var
vVector: Vector3D;
begin
// Полчим вектор взгляда
vVector.x := mView.x - mPos.x;
vVector.y := mView.y - mPos.y;
vVector.z := mView.z - mPos.z;
mView.y += speed;
end;
//--------------------------------------------------------------
// Установка камеры
//--------------------------------------------------------------
procedure Camera.Look();
begin
Glu.gluLookAt(mPos.x, mPos.y, mPos.z, // Ранее упомянутая команда
mView.x, mView.y, mView.z,
mUp.x, mUp.y, mUp.z);
end;
//--------------------------------------------------------------
// Обновление
//--------------------------------------------------------------
procedure Camera.update();
var
vCross : Vector3D;
begin
vCross := Cross(mView, mPos, mUp);
// Нормализуем вектор стрейфа
mStrafe := Normalize(vCross);
end;
//--------------------------------------------------------------
// Возвращает позицию камеры по Х
//--------------------------------------------------------------
function Camera.getPosX: real;
begin
Result := mPos.x;
end;
//--------------------------------------------------------------
// Возвращает позицию камеры по Y
//--------------------------------------------------------------
function Camera.getPosY() : real;
begin
Result := mPos.y;
end;
//--------------------------------------------------------------
// Возвращает позицию камеры по Z
//--------------------------------------------------------------
function Camera.getPosZ() : real;
begin
Result := mPos.z;
end;
//--------------------------------------------------------------
// Возвращает позицию взгляда по Х
//--------------------------------------------------------------
function Camera.getViewX() : real;
begin
Result := mView.x;
end;
//--------------------------------------------------------------
// Возвращает позицию взгляда по Y
//--------------------------------------------------------------
function Camera.getViewY() : real;
begin
Result := mView.y;
end;
//--------------------------------------------------------------
// Возвращает позицию взгляда по Z
//--------------------------------------------------------------
function Camera.getViewZ() : real;
begin
Result := mView.z;
end;
//------------------------------------------------------------------------
const
AppWidth = 640;
AppHeight = 480;
const
Key_W = 119;
Key_S = 115;
Key_A = 97;
Key_D = 100;
Key_Q = 113;
Key_E = 101;
Key_Z = 122;
Key_X = 120;
Key_ESC = 27;
var
ScreenWidth, ScreenHeight : Integer;
posX : Single;
posY : Single;
posZ : Single;
Texture : GLuint;
Texture2 : GLuint;
Cam: Camera;
//****************************************************//
//******* Процедура создания куба **********//
//****************************************************//
procedure DrawCube();
begin
// front
glColor3f(1.0, 0.0, 0.0);
glBegin(GL.GL_QUADS);
glVertex3f( -2.0, 2.0, 2.0); // 1
glVertex3f( -2.0, -2.0, 2.0); // 2
glVertex3f( 2.0, -2.0, 2.0); // 3
glVertex3f( 2.0, 2.0, 2.0); // 4
glEnd;
// back
glColor3f(0.0, 1.0, 0.0);
glBegin(GL.GL_QUADS);
glVertex3f( -2.0, 2.0, -2.0); // 5
glVertex3f( -2.0, -2.0, -2.0); // 6
glVertex3f( 2.0, -2.0, -2.0); // 7
glVertex3f( 2.0, 2.0, -2.0); // 8
glEnd;
// left
glColor3f(0.0, 0.0, 1.0);
glBegin(GL.GL_QUADS);
glVertex3f( -2.0, 2.0, -2.0); // 5
glVertex3f( -2.0, -2.0, -2.0); // 6
glVertex3f( -2.0, -2.0, 2.0); // 2
glVertex3f( -2.0, 2.0, 2.0); // 1
glEnd;
// right
glColor3f(1.0, 1.0, 0.0);
glBegin(GL.GL_QUADS);
glVertex3f( 2.0, -2.0, -2.0); // 7
glVertex3f( 2.0, 2.0, -2.0); // 8
glVertex3f( 2.0, 2.0, 2.0); // 4
glVertex3f( 2.0, -2.0, 2.0); // 3
glEnd;
// top
glColor3f(1.0, 0.0, 1.0);
glBegin(GL.GL_QUADS);
glVertex3f( -2.0, 2.0, 2.0); // 1
glVertex3f( 2.0, 2.0, 2.0); // 4
glVertex3f( 2.0, 2.0, -2.0); // 8
glVertex3f( -2.0, 2.0, -2.0); // 5
glEnd;
// down
glColor3f(0.5, 0.0, 0.5);
glBegin(GL.GL_QUADS);
glVertex3f( 2.0, -2.0, 2.0); // 3
glVertex3f( -2.0, -2.0, 2.0); // 2
glVertex3f( -2.0, -2.0, -2.0); // 6
glVertex3f( 2.0, -2.0, -2.0); // 7
glEnd;
end;
procedure MYQUAD( Tex : integer);
begin
Gl.glBindTexture(Gl.GL_TEXTURE_2D, Tex);
GL.glBegin(GL.GL_QUADS);
Gl.glTexCoord2f(0, 0); gl.glVertex3f( -2.0, 2.0, 0.0); // 1
Gl.glTexCoord2f(0, 1); gl.glVertex3f( -2.0, -2.0, 0.0); // 2
Gl.glTexCoord2f(1, 1); gl.glVertex3f( 2.0, -2.0, 0.0); // 3
Gl.glTexCoord2f(1, 0); gl.glVertex3f( 2.0, 2.0, 0.0); // 4
GL.glEnd();
end;
//****************************************************//
//******** Загрузка текстуры **********//
//****************************************************//
function LoadTextere (filename : string) : Integer;
var
// Создание пространства для хранения текстуры
TextureImage: PSDL_Surface;
texID : integer;
nMaxAnisotropy : Integer;
begin
nMaxAnisotropy := 16;
TextureImage := IMG_Load(PChar(filename));
if ( TextureImage <> Nil ) then begin
// Создадим текстуру
//glEnable(GL_TEXTURE_2D);
glGenTextures( 1, @texID );
glBindTexture( GL_TEXTURE_2D, texID );
glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, @nMaxAnisotropy);
if (nMaxAnisotropy > 0) then
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, nMaxAnisotropy);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
//glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, TextureImage^.W,TextureImage^.H, 0, GL_BGR_EXT,GL_UNSIGNED_BYTE, TextureImage^.pixels);
//glGenerateMipmap( GL_TEXTURE_2D );
gluBuild2DMipmaps (GL_TEXTURE_2D, GL_RGBA , TextureImage^.W,TextureImage^.H, GL_BGRA_EXT, GL_UNSIGNED_BYTE, TextureImage^.pixels);
end;
// Освобождаем память от картинки
if ( TextureImage <> nil ) then
SDL_FreeSurface( TextureImage );
Result := texID;
end;
//****************************************************//
//*** Инициализация ресурсов приложения и OpenGL ***//
//****************************************************//
procedure InitScene;
begin
glClearColor(0.0, 0.0, 0.0, 0.0);
glEnable(GL_DEPTH_TEST);
{
glEnable( GL_TEXTURE_2D );
glEnable( GL_ALPHA_TEST );
glAlphaFunc( GL_GREATER, 0.0 );
glEnable ( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
//glBlendEquation( GL_FUNC_ADD );
// Метод в текущей версии FPC 3.0.4 падает в исключение
// возможно в след версиях это исправят
Texture2 := LoadTextere('data\tex1.tga');
Texture := LoadTextere('data\a2.tga');
// Создание камеры и задание первоначальных значений
Cam := Camera.Create;
Cam.Position_Camera(0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
end;
//****************************************************//
//*** Процедура отрисовки ***//
//*** Данная процедура вызывается каждый кадр ***//
//****************************************************//
procedure RenderScene; cdecl;
var
i, j : Integer;
begin
glLoadIdentity();
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
Cam.Look();
for i := -10 to 10 do
for j := -10 to 10 do begin
glPushMatrix();
glTranslatef( 1.0 * i, -1.5, 1.0 * j );
glColor3f( 0.1 * i, 0.3, 0.1 * j );
glutSolidCube(0.5);
glPopMatrix();
end;
glPushMatrix();
glTranslatef( 0.0, -1.5, 0.0 );
glColor3f( 0.9, 0.3, 0.7);
glutSolidTeapot(1.0);
glPopMatrix();
Cam.update();
glutSwapBuffers;
//glutPostRedisplay;
end;
//****************************************************//
//*** Процедура перенастройки ***//
//*** Проц. вызыв. при изменении размера экрана ***//
//****************************************************//
procedure Reshape(Width, Height: Integer); cdecl;
begin
glViewport(0,0, Width, Height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity;
gluPerspective(45, Width / Height, 0.1, 10000.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity;
end;
//****************************************************//
//*** Процедура таймер. ***//
//*** Вызывается каждые 40 мсек для отрисовка кадра **//
//****************************************************//
procedure Timer(val: integer); cdecl;
begin
glutPostRedisplay();
glutTimerFunc(40, @Timer, 0);
end;
procedure pressKey ( key : byte; x, y : integer ); cdecl;
begin
case key of
Key_W : Cam.Move_Camera( 1.0);
Key_S : Cam.Move_Camera(-1.0);
Key_A : Cam.Strafe(-1.0);
Key_D : Cam.Strafe( 1.0);
Key_Q : Cam.Rotate_View(-0.05);
Key_E : Cam.Rotate_View( 0.05);
Key_Z : Cam.upDownAngle (-0.05);
Key_X : Cam.upDownAngle ( 0.05);
Key_ESC : halt;
end;
end;
//****************************************************//
//*** Главная программа ***//
//*** Создание окна и передача процедуры рендера ***//
//****************************************************//
begin
glutInit(@argc,argv);
glutInitDisplayMode(GLUT_RGBA or GLUT_DOUBLE or GLUT_DEPTH);
glutInitWindowSize(AppWidth, AppHeight);
ScreenWidth := glutGet(GLUT_SCREEN_WIDTH);
ScreenHeight := glutGet(GLUT_SCREEN_HEIGHT);
glutInitWindowPosition((ScreenWidth - AppWidth) div 2, (ScreenHeight - AppHeight) div 2);
glutCreateWindow('Lazarus OpenGL Tutorial');
glutKeyboardFunc ( @pressKey );
InitScene;
glutDisplayFunc(@RenderScene);
glutReshapeFunc(@Reshape);
glutTimerFunc(40, @Timer, 0);
glutMainLoop;
end.
| 34.052716 | 137 | 0.408453 |
479d79097beac763e087d7b4ee21de8fa695004c | 2,054 | pas | Pascal | screen/0087.pas | nickelsworth/swag | 7c21c0da2291fc249b9dc5cfe121a7672a4ffc08 | [
"BSD-2-Clause"
]
| 11 | 2015-12-12T05:13:15.000Z | 2020-10-14T13:32:08.000Z | screen/0087.pas | nickelsworth/swag | 7c21c0da2291fc249b9dc5cfe121a7672a4ffc08 | [
"BSD-2-Clause"
]
| null | null | null | screen/0087.pas | nickelsworth/swag | 7c21c0da2291fc249b9dc5cfe121a7672a4ffc08 | [
"BSD-2-Clause"
]
| 8 | 2017-05-05T05:24:01.000Z | 2021-07-03T20:30:09.000Z | {
┤ You mean there is a way to have just a PART of the screen scroll with
┤ registers?!?!?
All this routines is importet from Myown ASM-lib. And works fine i
Turbo Pascal. v7
Use this routine to "scroll" the screen :-))
My English is not good enough to explain Exactly that it does!
}
Procedure ScreenPos(Plass:word); assembler;
asm
mov bx,plass
mov dx,3d4h
mov al,0ch
mov ah,bh
out dx,ax
mov al,0dh
mov ah,bl
out dx,ax
end;
{
Thos routine will tell you there the "screen" should start Writing the
screen one more time...
It's just called a Split, screen Routine...:)
}
procedure Split_screen(Linje:word); assember;
label crt_ok, Vga_split;
asm
mov dx,3d4h
crt_ok:
mov al,18h
out dx,al
inc dx
MOV AX,linje
out dx,al
dec dx
VGA_split:
mov al,7
out dx,al
inc dx
in al,dx
mov bl,AH
and bl,1
mov cl,4
shl bl,cl
and al,not 10h
or al,bl
out dx,al
dec dx
mov al,9
out dx,al
inc dx
in al,dx
and al,not 40h
out dx,al
end;
{ This routine will wait for the vertical Retrace! }
Procedure WaitBorder; assembler;
label wb1,wb2;
asm
MOV DX,3dah
wb1: in al,dx
test al,8
jnz wb1
wb2: in al,dx
test al,8
jz wb2
end;
{
This was all!
Everytime you change some om the Split_Screens, and ScreenPos, Do wait
for the Vertical Retrace, if you don't want a flicking screen! :-)
And remember by using these registers in Text-modus, will show you
"two" pages, and might give you some errors.
The best place to use these routines is if you find a VGA, MODEX-
library!
But I will work half the way it should in standard VGA, 320x200. Mode.
But I know you will get it work :-))
}
| 22.086022 | 72 | 0.558909 |
fcd24b24ffa611d8cd051a9f67d213c08d957535 | 59,153 | dfm | Pascal | Cadastro/Data.Imagens.dfm | diondcm/formacao | 51603b11a6976e9695d98e81c5a6c4e167a50daf | [
"MIT"
]
| null | null | null | Cadastro/Data.Imagens.dfm | diondcm/formacao | 51603b11a6976e9695d98e81c5a6c4e167a50daf | [
"MIT"
]
| null | null | null | Cadastro/Data.Imagens.dfm | diondcm/formacao | 51603b11a6976e9695d98e81c5a6c4e167a50daf | [
"MIT"
]
| null | null | null | object dmdImagens: TdmdImagens
OldCreateOrder = True
Height = 251
Width = 486
object ImageListBase: TImageList
Height = 40
Width = 40
Left = 207
Top = 72
Bitmap = {
494C010102000800040028002800FFFFFFFFFF10FFFFFFFFFFFFFFFF424D3600
0000000000003600000028000000A00000002800000001002000000000000064
000000000000000000000000000000000000F7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFFAFAFAFFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FF0000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000F7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFFBFBFBFFFFFFFFFFEBEBEBFFFFFFFFFFFEFEFEFFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FF0000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000F7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFC3D8F0FF69A6EBFF62A2EBFF62A2EBFF62A2EBFF62A2EBFF62A2EBFF62A2
EBFF62A2EBFF62A2EBFF62A2EBFF62A2EBFF62A2EBFF63A2EBFF62A2EBFF69A6
EBFF83B4ECFFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFFCFCFCFFFFFF
FFFFF3F3F3FF545454FF000000FF070707FFE0E0E0FFFFFFFFFFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FF0000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000F7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFEDF1F5FF5D9E
E8FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576
E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576
E5FF1576E5FF5D9EE8FFEDF1F5FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFFCFCFCFFFFFFFFFFECECECFF4B4B
4BFF000000FF000000FF000000FF000000FF000000FF6E6E6EFFFFFFFFFFFEFE
FEFFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FF0000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000F7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FF6CA7E9FF1576
E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576
E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576
E5FF1576E5FF1576E5FF6BA6E9FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFFDFDFDFFFFFFFFFFE5E5E5FF424242FF000000FF0000
00FF000000FF000000FF000000FF000000FF000000FF000000FF050505FFDDDD
DDFFFFFFFFFFF8F8F8FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FF0000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000F7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFE1EAF4FF1777E4FF1576
E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576
E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576
E5FF1576E5FF1576E5FF1878E5FFE1EAF4FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFFEFEFEFFFFFFFFFFDDDDDDFF393939FF000000FF000000FF000000FF0000
00FF000000FF707070FFF1F1F1FF000000FF010101FF010101FF000000FF0000
00FF6B6B6BFFFFFFFFFFFFFFFFFFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FF0000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000F7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFB4CFEFFF1576E5FF1576
E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576
E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576
E5FF1576E5FF1576E5FF1576E5FFB4CFEFFFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFFFFFFFFFFFFF
FFFFD4D4D4FF313131FF000000FF000000FF000000FF000000FF000000FF7575
75FFFFFFFFFFFFFFFFFFF1F1F1FF000000FF010101FF010101FF010101FF0000
00FF000000FF030303FFDBDBDBFFFFFFFFFFF8F8F8FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FF0000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000F7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFA8C8EDFF1576E5FF1576
E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576
E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576
E5FF1576E5FF1576E5FF1576E5FFA7C8EDFFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFFFFFFFFFFFFFFFFFCBCBCBFF2727
27FF000000FF000000FF000000FF000000FF000000FF7E7E7EFFFFFFFFFFFFFF
FFFFF9F9F9FFFBFBFBFFEDEDEDFF000000FF010101FF010101FF010101FF0101
01FF010101FF000000FF000000FF686868FFFFFFFFFFFFFFFFFFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FF0000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000F7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFAFCDF0FF1576E5FF1576
E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576
E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576
E5FF1576E5FF1576E5FF1576E5FFAFCDF0FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFFFFFFFFFFFFFFFFFC2C2C2FF1F1F1FFF000000FF0000
00FF000000FF000000FF000000FF878787FFFFFFFFFFFFFFFFFFFFFFFFFFF7F7
F7FFF7F7F7FFFBFBFBFFEDEDEDFF000000FF010101FF010101FF010101FF0101
01FF010101FF010101FF000000FF000000FF020202FFD8D8D8FFFFFFFFFFF8F8
F8FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FF0000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000F7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFBAD3EFFF1576E5FF1576
E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576
E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576
E5FF1576E5FF1576E5FF1576E5FFBAD3EFFFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFFFFFFFFFFFFFFFFFBABABAFF171717FF000000FF000000FF000000FF0000
00FF000000FF909090FFFFFFFFFFFFFFFFFFFFFFFFFFD1D1D1FF929292FFFFFF
FFFFF7F7F7FFFBFBFBFFEDEDEDFF000000FF010101FF010101FF010101FF0101
01FF010101FF010101FF010101FF010101FF000000FF000000FF656565FFFFFF
FFFFFFFFFFFFF7F7F7FFF7F7F7FFF7F7F7FF0000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000F7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFD2E1F2FF1576E5FF1576
E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576
E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576
E5FF1576E5FF1576E5FF1576E5FFD2E1F2FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFFFFFFFFFFFFF
FFFFB1B1B1FF0F0F0FFF000000FF000000FF000000FF000000FF000000FF9999
99FFFFFFFFFFFFFFFFFFFFFFFFFFC7C7C7FF282828FF000000FF4C4C4CFFFFFF
FFFFF7F7F7FFFBFBFBFFEDEDEDFF000000FF010101FF010101FF010101FF0101
01FF010101FF010101FF010101FF010101FF010101FF000000FF000000FF0000
00FFD6D6D6FFFFFFFFFFF8F8F8FFF7F7F7FF0000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000F7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF1F3F6FF1A79E4FF1576
E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576
E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576
E5FF1576E5FF1576E5FF1B79E4FFF2F4F6FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFFFFFFFFFA8A8A8FF0808
08FF000000FF000000FF000000FF000000FF040404FFA2A2A2FFFFFFFFFFFFFF
FFFFFFFFFFFFB1B1B1FF131313FF000000FF000000FF6A6A6AFFF2F2F2FFFAFA
FAFFF7F7F7FFFBFBFBFFEDEDEDFF000000FF010101FF010101FF010101FF0101
01FF010101FF010101FF010101FF010101FF010101FF010101FF010101FF0000
00FF000000FF626262FFFFFFFFFFF8F8F8FF0000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000F7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FF4490E7FF1576
E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576
E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576
E5FF1576E5FF1576E5FF4591E7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFFFFFFFFF5B5B5BFF000000FF0000
00FF000000FF000000FF0A0A0AFFABABABFFFFFFFFFFFFFFFFFFFFFFFFFF9C9C
9CFF000000FF000000FF000000FF848484FFFFFFFFFFFFFFFFFFFAFAFAFFF7F7
F7FFF7F7F7FFFBFBFBFFEDEDEDFF000000FF010101FF010101FF010101FF0101
01FF010101FF010101FF010101FF010101FF010101FF010101FF010101FF0101
01FF000000FF000000FF535353FFFFFFFFFF0000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000F7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FF85B5EBFF1576
E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576
E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576
E5FF1576E5FF1576E5FF85B5ECFFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFFFFFFFFF626262FF000000FF0000
00FF181818FFB4B4B4FFFFFFFFFFFFFFFFFFFEFEFEFF878787FF000000FF0000
00FF000000FF9A9A9AFFFFFFFFFFFFFFFFFF757575FFE5E5E5FFF9F9F9FFF7F7
F7FFF7F7F7FFFBFBFBFFEDEDEDFF000000FF010101FF010101FF010101FF0101
01FF010101FF010101FF010101FF010101FF010101FF010101FF010101FF0101
01FF010101FF000000FF5D5D5DFFFFFFFFFF0000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000F7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFDAE5F3FF1878
E4FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576
E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576
E5FF1576E5FF1978E4FFDAE6F3FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFFFFFFFFF636363FF000000FF0000
00FFD0D0D0FFFFFFFFFFF7F7F7FFFFFFFFFF808080FF000000FF151515FFB5B5
B5FFFFFFFFFFFFFFFFFFFFFFFFFFB8B8B8FF000000FFE7E7E7FFFBFBFBFFF7F7
F7FFF7F7F7FFFBFBFBFFEDEDEDFF000000FF010101FF010101FF010101FF0101
01FF010101FF010101FF010101FF010101FF010101FF010101FF010101FF0101
01FF010101FF000000FF5E5E5EFFFFFFFFFF0000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000F7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FF72AA
EAFF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1B79E4FF4993
E7FF65A3EAFF4993E7FF1B79E4FF1576E5FF1576E5FF1576E5FF1576E5FF1576
E5FF1576E5FF71A9E9FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFFFFFFFFF636363FF000000FF0000
00FFBFBFBFFFFFFFFFFFF7F7F7FFFEFEFEFFADADADFFBCBCBCFFFFFFFFFFF2F2
F2FFF9F9F9FFF7F7F7FFFFFFFFFFBFBFBFFF000000FFE8E8E8FFFBFBFBFFF7F7
F7FFF7F7F7FFFBFBFBFFEDEDEDFF000000FF010101FF010101FF010101FF0101
01FF010101FF010101FF010101FF010101FF010101FF010101FF010101FF0101
01FF010101FF000000FF5E5E5EFFFFFFFFFF0000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000F7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFEAEF
F5FF3F8DE7FF1576E5FF1576E5FF1576E5FF1576E5FF9DC2EDFFEBF0F5FFF7F7
F7FFF6F6F7FFF7F7F7FFEBF0F5FF9EC3EDFF3387E6FF1576E5FF1576E5FF1576
E5FF1576E5FFEAEFF5FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFFFFFFFFF636363FF000000FF0000
00FFBFBFBFFFFFFFFFFFF7F7F7FFF7F7F7FFFEFEFEFFFFFFFFFF000000FF8484
84FFFFFFFFFFF7F7F7FFFFFFFFFFBFBFBFFF000000FFF5F5F5FFFFFFFFFFF7F7
F7FFF7F7F7FFFBFBFBFFEDEDEDFF000000FF010101FF010101FF010101FF0101
01FF010101FF010101FF010101FF010101FF010101FF010101FF010101FF0101
01FF010101FF000000FF5E5E5EFFFFFFFFFF0000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000F7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF4F0E8FFDEB86EFFD29520FFCD8905FFCD8906FFE1BF
80FFE9EEF5FF1B79E4FF1576E5FF1777E5FF79AEEAFFD6E4F4FF73ACECFF3689
E7FF1A79E4FF3789E7FF74ACECFFD5E3F4FFEEF1F5FF1777E5FF1576E5FF1C7A
E5FF70A9EAFFE1BF80FFCE8905FFCE8905FFCE8A07FFDEB86EFFF4F0E8FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFFFFFFFFF636363FF000000FF0000
00FFBFBFBFFFFFFFFFFFF7F7F7FFF7F7F7FFF7F7F7FFFFFFFFFF000000FF9292
92FFFFFFFFFFF7F7F7FFFFFFFFFFD0D0D0FF000000FF6A6A6AFFB8B8B8FFFDFD
FDFFF7F7F7FFFBFBFBFFEDEDEDFF000000FF010101FF010101FF010101FF0101
01FF010101FF010101FF010101FF010101FF010101FF010101FF010101FF0101
01FF010101FF000000FF5E5E5EFFFFFFFFFF0000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000F7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F6FFD6A039FFCF8800FFCF8800FFCF8800FFCF8800FFCF88
00FFDAAD57FFEDF1F5FFC6DBF2FFD3E2F3FFF7F7F7FF1A79E5FF1576E5FF1576
E5FF1576E5FF1576E5FF1576E5FF1A78E5FF91BCEEFFD3E2F3FFC6DAF2FFEDF1
F5FFF1E9DBFFCF8800FFCF8800FFCF8800FFCF8800FFCF8800FFD6A039FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFFFFFFFFF636363FF000000FF0000
00FFBFBFBFFFFFFFFFFFF7F7F7FFF7F7F7FFF7F7F7FFFFFFFFFF000000FF9999
99FFFFFFFFFFFFFFFFFFA4A4A4FF151515FF000000FF000000FFFFFFFFFFF7F7
F7FFF7F7F7FFFBFBFBFFEDEDEDFF000000FF010101FF010101FF010101FF0101
01FF010101FF010101FF010101FF010101FF010101FF010101FF010101FF0101
01FF010101FF000000FF5E5E5EFFFFFFFFFF0000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000F7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFEFE5D3FFCF8800FFCF8800FFCF8800FFCF8800FFCF8800FFCF88
00FFCF8800FFD6A13CFFDFBC78FFF7F7F7FF89B7EDFF1576E5FF1576E5FF1576
E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FFF7F7F6FFDFBB77FFD6A1
3CFFCF8904FFCF8800FFCF8800FFCF8800FFCF8800FFCF8800FFCF8800FFEFE5
D3FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFFFFFFFFF636363FF000000FF0000
00FFBFBFBFFFFFFFFFFFF7F7F7FFF7F7F7FFFAFAFAFFFFFFFFFF000000FF5858
58FF828282FFFFFFFFFFF4F4F4FF000000FF000000FFA7A7A7FFFFFFFFFFF7F7
F7FFF7F7F7FFFBFBFBFFEDEDEDFF000000FF010101FF010101FF010101FF0101
01FF010101FF010101FF010101FF010101FF010101FF010101FF010101FF0101
01FF010101FF000000FF5E5E5EFFFFFFFFFF0000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000F7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFEFE1C6FFCF8800FFCF8800FFCF8800FFCF8800FFCF8800FFCF88
00FFCF8800FFCF8800FFE3C488FFBFD7F2FF1677E5FF1576E5FF1576E5FF1576
E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FFBCD5F1FFE3C388FFCF88
00FFCF8800FFCF8800FFCF8800FFCF8800FFCF8800FFCF8800FFCF8800FFEFE1
C6FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFFFFFFFFF636363FF000000FF0000
00FFBFBFBFFFFFFFFFFFF7F7F7FFFAFAFAFFE1E1E1FF343434FF000000FF0000
00FFD8D8D8FFFDFDFDFFFFFFFFFFCFCFCFFF000000FFFFFFFFFFF7F7F7FFF7F7
F7FFF7F7F7FFFBFBFBFFEDEDEDFF000000FF010101FF010101FF010101FF0101
01FF010101FF010101FF010101FF010101FF010101FF010101FF010101FF0101
01FF010101FF000000FF5E5E5EFFFFFFFFFF0000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000F7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFEDE2CBFFCF8800FFCF8800FFCF8800FFCF8800FFCF8800FFCF88
00FFCF8800FFCF8B0AFFF4F1EBFF4C95E8FF1576E5FF1576E5FF1576E5FF1576
E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF4C95E8FFF4F0EAFFCF8B
09FFCF8800FFCF8800FFCF8800FFCF8800FFCF8800FFCF8800FFCF8800FFEDE2
CBFFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFFFFFFFFF636363FF000000FF0000
00FFBFBFBFFFFFFFFFFFF7F7F7FFF7F7F7FFFFFFFFFF2F2F2FFF000000FF4343
43FFFFFFFFFFF7F7F7FFF7F7F7FFFFFFFFFFF2F2F2FFF9F9F9FFF7F7F7FFF7F7
F7FFF8F8F8FFFFFFFFFFFFFFFFFF000000FF010101FF010101FF010101FF0101
01FF010101FF010101FF010101FF010101FF010101FF010101FF010101FF0101
01FF010101FF000000FF5E5E5EFFFFFFFFFF0000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000F7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF0EADEFFCF8800FFCF8800FFCF8800FFCF8800FFCF8800FFCF88
00FFCF8800FFD8A544FFE2EBF5FF1676E5FF1576E5FF1576E5FF1576E5FF1576
E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1677E5FFE3EBF5FFD8A5
44FFCF8800FFCF8800FFCF8800FFCF8800FFCF8800FFCF8800FFCF8800FFF0EA
DEFFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFFFFFFFFF636363FF000000FF0000
00FFBFBFBFFFFFFFFFFFF7F7F7FFF7F7F7FFF8F8F8FFFFFFFFFF000000FFECEC
ECFFFBFBFBFFF7F7F7FFF7F7F7FFF7F7F7FFF9F9F9FFF7F7F7FFFDFDFDFFFFFF
FFFFFFFFFFFFA9A9A9FF252525FF000000FF000000FF000000FF010101FF0101
01FF010101FF010101FF010101FF010101FF010101FF010101FF010101FF0101
01FF010101FF000000FF5E5E5EFFFFFFFFFF0000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000F7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF6F5F4FFCF8B08FFCF8800FFCF8800FFCF8800FFCF8800FFCF88
00FFCF8800FFDEB76DFFBBD4F1FF1576E5FF1576E5FF1576E5FF1576E5FF1576
E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FFBCD5F1FFDEB7
6DFFCF8800FFCF8800FFCF8800FFCF8800FFCF8800FFCF8800FFCF8B09FFF6F6
F5FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFFFFFFFFF636363FF000000FF0000
00FFBFBFBFFFFFFFFFFFF7F7F7FFF7F7F7FFF7F7F7FFFAFAFAFFFAFAFAFFFDFD
FDFFF7F7F7FFF7F7F7FFF7F7F7FFF9F9F9FFFFFFFFFFFFFFFFFFDFDFDFFF5E5E
5EFF000000FF000000FF1B1B1BFFA6A6A6FF3A3A3AFF000000FF000000FF0000
00FF010101FF010101FF010101FF010101FF010101FF010101FF010101FF0101
01FF010101FF000000FF5E5E5EFFFFFFFFFF0000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000F7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFD59E36FFCF8800FFCF8800FFCF8800FFCF8800FFCF88
00FFCF8800FFE0BC77FFB1CEF0FF1576E5FF1576E5FF1576E5FF1576E5FF1576
E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FFB1CEF0FFE0BC
77FFCF8800FFCF8800FFCF8800FFCF8800FFCF8800FFCF8800FFD59E35FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFFFFFFFFF636363FF000000FF0000
00FFBFBFBFFFFFFFFFFFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF8F8F8FFF7F7
F7FFF7F7F7FFFEFEFEFFFFFFFFFFFFFFFFFF949494FF0E0E0EFF000000FF0000
00FF6A6A6AFFE9E9E9FFFFFFFFFFFFFFFFFFFFFFFFFFD6D6D6FF262626FF0000
00FF000000FF010101FF010101FF010101FF010101FF010101FF010101FF0101
01FF010101FF000000FF5E5E5EFFFFFFFFFF0000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000F7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFE3C488FFCF8800FFCF8800FFD8A645FFE5CA97FFECDD
C1FFEDDFC5FFE7D3ADFFC4D9F2FF1576E5FF1576E5FF1576E5FF1576E5FF1576
E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FFC4DAF2FFE7D3
ADFFE8D2A7FFECDDC1FFE5CA97FFD8A645FFCF8902FFCF8800FFE3C488FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFFFFFFFFF636363FF000000FF0000
00FFBFBFBFFFFFFFFFFFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFFAFAFAFFFFFF
FFFFFFFFFFFFCACACAFF484848FF000000FF000000FF323232FFB5B5B5FFFFFF
FFFFFFFFFFFFFCFCFCFFF7F7F7FFF7F7F7FFF8F8F8FFFFFFFFFFFFFFFFFFB7B7
B7FF000000FF000000FF010101FF010101FF010101FF010101FF010101FF0101
01FF010101FF000000FF5E5E5EFFFFFFFFFF0000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000F7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF5F4F1FFDCB262FFDBAF5AFFF7F7F7FFF5F4F2FFEEE2
CCFFEDE1C9FFF7F7F7FFEEF2F6FF1B79E5FF1576E5FF1576E5FF1576E5FF1576
E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF1C7AE5FFEFF2F6FFF7F7
F7FFF4F2EDFFEEE3CCFFF5F4F2FFF7F7F7FFEFE5D1FFDCB262FFF5F4F1FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFFFFFFFFF636363FF000000FF0000
00FFBFBFBFFFFFFFFFFFF7F7F7FFF7F7F7FFFFFFFFFFFFFFFFFFFBFBFBFF7F7F
7FFF000000FF000000FF000000FF808080FFFBFBFBFFFFFFFFFFFFFFFFFFF7F7
F7FFF7F7F7FFF7F7F7FFFDFDFDFFFFFFFFFFFFFFFFFFA3A3A3FF262626FF0000
00FF000000FF000000FF000000FF000000FF000000FF010101FF010101FF0101
01FF010101FF000000FF5E5E5EFFFFFFFFFF0000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000F7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFE2C284FFD08F11FFCF88
00FFCF8800FFDEB76CFFF5F3EFFF69A5EAFF1576E5FF1576E5FF1576E5FF1576
E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FF6AA6EAFFF5F3EEFFDEB7
6BFFCF8B09FFCF8800FFD08F12FFE2C284FFF6F6F5FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFFFFFFFFF636363FF000000FF0000
00FFBFBFBFFFFFFFFFFFFFFFFFFFFFFFFFFFB5B5B5FF323232FF000000FF0000
00FF494949FFCACACAFFFFFFFFFFFFFFFFFFFAFAFAFFF7F7F7FFF7F7F7FFF9F9
F9FFFFFFFFFFFFFFFFFFD6D6D6FF595959FF000000FF000000FF000000FF0000
00FF000000FF000000FF2C2C2CFF939393FF010101FF000000FF000000FF0101
01FF010101FF000000FF5E5E5EFFFFFFFFFF0000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000F7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFCF8800FFCF8800FFCF88
00FFCF8800FFCF8800FFD7A33FFFDCE6F0FF237EE5FF1576E5FF1576E5FF1576
E5FF1576E5FF1576E5FF1576E5FF1576E5FF1576E5FFDCE5F0FFD7A33FFFCF88
00FFCF8800FFCF8800FFCF8800FFCF8800FFDCB363FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFFFFFFFFF636363FF000000FF0000
00FFD6D6D6FFF3F3F3FF6A6A6AFF000000FF000000FF0F0F0FFF959595FFFFFF
FFFFFFFFFFFFFEFEFEFFF7F7F7FFF7F7F7FFF7F7F7FFFFFFFFFFFFFFFFFFFFFF
FFFF8A8A8AFF0E0E0EFF000000FF000000FF000000FF000000FF000000FF0000
00FF747474FFF0F0F0FFFFFFFFFFFFFFFFFFFFFFFFFF969696FF000000FF0000
00FF010101FF000000FF5E5E5EFFFFFFFFFF0000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000F7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFEAD7B3FFCF8800FFCF8800FFCF88
00FFCF8800FFCF8800FFCF8800FFE3C58BFFBDD5F1FF1576E5FF1576E5FF1576
E5FF1576E5FF1576E5FF1576E5FF1576E5FF1E7BE5FFE3C58BFFCF8800FFCF88
00FFCF8800FFCF8800FFCF8800FFCF8800FFCF8800FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFFFFFFFFF636363FF000000FF0000
00FF171717FF000000FF000000FF707070FFE4E4E4FFFFFFFFFFFFFFFFFFF9F9
F9FFF7F7F7FFF7F7F7FFFBFBFBFFFFFFFFFFFFFFFFFFBDBDBDFF404040FF0000
00FF000000FF000000FF000000FF000000FF000000FF434343FFBFBFBFFFFFFF
FFFFFFFFFFFFFBFBFBFFF7F7F7FFFFFFFFFFFFFFFFFFFFFFFFFFBEBEBEFF0000
00FF000000FF000000FF5E5E5EFFFFFFFFFF0000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000F7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFDCAF5AFFCF8800FFCF8800FFCF88
00FFCF8800FFCF8800FFCF8800FFD59D32FFF7F7F7FF3E8DE7FF1576E5FF1576
E5FF1576E5FF1576E5FF1576E5FF3F8DE7FFCADDF3FFD59D32FFCF8800FFCF88
00FFCF8800FFCF8800FFCF8800FFCF8800FFCF8800FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFFFFFFFFF565656FF000000FF0000
00FF000000FF000000FF161616FF888888FFF8F8F8FFFFFFFFFFFFFFFFFFF9F9
F9FFFFFFFFFFFFFFFFFFEFEFEFFF727272FF000000FF000000FF000000FF0000
00FF000000FF000000FF111111FF8D8D8DFFFFFFFFFFFFFFFFFFFFFFFFFFF7F7
F7FFFDFDFDFFFFFFFFFFFFFFFFFFC0C0C0FF4F4F4FFF000000FF000000FF0000
00FF000000FF000000FF505050FFFFFFFFFF0000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000F7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFD7A23CFFCF8800FFCF8800FFCF88
00FFCF8800FFCF8800FFCF8800FFCF8E10FFF7F7F7FFF5F6F7FFB8D3F1FF79AF
ECFF5D9FEAFF79AFECFFB9D3F1FFF5F6F7FFF7F7F7FFCF8D0EFFCF8800FFCF88
00FFCF8800FFCF8800FFCF8800FFCF8800FFCF8800FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFFCFCFCFFDCDCDCFF595959FF0000
00FF000000FF000000FF000000FF000000FF000000FF2C2C2CFFABABABFFFFFF
FFFFA5A5A5FF272727FF000000FF000000FF000000FF000000FF000000FF0000
00FF5D5D5DFFD9D9D9FFFFFFFFFFFFFFFFFFF9F9F9FFFBFBFBFFFFFFFFFFFFFF
FFFFD7D7D7FF656565FF000000FF000000FF000000FF000000FF000000FF0000
00FF000000FF636363FFDBDBDBFFFCFCFCFF0000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000F7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFD9A84AFFCF8800FFCF8800FFCF88
00FFCF8800FFCF8800FFCF8800FFD29521FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFD29520FFCF8800FFCF88
00FFCF8800FFCF8800FFCF8800FFCF8800FFCF8800FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFFCFCFCFFFFFFFFFFFFFF
FFFFA1A1A1FF222222FF000000FF000000FF000000FF000000FF000000FF0000
00FF000000FF000000FF000000FF000000FF000000FF2B2B2BFFA7A7A7FFFFFF
FFFFFFFFFFFFFDFDFDFFFAFAFAFFFFFFFFFFFFFFFFFFEDEDEDFF7A7A7AFF0707
07FF000000FF000000FF000000FF000000FF000000FF000000FF4D4D4DFFBFBF
BFFFFFFFFFFFFFFFFFFFFCFCFCFFF7F7F7FF0000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000F7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFE3C68DFFCF8800FFCF8800FFCF88
00FFCF8800FFCF8800FFCF8800FFDDB465FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFDDB465FFCF8800FFCF88
00FFCF8800FFCF8800FFCF8800FFCF8800FFCF8800FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF8F8
F8FFFFFFFFFFFFFFFFFFE9E9E9FF6A6A6AFF000000FF000000FF000000FF0000
00FF010101FF010101FF000000FF212121FFFFFFFFFFFFFFFFFFFFFFFFFFF9F9
F9FFFFFFFFFFFFFFFFFFFFFFFFFF8F8F8FFF1C1C1CFF000000FF000000FF0000
00FF000000FF000000FF000000FF353535FFA7A7A7FFFFFFFFFFFFFFFFFFFFFF
FFFFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FF0000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000F7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF5F3EEFFCF8800FFCF8800FFCF88
00FFCF8800FFCF8800FFD18F12FFF1EADCFFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF1EADCFFD19012FFCF88
00FFCF8800FFCF8800FFCF8800FFCF8800FFD49928FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFFCFCFCFFFFFFFFFFFFFFFFFFB1B1B1FF323232FF0000
00FF000000FF000000FF010101FF000000FF000000FF5A5A5AFFDADADAFFFFFF
FFFFA4A4A4FF333333FF000000FF000000FF000000FF000000FF000000FF0000
00FF1C1C1CFF8F8F8FFFFFFFFFFFFFFFFFFFFFFFFFFFF8F8F8FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FF0000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000F7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFD59D32FFCF8800FFCF88
00FFCF8800FFD2951FFFEDE0C6FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFEDE0C6FFD295
1FFFCF8800FFCF8800FFCF8800FFD59D32FFF1EADBFFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFFFFFFFFFFFFFFFFFF6F6
F6FF797979FF000000FF000000FF000000FF000000FF000000FF000000FF0000
00FF000000FF000000FF000000FF000000FF000000FF040404FF787878FFEBEB
EBFFFFFFFFFFFFFFFFFFF9F9F9FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FF0000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000F7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF6F5F4FFE9D5AEFFE1BD
78FFE1BC75FFF5F3EFFFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF5F3
EEFFE7CFA1FFE1BD78FFE9D5AEFFF6F5F4FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFFAFA
FAFFFFFFFFFFFFFFFFFFC0C0C0FF424242FF000000FF000000FF000000FF0000
00FF000000FF000000FF000000FF606060FFD3D3D3FFFFFFFFFFFFFFFFFFFBFB
FBFFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FF0000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000F7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFFFFFFFFFFFFFFFFFFFFFFFFF898989FF090909FF0000
00FF484848FFBABABAFFFFFFFFFFFFFFFFFFFEFEFEFFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FF0000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000F7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF9F9F9FFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FF0000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000F7F7F700F7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF8F8
F8FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7
F7FFF7F7F7FFF7F7F7FFF7F7F7FFF7F7F7FF0000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000424D3E000000000000003E000000
28000000A0000000280000000100010000000000200300000000000000000000
000000000000000000000000FFFFFF0000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000}
end
end
| 70.086493 | 70 | 0.900411 |
83470c61ae7c810073d5702bffae6a0aae983276 | 25,321 | dfm | Pascal | Designer/FInRibbonGallery.dfm | FDE-LC2L/RibbonFramework | 4769c64e17b56cc794a5263a63ac260d733ac665 | [
"BSD-3-Clause"
]
| 42 | 2020-06-18T05:41:11.000Z | 2022-03-15T13:26:23.000Z | Designer/FInRibbonGallery.dfm | FDE-LC2L/RibbonFramework | 4769c64e17b56cc794a5263a63ac260d733ac665 | [
"BSD-3-Clause"
]
| 14 | 2018-12-12T10:06:24.000Z | 2020-02-06T16:05:43.000Z | Designer/FInRibbonGallery.dfm | FDE-LC2L/RibbonFramework | 4769c64e17b56cc794a5263a63ac260d733ac665 | [
"BSD-3-Clause"
]
| 16 | 2020-05-29T12:01:06.000Z | 2022-02-13T07:53:17.000Z | inherited FrameInRibbonGallery: TFrameInRibbonGallery
Width = 680
Height = 551
ExplicitWidth = 680
ExplicitHeight = 551
inherited LabelHeader: TLabel
Width = 680
end
inherited ImageSample: TImage
Left = 508
Width = 165
Height = 68
Picture.Data = {
0954506E67496D61676589504E470D0A1A0A0000000D49484452000000A50000
00440806000000E033F5FD0000001974455874536F6674776172650041646F62
6520496D616765526561647971C9653C0000032069545874584D4C3A636F6D2E
61646F62652E786D7000000000003C3F787061636B657420626567696E3D22EF
BBBF222069643D2257354D304D7043656869487A7265537A4E54637A6B633964
223F3E203C783A786D706D65746120786D6C6E733A783D2261646F62653A6E73
3A6D6574612F2220783A786D70746B3D2241646F626520584D5020436F726520
352E302D633036302036312E3133343737372C20323031302F30322F31322D31
373A33323A30302020202020202020223E203C7264663A52444620786D6C6E73
3A7264663D22687474703A2F2F7777772E77332E6F72672F313939392F30322F
32322D7264662D73796E7461782D6E7323223E203C7264663A44657363726970
74696F6E207264663A61626F75743D222220786D6C6E733A786D703D22687474
703A2F2F6E732E61646F62652E636F6D2F7861702F312E302F2220786D6C6E73
3A786D704D4D3D22687474703A2F2F6E732E61646F62652E636F6D2F7861702F
312E302F6D6D2F2220786D6C6E733A73745265663D22687474703A2F2F6E732E
61646F62652E636F6D2F7861702F312E302F73547970652F5265736F75726365
526566232220786D703A43726561746F72546F6F6C3D2241646F62652050686F
746F73686F70204353352057696E646F77732220786D704D4D3A496E7374616E
636549443D22786D702E6969643A463339393830323138313943313145304232
31314531323938313444413039382220786D704D4D3A446F63756D656E744944
3D22786D702E6469643A46333939383032323831394331314530423231314531
32393831344441303938223E203C786D704D4D3A4465726976656446726F6D20
73745265663A696E7374616E636549443D22786D702E6969643A463339393830
3146383139433131453042323131453132393831344441303938222073745265
663A646F63756D656E7449443D22786D702E6469643A46333939383032303831
39433131453042323131453132393831344441303938222F3E203C2F7264663A
4465736372697074696F6E3E203C2F7264663A5244463E203C2F783A786D706D
6574613E203C3F787061636B657420656E643D2272223F3ED7B1E9B6000020ED
4944415478DAED9D075C14D7F6C77F0B2220A8D87B073B76518A05C5426C899A
A7D13CF334E5D96289C616A3D167349AD84D8F26A668628D15D460A589227610
2C88BD6241A508FB3FE7EECEBA65769959F063CC9F93ACBB33ECDC9DB9F39D73
CFB9F79C7B352059B3EBB8160552202AC5A36861D5C7B8177141F58A2551B174
3127DAD4EA5F30FEACE17F18CAD783BC5FF43516C84B26A74E27A068F1E27075
758353E1428A8EB97BFF092EDD4845FBE65EEEB49963F6622873184A0D419953
006581A895F88424142F5102458A1441E1C2CE8A8F8B883B8BCEBE75CBD1C76C
7A3DA55796FE9DB705940E0465B60465D0A7BBB0FAFD362853CCE5455FB32209
3F7313AB232FE0444A2ACEDD4C13FB6A95758777D512E8D7BA3ADAD62BF7A24F
F1A59294DB8F50B5B49BA2EF9E26283D084A573BA0ECE25BD70B3A1833E8954E
AF4CFD76B605947F1E4EC1FC6DA731A96743746B5AF98555CE832759F099BA0D
09F35F95FDFBC94BF73067F309643ECD11F035A8EA811A65DC91430DC0B91B0F
71F2F23D6C387811850B3960724F6F34ACE2215B4EA511EBEC3EC72B5FF695DD
BF60FB69AC894EC6A53B8F159553A55411FC8BAEE18357EAE7FADDF53117316A
E521AB7F777172C4B945AFD9753D0C64CFF9BB11323108153C5C73FD7E1EA16C
051D8C4FE8F550FFCEDB590CA52341F9D4B8F9DE1C7B09DFEE4E42AF669531A8
4D2DB81476B4EB22F3220CDDC89F0E62EFC75D2CFEB6E7D475BCF37D24A6F769
8237FCAAEB8C11AD56009943EFC230D16FAF894AC6BC4D27F0C3BB7E086C50DE
A22C86F232C1C5C7D3FF26C772493946E51ACAA757E30FB7C842B96C4702AEA4
3EC1D04EB551A5641145655EBAF3083FEE398B5AF4508DEC52D766BDF87F1282
E19DEAE2F5D6D52CCA9BBCEA089CE9219CFF660BBBEA7CD057E16854BD24AED0
F92CFC77CB5CBF9F47283BE11990F7E9C5CD1C3FC5990C65218232CBDCA63C4F
DA667D4C0A22126F624C703DB4AF5F5EF18FE687FCB8F72C12AF3FC09CFECD4C
F65FB9FB181D3FDD8985837C10D4B0BC4D20258018E28F7F8FC31E02DC5C0330
949796F55105247F6E3A411ECAE653B662D3F80EA858C25555995709E4814BF6
E3C4DC9E56EB24F9561A41198AF8F9BDA8057034292FF551067CA786E0E4BC9E
28E1A6DE2BDE7828053B4E5CC3DC01CDD070FC26A12DADB52E92E4114A6E021F
D1EB01BDEEEADF793BC32A942C4F329F62DDC1142C2740FAFB56C7D0A0DA79C0
4C9DF459B817233BD7B5D06ED3D61E4569B27787D1B9280152FABC9C347F4646
3666BEDEC4A43C863265691F5540F2E7E613B7CA42692FE4B6CA94843559ADF2
C530914C2BF3F296EF3E8BB01357B16D4247D5759DFA28136D678662D9E05668
5AA324FE884AA6B2AEE1F7F7DBDA3C4E07A5879D50D6EB079D76642D791BCFB4
65BA4D2825093D76059F939DE9EF5506537A79DBD59C4725DDC2F8DF0E239B6A
7146DF26E8D2A8A2D5EF72D3CDCD73C427C17074D098FCADF5B4ED5835B20D2A
9572530C24FFED323549EF2F3F88E899AF9894C7105D2428D5C0C3EF2D275987
D21EC86D95C9C2B6B3D7D88DD8F95127E1881897F3345B8B461F6E2688DAA04D
5DF58EDDB85F0FC3C3DD19A383EB1ACE77F80F07F1767B4F6A8D2A583DEE743C
79DF25094A5775504632947EF5064207612A7450A6420D942C49D494F2C9FBD7
2E8BC6D54AA06BE34A8A4FE20279C56F2CDB8FAF87B4461655EEDB04DCCEC99D
AC1AD383BF89807F9DB27827D0CBE26FD547ADC7C92F7AA110C1AA14487ECFA0
DFED303D14C94BFA58407461496F55F0F07BABC9DBAC42690FE4B6CA64591412
8F83E76E63C5503F8BF20EC4DFC094D54744D3AD565859CCDD720A3F8FF037A9
B37DA7AFE39B9D6744336EAE182461288B598132ECC061746C236FDB32945DF3
034A167E5AD79257F9FD9E240CED581BFDFD6A28BAF0F77E884267EF8AE8DBAA
9AD89EB5F1B8F0AEE70D686EF15DEEE2618DBA7F5A57E1399B0B6BCA5F4690A6
2427422990BC7DE5EE238C591123AB29CF2DEEAD0A1EFEAFF5E4ED56A1B40772
5B65B2349AB805B3DF682ACC19F3631B8DDF6CB5EE6D99037C3F0367EDC028F2
19BA909231AFB359EB8FA155CDD27833A0A675284B584219167ED8F0B9638025
989147F3114A49FE227B633679B4BD5B56C5DB819E70B5D19B7FEDDE13749F17
86288241828C9D15F622B97966B80C1548FBBB7D1E2634AA2F990A72F2D19A38
942EEA82773B7A290692F7AFDC770E59566CCAB38B5F53050F7FF69B621D4A7B
20B755663469B33E8BF6217E412F68349A3C9727C9DCCD2791FA241393C82493
ABB3842BD43AAE8C110AC2CDC5F21E33941E6650FE6504A424416660461CCDA7
E6DB5C1E673CC5DBDF45A10935E5B69A73F6A2E32EDEC592B77C4CF6B329C05E
E2D4D71A896D7E6A7B7EB15B6853B966DB18DCF6F4742F18D452748C2B0192B5
EFCC3F8E22ECA3CE260F810451E2A25755C1C39F033E0AB10AA53D90DB2AB31B
3DD49D1B57C410AA97FC288F25F1DA03749EB30BFB3EE98AA2AE4E469ADDC879
A4EDA5DBE351C6CD19E3BB3790813251E77D0B28751EBF834C539F93631A5A11
71F4DCF381529215041DF76B329472DE39DB873D9B57C16BA4558D853568D0A7
3BB17258003C084E6EB2AB92F3620EAF9CFC75F21ADEF92E12537A37421F82D8
16901B6352B0906CA61FDEF39335DA19A28485AFAABAD9FC1B6DACDC70EE12FA
7D4C3B94277B594D99D7A93E467E178DD8D9DD4DCA63CFD87BE26644CC0C16F5
941FE7C8CE669F457BD1B95125F4F7AF6E02648EBEBF9681E4F7D4B40CF4F962
8FD096E63E004359DC0C4A2512F9BCA1E40B0C23483EDF760A43DA79E20D333B
936DC09F09BCDA158A591C1B72F40AA6AD3B2A3EB376FC6F47E55D4EECA1CFDC
704C740BF522E06B57288AAA6244474B8ED523245EBD8FCD872FA1303DB9D37A
37B639A2739A9A4535379B6F56DBA921563BCF93C9D37FA78317CAE9C15402E4
AFFBCEA35EF962169DE71357C7E261FA53CC19D02CDFCE71E5FE733846F537B5
B7B70C905A7D57DB33407F22C5F3302DD3A2539EA12C56D20E28E3CEE5BF4D29
2769E959E8B764BF453F59AD311B1037A7078AB93AE5A97C6BB29F3C4F1EFB3E
75F99EC9D87783CA1EE201C96DECFB790C337EB1F514FE2087903BC4950877B4
F3B9CA0D337A8EDD882799D9F9768EDC4205FE6F07568E08107D9EC6404BB03F
DBD67DCECED622707AA84587FADF1ECA027939E46D327B428F5DB5EBD88EE4F9
FF3C3CC0B05D006581FCEDE41443A9F7BE9D544019453665B05FFD02280B24FF
A500CA02F9DB8980D2C34E28FDFF0150E6DC3F05ED8921704C8BC95339D9EE3E
D078AF8043F106792AA740381D42DF25E4A20E4AEE120A0EF807D894593B2BC0
C97737E05A1DDA9C1CFD5EA5F96EBA0E5D8D8303F0241959511DE0D4F9DA8BBE
A4975EB6479CD1B9E8D0D5B096FE75607FDD41038D7EBF56439F73B89B89DEA1
35DCB16E6D5440C951D34A22A0F343B83BC6D630988984D2A9767C046D16BD9E
A6EBF6694DA14CBCA1EB82A95DCE2CD043A387B2900B344E6E4018BDBADA06FA
51FA53FCB8EF2C56475DC01BBE35F076A0175CF318ECCCD73BAE5BFD7CABDFC5
A1F198B7E594F23AB4211C753EEAE7187C31B0053CCB1555740C43D9C5B7B662
D5C0C2776247E4197550E677C55993C693B6883C1ACEAD39F6598FDC0F2028B5
81F7A17D7217C87CA4DFF9AC3A8E5F4DC7BF7F4B119F7F1958158D2A1AE718E9
87BE0ABB41E35A129A3DC5AD42C98301DCEFB9901ECEEECDAB60807F0DFC167E
01DB8E5CC258AA13EE4FB41635939B70DD72BAC2D457BD31B8BD679EEA8F876F
67FD79427CB637FD41121E727C63E97EFCA79D27BEDB9D88D523DBE61AE0CBB2
3D22019D7DEB209BFB3A7372FF1D0D35548EA42076462610942A6C4AA933F979
82C94076695C510402CCA68ADD75FC6AEE60B2A66C9F0AEDE35BD066A499FC29
26251DFFF9E32AA6F46E2A94E79C8D71F8A95F45F854354D7ED338BB4353A40C
B0B7842C949B622F91E639091FCF3202C6FA958B8B4687198CBFFA00BF1D388F
98B3B730A14743746FA63E7F89EB76DBC48EE8B3602F69A4E61643AF4A858370
A7FC11878DE30211FCD95F79D294C749293090A3E95E7334D0EFF440CEDF7A4A
0CFFB6A859CAE6B1DBC31310E4570739D9390466EEBF5588EA51E3E8803082F2
15B550C67EDA0DCD3FDAF65CC0340692A3861E676663EEA693D87DF21AE2E674
B77E2043D9EE0EB48F6E12940F0CBB0F9C4FC7907537317B400BF46856458C50
6C39721953571FC68ABE65D1A6E6333035CEC5A0712B0BEC2B6502258F0A71D4
13070EF7F7AB0E9F5AA5458BEFC0F61057A41E4C8ED0894ABC459AF3BCC8ABE1
6092803A654D4ED3D608D11B04FAF4BE8D71F8FC6D0C5A162EC6E36D053BCB09
3F38237F3C88B563DB534BE381E96B8F6175C405ABDFB7052CC7520EFA3A1C1F
F76E2C0261B4FAF1EE3F0FA560C6FA63F8F1BFFE16D7672C024ADFBAA425B3F1
5481A6E420318D8323C2A2E2D543C941AA37EF3F41CBA9DBF3154C7320A521AD
34B2DF78686EEFC9EBD6C11450DE86368D1C94741D9421679E60F8A6542C1EDC
0A9DBC2B9A0464EC3A7E0DE3C946FAAA570904D7D1DB982E04A57B0582B2B409
947CCDF3DF6A29727E183C869183ECAC81C995C6A322C396475BDC742E2B9923
CF8DCE456B162CC2DBFC208C22B87E1DD1C6E68D37162910E527D2622D3D4B99
8C4FE7C072ECBA99953C22A9ACFFFE108579A4B1839B5436002995174AADD794
55B1F8F61D5FABD1E7DBC3CF20A8B597307994684A47AA38367DC2A213094A95
3665F292DEA2026FDC4F47EB8FF3074C6B404A81008FD2B3B0605B3CF69FBE8E
23B365C06428DB92967C7815DAF43B587F32031F84A46105DD208E8637BFE97C
732248AB0DFB3E120B82DDD1A7A133342EA5A0294A9A697F590B288FCCEBA183
10500C668D511B64A1BCA0AF3FC358B21E14634079FF4EBAF1D3D7C461CDA876
685ABDA4CDFAE3F0BBB748AB2DA507B05DFD72B902C9DB2DACE4FC7092D8F8DF
62B16CB00F9555DE0248A93CBE17E37F89C5827FB7402FB2AFCD2584346587D6
BA70BAECECDC55A52351E94886A50E4A959AD23872FA2681E9372D244F60E606
A474F31E12984BB6C78BF07E0B3019CAD687E8F4D763658C1BA644D4C5DA31ED
D0986EA635ADC4FB8F26A7E2AD2FC331DB3F016FF9908354BA0F10DDD202CAC3
73BB1BE0530A664D2B509E67286D00691C5EB7990059B4ED34D68D698F7A958A
CBD65F5CF25DF45DB4179FBFD942D4A31220B556727E7E25D363FABA635839DC
1FCD6A94B20AA454DEE17377446ED3EC7E4DD1CFB7BA4959DC7C7768C59A3247
046D2881B2908303761FB4034A29725AD238371FA623605AA85D6072799DC96E
9A4F4F9B2D20A57D9C26C1E9B01109374D2B544049CD7168383E3D5045380C5E
158A19F2B57320DF4CF256E2B587E8BF701F26FB5FC6C857FC094A1F0B280F7D
D6DD043E2560D61ABD5116CA7322C85726685626DE93DFD7452763EBE14BB2F9
30DC3472A6E1DB81B5D1CFAF9A6220F9977C266D933D3F4906E86D5C6BE5CDDE
70026BA392C577F9B42E2D332D6B5B783CDAFBD4C653D29259D9BA48A6C1EFFF
CF82811F977E2CDE0B3B3A12988ED81B7306DDD542C991D35AA3A75C80F92003
ED3EB10F4C0E52E51C90093D1BC2D9C9C12A9069195958BA3D01074EDFB0B42D
194ADF18549A72516433B6F02C6D72BC1C9039460FD6E1F37730EC3BB2016757
230BDF12CA98CFBA09D8D480E935461ECAA445AFD904D2D084F365C55DC1BC3F
4F60CDE8766854B5846CFD71EC286BCAE9AF3741B7A6951401C9BFD9DA46229A
74AE9C62618F4D2AA03C108F40039439E258CE747D63D82786EFACFEFA13A493
33CBF5E8444AC991BCEFBD314904A54A9B5254AA119086A69CC0EC3063875D60
72131E44CEC8873D1B889393D3905F865A015282D2EF303645EDC5D64B7E5838
A8A56220F93A3E5A1587DED5A3D0CBB73D10D9C202CAE839DD74CDB20A306B8F
F953164A29BDC2FC1ACD81DC43CEC6346A15B85FD0871E325B1273F6B6C8085D
F8960FDA883410DB40F2DF7C73C9D11101CEF37BA9B6490D504624A07D4B2F1D
947AF75B4395E842E0F51F361DBF7F3D03E90CAB3E1D82EFBB13FD6D4F4CA27A
4D99C8E901900FFABC454D79D0CC9D7683D9C1BB02C6BE528F9EA842164086CB
D992C65006C4223B7533AA7ED610BBA672BE8DABE10658B329F93A38AFA7F7BC
3D489974128E257A92D7D0DC02CAA8D9AFE8E1530E669DB1F2509E314AAF9003
927F3982B336571E1251F94A27E192BCEF6FDFF343F39A256D02C9BF915BE218
9FEB498652854D6A0225D994813E5EA425B5C8CC7E1688CC50F120417A56B6C9
680F37DF4E6457EE3D94886E012AA1E49C156B51C8FCF9F68374749EB5CB2E30
9B4EDE8A760DCA6374B7BA74E28594012941D9368E4E7B3BBEDAE78C6B9A8EF8
A07B03138D2E6F5342243F5577DC83E1ED3200F757C8FB6E6A01E59C81CDD0BE
4179C560B2E73C86A0B265B3994BDFD6D530E9356F1CB9700743BF8DCA533FE5
2A72F238C564F686E364935EB4FAFDDCA03CFE454F5536A92994BAE63B93A0C8
52D051C93E053B3AFB04942A9BEF787DCE8A1C90D2053098C19FFE6537986DEB
97C3F0AE759501C92246744E004FC2F0E8D103D49E530F51B38251C4D9C96A13
CE9F1F12F49D48B3C74F8A4731F762806B4760AFB76CE779B912AEE8DDAA1A9A
D52C6515CC43E48DAE894CC6B5D4C7B29DE7B684EBF6E7F703F0DE3751791AD1
913CE875E3DBA3FB9C30BB4774F87C8E7DDEC36E9B742B35DF81D47C67D14199
4F45DBA41FD1D5856718DEB5BA7D850B915D4915BB979B6FB59AF214A9745B40
4A5AE93635E5DD6687D90D66F572EEB878332D7720594440C65920339A4E2015
B3B6B9A3B07B4B0C0EF4946DC2A5E69BF3BD354F6231B51B5DAF861C89C2AD81
304F9BC38C0C659FD6D5C9BB2F6A0033893C78F69263CFDD16530BDA3BCCC8CD
DAAC7F35B148B0532B9CA0B630245E7CB677EC9BCF278EA0B4D726155092A6CC
A0EF66897E4A3D841A8D01495DD08C6E3F37DF85E9A3707402EAAA83F2E4FC9E
B9026968CA1F66A0E71CFBC0541D25D4E92A909D481B7770852EC167660E0EEB
BB72CCBB81F8DCB83BA5CDD410C44C734025E1D896021C6B03BB2ADA0CC8604D
B424341E418D2BE2B55655B1213A0561D45CE74740C6B4DE8D54656DDA12D6EE
5FEE3C93274D999BE406657B09CA1CEDB3682C7D909A71B01A73E34CF5E64CDF
6147A787DAE6DB5E79AED1450C6597BB747577E8AA75A16BC3565CC1E6230F6D
1ED6B359517C3D443F5182D6858E253077947C21A16BFF34D91299800E04A598
E93447879F0347546A9ED5AD46CB60EAEC4D4E77E679347613943DFDFF0141BE
192195E11CF01D50D41FBAA9B1C525C310960673EDA5B7710C9F5908AA8711C8
087F0FCEC1975FF425BDF4B23532518CE8B04DC913963BE8427C2DBEA76BBCB5
28449F9C6823EC60127AF8D779F9A14CBBBE1B4E710349FD5FCF533919DAF2C8
6AFA1BDCCB7778D197F4D2CB1682B28BAF97DE29CE5DC45CE6F4CF8EA824D294
FF00280BE4EF275BC31384E321DA2B0D9E59911AB37408ADDEC294FA8FE9D5A3
ED3F2071AC40FE7EC2690D41ADD5A743EC3D7C1E41AD3CED8332AFDE596EB2EE
E045C39C95F921AF2FDA272287F243D80B9FFCFB1131E7BABDDEF6CB223C8916
072D5729E566982F9DF7C55EB883C28E0E68ED554676AED05082B22341C9B3AA
69159029FA7AA92EF7C79E43908F97FD504AB3D29AC407EA3BABE586D9D45484
EFB4ED62DE4A7B268E37178E069FB0FA08A6F46A88119DEBE6B93CCE8199BAF6
2866F46D6C736A4239795E4B96702E0DCF70C7532BDE799821665766F12A5F0C
A58A3AA369B59262863BB9C9C4E484EFC1147AF0F627DC44653A87CB74BE1E6E
4E181B5C5F4CACD58A60E4911A0696633ECDD7D7614D19D8AAB6488778AA301D
C281203FC050B6CA03941601AB46A327F53ED8643794DC17C895DBB092479E93
A8581A4ED88C29AF7A8B30FE3356D6DE512A3C0914878BAD1F1B883E0BE5A7C1
B32686254B82BCE846BB19FA4D7575665A7FD236C3BB7C4F126A95965FB28487
6227AE8A1579423D9A5516F38196707746AD7245C5F1DCB17F272D1DC72EA662
7BDC1534A8541C730734CF7552318E9CAF4ABFF941F7FA86FB7B24F90E56855F
1069218DABE9C6D7176E3B8DB2F47BE6E7166A0C654EEE54F294E00C65785EA1
340958350B08AD3FCE7E287982D409A4D5E66C3C61D78A06C6F2D3FE73229A7A
D5A83618F465043A35AC90A7952C7812A87A953D30AC536D7CB5F30C4E5FBA87
1F87FA2B3A96E7A7FC737C202A9628A208482958E36AEA630C586CB96409F797
F2824B1DE89A26F668A8A83C862822E106368FEB6031032FCFE0C6198BF7484B
B236DF3DAD0B8A1B4D9A2A17AF39E9B758BCD2B892C5B0A880D2C75304F82ACD
D1E140DFF0B80B796BBE8D0356CD4FB8A19D50F2C4FC03BF3C20563AE8F4E92E
AC1AD10635CABADB0D51FDF19B308D9A591EFAE3392FA7AF398AD35FF452742C
2F8D127DF6B6C93E0E7EFDE4F5C686EB9DB1EEB8C8F23396D69EA54993B697AD
B314C39225CA80B4B5360F4F019D499A68722F6F55E52DD87A1AC55D9CC4F226
C6C2F3CDB3562B5BDC454C389B1B905C56EC85BB22D8B7661977B13A882402CA
169ED47493A6A4F6FBCD9133ACD6F3AFCBA6A3903EF23CFCE885BC694A296055
EE84790278B55072D2FBDC2D2751979A98B7DAD522DBED1C4E5D4A1569AB4A92
E07B1344076520328EA09EB1FE38FE3083A81541B4410622E93A0706D4C498E0
BA6453395BBDDEBB6919F872C7197183AC5DB76487AB0592F7359B60192AC693
CEAE7EBFADB0F9D4949772270DA357C48879E58D855B01B63BBB36A964B50594
8BAFE4255F46FC106DB2904168D419B46BE689AC1C863207CE851D604DD23373
443C253B4E117985920356AD9DB0B5A5E0CC858D7236D0371E4EC18D07E962FC
7848A0A7A1BC5FA8F9FD2332191E459CD0D7A71A5EA566C296F3A383A886188B
2E46C7583BBF0722E727C12644C66532DCA308CC1204A63D404AE5242FEDAD1A
487E970BAAB5B73C5EA2A5EDC721164BB47002DAA2D078FC3A22403190BCBD36
EA220E27DD32999F328434659BE69E62BEFACC2CD3895DE52C4C672747E1C51F
3CA6124A7B733858E46E1627CE4F5D1BA79BF7DCA72A9AB0F16CA5BC1329F7B0
95E0E564AA59FF6A6A33924682888D7437E74279025292D12B6350B164110CEB
5CC7A2BC6F7625E21639408B739993DD3CF14E2990BC4F2E7E916DD48D64A396
2DE6AAAABC8BB7D330EEA743169A927B06D81C18D5B59E6220399D2168E60E6C
FDB0A349721B37DF01CDBD7450EA837CDF1D3DD3A24EBE5B3C4D145698A0E4B5
23A3495376520325CF4FB32434011BC6B517DE5D6E279C4CF6E19B4B0E8865E9
E456106061EF9135251BD677C9C0E6F57706B6A96928EFD703E7C593A854531A
03F041B7FA627E71F3F35BB1FB2C9686C4AB322F3EF8E5104A1573115EA67979
5F9396BC4FDA72412E0B699A27DE290592BF2BB7B8132FD152923CDFE1D283A2
B0BC455BE35182EAD3D80664E185113A35AA885E2DABA84A425B47F727E4C865
844E0A3294B5239AA0A4E63B83ECC90C6AC2B9F17625E8060E9B6EF8CEAF5FCF
C093A7BAFC1D5E4F9283320E1E4F46271F959DE7D23C352B47F8C3BB4A09AB27
7CFAF27DBCF74D2419E10D15F7E59DBDF150C42CB277FBEFB635B17CCF59245F
7F887104B4D2899524E18540DFFC2A5C36A49F939E7E1CEA27169552220C136B
66D692258B3A5B94778BCC8EEFFF4A1451DEB64067CDB6666C3B54F028A20AC8
6BF71E63E8375116AB4348DD53ACA1A5255A6C95C7F932DC425CBDFB48ACDC6B
1ED9C409749FAC3F86DF47B7550CE4E5BB8FB19EA04CB87C0F9BC73F8B19088D
4A244DE929346FBAE47E1351EEA411070E9D86DFBE9989475939BA3036AD2E47
87F377A2485376B66744879B5D5E4664C5307F11F46A7EC2D189B7306AC541B1
6A98DA8055F6BE0790F7BD69620711BDBE795CA0C5FA364AA4FF92FDA857C503
23BBD6B538BF6F7626E2744AAAA2119EDC80946E1007357F1F96840D36C0E47E
CA8BE414BCDBB1B658B64429903F93C357A75C31D97E4A293727F6B31EC28335
2E8FD7654CB87A5F982BB1E7EE500B912446C966F76B6635D4EED5057B70843C
6AEE8B9CFC5A239B4072F90153B70BEF9F272430BE4F2104A5B029494BA667EB
C6C0B51ADD50A21B0198262593E9CBE5C873170D4149366567B59A52128EC466
3B6BE15B2DE15FEFD9AC0C7B4E5E17537AF0CA60C14D94AFD1682CBC60D188E0
7A584EDA67BD15AF3837A9397A0356D1135FAD8C1B99001784FDD8A77535F1E2
64B1C1CBC2719E9A525BD277D13E31A78EB1FCCB976E566F6FC3F57EB6F18445
1E0CAF88B6CE0AF0C6AB43F423D83FA2B212AEDC17CEDCFA8396F934B6568790
84BDF0E5A420D869E4EEA94D872E89FD3C02CA2B617047390F07BEE95F5374F7
E4263C8CCAEB5C1E99DB034F092A3EB75E64F36F3C9842E03B501D5615F0AFA5
FDDFED3A233BF216129D4450D61241BE99669DE75A696456FB2C39829B6E179E
8FE9681EA06491E69C99D9BF193A342C8F6DB1973167E37131F991D22C3C3961
13E148CA5D9B6BFFD9929D27AE6216C1D2B34515D1595CAF62719166F03F3AB7
A31753319C344E48DC6511E9ADB4099784ED2E2F2A6F70074F2C27CD98484019
7B9D6AA4CAC875A48DBC317FCB29B17AAF3DD7CAC266C1900EB5B160EB49A105
CD67AB502B6CE7F35C51BBA60661714802DCA8C995029A39B5E10F7A087931A9
1AA5DDC4F8BFDCD065684C12D994042529C44CFDE0B7C690A323A108F1CE7F76
A23FBA3A4040D9A9651EA064E16E84C1DF46604CB706584ADE1B4FCA94DB3471
B9495EC7BE39F82292345C656A4E160F6A29B484241C48308A347CF2AD47F0A3
FD6A8334243BEEE7916D3068D90155C38CE6C2A601AFEBC31345599B964589D4
1DF72779E02E220352E9D8B62DE141865504214F91C3FEC064BD4324059FF0C8
0F7783D932AB4263CEA22D69CA74D29299468A526316BF22056B3811904253C6
3194B5F21EBAC606327BA75F5193AD64424D2592972821BED95F0D69253BF192
246C7E0C27BBD79E51A71FF624898CC1BCE6D4F0C33187349BDC829B6A84D7B2
9C499A36AFE5483281CC2F86BC8F4F35BB47D3420F52F3DD82BC6F822E330786
B84A0BD107017340860B99B99147A8F9CE0F28FFBF09DB5CECE8F174CBFFF4D0
357B2584A00C6CE98974ADC54CDFB2C25301723A44445C323AB5A859006581E4
BF6C2728837C3C2DD2213466EA522BD99BFAD701A550BEE80B2C90974F5C8B38
EB13C534FAB43DADD1BF3A31C553A3CB74A4FF7BFAE792F74D2FEE4360C3822D
F1D2FA7777FDFEFC31620AA4409E09273F72662E43781F3A28EFC30C4A4EC7E5
B06276EB4AEADFDDF4FB0BA02C90FC168632835EBCCC0787CFDFD5BFF3760643
C9DDFEDC27C3BEBFA42D79BCCF55BFBF00CA02C96F612833E9C50B1FF16C1292
96E4FC914C918A4B2F8E9BE7A69A41948074D1EF7750FF9B0552203685C71FD9
8FE1265C02F3897E3B4B8292B52503C89A916174D66F3BA200CA02C97F612839
D68DC1E4669C61CCD46F674B5EBA042637D54EFAF702200BE4798A042637E559
FA77DECE913C763127A8FEDDF855D06B5C20CF4BC44479662FB1CF183AF3D9A2
0A802C90E72DE6B39089CFFF07CC3702CACA45F2010000000049454E44AE4260
82}
ExplicitLeft = 508
ExplicitWidth = 165
ExplicitHeight = 68
end
object Label9: TLabel [9]
Left = 6
Top = 355
Width = 89
Height = 13
Caption = 'Min Columns Large'
end
object Label10: TLabel [10]
Left = 207
Top = 355
Width = 73
Height = 13
Caption = 'Use -1 for auto'
end
object Label11: TLabel [11]
Left = 6
Top = 382
Width = 98
Height = 13
Caption = 'Min Columns Medium'
end
object Label12: TLabel [12]
Left = 207
Top = 382
Width = 146
Height = 13
Caption = 'Use -1 for auto/defauilt height'
end
object Label13: TLabel [13]
Left = 6
Top = 408
Width = 102
Height = 13
Caption = 'Max Columns Medium'
end
object Label14: TLabel [14]
Left = 207
Top = 408
Width = 142
Height = 13
Caption = 'Use -1 for auto/defauilt width'
end
object Label15: TLabel [15]
Left = 6
Top = 435
Width = 63
Height = 13
Caption = 'Max Columns'
end
object Label16: TLabel [16]
Left = 207
Top = 435
Width = 146
Height = 13
Caption = 'Use -1 for auto/defauilt height'
end
object Label17: TLabel [17]
Left = 6
Top = 461
Width = 49
Height = 13
Caption = 'Max Rows'
end
object Label18: TLabel [18]
Left = 207
Top = 461
Width = 142
Height = 13
Caption = 'Use -1 for auto/defauilt width'
end
object EditMinColumnsLarge: TEdit
Left = 120
Top = 352
Width = 65
Height = 21
Hint =
'Minimum number of columns that the gallery displays in Large gro' +
'up layout, before switching to Medium'
TabOrder = 10
Text = '-1'
OnChange = EditMinColumnsLargeChange
end
object UpDownMinColumnsLarge: TUpDown
Left = 185
Top = 352
Width = 16
Height = 21
Associate = EditMinColumnsLarge
Min = -1
Max = 999
Position = -1
TabOrder = 11
end
object EditMinColumnsMedium: TEdit
Left = 120
Top = 379
Width = 65
Height = 21
Hint =
'Minimum number of columns that the gallery displays in Medium gr' +
'oup layout, before switching to Small'
TabOrder = 12
Text = '-1'
OnChange = EditMinColumnsMediumChange
end
object UpDownMinColumnsMedium: TUpDown
Left = 185
Top = 379
Width = 16
Height = 21
Associate = EditMinColumnsMedium
Min = -1
Max = 999
Position = -1
TabOrder = 13
end
object EditMaxColumnsMedium: TEdit
Left = 120
Top = 405
Width = 65
Height = 21
Hint =
'Maximum number of columns that the gallery displays in Medium gr' +
'oup layout, before switching to Large'
TabOrder = 14
Text = '-1'
OnChange = EditMaxColumnsMediumChange
end
object UpDownMaxColumnsMedium: TUpDown
Left = 185
Top = 405
Width = 16
Height = 21
Associate = EditMaxColumnsMedium
Min = -1
Max = 999
Position = -1
TabOrder = 15
end
object EditMaxColumns: TEdit
Left = 120
Top = 432
Width = 65
Height = 21
Hint = 'Maximum number of columns that the gallery displays'
TabOrder = 16
Text = '-1'
OnChange = EditMaxColumnsChange
end
object UpDownMaxColumns: TUpDown
Left = 185
Top = 432
Width = 16
Height = 21
Associate = EditMaxColumns
Min = -1
Max = 999
Position = -1
TabOrder = 17
end
object EditMaxRows: TEdit
Left = 120
Top = 458
Width = 65
Height = 21
Hint = 'Maximum number of rows that the gallery displays'
TabOrder = 18
Text = '-1'
OnChange = EditMaxRowsChange
end
object UpDownMaxRows: TUpDown
Left = 185
Top = 458
Width = 16
Height = 21
Associate = EditMaxRows
Min = -1
Max = 999
Position = -1
TabOrder = 19
end
end
| 51.361055 | 75 | 0.835946 |
fcc1d22eff50f531af4fe23b72dab4ed735c943c | 60,695 | pas | Pascal | Source/ncSources.pas | azrael11/NetCom7 | 97bc205c9686d5d25c2dee127f6645813eb1c0e6 | [
"MIT"
]
| 2 | 2020-06-01T06:39:14.000Z | 2020-07-20T10:58:59.000Z | Source/ncSources.pas | azrael11/NetCom7 | 97bc205c9686d5d25c2dee127f6645813eb1c0e6 | [
"MIT"
]
| null | null | null | Source/ncSources.pas | azrael11/NetCom7 | 97bc205c9686d5d25c2dee127f6645813eb1c0e6 | [
"MIT"
]
| 1 | 2020-07-20T10:59:00.000Z | 2020-07-20T10:59:00.000Z | unit ncSources;
// To disable as much of RTTI as possible (Delphi 2009/2010),
// Note: There is a bug if $RTTI is used before the "unit <unitname>;" section of a unit, hence the position
{$IF CompilerVersion >= 21.0 }
{$WEAKLINKRTTI ON }
{$RTTI EXPLICIT METHODS([]) PROPERTIES([]) FIELDS([]) }
{$IFEND }
{$WARN SYMBOL_PLATFORM OFF}
interface
uses
Windows, Classes, SysUtils, SyncObjs, Math, WinSock, ncSockets, ncCompression, ZLib, ncEncryption, ncIntList,
ncThreads;
type
TncCommandType = (ctInitiator, ctResponse);
TncCommandDirection = (cdIncoming, cdOutgoing);
TCommandProcessorType = (cpReaderContextOnly, cpThreadPool);
const
MagicHeader: Integer = High(Integer) div 2;
DefPort = 17233;
DefCommandExecTimeout = 15000;
DefExecThreadPriority = tpNormal;
DefExecThreads = 10;
DefExecThreadsPerCPU = 0;
DefExecThreadsGrowUpto = 100;
DefCompression = zcFastest;
DefEncryption = etNoEncryption;
DefEncryptionKey = 'SetEncryptionKey';
DefEncryptOnHashedKey = True;
DefCommandProcessorType = cpThreadPool;
procedure WriteInteger(const aValue: Integer; var aBuffer: TBytes; var aBufLen: Integer); inline;
procedure WriteInt64(const aValue: Int64; var aBuffer: TBytes; var aBufLen: Integer); inline;
procedure WriteDouble(const aValue: Double; var aBuffer: TBytes; var aBufLen: Integer); inline;
procedure WriteSingle(const aValue: Single; var aBuffer: TBytes; var aBufLen: Integer); inline;
procedure WriteDate(const aValue: TDateTime; var aBuffer: TBytes; var aBufLen: Integer); inline;
procedure WriteCurrency(const aValue: Currency; var aBuffer: TBytes; var aBufLen: Integer); inline;
procedure WriteBool(const aValue: Boolean; var aBuffer: TBytes; var aBufLen: Integer); inline;
procedure WriteByte(const aValue: Byte; var aBuffer: TBytes; var aBufLen: Integer); inline;
procedure WriteBytes(const aValue: TBytes; var aBuffer: TBytes; var aBufLen: Integer); inline;
procedure WriteString(const aValue: string; var aBuffer: TBytes; var aBufLen: Integer); inline;
function ReadInteger(var aBuffer: TBytes; var aOfs: Integer): Integer; inline;
function ReadInt64(var aBuffer: TBytes; var aOfs: Integer): Int64; inline;
function ReadDouble(var aBuffer: TBytes; var aOfs: Integer): Double; inline;
function ReadSingle(var aBuffer: TBytes; var aOfs: Integer): Single; inline;
function ReadDate(var aBuffer: TBytes; var aOfs: Integer): TDateTime; inline;
function ReadCurrency(var aBuffer: TBytes; var aOfs: Integer): Currency; inline;
function ReadBool(var aBuffer: TBytes; var aOfs: Integer): Boolean; inline;
function ReadByte(var aBuffer: TBytes; var aOfs: Integer): Byte; inline;
function ReadBytes(var aBuffer: TBytes; var aOfs: Integer): TBytes; inline;
function ReadString(var aBuffer: TBytes; var aOfs: Integer): string; inline;
type
// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// TncCommand
TncCommand = record
public
CommandType: TncCommandType;
UniqueID: Integer;
Cmd: Integer;
Data: TBytes;
RequiresResult: Boolean;
AsyncExecute: Boolean;
PeerComponentHandler: string;
SourceComponentHandler: string;
ResultIsErrorString: Boolean;
procedure FromBytes(var aBytes: TBytes); inline;
function ToBytes: TBytes; inline;
end;
TncCommandData = class
public
function FromBytes(aBytes: TBytes): Integer; virtual;
function ToBytes: TBytes; virtual;
end;
{ Must put also this into the pending commands }
{ CommandTimeout: Cardinal;
Compression: TncCompressionLevel;
Encryption: TEncryptorType; EncryptionKey: AnsiString; EncryptOnHashedKey: Boolean;
}
// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// TncSourceLine
TncSourceLine = class(TncLine)
protected
MessageData, HeaderBytes: TBytes;
BytesToEndOfMessage: Integer;
protected
function CreateLineObject: TncLine; override;
public
constructor Create; overload; override;
end;
TPendingCommand = record
public
Line: TncSourceLine;
Command: TncCommand;
CommandEvent: TEvent;
end;
PPendingCommand = ^TPendingCommand;
TUnhandledCommand = record
public
Line: TncSourceLine;
Command: TncCommand;
end;
PUnhandledCommand = ^TUnhandledCommand;
TncOnSourceConnectDisconnect = procedure(Sender: TObject; aLine: TncSourceLine) of object;
TncOnSourceReconnected = procedure(Sender: TObject; aLine: TncSourceLine) of object;
TncOnSourceHandleCommand = function(Sender: TObject; aLine: TncSourceLine; aCmd: Integer; aData: TBytes; aRequiresResult: Boolean; const aSenderComponent, aReceiverComponent: string): TBytes of object;
TncOnAsyncExecCommandResult = procedure(Sender: TObject; aLine: TncSourceLine; aCmd: Integer; aResult: TBytes; aResultIsError: Boolean; const aSenderComponent, aReceiverComponent: string) of object;
IncCommandHandler = interface
['{22337701-9561-489A-8593-82EAA3B1B431}']
procedure Connected(aLine: TncSourceLine);
procedure Disconnected(aLine: TncSourceLine);
function GetComponentName: string;
function GetOnHandleCommand: TncOnSourceHandleCommand;
procedure SetOnHandleCommand(const Value: TncOnSourceHandleCommand);
property OnHandleCommand: TncOnSourceHandleCommand read GetOnHandleCommand write SetOnHandleCommand;
end;
// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// TncSourceBase
// Is the base for handling Exec and Handle command for the ServerSource and ClientSource
TncCommandProcessor = class; // forward declaration
TncSourceBase = class(TComponent)
private
FCommandExecTimeout: Cardinal;
FCommandProcessorThreadPriority: TThreadPriority;
FCommandProcessorThreads: Integer;
FCommandProcessorThreadsPerCPU: Integer;
FCommandProcessorThreadsGrowUpto: Integer;
FCommandProcessorType: TCommandProcessorType;
FCompression: TncCompressionLevel;
FEncryption: TEncryptorType;
FEncryptionKey: AnsiString;
FEncryptOnHashedKey: Boolean;
FOnConnected: TncOnSourceConnectDisconnect;
FOnDisconnected: TncOnSourceConnectDisconnect;
FOnHandleCommand: TncOnSourceHandleCommand;
FOnAsyncExecCommandResult: TncOnAsyncExecCommandResult;
// From socket
function GetActive: Boolean;
procedure SetActive(const Value: Boolean);
function GetKeepAlive: Boolean;
procedure SetKeepAlive(const Value: Boolean);
function GetNoDelay: Boolean;
procedure SetNoDelay(const Value: Boolean);
function GetPort: Integer;
procedure SetPort(const Value: Integer);
function GetReaderThreadPriority: TThreadPriority;
procedure SetReaderThreadPriority(const Value: TThreadPriority);
function GetReaderUseMainThread: Boolean;
procedure SetReaderUseMainThread(const Value: Boolean);
function GetOnConnected: TncOnSourceConnectDisconnect;
procedure SetOnConnected(const Value: TncOnSourceConnectDisconnect);
function GetOnDisconnected: TncOnSourceConnectDisconnect;
procedure SetOnDisconnected(const Value: TncOnSourceConnectDisconnect);
// Sources new functionality
function GetCommandExecTimeout: Cardinal;
procedure SetCommandExecTimeout(const Value: Cardinal);
function GetCommandProcessorPriority: TThreadPriority;
procedure SetCommandProcessorPriority(const Value: TThreadPriority);
function GetCommandProcessorThreads: Integer;
procedure SetCommandProcessorThreads(const Value: Integer);
function GetCommandProcessorThreadsPerCPU: Integer;
procedure SetCommandProcessorThreadsPerCPU(const Value: Integer);
function GetCommandProcessorThreadsGrowUpto: Integer;
procedure SetCommandProcessorThreadsGrowUpto(const Value: Integer);
function GetCommandProcessorType: TCommandProcessorType;
procedure SetCommandProcessorType(const Value: TCommandProcessorType);
function GetCompression: TncCompressionLevel;
procedure SetCompression(const Value: TncCompressionLevel);
function GetEncryption: TEncryptorType;
procedure SetEncryption(const Value: TEncryptorType);
function GetEncryptionKey: AnsiString;
procedure SetEncryptionKey(const Value: AnsiString);
function GetEncryptOnHashedKey: Boolean;
procedure SetEncryptOnHashedKey(const Value: Boolean);
function GetOnHandleCommand: TncOnSourceHandleCommand;
procedure SetOnHandleCommand(const Value: TncOnSourceHandleCommand);
private
CommandHandlers: array of IncCommandHandler;
UniqueSentID: Integer;
WasSetActive: Boolean;
procedure HandleCommand(aLine: TncSourceLine; var aUnpackedCommand: TncCommand);
function GetOnAsyncExecCommandResult: TncOnAsyncExecCommandResult;
procedure SetOnAsyncExecCommandResult(const Value: TncOnAsyncExecCommandResult);
protected
PropertyLock: TCriticalSection;
PendingCommands: TIntList;
PendingCommandsLock: TCriticalSection;
UnhandledCommands: TIntList;
UnhandledCommandsLock: TCriticalSection;
CommandProcessor: TncCommandProcessor;
Socket: TncTCPBase;
procedure Loaded; override;
procedure SocketConnected(Sender: TObject; aLine: TncLine);
procedure SocketDisconnected(Sender: TObject; aLine: TncLine);
procedure SocketReconnected(Sender: TObject; aLine: TncLine);
procedure SocketReadData(Sender: TObject; aLine: TncLine; const aBuf: TBytes; aBufCount: Integer);
procedure WriteMessage(aLine: TncSourceLine; const aBuf: TBytes); virtual;
procedure WriteCommand(aLine: TncSourceLine; const aCmd: TncCommand);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function ExecCommand(aLine: TncSourceLine; const aCmd: Integer; const aData: TBytes = nil; const aRequiresResult: Boolean = True; const aAsyncExecute: Boolean = False; const aPeerComponentHandler: string = ''; const aSourceComponentHandler: string = '')
: TBytes; overload; virtual;
procedure AddCommandHandler(aHandler: TComponent);
procedure RemoveCommandHandler(aHandler: TComponent);
procedure ProcessSocketEvents;
published
// From socket
property Active: Boolean read GetActive write SetActive default False;
property Port: Integer read GetPort write SetPort default DefPort;
property ReaderThreadPriority: TThreadPriority read GetReaderThreadPriority write SetReaderThreadPriority default DefReaderThreadPriority;
property ReaderUseMainThread: Boolean read GetReaderUseMainThread write SetReaderUseMainThread default False;
property NoDelay: Boolean read GetNoDelay write SetNoDelay default True;
property KeepAlive: Boolean read GetKeepAlive write SetKeepAlive default True;
// New properties for sources
property CommandExecTimeout: Cardinal read GetCommandExecTimeout write SetCommandExecTimeout default DefCommandExecTimeout;
property CommandProcessorThreadPriority: TThreadPriority read GetCommandProcessorPriority write SetCommandProcessorPriority default DefExecThreadPriority;
property CommandProcessorThreads: Integer read GetCommandProcessorThreads write SetCommandProcessorThreads default DefExecThreads;
property CommandProcessorThreadsPerCPU: Integer read GetCommandProcessorThreadsPerCPU write SetCommandProcessorThreadsPerCPU default DefExecThreadsPerCPU;
property CommandProcessorThreadsGrowUpto: Integer read GetCommandProcessorThreadsGrowUpto write SetCommandProcessorThreadsGrowUpto default DefExecThreadsGrowUpto;
property CommandProcessorType: TCommandProcessorType read GetCommandProcessorType write SetCommandProcessorType default DefCommandProcessorType;
property Compression: TncCompressionLevel read GetCompression write SetCompression default DefCompression;
property Encryption: TEncryptorType read GetEncryption write SetEncryption default DefEncryption;
property EncryptionKey: AnsiString read GetEncryptionKey write SetEncryptionKey;
property EncryptOnHashedKey: Boolean read GetEncryptOnHashedKey write SetEncryptOnHashedKey default DefEncryptOnHashedKey;
property OnConnected: TncOnSourceConnectDisconnect read GetOnConnected write SetOnConnected;
property OnDisconnected: TncOnSourceConnectDisconnect read GetOnDisconnected write SetOnDisconnected;
property OnHandleCommand: TncOnSourceHandleCommand read GetOnHandleCommand write SetOnHandleCommand;
property OnAsyncExecCommandResult: TncOnAsyncExecCommandResult read GetOnAsyncExecCommandResult write SetOnAsyncExecCommandResult;
end;
THandleCommandWorker = class(TncReadyThread)
public
OnHandleCommand: TncOnSourceHandleCommand;
Source: TncSourceBase;
Line: TncSourceLine;
UnpackedCommand: TncCommand;
procedure ProcessEvent; override;
end;
TncCommandProcessor = class(TncThreadPool)
public
procedure CompletePendingEventsForLine(aLine: TncLine);
end;
// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// TncClientSource
// Connects to a server source
TncClientSource = class(TncSourceBase)
private
FOnReconnected: TncOnSourceReconnected;
function GetHost: string;
procedure SetHost(const Value: string);
function GetReconnect: Boolean;
procedure SetReconnect(const Value: Boolean);
function GetReconnectInterval: Cardinal;
procedure SetReconnectInterval(const Value: Cardinal);
function GetOnReconnected: TncOnSourceReconnected;
procedure SetOnReconnected(const Value: TncOnSourceReconnected);
protected
procedure WriteMessage(aLine: TncSourceLine; const aBuf: TBytes); override;
function GetLine: TncLine;
public
SocketCnt: TncTCPClient;
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function ExecCommand(const aCmd: Integer; const aData: TBytes = nil; const aRequiresResult: Boolean = True; const aAsyncExecute: Boolean = False; const aPeerComponentHandler: string = ''; const aSourceComponentHandler: string = ''): TBytes; overload;
virtual;
published
property Line: TncLine read GetLine;
property Host: string read GetHost write SetHost;
property Reconnect: Boolean read GetReconnect write SetReconnect default True;
property ReconnectInterval: Cardinal read GetReconnectInterval write SetReconnectInterval default DefCntReconnectInterval;
property OnReconnected: TncOnSourceReconnected read GetOnReconnected write SetOnReconnected;
end;
// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// TncServerSource
TncServerSource = class(TncSourceBase)
private
protected
function GetLines: TThreadLineList;
public
SocketSrv: TncTCPServer;
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property Lines: TThreadLineList read GetLines;
end;
TBytesArray = array of TBytes;
function PackArray(const aString: string): TBytes; overload;
function PackArray(const aArray: TBytesArray): TBytes; overload;
function UnpackArray(const aBuffer: TBytes): TBytesArray;
implementation
type
TIntByteRec = packed record
case Integer of
0:
(Int: Integer);
1:
(Bytes: array [0 .. 3] of Byte);
end;
// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
{ TncCommand }
// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function ReadInteger(var aBuffer: TBytes; var aOfs: Integer): Integer; inline;
const
ResultCount = SizeOf(Result);
begin
move(aBuffer[aOfs], Result, ResultCount);
aOfs := aOfs + ResultCount;
end;
function ReadInt64(var aBuffer: TBytes; var aOfs: Integer): Int64; inline;
const
ResultCount = SizeOf(Result);
begin
move(aBuffer[aOfs], Result, ResultCount);
aOfs := aOfs + ResultCount;
end;
function ReadDouble(var aBuffer: TBytes; var aOfs: Integer): Double;
const
ResultCount = SizeOf(Result);
begin
move(aBuffer[aOfs], Result, ResultCount);
aOfs := aOfs + ResultCount;
end;
function ReadSingle(var aBuffer: TBytes; var aOfs: Integer): Single; inline;
const
ResultCount = SizeOf(Result);
begin
move(aBuffer[aOfs], Result, ResultCount);
aOfs := aOfs + ResultCount;
end;
function ReadDate(var aBuffer: TBytes; var aOfs: Integer): TDateTime; inline;
begin
Result := ReadDouble(aBuffer, aOfs);
end;
function ReadCurrency(var aBuffer: TBytes; var aOfs: Integer): Currency; inline;
begin
Result := ReadDouble(aBuffer, aOfs);
end;
function ReadBool(var aBuffer: TBytes; var aOfs: Integer): Boolean; inline;
const
ResultCount = SizeOf(Result);
begin
move(aBuffer[aOfs], Result, ResultCount);
aOfs := aOfs + ResultCount;
end;
function ReadByte(var aBuffer: TBytes; var aOfs: Integer): Byte; inline;
const
ResultCount = SizeOf(Result);
begin
move(aBuffer[aOfs], Result, ResultCount);
aOfs := aOfs + ResultCount;
end;
function ReadBytes(var aBuffer: TBytes; var aOfs: Integer): TBytes; inline;
var
ResultCount: Integer;
begin
ResultCount := ReadInteger(aBuffer, aOfs);
SetLength(Result, ResultCount);
if ResultCount > 0 then
begin
move(aBuffer[aOfs], Result[0], ResultCount);
aOfs := aOfs + ResultCount;
end;
end;
function ReadString(var aBuffer: TBytes; var aOfs: Integer): string; inline;
// var
// ResultCount: Integer;
// begin
// ResultCount := ReadInteger(aBuffer, aOfs);
// SetLength(Result, ResultCount div SizeOf (char));
//
// if ResultCount > 0 then
// begin
// move(aBuffer[aOfs], Result[1], ResultCount);
// aOfs := aOfs + ResultCount;
// end;
// end;
begin
Result := StringOf(ReadBytes(aBuffer, aOfs));
end;
procedure TncCommand.FromBytes(var aBytes: TBytes);
function ReadCommandType(var aBuffer: TBytes; var aOfs: Integer): TncCommandType; inline;
const
ResultCount = SizeOf(Result);
begin
move(aBuffer[aOfs], Result, ResultCount);
aOfs := aOfs + ResultCount;
end;
procedure CheckSig(var aBuffer: TBytes; var aOfs: Integer); inline;
begin
if not ReadBool(aBuffer, aOfs) then
raise Exception.Create('Improper message encoding');
if ReadBool(aBuffer, aOfs) then
raise Exception.Create('Improper message encoding');
if not ReadBool(aBuffer, aOfs) then
raise Exception.Create('Improper message encoding');
if ReadBool(aBuffer, aOfs) then
raise Exception.Create('Improper message encoding');
end;
var
Ofs: Integer;
begin
// Inline only works optimal when aBytes is a var parameter, so do not make it a const or by value
Ofs := 0;
CheckSig(aBytes, Ofs);
CommandType := ReadCommandType(aBytes, Ofs);
UniqueID := ReadInteger(aBytes, Ofs);
Cmd := ReadInteger(aBytes, Ofs);
Data := ReadBytes(aBytes, Ofs);
RequiresResult := ReadBool(aBytes, Ofs);
PeerComponentHandler := ReadString(aBytes, Ofs);
SourceComponentHandler := ReadString(aBytes, Ofs);
ResultIsErrorString := ReadBool(aBytes, Ofs);
CheckSig(aBytes, Ofs);
end;
procedure WriteInteger(const aValue: Integer; var aBuffer: TBytes; var aBufLen: Integer); inline;
const
ValByteCount = SizeOf(aValue);
begin
SetLength(aBuffer, aBufLen + ValByteCount);
move(aValue, aBuffer[aBufLen], ValByteCount);
aBufLen := aBufLen + ValByteCount;
end;
procedure WriteInt64(const aValue: Int64; var aBuffer: TBytes; var aBufLen: Integer); inline;
const
ValByteCount = SizeOf(aValue);
begin
SetLength(aBuffer, aBufLen + ValByteCount);
move(aValue, aBuffer[aBufLen], ValByteCount);
aBufLen := aBufLen + ValByteCount;
end;
procedure WriteDouble(const aValue: Double; var aBuffer: TBytes; var aBufLen: Integer);
const
ValByteCount = SizeOf(aValue);
begin
SetLength(aBuffer, aBufLen + ValByteCount);
move(aValue, aBuffer[aBufLen], ValByteCount);
aBufLen := aBufLen + ValByteCount;
end;
procedure WriteSingle(const aValue: Single; var aBuffer: TBytes; var aBufLen: Integer); inline;
const
ValByteCount = SizeOf(aValue);
begin
SetLength(aBuffer, aBufLen + ValByteCount);
move(aValue, aBuffer[aBufLen], ValByteCount);
aBufLen := aBufLen + ValByteCount;
end;
procedure WriteDate(const aValue: TDateTime; var aBuffer: TBytes; var aBufLen: Integer); inline;
begin
WriteDouble(aValue, aBuffer, aBufLen);
end;
procedure WriteCurrency(const aValue: Currency; var aBuffer: TBytes; var aBufLen: Integer); inline;
begin
WriteDouble(aValue, aBuffer, aBufLen);
end;
procedure WriteBool(const aValue: Boolean; var aBuffer: TBytes; var aBufLen: Integer); inline;
const
ValByteCount = SizeOf(aValue);
begin
SetLength(aBuffer, aBufLen + ValByteCount);
move(aValue, aBuffer[aBufLen], ValByteCount);
aBufLen := aBufLen + ValByteCount;
end;
procedure WriteByte(const aValue: Byte; var aBuffer: TBytes; var aBufLen: Integer); inline;
const
ValByteCount = SizeOf(aValue);
begin
SetLength(aBuffer, aBufLen + ValByteCount);
move(aValue, aBuffer[aBufLen], ValByteCount);
aBufLen := aBufLen + ValByteCount;
end;
procedure WriteBytes(const aValue: TBytes; var aBuffer: TBytes; var aBufLen: Integer); inline;
var
ValByteCount: Integer;
begin
ValByteCount := Length(aValue);
WriteInteger(ValByteCount, aBuffer, aBufLen);
if ValByteCount > 0 then
begin
SetLength(aBuffer, aBufLen + ValByteCount);
move(aValue[0], aBuffer[aBufLen], ValByteCount);
aBufLen := aBufLen + ValByteCount;
end;
end;
procedure WriteString(const aValue: string; var aBuffer: TBytes; var aBufLen: Integer); inline;
begin
WriteBytes(BytesOf(aValue), aBuffer, aBufLen);
end;
function TncCommand.ToBytes: TBytes;
procedure WriteCommandType(const aValue: TncCommandType; var aBuffer: TBytes; var aBufLen: Integer); inline;
const
ValByteCount = SizeOf(aValue);
begin
SetLength(aBuffer, aBufLen + ValByteCount);
move(aValue, aBuffer[aBufLen], ValByteCount);
aBufLen := aBufLen + ValByteCount;
end;
procedure CreateSig(var aBuffer: TBytes; var aBufLen: Integer); inline;
begin
WriteBool(True, aBuffer, aBufLen);
WriteBool(False, aBuffer, aBufLen);
WriteBool(True, aBuffer, aBufLen);
WriteBool(False, aBuffer, aBufLen);
end;
var
BufLen: Integer;
begin
// This is intended for the use of WriteMessageEmbeddedBufferLen
SetLength(Result, 0);
BufLen := 0;
CreateSig(Result, BufLen);
WriteCommandType(CommandType, Result, BufLen);
WriteInteger(UniqueID, Result, BufLen);
WriteInteger(Cmd, Result, BufLen);
WriteBytes(Data, Result, BufLen);
WriteBool(RequiresResult, Result, BufLen);
WriteString(PeerComponentHandler, Result, BufLen);
WriteString(SourceComponentHandler, Result, BufLen);
WriteBool(ResultIsErrorString, Result, BufLen);
CreateSig(Result, BufLen);
end;
{ TncCommandData }
function TncCommandData.FromBytes(aBytes: TBytes): Integer;
begin
Result := 0; // Has not read anything
end;
function TncCommandData.ToBytes: TBytes;
begin
SetLength(Result, 0);
end;
// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
{ TncSourceLine }
// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TncSourceLine.Create;
begin
inherited Create;
BytesToEndOfMessage := 0;
SetLength(HeaderBytes, 0);
end;
function TncSourceLine.CreateLineObject: TncLine;
begin
Result := TncSourceLine.Create; // Create its own kind of objects
end;
// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
{ TncSourceBase }
// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TncSourceBase.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
PropertyLock := TCriticalSection.Create;
PendingCommandsLock := TCriticalSection.Create;
PendingCommands := TIntList.Create;
PendingCommands.Sorted := True;
PendingCommands.Duplicates := dupIgnore;
UnhandledCommandsLock := TCriticalSection.Create;
UnhandledCommands := TIntList.Create;
UnhandledCommands.Sorted := True;
UnhandledCommands.Duplicates := dupIgnore;
Socket := nil;
WasSetActive := False;
UniqueSentID := Random( high(Integer) - 1); // for encryption purposes
FCommandExecTimeout := DefCommandExecTimeout;
FCommandProcessorThreadPriority := DefExecThreadPriority;
FCommandProcessorThreads := DefExecThreads;
FCommandProcessorThreadsPerCPU := DefExecThreadsPerCPU;
FCommandProcessorThreadsGrowUpto := DefExecThreadsGrowUpto;
FCommandProcessorType := DefCommandProcessorType;
FCompression := DefCompression;
FEncryption := DefEncryption;
FEncryptionKey := DefEncryptionKey;
FEncryptOnHashedKey := DefEncryptOnHashedKey;
FOnConnected := nil;
FOnDisconnected := nil;
FOnHandleCommand := nil;
FOnAsyncExecCommandResult := nil;
CommandProcessor := TncCommandProcessor.Create(THandleCommandWorker);
end;
destructor TncSourceBase.Destroy;
begin
UnhandledCommands.Free;
UnhandledCommandsLock.Free;
PendingCommands.Free;
PendingCommandsLock.Free;
PropertyLock.Free;
inherited Destroy;
CommandProcessor.Free;
end;
procedure TncSourceBase.Loaded;
begin
inherited Loaded;
if FCommandProcessorType = cpReaderContextOnly then
CommandProcessor.SetExecThreads(0, tpNormal)
else
begin
CommandProcessor.SetThreadPriority(FCommandProcessorThreadPriority);
CommandProcessor.SetExecThreads(Max(1, Max(FCommandProcessorThreads, GetNumberOfProcessors * FCommandProcessorThreadsPerCPU)), FCommandProcessorThreadPriority);
end;
if WasSetActive then
Socket.Active := True;
end;
procedure TncSourceBase.AddCommandHandler(aHandler: TComponent);
var
Handler: IncCommandHandler;
Len: Integer;
begin
if aHandler.GetInterface(IncCommandHandler, Handler) then
try
Len := Length(CommandHandlers);
SetLength(CommandHandlers, Len + 1);
CommandHandlers[Len] := Handler;
finally
Handler := nil;
end
else
raise Exception.Create('Cannot attach component, it does not suppoer the command handler interface');
end;
procedure TncSourceBase.RemoveCommandHandler(aHandler: TComponent);
var
Handler: IncCommandHandler;
i: Integer;
begin
if aHandler.GetInterface(IncCommandHandler, Handler) then
try
for i := 0 to High(CommandHandlers) do
if CommandHandlers[i] = Handler then
begin
CommandHandlers[i] := CommandHandlers[ High(CommandHandlers)];
CommandHandlers[ High(CommandHandlers)] := nil;
SetLength(CommandHandlers, Length(CommandHandlers) - 1);
Break;
end;
finally
Handler := nil;
end
end;
procedure TncSourceBase.ProcessSocketEvents;
begin
if ReaderUseMainThread or (CommandProcessorType = cpReaderContextOnly) then
if Socket is TncCustomTCPClient then
begin
TncCustomTCPClient(Socket).LineProcessor.SocketProcess;
end
else if Socket is TncCustomTCPServer then
begin
TncCustomTCPServer(Socket).LineProcessor.SocketProcess;
end;
end;
procedure TncSourceBase.SocketConnected(Sender: TObject; aLine: TncLine);
var
i: Integer;
begin
if Assigned(OnConnected) then
try
OnConnected(Sender, TncSourceLine(aLine));
except
end;
for i := 0 to High(CommandHandlers) do
try
CommandHandlers[i].Connected(TncSourceLine(aLine));
except
end;
end;
procedure TncSourceBase.SocketDisconnected(Sender: TObject; aLine: TncLine);
var
i: Integer;
begin
if Assigned(FOnDisconnected) then
try
OnDisconnected(Sender, TncSourceLine(aLine));
except
end;
for i := 0 to High(CommandHandlers) do
try
CommandHandlers[i].Disconnected(TncSourceLine(aLine));
except
end;
// Also inform all commands for the aLine, in the command processor, to terminate
CommandProcessor.CompletePendingEventsForLine(aLine);
end;
procedure TncSourceBase.SocketReconnected(Sender: TObject; aLine: TncLine);
begin
if Assigned(TncClientSource(Self).OnReconnected) then
TncClientSource(Self).OnReconnected(Sender, TncSourceLine(aLine));
end;
procedure TncSourceBase.HandleCommand(aLine: TncSourceLine; var aUnpackedCommand: TncCommand);
var
Worker: THandleCommandWorker;
i: Integer;
FoundComponent: IncCommandHandler;
begin
// Process command to be executed directly,
// or add it to the thread pool to process
aUnpackedCommand.ResultIsErrorString := False;
if CommandProcessorType = cpReaderContextOnly then
begin
// Handle the command directly
// or send to appropriate subcomponent
FoundComponent := nil;
for i := 0 to High(CommandHandlers) do
if CommandHandlers[i].GetComponentName = aUnpackedCommand.PeerComponentHandler then
begin
FoundComponent := CommandHandlers[i];
Break;
end;
if (Trim(aUnpackedCommand.PeerComponentHandler) = '') or (FoundComponent = nil) then
begin
if Assigned(OnHandleCommand) then
try
aUnpackedCommand.Data := OnHandleCommand(Self, aLine, aUnpackedCommand.Cmd, aUnpackedCommand.Data, aUnpackedCommand.RequiresResult, aUnpackedCommand.SourceComponentHandler, aUnpackedCommand.PeerComponentHandler);
aUnpackedCommand.ResultIsErrorString := False;
except
on E: Exception do
begin
aUnpackedCommand.ResultIsErrorString := True;
aUnpackedCommand.Data := BytesOf(E.ClassName + ' error: ' + E.Message);
end;
end
else
SetLength(aUnpackedCommand.Data, 0);
end
else
begin
if not Assigned(FoundComponent) then
begin
aUnpackedCommand.ResultIsErrorString := True;
aUnpackedCommand.Data := BytesOf('Error: Peer component ' + aUnpackedCommand.PeerComponentHandler + ' not found');
end
else
begin
if Assigned(FoundComponent.OnHandleCommand) then
try
aUnpackedCommand.Data := FoundComponent.OnHandleCommand(Self, aLine, aUnpackedCommand.Cmd, aUnpackedCommand.Data, aUnpackedCommand.RequiresResult, aUnpackedCommand.SourceComponentHandler, aUnpackedCommand.PeerComponentHandler);
aUnpackedCommand.ResultIsErrorString := False;
except
on E: Exception do
begin
aUnpackedCommand.ResultIsErrorString := True;
aUnpackedCommand.Data := BytesOf(E.ClassName + ' error: ' + E.Message);
end;
end
else
SetLength(aUnpackedCommand.Data, 0);
end;
end;
// Send the response
if aUnpackedCommand.RequiresResult then
begin
aUnpackedCommand.CommandType := ctResponse;
WriteCommand(aLine, aUnpackedCommand);
end;
end
else
begin
// Handle the command from the thread pool
Worker := (CommandProcessor.RequestReadyThread as THandleCommandWorker);
Worker.OnHandleCommand := OnHandleCommand;
Worker.Source := Self;
Worker.Line := aLine;
Worker.UnpackedCommand := aUnpackedCommand;
CommandProcessor.RunRequestedThread(Worker);
end;
end;
// Only from one thread called here, the reader thread, or the main vcl
procedure TncSourceBase.SocketReadData(Sender: TObject; aLine: TncLine; const aBuf: TBytes; aBufCount: Integer);
function LastPendingCommandIsOnLine (aLine: TncSourceLine): Boolean;
begin
Result := False;
if PendingCommands.Count > 0 then
Result := PPendingCommand(PendingCommands.Objects[PendingCommands.Count - 1])^.Line = aLine;
end;
var
Line: TncSourceLine;
Ofs: Integer;
BytesToRead: Integer;
MesLen: Integer;
UnpackedCommand: TPendingCommand;
PendingCommandsNdx: Integer;
tmpInt: Integer;
UnhandledCommand: ^TUnhandledCommand;
begin
// From SocketProcess from
Line := TncSourceLine(aLine);
Ofs := 0;
while Ofs < aBufCount do
begin
if Line.BytesToEndOfMessage > 0 then
begin
BytesToRead := Min(Line.BytesToEndOfMessage, aBufCount - Ofs);
// Add to MessageData, BytesToRead from aBuf [Ofs]
MesLen := Length(Line.MessageData);
SetLength(Line.MessageData, MesLen + BytesToRead);
move(aBuf[Ofs], Line.MessageData[MesLen], BytesToRead);
Ofs := Ofs + BytesToRead;
Line.BytesToEndOfMessage := Line.BytesToEndOfMessage - BytesToRead;
end;
if Line.BytesToEndOfMessage = 0 then
begin
if Length(Line.MessageData) > 0 then
try
try
// Get message data uncompressed and unencrypted
if Encryption <> etNoEncryption then
Line.MessageData := DecryptBytes(Line.MessageData, EncryptionKey, Encryption, EncryptOnHashedKey, False);
if Compression <> zcNone then
Line.MessageData := DecompressBytes(Line.MessageData);
// Get MessageData and convert it into a ncCommand
UnpackedCommand.Command.FromBytes(Line.MessageData);
case UnpackedCommand.Command.CommandType of
ctInitiator:
begin
PendingCommandsLock.Acquire;
try
if (PendingCommands.Count = 0) or LastPendingCommandIsOnLine (Line) then // if we are not ExecCommand'ed anything
// The peer is sending a command to be handled here
HandleCommand(Line, UnpackedCommand.Command)
else
begin
// Postpone HandleCommand until we are finished
New(UnhandledCommand);
UnhandledCommandsLock.Acquire;
try
UnhandledCommand^.Line := Line;
UnhandledCommand^.Command := UnpackedCommand.Command;
UnhandledCommands.AddObject(UnhandledCommand^.Command.UniqueID, TObject(UnhandledCommand));
finally
UnhandledCommandsLock.Release;
end;
end;
finally
PendingCommandsLock.Release;
end;
end;
ctResponse:
// We had requested a command, we got its response
begin
PendingCommandsLock.Acquire;
try
PendingCommandsNdx := PendingCommands.IndexOf(UnpackedCommand.Command.UniqueID);
if PendingCommandsNdx <> -1 then
with PPendingCommand(PendingCommands.Objects[PendingCommandsNdx])^ do
begin
if Command.AsyncExecute then
begin
try
if Assigned(OnAsyncExecCommandResult) then
OnAsyncExecCommandResult(Self,
Line,
Command.Cmd,
UnpackedCommand.Command.Data,
UnpackedCommand.Command.ResultIsErrorString,
UnpackedCommand.Command.SourceComponentHandler,
UnpackedCommand.Command.PeerComponentHandler);
finally
Dispose(PPendingCommand(PendingCommands.Objects[PendingCommandsNdx]));
PendingCommands.Delete(PendingCommandsNdx);
end;
end
else
begin
Command.Data := UnpackedCommand.Command.Data;
SetLength(UnpackedCommand.Command.Data, 0);
Command.ResultIsErrorString := UnpackedCommand.Command.ResultIsErrorString;
CommandEvent.SetEvent;
end;
end;
finally
PendingCommandsLock.Release;
end;
end;
end;
finally
// Dispose MessageData, we are complete
SetLength(Line.MessageData, 0);
end;
except
end;
// Read a character
if Ofs < aBufCount then
begin
if Length(Line.HeaderBytes) < SizeOf(Integer) * 2 then
begin
SetLength(Line.HeaderBytes, Length(Line.HeaderBytes) + 1);
Line.HeaderBytes[ High(Line.HeaderBytes)] := aBuf[Ofs];
Inc(Ofs);
end
else
begin
move(Line.HeaderBytes[0], tmpInt, SizeOf(Integer));
if tmpInt <> MagicHeader then
begin
SetLength(Line.HeaderBytes, 0);
Dec(Ofs, SizeOf(Integer) * 2 - 1);
end
else
begin
// If a whole integer is read, prepare to read next message
move(Line.HeaderBytes[SizeOf(Integer)], Line.BytesToEndOfMessage, SizeOf(Integer));
SetLength(Line.HeaderBytes, 0);
end;
end;
end;
end; // if Line.BytesToEndOfMessage = 0
end; // while Ofs < aBufCount
end;
procedure TncSourceBase.WriteMessage(aLine: TncSourceLine; const aBuf: TBytes);
var
FinalBuf: TBytes;
MsgByteCount: Integer;
HeaderBytes: Integer;
begin
FinalBuf := aBuf;
// Get message data compressed and encrypted
if Compression <> zcNone then
FinalBuf := CompressBytes(FinalBuf, Compression);
if Encryption <> etNoEncryption then
FinalBuf := EncryptBytes(FinalBuf, EncryptionKey, Encryption, EncryptOnHashedKey, False);
MsgByteCount := Length(FinalBuf);
// Send 4 bytes of header, and 4 bytes how long the message will be
HeaderBytes := SizeOf(Integer) + SizeOf(MsgByteCount);
SetLength(FinalBuf, MsgByteCount + HeaderBytes);
move(FinalBuf[0], FinalBuf[HeaderBytes], MsgByteCount); // Shift everything 4 + 4 bytes right
move(MagicHeader, FinalBuf[0], SizeOf(Integer)); // Write MagicHeader
move(MsgByteCount, FinalBuf[SizeOf(Integer)], SizeOf(MsgByteCount)); // Write ByteCount
aLine.Send(FinalBuf[0], Length(FinalBuf), 0);
end;
procedure TncSourceBase.WriteCommand(aLine: TncSourceLine; const aCmd: TncCommand);
begin
WriteMessage(aLine, aCmd.ToBytes);
end;
function TncSourceBase.ExecCommand(aLine: TncSourceLine; const aCmd: Integer; const aData: TBytes = nil; const aRequiresResult: Boolean = True; const aAsyncExecute: Boolean = False; const aPeerComponentHandler: string = '';
const aSourceComponentHandler: string = ''): TBytes;
var
PendingCommand: ^TPendingCommand;
PendingCommandNdx: Integer;
WaitTime: Integer;
TheCommand: PUnhandledCommand;
begin
try
New(PendingCommand);
try
PendingCommandsLock.Acquire;
try
PendingCommand^.Line := aLine;
with PendingCommand^.Command do
begin
CommandType := ctInitiator;
UniqueID := UniqueSentID;
UniqueSentID := UniqueSentID + 1;
UniqueSentID := UniqueSentID mod ( high(Integer) - 1);
Cmd := aCmd;
Data := aData;
RequiresResult := aRequiresResult;
AsyncExecute := aAsyncExecute;
PeerComponentHandler := aPeerComponentHandler;
if aSourceComponentHandler = '' then
SourceComponentHandler := Name
else
SourceComponentHandler := aSourceComponentHandler;
end;
if aRequiresResult or aAsyncExecute then
begin
if not aAsyncExecute then
PendingCommand^.CommandEvent := TEvent.Create;
// Add it to the list of pending commands, pass the address of the pending command record
PendingCommands.AddObject(PendingCommand^.Command.UniqueID, TObject(PendingCommand));
end;
finally
PendingCommandsLock.Release;
end;
try
WriteCommand(aLine, PendingCommand^.Command);
if aRequiresResult and not aAsyncExecute then
begin
// Wait for the command to come back
ProcessSocketEvents;
if ReaderUseMainThread or (CommandProcessorType = cpReaderContextOnly) then
WaitTime := 0
else
WaitTime := 100;
while PendingCommand.CommandEvent.WaitFor(WaitTime) <> wrSignaled do
begin
if not aLine.Active then
Abort;
ProcessSocketEvents;
if GetTickCount - aLine.LastReceived >= CommandExecTimeout then
raise Exception.Create('Command Execution Timeout');
end;
// Get the result of the command into the result of this function
with PendingCommand.Command do
begin
if ResultIsErrorString then
raise Exception.Create(StringOf(Data))
else
Result := Data;
end;
end;
finally
if aRequiresResult and not aAsyncExecute then
begin
PendingCommand.CommandEvent.Free;
PendingCommandsLock.Acquire;
try
PendingCommandNdx := PendingCommands.IndexOf(PendingCommand.Command.UniqueID);
if PendingCommandNdx <> -1 then
PendingCommands.Delete(PendingCommandNdx);
finally
PendingCommandsLock.Release;
end;
end;
end;
finally
if aRequiresResult and not aAsyncExecute then
Dispose(PendingCommand);
end;
finally
PendingCommandsLock.Acquire;
try
if PendingCommands.Count = 0 then
begin
UnhandledCommandsLock.Acquire;
try
while (UnhandledCommands.Count > 0) do
begin
TheCommand := PUnhandledCommand(UnhandledCommands.Objects[0]);
try
UnhandledCommands.Delete(0);
try
HandleCommand(TheCommand^.Line, TheCommand^.Command);
except
end;
finally
Dispose(TheCommand);
end;
end;
finally
UnhandledCommandsLock.Release;
end;
end;
finally
PendingCommandsLock.Release;
end;
end;
end;
function TncSourceBase.GetActive: Boolean;
begin
Result := Socket.Active;
end;
procedure TncSourceBase.SetActive(const Value: Boolean);
begin
if csLoading in ComponentState then
WasSetActive := Value
else
Socket.Active := Value;
end;
function TncSourceBase.GetKeepAlive: Boolean;
begin
Result := Socket.KeepAlive;
end;
procedure TncSourceBase.SetKeepAlive(const Value: Boolean);
begin
Socket.KeepAlive := Value;
end;
function TncSourceBase.GetNoDelay: Boolean;
begin
Result := Socket.NoDelay;
end;
procedure TncSourceBase.SetNoDelay(const Value: Boolean);
begin
Socket.NoDelay := Value;
end;
function TncSourceBase.GetPort: Integer;
begin
Result := Socket.Port;
end;
procedure TncSourceBase.SetPort(const Value: Integer);
begin
Socket.Port := Value;
end;
function TncSourceBase.GetReaderThreadPriority: TThreadPriority;
begin
Result := Socket.ReaderThreadPriority;
end;
procedure TncSourceBase.SetReaderThreadPriority(const Value: TThreadPriority);
begin
Socket.ReaderThreadPriority := Value;
end;
function TncSourceBase.GetReaderUseMainThread: Boolean;
begin
Result := Socket.ReaderUseMainThread;
end;
procedure TncSourceBase.SetReaderUseMainThread(const Value: Boolean);
begin
Socket.ReaderUseMainThread := Value;
end;
function TncSourceBase.GetCommandExecTimeout: Cardinal;
begin
PropertyLock.Acquire;
try
Result := FCommandExecTimeout;
finally
PropertyLock.Release;
end;
end;
procedure TncSourceBase.SetCommandExecTimeout(const Value: Cardinal);
begin
PropertyLock.Acquire;
try
FCommandExecTimeout := Value;
finally
PropertyLock.Release;
end;
end;
function TncSourceBase.GetCommandProcessorPriority: TThreadPriority;
begin
PropertyLock.Acquire;
try
Result := FCommandProcessorThreadPriority;
finally
PropertyLock.Release;
end;
end;
procedure TncSourceBase.SetCommandProcessorPriority(const Value: TThreadPriority);
begin
PropertyLock.Acquire;
try
FCommandProcessorThreadPriority := Value;
if not(csLoading in ComponentState) then
CommandProcessor.SetThreadPriority(Value);
finally
PropertyLock.Release;
end;
end;
function TncSourceBase.GetCommandProcessorThreads: Integer;
begin
PropertyLock.Acquire;
try
Result := FCommandProcessorThreads;
finally
PropertyLock.Release;
end;
end;
procedure TncSourceBase.SetCommandProcessorThreads(const Value: Integer);
begin
PropertyLock.Acquire;
try
FCommandProcessorThreads := Value;
if Value <> 0 then
FCommandProcessorThreadsPerCPU := 0;
if not(csLoading in ComponentState) then
if FCommandProcessorType = cpThreadPool then
CommandProcessor.SetExecThreads(Max(1, Max(FCommandProcessorThreads, GetNumberOfProcessors * FCommandProcessorThreadsPerCPU)), FCommandProcessorThreadPriority)
else
CommandProcessor.SetExecThreads(0, tpNormal);
finally
PropertyLock.Release;
end;
end;
function TncSourceBase.GetCommandProcessorThreadsPerCPU: Integer;
begin
PropertyLock.Acquire;
try
Result := FCommandProcessorThreadsPerCPU;
finally
PropertyLock.Release;
end;
end;
procedure TncSourceBase.SetCommandProcessorThreadsPerCPU(const Value: Integer);
begin
PropertyLock.Acquire;
try
FCommandProcessorThreadsPerCPU := Value;
if Value <> 0 then
FCommandProcessorThreads := 0;
if not(csLoading in ComponentState) then
if FCommandProcessorType = cpThreadPool then
CommandProcessor.SetExecThreads(Max(1, Max(FCommandProcessorThreads, GetNumberOfProcessors * FCommandProcessorThreadsPerCPU)), FCommandProcessorThreadPriority)
else
CommandProcessor.SetExecThreads(0, tpNormal);
finally
PropertyLock.Release;
end;
end;
function TncSourceBase.GetCommandProcessorThreadsGrowUpto: Integer;
begin
PropertyLock.Acquire;
try
Result := FCommandProcessorThreadsGrowUpto;
finally
PropertyLock.Release;
end;
end;
procedure TncSourceBase.SetCommandProcessorThreadsGrowUpto(const Value: Integer);
begin
PropertyLock.Acquire;
try
FCommandProcessorThreadsGrowUpto := Value;
CommandProcessor.GrowUpto := Value;
finally
PropertyLock.Release;
end;
end;
function TncSourceBase.GetCommandProcessorType: TCommandProcessorType;
begin
PropertyLock.Acquire;
try
Result := FCommandProcessorType;
finally
PropertyLock.Release;
end;
end;
procedure TncSourceBase.SetCommandProcessorType(const Value: TCommandProcessorType);
begin
PropertyLock.Acquire;
try
FCommandProcessorType := Value;
if not(csLoading in ComponentState) then
if Value = cpReaderContextOnly then
CommandProcessor.SetExecThreads(0, tpNormal)
else
CommandProcessor.SetExecThreads(Max(1, Max(FCommandProcessorThreads, GetNumberOfProcessors * FCommandProcessorThreadsPerCPU)), FCommandProcessorThreadPriority);
finally
PropertyLock.Release;
end;
end;
function TncSourceBase.GetCompression: TZCompressionLevel;
begin
PropertyLock.Acquire;
try
Result := FCompression;
finally
PropertyLock.Release;
end;
end;
procedure TncSourceBase.SetCompression(const Value: TZCompressionLevel);
begin
PropertyLock.Acquire;
try
FCompression := Value;
finally
PropertyLock.Release;
end;
end;
function TncSourceBase.GetEncryption: TEncryptorType;
begin
PropertyLock.Acquire;
try
Result := FEncryption;
finally
PropertyLock.Release;
end;
end;
procedure TncSourceBase.SetEncryption(const Value: TEncryptorType);
begin
PropertyLock.Acquire;
try
FEncryption := Value;
finally
PropertyLock.Release;
end;
end;
function TncSourceBase.GetEncryptionKey: AnsiString;
begin
PropertyLock.Acquire;
try
Result := FEncryptionKey;
finally
PropertyLock.Release;
end;
end;
procedure TncSourceBase.SetEncryptionKey(const Value: AnsiString);
begin
PropertyLock.Acquire;
try
FEncryptionKey := Value;
finally
PropertyLock.Release;
end;
end;
function TncSourceBase.GetEncryptOnHashedKey: Boolean;
begin
PropertyLock.Acquire;
try
Result := FEncryptOnHashedKey;
finally
PropertyLock.Release;
end;
end;
procedure TncSourceBase.SetEncryptOnHashedKey(const Value: Boolean);
begin
PropertyLock.Acquire;
try
FEncryptOnHashedKey := Value;
finally
PropertyLock.Release;
end;
end;
function TncSourceBase.GetOnConnected: TncOnSourceConnectDisconnect;
begin
PropertyLock.Acquire;
try
Result := FOnConnected;
finally
PropertyLock.Release;
end;
end;
procedure TncSourceBase.SetOnConnected(const Value: TncOnSourceConnectDisconnect);
begin
PropertyLock.Acquire;
try
FOnConnected := Value;
finally
PropertyLock.Release;
end;
end;
function TncSourceBase.GetOnDisconnected: TncOnSourceConnectDisconnect;
begin
PropertyLock.Acquire;
try
Result := FOnDisconnected;
finally
PropertyLock.Release;
end;
end;
procedure TncSourceBase.SetOnDisconnected(const Value: TncOnSourceConnectDisconnect);
begin
PropertyLock.Acquire;
try
FOnDisconnected := Value;
finally
PropertyLock.Release;
end;
end;
function TncSourceBase.GetOnHandleCommand: TncOnSourceHandleCommand;
begin
PropertyLock.Acquire;
try
Result := FOnHandleCommand;
finally
PropertyLock.Release;
end;
end;
procedure TncSourceBase.SetOnHandleCommand(const Value: TncOnSourceHandleCommand);
begin
PropertyLock.Acquire;
try
FOnHandleCommand := Value;
finally
PropertyLock.Release;
end;
end;
function TncSourceBase.GetOnAsyncExecCommandResult: TncOnAsyncExecCommandResult;
begin
PropertyLock.Acquire;
try
Result := FOnAsyncExecCommandResult;
finally
PropertyLock.Release;
end;
end;
procedure TncSourceBase.SetOnAsyncExecCommandResult(const Value: TncOnAsyncExecCommandResult);
begin
PropertyLock.Acquire;
try
FOnAsyncExecCommandResult := Value;
finally
PropertyLock.Release;
end;
end;
{ THandleCommandWorker }
procedure THandleCommandWorker.ProcessEvent;
var
i: Integer;
FoundComponent: IncCommandHandler;
begin
// TODO: Put here to also execute the new OnAsyncExecuteResult
FoundComponent := nil;
for i := 0 to High(Source.CommandHandlers) do
if Source.CommandHandlers[i].GetComponentName = UnpackedCommand.PeerComponentHandler then
begin
FoundComponent := Source.CommandHandlers[i];
Break;
end;
// Handle the command directly
UnpackedCommand.ResultIsErrorString := False;
if (Trim(UnpackedCommand.PeerComponentHandler) = '') or (FoundComponent = nil) then
begin
if Assigned(OnHandleCommand) then
try
UnpackedCommand.Data := OnHandleCommand(Self, Line, UnpackedCommand.Cmd, UnpackedCommand.Data, UnpackedCommand.RequiresResult, UnpackedCommand.SourceComponentHandler, UnpackedCommand.PeerComponentHandler);
UnpackedCommand.ResultIsErrorString := False;
except
on E: Exception do
begin
UnpackedCommand.ResultIsErrorString := True;
UnpackedCommand.Data := BytesOf(E.ClassName + ' error: ' + E.Message);
end;
end
else
SetLength(UnpackedCommand.Data, 0);
end
else
begin
// This does not apply anymore as it is redirected above
if not Assigned(FoundComponent) then
begin
UnpackedCommand.ResultIsErrorString := True;
UnpackedCommand.Data := BytesOf('Error: Peer component ' + UnpackedCommand.PeerComponentHandler + ' not found');
end
else
begin
if Assigned(FoundComponent.OnHandleCommand) then
try
UnpackedCommand.Data := FoundComponent.OnHandleCommand(Self, Line, UnpackedCommand.Cmd, UnpackedCommand.Data, UnpackedCommand.RequiresResult, UnpackedCommand.SourceComponentHandler, UnpackedCommand.PeerComponentHandler);
UnpackedCommand.ResultIsErrorString := False;
except
on E: Exception do
begin
UnpackedCommand.ResultIsErrorString := True;
UnpackedCommand.Data := BytesOf(E.ClassName + ' error: ' + E.Message);
end;
end
else
SetLength(UnpackedCommand.Data, 0);
end;
end;
// Send the response
if UnpackedCommand.RequiresResult then
begin
UnpackedCommand.CommandType := ctResponse;
Source.WriteCommand(Line, UnpackedCommand);
end;
end;
{ TncCommandProcessor }
procedure TncCommandProcessor.CompletePendingEventsForLine(aLine: TncLine);
var
i: Integer;
begin
Serialiser.Acquire;
try
for i := 0 to High(Threads) do
if THandleCommandWorker(Threads[i]).Line = aLine then // processing our line
Threads[i].ReadyEvent.WaitFor(Infinite); // It is still processing,
// wait until it is in ready state again
finally
Serialiser.Release;
end;
end;
// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
{ TncClientSource }
// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
type
TncTCPClientSourceLine = class(TncTCPClient)
protected
function CreateLineObject: TncLine; override;
end;
function TncTCPClientSourceLine.CreateLineObject: TncLine;
begin
Result := TncSourceLine.Create;
end;
constructor TncClientSource.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FOnReconnected := nil;
Socket := TncTCPClientSourceLine.Create(nil);
SocketCnt := TncTCPClientSourceLine(Socket); // just a reference so that we don't type cast all the time
Socket.Port := DefPort;
Socket.OnConnected := SocketConnected;
Socket.OnDisconnected := SocketDisconnected;
Socket.OnReadData := SocketReadData;
TncTCPClient(Socket).OnReconnected := SocketReconnected;
end;
destructor TncClientSource.Destroy;
begin
Socket.Free;
inherited Destroy;
end;
function TncClientSource.GetLine: TncLine;
begin
Result := SocketCnt.DataSocket;
end;
procedure TncClientSource.WriteMessage(aLine: TncSourceLine; const aBuf: TBytes);
begin
Active := True;
inherited WriteMessage(aLine, aBuf);
end;
function TncClientSource.ExecCommand(const aCmd: Integer; const aData: TBytes = nil; const aRequiresResult: Boolean = True; const aAsyncExecute: Boolean = False; const aPeerComponentHandler: string = ''; const aSourceComponentHandler: string = ''): TBytes;
begin
if not Active then
Active := True;
Result := ExecCommand(GetLine as TncSourceLine, aCmd, aData, aRequiresResult, aAsyncExecute, aPeerComponentHandler, aSourceComponentHandler);
end;
function TncClientSource.GetHost: string;
begin
Result := TncTCPClient(Socket).Host;
end;
procedure TncClientSource.SetHost(const Value: string);
begin
TncTCPClient(Socket).Host := Value;
end;
function TncClientSource.GetReconnect: Boolean;
begin
Result := TncTCPClient(Socket).Reconnect;
end;
procedure TncClientSource.SetReconnect(const Value: Boolean);
begin
TncTCPClient(Socket).Reconnect := Value;
end;
function TncClientSource.GetReconnectInterval: Cardinal;
begin
Result := TncTCPClient(Socket).ReconnectInterval;
end;
procedure TncClientSource.SetReconnectInterval(const Value: Cardinal);
begin
TncTCPClient(Socket).ReconnectInterval := Value;
end;
function TncClientSource.GetOnReconnected: TncOnSourceReconnected;
begin
PropertyLock.Acquire;
try
Result := FOnReconnected;
finally
PropertyLock.Release;
end;
end;
procedure TncClientSource.SetOnReconnected(const Value: TncOnSourceReconnected);
begin
PropertyLock.Acquire;
try
FOnReconnected := Value;
finally
PropertyLock.Release;
end;
end;
// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
{ TncServerSource }
// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
type
TncTCPServerSourceLine = class(TncTCPServer)
protected
function CreateLineObject: TncLine; override;
end;
function TncTCPServerSourceLine.CreateLineObject: TncLine;
begin
Result := TncSourceLine.Create;
end;
constructor TncServerSource.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Socket := TncTCPServerSourceLine.Create(nil);
SocketSrv := TncTCPServerSourceLine(Socket); // just a reference so that we don't type cast all the time
Socket.Port := DefPort;
Socket.OnConnected := SocketConnected;
Socket.OnDisconnected := SocketDisconnected;
Socket.OnReadData := SocketReadData;
end;
destructor TncServerSource.Destroy;
begin
Socket.Free;
inherited Destroy;
end;
function TncServerSource.GetLines: TThreadLineList;
begin
Result := SocketSrv.DataSockets;
end;
function PackArray(const aString: string): TBytes; overload;
var
BytesArray: TBytesArray;
begin
SetLength(BytesArray, 1);
BytesArray[0] := BytesOf(aString);
Result := PackArray(BytesArray);
end;
function PackArray(const aArray: TBytesArray): TBytes; overload;
procedure WriteInteger(const aValue: Integer; var aBuffer: TBytes; var aBufLen: Integer); inline;
const
ValByteCount = SizeOf(aValue);
begin
SetLength(aBuffer, aBufLen + ValByteCount);
move(aValue, aBuffer[aBufLen], ValByteCount);
aBufLen := aBufLen + ValByteCount;
end;
procedure WriteBytes(const aValue: TBytes; var aBuffer: TBytes; var aBufLen: Integer); inline;
var
ValByteCount: Integer;
begin
ValByteCount := Length(aValue);
WriteInteger(ValByteCount, aBuffer, aBufLen);
if ValByteCount > 0 then
begin
SetLength(aBuffer, aBufLen + ValByteCount);
move(aValue[0], aBuffer[aBufLen], ValByteCount);
aBufLen := aBufLen + ValByteCount;
end;
end;
var
BufLen: Integer;
i: Integer;
begin
// This is intended for the use of WriteMessageEmbeddedBufferLen
SetLength(Result, 0);
BufLen := 0;
WriteInteger(Length(aArray), Result, BufLen);
for i := 0 to High(aArray) do
WriteBytes(aArray[i], Result, BufLen);
end;
function UnpackArray(const aBuffer: TBytes): TBytesArray;
function ReadInteger(const aBuffer: TBytes; var aOfs: Integer): Integer; inline;
const
ResultCount = SizeOf(Result);
begin
move(aBuffer[aOfs], Result, ResultCount);
aOfs := aOfs + ResultCount;
end;
function ReadBytes(const aBuffer: TBytes; var aOfs: Integer): TBytes; inline;
var
ResultCount: Integer;
begin
ResultCount := ReadInteger(aBuffer, aOfs);
SetLength(Result, ResultCount);
if ResultCount > 0 then
begin
move(aBuffer[aOfs], Result[0], ResultCount);
aOfs := aOfs + ResultCount;
end;
end;
var
Ofs: Integer;
i: Integer;
begin
// Inline only works optimal when aBytes is a var parameter, so do not make it a const or by value
Ofs := 0;
SetLength(Result, ReadInteger(aBuffer, Ofs));
for i := 0 to High(Result) do
Result[i] := ReadBytes(aBuffer, Ofs);
end;
end.
| 32.439872 | 258 | 0.682017 |
fcd57634ad1d353a7f6ce10623415d2e7b9de344 | 1,249 | pas | Pascal | FreePascal/UGrid.pas | BenediktMagnus/GameOfLife | 304c7a9bcf687f823ab918e28bee0afb646dc33d | [
"MIT"
]
| null | null | null | FreePascal/UGrid.pas | BenediktMagnus/GameOfLife | 304c7a9bcf687f823ab918e28bee0afb646dc33d | [
"MIT"
]
| null | null | null | FreePascal/UGrid.pas | BenediktMagnus/GameOfLife | 304c7a9bcf687f823ab918e28bee0afb646dc33d | [
"MIT"
]
| null | null | null | unit UGrid;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils;
type
TField = Array of Array of Boolean;
type
TGrid = class
protected
FField: TField;
FRows, FCols: UInt16;
function Neighbours (x, y: UInt16): Byte;
public
procedure SetSize (ARows, ACols: UInt16);
procedure Calculate;
property Field: TField read FField;
end;
implementation
procedure TGrid.SetSize (ARows, ACols: UInt16);
begin
SetLength(FField, 0, 0); //Delete the grid first.
SetLength(FField, ARows, ACols);
FRows := ARows;
FCols := ACols;
end;
procedure TGrid.Calculate;
var
x, y: UInt16;
LField: TField;
begin
SetLength(LField, FRows, FCols);
for x := 0 to FRows - 1 do
for y := 0 to FCols - 1 do
case Neighbours(x, y) of
0, 1, 4, 5, 6, 7, 8: LField[x, y] := false;
2: LField[x, y] := FField[x, y];
3: LField[x, y] := true;
end;
FField := LField;
end;
function TGrid.Neighbours (x, y: UInt16): Byte;
var
x1, y1: Int16;
begin
Result := 0;
for x1 := x - 1 to x + 1 do
for y1 := y - 1 to y + 1 do
if (x1 >= 0) and (x1 < FRows) and (y1 >= 0) and (y1 < FCols) and FField[x1, y1] then
Inc(Result);
if FField[x, y] then
Dec(Result);
end;
end.
| 17.591549 | 90 | 0.60048 |
6aa43107efa24b2d7ef4fe78c7ab2b420a980a00 | 17,156 | pas | Pascal | Desenvolvimento/fontes/operadora/backup/uprincipal.pas | Michel-Itapira/OpenTef | 98194e4069835a2ba92c2f5b6c90e58de43f3aaf | [
"MIT"
]
| 1 | 2022-03-23T11:38:00.000Z | 2022-03-23T11:38:00.000Z | Desenvolvimento/fontes/operadora/backup/uprincipal.pas | Michel-Itapira/OpenTef | 98194e4069835a2ba92c2f5b6c90e58de43f3aaf | [
"MIT"
]
| null | null | null | Desenvolvimento/fontes/operadora/backup/uprincipal.pas | Michel-Itapira/OpenTef | 98194e4069835a2ba92c2f5b6c90e58de43f3aaf | [
"MIT"
]
| null | null | null | unit uprincipal;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls, rxspin;
type
{ TForm1 }
TTransacaoStatus = (tsEfetivada, tsNegada, tsCancelada, tsProcessando, tsAguardandoComando, tsNaoLocalizada, tsInicializada, tsComErro, tsAbortada);
TServidorRecebimentoLib = function(VP_Codigo: integer; VP_Transmissao_ID, VP_DadosRecebidos: PChar; VP_IP: PChar; VP_ID: integer): integer; stdcall;
Tiniciarconexao = function(VP_ArquivoLog, VP_Chave, VP_IP_Caixa, VP_IP_Servico: PChar; VP_PortaCaixa, VP_PortaServico: integer;
VO_RetornoCaixa, VO_Retorno_Servico: TServidorRecebimentoLib): integer; stdcall;
Tfinalizaconexao = function(): integer; stdcall;
TResponde = function(VP_Transmissao_ID, VP_Mesagem: PChar; VP_ID: integer): integer; stdcall;
TTMensagemCreate = function(var VO_Mensagem: Pointer): integer; stdcall;
TTMensagemCarregaTags = function(VP_Mensagem: Pointer; VP_Dados: PChar): integer; stdcall;
TTMensagemComando = function(VP_Mensagem: Pointer): PChar; stdcall;
TTMensagemComandoDados = function(VP_Mensagem: Pointer): PChar; stdcall;
TTMensagemFree = procedure(VP_Mensagem: Pointer); stdcall;
TTMensagemaddtag = function(VP_Mensagem: Pointer; VP_Tag, VP_Dados: PChar): integer; stdcall;
TTMensagemaddcomando = function(VP_Mensagem: Pointer; VP_Tag, VP_Dados: PChar): integer; stdcall;
TTMensagemTagAsString = function(VP_Mensagem: Pointer): PChar; stdcall;
TTMensagemTagCount = function(VP_Mensagem: Pointer): integer; stdcall;
TTMensagemGetTag = function(VP_Mensagem: Pointer; VP_Tag: PChar; var VO_Dados: PChar): integer; stdcall;
TTMensagemGetTagIdx = function(VP_Mensagem: Pointer; VL_Idx: integer; var VO_Tag: PChar; var VO_Dados: PChar): integer; stdcall;
TTMensagemTagToStr = function(VP_Mensagem: Pointer; var VO_Dados: PChar): integer; stdcall;
TTMensagemLimpar = procedure(VP_Mensagem: Pointer); stdcall;
TDescriptaSenha3Des = function(VP_Wk, VP_pan, VP_Senha: ansistring): ansistring; stdcall;
TEncriptaSenha3Des = function(VP_Wk, VP_pan, VP_Senha: ansistring): ansistring; stdcall;
Twkc = function(): ansistring; stdcall;
Timk = function(): integer; stdcall;
TForm1 = class(TForm)
BInicializaDll: TButton;
BAtiva: TButton;
BDesativar: TButton;
EIPCaixa: TEdit;
EChave: TEdit;
EIPServico: TEdit;
Image1: TImage;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
EPortaCaixa: TRxSpinEdit;
EPortaServico: TRxSpinEdit;
Label5: TLabel;
procedure BAtivaClick(Sender: TObject);
procedure BDesativarClick(Sender: TObject);
procedure BInicializaDllClick(Sender: TObject);
private
public
end;
{ ThProcessaSolicitacoes }
ThProcessaSolicitacoes = class(TThread)
private
fVP_Transmissao_ID: string;
fVP_DadosRecebidos: string;
fIP: string;
fVP_ID: integer;
fVP_Retorno: TResponde;
protected
procedure Execute; override;
public
constructor Create(VP_Transmissao_ID, VP_DadosRecebidos, VP_IP: string; VP_ID: integer; VP_Retorno: TResponde);
end;
function ServidorRecebimentoCaixa(VP_Codigo: integer; VP_Transmissao_ID, VP_DadosRecebidos: PChar; VP_IP: PChar; VP_ID: integer): integer; stdcall;
function ServidorRecebimentoServico(VP_Codigo: integer; VP_Transmissao_ID, VP_DadosRecebidos: PChar; VP_IP: PChar; VP_ID: integer): integer; stdcall;
var
Form1: TForm1;
FMCom: THandle;
FKey: THandle;
finalizaconexao: Tfinalizaconexao;
iniciarconexao: Tiniciarconexao;
respondeservico, respondecaixa: TResponde;
F_MensagemCreate: TTMensagemcreate;
F_MensagemCarregaTags: TTMensagemCarregaTags;
F_MensagemComando: TTMensagemComando;
F_MensagemComandoDados: TTMensagemComandoDados;
F_MensagemFree: TTMensagemFree;
F_MensagemAddTag: TTMensagemaddtag;
F_MensagemAddComando: TTMensagemaddcomando;
F_MensagemTagAsString: TTMensagemTagAsString;
F_MensagemTagCount: TTMensagemTagCount;
F_MensagemGetTag: TTMensagemGetTag;
F_MensagemGetTagIdx: TTMensagemGetTagIdx;
F_MensagemTagToStr: TTMensagemTagToStr;
F_MensagemLimpar: TTMensagemLimpar;
F_Mensagem: Pointer;
F_DescriptaSenha3Des: TDescriptaSenha3Des;
F_EncriptaSenha3Des: TEncriptaSenha3Des;
F_Wk: Twkc;
F_Imk: Timk;
implementation
function ServidorRecebimentoCaixa(VP_Codigo: integer; VP_Transmissao_ID, VP_DadosRecebidos: PChar; VP_IP: PChar; VP_ID: integer): integer; stdcall;
begin
Result := VP_Codigo;
if Result <> 0 then exit;
ThProcessaSolicitacoes.Create(VP_Transmissao_ID, VP_DadosRecebidos, VP_IP, VP_ID, respondecaixa);
end;
function ServidorRecebimentoServico(VP_Codigo: integer; VP_Transmissao_ID, VP_DadosRecebidos: PChar; VP_IP: PChar; VP_ID: integer): integer; stdcall;
begin
Result := VP_Codigo;
if Result <> 0 then exit;
Result := 0;
ThProcessaSolicitacoes.Create(VP_Transmissao_ID, VP_DadosRecebidos, VP_IP, VP_ID, respondeservico);
end;
{$R *.lfm}
{ ThProcessaSolicitacoes }
procedure ThProcessaSolicitacoes.Execute;
var
VL_Erro: integer;
VL_Senha: PChar;
VL_Valor:PChar;
VL_Mensagem: Pointer;
VL_Mensagem_Dados: Pointer;
VL_Mensagem_Dados_Protegidos: Pointer;
VL_TagDados: PChar;
VL_Pan,VL_TK2: PChar;
VL_String: string;
VL_Stream:TMemoryStream;
procedure ImagemToStr(var Dados: string; Imagem: TImage);
var
Sm: TStringStream;
I: integer;
S: string;
begin
Dados:='';
Sm := TStringStream.Create('');
Imagem.Picture.SaveToStream(Sm);
S := sm.DataString;
for i := 0 to Length(S) -1 do
Dados := Dados + HexStr(Ord(S[i+1]), 2);
Sm.Free;
end;
begin
try
VL_Mensagem := nil;
VL_Mensagem_Dados := nil;
VL_Mensagem_Dados_Protegidos:=nil;
F_MensagemCreate(VL_Mensagem);
F_MensagemCreate(VL_Mensagem_Dados);
F_MensagemCreate(VL_Mensagem_Dados_Protegidos);
VL_Senha := '';
VL_TagDados := '';
VL_String := '';
VL_Valor:='';
VL_TK2:='';
vl_erro := F_MensagemCarregaTags(VL_Mensagem, PChar(fVP_DadosRecebidos));
if vl_erro <> 0 then
begin
end;
if ((F_MensagemComando(VL_Mensagem) = '00CD') and (F_MensagemComandoDados(VL_Mensagem) = 'S')) then // atualiza bins
begin
F_MensagemLimpar(VL_Mensagem);
F_MensagemAddComando(VL_Mensagem, '00CD', 'R');
F_MensagemAddTag(VL_Mensagem, '004D', PChar('0'));
F_MensagemAddTag(VL_Mensagem, '00CE', PChar('629867'));
VL_String := F_MensagemTagAsString(VL_Mensagem);
fVP_Retorno(PChar(fVP_Transmissao_ID), PChar(VL_String), fVP_ID);
Exit;
end;
if ((F_MensagemComando(VL_Mensagem) = '00CF') and (F_MensagemComandoDados(VL_Mensagem) = 'S')) then //MENU DE VENDA
begin
F_MensagemLimpar(VL_Mensagem);
F_MensagemAddComando(VL_Mensagem, '00CF', 'R'); // RETORNO VAZIO
F_MensagemAddTag(VL_Mensagem, '004D', PChar('0'));
F_MensagemAddTag(VL_Mensagem, '007D', PChar(''));
VL_String := F_MensagemTagAsString(VL_Mensagem);
fVP_Retorno(PChar(fVP_Transmissao_ID), PChar(VL_String), fVP_ID);
Exit;
end;
if ((F_MensagemComando(VL_Mensagem) = '00D4') and (F_MensagemComandoDados(VL_Mensagem) = 'S')) then // MENU DE OPERACAO
begin
F_MensagemLimpar(VL_Mensagem);
F_MensagemAddComando(VL_Mensagem, '00D4', 'R'); //renorno do comando
F_MensagemAddTag(VL_Mensagem, '004D', PChar('0')); //comando realizado com sucesso
F_MensagemAddComando(VL_Mensagem_Dados, '0018', PChar('R')); //renorno da lista de menu
F_MensagemAddTag(VL_Mensagem_Dados, '00D3', PChar('Cancela Venda')); //item do menu
F_MensagemAddTag(VL_Mensagem_Dados, 'FFD3', PChar('Cancela Plano')); //item do menu
VL_String := F_MensagemTagAsString(VL_Mensagem_Dados); //converte em string a mensagem
F_MensagemAddTag(VL_Mensagem, '007D', PChar(VL_String)); // coloca a mensagem na tag de mensagem
VL_String := F_MensagemTagAsString(VL_Mensagem); //converte em string a mensagem
fVP_Retorno(PChar(fVP_Transmissao_ID), PChar(VL_String), fVP_ID); // envia de volta o comando
Exit;
end;
if ((F_MensagemComando(VL_Mensagem) = '000A') and (F_MensagemComandoDados(VL_Mensagem) = 'S')) then // APROVACAO DA TRANSACAO
begin
VL_TagDados:='';
F_MensagemGetTag(VL_Mensagem, '007D', VL_TagDados);
if VL_TagDados<>'' then
F_MensagemCarregaTags(VL_Mensagem_Dados, VL_TagDados);
VL_TagDados:='';
F_MensagemGetTag(VL_Mensagem, '00E3', VL_TagDados);
if VL_TagDados<>'' then
F_MensagemCarregaTags(VL_Mensagem_Dados_Protegidos, VL_TagDados);
F_MensagemLimpar(VL_Mensagem_Dados);
F_MensagemAddTag(VL_Mensagem_Dados, PChar('00E3'), PChar('')); // solicita dados protegidos
VL_Pan := '6298671234567890123';
F_MensagemGetTag(VL_Mensagem_Dados_Protegidos, PChar('0060'), VL_Senha); // senha criptografada
F_MensagemGetTag(VL_Mensagem_Dados_Protegidos, PChar('004F'), VL_TK2); // tk2
// F_MensagemGetTag(VL_Mensagem_Dados, PChar('00D9'), VL_Pan); // pan nao enviado de proposito
F_MensagemGetTag(VL_Mensagem_Dados_Protegidos, PChar('0033'), VL_TagDados); // dados capturados
F_MensagemGetTag(VL_Mensagem_Dados_Protegidos, PChar('0013'), VL_Valor); // valordados capturados
if VL_Valor = '' then
begin
F_MensagemAddComando(VL_Mensagem_Dados, PChar('00E1'), PChar('S')); //solicita dados da venda
F_MensagemAddTag(VL_Mensagem_Dados, PChar('0013'), PChar('')); // solicita valor total da venda
VL_String := F_MensagemTagAsString(VL_Mensagem_Dados); //converte em string a mensagem
fVP_Retorno(PChar(fVP_Transmissao_ID), PChar(VL_String), fVP_ID); // envia de volta o comando
Exit;
end;
{ if VL_Senha = '' then
begin
// F_MensagemLimpar(VL_Mensagem_Dados);
F_MensagemAddComando(VL_Mensagem_Dados, PChar('005A'), PChar('S')); //solicita senha
F_MensagemAddTag(VL_Mensagem_Dados, PChar('005B'), PChar(IntToStr(F_Imk())));
F_MensagemAddTag(VL_Mensagem_Dados, PChar('005C'), PChar(' DIGITE A SENHA'));
F_MensagemAddTag(VL_Mensagem_Dados, PChar('005D'), PChar('4'));
F_MensagemAddTag(VL_Mensagem_Dados, PChar('005E'), PChar('8'));
F_MensagemAddTag(VL_Mensagem_Dados, PChar('005F'), PChar(F_Wk()));
F_MensagemAddTag(VL_Mensagem_Dados, PChar('00D9'), VL_Pan); // pan ficticio não precisa ser o cartão
VL_String := F_MensagemTagAsString(VL_Mensagem_Dados); //converte em string a mensagem
fVP_Retorno(PChar(fVP_Transmissao_ID), PChar(VL_String), fVP_ID); // envia de volta o comando
Exit;
end;
}
if VL_TagDados = '' then // exemplo de captura de dados
begin
F_MensagemLimpar(VL_Mensagem_Dados);
// INFORMA OS BOTOES DENTRO DA TAG DE COMANDO DO BOTAO 0018
F_MensagemAddComando(VL_Mensagem_Dados, '0000', 'S');
F_MensagemAddTag(VL_Mensagem_Dados, '002F', PChar('OK')); //BOTAO OK
VL_String := F_MensagemTagAsString(VL_Mensagem_Dados); //converte em string a mensagem
F_MensagemLimpar(VL_Mensagem_Dados);
F_MensagemAddComando(VL_Mensagem_Dados, PChar('002A'), PChar('S')); //solicita dados pdv
F_MensagemAddTag(VL_Mensagem_Dados, '00DA', PChar('INFORME O CPF')); //MENSAGEM A SER MOSTRADA
F_MensagemAddTag(VL_Mensagem_Dados, '00DD', PChar(VL_String)); //BOTOES A MOSTRAR
F_MensagemAddTag(VL_Mensagem_Dados, '0033', PChar('A')); //campo para capturar sem mascara
ImagemToStr(VL_String,Form1.Image1);
F_MensagemAddTag(VL_Mensagem_Dados, '002E', PChar(VL_String)); //campo para capturar sem mascara
VL_String := F_MensagemTagAsString(VL_Mensagem_Dados); //converte em string a mensagem
fVP_Retorno(PChar(fVP_Transmissao_ID), PChar(VL_String), fVP_ID); // envia de volta o comando
end
else
begin
// F_MensagemLimpar(VL_Mensagem_Dados);
VL_String :='Cartão:'+VL_TK2+#13+ 'Senha do cartão:' + F_DescriptaSenha3Des('', VL_Pan, VL_Senha) + #13 + 'CPF:' + VL_TagDados+#13+'Valor dos itens:'+VL_Valor;
F_MensagemAddComando(VL_Mensagem_Dados, PChar('002C'), PChar('S')); //MENSAGEM OPERADOR
F_MensagemAddTag(VL_Mensagem_Dados, '00DA', PChar(VL_String));
F_MensagemAddTag(VL_Mensagem_Dados, '004A', PChar(IntToStr(Ord(tsAbortada)))); // transacao obortada
VL_String := F_MensagemTagAsString(VL_Mensagem_Dados);
fVP_Retorno(PChar(fVP_Transmissao_ID), PChar(VL_String), fVP_ID); // envia de volta o comando
end;
Exit;
end;
F_MensagemLimpar(VL_Mensagem);
F_MensagemAddTag(VL_Mensagem, '00E3', PChar('')); //dados protegidos
F_MensagemAddComando(VL_Mensagem, '0018', PChar('S')); //renorno da lista de menu
F_MensagemAddTag(VL_Mensagem, '00D3', PChar('Cancela Venda')); //item do menu
F_MensagemAddTag(VL_Mensagem, 'FFD3', PChar('Cancela Plano')); //item do menu
VL_String := F_MensagemTagAsString(VL_Mensagem); //converte em string a mensagem
fVP_Retorno(PChar(fVP_Transmissao_ID), PChar(VL_String), fVP_ID); // envia de volta o comando
finally
F_MensagemFree(VL_Mensagem);
F_MensagemFree(VL_Mensagem_Dados);
F_MensagemFree(VL_Mensagem_Dados_Protegidos);
end;
end;
constructor ThProcessaSolicitacoes.Create(VP_Transmissao_ID, VP_DadosRecebidos, VP_IP: string; VP_ID: integer; VP_Retorno: TResponde);
begin
FreeOnTerminate := True;
fVP_Transmissao_ID := VP_Transmissao_ID;
fVP_DadosRecebidos := VP_DadosRecebidos;
fIP := VP_IP;
fVP_ID := VP_ID;
fVP_Retorno := VP_Retorno;
inherited Create(False);
end;
{ TForm1 }
procedure TForm1.BInicializaDllClick(Sender: TObject);
begin
FMCom := LoadLibrary(PChar(ExtractFilePath(ParamStr(0)) + '..\..\mcom_lib\win64\mcom_lib.dll'));
Pointer(finalizaconexao) := GetProcAddress(FMCom, 'finalizaconexao');
Pointer(iniciarconexao) := GetProcAddress(FMCom, 'iniciarconexao');
Pointer(respondecaixa) := GetProcAddress(FMCom, 'respondecaixa');
Pointer(respondeservico) := GetProcAddress(FMCom, 'respondeservico');
Pointer(F_MensagemCreate) := GetProcAddress(FMCom, 'mensagemcreate');
Pointer(F_MensagemCarregaTags) := GetProcAddress(FMCom, 'mensagemcarregatags');
Pointer(F_MensagemComando) := GetProcAddress(FMCom, 'mensagemcomando');
Pointer(F_MensagemComandoDados) := GetProcAddress(FMCom, 'mensagemcomandodados');
Pointer(F_MensagemFree) := GetProcAddress(FMCom, 'mensagemfree');
Pointer(F_Mensagemaddtag) := GetProcAddress(FMCom, 'mensagemaddtag');
Pointer(F_Mensagemaddcomando) := GetProcAddress(FMCom, 'mensagemaddcomando');
Pointer(F_MensagemTagAsString) := GetProcAddress(FMCom, 'mensagemtagasstring');
Pointer(F_MensagemTagCount) := GetProcAddress(FMCom, 'mensagemtagcount');
Pointer(F_MensagemGetTag) := GetProcAddress(FMCom, 'mensagemgettag');
Pointer(F_MensagemGetTagIdx) := GetProcAddress(FMCom, 'mensagemgettagidx');
Pointer(F_MensagemTagToStr) := GetProcAddress(FMCom, 'mensagemtagtostr');
Pointer(F_MensagemLimpar) := GetProcAddress(FMCom, 'mensagemlimpar');
FKey := LoadLibrary(PChar(ExtractFilePath(ParamStr(0)) + 'key_lib.dll'));
Pointer(F_DescriptaSenha3Des) := GetProcAddress(FKey, 'DescriptaSenha3Des');
Pointer(F_EncriptaSenha3Des) := GetProcAddress(FKey, 'EncriptaSenha3Des');
Pointer(F_Wk) := GetProcAddress(FKey, 'wkc');
Pointer(F_Imk) := GetProcAddress(FKey, 'imk');
end;
procedure TForm1.BDesativarClick(Sender: TObject);
begin
finalizaconexao;
end;
procedure TForm1.BAtivaClick(Sender: TObject);
begin
iniciarconexao(PChar(ExtractFilePath(ParamStr(0)) + 'operadora.log'), PChar(EChave.Text), PChar(EIPCaixa.Text), PChar(EIPServico.Text),
EPortaCaixa.AsInteger, EPortaServico.AsInteger, @ServidorRecebimentoCaixa, @ServidorRecebimentoServico);
end;
end.
| 40.654028 | 175 | 0.675391 |
fc229e62031c08ba7d3f856d640f86d8e9378d65 | 17,320 | pas | Pascal | HexConvert.pas | randydom/commonx | 2315f1acf41167bd77ba4d040b3f5b15a5c5b81a | [
"MIT"
]
| 1 | 2020-08-25T00:02:54.000Z | 2020-08-25T00:02:54.000Z | HexConvert.pas | jpluimers/commonx | c49e51b4edcc61b2b51e78590a5168d574b66282 | [
"MIT"
]
| null | null | null | HexConvert.pas | jpluimers/commonx | c49e51b4edcc61b2b51e78590a5168d574b66282 | [
"MIT"
]
| 1 | 2020-02-13T02:33:54.000Z | 2020-02-13T02:33:54.000Z | unit HexConvert;
interface
uses classes, stringx, typex, numbers, debug, helpers.stream, MultiBufferMemoryFileStream;
//Some Example Intel Hex LInes
//[len] [addr] [record type] [data] [checksum]
//:02 0000 04 8000 7A
//:20 4000 00 481FD70380004024EBCD404048261E26C048D70380003EFAC60CE0B083C9E3CD 99
//:02 0000 04 8006 74
//:20 0000 00 0000000000000000000000000000000000000000000000000000000000000000 E0
//:20 FFE0 00 00000000000000000000000000000000000000000000000000000000FB73C2E0 F1
//:04 0000 05 80004024 13
//:00 0000 01 FF
//Proposed Advanced Hex Type
//[len] [record type] {addr} [data] [checksum] [xor-sum]
//:02 04 0000 8000 7A 86
//:20 00 4000 481FD70380004024EBCD404048261E26C048D70380003EFAC60CE0B083C9E3CD 99 XS
//:02 04 0000 8006 74 80
//:20 00 0000 0000000000000000000000000000000000000000000000000000000000000000 E0 XS
//:20 00 FFE0 00000000000000000000000000000000000000000000000000000000FB73C2E0 F1 XS
//:04 05 0000 80004024 13 XS
//:00 01 FF XS
//Notes
// if high-bit is set on length, then length is actually a 15-bit integer, read one more byte, mask off high-bit. BIG endgia
//Record Type is Second, where it should be
type
THexLine = record
// recordtype
end;
function BinToHex(sFile: string; bytesPerLine: ni = 64): string;
function ConvertHex(sHexString: string; iMaxBytesPerLine: integer = 1024): string;
function ResizeHexLines(sHexString: string; iMaxBytesPerLine: integer): string;
function FindMemoryByte(sl: TStrings; addr: integer): byte;
function HexToLongHexLine(s: string): string;
procedure HextoLongHex(sl: TStrings);
function GetHexStartingAddress(s: string):integer;
function ReadHexFromString(s: string; iPos, iLength: integer): integer;
function ZReadHexFromString(s: string; iPosZeroBased, iLength: integer): integer;
function GetHexDataLength(s: string): integer;
function GetHexRecordType(s: string):integer;
function GetHexEndingAddress(s: string):integer;
function GetHexData(s: string): string;
function VerifyHexChecksum(s: string): boolean;
function IsLongLine(sLine: string): boolean;
function GetHexDataBytes(sLIne: string; idx:ni;iLen:ni): TDynByteArray;
function GetHexDataByte(sLine: string; idx:ni): byte;
function HexToZXHex(sIn: string; iMaxZeroPack: ni = 8192): string;
procedure CYACDtoBin(sInFile: string; sOutFile: string);
implementation
uses sysutils;
procedure CYACDtoBin(sInFile: string; sOutFile: string);
var
fs: TMultibufferMemoryFileStream;
c: byte;
t: ni;
s: string;
ac: ansichar;
idx: ni;
localbuf: array[0..4097] of byte;
localbufidx: ni;
procedure LocalFlush;
begin
stream_GuaranteeWrite(fs, @localbuf[0], localbufidx);
localbufidx := 0;
end;
procedure LocalWrite(c: byte);
begin
localbuf[localbufidx] := c;
inc(localbufidx);
if localbufidx = length(localbuf) then
LocalFlush;
end;
begin
localbufidx := 0;
fs := TMultibufferMemoryFileStream.create(sOutFile, fmCreate);
try
sInFile := LoadfileAsString(sInFile);
idx := 0;
setlength(s, length(sInFile));
for t:= 0 to length(sInFile)-1 do begin
ac := ansichar(sInFile[t]);
if (ac <> ansichar(':'))
and (ac <> ansichar(#13))
and (ac <> ansichar(#10))
then begin
s[idx] := sInFile[t];
inc(idx);
end;
end;
setlength(s, idx);
sInFile := s;
for t := 0 to (length(sInFile) div 2)-1 do begin
if (t and $2FF) = 0 then
Debug.Log('Convert:'+inttostr(t));
c := strtoint('$'+zcopy(sInFile, (t*2), 2));
LocalWrite(c);
// stream_GuaranteeWrite(fs, @c, 1);
// end;
end;
LocalFlush;
finally
fs.free;
end;
end;
function ReadHexFromString(s: string; iPos, iLength: integer): integer;
var
stemp: string;
begin
sTemp := copy(s, iPos, iLength);
result := strtoint('$'+sTemp);
end;
function ZReadHexFromString(s: string; iPosZeroBased, iLength: integer): integer;
begin
result := ReadHexFromString(s, STRZ+iPosZeroBased, iLength);
end;
function HexToLongHexLine(s: string): string;overload;
begin
result := '!00'+copy(s, 2, length(s));
end;
function GetHexDataLength(s: string): integer;
begin
if IsLongLIne(s) then
result := ReadHexFromString(s, 2, 4)
else
result := ReadHexFromString(s, 2, 2);
end;
function GetHexStartingAddress(s: string):integer;
begin
if IsLongLIne(s) then
result := ReadHexFromString(s,6,4)
else
result := ReadHexFromString(s,4,4)
end;
function GetHexRecordType(s: string):integer;
begin
if IsLongLIne(s) then
result := ReadHexFromString(s,10,2)
else
result := ReadHexFromString(s,8,2)
end;
function GetHexEndingAddress(s: string):integer;
begin
result := GetHexStartingAddress(s)+GetHexDataLength(s);
end;
function GetHexData(s: string): string;
begin
if IsLongLIne(s) then
result := zcopy(s, 12-1, GetHexDataLength(s)*2)
else
result := zcopy(s, 10-1, GetHexDataLength(s)*2);
end;
function AddCheckSum(sLine: string): string;
var
t: integer;
cs: integer;
begin
cs := 0;
for t:= STRZ to (length(sLine)-1)+STRZ do begin
if t mod 2 = 1 then continue;
inc(cs, ReadHexFromString(sLine, t, 2));
end;
cs := cs and 255;
cs := cs xor 255;
cs := cs +1;
cs := cs and 255;
result := sLine+inttohex(cs, 2);
end;
function CombineHexLines(sLine, sNextLine: string): string;
var
sData1, sData2: string;
begin
sData1 := GetHexData(sLine);
sData2 := GetHexData(sNextLine);
result := ':'+inttohex((length(sData1)+length(sData2)) div 2, 4)+
inttohex(GetHexStartingAddress(sLine),4)+
copy(sLine, 10, 2)+
sData1+
sData2;
result := Addchecksum(result);
end;
function ConvertHex(sHexString: string; iMaxBytesPerLine: integer = 1024): string;
var
slSource, slTarget: TStringList;
wStartAddr, wStarAddr2: word;
sThisLine, sNextLine: string;
sLine: string;
iLine: integer;
bIsLongHex: boolean;
function ShouldCommit(sLine, sNextLine: string): boolean;
var
bConsecutive: boolean;
iCombinedLength: integer;
iStart, iEnd: integer;
bDifferentTypes: boolean;
begin
if sLine = '' then begin
result := false;
exit;
end;
iStart := GetHexRecordType(sLine);
iEnd := GetHexRecordType(sNextLine);
bDifferentTypes := iStart <> iEnd;
iStart := GetHexEndingAddress(sLine);
iEnd := GetHexStartingAddress(sNextLine);
bConsecutive := iStart = iend ;
iCombinedLength := GetHexDataLength(sLine)+GetHexDataLength(sNextLine);
result := bDifferentTypes or (not bConsecutive) or (iCombinedLength > iMaxBytesPerLine);
end;
begin
slSource := TStringList.create;
slTarget := TStringList.create;
try
slSource.text := sHexString;
iLIne := 0;
//if we CAN combine the next line then combine it
repeat
sNextLine := HexToLongHexLine(slSource[iLine]);
bIsLongHex := true;
if iLine = slSource.count-1 then begin
if sLIne <> '' then
slTarget.Add(sLine);
slTarget.add(sNextLine);
break;
end;
//if the working line needs to be committed then
if ShouldCommit(sLine, sNextLine) then begin
//commit the working line to the target string list
slTarget.add(sLine);
//reset the working line to blank
if GetHexRecordType(sLine) = 01 then break;
sLine := '';
end else begin
//if sLine is blank
if sLine = '' then begin
//set working line to current line
sLine := sNextLine;
inc(iLine);
end else begin
sLine := CombineHexLines(sLine, sNextLine);
inc(iLine);
end;
end;
//if we're done then break
// if iLine = slSource.count then break;
until 2+2=5;
result := slTarget.Text;
finally
slSource.free;
slTarget.free;
end;
end;
function GetHexDataBytes(sLIne: string; idx:ni;iLen:ni): TDynByteArray;
var
t: ni;
begin
setlengtH(result, iLen);
for t:= 0 to iLen-1 do begin
result[t] := GetHexDataByte(sLine, t+idx);
end;
end;
function GetHexDataByte(sLine: string; idx:ni): byte;
var
bIsLongHex: boolean;
begin
bIsLongHex := zcopy(sLine,0,1)='!';
if bIsLongHex then
result := ReadHexFromString(sLine, (12+(idx*2))-1, 2)
else
result := ReadHexFromString(sLine, (10+(idx*2))-1, 2);
end;
function IsLongLine(sLine: string): boolean;
begin
if length(sLine) < 1 then
raise ECritical.create('blank line in hex');
result := zcopy(sLine, 0,1) = '!';
end;
function FindMemoryByte(sl: TStrings; addr: integer): byte;
var
t: integer;
iaddr: integer;
iaddr2: integer;
iLine: integer;
offset: int64;
iRecType: integer;
bIsLongHex: boolean;
datastart: integer;
begin
offset := 0;
iLine := -1;
bIsLongHex := zcopy(sl[0],0,1)='!';
try
for t:= 0 to sl.count-1 do begin
iRecType := GetHexRecordType(sl[t]);
if iRecType = 4 then begin
offset := ((GetHexDataByte(sl[t],0) shl 8)+GetHexDataByte(sl[t],1)) shl 16;
end;
iAddr := GetHexStartingAddress(sl[t]);
iaddr2 := GetHexEndingAddress(sl[t]);
if (addr >= iAddr) and (addr < iAddr2) then begin
iLine := t;
end;
end;
if iLine = -1 then begin
result := 255;
exit;
end else begin
iAddr := GetHexStartingAddress(sl[iLine]);
if bIsLongHex then
datastart := 12
else
datastart := 10;
result := ReadHexFromString(sl[iLine], datastart+((addr-iAddr)*2), 2);
end;
finally
end;
end;
procedure HextoLongHex(sl: TStrings);
var
t: integer;
begin
for t:= 0 to sl.count-1 do begin
sl[t] := HextoLongHexLine(sl[t]);
end;
end;
function VerifyHexChecksum(s: string): boolean;
var
t: integer;
check, cs, i: integer;
begin
result := true;
cs := 0;
for t:= 1 to length(s)-2 do begin
if (t mod 2) = 1 then continue;
i := ReadHexFromString(s, t, 2);
inc(cs,i);
end;
cs := cs and 255;
check := ReadHexFromString(s, length(s)-1, 2);
if (cs + check) and 255 <> 0 then
raise Exception.create('checksum invalid');
end;
function BytesToString(data: TDynByteArray): string;
var
t: ni;
begin
result := '';
for t:= low(data) to high(data) do begin
result := result + inttohex(data[t],2);
end;
end;
function ResizeHexLines(sHexString: string; iMaxBytesPerLine: integer): string;
var
slIn, slOut: TStringlist;
sLine: string;
iBytes: ni;
iRec: ni;
iOffSet: int64;
iLineAddr: int64;
iRemain: ni;
iCan,idx: ni;
data: TdynByteArray;
sOut: string;
t: ni;
begin
iOffset := 0;
slIn := TStringlist.create;
slOut := TStringlist.create;
try
slIn.text := sHexString;
for t:= 0 to slIn.count-1 do begin
sLine := slIn[t];
//get record type
iRec := GetHexRecordType(sLine);
if iRec = 04 then begin
iOffset := (GetHexDataByte(sLine, 0) shl 24)+(GetHexDataByte(sLIne, 1) shl 16);
slOut.Add(sLine);
continue;//there is no data in this line and its address is irrelevant
end;
if iRec = 05 then begin
slOut.Add(sLine);
continue;//there is no data in this line and its address is irrelevant
end;
if iRec = 01 then begin
slOut.Add(sLine);
continue;//there is no data in this line and its address is irrelevant
end;
iLineAddr := iOffset+GetHexStartingAddress(sLIne);
//determine number of bytes in the line
iBytes := GetHexDataLength(sLIne);
iRemain := iBytes;
idx := 0;
while iRemain > 0 do begin
iCan := lesserof(iRemain,8);
data := GetHexDataBytes(sLine, idx, iCan);
sOut := ':'+IntToHex(iCan,2)+inttohex(GetHexStartingAddress(sLine)+idx,4)+IntToHex(iRec,2);
sOut := sOut + bytestostring(data);
sOut := AddChecksum(sOut);
slOut.Add(sOut);
inc(idx, iCan);
dec(iRemain,iCan);
end;
end;
result := slOut.text;
finally
slin.free;
slout.free;
end;
end;
function IsAllZeros(sLine: string): boolean;
var
b: TDynbyteArray;
t: ni;
begin
result := false;
if GetHexRecordType(sLine) <> 0 then
exit;
if GetHexDataLength(sLine) = 0 then
exit;
b := GetHexDataBytes(sLIne, 0, GetHexDataLength(sLIne));
for t := 0 to high(b) do begin
if b[t] <> 0 then
exit;
end;
//if we make it here... we're all ZEROS
result := true;
end;
function BinToHex(sFile: string; bytesPerLine: ni): string;
//converts CYACD to standard intel hex file (NOT LONG HEX)
var
fs: TFileStream;
sLine: string;
a: array of byte;
t: ni;
addr: int64;
distToBoundary: int64;
lastsegment: int64;
segment: int64;
begin
//CYACD (IN)
//(SKIP FIRSTLINE)
//[ArrayID -1 byte] [RowNumber-2 bytes][Data Len-2bytes][Data][Checksum 1-byte]
//INTEL HEX (OUT)
//[len] [addr 2-bytes] [record type] [data] [checksum]
addr := 0;
lastSegment := -1;
segment := -1;
fs := TFileStream.create(sFile, fmOpenRead+fmShareDenyNone);
try
while fs.position < fs.size do begin
disttoboundary := $10000 - (addr and ($FFFF));
lastSegMent := segment;
segment := addr shr 16;
//IF THE SEGMENT ADDRESS CHANGED, ADD A SEGMENT RECORD
if segment <> lastSegment then begin
sLIne := AddCheckSum(':02000004'+inttohex(segment, 4));
result := result + sLine+NEWLINE;
end;
setlength(a, lesserof(distToBoundary, lesserof(bytesPerLine, fs.size-fs.position)));
t := 0;
stream_GuaranteeRead(fs, @a[0], length(a));
sLine := ':'+
IntToHex(length(a),2)+//LEN
IntToHex(addr and $ffff,4)+//ADDR (note, use segment addressing for higher addresses)
'00'+//Record type 0 = data
MemoryToString(@a[0], length(a));
sLine := AddCheckSum(sLine);
result := result + (sLine+NEWLINE);
inc(addr, length(a));
end;
sLine := ':00000001FF';//end of file
result := result + sLine+NEWLINE;
finally
fs.free;
end;
end;
function HexToZXHex(sIn: string; iMaxZeroPack: ni = 8192): string;
//WHAT IS A ZXHEX!?
//-- adds new line-type to hex file, 0x80 record type indicates a bunch of 0s
type
TZeros = record
startaddr: int64;
count: int64;
end;
var
t: ni;
slOut, slIn: TStringlist;
sPreviousLIne,sLIne: string;
prevaddr, prevlen: int64;
prevtype: ni;
thisaddr: int64;
len: int64;
rectype: ni;
sOutLine: string;
bCanMerge: boolean;
segment: int64;
b: TDynByteArray;
z: TZeros;
procedure CommitZeros;
var
ii,bbb,bct,bc: ni;
begin
//commit zeros if there are some
if (z.startaddr>=0) then begin
if z.count < 256 then
bc := 1
else
if z.count > 65535 then
bc := 3
else
bc := 2;
setlength(b, 4+bc);
b[0] := bc;
b[1] := (z.startaddr shr 8) and $ff;//addr seg offset
b[2] := (z.startaddr shr 0) and $ff;//addr seg offset
b[3] := $0A;//record type
for bct := bc-1 downto 0 do begin
ii := 4+((bc-1)-bct);
bbb := (z.count shr (8*(bct))) and $ff;
b[ii] := bbb;
end;
slOut.add(AddCheckSum(':'+MemoryToString(b)));
end;
z.startaddr := -1;
end;
begin
prevaddr := 0;
prevlen := 0;
prevtype := 0;
z.startaddr := -1;
z.count := 0;
bCanMerge := false;
slOut := Tstringlist.create;
try
slIn := STringToStringList(sIn);
try
for t:=0 to slIn.count-1 do
begin
//get the line
sLine := slIn[t];
rectype := GetHexRecordType(sLIne);
thisaddr := GetHexStartingAddress(sLIne);
len := GetHexDataLength(sLine);
if (thisaddr and $ffff) = $bfC0 then
debug.consolelog('here');
case rectype of
0:
begin
if not IsAllZeros(sLIne) then
begin
CommitZeros;
slOut.Add(sLine);//add as is
end else
begin
if (prevaddr+prevlen) <> thisaddr then begin
CommitZeros;
end;
if prevtype <> 0 then begin
CommitZeros;
end;
if z.count >= (2048*4) then begin
CommitZeros;
end;
//if we don't have a z, init
if z.startaddr < 0 then begin
z.startaddr := thisaddr;
z.count := 0;
end;
//update zeros
inc(z.count, len);
end;
end;
1:
begin
CommitZeros;
slOut.add(sLine);//add as is
end;
4:
begin
CommitZeros;
b := GetHexDataBytes(sLine, 0, 2);
segment := (b[0] shl 24) or (b[1] shl 16);
slOut.add(sLIne);//add as is
end;
end;
prevaddr := thisaddr;
prevlen := len;
prevtype := rectype;
end;
CommitZeros;
result:= slOut.text;
finally
slIn.free;
end;
result := slOUt.text;
finally
slOut.free;
end;
end;
end.
| 23.564626 | 124 | 0.617783 |
fcdd43885d9cafc2187df76e8362df7f54b77953 | 498 | pas | Pascal | 08-functions/Unit2.pas | kelfan/delphi-tutorials | 029df8e091e4bdc5e9fde7df9305492a1010b157 | [
"Apache-2.0"
]
| null | null | null | 08-functions/Unit2.pas | kelfan/delphi-tutorials | 029df8e091e4bdc5e9fde7df9305492a1010b157 | [
"Apache-2.0"
]
| null | null | null | 08-functions/Unit2.pas | kelfan/delphi-tutorials | 029df8e091e4bdc5e9fde7df9305492a1010b157 | [
"Apache-2.0"
]
| null | null | null | unit Unit2;
interface
uses
Vcl.Dialogs, Winapi.Windows;
// functions accessed by other units, has be in interface and after use sentence
function add(x, y: Integer): Integer;
implementation
procedure test(msg: string);
begin
showmessage('[debug] ------' + msg + '-------')
end;
function multiply(x, y: Integer): Integer;
begin
result := x * y;
end;
function add(x, y: Integer): Integer;
begin
result := x + y;
if (x * y) = multiply(x, y) then
test('add function');
end;
end.
| 15.5625 | 80 | 0.654618 |
fc4d1632bc4337ec64704d75d937cf598e6eb2b2 | 6,468 | pas | Pascal | sources/MVCFramework.HMAC.pas | JensMertelmeyer/delphimvcframework | 1c9bcea41cbded5eacffeaab3275b9b9aa9761de | [
"Apache-2.0"
]
| 2 | 2021-01-08T21:38:09.000Z | 2021-12-16T07:41:17.000Z | sources/MVCFramework.HMAC.pas | JensMertelmeyer/delphimvcframework | 1c9bcea41cbded5eacffeaab3275b9b9aa9761de | [
"Apache-2.0"
]
| null | null | null | sources/MVCFramework.HMAC.pas | JensMertelmeyer/delphimvcframework | 1c9bcea41cbded5eacffeaab3275b9b9aa9761de | [
"Apache-2.0"
]
| 1 | 2020-03-22T15:06:54.000Z | 2020-03-22T15:06:54.000Z | // ***************************************************************************
//
// Delphi MVC Framework
//
// Copyright (c) 2010-2020 Daniele Teti and the DMVCFramework Team
//
// https://github.com/danieleteti/delphimvcframework
//
// ***************************************************************************
//
// Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// *************************************************************************** }
unit MVCFramework.HMAC;
interface
uses
System.SysUtils;
type
EMVCHMACException = class(Exception)
end;
IHMAC = interface
['{95134024-BBAF-4E52-A4C3-54189672E18A}']
function HashValue(const Input, key: string): TBytes;
end;
function HMAC(const Algorithm: string; const Input, Key: string): TBytes;
procedure RegisterHMACAlgorithm(const Algorithm: string; Impl: IHMAC);
procedure UnRegisterHMACAlgorithm(const Algorithm: string);
const
// registering based on hash function
HMAC_MD5 = 'md5';
HMAC_SHA1 = 'sha1';
HMAC_SHA224 = 'sha224';
HMAC_SHA256 = 'sha256';
HMAC_SHA384 = 'sha384';
HMAC_SHA512 = 'sha512';
// the same using the JWT naming
HMAC_HS256 = 'HS256';
HMAC_HS384 = 'HS384';
HMAC_HS512 = 'HS512';
{$IFDEF CONDITIONALEXPRESSIONS}
{$IF CompilerVersion >= 30.0}
{$DEFINE USEBUILTINHMAC}
{$ENDIF}
{$ENDIF}
implementation
uses
{$IFDEF USEBUILTINHMAC}
System.Hash,
{$ELSE}
IdHMAC, IdSSLOpenSSL, IdHash, IdGlobal, IdHMACMD5, IdHMACSHA1,
{$ENDIF}
System.Generics.Collections;
var
GHMACRegistry: TDictionary<string, IHMAC>;
type
{$IFDEF USEBUILTINHMAC}
TSHA2HMACWrapper = class(TInterfacedObject, IHMAC)
private
FHMACType : THashSHA2.TSHA2Version;
public
constructor Create(HMACType: THashSHA2.TSHA2Version);
function HashValue(const Input: string; const key: string): TBytes;
end;
TSHA1HMACWrapper = class(TInterfacedObject, IHMAC)
public
function HashValue(const Input: string; const key: string): TBytes;
end;
TMD5HMACWrapper = class(TInterfacedObject, IHMAC)
public
function HashValue(const Input: string; const key: string): TBytes;
end;
{$ELSE}
THMACClass = class of TIdHMAC;
TIdHMACWrapper = class(TInterfacedObject, IHMAC)
private
FClass: THMACClass;
public
constructor Create(IdClass: THMACClass);
function HashValue(const Input: string;
const key: string): System.TArray<System.Byte>;
end;
{ TIdHMACWrapper }
constructor TIdHMACWrapper.Create(IdClass: THMACClass);
begin
FClass := IdClass;
end;
function TIdHMACWrapper.HashValue(const Input,
key: string): System.TArray<System.Byte>;
var
lHMAC: TIdHMAC;
begin
Assert(IdSSLOpenSSL.LoadOpenSSLLibrary, 'HMAC requires OpenSSL libraries');
lHMAC := FClass.Create;
try
lHMAC.Key := ToBytes(Key, IndyTextEncoding_UTF8);
Result := TBytes(lHMAC.HashValue(ToBytes(Input, IndyTextEncoding_UTF8)));
finally
lHMAC.Free;
end;
end;
{$ENDIF}
function HMAC(const Algorithm: string; const Input, Key: string): TBytes;
begin
if not GHMACRegistry.ContainsKey(Algorithm) then
raise EMVCHMACException.CreateFmt('Unknown HMAC algorithm [%s]', [Algorithm]);
result := GHMACRegistry[Algorithm].HashValue(Input, Key);
end;
procedure RegisterHMACAlgorithm(const Algorithm: string; Impl: IHMAC);
begin
if GHMACRegistry.ContainsKey(Algorithm) then
raise EMVCHMACException.Create('Algorithm already registered');
GHMACRegistry.Add(Algorithm, Impl);
end;
procedure UnRegisterHMACAlgorithm(const Algorithm: string);
begin
GHMACRegistry.Remove(Algorithm);
end;
{ THMACSHA256 }
{$IFDEF USEBUILTINHMAC}
constructor TSHA2HMACWrapper.Create(HMACType: THashSHA2.TSHA2Version);
begin
FHMACType := HMACType;
end;
function TSHA2HMACWrapper.HashValue(const Input, key: string): TBytes;
begin
Result := THashSHA2.GetHMACAsBytes(Input,key,FHMACType);
end;
{ TSHA1HMACWrapper }
function TSHA1HMACWrapper.HashValue(const Input, key: string): TBytes;
begin
Result := THashSHA1.GetHMACAsBytes(Input,Key);
end;
{ TMD5HMACWrapper }
function TMD5HMACWrapper.HashValue(const Input, key: string): TBytes;
begin
Result := THashMD5.GetHMACAsBytes(Input,Key);
end;
procedure RegisterBuiltinHMACFunctions;
begin
RegisterHMACAlgorithm('md5', TMD5HMACWrapper.create);
RegisterHMACAlgorithm('sha1', TSHA1HMACWrapper.create);
RegisterHMACAlgorithm('sha224', TSHA2HMACWrapper.create(THashSHA2.TSHA2Version.SHA224));
RegisterHMACAlgorithm('sha256', TSHA2HMACWrapper.create(THashSHA2.TSHA2Version.SHA256));
RegisterHMACAlgorithm('sha384', TSHA2HMACWrapper.create(THashSHA2.TSHA2Version.SHA384));
RegisterHMACAlgorithm('sha512', TSHA2HMACWrapper.create(THashSHA2.TSHA2Version.SHA512));
// the same using the JWT naming
RegisterHMACAlgorithm('HS256', TSHA2HMACWrapper.create(THashSHA2.TSHA2Version.SHA256));
RegisterHMACAlgorithm('HS384', TSHA2HMACWrapper.create(THashSHA2.TSHA2Version.SHA384));
RegisterHMACAlgorithm('HS512', TSHA2HMACWrapper.create(THashSHA2.TSHA2Version.SHA512));
end;
{$ELSE}
procedure RegisterIndyHMACFunctions;
begin
RegisterHMACAlgorithm('md5', TIdHMACWrapper.create(TIdHMACMD5));
RegisterHMACAlgorithm('sha1', TIdHMACWrapper.create(TIdHMACSHA1));
RegisterHMACAlgorithm('sha224', TIdHMACWrapper.create(TIdHMACSHA224));
RegisterHMACAlgorithm('sha256', TIdHMACWrapper.create(TIdHMACSHA256));
RegisterHMACAlgorithm('sha384', TIdHMACWrapper.create(TIdHMACSHA384));
RegisterHMACAlgorithm('sha512', TIdHMACWrapper.create(TIdHMACSHA512));
// the same using the JWT naming
RegisterHMACAlgorithm('HS256', TIdHMACWrapper.create(TIdHMACSHA256));
RegisterHMACAlgorithm('HS384', TIdHMACWrapper.create(TIdHMACSHA384));
RegisterHMACAlgorithm('HS512', TIdHMACWrapper.create(TIdHMACSHA512));
end;
{$ENDIF}
initialization
GHMACRegistry := TDictionary<string, IHMAC>.Create;
// registering based on hash function
{$IFDEF USEBUILTINHMAC}
RegisterBuiltinHMACFunctions;
{$ELSE}
RegisterIndyHMACFunctions;
{$ENDIF}
finalization
GHMACRegistry.Free;
end.
| 26.95 | 90 | 0.737168 |
c31fb7a110b4b69fbbd1ee096a293abaef13492f | 1,263 | pas | Pascal | crypto/prng/t_rnd_91.pas | amikey/delphi-crypto | a79895f25bff69819f354e9bf27c19e2f00fed19 | [
"Unlicense"
]
| 6 | 2019-02-15T02:47:02.000Z | 2021-08-02T22:34:34.000Z | crypto/prng/t_rnd_91.pas | amikey/delphi-crypto | a79895f25bff69819f354e9bf27c19e2f00fed19 | [
"Unlicense"
]
| null | null | null | crypto/prng/t_rnd_91.pas | amikey/delphi-crypto | a79895f25bff69819f354e9bf27c19e2f00fed19 | [
"Unlicense"
]
| 7 | 2020-05-04T21:44:13.000Z | 2021-04-02T12:42:23.000Z | {Simple test for xor4096 unit, we Apr.2007}
program t_rnd_91;
{$i STD.INC}
{$ifdef BIT16}
{$N+}
{$endif}
{$ifdef win32}
{$ifndef VirtualPascal}
{$apptype console}
{$endif}
{$endif}
uses
{$ifdef WINCRT}
wincrt,
{$else}
crt,
{$endif}
xor4096,ministat;
const
NMAX = MaxLongint;
label
_break;
var
mx,sx,x,xmin,xmax: double;
n: longint;
stat: TStatX;
rng: xor4096_ctx;
begin
writeln('Test program for xor4096 unit, mean/sdev of xor4096_double (c) 2007 W.Ehrhardt');
writeln('xor4096 selftest: ', xor4096_selftest);
writeln(' Count Mean 12*SDev**2');
xmin := 1E50;
xmax :=-1E50;
stat1_init(stat);
xor4096_init(rng,1);
for n:=1 to NMAX do begin
x := xor4096_double(rng);
stat1_add(stat,x);
if x<xmin then xmin := x;
if x>xmax then xmax := x;
if n and $3FFFF = 0 then begin
stat1_result(stat,mx,sx);
if stat.Error<>0 then begin
writeln('Ministat error: ',stat.Error);
halt;
end;
writeln(n:12, mx:15:12, 12*sqr(sx):15:12,xmin:12, xmax:15:12);
if keypressed and (readkey=#27) then goto _break;
end;
end;
_break:
stat1_result(stat,mx,sx);
writeln(stat.Nn:12, mx:15:12, 12*sqr(sx):15:12,xmin:12, xmax:15:12);
end.
| 20.370968 | 95 | 0.615994 |
6abbb9b85d6a8f597835f5f4b13a913bdfc6407a | 3,128 | pas | Pascal | ATViewer/Demo1/UFormViewOptions.pas | delphi-pascal-archive/at_viewer | e8dc5357b257184aa7ee7fdeae6d02ed1487290b | [
"Unlicense"
]
| null | null | null | ATViewer/Demo1/UFormViewOptions.pas | delphi-pascal-archive/at_viewer | e8dc5357b257184aa7ee7fdeae6d02ed1487290b | [
"Unlicense"
]
| null | null | null | ATViewer/Demo1/UFormViewOptions.pas | delphi-pascal-archive/at_viewer | e8dc5357b257184aa7ee7fdeae6d02ed1487290b | [
"Unlicense"
]
| null | null | null | unit UFormViewOptions;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TFormViewOptions = class(TForm)
btnOk: TButton;
btnCancel: TButton;
boxExt: TGroupBox;
edText: TEdit;
Label1: TLabel;
edImages: TEdit;
Label2: TLabel;
edMedia: TEdit;
Label3: TLabel;
edInternet: TEdit;
Label4: TLabel;
boxText: TGroupBox;
boxMedia: TGroupBox;
chkMediaMCI: TRadioButton;
chkMediaWMP64: TRadioButton;
btnTextColor: TButton;
btnTextFont: TButton;
FontDialog1: TFontDialog;
ColorDialog1: TColorDialog;
labTextFont: TLabel;
edTextWidth: TEdit;
Label5: TLabel;
edTextIndent: TEdit;
Label6: TLabel;
btnTextOptions: TButton;
chkTextWidthFit: TCheckBox;
procedure btnTextFontClick(Sender: TObject);
procedure btnTextColorClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure btnTextOptionsClick(Sender: TObject);
procedure chkTextWidthFitClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
fTextFontName: string;
fTextFontSize: integer;
fTextFontColor: integer;
fTextFontStyle: TFontStyles;
fTextBackColor: integer;
fTextDetect: boolean;
fTextDetectSize: DWORD;
fTextDetectLimit: DWORD;
end;
//var
// FormViewOptions: TFormViewOptions;
implementation
uses UFormViewOptions2;
{$R *.DFM}
procedure TFormViewOptions.btnTextFontClick(Sender: TObject);
begin
with FontDialog1 do
begin
Font.Name:= fTextFontName;
Font.Size:= fTextFontSize;
Font.Color:= fTextFontColor;
Font.Style:= fTextFontStyle;
if Execute then
begin
fTextFontName:= Font.Name;
fTextFontSize:= Font.Size;
fTextFontColor:= Font.Color;
fTextFontStyle:= Font.Style;
labTextFont.Caption:= fTextFontName+', '+IntToStr(fTextFontSize);
end;
end;
end;
procedure TFormViewOptions.btnTextColorClick(Sender: TObject);
begin
with ColorDialog1 do
begin
Color:= fTextBackColor;
if Execute then
fTextBackColor:= Color;
end;
end;
procedure TFormViewOptions.FormShow(Sender: TObject);
begin
labTextFont.Caption:= fTextFontName+', '+IntToStr(fTextFontSize);
chkTextWidthFitClick(Self);
end;
procedure TFormViewOptions.btnTextOptionsClick(Sender: TObject);
begin
with TFormViewOptions2.Create(Self) do
try
chkDetect.Checked:= fTextDetect;
edDetectSize.Text:= IntToStr(fTextDetectSize);
edDetectLimit.Text:= IntToStr(fTextDetectLimit);
if ShowModal=mrOk then
begin
fTextDetect:= chkDetect.Checked;
fTextDetectSize:= StrToIntDef(edDetectSize.Text, fTextDetectSize);
fTextDetectLimit:= StrToIntDef(edDetectLimit.Text, fTextDetectLimit);
end;
finally
Free;
end;
end;
procedure TFormViewOptions.chkTextWidthFitClick(Sender: TObject);
begin
edTextWidth.Enabled:= not chkTextWidthFit.Checked;
end;
end.
| 25.225806 | 79 | 0.686061 |
fc5770c3e25cb6cdcf664f97973a47b128d8104d | 51,737 | dfm | Pascal | ish/{app}/showresult/Unit1.dfm | TrueBashkir1/sigma-master | cbeaf372874f156413ddf7d060db0f285ae1c68c | [
"MIT"
]
| 7 | 2019-04-06T13:21:19.000Z | 2019-12-07T21:02:04.000Z | ish/{app}/showresult/Unit1.dfm | TrueBashkir1/sigma-master | cbeaf372874f156413ddf7d060db0f285ae1c68c | [
"MIT"
]
| 3 | 2020-04-12T08:27:31.000Z | 2020-05-23T14:18:00.000Z | ish/{app}/showresult/Unit1.dfm | TrueBashkir1/sigma-master | cbeaf372874f156413ddf7d060db0f285ae1c68c | [
"MIT"
]
| 5 | 2019-04-06T13:21:21.000Z | 2022-03-03T10:47:28.000Z | object Form1: TForm1
Left = 885
Top = 0
Width = 450
Height = 791
Caption = 'Sigma 7.4.4 - '#1055#1072#1088#1072#1084#1077#1090#1088#1099
Color = clBtnFace
Constraints.MaxWidth = 450
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object ScrollBox1: TScrollBox
Left = 0
Top = 0
Width = 442
Height = 757
Align = alClient
BevelOuter = bvRaised
BevelKind = bkSoft
BorderStyle = bsNone
Constraints.MaxWidth = 450
TabOrder = 0
object GroupBox2: TGroupBox
Left = 0
Top = 0
Width = 438
Height = 73
Align = alTop
Caption = #1052#1072#1089#1096#1090#1072#1073' '
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = [fsBold]
ParentFont = False
TabOrder = 0
object LabelScale: TLabel
Left = 2
Top = 15
Width = 434
Height = 13
Align = alTop
Alignment = taCenter
Caption = 'LabelScale'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
Layout = tlCenter
end
object TrackBar1: TTrackBar
Left = 2
Top = 28
Width = 434
Height = 37
Align = alTop
Max = 20
Position = 10
TabOrder = 0
OnChange = TrackBar1Change
end
end
object PageControl1: TPageControl
Left = 0
Top = 331
Width = 438
Height = 420
ActivePage = TabSheet2
Align = alTop
Anchors = []
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = [fsBold]
ParentFont = False
TabOrder = 1
object TabSheet1: TTabSheet
BorderWidth = 3
Caption = #1055#1077#1088#1077#1084#1077#1097#1077#1085#1080#1103
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
object GroupBox9: TGroupBox
Left = 0
Top = 0
Width = 437
Height = 177
Align = alTop
Caption = #1050#1086#1086#1088#1076#1080#1085#1072#1090#1099' '#1090#1086#1095#1082#1080' '
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
TabOrder = 0
object Label17: TLabel
Left = 8
Top = 144
Width = 101
Height = 13
Caption = #1055#1077#1088#1077#1084#1077#1097#1077#1085#1080#1077' '#1087#1086' Y:'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
end
object Label16: TLabel
Left = 8
Top = 118
Width = 101
Height = 13
Caption = #1055#1077#1088#1077#1084#1077#1097#1077#1085#1080#1077' '#1087#1086' X:'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
end
object Label27: TLabel
Left = 9
Top = 24
Width = 10
Height = 13
Caption = 'X:'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
end
object Label28: TLabel
Left = 9
Top = 48
Width = 10
Height = 13
Caption = 'Y:'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
end
object Label30: TLabel
Left = 8
Top = 96
Width = 54
Height = 13
Hint = #1053#1072#1087#1088#1103#1078#1077#1085#1080#1077' '#1087#1086' X'
Caption = #1053#1086#1084#1077#1088' '#1050#1069':'
ParentShowHint = False
ShowHint = True
end
object Label31: TLabel
Left = 245
Top = 52
Width = 38
Height = 13
Caption = 'Label31'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
end
object CurElemNum: TLabel
Left = 72
Top = 96
Width = 3
Height = 13
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
end
object InfoMoveX: TLabel
Left = 128
Top = 118
Width = 92
Height = 13
Caption = #1058#1086#1095#1082#1072' '#1085#1077' '#1074#1099#1073#1088#1072#1085#1072
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
end
object InfoMoveY: TLabel
Left = 128
Top = 144
Width = 3
Height = 13
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
end
object Label26: TLabel
Left = 245
Top = 24
Width = 63
Height = 13
Hint = #1053#1072#1087#1088#1103#1078#1077#1085#1080#1077' '#1087#1086' X'
Caption = #1053#1086#1084#1077#1088' '#1091#1079#1083#1072':'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
ParentShowHint = False
ShowHint = True
end
object EditMoveX: TEdit
Left = 22
Top = 21
Width = 98
Height = 21
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
TabOrder = 0
OnChange = EditMoveXChange
end
object EditMoveY: TEdit
Left = 22
Top = 46
Width = 98
Height = 21
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
TabOrder = 1
OnChange = EditMoveYChange
end
object NodeEditInput: TEdit
Left = 320
Top = 22
Width = 98
Height = 21
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
TabOrder = 2
OnChange = NodeEditInputChange
end
end
object GroupBox4: TGroupBox
Left = 0
Top = 177
Width = 437
Height = 80
Align = alTop
Caption = #1055#1077#1088#1077#1084#1077#1097#1077#1085#1080#1103' '
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
TabOrder = 1
object Mover: TTrackBar
Left = 2
Top = 15
Width = 433
Height = 34
Align = alTop
Max = 100
TabOrder = 0
OnChange = MoverChange
end
object Panel5: TPanel
Left = 2
Top = 49
Width = 433
Height = 29
Align = alClient
BevelOuter = bvNone
TabOrder = 1
object Label8: TLabel
Left = 8
Top = 6
Width = 73
Height = 13
Hint = #1050#1086#1101#1092#1092#1080#1094#1080#1077#1085#1090
Caption = #1050#1086#1101#1092#1092#1080#1094#1080#1077#1085#1090':'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
ParentShowHint = False
ShowHint = True
end
object EditMover: TEdit
Left = 91
Top = 3
Width = 75
Height = 21
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
TabOrder = 0
Text = '1'
OnChange = EditMoverChange
end
end
end
end
object TabSheet2: TTabSheet
BorderWidth = 3
Caption = #1053#1072#1087#1088#1103#1078#1077#1085#1080#1103
ImageIndex = 1
object StressType: TRadioGroup
Left = 0
Top = 0
Width = 424
Height = 80
Align = alTop
Caption = #1058#1080#1087' '#1085#1072#1087#1088#1103#1078#1077#1085#1080#1081' '
Columns = 2
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ItemIndex = 0
Items.Strings = (
#1053#1072#1087#1088#1103#1078#1077#1085#1080#1077' '#1087#1086' X'
#1053#1072#1087#1088#1103#1078#1077#1085#1080#1077' '#1087#1086' Y'
#1050#1072#1089#1072#1090#1077#1083#1100#1085#1086#1077
'1-'#1086#1077' '#1075#1083#1072#1074#1085#1086#1077
'2-'#1086#1077' '#1075#1083#1072#1074#1085#1086#1077
#1069#1082#1074#1080#1074#1072#1083#1077#1085#1090#1085#1086#1077
#1059#1075#1086#1083' '#1085#1072#1082#1083'. '#1074'-'#1088#1072' 2-'#1075#1086' '#1075#1083'. '#1085#1072#1087#1088'. '#1082' '#1086#1089#1080' '#1061
#1054#1073#1098#1077#1076#1080#1085#1077#1085#1080#1077)
ParentFont = False
ParentShowHint = False
ShowHint = True
TabOrder = 0
OnClick = StressTypeClick
end
object GroupBox8: TGroupBox
Left = 0
Top = 80
Width = 424
Height = 305
Align = alTop
Caption = #1052#1077#1090#1086#1076' '#1086#1087#1088#1077#1076#1077#1083#1077#1085#1080#1103' '#1085#1072#1087#1088#1103#1078#1077#1085#1080#1103' '#1074' '#1090#1086#1095#1082#1077' '
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
TabOrder = 1
object Panel9: TPanel
Left = 2
Top = 15
Width = 420
Height = 288
Align = alClient
BevelOuter = bvNone
TabOrder = 0
object Edit1: TEdit
Left = 80
Top = 32
Width = 80
Height = 21
TabOrder = 0
Text = 'Edit1'
end
object Panel1: TPanel
Left = 316
Top = 91
Width = 104
Height = 197
Align = alRight
BevelOuter = bvNone
TabOrder = 1
object InfoFiniteElementNumber: TEdit
Left = 0
Top = 8
Width = 89
Height = 21
TabOrder = 0
OnKeyDown = InfoFiniteElementNumberKeyDown
end
end
object Panel6: TPanel
Left = 0
Top = 0
Width = 420
Height = 91
Align = alTop
BevelOuter = bvNone
TabOrder = 2
object Label10: TLabel
Left = 9
Top = 48
Width = 10
Height = 13
Caption = 'X:'
end
object Label11: TLabel
Left = 9
Top = 72
Width = 10
Height = 13
Caption = 'Y:'
end
object Label25: TLabel
Left = 8
Top = 26
Width = 96
Height = 13
Caption = #1050#1086#1086#1088#1076#1080#1085#1072#1090#1099' '#1090#1086#1095#1082#1080':'
end
object Label32: TLabel
Left = 208
Top = 72
Width = 38
Height = 13
Caption = 'Label32'
end
object LabelMaxZnach: TLabel
Left = 208
Top = 24
Width = 144
Height = 13
Caption = #1042#1077#1088#1093#1085#1077#1077' '#1079#1085#1072#1095'. '#1085#1072#1087#1088#1103#1078'. '#1074' '#1050#1069':'
end
object LabelMinZhach: TLabel
Left = 208
Top = 48
Width = 142
Height = 13
Caption = #1053#1080#1078#1085#1077#1077' '#1079#1085#1072#1095'. '#1085#1072#1087#1088#1103#1078'. '#1074' '#1050#1069':'
end
object KonElNumMaxNapr: TLabel
Left = 360
Top = 24
Width = 93
Height = 13
Caption = 'KonElNumMaxNapr'
end
object KonElNumMinNapr: TLabel
Left = 360
Top = 48
Width = 90
Height = 13
Caption = 'KonElNumMinNapr'
end
object EditX: TEdit
Left = 22
Top = 45
Width = 98
Height = 21
TabOrder = 0
OnChange = EditXChange
end
object EditY: TEdit
Left = 22
Top = 70
Width = 98
Height = 21
TabOrder = 1
OnChange = EditYChange
end
object StressMethod1: TRadioButton
Left = 8
Top = 5
Width = 49
Height = 16
Caption = #1062#1055#1057
Checked = True
TabOrder = 2
TabStop = True
OnClick = StressMethod1Click
end
object StressMethod2: TRadioButton
Left = 80
Top = 5
Width = 57
Height = 15
Caption = #1062#1052
TabOrder = 3
OnClick = StressMethod2Click
end
object StressMethod3: TRadioButton
Left = 152
Top = 5
Width = 49
Height = 15
Caption = #1050#1069
TabOrder = 4
OnClick = StressMethod3Click
end
end
object Panel7: TPanel
Left = 0
Top = 91
Width = 316
Height = 197
Align = alClient
BevelOuter = bvNone
TabOrder = 3
object Label2: TLabel
Left = 5
Top = 31
Width = 27
Height = 13
Hint = #1053#1072#1087#1088#1103#1078#1077#1085#1080#1077' '#1087#1086' X'
Caption = #1055#1086' X:'
ParentShowHint = False
ShowHint = True
end
object Label3: TLabel
Left = 5
Top = 55
Width = 27
Height = 13
Hint = #1053#1072#1087#1088#1103#1078#1077#1085#1080#1077' '#1087#1086' Y'
Caption = #1055#1086' Y:'
ParentShowHint = False
ShowHint = True
end
object Label4: TLabel
Left = 5
Top = 80
Width = 69
Height = 13
Hint = #1050#1072#1089#1072#1090#1077#1083#1100#1085#1086#1077' '#1085#1072#1087#1088#1103#1078#1077#1085#1080#1077
Caption = #1050#1072#1089#1072#1090#1077#1083#1100#1085#1086#1077':'
ParentShowHint = False
ShowHint = True
end
object Label5: TLabel
Left = 5
Top = 104
Width = 68
Height = 13
Hint = '1-'#1086#1077' '#1075#1083#1072#1074#1085#1086#1077' '#1085#1072#1087#1088#1103#1078#1077#1085#1080#1077
Caption = '1-'#1086#1077' '#1075#1083#1072#1074#1085#1086#1077':'
ParentShowHint = False
ShowHint = True
end
object Label6: TLabel
Left = 5
Top = 129
Width = 68
Height = 13
Hint = '2-'#1086#1077' '#1075#1083#1072#1074#1085#1086#1077' '#1085#1072#1087#1088#1103#1078#1077#1085#1080#1077
Caption = '2-'#1086#1077' '#1075#1083#1072#1074#1085#1086#1077':'
ParentShowHint = False
ShowHint = True
end
object Label7: TLabel
Left = 5
Top = 152
Width = 67
Height = 13
Hint = #1059#1075#1086#1083
Caption = #1069#1082#1074#1080#1074#1072#1083'-'#1085#1086#1077':'
ParentShowHint = False
ShowHint = True
end
object Label12: TLabel
Left = 5
Top = 172
Width = 28
Height = 13
Hint = #1059#1075#1086#1083
Caption = #1059#1075#1086#1083':'
ParentShowHint = False
ShowHint = True
end
object Label13: TLabel
Left = 5
Top = 8
Width = 54
Height = 13
Hint = #1053#1072#1087#1088#1103#1078#1077#1085#1080#1077' '#1087#1086' X'
Caption = #1053#1086#1084#1077#1088' '#1050#1069':'
ParentShowHint = False
ShowHint = True
end
object InfoX1: TLabel
Left = 160
Top = 32
Width = 3
Height = 13
end
object InfoY1: TLabel
Left = 160
Top = 56
Width = 3
Height = 13
end
object InfoXY1: TLabel
Left = 160
Top = 80
Width = 3
Height = 13
end
object InfoMax1: TLabel
Left = 160
Top = 104
Width = 3
Height = 13
end
object InfoMin1: TLabel
Left = 160
Top = 128
Width = 3
Height = 13
end
object InfoEcv1: TLabel
Left = 160
Top = 152
Width = 3
Height = 13
end
object InfoConer1: TLabel
Left = 160
Top = 176
Width = 3
Height = 13
end
end
end
end
end
object TabSheet3: TTabSheet
BorderWidth = 3
Caption = #1057#1080#1083#1099
ImageIndex = 2
object Label21: TLabel
Left = 0
Top = 320
Width = 87
Height = 13
Caption = #1057#1091#1084#1084#1072' '#1089#1080#1083' '#1087#1086':'
end
object Label22: TLabel
Left = 0
Top = 344
Width = 9
Height = 13
Caption = 'X'
end
object Label23: TLabel
Left = 88
Top = 344
Width = 9
Height = 13
Caption = 'Y'
end
object Label29: TLabel
Left = 184
Top = 344
Width = 53
Height = 13
Caption = #1056#1077#1079#1091#1083#1100#1090'.'
end
object GroupBox5: TGroupBox
Left = 0
Top = 0
Width = 424
Height = 67
Align = alTop
Caption = #1054#1090#1086#1073#1088#1072#1078#1077#1085#1080#1077' '#1074#1077#1082#1090#1086#1088#1072' '#1089#1080#1083#1099' '
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
TabOrder = 0
object Label9: TLabel
Left = 8
Top = 46
Width = 73
Height = 13
Hint = #1044#1083#1080#1085#1072' '#1086#1076#1085#1086#1081' '#1077#1076#1080#1085#1080#1094#1099' '#1089#1080#1083#1099' ('#1074' '#1077#1076#1080#1085#1080#1094#1099#1093' '#1076#1083#1080#1085#1099')'
Caption = #1050#1086#1101#1092#1092#1080#1094#1080#1077#1085#1090':'
ParentShowHint = False
ShowHint = True
end
object EditForce: TEdit
Left = 88
Top = 42
Width = 81
Height = 21
TabOrder = 0
Text = '100'
OnChange = EditForceChange
end
object ForceTrackBar: TTrackBar
Left = 2
Top = 15
Width = 420
Height = 25
Align = alTop
Max = 7
Min = 1
Position = 4
TabOrder = 1
OnChange = ForceTrackBarChange
end
end
object GroupBox7: TGroupBox
Left = 0
Top = 67
Width = 424
Height = 246
Align = alTop
Caption = #1055#1088#1080#1083#1086#1078#1077#1085#1085#1099#1077' '#1089#1080#1083#1099' '
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
TabOrder = 1
object StringGrid1: TStringGrid
Left = 2
Top = 15
Width = 420
Height = 229
Align = alClient
ColCount = 6
DefaultColWidth = 36
DefaultRowHeight = 18
Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goDrawFocusSelected, goTabs]
TabOrder = 0
OnClick = StringGrid1Click
ColWidths = (
40
60
60
60
60
36)
RowHeights = (
18
18
18
18
18)
end
end
object Edit2: TEdit
Left = 16
Top = 340
Width = 65
Height = 21
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
TabOrder = 2
Text = 'Edit2'
end
object Edit3: TEdit
Left = 104
Top = 340
Width = 65
Height = 21
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
TabOrder = 3
Text = 'Edit3'
end
object Edit7: TEdit
Left = 240
Top = 340
Width = 65
Height = 21
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
TabOrder = 4
Text = 'Edit7'
end
end
object TabSheet4: TTabSheet
Caption = 'C'#1074'-'#1074#1072' '#1050#1069
ImageIndex = 3
object GroupBox1: TGroupBox
Left = 0
Top = 0
Width = 441
Height = 225
Caption = #1057#1074#1086#1081#1089#1090#1074#1072' '#1082#1086#1085#1077#1095#1085#1086#1075#1086' '#1101#1083#1077#1084#1077#1085#1090#1072
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
TabOrder = 0
object Label14: TLabel
Left = 8
Top = 26
Width = 54
Height = 13
Caption = #1053#1086#1084#1077#1088' '#1050#1069':'
end
object Label15: TLabel
Left = 8
Top = 56
Width = 104
Height = 13
Caption = #1052#1086#1076#1091#1083#1100' '#1091#1087#1088#1091#1075#1086#1089#1090#1080' E:'
end
object Label18: TLabel
Left = 8
Top = 88
Width = 145
Height = 13
Caption = #1050#1086#1101#1092#1092#1080#1094#1080#1077#1085#1090' '#1055#1091#1072#1089#1089#1086#1085#1072' '#1052#1102':'
end
object Label19: TLabel
Left = 8
Top = 120
Width = 109
Height = 13
Caption = #1044#1086#1087#1091#1089#1082#1072#1077#1084#1086#1077' '#1085#1072#1087#1088'-'#1077':'
end
object Label20: TLabel
Left = 8
Top = 152
Width = 49
Height = 13
Caption = #1058#1086#1083#1097#1080#1085#1072':'
end
object MUprug1: TLabel
Left = 208
Top = 56
Width = 3
Height = 13
end
object KoefPuas1: TLabel
Left = 208
Top = 88
Width = 3
Height = 13
end
object thickness1: TLabel
Left = 208
Top = 152
Width = 3
Height = 13
end
object DopNapr1: TLabel
Left = 208
Top = 120
Width = 3
Height = 13
end
object CaptPropNum: TLabel
Left = 8
Top = 184
Width = 87
Height = 13
Caption = #1053#1086#1084#1077#1088' '#1089#1074#1086#1081#1089#1090#1074#1072':'
end
object PropNum: TLabel
Left = 208
Top = 184
Width = 3
Height = 13
end
object KENumber1: TEdit
Left = 208
Top = 24
Width = 89
Height = 21
TabOrder = 0
OnKeyDown = KENumber1KeyDown
end
end
end
object TabSheet5: TTabSheet
Caption = #1044#1080#1072#1087#1072#1079#1086#1085#1099' '#1085#1072#1087#1088#1103#1078#1077#1085#1080#1081' '#1074' '#1079#1086#1085#1072#1093
ImageIndex = 4
object MaxZnachPlast: TLabel
Left = 16
Top = 336
Width = 188
Height = 13
Caption = #1042#1077#1088#1093#1085#1077#1077' '#1079#1085#1072#1095'. '#1085#1072#1087#1088#1103#1078'. '#1074' '#1087#1083#1072#1089#1090'. '#1074' '#1050#1069':'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
end
object MinZnachPlast: TLabel
Left = 16
Top = 360
Width = 186
Height = 13
Caption = #1053#1080#1078#1085#1077#1077' '#1079#1085#1072#1095'. '#1085#1072#1087#1088#1103#1078'. '#1074' '#1087#1083#1072#1089#1090'. '#1074' '#1050#1069':'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
end
object MaxNaprPlast: TLabel
Left = 216
Top = 336
Width = 66
Height = 13
Caption = 'MaxNaprPlast'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
end
object MinNaprPlast: TLabel
Left = 216
Top = 360
Width = 63
Height = 13
Caption = 'MinNaprPlast'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
end
object StressType1: TRadioGroup
Left = 0
Top = 0
Width = 430
Height = 80
Align = alTop
Caption = #1058#1080#1087' '#1085#1072#1087#1088#1103#1078#1077#1085#1080#1081' '
Columns = 2
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ItemIndex = 0
Items.Strings = (
#1053#1072#1087#1088#1103#1078#1077#1085#1080#1077' '#1087#1086' X'
#1053#1072#1087#1088#1103#1078#1077#1085#1080#1077' '#1087#1086' Y'
#1050#1072#1089#1072#1090#1077#1083#1100#1085#1086#1077
'1-'#1086#1077' '#1075#1083#1072#1074#1085#1086#1077
'2-'#1086#1077' '#1075#1083#1072#1074#1085#1086#1077
#1069#1082#1074#1080#1074#1072#1083#1077#1085#1090#1085#1086#1077
#1059#1075#1086#1083' '#1085#1072#1082#1083'. '#1074'-'#1088#1072' 2-'#1075#1086' '#1075#1083'. '#1085#1072#1087#1088'. '#1082' '#1086#1089#1080' '#1061
#1054#1073#1098#1077#1076#1080#1085#1077#1085#1080#1077)
ParentFont = False
ParentShowHint = False
ShowHint = True
TabOrder = 0
OnClick = StressType1Click
end
object GroupBox10: TGroupBox
Left = 0
Top = 80
Width = 430
Height = 246
Align = alTop
Caption = #1042#1077#1088#1093#1085#1077#1077' '#1080' '#1085#1080#1078#1085#1077#1077' '#1079#1085#1072#1095#1077#1085#1080#1077' '#1085#1072#1087#1088#1103#1078#1077#1085#1080#1103' '#1074' '#1079#1086#1085#1072#1093' '
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
TabOrder = 1
object ZoneStress: TStringGrid
Left = 2
Top = 15
Width = 426
Height = 229
Align = alClient
ColCount = 8
DefaultColWidth = 36
DefaultRowHeight = 18
Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goDrawFocusSelected, goTabs]
TabOrder = 0
OnClick = ZoneStressClick
ColWidths = (
40
40
33
60
33
60
73
70)
RowHeights = (
18
18
18
18
18)
end
end
end
object TabSheet6: TTabSheet
Caption = #1044#1080#1072#1087#1072#1079#1086#1085#1099' '#1085#1072#1087#1088#1103#1078#1077#1085#1080#1081' '#1074' '#1089#1074#1086#1081#1089#1090#1074#1072#1093
ImageIndex = 5
object MaxNaprPlast1: TLabel
Left = 216
Top = 336
Width = 72
Height = 13
Caption = 'MaxNaprPlast1'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
end
object MinNaprPlast1: TLabel
Left = 216
Top = 360
Width = 69
Height = 13
Caption = 'MinNaprPlast1'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
end
object MaxZnachPlast2: TLabel
Left = 16
Top = 336
Width = 188
Height = 13
Caption = #1042#1077#1088#1093#1085#1077#1077' '#1079#1085#1072#1095'. '#1085#1072#1087#1088#1103#1078'. '#1074' '#1087#1083#1072#1089#1090'. '#1074' '#1050#1069':'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
end
object MinZnachPlast2: TLabel
Left = 16
Top = 360
Width = 186
Height = 13
Caption = #1053#1080#1078#1085#1077#1077' '#1079#1085#1072#1095'. '#1085#1072#1087#1088#1103#1078'. '#1074' '#1087#1083#1072#1089#1090'. '#1074' '#1050#1069':'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
end
object StressType2: TRadioGroup
Left = 0
Top = 0
Width = 430
Height = 80
Align = alTop
Caption = #1058#1080#1087' '#1085#1072#1087#1088#1103#1078#1077#1085#1080#1081' '
Columns = 2
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ItemIndex = 0
Items.Strings = (
#1053#1072#1087#1088#1103#1078#1077#1085#1080#1077' '#1087#1086' X'
#1053#1072#1087#1088#1103#1078#1077#1085#1080#1077' '#1087#1086' Y'
#1050#1072#1089#1072#1090#1077#1083#1100#1085#1086#1077
'1-'#1086#1077' '#1075#1083#1072#1074#1085#1086#1077
'2-'#1086#1077' '#1075#1083#1072#1074#1085#1086#1077
#1069#1082#1074#1080#1074#1072#1083#1077#1085#1090#1085#1086#1077
#1059#1075#1086#1083' '#1085#1072#1082#1083'. '#1074'-'#1088#1072' 2-'#1075#1086' '#1075#1083'. '#1085#1072#1087#1088'. '#1082' '#1086#1089#1080' '#1061
#1054#1073#1098#1077#1076#1080#1085#1077#1085#1080#1077)
ParentFont = False
ParentShowHint = False
ShowHint = True
TabOrder = 0
OnClick = StressType2Click
end
object GroupBox11: TGroupBox
Left = 0
Top = 80
Width = 430
Height = 246
Align = alTop
Caption = #1042#1077#1088#1093#1085#1077#1077' '#1080' '#1085#1080#1078#1085#1077#1077' '#1079#1085#1072#1095#1077#1085#1080#1077' '#1085#1072#1087#1088#1103#1078#1077#1085#1080#1103' '#1074' '#1089#1074#1086#1081#1089#1090#1074#1072#1093
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
TabOrder = 1
object ZoneStress2: TStringGrid
Left = 2
Top = 15
Width = 426
Height = 229
Align = alClient
ColCount = 6
DefaultColWidth = 36
DefaultRowHeight = 18
Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goDrawFocusSelected, goTabs]
TabOrder = 0
OnClick = ZoneStress2Click
ColWidths = (
60
40
40
60
40
60)
RowHeights = (
18
18
18
18
18)
end
end
end
end
object Group4: TGroupBox
Left = 0
Top = 73
Width = 438
Height = 258
Align = alTop
Caption = #1053#1072#1089#1090#1088#1086#1081#1082#1080' '
Ctl3D = True
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = [fsBold]
ParentCtl3D = False
ParentFont = False
TabOrder = 2
object GroupBox3: TGroupBox
Left = 2
Top = 199
Width = 434
Height = 57
Align = alBottom
Caption = #1050#1086#1083#1080#1095#1077#1089#1090#1074#1086' '#1094#1074#1077#1090#1086#1074#1099#1093' '#1075#1088#1072#1076#1072#1094#1080#1081
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = [fsBold]
ParentFont = False
TabOrder = 0
object LevelNumber: TLabel
Left = 2
Top = 42
Width = 430
Height = 13
Align = alBottom
Alignment = taCenter
Caption = '4'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
end
object ChangeLegend: TTrackBar
Left = 2
Top = 15
Width = 430
Height = 27
Align = alClient
Anchors = [akLeft, akRight, akBottom]
Max = 255
Min = 4
ParentShowHint = False
Position = 4
ShowHint = True
TabOrder = 0
OnChange = ChangeLegendChange
end
end
object UseAxes: TCheckBox
Left = 205
Top = 16
Width = 139
Height = 17
Hint = #1055#1086#1082#1072#1079#1099#1074#1072#1090#1100' '#1086#1089#1080' '#1082#1086#1086#1088#1076#1080#1085#1072#1090
Caption = #1054#1089#1080' '#1082#1086#1086#1088#1076#1080#1085#1072#1090
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
ParentShowHint = False
ShowHint = True
TabOrder = 1
OnClick = UseAxesClick
end
object UseNumZone: TCheckBox
Left = 6
Top = 94
Width = 127
Height = 17
Hint = #1053#1086#1084#1077#1088#1072' '#1079#1086#1085
Caption = #1053#1086#1084#1077#1088#1072' '#1101#1083#1077#1084#1077#1085#1090#1086#1074
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
ParentShowHint = False
ShowHint = True
TabOrder = 2
OnClick = UseNumZoneClick
end
object UseNumNode: TCheckBox
Left = 6
Top = 78
Width = 104
Height = 17
Hint = #1053#1086#1084#1077#1088#1072' '#1091#1079#1083#1086#1074
Caption = #1053#1086#1084#1077#1088#1072' '#1091#1079#1083#1086#1074
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
ParentShowHint = False
ShowHint = True
TabOrder = 3
OnClick = UseNumNodeClick
end
object UseLines: TCheckBox
Left = 6
Top = 158
Width = 139
Height = 17
Hint = #1051#1080#1085#1080#1080' '#1091#1088#1086#1074#1085#1103
TabStop = False
Caption = #1051#1080#1085#1080#1080' '#1091#1088#1086#1074#1085#1103
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
ParentShowHint = False
ShowHint = True
TabOrder = 4
OnClick = UseLinesClick
end
object UseLegend: TCheckBox
Left = 6
Top = 31
Width = 115
Height = 17
Hint = #1062#1074#1077#1090#1086#1074#1072#1103' '#1096#1082#1072#1083#1072
Caption = #1062#1074#1077#1090#1086#1074#1072#1103' '#1096#1082#1072#1083#1072
Checked = True
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
ParentShowHint = False
ShowHint = True
State = cbChecked
TabOrder = 5
OnClick = UseLegendClick
end
object UseForce: TCheckBox
Left = 6
Top = 46
Width = 98
Height = 17
Hint = #1053#1072#1075#1088#1091#1079#1082#1080
Caption = #1053#1072#1075#1088#1091#1079#1082#1080
Checked = True
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
ParentShowHint = False
ShowHint = True
State = cbChecked
TabOrder = 6
OnClick = UseForceClick
end
object UseBound: TCheckBox
Left = 6
Top = 62
Width = 130
Height = 17
Hint = #1043#1088#1072#1085#1080#1095#1085#1099#1077' '#1091#1089#1083#1086#1074#1080#1103
Caption = #1043#1088#1072#1085#1080#1095#1085#1099#1077' '#1091#1089#1083#1086#1074#1080#1103
Checked = True
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
ParentShowHint = False
ShowHint = True
State = cbChecked
TabOrder = 7
OnClick = UseBoundClick
end
object TestElements: TCheckBox
Left = 6
Top = 142
Width = 150
Height = 17
Hint = #1055#1088#1086#1074#1077#1088#1103#1090#1100' '#1085#1072#1087#1088#1103#1078#1077#1085#1080#1103' '#1074' '#1050#1069
Caption = #1055#1088#1086#1074#1077#1088#1082#1072' '#1085#1072' '#1088#1072#1079#1088#1091#1096#1077#1085#1080#1077
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
ParentShowHint = False
ShowHint = True
TabOrder = 8
OnClick = TestElementsClick
end
object UseNumMater: TCheckBox
Left = 6
Top = 110
Width = 127
Height = 17
Hint = #1053#1086#1084#1077#1088#1072' '#1089#1074#1086#1081#1089#1090#1074' '#1050#1069
Caption = #1053#1086#1084#1077#1088#1072' '#1089#1074#1086#1081#1089#1090#1074' '#1050#1069
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
ParentShowHint = False
ShowHint = True
TabOrder = 9
OnClick = UseNumMaterClick
end
object CheckBox1: TCheckBox
Left = 6
Top = 174
Width = 81
Height = 17
TabStop = False
Caption = #1054#1073#1083#1072#1089#1090#1080
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
ParentShowHint = False
ShowHint = True
TabOrder = 10
OnClick = CheckBox1Click
end
object CheckBox2: TCheckBox
Left = 6
Top = 127
Width = 211
Height = 17
Hint = #1054#1090#1086#1073#1088#1072#1078#1077#1085#1080#1077' '#1084#1072#1090#1077#1088#1080#1072#1083#1086#1074' '#1094#1074#1077#1090#1086#1084
Caption = #1054#1090#1086#1073#1088#1072#1078#1077#1085#1080#1077' '#1089#1074#1086#1081#1089#1090#1074' '#1094#1074#1077#1090#1086#1084
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
TabOrder = 11
OnClick = CheckBox2Click
end
object ZoneCheckBox: TCheckBox
Left = 6
Top = 17
Width = 59
Height = 17
Hint = #1055#1086#1082#1072#1079#1072#1090#1100' '#1080#1089#1093#1086#1076#1085#1086#1077' '#1088#1072#1079#1073#1080#1077#1085#1080#1077
Caption = #1047#1086#1085#1099
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
ParentShowHint = False
ShowHint = False
TabOrder = 12
OnClick = ZoneCheckBoxClick
end
object CheckBoxZonesNum: TCheckBox
Left = 101
Top = 16
Width = 100
Height = 17
Hint = #1055#1086#1082#1072#1079#1099#1074#1072#1090#1100' '#1085#1086#1084#1077#1088#1072' '#1079#1086#1085' '
Caption = #1053#1086#1084#1077#1088#1072' '#1079#1086#1085
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
ParentShowHint = False
ShowHint = True
TabOrder = 13
OnClick = CheckBoxZonesNumClick
end
object GroupBox12: TGroupBox
Left = 232
Top = 40
Width = 193
Height = 144
Caption = #1048#1085#1092#1086#1088#1084#1072#1094#1080#1103
TabOrder = 14
object Label36: TLabel
Left = 8
Top = 36
Width = 62
Height = 13
Caption = #1063#1080#1089#1083#1086' '#1079#1086#1085' ='
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
end
object PropNumLbl: TLabel
Left = 112
Top = 52
Width = 23
Height = 13
Caption = '(20)'
end
object NodesNumLbl: TLabel
Left = 112
Top = 84
Width = 23
Height = 13
Caption = '(20)'
end
object Label35: TLabel
Left = 8
Top = 52
Width = 88
Height = 13
Caption = #1063#1080#1089#1083#1086' '#1089#1074#1086#1081#1089#1090#1074' = '
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
end
object Label34: TLabel
Left = 8
Top = 68
Width = 102
Height = 13
Caption = #1063#1080#1089#1083#1086' '#1101#1083#1077#1084#1077#1085#1090#1086#1074' = '
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
end
object Label33: TLabel
Left = 8
Top = 84
Width = 76
Height = 13
Caption = #1063#1080#1089#1083#1086' '#1091#1079#1083#1086#1074' = '
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
end
object ElemNumLbl: TLabel
Left = 112
Top = 68
Width = 23
Height = 13
Caption = '(20)'
end
object ZonesNumLbl: TLabel
Left = 112
Top = 36
Width = 23
Height = 13
Caption = '(20)'
end
object Label37: TLabel
Left = 8
Top = 100
Width = 35
Height = 13
Caption = 'NRC = '
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
end
object NRCNum: TLabel
Left = 112
Top = 100
Width = 23
Height = 13
Caption = '(20)'
end
object Label38: TLabel
Left = 8
Top = 20
Width = 71
Height = 13
Caption = #1056#1072#1079#1084#1077#1088#1085#1086#1089#1090#1100':'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
end
object ForceLbl: TLabel
Left = 88
Top = 20
Width = 23
Height = 13
Caption = '(20)'
end
object DimLbl: TLabel
Left = 144
Top = 20
Width = 23
Height = 13
Caption = '(20)'
end
object Label24: TLabel
Left = 136
Top = 20
Width = 5
Height = 13
Caption = ','
end
object Label39: TLabel
Left = 8
Top = 120
Width = 46
Height = 13
Caption = 'Label39'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = [fsBold]
ParentFont = False
end
end
end
end
end
| 31.508526 | 248 | 0.483909 |
Subsets and Splits