1 ###############################################################################
3 # Package: NaturalDocs::SourceDB::File
5 ###############################################################################
7 # A class used to index items by file.
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
19 package NaturalDocs::SourceDB::File;
21 use NaturalDocs::DefineMembers 'ITEMS';
27 # These constants serve as indexes into the object array.
29 # ITEMS - An arrayref where an <ExtensionID> is the index and the members are existence hashrefs of the item strigs defined
30 # in this file. The arrayref will always exist, but the hashrefs may be undef.
37 # Returns a new object.
44 $object->[ITEMS] = [ ];
46 bless $object, $package;
54 # Adds an item to this file. Returns whether this added a new item.
56 sub AddItem #(ExtensionID extension, string itemString) => bool
58 my ($self, $extension, $itemString) = @_;
60 if (!defined $self->[ITEMS]->[$extension])
62 $self->[ITEMS]->[$extension] = { $itemString => 1 };
65 elsif (!exists $self->[ITEMS]->[$extension]->{$itemString})
67 $self->[ITEMS]->[$extension]->{$itemString} = 1;
80 # Returns whether the item exists in this file.
82 sub HasItem #(ExtensionID extension, string itemString) => bool
84 my ($self, $extension, $itemString) = @_;
86 if (defined $self->[ITEMS]->[$extension])
87 { return exists $self->[ITEMS]->[$extension]->{$itemString}; }
94 # Function: DeleteItem
96 # Deletes the passed item. Returns whether it existed.
98 sub DeleteItem #(ExtensionID extension, string itemString) => bool
100 my ($self, $extension, $itemString) = @_;
102 if (!defined $self->[ITEMS]->[$extension])
104 elsif (exists $self->[ITEMS]->[$extension]->{$itemString})
106 delete $self->[ITEMS]->[$extension]->{$itemString};
115 # Function: ListItems
117 # Returns an array of all the item strings defined for a particular extension, or an empty list if none.
119 sub ListItems #(ExtensionID extension) => string array
121 my ($self, $extension) = @_;
123 if (defined $self->[ITEMS]->[$extension])
124 { return keys %{$self->[ITEMS]->[$extension]}; }