shape_accessor.hxx

Go to the documentation of this file.
00001 #pragma once
00002 #ifndef OPENGM_SHAPE_ACCESSOR_HXX
00003 #define OPENGM_SHAPE_ACCESSOR_HXX
00004 
00005 namespace opengm {
00006 
00008 
00009    template<class FUNCTION>
00010    class FunctionShapeAccessor {
00011    public:
00012       typedef size_t value_type;
00013       typedef const value_type reference;
00014       typedef const value_type* pointer;
00015       typedef const FUNCTION& factor_reference;
00016       typedef const FUNCTION* factor_pointer;
00017 
00018       FunctionShapeAccessor(factor_pointer f = NULL)
00019          : factor_(f) 
00020          {}
00021       FunctionShapeAccessor(factor_reference f)
00022          : factor_(&f) 
00023          {}
00024       size_t size() const { 
00025          return factor_ == NULL ? 0 : factor_->dimension();
00026       }
00027       value_type operator[](const size_t j) { 
00028          OPENGM_ASSERT(j<factor_->dimension());
00029          return factor_->shape(j); 
00030       }
00031       const value_type operator[](const size_t j) const { 
00032          OPENGM_ASSERT(j<factor_->dimension());
00033          return factor_->shape(j); 
00034       }
00035       bool operator==(const FunctionShapeAccessor<FUNCTION> & other) const 
00036          { return factor_ == other.factor_; }
00037    
00038    private:
00039       factor_pointer factor_;
00040    };
00041 
00042    template<class FACTOR>
00043    class FactorShapeAccessor {
00044    public:
00045       typedef size_t value_type;
00046       typedef const value_type reference;
00047       typedef const value_type* pointer;
00048       typedef const FACTOR& factor_reference;
00049       typedef const FACTOR* factor_pointer;
00050 
00051       FactorShapeAccessor(factor_pointer f = 0)
00052          : factor_(f) 
00053          {}
00054       FactorShapeAccessor(factor_reference f)
00055          : factor_(&f) 
00056          {}
00057       size_t size() const 
00058          { return factor_ == 0 ? 0 : factor_->numberOfVariables(); }
00059       reference operator[](const size_t j) 
00060          { return factor_->numberOfLabels(j); }
00061       const value_type operator[](const size_t j) const 
00062          { return factor_->numberOfLabels(j); }
00063       bool operator==(const FactorShapeAccessor<FACTOR> & other) const 
00064          { return factor_ == other.factor_; }
00065    
00066    private:
00067       factor_pointer factor_;
00068    };
00069    
00070    template<class FACTOR>
00071    class FactorVariablesAccessor {
00072    public:
00073       typedef typename FACTOR::IndexType IndexType;
00074       typedef IndexType value_type;
00075       typedef const value_type reference;
00076       typedef const value_type* pointer;
00077       typedef const FACTOR& factor_reference;
00078       typedef const FACTOR* factor_pointer;
00079 
00080       FactorVariablesAccessor(factor_pointer f = 0)
00081          : factor_(f) 
00082          {}
00083       FactorVariablesAccessor(factor_reference f)
00084          : factor_(&f) 
00085          {}
00086       IndexType size() const 
00087          { return factor_ == 0 ? 0 : factor_->numberOfVariables(); }
00088       reference operator[](const size_t j) 
00089          { return factor_->numberOfLabels(j); }
00090       const value_type operator[](const size_t j) const 
00091          { return factor_->variableIndex(j); }
00092       bool operator==(const FactorVariablesAccessor<FACTOR> & other) const 
00093          { return factor_ == other.factor_; }
00094    
00095    private:
00096       factor_pointer factor_;
00097    };
00098 
00100 
00101 } // namespace opengm
00102 
00103 #endif // #ifndef OPENGM_SHAPE_ACCESSOR_HXX
00104 
 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