[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 was unclear in my last post. The trouble lines are:
<p>mykey = webster.CreateKey(); // 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> RawText webster("modules/texts/rawtext/webster/",
"Webster", "Webster Text");
<br> RawCom mhc("modules/comments/rawcom/mhc/",
"MHC", "Matthew Henry's Commentary on the Whole Bible");
<p> VerseKey *mykey;
<br> mykey = webster.CreateKey(); //
this creates a VerseKey object
<p> mykey.Persist(true);
<p> webster.SetKey(*mykey);
<br> mhc.SetKey(*mykey);
<p> for (mykey = "jas 1:1"; mykey.Chapter() == 1; mykey++)
{
<br> cout << webster.KeyText()
<< ":\n";
<br> cout << (const char
*) webster << "\n";
<br> cout << "-------------\n";
<br> cout << (const char
*) mhc << "\n";
<br> }
<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>
<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> -Troy.</blockquote>
<pre>--
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Tim Hawes
***Althusius.net***
<a href="http://Althusius.net">http://Althusius.net
</a> 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</pre>
</blockquote>
<pre>--
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Tim Hawes
***Althusius.net***
<A HREF="http://Althusius.net">http://Althusius.net</A>
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</pre>
</html>
--------------BF9E858A78AD33816584E4EF--