Class ADictionaryEntry

DescriptionHierarchyFieldsMethodsProperties

Unit

Declaration

type ADictionaryEntry = class(AMappingEntry)

Description

This class represents a dictionary entry, which is an item that is indexed by a string key. The value of the item is represented by a variant object, so as enable the dictionary element to store the widest possible array of values.

Unlike a typical dictionary, the item here is not associated with a hash lookup table; instead, it is treated as a node in a binary tree.

Hierarchy

Overview

Fields

Protected myValue: Variant;

Methods

Public constructor named(const thisName: string; const thisValue: Variant); reintroduce; virtual;
Public constructor fromDelimitedString(item: AnsiString; delimiter: string = ''); virtual;
Public function init: boolean; override;
Public function shallowCopyFrom(const Other: AnObject): boolean; override;
Public function selfStreamingLength: TStreamIOSize; override;
Public function writeSelfTo(const Dest: AStream): TStreamIOSize; override;
Public function readFrom(const Source: AStream): TStreamIOSize; override;
Public function value: Variant; virtual;
Public function setValue(const newValue: Variant): Variant; virtual;
Public function valueAsString: string; override;
Public function setValueFromString(const newValue: string): string; virtual;

Description

Fields

Protected myValue: Variant;

Stores the value of the entry

Methods

Public constructor named(const thisName: string; const thisValue: Variant); reintroduce; virtual;

Construct a new entry that associates the specified name with the specified variant value. The value of thisName will be hashed to determine the sort key of the dictionary entry when it is inserted into a dictionary.

Public constructor fromDelimitedString(item: AnsiString; delimiter: string = ''); virtual;

Explode the entry from a string which contains a key/value pair, where the key and value are separated from each other by delimiter.

This method attempts to break item into two strings by searching for delimiter. If successful, the method will call the inherited constructor to set the name and sort key of the entry, after which it will call Self.setValueFromString to set the value of the entry.

If delimiter is not found, then this method constructs an empty mapping entry.

If delimiter is not specified by the caller, of it is an empty string, then the value of mapDefaultDelimiter is used.

Public function init: boolean; override;

Initializer

Public function shallowCopyFrom(const Other: AnObject): boolean; override;

Construct a shallow copy of the other object.

This method overrides the behavior inherited from AStringLeaf.shallowCopyFrom: it calls that routine, then checks to see whether Other is an instance of ADictionaryEntry. If so, it copies the value of ADictionaryEntry.value from Other to Self, overwriting the value in Self.

Note that this method does NOT copy any sibling or child nodes and so cannot be used to create a full copy of any descendant of ANode. Likewise, it does NOT copy the left or right subtrees and so cannot be used to create a full copy of any descendant of ABinaryLeaf. The copy will NOT be automatically placed in the binary tree to which Other belongs, if any, but the caller is free to do so, so long as the node's sort key does not match one that already exists in the tree.

Public function selfStreamingLength: TStreamIOSize; override;

Calculate the number of bytes required to stream the node, and just the node.

This method builds upon the behavior inherited from AStringLeaf.selfStreamingLength: it calls the inherited method, then adds the number of bytes required to store an instance of TVarData.

Public function writeSelfTo(const Dest: AStream): TStreamIOSize; override;

Write the node, and just the node, to the specified stream.

This method builds upon the behavior inherited from AStringLeaf.writeSelfTo: it first calls the inherited routine, then writes the value of the entry by converting it to an instance of TVarData.

Returns

The total number of bytes written to Dest.

Public function readFrom(const Source: AStream): TStreamIOSize; override;

Read the node from the specified stream.

This method builds upon the behavior inherited from AStringLeaf.readFrom: it calls the inherited routine first, then reads the value of the entry by treating it as an instance of TVarData when reading it from Source.

Returns

The total number of bytes read from Source.

Public function value: Variant; virtual;

Retrieve the value associated with the entry.

Public function setValue(const newValue: Variant): Variant; virtual;

Sets the value of the entry.

Returns

The previous value of the entry.

Public function valueAsString: string; override;

Retrieve the value of the entry as a string.

This method calls Variants.varToStr on Self.value and returns the result.

Public function setValueFromString(const newValue: string): string; virtual;

Set the value of the entry from the given string.

This method calls Self.setValue with newValue and returns the result formatted as a string.


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