OSDN Git Service

Version 5.91
[vbslib/main.git] / GPL_bin_fullset / NaturalDocs / Modules / NaturalDocs / ClassHierarchy / File.pm
1 ###############################################################################
2 #
3 #   Class: NaturalDocs::ClassHierarchy::File
4 #
5 ###############################################################################
6 #
7 #   An object that stores information about what hierarchy information is present in a file.  It does not store its <FileName>; it
8 #   assumes that it will be stored in a hashref where the key is the <FileName>.
9 #
10 ###############################################################################
11
12 # This file is part of Natural Docs, which is Copyright © 2003-2010 Greg Valure
13 # Natural Docs is licensed under version 3 of the GNU Affero General Public License (AGPL)
14 # Refer to License.txt for the complete details
15
16 use strict;
17 use integer;
18
19 package NaturalDocs::ClassHierarchy::File;
20
21
22 #
23 #   Topic: Implementation
24 #
25 #   Since there's only one member in the class, and it's a hashref, the class is simply the hashref itself blessed as a class.
26 #   The keys are the class <SymbolStrings> that are defined in the file, and the values are existence hashrefs of each class'
27 #   parent <ReferenceStrings>, or undef if none.
28 #
29
30
31 ###############################################################################
32 # Group: Modification Functions
33
34
35 #
36 #   Function: New
37 #
38 #   Creates and returns a new class.
39 #
40 sub New
41     {
42     my ($package) = @_;
43
44     my $object = { };
45     bless $object, $package;
46
47     return $object;
48     };
49
50 #
51 #   Function: AddClass
52 #   Adds a rew class <SymbolString> to the file.
53 #
54 sub AddClass #(class)
55     {
56     my ($self, $class) = @_;
57
58     if (!exists $self->{$class})
59         {  $self->{$class} = undef;  };
60     };
61
62 #
63 #   Function: DeleteClass
64 #   Deletes a class <SymbolString> from the file.
65 #
66 sub DeleteClass #(class)
67     {
68     my ($self, $class) = @_;
69     delete $self->{$class};
70     };
71
72 #
73 #   Function: AddParentReference
74 #   Adds a parent <ReferenceString> to a class <SymbolString>.
75 #
76 sub AddParentReference #(class, parentReference)
77     {
78     my ($self, $class, $parent) = @_;
79
80     if (!exists $self->{$class} || !defined $self->{$class})
81         {  $self->{$class} = { };  };
82
83     $self->{$class}->{$parent} = 1;
84     };
85
86 #
87 #   Function: DeleteParentReference
88 #   Deletes a parent <ReferenceString> from a class <SymbolString>.
89 #
90 sub DeleteParentReference #(class, parent)
91     {
92     my ($self, $class, $parent) = @_;
93
94     if (exists $self->{$class})
95         {
96         delete $self->{$class}->{$parent};
97
98         if (!scalar keys %{$self->{$class}})
99             {  $self->{$class} = undef;  };
100         };
101     };
102
103
104
105 ###############################################################################
106 # Group: Information Functions
107
108
109 #
110 #   Function: Classes
111 #   Returns an array of the class <SymbolStrings> that are defined by this file, or an empty array if none.
112 #
113 sub Classes
114     {
115     my ($self) = @_;
116     return keys %{$self};
117     };
118
119 #
120 #   Function: HasClass
121 #   Returns whether the file defines the passed class <SymbolString>.
122 #
123 sub HasClass #(class)
124     {
125     my ($self, $class) = @_;
126     return exists $self->{$class};
127     };
128
129 #
130 #   Function: ParentReferencesOf
131 #   Returns an array of the parent <ReferenceStrings> that are defined by the class, or an empty array if none.
132 #
133 sub ParentReferencesOf #(class)
134     {
135     my ($self, $class) = @_;
136
137     if (!exists $self->{$class} || !defined $self->{$class})
138         {  return ( );  }
139     else
140         {  return keys %{$self->{$class}};  };
141     };
142
143 #
144 #   Function: HasParentReference
145 #   Returns whether the file defines the passed class <SymbolString> and parent <ReferenceString>.
146 #
147 sub HasParentReference #(class, parent)
148     {
149     my ($self, $class, $parent) = @_;
150
151     if (!$self->HasClass($class))
152         {  return undef;  };
153
154     return exists $self->{$class}->{$parent};
155     };
156
157
158 1;