[sword-svn] r2368 - trunk/bindings/swig
benpmorgan at crosswire.org
benpmorgan at crosswire.org
Wed Apr 29 23:46:11 MST 2009
Author: benpmorgan
Date: 2009-04-29 23:46:10 -0700 (Wed, 29 Apr 2009)
New Revision: 2368
Modified:
trunk/bindings/swig/markupcallback.h
trunk/bindings/swig/rendercallback.h
trunk/bindings/swig/searcher.h
Log:
Update rendercallback to try substituting token, and also exposed substitution
methods.
Clean up whitespace substantially
Modified: trunk/bindings/swig/markupcallback.h
===================================================================
--- trunk/bindings/swig/markupcallback.h 2009-04-29 23:25:56 UTC (rev 2367)
+++ trunk/bindings/swig/markupcallback.h 2009-04-30 06:46:10 UTC (rev 2368)
@@ -5,43 +5,42 @@
class MarkupCallback {
public:
- virtual ~MarkupCallback() { ;}
- virtual bool run(SWModule* x) {return false;}
+ virtual ~MarkupCallback() { ;}
+ virtual bool run(SWModule* x) {return false;}
};
- class MyMarkup : public MarkupFilterMgr
- {
+class MyMarkup : public MarkupFilterMgr {
+private:
+ MarkupCallback* _callback;
- private:
- MarkupCallback* _callback;
+public:
+ MyMarkup(MarkupCallback* callback, char markup = FMT_THML, char encoding = ENC_UTF8) :
+ MarkupFilterMgr(markup, encoding), _callback(callback) {}
- public:
-
- MyMarkup(MarkupCallback* callback, char markup = FMT_THML, char encoding = ENC_UTF8): MarkupFilterMgr(markup, encoding), _callback(callback)
- {}
- virtual ~MyMarkup() {
- delCallback();
- }
- void delCallback() {
- delete _callback; _callback = 0;
- }
- void setCallback(MarkupCallback *cb)
- {
- delCallback();
- _callback = cb;
- }
- bool call(SWModule* x) {
- if (_callback)
- return _callback->run(x);
- return false;
- }
- protected:
- virtual void AddRenderFilters(SWModule *module, ConfigEntMap
- §ion) {
- if(!call(module)) {
- MarkupFilterMgr::AddRenderFilters(module, section);
- }
- }
- };
+ virtual ~MyMarkup() {
+ delCallback();
+ }
+ void delCallback() {
+ delete _callback; _callback = 0;
+ }
+ void setCallback(MarkupCallback *cb) {
+ delCallback();
+ _callback = cb;
+ }
+
+ bool call(SWModule* x) {
+ if (_callback)
+ return _callback->run(x);
+ return false;
+ }
+
+protected:
+ virtual void AddRenderFilters(SWModule *module,
+ ConfigEntMap §ion) {
+ if(!call(module)) {
+ MarkupFilterMgr::AddRenderFilters(module, section);
+ }
+ }
+};
Modified: trunk/bindings/swig/rendercallback.h
===================================================================
--- trunk/bindings/swig/rendercallback.h 2009-04-29 23:25:56 UTC (rev 2367)
+++ trunk/bindings/swig/rendercallback.h 2009-04-30 06:46:10 UTC (rev 2368)
@@ -17,24 +17,24 @@
class ReturnSuccess
{
public:
- ReturnSuccess(): data(""), success(FAILED) {}
- ReturnSuccess(char* data, int success): data(data), success(success) {}
- virtual ~ReturnSuccess() {}
- char* data;
- int success;
+ ReturnSuccess(): data(""), success(FAILED) {}
+ ReturnSuccess(char* data, int success): data(data), success(success) {}
+ virtual ~ReturnSuccess() {}
+ char* data;
+ int success;
};
class RenderCallback {
public:
- virtual ~RenderCallback() {;}
+ virtual ~RenderCallback() {;}
- virtual ReturnSuccess run(sword::SWBuf& x, const char * token,
+ virtual ReturnSuccess run(sword::SWBuf& x, const char * token,
sword::BasicFilterUserData* userData)
{
- ReturnSuccess nullm("", INHERITED);
- return nullm;
- }
+ ReturnSuccess nullm("", INHERITED);
+ return nullm;
+ }
};
// Forward declarations
@@ -45,30 +45,35 @@
class PyOSISHTMLHREF: public sword::OSISHTMLHREF
{
private:
- RenderCallback* _callback;
+ RenderCallback* _callback;
public:
// Create a class which can be inherited externally
#ifndef SWIG
using sword::OSISHTMLHREF::MyUserData;
- class MyOsisUserData : public MyUserData {
- public:
- MyOsisUserData(const SWModule *module, const SWKey *key):
- MyUserData(module, key) {};
- };
+ class MyOsisUserData : public MyUserData {
+ public:
+ MyOsisUserData(const SWModule *module, const SWKey *key):
+ MyUserData(module, key) {};
+ };
#endif
-
+
+ using sword::OSISHTMLHREF::removeTokenSubstitute;
+ using sword::OSISHTMLHREF::addTokenSubstitute;
+ using sword::OSISHTMLHREF::addAllowedEscapeString;
+ using sword::OSISHTMLHREF::removeAllowedEscapeString;
+
PyOSISHTMLHREF(RenderCallback* callback)
- {
- _callback=callback;
- }
+ {
+ _callback=callback;
+ }
static OSISData* getData(sword::BasicFilterUserData* f)
{
- return (OSISData*) f;
+ return (OSISData*) f;
}
- virtual ~PyOSISHTMLHREF()
+ virtual ~PyOSISHTMLHREF()
{
delCallback();
}
@@ -85,50 +90,58 @@
_callback = cb;
}
- ReturnSuccess call(sword::SWBuf &buf, const char *token, sword::BasicFilterUserData *userData)
- {
- if (_callback) return _callback->run(buf, token, userData);
- else
- {
- ReturnSuccess nullm("", INHERITED);
- return nullm;
- }
- }
+ ReturnSuccess call(sword::SWBuf &buf, const char *token, sword::BasicFilterUserData *userData)
+ {
+ if (_callback) return _callback->run(buf, token, userData);
+ else
+ {
+ ReturnSuccess nullm("", INHERITED);
+ return nullm;
+ }
+ }
- protected:
- virtual bool handleToken(sword::SWBuf &buf, const char *token, sword::BasicFilterUserData *userData)
- {
- ReturnSuccess result = call(buf, token, userData);
- switch(result.success)
- {
- case INHERITED:
- return sword::OSISHTMLHREF::handleToken(buf, token, userData);
- case FAILED:
- return false;
- case SUCCEEDED:
- buf += result.data;
- return true;
- }
+protected:
+ virtual bool handleToken(sword::SWBuf &buf, const char *token, sword::BasicFilterUserData *userData)
+ {
+ SWBuf scratch;
+ bool sub = (userData->suspendTextPassThru) ? substituteToken(scratch, token) : substituteToken(buf, token);
+ if(sub) return true;
- return true;
- }
- };
+ ReturnSuccess result = call(buf, token, userData);
+ switch(result.success)
+ {
+ case INHERITED:
+ return sword::OSISHTMLHREF::handleToken(buf, token, userData);
+ case FAILED:
+ return false;
+ case SUCCEEDED:
+ buf += result.data;
+ return true;
+ }
+ return true;
+ }
+};
+
class PyThMLHTMLHREF : public ThMLHTMLHREF {
private:
- RenderCallback* _callback;
+ RenderCallback* _callback;
public:
// Create a class which can be inherited externally
#ifndef SWIG
using sword::ThMLHTMLHREF::MyUserData;
class MyThmlUserData : public MyUserData {
- public:
- MyThmlUserData(const SWModule *module, const SWKey *key):
- MyUserData(module, key) {};
- };
+ public:
+ MyThmlUserData(const SWModule *module, const SWKey *key):
+ MyUserData(module, key) {};
+ };
#endif
+ using sword::ThMLHTMLHREF::removeTokenSubstitute;
+ using sword::ThMLHTMLHREF::addTokenSubstitute;
+ using sword::ThMLHTMLHREF::addAllowedEscapeString;
+ using sword::ThMLHTMLHREF::removeAllowedEscapeString;
PyThMLHTMLHREF(RenderCallback* callback)
{
_callback=callback;
@@ -136,10 +149,10 @@
static ThMLData* getData(sword::BasicFilterUserData* f)
{
- return (ThMLData*) f;
+ return (ThMLData*) f;
}
- virtual ~PyThMLHTMLHREF()
+ virtual ~PyThMLHTMLHREF()
{
delCallback();
}
@@ -156,60 +169,60 @@
_callback = cb;
}
- ReturnSuccess call(sword::SWBuf &buf, const char *token, sword::BasicFilterUserData *userData)
- {
- if (_callback) return _callback->run(buf, token, userData);
- else
- {
- ReturnSuccess nullm("", INHERITED);
- return nullm;
- }
- }
+ ReturnSuccess call(sword::SWBuf &buf, const char *token, sword::BasicFilterUserData *userData)
+ {
+ if (_callback) return _callback->run(buf, token, userData);
+ else
+ {
+ ReturnSuccess nullm("", INHERITED);
+ return nullm;
+ }
+ }
protected:
- virtual bool handleToken(sword::SWBuf &buf, const char *token, sword::BasicFilterUserData *userData)
- {
- ReturnSuccess result = call(buf, token, userData);
- switch(result.success)
- {
- case INHERITED:
- return sword::ThMLHTMLHREF::handleToken(buf, token, userData);
- case FAILED:
- return false;
- case SUCCEEDED:
- buf += result.data;
- return true;
- }
+ virtual bool handleToken(sword::SWBuf &buf, const char *token, sword::BasicFilterUserData *userData)
+ {
+ SWBuf scratch;
+ bool sub = (userData->suspendTextPassThru) ? substituteToken(scratch, token) : substituteToken(buf, token);
+ if(sub) return true;
+
+ ReturnSuccess result = call(buf, token, userData);
+ switch(result.success)
+ {
+ case INHERITED:
+ return sword::ThMLHTMLHREF::handleToken(buf, token, userData);
+ case FAILED:
+ return false;
+ case SUCCEEDED:
+ buf += result.data;
+ return true;
+ }
- return true;
- }
-
-public:
-
-
+ return true;
+ }
};
class OSISData :
#ifndef SWIG
public PyOSISHTMLHREF::MyOsisUserData {
- public:
- OSISData(const SWModule *module, const SWKey *key):
- PyOSISHTMLHREF::MyOsisUserData(module, key) {};
+public:
+ OSISData(const SWModule *module, const SWKey *key):
+ PyOSISHTMLHREF::MyOsisUserData(module, key) {};
#else
// trick SWIG into thinking this is not inherited from an inner class...
public sword::BasicFilterUserData
{
public:
- bool osisQToTick;
- bool inBold;
- bool inXRefNote;
- bool BiblicalText;
- int suspendLevel;
- SWBuf wordsOfChristStart;
- SWBuf wordsOfChristEnd;
- SWBuf lastTransChange;
- SWBuf w;
- SWBuf fn;
- SWBuf version;
+ bool osisQToTick;
+ bool inBold;
+ bool inXRefNote;
+ bool BiblicalText;
+ int suspendLevel;
+ SWBuf wordsOfChristStart;
+ SWBuf wordsOfChristEnd;
+ SWBuf lastTransChange;
+ SWBuf w;
+ SWBuf fn;
+ SWBuf version;
#endif //!SWIG
};
@@ -217,20 +230,20 @@
class ThMLData :
#ifndef SWIG
public PyThMLHTMLHREF::MyThmlUserData {
- public:
- ThMLData(const SWModule *module, const SWKey *key):
- PyThMLHTMLHREF::MyThmlUserData(module, key) {};
+ public:
+ ThMLData(const SWModule *module, const SWKey *key):
+ PyThMLHTMLHREF::MyThmlUserData(module, key) {};
#else
// trick SWIG into thinking this is not inherited from an inner class...
public sword::BasicFilterUserData
{
public:
- SWBuf inscriptRef;
- bool SecHead;
- bool BiblicalText;
- SWBuf version;
- XMLTag startTag;
+ SWBuf inscriptRef;
+ bool SecHead;
+ bool BiblicalText;
+ SWBuf version;
+ XMLTag startTag;
#endif //!SWIG
};
Modified: trunk/bindings/swig/searcher.h
===================================================================
--- trunk/bindings/swig/searcher.h 2009-04-29 23:25:56 UTC (rev 2367)
+++ trunk/bindings/swig/searcher.h 2009-04-30 06:46:10 UTC (rev 2368)
@@ -1,39 +1,43 @@
+#include <swmodule.h>
+#include <swkey.h>
+#include <listkey.h>
+
using namespace sword;
class SWSearcher{
- public:
- sword::SWModule* mod;
- int percent;
+public:
+ sword::SWModule* mod;
+ int percent;
- static void Callback(char status, void *me){
- SWSearcher* searcher = (SWSearcher*)me;
- searcher->PercentFunction((int) status);
- }
+ static void Callback(char status, void *me){
+ SWSearcher* searcher = (SWSearcher*)me;
+ searcher->PercentFunction((int) status);
+ }
- virtual void PercentFunction(int value){
- percent=value;
- }
-
- SWSearcher(sword::SWModule* Mod){mod=Mod;}
- virtual ~SWSearcher(){}
+ virtual void PercentFunction(int value){
+ percent=value;
+ }
+
+ SWSearcher(sword::SWModule* Mod){mod=Mod;}
+ virtual ~SWSearcher(){}
- int GetPercent(){return percent;}
+ int GetPercent(){return percent;}
- bool isSearchSupported(const char *istr, int searchType = 0,
- int flags = 0,
- SWKey * scope = 0) {
- bool checksupported = true;
- mod->search(istr, searchType, flags, scope, &checksupported);
- return checksupported;
- }
+ bool isSearchSupported(const char *istr, int searchType = 0,
+ int flags = 0,
+ SWKey * scope = 0) {
+ bool checksupported = true;
+ mod->search(istr, searchType, flags, scope, &checksupported);
+ return checksupported;
+ }
- ListKey &doSearch(const char *istr, int searchType = 0, int flags = 0,
- SWKey *scope = 0) {
- return mod->search(istr, searchType, flags, scope,
- 0, this->Callback, (void *) this);
- }
+ ListKey &doSearch(const char *istr, int searchType = 0, int flags = 0,
+ SWKey *scope = 0) {
+ return mod->search(istr, searchType, flags, scope,
+ 0, this->Callback, (void *) this);
+ }
- void TerminateSearch(){
- mod->terminateSearch=true;
- }
+ void TerminateSearch(){
+ mod->terminateSearch=true;
+ }
};
More information about the sword-cvs
mailing list