Class AnObjectMapping

DescriptionHierarchyFieldsMethodsProperties

Unit

Declaration

type AnObjectMapping = class(AMapping)

Description

This class represents an object mapping, which is a list of object references that are index by string keys. The overall functionality of the mapping is similar to that provided by Python and other languages that implement such objects; however, the dictionary is implemented as a binary tree rather than a table of hashed objects.

As with instances of ABinaryTree, the mapping is capable of looking up entries and streaming those entries to and from arbitrary streams. The mapping also supports condensing itself into a delimited string and iterating over its keys and values.

Hierarchy

Overview

Methods

Public function References: AnObjectList; virtual;
Public function Add(const thisKey: string; const ThisReference: AnObject; const takeOwnershipOfReference: boolean = true): AnObjectMappingEntry; reintroduce; virtual;
Public function ReferenceNamed(const key: string; const DefaultReference: AnObject = nil): AnObject; virtual;
Public function SetReferenceNamed(const key: string; const NewReference: AnObject; const takeOwnershipOfReference: boolean = true): AnObject; virtual;
Public function ReferenceAt(const thisIndex: TIndexAbsolute): AnObject; virtual;
Public function SetReferenceAt(const ThisIndex: TIndexAbsolute; const NewReference: AnObject; const takeOwnershipOfReference: boolean = true): AnObject; virtual;

Description

Methods

Public function References: AnObjectList; virtual;

Construct a list of all references maintained by the mapping.

This method proceeds sequentially through all entries in the mapping, obtaining the reference held by each. The references are inserted into an instance of AnObjectList which is constructed for this purpose.

Returns

An instance of AnObjectList that contains the references held by all mapping entries. This list should be freed by the caller when it is no longer required. If there are no entries in the mapping, an empty object list is returned.

Public function Add(const thisKey: string; const ThisReference: AnObject; const takeOwnershipOfReference: boolean = true): AnObjectMappingEntry; reintroduce; virtual;

Add the specified key and value to the mapping.

As with other instances of ABinaryTree, AnObjectMapping does not allow duplicate entries; consequently, if thisKey already exists in the dictionary, its value will be updated with ThisReference. Otherwise, a new entry is created.

If takeOwnershipOfReference is True, the entry specified will assume ownership of ThisReference and free it when the entry itself is freed.

Returns

A reference to the mapping entry that has been created and inserted or, if the entry already existed, the existing entry. The caller should NOT attempt to free this reference; that will be done when the dictionary is destroyed.

Public function ReferenceNamed(const key: string; const DefaultReference: AnObject = nil): AnObject; virtual;

Retrieve the reference associated with the given name.

This method retrieves the instance of AnObjectMappingEntry that has the specified key; it then returns the reference obtained by calling AnObjectMappingEntry.Reference on that entry.

If no entry that matches key is found in the dictionary, this routine returns the value of DefaultReference.

Public function SetReferenceNamed(const key: string; const NewReference: AnObject; const takeOwnershipOfReference: boolean = true): AnObject; virtual;

Set the reference associated with the given name.

This method retrieves the instance of AnObjectMappingEntry that has the specified key; it then sets the value by calling AnObjectMappingEntry.SetReference on that entry.

If no entry that matches key is found in the dictionary, then this method will add a new entry.

If takeOwnershipOfReference is True, then the mapping entry will assume ownership of NewReference and will free the object reference when the mapping entry itself is freed. Otherwise, the caller is responsible for freeing NewReference when it is no longer required, but NOT before freeing the instance of AnObjectMappingEntry.

Returns

The previous reference maintained by the named entry, if the AnObjectMappingEntry.ownsReference is True. In such cases, the caller is responsible for freeing the reference returned. Otherwise, this method returns Nil.

Public function ReferenceAt(const thisIndex: TIndexAbsolute): AnObject; virtual;

Retrieve the reference at the specified index in the dictionary.

Internally, this method calls ABinaryTree.LeafAtIndex on itself; if that method returns a node, then AnObjectMappingEntry.Reference is called on it.

Returns

The reference maintained by the node at the specified index, if found; Nil otherwise.

Public function SetReferenceAt(const ThisIndex: TIndexAbsolute; const NewReference: AnObject; const takeOwnershipOfReference: boolean = true): AnObject; virtual;

Set the reference maintained by the entry at the specified index.

Internally, this method calls ABinaryTree.LeafAtIndex on itself; if that method returns a node, then AnObjectMappingEntry.SetReference is called on it.

If takeOwnershipOfReference is True, then the mapping entry will assume ownership of NewReference and will free the object reference when the mapping entry itself is freed. Otherwise, the caller is responsible for freeing NewReference when it is no longer required, but NOT before freeing the instance of AnObjectMappingEntry.

Returns

The previous reference maintained by the named entry, if the AnObjectMappingEntry.ownsReference is True. In such cases, the caller is responsible for freeing the reference returned. Otherwise, this method returns Nil.


Generated by PasDoc 0.13.0 on 2015-06-23 19:40:11