From 2de71d7b1d2c9b5611865bd32007b028901c5cf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20K=C4=99dzia?= <pawel.kedzia@pwr.wroc.pl> Date: Tue, 26 Apr 2011 09:29:40 +0200 Subject: [PATCH] Wrapper for Corpus2::Tag --- swig/Makefile | 60 +++++++++++++++++++++++++++++++++++++++++ swig/boost_shared_ptr.i | 25 +++++++++++++++++ swig/libcorpustag.i | 58 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 143 insertions(+) create mode 100644 swig/Makefile create mode 100644 swig/boost_shared_ptr.i create mode 100644 swig/libcorpustag.i diff --git a/swig/Makefile b/swig/Makefile new file mode 100644 index 0000000..a089f80 --- /dev/null +++ b/swig/Makefile @@ -0,0 +1,60 @@ +CPP=g++ +SWIG=swig +SWIGOPTS_LANG=-c++ -python + +PYTHONDIR=/usr/include/python2.6 +WCCLDIR=/usr/local/include/libwccl/ +CORPUS2DIR=/usr/local/include/libcorpus2/ +PWRUTILDIR= + +CORPUS2BIN=/usr/local/lib/libcorpus2.so +PWRUTILBIN=/usr/local/lib/libpwrutils.so +ANTLRLIB=/usr/lib/libantlr-pic.a + +CPPFLAGS=-fPIC -O2 + +CBIN=libcorpustag.o + +CBINOUT=_boost_shared_ptr.so \ + _libcorpustag.so + +CWRAP=boost_shared_ptr_wrap.cxx \ + libcorpustag_wrap.cxx + +CWRAPBIN=boost_shared_ptr_wrap.o \ + libcorpustag_wrap.o + +PYMODULES=boost_shared_ptr.py \ + libcorpustag.py + +PYCBIN=boost_shared_ptr.pyc \ + libcorpustag.pyc + +# ----------------------------------------------------------------------------- +all:boost_shared_ptr.o $(CBIN) + # Done +# ----------------------------------------------------------------------------- + +# ----------------------------------------------------------------------------- +# boost::shared_ptr wrappers +# ----------------------------------------------------------------------------- +# shared_ptr +boost_shared_ptr.o: + $(SWIG) $(SWIGOPTS_LANG) boost_shared_ptr.i + $(CPP) -c boost_shared_ptr_wrap.cxx -I$(PYTHONDIR) $(CPPFLAGS) + $(CPP) -shared boost_shared_ptr_wrap.o -o _boost_shared_ptr.so + + +# ----------------------------------------------------------------------------- +# Corpus2 Wrappers +# ----------------------------------------------------------------------------- +# Tag +libcorpustag.o: + $(SWIG) $(SWIGOPTS_LANG) libcorpustag.i + $(CPP) -c libcorpustag_wrap.cxx -I$(PYTHONDIR) $(CPPFLAGS) + $(CPP) -shared libcorpustag_wrap.o \ + $(PWRUTILBIN) $(CORPUS2BIN) -o _libcorpustag.so + +# ----------------------------------------------------------------------------- +clean: + rm -f $(CBIN) $(CBINOUT) $(CWRAP) $(CWRAPBIN) $(PYMODULES) $(PYCBIN) diff --git a/swig/boost_shared_ptr.i b/swig/boost_shared_ptr.i new file mode 100644 index 0000000..7803b22 --- /dev/null +++ b/swig/boost_shared_ptr.i @@ -0,0 +1,25 @@ +/** + * Wrapper for boost shared_ptr + */ +#ifndef SWIG_BOOST_SHAREDPTR +#define SWIG_BOOST_SHAREDPTR + +%module boost_shared_ptr +%{ +%} + +namespace boost { + template<class T> class shared_ptr { + public: + shared_ptr(); + shared_ptr(T * p); + T* operator->(); + private: + T * px; + int pn; + }; +} + +using namespace boost; + +#endif /* SWIG_BOOST_SHAREDPTR */ diff --git a/swig/libcorpustag.i b/swig/libcorpustag.i new file mode 100644 index 0000000..0197662 --- /dev/null +++ b/swig/libcorpustag.i @@ -0,0 +1,58 @@ +#ifndef SWIG_LIBCORPUS2_TAG_I +#define SWIG_LIBCORPUS2_TAG_I + +%module libcorpustag +%{ + #include <libcorpus2/tag.h> + #include <boost/cstdint.hpp> +%} + +%include "std_string.i" +%include "std_vector.i" + +/* Typedefs */ +%inline %{ + typedef std::bitset<64> mask_t; +%} + +%feature("notabstract") Corpus2::Tag; + +%rename(__op_eq__) Corpus2::Tag::operator==(const Tag& other) const; +%rename(__op_lw__) Corpus2::Tag::operator<(const Tag& other) const; + +namespace Corpus2 { + class Tag { + public: + Tag(); + explicit Tag(mask_t pos); + Tag(mask_t pos, mask_t values); + + /* --------------------------------------------------------------------- */ + ~Tag(); + + /* --------------------------------------------------------------------- */ + bool is_null() const; + int pos_count() const; + int get_pos_index() const; + + mask_t get_values() const; + mask_t get_pos() const; + + Tag& combine_with(const Tag& other); + Tag get_combined(const Tag& other) const; + Tag& mask_with(const Tag& other); + Tag get_masked(const Tag& other); + + std::string raw_dump() const; + bool operator<(const Tag& other) const; + bool operator==(const Tag& other) const; + }; + + size_t hash_value(const Tag &tag); +} + +using namespace std; +using namespace Corpus2; + + +#endif /* SWIG_LIBCORPUS2_TAG_I */ -- GitLab