Bonmin
1.7
|
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(size_t n, const T& v): std::vector<T>(n,v){} 00016 vector(const vector<T>& other): std::vector<T>(other){} 00018 vector(const std::vector<T>& other): std::vector<T>(other){} 00020 vector(size_t n): std::vector<T>(n){} 00022 vector<T>& operator=(const vector<T>& other){ 00023 std::vector<T>::operator=(other); 00024 return (*this);} 00026 vector<T>& operator=(const std::vector<T>& other){ 00027 return std::vector<T>::operator=(other); 00028 return (*this);} 00029 00031 inline T* operator()(){ 00032 #if defined(_MSC_VER) 00033 if (std::vector<T>::size() == 0) 00034 return NULL; 00035 #endif 00036 return &std::vector<T>::front();} 00038 inline const T* operator()() const { 00039 #if defined(_MSC_VER) 00040 if (std::vector<T>::size() == 0) 00041 return NULL; 00042 #endif 00043 return &std::vector<T>::front(); 00044 } 00045 }; 00046 00047 //structure to store an object of class X in a Coin::ReferencedObject 00048 template<class X> 00049 struct SimpleReferenced : public Coin::ReferencedObject { 00051 X object; 00052 00053 const X& operator()() const{ 00054 return object;} 00055 00056 X& operator()() { 00057 return object;} 00058 00059 }; 00060 //structure to store a pointer to an object of class X in a 00061 // Coin::ReferencedObject 00062 template<class X> 00063 struct SimpleReferencedPtr : public Coin::ReferencedObject { 00065 X * object; 00066 00067 SimpleReferencedPtr(): 00068 object(NULL){} 00069 00070 ~SimpleReferencedPtr(){ 00071 delete object;} 00072 00073 const X& operator()() const{ 00074 return *object;} 00075 00076 X& operator()() { 00077 return *object;} 00078 00079 const X* ptr() const{ 00080 return object;} 00081 00082 X* ptr(){ 00083 return object;} 00084 }; 00085 00086 template <class X> 00087 SimpleReferenced<X> * make_referenced(X other){ 00088 SimpleReferenced<X> * ret_val = new SimpleReferenced<X>; 00089 ret_val->object = other; 00090 return ret_val; 00091 } 00092 template <class X> 00093 SimpleReferencedPtr<X> * make_referenced(X* other){ 00094 SimpleReferencedPtr <X> * ret_val = new SimpleReferencedPtr<X>; 00095 ret_val->object = other; 00096 return ret_val; 00097 } 00098 00099 00100 } 00101 #endif 00102