Class AnObjectMappingEntry

DescriptionHierarchyFieldsMethodsProperties

Unit

Declaration

type AnObjectMappingEntry = class(AMappingEntry)

Description

This class represents an entry in an object mapping, which is an object reference that is indexed by a string key.

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 MyReference: AnObject;
Protected myOwnReference: boolean;

Methods

Public constructor named(const thisName: string; const ThisReference: AnObject; const takeOwnershipOfReference: boolean = true); reintroduce; 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 ownsReference: boolean; virtual;
Public function setOwnsReference(const flag: boolean): boolean; virtual;
Public function Reference: AnObject; virtual;
Public function SetReference(const NewReference: AnObject; const takeOwnershipOfReference: boolean = true): AnObject; virtual;
Public function valueAsString: string; override;

Description

Fields

Protected MyReference: AnObject;

Stores the object to which the entry refers

Protected myOwnReference: boolean;

Indicates whether or not the entry owns its reference

Methods

Public constructor named(const thisName: string; const ThisReference: AnObject; const takeOwnershipOfReference: boolean = true); reintroduce; virtual;

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

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

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 AnObjectMappingEntry. If so, it copies the value of AnObjectMappingEntry.Reference from Other to Self, overwriting the value in Self. If AnObjectMappingEntry.ownsReference Self.ownsReference is True, then the reference held by Self is first freed before the new one is copied from Other.

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 stream Self.Reference, so long as Self.Reference is an instance of an object which implements the CanStream interface.

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 Self.Reference, so long as Self.Reference is an instance of an object which implements the CanStream interface.

Returns

The total number of bytes written to Dest.

Public function ownsReference: boolean; virtual;

Determine whether or not the entry owns its object reference.

If this method returns True, then the entry assumes ownership of the object to which AnObjectMappingEntry.Reference refers, and will free that reference when the entry itself is freed. Otherwise, the mapping entry does not assume ownership of its object reference and, to prevent memory leaks, the caller is responsible for freeing the reference when it is no longer required.

Public function setOwnsReference(const flag: boolean): boolean; virtual;

Set whether or not the entry owns its object reference.

If flag is True, then the entry assumes ownership of the object to which AnObjectMappingEntry.Reference refers, and will free that reference when the entry itself is freed. Otherwise, the mapping entry does not assume ownership of its object reference and, to prevent memory leaks, the caller is responsible for freeing the reference when it is no longer required.

Returns

The previous value of Self.ownsReference.

Public function Reference: AnObject; virtual;

Retrieve the reference held by the entry.

The reference returned by this routine should NOT be freed by the caller without first ensuring that AnObjectMappingEntry.ownsReference is False.

Public function SetReference(const NewReference: AnObject; const takeOwnershipOfReference: boolean = true): AnObject; virtual;

Set the reference held by the 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 held by the entry, if AnObjectMappingEntry.ownsReference is False. In such cases, the caller is responsible for freeing this reference. Otherwise, this method returns Nil.

Public function valueAsString: string; override;

Retrieve the value of the entry as a string.

If Self.Reference represents an instance of a class that implements the CanPrint interface, this method calls CanPrint.toString on the reference and returns the result. Otherwise, it returns the value obtained by calling AnObject.name on the reference.


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