<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">###############################################################################
#
#   Package: NaturalDocs::SourceDB::Item
#
###############################################################################
#
#   A base class for something being tracked in &lt;NaturalDocs::SourceDB&gt;.
#
###############################################################################

# 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 &lt;FileNames&gt; to either &lt;NaturalDocs::SourceDB::ItemDefinition&gt;-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 &lt;NaturalDocs::SourceDB&gt;.  You should not be calling them directly.  Call functions
#   like &lt;NaturalDocs::SourceDB-&gt;AddDefinition()&gt; instead.
#


#
#   Function: AddDefinition
#
#   Adds a definition for the passed &lt;FileName&gt;.  If it's already defined, the new definition will be ignored.
#
#   Parameters:
#
#       file - The &lt;FileName&gt;.
#       definition - The definition, which must be an object derived from &lt;NaturalDocs::SourceDB::ItemDefinition&gt; 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 &lt;FileName&gt;.
#
sub AddDefinition #(FileName file, optional NaturalDocs::SourceDB::ItemDefinition definition) =&gt; bool
    {
    my ($self, $file, $definition) = @_;

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

    if (!exists $self-&gt;[DEFINITIONS]-&gt;{$file})
        {
        if (!defined $definition)
            {  $definition = 1;  };

        $self-&gt;[DEFINITIONS]-&gt;{$file} = $definition;
        return 1;
        }
    else
        {  return 0;  };
    };


#
#   Function: ChangeDefinition
#
#   Changes the definition for the passed &lt;FileName&gt;.
#
#   Parameters:
#
#       file - The &lt;FileName&gt;.
#       definition - The definition, which must be an object derived from &lt;NaturalDocs::SourceDB::ItemDefinition&gt;.
#
sub ChangeDefinition #(FileName file, NaturalDocs::SourceDB::ItemDefinition definition)
    {
    my ($self, $file, $definition) = @_;

    if (!defined $self-&gt;[DEFINITIONS] || !exists $self-&gt;[DEFINITIONS]-&gt;{$file})
        {  die "Tried to change a non-existant definition in SourceD::Item.";  };

    $self-&gt;[DEFINITIONS]-&gt;{$file} = $definition;
    };


#
#   Function: GetDefinition
#
#   Returns the &lt;NaturalDocs::SourceDB::ItemDefinition&gt;-derived object for the passed &lt;FileName&gt;, non-zero if it only tracks
#   existence, or undef if there is no definition.
#
sub GetDefinition #(FileName file) =&gt; NaturalDocs::SourceDB::ItemDefinition or bool
    {
    my ($self, $file) = @_;

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


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

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

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

            return 1;
            };
        };

    return 0;
    };


#
#   Function: HasDefinitions
#
#   Returns whether there are any definitions for this item.
#
sub HasDefinitions # =&gt; bool
    {
    my $self = shift;
    return (defined $self-&gt;[DEFINITIONS]);
    };


#
#   Function: HasDefinition
#
#   Returns whether there is a definition for the passed &lt;FileName&gt;.
#
sub HasDefinition #(FileName file) =&gt; bool
    {
    my ($self, $file) = @_;

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


#
#   Function: GetAllDefinitionsHashRef
#
#   Returns a hashref of all the definitions of this item.  *Do not change.*  The keys are the &lt;FileNames&gt;, and the values are
#   either &lt;NaturalDocs::SourceDB::ItemDefinition&gt;-derived objects or it's just an existence hashref if those aren't used.
#
sub GetAllDefinitionsHashRef
    {
    my $self = shift;
    return $self-&gt;[DEFINITIONS];
    };


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