OSDN Git Service

Version 5.91
[vbslib/main.git] / GPL_bin_fullset / NaturalDocs / Modules / NaturalDocs / SourceDB / File.pm
1 ###############################################################################
2 #
3 #   Package: NaturalDocs::SourceDB::File
4 #
5 ###############################################################################
6 #
7 #   A class used to index items by file.
8 #
9 ###############################################################################
10
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
14
15 use strict;
16 use integer;
17
18
19 package NaturalDocs::SourceDB::File;
20
21 use NaturalDocs::DefineMembers 'ITEMS';
22
23
24 #
25 #   Variables: Members
26 #
27 #   These constants serve as indexes into the object array.
28 #
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.
31 #
32
33
34 #
35 #   Function: New
36 #
37 #   Returns a new object.
38 #
39 sub New
40     {
41     my $package = shift;
42
43     my $object = [ ];
44     $object->[ITEMS] = [ ];
45
46     bless $object, $package;
47     return $object;
48     };
49
50
51 #
52 #   Function: AddItem
53 #
54 #   Adds an item to this file.  Returns whether this added a new item.
55 #
56 sub AddItem #(ExtensionID extension, string itemString) => bool
57     {
58     my ($self, $extension, $itemString) = @_;
59
60     if (!defined $self->[ITEMS]->[$extension])
61         {
62         $self->[ITEMS]->[$extension] = { $itemString => 1 };
63         return 1;
64         }
65     elsif (!exists $self->[ITEMS]->[$extension]->{$itemString})
66         {
67         $self->[ITEMS]->[$extension]->{$itemString} = 1;
68         return 1;
69         }
70     else
71         {
72         return 0;
73         };
74     };
75
76
77 #
78 #   Function: HasItem
79 #
80 #   Returns whether the item exists in this file.
81 #
82 sub HasItem #(ExtensionID extension, string itemString) => bool
83     {
84     my ($self, $extension, $itemString) = @_;
85
86     if (defined $self->[ITEMS]->[$extension])
87         {  return exists $self->[ITEMS]->[$extension]->{$itemString};  }
88     else
89         {  return 0;  };
90     };
91
92
93 #
94 #   Function: DeleteItem
95 #
96 #   Deletes the passed item.  Returns whether it existed.
97 #
98 sub DeleteItem #(ExtensionID extension, string itemString) => bool
99     {
100     my ($self, $extension, $itemString) = @_;
101
102     if (!defined $self->[ITEMS]->[$extension])
103         {  return 0;  }
104     elsif (exists $self->[ITEMS]->[$extension]->{$itemString})
105         {
106         delete $self->[ITEMS]->[$extension]->{$itemString};
107         return 1;
108         }
109     else
110         {  return 0;  };
111     };
112
113
114 #
115 #   Function: ListItems
116 #
117 #   Returns an array of all the item strings defined for a particular extension, or an empty list if none.
118 #
119 sub ListItems #(ExtensionID extension) => string array
120     {
121     my ($self, $extension) = @_;
122
123     if (defined $self->[ITEMS]->[$extension])
124         {  return keys %{$self->[ITEMS]->[$extension]};  }
125     else
126         {  return ( );  };
127     };
128
129
130 1;