1 ###############################################################################
3 # Package: NaturalDocs::SymbolTable::File
5 ###############################################################################
7 # A class representing a file, keeping track of what symbols and references are defined in it.
9 ###############################################################################
11 # This file is part of Natural Docs, which is Copyright © 2003-2010 Greg Valure
12 # Natural Docs is licensed under version 3 of the GNU Affero General Public License (AGPL)
13 # Refer to License.txt for the complete details
18 package NaturalDocs::SymbolTable::File;
21 ###############################################################################
22 # Group: Implementation
27 # The class is implemented as a blessed arrayref. The following constants are its members.
29 # SYMBOLS - An existence hashref of the <SymbolStrings> it defines.
30 # REFERENCES - An existence hashref of the <ReferenceStrings> in the file.
33 # DEPENDENCY: New() depends on the order of these constants. If they change, New() has to be updated.
34 use constant SYMBOLS => 0;
35 use constant REFERENCES => 1;
38 ###############################################################################
39 # Group: Modification Functions
45 # Creates and returns a new object.
51 # Let's make it safe, since normally you can pass values to New. Having them just be ignored would be an obscure error.
53 { die "You can't pass values to NaturalDocs::SymbolTable::File->New()\n"; };
55 # DEPENDENCY: This code depends on the order of the member constants.
56 my $object = [ { }, { } ];
57 bless $object, $package;
66 # Adds a <SymbolString> definition.
70 # symbol - The <SymbolString> being added.
72 sub AddSymbol #(symbol)
74 my ($self, $symbol) = @_;
75 $self->[SYMBOLS]{$symbol} = 1;
80 # Function: DeleteSymbol
82 # Removes a <SymbolString> definition.
86 # symbol - The <SymbolString> to delete.
88 sub DeleteSymbol #(symbol)
90 my ($self, $symbol) = @_;
91 delete $self->[SYMBOLS]{$symbol};
96 # Function: AddReference
98 # Adds a reference definition.
102 # referenceString - The <ReferenceString> being added.
104 sub AddReference #(referenceString)
106 my ($self, $referenceString) = @_;
107 $self->[REFERENCES]{$referenceString} = 1;
112 # Function: DeleteReference
114 # Removes a reference definition.
118 # referenceString - The <ReferenceString> to delete.
120 sub DeleteReference #(referenceString)
122 my ($self, $referenceString) = @_;
123 delete $self->[REFERENCES]{$referenceString};
128 ###############################################################################
129 # Group: Information Functions
133 # Function: HasAnything
135 # Returns whether the file has any symbol or reference definitions at all.
139 return (scalar keys %{$_[0]->[SYMBOLS]} || scalar keys %{$_[0]->[REFERENCES]});
145 # Returns an array of all the <SymbolStrings> defined in this file. If none, returns an empty array.
149 return keys %{$_[0]->[SYMBOLS]};
154 # Function: References
156 # Returns an array of all the <ReferenceStrings> defined in this file. If none, returns an empty array.
160 return keys %{$_[0]->[REFERENCES]};
165 # Function: DefinesSymbol
167 # Returns whether the file defines the passed <SymbolString> or not.
169 sub DefinesSymbol #(symbol)
171 my ($self, $symbol) = @_;
172 return exists $self->[SYMBOLS]{$symbol};
177 # Function: DefinesReference
179 # Returns whether the file defines the passed <ReferenceString> or not.
181 sub DefinesReference #(referenceString)
183 my ($self, $referenceString) = @_;
184 return exists $self->[REFERENCES]{$referenceString};