Skip to content

TFPGMapObject

[Properties (by Name)][Methods (by Name)][Events (by Name)]

Generic map

Declaration

Source position: fgl.pp line 346

Type
  generic TFPGMapObject<TKey, TData> = class (TFPSMap)
  private
    TKeyCompareFunc = function(const Key1: TKey; const Key2: TKey) : Integer;
    TDataCompareFunc = function(const Data1: TData; const Data2: TData)
                                 : Integer;
    PKey = ^TKey;
  protected
    FOnKeyCompare : TKeyCompareFunc;
    FOnDataCompare : TDataCompareFunc;
    FFreeObjects : Boolean;
    procedure CopyItem(Src: Pointer; Dest: Pointer);  Override;
    procedure CopyKey(Src: Pointer; Dest: Pointer);  Override;
    procedure CopyData(Src: Pointer; Dest: Pointer);  Override;
    procedure Deref(Item: Pointer);  Override;
    procedure InitOnPtrCompare;  Override;
    function GetKey(Index: Integer) : TKey;
    function GetKeyData(const AKey: TKey) : TData;
    function GetData(Index: Integer) : TData;
    function KeyCompare(Key1: Pointer; Key2: Pointer) : Integer;
    function KeyCustomCompare(Key1: Pointer; Key2: Pointer) : Integer;
    function DataCustomCompare(Data1: Pointer; Data2: Pointer) : Integer;
    procedure PutKey(Index: Integer; const NewKey: TKey);
    procedure PutKeyData(const AKey: TKey; const NewData: TData);
    procedure PutData(Index: Integer; const NewData: TData);
    procedure SetOnKeyCompare(NewCompare: TKeyCompareFunc);
    procedure SetOnDataCompare(NewCompare: TDataCompareFunc);
  public
    constructor Create(AFreeObjects: Boolean);
    constructor Create;
    function Add(const AKey: TKey; const AData: TData) : Integer;
    function Add(const AKey: TKey) : Integer;
    function Find(const AKey: TKey; out Index: Integer) : Boolean;
    function TryGetData(const AKey: TKey; out AData: TData) : Boolean;
    procedure AddOrSetData(const AKey: TKey; const AData: TData);
    function IndexOf(const AKey: TKey) : Integer;
    function IndexOfData(const AData: TData) : Integer;
    procedure InsertKey(Index: Integer; const AKey: TKey);
    procedure InsertKeyData(Index: Integer; const AKey: TKey; 
                           const AData: TData);
    function Remove(const AKey: TKey) : Integer;
    Keys[Index: Integer]: TKey;
    Data[Index: Integer]: TData;
    KeyData[AKey: TKey]: TData; default;
    OnCompare : TKeyCompareFunc;
    OnKeyCompare : TKeyCompareFunc;
    OnDataCompare : TDataCompareFunc;
  end
  ;

Description

TFPGMapObject is a generic map class. It can be used to specialize a map for object types, but not objects with automated reference counting: For reference counted interface objects, TFPGMapInterfacedObjectData must be used.

Members

Member Type Visibility Description
Add Method public Add a key and value to the map
AddOrSetData Method public Add data with given or set value if the key already exists.
CopyData Method protected
CopyItem Method protected
CopyKey Method protected
Create Method public Create a new instance of the map
Data Property public Indexed access to the data in the list
DataCustomCompare Method protected
Deref Method protected
FFreeObjects Field protected
Find Method public Find item based on key
FOnDataCompare Field protected
FOnKeyCompare Field protected
GetData Method protected
GetKey Method protected
GetKeyData Method protected
IndexOf Method public Find index of a key in the list.
IndexOfData Method public Find index of data value in the list.
InitOnPtrCompare Method protected
InsertKey Method public Insert a new key in the list
InsertKeyData Method public Insert a new key with associated data in the list
KeyCompare Method protected
KeyCustomCompare Method protected
KeyData Property public Access to data based on key
Keys Property public Indexed access to the keys in the list.
OnCompare Property public Alias for OnKeyCompare
OnDataCompare Property public Compare function for data values.
OnKeyCompare Property public Compare function for key values.
PKey Type private
PutData Method protected
PutKey Method protected
PutKeyData Method protected
Remove Method public Remove a key from the list
SetOnDataCompare Method protected
SetOnKeyCompare Method protected
TDataCompareFunc Type private
TKeyCompareFunc Type private
TryGetData Method public Find data or return default

Inheritance

Class Description
TFPGMapObject Generic map

See also

Name Description
TFPGMapInterfacedObjectData Generic map for reference counted objects