From 1c08da810071facd303c48aae0398c9f3451c40f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20K=C4=99dzia?= <pawel.kedzia@pwr.wroc.pl> Date: Wed, 11 May 2011 13:33:59 +0200 Subject: [PATCH] (swig) Added wrappers for Wccl::FunctionalOpSequence, Wccl::UntypedOpSequence, Wccl::OpSequence --- swig/Makefile | 13 ++ swig/libcclfunctionalopsequence.i | 203 ++++++++++++++++++++++++++++++ 2 files changed, 216 insertions(+) create mode 100644 swig/libcclfunctionalopsequence.i diff --git a/swig/Makefile b/swig/Makefile index 32855f6..3fdbb67 100644 --- a/swig/Makefile +++ b/swig/Makefile @@ -37,6 +37,7 @@ CBIN=libcclvalue.o \ libccltagrule.o \ libccltagrulesequence.o \ libcclmatchrule.o \ + libcclfunctionalopsequence.o \ wccl.o CBINOUT=_libcclvalue.so \ @@ -62,6 +63,7 @@ CBINOUT=_libcclvalue.so \ _libccltagrulesequence.so \ _libcclmatchrule.so \ _wccl.so \ + _libcclfunctionalopsequence.so \ _boost_shared_ptr.so CWRAP=libcclvalue_wrap.cxx \ @@ -87,6 +89,7 @@ CWRAP=libcclvalue_wrap.cxx \ libccltagrulesequence_wrap.cxx \ libcclmatchrule_wrap.cxx \ wccl_wrap.cxx \ + libcclfunctionalopsequence_wrap.cxx \ boost_shared_ptr_wrap.cxx CWRAPBIN=libcclvalue_wrap.o \ @@ -112,6 +115,7 @@ CWRAPBIN=libcclvalue_wrap.o \ libccltagrulesequence_wrap.o \ libcclmatchrule_wrap.o \ wccl_wrap.o \ + libcclfunctionalopsequence_wrap.o \ boost_shared_ptr_wrap.o PYMODULES=libcclvalue.py \ @@ -137,6 +141,7 @@ PYMODULES=libcclvalue.py \ libccltagrulesequence.py \ libcclmatchrule.py \ wccl.py \ + libcclfunctionalopsequence.py \ boost_shared_ptr.py PYCBIN=libcclvalue.pyc \ @@ -162,6 +167,7 @@ PYCBIN=libcclvalue.pyc \ libccltagrulesequence.pyc \ libcclmatchrule.pyc \ wccl.pyc \ + libcclfunctionalopsequence.pyc \ boost_shared_ptr.pyc all:boost_shared_ptr.o $(CBIN) @@ -341,6 +347,13 @@ libcclmatchrule.o: $(CPP) -shared libcclmatchrule_wrap.o \ $(CCLBIN) $(ANTLRLIB) -o _libcclmatchrule.so +# FunctionalOpSequence +libcclfunctionalopsequence.o: + $(SWIG) $(SWIGOPTS_LANG) libcclfunctionalopsequence.i + $(CPP) -c libcclfunctionalopsequence_wrap.cxx -I$(PYTHONDIR) -I$(WCCLDIR) $(CPPFLAGS) + $(CPP) -shared libcclfunctionalopsequence_wrap.o \ + $(CCLBIN) $(ANTLRLIB) -o _libcclfunctionalopsequence.so + # ----------------------------------------------------------------------------- # Wccl Library wccl.o: diff --git a/swig/libcclfunctionalopsequence.i b/swig/libcclfunctionalopsequence.i new file mode 100644 index 0000000..0a15daf --- /dev/null +++ b/swig/libcclfunctionalopsequence.i @@ -0,0 +1,203 @@ +#ifndef SWIG_LIBWCCL_FUNCTIONALOPSEQUENCE_I +#define SWIG_LIBWCCL_FUNCTIONALOPSEQUENCE_I + +%module libcclfunctionalopsequence +%{ + #include <libwccl/ops/opsequence.h> +%} + +%include "libccloperator.i" +%include "libcclexpression.i" +%include "libcclfunctionaloperator.i" + +%include "std_pair.i" +%include "std_string.i" +%include "std_vector.i" + +%nodefaultctor Wccl::FunctionalOpSequence; + +%template(fun_op_ptr_t) boost::shared_ptr<FunctionalOperator>; +%template(fun_op_ptr_c_t) boost::shared_ptr<const FunctionalOperator>; +%template(name_op_pair_t) std::pair<std::string, boost::shared_ptr<FunctionalOperator> > ; +%template(name_op_pair_c_t) std::pair<std::string, boost::shared_ptr<const FunctionalOperator> >; +%template(name_op_v_t) std::vector<std::pair<std::string, boost::shared_ptr<FunctionalOperator> > >; +%template(name_op_v_c_t) std::vector<std::pair<std::string, boost::shared_ptr<const FunctionalOperator> > >; + +namespace Wccl { + class FunctionalOpSequence : public Expression { + public: + typedef shared_ptr<FunctionalOperator> fun_op_ptr_t; + typedef shared_ptr<const FunctionalOperator> fun_op_ptr_c_t; + typedef std::pair<std::string, fun_op_ptr_t> name_op_pair_t; + typedef std::pair<std::string, fun_op_ptr_c_t> name_op_pair_c_t; + typedef std::vector<name_op_pair_t> name_op_v_t; + typedef std::vector<name_op_pair_c_t> name_op_v_c_t; + /* --------------------------------------------------------------------- */ + + std::string name() const; + /* --------------------------------------------------------------------- */ + + virtual size_t size() const = 0; + virtual bool empty() const = 0; + /* --------------------------------------------------------------------- */ + + virtual FunctionalOperator& get(size_t idx) = 0; + virtual const FunctionalOperator& get(size_t idx) const = 0; + /* --------------------------------------------------------------------- */ + + virtual fun_op_ptr_t get_untyped_ptr(size_t idx) = 0; + virtual fun_op_ptr_c_t get_untyped_ptr(size_t idx) const = 0; + /* --------------------------------------------------------------------- */ + + name_op_v_t& add_name_op_pairs_untyped(name_op_v_t& pairs); + name_op_v_c_t& add_name_op_pairs_untyped(name_op_v_c_t& pairs) const; + /* --------------------------------------------------------------------- */ + + name_op_v_t gen_name_op_pairs_untyped(); + name_op_v_c_t gen_name_op_pairs_untyped() const; + /* --------------------------------------------------------------------- */ + + std::string gen_op_name(size_t idx) const; + /* --------------------------------------------------------------------- */ + + name_op_pair_t gen_name_op_pair_untyped(size_t idx); + name_op_pair_c_t gen_name_op_pair_untyped(size_t idx) const; + /* --------------------------------------------------------------------- */ + + shared_ptr<FunctionalOpSequence> clone() const; + /* --------------------------------------------------------------------- */ + + virtual ~FunctionalOpSequence(); + /* --------------------------------------------------------------------- */ + + protected: + FunctionalOpSequence(const std::string& name); + virtual FunctionalOpSequence* clone_internal() const = 0; + }; // FunctionalOpSequence + + /* ----------------------------------------------------------------------- */ + + + class UntypedOpSequence : public FunctionalOpSequence { + public: + typedef FunctionalOperator op_t; + + UntypedOpSequence(const std::string& name); + /* --------------------------------------------------------------------- */ + + bool empty() const; + size_t size() const; + /* --------------------------------------------------------------------- */ + + void append(const fun_op_ptr_t& op); + /* --------------------------------------------------------------------- */ + + op_t& get(size_t idx); + const op_t& get(size_t idx) const; + /* --------------------------------------------------------------------- */ + + fun_op_ptr_t get_untyped_ptr(size_t idx); + fun_op_ptr_c_t get_untyped_ptr(size_t idx) const; + /* --------------------------------------------------------------------- */ + + fun_op_ptr_t get_ptr(size_t idx); + fun_op_ptr_c_t get_ptr(size_t idx) const; + /* --------------------------------------------------------------------- */ + + name_op_v_t& add_name_op_pairs(name_op_v_t& pairs); + name_op_v_c_t& add_name_op_pairs(name_op_v_c_t& pairs) const; + /* --------------------------------------------------------------------- */ + + name_op_v_t gen_name_op_pairs(); + name_op_v_c_t gen_name_op_pairs() const; + /* --------------------------------------------------------------------- */ + + name_op_pair_t gen_name_op_pair(size_t idx); + name_op_pair_c_t gen_name_op_pair(size_t idx) const; + /* --------------------------------------------------------------------- */ + + std::string to_string(const Corpus2::Tagset& tagset) const; + /* --------------------------------------------------------------------- */ + + UntypedOpSequence(const UntypedOpSequence& seq); + /* --------------------------------------------------------------------- */ + + shared_ptr<UntypedOpSequence> clone() const; + /* --------------------------------------------------------------------- */ + + protected: + std::ostream& write_to(std::ostream& ostream) const; + UntypedOpSequence* clone_internal() const; + }; // UntypedOpSequence + + /* ----------------------------------------------------------------------- */ + + %rename(op_t) Wccl::Operator<T>; + %rename(op_ptr_t) boost::shared_ptr<Wccl::Operator<T> >; + %rename(op_ptr_c_t) boost::shared_ptr<const Wccl::Operator<T> >; + + template<class T> class OpSequence : public FunctionalOpSequence { + public: + typedef Operator<T> op_t; + typedef typename shared_ptr<Operator<T> > op_ptr_t; + typedef typename shared_ptr<const Operator<T> > op_ptr_c_t; + typedef typename std::pair<std::string, op_ptr_t> name_op_pair_t; + typedef typename std::pair<std::string, op_ptr_c_t> name_op_pair_c_t; + typedef typename std::vector<name_op_pair_t> name_op_v_t; + typedef typename std::vector<name_op_pair_c_t> name_op_v_c_t; + /* --------------------------------------------------------------------- */ + + OpSequence(const std::string& name); + /* --------------------------------------------------------------------- */ + + bool empty() const; + size_t size() const; + /* --------------------------------------------------------------------- */ + + void append(const op_ptr_t& op); + /* --------------------------------------------------------------------- */ + + op_t& get(size_t idx); + const op_t& get(size_t idx) const; + /* --------------------------------------------------------------------- */ + + op_ptr_t get_ptr(size_t idx); + op_ptr_c_t get_ptr(size_t idx) const; + /* --------------------------------------------------------------------- */ + + FunctionalOpSequence::fun_op_ptr_t get_untyped_ptr(size_t idx); + FunctionalOpSequence::fun_op_ptr_c_t get_untyped_ptr(size_t idx) const; + /* --------------------------------------------------------------------- */ + + name_op_v_t gen_name_op_pairs(); + name_op_v_c_t gen_name_op_pairs() const; + /* --------------------------------------------------------------------- */ + + name_op_v_t& add_name_op_pairs(name_op_v_t& pairs); + name_op_v_c_t& add_name_op_pairs(name_op_v_c_t& pairs) const; + /* --------------------------------------------------------------------- */ + + name_op_pair_t gen_name_op_pair(size_t idx); + name_op_pair_c_t gen_name_op_pair(size_t idx) const; + /* --------------------------------------------------------------------- */ + + std::string to_string(const Corpus2::Tagset& tagset) const; + /* --------------------------------------------------------------------- */ + + OpSequence(const OpSequence<T>& seq); + /* --------------------------------------------------------------------- */ + + shared_ptr<OpSequence<T> > clone() const; + /* --------------------------------------------------------------------- */ + + protected: + std::ostream& write_to(std::ostream& os) const; + virtual OpSequence<T>* clone_internal() const; + }; // OpSequence +} + +using namespace boost; +using namespace Wccl; +using namespace std; + +#endif /* SWIG_LIBWCCL_FUNCTIONALOPSEQUENCE_I */ -- GitLab