<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">###############################################################################
#
#   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 &lt;ExtensionID&gt; 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-&gt;[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) =&gt; bool
    {
    my ($self, $extension, $itemString) = @_;

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


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

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


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

    if (!defined $self-&gt;[ITEMS]-&gt;[$extension])
        {  return 0;  }
    elsif (exists $self-&gt;[ITEMS]-&gt;[$extension]-&gt;{$itemString})
        {
        delete $self-&gt;[ITEMS]-&gt;[$extension]-&gt;{$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) =&gt; string array
    {
    my ($self, $extension) = @_;

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


1;
</pre></body></html>