Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

SWModule Class Reference

The class SWModule is the base class for all modules used in Sword. More...

#include <swmodule.h>

Inheritance diagram for SWModule:

Inheritance graph
[legend]
Collaboration diagram for SWModule:

Collaboration graph
[legend]
List of all members.

Public Methods

 SWModule (const char *imodname=0, const char *imoddesc=0, SWDisplay *idisp=0, char *imodtype=0, SWTextEncoding encoding=ENC_UNKNOWN, SWTextDirection dir=DIRECTION_LTR, SWTextMarkup markup=FMT_UNKNOWN, const char *modlang=0)
 Initializes data for instance of SWModule. More...

virtual ~SWModule ()
 Cleans up instance of SWModule.

virtual char Error ()
 Gets and clears error status. More...

virtual const bool isUnicode () const
virtual const ConfigEntMap & getConfig () const
virtual void setConfig (ConfigEntMap *config)
virtual const char * getConfigEntry (const char *key) const
virtual const int getEntrySize () const
virtual char SetKey (const SWKey *ikey)
 Sets a key to this module for position to a particular record or set of records. More...

virtual char SetKey (const SWKey &ikey)
 Sets the key of this module. More...

virtual SWKeyKey () const
 Gets the current module key. More...

virtual char Key (const SWKey &ikey)
 Sets the current key of the module to ikey, and returns the keytext. More...

virtual const char * KeyText (const char *imodtype=0)
 Sets/gets module KeyText. More...

virtual char Display ()
 Calls this modules display object and passes itself. More...

virtual SWDisplayDisp (SWDisplay *idisp=0)
 Sets/gets display driver. More...

virtual char * Name (const char *imodname=0)
 Sets/gets module name. More...

virtual char * Description (const char *imoddesc=0)
 Sets/gets module description. More...

virtual char * Type (const char *imodtype=0)
 Sets/gets module type. More...

virtual char Direction (signed char newdir=-1)
 Sets/gets module direction. More...

virtual char Encoding (signed char enc=-1)
 Sets/gets module encoding. More...

virtual char Markup (signed char enc=-1)
 Sets/gets module markup. More...

virtual char * Lang (const char *imodlang=0)
 Sets/gets module language. More...

virtual ListKeySearch (const char *istr, int searchType=0, int flags=0, SWKey *scope=0, bool *justCheckIfSupported=0, void(*percent)(char, void *)=&nullPercent, void *percentUserData=0)
 Searches a module for a string. More...

virtual signed char createSearchFramework ()
virtual bool hasSearchFramework ()
virtual bool isSearchOptimallySupported (const char *istr, int searchType, int flags, SWKey *scope)
 Check if the search is optimally supported (e.g. More...

virtual SWKeyCreateKey ()
 Allocates a key of specific type for module The different reimplementatiosn of SWModule (e.g. More...

virtual operator const char * ()
 Renders and returns the current module text. More...

virtual char * getRawEntry ()=0
 This function is reimplemented by the different kinds of module objects. More...

virtual operator SWKey & ()
 Cast operator to cast to a SWKey reference. More...

virtual operator SWKey * ()
 Operator to cast to an SWKey pointer. More...

virtual bool isWritable ()
 Is the module writable? :). More...

virtual SWModule & setentry (const char *inbuf, long len)
 Modify the current module entry text only if module isWritable. More...

virtual SWModule & operator<< (const char *)
 Modify the current module entry text only if module isWritable. More...

virtual SWModule & operator<< (const SWKey *)
 Link the current module entry to another module entry only if module isWritable. More...

virtual void deleteEntry ()
 Delete current module entry - only if module isWritable.

virtual SWModule & operator-= (int decrement)
 Decrements module key a number of entries. More...

virtual SWModule & operator+= (int increment)
 Increments module key a number of entries. More...

virtual SWModule & operator++ (int)
 Increments module key by 1 entry.

virtual SWModule & operator-- (int)
 Decrements module key by 1 entry.

virtual SWModule & operator= (SW_POSITION p)
 Positions this modules to an entry. More...

virtual SWModule & AddRenderFilter (SWFilter *newfilter)
 Adds a RenderFilter to this module's. More...

virtual SWModule & RemoveRenderFilter (SWFilter *oldfilter)
 Removes a RenderFilter from this module's. More...

virtual SWModule & ReplaceRenderFilter (SWFilter *oldfilter, SWFilter *newfilter)
 Replaces a RenderFilter in this module's. More...

virtual void renderFilter (char *buf, long size, SWKey *key)
 RenderFilter a text buffer. More...

virtual SWModule & AddEncodingFilter (SWFilter *newfilter)
 Adds an EncodingFilter to this module's. More...

virtual SWModule & RemoveEncodingFilter (SWFilter *oldfilter)
 Removes an EncodingFilter from this module's. More...

virtual SWModule & ReplaceEncodingFilter (SWFilter *oldfilter, SWFilter *newfilter)
 Replaces an EncodingFilter in this module's. More...

virtual void encodingFilter (char *buf, long size, SWKey *key)
 encodingFilter a text buffer. More...

virtual SWModule & AddStripFilter (SWFilter *newfilter)
 Adds a StripFilter to this module's stripfilters queue. More...

virtual void stripFilter (char *buf, long size, SWKey *key)
 StripFilter a text buffer. More...

virtual SWModule & AddRawFilter (SWFilter *newfilter)
 Adds a RawFilter to this module's rawfilters queue. More...

virtual void filterBuffer (FilterList *filters, char *buf, long size, SWKey *key)
 FilterBuffer a text buffer. More...

virtual void rawFilter (char *buf, long size, SWKey *key)
 RawFilter a text buffer. More...

virtual SWModule & AddOptionFilter (SWFilter *newfilter)
 Adds an OptionFilter to this module's optionfilters queue. More...

virtual void optionFilter (char *buf, long size, SWKey *key)
 OptionFilter a text buffer. More...

virtual const char * StripText (char *buf=0, int len=-1)
 calls all StripFilters on buffer or current text. More...

virtual const char * RenderText (char *buf=0, int len=-1, bool render=true)
 calls all RenderFilters on buffer or current text. More...

virtual const char * StripText (SWKey *tmpKey)
 calls all StripFilters on current text. More...

virtual const char * RenderText (SWKey *tmpKey)
 calls all RenderFilters on current text. More...

virtual void setSkipConsecutiveLinks (bool val)
 option to specify behaviour when iterating over consecutive entried linked to same text. More...

virtual bool getSkipConsecutiveLinks ()
virtual AttributeTypeList & getEntryAttributes () const
virtual void processEntryAttributes (bool val) const
virtual bool isProcessEntryAttributes () const

Static Public Methods

void nullPercent (char percent, void *userData)
 This is the default callback function for searching. More...

signed char createModule (const char *)
 Creates a new module. More...


Public Attributes

bool terminateSearch
 Set this bool to false to terminate the search which is executed by this module (Search). More...


Protected Attributes

ConfigEntMap ownConfig
ConfigEntMap * config
AttributeTypeList entryAttributes
bool procEntAttr
char error
bool skipConsecutiveLinks
SWKeykey
 the current key.

ListKey listkey
char * modname
char * moddesc
char * modtype
char * modlang
char direction
char markup
char encoding
SWDisplaydisp
 this module's display object.

char * entrybuf
unsigned long entrybufallocsize
FilterList * stripFilters
 executed to remove all markup (for searches).

FilterList * rawFilters
 executed immediately upon fileread.

FilterList * renderFilters
 executed to format for display.

FilterList * optionFilters
 executed to change markup to user prefs.

FilterList * encodingFilters
 executed to decode text for display.

int entrySize

Static Protected Attributes

SWDisplay rawdisp

Detailed Description

The class SWModule is the base class for all modules used in Sword.

It provides functions to look up a text passage, to search in the module, to switch on/off the state of optional things like Strong's numbers or footnotes.

SWModule has also functions to write to the data files. This might be useful in future for frontend authors to support user-created modules.

Definition at line 64 of file swmodule.h.


Constructor & Destructor Documentation

SWModule::SWModule const char *    imodname = 0,
const char *    imoddesc = 0,
SWDisplay   idisp = 0,
char *    imodtype = 0,
SWTextEncoding    encoding = ENC_UNKNOWN,
SWTextDirection    dir = DIRECTION_LTR,
SWTextMarkup    markup = FMT_UNKNOWN,
const char *    modlang = 0
 

Initializes data for instance of SWModule.

Parameters:
imodname  Internal name for module; see also Name
imoddesc  Name to display to user for module; see also Description
idisp  Display object to use for displaying see also Disp
imodtype  Type of Module (All modules will be displayed with others of same type under their modtype heading) see also Type

Definition at line 31 of file swmodule.cpp.

References CreateKey(), disp, encodingFilters, key, optionFilters, rawFilters, renderFilters, and stripFilters.

00032 {
00033         key       = CreateKey();
00034         entrybuf  = new char [1];
00035         *entrybuf = 0;
00036         config    = &ownConfig;
00037         entrybufallocsize = 0;
00038         modname   = 0;
00039         error     = 0;
00040         moddesc   = 0;
00041         modtype   = 0;
00042         modlang   = 0;
00043         this->encoding = encoding;
00044         this->direction = direction;
00045         this->markup  = markup;
00046         entrySize= -1;
00047         disp     = (idisp) ? idisp : &rawdisp;
00048         stdstr(&modname, imodname);
00049         stdstr(&moddesc, imoddesc);
00050         stdstr(&modtype, imodtype);
00051         stdstr(&modlang, imodlang);
00052         stripFilters = new FilterList();
00053         rawFilters = new FilterList();
00054         renderFilters = new FilterList();
00055         optionFilters = new FilterList();
00056         encodingFilters = new FilterList();
00057         skipConsecutiveLinks = true;
00058         procEntAttr = true;
00059 }


Member Function Documentation

virtual SWModule& SWModule::AddEncodingFilter SWFilter *    newfilter [inline, virtual]
 

Adds an EncodingFilter to this module's.

See also:
encodingfilters queue
Parameters:
newfilter  the filter to add
Returns:
*this

Definition at line 451 of file swmodule.h.

Referenced by EncodingFilterMgr::AddEncodingFilters().

00451                                                               {
00452     encodingFilters->push_back (newfilter);
00453     return *this;
00454   }

virtual SWModule& SWModule::AddOptionFilter SWFilter *    newfilter [inline, virtual]
 

Adds an OptionFilter to this module's optionfilters queue.

Parameters:
newfilter  the filter to add
Returns:
*this

Definition at line 536 of file swmodule.h.

00536                                                             {
00537     optionFilters->push_back (newfilter);
00538     return *this;
00539   }

virtual SWModule& SWModule::AddRawFilter SWFilter *    newfilter [inline, virtual]
 

Adds a RawFilter to this module's rawfilters queue.

Parameters:
newfilter  the filter to add
Returns:
*this

Definition at line 505 of file swmodule.h.

Referenced by SWMgr::AddRawFilters(), and EncodingFilterMgr::AddRawFilters().

00505                                                          {
00506     rawFilters->push_back (newfilter);
00507     return *this;
00508   }

virtual SWModule& SWModule::AddRenderFilter SWFilter *    newfilter [inline, virtual]
 

Adds a RenderFilter to this module's.

See also:
renderfilters queue
Parameters:
newfilter  the filter to add
Returns:
*this

Definition at line 414 of file swmodule.h.

Referenced by MarkupFilterMgr::AddRenderFilters().

00414                                                             {
00415     renderFilters->push_back (newfilter);
00416     return *this;
00417   }

virtual SWModule& SWModule::AddStripFilter SWFilter *    newfilter [inline, virtual]
 

Adds a StripFilter to this module's stripfilters queue.

Parameters:
newfilter  the filter to add
Returns:
*this

Definition at line 488 of file swmodule.h.

Referenced by SWMgr::AddStripFilters().

00488                                                            {
00489     stripFilters->push_back (newfilter);
00490     return *this;
00491   }

SWKey * SWModule::CreateKey   [virtual]
 

Allocates a key of specific type for module The different reimplementatiosn of SWModule (e.g.

SWText) support SWKey implementations, which support special. This functions returns a SWKey object which works with the current implementation of SWModule. For example for the SWText class it returns a VerseKey object.

See also:
VerseKey, ListKey, SWText, SWLD, SWCom
Returns:
pointer to allocated key

Reimplemented in SWCom, SWGenBook, SWLD, and SWText.

Definition at line 105 of file swmodule.cpp.

Referenced by RenderText(), Search(), SetKey(), StripText(), and SWModule().

00106 {
00107         return new SWKey();
00108 }

signed char SWModule::createModule const char *    [inline, static]
 

Creates a new module.

Parameters:
path  The first parameter is path of the new module
Returns:
error

Definition at line 349 of file swmodule.h.

00349                                                  {
00350     return -1;
00351   }

char * SWModule::Description const char *    imoddesc = 0 [virtual]
 

Sets/gets module description.

Parameters:
imoddesc  value which to set moddesc; [0] - only get
Returns:
pointer to moddesc

Definition at line 150 of file swmodule.cpp.

00151 {
00152         return stdstr(&moddesc, imoddesc);
00153 }

char SWModule::Direction signed char    newdir = -1 [virtual]
 

Sets/gets module direction.

Parameters:
newdir  value which to set direction; [-1] - only get
Returns:
char direction

Definition at line 178 of file swmodule.cpp.

00178                                            {
00179         if (newdir != -1)
00180                 direction = newdir;
00181         return direction;
00182 }

SWDisplay * SWModule::Disp SWDisplay   idisp = 0 [virtual]
 

Sets/gets display driver.

Parameters:
idisp  value which to set disp; [0] - only get
Returns:
pointer to disp

Definition at line 237 of file swmodule.cpp.

References disp.

00238 {
00239         if (idisp)
00240                 disp = idisp;
00241 
00242         return disp;
00243 }

char SWModule::Display   [virtual]
 

Calls this modules display object and passes itself.

Returns:
error status

Definition at line 252 of file swmodule.cpp.

References disp, and SWDisplay::Display().

00253 {
00254         disp->Display(*this);
00255         return 0;
00256 }

char SWModule::Encoding signed char    enc = -1 [virtual]
 

Sets/gets module encoding.

Parameters:
newdir  value which to set encoding; [-1] - only get
Returns:
char encoding

Definition at line 192 of file swmodule.cpp.

00192                                           {
00193         if (newenc != -1)
00194                 encoding = newenc;
00195         return encoding;
00196 }

virtual void SWModule::encodingFilter char *    buf,
long    size,
SWKey   key
[inline, virtual]
 

encodingFilter a text buffer.

Parameters:
buf  the buffer to filter
size  the allocated size of the buffer
key  key location from where this buffer was extracted
Returns:
*this

Definition at line 481 of file swmodule.h.

Referenced by RenderText().

00481                                                                  {
00482         filterBuffer(encodingFilters, buf, size, key);
00483   }

char SWModule::Error   [virtual]
 

Gets and clears error status.

Returns:
error status

Definition at line 117 of file swmodule.cpp.

Referenced by Search().

00118 {
00119         char retval = error;
00120 
00121         error = 0;
00122         return retval;
00123 }

virtual void SWModule::filterBuffer FilterList *    filters,
char *    buf,
long    size,
SWKey   key
[inline, virtual]
 

FilterBuffer a text buffer.

Parameters:
filters  the FilterList of filters to iterate
buf  the buffer to filter
size  the allocated size of the buffer
key  key location from where this buffer was extracted
Returns:
*this

Definition at line 516 of file swmodule.h.

00516                                                                                     {
00517         FilterList::iterator it;
00518         for (it = filters->begin(); it != filters->end(); it++) {
00519                 (*it)->ProcessText(buf, size, key, this);
00520         }
00521   }

virtual const int SWModule::getEntrySize   const [inline, virtual]
 

Returns:
The size of the current entry.

Definition at line 162 of file swmodule.h.

Referenced by RenderText().

00162 {return entrySize;}

virtual char* SWModule::getRawEntry   [pure virtual]
 

This function is reimplemented by the different kinds of module objects.

Returns:
the raw module text of the current entry

Referenced by SWLD::KeyText(), and RenderText().

virtual bool SWModule::isSearchOptimallySupported const char *    istr,
int    searchType,
int    flags,
SWKey   scope
[inline, virtual]
 

Check if the search is optimally supported (e.g.

if index files are presnt and working) This function checks whether the search framework may work in the best way.

Returns:
True if the the search is optimally supported, false if it's not working in the best way.

Definition at line 295 of file swmodule.h.

00296                                                                      {
00297       bool retVal = false;
00298       Search (istr, searchType, flags, scope, &retVal);
00299       return retVal;
00300   }

virtual const bool SWModule::isUnicode   const [inline, virtual]
 

Returns:
True if this module is encoded in Unicode, otherwise return false.

Definition at line 150 of file swmodule.h.

00150 {return (encoding == (char)ENC_UTF8 || encoding == (char)ENC_SCSU);}

virtual bool SWModule::isWritable   [inline, virtual]
 

Is the module writable? :).

Returns:
yes or no

Definition at line 342 of file swmodule.h.

00342                              {
00343     return false;
00344   }

virtual char SWModule::Key const SWKey   ikey [inline, virtual]
 

Sets the current key of the module to ikey, and returns the keytext.

Parameters:
ikey  new current key for the module
Returns:
the keytext of the current module key

Definition at line 189 of file swmodule.h.

00189                                         {
00190     return SetKey (ikey);
00191   }

virtual SWKey& SWModule::Key   const [inline, virtual]
 

Gets the current module key.

Returns:
the current key of this module

Definition at line 180 of file swmodule.h.

00180                                {
00181     return *key;
00182   }

const char * SWModule::KeyText const char *    imodtype = 0 [virtual]
 

Sets/gets module KeyText.

Parameters:
ikeytext  value which to set keytext; [0] - only get
Returns:
pointer to keytext

Reimplemented in SWLD.

Definition at line 303 of file swmodule.cpp.

References key, and SetKey().

Referenced by SWLD::KeyText(), and Search().

00304 {
00305         if (ikeytext)
00306                 SetKey(ikeytext);
00307 
00308         return *key;
00309 }

char * SWModule::Lang const char *    imodlang = 0 [virtual]
 

Sets/gets module language.

Parameters:
imodlang  value which to set modlang; [0] - only get
Returns:
pointer to modlang

Definition at line 222 of file swmodule.cpp.

00223 {
00224         return stdstr(&modlang, imodlang);
00225 }

char SWModule::Markup signed char    enc = -1 [virtual]
 

Sets/gets module markup.

Parameters:
newdir  value which to set markup; [-1] - only get
Returns:
char markup

Definition at line 206 of file swmodule.cpp.

Referenced by MarkupFilterMgr::AddRenderFilters().

00206                                          {
00207         if (newmark != -1)
00208                 markup = newmark;
00209         return markup;
00210 }

char * SWModule::Name const char *    imodname = 0 [virtual]
 

Sets/gets module name.

Parameters:
imodname  value which to set modname; [0] - only get
Returns:
pointer to modname

Definition at line 135 of file swmodule.cpp.

Referenced by SWMgr::AddRawFilters().

00136 {
00137         return stdstr(&modname, imodname);
00138 }

void SWModule::nullPercent char    percent,
void *    userData
[static]
 

This is the default callback function for searching.

This function is a placeholder and does nothing. You can define your own function for search progress evaluation, and pass it over to Search.

Definition at line 18 of file swmodule.cpp.

00018 {}

SWModule::operator const char *   [virtual]
 

Renders and returns the current module text.

Returns:
the rendered current module text

Definition at line 662 of file swmodule.cpp.

References RenderText().

00662                                {
00663         return RenderText();
00664 }

virtual SWModule::operator SWKey &   [inline, virtual]
 

Cast operator to cast to a SWKey reference.

This operator may be used to cast this module to a SWKey object.

See also:
SWKey*()

Definition at line 322 of file swmodule.h.

00322                               {
00323     return *key;
00324   }

virtual SWModule::operator SWKey *   [inline, virtual]
 

Operator to cast to an SWKey pointer.

This function may be used to cast this object to an SWKey pointer.

 //we assume here that SWModule* module is already defined and valid.
 SWKey* currentKey = (SWKey*)module;
 // do something with currentKey (e.g. print out on screen)

Definition at line 333 of file swmodule.h.

00333                              {
00334     return key;
00335   }

SWModule & SWModule::operator+= int    increment [virtual]
 

Increments module key a number of entries.

Parameters:
increment  Number of entries to jump forward
Returns:
*this

Definition at line 350 of file swmodule.cpp.

References SWKey::Error(), and key.

00351 {
00352         (*key) += increment;
00353         error = key->Error();
00354 
00355         return *this;
00356 }

SWModule & SWModule::operator-= int    decrement [virtual]
 

Decrements module key a number of entries.

Parameters:
decrement  Number of entries to jump backward
Returns:
*this

Definition at line 367 of file swmodule.cpp.

References SWKey::Error(), and key.

00368 {
00369         (*key) -= increment;
00370         error = key->Error();
00371 
00372         return *this;
00373 }

virtual SWModule& SWModule::operator<< const SWKey   [inline, virtual]
 

Link the current module entry to another module entry only if module isWritable.

Returns:
*this

Definition at line 370 of file swmodule.h.

00370                                                  {
00371     return *this;
00372   }

virtual SWModule& SWModule::operator<< const char *    [inline, virtual]
 

Modify the current module entry text only if module isWritable.

Returns:
*this

Definition at line 363 of file swmodule.h.

00363                                                 {
00364     return *this;
00365   }

SWModule & SWModule::operator= SW_POSITION    p [virtual]
 

Positions this modules to an entry.

Parameters:
p  position (e.g. TOP, BOTTOM)
Returns:
*this

Definition at line 320 of file swmodule.cpp.

References SWKey::Error(), and key.

00321 {
00322         *key = p;
00323         char saveError = key->Error();
00324 
00325         switch (p) {
00326         case POS_TOP:
00327                 (*this)++;
00328                 (*this)--;
00329                 break;
00330 
00331         case POS_BOTTOM:
00332                 (*this)--;
00333                 (*this)++;
00334                 break;
00335         }
00336 
00337         error = saveError;
00338         return *this;
00339 }

virtual void SWModule::optionFilter char *    buf,
long    size,
SWKey   key
[inline, virtual]
 

OptionFilter a text buffer.

Parameters:
buf  the buffer to filter
size  the allocated size of the buffer
key  key location from where this buffer was extracted
Returns:
*this

Definition at line 546 of file swmodule.h.

Referenced by RenderText().

00546                                                                {
00547         filterBuffer(optionFilters, buf, size, key);
00548   }

virtual void SWModule::rawFilter char *    buf,
long    size,
SWKey   key
[inline, virtual]
 

RawFilter a text buffer.

Parameters:
buf  the buffer to filter
size  the allocated size of the buffer
key  key location from where this buffer was extracted
Returns:
*this

Definition at line 528 of file swmodule.h.

00528                                                             {
00529         buf[size] = 0;
00530         filterBuffer(rawFilters, buf, size, key);
00531   }

virtual SWModule& SWModule::RemoveEncodingFilter SWFilter *    oldfilter [inline, virtual]
 

Removes an EncodingFilter from this module's.

See also:
encodingfilters queue
Parameters:
oldfilter  the filter to remove
Returns:
*this

Definition at line 459 of file swmodule.h.

00459                                                                  {
00460     encodingFilters->remove (oldfilter);
00461     return *this;
00462   }

virtual SWModule& SWModule::RemoveRenderFilter SWFilter *    oldfilter [inline, virtual]
 

Removes a RenderFilter from this module's.

See also:
renderfilters queue
Parameters:
oldfilter  the filter to remove
Returns:
*this

Definition at line 422 of file swmodule.h.

00422                                                                {
00423     renderFilters->remove (oldfilter);
00424     return *this;
00425   }

virtual void SWModule::renderFilter char *    buf,
long    size,
SWKey   key
[inline, virtual]
 

RenderFilter a text buffer.

Parameters:
buf  the buffer to filter
size  the allocated size of the buffer
key  key location from where this buffer was extracted
Returns:
*this

Definition at line 444 of file swmodule.h.

Referenced by RenderText().

00444                                                                {
00445         filterBuffer(renderFilters, buf, size, key);
00446   }

const char * SWModule::RenderText SWKey   tmpKey [virtual]
 

calls all RenderFilters on current text.

Parameters:
tmpKey  key to use to grab text
Returns:
this module's text at specified key location massaged by Render filters

Definition at line 606 of file swmodule.cpp.

References CreateKey(), key, SWKey::Persist(), RenderText(), and SetKey().

00607 {
00608         SWKey *savekey;
00609         const char *retVal;
00610 
00611         if (!key->Persist()) {
00612                 savekey = CreateKey();
00613                 *savekey = *key;
00614         }
00615         else    savekey = key;
00616 
00617         SetKey(*tmpKey);
00618 
00619         retVal = RenderText();
00620 
00621         SetKey(*savekey);
00622 
00623         if (!savekey->Persist())
00624                 delete savekey;
00625 
00626         return retVal;
00627 }

const char * SWModule::RenderText char *    buf = 0,
int    len = -1,
bool    render = true
[virtual]
 

calls all RenderFilters on buffer or current text.

Parameters:
buf  buffer to Render instead of current module position; if buf is NULL, the current text will be used
len  max len of buf OR current text -- will be applied anyway
Returns:
this module's text at specified key location massaged by Render filters

Definition at line 570 of file swmodule.cpp.

References encodingFilter(), getEntrySize(), getRawEntry(), key, optionFilter(), renderFilter(), and stripFilter().

Referenced by operator const char *(), RenderText(), and StripText().

00570                                                                  {
00571         entryAttributes.clear();
00572         char *tmpbuf = (buf) ? buf : getRawEntry();
00573         SWKey *key = 0;
00574         static char *null = "";
00575 
00576         if (tmpbuf) {
00577                 unsigned long size = (len < 0) ? ((getEntrySize()<0) ? strlen(tmpbuf) : getEntrySize()) * FILTERPAD : len;
00578                 if (size > 0) {
00579                         key = (SWKey *)*this;
00580 
00581                         optionFilter(tmpbuf, size, key);
00582         
00583                         if (render) {
00584                                 renderFilter(tmpbuf, size, key);
00585                                 encodingFilter(tmpbuf, size, key);
00586                         }
00587                         else    stripFilter(tmpbuf, size, key);
00588                 }
00589         }
00590         else {
00591                 tmpbuf = null;
00592         }
00593 
00594         return tmpbuf;
00595 }

virtual SWModule& SWModule::ReplaceEncodingFilter SWFilter *    oldfilter,
SWFilter *    newfilter
[inline, virtual]
 

Replaces an EncodingFilter in this module's.

See also:
encodingfilters queue
Parameters:
oldfilter  the filter to remove
newfilter  the filter to add in its place
Returns:
*this

Definition at line 468 of file swmodule.h.

00468                                                                                         {
00469     FilterList::iterator iter;
00470     for (iter = encodingFilters->begin(); iter != encodingFilters->end(); iter++)
00471         if (*iter == oldfilter)
00472                 *iter = newfilter;
00473     return *this;
00474   }

virtual SWModule& SWModule::ReplaceRenderFilter SWFilter *    oldfilter,
SWFilter *    newfilter
[inline, virtual]
 

Replaces a RenderFilter in this module's.

See also:
renderfilters queue
Parameters:
oldfilter  the filter to remove
newfilter  the filter to add in its place
Returns:
*this

Definition at line 431 of file swmodule.h.

00431                                                                                       {
00432     FilterList::iterator iter;
00433     for (iter = renderFilters->begin(); iter != renderFilters->end(); iter++)
00434         if (*iter == oldfilter)
00435                 *iter = newfilter;
00436     return *this;
00437   }

ListKey & SWModule::Search const char *    istr,
int    searchType = 0,
int    flags = 0,
SWKey   scope = 0,
bool *    justCheckIfSupported = 0,
void(*    percent)(char, void *) = &nullPercent,
void *    percentUserData = 0
[virtual]
 

Searches a module for a string.

Parameters:
istr  string for which to search
searchType  type of search to perform <=0 ->regex; 1->phrase; 2->multiword;
flags  options flags for search
justCheckIfSupported  if set, don't search, only tell if this function supports requested search.
Returns:
listkey set to verses that contain istr

Definition at line 391 of file swmodule.cpp.

References ListKey::ClearList(), SWKey::clone(), CreateKey(), Error(), SWKey::Index(), key, KeyText(), VerseKey::NewIndex(), SWKey::Persist(), SetKey(), StripText(), and terminateSearch.

00392 {
00393         SWKey *savekey = 0;
00394         SWKey *searchkey = 0;
00395         regex_t preg;
00396         SWKey textkey;
00397         char **words = 0;
00398         char *wordBuf = 0;
00399         int wordCount = 0;
00400         const char *sres;
00401         terminateSearch = false;
00402         char perc = 1;
00403         bool savePEA = isProcessEntryAttributes();
00404 
00405         processEntryAttributes(false);
00406         listkey.ClearList();
00407 
00408         if (!key->Persist()) {
00409                 savekey = CreateKey();
00410                 *savekey = *key;
00411         }
00412         else    savekey = key;
00413 
00414         searchkey = (scope)?scope->clone():(key->Persist())?key->clone():0;
00415         if (searchkey) {
00416                 searchkey->Persist(1);
00417                 SetKey(*searchkey);
00418         }
00419 
00420         (*percent)(perc, percentUserData);
00421         // MAJOR KLUDGE: VerseKey::Index still return index within testament.
00422         //      VerseKey::NewIndex should be moved to Index and Index should be some
00423         //      VerseKey specific name
00424         VerseKey *vkcheck = 0;
00425 #ifndef _WIN32_WCE
00426         try {
00427 #endif
00428                 vkcheck = SWDYNAMIC_CAST(VerseKey, key);
00429 #ifndef _WIN32_WCE
00430         }
00431         catch (...) {}
00432 #endif
00433         // end MAJOR KLUDGE
00434 
00435         *this = BOTTOM;
00436         // fix below when we find out the bug
00437         long highIndex = (vkcheck)?32300/*vkcheck->NewIndex()*/:key->Index();
00438         if (!highIndex)
00439                 highIndex = 1;          // avoid division by zero errors.
00440         *this = TOP;
00441         if (searchType >= 0) {
00442                 flags |=searchType|REG_NOSUB|REG_EXTENDED;
00443                 regcomp(&preg, istr, flags);
00444         }
00445 
00446         (*percent)(++perc, percentUserData);
00447         if (searchType == -2) {
00448                 wordBuf = (char *)calloc(sizeof(char), strlen(istr) + 1);
00449                 strcpy(wordBuf, istr);
00450                 words = (char **)calloc(sizeof(char *), 10);
00451                 int allocWords = 10;
00452                 words[wordCount] = strtok(wordBuf, " ");
00453                 while (words[wordCount]) {
00454                         wordCount++;
00455                         if (wordCount == allocWords) {
00456                                 allocWords+=10;
00457                                 words = (char **)realloc(words, sizeof(char *)*allocWords);
00458                         }
00459                         words[wordCount] = strtok(NULL, " ");
00460                 }
00461         }
00462 
00463         perc = 5;
00464         (*percent)(perc, percentUserData);
00465 
00466         while (!Error() && !terminateSearch) {
00467 
00468         
00469                 long mindex = 0;
00470                 if (vkcheck)
00471                         mindex = vkcheck->NewIndex();
00472                 else mindex = key->Index();
00473                 float per = (float)mindex / highIndex;
00474                 per *= 93;
00475                 per += 5;
00476                 char newperc = (char)per;
00477 //              char newperc = (char)(5+(93*(((float)((vkcheck)?vkcheck->NewIndex():key->Index()))/highIndex)));
00478                 if (newperc > perc) {
00479                         perc = newperc;
00480                         (*percent)(perc, percentUserData);
00481                 }
00482                 else if (newperc < perc) {
00483 #ifndef _MSC_VER
00484                         cerr << "Serious error: new percentage complete is less than previous value\n";
00485                         cerr << "using vk? " << ((vkcheck)?"yes":"no") << "\n";
00486                         cerr << "index: " << ((vkcheck)?vkcheck->NewIndex():key->Index()) << "\n";
00487                         cerr << "highIndex: " << highIndex << "\n";
00488                         cerr << "newperc ==" << (int)newperc << "%" << "is smaller than\n";
00489                         cerr << "perc == "  << (int )perc << "% \n";
00490 #endif
00491                 }
00492                 if (searchType >= 0) {
00493                         if (!regexec(&preg,  StripText(), 0, 0, 0)) {
00494                                 textkey = KeyText();
00495                                 listkey << textkey;
00496                         }
00497                 }
00498                 else {
00499                         if (searchType == -1) {
00500                                 sres = ((flags & REG_ICASE) == REG_ICASE) ? stristr(StripText(), istr) : strstr(StripText(), istr);
00501                                 if (sres) {
00502                                                 textkey = KeyText();
00503                                                 listkey << textkey;
00504                                 }
00505                         }
00506                         if (searchType == -2) {
00507                                 int i;
00508                                 const char *stripBuf = StripText();
00509                                 for (i = 0; i < wordCount; i++) {
00510                                         sres = ((flags & REG_ICASE) == REG_ICASE) ? stristr(stripBuf, words[i]) : strstr(stripBuf, words[i]);
00511                                         if (!sres)
00512                                                 break;
00513                                 }
00514                                 if (i == wordCount) {
00515                                         textkey = KeyText();
00516                                         listkey << textkey;
00517                                 }
00518 
00519                         }
00520                 }
00521                 (*this)++;
00522         }
00523         if (searchType >= 0)
00524                 regfree(&preg);
00525 
00526         if (searchType == -2) {
00527                 free(words);
00528                 free(wordBuf);
00529         }
00530 
00531         SetKey(*savekey);
00532 
00533         if (!savekey->Persist())
00534                 delete savekey;
00535 
00536         if (searchkey)
00537                 delete searchkey;
00538 
00539         listkey = TOP;
00540         processEntryAttributes(savePEA);
00541         (*percent)(100, percentUserData);
00542 
00543         return listkey;
00544 }

virtual SWModule& SWModule::setentry const char *    inbuf,
long    len
[inline, virtual]
 

Modify the current module entry text only if module isWritable.

Returns:
*this

Definition at line 356 of file swmodule.h.

00356                                                             {
00357     return *this;
00358   }

char SWModule::SetKey const SWKey   ikey [virtual]
 

Sets the key of this module.

Similair to

See also:
SetKey(const SWKey*) .
Parameters:
ikey  The SWKey which should be used as new key.
Returns:
Error status

Definition at line 268 of file swmodule.cpp.

References SetKey().

00268                                        {
00269         return SetKey(&ikey);
00270 }

char SWModule::SetKey const SWKey   ikey [virtual]
 

Sets a key to this module for position to a particular record or set of records.

Parameters:
ikey  key with which to set this module
Returns:
error status

Definition at line 272 of file swmodule.cpp.

References CreateKey(), key, and SWKey::Persist().

Referenced by KeyText(), RenderText(), Search(), SetKey(), and StripText().

00273 {
00274         SWKey *oldKey = 0;
00275 
00276         if (key) {
00277                 if (!key->Persist())    // if we have our own copy
00278                         oldKey = key;
00279         }
00280 
00281         if (!ikey->Persist()) {         // if we are to keep our own copy
00282                  key = CreateKey();
00283                 *key = *ikey;
00284         }
00285         else     key = (SWKey *)ikey;           // if we are to just point to an external key
00286 
00287         if (oldKey)
00288                 delete oldKey;
00289 
00290         return 0;
00291 }

virtual void SWModule::setSkipConsecutiveLinks bool    val [inline, virtual]
 

option to specify behaviour when iterating over consecutive entried linked to same text.

Parameters:
val  = true means only include entry once in iteration

Definition at line 584 of file swmodule.h.

00584 { skipConsecutiveLinks = val; }

virtual void SWModule::stripFilter char *    buf,
long    size,
SWKey   key
[inline, virtual]
 

StripFilter a text buffer.

Parameters:
buf  the buffer to filter
size  the allocated size of the buffer
key  key location from where this buffer was extracted
Returns:
*this

Definition at line 498 of file swmodule.h.

Referenced by RenderText().

00498                                                               {
00499         filterBuffer(stripFilters, buf, size, key);
00500   }

const char * SWModule::StripText SWKey   tmpKey [virtual]
 

calls all StripFilters on current text.

Parameters:
tmpKey  key to use to grab text
Returns:
this module's text at specified key location massaged by Strip filters

Definition at line 638 of file swmodule.cpp.

References CreateKey(), key, SWKey::Persist(), SetKey(), and StripText().

00639 {
00640         SWKey *savekey;
00641         const char *retVal;
00642 
00643         if (!key->Persist()) {
00644                 savekey = CreateKey();
00645                 *savekey = *key;
00646         }
00647         else    savekey = key;
00648 
00649         SetKey(*tmpKey);
00650 
00651         retVal = StripText();
00652 
00653         SetKey(*savekey);
00654 
00655         if (!savekey->Persist())
00656                 delete savekey;
00657 
00658         return retVal;
00659 }

const char * SWModule::StripText char *    buf = 0,
int    len = -1
[virtual]
 

calls all StripFilters on buffer or current text.

Parameters:
buf  buf to massage instead of current module position; if buf is NULL, the current text will be used
len  max len of buf OR current text -- will be applied anyway
Returns:
this module's text at specified key location massaged by Strip filters

Definition at line 556 of file swmodule.cpp.

References RenderText().

Referenced by Search(), and StripText().

00557 {
00558         return RenderText(buf, len, false);
00559 }

char * SWModule::Type const char *    imodtype = 0 [virtual]
 

Sets/gets module type.

Parameters:
imodtype  value which to set modtype; [0] - only get
Returns:
pointer to modtype

Definition at line 165 of file swmodule.cpp.

00166 {
00167         return stdstr(&modtype, imodtype);
00168 }


Member Data Documentation

bool SWModule::terminateSearch
 

Set this bool to false to terminate the search which is executed by this module (Search).

This is useful for threaded applications to terminate the search in another thread.

Definition at line 125 of file swmodule.h.

Referenced by Search().


The documentation for this class was generated from the following files:
Generated on Thu Jun 20 22:13:04 2002 for The Sword Project by doxygen1.2.15