[sword-devel] Feature Complete Perl Interface

John Keiser sword-devel@crosswire.org
21 Jul 2001 22:38:52 -0400


Hmm.  So what you're saying is, even if I get a whole other SWKey object (as I am doing in that example--it's not just a reference, it's a whole SWKey), that object is tied to whatever the current key is in SWModule?

I'll have to think about that, it pretty much invalidates my entire
architecture :)

Let me tell you about what I'm doing.  I want to be able to create
multiple Iterators (essentially VerseKeys) that remember what verse
they're pointing to, and be able to use these Iterators in between each
other (e.g. $a->get_verse(); $b->next(); $b->get_verse(); $a->next();
$a->get_verse()).

The way I am doing this is, I store a VerseKey in my Iterator class.
Whenever someone accesses the iterator, I do these steps:

module->SetKey(key);
do my thing (possibly a *module++ or *module--)
key = module->Key(); (if I changed anything)

For instance, here is my implementation of next():

int VerseIterator::next(int how_far) {
        if(key == key.UpperBound()) {
                return 0;
        }
        module->SetKey(key);
        (*module) += how_far;
        key = module->Key();
        return 1;
}

The funny thing is, through a lot of testing, what I'm doing seems to
work (even when I do totally different stuff with my keys and access
them in between each other).

Am I doing this wrong?

I am aware that key supposedly supports adding and subtracting directly,
but my experience so far has been that it didn't do anything ... again,
I could be using the system wrong and probably am :)

--John


On 21 Jul 2001 16:54:38 -0700, Troy A. Griffitts wrote:
> > Oh, while we're at it, I think I've found a bug (though I could be just
> > doing something wrong.  The software does not seem to be able to compare
> > verses from books 32 and above (Jonah and above in the Old Testament).
> > Specifically, given the following code:
> > 
> > int VerseIterator::_verse_greater(char * verse1, char * verse2) {
> >         if(module->SetKey(verse1)) {
> >                 return -1;
> >         }
> >         SWKey key1 = module->Key();
> >         if(module->SetKey(verse2)) {
> >                 return -1;
> >         }
> >         SWKey key2 = module->Key();
> >         return key1 > key2;
> > }
> > 
> > The following results occur:
> > 
> > _verse_greater("James 3:4", "Malachi 4:5"); FALSE
> > _verse_greater("James 3:4", "Obadiah 12:21"); TRUE
> > _verse_greater("James 3:4", "Jonah 1:1"); FALSE
> > 
> 
> John,
>       This may sound weird, but you may be doing something illegal.  The
> module->SetKey method sets the module's key to a new internal VerseKey
> (assuming it's a Bible text).  You then grab a reference to the
> modules's key.  After this you, again, reset the module's key to a new
> value.  What your initial reference is pointing to is undefined.  It may
> be deallocated.  It may be the same internal key reset to the new value.
> 
> Am I making sense?  You may:
> 
> SWKey *key1 = module->Key().clone();
> 
> 
> or:
> 
> SWKey *key1 = module->CreateKey();
> *key1 = verse1;
> 
> either way, you'll need to delete key1 before you return from the
> method.
> 
>       Hope this helps,
>               -Troy.
> 
> PS.  Please let us know if there is still a comparison bug.
>