- sometimes include original C header file
authorArvin Schnell <aschnell@suse.de>
Tue, 25 Sep 2007 12:40:49 +0000 (12:40 +0000)
committerArvin Schnell <aschnell@suse.de>
Tue, 25 Sep 2007 12:40:49 +0000 (12:40 +0000)
- global rename for asString
- added examples

24 files changed:
examples/python/bytecount.py [new file with mode: 0755]
examples/python/url.py [new file with mode: 0755]
examples/ruby/bytecount.rb [new file with mode: 0755]
examples/ruby/url.rb [new file with mode: 0755]
swig/Arch.i
swig/ByteCount.i
swig/CapFactory.i
swig/Capability.i
swig/Date.i
swig/Dep.i
swig/Edition.i
swig/NVR.i
swig/NVRA.i
swig/NVRAD.i
swig/Package.i
swig/Pathname.i
swig/PublicKey.i
swig/RepoInfo.i
swig/RepoType.i
swig/ResObject.i
swig/Resolvable.i
swig/Url.i
swig/python/python.i
swig/ruby/ruby.i

diff --git a/examples/python/bytecount.py b/examples/python/bytecount.py
new file mode 100755 (executable)
index 0000000..912fa05
--- /dev/null
@@ -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 (executable)
index 0000000..07c772c
--- /dev/null
@@ -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 (executable)
index 0000000..56393a8
--- /dev/null
@@ -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 (executable)
index 0000000..81f3848
--- /dev/null
@@ -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}"
+
index 82c771a..3f314b1 100644 (file)
@@ -3,10 +3,6 @@ typedef std::set<Arch,CompareByGT<Arch> > CompatSet;
 
 %ignore Arch::compare(const Arch &, const Arch &);
 
-#if defined(SWIGPYTHON) || defined(SWIGRUBY)
-%rename Arch::asString "__str__";
-#endif
-
 class Arch
 {
 public:
index 4bd2285..03f17c6 100644 (file)
@@ -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 <zypp/ByteCount.h>
+
+
+#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
+
index 4eaae2b..cb61475 100644 (file)
@@ -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.
index ea45291..5f3984c 100644 (file)
@@ -1,8 +1,4 @@
 
-#if defined(SWIGPYTHON) || defined(SWIGRUBY)
-%rename Capability::asString "__str__";
-#endif
-
 class Capability
 {
   public:
index cd63399..a70c180 100644 (file)
@@ -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 <zypp/Date.h>
 
index 50f0751..4779b7c 100644 (file)
@@ -1,8 +1,4 @@
 
-#if defined(SWIGPYTHON) || defined(SWIGRUBY)
-%rename Dep::asString "__str__";
-#endif
-
 struct Dep
 {
     /** \name Dependency types
index 9f0fb2e..2530aff 100644 (file)
@@ -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 <zypp/Edition.h>
+
+#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<Edition> Compare;
-    typedef Range<Edition> 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<Edition> Compare;
+       typedef Range<Edition> CompareRange;
+    public:
+       static int match( const Edition & lhs, const Edition & rhs );
+       int match( const Edition & rhs ) const;
+    };
 
+}
+
+#endif
index aa7bc36..19a515d 100644 (file)
@@ -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
+  };
index 3678a88..f62d529 100644 (file)
@@ -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
+  };
index 8fa5660..eae9a06 100644 (file)
@@ -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
+  };
index 9bde80e..433977d 100644 (file)
@@ -37,7 +37,7 @@ class Package : public ResObject
     /** */
     Text postun() const;
     /** */
-    ByteCount sourcesize() const;
+    zypp::ByteCount sourcesize() const;
     /** */
     std::list<std::string> authors() const;
     /** */
index db00757..67bd58c 100644 (file)
@@ -1,8 +1,4 @@
 
-#if defined(SWIGPYTHON) || defined(SWIGRUBY)
-%rename Pathname::asString "__str__";
-#endif
-
 class Pathname
 {
 public:
index b42c013..a219661 100644 (file)
@@ -1,8 +1,4 @@
 
-#if defined(SWIGPYTHON) || defined(SWIGRUBY)
-%rename PublicKey::asString "__str__";
-#endif
-
 class PublicKey
 {
 
index afbd32a..7456431 100644 (file)
@@ -1,6 +1,6 @@
 #ifdef SWIGPERL5
 #else
-   %template(UrlSet) std::set<Url>;
+    %template(UrlSet) std::set<Url>;
 #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
index 1152d25..c1bab9a 100644 (file)
@@ -1,8 +1,4 @@
 
-#if defined(SWIGPYTHON) || defined(SWIGRUBY)
-%rename RepoType::asString "__str__";
-#endif
-
 struct RepoType
 {
     static const RepoType RPMMD;
index 06fb2e1..90d8a97 100644 (file)
@@ -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;
index 817b64d..1a63349 100644 (file)
@@ -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;
index c088733..2885915 100644 (file)
@@ -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 <zypp/Url.h>
 
-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
index f7826ec..98e40dc 100644 (file)
@@ -1,4 +1,15 @@
 
+
+%rename *::asString "__str__";
+
+
+namespace zypp
+{
+    // Just to avoid warnings.
+    %ignore operator<<;
+}
+
+
 %define iter( cls )
 %extend cls {
     %pythoncode %{
index a54445e..36b1ec1 100644 (file)
@@ -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.