1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
|
###############################################################################
#
# Class: NaturalDocs::ClassHierarchy::File
#
###############################################################################
#
# An object that stores information about what hierarchy information is present in a file. It does not store its <FileName>; it
# assumes that it will be stored in a hashref where the key is the <FileName>.
#
###############################################################################
# This file is part of Natural Docs, which is Copyright 2003-2010 Greg Valure
# Natural Docs is licensed under version 3 of the GNU Affero General Public License (AGPL)
# Refer to License.txt for the complete details
use strict;
use integer;
package NaturalDocs::ClassHierarchy::File;
#
# Topic: Implementation
#
# Since there's only one member in the class, and it's a hashref, the class is simply the hashref itself blessed as a class.
# The keys are the class <SymbolStrings> that are defined in the file, and the values are existence hashrefs of each class'
# parent <ReferenceStrings>, or undef if none.
#
###############################################################################
# Group: Modification Functions
#
# Function: New
#
# Creates and returns a new class.
#
sub New
{
my ($package) = @_;
my $object = { };
bless $object, $package;
return $object;
};
#
# Function: AddClass
# Adds a rew class <SymbolString> to the file.
#
sub AddClass #(class)
{
my ($self, $class) = @_;
if (!exists $self->{$class})
{ $self->{$class} = undef; };
};
#
# Function: DeleteClass
# Deletes a class <SymbolString> from the file.
#
sub DeleteClass #(class)
{
my ($self, $class) = @_;
delete $self->{$class};
};
#
# Function: AddParentReference
# Adds a parent <ReferenceString> to a class <SymbolString>.
#
sub AddParentReference #(class, parentReference)
{
my ($self, $class, $parent) = @_;
if (!exists $self->{$class} || !defined $self->{$class})
{ $self->{$class} = { }; };
$self->{$class}->{$parent} = 1;
};
#
# Function: DeleteParentReference
# Deletes a parent <ReferenceString> from a class <SymbolString>.
#
sub DeleteParentReference #(class, parent)
{
my ($self, $class, $parent) = @_;
if (exists $self->{$class})
{
delete $self->{$class}->{$parent};
if (!scalar keys %{$self->{$class}})
{ $self->{$class} = undef; };
};
};
###############################################################################
# Group: Information Functions
#
# Function: Classes
# Returns an array of the class <SymbolStrings> that are defined by this file, or an empty array if none.
#
sub Classes
{
my ($self) = @_;
return keys %{$self};
};
#
# Function: HasClass
# Returns whether the file defines the passed class <SymbolString>.
#
sub HasClass #(class)
{
my ($self, $class) = @_;
return exists $self->{$class};
};
#
# Function: ParentReferencesOf
# Returns an array of the parent <ReferenceStrings> that are defined by the class, or an empty array if none.
#
sub ParentReferencesOf #(class)
{
my ($self, $class) = @_;
if (!exists $self->{$class} || !defined $self->{$class})
{ return ( ); }
else
{ return keys %{$self->{$class}}; };
};
#
# Function: HasParentReference
# Returns whether the file defines the passed class <SymbolString> and parent <ReferenceString>.
#
sub HasParentReference #(class, parent)
{
my ($self, $class, $parent) = @_;
if (!$self->HasClass($class))
{ return undef; };
return exists $self->{$class}->{$parent};
};
1;
|