summaryrefslogtreecommitdiff
path: root/bindings/objc/src/SwordVerseManager.mm
blob: a9bc12bd314f0fd8c10eb0ff72215ffe77516bf2 (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
//
//  SwordVerseManager.m
//  MacSword2
//
//  Created by Manfred Bergmann on 19.03.09.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "SwordVerseManager.h"
#import "SwordBibleBook.h"


@interface SwordVerseManager ()

@property (retain, readwrite) NSMutableDictionary *booksPerVersification;

@end

@implementation SwordVerseManager

@synthesize booksPerVersification;

+ (SwordVerseManager *)defaultManager {
    static SwordVerseManager *singleton;
    if(!singleton) {
        singleton = [[SwordVerseManager alloc] init];
    }
    
    return singleton;
}

- (id)init {
    self = [super init];
    if(self) {
        self.booksPerVersification = [NSMutableDictionary dictionary];
        verseMgr = sword::VerseMgr::getSystemVerseMgr();
    }
    
    return self;
}

- (void)finalize {
    [super finalize];
}

- (void)dealloc {
    [self setBooksPerVersification:nil];
    
    [super dealloc];
}

/** convenience method that returns the books for default scheme (KJV) */
- (NSArray *)books {
    return [self booksForVersification:SW_VERSIFICATION_KJV];
}

/** books for a versification scheme */
- (NSArray *)booksForVersification:(NSString *)verseScheme {
    NSArray *ret = [booksPerVersification objectForKey:verseScheme];
    if(ret == nil) {
        // hasn't been initialized yet
        const sword::VerseMgr::System *system = verseMgr->getVersificationSystem([verseScheme UTF8String]);
        int bookCount = system->getBookCount();
        NSMutableArray *buf = [NSMutableArray arrayWithCapacity:bookCount];
        for(int i = 0;i < bookCount;i++) {
            sword::VerseMgr::Book *book = (sword::VerseMgr::Book *)system->getBook(i);
            
            SwordBibleBook *bb = [[SwordBibleBook alloc] initWithBook:book];
            [bb setNumber:i+1]; // VerseKey-Book() starts at index 1
            
            // add to array
            [buf addObject:bb];
        }
        [booksPerVersification setObject:buf forKey:verseScheme];
        ret = buf;
    }
    
    return ret;
}

- (sword::VerseMgr *)verseMgr {
    return verseMgr;
}

@end