[Lemon-commits] Balazs Dezso: Use void* like LPX object (#337)

Lemon HG hg at lemon.cs.elte.hu
Mon Feb 15 09:00:50 CET 2010


details:   http://lemon.cs.elte.hu/hg/lemon/rev/5100072d83ca
changeset: 900:5100072d83ca
user:      Balazs Dezso <deba [at] inf.elte.hu>
date:      Sun Feb 14 23:10:24 2010 +0100
description:
	Use void* like LPX object (#337)

diffstat:

 lemon/glpk.h |  35 +++++++++++++++++++++++------------
 1 files changed, 23 insertions(+), 12 deletions(-)

diffs (62 lines):

diff --git a/lemon/glpk.h b/lemon/glpk.h
--- a/lemon/glpk.h
+++ b/lemon/glpk.h
@@ -25,16 +25,28 @@
 
 #include <lemon/lp_base.h>
 
-// forward declaration
-#if !defined _GLP_PROB && !defined GLP_PROB
-#define _GLP_PROB
-#define GLP_PROB
-typedef struct { double _opaque_prob; } glp_prob;
-/* LP/MIP problem object */
-#endif
-
 namespace lemon {
 
+  namespace _solver_bits {
+    class VoidPtr {
+    private:
+      void *_ptr;      
+    public:
+      VoidPtr() : _ptr(0) {}
+
+      template <typename T>
+      VoidPtr(T* ptr) : _ptr(reinterpret_cast<void*>(ptr)) {}
+
+      template <typename T>
+      VoidPtr& operator=(T* ptr) { 
+        _ptr = reinterpret_cast<void*>(ptr); 
+        return *this;
+      }
+
+      template <typename T>
+      operator T*() const { return reinterpret_cast<T*>(_ptr); }
+    };
+  }
 
   /// \brief Base interface for the GLPK LP and MIP solver
   ///
@@ -43,8 +55,7 @@
   class GlpkBase : virtual public LpBase {
   protected:
 
-    typedef glp_prob LPX;
-    glp_prob* lp;
+    _solver_bits::VoidPtr lp;
 
     GlpkBase();
     GlpkBase(const GlpkBase&);
@@ -122,9 +133,9 @@
   public:
 
     ///Pointer to the underlying GLPK data structure.
-    LPX *lpx() {return lp;}
+    _solver_bits::VoidPtr lpx() {return lp;}
     ///Const pointer to the underlying GLPK data structure.
-    const LPX *lpx() const {return lp;}
+    _solver_bits::VoidPtr lpx() const {return lp;}
 
     ///Returns the constraint identifier understood by GLPK.
     int lpxRow(Row r) const { return rows(id(r)); }



More information about the Lemon-commits mailing list