OpenGM  2.3.x
Discrete Graphical Model Library
static_simplediscretespace.hxx
Go to the documentation of this file.
1 #pragma once
2 #ifndef OPENGM_STATIC_SIMPLE_DISCRETE_SPACE_HXX
3 #define OPENGM_STATIC_SIMPLE_DISCRETE_SPACE_HXX
4 
5 #include "opengm/opengm.hxx"
7 
8 namespace opengm {
9 
13 template<size_t LABELS, class I = std::size_t , class L = std::size_t>
15 : public SpaceBase<StaticSimpleDiscreteSpace<LABELS, I, L>, I, L>
16 {
17 public:
18  typedef I IndexType;
19  typedef L LabelType;
20 
22  StaticSimpleDiscreteSpace(const IndexType);
23  void assign(const IndexType);
24  template<class Iterator> void assignDense(Iterator, Iterator);
25  IndexType addVariable(const LabelType );
26  IndexType numberOfVariables() const;
27  LabelType numberOfLabels(const IndexType) const;
28  bool isSimpleSpace()const;
29 
30 private:
31  IndexType numberOfVariables_;
32 };
33 
34 template<size_t LABELS,class I, class L>
35 inline
37 : numberOfVariables_()
38 {}
39 
40 template<size_t LABELS,class I, class L>
41 inline
43  const IndexType numberOfVariables
44 )
45 : numberOfVariables_(numberOfVariables)
46 {}
47 
48 template<size_t LABELS,class I, class L>
49 template<class Iterator>
50 inline void
52  Iterator begin,
53  Iterator end
54 ) {
55  numberOfVariables_=std::distance(begin, end);
56  numberOfVariables_=static_cast<L>(*begin);
57  while(begin!=end) {
58  if(LABELS!=static_cast<size_t>(*begin)) {
59  throw opengm::RuntimeError("*begin==LABELS_ is violated \
60  in StaticSimpleDiscreteSpace::assignDense ");
61  }
62  ++begin;
63  }
64 }
65 
66 template<size_t LABELS,class I, class L>
67 inline void
69  const IndexType numberOfVariables
70 ) {
71  numberOfVariables_ = numberOfVariables;
72 }
73 
74 template<size_t LABELS,class I, class L>
75 inline I
77  const L numberOfLabels
78 ) {
79  if(numberOfLabels!=static_cast<L> (LABELS)) {
80  throw opengm::RuntimeError("numberOfLabels==LABELS is violated \
81  in StaticSimpleDiscreteSpace::addVariable ");
82  }
83 }
84 
85 template<size_t LABELS,class I, class L>
88  return numberOfVariables_;
89 }
90 
91 template<size_t LABELS,class I, class L>
94  const IndexType dimension
95 ) const {
96  return static_cast<L> LABELS;
97 }
98 
99 template<size_t LABELS,class I, class L>
100 inline bool
102 {
103  return true;
104 }
105 
106 } // namespace opengm
107 
108 #endif // #ifndef OPENGM_STATIC_SIMPLE_DISCRETE_SPACE_HXX
The OpenGM namespace.
Definition: config.hxx:43
Discrete space in which all variables have the same number of labels.
LabelType numberOfLabels(const IndexType) const
Interface of label spaces.
Definition: space_base.hxx:15
OpenGM runtime error.
Definition: opengm.hxx:100