OpenGM  2.3.x
Discrete Graphical Model Library
viewspace.hxx
Go to the documentation of this file.
1 #pragma once
2 #ifndef OPENGM_VIEW_SPACE_HXX
3 #define OPENGM_VIEW_SPACE_HXX
4 
5 #include <vector>
6 #include <limits>
7 
8 #include "opengm/opengm.hxx"
10 
12 
13 namespace opengm {
14 
18 template<class GM>
19 class ViewSpace
20 : public SpaceBase<ViewSpace<GM>, typename GM::IndexType, typename GM::LabelType> {
21 public:
22  typedef typename GM::IndexType IndexType;
23  typedef typename GM::LabelType LabelType;
24  typedef typename GM::SpaceType SrcSpaceType;
25 
26  ViewSpace();
27  ViewSpace(const GM &);
28  void assign(const GM &);
29  IndexType addVariable(const LabelType);
30  IndexType numberOfVariables() const;
31  LabelType numberOfLabels(const IndexType) const;
32 
33 private:
34  SrcSpaceType const* space_;
35 };
36 
37 template<class GM>
38 inline
39 ViewSpace<GM>::ViewSpace()
40 : space_(NULL)
41 {}
42 
43 template<class GM>
44 inline
45 ViewSpace<GM>::ViewSpace(
46  const GM & gm
47 )
48 : space_(&gm.space())
49 {}
50 
51 template<class GM>
52 inline void
53 ViewSpace<GM>::assign(
54  const GM & gm
55 )
56 {
57  space_=& gm.space();
58 }
59 
60 template<class GM>
61 inline typename ViewSpace<GM>::IndexType
62 ViewSpace<GM>::addVariable(
63  const LabelType numberOfLabels
64 )
65 {
66  opengm::RuntimeError("cannot add Variable with a ViewSpace as a space object");
67 }
68 
69 template<class GM>
70 inline typename ViewSpace<GM>::IndexType
71 ViewSpace<GM>::numberOfVariables() const
72 {
73  OPENGM_ASSERT(space_!=NULL);
74  return space_->numberOfVariables();
75 }
76 
77 template<class GM>
78 inline typename ViewSpace<GM>::IndexType
79 ViewSpace<GM>::numberOfLabels
80 (
81  const IndexType dimension
82 ) const
83 {
84  OPENGM_ASSERT(space_!=NULL);
85  return space_->numberOfLabels(dimension);
86 }
87 
88 } // namespace opengm
89 
91 
92 #endif // #ifndef OPENGM_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