1 ###############################################################################
3 # Class: NaturalDocs::ClassHierarchy::File
5 ###############################################################################
7 # An object that stores information about what hierarchy information is present in a file. It does not store its <FileName>; it
8 # assumes that it will be stored in a hashref where the key is the <FileName>.
10 ###############################################################################
12 # This file is part of Natural Docs, which is Copyright © 2003-2010 Greg Valure
13 # Natural Docs is licensed under version 3 of the GNU Affero General Public License (AGPL)
14 # Refer to License.txt for the complete details
19 package NaturalDocs::ClassHierarchy::File;
23 # Topic: Implementation
25 # 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.
26 # The keys are the class <SymbolStrings> that are defined in the file, and the values are existence hashrefs of each class'
27 # parent <ReferenceStrings>, or undef if none.
31 ###############################################################################
32 # Group: Modification Functions
38 # Creates and returns a new class.
45 bless $object, $package;
52 # Adds a rew class <SymbolString> to the file.
56 my ($self, $class) = @_;
58 if (!exists $self->{$class})
59 { $self->{$class} = undef; };
63 # Function: DeleteClass
64 # Deletes a class <SymbolString> from the file.
66 sub DeleteClass #(class)
68 my ($self, $class) = @_;
69 delete $self->{$class};
73 # Function: AddParentReference
74 # Adds a parent <ReferenceString> to a class <SymbolString>.
76 sub AddParentReference #(class, parentReference)
78 my ($self, $class, $parent) = @_;
80 if (!exists $self->{$class} || !defined $self->{$class})
81 { $self->{$class} = { }; };
83 $self->{$class}->{$parent} = 1;
87 # Function: DeleteParentReference
88 # Deletes a parent <ReferenceString> from a class <SymbolString>.
90 sub DeleteParentReference #(class, parent)
92 my ($self, $class, $parent) = @_;
94 if (exists $self->{$class})
96 delete $self->{$class}->{$parent};
98 if (!scalar keys %{$self->{$class}})
99 { $self->{$class} = undef; };
105 ###############################################################################
106 # Group: Information Functions
111 # Returns an array of the class <SymbolStrings> that are defined by this file, or an empty array if none.
116 return keys %{$self};
121 # Returns whether the file defines the passed class <SymbolString>.
123 sub HasClass #(class)
125 my ($self, $class) = @_;
126 return exists $self->{$class};
130 # Function: ParentReferencesOf
131 # Returns an array of the parent <ReferenceStrings> that are defined by the class, or an empty array if none.
133 sub ParentReferencesOf #(class)
135 my ($self, $class) = @_;
137 if (!exists $self->{$class} || !defined $self->{$class})
140 { return keys %{$self->{$class}}; };
144 # Function: HasParentReference
145 # Returns whether the file defines the passed class <SymbolString> and parent <ReferenceString>.
147 sub HasParentReference #(class, parent)
149 my ($self, $class, $parent) = @_;
151 if (!$self->HasClass($class))
154 return exists $self->{$class}->{$parent};