1 %{ 2 #include "versekey.h" 3 #include "versificationmgr.h" 4 %} 5 6 7 %ignore sword::sbook::versemax; 8 %ignore sword::VerseKey::setBookAbbrevs; 9 %ignore sword::VerseKey::setBooks; 10 11 %ignore sword::VerseKey::builtin_BMAX; 12 %ignore sword::VerseKey::builtin_books; 13 %ignore sword::VerseKey::BMAX; 14 %ignore sword::VerseKey::books; 15 %ignore sword::VerseKey::VerseKey(SWKey const &); 16 17 %immutable sword::VerseKey::builtin_abbrevs; 18 %immutable sword::sbook::name; 19 %immutable sword::sbook::prefAbbrev; 20 %immutable sword::abbrev::ab; 21 22 %include "versekey.h" 23 %include "versificationmgr.h" 24 25 %extend sword::abbrev { getAbbrevCount()26 int getAbbrevCount() { 27 int abbrevsCnt; 28 for (abbrevsCnt = 0; *self[abbrevsCnt].ab; abbrevsCnt++) {} 29 return abbrevsCnt-1; 30 } 31 getAbbrevData(int i)32 const struct sword::abbrev* getAbbrevData(int i) { 33 return &(self[i]); 34 } 35 } 36 37 %extend sword::sbook { verseMax(int chapter)38 const int verseMax( int chapter ) { 39 if ( chapter > 0 && chapter < self->chapmax ) { 40 return self->versemax[chapter-1]; 41 } else { 42 return 0; 43 } 44 } 45 }; 46 47 48 49 %extend sword::VerseKey { 50 /* C++-style cast */ castTo(sword::SWKey * o)51 static sword::VerseKey *castTo(sword::SWKey *o) { 52 return dynamic_cast<sword::VerseKey*>(o); 53 } 54 55 56 /* Get number of books in the given testament 57 * testament may be 1 (OT) or 2 (NT) 58 */ 59 60 bookCount(const int testament)61 const int bookCount( const int testament ) { 62 if ( (testament < 1) || (testament > 2) ) { 63 return 0; 64 }; 65 return self->BMAX[testament-1]; 66 }; 67 68 getBookCount()69 const int getBookCount(){ 70 const sword::VersificationMgr::System* system = sword::VersificationMgr::getSystemVersificationMgr()->getVersificationSystem( 71 self->getVersificationSystem() 72 ); 73 return system->getBookCount(); 74 } 75 76 77 /* Get name of book 78 * Returns the name of the booknumber in the givn testament. 79 * Testament may be 1 (OT) or 2 (NT) 80 * book may be in the range of 1 <= bookCount(testament) 81 */ bookName(const int testament,const int book)82 const char* bookName( const int testament, const int book ) { 83 if ( (testament < 1) || (testament > 2) ) { 84 return 0; 85 }; 86 if ( (book < 1) || (book > self->BMAX[testament-1]) ) { 87 return 0; 88 } 89 90 const sword::VersificationMgr::System* system = sword::VersificationMgr::getSystemVersificationMgr()->getVersificationSystem( 91 self->getVersificationSystem() 92 ); 93 94 int book_num = (book - 1) + ( 95 (testament == 2) ? self->BMAX[0] : 0 96 ); 97 98 const sword::VersificationMgr::Book* b = system->getBook(book_num); 99 if(!b) { 100 fprintf(stderr, "b is null for %d?!?\n", book_num); 101 return 0; 102 } 103 return b->getLongName(); 104 105 106 }; 107 getBookNumberByOSISName(const char * bookname)108 int getBookNumberByOSISName( const char* bookname ) { 109 const sword::VersificationMgr::System* system = sword::VersificationMgr::getSystemVersificationMgr()->getVersificationSystem( 110 self->getVersificationSystem() 111 ); 112 return system->getBookNumberByOSISName(bookname); 113 } 114 getOSISBookName(const int book)115 const char* getOSISBookName( const int book ) { 116 const sword::VersificationMgr::System* system = sword::VersificationMgr::getSystemVersificationMgr()->getVersificationSystem( 117 self->getVersificationSystem() 118 ); 119 if ( (book < 0) || (book >= system->getBookCount())) 120 return 0; 121 122 return system->getBook(book)->getOSISName(); 123 } 124 125 126 127 /* Get number of chapters in the given testament and book number 128 * testament may be 1 (OT) or 2 (NT) 129 * book may be in the range 1 <= bookCount(testament) 130 */ chapterCount(const int testament,const int book)131 const int chapterCount( const int testament, const int book ) { 132 if ( (testament < 1) || (testament > 2) ) { 133 return 0; 134 }; 135 if ( (book < 1) || (book > self->BMAX[testament-1]) ) { 136 return 0; 137 } 138 139 const sword::VersificationMgr::System* system = sword::VersificationMgr::getSystemVersificationMgr()->getVersificationSystem( 140 self->getVersificationSystem() 141 ); 142 143 int book_num = (book - 1) + ( 144 (testament == 2) ? self->BMAX[0] : 0 145 ); 146 147 const sword::VersificationMgr::Book* b = system->getBook(book_num); 148 if(!b) { 149 fprintf(stderr, "b is null for %d?!?\n", book_num); 150 return 0; 151 } 152 153 return b->getChapterMax(); 154 }; 155 /* Get number of verses in the given chapter of the given in the given testament, 156 * testament may be 1 (OT) or 2 (NT) 157 * book may be in the range 1 <= bookCount(testament) 158 * chapter may be in the range 1 <= chapterCount(testament, book) 159 */ verseCount(const int testament,const int book,const int chapter)160 const int verseCount( const int testament, const int book, const int chapter ) { 161 if ( (testament < 1) || (testament > 2) ) { 162 return 0; 163 }; 164 if ( (book < 1) || (book > self->BMAX[testament-1]) ) { 165 return 0; 166 } 167 168 const sword::VersificationMgr::System* system = sword::VersificationMgr::getSystemVersificationMgr()->getVersificationSystem( 169 self->getVersificationSystem() 170 ); 171 172 int book_num = (book - 1) + ( 173 (testament == 2) ? self->BMAX[0] : 0 174 ); 175 176 const sword::VersificationMgr::Book* b = system->getBook(book_num); 177 if(!b) { 178 fprintf(stderr, "b is null for %d?!?\n", book_num); 179 return 0; 180 } 181 if ( (chapter < 1) || (chapter > b->getChapterMax()) ) { 182 return 0; 183 } 184 185 return b->getVerseMax(chapter); 186 187 }; 188 }; 189