1 ###############################################################################
3 # Package: NaturalDocs::Topics::Type
5 ###############################################################################
7 # A class storing information about a <TopicType>.
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
19 package NaturalDocs::Topics::Type;
21 use NaturalDocs::DefineMembers 'NAME', 'Name()',
22 'PLURAL_NAME', 'PluralName()', 'SetPluralName()',
23 'INDEX', 'Index()', 'SetIndex()',
24 'SCOPE', 'Scope()', 'SetScope()',
25 'PAGE_TITLE_IF_FIRST', 'PageTitleIfFirst()', 'SetPageTitleIfFirst()',
26 'BREAK_LISTS', 'BreakLists()', 'SetBreakLists()',
27 'CLASS_HIERARCHY', 'ClassHierarchy()', 'SetClassHierarchy()',
30 # Dependency: New() depends on the order of these and that there are no parent classes.
33 our @EXPORT = ('SCOPE_NORMAL', 'SCOPE_START', 'SCOPE_END', 'SCOPE_ALWAYS_GLOBAL');
38 # The object is implemented as a blessed arrayref, with the following constants as its indexes.
40 # NAME - The topic's name.
41 # PLURAL_NAME - The topic's plural name.
42 # INDEX - Whether the topic is indexed.
43 # SCOPE - The topic's <ScopeType>.
44 # PAGE_TITLE_IF_FIRST - Whether the topic becomes the page title if it's first in a file.
45 # BREAK_LISTS - Whether list topics should be broken into individual topics in the output.
46 # CLASS_HIERARCHY - Whether the topic is part of the class hierarchy.
47 # CAN_GROUP_WITH - The existence hashref of <TopicTypes> the type can be grouped with.
52 ###############################################################################
57 # Constants: ScopeType
59 # The possible values for <Scope()>.
61 # SCOPE_NORMAL - The topic stays in the current scope without affecting it.
62 # SCOPE_START - The topic starts a scope.
63 # SCOPE_END - The topic ends a scope, returning it to global.
64 # SCOPE_ALWAYS_GLOBAL - The topic is always global, but it doesn't affect the current scope.
66 use constant SCOPE_NORMAL => 1;
67 use constant SCOPE_START => 2;
68 use constant SCOPE_END => 3;
69 use constant SCOPE_ALWAYS_GLOBAL => 4;
73 ###############################################################################
80 # Creates and returns a new object.
84 # name - The topic name.
85 # pluralName - The topic's plural name.
86 # index - Whether the topic is indexed.
87 # scope - The topic's <ScopeType>.
88 # pageTitleIfFirst - Whether the topic becomes the page title if it's the first one in a file.
89 # breakLists - Whether list topics should be broken into individual topics in the output.
91 sub New #(name, pluralName, index, scope, pageTitleIfFirst, breakLists)
93 my ($self, @params) = @_;
95 # Dependency: Depends on the parameter order matching the member order and that there are no parent classes.
97 my $object = [ @params ];
105 # Functions: Accessors
107 # Name - Returns the topic name.
108 # PluralName - Returns the topic's plural name.
109 # SetPluralName - Replaces the topic's plural name.
110 # Index - Whether the topic is indexed.
111 # SetIndex - Sets whether the topic is indexed.
112 # Scope - Returns the topic's <ScopeType>.
113 # SetScope - Replaces the topic's <ScopeType>.
114 # PageTitleIfFirst - Returns whether the topic becomes the page title if it's first in the file.
115 # SetPageTitleIfFirst - Sets whether the topic becomes the page title if it's first in the file.
116 # BreakLists - Returns whether list topics should be broken into individual topics in the output.
117 # SetBreakLists - Sets whether list topics should be broken into individual topics in the output.
118 # ClassHierarchy - Returns whether the topic is part of the class hierarchy.
119 # SetClassHierarchy - Sets whether the topic is part of the class hierarchy.
124 # Function: CanGroupWith
126 # Returns whether the type can be grouped with the passed <TopicType>.
128 sub CanGroupWith #(TopicType type) -> bool
130 my ($self, $type) = @_;
131 return ( defined $self->[CAN_GROUP_WITH] && exists $self->[CAN_GROUP_WITH]->{$type} );
136 # Function: SetCanGroupWith
138 # Sets the list of <TopicTypes> the type can be grouped with.
140 sub SetCanGroupWith #(TopicType[] types)
142 my ($self, $types) = @_;
144 $self->[CAN_GROUP_WITH] = { };
146 foreach my $type (@$types)
147 { $self->[CAN_GROUP_WITH]->{$type} = 1; };