[sword-devel] Learning the Sword API

Tim Hawes sword-devel@crosswire.org
Tue, 06 Feb 2001 08:48:59 -0500


--------------BF9E858A78AD33816584E4EF
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

I realize that I was unclear in my last post. The trouble lines are:

mykey = webster.CreateKey();    // this creates a VerseKey object
type `VerseKey' is not a base type for type `SWKey'

If I cast webster.CreateKey() with (VerseKey *), the program compiles
but then segfaults

But this might be because of this:

for (mykey = "jas 1:1"; mykey->Chapter() == 1; mykey++) {
assignment to `VerseKey *' from `const char *'

Going on your suggestion to change mykey = "jas 1:1" to *mykey="jas 1:1"
the compiler quits complaining, but still segfaults when run. I compiled
with Electric Fence and efence reports in gdb:

Program received signal SIGSEGV, Segmentation fault.
0x8049bf9 in main (argc=1, argv=0xbfffeb44) at test.cpp:25

Line 25 is this line:
for (*mykey = "jas 1:1"; mykey->Chapter() == 1; mykey++) {

I hope this is clearer.

Tim Hawes wrote:

> This is taken directly from the Sword API Primer:
>
>     RawText webster("modules/texts/rawtext/webster/", "Webster",
> "Webster Text");
>     RawCom  mhc("modules/comments/rawcom/mhc/", "MHC", "Matthew
> Henry's Commentary on the Whole Bible");
>
>     VerseKey *mykey;
>     mykey = webster.CreateKey();    // this creates a VerseKey object
>
>     mykey.Persist(true);
>
>     webster.SetKey(*mykey);
>     mhc.SetKey(*mykey);
>
>     for (mykey = "jas 1:1"; mykey.Chapter() == 1; mykey++) {
>         cout << webster.KeyText() << ":\n";
>         cout << (const char *) webster << "\n";
>         cout << "-------------\n";
>         cout << (const char *) mhc << "\n";
>     }
>
> I get these errors:
> g++ -c -g3 -I/usr/include/sword -o test.o test.cpp
> test.cpp: In function `int main(int, char **)':
> test.cpp:18: type `VerseKey' is not a base type for type `SWKey'
> test.cpp:20: request for member `Persist' in `mykey', which is of
> non-aggregate type `VerseKey *'
> test.cpp:25: assignment to `VerseKey *' from `const char *'
> test.cpp:25: request for member `Chapter' in `mykey', which is of
> non-aggregate type `VerseKey *'
>
> Now there are some obvious mistakes. mykey is a pointer so
> mykey.Persist(true) should be mykey->Persist(true) and mykey.Chapter()
> should be mykey->Chapter(). These are easy enough, but what about
> "VerseKey' is not a base type for type `SWKey'" and "assignment to
> `VerseKey *' from `const char *'"? I tried casting these accordingly
> and it either doesn't compile or it segfaults when run.
>
>
> "Troy A. Griffitts" wrote:
>
>> Tim Hawes wrote:
>> >
>> > I can tell the Sword API Primer is dated. Even after examining the
>>
>> > header files, it is still very unclear how I can set a VerseKey to
>> a
>> > particular reference. This does not work:
>> >
>> > VerseKey *mykey;
>> >
>> > mykey = "jas 1:19";
>> >
>> > Can anyone help me out, here? Thanks in advance.
>>
>> VerseKey mykey;
>> mykey = "jas 1:19
>>
>> NOTE:
>> -VerseKey *mykey;
>> +VerseKey mykey;
>>
>> If you're gonna declare a pointer, you must new the object, then
>> free
>> it... e.g.
>>
>> VerseKey *mykey = new VerseKey();
>> *mykey = "jas 1:19";
>>
>> // do some stuff with the key
>>
>> delete mykey;
>>
>> Maybe a C++Primer might help.
>>
>>         -Troy.
>
> --
> \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
>
>   Tim Hawes
>
>      ***Althusius.net***
>       http://Althusius.net
>
>           thawes@althusius.net
>
> ---------------------------------------------------------
>  Toleration is an inner personal disposition, is a
> fundamental requirement of being human and of living
> together in society . . .When toleration becomes
> indifference, it is ruined.                -Van Ruler
>
>

--
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

  Tim Hawes

     ***Althusius.net***
      http://Althusius.net

          thawes@althusius.net

---------------------------------------------------------
 Toleration is an inner personal disposition, is a
fundamental requirement of being human and of living
together in society . . .When toleration becomes
indifference, it is ruined.                -Van Ruler



--------------BF9E858A78AD33816584E4EF
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
I realize that I&nbsp;was unclear in my last post. The trouble lines are:
<p>mykey = webster.CreateKey();&nbsp;&nbsp;&nbsp; // this creates a VerseKey
object
<br>type `VerseKey' is not a base type for type `SWKey'
<p>If I cast webster.CreateKey() with (VerseKey *), the program compiles
but then segfaults
<p>But this might be because of this:
<p>for (mykey = "jas 1:1"; mykey->Chapter() == 1; mykey++) {
<br>assignment to `VerseKey *' from `const char *'
<p>Going on your suggestion to change mykey = "jas 1:1" to *mykey="jas
1:1" the compiler quits complaining, but still segfaults when run. I compiled
with Electric Fence and efence reports in gdb:
<p>Program received signal SIGSEGV, Segmentation fault.
<br>0x8049bf9 in main (argc=1, argv=0xbfffeb44) at test.cpp:25
<p>Line 25 is this line:
<br>for (*mykey = "jas 1:1"; mykey->Chapter() == 1; mykey++) {
<p>I hope this is clearer.
<p>Tim Hawes wrote:
<blockquote TYPE=CITE>This is taken directly from the Sword API Primer:
<p>&nbsp;&nbsp;&nbsp; RawText webster("modules/texts/rawtext/webster/",
"Webster", "Webster Text");
<br>&nbsp;&nbsp;&nbsp; RawCom&nbsp; mhc("modules/comments/rawcom/mhc/",
"MHC", "Matthew Henry's Commentary on the Whole Bible");
<p>&nbsp;&nbsp;&nbsp; VerseKey *mykey;
<br>&nbsp;&nbsp;&nbsp; mykey = webster.CreateKey();&nbsp;&nbsp;&nbsp; //
this creates a VerseKey object
<p>&nbsp;&nbsp;&nbsp; mykey.Persist(true);
<p>&nbsp;&nbsp;&nbsp; webster.SetKey(*mykey);
<br>&nbsp;&nbsp;&nbsp; mhc.SetKey(*mykey);
<p>&nbsp;&nbsp;&nbsp; for (mykey = "jas 1:1"; mykey.Chapter() == 1; mykey++)
{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cout &lt;&lt; webster.KeyText()
&lt;&lt; ":\n";
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cout &lt;&lt; (const char
*) webster &lt;&lt; "\n";
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cout &lt;&lt; "-------------\n";
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cout &lt;&lt; (const char
*) mhc &lt;&lt; "\n";
<br>&nbsp;&nbsp;&nbsp; }
<p>I get these errors:
<br>g++ -c -g3 -I/usr/include/sword -o test.o test.cpp
<br>test.cpp: In function `int main(int, char **)':
<br>test.cpp:18: type `VerseKey' is not a base type for type `SWKey'
<br>test.cpp:20: request for member `Persist' in `mykey', which is of non-aggregate
type `VerseKey *'
<br>test.cpp:25: assignment to `VerseKey *' from `const char *'
<br>test.cpp:25: request for member `Chapter' in `mykey', which is of non-aggregate
type `VerseKey *'
<p>Now there are some obvious mistakes. mykey is a pointer so mykey.Persist(true)
should be mykey->Persist(true) and mykey.Chapter() should be mykey->Chapter().
These are easy enough, but what about "VerseKey' is not a base type for
type `SWKey'" and "assignment to `VerseKey *' from `const char *'"? I tried
casting these accordingly and it either doesn't compile or it segfaults
when run.
<br>&nbsp;
<p>"Troy A. Griffitts" wrote:
<blockquote TYPE=CITE>Tim Hawes wrote:
<br>>
<br>> I can tell the Sword API Primer is dated. Even after examining the
<br>> header files, it is still very unclear how I can set a VerseKey to
a
<br>> particular reference. This does not work:
<br>>
<br>> VerseKey *mykey;
<br>>
<br>> mykey = "jas 1:19";
<br>>
<br>> Can anyone help me out, here? Thanks in advance.
<p>VerseKey mykey;
<br>mykey = "jas 1:19
<p>NOTE:
<br>-VerseKey *mykey;
<br>+VerseKey mykey;
<p>If you're gonna declare a pointer, you must new the object, then free
<br>it... e.g.
<p>VerseKey *mykey = new VerseKey();
<br>*mykey = "jas 1:19";
<p>// do some stuff with the key
<p>delete mykey;
<p>Maybe a C++Primer might help.
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -Troy.</blockquote>

<pre>--&nbsp;
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

&nbsp; Tim Hawes

&nbsp;&nbsp;&nbsp;&nbsp; ***Althusius.net***
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="http://Althusius.net">http://Althusius.net

</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; thawes@althusius.net

---------------------------------------------------------
&nbsp;Toleration is an inner personal disposition, is a
fundamental requirement of being human and of living
together in society . . .When toleration becomes
indifference, it is ruined.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -Van Ruler</pre>
&nbsp;</blockquote>

<pre>--&nbsp;
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

&nbsp; Tim Hawes

&nbsp;&nbsp;&nbsp;&nbsp; ***Althusius.net***
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <A HREF="http://Althusius.net">http://Althusius.net</A>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; thawes@althusius.net

---------------------------------------------------------
&nbsp;Toleration is an inner personal disposition, is a
fundamental requirement of being human and of living
together in society . . .When toleration becomes
indifference, it is ruined.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -Van Ruler</pre>
&nbsp;</html>

--------------BF9E858A78AD33816584E4EF--