diff options
Diffstat (limited to 'bindings/objc/src/SwordVerseManager.mm')
-rw-r--r-- | bindings/objc/src/SwordVerseManager.mm | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/bindings/objc/src/SwordVerseManager.mm b/bindings/objc/src/SwordVerseManager.mm new file mode 100644 index 0000000..a9bc12b --- /dev/null +++ b/bindings/objc/src/SwordVerseManager.mm @@ -0,0 +1,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 |