Debian Codegraph @

Bonmin/src/Interfaces/BonTypes.hpp

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