From 61bfe2d70cae6be8c4086a210a5451135ccca9ea Mon Sep 17 00:00:00 2001 From: Magnus Auvinen Date: Sat, 2 Aug 2008 08:21:29 +0000 Subject: added doc tool --- docs/tool/Modules/NaturalDocs/SourceDB/Item.pm | 201 +++++++++++++++++++++++++ 1 file changed, 201 insertions(+) create mode 100644 docs/tool/Modules/NaturalDocs/SourceDB/Item.pm (limited to 'docs/tool/Modules/NaturalDocs/SourceDB/Item.pm') diff --git a/docs/tool/Modules/NaturalDocs/SourceDB/Item.pm b/docs/tool/Modules/NaturalDocs/SourceDB/Item.pm new file mode 100644 index 00000000..6654465c --- /dev/null +++ b/docs/tool/Modules/NaturalDocs/SourceDB/Item.pm @@ -0,0 +1,201 @@ +############################################################################### +# +# Package: NaturalDocs::SourceDB::Item +# +############################################################################### +# +# A base class for something being tracked in . +# +############################################################################### + +# 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 to either -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 . You should not be calling them directly. Call functions +# like AddDefinition()> instead. +# + + +# +# Function: AddDefinition +# +# Adds a definition for the passed . If it's already defined, the new definition will be ignored. +# +# Parameters: +# +# file - The . +# definition - The definition, which must be an object derived from 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 . +# +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 . +# +# Parameters: +# +# file - The . +# definition - The definition, which must be an object derived from . +# +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 -derived object for the passed , 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 . 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 . +# +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 , and the values are +# either -derived objects or it's just an existence hashref if those aren't used. +# +sub GetAllDefinitionsHashRef + { + my $self = shift; + return $self->[DEFINITIONS]; + }; + + +1; -- cgit 1.4.1