causerieIntroduction Units Class Hierarchy Classes, Interfaces, Objects and Records Types Variables Constants Functions and Procedures Identifiers Classes hierarchy graph
|
Class AMapping
Unit
classwork
Declaration
type AMapping = class(ABinaryTree)
Description
This class represents a mappings, which is a list of items that are indexed by a string key. The overall functionality of the mapping is similar to that provided by Python and other languages that implement such objects; however, the maping is implemented as a binary tree rather than a table of hashed objects and buckets.
Hierarchy
Overview
Methods
|
function init: boolean; override; |
|
constructor fromDelimitedList(const thisList: AnsiString; const pairsDelimiter: string = ''; const keyValueDelimiter: string = ''); |
|
function explode(thisList: AnsiString; pairsDelimiter: string = ''; keyValueDelimiter: string = ''): TCensus; virtual; |
|
function implode(pairsDelimiter: string = ''; keyValueDelimiter: string = ''): AnsiString; virtual; |
|
function Keys: AStringList; virtual; |
|
function implodeKeys(delimiter: string = ''): AnsiString; virtual; |
|
function implodeValues(delimiter: string = ''): AnsiString; virtual; |
|
function Entry(const key: string): AMappingEntry; virtual; |
|
function keyAt(const thisIndex: TNodeAbsoluteIndex): string; virtual; |
Description
Methods
|
function init: boolean; override; |
Initializer
|
|
constructor fromDelimitedList(const thisList: AnsiString; const pairsDelimiter: string = ''; const keyValueDelimiter: string = ''); |
Construct a new mapping instance that will parse the given string to populate its entries.
thisList must be a doubly-delimited string: each key and value pair must be separated from the next by pairsDelimiter , and the keys themselves must be separated from their associated values by keyValueDelimiter .
If pairsDelimiter is not specified by the caller, or if it is an empty string, then the value of llstDefaultDelimiter is used; likewise, if keyValueDelimiter is not specified by the caller, or if it is an empty string, then the value of mapDefaultDelimiter is used.
See AMapping.explode for more information.
|
|
function explode(thisList: AnsiString; pairsDelimiter: string = ''; keyValueDelimiter: string = ''): TCensus; virtual; |
Parse the given string to add new entries to the mapping.
thisList must be a doubly-delimited string: each key and value pair must be separated from the next by pairsDelimiter , and the keys themselves must be separated from their associated values by keyValueDelimiter .
If pairsDelimiter is not specified by the caller, or if it is an empty string, then the value of llstDefaultDelimiter is used; likewise, if keyValueDelimiter is not specified by the caller, or if it is an empty string, then the value of mapDefaultDelimiter is used.
An example of a string that would be successfully parsed by this routine is shown below:
const
simpleList: string = 'firstItem=1,secondItem=second,thirdItem=42';
The above string would result in three mapping entries when passed to this routine: the first named firstItem with a value of 1 ; the second named secondItem with a value of second ; and the third named thirdItem with a value of 42 .
This method iterates through the key/value pairs in the list, constructing new instances of the class specified by Self.LeafType and then calling AMappingEntry.fromDelimitedString to have the key/value parsed. If, for some reason, Self.LeafType does not refer to a descendant of AMappingEntry, this this routine does nothing.
Returns
The total number of items added to the mapping. |
|
function implode(pairsDelimiter: string = ''; keyValueDelimiter: string = ''): AnsiString; virtual; |
Condense the mapping and its entries into a doubly-delimited string. In essence, this method reverses the work done by AMapping.explode; and, in fact, the string returned by this routine can be passed to AMapping.explode to reconstitute the dictionary.
This method iterates through the items in the mapping, calling AMappingEntry.implode on each one. The resulting string will consist of key/value pairs, in which the keys and values are separated by keyValueDelimiter and the key/value pairs are separated from each other by pairsDelimiter .
If keyValueDelimiter is not specified by the caller, or if it is an empty string, then the value of mapDefaultDelimiter is used. If pairsDelimiter is not specified by the caller, or if it is an empty string, then value of llstDefaultDelimiter is used.
Returns
A doubly-delimited string that contains representations of all dictionary entries. |
|
function Keys: AStringList; virtual; |
Construct a list of all string keys in the mapping.
This method proceeds sequentially through all entries in the mapping, obtaining the name of each. The names are inserted into an instance of AStringList which is constructed for this purpose.
Returns
An instance of AStringList that contains the names of all mapping entries. This list should be freed by the caller when it is no longer required. If there are no entries in the dictionary, an empty string list is returned. |
|
function implodeKeys(delimiter: string = ''): AnsiString; virtual; |
Construct a delimited string that contains the names of all entries in the mapping. The names are separated from each other by the string specified in delimiter . If delimiter is not provided by the caller, or if it is an empty string, then the value of llstDefaultDelimiter is used.
|
|
function implodeValues(delimiter: string = ''): AnsiString; virtual; |
Construct a delimited string that contains the values of all entries in the dictionary. The values are separated from each other by the string specified in delimiter . If delimiter is not provided by the caller, or if it is an empty string, then the value of llstDefaultDelimiter is used.
|
|
function keyAt(const thisIndex: TNodeAbsoluteIndex): string; virtual; |
Retrieve the key at the specified index in the mapping.
Internally, this method calls ABinaryTree.LeafAtIndex on itself; if that method returns a node, then AMappingEntry.name is called on it.
Returns
The name of the node at the specified index , if found; an empty string otherwise. |
Generated by PasDoc 0.13.0 on 2015-01-10 17:13:18
|