[sword-svn] r2280 - in trunk: examples/cmdline include src/keys src/modules src/modules/comments src/modules/genbook src/modules/genbook/rawgenbook src/modules/lexdict src/modules/texts tests

scribe at crosswire.org scribe at crosswire.org
Sat Mar 7 08:34:36 MST 2009


Author: scribe
Date: 2009-03-07 08:34:36 -0700 (Sat, 07 Mar 2009)
New Revision: 2280

Modified:
   trunk/examples/cmdline/search.cpp
   trunk/include/rawgenbook.h
   trunk/include/swcom.h
   trunk/include/swgenbook.h
   trunk/include/swld.h
   trunk/include/swmodule.h
   trunk/include/swtext.h
   trunk/include/treekey.h
   trunk/include/treekeyidx.h
   trunk/src/keys/listkey.cpp
   trunk/src/keys/treekeyidx.cpp
   trunk/src/keys/versekey.cpp
   trunk/src/keys/versetreekey.cpp
   trunk/src/modules/comments/swcom.cpp
   trunk/src/modules/genbook/rawgenbook/rawgenbook.cpp
   trunk/src/modules/genbook/swgenbook.cpp
   trunk/src/modules/lexdict/swld.cpp
   trunk/src/modules/swmodule.cpp
   trunk/src/modules/texts/swtext.cpp
   trunk/tests/vtreekeytest.cpp
Log:
ranges and searches work now with gb Bibles, but NOT optimized.
We always sync the tree and vkey up even when we don't have to.
Need to make this done on demand for speed.


Modified: trunk/examples/cmdline/search.cpp
===================================================================
--- trunk/examples/cmdline/search.cpp	2009-03-07 13:05:22 UTC (rev 2279)
+++ trunk/examples/cmdline/search.cpp	2009-03-07 15:34:36 UTC (rev 2280)
@@ -42,7 +42,6 @@
 	SWModule *target;
 	ListKey listkey;
 	ListKey scope;
-	VerseKey parser;
 	ModMap::iterator it;
 
 	if ((argc < 3) || (argc > 5)) {
@@ -70,14 +69,18 @@
 	target = (*it).second;
 
 	if (argc > 3) {			// if min / max specified
-		scope = parser.ParseVerseList(argv[3], parser, true);
+		SWKey *k = target->getKey();
+		VerseKey *parser = SWDYNAMIC_CAST(VerseKey, k);
+		VerseKey kjvParser;
+		if (!parser) parser = &kjvParser;	// use standard KJV parsing as fallback
+		scope = parser->ParseVerseList(argv[3], *parser, true);
 		scope.Persist(1);
 		target->setKey(scope);
 	}
 
 	std::cerr << "[0=================================50===============================100]\n ";
 	char lineLen = 70;
-	listkey = target->Search(searchTerm.c_str(), SEARCH_TYPE, /*SEARCHFLAG_MATCHWHOLEENTRY*/ REG_ICASE, 0, 0, &percentUpdate, &lineLen);
+	listkey = target->search(searchTerm.c_str(), SEARCH_TYPE, /*SEARCHFLAG_MATCHWHOLEENTRY*/ REG_ICASE, 0, 0, &percentUpdate, &lineLen);
 	std::cerr << std::endl;
 	if (argc > 4) {			// if min / max specified
 		scope = listkey;
@@ -85,7 +88,7 @@
 		target->setKey(scope);
 		printed = 0;
 		std::cerr << " ";
-		listkey = target->Search(argv[4], SEARCH_TYPE, /*SEARCHFLAG_MATCHWHOLEENTRY*/ REG_ICASE, 0, 0, &percentUpdate, &lineLen);
+		listkey = target->search(argv[4], SEARCH_TYPE, /*SEARCHFLAG_MATCHWHOLEENTRY*/ REG_ICASE, 0, 0, &percentUpdate, &lineLen);
 		std::cerr << std::endl;
 	}
 	listkey.sort();

Modified: trunk/include/rawgenbook.h
===================================================================
--- trunk/include/rawgenbook.h	2009-03-07 13:05:22 UTC (rev 2279)
+++ trunk/include/rawgenbook.h	2009-03-07 15:34:36 UTC (rev 2280)
@@ -51,7 +51,7 @@
 	virtual void setEntry(const char *inbuf, long len = -1);	// Modify current module entry
 	virtual void linkEntry(const SWKey * linkKey);	// Link current module entry to other module entry
 	virtual void deleteEntry();	// Delete current module entry
-	virtual SWKey *CreateKey();
+	virtual SWKey *CreateKey() const;
 	// end write interface ------------------------
 
 

Modified: trunk/include/swcom.h
===================================================================
--- trunk/include/swcom.h	2009-03-07 13:05:22 UTC (rev 2279)
+++ trunk/include/swcom.h	2009-03-07 15:34:36 UTC (rev 2280)
@@ -54,7 +54,7 @@
 			const char *versification = "KJV");
 
 	virtual ~SWCom();
-	virtual SWKey *CreateKey();
+	virtual SWKey *CreateKey() const;
 
 	virtual long Index() const;
 	virtual long Index(long iindex);

Modified: trunk/include/swgenbook.h
===================================================================
--- trunk/include/swgenbook.h	2009-03-07 13:05:22 UTC (rev 2279)
+++ trunk/include/swgenbook.h	2009-03-07 15:34:36 UTC (rev 2280)
@@ -22,9 +22,11 @@
 #ifndef SWGENBOOK_H
 #define SWGENBOOK_H
 
+#include <defs.h>
+
 #include <swmodule.h>
+#include <treekey.h>
 
-#include <defs.h>
 
 SWORD_NAMESPACE_START
 
@@ -34,6 +36,8 @@
 
 protected:
 	char *entkeytxt;
+	mutable TreeKey *tmpTreeKey;
+	TreeKey &getTreeKey() const;
 
 public:
 	/** Initializes data for instance of SWGenBook
@@ -44,7 +48,7 @@
 			SWTextMarkup markup = FMT_UNKNOWN, const char* ilang = 0);
 
 	virtual ~SWGenBook();
-	virtual SWKey *CreateKey() = 0;
+	virtual SWKey *CreateKey() const = 0;
 
 
 	// OPERATORS -----------------------------------------------------------------

Modified: trunk/include/swld.h
===================================================================
--- trunk/include/swld.h	2009-03-07 13:05:22 UTC (rev 2279)
+++ trunk/include/swld.h	2009-03-07 15:34:36 UTC (rev 2280)
@@ -44,7 +44,7 @@
 			SWTextMarkup markup = FMT_UNKNOWN, const char* ilang = 0);
 	
 	virtual ~SWLD();
-	virtual SWKey *CreateKey();
+	virtual SWKey *CreateKey() const;
 
 	/** Sets/gets module KeyText, getting from saved text if key is persistent
 	*

Modified: trunk/include/swmodule.h
===================================================================
--- trunk/include/swmodule.h	2009-03-07 13:05:22 UTC (rev 2279)
+++ trunk/include/swmodule.h	2009-03-07 15:34:36 UTC (rev 2280)
@@ -78,7 +78,7 @@
 // cache data.  But if we don't do this, then we need another mechanism to
 // check if we are an SWCacher.  Maybe make SWModule extend SWObject (which
 // it probably should anyway.  But then we need to add all the cheezy
-// heirarchy info to all he decendent classes for our SWDYNAMIC_CAST and
+// heirarchy info to all the decendent classes for our SWDYNAMIC_CAST and
 // then we can see if we implement SWCacher so we know whether or not to add
 // to the yet to be developed cachemgr.
 // Just leave for now.  This lets us always able to call module->flush()
@@ -381,7 +381,7 @@
 	 * @see VerseKey, ListKey, SWText, SWLD, SWCom
 	 * @return pointer to allocated key
 	 */
-	virtual SWKey *CreateKey();
+	virtual SWKey *CreateKey() const;
 
 	/** This function is reimplemented by the different kinds
 	 * of module objects
@@ -438,14 +438,14 @@
 	 * @param buf the buffer to filter
 	 * @param key key location from where this buffer was extracted
 	 */
-	virtual void filterBuffer(OptionFilterList *filters, SWBuf &buf, SWKey *key);
+	virtual void filterBuffer(OptionFilterList *filters, SWBuf &buf, const SWKey *key);
 
 	/** FilterBuffer a text buffer
 	 * @param filters the FilterList of filters to iterate
 	 * @param buf the buffer to filter
 	 * @param key key location from where this buffer was extracted
 	 */
-	virtual void filterBuffer(FilterList *filters, SWBuf &buf, SWKey *key);
+	virtual void filterBuffer(FilterList *filters, SWBuf &buf, const SWKey *key);
 
 	/** Adds a RenderFilter to this module's renderFilters queue.
 	 *	Render Filters are called when the module is asked to produce
@@ -493,7 +493,7 @@
 	 * @param buf the buffer to filter
 	 * @param key key location from where this buffer was extracted
 	 */
-	virtual void renderFilter(SWBuf &buf, SWKey *key) {
+	virtual void renderFilter(SWBuf &buf, const SWKey *key) {
 		filterBuffer(renderFilters, buf, key);
 	}
 
@@ -536,7 +536,7 @@
 	 * @param buf the buffer to filter
 	 * @param key key location from where this buffer was extracted
 	 */
-	virtual void encodingFilter(SWBuf &buf, SWKey *key) {
+	virtual void encodingFilter(SWBuf &buf, const SWKey *key) {
 		filterBuffer(encodingFilters, buf, key);
 	}
 
@@ -564,7 +564,7 @@
 	 * @param buf the buffer to filter
 	 * @param key key location from where this buffer was extracted
 	 */
-	virtual void stripFilter(SWBuf &buf, SWKey *key) {
+	virtual void stripFilter(SWBuf &buf, const SWKey *key) {
 		filterBuffer(stripFilters, buf, key);
 	}
 
@@ -573,7 +573,7 @@
 	 * @param buf the buffer to filter
 	 * @param key key location from where this buffer was extracted
 	 */
-	virtual void rawFilter(SWBuf &buf, SWKey *key) {
+	virtual void rawFilter(SWBuf &buf, const SWKey *key) {
 		filterBuffer(rawFilters, buf, key);
 	}
 
@@ -593,7 +593,7 @@
 	 * @param buf the buffer to filter
 	 * @param key key location from where this buffer was extracted
 	 */
-	virtual void optionFilter(SWBuf &buf, SWKey *key) {
+	virtual void optionFilter(SWBuf &buf, const SWKey *key) {
 		filterBuffer(optionFilters, buf, key);
 	}
 
@@ -621,13 +621,13 @@
 	 * @param tmpKey desired module entry
 	 * @return result buffer
 	 */
-	virtual const char *StripText(SWKey *tmpKey);
+	virtual const char *StripText(const SWKey *tmpKey);
 
 	/** Produces renderable text of the module entry at the supplied key
 	 * @param tmpKey key to use to grab text
 	 * @return this module's text at specified key location massaged by Render filters
 	 */
-	virtual const char *RenderText(SWKey *tmpKey);
+	virtual const char *RenderText(const SWKey *tmpKey);
 
 	/** Whether or not to only hit one entry when iterating encounters
 	 *	consecutive links when iterating

Modified: trunk/include/swtext.h
===================================================================
--- trunk/include/swtext.h	2009-03-07 13:05:22 UTC (rev 2279)
+++ trunk/include/swtext.h	2009-03-07 15:34:36 UTC (rev 2280)
@@ -55,7 +55,7 @@
 	virtual ~SWText();
 	/** Create the correct key (VerseKey) for use with SWText
 	*/
-	virtual SWKey *CreateKey();
+	virtual SWKey *CreateKey() const;
 
 	virtual long Index() const;
 	virtual long Index(long iindex);

Modified: trunk/include/treekey.h
===================================================================
--- trunk/include/treekey.h	2009-03-07 13:05:22 UTC (rev 2279)
+++ trunk/include/treekey.h	2009-03-07 15:34:36 UTC (rev 2280)
@@ -74,7 +74,7 @@
 
 	virtual int getLevel() { long bm = getOffset(); int level = 0; do { level++; } while (parent()); setOffset(bm); return level; }
 
-	virtual const char *getUserData(int *size = 0) = 0;
+	virtual const char *getUserData(int *size = 0) const = 0;
 	virtual void setUserData(const char *userData, int size = 0) = 0;
 
 	/** Go to the root node

Modified: trunk/include/treekeyidx.h
===================================================================
--- trunk/include/treekeyidx.h	2009-03-07 13:05:22 UTC (rev 2279)
+++ trunk/include/treekeyidx.h	2009-03-07 15:34:36 UTC (rev 2280)
@@ -75,7 +75,7 @@
 	virtual const char *getLocalName();
 	virtual const char *setLocalName(const char *);
 
-	virtual const char *getUserData(int *size = 0);
+	virtual const char *getUserData(int *size = 0) const;
 	virtual void setUserData(const char *userData, int size = 0);
 
 	virtual void root();

Modified: trunk/src/keys/listkey.cpp
===================================================================
--- trunk/src/keys/listkey.cpp	2009-03-07 13:05:22 UTC (rev 2279)
+++ trunk/src/keys/listkey.cpp	2009-03-07 15:34:36 UTC (rev 2280)
@@ -58,6 +58,8 @@
 
 void ListKey::init() {
 	myclass = &classdef;
+	// this is a listkey, bound is always set
+	boundSet = true;
 }
 
 

Modified: trunk/src/keys/treekeyidx.cpp
===================================================================
--- trunk/src/keys/treekeyidx.cpp	2009-03-07 13:05:22 UTC (rev 2279)
+++ trunk/src/keys/treekeyidx.cpp	2009-03-07 15:34:36 UTC (rev 2280)
@@ -91,7 +91,7 @@
 }
 
 
-const char *TreeKeyIdx::getUserData(int *size) {
+const char *TreeKeyIdx::getUserData(int *size) const {
 	unsnappedKeyText = "";
 	if (size)
 		*size = (int)currentNode.dsize;

Modified: trunk/src/keys/versekey.cpp
===================================================================
--- trunk/src/keys/versekey.cpp	2009-03-07 13:05:22 UTC (rev 2279)
+++ trunk/src/keys/versekey.cpp	2009-03-07 15:34:36 UTC (rev 2280)
@@ -1319,7 +1319,11 @@
 {
 	int bnum = getBookAbbrev(bname);
 	if (bnum > -1) {
-		setTestament(1);
+		if (bnum > BMAX[0]) {
+			bnum -= BMAX[0];
+			testament = 2;
+		}
+		else	testament = 1;
 		setBook(bnum);
 	}
 	else error = KEYERR_OUTOFBOUNDS;
@@ -1463,7 +1467,7 @@
 
 
 /******************************************************************************
- * VerseKey::Index - Gets index based upon current verse
+ * VerseKey::TestamentIndex - Gets index based upon current verse
  *
  * RET:	offset
  */
@@ -1497,56 +1501,6 @@
 	if (book < 0) { testament = 0; book = 0; }
 	if (chapter < 0) { book = 0; chapter = 0; }
 
-/*
-	suffix = 0;
-// This is the dirty stuff --------------------------------------------
-
-	if (!testament)
-		testament = 1;
-
-	if (iindex < 1) {				// if (-) or module heading
-		if (testament < 2) {
-			if (iindex < 0) {
-				testament = 0;  // previously we changed 0 -> 1
-				error     = KEYERR_OUTOFBOUNDS;
-			}
-			else testament = 0;		// we want module heading
-		}
-		else {
-			testament--;
-			const VerseMgr::Book *b = refSys->getBook(BMAX[0]+((testament)?BMAX[1]:0)-1);
-			iindex = offsets[testament-1][1][offsize[testament-1][1]-1]
-			       + b->getVerseMax(b->getChapterMax())
-			       + iindex; // What a doozy! ((offset of last chapter + number of verses in the last chapter) + iindex)
-		}
-	}
-
-// --------------------------------------------------------------------
-
-
-	if (testament) {
-		if ((!error) && (iindex)) {
-			offset  = findindex(offsets[testament-1][1], offsize[testament-1][1], iindex);
-			verse   = iindex - offsets[testament-1][1][offset];
-			book    = findindex(offsets[testament-1][0], offsize[testament-1][0], offset);
-			chapter = offset - offsets[testament-1][0][VerseKey::book];
-			verse   = (chapter) ? verse : 0;  // funny check. if we are index=1 (testmt header) all gets set to 0 exept verse.  Don't know why.  Fix if you figure out.  Think its in the offsets table.
-			if (verse) {		// only check if -1 won't give negative
-				if (verse > getVerseMax()) {
-					if (testament > 1) {
-						verse = getVerseMax();
-						error = KEYERR_OUTOFBOUNDS;
-					}
-					else {
-						testament++;
-						const VerseMgr::Book *b = refSys->getBook(book-1);
-						Index(verse - b->getVerseMax(chapter-1));
-					}
-				}
-			}
-		}
-	}
-*/
 	long i = Index();
 
 	initBounds();

Modified: trunk/src/keys/versetreekey.cpp
===================================================================
--- trunk/src/keys/versetreekey.cpp	2009-03-07 13:05:22 UTC (rev 2279)
+++ trunk/src/keys/versetreekey.cpp	2009-03-07 15:34:36 UTC (rev 2280)
@@ -141,7 +141,17 @@
 		treeKey->setOffset(lastGoodOffset);
 		error = treeError;
 	}
+	if (_compare(UpperBound()) > 0) {
+		positionFrom(UpperBound());
+		error = KEYERR_OUTOFBOUNDS;
+	}
+	if (_compare(LowerBound()) < 0) {
+		positionFrom(LowerBound());
+		error = KEYERR_OUTOFBOUNDS;
+	}
 }
+
+
 void VerseTreeKey::increment(int steps) {
 	int treeError = 0;
 	if (!error) lastGoodOffset = getTreeKey()->getOffset();
@@ -159,6 +169,15 @@
 		treeKey->setOffset(lastGoodOffset);
 		error = treeError;
 	}
+	// bounds
+	if (_compare(UpperBound()) > 0) {
+		positionFrom(UpperBound());
+		error = KEYERR_OUTOFBOUNDS;
+	}
+	if (_compare(LowerBound()) < 0) {
+		positionFrom(LowerBound());
+		error = KEYERR_OUTOFBOUNDS;
+	}
 }
 
 
@@ -175,6 +194,8 @@
 			legs++;
 		} while (tkey->parent() && (legs < 4));
 
+		legs--;
+
 		if ((legs < 2) && (!seg[0].length() || seg[0] == "/")) {		//"[ Module Heading ]";
 			testament = 0;
 			book      = 0;
@@ -191,9 +212,9 @@
 			setVerse(0);
 		}	//path = "[ Module Heading ]";
 		else {
-			setBookName(seg[legs--]);
-			chapter = (legs > -1) ? atoi(seg[legs--]) : 0;
-			setVerse((legs > -1) ? atoi(seg[legs--]) : 0);
+			setBookName(seg[--legs]);
+			chapter = (legs > 0) ? atoi(seg[--legs]) : 0;
+			setVerse((legs > 0) ? atoi(seg[--legs]) : 0);
 		}
 
 //		setText(path);

Modified: trunk/src/modules/comments/swcom.cpp
===================================================================
--- trunk/src/modules/comments/swcom.cpp	2009-03-07 13:05:22 UTC (rev 2279)
+++ trunk/src/modules/comments/swcom.cpp	2009-03-07 15:34:36 UTC (rev 2280)
@@ -56,7 +56,7 @@
 }
 
 
-SWKey *SWCom::CreateKey() {
+SWKey *SWCom::CreateKey() const {
 	VerseKey *vk = new VerseKey();
 
 	vk->setVersificationSystem(versification);
@@ -104,7 +104,7 @@
 
 
 VerseKey &SWCom::getVerseKey() const {
-	VerseKey *key = NULL;
+	VerseKey *key = 0;
 	// see if we have a VerseKey * or decendant
 	SWTRY {
 		key = SWDYNAMIC_CAST(VerseKey, this->key);

Modified: trunk/src/modules/genbook/rawgenbook/rawgenbook.cpp
===================================================================
--- trunk/src/modules/genbook/rawgenbook/rawgenbook.cpp	2009-03-07 13:05:22 UTC (rev 2279)
+++ trunk/src/modules/genbook/rawgenbook/rawgenbook.cpp	2009-03-07 15:34:36 UTC (rev 2280)
@@ -98,37 +98,17 @@
 
 	__u32 offset = 0;
 	__u32 size = 0;
-	bool freeKey = false;
 
-	TreeKey *key = 0;
-	SWTRY {
-		key = SWDYNAMIC_CAST(TreeKey, (this->key));
-	}
-	SWCATCH ( ... ) {}
+	const TreeKey &key = getTreeKey();
 
-	if (!key) {
-		VerseTreeKey *tkey = 0;
-		SWTRY {
-			tkey = SWDYNAMIC_CAST(VerseTreeKey, (this->key));
-		}
-		SWCATCH ( ... ) {}
-		if (tkey) key = tkey->getTreeKey();
-	}
-
-	if (!key) {
-		freeKey = true;
-		key = (TreeKeyIdx *)CreateKey();
-		(*key) = *(this->key);
-	}
-
 	int dsize;
-	key->getUserData(&dsize);
+	key.getUserData(&dsize);
 	entryBuf = "";
 	if (dsize > 7) {
-		memcpy(&offset, key->getUserData(), 4);
+		memcpy(&offset, key.getUserData(), 4);
 		offset = swordtoarch32(offset);
 
-		memcpy(&size, key->getUserData() + 4, 4);
+		memcpy(&size, key.getUserData() + 4, 4);
 		size = swordtoarch32(size);
 
 		entrySize = size;        // support getEntrySize call
@@ -139,15 +119,12 @@
 		bdtfd->read(entryBuf.getRawData(), size);
 
 		rawFilter(entryBuf, 0);	// hack, decipher
-		rawFilter(entryBuf, key);
+		rawFilter(entryBuf, &key);
 
 //		   if (!isUnicode())
 			SWModule::prepText(entryBuf);
 	}
 
-	if (freeKey) // free our key if we created a VerseKey
-		delete key;
-
 	return entryBuf;
 }
 
@@ -156,7 +133,7 @@
 
 	__u32 offset = archtosword32(bdtfd->seek(0, SEEK_END));
 	__u32 size = 0;
-	TreeKeyIdx *key = ((TreeKeyIdx *)this->key);
+	TreeKeyIdx *key = ((TreeKeyIdx *)&(getTreeKey()));
 
 	char userData[8];
 
@@ -175,7 +152,7 @@
 
 void RawGenBook::linkEntry(const SWKey *inkey) {
 	TreeKeyIdx *srckey = 0;
-	TreeKeyIdx *key = ((TreeKeyIdx *)this->key);
+	TreeKeyIdx *key = ((TreeKeyIdx *)&(getTreeKey()));
 	// see if we have a VerseKey * or decendant
 	SWTRY {
 		srckey = SWDYNAMIC_CAST(TreeKeyIdx, inkey);
@@ -202,7 +179,7 @@
  */
 
 void RawGenBook::deleteEntry() {
-	TreeKeyIdx *key = ((TreeKeyIdx *)this->key);
+	TreeKeyIdx *key = ((TreeKeyIdx *)&(getTreeKey()));
 	key->remove();
 }
 
@@ -230,7 +207,7 @@
 }
 
 
-SWKey *RawGenBook::CreateKey() {
+SWKey *RawGenBook::CreateKey() const {
 	TreeKey *tKey = new TreeKeyIdx(path);
 	if (verseKey) { SWKey *vtKey = new VerseTreeKey(tKey); delete tKey; return vtKey; }
 	return tKey;

Modified: trunk/src/modules/genbook/swgenbook.cpp
===================================================================
--- trunk/src/modules/genbook/swgenbook.cpp	2009-03-07 13:05:22 UTC (rev 2279)
+++ trunk/src/modules/genbook/swgenbook.cpp	2009-03-07 15:34:36 UTC (rev 2280)
@@ -21,6 +21,7 @@
 
 
 #include <swgenbook.h>
+#include <versetreekey.h>
 
 SWORD_NAMESPACE_START
 
@@ -33,14 +34,65 @@
  */
 
 SWGenBook::SWGenBook(const char *imodname, const char *imoddesc, SWDisplay *idisp, SWTextEncoding enc, SWTextDirection dir, SWTextMarkup mark, const char* ilang) : SWModule(imodname, imoddesc, idisp, (char *)"Generic Books", enc, dir, mark, ilang) {
+	tmpTreeKey = 0;
 }
 
 
 /******************************************************************************
- * SWLD Destructor - Cleans up instance of SWLD
+ * SWLD Destructor - Cleans up instance of SWGenBook
  */
 
 SWGenBook::~SWGenBook() {
+	delete tmpTreeKey;
 }
 
+
+TreeKey &SWGenBook::getTreeKey() const {
+
+	TreeKey *key = 0;
+
+	SWTRY {
+		key = SWDYNAMIC_CAST(TreeKey, (this->key));
+	}
+	SWCATCH ( ... ) {}
+
+	if (!key) {
+		ListKey *lkTest = 0;
+		SWTRY {
+			lkTest = SWDYNAMIC_CAST(ListKey, this->key);
+		}
+		SWCATCH ( ... ) {	}
+		if (lkTest) {
+			SWTRY {
+				key = SWDYNAMIC_CAST(TreeKey, lkTest->GetElement());
+				if (!key) {
+					VerseTreeKey *tkey = 0;
+					SWTRY {
+						tkey = SWDYNAMIC_CAST(VerseTreeKey, lkTest->GetElement());
+					}
+					SWCATCH ( ... ) {}
+					if (tkey) key = tkey->getTreeKey();
+				}
+			}
+			SWCATCH ( ... ) {	}
+		}
+	}
+	if (!key) {
+		VerseTreeKey *tkey = 0;
+		SWTRY {
+			tkey = SWDYNAMIC_CAST(VerseTreeKey, (this->key));
+		}
+		SWCATCH ( ... ) {}
+		if (tkey) key = tkey->getTreeKey();
+	}
+
+	if (!key) {
+		delete tmpTreeKey;
+		tmpTreeKey = (TreeKey *)CreateKey();
+		(*tmpTreeKey) = *(this->key);
+		return (*tmpTreeKey);
+	}
+	else	return *key;
+}
+
 SWORD_NAMESPACE_END

Modified: trunk/src/modules/lexdict/swld.cpp
===================================================================
--- trunk/src/modules/lexdict/swld.cpp	2009-03-07 13:05:22 UTC (rev 2279)
+++ trunk/src/modules/lexdict/swld.cpp	2009-03-07 15:34:36 UTC (rev 2280)
@@ -52,7 +52,7 @@
 }
 
 
-SWKey *SWLD::CreateKey() { return new StrKey(); }
+SWKey *SWLD::CreateKey() const { return new StrKey(); }
 
 
 /******************************************************************************

Modified: trunk/src/modules/swmodule.cpp
===================================================================
--- trunk/src/modules/swmodule.cpp	2009-03-07 13:05:22 UTC (rev 2279)
+++ trunk/src/modules/swmodule.cpp	2009-03-07 15:34:36 UTC (rev 2280)
@@ -145,7 +145,7 @@
  * RET:	pointer to allocated key
  */
 
-SWKey *SWModule::CreateKey()
+SWKey *SWModule::CreateKey() const
 {
 	return new SWKey();
 }
@@ -874,7 +874,7 @@
  * RET: this module's text at current key location massaged by RenderFilers
  */
 
- const char *SWModule::RenderText(SWKey *tmpKey) {
+ const char *SWModule::RenderText(const SWKey *tmpKey) {
 	SWKey *saveKey;
 	const char *retVal;
 
@@ -905,7 +905,7 @@
  * RET: this module's text at specified key location massaged by Strip filters
  */
 
-const char *SWModule::StripText(SWKey *tmpKey) {
+const char *SWModule::StripText(const SWKey *tmpKey) {
 	SWKey *saveKey;
 	const char *retVal;
 
@@ -1314,7 +1314,7 @@
  * @param buf the buffer to filter
  * @param key key location from where this buffer was extracted
  */
-void SWModule::filterBuffer(OptionFilterList *filters, SWBuf &buf, SWKey *key) {
+void SWModule::filterBuffer(OptionFilterList *filters, SWBuf &buf, const SWKey *key) {
 	OptionFilterList::iterator it;
 	for (it = filters->begin(); it != filters->end(); it++) {
 		(*it)->processText(buf, key, this);
@@ -1326,7 +1326,7 @@
  * @param buf the buffer to filter
  * @param key key location from where this buffer was extracted
  */
-void SWModule::filterBuffer(FilterList *filters, SWBuf &buf, SWKey *key) {
+void SWModule::filterBuffer(FilterList *filters, SWBuf &buf, const SWKey *key) {
 	FilterList::iterator it;
 	for (it = filters->begin(); it != filters->end(); it++) {
 		(*it)->processText(buf, key, this);

Modified: trunk/src/modules/texts/swtext.cpp
===================================================================
--- trunk/src/modules/texts/swtext.cpp	2009-03-07 13:05:22 UTC (rev 2279)
+++ trunk/src/modules/texts/swtext.cpp	2009-03-07 15:34:36 UTC (rev 2280)
@@ -58,7 +58,7 @@
  * SWText CreateKey - Create the correct key (VerseKey) for use with SWText
  */
 
-SWKey *SWText::CreateKey() {
+SWKey *SWText::CreateKey() const {
 	VerseKey *vk = new VerseKey();
 
 	vk->setVersificationSystem(versification);
@@ -106,7 +106,7 @@
 
 
 VerseKey &SWText::getVerseKey() const {
-	VerseKey *key = NULL;
+	VerseKey *key = 0;
 	// see if we have a VerseKey * or decendant
 	SWTRY {
 		key = SWDYNAMIC_CAST(VerseKey, this->key);

Modified: trunk/tests/vtreekeytest.cpp
===================================================================
--- trunk/tests/vtreekeytest.cpp	2009-03-07 13:05:22 UTC (rev 2279)
+++ trunk/tests/vtreekeytest.cpp	2009-03-07 15:34:36 UTC (rev 2280)
@@ -72,13 +72,17 @@
 	cout << "\nListkey persist key iteration test\n\n";
 	keys = key1->ParseVerseList("mat1", 0, true);
 
+	for (keys = TOP; !keys.Error(); keys++) {
+		cout << "\n" << keys.getText() << ":\n" << endl;
+	}
+
+
 	keys.Persist(1);
 
 	mod->setKey(keys);
 
 	for ((*mod) = TOP; !mod->Error(); (*mod)++) {
 		cout << "\n" << mod->getKeyText() << ":\n" << endl;
-		
 	}
 
 	delete key1;




More information about the sword-cvs mailing list