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

swmodule.h

00001 /******************************************************************************
00002  *  swmodule.h  - code for base class 'module'.  Module is the basis for all
00003  *                types of modules (e.g. texts, commentaries, maps, lexicons,
00004  *                etc.)
00005  *
00006  * $Id: swmodule_h-source.html,v 1.4 2001/10/05 20:45:22 mgruner Exp $
00007  *
00008  * Copyright 1998 CrossWire Bible Society (http://www.crosswire.org)
00009  *      CrossWire Bible Society
00010  *      P. O. Box 2528
00011  *      Tempe, AZ  85280-2528
00012  *
00013  * This program is free software; you can redistribute it and/or modify it
00014  * under the terms of the GNU General Public License as published by the
00015  * Free Software Foundation version 2.
00016  *
00017  * This program is distributed in the hope that it will be useful, but
00018  * WITHOUT ANY WARRANTY; without even the implied warranty of
00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020  * General Public License for more details.
00021  *
00022  */
00023 
00024 #ifndef SWMODULE_H
00025 #define SWMODULE_H
00026 
00027 #include <swdisp.h>
00028 #include <swkey.h>
00029 #include <listkey.h>
00030 #include <swfilter.h>
00031 #include <list>
00032 
00033 #include <defs.h>
00034 
00035 #define FILTERPAD 8
00036 
00037 using namespace std;
00038 
00039 typedef list < SWFilter * >FilterList;
00040 
00041 
00047 class SWDLLEXPORT SWModule {
00048 
00049 protected:
00050 
00051   char error;
00052 
00054   SWKey *key;
00055 
00056   ListKey listkey;
00057   char *modname;
00058   char *moddesc;
00059   char *modtype;
00060 
00062   SWDisplay *disp;
00063 
00064   static SWDisplay rawdisp;
00065   char *entrybuf;
00066 
00068   FilterList *stripFilters;
00069 
00071   FilterList *rawFilters;
00072 
00074   FilterList *renderFilters;
00075 
00077   FilterList *optionFilters;
00078 
00079   bool render;
00080   bool unicode;
00081   int entrySize;
00082 
00083 public:
00084 
00091   static void nullPercent (char percent, void *userData);
00092 
00097   bool terminateSearch;
00098 
00111   SWModule (const char *imodname = 0, const char *imoddesc = 0, SWDisplay * idisp = 0, char *imodtype = 0, bool unicode = false);
00112 
00115   virtual ~ SWModule ();
00116 
00121   virtual char Error ();
00122 
00126   virtual const bool isUnicode() const {return unicode;}
00130   virtual const int getEntrySize() const {return entrySize;}
00131 
00139   virtual char SetKey (const SWKey *ikey);
00140 
00146   virtual char SetKey (const SWKey &ikey);
00147 
00151   virtual SWKey & Key () const {
00152     return *key;
00153   }
00154   
00161   virtual char Key (const SWKey & ikey) {
00162     return SetKey (ikey);
00163   }
00164   
00171   virtual const char *KeyText (const char *imodtype = 0);
00172   
00177   virtual char Display ();
00178   
00185   virtual SWDisplay *Disp (SWDisplay * idisp = 0);
00186   
00193   virtual char *Name (const char *imodname = 0);
00194   
00201   virtual char *Description (const char *imoddesc = 0);
00202   
00209   virtual char *Type (const char *imodtype = 0);
00210 
00211   // search methods
00212 
00224   virtual ListKey & Search (const char *istr, int searchType = 0, int flags = 0,
00225                   SWKey * scope = 0,
00226                   bool * justCheckIfSupported = 0,
00227                   void (*percent) (char, void *) = &nullPercent,
00228                   void *percentUserData = 0);
00232   virtual char createSearchFramework () {
00233     return 0;
00234   }                             // special search framework
00235   
00239   virtual bool hasSearchFramework () {
00240     return false;
00241   }                             // special search framework
00242   
00246   virtual bool isSearchOptimallySupported (const char *istr, int searchType,
00247                                            int flags, SWKey * scope) {
00248       bool retVal = false;
00249       Search (istr, searchType, flags, scope, &retVal);
00250       return retVal;
00251   }
00252 
00257   virtual SWKey *CreateKey ();
00258 
00262   virtual operator char *();
00263   
00268   virtual char *getRawEntry () = 0;
00269   
00273   virtual operator SWKey & () {
00274     return *key;
00275   }
00276   
00280   virtual operator SWKey *() {
00281     return key;
00282   }
00283 
00284   // write interface ----------------------------
00288   virtual bool isWritable () {
00289     return false;
00290   }
00291   
00296   static char createModule (const char *) {
00297     return -1;
00298   }
00299   
00304   virtual SWModule & operator << (const char *) {
00305     return *this;
00306   }
00307   
00312   virtual SWModule & operator << (const SWKey *) {
00313     return *this;
00314   }
00315   
00319   virtual void deleteEntry () {
00320   }
00321   
00322   // end write interface ------------------------
00323 
00329   virtual SWModule & operator -= (int decrement);
00330   
00336   virtual SWModule & operator += (int increment);
00337   
00341   virtual SWModule & operator++ (int) {
00342     return *this += 1;
00343   }
00344   
00348   virtual SWModule & operator-- (int) {
00349     return *this -= 1;
00350   }
00351   
00357   virtual SWModule & operator = (SW_POSITION p);
00358   
00363   virtual SWModule & AddRenderFilter (SWFilter * newfilter) {
00364     renderFilters->push_back (newfilter);
00365     return *this;
00366   }
00367 
00372   virtual SWModule & RemoveRenderFilter (SWFilter * oldfilter) {
00373     renderFilters->remove (oldfilter);
00374     return *this;
00375   }
00376 
00383   virtual void renderFilter (char *buf, long size, SWKey *key) {
00384         filterBuffer(renderFilters, buf, size, key);
00385   }
00386 
00391   virtual SWModule & AddStripFilter (SWFilter * newfilter) {
00392     stripFilters->push_back (newfilter);
00393     return *this;
00394   }
00395 
00402   virtual void stripFilter (char *buf, long size, SWKey *key) {
00403         filterBuffer(stripFilters, buf, size, key);
00404   }
00405   
00410   virtual SWModule & AddRawFilter (SWFilter * newfilter) {
00411     rawFilters->push_back (newfilter);
00412     return *this;
00413   }
00414   
00422   virtual void filterBuffer (FilterList *filters, char *buf, long size, SWKey *key) {
00423         FilterList::iterator it;
00424         for (it = filters->begin(); it != filters->end(); it++) {
00425                 (*it)->ProcessText(buf, size, key);
00426         }
00427   }
00428 
00435   virtual void rawFilter (char *buf, long size, SWKey *key) {
00436         filterBuffer(rawFilters, buf, size, key);
00437   }
00438   
00443   virtual SWModule & AddOptionFilter (SWFilter * newfilter) {
00444     optionFilters->push_back (newfilter);
00445     return *this;
00446   }
00447 
00454   virtual void optionFilter (char *buf, long size, SWKey *key) {
00455         filterBuffer(optionFilters, buf, size, key);
00456   }
00457   
00465   virtual const char *StripText (char *buf = 0, int len = -1);
00466   
00474   virtual const char *RenderText (char *buf = 0, int len = -1);
00475   
00481   virtual const char *StripText (SWKey * tmpKey);
00482   
00488   virtual const char *RenderText (SWKey * tmpKey);
00489   
00490 };
00491 
00492 
00493 #endif

Generated at Fri Oct 5 22:45:33 2001 for The Sword Project by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001