From: Arvin Schnell Date: Tue, 25 Sep 2007 12:40:49 +0000 (+0000) Subject: - sometimes include original C header file X-Git-Tag: BASE-SuSE-Code-12_2-Branch~177 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7ca448153a21e34bce24af964c84d59c7efd4dc9;p=platform%2Fupstream%2Flibzypp-bindings.git - sometimes include original C header file - global rename for asString - added examples --- diff --git a/examples/python/bytecount.py b/examples/python/bytecount.py new file mode 100755 index 0000000..912fa05 --- /dev/null +++ b/examples/python/bytecount.py @@ -0,0 +1,10 @@ +#!/usr/bin/python + +from zypp import ByteCount + +print ByteCount(ByteCount.G) +print ByteCount(ByteCount.GB) + +x = ByteCount(ByteCount.K) +print int(x) + diff --git a/examples/python/url.py b/examples/python/url.py new file mode 100755 index 0000000..07c772c --- /dev/null +++ b/examples/python/url.py @@ -0,0 +1,21 @@ +#!/usr/bin/python + +from zypp import Url + +a = Url("http://www.suse.de/download") +print "a = %s" % a +print " %s %s %s" % (a.getScheme(), a.getHost(), a.getPathData()) + +b = Url(a) +b.setHost("download.novell.com") +print "b = %s" % b + +c = a # oops +c.setPathData("/repository") +print "c = %s" % c + +print +print "a = %s" % a # oops +print "b = %s" % b +print "c = %s" % c + diff --git a/examples/ruby/bytecount.rb b/examples/ruby/bytecount.rb new file mode 100755 index 0000000..56393a8 --- /dev/null +++ b/examples/ruby/bytecount.rb @@ -0,0 +1,11 @@ +#!/usr/bin/ruby + +require 'zypp' +include Zypp + +puts ByteCount.new(ByteCount.G) +puts ByteCount.new(ByteCount.GB) + +x = ByteCount.new(ByteCount.K) +puts x.to_i + diff --git a/examples/ruby/url.rb b/examples/ruby/url.rb new file mode 100755 index 0000000..81f3848 --- /dev/null +++ b/examples/ruby/url.rb @@ -0,0 +1,22 @@ +#!/usr/bin/ruby + +require 'zypp' +include Zypp + +a = Url.new("http://www.suse.de/download") +puts "a = #{a}" +puts " #{a.get_scheme} #{a.get_host} #{a.get_path_data}" + +b = Url.new(a) +b.set_host("download.novell.com") +puts "b = #{b}" + +c = a # oops +c.set_path_data("/repository") +puts "c = #{c}" + +puts +puts "a = #{a}" # oops +puts "b = #{b}" +puts "c = #{c}" + diff --git a/swig/Arch.i b/swig/Arch.i index 82c771a..3f314b1 100644 --- a/swig/Arch.i +++ b/swig/Arch.i @@ -3,10 +3,6 @@ typedef std::set > CompatSet; %ignore Arch::compare(const Arch &, const Arch &); -#if defined(SWIGPYTHON) || defined(SWIGRUBY) -%rename Arch::asString "__str__"; -#endif - class Arch { public: diff --git a/swig/ByteCount.i b/swig/ByteCount.i index 4bd2285..03f17c6 100644 --- a/swig/ByteCount.i +++ b/swig/ByteCount.i @@ -1,24 +1,49 @@ + #ifdef SWIGRUBY -%typemap(in) ByteCount { - ByteCount::SizeType bytes = (Date::SizeType) NUM2LONG( rb_funcall( $input, rb_intern("to_i"), 0, 0) ); - $1 = ByteCount(bytes); +namespace zypp +{ + // how to do that? + // %rename "ByteCount::operator SizeType()" to_i; } -%typemap(out) ByteCount { - VALUE rbbytenum = INT2NUM( (ByteCount::SizeType) $1 ); - return rbbytenum; +#endif + + +// TODO: tell make about dependencies +%include + + +#ifdef SWIGRUBY + +namespace zypp +{ + %extend ByteCount + { + long long int to_i() + { + ByteCount::SizeType tmp = *self; + return tmp; + } + } } #endif -#ifdef SWIGPERL5 +#ifdef SWIGPYTHON -%typemap(out) ByteCount { - $result = sv_newmortal(); - sv_setiv($result, (IV) (ByteCount::SizeType) $1 ); - argvi++; +namespace zypp +{ + %extend ByteCount + { + long long int __int__() + { + ByteCount::SizeType tmp = *self; + return tmp; + } + } } #endif + diff --git a/swig/CapFactory.i b/swig/CapFactory.i index 4eaae2b..cb61475 100644 --- a/swig/CapFactory.i +++ b/swig/CapFactory.i @@ -32,7 +32,7 @@ class CapFactory Capability parse( const Resolvable::Kind & refers_r, const std::string & name_r, Rel op_r, - const Edition & edition_r ) const; + const zypp::Edition & edition_r ) const; /** Special Capability, triggering evaluation of Hal * capabilities when matched. diff --git a/swig/Capability.i b/swig/Capability.i index ea45291..5f3984c 100644 --- a/swig/Capability.i +++ b/swig/Capability.i @@ -1,8 +1,4 @@ -#if defined(SWIGPYTHON) || defined(SWIGRUBY) -%rename Capability::asString "__str__"; -#endif - class Capability { public: diff --git a/swig/Date.i b/swig/Date.i index cd63399..a70c180 100644 --- a/swig/Date.i +++ b/swig/Date.i @@ -1,20 +1,4 @@ -#if defined(SWIGPYTHON) || defined(SWIGRUBY) -%rename Date::asString "__str__"; -#endif - -class Date -{ -public: - - Date(); - Date(const std::string & seconds_r); - - static Date now(); - - std::string form(const std::string & format_r) const; - std::string asString() const; - std::string asSeconds() const; - -}; +// TODO: tell make about dependencies +%include diff --git a/swig/Dep.i b/swig/Dep.i index 50f0751..4779b7c 100644 --- a/swig/Dep.i +++ b/swig/Dep.i @@ -1,8 +1,4 @@ -#if defined(SWIGPYTHON) || defined(SWIGRUBY) -%rename Dep::asString "__str__"; -#endif - struct Dep { /** \name Dependency types diff --git a/swig/Edition.i b/swig/Edition.i index 9f0fb2e..2530aff 100644 --- a/swig/Edition.i +++ b/swig/Edition.i @@ -1,37 +1,52 @@ -#if defined(SWIGPYTHON) || defined(SWIGRUBY) -%rename Edition::asString "__str__"; -#endif +// example for including the original header file + +#if 1 + +namespace zypp +{ + %rename Edition::compare(const Edition& lhs, const Edition& rhs) compare2; + %rename Edition::match(const Edition& lhs, const Edition& rhs) match2; +} -class Edition +// TODO: tell make about dependencies +%include + +#else + +namespace zypp { - public: - typedef unsigned epoch_t; - static const epoch_t noepoch = 0; - static const Edition noedition; - public: - Edition(); - - Edition( const std::string & edition_r ); - Edition( const std::string & version_r, - const std::string & release_r, - epoch_t epoch_r = noepoch ); - Edition( const std::string & version_r, - const std::string & release_r, - const std::string & epoch_r ); - ~Edition(); - public: - epoch_t epoch() const; - const std::string & version() const; - const std::string & release() const; - std::string asString() const; - public: - static int compare( const Edition & lhs, const Edition & rhs ); - int compare( const Edition & rhs ) const; - typedef Compare Compare; - typedef Range CompareRange; - public: - static int match( const Edition & lhs, const Edition & rhs ); - int match( const Edition & rhs ) const; -}; + class Edition + { + public: + typedef unsigned epoch_t; + static const epoch_t noepoch = 0; + static const Edition noedition; + public: + Edition(); + Edition( const std::string & edition_r ); + Edition( const std::string & version_r, + const std::string & release_r, + epoch_t epoch_r = noepoch ); + Edition( const std::string & version_r, + const std::string & release_r, + const std::string & epoch_r ); + ~Edition(); + public: + epoch_t epoch() const; + const std::string & version() const; + const std::string & release() const; + std::string asString() const; + public: + static int compare( const Edition & lhs, const Edition & rhs ); + int compare( const Edition & rhs ) const; + typedef Compare Compare; + typedef Range CompareRange; + public: + static int match( const Edition & lhs, const Edition & rhs ); + int match( const Edition & rhs ) const; + }; +} + +#endif diff --git a/swig/NVR.i b/swig/NVR.i index aa7bc36..19a515d 100644 --- a/swig/NVR.i +++ b/swig/NVR.i @@ -7,7 +7,7 @@ /** Ctor */ explicit NVR( const std::string & name_r, - const Edition & edition_r = Edition() ) + const zypp::Edition & edition_r = zypp::Edition() ) : name( name_r ) , edition( edition_r ) {} @@ -19,7 +19,7 @@ /** */ std::string name; /** */ - Edition edition; + zypp::Edition edition; public: /** Comparison mostly for std::container */ @@ -30,4 +30,4 @@ return res; return lhs.edition.compare( rhs.edition ); } - }; \ No newline at end of file + }; diff --git a/swig/NVRA.i b/swig/NVRA.i index 3678a88..f62d529 100644 --- a/swig/NVRA.i +++ b/swig/NVRA.i @@ -7,7 +7,7 @@ struct NVRA : public NVR /** Ctor */ explicit NVRA( const std::string & name_r, - const Edition & edition_r = Edition(), + const zypp::Edition & edition_r = Edition(), const Arch & arch_r = Arch() ) : NVR( name_r, edition_r ) , arch( arch_r ) @@ -37,4 +37,4 @@ struct NVRA : public NVR return res; return lhs.arch.compare( rhs.arch ); } - }; \ No newline at end of file + }; diff --git a/swig/NVRAD.i b/swig/NVRAD.i index 8fa5660..eae9a06 100644 --- a/swig/NVRAD.i +++ b/swig/NVRAD.i @@ -8,7 +8,7 @@ struct NVRAD : public NVRA, public Dependencies /** Ctor */ explicit NVRAD( const std::string & name_r, - const Edition & edition_r = Edition(), + const zypp::Edition & edition_r = zypp::Edition(), const Arch & arch_r = Arch(), const Dependencies & deps_r = Dependencies() ) : NVRA( name_r, edition_r, arch_r ) @@ -35,4 +35,4 @@ struct NVRAD : public NVRA, public Dependencies /** Ctor */ explicit NVRAD( Resolvable::constPtr res_r ); - }; \ No newline at end of file + }; diff --git a/swig/Package.i b/swig/Package.i index 9bde80e..433977d 100644 --- a/swig/Package.i +++ b/swig/Package.i @@ -37,7 +37,7 @@ class Package : public ResObject /** */ Text postun() const; /** */ - ByteCount sourcesize() const; + zypp::ByteCount sourcesize() const; /** */ std::list authors() const; /** */ diff --git a/swig/Pathname.i b/swig/Pathname.i index db00757..67bd58c 100644 --- a/swig/Pathname.i +++ b/swig/Pathname.i @@ -1,8 +1,4 @@ -#if defined(SWIGPYTHON) || defined(SWIGRUBY) -%rename Pathname::asString "__str__"; -#endif - class Pathname { public: diff --git a/swig/PublicKey.i b/swig/PublicKey.i index b42c013..a219661 100644 --- a/swig/PublicKey.i +++ b/swig/PublicKey.i @@ -1,8 +1,4 @@ -#if defined(SWIGPYTHON) || defined(SWIGRUBY) -%rename PublicKey::asString "__str__"; -#endif - class PublicKey { diff --git a/swig/RepoInfo.i b/swig/RepoInfo.i index afbd32a..7456431 100644 --- a/swig/RepoInfo.i +++ b/swig/RepoInfo.i @@ -1,6 +1,6 @@ #ifdef SWIGPERL5 #else - %template(UrlSet) std::set; + %template(UrlSet) std::set; #endif class RepoInfo @@ -79,13 +79,13 @@ public: * * To edit or remove urls, create a new RepoInfo instead. */ - RepoInfo & addBaseUrl( const Url &url ); + RepoInfo & addBaseUrl( const zypp::Url &url ); /** * Set mirror list url. \see mirrorListUrl * \param url The base url for the list */ - RepoInfo & setMirrorListUrl( const Url &url ); + RepoInfo & setMirrorListUrl( const zypp::Url &url ); /** * enable or disable the repository \see enabled diff --git a/swig/RepoType.i b/swig/RepoType.i index 1152d25..c1bab9a 100644 --- a/swig/RepoType.i +++ b/swig/RepoType.i @@ -1,8 +1,4 @@ -#if defined(SWIGPYTHON) || defined(SWIGRUBY) -%rename RepoType::asString "__str__"; -#endif - struct RepoType { static const RepoType RPMMD; diff --git a/swig/ResObject.i b/swig/ResObject.i index 06fb2e1..90d8a97 100644 --- a/swig/ResObject.i +++ b/swig/ResObject.i @@ -17,8 +17,8 @@ class ResObject : public Resolvable Text delnotify() const; Text licenseToConfirm() const; Vendor vendor() const; - ByteCount size() const; - ByteCount downloadSize() const; + zypp::ByteCount size() const; + zypp::ByteCount downloadSize() const; Repository repository() const; unsigned mediaNr() const; bool installOnly() const; diff --git a/swig/Resolvable.i b/swig/Resolvable.i index 817b64d..1a63349 100644 --- a/swig/Resolvable.i +++ b/swig/Resolvable.i @@ -10,7 +10,7 @@ class Resolvable const Kind & kind() const; const std::string & name() const; - const Edition & edition() const; + const zypp::Edition & edition() const; const Arch & arch() const; const CapSet & dep( Dep which_r ) const; diff --git a/swig/Url.i b/swig/Url.i index c088733..2885915 100644 --- a/swig/Url.i +++ b/swig/Url.i @@ -1,20 +1,30 @@ -#if defined(SWIGPYTHON) || defined(SWIGRUBY) -%rename Url::asString "__str__"; -#endif +// example for including the original header file + +#if 1 + +// TODO: tell make about dependencies +%include -class Url +#else + +namespace zypp { -public: + class Url + { + public: - Url(); - ~Url(); + Url(); + ~Url(); - Url(const std::string& encodedUrl); + Url(const Url &url); + Url(const std::string &encodedUrl); - bool isValid() const; + bool isValid() const; - std::string asString() const; + std::string asString() const; -}; + }; +} +#endif diff --git a/swig/python/python.i b/swig/python/python.i index f7826ec..98e40dc 100644 --- a/swig/python/python.i +++ b/swig/python/python.i @@ -1,4 +1,15 @@ + +%rename *::asString "__str__"; + + +namespace zypp +{ + // Just to avoid warnings. + %ignore operator<<; +} + + %define iter( cls ) %extend cls { %pythoncode %{ diff --git a/swig/ruby/ruby.i b/swig/ruby/ruby.i index a54445e..36b1ec1 100644 --- a/swig/ruby/ruby.i +++ b/swig/ruby/ruby.i @@ -1,5 +1,21 @@ +%rename *::asString "__str__"; + + +namespace zypp +{ + // Not ignoring gives a very strange error in the "pokus" testsuite: SWIG + // defines a Ruby module-function "==" which (when included into the main + // namespace) is apparently used where is should not. + %ignore operator==; + + // Just to avoid warnings. + %ignore operator!=; + %ignore operator<<; +} + + /* * Extend cls with an ruby-like each iterator and a to_a method. Yields * objects of type storetype. Parameter storetype must be a pointer type.