/
GBModelBase.m
109 lines (88 loc) · 2.71 KB
/
GBModelBase.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//
// GBModelBase.m
// appledoc
//
// Created by Tomaz Kragelj on 28.7.10.
// Copyright (C) 2010, Gentle Bytes. All rights reserved.
//
#import "GBComment.h"
#import "GBSourceInfo.h"
#import "GBModelBase.h"
@implementation GBModelBase
#pragma mark Initialization & disposal
- (id)init {
self = [super init];
if (self) {
_sourceInfos = [[NSMutableSet alloc] init];
_sourceInfosByFilenames = [[NSMutableDictionary alloc] init];
_includeInOutput = YES;
}
return self;
}
#pragma mark Merging handling
- (void)mergeDataFromObject:(id)source {
NSParameterAssert([source isKindOfClass:[self class]]);
// Merge declared files.
NSArray *sourceFiles = [[source sourceInfos] allObjects];
for (GBSourceInfo *filedata in sourceFiles) {
GBSourceInfo *ourfiledata = _sourceInfosByFilenames[filedata.filename];
if (ourfiledata) {
if (ourfiledata.lineNumber < filedata.lineNumber) {
_sourceInfosByFilenames[filedata.filename] = filedata;
[_sourceInfos removeObject:ourfiledata];
[_sourceInfos addObject:filedata];
}
continue;
}
_sourceInfosByFilenames[filedata.filename] = filedata;
[_sourceInfos addObject:filedata];
}
// Merge comment.
GBComment *theComment = [(GBModelBase *)source comment];
if (self.comment && theComment) {
GBLogXInfo(self.prefferedSourceInfo, @"%@: Comment found in %@ and %@", self, self.comment.sourceInfo, theComment.sourceInfo);
return;
}
if (!self.comment && theComment) self.comment = theComment;
}
#pragma mark Source information handling
- (void)registerSourceInfo:(GBSourceInfo *)data {
NSParameterAssert(data != nil);
// Ignore already registered objects.
if ([_sourceInfos member:data]) return;
// Replace data with same filename.
GBSourceInfo *existing = _sourceInfosByFilenames[data.filename];
if (existing) [_sourceInfos removeObject:existing];
// Add object.
_sourceInfosByFilenames[data.filename] = data;
[_sourceInfos addObject:data];
}
- (GBSourceInfo *)prefferedSourceInfo {
if (self.comment && self.comment.sourceInfo) return self.comment.sourceInfo;
if ([self.sourceInfos count] > 0) {
NSArray *infos = [self sourceInfosSortedByName];
for (GBSourceInfo *info in infos) {
if ([[info.filename pathExtension] isEqualToString:@"h"]) return info;
}
return infos[0];
}
return nil;
}
- (NSArray *)sourceInfosSortedByName {
return [[self.sourceInfos allObjects] sortedArrayUsingSelector:@selector(compare:)];
}
#pragma Helper methods
- (BOOL)isStaticDocument {
return NO;
}
- (BOOL)isTopLevelObject {
return NO;
}
#pragma mark Properties
@synthesize comment;
@synthesize sourceInfos = _sourceInfos;
@synthesize parentObject;
@synthesize htmlLocalReference;
@synthesize htmlReferenceName;
@synthesize includeInOutput = _includeInOutput;
@end