Difference between revisions of "Tutorials:SWORD 103"

From CrossWire Bible Society
Jump to: navigation, search
(Copied from email, lightly edited)
 
(The anatomy of an SWFilter)
Line 1: Line 1:
 
== The anatomy of an SWFilter ==
 
== The anatomy of an SWFilter ==
<pre>
+
 
 
At the most basic level, a SWORD filter performs some distinct and
 
At the most basic level, a SWORD filter performs some distinct and
 
concise transformation to the data stream.
 
concise transformation to the data stream.
Line 6: Line 6:
 
The actual signature of a filter is very minimal, and looking at the
 
The actual signature of a filter is very minimal, and looking at the
 
SWFilter interface itself...
 
SWFilter interface itself...
</pre>
 
 
http://crosswire.org/svn/sword/trunk/include/swfilter.h
 
http://crosswire.org/svn/sword/trunk/include/swfilter.h
<pre>
+
 
 
... there is simply 1 method you need to implemented to create a filter:
 
... there is simply 1 method you need to implemented to create a filter:
  
char SWFilter::processText(
+
<pre>char SWFilter::processText(
 
                 SWBuf &text,
 
                 SWBuf &text,
 
         const SWKey *key = 0,
 
         const SWKey *key = 0,
 
         const SWModule *module = 0) = 0;
 
         const SWModule *module = 0) = 0;
 
+
</pre>
  
 
Basically, you're sent a buffer of text, possibly along with some
 
Basically, you're sent a buffer of text, possibly along with some
Line 27: Line 26:
 
into tiny manageable chunks that anyone can tackle.
 
into tiny manageable chunks that anyone can tackle.
  
"Handle <title> tags in a buffer?  Sure, I can do that!  That's easy....
+
"Handle <title> tags in a buffer?  Sure, I can do that!  That's easy.... Wait....  What should I _DO_ with a <title> tag?"
Wait....  What should I _DO_ with a <title> tag?"
 
  
 
That's when the real world hits and things get more complex.  A SWORD
 
That's when the real world hits and things get more complex.  A SWORD
Line 36: Line 34:
 
distinct roles they are expected to fill, when, and in what order-- is
 
distinct roles they are expected to fill, when, and in what order-- is
 
hidden knowledge that for years only few have been privy to yield...
 
hidden knowledge that for years only few have been privy to yield...
</pre>
+
 
 
Stay tuned for "The Red Pill" coming soon to a listserv near you.
 
Stay tuned for "The Red Pill" coming soon to a listserv near you.

Revision as of 19:35, 3 December 2010

The anatomy of an SWFilter

At the most basic level, a SWORD filter performs some distinct and concise transformation to the data stream.

The actual signature of a filter is very minimal, and looking at the SWFilter interface itself... http://crosswire.org/svn/sword/trunk/include/swfilter.h

... there is simply 1 method you need to implemented to create a filter:

char SWFilter::processText(
                SWBuf &text,
        const SWKey *key = 0,
        const SWModule *module = 0) = 0;

Basically, you're sent a buffer of text, possibly along with some context in the form of an SWKey and SWModule-- in case you care, and then you make some small change to the buffer.

Easy, right? Well, sortof.

Anyone can write a filter. The great thing about filters is that they partition up a very complicated task: processing a complex document, into tiny manageable chunks that anyone can tackle.

"Handle <title> tags in a buffer? Sure, I can do that! That's easy.... Wait.... What should I _DO_ with a <title> tag?"

That's when the real world hits and things get more complex. A SWORD filter is an easy to grasp, easy to code against, abstract concept.

How filters are orchestrated together inside the SWORD engine-- what distinct roles they are expected to fill, when, and in what order-- is hidden knowledge that for years only few have been privy to yield...

Stay tuned for "The Red Pill" coming soon to a listserv near you.