static_simplediscretespace.hxx

Go to the documentation of this file.
00001 #pragma once
00002 #ifndef OPENGM_STATIC_SIMPLE_DISCRETE_SPACE_HXX
00003 #define OPENGM_STATIC_SIMPLE_DISCRETE_SPACE_HXX
00004 
00005 #include "opengm/opengm.hxx"
00006 #include "opengm/graphicalmodel/space/space_base.hxx"
00007 
00008 namespace opengm {
00009 
00013 template<size_t LABELS, class I = std::size_t , class L = std::size_t>
00014 class StaticSimpleDiscreteSpace
00015 :  public SpaceBase<StaticSimpleDiscreteSpace<LABELS, I, L>, I, L>
00016 {
00017 public:
00018    typedef I IndexType;
00019    typedef L LabelType;
00020 
00021    StaticSimpleDiscreteSpace();
00022    StaticSimpleDiscreteSpace(const IndexType);
00023    void assign(const IndexType);
00024    template<class Iterator> void assignDense(Iterator, Iterator);
00025    IndexType addVariable(const LabelType );
00026    IndexType numberOfVariables() const;
00027    LabelType numberOfLabels(const IndexType) const;
00028    bool isSimpleSpace()const;
00029 
00030 private:
00031    IndexType numberOfVariables_;
00032 };
00033 
00034 template<size_t LABELS,class I, class L>
00035 inline
00036 StaticSimpleDiscreteSpace<LABELS,I, L>::StaticSimpleDiscreteSpace()
00037 :  numberOfVariables_()
00038 {}
00039 
00040 template<size_t LABELS,class I, class L>
00041 inline
00042 StaticSimpleDiscreteSpace<LABELS,I, L>::StaticSimpleDiscreteSpace(
00043    const IndexType numberOfVariables
00044 )
00045 :  numberOfVariables_(numberOfVariables)
00046 {}
00047 
00048 template<size_t LABELS,class I, class L>
00049 template<class Iterator>
00050 inline void
00051 StaticSimpleDiscreteSpace<LABELS,I, L>::assignDense(
00052    Iterator begin,
00053    Iterator end
00054 ) {
00055    numberOfVariables_=std::distance(begin, end);
00056    numberOfVariables_=static_cast<L>(*begin);
00057    while(begin!=end) {
00058       if(LABELS!=static_cast<size_t>(*begin)) {
00059          throw opengm::RuntimeError("*begin==LABELS_ is violated \
00060          in StaticSimpleDiscreteSpace::assignDense ");
00061       }
00062       ++begin;
00063    }
00064 }
00065 
00066 template<size_t LABELS,class I, class L>
00067 inline void
00068 StaticSimpleDiscreteSpace<LABELS,I, L>::assign(
00069    const IndexType numberOfVariables
00070 ) {
00071    numberOfVariables_ = numberOfVariables;
00072 }
00073 
00074 template<size_t LABELS,class I, class L>
00075 inline I
00076 StaticSimpleDiscreteSpace<LABELS,I, L>::addVariable(
00077    const L numberOfLabels
00078 ) {
00079    if(numberOfLabels!=static_cast<L> (LABELS)) {
00080       throw opengm::RuntimeError("numberOfLabels==LABELS is violated \
00081       in StaticSimpleDiscreteSpace::addVariable ");
00082    }
00083 }
00084 
00085 template<size_t LABELS,class I, class L>
00086 inline typename StaticSimpleDiscreteSpace<LABELS,I, L>::IndexType
00087 StaticSimpleDiscreteSpace<LABELS,I, L>::numberOfVariables() const {
00088    return numberOfVariables_;
00089 }
00090 
00091 template<size_t LABELS,class I, class L>
00092 inline typename StaticSimpleDiscreteSpace<LABELS,I, L>::LabelType
00093 StaticSimpleDiscreteSpace<LABELS,I, L>::numberOfLabels(
00094    const IndexType dimension
00095 ) const {
00096    return static_cast<L> LABELS;
00097 }
00098 
00099 template<size_t LABELS,class I, class L>
00100 inline bool
00101 StaticSimpleDiscreteSpace<LABELS,I, L>::isSimpleSpace() const
00102 {
00103    return true;
00104 }
00105 
00106 } // namespace opengm
00107 
00108 #endif // #ifndef OPENGM_STATIC_SIMPLE_DISCRETE_SPACE_HXX
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Mon Jun 17 16:31:06 2013 for OpenGM by  doxygen 1.6.3