[sword-svn] r2781 - in trunk: include src/keys src/mgr tests utilities
scribe at crosswire.org
scribe at crosswire.org
Sat Feb 16 08:03:09 MST 2013
Author: scribe
Date: 2013-02-16 08:03:08 -0700 (Sat, 16 Feb 2013)
New Revision: 2781
Added:
trunk/include/versificationmgr.h
trunk/src/mgr/versificationmgr.cpp
Removed:
trunk/include/versemgr.h
trunk/src/mgr/versemgr.cpp
Modified:
trunk/include/Makefile.am
trunk/include/versekey.h
trunk/src/keys/versekey.cpp
trunk/src/mgr/Makefile.am
trunk/src/mgr/swlocale.cpp
trunk/tests/versemgrtest.cpp
trunk/utilities/imp2vs.cpp
trunk/utilities/osis2mod.cpp
Log:
renamed versemgr to versificationmgr
Modified: trunk/include/Makefile.am
===================================================================
--- trunk/include/Makefile.am 2013-02-01 09:11:52 UTC (rev 2780)
+++ trunk/include/Makefile.am 2013-02-16 15:03:08 UTC (rev 2781)
@@ -13,7 +13,7 @@
pkginclude_HEADERS += $(swincludedir)/entriesblk.h
pkginclude_HEADERS += $(swincludedir)/femain.h
pkginclude_HEADERS += $(swincludedir)/filemgr.h
-pkginclude_HEADERS += $(swincludedir)/versemgr.h
+pkginclude_HEADERS += $(swincludedir)/versificationmgr.h
pkginclude_HEADERS += $(swincludedir)/flatapi.h
pkginclude_HEADERS += $(swincludedir)/ftpparse.h
pkginclude_HEADERS += $(swincludedir)/ftptrans.h
Modified: trunk/include/versekey.h
===================================================================
--- trunk/include/versekey.h 2013-02-01 09:11:52 UTC (rev 2780)
+++ trunk/include/versekey.h 2013-02-16 15:03:08 UTC (rev 2781)
@@ -26,7 +26,7 @@
#include <swkey.h>
#include <swmacs.h>
#include <listkey.h>
-#include <versemgr.h>
+#include <versificationmgr.h>
#include <defs.h>
@@ -55,7 +55,7 @@
static int instance;
ListKey internalListKey;
- const VerseMgr::System *refSys;
+ const VersificationMgr::System *refSys;
/** flag for auto normalization
*/
Deleted: trunk/include/versemgr.h
===================================================================
--- trunk/include/versemgr.h 2013-02-01 09:11:52 UTC (rev 2780)
+++ trunk/include/versemgr.h 2013-02-16 15:03:08 UTC (rev 2781)
@@ -1,163 +0,0 @@
-/******************************************************************************
- * versemgr.h - definition of class VerseMgr used for managing
- * versification systems
- *
- * $Id: versemgr.cpp 2108 2007-10-13 20:35:02Z scribe $
- *
- * Copyright 1998 CrossWire Bible Society (http://www.crosswire.org)
- * CrossWire Bible Society
- * P. O. Box 2528
- * Tempe, AZ 85280-2528
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation version 2.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- */
-
-#include <list>
-#include <defs.h>
-#include <swcacher.h>
-#include <swbuf.h>
-
-
-#ifndef VERSEMGR_H
-#define VERSEMGR_H
-
-
-SWORD_NAMESPACE_START
-
-typedef std::list <SWBuf>StringList;
-
-struct sbook;
-class TreeKey;
-
-
-struct abbrev
-{
- const char *ab;
- const char *osis;
-};
-
-struct sbook {
- /**Name of book
- */
- const char *name;
-
- /**OSIS name
- */
- const char *osis;
-
- /**Preferred Abbreviation
- */
- const char *prefAbbrev;
-
- /**Maximum chapters in book
- */
- unsigned char chapmax;
- /** Array[chapmax] of maximum verses in chapters
- */
- int *versemax;
-};
-
-
-class SWDLLEXPORT VerseMgr : public SWCacher {
-
-
-public:
- class System;
-
-private:
- friend class __staticsystemVerseMgr;
-
- class Private;
- Private *p;
-
- void init();
-
-protected:
- static VerseMgr *systemVerseMgr;
-
-public:
- class SWDLLEXPORT Book {
- friend class System;
- friend struct BookOffsetLess;
- class Private;
- Private *p;
-
- /** book name */
- SWBuf longName;
-
- /** OSIS Abbreviation */
- SWBuf osisName;
-
- /** Preferred Abbreviation */
- SWBuf prefAbbrev;
-
- /** Maximum chapters in book */
- unsigned int chapMax;
-
- void init();
-
- public:
- Book() { init(); }
- Book(const Book &other);
- Book &operator =(const Book &other);
- Book(const char *longName, const char *osisName, const char *prefAbbrev, int chapMax) {
- this->longName = longName;
- this->osisName = osisName;
- this->prefAbbrev = prefAbbrev;
- this->chapMax = chapMax;
- init();
- }
- ~Book();
- const char *getLongName() const { return longName.c_str(); }
- const char *getOSISName() const { return osisName.c_str(); }
- const char *getPreferredAbbreviation() const { return prefAbbrev.c_str(); }
- int getChapterMax() const { return chapMax; }
- int getVerseMax(int chapter) const;
- };
-
- class SWDLLEXPORT System {
- class Private;
- Private *p;
- SWBuf name;
- int BMAX[2];
- long ntStartOffset;
- void init();
- public:
- System() { this->name = ""; init(); }
- System(const System &other);
- System &operator =(const System &other);
- System(const char *name) { this->name = name; init(); }
- ~System();
- const char *getName() const { return name.c_str(); }
- const Book *getBookByName(const char *bookName) const;
- int getBookNumberByOSISName(const char *bookName) const;
- const Book *getBook(int number) const;
- int getBookCount() const;
- void loadFromSBook(const sbook *ot, const sbook *nt, int *chMax);
- long getOffsetFromVerse(int book, int chapter, int verse) const;
- char getVerseFromOffset(long offset, int *book, int *chapter, int *verse) const;
- const int *getBMAX() const { return BMAX; };
- long getNTStartOffset() const { return ntStartOffset; }
- };
- VerseMgr() { init(); }
- ~VerseMgr();
- static VerseMgr *getSystemVerseMgr();
- static void setSystemVerseMgr(VerseMgr *newVerseMgr);
- const StringList getVersificationSystems() const;
- const System *getVersificationSystem(const char *name) const;
- void registerVersificationSystem(const char *name, const sbook *ot, const sbook *nt, int *chMax);
- void registerVersificationSystem(const char *name, const TreeKey *);
-};
-
-SWDLLEXPORT extern const struct abbrev builtin_abbrevs[];
-
-SWORD_NAMESPACE_END
-#endif
Copied: trunk/include/versificationmgr.h (from rev 2772, trunk/include/versemgr.h)
===================================================================
--- trunk/include/versificationmgr.h (rev 0)
+++ trunk/include/versificationmgr.h 2013-02-16 15:03:08 UTC (rev 2781)
@@ -0,0 +1,163 @@
+/******************************************************************************
+ * versification.h - definition of class VersificationMgr used for managing
+ * versification systems
+ *
+ * $Id: versification.cpp 2108 2007-10-13 20:35:02Z scribe $
+ *
+ * Copyright 1998 CrossWire Bible Society (http://www.crosswire.org)
+ * CrossWire Bible Society
+ * P. O. Box 2528
+ * Tempe, AZ 85280-2528
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ */
+
+#include <list>
+#include <defs.h>
+#include <swcacher.h>
+#include <swbuf.h>
+
+
+#ifndef VERSIFICATIONMGR_H
+#define VERSIFICATIONMGR_H
+
+
+SWORD_NAMESPACE_START
+
+typedef std::list <SWBuf>StringList;
+
+struct sbook;
+class TreeKey;
+
+
+struct abbrev
+{
+ const char *ab;
+ const char *osis;
+};
+
+struct sbook {
+ /**Name of book
+ */
+ const char *name;
+
+ /**OSIS name
+ */
+ const char *osis;
+
+ /**Preferred Abbreviation
+ */
+ const char *prefAbbrev;
+
+ /**Maximum chapters in book
+ */
+ unsigned char chapmax;
+ /** Array[chapmax] of maximum verses in chapters
+ */
+ int *versemax;
+};
+
+
+class SWDLLEXPORT VersificationMgr : public SWCacher {
+
+
+public:
+ class System;
+
+private:
+ friend class __staticsystemVersificationMgr;
+
+ class Private;
+ Private *p;
+
+ void init();
+
+protected:
+ static VersificationMgr *systemVersificationMgr;
+
+public:
+ class SWDLLEXPORT Book {
+ friend class System;
+ friend struct BookOffsetLess;
+ class Private;
+ Private *p;
+
+ /** book name */
+ SWBuf longName;
+
+ /** OSIS Abbreviation */
+ SWBuf osisName;
+
+ /** Preferred Abbreviation */
+ SWBuf prefAbbrev;
+
+ /** Maximum chapters in book */
+ unsigned int chapMax;
+
+ void init();
+
+ public:
+ Book() { init(); }
+ Book(const Book &other);
+ Book &operator =(const Book &other);
+ Book(const char *longName, const char *osisName, const char *prefAbbrev, int chapMax) {
+ this->longName = longName;
+ this->osisName = osisName;
+ this->prefAbbrev = prefAbbrev;
+ this->chapMax = chapMax;
+ init();
+ }
+ ~Book();
+ const char *getLongName() const { return longName.c_str(); }
+ const char *getOSISName() const { return osisName.c_str(); }
+ const char *getPreferredAbbreviation() const { return prefAbbrev.c_str(); }
+ int getChapterMax() const { return chapMax; }
+ int getVerseMax(int chapter) const;
+ };
+
+ class SWDLLEXPORT System {
+ class Private;
+ Private *p;
+ SWBuf name;
+ int BMAX[2];
+ long ntStartOffset;
+ void init();
+ public:
+ System() { this->name = ""; init(); }
+ System(const System &other);
+ System &operator =(const System &other);
+ System(const char *name) { this->name = name; init(); }
+ ~System();
+ const char *getName() const { return name.c_str(); }
+ const Book *getBookByName(const char *bookName) const;
+ int getBookNumberByOSISName(const char *bookName) const;
+ const Book *getBook(int number) const;
+ int getBookCount() const;
+ void loadFromSBook(const sbook *ot, const sbook *nt, int *chMax);
+ long getOffsetFromVerse(int book, int chapter, int verse) const;
+ char getVerseFromOffset(long offset, int *book, int *chapter, int *verse) const;
+ const int *getBMAX() const { return BMAX; };
+ long getNTStartOffset() const { return ntStartOffset; }
+ };
+ VersificationMgr() { init(); }
+ ~VersificationMgr();
+ static VersificationMgr *getSystemVersificationMgr();
+ static void setSystemVersificationMgr(VersificationMgr *newVersificationMgr);
+ const StringList getVersificationSystems() const;
+ const System *getVersificationSystem(const char *name) const;
+ void registerVersificationSystem(const char *name, const sbook *ot, const sbook *nt, int *chMax);
+ void registerVersificationSystem(const char *name, const TreeKey *);
+};
+
+SWDLLEXPORT extern const struct abbrev builtin_abbrevs[];
+
+SWORD_NAMESPACE_END
+#endif
Modified: trunk/src/keys/versekey.cpp
===================================================================
--- trunk/src/keys/versekey.cpp 2013-02-01 09:11:52 UTC (rev 2780)
+++ trunk/src/keys/versekey.cpp 2013-02-16 15:03:08 UTC (rev 2781)
@@ -32,7 +32,7 @@
#include <versekey.h>
#include <swlocale.h>
#include <roman.h>
-#include <versemgr.h>
+#include <versificationmgr.h>
SWORD_NAMESPACE_START
@@ -252,9 +252,9 @@
void VerseKey::setVersificationSystem(const char *name) {
- const VerseMgr::System *newRefSys = VerseMgr::getSystemVerseMgr()->getVersificationSystem(name);
+ const VersificationMgr::System *newRefSys = VersificationMgr::getSystemVersificationMgr()->getVersificationSystem(name);
// TODO: cheese, but what should we do if requested v11n system isn't found?
- if (!newRefSys) newRefSys = VerseMgr::getSystemVerseMgr()->getVersificationSystem("KJV");
+ if (!newRefSys) newRefSys = VersificationMgr::getSystemVersificationMgr()->getVersificationSystem("KJV");
if (refSys != newRefSys) {
refSys = newRefSys;
BMAX[0] = refSys->getBMAX()[0];
@@ -1228,12 +1228,12 @@
}
int VerseKey::getChapterMax() const {
- const VerseMgr::Book *b = refSys->getBook(((testament>1)?BMAX[0]:0)+book-1);
+ const VersificationMgr::Book *b = refSys->getBook(((testament>1)?BMAX[0]:0)+book-1);
return (b) ? b->getChapterMax() : -1;
}
int VerseKey::getVerseMax() const {
- const VerseMgr::Book *b = refSys->getBook(((testament>1)?BMAX[0]:0)+book-1);
+ const VersificationMgr::Book *b = refSys->getBook(((testament>1)?BMAX[0]:0)+book-1);
return (b) ? b->getVerseMax(chapter) : -1;
}
@@ -1343,12 +1343,12 @@
}
else {
if (book > 1) {
- const VerseMgr::Book *prevBook = refSys->getBook(((testament>1)?BMAX[0]:0)+book-2);
+ const VersificationMgr::Book *prevBook = refSys->getBook(((testament>1)?BMAX[0]:0)+book-2);
verse += prevBook->getVerseMax(prevBook->getChapterMax());
}
else {
if (testament > 1) {
- const VerseMgr::Book *lastOTBook = refSys->getBook(BMAX[0]-1);
+ const VersificationMgr::Book *lastOTBook = refSys->getBook(BMAX[0]-1);
verse += lastOTBook->getVerseMax(lastOTBook->getChapterMax());
}
}
Modified: trunk/src/mgr/Makefile.am
===================================================================
--- trunk/src/mgr/Makefile.am 2013-02-01 09:11:52 UTC (rev 2780)
+++ trunk/src/mgr/Makefile.am 2013-02-16 15:03:08 UTC (rev 2781)
@@ -23,7 +23,7 @@
libsword_la_SOURCES += $(mgrdir)/encfiltmgr.cpp
libsword_la_SOURCES += $(mgrdir)/markupfiltmgr.cpp
libsword_la_SOURCES += $(mgrdir)/filemgr.cpp
-libsword_la_SOURCES += $(mgrdir)/versemgr.cpp
+libsword_la_SOURCES += $(mgrdir)/versificationmgr.cpp
libsword_la_SOURCES += $(mgrdir)/ftptrans.cpp
libsword_la_SOURCES += $(mgrdir)/swlocale.cpp
libsword_la_SOURCES += $(mgrdir)/localemgr.cpp
Modified: trunk/src/mgr/swlocale.cpp
===================================================================
--- trunk/src/mgr/swlocale.cpp 2013-02-01 09:11:52 UTC (rev 2780)
+++ trunk/src/mgr/swlocale.cpp 2013-02-16 15:03:08 UTC (rev 2781)
@@ -25,7 +25,7 @@
#include <map>
#include <swconfig.h>
#include <versekey.h>
-#include <versemgr.h>
+#include <versificationmgr.h>
SWORD_NAMESPACE_START
Deleted: trunk/src/mgr/versemgr.cpp
===================================================================
--- trunk/src/mgr/versemgr.cpp 2013-02-01 09:11:52 UTC (rev 2780)
+++ trunk/src/mgr/versemgr.cpp 2013-02-16 15:03:08 UTC (rev 2781)
@@ -1,383 +0,0 @@
-/******************************************************************************
- * versemgr.cpp - implementation of class VerseMgr used for managing
- * versification systems
- *
- * $Id: versemgr.cpp 2108 2007-10-13 20:35:02Z scribe $
- *
- * Copyright 2010 CrossWire Bible Society (http://www.crosswire.org)
- * CrossWire Bible Society
- * P. O. Box 2528
- * Tempe, AZ 85280-2528
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation version 2.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- */
-
-#include <versemgr.h>
-#include <vector>
-#include <map>
-#include <treekey.h>
-#include <canon.h> // KJV internal versification system
-#include <swlog.h>
-#include <algorithm>
-
-#include <canon_null.h> // null v11n system
-
-#include <canon_leningrad.h> // Leningrad Codex (WLC) v11n system
-#include <canon_mt.h> // Masoretic Text (MT) v11n system
-#include <canon_kjva.h> // KJV + Apocrypha v11n system
-#include <canon_nrsv.h> // NRSV v11n system
-#include <canon_nrsva.h> // NRSV + Apocrypha v11n system
-#include <canon_synodal.h> // Russian Synodal v11n system
-#include <canon_vulg.h> // Vulgate v11n system
-#include <canon_german.h> // German v11n system
-#include <canon_luther.h> // Luther v11n system
-#include <canon_catholic.h> // Catholic v11n system (10 chapter Esther)
-#include <canon_catholic2.h> // Catholic2 v11n system (16 chapter Esther)
-#include <canon_rahlfs.h> // Rahlfs LXX v11n system
-
-using std::vector;
-using std::map;
-using std::distance;
-using std::lower_bound;
-
-SWORD_NAMESPACE_START
-
-
-VerseMgr *VerseMgr::getSystemVerseMgr() {
- if (!systemVerseMgr) {
- systemVerseMgr = new VerseMgr();
- systemVerseMgr->registerVersificationSystem("KJV", otbooks, ntbooks, vm);
- systemVerseMgr->registerVersificationSystem("Leningrad", otbooks_leningrad, ntbooks_null, vm_leningrad);
- systemVerseMgr->registerVersificationSystem("MT", otbooks_mt, ntbooks_null, vm_mt);
- systemVerseMgr->registerVersificationSystem("KJVA", otbooks_kjva, ntbooks, vm_kjva);
- systemVerseMgr->registerVersificationSystem("NRSV", otbooks, ntbooks, vm_nrsv);
- systemVerseMgr->registerVersificationSystem("NRSVA", otbooks_nrsva, ntbooks, vm_nrsva);
- systemVerseMgr->registerVersificationSystem("Synodal", otbooks_synodal, ntbooks_synodal, vm_synodal);
- systemVerseMgr->registerVersificationSystem("Vulg", otbooks_vulg, ntbooks_vulg, vm_vulg);
- systemVerseMgr->registerVersificationSystem("German", otbooks_german, ntbooks, vm_german);
- systemVerseMgr->registerVersificationSystem("Luther", otbooks_luther, ntbooks_luther, vm_luther);
- systemVerseMgr->registerVersificationSystem("Catholic", otbooks_catholic, ntbooks, vm_catholic);
- systemVerseMgr->registerVersificationSystem("Catholic2", otbooks_catholic2, ntbooks, vm_catholic2);
- systemVerseMgr->registerVersificationSystem("Rahlfs", otbooks_rahlfs, ntbooks_null, vm_rahlfs);
- }
- return systemVerseMgr;
-}
-
-
-class VerseMgr::System::Private {
-public:
- /** Array[chapmax] of maximum verses in chapters */
- vector<Book> books;
- map<SWBuf, int> osisLookup;
-
- Private() {
- }
- Private(const VerseMgr::System::Private &other) {
- books = other.books;
- osisLookup = other.osisLookup;
- }
- VerseMgr::System::Private &operator =(const VerseMgr::System::Private &other) {
- books = other.books;
- osisLookup = other.osisLookup;
- return *this;
- }
-};
-
-
-class VerseMgr::Book::Private {
-friend struct BookOffsetLess;
-public:
- /** Array[chapmax] of maximum verses in chapters */
- vector<int> verseMax;
- vector<long> offsetPrecomputed;
-
- Private() {
- verseMax.clear();
- }
- Private(const VerseMgr::Book::Private &other) {
- verseMax.clear();
- verseMax = other.verseMax;
- offsetPrecomputed = other.offsetPrecomputed;
- }
- VerseMgr::Book::Private &operator =(const VerseMgr::Book::Private &other) {
- verseMax.clear();
- verseMax = other.verseMax;
- offsetPrecomputed = other.offsetPrecomputed;
- return *this;
- }
-};
-
-struct BookOffsetLess {
- bool operator() (const VerseMgr::Book &o1, const VerseMgr::Book &o2) const { return o1.p->offsetPrecomputed[0] < o2.p->offsetPrecomputed[0]; }
- bool operator() (const long &o1, const VerseMgr::Book &o2) const { return o1 < o2.p->offsetPrecomputed[0]; }
- bool operator() (const VerseMgr::Book &o1, const long &o2) const { return o1.p->offsetPrecomputed[0] < o2; }
- bool operator() (const long &o1, const long &o2) const { return o1 < o2; }
-};
-
-void VerseMgr::Book::init() {
- p = new Private();
-}
-
-void VerseMgr::System::init() {
- p = new Private();
- BMAX[0] = 0;
- BMAX[1] = 0;
- ntStartOffset = 0;
-}
-
-
-VerseMgr::System::System(const System &other) {
- init();
- name = other.name;
- BMAX[0] = other.BMAX[0];
- BMAX[1] = other.BMAX[1];
- (*p) = *(other.p);
- ntStartOffset = other.ntStartOffset;
-}
-
-VerseMgr::System &VerseMgr::System::operator =(const System &other) {
- name = other.name;
- BMAX[0] = other.BMAX[0];
- BMAX[1] = other.BMAX[1];
- (*p) = *(other.p);
- ntStartOffset = other.ntStartOffset;
- return *this;
-}
-
-
-VerseMgr::System::~System() {
- delete p;
-}
-
-const VerseMgr::Book *VerseMgr::System::getBook(int number) const {
- return (number < (signed int)p->books.size()) ? &(p->books[number]) : 0;
-}
-
-
-int VerseMgr::System::getBookNumberByOSISName(const char *bookName) const {
- map<SWBuf, int>::const_iterator it = p->osisLookup.find(bookName);
- return (it != p->osisLookup.end()) ? it->second : -1;
-}
-
-
-void VerseMgr::System::loadFromSBook(const sbook *ot, const sbook *nt, int *chMax) {
- int chap = 0;
- int book = 0;
- long offset = 0; // module heading
- offset++; // testament heading
- while (ot->chapmax) {
- p->books.push_back(Book(ot->name, ot->osis, ot->prefAbbrev, ot->chapmax));
- offset++; // book heading
- Book &b = p->books[p->books.size()-1];
- p->osisLookup[b.getOSISName()] = p->books.size();
- for (int i = 0; i < ot->chapmax; i++) {
- b.p->verseMax.push_back(chMax[chap]);
- offset++; // chapter heading
- b.p->offsetPrecomputed.push_back(offset);
- offset += chMax[chap++];
- }
- ot++;
- book++;
- }
- BMAX[0] = book;
- book = 0;
- ntStartOffset = offset;
- offset++; // testament heading
- while (nt->chapmax) {
- p->books.push_back(Book(nt->name, nt->osis, nt->prefAbbrev, nt->chapmax));
- offset++; // book heading
- Book &b = p->books[p->books.size()-1];
- p->osisLookup[b.getOSISName()] = p->books.size();
- for (int i = 0; i < nt->chapmax; i++) {
- b.p->verseMax.push_back(chMax[chap]);
- offset++; // chapter heading
- b.p->offsetPrecomputed.push_back(offset);
- offset += chMax[chap++];
- }
- nt++;
- book++;
- }
- BMAX[1] = book;
-
- // TODO: build offset speed array
-}
-
-
-VerseMgr::Book::Book(const Book &other) {
- longName = other.longName;
- osisName = other.osisName;
- prefAbbrev = other.prefAbbrev;
- chapMax = other.chapMax;
- init();
- (*p) = *(other.p);
-}
-
-VerseMgr::Book& VerseMgr::Book::operator =(const Book &other) {
- longName = other.longName;
- osisName = other.osisName;
- prefAbbrev = other.prefAbbrev;
- chapMax = other.chapMax;
- init();
- (*p) = *(other.p);
- return *this;
-}
-
-
-VerseMgr::Book::~Book() {
- delete p;
-}
-
-
-int VerseMgr::Book::getVerseMax(int chapter) const {
- chapter--;
- return (p && (chapter < (signed int)p->verseMax.size()) && (chapter > -1)) ? p->verseMax[chapter] : -1;
-}
-
-
-int VerseMgr::System::getBookCount() const {
- return (p ? p->books.size() : 0);
-}
-
-
-long VerseMgr::System::getOffsetFromVerse(int book, int chapter, int verse) const {
- long offset = -1;
- chapter--;
-
- const Book *b = getBook(book);
-
- if (!b) return -1; // assert we have a valid book
- if ((chapter > -1) && (chapter >= (signed int)b->p->offsetPrecomputed.size())) return -1; // assert we have a valid chapter
-
- offset = b->p->offsetPrecomputed[(chapter > -1)?chapter:0];
- if (chapter < 0) offset--;
-
-/* old code
- *
- offset = offsets[testament-1][0][book];
- offset = offsets[testament-1][1][(int)offset + chapter];
- if (!(offset|verse)) // if we have a testament but nothing else.
- offset = 1;
-
-*/
-
- return (offset + verse);
-}
-
-
-char VerseMgr::System::getVerseFromOffset(long offset, int *book, int *chapter, int *verse) const {
-
- if (offset < 1) { // just handle the module heading corner case up front (and error case)
- (*book) = -1;
- (*chapter) = 0;
- (*verse) = 0;
- return offset; // < 0 = error
- }
-
- // binary search for book
- vector<Book>::iterator b = lower_bound(p->books.begin(), p->books.end(), offset, BookOffsetLess());
- if (b == p->books.end()) b--;
- (*book) = distance(p->books.begin(), b)+1;
- if (offset < (*(b->p->offsetPrecomputed.begin()))-((((!(*book)) || (*book)==BMAX[0]+1))?2:1)) { // -1 for chapter headings
- (*book)--;
- if (b != p->books.begin()) {
- b--;
- }
- }
- vector<long>::iterator c = lower_bound(b->p->offsetPrecomputed.begin(), b->p->offsetPrecomputed.end(), offset);
-
- // if we're a book heading, we are lessthan chapter precomputes, but greater book. This catches corner case.
- if (c == b->p->offsetPrecomputed.end()) {
- c--;
- }
- if ((offset < *c) && (c == b->p->offsetPrecomputed.begin())) {
- (*chapter) = (offset - *c)+1; // should be 0 or -1 (for testament heading)
- (*verse) = 0;
- }
- else {
- if (offset < *c) c--;
- (*chapter) = distance(b->p->offsetPrecomputed.begin(), c)+1;
- (*verse) = (offset - *c);
- }
- return ((*chapter > 0) && (*verse > b->getVerseMax(*chapter))) ? KEYERR_OUTOFBOUNDS : 0;
-}
-
-
-/***************************************************
- * VerseMgr
- */
-
-class VerseMgr::Private {
-public:
- Private() {
- }
- Private(const VerseMgr::Private &other) {
- systems = other.systems;
- }
- VerseMgr::Private &operator =(const VerseMgr::Private &other) {
- systems = other.systems;
- return *this;
- }
- map<SWBuf, System> systems;
-};
-// ---------------- statics -----------------
-VerseMgr *VerseMgr::systemVerseMgr = 0;
-
-class __staticsystemVerseMgr {
-public:
- __staticsystemVerseMgr() { }
- ~__staticsystemVerseMgr() { delete VerseMgr::systemVerseMgr; }
-} _staticsystemVerseMgr;
-
-
-void VerseMgr::init() {
- p = new Private();
-}
-
-
-VerseMgr::~VerseMgr() {
- delete p;
-}
-
-
-void VerseMgr::setSystemVerseMgr(VerseMgr *newVerseMgr) {
- if (systemVerseMgr)
- delete systemVerseMgr;
- systemVerseMgr = newVerseMgr;
-}
-
-
-const VerseMgr::System *VerseMgr::getVersificationSystem(const char *name) const {
- map<SWBuf, System>::const_iterator it = p->systems.find(name);
- return (it != p->systems.end()) ? &(it->second) : 0;
-}
-
-
-void VerseMgr::registerVersificationSystem(const char *name, const sbook *ot, const sbook *nt, int *chMax) {
- p->systems[name] = name;
- System &s = p->systems[name];
- s.loadFromSBook(ot, nt, chMax);
-}
-
-
-void VerseMgr::registerVersificationSystem(const char *name, const TreeKey *tk) {
-}
-
-
-const StringList VerseMgr::getVersificationSystems() const {
- StringList retVal;
- for (map<SWBuf, System>::const_iterator it = p->systems.begin(); it != p->systems.end(); it++) {
- retVal.push_back(it->first);
- }
- return retVal;
-}
-
-
-SWORD_NAMESPACE_END
Copied: trunk/src/mgr/versificationmgr.cpp (from rev 2772, trunk/src/mgr/versemgr.cpp)
===================================================================
--- trunk/src/mgr/versificationmgr.cpp (rev 0)
+++ trunk/src/mgr/versificationmgr.cpp 2013-02-16 15:03:08 UTC (rev 2781)
@@ -0,0 +1,383 @@
+/******************************************************************************
+ * versificationmgr.cpp - implementation of class VersificationMgr used for managing
+ * versification systems
+ *
+ * $Id: versificationmgr.cpp 2108 2007-10-13 20:35:02Z scribe $
+ *
+ * Copyright 2010 CrossWire Bible Society (http://www.crosswire.org)
+ * CrossWire Bible Society
+ * P. O. Box 2528
+ * Tempe, AZ 85280-2528
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ */
+
+#include <versificationmgr.h>
+#include <vector>
+#include <map>
+#include <treekey.h>
+#include <canon.h> // KJV internal versification system
+#include <swlog.h>
+#include <algorithm>
+
+#include <canon_null.h> // null v11n system
+
+#include <canon_leningrad.h> // Leningrad Codex (WLC) v11n system
+#include <canon_mt.h> // Masoretic Text (MT) v11n system
+#include <canon_kjva.h> // KJV + Apocrypha v11n system
+#include <canon_nrsv.h> // NRSV v11n system
+#include <canon_nrsva.h> // NRSV + Apocrypha v11n system
+#include <canon_synodal.h> // Russian Synodal v11n system
+#include <canon_vulg.h> // Vulgate v11n system
+#include <canon_german.h> // German v11n system
+#include <canon_luther.h> // Luther v11n system
+#include <canon_catholic.h> // Catholic v11n system (10 chapter Esther)
+#include <canon_catholic2.h> // Catholic2 v11n system (16 chapter Esther)
+#include <canon_rahlfs.h> // Rahlfs LXX v11n system
+
+using std::vector;
+using std::map;
+using std::distance;
+using std::lower_bound;
+
+SWORD_NAMESPACE_START
+
+
+VersificationMgr *VersificationMgr::getSystemVersificationMgr() {
+ if (!systemVersificationMgr) {
+ systemVersificationMgr = new VersificationMgr();
+ systemVersificationMgr->registerVersificationSystem("KJV", otbooks, ntbooks, vm);
+ systemVersificationMgr->registerVersificationSystem("Leningrad", otbooks_leningrad, ntbooks_null, vm_leningrad);
+ systemVersificationMgr->registerVersificationSystem("MT", otbooks_mt, ntbooks_null, vm_mt);
+ systemVersificationMgr->registerVersificationSystem("KJVA", otbooks_kjva, ntbooks, vm_kjva);
+ systemVersificationMgr->registerVersificationSystem("NRSV", otbooks, ntbooks, vm_nrsv);
+ systemVersificationMgr->registerVersificationSystem("NRSVA", otbooks_nrsva, ntbooks, vm_nrsva);
+ systemVersificationMgr->registerVersificationSystem("Synodal", otbooks_synodal, ntbooks_synodal, vm_synodal);
+ systemVersificationMgr->registerVersificationSystem("Vulg", otbooks_vulg, ntbooks_vulg, vm_vulg);
+ systemVersificationMgr->registerVersificationSystem("German", otbooks_german, ntbooks, vm_german);
+ systemVersificationMgr->registerVersificationSystem("Luther", otbooks_luther, ntbooks_luther, vm_luther);
+ systemVersificationMgr->registerVersificationSystem("Catholic", otbooks_catholic, ntbooks, vm_catholic);
+ systemVersificationMgr->registerVersificationSystem("Catholic2", otbooks_catholic2, ntbooks, vm_catholic2);
+ systemVersificationMgr->registerVersificationSystem("Rahlfs", otbooks_rahlfs, ntbooks_null, vm_rahlfs);
+ }
+ return systemVersificationMgr;
+}
+
+
+class VersificationMgr::System::Private {
+public:
+ /** Array[chapmax] of maximum verses in chapters */
+ vector<Book> books;
+ map<SWBuf, int> osisLookup;
+
+ Private() {
+ }
+ Private(const VersificationMgr::System::Private &other) {
+ books = other.books;
+ osisLookup = other.osisLookup;
+ }
+ VersificationMgr::System::Private &operator =(const VersificationMgr::System::Private &other) {
+ books = other.books;
+ osisLookup = other.osisLookup;
+ return *this;
+ }
+};
+
+
+class VersificationMgr::Book::Private {
+friend struct BookOffsetLess;
+public:
+ /** Array[chapmax] of maximum verses in chapters */
+ vector<int> verseMax;
+ vector<long> offsetPrecomputed;
+
+ Private() {
+ verseMax.clear();
+ }
+ Private(const VersificationMgr::Book::Private &other) {
+ verseMax.clear();
+ verseMax = other.verseMax;
+ offsetPrecomputed = other.offsetPrecomputed;
+ }
+ VersificationMgr::Book::Private &operator =(const VersificationMgr::Book::Private &other) {
+ verseMax.clear();
+ verseMax = other.verseMax;
+ offsetPrecomputed = other.offsetPrecomputed;
+ return *this;
+ }
+};
+
+struct BookOffsetLess {
+ bool operator() (const VersificationMgr::Book &o1, const VersificationMgr::Book &o2) const { return o1.p->offsetPrecomputed[0] < o2.p->offsetPrecomputed[0]; }
+ bool operator() (const long &o1, const VersificationMgr::Book &o2) const { return o1 < o2.p->offsetPrecomputed[0]; }
+ bool operator() (const VersificationMgr::Book &o1, const long &o2) const { return o1.p->offsetPrecomputed[0] < o2; }
+ bool operator() (const long &o1, const long &o2) const { return o1 < o2; }
+};
+
+void VersificationMgr::Book::init() {
+ p = new Private();
+}
+
+void VersificationMgr::System::init() {
+ p = new Private();
+ BMAX[0] = 0;
+ BMAX[1] = 0;
+ ntStartOffset = 0;
+}
+
+
+VersificationMgr::System::System(const System &other) {
+ init();
+ name = other.name;
+ BMAX[0] = other.BMAX[0];
+ BMAX[1] = other.BMAX[1];
+ (*p) = *(other.p);
+ ntStartOffset = other.ntStartOffset;
+}
+
+VersificationMgr::System &VersificationMgr::System::operator =(const System &other) {
+ name = other.name;
+ BMAX[0] = other.BMAX[0];
+ BMAX[1] = other.BMAX[1];
+ (*p) = *(other.p);
+ ntStartOffset = other.ntStartOffset;
+ return *this;
+}
+
+
+VersificationMgr::System::~System() {
+ delete p;
+}
+
+const VersificationMgr::Book *VersificationMgr::System::getBook(int number) const {
+ return (number < (signed int)p->books.size()) ? &(p->books[number]) : 0;
+}
+
+
+int VersificationMgr::System::getBookNumberByOSISName(const char *bookName) const {
+ map<SWBuf, int>::const_iterator it = p->osisLookup.find(bookName);
+ return (it != p->osisLookup.end()) ? it->second : -1;
+}
+
+
+void VersificationMgr::System::loadFromSBook(const sbook *ot, const sbook *nt, int *chMax) {
+ int chap = 0;
+ int book = 0;
+ long offset = 0; // module heading
+ offset++; // testament heading
+ while (ot->chapmax) {
+ p->books.push_back(Book(ot->name, ot->osis, ot->prefAbbrev, ot->chapmax));
+ offset++; // book heading
+ Book &b = p->books[p->books.size()-1];
+ p->osisLookup[b.getOSISName()] = p->books.size();
+ for (int i = 0; i < ot->chapmax; i++) {
+ b.p->verseMax.push_back(chMax[chap]);
+ offset++; // chapter heading
+ b.p->offsetPrecomputed.push_back(offset);
+ offset += chMax[chap++];
+ }
+ ot++;
+ book++;
+ }
+ BMAX[0] = book;
+ book = 0;
+ ntStartOffset = offset;
+ offset++; // testament heading
+ while (nt->chapmax) {
+ p->books.push_back(Book(nt->name, nt->osis, nt->prefAbbrev, nt->chapmax));
+ offset++; // book heading
+ Book &b = p->books[p->books.size()-1];
+ p->osisLookup[b.getOSISName()] = p->books.size();
+ for (int i = 0; i < nt->chapmax; i++) {
+ b.p->verseMax.push_back(chMax[chap]);
+ offset++; // chapter heading
+ b.p->offsetPrecomputed.push_back(offset);
+ offset += chMax[chap++];
+ }
+ nt++;
+ book++;
+ }
+ BMAX[1] = book;
+
+ // TODO: build offset speed array
+}
+
+
+VersificationMgr::Book::Book(const Book &other) {
+ longName = other.longName;
+ osisName = other.osisName;
+ prefAbbrev = other.prefAbbrev;
+ chapMax = other.chapMax;
+ init();
+ (*p) = *(other.p);
+}
+
+VersificationMgr::Book& VersificationMgr::Book::operator =(const Book &other) {
+ longName = other.longName;
+ osisName = other.osisName;
+ prefAbbrev = other.prefAbbrev;
+ chapMax = other.chapMax;
+ init();
+ (*p) = *(other.p);
+ return *this;
+}
+
+
+VersificationMgr::Book::~Book() {
+ delete p;
+}
+
+
+int VersificationMgr::Book::getVerseMax(int chapter) const {
+ chapter--;
+ return (p && (chapter < (signed int)p->verseMax.size()) && (chapter > -1)) ? p->verseMax[chapter] : -1;
+}
+
+
+int VersificationMgr::System::getBookCount() const {
+ return (p ? p->books.size() : 0);
+}
+
+
+long VersificationMgr::System::getOffsetFromVerse(int book, int chapter, int verse) const {
+ long offset = -1;
+ chapter--;
+
+ const Book *b = getBook(book);
+
+ if (!b) return -1; // assert we have a valid book
+ if ((chapter > -1) && (chapter >= (signed int)b->p->offsetPrecomputed.size())) return -1; // assert we have a valid chapter
+
+ offset = b->p->offsetPrecomputed[(chapter > -1)?chapter:0];
+ if (chapter < 0) offset--;
+
+/* old code
+ *
+ offset = offsets[testament-1][0][book];
+ offset = offsets[testament-1][1][(int)offset + chapter];
+ if (!(offset|verse)) // if we have a testament but nothing else.
+ offset = 1;
+
+*/
+
+ return (offset + verse);
+}
+
+
+char VersificationMgr::System::getVerseFromOffset(long offset, int *book, int *chapter, int *verse) const {
+
+ if (offset < 1) { // just handle the module heading corner case up front (and error case)
+ (*book) = -1;
+ (*chapter) = 0;
+ (*verse) = 0;
+ return offset; // < 0 = error
+ }
+
+ // binary search for book
+ vector<Book>::iterator b = lower_bound(p->books.begin(), p->books.end(), offset, BookOffsetLess());
+ if (b == p->books.end()) b--;
+ (*book) = distance(p->books.begin(), b)+1;
+ if (offset < (*(b->p->offsetPrecomputed.begin()))-((((!(*book)) || (*book)==BMAX[0]+1))?2:1)) { // -1 for chapter headings
+ (*book)--;
+ if (b != p->books.begin()) {
+ b--;
+ }
+ }
+ vector<long>::iterator c = lower_bound(b->p->offsetPrecomputed.begin(), b->p->offsetPrecomputed.end(), offset);
+
+ // if we're a book heading, we are lessthan chapter precomputes, but greater book. This catches corner case.
+ if (c == b->p->offsetPrecomputed.end()) {
+ c--;
+ }
+ if ((offset < *c) && (c == b->p->offsetPrecomputed.begin())) {
+ (*chapter) = (offset - *c)+1; // should be 0 or -1 (for testament heading)
+ (*verse) = 0;
+ }
+ else {
+ if (offset < *c) c--;
+ (*chapter) = distance(b->p->offsetPrecomputed.begin(), c)+1;
+ (*verse) = (offset - *c);
+ }
+ return ((*chapter > 0) && (*verse > b->getVerseMax(*chapter))) ? KEYERR_OUTOFBOUNDS : 0;
+}
+
+
+/***************************************************
+ * VersificationMgr
+ */
+
+class VersificationMgr::Private {
+public:
+ Private() {
+ }
+ Private(const VersificationMgr::Private &other) {
+ systems = other.systems;
+ }
+ VersificationMgr::Private &operator =(const VersificationMgr::Private &other) {
+ systems = other.systems;
+ return *this;
+ }
+ map<SWBuf, System> systems;
+};
+// ---------------- statics -----------------
+VersificationMgr *VersificationMgr::systemVersificationMgr = 0;
+
+class __staticsystemVersificationMgr {
+public:
+ __staticsystemVersificationMgr() { }
+ ~__staticsystemVersificationMgr() { delete VersificationMgr::systemVersificationMgr; }
+} _staticsystemVersificationMgr;
+
+
+void VersificationMgr::init() {
+ p = new Private();
+}
+
+
+VersificationMgr::~VersificationMgr() {
+ delete p;
+}
+
+
+void VersificationMgr::setSystemVersificationMgr(VersificationMgr *newVersificationMgr) {
+ if (systemVersificationMgr)
+ delete systemVersificationMgr;
+ systemVersificationMgr = newVersificationMgr;
+}
+
+
+const VersificationMgr::System *VersificationMgr::getVersificationSystem(const char *name) const {
+ map<SWBuf, System>::const_iterator it = p->systems.find(name);
+ return (it != p->systems.end()) ? &(it->second) : 0;
+}
+
+
+void VersificationMgr::registerVersificationSystem(const char *name, const sbook *ot, const sbook *nt, int *chMax) {
+ p->systems[name] = name;
+ System &s = p->systems[name];
+ s.loadFromSBook(ot, nt, chMax);
+}
+
+
+void VersificationMgr::registerVersificationSystem(const char *name, const TreeKey *tk) {
+}
+
+
+const StringList VersificationMgr::getVersificationSystems() const {
+ StringList retVal;
+ for (map<SWBuf, System>::const_iterator it = p->systems.begin(); it != p->systems.end(); it++) {
+ retVal.push_back(it->first);
+ }
+ return retVal;
+}
+
+
+SWORD_NAMESPACE_END
Modified: trunk/tests/versemgrtest.cpp
===================================================================
--- trunk/tests/versemgrtest.cpp 2013-02-01 09:11:52 UTC (rev 2780)
+++ trunk/tests/versemgrtest.cpp 2013-02-16 15:03:08 UTC (rev 2781)
@@ -19,7 +19,7 @@
#include <stdio.h>
#include <stdlib.h>
-#include <versemgr.h>
+#include <versificationmgr.h>
#ifndef NO_SWORD_NAMESPACE
using namespace sword;
#endif
@@ -31,10 +31,10 @@
const char *v11n = (argc > 1) ? argv[1] : "KJV";
- VerseMgr *vmgr = VerseMgr::getSystemVerseMgr();
- const VerseMgr::System *system = vmgr->getVersificationSystem(v11n);
+ VersificationMgr *vmgr = VersificationMgr::getSystemVersificationMgr();
+ const VersificationMgr::System *system = vmgr->getVersificationSystem(v11n);
int bookCount = system->getBookCount();
- const VerseMgr::Book *lastBook = system->getBook(bookCount-1);
+ const VersificationMgr::Book *lastBook = system->getBook(bookCount-1);
int chapMax = lastBook->getChapterMax();
int verseMax = lastBook->getVerseMax(chapMax);
long offsetMax = system->getOffsetFromVerse(bookCount-1, chapMax, verseMax);
Modified: trunk/utilities/imp2vs.cpp
===================================================================
--- trunk/utilities/imp2vs.cpp 2013-02-01 09:11:52 UTC (rev 2780)
+++ trunk/utilities/imp2vs.cpp 2013-02-16 15:03:08 UTC (rev 2781)
@@ -53,7 +53,7 @@
fprintf(stderr, "\t\t\t\t 2 - verse; 3 - chapter; 4 - book\n");
fprintf(stderr, " -v <v11n>\t\t specify a versification scheme to use (default is KJV)\n");
fprintf(stderr, "\t\t\t\t Note: The following are valid values for v11n:\n");
- VerseMgr *vmgr = VerseMgr::getSystemVerseMgr();
+ VersificationMgr *vmgr = VersificationMgr::getSystemVersificationMgr();
StringList av11n = vmgr->getVersificationSystems();
for (StringList::iterator loop = av11n.begin(); loop != av11n.end(); loop++) {
fprintf(stderr, "\t\t\t\t\t%s\n", (*loop).c_str());
@@ -133,7 +133,7 @@
else usage(progName, (((SWBuf)"Unknown argument: ")+ argv[i]).c_str());
}
// -----------------------------------------------------
- const VerseMgr::System *v = VerseMgr::getSystemVerseMgr()->getVersificationSystem(v11n);
+ const VersificationMgr::System *v = VersificationMgr::getSystemVersificationMgr()->getVersificationSystem(v11n);
if (!v) std::cout << "Warning: Versification " << v11n << " not found. Using KJV versification...\n";
if (compType == "ZIP") {
Modified: trunk/utilities/osis2mod.cpp
===================================================================
--- trunk/utilities/osis2mod.cpp 2013-02-01 09:11:52 UTC (rev 2780)
+++ trunk/utilities/osis2mod.cpp 2013-02-16 15:03:08 UTC (rev 2781)
@@ -96,8 +96,8 @@
static bool normalize = true; // Whether to normalize UTF-8 to NFC
bool isOSISAbbrev(const char *buf) {
- VerseMgr *vmgr = VerseMgr::getSystemVerseMgr();
- const VerseMgr::System *av11n = vmgr->getVersificationSystem(currentVerse.getVersificationSystem());
+ VersificationMgr *vmgr = VersificationMgr::getSystemVersificationMgr();
+ const VersificationMgr::System *av11n = vmgr->getVersificationSystem(currentVerse.getVersificationSystem());
return av11n->getBookNumberByOSISName(buf) >= 0;
}
@@ -1300,7 +1300,7 @@
fprintf(stderr, "\t\t\t\t (2 bytes to store size equal 65535 characters)\n");
fprintf(stderr, " -v <v11n>\t\t specify a versification scheme to use (default is KJV)\n");
fprintf(stderr, "\t\t\t\t Note: The following are valid values for v11n:\n");
- VerseMgr *vmgr = VerseMgr::getSystemVerseMgr();
+ VersificationMgr *vmgr = VersificationMgr::getSystemVersificationMgr();
StringList av11n = vmgr->getVersificationSystems();
for (StringList::iterator loop = av11n.begin(); loop != av11n.end(); loop++) {
fprintf(stderr, "\t\t\t\t\t%s\n", (*loop).c_str());
More information about the sword-cvs
mailing list