55 using std::lower_bound;
152 bool operator() (
const long &o1,
const long &o2)
const {
return o1 < o2; }
172 BMAX[0] = other.
BMAX[0];
173 BMAX[1] = other.
BMAX[1];
181 BMAX[0] = other.
BMAX[0];
182 BMAX[1] = other.
BMAX[1];
195 return (number < (
signed int)
p->books.size()) ? &(
p->books[number]) : 0;
200 map<SWBuf, int>::const_iterator it =
p->osisLookup.find(bookName);
201 return (it !=
p->osisLookup.end()) ? it->second : -1;
213 Book &b =
p->books[
p->books.size()-1];
215 for (
int i = 0; i < ot->
chapmax; i++) {
216 b.
p->verseMax.push_back(chMax[chap]);
218 b.
p->offsetPrecomputed.push_back(offset);
219 offset += chMax[chap++];
226 ntStartOffset = offset;
231 Book &b =
p->books[
p->books.size()-1];
233 for (
int i = 0; i < nt->
chapmax; i++) {
234 b.
p->verseMax.push_back(chMax[chap]);
236 b.
p->offsetPrecomputed.push_back(offset);
237 offset += chMax[chap++];
247 if (mappings !=
NULL) {
248 const unsigned char *
m=mappings;
249 for (; *m != 0; m += strlen((
const char*)m)+1) {
250 p->mappingsExtraBooks.push_back((
const char*)m);
252 p->mappings.resize(
p->books.size()+
p->mappingsExtraBooks.size());
254 for (++m; *m != 0; m += 7) {
255 p->mappings[m[0]-1].push_back(m);
256 if (*m >
p->books.size()) {
257 p->mappings[m[7]-1].push_back(m);
293 return (
p && (chapter < (
signed int)
p->verseMax.size()) && (chapter > -1)) ?
p->verseMax[chapter] : -1;
298 return (
int)(
p ?
p->books.size() : 0);
306 const Book *b = getBook(book);
309 if ((chapter > -1) && (chapter >= (
signed int)b->
p->offsetPrecomputed.size()))
return -1;
311 offset = b->
p->offsetPrecomputed[(chapter > -1)?chapter:0];
312 if (chapter < 0) offset--;
323 return (offset + verse);
337 vector<Book>::iterator b = lower_bound(
p->books.begin(),
p->books.end(), offset,
BookOffsetLess());
338 if (b ==
p->books.end()) b--;
339 (*book) = distance(
p->books.begin(), b)+1;
340 if (offset < (*(b->p->offsetPrecomputed.begin()))-((((!(*book)) || (*book)==BMAX[0]+1))?2:1)) {
342 if (b !=
p->books.begin()) {
346 vector<long>::iterator c = lower_bound(b->p->offsetPrecomputed.begin(), b->p->offsetPrecomputed.end(), offset);
349 if (c == b->p->offsetPrecomputed.end()) {
352 if ((offset < *c) && (c == b->p->offsetPrecomputed.begin())) {
353 (*chapter) = (offset - *c)+1;
357 if (offset < *c) c--;
358 (*chapter) = distance(b->p->offsetPrecomputed.begin(), c)+1;
359 (*verse) = (offset - *c);
361 return ((*chapter > 0) && (*verse > b->getVerseMax(*chapter))) ?
KEYERR_OUTOFBOUNDS : 0;
410 map<SWBuf, System>::const_iterator it =
p->
systems.find(name);
411 return (it !=
p->
systems.end()) ? &(it->second) : 0;
428 for (map<SWBuf, System>::const_iterator it =
p->
systems.begin(); it !=
p->
systems.end(); it++) {
429 retVal.push_back(it->first);
437 if (!strcmp(getName(),
"KJVA") || !strcmp(getName(),
"KJV")) {
438 if (!strcmp(dstSys->
getName(),
"KJVA") || !strcmp(dstSys->
getName(),
"KJV"))
448 for (
int i=0; i<(int)dstSys->
p->mappingsExtraBooks.size(); ++i) {
450 if (!strcmp(*book, dstSys->
p->mappingsExtraBooks[i])) {
451 b = (int)
p->books.size()+i-2;
459 if (b >= (
int)dstSys->
p->mappings.size() || b < 0) {
464 const unsigned char *a =
NULL;
467 for (
unsigned int i=0; i<dstSys->
p->mappings[b].size(); ++i) {
468 const unsigned char *
m = dstSys->
p->mappings[b][i];
470 if (m[0] != b+1)
continue;
472 if (m[4] == *chapter && m[5] <= *verse) {
474 if (m[5] == *verse || (m[6] >= *verse && m[5] <= *verse)) {
479 if (*m >= dstSys->
p->books.size()) {
486 if (a ==
NULL || (a[5]>a[6]?a[5]:a[6]) <= (m[5]>m[6]?m[5]:m[6]))
494 const int d = (a[3]>a[2]?a[3]:a[2])-(a[6]>a[5]?a[6]:a[5]);
495 if (*verse < *verse_end)
498 *verse_end = (*verse) + d;
500 if (*a > dstSys->
p->books.size()) {
509 else if (strcmp(dstSys->
getName(),
"KJVA") && strcmp(dstSys->
getName(),
"KJV")) {
511 const int src_verse = *verse;
513 translateVerse(kjva, book, chapter, verse, verse_end);
515 int interm_verse = *verse, interm_range = *verse_end, interm_chapter = *chapter;
516 const char *interm_book = *book;
521 if (verse < verse_end && !(interm_verse < interm_range)) {
522 kjva->
translateVerse(
this, &interm_book, &interm_chapter, &interm_verse, &interm_range);
523 if (interm_verse < interm_range) {
524 *verse += src_verse - interm_verse;
525 if (*verse > *verse_end)
534 const int b = getBookNumberByOSISName(*book)-1;
535 if (b >= (
int)
p->mappings.size())
538 for (
int i = (
int)
p->mappings[b].size()-1; i>=0; --i) {
539 const unsigned char *
m =
p->mappings[b][i];
540 if (m[1] < *chapter) {
544 if (m[1] == *chapter && m[2] <= *verse) {
546 if (m[2] == *verse || (m[3] >= *verse && m[2] <= *verse)) {
554 const int d = (m[6]>m[5]?m[6]:m[5])-(m[3]>m[2]?m[3]:m[2]);
555 if (*verse < *verse_end)
558 *verse_end = (*verse) + d;
561 if (*m >
p->books.size())
562 *book =
p->mappingsExtraBooks[m[0]-
p->books.size()-1];
SWORD_NAMESPACE_START int vm_nrsv[]
#define SWORD_NAMESPACE_START
SWORD_NAMESPACE_START struct sbook otbooks_german[]
SWORD_NAMESPACE_START struct sbook otbooks_luther[]
map< SWBuf, int > osisLookup
Book & operator=(const Book &other)
unsigned char mappings_synodal[]
long getOffsetFromVerse(int book, int chapter, int verse) const
static SWLog * getSystemLog()
SWORD_NAMESPACE_START struct sbook otbooks_lxx[]
unsigned char mappings_nrsv[]
Private(const VersificationMgr::Private &other)
SWORD_NAMESPACE_START int vm_segond[]
SWORD_NAMESPACE_START struct sbook otbooks_kjva[]
class __staticsystemVersificationMgr _staticsystemVersificationMgr
Private(const VersificationMgr::System::Private &other)
SWORD_NAMESPACE_START struct sbook otbooks_catholic2[]
vector< mappingRule > mappings
unsigned char mappings_segond[]
void loadFromSBook(const sbook *ot, const sbook *nt, int *chMax, const unsigned char *mappings=NULL)
unsigned char mappings_calvin[]
SWORD_NAMESPACE_START struct sbook otbooks[]
struct sbook ntbooks_synodal[]
char getVerseFromOffset(long offset, int *book, int *chapter, int *verse) const
const Book * getBook(int number) const
~__staticsystemVersificationMgr()
System & operator=(const System &other)
void registerVersificationSystem(const char *name, const sbook *ot, const sbook *nt, int *chMax, const unsigned char *mappings=NULL)
SWORD_NAMESPACE_START struct sbook otbooks_nrsva[]
struct sbook ntbooks_luther[]
std::list< SWBuf > StringList
map< SWBuf, System > systems
SWORD_NAMESPACE_START struct sbook otbooks_vulg[]
SWORD_NAMESPACE_START struct sbook otbooks_orthodox[]
SWORD_NAMESPACE_START struct sbook otbooks_leningrad[]
VersificationMgr::System::Private & operator=(const VersificationMgr::System::Private &other)
vector< const unsigned char * > mappingRule
void translateVerse(const System *dstSys, const char **book, int *chapter, int *verse, int *verse_end) const
SWORD_NAMESPACE_START int vm_calvin[]
int getBookNumberByOSISName(const char *bookName) const
const StringList getVersificationSystems() const
#define KEYERR_OUTOFBOUNDS
const char * getOSISName() const
const char * getName() const
static void setSystemVersificationMgr(VersificationMgr *newVersificationMgr)
vector< long > offsetPrecomputed
SWORD_NAMESPACE_START struct sbook otbooks_mt[]
void logWarning(const char *fmt,...) const
struct sbook ntbooks_vulg[]
SWORD_NAMESPACE_START struct sbook otbooks_synodalProt[]
SWORD_NAMESPACE_START int vm_darbyfr[]
static VersificationMgr * systemVersificationMgr
int getVerseMax(int chapter) const
vector< const char * > mappingsExtraBooks
SWORD_NAMESPACE_START struct sbook otbooks_synodal[]
unsigned char mappings_vulg[]
#define SWORD_NAMESPACE_END
bool operator()(const VersificationMgr::Book &o1, const VersificationMgr::Book &o2) const
VersificationMgr::Book::Private & operator=(const VersificationMgr::Book::Private &other)
Private(const VersificationMgr::Book::Private &other)
static VersificationMgr * getSystemVersificationMgr()
__staticsystemVersificationMgr()
const System * getVersificationSystem(const char *name) const
struct sbook ntbooks_null[]
unsigned char mappings_darbyfr[]
SWORD_NAMESPACE_START struct sbook otbooks_catholic[]