124 lines
3.6 KiB
ObjectPascal
124 lines
3.6 KiB
ObjectPascal
unit dpgrtl.stringmap;
|
|
|
|
interface
|
|
uses
|
|
System.Classes;
|
|
|
|
type
|
|
TStringMap = class
|
|
strict protected
|
|
fData : TStringList;
|
|
|
|
private
|
|
function GetCaseSensitive : boolean;
|
|
function GetValue(Name:AnsiString): integer;
|
|
|
|
procedure SetCaseSensitive( Value: boolean);
|
|
procedure SetValue( Name:AnsiString; Value: integer);
|
|
|
|
public
|
|
procedure AfterConstruction; override;
|
|
procedure BeforeDestruction; override;
|
|
|
|
procedure Clear;
|
|
procedure Sort;
|
|
|
|
public
|
|
property CaseSensitive : boolean read GetCaseSensitive
|
|
write SetCaseSensitive;
|
|
|
|
property Value[Name:AnsiString] : integer read GetValue
|
|
write SetValue; default;
|
|
end;
|
|
|
|
implementation
|
|
uses
|
|
System.SysUtils;
|
|
|
|
{ TStringMap }
|
|
|
|
// ================================================================================================
|
|
// After Construction
|
|
// ================================================================================================
|
|
procedure TStringMap.AfterConstruction;
|
|
begin
|
|
inherited;
|
|
fData := TStringList.Create
|
|
end;
|
|
|
|
// ================================================================================================
|
|
// Before Destruction
|
|
// ================================================================================================
|
|
procedure TStringMap.BeforeDestruction;
|
|
begin
|
|
fData.Free;
|
|
inherited
|
|
end;
|
|
|
|
// ================================================================================================
|
|
// Get CaseSensitive
|
|
// ================================================================================================
|
|
function TStringMap.GetCaseSensitive: boolean;
|
|
begin
|
|
result := fData.CaseSensitive
|
|
end;
|
|
|
|
// ================================================================================================
|
|
// Get Value
|
|
// ================================================================================================
|
|
function TStringMap.GetValue(Name: AnsiString): integer;
|
|
var
|
|
idx: integer;
|
|
|
|
begin
|
|
idx := fData.IndexOfName(String(Name));
|
|
|
|
if idx >= 0
|
|
then result := StrToIntDef( fData.ValueFromIndex[idx], -1)
|
|
else result := -1
|
|
end;
|
|
|
|
|
|
// ================================================================================================
|
|
// Set CaseSensitive
|
|
// ================================================================================================
|
|
procedure TStringMap.SetCaseSensitive(Value: boolean);
|
|
begin
|
|
fData.CaseSensitive := Value
|
|
end;
|
|
|
|
// ================================================================================================
|
|
// Set Value
|
|
// ================================================================================================
|
|
procedure TStringMap.SetValue(Name: AnsiString; Value: integer);
|
|
var
|
|
idx: integer;
|
|
val: string;
|
|
|
|
begin
|
|
idx := fData.IndexOfName(String(Name));
|
|
val := IntToStr(Value);
|
|
|
|
if idx >= 0
|
|
then fData.ValueFromIndex[idx] := val
|
|
else fData.Add(String(Name)+'='+val)
|
|
end;
|
|
|
|
// ================================================================================================
|
|
// Clear
|
|
// ================================================================================================
|
|
procedure TStringMap.Clear;
|
|
begin
|
|
fData.Clear
|
|
end;
|
|
|
|
// ================================================================================================
|
|
// Sort
|
|
// ================================================================================================
|
|
procedure TStringMap.Sort;
|
|
begin
|
|
fData.Sort
|
|
end;
|
|
|
|
end.
|