about summary refs log tree commit diff
path: root/docs/tool/Modules/NaturalDocs/SourceDB/File.pm
blob: c364c948fdad5a9876d43540310984f454ff11b2 (plain)
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
###############################################################################
#
#   Package: NaturalDocs::SourceDB::File
#
###############################################################################
#
#   A class used to index items by file.
#
###############################################################################

# 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::File;

use NaturalDocs::DefineMembers 'ITEMS';


#
#   Variables: Members
#
#   These constants serve as indexes into the object array.
#
#   ITEMS - An arrayref where an <ExtensionID> is the index and the members are existence hashrefs of the item strigs defined
#               in this file.  The arrayref will always exist, but the hashrefs may be undef.
#


#
#   Function: New
#
#   Returns a new object.
#
sub New
    {
    my $package = shift;

    my $object = [ ];
    $object->[ITEMS] = [ ];

    bless $object, $package;
    return $object;
    };


#
#   Function: AddItem
#
#   Adds an item to this file.  Returns whether this added a new item.
#
sub AddItem #(ExtensionID extension, string itemString) => bool
    {
    my ($self, $extension, $itemString) = @_;

    if (!defined $self->[ITEMS]->[$extension])
        {
        $self->[ITEMS]->[$extension] = { $itemString => 1 };
        return 1;
        }
    elsif (!exists $self->[ITEMS]->[$extension]->{$itemString})
        {
        $self->[ITEMS]->[$extension]->{$itemString} = 1;
        return 1;
        }
    else
        {
        return 0;
        };
    };


#
#   Function: HasItem
#
#   Returns whether the item exists in this file.
#
sub HasItem #(ExtensionID extension, string itemString) => bool
    {
    my ($self, $extension, $itemString) = @_;

    if (defined $self->[ITEMS]->[$extension])
        {  return exists $self->[ITEMS]->[$extension]->{$itemString};  }
    else
        {  return 0;  };
    };


#
#   Function: DeleteItem
#
#   Deletes the passed item.  Returns whether it existed.
#
sub DeleteItem #(ExtensionID extension, string itemString) => bool
    {
    my ($self, $extension, $itemString) = @_;

    if (!defined $self->[ITEMS]->[$extension])
        {  return 0;  }
    elsif (exists $self->[ITEMS]->[$extension]->{$itemString})
        {
        delete $self->[ITEMS]->[$extension]->{$itemString};
        return 1;
        }
    else
        {  return 0;  };
    };


#
#   Function: ListItems
#
#   Returns an array of all the item strings defined for a particular extension, or an empty list if none.
#
sub ListItems #(ExtensionID extension) => string array
    {
    my ($self, $extension) = @_;

    if (defined $self->[ITEMS]->[$extension])
        {  return keys %{$self->[ITEMS]->[$extension]};  }
    else
        {  return ( );  };
    };


1;