OSDN Git Service

Version 5.91
[vbslib/main.git] / GPL_bin_fullset / NaturalDocs / Modules / NaturalDocs / SymbolTable / File.pm
1 ###############################################################################
2 #
3 #   Package: NaturalDocs::SymbolTable::File
4 #
5 ###############################################################################
6 #
7 #   A class representing a file, keeping track of what symbols and references are defined in it.
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 package NaturalDocs::SymbolTable::File;
19
20
21 ###############################################################################
22 # Group: Implementation
23
24 #
25 #   Constants: Members
26 #
27 #   The class is implemented as a blessed arrayref.  The following constants are its members.
28 #
29 #       SYMBOLS       - An existence hashref of the <SymbolStrings> it defines.
30 #       REFERENCES  - An existence hashref of the <ReferenceStrings> in the file.
31 #
32
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;
36
37
38 ###############################################################################
39 # Group: Modification Functions
40
41
42 #
43 #   Function: New
44 #
45 #   Creates and returns a new object.
46 #
47 sub New
48     {
49     my $package = shift;
50
51     # Let's make it safe, since normally you can pass values to New.  Having them just be ignored would be an obscure error.
52     if (scalar @_)
53         {  die "You can't pass values to NaturalDocs::SymbolTable::File->New()\n";  };
54
55     # DEPENDENCY: This code depends on the order of the member constants.
56     my $object = [ { }, { } ];
57     bless $object, $package;
58
59     return $object;
60     };
61
62
63 #
64 #   Function: AddSymbol
65 #
66 #   Adds a <SymbolString> definition.
67 #
68 #   Parameters:
69 #
70 #       symbol - The <SymbolString> being added.
71 #
72 sub AddSymbol #(symbol)
73     {
74     my ($self, $symbol) = @_;
75     $self->[SYMBOLS]{$symbol} = 1;
76     };
77
78
79 #
80 #   Function: DeleteSymbol
81 #
82 #   Removes a <SymbolString> definition.
83 #
84 #   Parameters:
85 #
86 #       symbol - The <SymbolString> to delete.
87 #
88 sub DeleteSymbol #(symbol)
89     {
90     my ($self, $symbol) = @_;
91     delete $self->[SYMBOLS]{$symbol};
92     };
93
94
95 #
96 #   Function: AddReference
97 #
98 #   Adds a reference definition.
99 #
100 #   Parameters:
101 #
102 #       referenceString - The <ReferenceString> being added.
103 #
104 sub AddReference #(referenceString)
105     {
106     my ($self, $referenceString) = @_;
107     $self->[REFERENCES]{$referenceString} = 1;
108     };
109
110
111 #
112 #   Function: DeleteReference
113 #
114 #   Removes a reference definition.
115 #
116 #   Parameters:
117 #
118 #       referenceString - The <ReferenceString> to delete.
119 #
120 sub DeleteReference #(referenceString)
121     {
122     my ($self, $referenceString) = @_;
123     delete $self->[REFERENCES]{$referenceString};
124     };
125
126
127
128 ###############################################################################
129 # Group: Information Functions
130
131
132 #
133 #   Function: HasAnything
134 #
135 #   Returns whether the file has any symbol or reference definitions at all.
136 #
137 sub HasAnything
138     {
139     return (scalar keys %{$_[0]->[SYMBOLS]} || scalar keys %{$_[0]->[REFERENCES]});
140     };
141
142 #
143 #   Function: Symbols
144 #
145 #   Returns an array of all the <SymbolStrings> defined in this file.  If none, returns an empty array.
146 #
147 sub Symbols
148     {
149     return keys %{$_[0]->[SYMBOLS]};
150     };
151
152
153 #
154 #   Function: References
155 #
156 #   Returns an array of all the <ReferenceStrings> defined in this file.  If none, returns an empty array.
157 #
158 sub References
159     {
160     return keys %{$_[0]->[REFERENCES]};
161     };
162
163
164 #
165 #   Function: DefinesSymbol
166 #
167 #   Returns whether the file defines the passed <SymbolString> or not.
168 #
169 sub DefinesSymbol #(symbol)
170     {
171     my ($self, $symbol) = @_;
172     return exists $self->[SYMBOLS]{$symbol};
173     };
174
175
176 #
177 #   Function: DefinesReference
178 #
179 #   Returns whether the file defines the passed <ReferenceString> or not.
180 #
181 sub DefinesReference #(referenceString)
182     {
183     my ($self, $referenceString) = @_;
184     return exists $self->[REFERENCES]{$referenceString};
185     };
186
187 1;