[sword-devel] Learning the Sword API

Tim Hawes sword-devel@crosswire.org
Tue, 06 Feb 2001 07:04:35 -0500


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

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



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

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
This is taken directly from the Sword API&nbsp;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;</html>

--------------448CC2D1DFDE774C630C5770--