00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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 <swconfig.h>
00032 #include <swcacher.h>
00033 #include <list>
00034
00035 #include <defs.h>
00036 #include <multimapwdef.h>
00037
00038 SWORD_NAMESPACE_START
00039
00040 #define SWMODULE_OPERATORS \
00041 operator const char *() { return RenderText(); } \
00042 operator SWKey &() { return *getKey(); } \
00043 operator SWKey *() { return getKey(); } \
00044 SWModule &operator <<(const char *inbuf) { setEntry(inbuf); return *this; } \
00045 SWModule &operator <<(const SWKey *sourceKey) { linkEntry(sourceKey); return *this; } \
00046 SWModule &operator -=(int steps) { decrement(steps); return *this; } \
00047 SWModule &operator +=(int steps) { increment(steps); return *this; } \
00048 SWModule &operator ++(int) { return *this += 1; } \
00049 SWModule &operator --(int) { return *this -= 1; } \
00050 SWModule &operator =(SW_POSITION p) { setPosition(p); return *this; }
00051
00052
00053 typedef std::list < SWFilter * >FilterList;
00054
00055 typedef std::map < std::string, std::string, std::less < std::string > > AttributeValue;
00056 typedef std::map < std::string, AttributeValue, std::less < std::string > > AttributeList;
00057 typedef std::map < std::string, AttributeList, std::less < std::string > > AttributeTypeList;
00058
00059 #define SWTextDirection char
00060 #define SWTextEncoding char
00061 #define SWTextMarkup char
00062
00063 enum {DIRECTION_LTR = 0, DIRECTION_RTL, DIRECTION_BIDI};
00064 enum {FMT_UNKNOWN = 0, FMT_PLAIN, FMT_THML, FMT_GBF, FMT_HTML, FMT_HTMLHREF, FMT_RTF, FMT_OSIS};
00065 enum {ENC_UNKNOWN = 0, ENC_LATIN1, ENC_UTF8, ENC_SCSU, ENC_UTF16, ENC_RTF, ENC_HTML};
00066
00075 class SWDLLEXPORT SWModule : public SWCacher {
00076
00077 protected:
00078
00079 ConfigEntMap ownConfig;
00080 ConfigEntMap *config;
00081 mutable AttributeTypeList entryAttributes;
00082 mutable bool procEntAttr;
00083
00084 char error;
00085 bool skipConsecutiveLinks;
00086
00088 SWKey *key;
00089
00090 ListKey listkey;
00091 char *modname;
00092 char *moddesc;
00093 char *modtype;
00094 char *modlang;
00095
00096 char direction;
00097 char markup;
00098 char encoding;
00099
00101 SWDisplay *disp;
00102
00103 static SWDisplay rawdisp;
00104 char *entrybuf;
00105 unsigned long entrybufallocsize;
00106
00108 FilterList *stripFilters;
00109
00111 FilterList *rawFilters;
00112
00114 FilterList *renderFilters;
00115
00117 FilterList *optionFilters;
00118
00120 FilterList *encodingFilters;
00121
00122 int entrySize;
00123 mutable long entryIndex;
00124
00125 public:
00132 static void nullPercent(char percent, void *userData);
00137 bool terminateSearch;
00150 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);
00153 virtual ~SWModule();
00158 virtual char Error();
00162 virtual const bool isUnicode() const { return (encoding == (char)ENC_UTF8 || encoding == (char)ENC_SCSU); }
00163
00164
00165
00166
00167 virtual const ConfigEntMap &getConfig() const { return *config; }
00168 virtual void setConfig(ConfigEntMap *config);
00169 virtual const char *getConfigEntry(const char *key) const;
00170
00174 virtual const int getEntrySize() const { return entrySize; }
00183 char SetKey(const SWKey *ikey) { return setKey(ikey); }
00184 virtual char setKey(const SWKey *ikey);
00185
00186
00187 virtual long Index() const { return entryIndex; }
00188 virtual long Index(long iindex) { entryIndex = iindex; return entryIndex; }
00189
00196 char SetKey(const SWKey &ikey) { return setKey(ikey); }
00197 char setKey(const SWKey &ikey) { return SetKey(&ikey); }
00198
00203 SWKey &Key() const { return *getKey(); }
00204 SWKey *getKey() const;
00205
00213 char Key(const SWKey & ikey) { return setKey(ikey); }
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223 virtual const char *KeyText(const char *ikeytext = 0) {
00224 if (ikeytext) setKey(ikeytext);
00225 return *getKey();
00226 }
00227
00232 virtual char Display();
00233
00240 virtual SWDisplay *Disp(SWDisplay * idisp = 0);
00247 virtual char *Name(const char *imodname = 0);
00254 virtual char *Description(const char *imoddesc = 0);
00261 virtual char *Type(const char *imodtype = 0);
00268 virtual char Direction(signed char newdir = -1);
00275 virtual char Encoding(signed char enc = -1);
00282 virtual char Markup(signed char enc = -1);
00289 virtual char *Lang(const char *imodlang = 0);
00290
00291
00292
00304 virtual ListKey & Search(const char *istr, int searchType = 0, int flags = 0,
00305 SWKey * scope = 0,
00306 bool * justCheckIfSupported = 0,
00307 void (*percent) (char, void *) = &nullPercent,
00308 void *percentUserData = 0);
00312 virtual signed char createSearchFramework() { return 0; }
00316 virtual bool hasSearchFramework() { return false; }
00321 virtual bool isSearchOptimallySupported(const char *istr, int searchType,
00322 int flags, SWKey * scope) {
00323 bool retVal = false;
00324 Search(istr, searchType, flags, scope, &retVal);
00325 return retVal;
00326 }
00333 virtual SWKey *CreateKey();
00338 #ifndef SWIG
00339 virtual char *getRawEntry() = 0;
00340 #else
00341 virtual char *getRawEntry() {};
00342 #endif
00343
00344
00345
00349 virtual bool isWritable() { return false; }
00354 static signed char createModule(const char *) { return -1; }
00359 virtual void setEntry(const char *inbuf, long len = -1) { }
00363 virtual void linkEntry(const SWKey *sourceKey) { }
00367 virtual void deleteEntry() {}
00368
00369
00370
00376 virtual void decrement(int steps = 1);
00382 virtual void increment(int steps = 1);
00388 virtual void setPosition(SW_POSITION p);
00393 virtual SWModule & AddRenderFilter(SWFilter * newfilter) {
00394 renderFilters->push_back (newfilter);
00395 return *this;
00396 }
00401 virtual SWModule & RemoveRenderFilter(SWFilter * oldfilter) {
00402 renderFilters->remove (oldfilter);
00403 return *this;
00404 }
00410 virtual SWModule & ReplaceRenderFilter(SWFilter * oldfilter, SWFilter * newfilter) {
00411 FilterList::iterator iter;
00412 for (iter = renderFilters->begin(); iter != renderFilters->end(); iter++) {
00413 if (*iter == oldfilter)
00414 *iter = newfilter;
00415 }
00416 return *this;
00417 }
00424 virtual void renderFilter(char *buf, long size, SWKey *key) {
00425 filterBuffer(renderFilters, buf, size, key);
00426 }
00431 virtual SWModule & AddEncodingFilter(SWFilter * newfilter) {
00432 encodingFilters->push_back (newfilter);
00433 return *this;
00434 }
00439 virtual SWModule & RemoveEncodingFilter(SWFilter * oldfilter) {
00440 encodingFilters->remove (oldfilter);
00441 return *this;
00442 }
00448 virtual SWModule & ReplaceEncodingFilter(SWFilter * oldfilter, SWFilter * newfilter) {
00449 FilterList::iterator iter;
00450 for (iter = encodingFilters->begin(); iter != encodingFilters->end(); iter++) {
00451 if (*iter == oldfilter)
00452 *iter = newfilter;
00453 }
00454 return *this;
00455 }
00462 virtual void encodingFilter(char *buf, long size, SWKey *key) {
00463 filterBuffer(encodingFilters, buf, size, key);
00464 }
00469 virtual SWModule & AddStripFilter(SWFilter * newfilter) {
00470 stripFilters->push_back (newfilter);
00471 return *this;
00472 }
00479 virtual void stripFilter(char *buf, long size, SWKey *key) {
00480 filterBuffer(stripFilters, buf, size, key);
00481 }
00486 virtual SWModule & AddRawFilter(SWFilter * newfilter) {
00487 rawFilters->push_back (newfilter);
00488 return *this;
00489 }
00497 virtual void filterBuffer(FilterList *filters, char *buf, long size, SWKey *key) {
00498 FilterList::iterator it;
00499 for (it = filters->begin(); it != filters->end(); it++) {
00500 (*it)->ProcessText(buf, size, key, this);
00501 }
00502 }
00509 virtual void rawFilter(char *buf, long size, SWKey *key) {
00510 filterBuffer(rawFilters, buf, size, key);
00511 }
00516 virtual SWModule & AddOptionFilter(SWFilter * newfilter) {
00517 optionFilters->push_back(newfilter);
00518 return *this;
00519 }
00526 virtual void optionFilter(char *buf, long size, SWKey *key) {
00527 filterBuffer(optionFilters, buf, size, key);
00528 }
00536 virtual const char *StripText(char *buf = 0, int len = -1);
00544 virtual const char *RenderText(char *buf = 0, int len = -1, bool render = true);
00550 virtual const char *StripText(SWKey * tmpKey);
00556 virtual const char *RenderText(SWKey * tmpKey);
00557
00564 virtual void setSkipConsecutiveLinks(bool val) { skipConsecutiveLinks = val; }
00565 virtual bool getSkipConsecutiveLinks() { return skipConsecutiveLinks; }
00566 virtual AttributeTypeList &getEntryAttributes() const { return entryAttributes; }
00567 virtual void processEntryAttributes(bool val) const { procEntAttr = val; }
00568 virtual bool isProcessEntryAttributes() const { return procEntAttr; }
00569
00570
00571
00572
00573
00574 SWMODULE_OPERATORS
00575
00576 };
00577
00578 SWORD_NAMESPACE_END
00579 #endif