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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
|
###############################################################################
#
# Package: NaturalDocs::SourceDB::Item
#
###############################################################################
#
# A base class for something being tracked in <NaturalDocs::SourceDB>.
#
###############################################################################
# This file is part of Natural Docs, which is Copyright (C) 2003-2008 Greg Valure
# Natural Docs is licensed under the GPL
use strict;
use integer;
package NaturalDocs::SourceDB::Item;
use NaturalDocs::DefineMembers 'DEFINITIONS';
#
# Variables: Members
#
# The following constants are indexes into the object array.
#
# DEFINITIONS - A hashref that maps <FileNames> to either <NaturalDocs::SourceDB::ItemDefinition>-derived objects or
# serves as an existence hashref depending on whether the extension only tracks existence. Will be undef if
# there are none.
#
#
# Function: New
#
# Creates and returns a new object.
#
sub New
{
my $class = shift;
my $object = [ ];
bless $object, $class;
return $object;
};
###############################################################################
#
# Group: Definition Functions
#
# These functions should be called by <NaturalDocs::SourceDB>. You should not be calling them directly. Call functions
# like <NaturalDocs::SourceDB->AddDefinition()> instead.
#
#
# Function: AddDefinition
#
# Adds a definition for the passed <FileName>. If it's already defined, the new definition will be ignored.
#
# Parameters:
#
# file - The <FileName>.
# definition - The definition, which must be an object derived from <NaturalDocs::SourceDB::ItemDefinition> or undef if
# the extension only tracks existence.
#
# Returns:
#
# Whether the definition was added, which is to say, whether this was the first definition for the passed <FileName>.
#
sub AddDefinition #(FileName file, optional NaturalDocs::SourceDB::ItemDefinition definition) => bool
{
my ($self, $file, $definition) = @_;
if (!defined $self->[DEFINITIONS])
{ $self->[DEFINITIONS] = { }; };
if (!exists $self->[DEFINITIONS]->{$file})
{
if (!defined $definition)
{ $definition = 1; };
$self->[DEFINITIONS]->{$file} = $definition;
return 1;
}
else
{ return 0; };
};
#
# Function: ChangeDefinition
#
# Changes the definition for the passed <FileName>.
#
# Parameters:
#
# file - The <FileName>.
# definition - The definition, which must be an object derived from <NaturalDocs::SourceDB::ItemDefinition>.
#
sub ChangeDefinition #(FileName file, NaturalDocs::SourceDB::ItemDefinition definition)
{
my ($self, $file, $definition) = @_;
if (!defined $self->[DEFINITIONS] || !exists $self->[DEFINITIONS]->{$file})
{ die "Tried to change a non-existant definition in SourceD::Item."; };
$self->[DEFINITIONS]->{$file} = $definition;
};
#
# Function: GetDefinition
#
# Returns the <NaturalDocs::SourceDB::ItemDefinition>-derived object for the passed <FileName>, non-zero if it only tracks
# existence, or undef if there is no definition.
#
sub GetDefinition #(FileName file) => NaturalDocs::SourceDB::ItemDefinition or bool
{
my ($self, $file) = @_;
if (defined $self->[DEFINITIONS])
{ return $self->[DEFINITIONS]->{$file}; }
else
{ return undef; };
};
#
# Function: DeleteDefinition
#
# Removes the definition for the passed <FileName>. Returns whether it was successful, meaning whether a definition existed
# for that file.
#
sub DeleteDefinition #(FileName file) => bool
{
my ($self, $file) = @_;
if (defined $self->[DEFINITIONS])
{
if (exists $self->[DEFINITIONS]->{$file})
{
delete $self->[DEFINITIONS]->{$file};
if (!scalar keys %{$self->[DEFINITIONS]})
{ $self->[DEFINITIONS] = undef; };
return 1;
};
};
return 0;
};
#
# Function: HasDefinitions
#
# Returns whether there are any definitions for this item.
#
sub HasDefinitions # => bool
{
my $self = shift;
return (defined $self->[DEFINITIONS]);
};
#
# Function: HasDefinition
#
# Returns whether there is a definition for the passed <FileName>.
#
sub HasDefinition #(FileName file) => bool
{
my ($self, $file) = @_;
if (defined $self->[DEFINITIONS])
{ return (exists $self->[DEFINITIONS]->{$file}); }
else
{ return 0; };
};
#
# Function: GetAllDefinitionsHashRef
#
# Returns a hashref of all the definitions of this item. *Do not change.* The keys are the <FileNames>, and the values are
# either <NaturalDocs::SourceDB::ItemDefinition>-derived objects or it's just an existence hashref if those aren't used.
#
sub GetAllDefinitionsHashRef
{
my $self = shift;
return $self->[DEFINITIONS];
};
1;
|