Class AStringLeaf

DescriptionHierarchyFieldsMethodsProperties

Unit

Declaration

type AStringLeaf = class(ABinaryLeaf)

Description

This class represents a node in a binary tree that keeps the string used to define its sort key. As with ABinaryLeaf, instances of AStringLeaf use the hash value of a given string, as calculated by Charstring.hashValueOf, to determine their sort key.

Hierarchy

Overview

Fields

Protected myName: string;

Methods

Public constructor named(const thisKey: string); override;
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 toString: AnsiString; override;
Public function name: string; override;

Description

Fields

Protected myName: string;

Stores the string used to generate the sort key for the node

Methods

Public constructor named(const thisKey: string); override;

Construct a new node that uses the hash value of the specified string as its sort key.

The implementation of this method is identical to that provided by ABinaryLeaf.withSortKey, except that thisKey is stored internally by the node. The string can be retrieved by calling AStringLeaf.name.

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 ABinaryLeaf.shallowCopyFrom: it calls that method, then checks to see whether Other is an instance of AStringLeaf. If so, it copies the value of AStringLeaf.name 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.

This method builds upon the behavior inherited from ABinaryLeaf.selfStreamingLength; it calls the inherited routine, then calculates the number of bytes required to write its name and adds that to the result, which is then returned to the user.

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 ABinaryLeaf.writeSelfTo: it first calls the inherited routine, then writes the value of AStringLeaf.name to the stream by calling AStream.writeString on Dest.

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 ABinaryLeaf.readFrom: it calls the inherited routine first, then reads the value of AStringLeaf.name from the stream by calling AStream.readString on Source.

Returns

The total number of bytes read from Source.

Public function toString: AnsiString; override;

Construct and return a string representation of the node, suitable for printing to a text-based console or device.

In accordance with the criteria described by APrintingObject.toString, this method returns a string which contains the index of the node and the string used to define its sort key. The format of the string returned is controlled by stlfStringRepresentation.

Public function name: string; override;

Retrieve the name of the node. This is the string that was used at construction time to generate the sort key of the node.


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