blob: eeb956b7df01cef5b283529acd05ad3a15e83072 (
plain)
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
110
111
112
|
//
// SwordBibleBook.m
// MacSword2
//
// Created by Manfred Bergmann on 18.02.09.
// Copyright 2009 __MyCompanyName__. All rights reserved.
//
#import "SwordBibleBook.h"
#import "SwordBibleChapter.h"
@implementation SwordBibleBook
@synthesize number;
@synthesize numberInTestament;
@synthesize testament;
@synthesize localizedName;
@dynamic chapters;
- (id)init {
self = [super init];
if(self) {
self.number = 0;
self.numberInTestament = 0;
self.testament = 0;
self.localizedName = @"";
self.chapters = nil;
}
return self;
}
- (id)initWithBook:(sword::VersificationMgr::Book *)aBook {
self = [self init];
if(self) {
swBook = aBook;
sword::VerseKey vk = sword::VerseKey(aBook->getOSISName());
[self setTestament:vk.Testament()];
[self setNumberInTestament:vk.Book()];
// get system localeMgr to be able to translate the english bookName
sword::LocaleMgr *lmgr = sword::LocaleMgr::getSystemLocaleMgr();
self.localizedName = [NSString stringWithUTF8String:lmgr->translate(swBook->getLongName())];
}
return self;
}
- (void)finalize {
[super finalize];
}
- (void)dealloc {
[self setLocalizedName:nil];
[self setChapters:nil];
[super dealloc];
}
- (NSString *)name {
return [NSString stringWithUTF8String:swBook->getLongName()];
}
- (NSString *)osisName {
return [NSString stringWithUTF8String:swBook->getOSISName()];
}
- (int)numberOfChapters {
return swBook->getChapterMax();
}
- (int)numberOfVersesForChapter:(int)chapter {
return swBook->getVerseMax(chapter);
}
- (void)setChapters:(NSArray *)anArray {
[anArray retain];
[chapters release];
chapters = anArray;
}
- (NSArray *)chapters {
if(chapters == nil) {
NSMutableArray *temp = [NSMutableArray array];
for(int i = 0;i < swBook->getChapterMax();i++) {
[temp addObject:[[[SwordBibleChapter alloc] initWithBook:self andChapter:i+1] autorelease]];
}
[self setChapters:[NSArray arrayWithArray:temp]];
}
return chapters;
}
/**
get book index for verseKey
that is: book number + testament * 100
*/
- (int)generatedIndex {
return number + testament * 100;
}
- (sword::VersificationMgr::Book *)book {
return swBook;
}
/** we implement this for sorting */
- (NSComparisonResult)compare:(SwordBibleBook *)b {
return [[NSNumber numberWithInt:number] compare:[NSNumber numberWithInt:[b number]]];
}
@end
|