vector_view_space.hxx
Go to the documentation of this file.00001 #pragma once
00002 #ifndef OPENGM_VECTOR_VIEW_SPACE_HXX
00003 #define OPENGM_VECTOR_VIEW_SPACE_HXX
00004
00006
00007 #include <vector>
00008 #include <limits>
00009
00010 #include "opengm/opengm.hxx"
00011 #include "opengm/graphicalmodel/space/space_base.hxx"
00012
00013 namespace opengm {
00014
00018 template<class I = std::size_t, class L = std::size_t>
00019 class VectorViewSpace
00020 : public SpaceBase<VectorViewSpace<I,L>,I,L>
00021 {
00022 public:
00023 typedef I IndexType;
00024 typedef L LabelType;
00025
00026 VectorViewSpace();
00027 VectorViewSpace(const std::vector<LabelType>&);
00028 IndexType addVariable(const LabelType);
00029 IndexType numberOfVariables() const;
00030 LabelType numberOfLabels(const IndexType) const;
00031
00032 private:
00033 std::vector<LabelType> const* numbersOfLabels_;
00034 };
00035
00036 template<class I, class L>
00037 inline
00038 VectorViewSpace<I, L>::VectorViewSpace()
00039 : numbersOfLabels_(NULL)
00040 {}
00041
00042 template<class I, class L>
00043 inline
00044 VectorViewSpace<I, L>::VectorViewSpace
00045 (
00046 const std::vector<LabelType>& spaceVector
00047 )
00048 : numbersOfLabels_(&spaceVector)
00049 {
00050 OPENGM_ASSERT(numbersOfLabels_->size()>0);
00051 }
00052
00053 template<class I, class L>
00054 inline typename VectorViewSpace<I, L>::IndexType
00055 VectorViewSpace<I, L>::addVariable(
00056 const LabelType numberOfLabels
00057 ) {
00058 throw opengm::RuntimeError("attempt to add a variable to VectorViewSpace");
00059 }
00060
00061 template<class I, class L>
00062 inline typename VectorViewSpace<I, L>::IndexType
00063 VectorViewSpace<I, L>::numberOfVariables() const
00064 {
00065 return static_cast<IndexType>(numbersOfLabels_->size());
00066 }
00067
00068 template<class I, class L>
00069 inline typename VectorViewSpace<I, L>::LabelType
00070 VectorViewSpace<I, L>::numberOfLabels(
00071 const IndexType dimension
00072 ) const
00073 {
00074 OPENGM_ASSERT(dimension<numbersOfLabels_->size());
00075 return numbersOfLabels_->operator[](dimension);
00076 }
00077
00078 }
00079
00081
00082 #endif // #ifndef OPENGM_VECTOR_VIEW_SPACE_HXX