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