1 ###############################################################################
3 # Class: NaturalDocs::Project::ImageFile
5 ###############################################################################
7 # A simple information class about project image files.
9 ###############################################################################
11 # This file is part of Natural Docs, which is Copyright © 2003-2010 Greg Valure
12 # Natural Docs is licensed under version 3 of the GNU Affero General Public License (AGPL)
13 # Refer to License.txt for the complete details
18 package NaturalDocs::Project::ImageFile;
22 ###############################################################################
23 # Group: Implementation
28 # The class is implemented as a blessed arrayref. The following constants are used as indexes.
30 # LAST_MODIFIED - The integer timestamp of when the file was last modified.
31 # STATUS - <FileStatus> since the last build.
32 # REFERENCE_COUNT - The number of references to the image from the source files.
33 # WAS_USED - Whether the image was used the last time Natural Docs was run.
34 # WIDTH - The image width. Undef if can't be determined, -1 if haven't attempted to determine yet.
35 # HEIGHT - The image height. Undef if can't be determined, -1 if haven't attempted to determine yet.
38 use NaturalDocs::DefineMembers 'LAST_MODIFIED', 'LastModified()', 'SetLastModified()',
39 'STATUS', 'Status()', 'SetStatus()',
40 'REFERENCE_COUNT', 'ReferenceCount()',
41 'WAS_USED', 'WasUsed()', 'SetWasUsed()',
47 # Topic: WasUsed versus References
49 # <WasUsed()> is a simple true/false that notes whether this image file was used the last time Natural Docs was run.
50 # <ReferenceCount()> is a counter for the number of times it's used *this* run. As such, it starts at zero regardless of whether
51 # <WasUsed()> is set or not.
55 ###############################################################################
61 # Creates and returns a new file object.
65 # lastModified - The image file's last modification timestamp
66 # status - The <FileStatus>.
67 # wasUsed - Whether this image file was used the *last* time Natural Docs was run.
69 sub New #(timestamp lastModified, FileStatus status, bool wasUsed)
71 my ($package, $lastModified, $status, $width, $height, $wasUsed) = @_;
74 $object->[LAST_MODIFIED] = $lastModified;
75 $object->[STATUS] = $status;
76 $object->[REFERENCE_COUNT] = 0;
77 $object->[WAS_USED] = $wasUsed;
78 $object->[WIDTH] = -1;
79 $object->[HEIGHT] = -1;
81 bless $object, $package;
88 # Functions: Member Functions
90 # LastModified - Returns the integer timestamp of when the file was last modified.
91 # SetLastModified - Sets the file's last modification timestamp.
92 # Status - Returns the <FileStatus> since the last build.
93 # SetStatus - Sets the <FileStatus> since the last build.
97 # Function: ReferenceCount
98 # Returns the current number of references to this image file during *this* Natural Docs execution.
102 # Function: AddReference
103 # Increases the number of references to this image file by one. Returns the new reference count.
109 $self->[REFERENCE_COUNT]++;
110 return $self->[REFERENCE_COUNT];
114 # Function: DeleteReference
115 # Decreases the number of references to this image file by one. Returns the new reference count.
120 $self->[REFERENCE_COUNT]--;
122 if ($self->[REFERENCE_COUNT] < 0)
123 { die "Deleted more references to an image file than existed."; };
125 return $self->[REFERENCE_COUNT];
130 # Functions: Member Functions
132 # WasUsed - Returns whether this image file was used during the *last* Natural Docs execution.
133 # SetWasUsed - Sets whether this image file was used during the *last* Natural Docs execution.
134 # Width - Returns the width in pixels, undef if it can't be determined, and -1 if determination hasn't been attempted yet.
135 # Height - Returns the width in pixels, undef if it can't be determined, and -1 if determination hasn't been attempted yet.
140 # Function: SetDimensions
141 # Sets the width and height of the image. Set to undef if they can't be determined.
143 sub SetDimensions #(int width, int height)
145 my ($self, $width, $height) = @_;
147 # If either are undef, both should be undef. This will also convert zeroes to undef.
148 if (!$width || !$height)
150 $self->[WIDTH] = undef;
151 $self->[HEIGHT] = undef;
155 $self->[WIDTH] = $width;
156 $self->[HEIGHT] = $height;