OpenGM  2.3.x
Discrete Graphical Model Library
vector_view.hxx
Go to the documentation of this file.
1 #ifndef OPENGM_VECTOR_VIEW
2 #define OPENGM_VECTOR_VIEW
3 
4 namespace opengm{
5 
6 template<class VECTOR,class INDEX_TYPE>
7 class VectorView{
8 
9 public:
10 
11 
12 
13  typedef VECTOR VectorType;
14  typedef INDEX_TYPE IndexType;
15  typedef typename VectorType::value_type ValueType;
16 
17  typedef typename VectorType::const_iterator const_iterator;
18  typedef typename VectorType::iterator iterator;
19 
21 
22 
24  const VectorType & vector
25  ) : vectorPtr_(&vector),
26  start_(0),
27  size_(0){
28 
29  }
30 
31 
33  const VectorType & vector,
34  const IndexType start,
35  const IndexType size
36  ) : vectorPtr_(&vector),
37  start_(start),
38  size_(size){
39 
40  }
41 
42  void assign(
43  const VectorType & vector,
44  const IndexType start,
45  const IndexType size
46  ){
47  vectorPtr_=&vector;
48  start_=start;
49  size_=size;
50  }
51 
52 
53  void assignPtr(
54  const VectorType & vector
55  ){
56  vectorPtr_=&vector;
57  }
58 
59 
60  iterator begin(){
61  return vectorPtr_->begin()+start_;
62  }
63  iterator end(){
64  return vectorPtr_->begin()+start_+size_;
65  }
66 
67  const_iterator begin()const{
68  return vectorPtr_->begin()+start_;
69  }
70  const_iterator end()const{
71  return vectorPtr_->begin()+start_+size_;
72  }
73 
74 
75  const IndexType size()const{
76  return size_;
77  }
78  const ValueType & operator[](const IndexType i)const{
79  return (*vectorPtr_)[start_+i];
80  }
81  ValueType & operator[](const IndexType i){
82  return (*vectorPtr_)[start_+i];
83  }
84 
85 
86 private:
87  const VectorType * vectorPtr_;
88  IndexType start_;
89  IndexType size_;
90 
91 };
92 
93 }
94 
95 
96 #endif
The OpenGM namespace.
Definition: config.hxx:43
VectorType::value_type ValueType
Definition: vector_view.hxx:15
const_iterator begin() const
Definition: vector_view.hxx:67
const ValueType & operator[](const IndexType i) const
Definition: vector_view.hxx:78
void assignPtr(const VectorType &vector)
Definition: vector_view.hxx:53
VectorType::const_iterator const_iterator
Definition: vector_view.hxx:17
const_iterator end() const
Definition: vector_view.hxx:70
INDEX_TYPE IndexType
Definition: vector_view.hxx:14
VectorType::iterator iterator
Definition: vector_view.hxx:18
ValueType & operator[](const IndexType i)
Definition: vector_view.hxx:81
const IndexType size() const
Definition: vector_view.hxx:75
void assign(const VectorType &vector, const IndexType start, const IndexType size)
Definition: vector_view.hxx:42
VectorView(const VectorType &vector, const IndexType start, const IndexType size)
Definition: vector_view.hxx:32
VectorView(const VectorType &vector)
Definition: vector_view.hxx:23