simplediscretespace.hxx

Go to the documentation of this file.
00001 #pragma once
00002 #ifndef OPENGM_SIMPLE_DISCRETE_SPACE_HXX
00003 #define OPENGM_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<class I = std::size_t, class L = std::size_t>
00014 class SimpleDiscreteSpace
00015 :  public SpaceBase<SimpleDiscreteSpace<I, L>, I, L> {
00016 public:
00017    typedef I IndexType;
00018    typedef L LabelType;
00019 
00020    SimpleDiscreteSpace();
00021    SimpleDiscreteSpace(const IndexType, const LabelType);
00022    void assign(const IndexType, const LabelType);
00023    template<class Iterator> void assignDense(Iterator, Iterator);
00024    IndexType addVariable(const LabelType);
00025    IndexType numberOfVariables() const;
00026    LabelType numberOfLabels(const IndexType) const;
00027    bool isSimpleSpace() const ;
00028 
00029 private:
00030    IndexType numberOfVariables_;
00031    LabelType numberOfLabels_;
00032 };
00033 
00034 template<class I, class L>
00035 inline
00036 SimpleDiscreteSpace<I, L>::SimpleDiscreteSpace()
00037 :  numberOfVariables_(),
00038    numberOfLabels_()
00039 {}
00040 
00041 template<class I, class L>
00042 inline
00043 SimpleDiscreteSpace<I, L>::SimpleDiscreteSpace
00044 (
00045    const IndexType numberOfVariables,
00046    const LabelType numberOfLabels
00047 )
00048 :  numberOfVariables_(numberOfVariables),
00049    numberOfLabels_(numberOfLabels)
00050 {}
00051 
00052 template<class I, class L>
00053 template<class Iterator>
00054 inline void
00055 SimpleDiscreteSpace<I, L>::assignDense
00056 (
00057    Iterator begin,
00058    Iterator end
00059 ) {
00060    numberOfVariables_ = std::distance(begin, end);
00061    numberOfLabels_ = static_cast<L>(*begin);
00062    while(begin != end) {
00063       if(numberOfLabels_ != static_cast<LabelType>(*begin)) {
00064          throw opengm::RuntimeError("*begin == SimpleDiscreteSpace.numberOfLabels_ is violated in SimpleDiscreteSpace::assignDense");
00065       }
00066       ++begin;
00067    }
00068 }
00069 
00070 template<class I, class L>
00071 inline void
00072 SimpleDiscreteSpace<I, L>::assign
00073 (
00074    const IndexType numberOfVariables,
00075    const LabelType numberOfLabels
00076 ) {
00077    numberOfVariables_ = numberOfVariables;
00078    numberOfLabels_ = numberOfLabels;
00079 }
00080 
00081 template<class I, class L>
00082 inline typename SimpleDiscreteSpace<I, L>::IndexType
00083 SimpleDiscreteSpace<I, L>::addVariable
00084 (
00085    const LabelType numberOfLabels
00086 ) {
00087    if(numberOfLabels != numberOfLabels_) {
00088       throw opengm::RuntimeError("numberOfLabels == SimpleDiscreteSpace.numberOfLabels_ is violated in SimpleDiscreteSpace::addVariable");
00089    }
00090    ++numberOfVariables_;
00091    return numberOfVariables_ - 1;
00092 }
00093 
00094 template<class I, class L>
00095 inline typename SimpleDiscreteSpace<I, L>::IndexType
00096 SimpleDiscreteSpace<I, L>::numberOfVariables() const {
00097    return numberOfVariables_;
00098 }
00099 
00100 template<class I, class L>
00101 inline typename SimpleDiscreteSpace<I, L>::LabelType
00102 SimpleDiscreteSpace<I, L>::numberOfLabels
00103 (
00104    const IndexType dimension
00105 ) const {
00106    return numberOfLabels_;
00107 }
00108 
00109 template<class I, class L>
00110 inline  bool
00111 SimpleDiscreteSpace<I, L>::isSimpleSpace() const{
00112    return true;
00113 }
00114 
00115 } // namespace opengm
00116 
00117 #endif // #ifndef OPENGM_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