Class TMutableMap

Unit

Declaration

type generic TMutableMap<TKey,TValue,TInfo> = class(specialize TReadOnlyMap<TKey,TValue,TInfo>)

Description

Generic mutable map

Data in this map can be read (see ancestor TReadOnlyMap) and modified.

Example:

type TMutableMapStringString = specialize TMutableMap<string, string, THAMTTypeInfo>;
var map: TMutableMapStringString;
    p: TMutableMapStringString.PPair;
begin
  map := TMutableMapStringString.create;
  map.Insert('hello', 'world');
  map.insert('foo', 'bar');
  map['abc'] := 'def';

  writeln(map['hello']); // world
  writeln(map.get('foo')); // bar
  writeln(map.get('abc', 'default')); // def

  //enumerate all
  for p in map do
    writeln(pˆ.key, ': ', pˆ.value);

  map.free;
end.

Hierarchy

Overview

Methods

Public function include(const key: TKey; const value: TValue; allowOverride: boolean = true): boolean; inline;
Public function exclude(const key: TKey): boolean; inline;
Public procedure insert(const key: TKey; const value: TValue); inline;
Public procedure remove(const key:TKey); inline;
Public procedure clear;
Public function clone: TMutableMap;

Properties

Public property items[key: TKey]: TValue read get write includeItem;
Public property mutable[key: TKey]: PValue read getRef;

Description

Methods

Public function include(const key: TKey; const value: TValue; allowOverride: boolean = true): boolean; inline;

Inserts a (key, value) pair, if allowOverride is true or key did not exist

Returns

If the map did not contain key

Public function exclude(const key: TKey): boolean; inline;

Removes a (key, value) pair

Returns

If the map did contain key

Public procedure insert(const key: TKey; const value: TValue); inline;

Inserts a (key, value) pair, or raises an exception if the map did not contain key

Public procedure remove(const key:TKey); inline;

Removes key (and the associated value), or raises an exception if the map did not contain key

Public procedure clear;

Removes everything from the map;

Public function clone: TMutableMap;

Creates a new map equal to self. No data is copied, till either map is modified (copy-on-write).

Properties

Public property items[key: TKey]: TValue read get write includeItem;

Default parameter, so you can read or write elements with map[key]

Public property mutable[key: TKey]: PValue read getRef;

Pointer to value


Generated by PasDoc 0.16.0.