[sword-svn] r2313 - in trunk: include src/keys
scribe at crosswire.org
scribe at crosswire.org
Thu Apr 9 07:38:57 MST 2009
Author: scribe
Date: 2009-04-09 07:38:57 -0700 (Thu, 09 Apr 2009)
New Revision: 2313
Modified:
trunk/include/versekey.h
trunk/src/keys/versekey.cpp
Log:
Added code to better handle autonorm off
Modified: trunk/include/versekey.h
===================================================================
--- trunk/include/versekey.h 2009-04-09 13:10:03 UTC (rev 2312)
+++ trunk/include/versekey.h 2009-04-09 14:38:57 UTC (rev 2313)
@@ -89,7 +89,9 @@
*/
int findindex(long *array, int size, long value);
- mutable long lowerBound, upperBound;
+ // internal upper/lower bounds optimizations
+ mutable long lowerBound, upperBound; // if autonorms is on
+ mutable struct { int test; int book; int chap; int verse; } lowerBoundComponents, upperBoundComponents; // if autonorms is off, we can't optimize with index
mutable VerseKey *tmpClone;
protected:
@@ -349,8 +351,12 @@
* @return if unchanged -> value of autonorm,
* if changed -> previous value of autonorm
*/
- virtual char AutoNormalize(char iautonorm = MAXPOS(char));
+ virtual char AutoNormalize(char iautonorm) { char retVal = isAutoNormalize()?1:0; setAutoNormalize(iautonorm); return retVal; } // deprecated
+ virtual char AutoNormalize() const { return isAutoNormalize()?1:0; } // deprecated
+ virtual bool isAutoNormalize() const;
+ virtual void setAutoNormalize(bool iautonorm);
+
/** Sets/gets flag that tells VerseKey to include
* chapter/book/testament/module headings
*
Modified: trunk/src/keys/versekey.cpp
===================================================================
--- trunk/src/keys/versekey.cpp 2009-04-09 13:10:03 UTC (rev 2312)
+++ trunk/src/keys/versekey.cpp 2009-04-09 14:38:57 UTC (rev 2313)
@@ -903,15 +903,20 @@
VerseKey &VerseKey::LowerBound(const VerseKey &lb)
{
initBounds();
+
lowerBound = lb.Index();
+ lowerBoundComponents.test = lb.getTestament();
+ lowerBoundComponents.book = lb.getBook();
+ lowerBoundComponents.chap = lb.getChapter();
+ lowerBoundComponents.verse = lb.getVerse();
+
// both this following check and UpperBound check force upperBound to
// change allowing LowerBound then UpperBound logic to always flow
// and set values without restrictions, as expected
if (upperBound < lowerBound) upperBound = lowerBound;
- tmpClone->Index(lowerBound);
boundSet = true;
- return (*tmpClone);
+ return LowerBound();
}
@@ -922,13 +927,18 @@
VerseKey &VerseKey::UpperBound(const VerseKey &ub)
{
initBounds();
+
upperBound = ub.Index();
+ upperBoundComponents.test = ub.getTestament();
+ upperBoundComponents.book = ub.getBook();
+ upperBoundComponents.chap = ub.getChapter();
+ upperBoundComponents.verse = ub.getVerse();
+
// see LowerBound comment, above
if (upperBound < lowerBound) upperBound = lowerBound;
- tmpClone->Index(upperBound);
boundSet = true;
- return (*tmpClone);
+ return UpperBound();
}
@@ -939,7 +949,13 @@
VerseKey &VerseKey::LowerBound() const
{
initBounds();
- tmpClone->Index(lowerBound);
+ if (!isAutoNormalize()) {
+ tmpClone->testament = lowerBoundComponents.test;
+ tmpClone->book = lowerBoundComponents.book;
+ tmpClone->chapter = lowerBoundComponents.chap;
+ tmpClone->setVerse (lowerBoundComponents.verse);
+ }
+ else tmpClone->Index(lowerBound);
return (*tmpClone);
}
@@ -952,7 +968,13 @@
VerseKey &VerseKey::UpperBound() const
{
initBounds();
- tmpClone->Index(upperBound);
+ if (!isAutoNormalize()) {
+ tmpClone->testament = upperBoundComponents.test;
+ tmpClone->book = upperBoundComponents.book;
+ tmpClone->chapter = upperBoundComponents.chap;
+ tmpClone->setVerse (upperBoundComponents.verse);
+ }
+ else tmpClone->Index(upperBound);
return (*tmpClone);
}
@@ -982,7 +1004,17 @@
tmpClone->Chapter(tmpClone->getChapterMax());
tmpClone->Verse(tmpClone->getVerseMax());
upperBound = tmpClone->Index();
+ upperBoundComponents.test = tmpClone->getTestament();
+ upperBoundComponents.book = tmpClone->getBook();
+ upperBoundComponents.chap = tmpClone->getChapter();
+ upperBoundComponents.verse = tmpClone->getVerse();
+
lowerBound = 0;
+ lowerBoundComponents.test = 0;
+ lowerBoundComponents.book = 0;
+ lowerBoundComponents.chap = 0;
+ lowerBoundComponents.verse = 0;
+
}
else tmpClone->setLocale(getLocale());
}
@@ -1043,19 +1075,19 @@
switch (p) {
case POS_TOP: {
const VerseKey *lb = &LowerBound();
- testament = lb->Testament();
- book = lb->Book();
- chapter = lb->Chapter();
- verse = lb->Verse();
+ testament = (lb->Testament() || headings) ? lb->Testament() : 1;
+ book = (lb->Book() || headings) ? lb->Book() : 1;
+ chapter = (lb->Chapter() || headings) ? lb->Chapter() : 1;
+ verse = (lb->Verse() || headings) ? lb->Verse() : 1;
suffix = lb->getSuffix();
break;
}
case POS_BOTTOM: {
const VerseKey *ub = &UpperBound();
- testament = ub->Testament();
- book = ub->Book();
- chapter = ub->Chapter();
- verse = ub->Verse();
+ testament = (ub->Testament() || headings) ? ub->Testament() : 1;
+ book = (ub->Book() || headings) ? ub->Book() : 1;
+ chapter = (ub->Chapter() || headings) ? ub->Chapter() : 1;
+ verse = (ub->Verse() || headings) ? ub->Verse() : 1;
suffix = ub->getSuffix();
break;
}
@@ -1235,7 +1267,7 @@
/******************************************************************************
- * VerseKey::Testament - Gets testament
+ * VerseKey::getTestament - Gets testament
*
* RET: value of testament
*/
@@ -1247,7 +1279,7 @@
/******************************************************************************
- * VerseKey::Book - Gets book
+ * VerseKey::getBook - Gets book
*
* RET: value of book
*/
@@ -1302,7 +1334,7 @@
/******************************************************************************
- * VerseKey::Book - Sets/gets book
+ * VerseKey::setBook - Sets/gets book
*
* ENT: ibook - value which to set book
*/
@@ -1317,7 +1349,7 @@
/******************************************************************************
- * VerseKey::Book - Sets/gets book by name
+ * VerseKey::setBookName - Sets/gets book by name
*
* ENT: bname - book name/abbrev
*/
@@ -1338,7 +1370,7 @@
/******************************************************************************
- * VerseKey::Chapter - Sets/gets chapter
+ * VerseKey::setChapter - Sets/gets chapter
*
* ENT: ichapter - value which to set chapter
*/
@@ -1352,7 +1384,7 @@
/******************************************************************************
- * VerseKey::Verse - Sets/gets verse
+ * VerseKey::setVerse - Sets/gets verse
*
* ENT: iverse - value which to set verse
* [MAXPOS(int)] - only get
@@ -1380,23 +1412,17 @@
/******************************************************************************
* VerseKey::AutoNormalize - Sets/gets flag that tells VerseKey to auto-
* matically normalize itself when modified
- *
- * ENT: iautonorm - value which to set autonorm
- * [MAXPOS(char)] - only get
- *
- * RET: if unchanged -> value of autonorm
- * if changed -> previous value of autonorm
*/
-char VerseKey::AutoNormalize(char iautonorm)
+bool VerseKey::isAutoNormalize() const
{
- char retval = autonorm;
+ return autonorm;
+}
- if (iautonorm != MAXPOS(char)) {
- autonorm = iautonorm;
- Normalize(1);
- }
- return retval;
+void VerseKey::setAutoNormalize(bool iautonorm)
+{
+ autonorm = iautonorm?1:0;
+ Normalize(1);
}
More information about the sword-cvs
mailing list