OpenGM  2.3.x
Discrete Graphical Model Library
vector_view_space.hxx
Go to the documentation of this file.
1 #pragma once
2 #ifndef OPENGM_VECTOR_VIEW_SPACE_HXX
3 #define OPENGM_VECTOR_VIEW_SPACE_HXX
4 
6 
7 #include <vector>
8 #include <limits>
9 
10 #include "opengm/opengm.hxx"
12 
13 namespace opengm {
14 
18 template<class I = std::size_t, class L = std::size_t>
19 class VectorViewSpace
20 : public SpaceBase<VectorViewSpace<I,L>,I,L>
21 {
22 public:
23  typedef I IndexType;
24  typedef L LabelType;
25 
26  VectorViewSpace();
27  VectorViewSpace(const std::vector<LabelType>&);
28  IndexType addVariable(const LabelType);
29  IndexType numberOfVariables() const;
30  LabelType numberOfLabels(const IndexType) const;
31 
32 private:
33  std::vector<LabelType> const* numbersOfLabels_;
34 };
35 
36 template<class I, class L>
37 inline
38 VectorViewSpace<I, L>::VectorViewSpace()
39 : numbersOfLabels_(NULL)
40 {}
41 
42 template<class I, class L>
43 inline
44 VectorViewSpace<I, L>::VectorViewSpace
45 (
46  const std::vector<LabelType>& spaceVector
47 )
48 : numbersOfLabels_(&spaceVector)
49 {
50  OPENGM_ASSERT(numbersOfLabels_->size()>0);
51 }
52 
53 template<class I, class L>
54 inline typename VectorViewSpace<I, L>::IndexType
55 VectorViewSpace<I, L>::addVariable(
56  const LabelType numberOfLabels
57 ) {
58  throw opengm::RuntimeError("attempt to add a variable to VectorViewSpace");
59 }
60 
61 template<class I, class L>
62 inline typename VectorViewSpace<I, L>::IndexType
63 VectorViewSpace<I, L>::numberOfVariables() const
64 {
65  return static_cast<IndexType>(numbersOfLabels_->size());
66 }
67 
68 template<class I, class L>
69 inline typename VectorViewSpace<I, L>::LabelType
70 VectorViewSpace<I, L>::numberOfLabels(
71  const IndexType dimension
72 ) const
73 {
74  OPENGM_ASSERT(dimension<numbersOfLabels_->size());
75  return numbersOfLabels_->operator[](dimension);
76 }
77 
78 } // namespace opengm
79 
81 
82 #endif // #ifndef OPENGM_VECTOR_VIEW_SPACE_HXX
The OpenGM namespace.
Definition: config.hxx:43
#define OPENGM_ASSERT(expression)
Definition: opengm.hxx:77
OpenGM runtime error.
Definition: opengm.hxx:100