This adds a (very simple) versification mapping class, and fixes a slight problem in versekey with v11n of bounds.
API is something like this (I'm not sure I like the names, though...): VerseMapMgr { static VerseMapMgr* getSystemVerseMapMgr() SWVerseMapper* getMapper(char* v11n_from, char* v11n_to); SWVerseMapper* getMapper(VerseMgr::System* v11n_from, VerseMgr::System* v11n_to); } SWVerseMapper { VerseKey* map(VerseKey* from); } The rules of this verse mapper are very simple (i.e. it doesn't do a proper job...) if bound set: l = map(lower bound) u = map(upper bound) if u is NULL: set u to the end of l's book if l is NULL: set l to the start of u's book swap u and l if u is before l (i.e. book order is different, and bounds go across border) return versekey composed of u and l otherwise: if book of from key isn't in to v11n: return NULL if chapter isn't in destination v11n: return last verse in book in destination v11n if verse isn't in destination v11n: return last verse in chapter in destination v11n otherwise, return the same verse, but in new v11n. This serves two purposes: 1) it defines an API which we can use later. By making getMapper return a more intelligent mapper, we can put proper mapping in later very easily. 2) it will do a better job than just copying the text across (because it clips, not normalizes) God Bless, Ben ------------------------------------------------------------------------------------------- Multitudes, multitudes, in the valley of decision! For the day of the LORD is near in the valley of decision. Giôên 3:14 (ESV)
Index: src/mgr/swversemapper.cpp =================================================================== --- src/mgr/swversemapper.cpp (revision 0) +++ src/mgr/swversemapper.cpp (revision 0) @@ -0,0 +1,99 @@ +/****************************************************************************** + * versemapmgr.cpp - implementation of class VerseMapMgr 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 <swversemapper.h> +#include <versekey.h> +#include <swlog.h> + +SWORD_NAMESPACE_START + +VerseKey* SWVerseMapper::map(VerseKey* source_vk) { + if(source_vk->getVersificationSystem() != from_v11n->getName()) { + SWLog::getSystemLog()->logWarning("SWVerseMapper::map: source versekey doesn't match source versification!"); + return NULL; + } + + VerseKey* dest_vk = (VerseKey*) source_vk->clone(); + dest_vk->setVersificationSystem(to_v11n->getName()); + if(source_vk->isBoundSet()) + { + VerseKey* l = map(&source_vk->LowerBound()); + VerseKey* u = map(&source_vk->UpperBound()); + if(!l && !u) return NULL; + + // if only one of l and u are true, then we are reaching across + // book boundaries, so set the missing bound to start/end of book + if(!l) { + l = (VerseKey*) u->clone(); + l->Chapter(l->Headings() ? 0 : 1); + l->Verse(l->Headings() ? 0 : 1); + } + + if(!u) { + u = (VerseKey*) l->clone(); + u->setPosition(MAXCHAPTER); + u->setPosition(MAXVERSE); + } + + // swap them if necessary - it may not be much good, but we have to try + // for example, KJV VerseKey("Neh", "Mal") => Leningrad Mal 3:24-Neh 1:1 + if(*l > *u) { + VerseKey* tmp = l; + l = u; + u = tmp; + } + + dest_vk->LowerBound(l); + dest_vk->UpperBound(u); + delete l; + delete u; + + return dest_vk; + } + + int i = to_v11n->getBookNumberByOSISName(source_vk->getOSISBookName()); + if(i == -1) { + return NULL; + } + + dest_vk->Testament(1); + dest_vk->Book(i); + + if(source_vk->Chapter() > dest_vk->getChapterMax()){ + dest_vk->setPosition(MAXCHAPTER); + dest_vk->setPosition(MAXVERSE); + return dest_vk; + } + + dest_vk->Chapter(source_vk->Chapter()); + if(source_vk->Verse() > dest_vk->getVerseMax()) { + dest_vk->setPosition(MAXVERSE); + return dest_vk; + } + + dest_vk->setVerse(source_vk->getVerse()); + dest_vk->setSuffix(source_vk->getSuffix()); + return dest_vk; +} + + +SWORD_NAMESPACE_END Index: src/mgr/Makefile.am =================================================================== --- src/mgr/Makefile.am (revision 2368) +++ src/mgr/Makefile.am (working copy) @@ -31,5 +31,7 @@ libsword_la_SOURCES += $(mgrdir)/swsearchable.cpp libsword_la_SOURCES += $(mgrdir)/installmgr.cpp libsword_la_SOURCES += $(mgrdir)/stringmgr.cpp +libsword_la_SOURCES += $(mgrdir)/versemapmgr.cpp +libsword_la_SOURCES += $(mgrdir)/swversemapper.cpp Index: src/mgr/versemapmgr.cpp =================================================================== --- src/mgr/versemapmgr.cpp (revision 0) +++ src/mgr/versemapmgr.cpp (revision 0) @@ -0,0 +1,76 @@ +/****************************************************************************** + * versemapmgr.cpp - implementation of class VerseMapMgr 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 <versemapmgr.h> +#include <versekey.h> + +SWORD_NAMESPACE_START + +/*************************************************** + * VerseMapMgr + */ + +// ---------------- statics ----------------- +VerseMapMgr *VerseMapMgr::systemVerseMapMgr = 0; + +class __staticsystemVerseMapMgr { +public: + __staticsystemVerseMapMgr() { } + ~__staticsystemVerseMapMgr() { delete VerseMapMgr::systemVerseMapMgr; } +} _staticsystemVerseMapMgr; + + +void VerseMapMgr::init() { +} + + +VerseMapMgr::~VerseMapMgr() { +} + + +VerseMapMgr *VerseMapMgr::getSystemVerseMapMgr() { + if (!systemVerseMapMgr) { + systemVerseMapMgr = new VerseMapMgr(); + } + return systemVerseMapMgr; +} + + +void VerseMapMgr::setSystemVerseMapMgr(VerseMapMgr *newVerseMapMgr) { + if (systemVerseMapMgr) + delete systemVerseMapMgr; + systemVerseMapMgr = newVerseMapMgr; +} + + +SWVerseMapper* VerseMapMgr::getMapper(const char* v11n_from, const char* v11n_to) const { + const VerseMgr* v = VerseMgr::getSystemVerseMgr(); + return getMapper(v->getVersificationSystem(v11n_from), + v->getVersificationSystem(v11n_to)); +} + +SWVerseMapper* VerseMapMgr::getMapper(const VerseMgr::System* v11n_from, const VerseMgr::System* v11n_to) const { + if(!v11n_from || !v11n_to) return NULL; + return new SWVerseMapper(v11n_from, v11n_to); +} + +SWORD_NAMESPACE_END Index: src/keys/versekey.cpp =================================================================== --- src/keys/versekey.cpp (revision 2368) +++ src/keys/versekey.cpp (working copy) @@ -1041,7 +1041,10 @@ lowerBoundComponents.verse = 0; } - else tmpClone->setLocale(getLocale()); + else { + tmpClone->setLocale(getLocale()); + tmpClone->setVersificationSystem(getVersificationSystem()); + } } Index: bindings/swig/versekey.i =================================================================== --- bindings/swig/versekey.i (revision 2368) +++ bindings/swig/versekey.i (working copy) @@ -1,6 +1,8 @@ %{ #include "versekey.h" #include "versemgr.h" +#include "versemapmgr.h" +#include "swversemapper.h" %} @@ -21,6 +23,9 @@ %include "versekey.h" %include "versemgr.h" +%include "versemapmgr.h" +%include "swversemapper.h" + %extend sword::abbrev { int getAbbrevCount() { int abbrevsCnt; Index: include/Makefile.am =================================================================== --- include/Makefile.am (revision 2368) +++ include/Makefile.am (working copy) @@ -13,6 +13,8 @@ pkginclude_HEADERS += $(swincludedir)/femain.h pkginclude_HEADERS += $(swincludedir)/filemgr.h pkginclude_HEADERS += $(swincludedir)/versemgr.h +pkginclude_HEADERS += $(swincludedir)/versemapmgr.h +pkginclude_HEADERS += $(swincludedir)/swversemapper.h pkginclude_HEADERS += $(swincludedir)/flatapi.h pkginclude_HEADERS += $(swincludedir)/ftpparse.h pkginclude_HEADERS += $(swincludedir)/ftptrans.h Index: include/versemapmgr.h =================================================================== --- include/versemapmgr.h (revision 0) +++ include/versemapmgr.h (revision 0) @@ -0,0 +1,51 @@ +/****************************************************************************** + * versemapmgr.h - definition of class VerseMapMgr used for mapping + * versification systems + * + * $Id: $ + * + * Copyright 2009 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. + * + */ + +#ifndef VERSEMAPMGR_H +#define VERSEMAPMGR_H +#include <versemgr.h> +#include <swversemapper.h> + + + +SWORD_NAMESPACE_START + +class SWDLLEXPORT VerseMapMgr { +private: + friend class __staticsystemVerseMapMgr; + void init(); + +protected: + static VerseMapMgr *systemVerseMapMgr; + +public: + VerseMapMgr() { init(); } + virtual ~VerseMapMgr(); + static VerseMapMgr *getSystemVerseMapMgr(); + static void setSystemVerseMapMgr(VerseMapMgr *newVerseMgr); + virtual SWVerseMapper* getMapper(const char* v11n_from, const char* v11n_to) const; + virtual SWVerseMapper* getMapper(const VerseMgr::System* v11n_from, const VerseMgr::System* v11n_to) const; + +}; + +SWORD_NAMESPACE_END +#endif Index: include/swversemapper.h =================================================================== --- include/swversemapper.h (revision 0) +++ include/swversemapper.h (revision 0) @@ -0,0 +1,48 @@ +/****************************************************************************** + * versemapmgr.h - definition of class VerseMapMgr used for mapping + * versification systems + * + * $Id: $ + * + * Copyright 2009 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 <defs.h> +#include <versemgr.h> +#include <versekey.h> + +#ifndef SWVERSEMAPPER_H +#define SWVERSEMAPPER_H + + +SWORD_NAMESPACE_START + +class SWDLLEXPORT SWVerseMapper { +protected: + const VerseMgr::System* from_v11n; + const VerseMgr::System* to_v11n; + +public: + SWVerseMapper(const VerseMgr::System* i_from_v11n, + const VerseMgr::System* i_to_v11n) + : from_v11n(i_from_v11n), to_v11n(i_to_v11n) {}; + + virtual ~SWVerseMapper() {}; + virtual VerseKey* map(VerseKey* vk_from); +}; + +SWORD_NAMESPACE_END +#endif
_______________________________________________ sword-devel mailing list: sword-devel@crosswire.org http://www.crosswire.org/mailman/listinfo/sword-devel Instructions to unsubscribe/change your settings at above page