[sword-svn] r2025 - in trunk: . examples/cmdline
scribe at www.crosswire.org
scribe at www.crosswire.org
Sun Dec 10 13:47:13 MST 2006
Author: scribe
Date: 2006-12-10 13:47:13 -0700 (Sun, 10 Dec 2006)
New Revision: 2025
Added:
trunk/examples/cmdline/verserangeparse.cpp
Modified:
trunk/ChangeLog
trunk/examples/cmdline/Makefile.am
Log:
Added example: examples/cmdline/verserangeparse.cpp
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2006-12-08 21:49:17 UTC (rev 2024)
+++ trunk/ChangeLog 2006-12-10 20:47:13 UTC (rev 2025)
@@ -1,6 +1,9 @@
API ChangeLog (see the ChangeLog in each 'apps' directory for
app specific changes)
+10-Dec-2006 Troy A. Griffitts <scribe at crosswire.org>
+ Added example: examples/cmdline/verserangeparse.cpp
+
2-Dec-2006 Troy A. Griffitts <scribe at crosswire.org>
Added example: examples/cmdline/listoptions.cpp
Added entryAttributes processing for morph segs
Modified: trunk/examples/cmdline/Makefile.am
===================================================================
--- trunk/examples/cmdline/Makefile.am 2006-12-08 21:49:17 UTC (rev 2024)
+++ trunk/examples/cmdline/Makefile.am 2006-12-10 20:47:13 UTC (rev 2025)
@@ -2,10 +2,11 @@
INCLUDES = -I $(top_srcdir)/include
LDADD = $(top_builddir)/lib/libsword.la
-noinst_PROGRAMS = lookup search threaded_search listoptions
+noinst_PROGRAMS = lookup search threaded_search listoptions verserangeparse
lookup_SOURCES = lookup.cpp
search_SOURCES = search.cpp
listoptions_SOURCES = listoptions.cpp
+verserangeparse_SOURCES = verserangeparse.cpp
threaded_search_SOURCES = threaded_search.cpp
threaded_search_LDADD = $(LDADD) -lpthread
Added: trunk/examples/cmdline/verserangeparse.cpp
===================================================================
--- trunk/examples/cmdline/verserangeparse.cpp (rev 0)
+++ trunk/examples/cmdline/verserangeparse.cpp 2006-12-10 20:47:13 UTC (rev 2025)
@@ -0,0 +1,69 @@
+/******************************************************************
+ * This example shows:
+ * How to parse a verse reference
+ * How to persist a custom range key in a book
+ */
+
+#include <iostream>
+#include <swmgr.h>
+#include <versekey.h>
+#include <listkey.h>
+#include <swmodule.h>
+#include <markupfiltmgr.h>
+
+using sword::SWMgr;
+using sword::VerseKey;
+using sword::ListKey;
+using sword::SWModule;
+using sword::SW_POSITION;
+using sword::FMT_PLAIN;
+using sword::MarkupFilterMgr;
+using std::cout;
+using std::endl;
+
+int main(int argc, char **argv)
+{
+ const char *range = (argc > 1) ? argv[1] : "Mat 2:10,12-15";
+
+ VerseKey parser;
+ ListKey result;
+
+ result = parser.ParseVerseList(range, parser, true);
+ // let's iterate the key and display
+ for (result = TOP; !result.Error(); result++) {
+ cout << result << "\n";
+ }
+ cout << endl;
+
+ // Now if we'd like persist this key for use inside of a book...
+ result.Persist(true);
+
+ // Let's get a book;
+ SWMgr library(new MarkupFilterMgr(FMT_PLAIN)); // render plain without fancy markup
+ SWModule *book = library.getModule("KJV");
+
+ // and set our limited key inside
+ book->setKey(result);
+
+ // now let's iterate the book and display
+ for ((*book) = TOP; !book->Error(); (*book)++) {
+ cout << "*** " << book->getKeyText() << ": " << book->RenderText() << "\n";
+ }
+
+ // since we've told our result key to persist in book, we can reuse our
+ // setup by simply resetting result, e.g.
+ //
+ // result = parser.ParseVerseList(someNewRange, parser, true);
+ //
+ // now an iteration of book will give us our new range.
+ //
+ // to stop persistence of our custom key, we'll need to set our book's key
+ // to something simple:
+ //
+ // book->setKey("gen.1.1");
+ //
+ // this allows book to create and use an instance of its preferred key type
+ //
+
+ return 0;
+}
More information about the sword-cvs
mailing list