Bonmin  1.8.8
BonTypes.hpp
Go to the documentation of this file.
1 #ifndef __BonTypes_H_
2 #define __BonTypes_H_
3 #include<vector>
4 #include "CoinSmartPtr.hpp"
5 
6 namespace Bonmin {
8 template<typename T>
9 class vector : public std::vector<T>{
10 public:
12  vector(): std::vector<T>(){}
14  vector(size_t n, const T& v): std::vector<T>(n,v){}
16  vector(const vector<T>& other): std::vector<T>(other){}
18  vector(const std::vector<T>& other): std::vector<T>(other){}
20  vector(size_t n): std::vector<T>(n){}
22  vector<T>& operator=(const vector<T>& other){
23  std::vector<T>::operator=(other);
24  return (*this);}
26  vector<T>& operator=(const std::vector<T>& other){
27  return std::vector<T>::operator=(other);
28  return (*this);}
29 
31 inline T* operator()(){
32 #if defined(_MSC_VER)
33  if (std::vector<T>::size() == 0)
34  return NULL;
35 #endif
36 return &std::vector<T>::front();}
38 inline const T* operator()() const {
39 #if defined(_MSC_VER)
40  if (std::vector<T>::size() == 0)
41  return NULL;
42 #endif
43 return &std::vector<T>::front();
44 }
45 };
46 
47 //structure to store an object of class X in a Coin::ReferencedObject
48 template<class X>
49 struct SimpleReferenced : public Coin::ReferencedObject {
51  X object;
52 
53  const X& operator()() const{
54  return object;}
55 
56  X& operator()() {
57  return object;}
58 
59 };
60 //structure to store a pointer to an object of class X in a
61 // Coin::ReferencedObject
62 template<class X>
63 struct SimpleReferencedPtr : public Coin::ReferencedObject {
65  X * object;
66 
68  object(NULL){}
69 
71  delete object;}
72 
73  const X& operator()() const{
74  return *object;}
75 
76  X& operator()() {
77  return *object;}
78 
79  const X* ptr() const{
80  return object;}
81 
82  X* ptr(){
83  return object;}
84 };
85 
86 template <class X>
89  ret_val->object = other;
90  return ret_val;
91 }
92 template <class X>
95  ret_val->object = other;
96  return ret_val;
97 }
98 
99 
100 }
101 #endif
102 
vector(size_t n, const T &v)
Constructor with initialization.
Definition: BonTypes.hpp:14
vector()
Default constructor.
Definition: BonTypes.hpp:12
T * operator()()
Access pointer to first element of storage.
Definition: BonTypes.hpp:31
vector(size_t n)
constructor with size.
Definition: BonTypes.hpp:20
const T * operator()() const
Access pointer to first element of storage.
Definition: BonTypes.hpp:38
A small wrap around std::vector to give easy access to array for interfacing with fortran code...
Definition: BonTypes.hpp:9
X * object
The object.
Definition: BonTypes.hpp:65
const X * ptr() const
Definition: BonTypes.hpp:79
vector< T > & operator=(const vector< T > &other)
Assignment.
Definition: BonTypes.hpp:22
SimpleReferenced< X > * make_referenced(X other)
Definition: BonTypes.hpp:87
vector< T > & operator=(const std::vector< T > &other)
Assignment.
Definition: BonTypes.hpp:26
vector(const std::vector< T > &other)
Copy constructor.
Definition: BonTypes.hpp:18
const X & operator()() const
Definition: BonTypes.hpp:73
const X & operator()() const
Definition: BonTypes.hpp:53
X object
The object.
Definition: BonTypes.hpp:51
vector(const vector< T > &other)
Copy constructor.
Definition: BonTypes.hpp:16