discretespace.hxx

Go to the documentation of this file.
00001 #pragma once
00002 #ifndef OPENGM_DISCRETE_SPACE_HXX
00003 #define OPENGM_DISCRETE_SPACE_HXX
00004 
00005 #include <vector>
00006 #include <limits>
00007 
00008 #include "opengm/opengm.hxx"
00009 #include "opengm/graphicalmodel/space/space_base.hxx"
00010 
00011 namespace opengm {
00012 
00016 template<class I = std::size_t, class L = std::size_t>
00017 class DiscreteSpace 
00018 :  public SpaceBase<DiscreteSpace<I, L>, I, L> {
00019 public:
00020    typedef I IndexType;
00021    typedef L LabelType;
00022 
00023    DiscreteSpace();
00024    template<class Iterator> DiscreteSpace(Iterator, Iterator);
00025    template<class Iterator> void assign(Iterator, Iterator);
00026    template<class Iterator> void assignDense(Iterator, Iterator);
00027    IndexType addVariable(const LabelType);
00028    IndexType numberOfVariables() const;
00029    LabelType numberOfLabels(const IndexType) const;
00030    void reserve(const IndexType);
00031 
00032 private:
00033    std::vector<LabelType> numbersOfLabels_;
00034 };
00035 
00037 template<class I, class L>
00038 inline
00039 DiscreteSpace<I, L>::DiscreteSpace()
00040 :  numbersOfLabels_() {
00041 }
00042 
00043 
00053 template<class I, class L>
00054 template<class Iterator>
00055 inline
00056 DiscreteSpace<I, L>::DiscreteSpace
00057 (
00058    Iterator begin, 
00059    Iterator end 
00060 )
00061 :  numbersOfLabels_(begin, end) {
00062    OPENGM_ASSERT(numbersOfLabels_.size()>0);
00063    OPENGM_ASSERT(std::numeric_limits<IndexType>::max()>numbersOfLabels_.size());
00064 }
00065 
00069 template<class I, class L>
00070 template<class Iterator>
00071 inline void
00072 DiscreteSpace<I, L>::assign
00073 (
00074    Iterator begin,
00075    Iterator end
00076 ) {
00077    numbersOfLabels_.assign(begin, end);
00078    OPENGM_ASSERT(std::numeric_limits<IndexType>::max()>numbersOfLabels_.size());
00079 }
00080 
00082 template<class I, class L>
00083 inline void
00084 DiscreteSpace<I, L>::reserve
00085 (
00086    const I numberOfVariables
00087 ) {
00088    this->numbersOfLabels_.reserve(numberOfVariables);
00089 }
00090 
00091 template<class I, class L>
00092 template<class Iterator>
00093 inline void
00094 DiscreteSpace<I, L>::assignDense
00095 (
00096    Iterator begin,
00097    Iterator end
00098 ) {
00099    this->assign(begin, end);
00100 }
00101 
00103 template<class I, class L>
00104 inline typename DiscreteSpace<I, L>::IndexType
00105 DiscreteSpace<I, L>::addVariable
00106 (
00107    const LabelType numberOfLabels
00108 ) {
00109    numbersOfLabels_.push_back(numberOfLabels);
00110    OPENGM_ASSERT(std::numeric_limits<IndexType>::max()>numbersOfLabels_.size());
00111    return numbersOfLabels_.size() - 1;
00112 }
00113 
00114 template<class I, class L>
00115 inline typename DiscreteSpace<I, L>::IndexType
00116 DiscreteSpace<I, L>::numberOfVariables() const
00117 {
00118    return static_cast<IndexType>(numbersOfLabels_.size());
00119 }
00120 
00121 template<class I, class L>
00122 inline typename DiscreteSpace<I, L>::LabelType
00123 DiscreteSpace<I, L>::numberOfLabels
00124 (
00125    const IndexType dimension
00126 ) const
00127 {
00128    return numbersOfLabels_[dimension];
00129 }
00130 
00131 } // namespace opengm
00132 
00133 #endif // #ifndef OPENGM_DISCRETE_SPACE_HXX
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Mon Jun 17 16:31:01 2013 for OpenGM by  doxygen 1.6.3