[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 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>
</html>
--------------448CC2D1DFDE774C630C5770--