diff --git a/lemon/glpk.h b/lemon/glpk.h --- a/lemon/glpk.h +++ b/lemon/glpk.h @@ -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)); }