<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">###############################################################################
#
#   Package: NaturalDocs::SourceDB::WatchedFileDefinitions
#
###############################################################################
#
#   A class to track the definitions appearing in a watched file.  This is only used for extensions that track definition info with
#   &lt;NaturalDocs::SourceDB::ItemDefinition&gt;-derived objects.  Do not use it for extensions that only track existence.
#
###############################################################################

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


#
#   Variables: Members
#
#   This object would only have one member, which is an array, so the object itself serves as that member.
#
#   &lt;ExtensionIDs&gt; are used as indexes into this object.  Each entry is a hashref that maps item strings to
#   &lt;NaturalDocs::SourceDB::ItemDefinition&gt;-derived objects.  This is only done for extensions that use those objects to track
#   definitions, it's not needed for extensions that only track existence.  If there are no definitions, the entry will be undef.
#


#
#   Function: New
#
#   Creates and returns a new object.
#
sub New
    {
    my $class = shift;

    my $object = [ ];
    bless $object, $class;

    return $object;
    };



###############################################################################
# Group: Definition Functions
#


#
#   Function: AddDefinition
#
#   Adds a definition for the passed item string.  If it's already defined, the new definition will be ignored.
#
#   Parameters:
#
#       extension - The &lt;ExtensionID&gt;.
#       itemString - The item string.
#       definition - The definition, which must be an object derived from &lt;NaturalDocs::SourceDB::ItemDefinition&gt;.
#
#   Returns:
#
#       Whether the definition was added, which is to say, whether this was the first definition for the passed &lt;FileName&gt;.
#
sub AddDefinition #(ExtensionID extension, string itemString, NaturalDocs::SourceDB::ItemDefinition definition) =&gt; bool
    {
    my ($self, $extension, $itemString, $definition) = @_;

    if (!defined $self-&gt;[$extension])
        {  $self-&gt;[$extension] = { };  };

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


#
#   Function: GetDefinition
#
#   Returns the &lt;NaturalDocs::SourceDB::ItemDefinition&gt;-derived object for the passed item string  or undef if there is none.
#
sub GetDefinition #(ExtensionID extension, string itemString) =&gt; NaturalDocs::SourceDB::ItemDefinition
    {
    my ($self, $extension, $itemString) = @_;

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


#
#   Function: DeleteDefinition
#
#   Removes the definition for the passed item string.  Returns whether it was successful, meaning whether a definition existed
#   for that item.
#
sub DeleteDefinition #(ExtensionID extension, string itemString) =&gt; bool
    {
    my ($self, $extension, $itemString) = @_;

    if (defined $self-&gt;[$extension])
        {
        if (exists $self-&gt;[$extension]-&gt;{$itemString})
            {
            delete $self-&gt;[$extension]-&gt;{$itemString};

            if (!scalar keys %{$self-&gt;[$extension]})
                {  $self-&gt;[$extension] = undef;  };

            return 1;
            };
        };

    return 0;
    };


#
#   Function: HasDefinitions
#
#   Returns whether there are any definitions for this item.
#
sub HasDefinitions #(ExtensionID extension) =&gt; bool
    {
    my ($self, $extension) = @_;

    return (defined $self-&gt;[$extension]);
    };


#
#   Function: HasDefinition
#
#   Returns whether there is a definition for the passed item string.
#
sub HasDefinition #(ExtensionID extension, string itemString) =&gt; bool
    {
    my ($self, $extension, $itemString) = @_;

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


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