00001 #ifndef __BonTypes_H_ 00002 #define __BonTypes_H_ 00003 #include<vector> 00004 #include "CoinSmartPtr.hpp" 00005 00006 namespace Bonmin { 00008 template<typename T> 00009 class vector : public std::vector<T>{ 00010 public: 00012 vector(): std::vector<T>(){} 00014 vector(const vector<T>& other): std::vector<T>(other){} 00016 vector(const std::vector<T>& other): std::vector<T>(other){} 00018 vector(unsigned int n): std::vector<T>(n){} 00020 vector<T>& operator=(const vector<T>& other){ 00021 std::vector<T>::operator=(other); 00022 return (*this);} 00024 vector<T>& operator=(const std::vector<T>& other){ 00025 return std::vector<T>::operator=(other); 00026 return (*this);} 00027 00029 inline T* operator()(){ 00030 #if defined(_MSC_VER) 00031 if(std::vector<T>::size() == 0) 00032 return NULL; 00033 #endif 00034 return &std::vector<T>::front();} 00036 inline const T* operator()() const { 00037 #if defined(_MSC_VER) 00038 if(std::vector<T>::size() == 0) 00039 return NULL; 00040 #endif 00041 return &std::vector<T>::front();} 00042 }; 00043 00044 //structure to store an object of class X in a Coin::ReferencedObject 00045 template<class X> 00046 struct SimpleReferenced : public Coin::ReferencedObject { 00048 X object; 00049 00050 const X& operator()() const{ 00051 return object;} 00052 00053 X& operator()() { 00054 return object;} 00055 00056 }; 00057 //structure to store a pointer to an object of class X in a 00058 // Coin::ReferencedObject 00059 template<class X> 00060 struct SimpleReferencedPtr : public Coin::ReferencedObject { 00062 X * object; 00063 00064 SimpleReferencedPtr(): 00065 object(NULL){} 00066 00067 ~SimpleReferencedPtr(){ 00068 delete object;} 00069 00070 const X& operator()() const{ 00071 return *object;} 00072 00073 X& operator()() { 00074 return *object;} 00075 00076 const X* ptr() const{ 00077 return object;} 00078 00079 X* ptr(){ 00080 return object;} 00081 }; 00082 00083 template <class X> 00084 SimpleReferenced<X> * make_referenced(X other){ 00085 SimpleReferenced<X> * ret_val = new SimpleReferenced<X>; 00086 ret_val->object = other; 00087 return ret_val; 00088 } 00089 template <class X> 00090 SimpleReferencedPtr<X> * make_referenced(X* other){ 00091 SimpleReferencedPtr <X> * ret_val = new SimpleReferencedPtr<X>; 00092 ret_val->object = other; 00093 return ret_val; 00094 } 00095 00096 00097 } 00098 #endif 00099