#include <versemgr.h>

Classes | |
| class | Private |
Public Member Functions | |
| const int * | getBMAX () const |
| const Book * | getBook (int number) const |
| const Book * | getBookByName (const char *bookName) const |
| int | getBookCount () const |
| int | getBookNumberByOSISName (const char *bookName) const |
| const char * | getName () const |
| long | getNTStartOffset () const |
| long | getOffsetFromVerse (int book, int chapter, int verse) const |
| char | getVerseFromOffset (long offset, int *book, int *chapter, int *verse) const |
| void | loadFromSBook (const sbook *ot, const sbook *nt, int *chMax) |
| System & | operator= (const System &other) |
| System (const char *name) | |
| System (const System &other) | |
| System () | |
| ~System () | |
Private Member Functions | |
| void | init () |
Private Attributes | |
| int | BMAX [2] |
| SWBuf | name |
| long | ntStartOffset |
| Private * | p |
Definition at line 126 of file versemgr.h.
| VerseMgr::System::System | ( | ) | [inline] |
Definition at line 134 of file versemgr.h.
| VerseMgr::System::System | ( | const System & | other | ) |
Definition at line 137 of file versemgr.cpp.
00137 { 00138 init(); 00139 name = other.name; 00140 BMAX[0] = other.BMAX[0]; 00141 BMAX[1] = other.BMAX[1]; 00142 (*p) = *(other.p); 00143 ntStartOffset = other.ntStartOffset; 00144 }
| VerseMgr::System::System | ( | const char * | name | ) | [inline] |
Definition at line 137 of file versemgr.h.
| VerseMgr::System::~System | ( | ) |
Definition at line 156 of file versemgr.cpp.
00156 { 00157 delete p; 00158 }
| const int* VerseMgr::System::getBMAX | ( | ) | const [inline] |
Definition at line 147 of file versemgr.h.
00147 { return BMAX; };
| const VerseMgr::Book * VerseMgr::System::getBook | ( | int | number | ) | const |
| const Book* VerseMgr::System::getBookByName | ( | const char * | bookName | ) | const |
| int VerseMgr::System::getBookCount | ( | ) | const |
Definition at line 245 of file versemgr.cpp.
| int VerseMgr::System::getBookNumberByOSISName | ( | const char * | bookName | ) | const |
Definition at line 165 of file versemgr.cpp.
00165 { 00166 map<SWBuf, int>::const_iterator it = p->osisLookup.find(bookName); 00167 return (it != p->osisLookup.end()) ? it->second : -1; 00168 }
| const char* VerseMgr::System::getName | ( | ) | const [inline] |
Definition at line 139 of file versemgr.h.
| long VerseMgr::System::getNTStartOffset | ( | ) | const [inline] |
Definition at line 148 of file versemgr.h.
00148 { return ntStartOffset; }
| long VerseMgr::System::getOffsetFromVerse | ( | int | book, | |
| int | chapter, | |||
| int | verse | |||
| ) | const |
Definition at line 250 of file versemgr.cpp.
00250 { 00251 long offset = -1; 00252 chapter--; 00253 00254 const Book *b = getBook(book); 00255 00256 if (!b) return -1; // assert we have a valid book 00257 if ((chapter > -1) && (chapter >= (signed int)b->p->offsetPrecomputed.size())) return -1; // assert we have a valid chapter 00258 00259 offset = b->p->offsetPrecomputed[(chapter > -1)?chapter:0]; 00260 if (chapter < 0) offset--; 00261 00262 /* old code 00263 * 00264 offset = offsets[testament-1][0][book]; 00265 offset = offsets[testament-1][1][(int)offset + chapter]; 00266 if (!(offset|verse)) // if we have a testament but nothing else. 00267 offset = 1; 00268 00269 */ 00270 00271 return (offset + verse); 00272 }
| char VerseMgr::System::getVerseFromOffset | ( | long | offset, | |
| int * | book, | |||
| int * | chapter, | |||
| int * | verse | |||
| ) | const |
Definition at line 275 of file versemgr.cpp.
00275 { 00276 00277 if (offset < 1) { // just handle the module heading corner case up front (and error case) 00278 (*book) = -1; 00279 (*chapter) = 0; 00280 (*verse) = 0; 00281 return offset; // < 0 = error 00282 } 00283 00284 // binary search for book 00285 vector<Book>::iterator b = lower_bound(p->books.begin(), p->books.end(), offset, BookOffsetLess()); 00286 if (b == p->books.end()) b--; 00287 (*book) = distance(p->books.begin(), b)+1; 00288 if (offset < (*(b->p->offsetPrecomputed.begin()))-((((!(*book)) || (*book)==BMAX[0]+1))?2:1)) { // -1 for chapter headings 00289 (*book)--; 00290 if (b != p->books.begin()) { 00291 b--; 00292 } 00293 } 00294 vector<long>::iterator c = lower_bound(b->p->offsetPrecomputed.begin(), b->p->offsetPrecomputed.end(), offset); 00295 00296 // if we're a book heading, we are lessthan chapter precomputes, but greater book. This catches corner case. 00297 if (c == b->p->offsetPrecomputed.end()) { 00298 c--; 00299 } 00300 if ((offset < *c) && (c == b->p->offsetPrecomputed.begin())) { 00301 (*chapter) = (offset - *c)+1; // should be 0 or -1 (for testament heading) 00302 (*verse) = 0; 00303 } 00304 else { 00305 if (offset < *c) c--; 00306 (*chapter) = distance(b->p->offsetPrecomputed.begin(), c)+1; 00307 (*verse) = (offset - *c); 00308 } 00309 return ((*chapter > 0) && (*verse > b->getVerseMax(*chapter))) ? KEYERR_OUTOFBOUNDS : 0; 00310 }
| void VerseMgr::System::init | ( | ) | [private] |
Definition at line 129 of file versemgr.cpp.
00129 { 00130 p = new Private(); 00131 BMAX[0] = 0; 00132 BMAX[1] = 0; 00133 ntStartOffset = 0; 00134 }
Definition at line 171 of file versemgr.cpp.
00171 { 00172 int chap = 0; 00173 int book = 0; 00174 long offset = 0; // module heading 00175 offset++; // testament heading 00176 while (ot->chapmax) { 00177 p->books.push_back(Book(ot->name, ot->osis, ot->prefAbbrev, ot->chapmax)); 00178 offset++; // book heading 00179 Book &b = p->books[p->books.size()-1]; 00180 p->osisLookup[b.getOSISName()] = p->books.size(); 00181 for (int i = 0; i < ot->chapmax; i++) { 00182 b.p->verseMax.push_back(chMax[chap]); 00183 offset++; // chapter heading 00184 b.p->offsetPrecomputed.push_back(offset); 00185 offset += chMax[chap++]; 00186 } 00187 ot++; 00188 book++; 00189 } 00190 BMAX[0] = book; 00191 book = 0; 00192 ntStartOffset = offset; 00193 offset++; // testament heading 00194 while (nt->chapmax) { 00195 p->books.push_back(Book(nt->name, nt->osis, nt->prefAbbrev, nt->chapmax)); 00196 offset++; // book heading 00197 Book &b = p->books[p->books.size()-1]; 00198 p->osisLookup[b.getOSISName()] = p->books.size(); 00199 for (int i = 0; i < nt->chapmax; i++) { 00200 b.p->verseMax.push_back(chMax[chap]); 00201 offset++; // chapter heading 00202 b.p->offsetPrecomputed.push_back(offset); 00203 offset += chMax[chap++]; 00204 } 00205 nt++; 00206 book++; 00207 } 00208 BMAX[1] = book; 00209 00210 // TODO: build offset speed array 00211 }
| VerseMgr::System & VerseMgr::System::operator= | ( | const System & | other | ) |
Definition at line 146 of file versemgr.cpp.
00146 { 00147 name = other.name; 00148 BMAX[0] = other.BMAX[0]; 00149 BMAX[1] = other.BMAX[1]; 00150 (*p) = *(other.p); 00151 ntStartOffset = other.ntStartOffset; 00152 return *this; 00153 }
int VerseMgr::System::BMAX[2] [private] |
Definition at line 130 of file versemgr.h.
SWBuf VerseMgr::System::name [private] |
Definition at line 129 of file versemgr.h.
long VerseMgr::System::ntStartOffset [private] |
Definition at line 131 of file versemgr.h.
Private* VerseMgr::System::p [private] |
Definition at line 127 of file versemgr.h.
1.6.1