[sword-svn] r2145 - in trunk/bindings/swig: . package

benpmorgan at www.crosswire.org benpmorgan at www.crosswire.org
Tue Mar 4 15:34:57 MST 2008


Author: benpmorgan
Date: 2008-03-04 15:34:55 -0700 (Tue, 04 Mar 2008)
New Revision: 2145

Added:
   trunk/bindings/swig/bases.i
   trunk/bindings/swig/extras.i
   trunk/bindings/swig/markupcallback.h
   trunk/bindings/swig/osishtmlhref.i
   trunk/bindings/swig/rendercallback.h
   trunk/bindings/swig/searcher.h
Modified:
   trunk/bindings/swig/package/Makefile.am
   trunk/bindings/swig/package/autogen.sh
   trunk/bindings/swig/sword.i
Log:
Updated SWIG bindings to add changes made for BPBible

Added: trunk/bindings/swig/bases.i
===================================================================
--- trunk/bindings/swig/bases.i	                        (rev 0)
+++ trunk/bindings/swig/bases.i	2008-03-04 22:34:55 UTC (rev 2145)
@@ -0,0 +1,35 @@
+%{
+#include "rawverse.h"
+#include "zverse.h"
+#include "rawstr.h"
+#include "rawstr4.h"
+#include "zstr.h"
+#include "swgenbook.h"
+#include "lzsscomprs.h"
+#include "zipcomprs.h"
+#include "versekey.h"
+#include "versetreekey.h"
+#include "treekey.h"
+#include "rawgenbook.h"
+#include "swtext.h"
+#include "swcom.h"
+#include "rawcom.h"
+#include "swld.h"
+#include "zld.h"
+#include "zcom.h"
+#include "ztext.h"
+#include "rawld.h"
+#include "rawld4.h"
+#include "treekeyidx.h"
+#include "rawtext.h"
+
+
+%}
+
+%immutable sword::RawVerse::nl;
+
+%include "rawverse.h"
+%include "zverse.h"
+%include "rawstr.h"
+%include "rawstr4.h"
+%include "zstr.h"


Property changes on: trunk/bindings/swig/bases.i
___________________________________________________________________
Name: svn:executable
   + *

Added: trunk/bindings/swig/extras.i
===================================================================
--- trunk/bindings/swig/extras.i	                        (rev 0)
+++ trunk/bindings/swig/extras.i	2008-03-04 22:34:55 UTC (rev 2145)
@@ -0,0 +1,13 @@
+%{ 
+#include "markupcallback.h"
+#include "rendercallback.h"
+#include "searcher.h"
+%}
+
+%include "markupcallback.h"
+%include "rendercallback.h"
+%include "searcher.h"
+
+
+
+


Property changes on: trunk/bindings/swig/extras.i
___________________________________________________________________
Name: svn:executable
   + *

Added: trunk/bindings/swig/markupcallback.h
===================================================================
--- trunk/bindings/swig/markupcallback.h	                        (rev 0)
+++ trunk/bindings/swig/markupcallback.h	2008-03-04 22:34:55 UTC (rev 2145)
@@ -0,0 +1,47 @@
+#include <markupfiltmgr.h>
+#include <swbuf.h>
+#include <defs.h>
+using namespace sword;
+
+class MarkupCallback {
+public:
+    virtual ~MarkupCallback() { ;}
+    virtual bool run(SWModule* x) {return false;}
+};
+
+  class MyMarkup : public MarkupFilterMgr
+  {
+
+  private:
+      MarkupCallback* _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
+  &section) { 
+          if(!call(module)) {
+              MarkupFilterMgr::AddRenderFilters(module, section);
+          }       
+      }
+  };
+
+


Property changes on: trunk/bindings/swig/markupcallback.h
___________________________________________________________________
Name: svn:executable
   + *

Added: trunk/bindings/swig/osishtmlhref.i
===================================================================
--- trunk/bindings/swig/osishtmlhref.i	                        (rev 0)
+++ trunk/bindings/swig/osishtmlhref.i	2008-03-04 22:34:55 UTC (rev 2145)
@@ -0,0 +1,19 @@
+
+%feature("director") OSISHTMLHREF;
+
+%{
+#include <swbasicfilter.h>
+#include <osishtmlhref.h>
+#include <plainhtml.h>
+#include <thmlhtmlhref.h>
+#include <gbfhtmlhref.h>
+#include "utf8html.h"
+%}
+
+%include <swbasicfilter.h>
+%include "osishtmlhref.h"
+%include "plainhtml.h"
+%include "thmlhtmlhref.h"
+%include "gbfhtmlhref.h"
+%include "utf8html.h"
+


Property changes on: trunk/bindings/swig/osishtmlhref.i
___________________________________________________________________
Name: svn:executable
   + *

Modified: trunk/bindings/swig/package/Makefile.am
===================================================================
--- trunk/bindings/swig/package/Makefile.am	2008-03-02 20:53:38 UTC (rev 2144)
+++ trunk/bindings/swig/package/Makefile.am	2008-03-04 22:34:55 UTC (rev 2145)
@@ -40,7 +40,7 @@
 	@echo "WriteMakefile(" >> perl/Makefile.PL
 	@echo "		'NAME'		=> 'Sword'," >> perl/Makefile.PL
 	@echo "		'VERSION'	=> '$(VERSION)'," >> perl/Makefile.PL
-	@echo "		'INC'		=> '$(SWORD_INCLUDES)'," >> perl/Makefile.PL
+	@echo "		'INC'		=> '$(SWORD_INCLUDES) -I..'," >> perl/Makefile.PL
 	@echo "		'DEFINE'	=> '-DSWIG'," >> perl/Makefile.PL
 	@echo "		'LIBS'		=> '$(LIB_SWORD) -lz'," >> perl/Makefile.PL
 	@echo "		'PREREQ_PM'	=> {}, # e.g., Module::Name => 1.1" >> perl/Makefile.PL
@@ -72,7 +72,7 @@
 	$(SWIG) -tcl -c++ -namespace -pkgversion $(VERSION) -o tcl/Sword.cxx -I$(top_srcdir) $(SWORD_INCLUDES) $(top_srcdir)/sword.i
 
 python_make: python_makebuild
-	cd python && $(PYTHON) setup.py build_ext $(SWORD_INCLUDES) $(LIB_SWORD)
+	cd python && $(PYTHON) setup.py build_ext $(SWORD_INCLUDES):.. $(LIB_SWORD)
 
 pythonswig: sword.i
 	mkdir -p python
@@ -90,9 +90,9 @@
 	@echo "	maintainer_email = \"sword-devel at crosswire.org\"," >> python/setup.py
 	@echo "	url = \"http://www.crosswire.org/sword\"," >> python/setup.py
 	@echo "	py_modules = [\"Sword\"]," >> python/setup.py
-	@echo " include_dirs=['$(SWORD_INCLUDES)']," >> python/setup.py
+	@echo "	include_dirs=['$(SWORD_INCLUDES)']," >> python/setup.py
 	@echo "	ext_modules = [Extension(\"_Sword\", [\"Sword.cxx\"]," >> python/setup.py
-	@echo " libraries=[('sword')], " >> python/setup.py
+	@echo "	libraries=[('sword')], " >> python/setup.py
 	@echo "	define_macros=[('SWIG',1)])], " >> python/setup.py
 	@echo ")" >> python/setup.py
 

Modified: trunk/bindings/swig/package/autogen.sh
===================================================================
--- trunk/bindings/swig/package/autogen.sh	2008-03-02 20:53:38 UTC (rev 2144)
+++ trunk/bindings/swig/package/autogen.sh	2008-03-04 22:34:55 UTC (rev 2145)
@@ -1,7 +1,9 @@
 #!/bin/sh
 echo "*** copying swig files"
 cp -a ../*.i .
+cp -a ../*.h .
 
+
 ACLOCAL="$AUTODIR""aclocal"
 echo "*** Recreating aclocal.m4"
 echo "$ACLOCAL"

Added: trunk/bindings/swig/rendercallback.h
===================================================================
--- trunk/bindings/swig/rendercallback.h	                        (rev 0)
+++ trunk/bindings/swig/rendercallback.h	2008-03-04 22:34:55 UTC (rev 2145)
@@ -0,0 +1,219 @@
+#ifndef _RENDERCALLBACK_H
+#define _RENDERCALLBACK_H
+#include <swbuf.h>
+#include <swmodule.h>
+#include <swkey.h>
+#include <swbasicfilter.h>
+#include <utilxml.h>
+#include <osishtmlhref.h>
+#include <thmlhtmlhref.h>
+
+#define FAILED 0
+#define SUCCEEDED 1
+#define INHERITED 2
+
+using namespace sword;
+
+class ReturnSuccess 
+{
+public:
+    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 ReturnSuccess run(sword::SWBuf& x, const char * token, 
+			sword::BasicFilterUserData* userData) 
+	{
+        ReturnSuccess nullm("", INHERITED);
+        return nullm;
+    }
+};
+
+// Forward declarations
+class OSISData;
+class ThMLData;
+
+
+class PyOSISHTMLHREF: public sword::OSISHTMLHREF 
+{
+private:
+    RenderCallback* _callback;
+
+public:
+	// Create a class which can be inherited externally
+	using sword::OSISHTMLHREF::MyUserData;
+	class MyOsisUserData : public MyUserData {};
+    
+	PyOSISHTMLHREF(RenderCallback* callback)
+    {
+        _callback=callback;
+    }
+
+	static OSISData* getData(sword::BasicFilterUserData* f)
+	{
+        return (OSISData*) f;
+	}
+			
+    virtual ~PyOSISHTMLHREF() 
+	{ 
+		delCallback();
+	} 
+	
+	void delCallback() 
+	{
+		delete _callback;
+		_callback = 0;
+	}
+	
+	void setCallback(RenderCallback *cb)
+	{
+		delCallback();
+		_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;
+         }
+     }
+
+ 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;
+		 }        
+
+		 return true;
+     }
+ };
+
+
+class PyThMLHTMLHREF : public ThMLHTMLHREF {
+private:
+    RenderCallback* _callback;
+public:
+	// Create a class which can be inherited externally
+	using sword::ThMLHTMLHREF::MyUserData;
+	class MyThmlUserData : public MyUserData {};
+
+	PyThMLHTMLHREF(RenderCallback* callback)
+	{
+		_callback=callback;
+	}
+
+	static ThMLData* getData(sword::BasicFilterUserData* f)
+	{
+        return (ThMLData*) f;
+	}
+	
+    virtual ~PyThMLHTMLHREF() 
+	{ 
+		delCallback();
+	} 
+	
+	void delCallback() 
+	{
+		delete _callback;
+		_callback = 0;
+	}
+	
+	void setCallback(RenderCallback *cb)
+	{
+		delCallback();
+		_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;
+         }
+     }
+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;
+		 }        
+
+		 return true;
+     }
+
+public:
+
+
+};
+
+class OSISData : 
+#ifndef SWIG
+public PyOSISHTMLHREF::MyOsisUserData {
+#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;
+
+#endif //!SWIG
+};
+
+class ThMLData : 
+#ifndef SWIG
+public PyThMLHTMLHREF::MyThmlUserData {
+#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;	
+
+#endif //!SWIG
+};
+
+#endif // _RENDERCALLBACK_H


Property changes on: trunk/bindings/swig/rendercallback.h
___________________________________________________________________
Name: svn:executable
   + *

Added: trunk/bindings/swig/searcher.h
===================================================================
--- trunk/bindings/swig/searcher.h	                        (rev 0)
+++ trunk/bindings/swig/searcher.h	2008-03-04 22:34:55 UTC (rev 2145)
@@ -0,0 +1,39 @@
+using namespace sword;
+class SWSearcher{
+	public:
+        sword::SWModule* mod;
+        int percent;
+
+        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(){}
+
+        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;
+        }
+
+        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;
+        }
+};
+


Property changes on: trunk/bindings/swig/searcher.h
___________________________________________________________________
Name: svn:executable
   + *

Modified: trunk/bindings/swig/sword.i
===================================================================
--- trunk/bindings/swig/sword.i	2008-03-02 20:53:38 UTC (rev 2144)
+++ trunk/bindings/swig/sword.i	2008-03-04 22:34:55 UTC (rev 2145)
@@ -4,7 +4,40 @@
 #define SWDLLEXPORT  
 
 %module "Sword"
+%module(directors="1") Sword;
 
+%feature("director") sword::SWLog::logMessage;
+
+%feature("director") RenderCallback;
+%feature("director") MarkupCallback;
+
+%feature("director") SWSearcher;
+
+%feature("director") sword::StatusReporter;
+
+
+%feature("director:except") {
+    if ($error != NULL) {
+        throw Swig::DirectorMethodException();
+    }
+}
+
+%exception {
+    try { $action }
+    catch (Swig::DirectorException &e) { SWIG_fail; }
+}
+
+
+
+
+%ignore *::operator=;
+%ignore *::operator++;
+%ignore *::operator--;
+%ignore *::operator const char *;
+%ignore *::operator sword::SWKey &;
+%ignore *::operator sword::SWKey *;
+
+
 %include "defs.i"
 
 %include "swbuf.i"
@@ -63,3 +96,10 @@
 %include "localemgr.i"
 
 %include "url.i"
+
+%include "bases.i"
+%include "osishtmlhref.i"
+%include "extras.i"
+%include "swlog.i"
+%include "installmgr.i"
+




More information about the sword-cvs mailing list