OpenGM  2.3.x
Discrete Graphical Model Library
space_base.hxx
Go to the documentation of this file.
1 #pragma once
2 #ifndef OPENGM_SPACE_BASE_HXX
3 #define OPENGM_SPACE_BASE_HXX
4 
5 #include <vector>
6 #include <limits>
7 #include <typeinfo>
8 
9 #include "opengm/opengm.hxx"
10 
11 namespace opengm {
12 
14 template<class SPACE, class I = std::size_t, class L = std::size_t>
15 class SpaceBase {
16 public:
17  typedef I IndexType;
18  typedef L LabelType;
19 
20  IndexType numberOfVariables() const; // must be implemented in Space
21  LabelType numberOfLabels(const IndexType) const; // must be implemented in Space
22  template<class Iterator> void assignDense(Iterator, Iterator);
23  IndexType addVariable(const LabelType);
24  bool isSimpleSpace() const;
25 };
26 
27 template<class SPACE, class I, class L>
28 inline bool
30  const IndexType numVar = static_cast<SPACE const*>(this)->numberOfVariables();
31  const IndexType l = static_cast<SPACE const*>(this)->numberOfLabels(0);
32  for(size_t i=1;i<numVar;++i) {
33  if(l!=static_cast<SPACE const *>(this)->numberOfLabels(i)) {
34  return false;
35  }
36  }
37  return true;
38 }
39 
40 template<class SPACE, class I, class L>
41 template<class Iterator>
42 inline void
44 (
45  Iterator begin,
46  Iterator end
47 ) {
48  throw RuntimeError(std::string("assignDense(begin, end) is not implemented in ")+typeid(SPACE).name());
49 }
50 
51 template<class SPACE, class I, class L>
54 (
55  const LabelType numberOfLabels
56 ) {
57  throw RuntimeError(std::string("addVariable(numberOfLabels) is not implemented in ")+typeid(SPACE).name());
58  return IndexType();
59 }
60 
61 } // namespace opengm
62 
63 #endif // #ifndef OPENGM_SPACE_BASE_HXX
The OpenGM namespace.
Definition: config.hxx:43
LabelType numberOfLabels(const IndexType) const
IndexType addVariable(const LabelType)
Definition: space_base.hxx:54
IndexType numberOfVariables() const
void assignDense(Iterator, Iterator)
Definition: space_base.hxx:44
Interface of label spaces.
Definition: space_base.hxx:15
bool isSimpleSpace() const
Definition: space_base.hxx:29
OpenGM runtime error.
Definition: opengm.hxx:100