NaturalDocs:: ClassHierarchy:: Class

An object that stores information about a class in the hierarchy.  It does not store its name; it assumes that it will be stored in a hashref where the key is the name.

Summary
An object that stores information about a class in the hierarchy.
This class is designed to handle multiple definitions of classes, even though that shouldn’t be typical.
The class is implemented as a blessed arrayref.
Creates and returns a new class.
Adds a rew file that defines this class.
Removes the file definition of this class and returns true if there are no more definitions.
Adds a parent definition to the class.
Deletes a parent definition from the class.
Adds a child to the class.
Deletes a child from the class.
Returns an array of the parent classes, or an empty array if none.
Returns whether any parent classes are defined.
Returns an array of all the files that define the parent as part of the class, or an empty array if none.
Returns an array of the child classes, or an empty array if none.
Returns whether any child classes are defined.
Returns an array of the files that define this class, or an empty array if none.
Returns whether the class is defined in the passed file.
Returns whether the class is defined in any files.

Architecture

This class is designed to handle multiple definitions of classes, even though that shouldn’t be typical.  Some language may allow a package to be defined in one file and continued in another.  It’s also possible that a class may be predeclared somewhere, or there is an interface/header declaration and a later source definition.

The end result is that all of these definitions are coalesced into one simply by adding each’s parents to the list.  This is why the functions AddParent() and DeleteParent() return whether they resulted in an actual change to the list of parents.  The answer is not always yes.  The class will handle all of the parent definitions internally.

However, the same is not true for the children.  Since every language defines the hierarchy via each class declaring its parents, that’s where all the internal management is focused.  Doing the same for the children would be redundant and can be avoided if the calling code handles everything correctly.

Important: The calling code is responsible for detecting when AddParent() and DeleteParent() return true, and adjusting the parent’s children list accordingly.  The parent will not keep track of how many times it is declared the parent of the child.

Note that it’s possible for these objects to exist, and even have children, without any definitions defined.  This is because a class may be found to have a parent before that parent has been found in the source.  Also, it’s possible that some parents simply won’t be in the documentation, such as those inherent to the language or in frameworks not documented with Natural Docs.

Members

The class is implemented as a blessed arrayref.  The keys are the constants below.

DEFINITIONSAn existence hashref of all the files which define this class.  Undef if none.
PARENTSA hashref of parents this class has.  The keys are the names, and the values are existence hashrefs of all the files that define this class as having the parent.  Undef if none.
CHILDRENAn existence hashref of children this class has.  Undef if none.  It does not keep track of all the files which define this relationship.  It is up to NaturalDocs::ClassHierarchy to manage this when adding or deleting the child’s parents.

Modification Functions

New

sub New

Creates and returns a new class.

AddDefinition

sub AddDefinition #(file)

Adds a rew file that defines this class.

DeleteDefinition

sub DeleteDefinition #(file)

Removes the file definition of this class and returns true if there are no more definitions.  Note that if there are no more definitions, you may still want to keep the object around if HasChildren() returns true.

AddParent

sub AddParent #(file,
parent)

Adds a parent definition to the class.  Returns whether this was the first definition of that parent.

DeleteParent

sub DeleteParent #(file,
parent)

Deletes a parent definition from the class.  Returns if this deleted the last definition of that parent.

AddChild

sub AddChild #(child)

Adds a child to the class.  This only keeps track of if it has the child, not of the definitions.  See Architecture.

DeleteChild

sub DeleteChild #(child)

Deletes a child from the class.  This only keeps track of if it has the child, not of the definitions.  See Architecture.

Information Functions

Parents

sub Parents

Returns an array of the parent classes, or an empty array if none.

HasParents

sub HasParents

Returns whether any parent classes are defined.

ParentDefinitions

sub ParentDefinitions #(parent)

Returns an array of all the files that define the parent as part of the class, or an empty array if none.

Children

sub Children

Returns an array of the child classes, or an empty array if none.

HasChildren

sub HasChildren

Returns whether any child classes are defined.

Definitions

sub Definitions

Returns an array of the files that define this class, or an empty array if none.

IsDefinedIn

sub IsDefinedIn #(file)

Returns whether the class is defined in the passed file.

IsDefined

sub IsDefined

Returns whether the class is defined in any files.

sub New
Creates and returns a new class.
sub AddDefinition #(file)
Adds a rew file that defines this class.
sub DeleteDefinition #(file)
Removes the file definition of this class and returns true if there are no more definitions.
sub AddParent #(file,
parent)
Adds a parent definition to the class.
sub DeleteParent #(file,
parent)
Deletes a parent definition from the class.
sub AddChild #(child)
Adds a child to the class.
sub DeleteChild #(child)
Deletes a child from the class.
sub Parents
Returns an array of the parent classes, or an empty array if none.
sub HasParents
Returns whether any parent classes are defined.
sub ParentDefinitions #(parent)
Returns an array of all the files that define the parent as part of the class, or an empty array if none.
sub Children
Returns an array of the child classes, or an empty array if none.
sub HasChildren
Returns whether any child classes are defined.
sub Definitions
Returns an array of the files that define this class, or an empty array if none.
sub IsDefinedIn #(file)
Returns whether the class is defined in the passed file.
sub IsDefined
Returns whether the class is defined in any files.
A package that handles all the gory details of managing the class hierarchy.
This class is designed to handle multiple definitions of classes, even though that shouldn’t be typical.