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 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
|
###############################################################################
#
# Package: NaturalDocs::SymbolTable::File
#
###############################################################################
#
# A class representing a file, keeping track of what symbols and references are defined in it.
#
###############################################################################
# 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::SymbolTable::File;
###############################################################################
# Group: Implementation
#
# Constants: Members
#
# The class is implemented as a blessed arrayref. The following constants are its members.
#
# SYMBOLS - An existence hashref of the <SymbolStrings> it defines.
# REFERENCES - An existence hashref of the <ReferenceStrings> in the file.
#
# DEPENDENCY: New() depends on the order of these constants. If they change, New() has to be updated.
use constant SYMBOLS => 0;
use constant REFERENCES => 1;
###############################################################################
# Group: Modification Functions
#
# Function: New
#
# Creates and returns a new object.
#
sub New
{
my $package = shift;
# Let's make it safe, since normally you can pass values to New. Having them just be ignored would be an obscure error.
if (scalar @_)
{ die "You can't pass values to NaturalDocs::SymbolTable::File->New()\n"; };
# DEPENDENCY: This code depends on the order of the member constants.
my $object = [ { }, { } ];
bless $object, $package;
return $object;
};
#
# Function: AddSymbol
#
# Adds a <SymbolString> definition.
#
# Parameters:
#
# symbol - The <SymbolString> being added.
#
sub AddSymbol #(symbol)
{
my ($self, $symbol) = @_;
$self->[SYMBOLS]{$symbol} = 1;
};
#
# Function: DeleteSymbol
#
# Removes a <SymbolString> definition.
#
# Parameters:
#
# symbol - The <SymbolString> to delete.
#
sub DeleteSymbol #(symbol)
{
my ($self, $symbol) = @_;
delete $self->[SYMBOLS]{$symbol};
};
#
# Function: AddReference
#
# Adds a reference definition.
#
# Parameters:
#
# referenceString - The <ReferenceString> being added.
#
sub AddReference #(referenceString)
{
my ($self, $referenceString) = @_;
$self->[REFERENCES]{$referenceString} = 1;
};
#
# Function: DeleteReference
#
# Removes a reference definition.
#
# Parameters:
#
# referenceString - The <ReferenceString> to delete.
#
sub DeleteReference #(referenceString)
{
my ($self, $referenceString) = @_;
delete $self->[REFERENCES]{$referenceString};
};
###############################################################################
# Group: Information Functions
#
# Function: HasAnything
#
# Returns whether the file has any symbol or reference definitions at all.
#
sub HasAnything
{
return (scalar keys %{$_[0]->[SYMBOLS]} || scalar keys %{$_[0]->[REFERENCES]});
};
#
# Function: Symbols
#
# Returns an array of all the <SymbolStrings> defined in this file. If none, returns an empty array.
#
sub Symbols
{
return keys %{$_[0]->[SYMBOLS]};
};
#
# Function: References
#
# Returns an array of all the <ReferenceStrings> defined in this file. If none, returns an empty array.
#
sub References
{
return keys %{$_[0]->[REFERENCES]};
};
#
# Function: DefinesSymbol
#
# Returns whether the file defines the passed <SymbolString> or not.
#
sub DefinesSymbol #(symbol)
{
my ($self, $symbol) = @_;
return exists $self->[SYMBOLS]{$symbol};
};
#
# Function: DefinesReference
#
# Returns whether the file defines the passed <ReferenceString> or not.
#
sub DefinesReference #(referenceString)
{
my ($self, $referenceString) = @_;
return exists $self->[REFERENCES]{$referenceString};
};
1;
|