# HG changeset patch # User Balazs Dezso # Date 1266185424 -3600 # Node ID 5100072d83caa82eaf0be1a84a27e5d1917f2efd # Parent 994c7df296c94a4705d55e67858911b2e6991e86 Use void* like LPX object (#337) diff -r 994c7df296c9 -r 5100072d83ca lemon/glpk.h --- a/lemon/glpk.h Thu Dec 10 17:05:35 2009 +0100 +++ b/lemon/glpk.h Sun Feb 14 23:10:24 2010 +0100 @@ -25,16 +25,28 @@ #include -// 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 + VoidPtr(T* ptr) : _ptr(reinterpret_cast(ptr)) {} + + template + VoidPtr& operator=(T* ptr) { + _ptr = reinterpret_cast(ptr); + return *this; + } + + template + operator T*() const { return reinterpret_cast(_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)); }